Dependents: rtest LeonardoMbos OS_test Labo_TRSE_Drone ... more
Diff: mbos.h
- Revision:
- 4:e740e08cbea9
- Parent:
- 3:6cb5413f143f
--- a/mbos.h Sun Dec 05 13:36:15 2010 +0000 +++ b/mbos.h Mon Jan 31 03:39:39 2011 +0000 @@ -43,52 +43,59 @@ * * A typical simple example with two tasks, and one timer, might look like this: * @code - * #include "mbed.h" + * // mbos Blinky demonstration. + * // Task 1 toggles LED1 every second, under control of a timer. It then posts an event to + * // task 2 which flashed LED2 briefly. + * #include "mbed.h" * #include "mbos.h" * - * #define TASK1_ID 1 // defines to make the code more readable - * #define TASK1_PRIO 50 - * #define TASK1_STACK_SZ 32 - * #define TASK2_ID 2 - * #define TASK2_PRIO 60 - * #define TASK2_STACK_SZ 32 - * #define TIMER0_ID 0 - * #define TIMER0_PERIOD 1000 - * #define TIMER0_EVENT 1 - * #define T1_TO_T2_EVENT 2 + * #define TASK1_ID 1 // Id for task 1 (idle task is 0) + * #define TASK1_PRIO 50 // priority for task 1 + * #define TASK1_STACK_SZ 32 // stack size for task 1 in words + * #define TASK2_ID 2 // Id for task 2 + * #define TASK2_PRIO 60 // priority for task 2 + * #define TASK2_STACK_SZ 32 // stack size for task 2 in words + * #define TIMER0_ID 0 // Id for timer 0 + * #define TIMER0_PERIOD 1000 // Time period in milliseconds + * #define TIMER0_EVENT 1 // Event flag (1 << 0) + * #define T1_TO_T2_EVENT 2 // Event flag (1 << 1) * - * void task1(void); // task function prototypes + * void task1(void); // task function prototypes * void task2(void); * * DigitalOut led1(LED1); * DigitalOut led2(LED2); - * mbos os(2, 1); // 2 tasks, 1 timer + * mbos os(2, 1); // Instantiate mbos with 2 tasks & 1 timer * * int main(void) * { + * // Configure tasks and timers * os.CreateTask(TASK1_ID, TASK1_PRIO, TASK1_STACK_SZ, task1); * os.CreateTask(TASK2_ID, TASK2_PRIO, TASK2_STACK_SZ, task2); * os.CreateTimer(TIMER0_ID, TIMER0_EVENT, TASK1_ID); + * // Start mbos * os.Start(); - * // never get here! + * // never return! * } + * * void task1(void) * { * os.SetTimer(TIMER0_ID, TIMER0_PERIOD, TIMER0_PERIOD); * while(1){ - * os.WaitEvent(TIMER0_EVENT); - * led1 = !led1; - * os.SetEvent(T1_TO_T2_EVENT, TASK2_ID); - * } + * os.WaitEvent(TIMER0_EVENT); + * led1 = !led1; + * os.SetEvent(T1_TO_T2_EVENT, TASK2_ID); + * } * } + * * void task2(void) * { - * while(1){ - * os.WaitEvent(T1_TO_T2_EVENT); - * led2 = 1; - * wait_ms(100); - * led2 = 0; - * } + * while(1){ + * os.WaitEvent(T1_TO_T2_EVENT); + * led2 = 1; + * wait_ms(100); + * led2 = 0; + * } * } * @endcode */ @@ -110,7 +117,7 @@ * @param idlestacksize Size in words (>= 32) of the user-written idle task if present. * @returns Never returns */ - void Start(uint idlestacksize = 0); + void Start(uint idlestacksize = 32); /** Create an mbos task. Allocates and initialises data structures for the task. * @@ -183,6 +190,16 @@ * @param reload The optional time to reload into the timer when it times out. */ void SetTimer(uint timerid, uint time, uint reload = 0); + + /** Redirects an mbos timer. Changes the task and event associated with a timer. If the timer + * is running, the fun ction has no effect. + * + * @param timerid The ID of the timer. + * @param taskid The ID of the task to which the timer will post events. May not be + * the idle task. + * @param event The event flag(s) that the timer should post on timeout. May not be NULL. + */ + void RedirectTimer(uint timerid, uint taskid, uint event); /** Stops and clears an mbos timer. *