Skip to content

Commit 27d80fc

Browse files
committed
RPC: use signals to allow executing callback outside IRQ
1 parent 4b38d92 commit 27d80fc

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

libraries/RPC/RPC.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ void RPC::new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t d
6666
}
6767
}
6868

69+
osThreadId eventHandlerThreadId;
70+
71+
void eventHandler() {
72+
eventHandlerThreadId = osThreadGetId();
73+
while (1) {
74+
osEvent v = osSignalWait(0, osWaitForever);
75+
#ifdef CORE_CM4
76+
delay(50);
77+
#endif
78+
OPENAMP_check_for_message();
79+
}
80+
}
6981

7082
#ifdef CORE_CM4
7183
int RPC::begin() {
@@ -75,6 +87,9 @@ int RPC::begin() {
7587
/*HW semaphore Notification enable*/
7688
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
7789

90+
eventThread = new rtos::Thread(osPriorityHigh);
91+
eventThread->start(&eventHandler);
92+
7893
/* Inilitize OpenAmp and libmetal libraries */
7994
if (MX_OPENAMP_Init(RPMSG_REMOTE, NULL) != 0) {
8095
return 0;
@@ -107,10 +122,6 @@ int RPC::begin() {
107122
return 0;
108123
}
109124

110-
eventThread = new rtos::Thread(osPriorityNormal);
111-
eventThread->start(callback(&eventQueue, &events::EventQueue::dispatch_forever));
112-
ticker.attach(eventQueue.event(&OPENAMP_check_for_message), 0.01f);
113-
114125
dispatcherThread = new rtos::Thread(osPriorityNormal);
115126
dispatcherThread->start(mbed::callback(this, &RPC::dispatch));
116127

@@ -157,8 +168,8 @@ int RPC::begin() {
157168
//HAL_SYSCFG_EnableCM4BOOT();
158169
HAL_RCCEx_EnableBootCore(RCC_BOOT_C2);
159170

160-
/* Initialize the mailbox use notify the other core on new message */
161-
MAILBOX_Init();
171+
eventThread = new rtos::Thread(osPriorityHigh);
172+
eventThread->start(&eventHandler);
162173

163174
/* Initialize OpenAmp and libmetal libraries */
164175
if (MX_OPENAMP_Init(RPMSG_MASTER, new_service_cb) != HAL_OK) {
@@ -191,10 +202,6 @@ int RPC::begin() {
191202
OPENAMP_send(&rp_endpoints[1], &message, sizeof(message));
192203
OPENAMP_send(&rp_endpoints[2], &message, sizeof(message));
193204

194-
//eventThread = new rtos::Thread(osPriorityNormal);
195-
//eventThread->start(callback(&eventQueue, &events::EventQueue::dispatch_forever));
196-
//ticker.attach(eventQueue.event(&OPENAMP_check_for_message), 0.01f);
197-
198205
dispatcherThread = new rtos::Thread(osPriorityNormal);
199206
dispatcherThread->start(mbed::callback(this, &RPC::dispatch));
200207

libraries/openamp_arduino/src/mailbox_hsem_if.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ static uint32_t msg_received = RX_NO_MSG;
6969

7070
void OPENAMP_check_for_message(void);
7171

72+
#include "cmsis_os.h"
73+
extern osThreadId eventHandlerThreadId;
74+
7275
/* Private functions ---------------------------------------------------------*/
7376
void HAL_HSEM_FreeCallback(uint32_t SemMask)
7477
{
@@ -83,9 +86,7 @@ void HAL_HSEM_FreeCallback(uint32_t SemMask)
8386
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
8487
#endif
8588

86-
#ifdef CORE_CM7
87-
OPENAMP_check_for_message();
88-
#endif
89+
osSignalSet(eventHandlerThreadId, 0x1);
8990
}
9091

9192
/**

0 commit comments

Comments
 (0)