Go Down

Topic: RTOS hooks (Read 2 times) previous topic - next topic

fat16lib

It would be nice to have hooks in Due so popular RTOSs could be ported to Due as libraries.

The main requirement is to have access to the SVC_Handler, PendSV_Handler, and SysTick_Handler vectors.

A call to a weak dummy function at the end of these handles would be sufficient.  Currently SVC_Handler and PendSV_Handler are just for() loops that stop execution.

I understand that full preemptive RTOSs are not appropriate for most Arduino users but a few advanced users want the functionally of a full RTOS.

There are a lot of first class open source RTOSs that would run well on Due.

Paul Stoffregen provided these hooks for Teensy 3.0 and I ported ChibiOS/RT and FreeRTOS to Teensy 3.0 using these hooks.  I may port additional systems since I enjoy seeing how RTOSs are implemented and how they perform. 

I would like to provide these libraries to Due users in a way that would not require modification of the Arduino core.

Palliser

Hello fat16lib. Right now I am porting CAN protocol in Due. To test transmission (receiving messages) I am using a couple of interrupt handlers that read CAN controllers addresses at 0x400000000 in the memory-mapped interrupts of the CORTEX-M3. After a message is received, some I/O are managed. Like you said, a couple of calls to weak (aliases) dummy functions were enough. All these with third-party CMSIS gnu gcc exceptions. Regarding your RTOS hooks, I believe they could add more value for Due but from what I understand, as the more we are attached to the Arduino IDE libraries, the better for the Arduino community. Some 'exceptions' may apply. Regards.

cmaglie

fat16lib,
I'm actually resolving an issue with weak-symbols in interrupt handlers, I guess that at the end of my refactoring you can "hook" the interrupts directly.

C.

fat16lib

cmaglie,

That sounds great.  Teensy 3.0 has these three weak handlers, SVC_Handler, PendSV_Handler, and SysTick_Handler.

The only question is how to handle SysTick.  In Teensy 3.0 I replace the handler with one that that duplicates the Teensy 3.0 functionality and the RTOS needs.

I want the standard Arduino functionality to continue to work and have the option for a few high priority tasks and ISRs to use the RTOS functionality.

This way an ISR can cause a high priority task to execute in about 3 microseconds while loop() does low priority stuff like a normal Arduino sketch.

cmaglie


cmaglie,
The only question is how to handle SysTick.  In Teensy 3.0 I replace the handler with one that that duplicates the Teensy 3.0 functionality and the RTOS needs.

I want the standard Arduino functionality to continue to work and have the option for a few high priority tasks and ISRs to use the RTOS functionality.


I see the issue with SysTick, i've found the following solution to avoid code duplication:

https://github.com/arduino/Arduino/blob/ide-1.5.x/hardware/arduino/sam/cores/arduino/hooks.c

you just need to define a function called:

Code: [Select]
int sysTickHook(void)

that overrides the empty sysTickHook. If you return 0 the Arduino's handler is runned afterward, any other value instead prevents it from running (I don't know if this could be useful for something but its for free).



I understand that full preemptive RTOSs are not appropriate for most Arduino users but a few advanced users want the functionally of a full RTOS.


Until the changes needed are so small and doesn't affect anything, IMHO its worth trying. Of course, don't expect support for more advanced stuff about RTOS... from now on you're alone! ;)

(but I'm curious to see what you can do it :))
C.

Go Up