Go Down

Topic: Updated versions of ChibiOS/RT, NilRTOS, and FreeRTOS (Read 14827 times) previous topic - next topic

LinuxGuru


vTaskStartScheduler() never returns.  Please see the FreeRTOS documentation for details of API functions.

Here is a link to vTaskStartScheduler() http://www.freertos.org/a00132.html.


I meant task themselves are not executed, call of vTaskStartScheduler() hangs Due.

fat16lib

I suspect one of your tasks crashes the system when it returns.

You should read the FreeRTOS documentation for task structure.  Here is a link http://www.freertos.org/implementing-a-FreeRTOS-task.html.

Here is a quote from the documentation for xTaskCreate():
Quote

pvTaskCode    Pointer to the task entry function. Tasks must be implemented to never return (i.e. continuous loop).


Here is a link to more details http://www.freertos.org/a00125.html.

LinuxGuru


I suspect one of your tasks crashes the system when it returns.


Bingo ! One of my tasks really exited from the loop.
Another thing - I had to increase stack size to 2048.

Thanks a lot, fat16lib !

LinuxGuru

From the html manual:
On ARM Due you must connect pin 2 to pin 3

Is it necessary only for attachInterrupt() examples?

LinuxGuru

With help of fat16lib, I loaded Due with damn simple simple program which controls bipolar step motor and scrolls text on TM1638 LED (with TM1638 library).
Looks like FreeRTOS have very high latency on Due or I'm being missing something.

1) I can't get step motor running with speed over 75 rpm, even with smooth long-time acceleration. This is certainly problem related to FreeRTOS, since without FreeRTOS I can get much faster speed from the same motor.

2) Scrolling text on TM1638 LED (running as separate task) creates audible ticks and vibration (with frequency equal to scroll text speed) on running step motor. Bypassing scroll code in this task removed problem with ticking step motor.

Step motor have priority 1, scrolling text - 2.

-------------------------------------------------------------------------

// Motor run code:
while (1) {
   digitalWrite(MOTORCLK, HIGH);
   vTaskDelayUntil(&xLastWakeTime, xTargetFreq / 2);
   digitalWrite(MOTORCLK, LOW);
   vTaskDelayUntil(&xLastWakeTime, xTargetFreq / 2);
};

-------------------------------------------------------------------------

// TM1638 scroll function
static void vNumericLED(void *pvParameters)
{
  portTickType xLastWakeTime = xTaskGetTickCount();
 
   while (1) {
 
     for (int i = 0; i < MODULES; i++) {
       const char* pos = string + base + (i * 8);
 
       if (pos >= string && pos + 8 < string + sizeof(string)) {
         modules.setDisplayToString(pos);
       } else {
         modules.clearDisplay();
       }
     }
 
   base++;
 
   if (base == sizeof(string) - 8) {
     base = -MODULES * 8;
   }
   
   vTaskDelayUntil(&xLastWakeTime, (1000 / portTICK_RATE_MS) / 2);
 };
}

-------------------------------------------------------------------------

Should I try ChibliOS, NilRTOS, or I just did something wrong with FreeRTOS on Due?

fat16lib

Quote

Looks like FreeRTOS have very high latency on Due or I'm being missing something.

FreeRTOS has very fast context switch time on Due.  ChibiOS is a bit faster but I don't think this is your problem.  ChibiOS is in the one microsecond range and FreeRTOS is under two microseconds on Due.

Quote

Step motor have priority 1, scrolling text - 2.

So why run the step motor task at lower priority than the display?  Read about task priorities here http://www.freertos.org/RTOS-task-priority.html.

Quote
Scrolling text on TM1638 LED (running as separate task) creates audible ticks and vibration (with frequency equal to scroll text speed) on running step motor. Bypassing scroll code in this task removed problem with ticking step motor.
This is the result of running the scroll task at higher priority.   The RTOS is doing what you asked it to do, give the scrolling highest priority.

