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