Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multithreading using C on PIC18

How does one create threads that run in parallel while programming PIC18, since there is no OS?

like image 889
M3. Avatar asked Oct 26 '09 11:10

M3.


3 Answers

Don't use threads, use an event loop.

The PIC18 is a small processor and an event loop based style means you don't have to keep many deep stacks hanging around. You need to write your code in terms of the event loop, but that is probably reasonable.

If you do have some long running tasks, use timers are different interrupt priority levels to allow higher priority event loops to preempt lower priority event loops, and put appropriate types of work into the appropriate event queue.

like image 159
janm Avatar answered Sep 23 '22 21:09

janm


You could try Cooperative multitasking.

For types of problems that PICs solve, you'd probably be better of if you try a different design that uses interrupts or polling instead of multiple threads.

like image 21
Wernsey Avatar answered Sep 25 '22 21:09

Wernsey


You can put an RTOS on there (there's an unofficial ucOS port, or you could check out FreeRTOS's PIC18 port).

Otherwise, you could try implementing coroutines in C by using setjmp and longjmp.

like image 26
Mark Rushakoff Avatar answered Sep 25 '22 21:09

Mark Rushakoff