G'day,

Is there likely to be a working Ethernet Library for Chibios by any chance? What would be required to get one working. I think the next evolution for Arduino is multitasking.... it can then find a good commercial footing and an OS like CHibios might be the key as opposed to using FreeRTOS with its overheads...

Sid




I don't recall a post about the Ethernet library. 

Many Arduino libraries are not RTOS friendly but that doesn't mean you can't use them.

Here is an example from the Ethernet library:
Code: [Select]

    // Wait for a response packet
    while(iUdp.parsePacket() <= 0)
    {
        if((millis() - startTime) > aTimeout)
            return TIMED_OUT;
        delay(50);
    }


This loop has a delay(50) call that will block lower priority threads.  If the delay were replaced by a chThdSleep(50) call, lower priority threads could use the CPU time.

I think a web server is an ideal candidate for RTOS use.  I would love to have a well designed web server as an example.

I hope to write a "How To" for making minimal changes to libraries that will improve their performance with an RTOS.
Sid Young
http://z900collector.wordpress.com/coding/

#37
Jan 29, 2014, 04:11 am Last Edit: Jan 29, 2014, 07:48 am by dgriffith Reason: 1
Hi All,

I'm currently building an little app with four threads using NilRTOS and using ethernet.
Lots of blocking with one thread whilst using the network, so I had a look at the ethernet library and straight away, the W5100:Class::init has a 300 millisecond delay in it. After a bit of fiddling I took fat16lib's cue and altered it to use nilThdSleepMilliseconds() instead of delay() - all good. Except for the now non-portable ethernet library - it doesn't work if you don't include the NilRTOS headers at the top of the library..... including them at the top of your sketch doesn't work, even if the Ethernet library is included further down.

So after some more fiddling about, here's a few steps for the not-everyday-programmers  :P to do it in a more transparent fashion:
Put your
Code: [Select]
#include <NilRTOS.h> that you have at the top of your sketch into a new header file (made by pressing the 'new' button with your existing sketch open. I had one already as I defined a few types for passing data back and forth.)
Include this new file in your sketch at the top eg. #include "MyTypes.h" - note the " instead of the <>

Open up your library .cpp file (under \Libraries\ in your arduino program directory) with notepad or your favorite C editor and poke about in it. Maybe save a backup copy somewhere  :)

Everywhere you see a delay() in your library put something like:
Code: [Select]
// make it a little bit more friendly to NilRTOS.
#if defined(__NIL__)
  nilThdSleepMilliseconds(300);
#elseif
  delay(300);
#endif


When this is compiled, if __NIL__ is defined (as it is in NilRTOS.h), the NilRTOS library is there and you can use it's functions, otherwise the library will just use the normal delay and all your 'normal'' sketches will run as-is.

This makes threading much nicer with the Ethernet library.... I might go through the LCD one as well as there are delays liberally sprinkled through it.

Hope this helps, and if anyone knows the 'right' way to do this, let me know  :P

gallegojm

I plan to modify my ftp server ( http://forum.arduino.cc/index.php?topic=182382.0 ) so it works under one of the rtos ChibiOS/RT, NilRTOS or FreeRTOS.
The server make use of libraries SdFat and Ethernet.
After reading different posts on the blog, I have some questions:
- Does one of this os allows me to use simultaneously two (or more) devices accessed through SPI?
- Would it be possible to have two thread, one reading a file, an other creating and writing to file, working simultaneously?
- Witch of this os would be the most adapted?
I understand, after searching the forum, than I should make some changes in the libraries, such as removing the calls to the delay() function, but I think the effort is worth it.

Rensen

I'm trying to use malloc from within a task, but with no luck.. Both malloc and new returns NULL when i try to allocate memory for an object. I'm using an Arduino mega, and i only have one simple task, so i don't think that i run out of memory, what could it be? Does NilRTOS support heap allocation?

Go Up