Very simple cooperative round-robin task scheduler. See examples.
Examples/example1.h@1:f043501c4bed, 2011-03-04 (annotated)
- Committer:
- AjK
- Date:
- Fri Mar 04 12:15:38 2011 +0000
- Revision:
- 1:f043501c4bed
1.0 See ChangeLog.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 1:f043501c4bed | 1 | /* |
AjK | 1:f043501c4bed | 2 | Copyright (c) 2011 Andy Kirkham |
AjK | 1:f043501c4bed | 3 | |
AjK | 1:f043501c4bed | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
AjK | 1:f043501c4bed | 5 | of this software and associated documentation files (the "Software"), to deal |
AjK | 1:f043501c4bed | 6 | in the Software without restriction, including without limitation the rights |
AjK | 1:f043501c4bed | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
AjK | 1:f043501c4bed | 8 | copies of the Software, and to permit persons to whom the Software is |
AjK | 1:f043501c4bed | 9 | furnished to do so, subject to the following conditions: |
AjK | 1:f043501c4bed | 10 | |
AjK | 1:f043501c4bed | 11 | The above copyright notice and this permission notice shall be included in |
AjK | 1:f043501c4bed | 12 | all copies or substantial portions of the Software. |
AjK | 1:f043501c4bed | 13 | |
AjK | 1:f043501c4bed | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
AjK | 1:f043501c4bed | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
AjK | 1:f043501c4bed | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
AjK | 1:f043501c4bed | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
AjK | 1:f043501c4bed | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
AjK | 1:f043501c4bed | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
AjK | 1:f043501c4bed | 20 | THE SOFTWARE. |
AjK | 1:f043501c4bed | 21 | |
AjK | 1:f043501c4bed | 22 | @file example1.h |
AjK | 1:f043501c4bed | 23 | @purpose Simple round-robin cooperative scheduler example |
AjK | 1:f043501c4bed | 24 | @date Mar 2011 |
AjK | 1:f043501c4bed | 25 | @author Andy Kirkham |
AjK | 1:f043501c4bed | 26 | */ |
AjK | 1:f043501c4bed | 27 | |
AjK | 1:f043501c4bed | 28 | /* This example shows how to call tasks defined as C functions. */ |
AjK | 1:f043501c4bed | 29 | |
AjK | 1:f043501c4bed | 30 | #include "mbed.h" |
AjK | 1:f043501c4bed | 31 | #include "SimpleScheduler.h" |
AjK | 1:f043501c4bed | 32 | |
AjK | 1:f043501c4bed | 33 | DigitalOut led1(LED1); |
AjK | 1:f043501c4bed | 34 | DigitalOut led2(LED2); |
AjK | 1:f043501c4bed | 35 | DigitalOut led3(LED3); |
AjK | 1:f043501c4bed | 36 | DigitalOut led4(LED4); |
AjK | 1:f043501c4bed | 37 | |
AjK | 1:f043501c4bed | 38 | void f1(SimpleTask *task) { led1 = !led1; } |
AjK | 1:f043501c4bed | 39 | void f2(SimpleTask *task) { led2 = !led2; } |
AjK | 1:f043501c4bed | 40 | void f3(SimpleTask *task) { led3 = !led3; } |
AjK | 1:f043501c4bed | 41 | void f4(SimpleTask *task) { led4 = !led4; } |
AjK | 1:f043501c4bed | 42 | |
AjK | 1:f043501c4bed | 43 | SimpleScheduler *scheduler; |
AjK | 1:f043501c4bed | 44 | |
AjK | 1:f043501c4bed | 45 | int main() { |
AjK | 1:f043501c4bed | 46 | |
AjK | 1:f043501c4bed | 47 | scheduler = new SimpleScheduler; |
AjK | 1:f043501c4bed | 48 | |
AjK | 1:f043501c4bed | 49 | scheduler |
AjK | 1:f043501c4bed | 50 | ->addTask( new SimpleTask(0, f1) ) |
AjK | 1:f043501c4bed | 51 | ->addTask( new SimpleTask(200, f2) ) |
AjK | 1:f043501c4bed | 52 | ->addTask( new SimpleTask(300, f3) ) |
AjK | 1:f043501c4bed | 53 | ->addTask( new SimpleTask(0.4, f4) ) |
AjK | 1:f043501c4bed | 54 | ; |
AjK | 1:f043501c4bed | 55 | |
AjK | 1:f043501c4bed | 56 | scheduler->run(); |
AjK | 1:f043501c4bed | 57 | } |