My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lpc17xx_systick.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /**********************************************************************
  2. * $Id$ lpc17xx_systick.c 2010-05-21
  3. *//**
  4. * @file lpc17xx_systick.c
  5. * @brief Contains all functions support for SYSTICK firmware library
  6. * on LPC17xx
  7. * @version 2.0
  8. * @date 21. May. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, 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. /** @addtogroup SYSTICK
  34. * @{
  35. */
  36. /* Includes ------------------------------------------------------------------- */
  37. #include "lpc17xx_systick.h"
  38. #include "lpc17xx_clkpwr.h"
  39. /* If this source file built with example, the LPC17xx FW library configuration
  40. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  41. * otherwise the default FW library configuration file must be included instead
  42. */
  43. #ifdef __BUILD_WITH_EXAMPLE__
  44. #include "lpc17xx_libcfg.h"
  45. #else
  46. #include "lpc17xx_libcfg_default.h"
  47. #endif /* __BUILD_WITH_EXAMPLE__ */
  48. #ifdef _SYSTICK
  49. /* Public Functions ----------------------------------------------------------- */
  50. /** @addtogroup SYSTICK_Public_Functions
  51. * @{
  52. */
  53. /*********************************************************************//**
  54. * @brief Initial System Tick with using internal CPU clock source
  55. * @param[in] time time interval(ms)
  56. * @return None
  57. **********************************************************************/
  58. void SYSTICK_InternalInit(uint32_t time)
  59. {
  60. uint32_t cclk;
  61. float maxtime;
  62. cclk = SystemCoreClock;
  63. /* With internal CPU clock frequency for LPC17xx is 'SystemCoreClock'
  64. * And limit 24 bit for RELOAD value
  65. * So the maximum time can be set:
  66. * 1/SystemCoreClock * (2^24) * 1000 (ms)
  67. */
  68. //check time value is available or not
  69. maxtime = (1<<24)/(SystemCoreClock / 1000);
  70. if(time > maxtime)
  71. //Error loop
  72. while(1);
  73. else
  74. {
  75. //Select CPU clock is System Tick clock source
  76. SysTick->CTRL |= ST_CTRL_CLKSOURCE;
  77. /* Set RELOAD value
  78. * RELOAD = (SystemCoreClock/1000) * time - 1
  79. * with time base is millisecond
  80. */
  81. SysTick->LOAD = (cclk/1000)*time - 1;
  82. }
  83. }
  84. /*********************************************************************//**
  85. * @brief Initial System Tick with using external clock source
  86. * @param[in] freq external clock frequency(Hz)
  87. * @param[in] time time interval(ms)
  88. * @return None
  89. **********************************************************************/
  90. void SYSTICK_ExternalInit(uint32_t freq, uint32_t time)
  91. {
  92. float maxtime;
  93. /* With external clock frequency for LPC17xx is 'freq'
  94. * And limit 24 bit for RELOAD value
  95. * So the maximum time can be set:
  96. * 1/freq * (2^24) * 1000 (ms)
  97. */
  98. //check time value is available or not
  99. maxtime = (1<<24)/(freq / 1000);
  100. if (time>maxtime)
  101. //Error Loop
  102. while(1);
  103. else
  104. {
  105. //Select external clock is System Tick clock source
  106. SysTick->CTRL &= ~ ST_CTRL_CLKSOURCE;
  107. /* Set RELOAD value
  108. * RELOAD = (freq/1000) * time - 1
  109. * with time base is millisecond
  110. */
  111. maxtime = (freq/1000)*time - 1;
  112. SysTick->LOAD = (freq/1000)*time - 1;
  113. }
  114. }
  115. /*********************************************************************//**
  116. * @brief Enable/disable System Tick counter
  117. * @param[in] NewState System Tick counter status, should be:
  118. * - ENABLE
  119. * - DISABLE
  120. * @return None
  121. **********************************************************************/
  122. void SYSTICK_Cmd(FunctionalState NewState)
  123. {
  124. CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
  125. if(NewState == ENABLE)
  126. //Enable System Tick counter
  127. SysTick->CTRL |= ST_CTRL_ENABLE;
  128. else
  129. //Disable System Tick counter
  130. SysTick->CTRL &= ~ST_CTRL_ENABLE;
  131. }
  132. /*********************************************************************//**
  133. * @brief Enable/disable System Tick interrupt
  134. * @param[in] NewState System Tick interrupt status, should be:
  135. * - ENABLE
  136. * - DISABLE
  137. * @return None
  138. **********************************************************************/
  139. void SYSTICK_IntCmd(FunctionalState NewState)
  140. {
  141. CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
  142. if(NewState == ENABLE)
  143. //Enable System Tick counter
  144. SysTick->CTRL |= ST_CTRL_TICKINT;
  145. else
  146. //Disable System Tick counter
  147. SysTick->CTRL &= ~ST_CTRL_TICKINT;
  148. }
  149. /*********************************************************************//**
  150. * @brief Get current value of System Tick counter
  151. * @param[in] None
  152. * @return current value of System Tick counter
  153. **********************************************************************/
  154. uint32_t SYSTICK_GetCurrentValue(void)
  155. {
  156. return (SysTick->VAL);
  157. }
  158. /*********************************************************************//**
  159. * @brief Clear Counter flag
  160. * @param[in] None
  161. * @return None
  162. **********************************************************************/
  163. void SYSTICK_ClearCounterFlag(void)
  164. {
  165. SysTick->CTRL &= ~ST_CTRL_COUNTFLAG;
  166. }
  167. /**
  168. * @}
  169. */
  170. #endif /* _SYSTICK */
  171. /**
  172. * @}
  173. */
  174. /* --------------------------------- End Of File ------------------------------ */