Some years ago I found a document by Simon Tatham with a coroutine.h source conaining a set C macros to make cooperative routines.
http://www.chiark.greenend.org.uk/~sgta ... tines.html
I became a fan of those macros that let you make a sort of multi tasking. No need to waste precious real time deterministic xcore threads to run low priority tasks.
Very smart the way Duff's device is used.
Also I suggest a reading at protothread:
http://dunkels.com/adam/pt/about.html
Coroutines: a "must know" for programmers (according to me)
-
- Active Member
- Posts: 52
- Joined: Mon Oct 31, 2011 4:08 pm
-
- XCore Expert
- Posts: 589
- Joined: Wed Feb 29, 2012 10:03 am
Thank you for sharing the information. Hopefully, the other members in the community also find the information useful.
Sethu.
Sethu.
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
These routines store all state globally, there can be only
one instance running consecutively; these aren't coroutines.
You could pass in a pointer to a struct to store the state in,
destroying all the neat syntactic sugar: but that does show
what you really have, namely an explicit state machine.
Don't the latest XC additions support cooperative threading
btw? I haven't more than glanced at it I'm afraid :-(
one instance running consecutively; these aren't coroutines.
You could pass in a pointer to a struct to store the state in,
destroying all the neat syntactic sugar: but that does show
what you really have, namely an explicit state machine.
Don't the latest XC additions support cooperative threading
btw? I haven't more than glanced at it I'm afraid :-(
-
- Experienced Member
- Posts: 111
- Joined: Sun Mar 06, 2011 11:39 pm
Very interesting stuff Lele.
I think the XC addition segher mentioned is combinable functions. I haven't used that feature yet either, but it does sound similar to the information Lele linked to.
I think the XC addition segher mentioned is combinable functions. I haven't used that feature yet either, but it does sound similar to the information Lele linked to.
-
- Active Member
- Posts: 52
- Joined: Mon Oct 31, 2011 4:08 pm
Segher is right: the first set of macro is not for reentrant/recursive functions.
But there is also a set which stores local variables
But there is also a set which stores local variables