We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
The problem is similar to http://www.keil.com/forum/9257/ . I don't know whether it was solved.
when I call osSemaphoreWait(), the returned value is 0xFFFFFFFF (-1) , which is happened when I use hardware timer independently. The code is showing below,
int32_t sem; osSemaphoreId rl_sem[1]; osSemaphoreDef(sem_0); //user thread 1 Thread() { rl_sem[0]=osSemaphoreCreate(osSemaphore(sem_0),1); while(1) { ... sem = osSemaphoreWait(rl_sem[0],0); printf("sem=%d",sem); //sem normally should be 1, but here it is 0xFFFFFFFF, ie, -1 } } //CAN ISR CAN_IRQHandler() { ... osSemaphoreRelease(rl_sem[0]); } //timer ISR Timer_Callback() { // nothing to do with semaphore }
your advice is much appreciated!
There is no generic problem with semaphores CMSIS-RTOS RTX. Two things that you might verify.
Does this line return a proper ID?
rl_sem[0]=osSemaphoreCreate(osSemaphore(sem_0),1);
What is the return value of osSemaphoreRelease(rl_sem[0]) in the CAN_IRQHandler()?
yeah,the returned of osSemaphoreCreate is ok, for when no hardware time is used, it works normally. the return value of osSemaphoreRelease(rl_sem[0]) is 0,which means osOK.
Just when I use hardware timer, the return value of osSemaphoreWait is -1.
My cpu is MK64F12,and I use PIT timer. thank you!
Besides, if I set the timer period too small ,like 1ms, then other threads don't work anymore.
I use the hardware timer independently, RTX timer tick is 1000us or 100us which I both tried. The cpu clock is 120MHz.
what should I do , if a fast hardware counter is needed in CMSIS-RTX ? thank a lot.
sorry, I find I use "printf" in Timer IRQ, that resulted in the second problem. But semaphore problem is still not solved.
now, I find the problem, I look into the source code, and osSemaphoreWait is not allowed in ISR, so it returns -1. Thank you!