If i create the global semaphore in the task that uses it, then the task gets notifications at roughly the FreeRTOS tick rate ( in this case, 500Hz ) with some gaps.
If i create the semaphore in app_main before creating the task that uses it, everything works as expected, the notifications are processed at the data ready interrupt rate (~400Hz) without missing any.
Not sure if this is correct behavior, in any case, it would be nice to have an explanation.
Code: Select all
volatile SemaphoreHandle_t imuSemaphore;
void drdyHandler(void) {
xSemaphoreGiveFromISR(imuSemaphore, NULL);
}
static void imu_task() {
// does not work if created here !
//imuSemaphore = xSemaphoreCreateBinary();
//attachInterrupt(pinDRDYINT, drdyHandler, RISING);
// initialize device to generate data and data ready interrupts ...
while (1) {
if (xSemaphoreTake(imuSemaphore, portMAX_DELAY)) {
LED_ON();
// read the data from device
LED_OFF();
}
}
}
void app_main() {
// init stuff ...
// works if semaphore created here
imuSemaphore = xSemaphoreCreateBinary();
attachInterrupt(pinDRDYINT, drdyHandler, RISING);
xTaskCreatePinnedToCore(&imu_task, "imutask", 2048, NULL, 20, NULL, 1);
while(1) {
// do some stuff
delayMs(30);
}
}