timer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2013 Semtech
  8. Description: Timer objects and scheduling management
  9. License: Revised BSD License, see LICENSE.TXT file include in the project
  10. Maintainer: Miguel Luis and Gregory Cristian
  11. */
  12. #ifndef __TIMER_H__
  13. #define __TIMER_H__
  14. /*!
  15. * \brief Timer object description
  16. */
  17. typedef struct TimerEvent_s
  18. {
  19. uint32_t Timestamp; //! Current timer value
  20. uint32_t ReloadValue; //! Timer delay value
  21. bool IsRunning; //! Is the timer currently running
  22. void ( *Callback )( void ); //! Timer IRQ callback function
  23. struct TimerEvent_s *Next; //! Pointer to the next Timer object.
  24. }TimerEvent_t;
  25. /*!
  26. * \brief Timer time variable definition
  27. */
  28. #ifndef TimerTime_t
  29. typedef uint64_t TimerTime_t;
  30. #endif
  31. /*!
  32. * \brief Enables/Disables low power timers usage
  33. *
  34. * \param [IN] enable [true]RTC timer used, [false]Normal timer used
  35. */
  36. void TimerSetLowPowerEnable( bool enable );
  37. /*!
  38. * \brief Initializes the timer object
  39. *
  40. * \retval enable [true]RTC timer used, [false]Normal timer used
  41. */
  42. bool TimerGetLowPowerEnable( void );
  43. /*!
  44. * \brief Initializes the timer object
  45. *
  46. * \remark TimerSetValue function must be called before starting the timer.
  47. * this function initializes timestamp and reload value at 0.
  48. *
  49. * \param [IN] obj Structure containing the timer object parameters
  50. * \param [IN] callback Function callback called at the end of the timeout
  51. */
  52. void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) );
  53. /*!
  54. * Timer IRQ event handler
  55. */
  56. void TimerIrqHandler( void );
  57. /*!
  58. * \brief Starts and adds the timer object to the list of timer events
  59. *
  60. * \param [IN] obj Structure containing the timer object parameters
  61. */
  62. void TimerStart( TimerEvent_t *obj );
  63. /*!
  64. * \brief Stops and removes the timer object from the list of timer events
  65. *
  66. * \param [IN] obj Structure containing the timer object parameters
  67. */
  68. void TimerStop( TimerEvent_t *obj );
  69. /*!
  70. * \brief Resets the timer object
  71. *
  72. * \param [IN] obj Structure containing the timer object parameters
  73. */
  74. void TimerReset( TimerEvent_t *obj );
  75. /*!
  76. * \brief Set timer new timeout value
  77. *
  78. * \param [IN] obj Structure containing the timer object parameters
  79. * \param [IN] value New timer timeout value
  80. */
  81. void TimerSetValue( TimerEvent_t *obj, uint32_t value );
  82. /*!
  83. * \brief Read the current time
  84. *
  85. * \retval time returns current time
  86. */
  87. TimerTime_t TimerGetCurrentTime( void );
  88. /*!
  89. * \brief Manages the entry into ARM cortex deep-sleep mode
  90. */
  91. void TimerLowPowerHandler( void );
  92. #endif // __TIMER_H__