Skip to content

Conversation

@Donny9
Copy link
Contributor

@Donny9 Donny9 commented Jul 22, 2022

Summary

system/uorb: support uorb, include uorb wraper, unit test, uorb_listener, topic definition

refer to: https://docs.px4.io/v1.12/en/middleware/uorb.html
uORB comes from the open source flight control PX4, is the internal pub-sub messaging system, used for communication between modules.

About original uORB implementation:

  • No thread or work queue is needed, the module start only makes sure to initialize the shared global state.
  • Communication is done via shared memory.
  • The implementation is asynchronous and lock-free, ie. a publisher does not wait for a subscriber and vice versa.
  • This is achieved by having a separate buffer between a publisher and a subscriber.
  • The code is optimized to minimize the memory footprint and the latency to exchange messages.

About uORB shortcoming:

  • The internal driver of uorb is implemented in user space and cannot run in kernel mode.
  • Uorb is developed in C++ language, and the integration needs to rely on libc++, which is not good for embedded devices with limited resources.
  • There is no relationship between the subscriber and the publisher, and it is impossible to control the publisher according to the status of the subscriber, which is required in many cases.For example, to control whether to open it according to the subscription of the sensor.
  • For weaker sampling support, there is a cumulative error.

For the original design, vela has been enhanced:

  • Enhanced nuttx sensor driver framework, adapted to uorb cdev function.
  • Use c language to implement uorb upper wrapper.
  • The interaction between subscribers and publishers is completed through event POLLPRI, making the whole framework more intelligent.
  • By working with sensor rpmsg, you can subscribe to multi-core topics transparently and without any sense, make the whole system configuration more flexible.
  • Change all interfaces of uorb to file descriptor operations to simplify usage.
  • Keep most of the test cases and test tools with the original uorb.

Impact

Support uorb middleware

Testing

Vela CI

refer to: https://docs.px4.io/v1.12/en/middleware/uorb.html

- orb_open: do real work for advertise() and subscribe(), if thre is
            no user, register topic first, then save meta in driver;
            only first user can successfully set buffer number.
- orb_exists: check topic state, if topic only has subscribers,
	      return "not exists".

Signed-off-by: jihandong <jihandong@xiaomi.com>
jihandong and others added 19 commits July 22, 2022 08:12
testcases:
1. test_single(): single instance, advertise then subscribe.
2. test_multi_inst10(): 10 instance, each 1 subscriber.
3. test_multi(): 2 instances, 2 advertisers, 2 subscribers.
4. test_multi_reversed(): same as test_multi(), but subsribe before
		          advertise.
5. test_unadvertise(): unadvertise upper 4 advertisers.
6. test_multi2(): same as tset_multi(). but multi-thread.
7, test_queue():  topic queue_size = 16.

Signed-off-by: jihandong <jihandong@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Listener can scan device under ORB_SENSOR_PATH, subscribe them and
cotinue printing messages by call their cb.

'-T' can Continuously print updating objects, '-l' means only
print once.

Signed-off-by: jihandong <jihandong@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
don't using subscriber to get state to avoid rpmsg access

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
…ce 0

1.orb_advertise, orb_advertise_queue for instance 0
2.orb_advertise_multi, orb_advertise__multi_queue for specified instance
3.If orb_advertise_multi_queue with instance is NULL, auto increase
instance from existing base.

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: jihandong <jihandong@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
int func(int b)
{
    int a;

    while (1) {
        ...;

        if (b != 0)
            a = 1000 / b;

        ...;
    }
}

if b == 0, then system crash in Xtensa arch, clang compiler

Signed-off-by: ligd <liguiding1@xiaomi.com>
orb_advertise_multi_queue_persist

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
And remove dead code.

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: jihandong <jihandong@xiaomi.com>
Signed-off-by: jihandong <jihandong@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
Signed-off-by: jihandong <jihandong@xiaomi.com>
@acassis acassis merged commit 74af9a8 into apache:master Jul 23, 2022

ret = ioctl(fd, SNIOC_REGISTER, (unsigned long)(uintptr_t)&reginfo);
close(fd);
if (ret < 0 && ret != -EEXIST)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check errno instead

if (first_open)
{
ioctl(fd, SNIOC_SET_USERPRIV, (unsigned long)(uintptr_t)meta);
if (ret != -EEXIST)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use errno instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants