This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lab12 [2019/01/11 09:05] dan.tudose [The Event Timer] |
lab12 [2019/01/11 09:27] (current) dan.tudose [Processes] |
||
---|---|---|---|
Line 2: | Line 2: | ||
This tutorial will show how to make use of timers in Contiki. It will also give a basic into to events. | This tutorial will show how to make use of timers in Contiki. It will also give a basic into to events. | ||
- | Contiki provides 3 kind of timers: | ||
- | * Unordered List ItemSimple timer: The timer library provides functions for setting, resetting and restarting timers, and for checking if a timer has expired. An application must " | ||
- | * Unordered List ItemCallback timer: The callback timer library provides the same functions as above, but when the timer expires can callback a C function. | ||
- | * Unordered List ItemEvent timer: The same as above, with the difference that instead of calling a function, when the timer expires it post an event signalling the timer expiration. | ||
+ | ===== Processes ===== | ||
+ | |||
+ | All Contiki programs are processes. A process is a piece of code that is executed regularly by the Contiki system. Processes in Contiki are typically started when the system boots, or when a module that contains a process is loaded into the system. Processes run when something happens, such as a timer firing or an external event occurring. | ||
+ | |||
+ | Code in Contiki can run in one of two execution contexts: cooperative or preemptive. Code running in the cooperative execution context is run sequentially with respect to other code in the cooperative context. Cooperative code must run to completion before other cooperatively scheduled code can run. Preemptive code may stop the cooperative code at any time. When preemptive code stops the cooperative code, the cooperative code will not be resumed until the preemptive code has completed. The concept of Contiki' | ||
+ | |||
+ | Processes always run in the cooperative context. The preemptive context is used by interrupt handlers in device drivers and by real-time tasks that have been scheduled for a specific deadline. | ||
+ | |||
+ | An example process that receives events and prints out their number: | ||
+ | <code C> | ||
+ | # | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | { | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The complete reference on Contiki processes can be found [[https:// | ||
+ | |||
+ | Contiki provides three kinds of timers: | ||
+ | * **Simple timer:** The timer library provides functions for setting, resetting and restarting timers, and for checking if a timer has expired. An application must " | ||
+ | * **Callback timer:** The callback timer library provides the same functions as above, but when the timer expires can callback a C function. | ||
+ | * **Event timer:** The same as above, with the difference that instead of calling a function, when the timer expires it post an event signalling the timer expiration. | ||
+ | |||
+ | More information on timer can be found on the Contiki' | ||
===== The Event Timer ===== | ===== The Event Timer ===== | ||
Line 40: | Line 72: | ||
But when waiting for this event in this way -- all other events will be ignored so the first approach is more flexible as this will enable handling multiple types of events more easily. | But when waiting for this event in this way -- all other events will be ignored so the first approach is more flexible as this will enable handling multiple types of events more easily. | ||
- | < | + | < |
- | < | + | < |