My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

lpc17xx_rit.c 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**********************************************************************
  2. * $Id$ lpc17xx_rit.c 2010-05-21
  3. *//**
  4. * @file lpc17xx_rit.c
  5. * @brief Contains all functions support for RIT firmware library on LPC17xx
  6. * @version 2.0
  7. * @date 21. May. 2010
  8. * @author NXP MCU SW Application Team
  9. *
  10. * Copyright(C) 2010, NXP Semiconductor
  11. * All rights reserved.
  12. *
  13. ***********************************************************************
  14. * Software that is described herein is for illustrative purposes only
  15. * which provides customers with programming information regarding the
  16. * products. This software is supplied "AS IS" without any warranties.
  17. * NXP Semiconductors assumes no responsibility or liability for the
  18. * use of the software, conveys no license or title under any patent,
  19. * copyright, or mask work right to the product. NXP Semiconductors
  20. * reserves the right to make changes in the software without
  21. * notification. NXP Semiconductors also make no representation or
  22. * warranty that such application will be suitable for the specified
  23. * use without further testing or modification.
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors'
  26. * relevant copyright in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. **********************************************************************/
  31. /* Peripheral group ----------------------------------------------------------- */
  32. /** @addtogroup RIT
  33. * @{
  34. */
  35. /* Includes ------------------------------------------------------------------- */
  36. #include "lpc17xx_rit.h"
  37. #include "lpc17xx_clkpwr.h"
  38. /* If this source file built with example, the LPC17xx FW library configuration
  39. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  40. * otherwise the default FW library configuration file must be included instead
  41. */
  42. #ifdef __BUILD_WITH_EXAMPLE__
  43. #include "lpc17xx_libcfg.h"
  44. #else
  45. #include "lpc17xx_libcfg_default.h"
  46. #endif /* __BUILD_WITH_EXAMPLE__ */
  47. #ifdef _RIT
  48. /* Public Functions ----------------------------------------------------------- */
  49. /** @addtogroup RIT_Public_Functions
  50. * @{
  51. */
  52. /******************************************************************************//*
  53. * @brief Initial for RIT
  54. * - Turn on power and clock
  55. * - Setup default register values
  56. * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
  57. * @return None
  58. *******************************************************************************/
  59. void RIT_Init(LPC_RIT_TypeDef *RITx)
  60. {
  61. CHECK_PARAM(PARAM_RITx(RITx));
  62. CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRIT, ENABLE);
  63. //Set up default register values
  64. RITx->RICOMPVAL = 0xFFFFFFFF;
  65. RITx->RIMASK = 0x00000000;
  66. RITx->RICTRL = 0x0C;
  67. RITx->RICOUNTER = 0x00000000;
  68. // Turn on power and clock
  69. }
  70. /******************************************************************************//*
  71. * @brief DeInitial for RIT
  72. * - Turn off power and clock
  73. * - ReSetup default register values
  74. * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
  75. * @return None
  76. *******************************************************************************/
  77. void RIT_DeInit(LPC_RIT_TypeDef *RITx)
  78. {
  79. CHECK_PARAM(PARAM_RITx(RITx));
  80. // Turn off power and clock
  81. CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRIT, DISABLE);
  82. //ReSetup default register values
  83. RITx->RICOMPVAL = 0xFFFFFFFF;
  84. RITx->RIMASK = 0x00000000;
  85. RITx->RICTRL = 0x0C;
  86. RITx->RICOUNTER = 0x00000000;
  87. }
  88. /******************************************************************************//*
  89. * @brief Set compare value, mask value and time counter value
  90. * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
  91. * @param[in] time_interval: timer interval value (ms)
  92. * @return None
  93. *******************************************************************************/
  94. void RIT_TimerConfig(LPC_RIT_TypeDef *RITx, uint32_t time_interval)
  95. {
  96. uint32_t clock_rate, cmp_value;
  97. CHECK_PARAM(PARAM_RITx(RITx));
  98. // Get PCLK value of RIT
  99. clock_rate = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_RIT);
  100. /* calculate compare value for RIT to generate interrupt at
  101. * specified time interval
  102. * COMPVAL = (RIT_PCLK * time_interval)/1000
  103. * (with time_interval unit is millisecond)
  104. */
  105. cmp_value = (clock_rate /1000) * time_interval;
  106. RITx->RICOMPVAL = cmp_value;
  107. /* Set timer enable clear bit to clear timer to 0 whenever
  108. * counter value equals the contents of RICOMPVAL
  109. */
  110. RITx->RICTRL |= (1<<1);
  111. }
  112. /******************************************************************************//*
  113. * @brief Enable/Disable Timer
  114. * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
  115. * @param[in] NewState New State of this function
  116. * -ENABLE: Enable Timer
  117. * -DISABLE: Disable Timer
  118. * @return None
  119. *******************************************************************************/
  120. void RIT_Cmd(LPC_RIT_TypeDef *RITx, FunctionalState NewState)
  121. {
  122. CHECK_PARAM(PARAM_RITx(RITx));
  123. CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
  124. //Enable or Disable Timer
  125. if(NewState==ENABLE)
  126. {
  127. RITx->RICTRL |= RIT_CTRL_TEN;
  128. }
  129. else
  130. {
  131. RITx->RICTRL &= ~RIT_CTRL_TEN;
  132. }
  133. }
  134. /******************************************************************************//*
  135. * @brief Timer Enable/Disable on debug
  136. * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
  137. * @param[in] NewState New State of this function
  138. * -ENABLE: The timer is halted whenever a hardware break condition occurs
  139. * -DISABLE: Hardware break has no effect on the timer operation
  140. * @return None
  141. *******************************************************************************/
  142. void RIT_TimerDebugCmd(LPC_RIT_TypeDef *RITx, FunctionalState NewState)
  143. {
  144. CHECK_PARAM(PARAM_RITx(RITx));
  145. CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
  146. //Timer Enable/Disable on break
  147. if(NewState==ENABLE)
  148. {
  149. RITx->RICTRL |= RIT_CTRL_ENBR;
  150. }
  151. else
  152. {
  153. RITx->RICTRL &= ~RIT_CTRL_ENBR;
  154. }
  155. }
  156. /******************************************************************************//*
  157. * @brief Check whether interrupt flag is set or not
  158. * @param[in] RITx is RIT peripheral selected, should be: LPC_RIT
  159. * @return Current interrupt status, could be: SET/RESET
  160. *******************************************************************************/
  161. IntStatus RIT_GetIntStatus(LPC_RIT_TypeDef *RITx)
  162. {
  163. IntStatus result;
  164. CHECK_PARAM(PARAM_RITx(RITx));
  165. if((RITx->RICTRL&RIT_CTRL_INTEN)==1) result= SET;
  166. else return RESET;
  167. //clear interrupt flag
  168. RITx->RICTRL |= RIT_CTRL_INTEN;
  169. return result;
  170. }
  171. /**
  172. * @}
  173. */
  174. #endif /* _RIT */
  175. /**
  176. * @}
  177. */
  178. /* --------------------------------- End Of File ------------------------------ */