nrf_drv_wdt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright (c) 2014 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. * @addtogroup nrf_wdt WDT HAL and driver
  14. * @ingroup nrf_drivers
  15. * @brief Watchdog timer (WDT) APIs.
  16. * @details The WDT HAL provides basic APIs for accessing the registers of the watchdog timer.
  17. * The WDT driver provides APIs on a higher level.
  18. * @defgroup lib_driver_wdt WDT driver
  19. * @{
  20. * @ingroup nrf_wdt
  21. *
  22. * @brief Driver for managing the watchdog timer (WDT).
  23. */
  24. #ifndef NRF_DRV_WDT_H__
  25. #define NRF_DRV_WDT_H__
  26. #include <stdbool.h>
  27. #include <stdint.h>
  28. #include "sdk_errors.h"
  29. #include "nrf_wdt.h"
  30. #include "nrf_drv_config.h"
  31. /**@brief Struct for WDT initialization. */
  32. typedef struct
  33. {
  34. nrf_wdt_behaviour_t behaviour; /**< WDT behaviour when CPU in sleep/halt mode. */
  35. uint32_t reload_value; /**< WDT reload value in ms. */
  36. uint8_t interrupt_priority; /**< WDT interrupt priority */
  37. } nrf_drv_wdt_config_t;
  38. /**@brief WDT event handler function type. */
  39. typedef void (*nrf_wdt_event_handler_t)(void);
  40. /**@brief WDT channel id type. */
  41. typedef nrf_wdt_rr_register_t nrf_drv_wdt_channel_id;
  42. #define NRF_DRV_WDT_DEAFULT_CONFIG \
  43. { \
  44. .behaviour = WDT_CONFIG_BEHAVIOUR, \
  45. .reload_value = WDT_CONFIG_RELOAD_VALUE, \
  46. .interrupt_priority = WDT_CONFIG_IRQ_PRIORITY, \
  47. }
  48. /**
  49. * @brief This function initializes watchdog.
  50. *
  51. * @param[in] p_config Initial configuration. Default configuration used if NULL.
  52. * @param[in] wdt_event_handler specifies event handler provided by user.
  53. *
  54. * @note Function asserts if wdt_event_handler is NULL.
  55. *
  56. * @return NRF_SUCCESS on success, NRF_ERROR_INVALID_STATE if module ws already initialized.
  57. */
  58. ret_code_t nrf_drv_wdt_init(nrf_drv_wdt_config_t const * p_config,
  59. nrf_wdt_event_handler_t wdt_event_handler);
  60. /**
  61. * @brief This function allocate watchdog channel.
  62. *
  63. * @note This function can not be called after nrf_drv_wdt_start(void).
  64. *
  65. * @param[out] p_channel_id ID of granted channel.
  66. *
  67. * @return NRF_SUCCESS on success, otherwise an error code.
  68. */
  69. ret_code_t nrf_drv_wdt_channel_alloc(nrf_drv_wdt_channel_id * p_channel_id);
  70. /**
  71. * @brief This function starts watchdog.
  72. *
  73. * @note After calling this function the watchdog is started, so the user needs to feed all allocated
  74. * watchdog channels to avoid reset. At least one watchdog channel has to be allocated.
  75. */
  76. void nrf_drv_wdt_enable(void);
  77. /**
  78. * @brief This function feeds the watchdog.
  79. *
  80. * @details Function feeds all allocated watchdog channels.
  81. */
  82. void nrf_drv_wdt_feed(void);
  83. /**
  84. * @brief This function feeds the invidual watchdog channel.
  85. *
  86. * @param[in] channel_id ID of watchdog channel.
  87. */
  88. void nrf_drv_wdt_channel_feed(nrf_drv_wdt_channel_id channel_id);
  89. /**@brief Function for returning a requested task address for the wdt driver module.
  90. *
  91. * @param[in] task One of the peripheral tasks.
  92. *
  93. * @retval Task address.
  94. */
  95. __STATIC_INLINE uint32_t nrf_drv_wdt_ppi_task_addr(nrf_wdt_task_t task)
  96. {
  97. return nrf_wdt_task_address_get(task);
  98. }
  99. /**@brief Function for returning a requested event address for the wdt driver module.
  100. *
  101. * @param[in] event One of the peripheral events.
  102. *
  103. * @retval Event address
  104. */
  105. __STATIC_INLINE uint32_t nrf_drv_wdt_ppi_event_addr(nrf_wdt_event_t event)
  106. {
  107. return nrf_wdt_event_address_get(event);
  108. }
  109. #endif
  110. /** @} */