em_wdog.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Watchdog (WDOG) peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #ifndef __EM_WDOG_H
  34. #define __EM_WDOG_H
  35. #include <stdbool.h>
  36. #include "em_part.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /***************************************************************************//**
  41. * @addtogroup EM_Library
  42. * @{
  43. ******************************************************************************/
  44. /***************************************************************************//**
  45. * @addtogroup WDOG
  46. * @{
  47. ******************************************************************************/
  48. /*******************************************************************************
  49. ******************************** ENUMS ************************************
  50. ******************************************************************************/
  51. /** Watchdog clock selection. */
  52. typedef enum
  53. {
  54. wdogClkSelULFRCO = _WDOG_CTRL_CLKSEL_ULFRCO, /**< Ultra low frequency (1 kHz) clock */
  55. wdogClkSelLFRCO = _WDOG_CTRL_CLKSEL_LFRCO, /**< Low frequency RC oscillator */
  56. wdogClkSelLFXO = _WDOG_CTRL_CLKSEL_LFXO /**< Low frequency crystal oscillator */
  57. } WDOG_ClkSel_TypeDef;
  58. /** Watchdog period selection. */
  59. typedef enum
  60. {
  61. wdogPeriod_9 = 0x0, /**< 9 clock periods */
  62. wdogPeriod_17 = 0x1, /**< 17 clock periods */
  63. wdogPeriod_33 = 0x2, /**< 33 clock periods */
  64. wdogPeriod_65 = 0x3, /**< 65 clock periods */
  65. wdogPeriod_129 = 0x4, /**< 129 clock periods */
  66. wdogPeriod_257 = 0x5, /**< 257 clock periods */
  67. wdogPeriod_513 = 0x6, /**< 513 clock periods */
  68. wdogPeriod_1k = 0x7, /**< 1025 clock periods */
  69. wdogPeriod_2k = 0x8, /**< 2049 clock periods */
  70. wdogPeriod_4k = 0x9, /**< 4097 clock periods */
  71. wdogPeriod_8k = 0xA, /**< 8193 clock periods */
  72. wdogPeriod_16k = 0xB, /**< 16385 clock periods */
  73. wdogPeriod_32k = 0xC, /**< 32769 clock periods */
  74. wdogPeriod_64k = 0xD, /**< 65537 clock periods */
  75. wdogPeriod_128k = 0xE, /**< 131073 clock periods */
  76. wdogPeriod_256k = 0xF /**< 262145 clock periods */
  77. } WDOG_PeriodSel_TypeDef;
  78. /*******************************************************************************
  79. ******************************* STRUCTS ***********************************
  80. ******************************************************************************/
  81. /** Watchdog initialization structure. */
  82. typedef struct
  83. {
  84. /** Enable watchdog when init completed. */
  85. bool enable;
  86. /** Counter shall keep running during debug halt. */
  87. bool debugRun;
  88. /** Counter shall keep running when in EM2. */
  89. bool em2Run;
  90. /** Counter shall keep running when in EM3. */
  91. bool em3Run;
  92. /** Block EMU from entering EM4. */
  93. bool em4Block;
  94. /** Block SW from disabling LFRCO/LFXO oscillators. */
  95. bool swoscBlock;
  96. /** Block SW from modifying the configuration (a reset is needed to reconfigure). */
  97. bool lock;
  98. /** Clock source to use for watchdog. */
  99. WDOG_ClkSel_TypeDef clkSel;
  100. /** Watchdog timeout period. */
  101. WDOG_PeriodSel_TypeDef perSel;
  102. } WDOG_Init_TypeDef;
  103. /** Suggested default config for WDOG init structure. */
  104. #define WDOG_INIT_DEFAULT \
  105. { true, /* Start watchdog when init done */ \
  106. false, /* WDOG not counting during debug halt */ \
  107. false, /* WDOG not counting when in EM2 */ \
  108. false, /* WDOG not counting when in EM3 */ \
  109. false, /* EM4 can be entered */ \
  110. false, /* Do not block disabling LFRCO/LFXO in CMU */ \
  111. false, /* Do not lock WDOG configuration (if locked, reset needed to unlock) */ \
  112. wdogClkSelULFRCO, /* Select 1kHZ WDOG oscillator */ \
  113. wdogPeriod_256k /* Set longest possible timeout period */ \
  114. }
  115. /*******************************************************************************
  116. ***************************** PROTOTYPES **********************************
  117. ******************************************************************************/
  118. void WDOG_Enable(bool enable);
  119. void WDOG_Feed(void);
  120. void WDOG_Init(const WDOG_Init_TypeDef *init);
  121. void WDOG_Lock(void);
  122. /** @} (end addtogroup WDOG) */
  123. /** @} (end addtogroup EM_Library) */
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* __EM_WDOG_H */