events: Move implementation of events::send() to lib/events

Events have a global, system-wide sequence number, which must be handled
atomically, (fetching and incrementing the sequence AND sending the event
to uORB must be atomic). Currently in FLAT mode, only one instance of this
sequence number exists, so it is OK to have it in px4_platform.

However, in PROTECTED mode px4_platform is instantiated both in kernel-
and user spaces, which makes two instances of this sequence number, which
causes problems in the mavlink event handling logic.

When mavlink receives and handles events, it expects that:
- The sequence numbers arrive in order (seq n is followed by n+1 etc)
- It increments by 1
- There is only one instance of the sequence number

In PROTECTED mode this is violated, as the kernel and user sequence
numbers run freely on their own. This patch fixes the issue by moving
the event backend to the kernel and by providing user access to it via
ioctl.
This commit is contained in:
Ville Juven
2023-09-25 09:54:11 +02:00
committed by Beat Küng
parent fafec397e8
commit 6cb2c176d5
13 changed files with 233 additions and 4 deletions
@@ -53,7 +53,8 @@
#define _CRYPTOIOCBASE IOCTL_IDX_TO_BASE(2)
#define _PARAMIOCBASE IOCTL_IDX_TO_BASE(3)
#define _PLATFORMIOCBASE IOCTL_IDX_TO_BASE(4)
#define MAX_IOCTL_PTRS 5
#define _EVENTSIOCBASE IOCTL_IDX_TO_BASE(5)
#define MAX_IOCTL_PTRS 6
/* The PLATFORMIOCLAUNCH IOCTL is used to launch kernel side modules
* from the user side code
@@ -38,6 +38,7 @@
#include <px4_platform_common/console_buffer.h>
#include <px4_platform_common/defines.h>
#include <drivers/drv_hrt.h>
#include <lib/events/events.h>
#include <lib/parameters/param.h>
#include <px4_platform_common/px4_work_queue/WorkQueueManager.hpp>
#include <px4_platform/cpuload.h>
@@ -125,6 +126,7 @@ int px4_platform_init()
#if !defined(CONFIG_BUILD_FLAT)
hrt_ioctl_init();
events_ioctl_init();
#endif
/* configure CPU load estimation */
@@ -52,6 +52,8 @@ target_link_libraries(px4_kernel_layer
nuttx_kc
nuttx_karch
nuttx_kmm
PRIVATE
kernel_events_interface # events_ioctl_init
)
target_link_libraries(px4_kernel_layer