FreeRTOS ISRs on Cortex M3 - Page 1
Forum section: electronics / general

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: December 09, 2020, 11:20:16 pm
content: I've been using FreeRTOS on the PSoC 5 devices (Cortex M3), and learning from examples as I go. I found this construct used in all the interrupt service routines, when the ISRs have to signal a task using Task Notifications or writing to queues:Code:CY_ISR_PROTO(my_isr);CY_ISR(my_isr){portBASE_TYPE higher_priority_woken = pdFALSE;uint32_t mask = 0;mask = portSET_INTERRUPT_MASK_FROM_ISR();{xTaskNotifyFromISR(my_task_id, 0x1, eSetBits, &higher_priority_woken);/* Can also be the following:xQueueSendFromISR(my_queue, &some_data, &higher_priority_woken);*/}portCLEAR_INTERRUPT_MASK_FROM_ISR(mask);portEND_SWITCHING_ISR(higher_priority_woken);}What do theportSET_INTERRUPT_MASK_FROM_ISRandportCLEAR_INTERRUPT_MASK_FROM_ISRmacros do? They are not present in examples found Richard Barry's "Mastering the FreeRTOS Real Time Kernel" book, and in many other examples that are meant for other architectures (like AVR). My Google-fu seems weak when looking for info on this. Thanks!

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 10, 2020, 03:43:27 am
content: The quickest answer to such questions really is to just read the code of those macro's, figure out what registers they use and read that part of the datasheet.If your IDE does not help you do such a thing in 20s or less, then ditch it and get a decent programming environment.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: December 10, 2020, 07:09:24 pm
content: Is it code generated by PSoC Creator?

author: newbrain
author_rank: Super Contributor
timestamp: December 10, 2020, 11:14:33 pm
content: Those two function-like macros are totally redundant in the ISR, as they are already part of the notification or queue API calls.Their purpose is to inhibit interrupts with a priority lower or equal to the maximum allowed priority for IRS that use FreeRTOS API.In practice, they avoid API call to overlap in critical parts, while still allowing for higher priority interrupts (banned from using the API).Which release of FreeRTOS is that? It might be they were once needed (the behaviour has changed in this respect), but surely not from 8.0 onward.

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: December 11, 2020, 06:10:36 am
content: Quote from: GromBeestje on December 10, 2020, 07:09:24 pmNo, it came from examples I found on writing ISRs for FreeRTOS; the CY_ISR_PROTO and CY_ISR macros are part of Cypress' HAL. Here's some info on the PSoC port of FreeRTOS:https://www.freertos.org/FreeRTOS-port-and-demo-for-Cypress-PSoC5-CY8C5588-Cortex-M3.html(hmm, shouldn't that be CY8C5888?) The corresponding demo within the FreeRTOS source includes a serial port demo, whose ISR sets and clears the interrupt mask; I used this as the basis for my own ISRs. However, most other examples I found don't seem to use them, hence my question.Quote from: newbrain on December 10, 2020, 11:14:33 pmThat's what I suspected, but had no easy way to test. My code ran just fine without them, but I'm not well versed enough with FreeRTOS to say if this would cause failures down the road when the CM3 generated "nested" interrupts (for now, all my interrupts have the same priority). I'm using FreeRTOS 10.4.0, but the examples may have been for an older version. Would you say it's safe to leave them out? Given the examples I used date back to 2017, it's likely they were written for an older version of FreeRTOS.

author: newbrain
author_rank: Super Contributor
timestamp: December 11, 2020, 08:57:38 am
content: Quote from: radar_macgyver on December 11, 2020, 06:10:36 amAs you say, they don't appear in any of the other demos I've checked.FreeRTOS example code does not include them when describing the...fromISRAPI calls.Considering that the PSoC5 port does not differ in task/notification/queues implementation, I'm inclined to think they are dead code and safe to be removed.Disclaimer: not a FreeRTOS expert, just a hobbyist user.

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: December 11, 2020, 11:43:06 pm
content: Thanks, I'll comment them out and see if anything crops up during further development. This is only my second FreeRTOS project, so any advice is greatly appreciated!