]> git.sur5r.net Git - freertos/blob
58470534f0e6a26f485f51edd47737239631208c
[freertos] /
1 /**********************************************************************\r
2 * $Id$          lpc18xx_rgu.c           2011-06-02\r
3 *//**\r
4 * @file         lpc18xx_rgu.c\r
5 * @brief        Contains all functions support for RGU 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 RGU\r
28  * @{\r
29  */\r
30 \r
31 /* Includes ------------------------------------------------------------------- */\r
32 #include "lpc18xx_rgu.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 \r
46 #ifdef _RGU\r
47 /* Public Functions ----------------------------------------------------------- */\r
48 /** @addtogroup RGU_Public_Functions\r
49  * @{\r
50  */\r
51 \r
52 /*********************************************************************//**\r
53  * @brief               Soft Reset a Signal\r
54  * @param[in]   ResetSignal indicates which signal will be reset, should be:\r
55  *                                      - RGU_SIG_CORE          :Core\r
56  *                                      - RGU_SIG_PERIPH        :Peripheral\r
57  *                                      - RGU_SIG_MASTER        :Master\r
58  *                                      - RGU_SIG_WWDT          :WWDT\r
59  *                                      - RGU_SIG_CREG          :Configuration register block\r
60  *                                      - RGU_SIG_BUS           :Buses\r
61  *                                      - RGU_SIG_SCU           :System control unit\r
62  *                                      - RGU_SIG_PINMUX        :Pin mux\r
63  *                                      - RGU_SIG_M3            :Cortex-M3 system\r
64  *                                      - RGU_SIG_LCD           :LCD controller\r
65  *                                      - RGU_SIG_USB0          :USB0\r
66  *                                      - RGU_SIG_USB1          :USB1\r
67  *                                      - RGU_SIG_DMA           :DMA\r
68  *                                      - RGU_SIG_SDIO          :SDIO\r
69  *                                      - RGU_SIG_EMC           :External memory controller\r
70  *                                      - RGU_SIG_ETHERNET      :Ethernet\r
71  *                                      - RGU_SIG_AES           :AES\r
72  *                                      - RGU_SIG_GPIO          :GPIO\r
73  *                                      - RGU_SIG_TIMER0        :Timer 0\r
74  *                                      - RGU_SIG_TIMER1        :Timer 1\r
75  *                                      - RGU_SIG_TIMER2        :Timer 2\r
76  *                                      - RGU_SIG_TIMER3        :Timer 3\r
77  *                                      - RGU_SIG_RITIMER       :Repetitive Interrupt Timer\r
78  *                                      - RGU_SIG_SCT           :State Configurable Timer\r
79  *                                      - RGU_SIG_MOTOCONPWM:Motor Control PWM\r
80  *                                      - RGU_SIG_QEI           :QEI\r
81  *                                      - RGU_SIG_ADC0          :ADC0\r
82  *                                      - RGU_SIG_ADC1          :ADC1\r
83  *                                      - RGU_SIG_DAC           :DAC\r
84  *                                      - RGU_SIG_UART0         :UART0\r
85  *                                      - RGU_SIG_UART1         :UART1\r
86  *                                      - RGU_SIG_UART2         :UART2\r
87  *                                      - RGU_SIG_UART3         :UART3\r
88  *                                      - RGU_SIG_I2C0          :I2C0\r
89  *                                      - RGU_SIG_I2C1          :I2C1\r
90  *                                      - RGU_SIG_SSP0          :SSP0\r
91  *                                      - RGU_SIG_SSP1          :SSP1\r
92  *                                      - RGU_SIG_I2S           :I2S\r
93  *                                      - RGU_SIG_SPIFI         :SPIFI\r
94  *                                      - RGU_SIG_CAN           :CAN\r
95  * @return              None\r
96  **********************************************************************/\r
97 void RGU_SoftReset(RGU_SIG ResetSignal)\r
98 {\r
99         if(ResetSignal < 32){\r
100                 LPC_RGU->RESET_CTRL0 = 1 << ResetSignal;\r
101                 LPC_RGU->RESET_CTRL0 = 0;\r
102         }else{\r
103                 LPC_RGU->RESET_CTRL1 = 1 << (ResetSignal - 32);\r
104                 LPC_RGU->RESET_CTRL1 = 0;\r
105         }\r
106 }\r
107 \r
108 /*********************************************************************//**\r
109  * @brief               Get source cause of a signal\r
110  * @param[in]   ResetSignal reset signal, should be:\r
111  *                                      - RGU_SIG_CORE          :Core\r
112  *                                      - RGU_SIG_PERIPH        :Peripheral\r
113  *                                      - RGU_SIG_MASTER        :Master\r
114  *                                      - RGU_SIG_WWDT          :WWDT\r
115  *                                      - RGU_SIG_CREG          :Configuration register block\r
116  *                                      - RGU_SIG_BUS           :Buses\r
117  *                                      - RGU_SIG_SCU           :System control unit\r
118  *                                      - RGU_SIG_PINMUX        :Pin mux\r
119  *                                      - RGU_SIG_M3            :Cortex-M3 system\r
120  *                                      - RGU_SIG_LCD           :LCD controller\r
121  *                                      - RGU_SIG_USB0          :USB0\r
122  *                                      - RGU_SIG_USB1          :USB1\r
123  *                                      - RGU_SIG_DMA           :DMA\r
124  *                                      - RGU_SIG_SDIO          :SDIO\r
125  *                                      - RGU_SIG_EMC           :External memory controller\r
126  *                                      - RGU_SIG_ETHERNET      :Ethernet\r
127  *                                      - RGU_SIG_AES           :AES\r
128  *                                      - RGU_SIG_GPIO          :GPIO\r
129  *                                      - RGU_SIG_TIMER0        :Timer 0\r
130  *                                      - RGU_SIG_TIMER1        :Timer 1\r
131  *                                      - RGU_SIG_TIMER2        :Timer 2\r
132  *                                      - RGU_SIG_TIMER3        :Timer 3\r
133  *                                      - RGU_SIG_RITIMER       :Repetitive Interrupt Timer\r
134  *                                      - RGU_SIG_SCT           :State Configurable Timer\r
135  *                                      - RGU_SIG_MOTOCONPWM:Motor Control PWM\r
136  *                                      - RGU_SIG_QEI           :QEI\r
137  *                                      - RGU_SIG_ADC0          :ADC0\r
138  *                                      - RGU_SIG_ADC1          :ADC1\r
139  *                                      - RGU_SIG_DAC           :DAC\r
140  *                                      - RGU_SIG_UART0         :UART0\r
141  *                                      - RGU_SIG_UART1         :UART1\r
142  *                                      - RGU_SIG_UART2         :UART2\r
143  *                                      - RGU_SIG_UART3         :UART3\r
144  *                                      - RGU_SIG_I2C0          :I2C0\r
145  *                                      - RGU_SIG_I2C1          :I2C1\r
146  *                                      - RGU_SIG_SSP0          :SSP0\r
147  *                                      - RGU_SIG_SSP1          :SSP1\r
148  *                                      - RGU_SIG_I2S           :I2S\r
149  *                                      - RGU_SIG_SPIFI         :SPIFI\r
150  *                                      - RGU_SIG_CAN           :CAN\r
151  * @return              Source cause of reset, could be:\r
152  *                                      - RGU_SRC_NONE          :No source\r
153  *                                      - RGU_SRC_SOFT          :Software reset source\r
154  *                                      - RGU_SRC_EXT           :External reset source\r
155  *                                      - RGU_SRC_CORE          :Core reset source\r
156  *                                      - RGU_SRC_PERIPH        :Peripheral reset source\r
157  *                                      - RGU_SRC_MASTER        :Master reset source\r
158  *                                      - RGU_SRC_BOD           :BOD reset source\r
159  *                                      - RGU_SRC_WWDT          :WWDT reset source\r
160  **********************************************************************/\r
161 RGU_SRC RGU_GetSource(RGU_SIG ResetSignal)\r
162 {\r
163         uint32_t i, temp, registercache;\r
164         if(ResetSignal < 16)\r
165                 temp = 3 & (LPC_RGU->RESET_STATUS0 >> ResetSignal);\r
166         else if(ResetSignal < 32)\r
167                 temp = 3 & (LPC_RGU->RESET_STATUS1 >> (ResetSignal - 16));\r
168         else if(ResetSignal < 48)\r
169                 temp = 3 & (LPC_RGU->RESET_STATUS2 >> (ResetSignal - 32));\r
170         else\r
171                 temp = 3 & (LPC_RGU->RESET_STATUS3 >> (ResetSignal - 48));\r
172 \r
173         if(temp == 0) return RGU_SRC_NONE;\r
174         else if(temp == 3) return RGU_SRC_SOFT;\r
175         else if(temp == 1){\r
176                 registercache = (((uint32_t*)&LPC_RGU->RESET_EXT_STAT0)[ResetSignal]);\r
177                 for(i = 0; i < 6; i++){\r
178                         if(registercache & (1<<i)){\r
179                                 return (RGU_SRC)(RGU_SRC_EXT + i);\r
180                         }\r
181                 }\r
182         }\r
183         return RGU_SRC_NONE;\r
184 }\r
185 \r
186 /*********************************************************************//**\r
187  * @brief               Get Current Status of Signal\r
188  * @param[in]   ResetSignal Reset Signal, should be:\r
189  *                                      - RGU_SIG_CORE          :Core\r
190  *                                      - RGU_SIG_PERIPH        :Peripheral\r
191  *                                      - RGU_SIG_MASTER        :Master\r
192  *                                      - RGU_SIG_WWDT          :WWDT\r
193  *                                      - RGU_SIG_CREG          :Configuration register block\r
194  *                                      - RGU_SIG_BUS           :Buses\r
195  *                                      - RGU_SIG_SCU           :System control unit\r
196  *                                      - RGU_SIG_PINMUX        :Pin mux\r
197  *                                      - RGU_SIG_M3            :Cortex-M3 system\r
198  *                                      - RGU_SIG_LCD           :LCD controller\r
199  *                                      - RGU_SIG_USB0          :USB0\r
200  *                                      - RGU_SIG_USB1          :USB1\r
201  *                                      - RGU_SIG_DMA           :DMA\r
202  *                                      - RGU_SIG_SDIO          :SDIO\r
203  *                                      - RGU_SIG_EMC           :External memory controller\r
204  *                                      - RGU_SIG_ETHERNET      :Ethernet\r
205  *                                      - RGU_SIG_AES           :AES\r
206  *                                      - RGU_SIG_GPIO          :GPIO\r
207  *                                      - RGU_SIG_TIMER0        :Timer 0\r
208  *                                      - RGU_SIG_TIMER1        :Timer 1\r
209  *                                      - RGU_SIG_TIMER2        :Timer 2\r
210  *                                      - RGU_SIG_TIMER3        :Timer 3\r
211  *                                      - RGU_SIG_RITIMER       :Repetitive Interrupt Timer\r
212  *                                      - RGU_SIG_SCT           :State Configurable Timer\r
213  *                                      - RGU_SIG_MOTOCONPWM:Motor Control PWM\r
214  *                                      - RGU_SIG_QEI           :QEI\r
215  *                                      - RGU_SIG_ADC0          :ADC0\r
216  *                                      - RGU_SIG_ADC1          :ADC1\r
217  *                                      - RGU_SIG_DAC           :DAC\r
218  *                                      - RGU_SIG_UART0         :UART0\r
219  *                                      - RGU_SIG_UART1         :UART1\r
220  *                                      - RGU_SIG_UART2         :UART2\r
221  *                                      - RGU_SIG_UART3         :UART3\r
222  *                                      - RGU_SIG_I2C0          :I2C0\r
223  *                                      - RGU_SIG_I2C1          :I2C1\r
224  *                                      - RGU_SIG_SSP0          :SSP0\r
225  *                                      - RGU_SIG_SSP1          :SSP1\r
226  *                                      - RGU_SIG_I2S           :I2S\r
227  *                                      - RGU_SIG_SPIFI         :SPIFI\r
228  *                                      - RGU_SIG_CAN           :CAN\r
229  * @return              Signal status, could be:\r
230  *                                      - TRUE  :reset is active\r
231  *                                      - FALSE :reset is inactive\r
232  **********************************************************************/\r
233 Bool RGU_GetSignalStatus(RGU_SIG ResetSignal)\r
234 {\r
235         if(ResetSignal < 32)\r
236                 return (Bool)!(LPC_RGU->RESET_ACTIVE_STATUS0 | (1 << ResetSignal));\r
237         else\r
238                 return (Bool)!(LPC_RGU->RESET_ACTIVE_STATUS1 | (1 << (ResetSignal - 32)));\r
239 }\r
240 \r
241 \r
242 /**\r
243  * @}\r
244  */\r
245 \r
246 #endif /* _RGU */\r
247 \r
248 /**\r
249  * @}\r
250  */\r
251 \r
252 /* --------------------------------- End Of File ------------------------------ */\r
253 \r