LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
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 */
28
static
CPU_INT32U
reload_val
;
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 */
50
Chip_RIT_ClearInt
(
LPC_RITIMER
);
51
Chip_RIT_SetCOMPVAL
(
LPC_RITIMER
,
Chip_RIT_GetCounter
(
LPC_RITIMER
) +
reload_val
);
/* Reload value */
52
53
CPU_CRITICAL_ENTER
();
54
OSIntNestingCtr
++;
/* Tell uC/OS-III that we are starting an ISR */
55
CPU_CRITICAL_EXIT
();
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 */
65
Chip_RIT_ClearInt
(
LPC_RITIMER
);
66
67
/* Calculate reload value */
68
reload_val
= (
SystemCoreClock
/
OSCfg_TickRate_Hz
);
69
Chip_RIT_SetCOMPVAL
(
LPC_RITIMER
,
Chip_RIT_GetCounter
(
LPC_RITIMER
) +
reload_val
);
/* Start tick */
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 */
134
Chip_TIMER_Init
(
LPC_TIMER1
);
135
Chip_RGU_TriggerReset
(
RGU_TIMER1_RST
);
136
while
(
Chip_RGU_InReset
(
RGU_TIMER1_RST
)) ;
137
138
/* Get timer 1 peripheral clock rate */
139
fclk_freq = (
CPU_INT32U
)
Chip_Clock_GetRate
(
CLK_MX_TIMER1
);
140
141
/* Timer will recycle after 1s */
142
Chip_TIMER_Reset
(
LPC_TIMER1
);
143
Chip_TIMER_SetMatch
(
LPC_TIMER1
, 1, fclk_freq);
144
Chip_TIMER_ResetOnMatchEnable
(
LPC_TIMER1
, 1);
145
Chip_TIMER_Enable
(
LPC_TIMER1
);
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)
236
CPU_TS_TMR
CPU_TS_TmrRd
(
void
)
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)
306
CPU_INT64U
CPU_TS32_to_uSec
(
CPU_TS32
ts_cnts)
307
{
308
309
return
0u;
310
311
}
312
313
#endif
314
315
#if (CPU_CFG_TS_64_EN == DEF_ENABLED)
316
CPU_INT64U
CPU_TS64_to_uSec
(
CPU_TS64
ts_cnts)
317
{
318
319
return
0u;
320
321
}
322
323
#endif
324
#endif
software
ucos_iii
lpc_ucos_iii
lpc18xx43xx_bsp
cpu_bsp_lpc43xx_m0.c
Generated on Fri May 10 2013 10:42:25 for LPCOpen Platform by
1.8.2