Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #15 on: February 19, 2013, 11:16:22 am » |
fat16lib,
Got another question for you...
One of the functions (apps?) that I want to run on the RTOS is a web server. However, I think I read one of your posts that said the Ethernet lib isn't RTOS friendly. I can't find the post again but do I have that right?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #16 on: February 19, 2013, 01:04:11 pm » |
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: // 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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #17 on: February 20, 2013, 08:19:23 am » |
pito, I found my BMP085 and it seems to work with the Adafruit library by just changing Wire.h to TwiMaster.h. I noticed this call in your post: bmp.begin(I2C_100KHZ);
The argument should be a BMP085 mode, not an I2C speed. I don't know if that would make a difference. I tested on an Uno and a 2560 Mega using the Adafruit example sketch. I don't have a 1284.
|
|
|
|
|
Logged
|
|
|
|
|
Rapa Nui
Offline
God Member
Karma: 16
Posts: 885
Pukao hats cleaning services
|
 |
« Reply #18 on: February 20, 2013, 12:45:22 pm » |
The argument should be a BMP085 mode, not an I2C speed. I don't know if that would make a difference.
This is how I set up the bmp now: //#include <Wire.h> #include <TwiMaster.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 bmp; .. void setup() { Serial.begin(115200); bmp.begin(BMP085_ULTRAHIGHRES); ..
Still hangs at bmp.begin().. Enclosed the sketch you may try with ie Mega (you want to decrease the buffer size).
|
|
|
|
« Last Edit: February 20, 2013, 02:09:42 pm by pito »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #19 on: February 20, 2013, 02:23:35 pm » |
Strange! On an Uno this sketch: #include <TwiMaster.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 bmp;
void setup() { Serial.begin(115200); if (!bmp.begin(BMP085_ULTRAHIGHRES)) { Serial.println("bmp.begin failed"); while(1); } Serial.print("Altitude: "); Serial.println(bmp.readAltitude()); } void loop() {}
Prints: Altitude: 82.33
The only change to the library is this in Adafruit_BMP085.h: #include "TwiMaster.h" //#include "Wire.h"
|
|
|
|
« Last Edit: February 20, 2013, 02:25:40 pm by fat16lib »
|
Logged
|
|
|
|
|
Rapa Nui
Offline
God Member
Karma: 16
Posts: 885
Pukao hats cleaning services
|
 |
« Reply #20 on: February 20, 2013, 02:34:31 pm » |
With 1.5.1r2 and mighty 1284p: #include <TwiMaster.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 bmp;
void setup() { Serial.begin(115200); // if (!bmp.begin(BMP085_ULTRAHIGHRES)) { // Serial.println("bmp.begin failed"); // while(1); } bmp.begin(BMP085_ULTRAHIGHRES); Serial.print("Altitude: "); Serial.println(bmp.readAltitude(99500, 101350)); } void loop() {} Altitude: 155.14
With your original sketch I get errors during build.. PS: It seems my BMP lib is older one, with the latest I get with your original sketch: Altitude: 200.40
|
|
|
|
« Last Edit: February 20, 2013, 02:48:34 pm by pito »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #21 on: February 20, 2013, 02:38:52 pm » |
I understand the problem. TwiMaster uses a semaphore when linked with Nil RTOS so Nil RTOS must be started to do I2C I/O. Move bmp.begin() here: // Declare thread function for thread 1. NIL_THREAD(Thread1, arg) { bmp.begin(BMP085_HIGHRES); // Start timer 1 with a period of PERIOD_USEC. nilTimer1Start(PERIOD_USEC);
bmp.begin() does lots of I/O.
|
|
|
|
« Last Edit: February 20, 2013, 02:41:03 pm by fat16lib »
|
Logged
|
|
|
|
|
Rapa Nui
Offline
God Member
Karma: 16
Posts: 885
Pukao hats cleaning services
|
 |
« Reply #22 on: February 20, 2013, 02:56:23 pm » |
I understand the problem. TwiMaster uses a semaphore when linked with Nil RTOS so Nil RTOS must be started to do I2C I/O.
Move bmp.begin() here: Yep, it works now. Bmp stuff takes 22ms now (35ms with wire). A high time to replace _delay_ms() with chThdSleep() in the bmp driver.. Not easy, though.. 
|
|
|
|
« Last Edit: February 20, 2013, 03:10:00 pm by pito »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #23 on: February 20, 2013, 03:18:52 pm » |
I will put problems like these on my to-think-about list.
I am experimenting with using a weak symbol for delay. The weak symbol would use the standard Arduino delay.
When you link a library with an RTOS, the weak symbol would be replaced by the appropriate sleep or delay function in the RTOS.
This way you can have a single library and it will work with standard Arduino sketches or any RTOS that defines the override for the weak delay.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 21
|
 |
« Reply #24 on: March 07, 2013, 07:17:35 am » |
Is it possible to use the RTOS you have ported with Atmel Studio? If it is possible do you have any guide of how to do it? Or I just can copy the folder and place it in my project. What I want to do is use Arduino Due with Atmel Studio.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #25 on: March 07, 2013, 10:30:34 am » |
I think it would be better to use the unmodified versions of FreeRTOS or ChibiOS with Atmel Studio. Both of theses systems have AVR ports and examples.
I know FreeRTOS and Atmel are cooperating to make their products work together.
I really like ChibiOS/RT on Due. It is fast, takes a bit less memory than FreeRTOS but has more features.
Nill RTOS is great when you need minimal memory use and simple features are adequate.
Nil RTOS is experimental and not really supported yet by the author. I am personally supporting Nill RTOS mods for the Arduino core.
I assume you are not using the Arduino core software. My mods were to allow use of an RTOS with the Arduino core and Arduino libraries.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #26 on: March 14, 2013, 03:55:54 am » |
Hi, fat16lib,
Thanks a LOT for so useful contribution! I just come across your work. May I ask you few quick questions?
1) Which Arduino libraries known NOT to work with FreeRTOS, or have timing issues? 2) Which Arduino would you recommend to handle 3 step motors (at speed up to 2000 rpm), 2 rotary encoders and 2 magnetic hall sensors with any of RTOS? Probably Arduino Due is a minimum?
Thanks in advance for any suggestion(s).
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1077
Arduino rocks
|
 |
« Reply #27 on: March 14, 2013, 09:37:35 am » |
I don't have a list of libraries that don't work.
Any library that calls delay() or has a wait loop for something to complete will block all lower priority threads.
The ideal way to handle devices with an RTOS is to start an operation in a thread then wait on a semaphore. When the operation completes, an interrupt occurs and the device ISR signals with the semaphore to wake the waiting thread. This means many Arduino libraries need some mods for optimum performance.
The malloc() included with new versions of the Arduino IDE will not work in threads. This is O.K. since dynamic memory is not a good idea in real-time systems after setup.
FreeRTOS uses the most RAM and flash, ChibiOS/RT is smaller, faster, and has more features. Nil RTOS is the smallest but has few features and probably is not appropriate for your system.
Certainly Due is the minimum but I can't guess what you will need.
|
|
|
|
|
Logged
|
|
|
|
|
|