lpc176x_wdt.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef _LPC176X_WDT_H_
  2. #define _LPC176X_WDT_H_
  3. /*
  4. * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. *
  36. **************************************************************************
  37. *
  38. * Parts taken from lpc17xx_wdt.h
  39. *
  40. * file : lpc17xx_wdt.h
  41. * brief : Contains all macro definitions and function prototypes
  42. * support for WDT firmware library on LPC17xx
  43. * version : 1.0
  44. * date : 9. April. 2009
  45. * author : HieuNguyen
  46. **************************************************************************
  47. * Software that is described herein is for illustrative purposes only
  48. * which provides customers with programming information regarding the
  49. * products. This software is supplied "AS IS" without any warranties.
  50. * NXP Semiconductors assumes no responsibility or liability for the
  51. * use of the software, conveys no license or title under any patent,
  52. * copyright, or mask work right to the product. NXP Semiconductors
  53. * reserves the right to make changes in the software without
  54. * notification. NXP Semiconductors also make no representation or
  55. * warranty that such application will be suitable for the specified
  56. * use without further testing or modification.
  57. **************************************************************************/
  58. /*!
  59. * \verbatim
  60. * $Id: $
  61. * \endverbatim
  62. */
  63. /*============================================================================*
  64. LPC177x_8x Windowed watchdog timer
  65. *============================================================================*/
  66. /*----------------------------------------------------------------------------*
  67. Some macros
  68. *----------------------------------------------------------------------------*/
  69. #define PPCLK_WDT 4000000
  70. /* Calculation macros, time is calculated by usec */
  71. #define WDT_GET_FROM_USEC(time) (time/((WDT_US_INDEX * 4)/PPCLK_WDT))
  72. #define WDT_GET_USEC(counter) (counter * ((WDT_US_INDEX * 4)/PPCLK_WDT))
  73. /*----------------------------------------------------------------------------*
  74. WDT Control register
  75. *----------------------------------------------------------------------------*/
  76. /* WDT interrupt enable bit */
  77. #define WDT_WDMOD_WDEN _BV(0)
  78. /* WDT interrupt enable bit */
  79. #define WDT_WDMOD_WDRESET _BV(1)
  80. /* WDT time out flag bit */
  81. #define WDT_WDMOD_WDTOF _BV(2)
  82. /* WDT Time Out flag bit */
  83. #define WDT_WDMOD_WDINT _BV(3)
  84. /* WDT Mode */
  85. #define WDT_WDMOD(n) _BV(1)
  86. /*----------------------------------------------------------------------------*
  87. Some defines
  88. *----------------------------------------------------------------------------*/
  89. /* Define divider index for microsecond ( us ) */
  90. #define WDT_US_INDEX 1000000
  91. /* WDT Time out minimum value */
  92. #define WDT_TIMEOUT_MIN 0xFF
  93. /* WDT Time out maximum value */
  94. #define WDT_TIMEOUT_MAX 0xFFFFFFFF
  95. /* Watchdog mode register mask */
  96. #define WDT_WDMOD_MASK 0x02
  97. /* Watchdog timer constant register mask */
  98. #define WDT_WDTC_MASK 0xFFFFFFFF
  99. /* Watchdog feed sequence register mask */
  100. #define WDT_WDFEED_MASK 0x000000FF
  101. /* Watchdog timer value register mask */
  102. #define WDT_WDCLKSEL_MASK 0x03
  103. /* Clock selected from internal RC */
  104. #define WDT_WDCLKSEL_RC 0x00
  105. /* Clock selected from PCLK */
  106. #define WDT_WDCLKSEL_PCLK 0x01
  107. /* Clock selected from external RTC */
  108. #define WDT_WDCLKSEL_RTC 0x02
  109. /*----------------------------------------------------------------------------*
  110. WDT enums
  111. *----------------------------------------------------------------------------*/
  112. /* Clock source option for WDT */
  113. typedef enum {
  114. WDT_CLKSRC_IRC = 0, /*!< Clock source from Internal RC oscillator */
  115. WDT_CLKSRC_PCLK = 1, /*!< Selects the APB peripheral clock (PCLK) */
  116. WDT_CLKSRC_RTC = 2 /*!< Selects the RTC oscillator */
  117. } WDT_CLK_OPT;
  118. #define PARAM_WDT_CLK_OPT(OPTION) ((OPTION ==WDT_CLKSRC_IRC)||\
  119. (OPTION ==WDT_CLKSRC_IRC)||\
  120. (OPTION ==WDT_CLKSRC_IRC))
  121. /* WDT operation mode */
  122. typedef enum {
  123. WDT_MODE_INT_ONLY = 0, /*!< Use WDT to generate interrupt only */
  124. WDT_MODE_RESET = 1 /*!< Use WDT to generate interrupt and reset MCU */
  125. } WDT_MODE_OPT;
  126. #define PARAM_WDT_MODE_OPT(OPTION) ((OPTION ==WDT_MODE_INT_ONLY)||\
  127. (OPTION ==WDT_MODE_RESET))
  128. #endif /* _LPC176X_WDT_H_ */