CMSIS RTOS: Event fired in SW Timer callback does not immediately run waiting thread
Hello,
I implement kind of “lazy write cache” for flash and have problem.
The consumer thread sends out cache write requests to the flash thread using events.
The flash thread starts a SW timer which fires an event if no more cache write occurs.
In the oscilloscope I see that the timer callback is run after timeout occured but the flash thread, which is triggered by the callback, is not executed immediately (it is run as soon as the next cache write event is received).
I’m afraid this is a priority problem, but fiddling with task prios doesn’t help.
Any idea is greatly appreciated!
Thanks,
Jochen
uint32_t NCB_Cache_Write(eREQID_t eRid, ePNORNUM_t eFid, uint32_t ulOfs, uint8_t bData) {
psNcbTaskArgs_t psArgs = &asNcbTaskArgs[eFid];
psArgs->pusBuf[ulOfs] = bData;
psArgs->ulAdr = ulOfs;
// run core thread after send request called by upper layer / send notification
osEventFlagsSet(psArgs->phEventId, NCB_FLAG_FLUSH_REQ);
}
static void NCB_Timer_CB(void *arg) {
// set TIMER event flag of appropriate thread
uint32_t ulTID = (uint32_t)arg;
psNcbTaskArgs_t psArgs = &asNcbTaskArgs[ulTID];
TEST_TRIGGER(1);
osEventFlagsSet(psArgs->phEventId, NCB_FLAG_TIMER_EXP);
TEST_TRIGGER(0);
}
static void NCB_CoreThread(void *argument) {
// configuration data passed via task argument
psNcbTaskArgs_t psArgs = (psNcbTaskArgs_t) argument;
:
while (1) {
psArgs->eEvtFlag = osEventFlagsWait(psArgs->phEventId, 0xffff,
osFlagsWaitAny, osWaitForever);
if(psArgs->eEvtFlag & NCB_FLAG_TIMER_EXP) {
TEST_TRIGGER(1);
osDelay(2);
TEST_TRIGGER(0);
} else if(psArgs->eEvtFlag & NCB_FLAG_FLUSH_REQ) {
TEST_TRIGGER(1);
osTimerStart(psArgs->phTimerId, NCB_CACHE_TIMEOUT_MS);
TEST_TRIGGER(0);
}
} // while(1)
} // NCB_CoreThread()
void NCB_Init(void) {
for (uint32_t iTID = 0; iTID < NCB_TASK_CNT; iTID++) {
psNcbTaskArgs_t psArgs = &asNcbTaskArgs[iTID];
ahNCBCoreThread[iTID] = osThreadNew(NCB_CoreThread, (void*) psArgs,
&NCB_Thread_attributes);
psArgs->phEventId = osEventFlagsNew(NULL);
// creates a one-shot timer, iTID passed as an argument to the callback function
psArgs->phTimerId = osTimerNew(NCB_Timer_CB, osTimerOnce, (void *)iTID, NULL);
} // for()
} // PNOR_CoreInit()
