Go Down

Topic: project: simpleThreads only generated with macros and some global variables (Read 965 times) previous topic - next topic


I wrote a lib, that can be create simple Threads only with Makros.

The following functions are supported
sequence control:
* __simpleThread_START(thread_name):
* __simpleThread_STOP(thread_name):
* __simpleThread_RESET(thread_name):
* __simpleThread_RESTART(thread_name): reset + start
* __simpleThread_IS_RUNNING(thread_name): check if a therad is started
* __simpleThread_SET_DYN_TIME(thread_name, loop time in ms):  set new loop time, is only available when the thread is with
     __simpleThread_dyn initialized
* __simpleThread_GET_DYN_TIME(thread_name): get loop time, is only available when the thread is with __simpleThread_dyn initialized

* __simpleThread(thread_name, loop_time): create a new static thread with a name and a default loop time
* __simpleThread_dyn(thread_name, loop_time on start): create a new dynamic thread with a name and a default loop time
* __simpleThread_PTR(thread_name): containes the function pointer
* __simpleThread_LOOP(thread_name): thread loop, same feature as in the arduino software
* __simpleThread_SETUP(thread_name): thread setup, same feature as in the arduino software
* __simpleThread_IN_LOOP(): this macro must be called from the orginal arduino loop function

* - the lib contains only macros and one typedef
* - the first thread need about 300 byte flash memory, ever next need about 90 byte flash memory
* - threads can be controlled from other threads
* - a thread must be started befor it runs
* - the thread call is standardized
* - the ram use is as small as possible. Every static thread needs 4 byte and a few bits
* - few bits: for the first 1 - 8 threads 3 bytes are needed for the thread management. For the next 9 - 16 threads 3 new bytes are required
* - the dynamic threads needs 4 additional bytes ram for the unsigned long loop time value
* - the loop time from dynamic threads can be changed in the programm running
* - the loop to call the thread functions needs some bytes on ram, this value is ever the same

What do you think ?

I come from Germany and presented this lib already in the forum. A user said that it might be useful for arduino :: std :: Lib.
PS: Sorry for my "brocken" english, i hope you can read and understand it.

Update 13.05.2013
- add two examples:
--- example: blinking of two leds with different frequences (2 threads)
--- example: thread control with three threads, output over serial monitor


Thanks for sharing,

Can you give a small example sketch e.g. to blink two leds at a different frequency?

and no worries your English is fine!
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


i have updated the first thread. There are now two examples in the lib archiv:

- led blinking with two different frequenys on digital pin 12 and 13
- thread control with three threads and an output over serial monitor

Examples under:  File->examples->simpleThread->...  in arduino software

Go Up