app_simple_timer.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /**@file
  13. *
  14. * @defgroup lib_driver_simple_timer Simple Timer
  15. * @{
  16. * @ingroup app_common
  17. *
  18. * @brief Simple timer module.
  19. *
  20. * Supported features and limitations:
  21. * - Two modes: single shot mode and repeated mode.
  22. * - No more than one timer can run simultaneously.
  23. * - The timer is hard-coded to use the TIMER1 peripheral and compare channel 0.
  24. */
  25. #ifndef TIMER_H__
  26. #define TIMER_H__
  27. #include <stdint.h>
  28. /**@brief Timer time-out handler type. */
  29. typedef void (*app_simple_timer_timeout_handler_t)(void * p_context);
  30. /**@brief Timer modes. */
  31. typedef enum
  32. {
  33. APP_SIMPLE_TIMER_MODE_SINGLE_SHOT, /**< The timer will expire only once. */
  34. APP_SIMPLE_TIMER_MODE_REPEATED /**< The timer will restart each time it expires. */
  35. } app_simple_timer_mode_t;
  36. /**@brief Function for configuring and setting up the timer hardware.
  37. *
  38. * @note Configuration parameters should be set in nrf_drv_config.h file.
  39. * The TIMER1_CONFIG_MODE has to be set to NRF_TIMER_MODE_TIMER value.
  40. * The TIMER1_CONFIG_BIT_WIDTH has to be set to NRF_TIMER_BIT_WIDTH_16 value.
  41. *
  42. * @retval NRF_SUCCESS If the operation is successful.
  43. * @retval NRF_ERROR_INVALID_STATE If the operation fails because the timer is already initialized.
  44. * @retval NRF_ERROR_INVALID_PARAM If the operation fails because some configuration parameter is
  45. * not valid.
  46. */
  47. uint32_t app_simple_timer_init(void);
  48. /**@brief Function for starting a timer.
  49. *
  50. * @note If this function is called for a timer that is already running, the currently running
  51. * timer is stopped before starting the new one.
  52. *
  53. * @param[in] mode Timer mode (see @ref app_simple_timer_mode_t).
  54. * @param[in] timeout_handler Function to be executed when the timer expires
  55. * (see @ref app_simple_timer_timeout_handler_t).
  56. * @param[in] timeout_ticks Number of timer ticks to time-out event.
  57. * @param[in] p_context General purpose pointer. Will be passed to the time-out handler
  58. * when the timer expires.
  59. *
  60. * @retval NRF_SUCCESS If the operation is successful.
  61. * @retval NRF_ERROR_INVALID_STATE If the operation fails because @ref app_simple_timer_init has not
  62. * been called and the operation is not allowed in this state.
  63. * @retval NRF_ERROR_NULL If the operation fails because timeout_handler is NULL.
  64. * @retval NRF_ERROR_INVALID_PARAM If the operation fails because "mode" parameter is not valid.
  65. */
  66. uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
  67. app_simple_timer_timeout_handler_t timeout_handler,
  68. uint16_t timeout_ticks,
  69. void * p_context);
  70. /**@brief Function for stopping the timer.
  71. *
  72. * @retval NRF_SUCCESS If the operation is successful.
  73. */
  74. uint32_t app_simple_timer_stop(void);
  75. /**@brief Function for uninitializing the timer. Should be called also when the timer is not used
  76. * anymore to reach lowest power consumption in system.
  77. *
  78. * @note The function switches off the internal core of the timer to reach lowest power consumption
  79. * in system. The startup time from this state may be longer compared to starting the timer
  80. * from the stopped state.
  81. *
  82. * @retval NRF_SUCCESS If the operation is successful.
  83. */
  84. uint32_t app_simple_timer_uninit(void);
  85. #endif // TIMER_H__
  86. /** @} */