Pages: [1]   Go Down
Author Topic: RTOS hooks  (Read 2165 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

C.

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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! smiley-wink

(but I'm curious to see what you can do it smiley)
Logged

C.

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cmaglie,

Perfect!

I understand this may not be supported in the future or may change.

Soon after I get my Due, I will post a version of ChibiOS/RT and FreeRTOS for Due with a number of examples.

I also have a version of SdFat ready for testing.  I have optimized it for chips with large memory.

I wish there were fast native SPI functions for reading and writing blocks of memory on Due.  On Teensy 3.0 with 24 MHz native SPI I get file read and write rates over 2 MB/sec for large reads and writes.  Due should be even faster but I plan to use the official SPI library
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for access to systick, I can think of a couple of uses for that.

Now what happens if two people want to use it?

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now what happens if two people want to use it?

Good point, I guess they remains incompatible for now. smiley-wink

C
Logged

C.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a pin debounce function that I'd like to port to the Due and it needs access to SysTick. So the obvious problem is that if you use that you can't use anything else and vv.

In my LPC framework I allow up to 3 SysTick handlers and there's similar system to interrupts ie

Code:
attachEventHandler(EVENT_SYS_TICK0, debounceHandler);
attachEventHandler(EVENT_SYS_TICK1, someOtherHandler);
attachEventHandler(EVENT_SYS_TICK2, yetAnotherHandler);

Obviously it's up to the programmer to keep these very short.

______
Rob

Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 1
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I realize that this thread is a bit old, but I quickly tried getting this running today on 1.52 and wasn't having much luck.  I added the following code as a cpp file to my project:

Code:
#include <Arduino.h>

int count = 0;

int sysTickHook(void)
{
  count++;
  return 0;
}

It doesn't seem that this code is being called.  What am I missing?  Thanks for the help...
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I realize that this thread is a bit old, but I quickly tried getting this running today on 1.52 and wasn't having much luck.  I added the following code as a cpp file to my project:

Code:
#include <Arduino.h>

int count = 0;

int sysTickHook(void)
{
  count++;
  return 0;
}

It doesn't seem that this code is being called.  What am I missing?  Thanks for the help...

It needs to be in an extern "C" { ... } block, eg
Code:
extern "C" {
  int sysTickHook(void)
  {
    count++;
    return 0;
  }
}
Logged


Offline Offline
Newbie
*
Karma: 1
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It needs to be in an extern "C" { ... } block, eg
Code:
extern "C" {
  int sysTickHook(void)
  {
    count++;
    return 0;
  }
}

Yep, that did the trick.  Thanks for the quick reply...
Logged

Hannover, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank You stimmer, this was the information I needed also.
And Your contribution was the reason for me to register here.
Have a nice weekend.
Logged

Pages: [1]   Go Up
Jump to: