RTOS lib used for Eurobot 2012
RtosTimer.h@1:b270f864114f, 2019-08-01 (annotated)
- Committer:
- eembed
- Date:
- Thu Aug 01 07:49:38 2019 +0000
- Revision:
- 1:b270f864114f
- Parent:
- 0:e477ba491a3b
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 0:e477ba491a3b | 1 | /* Copyright (c) 2012 mbed.org */ |
narshu | 0:e477ba491a3b | 2 | #ifndef TIMER_H |
narshu | 0:e477ba491a3b | 3 | #define TIMER_H |
narshu | 0:e477ba491a3b | 4 | |
narshu | 0:e477ba491a3b | 5 | #include <stdint.h> |
narshu | 0:e477ba491a3b | 6 | #include "cmsis_os.h" |
narshu | 0:e477ba491a3b | 7 | |
narshu | 0:e477ba491a3b | 8 | namespace rtos { |
narshu | 0:e477ba491a3b | 9 | |
narshu | 0:e477ba491a3b | 10 | /*! The RtosTimer class allow creating and and controlling of timer functions in the system. |
narshu | 0:e477ba491a3b | 11 | A timer function is called when a time period expires whereby both on-shot and |
narshu | 0:e477ba491a3b | 12 | periodic timers are possible. A timer can be started, restarted, or stopped. |
narshu | 0:e477ba491a3b | 13 | |
narshu | 0:e477ba491a3b | 14 | Timers are handled in the thread osTimerThread. |
narshu | 0:e477ba491a3b | 15 | Callback functions run under control of this thread and may use CMSIS-RTOS API calls. |
narshu | 0:e477ba491a3b | 16 | */ |
narshu | 0:e477ba491a3b | 17 | class RtosTimer { |
narshu | 0:e477ba491a3b | 18 | public: |
narshu | 0:e477ba491a3b | 19 | /*! Create and Start timer. |
narshu | 0:e477ba491a3b | 20 | \param task name of the timer call back function. |
narshu | 0:e477ba491a3b | 21 | \param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
narshu | 0:e477ba491a3b | 22 | \param argument argument to the timer call back function. (default: NULL) |
narshu | 0:e477ba491a3b | 23 | */ |
narshu | 0:e477ba491a3b | 24 | RtosTimer(void (*task)(void const *argument), |
narshu | 0:e477ba491a3b | 25 | os_timer_type type=osTimerPeriodic, |
narshu | 0:e477ba491a3b | 26 | void *argument=NULL); |
narshu | 0:e477ba491a3b | 27 | |
narshu | 0:e477ba491a3b | 28 | /*! Stop the timer. |
narshu | 0:e477ba491a3b | 29 | \return status code that indicates the execution status of the function. |
narshu | 0:e477ba491a3b | 30 | */ |
narshu | 0:e477ba491a3b | 31 | osStatus stop(void); |
narshu | 0:e477ba491a3b | 32 | |
narshu | 0:e477ba491a3b | 33 | /*! start a timer. |
narshu | 0:e477ba491a3b | 34 | \param millisec time delay value of the timer. |
narshu | 0:e477ba491a3b | 35 | \return status code that indicates the execution status of the function. |
narshu | 0:e477ba491a3b | 36 | */ |
narshu | 0:e477ba491a3b | 37 | osStatus start(uint32_t millisec); |
narshu | 0:e477ba491a3b | 38 | |
narshu | 0:e477ba491a3b | 39 | private: |
narshu | 0:e477ba491a3b | 40 | osTimerId _timer_id; |
narshu | 0:e477ba491a3b | 41 | osTimerDef_t _timer; |
narshu | 0:e477ba491a3b | 42 | #ifdef CMSIS_OS_RTX |
narshu | 0:e477ba491a3b | 43 | uint32_t _timer_data[5]; |
narshu | 0:e477ba491a3b | 44 | #endif |
narshu | 0:e477ba491a3b | 45 | }; |
narshu | 0:e477ba491a3b | 46 | |
narshu | 0:e477ba491a3b | 47 | } |
narshu | 0:e477ba491a3b | 48 | |
narshu | 0:e477ba491a3b | 49 | #endif |