lpc_wwdt.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**********************************************************************
  2. * $Id$ lpc_wwdt.h 2011-06-02
  3. *//**
  4. * @file lpc_wwdt.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support forWindow Watchdog Timer firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup WWDT WWDT (Windowed Watchdog Timer)
  34. * @ingroup LPC_CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC_WWDT_H_
  38. #define __LPC_WWDT_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC407x_8x_177x_8x.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /** @defgroup WDT_Private_Macros WDT Private Macros
  47. * @{
  48. */
  49. // time is calculated by usec
  50. #define WDT_GET_FROM_USEC(time) (time/((WWDT_US_INDEX * 4)/WDT_OSC))
  51. #define WDT_GET_USEC(counter) (counter * ((WWDT_US_INDEX * 4)/WDT_OSC))
  52. #define WWDT_FUNC_OK (0)
  53. #define WWDT_FUNC_BAD_PARAM (-1)
  54. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  55. /** WWDT interrupt enable bit */
  56. #define WWDT_WDMOD_WDEN ((uint32_t)(1<<0))
  57. /** WWDT interrupt enable bit */
  58. #define WWDT_WDMOD_WDRESET ((uint32_t)(1<<1))
  59. /** WWDT time out flag bit */
  60. #define WWDT_WDMOD_WDTOF ((uint32_t)(1<<2))
  61. /** WDT Time Out flag bit */
  62. #define WWDT_WDMOD_WDINT ((uint32_t)(1<<3))
  63. /** WWDT Protect flag bit */
  64. #define WWDT_WDMOD_WDPROTECT ((uint32_t)(1<<4))
  65. /** Define divider index for microsecond ( us ) */
  66. #define WWDT_US_INDEX ((uint32_t)(1000000))
  67. /** WWDT Time out minimum value */
  68. #define WWDT_TIMEOUT_MIN ((uint32_t)(0xFF))
  69. /** WWDT Time out maximum value */
  70. #define WWDT_TIMEOUT_MAX ((uint32_t)(0x00FFFFFF))
  71. /** WWDT Warning minimum value */
  72. #define WWDT_WARNINT_MIN ((uint32_t)(0xFF))
  73. /** WWDT Warning maximum value */
  74. #define WWDT_WARNINT_MAX ((uint32_t)(0x000003FF))
  75. /** WWDT Windowed minimum value */
  76. #define WWDT_WINDOW_MIN ((uint32_t)(0xFF))
  77. /** WWDT Windowed minimum value */
  78. #define WWDT_WINDOW_MAX ((uint32_t)(0x00FFFFFF))
  79. /** WWDT timer constant register mask */
  80. #define WWDT_WDTC_MASK ((uint32_t)(0x00FFFFFF))
  81. /** WWDT warning value register mask */
  82. #define WWDT_WDWARNINT_MASK ((uint32_t)(0x000003FF))
  83. /** WWDT feed sequence register mask */
  84. #define WWDT_WDFEED_MASK ((uint32_t)(0x000000FF))
  85. /** WWDT flag */
  86. #define WWDT_WARNINT_FLAG ((uint8_t)(0))
  87. #define WWDT_TIMEOUT_FLAG ((uint8_t)(1))
  88. /** WWDT mode definitions */
  89. #define WWDT_PROTECT_MODE ((uint8_t)(0))
  90. #define WWDT_RESET_MODE ((uint8_t)(1))
  91. /* WWDT Timer value definition (us) */
  92. #define WWDT_TIMEOUT_USEC_MIN ((uint32_t)(WDT_GET_USEC(WWDT_TIMEOUT_MIN)))//microseconds
  93. #define WWDT_TIMEOUT_USEC_MAX ((uint32_t)(WDT_GET_USEC(WWDT_TIMEOUT_MAX)))
  94. #define WWDT_TIMEWARN_USEC_MIN ((uint32_t)(WDT_GET_USEC(WWDT_WARNINT_MIN)))
  95. #define WWDT_TIMEWARN_USEC_MAX ((uint32_t)(WDT_GET_USEC(WWDT_WARNINT_MAX)))
  96. #define WWDT_TIMEWINDOWED_USEC_MIN ((uint32_t)(WDT_GET_USEC(WWDT_WINDOW_MIN)))
  97. #define WWDT_TIMEWINDOWED_USEC_MAX ((uint32_t)(WDT_GET_USEC(WWDT_WINDOW_MAX)))
  98. /**
  99. * @}
  100. */
  101. /** @defgroup WDT_Public_Types WDT Public Types
  102. * @{
  103. */
  104. /**
  105. * @brief The field to configurate the WatchDog Timer
  106. */
  107. typedef struct Wdt_Config
  108. {
  109. uint8_t wdtEnable; /**< if ENABLE -> the enable bit is enabled */
  110. uint8_t wdtReset; /**< if ENABLE -> the Reset bit is enabled */
  111. uint8_t wdtProtect; /**< if ENABLE -> the Protect bit is enabled */
  112. uint32_t wdtTmrConst; /**< Set the constant value to timeout the WDT */
  113. uint32_t wdtWarningVal; /**< Set the value to warn the WDT with interrupt */
  114. uint32_t wdtWindowVal; /**< Set a window vaule for WDT */
  115. }st_Wdt_Config;
  116. /**
  117. * @}
  118. */
  119. /* Public Functions ----------------------------------------------------------- */
  120. /** @defgroup WDT_Public_Functions WDT Public Functions
  121. * @{
  122. */
  123. int8_t WWDT_Init(uint32_t TimeOut);
  124. int8_t WWDT_Start(uint32_t TimeOut);
  125. void WWDT_SetMode(uint8_t mode, FunctionalState NewState);
  126. void WWDT_SetTimerConstant(uint32_t constVal);
  127. void WWDT_Enable(FunctionalState NewState);
  128. void WWDT_Cmd(FunctionalState NewState);
  129. int8_t WWDT_SetWarningRaw(uint32_t warnVal);
  130. int8_t WWDT_SetWarning(uint32_t WarnTime);
  131. int8_t WWDT_SetWindowRaw(uint32_t wndVal);
  132. int8_t WWDT_SetWindow(uint32_t WindowedTime);
  133. void WWDT_UpdateTimeOut(uint32_t TimeOut);
  134. FlagStatus WWDT_GetStatus (uint8_t Status);
  135. void WWDT_ClearStatusFlag (uint8_t flag);
  136. void WWDT_ClrTimeOutFlag (void);
  137. void WWDT_FeedStdSeq (void);
  138. void WWDT_Feed (void);
  139. uint32_t WWDT_GetCurrentCount(void);
  140. /**
  141. * @}
  142. */
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif /* __LPC_WWDT_H_ */
  147. /**
  148. * @}
  149. */
  150. /* --------------------------------- End Of File ------------------------------ */