LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cpu_bsp_lpc43xx_m0.c
Go to the documentation of this file.
1 /*
2  *
3  *
4  */
5 #include "os.h"
6 #include "os_cfg_app.h"
7 #include "board.h"
8 #include "chip.h"
9 
22 #define CONFIG_CPU_CLOCK_HZ ( 204000000 )
23 
24 #define RITENCLR (1 << 1)
25 #define RITINT (1 << 0)
26 
27 /* Timer reload value for next tick */
29 
30 /*$PAGE*/
31 /*
32  *********************************************************************************************************
33  * SYS TICK HANDLER
34  *
35  * Description: Handle the system tick (SysTick) interrupt, which is used to generate the uC/OS-III tick
36  * interrupt.Since M0 is not implemented with systick RI timer is used.
37  *
38  * Arguments : None.
39  *
40  *
41  *********************************************************************************************************
42  */
43 
44 void RIT_IRQHandler(void)
45 {
46 
47  CPU_SR_ALLOC();
48 
49  /* TODO: check if WWDT interrupt and redirect */
52 
54  OSIntNestingCtr++; /* Tell uC/OS-III that we are starting an ISR */
56 
57  OSTimeTick(); /* Call uC/OS-III's OSTimeTick() */
58 
59  OSIntExit(); /* Tell uC/OS-III that we are leaving the ISR */
60 }
61 
62 void OS_CSP_TickInit(void)
63 {
64  /* Clear any pending interrupt */
66 
67  /* Calculate reload value */
70 
71  NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, ((0x01 << 3) | 0x01));
72  NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn);
73 }
74 
75 /*$PAGE*/
76 /*
77  *********************************************************************************************************
78  * CPU_TS_TmrInit()
79  *
80  * Description : Initialize & start CPU timestamp timer.
81  *
82  * Argument(s) : none.
83  *
84  * Return(s) : none.
85  *
86  * Caller(s) : CPU_TS_Init().
87  *
88  * This function is an INTERNAL CPU module function & MUST be implemented by application/
89  * BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
90  *
91  * Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
92  * if either of the following CPU features is enabled :
93  *
94  * (a) CPU timestamps
95  * (b) CPU interrupts disabled time measurements
96  *
97  * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
98  * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
99  *
100  * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
101  * data type.
102  *
103  * (1) If timer has more bits, truncate timer values' higher-order bits greater
104  * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
105  *
106  * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
107  * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
108  * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
109  *
110  * In other words, if timer size is not a binary-multiple of 8-bit octets
111  * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
112  * octet word size SHOULD be configured (e.g. to 16-bits). However, the
113  * minimum supported word size for CPU timestamp timers is 8-bits.
114  *
115  * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
116  * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
117  *
118  * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
119  *
120  * (c) When applicable, timer period SHOULD be less than the typical measured time
121  * but MUST be less than the maximum measured time; otherwise, timer resolution
122  * inadequate to measure desired times.
123  *
124  * See also 'CPU_TS_TmrRd() Note #2'.
125  *********************************************************************************************************
126  */
127 
128 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
129 void CPU_TS_TmrInit(void)
130 {
131  CPU_INT32U fclk_freq;
132 
133  /* Use timer 1 */
137 
138  /* Get timer 1 peripheral clock rate */
140 
141  /* Timer will recycle after 1s */
143  Chip_TIMER_SetMatch(LPC_TIMER1, 1, fclk_freq);
146 
147  CPU_TS_TmrFreqSet((CPU_TS_TMR_FREQ) fclk_freq);
148 }
149 
150 #endif
151 
152 /*$PAGE*/
153 /*
154  *********************************************************************************************************
155  * CPU_TS_TmrRd()
156  *
157  * Description : Get current CPU timestamp timer count value.
158  *
159  * Argument(s) : none.
160  *
161  * Return(s) : Timestamp timer count (see Notes #2a & #2b).
162  *
163  * Caller(s) : CPU_TS_Init(),
164  * CPU_TS_Get32(),
165  * CPU_TS_Get64(),
166  * CPU_IntDisMeasStart(),
167  * CPU_IntDisMeasStop().
168  *
169  * This function is an INTERNAL CPU module function & MUST be implemented by application/
170  * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
171  *
172  * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
173  * if either of the following CPU features is enabled :
174  *
175  * (a) CPU timestamps
176  * (b) CPU interrupts disabled time measurements
177  *
178  * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
179  * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
180  *
181  * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
182  * data type.
183  *
184  * (1) If timer has more bits, truncate timer values' higher-order bits greater
185  * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
186  *
187  * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
188  * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
189  * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
190  *
191  * In other words, if timer size is not a binary-multiple of 8-bit octets
192  * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
193  * octet word size SHOULD be configured (e.g. to 16-bits). However, the
194  * minimum supported word size for CPU timestamp timers is 8-bits.
195  *
196  * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
197  * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
198  *
199  * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
200  *
201  * (1) If timer is a 'down' counter whose values decrease with each time count,
202  * then the returned timer value MUST be ones-complemented.
203  *
204  * (c) (1) When applicable, the amount of time measured by CPU timestamps is
205  * calculated by either of the following equations :
206  *
207  * (A) Time measured = Number timer counts * Timer period
208  *
209  * where
210  *
211  * Number timer counts Number of timer counts measured
212  * Timer period Timer's period in some units of
213  * (fractional) seconds
214  * Time measured Amount of time measured, in same
215  * units of (fractional) seconds
216  * as the Timer period
217  *
218  * Number timer counts
219  * (B) Time measured = ---------------------
220  * Timer frequency
221  *
222  * where
223  *
224  * Number timer counts Number of timer counts measured
225  * Timer frequency Timer's frequency in some units
226  * of counts per second
227  * Time measured Amount of time measured, in seconds
228  *
229  * (2) Timer period SHOULD be less than the typical measured time but MUST be less
230  * than the maximum measured time; otherwise, timer resolution inadequate to
231  * measure desired times.
232  *********************************************************************************************************
233  */
234 
235 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
237 {
238  CPU_TS_TMR ts_tmr_cnts;
239 
240  ts_tmr_cnts = (CPU_TS_TMR) Chip_TIMER_ReadCount(LPC_TIMER1);
241 
242  return ts_tmr_cnts;
243 }
244 
245 #endif
246 
247 #if 0
248 /*$PAGE*/
249 /*
250  *********************************************************************************************************
251  * CPU_TSxx_to_uSec()
252  *
253  * Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
254  *
255  * Argument(s) : ts_cnts CPU timestamp (in timestamp timer counts [see Note #2aA]).
256  *
257  * Return(s) : Converted CPU timestamp (in microseconds [see Note #2aD]).
258  *
259  * Caller(s) : Application.
260  *
261  * This function is an (optional) CPU module application interface (API) function which
262  * MAY be implemented by application/BSP function(s) [see Note #1] & MAY be called by
263  * application function(s).
264  *
265  * Note(s) : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
266  * optionally defined by the developer when either of the following CPU features is
267  * enabled :
268  *
269  * (a) CPU timestamps
270  * (b) CPU interrupts disabled time measurements
271  *
272  * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
273  * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
274  *
275  * (2) (a) The amount of time measured by CPU timestamps is calculated by either of
276  * the following equations :
277  *
278  * 10^6 microseconds
279  * (1) Time measured = Number timer counts * ------------------- * Timer period
280  * 1 second
281  *
282  * Number timer counts 10^6 microseconds
283  * (2) Time measured = --------------------- * -------------------
284  * Timer frequency 1 second
285  *
286  * where
287  *
288  * (A) Number timer counts Number of timer counts measured
289  * (B) Timer frequency Timer's frequency in some units
290  * of counts per second
291  * (C) Timer period Timer's period in some units of
292  * (fractional) seconds
293  * (D) Time measured Amount of time measured,
294  * in microseconds
295  *
296  * (b) Timer period SHOULD be less than the typical measured time but MUST be less
297  * than the maximum measured time; otherwise, timer resolution inadequate to
298  * measure desired times.
299  *
300  * (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
301  * -- up to 32 or 64, respectively -- into microseconds.
302  *********************************************************************************************************
303  */
304 
305 #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
307 {
308 
309  return 0u;
310 
311 }
312 
313 #endif
314 
315 #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
317 {
318 
319  return 0u;
320 
321 }
322 
323 #endif
324 #endif