Embedded Systems Design Europe - May 2008 - (Page 15) cover feature Listing 1 How processTick() could be implemented. loop through the table of tasks if (cooperative_Tasks[i].expires == 0) { cooperative_Tasks[i].ready++; /* schedule the task for execution */ if (cooperative_Tasks[i].reload) /* reload the timer */ cooperative_Tasks[i].expires = cooperative_Tasks[i].reload; else cooperative_Tasks[i].expires = -1; } else if (cooperative_Tasks[i].expires > 0) cooperative_Tasks[i].expires--; that only needs to be compiled with the new target compiler in order to run? Recently, while taking a real-time operating systems class at Metro State University in St. Paul, I learned about a cooperative scheduler based on work from Michael J. Pont (author of Patterns for Time-Triggered Embedded Systems) in which tasks can be created and executed at different priorities. An implementation of this scheduler produces an extremely small cooperative operating system, which is also very easy to port: an instant-up operating system (IOS #1). About the same time, I was also introduced to Protothreads, written by Adam Dunkels. To quote from the website, “Protothreads are extremely lightweight stackless threads . . . .” They are written in C and “provide linear code execution for event-driven systems.” Protothreads are a collection of C macros that give a simple way to have multiple threads running completely in C. There are no worries about stack allocations or context switching, since the compiler does the heavy lifting. Protothreads provides a method to create threads that seemingly don’t run to completion and give virtual concurrency. Protothreads, of course, don’t give true concurrency, but threads can be organized as though they do. And Protothreads is easy to port. Voila! IOS #2. Discovery of Protothreads got me wondering: what would happen if it were blended with a cooperative scheduler? Would this result in IOS #3, merging the virtual concurrency of Protothreads with the scheduling provided by the cooperative scheduler? I found that porting either of them is easy. Indeed, in the case of the cooperative scheduler, only a regular “tick” or timeout is required. COOPERATIVE SCHEDULERS A cooperative scheduler works on a very simple concept. Given a tick or other delay mechanism, tasks are scheduled and executed at assigned times. In our example, the scheduler maintains a table of tasks, and, as each tick occurs, the expiration times for each task are decremented. When a task’s timer expires, the task is scheduled for execution and the timer is reloaded with the reload value given during task creation. The task control structure for the example cooperative scheduler is simple. It contains a function pointer to a task and a parameter to be passed to the function when called. It also contains data regarding when the task expiration timer and reload value expire. typedef struct { int (*pTask) (void * data); void * param; int ready; int valid; int expires; int reload; int handle; } cooperativeTask_t; A task is created using the function createTask, which loads the function pointer of the task and the data pointer into the task control structure. An initial expire time and reload value are loaded as well. Note that expire and reload times are based on ticks. int cooperative_createTask (int (*pFunction) (void * data), void * data, int expires, int reload) Some type of timer or interrupt service routine (ISR) is necessary to execute the processTick() function on a regular basis. This step gives developers flexibility to test and simulate their implementation on a desktop. Listing 1 shows how processTick() could be implemented. The processTasks() function simply checks which tasks are scheduled, have expired, executes the tasks’ functions, and deletes any task with no programmed reload value. It’s even possible to have a task execute one time and be deleted. Listing 2 is an example of how processTasks() might be implemented. To tie everything together, a main loop is required. If the timer tick is not handled in an ISR, a simple main loop can be implemented as shown below. If a tick ISR is used, the main loop would simply have a processTasks() call. while (1) { usleep (100); cooperative_processTick (); cooperative_processTasks (); } 15 A tasksConstructor needs to be called first; it simply clears the data for all possible tasks and prepares for new tasks to be created. cooperative_tasksConstructor (); www.embedded.com/europe | embedded systems design europe | MAY 2008 http://www.embedded.com/europe
Table of Contents Feed for the Digital Edition of Embedded Systems Design Europe - May 2008 Embedded Systems Design Europe - May 2008 Contents Microsoft Provides Embedded Roadmap Enea Buys Developers Irish Start-Up Raises Funds for Telecom FPGAs Kontron Promotes COM Express Nano Mentor Nucleus Platform Provides UI for Atmel Small Form Factor Boards Head for the SUMIT Proffibus Advances IO-Link Integration Embedded Developers Cautious on Multicore Auto Cooperation Improves Test Altera Launches DO-254 Partner Network Building an ‘Instant-Up’ Real-Time Operating Systems An Architecture for Reusable Embedded Systems Software Free up Bandwidth in PCI Express Evaluating Software in Medical Devices Circuit Sensitivity in Analog Circuits Choosing Flash Memory New Products Advertising Contacts Embedded Systems Design Europe - May 2008 Embedded Systems Design Europe - May 2008 - Embedded Systems Design Europe - May 2008 (Page 1) Embedded Systems Design Europe - May 2008 - Embedded Systems Design Europe - May 2008 (Page 2) Embedded Systems Design Europe - May 2008 - Contents (Page 3) Embedded Systems Design Europe - May 2008 - Contents (Page 4) Embedded Systems Design Europe - May 2008 - Contents (Page 5) Embedded Systems Design Europe - May 2008 - Microsoft Provides Embedded Roadmap (Page 6) Embedded Systems Design Europe - May 2008 - Microsoft Provides Embedded Roadmap (Page 7) Embedded Systems Design Europe - May 2008 - Irish Start-Up Raises Funds for Telecom FPGAs (Page 8) Embedded Systems Design Europe - May 2008 - Irish Start-Up Raises Funds for Telecom FPGAs (Page 9) Embedded Systems Design Europe - May 2008 - Mentor Nucleus Platform Provides UI for Atmel (Page 10) Embedded Systems Design Europe - May 2008 - Mentor Nucleus Platform Provides UI for Atmel (Page 11) Embedded Systems Design Europe - May 2008 - Proffibus Advances IO-Link Integration (Page 12) Embedded Systems Design Europe - May 2008 - Altera Launches DO-254 Partner Network (Page 13) Embedded Systems Design Europe - May 2008 - Building an ‘Instant-Up’ Real-Time Operating Systems (Page 14) Embedded Systems Design Europe - May 2008 - Building an ‘Instant-Up’ Real-Time Operating Systems (Page 15) Embedded Systems Design Europe - May 2008 - Building an ‘Instant-Up’ Real-Time Operating Systems (Page 16) Embedded Systems Design Europe - May 2008 - Building an ‘Instant-Up’ Real-Time Operating Systems (Page 17) Embedded Systems Design Europe - May 2008 - An Architecture for Reusable Embedded Systems Software (Page 18) Embedded Systems Design Europe - May 2008 - An Architecture for Reusable Embedded Systems Software (Page 19) Embedded Systems Design Europe - May 2008 - An Architecture for Reusable Embedded Systems Software (Page 20) Embedded Systems Design Europe - May 2008 - An Architecture for Reusable Embedded Systems Software (Page 21) Embedded Systems Design Europe - May 2008 - Free up Bandwidth in PCI Express (Page 22) Embedded Systems Design Europe - May 2008 - Free up Bandwidth in PCI Express (Page 23) Embedded Systems Design Europe - May 2008 - Free up Bandwidth in PCI Express (Page 24) Embedded Systems Design Europe - May 2008 - Free up Bandwidth in PCI Express (Page 25) Embedded Systems Design Europe - May 2008 - Evaluating Software in Medical Devices (Page 26) Embedded Systems Design Europe - May 2008 - Evaluating Software in Medical Devices (Page 27) Embedded Systems Design Europe - May 2008 - Evaluating Software in Medical Devices (Page 28) Embedded Systems Design Europe - May 2008 - Evaluating Software in Medical Devices (Page 29) Embedded Systems Design Europe - May 2008 - Circuit Sensitivity in Analog Circuits (Page 30) Embedded Systems Design Europe - May 2008 - Circuit Sensitivity in Analog Circuits (Page 31) Embedded Systems Design Europe - May 2008 - Circuit Sensitivity in Analog Circuits (Page 32) Embedded Systems Design Europe - May 2008 - Circuit Sensitivity in Analog Circuits (Page 33) Embedded Systems Design Europe - May 2008 - Circuit Sensitivity in Analog Circuits (Page 34) Embedded Systems Design Europe - May 2008 - Circuit Sensitivity in Analog Circuits (Page 35) Embedded Systems Design Europe - May 2008 - Choosing Flash Memory (Page 36) Embedded Systems Design Europe - May 2008 - Choosing Flash Memory (Page 37) Embedded Systems Design Europe - May 2008 - Choosing Flash Memory (Page 38) Embedded Systems Design Europe - May 2008 - Choosing Flash Memory (Page 39) Embedded Systems Design Europe - May 2008 - New Products (Page 40) Embedded Systems Design Europe - May 2008 - New Products (Page 41) Embedded Systems Design Europe - May 2008 - New Products (Page 42) Embedded Systems Design Europe - May 2008 - Advertising Contacts (Page 43) Embedded Systems Design Europe - May 2008 - Advertising Contacts (Page 44)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.