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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /**********************************************************************
  2. * $Id$ lpc17xx_timer.h 2010-05-21
  3. *//**
  4. * @file lpc17xx_timer.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for Timer firmware library 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. /** @defgroup TIM TIM (Timer)
  34. * @ingroup LPC1700CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC17XX_TIMER_H_
  38. #define __LPC17XX_TIMER_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC17xx.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Private Macros ------------------------------------------------------------- */
  47. /** @defgroup TIM_Private_Macros TIM Private Macros
  48. * @{
  49. */
  50. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  51. /**********************************************************************
  52. ** Interrupt information
  53. **********************************************************************/
  54. /** Macro to clean interrupt pending */
  55. #define TIM_IR_CLR(n) _BIT(n)
  56. /**********************************************************************
  57. ** Timer interrupt register definitions
  58. **********************************************************************/
  59. /** Macro for getting a timer match interrupt bit */
  60. #define TIM_MATCH_INT(n) (_BIT(n & 0x0F))
  61. /** Macro for getting a capture event interrupt bit */
  62. #define TIM_CAP_INT(n) (_BIT(((n & 0x0F) + 4)))
  63. /**********************************************************************
  64. * Timer control register definitions
  65. **********************************************************************/
  66. /** Timer/counter enable bit */
  67. #define TIM_ENABLE ((uint32_t)(1<<0))
  68. /** Timer/counter reset bit */
  69. #define TIM_RESET ((uint32_t)(1<<1))
  70. /** Timer control bit mask */
  71. #define TIM_TCR_MASKBIT ((uint32_t)(3))
  72. /**********************************************************************
  73. * Timer match control register definitions
  74. **********************************************************************/
  75. /** Bit location for interrupt on MRx match, n = 0 to 3 */
  76. #define TIM_INT_ON_MATCH(n) (_BIT((n * 3)))
  77. /** Bit location for reset on MRx match, n = 0 to 3 */
  78. #define TIM_RESET_ON_MATCH(n) (_BIT(((n * 3) + 1)))
  79. /** Bit location for stop on MRx match, n = 0 to 3 */
  80. #define TIM_STOP_ON_MATCH(n) (_BIT(((n * 3) + 2)))
  81. /** Timer Match control bit mask */
  82. #define TIM_MCR_MASKBIT ((uint32_t)(0x0FFF))
  83. /** Timer Match control bit mask for specific channel*/
  84. #define TIM_MCR_CHANNEL_MASKBIT(n) ((uint32_t)(7<<(n*3)))
  85. /**********************************************************************
  86. * Timer capture control register definitions
  87. **********************************************************************/
  88. /** Bit location for CAP.n on CRx rising edge, n = 0 to 3 */
  89. #define TIM_CAP_RISING(n) (_BIT((n * 3)))
  90. /** Bit location for CAP.n on CRx falling edge, n = 0 to 3 */
  91. #define TIM_CAP_FALLING(n) (_BIT(((n * 3) + 1)))
  92. /** Bit location for CAP.n on CRx interrupt enable, n = 0 to 3 */
  93. #define TIM_INT_ON_CAP(n) (_BIT(((n * 3) + 2)))
  94. /** Mask bit for rising and falling edge bit */
  95. #define TIM_EDGE_MASK(n) (_SBF((n * 3), 0x03))
  96. /** Timer capture control bit mask */
  97. #define TIM_CCR_MASKBIT ((uint32_t)(0x3F))
  98. /** Timer Capture control bit mask for specific channel*/
  99. #define TIM_CCR_CHANNEL_MASKBIT(n) ((uint32_t)(7<<(n*3)))
  100. /**********************************************************************
  101. * Timer external match register definitions
  102. **********************************************************************/
  103. /** Bit location for output state change of MAT.n when external match
  104. happens, n = 0 to 3 */
  105. #define TIM_EM(n) _BIT(n)
  106. /** Output state change of MAT.n when external match happens: no change */
  107. #define TIM_EM_NOTHING ((uint8_t)(0x0))
  108. /** Output state change of MAT.n when external match happens: low */
  109. #define TIM_EM_LOW ((uint8_t)(0x1))
  110. /** Output state change of MAT.n when external match happens: high */
  111. #define TIM_EM_HIGH ((uint8_t)(0x2))
  112. /** Output state change of MAT.n when external match happens: toggle */
  113. #define TIM_EM_TOGGLE ((uint8_t)(0x3))
  114. /** Macro for setting for the MAT.n change state bits */
  115. #define TIM_EM_SET(n,s) (_SBF(((n << 1) + 4), (s & 0x03)))
  116. /** Mask for the MAT.n change state bits */
  117. #define TIM_EM_MASK(n) (_SBF(((n << 1) + 4), 0x03))
  118. /** Timer external match bit mask */
  119. #define TIM_EMR_MASKBIT 0x0FFF
  120. /**********************************************************************
  121. * Timer Count Control Register definitions
  122. **********************************************************************/
  123. /** Mask to get the Counter/timer mode bits */
  124. #define TIM_CTCR_MODE_MASK 0x3
  125. /** Mask to get the count input select bits */
  126. #define TIM_CTCR_INPUT_MASK 0xC
  127. /** Timer Count control bit mask */
  128. #define TIM_CTCR_MASKBIT 0xF
  129. #define TIM_COUNTER_MODE ((uint8_t)(1))
  130. /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
  131. /** Macro to determine if it is valid TIMER peripheral */
  132. #define PARAM_TIMx(n) ((((uint32_t *)n)==((uint32_t *)LPC_TIM0)) || (((uint32_t *)n)==((uint32_t *)LPC_TIM1)) \
  133. || (((uint32_t *)n)==((uint32_t *)LPC_TIM2)) || (((uint32_t *)n)==((uint32_t *)LPC_TIM3)))
  134. /* Macro check interrupt type */
  135. #define PARAM_TIM_INT_TYPE(TYPE) ((TYPE ==TIM_MR0_INT)||(TYPE ==TIM_MR1_INT)\
  136. ||(TYPE ==TIM_MR2_INT)||(TYPE ==TIM_MR3_INT)\
  137. ||(TYPE ==TIM_CR0_INT)||(TYPE ==TIM_CR1_INT))
  138. /* Macro check TIMER mode */
  139. #define PARAM_TIM_MODE_OPT(MODE) ((MODE == TIM_TIMER_MODE)||(MODE == TIM_COUNTER_RISING_MODE)\
  140. || (MODE == TIM_COUNTER_RISING_MODE)||(MODE == TIM_COUNTER_RISING_MODE))
  141. /* Macro check TIMER prescale value */
  142. #define PARAM_TIM_PRESCALE_OPT(OPT) ((OPT == TIM_PRESCALE_TICKVAL)||(OPT == TIM_PRESCALE_USVAL))
  143. /* Macro check TIMER counter intput mode */
  144. #define PARAM_TIM_COUNTER_INPUT_OPT(OPT) ((OPT == TIM_COUNTER_INCAP0)||(OPT == TIM_COUNTER_INCAP1))
  145. /* Macro check TIMER external match mode */
  146. #define PARAM_TIM_EXTMATCH_OPT(OPT) ((OPT == TIM_EXTMATCH_NOTHING)||(OPT == TIM_EXTMATCH_LOW)\
  147. ||(OPT == TIM_EXTMATCH_HIGH)||(OPT == TIM_EXTMATCH_TOGGLE))
  148. /* Macro check TIMER external match mode */
  149. #define PARAM_TIM_CAP_MODE_OPT(OPT) ((OPT == TIM_CAPTURE_NONE)||(OPT == TIM_CAPTURE_RISING) \
  150. ||(OPT == TIM_CAPTURE_FALLING)||(OPT == TIM_CAPTURE_ANY))
  151. /**
  152. * @}
  153. */
  154. /* Public Types --------------------------------------------------------------- */
  155. /** @defgroup TIM_Public_Types TIM Public Types
  156. * @{
  157. */
  158. /***********************************************************************
  159. * Timer device enumeration
  160. **********************************************************************/
  161. /** @brief interrupt type */
  162. typedef enum
  163. {
  164. TIM_MR0_INT =0, /*!< interrupt for Match channel 0*/
  165. TIM_MR1_INT =1, /*!< interrupt for Match channel 1*/
  166. TIM_MR2_INT =2, /*!< interrupt for Match channel 2*/
  167. TIM_MR3_INT =3, /*!< interrupt for Match channel 3*/
  168. TIM_CR0_INT =4, /*!< interrupt for Capture channel 0*/
  169. TIM_CR1_INT =5 /*!< interrupt for Capture channel 1*/
  170. }TIM_INT_TYPE;
  171. /** @brief Timer/counter operating mode */
  172. typedef enum
  173. {
  174. TIM_TIMER_MODE = 0, /*!< Timer mode */
  175. TIM_COUNTER_RISING_MODE, /*!< Counter rising mode */
  176. TIM_COUNTER_FALLING_MODE, /*!< Counter falling mode */
  177. TIM_COUNTER_ANY_MODE /*!< Counter on both edges */
  178. } TIM_MODE_OPT;
  179. /** @brief Timer/Counter prescale option */
  180. typedef enum
  181. {
  182. TIM_PRESCALE_TICKVAL = 0, /*!< Prescale in absolute value */
  183. TIM_PRESCALE_USVAL /*!< Prescale in microsecond value */
  184. } TIM_PRESCALE_OPT;
  185. /** @brief Counter input option */
  186. typedef enum
  187. {
  188. TIM_COUNTER_INCAP0 = 0, /*!< CAPn.0 input pin for TIMERn */
  189. TIM_COUNTER_INCAP1, /*!< CAPn.1 input pin for TIMERn */
  190. } TIM_COUNTER_INPUT_OPT;
  191. /** @brief Timer/Counter external match option */
  192. typedef enum
  193. {
  194. TIM_EXTMATCH_NOTHING = 0, /*!< Do nothing for external output pin if match */
  195. TIM_EXTMATCH_LOW, /*!< Force external output pin to low if match */
  196. TIM_EXTMATCH_HIGH, /*!< Force external output pin to high if match */
  197. TIM_EXTMATCH_TOGGLE /*!< Toggle external output pin if match */
  198. }TIM_EXTMATCH_OPT;
  199. /** @brief Timer/counter capture mode options */
  200. typedef enum {
  201. TIM_CAPTURE_NONE = 0, /*!< No Capture */
  202. TIM_CAPTURE_RISING, /*!< Rising capture mode */
  203. TIM_CAPTURE_FALLING, /*!< Falling capture mode */
  204. TIM_CAPTURE_ANY /*!< On both edges */
  205. } TIM_CAP_MODE_OPT;
  206. /** @brief Configuration structure in TIMER mode */
  207. typedef struct
  208. {
  209. uint8_t PrescaleOption; /**< Timer Prescale option, should be:
  210. - TIM_PRESCALE_TICKVAL: Prescale in absolute value
  211. - TIM_PRESCALE_USVAL: Prescale in microsecond value
  212. */
  213. uint8_t Reserved[3]; /**< Reserved */
  214. uint32_t PrescaleValue; /**< Prescale value */
  215. } TIM_TIMERCFG_Type;
  216. /** @brief Configuration structure in COUNTER mode */
  217. typedef struct {
  218. uint8_t CounterOption; /**< Counter Option, should be:
  219. - TIM_COUNTER_INCAP0: CAPn.0 input pin for TIMERn
  220. - TIM_COUNTER_INCAP1: CAPn.1 input pin for TIMERn
  221. */
  222. uint8_t CountInputSelect;
  223. uint8_t Reserved[2];
  224. } TIM_COUNTERCFG_Type;
  225. /** @brief Match channel configuration structure */
  226. typedef struct {
  227. uint8_t MatchChannel; /**< Match channel, should be in range
  228. from 0..3 */
  229. uint8_t IntOnMatch; /**< Interrupt On match, should be:
  230. - ENABLE: Enable this function.
  231. - DISABLE: Disable this function.
  232. */
  233. uint8_t StopOnMatch; /**< Stop On match, should be:
  234. - ENABLE: Enable this function.
  235. - DISABLE: Disable this function.
  236. */
  237. uint8_t ResetOnMatch; /**< Reset On match, should be:
  238. - ENABLE: Enable this function.
  239. - DISABLE: Disable this function.
  240. */
  241. uint8_t ExtMatchOutputType; /**< External Match Output type, should be:
  242. - TIM_EXTMATCH_NOTHING: Do nothing for external output pin if match
  243. - TIM_EXTMATCH_LOW: Force external output pin to low if match
  244. - TIM_EXTMATCH_HIGH: Force external output pin to high if match
  245. - TIM_EXTMATCH_TOGGLE: Toggle external output pin if match.
  246. */
  247. uint8_t Reserved[3]; /** Reserved */
  248. uint32_t MatchValue; /** Match value */
  249. } TIM_MATCHCFG_Type;
  250. /** @brief Capture Input configuration structure */
  251. typedef struct {
  252. uint8_t CaptureChannel; /**< Capture channel, should be in range
  253. from 0..1 */
  254. uint8_t RisingEdge; /**< caption rising edge, should be:
  255. - ENABLE: Enable rising edge.
  256. - DISABLE: Disable this function.
  257. */
  258. uint8_t FallingEdge; /**< caption falling edge, should be:
  259. - ENABLE: Enable falling edge.
  260. - DISABLE: Disable this function.
  261. */
  262. uint8_t IntOnCaption; /**< Interrupt On caption, should be:
  263. - ENABLE: Enable interrupt function.
  264. - DISABLE: Disable this function.
  265. */
  266. } TIM_CAPTURECFG_Type;
  267. /**
  268. * @}
  269. */
  270. /* Public Functions ----------------------------------------------------------- */
  271. /** @defgroup TIM_Public_Functions TIM Public Functions
  272. * @{
  273. */
  274. /* Init/DeInit TIM functions -----------*/
  275. void TIM_Init(LPC_TIM_TypeDef *TIMx, TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct);
  276. void TIM_DeInit(LPC_TIM_TypeDef *TIMx);
  277. /* TIM interrupt functions -------------*/
  278. void TIM_ClearIntPending(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag);
  279. void TIM_ClearIntCapturePending(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag);
  280. FlagStatus TIM_GetIntStatus(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag);
  281. FlagStatus TIM_GetIntCaptureStatus(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag);
  282. /* TIM configuration functions --------*/
  283. void TIM_ConfigStructInit(TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct);
  284. void TIM_ConfigMatch(LPC_TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct);
  285. void TIM_UpdateMatchValue(LPC_TIM_TypeDef *TIMx,uint8_t MatchChannel, uint32_t MatchValue);
  286. void TIM_SetMatchExt(LPC_TIM_TypeDef *TIMx,TIM_EXTMATCH_OPT ext_match );
  287. void TIM_ConfigCapture(LPC_TIM_TypeDef *TIMx, TIM_CAPTURECFG_Type *TIM_CaptureConfigStruct);
  288. void TIM_Cmd(LPC_TIM_TypeDef *TIMx, FunctionalState NewState);
  289. uint32_t TIM_GetCaptureValue(LPC_TIM_TypeDef *TIMx, TIM_COUNTER_INPUT_OPT CaptureChannel);
  290. void TIM_ResetCounter(LPC_TIM_TypeDef *TIMx);
  291. /**
  292. * @}
  293. */
  294. #ifdef __cplusplus
  295. }
  296. #endif
  297. #endif /* __LPC17XX_TIMER_H_ */
  298. /**
  299. * @}
  300. */
  301. /* --------------------------------- End Of File ------------------------------ */