Semaphore take and give not working after they are moved to two files


I am taking an example of a FreeRTOS and develop my own software. There is one task taking the semaphore which is given from a timer ISR.
In the example, both the task function and the ISR are in the main.c. But after either the task function or the ISR is moved to a separate file, the semaphore give and take doesn’t work any more.
Anyone has this kind of experience or knows what might be the cause? Thanks!


The biggest issue tends to be that they are no longer looking at the same variable holding the handle to the semaphore.

It needs to either be stored in a global or somehow passed to a file-scoped variable for the functions to access.

Thanks Richard for your reply. Yes, it is the cause. I defined a global variable for the semaphore and it works.