cagezero 0 Posted August 17, 2015 Share Posted August 17, 2015 I am working with a simplified version of the Galaxia_Task example. For some reason the rtosSetup() function does not seem to be firing. My code:TaskTest.ino #include "Energia.h" #include "rtosGlobals.h" void setup() { Serial.begin(115200); } void loop() { Serial.println("Hello from test loop"); delay(1000); } rtosGlobals.h #include "Energia.h" #include "Task.h" void functionTask(); Task myTask; void functionTask() { while(true) { Serial.println("hello from task"); delay(500); } } void rtosSetup() { myTask.begin(functionTask, Task_numPriorities - 1); } The only serial output I get is Quote Link to post Share on other sites
Rei Vilo 695 Posted August 18, 2015 Share Posted August 18, 2015 Welcome to the fascinating world of RTOS! Presently, rtosSetup() is an extension of the RTOS and hasn't been implemented yet in Energia MT. It's awaiting validation at the GitHub repository. See Main setup() for Energia MT #631. With Energia, copy-paste rtosGlobals.h into Second.ino, delete rtosGlobals.h, edit Second.ino and add the empty loop rtosLoop() will be called once at the beginning. Add Serial.begin(115200); to rtosSetup(). The Serial port needs to be initialised in each thread. void rtosSetup() { Serial.begin(115200); myTask.begin(functionTask, Task_numPriorities - 1); } void rtosLoop() { ; } You're sharing one single resource, the Serial port, between two clients. More over, delay(500); and delay(1000); are colliding. Try with delay(600); instead of delay(500);. hello from task hello from task Hello from test loop hello from task Hello from test loop hello from task hello from task Hello from test loop hello from task hello from task Hello from test loop Actually, you're losing the interest of the Task element. A simpler solution would be to skip myTask and use Second.ino with standard setup() and loop() functions. void rtosSetup() { Serial.begin(9600); } void rtosLoop() { Serial.println("hello from task"); delay(600); } However, the correct solution is to use a semaphore. The semaphore ensures the resource, here the Serial port, is used by only one client at a time. The semaphore grants an exclusive access at the resource to one client only at a time. See the Galaxia_Semaphore library and the associated example. As a matter of facts, I'm no longer using the Energia IDE but only the Energia framework on Xcode, thanks to the embedXcode plug-in I've developed. If you're a Mac user, give it a try! bluehash, adrianF, cagezero and 1 other 4 Quote Link to post Share on other sites
cagezero 0 Posted August 18, 2015 Author Share Posted August 18, 2015 Thank you Rei Vilo. Presently, rtosSetup() is an extension of the RTOS and hasn't been implemented yet in Energia MT. It's awaiting validation at the GitHub repository. See Main setup() for Energia MT #631. I was not aware that rtosSetup and rtosGlobals are not yet included. It is hard to use what is not there! Actually, you're losing the interest of the Task element. A simpler solution would be to skip myTask and use Second.ino with standard setup() and loop() functions. I could just create a second task (and have tested that) but I am looking for a thread that can be spawned by code, and rtos_Task seems to be the best option. My application will have at least one thread that needs to be kicked off and then die in under a minute. I really don Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.