scoping of xBinarySemaphore?

jack-king wrote on Sunday, February 10, 2019:

Hello, I am working through the Cortex-M3 FreeRTOS guide and reviewing the Example 12 for interrupts and binary semaphores.

Looking at the main() function that creates the xBinarySemaphore handle in Listing 48… how is the semaphore handle in scope for the ISR handler?

I am using a hardware GPIO ISR and get a scoping error when trying to access the semaphore in the ISR.

richarddamon wrote on Sunday, February 10, 2019:

I don’t have that manual/listing in front of me, but generally I put FreeRTOS item handles at global scope (or part of a structure that is at global scope) to make it easier for the different pieces to access it.

In general, and especially for things like the Cortex-M3, there shouldn’t be items declared in the scope of main (maybe a loop counter for loops in the setup code in main), as those aren’t available to other functions, and on many ports, the Arm included, the main function stack gets reused as the interrupt stack, so any object declared their might get overwritten.

rtel wrote on Sunday, February 10, 2019:

Looking in the book text, it doesn’t show where the semaphore is
declared, but you have the source code available too so you can look in
there. I would suspect it will be a file scope static.

jack-king wrote on Sunday, February 10, 2019:

Yes, I tracked down the example code and see the semaphore declared with global scope outside main(). Thanks!