RtosTimer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (c) 2012 mbed.org */
  2. #ifndef TIMER_H
  3. #define TIMER_H
  4. #include <stdint.h>
  5. #include "cmsis_os.h"
  6. namespace rtos {
  7. /*! The RtosTimer class allow creating and and controlling of timer functions in the system.
  8. A timer function is called when a time period expires whereby both on-shot and
  9. periodic timers are possible. A timer can be started, restarted, or stopped.
  10. Timers are handled in the thread osTimerThread.
  11. Callback functions run under control of this thread and may use CMSIS-RTOS API calls.
  12. */
  13. class RtosTimer {
  14. public:
  15. /*! Create and Start timer.
  16. \param task name of the timer call back function.
  17. \param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
  18. \param argument argument to the timer call back function. (default: NULL)
  19. */
  20. RtosTimer(void (*task)(void const *argument),
  21. os_timer_type type=osTimerPeriodic,
  22. void *argument=NULL);
  23. /*! Stop the timer.
  24. \return status code that indicates the execution status of the function.
  25. */
  26. osStatus stop(void);
  27. /*! start a timer.
  28. \param millisec time delay value of the timer.
  29. \return status code that indicates the execution status of the function.
  30. */
  31. osStatus start(uint32_t millisec);
  32. private:
  33. osTimerId _timer_id;
  34. osTimerDef_t _timer;
  35. #ifdef CMSIS_OS_RTX
  36. uint32_t _timer_data[5];
  37. #endif
  38. };
  39. }
  40. #endif