| 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.c
Go to the documentation of this file.
1 /*
2 *********************************************************************************************************
3 * uC/CPU
4 * CPU CONFIGURATION & PORT LAYER
5 *
6 * (c) Copyright 2004-2010; Micrium, Inc.; Weston, FL
7 *
8 * All rights reserved. Protected by international copyright laws.
9 *
10 * uC/CPU is provided in source form to registered licensees ONLY. It is
11 * illegal to distribute this source code to any third party unless you receive
12 * written permission by an authorized Micrium representative. Knowledge of
13 * the source code may NOT be used to develop a similar product.
14 *
15 * Please help us continue to provide the Embedded community with the finest
16 * software available. Your honesty is greatly appreciated.
17 *
18 * You can contact us at www.micrium.com.
19 *********************************************************************************************************
20 */
21
22 /*
23 *********************************************************************************************************
24 *
25 * CPU BOARD SUPPORT PACKAGE (BSP) FUNCTIONS
26 *
27 * KEIL MCB1700 DEVELOPMENT KIT
28 *
29 * Filename : cpu_bsp.c
30 * Version : V1.25
31 * Programmer(s) : ITJ
32 *********************************************************************************************************
33 */
34
35
36 /*
37 *********************************************************************************************************
38 * INCLUDE FILES
39 *********************************************************************************************************
40 */
41
42 #define CPU_BSP_MODULE
43 #include "os.h"
44 #include "chip.h"
45
46 /*$PAGE*/
47 /*
48 *********************************************************************************************************
49 * LOCAL DEFINES
50 *********************************************************************************************************
51 */
52
53
54 /*
55 *********************************************************************************************************
56 * LOCAL CONSTANTS
57 *********************************************************************************************************
58 */
59
60
61 /*
62 *********************************************************************************************************
63 * LOCAL DATA TYPES
64 *********************************************************************************************************
65 */
66
67
68 /*
69 *********************************************************************************************************
70 * LOCAL TABLES
71 *********************************************************************************************************
72 */
73
74
75 /*
76 *********************************************************************************************************
77 * LOCAL GLOBAL VARIABLES
78 *********************************************************************************************************
79 */
80
81
82 /*
83 *********************************************************************************************************
84 * LOCAL FUNCTION PROTOTYPES
85 *********************************************************************************************************
86 */
87
88
89 /*
90 *********************************************************************************************************
91 * LOCAL CONFIGURATION ERRORS
92 *********************************************************************************************************
93 */
94
95 void OS_CSP_TickInit(void)
96 {
97 CPU_INT32U cnts;
98 CPU_INT32U cpu_freq;
99
100
101 cpu_freq = (CPU_INT32U) Chip_Clock_GetRate(CLK_MX_MXCORE);
102 cnts = (cpu_freq / OSCfg_TickRate_Hz);
103
104 OS_CPU_SysTickInit(cnts);
105 }
106
107 /*$PAGE*/
108 /*
109 *********************************************************************************************************
110 * CPU_TS_TmrInit()
111 *
112 * Description : Initialize & start CPU timestamp timer.
113 *
114 * Argument(s) : none.
115 *
116 * Return(s) : none.
117 *
118 * Caller(s) : CPU_TS_Init().
119 *
120 * This function is an INTERNAL CPU module function & MUST be implemented by application/
121 * BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
122 *
123 * Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
124 * if either of the following CPU features is enabled :
125 *
126 * (a) CPU timestamps
127 * (b) CPU interrupts disabled time measurements
128 *
129 * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
130 * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
131 *
132 * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
133 * data type.
134 *
135 * (1) If timer has more bits, truncate timer values' higher-order bits greater
136 * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
137 *
138 * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
139 * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
140 * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
141 *
142 * In other words, if timer size is not a binary-multiple of 8-bit octets
143 * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
144 * octet word size SHOULD be configured (e.g. to 16-bits). However, the
145 * minimum supported word size for CPU timestamp timers is 8-bits.
146 *
147 * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
148 * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
149 *
150 * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
151 *
152 * (c) When applicable, timer period SHOULD be less than the typical measured time
153 * but MUST be less than the maximum measured time; otherwise, timer resolution
154 * inadequate to measure desired times.
155 *
156 * See also 'CPU_TS_TmrRd() Note #2'.
157 *********************************************************************************************************
158 */
159
160 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
161 void CPU_TS_TmrInit (void)
162 {
163 CPU_INT32U fclk_freq;
164
165 /* Use timer 0 */
166 Chip_TIMER_Init(LPC_TIMER0);
167 Chip_RGU_TriggerReset(RGU_TIMER0_RST);
168 while (Chip_RGU_InReset(RGU_TIMER0_RST));
169
170 /* Get timer 0 peripheral clock rate */
171 fclk_freq = (CPU_INT32U) Chip_Clock_GetRate(CLK_MX_TIMER0);
172
173 /* Timer will recycle after 1s */
174 Chip_TIMER_Reset(LPC_TIMER0);
175 Chip_TIMER_SetMatch(LPC_TIMER0, 1, fclk_freq);
176 Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
177 Chip_TIMER_Enable(LPC_TIMER0);
178
179 CPU_TS_TmrFreqSet((CPU_TS_TMR_FREQ) fclk_freq);
180 }
181 #endif
182
183
184 /*$PAGE*/
185 /*
186 *********************************************************************************************************
187 * CPU_TS_TmrRd()
188 *
189 * Description : Get current CPU timestamp timer count value.
190 *
191 * Argument(s) : none.
192 *
193 * Return(s) : Timestamp timer count (see Notes #2a & #2b).
194 *
195 * Caller(s) : CPU_TS_Init(),
196 * CPU_TS_Get32(),
197 * CPU_TS_Get64(),
198 * CPU_IntDisMeasStart(),
199 * CPU_IntDisMeasStop().
200 *
201 * This function is an INTERNAL CPU module function & MUST be implemented by application/
202 * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
203 *
204 * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
205 * if either of the following CPU features is enabled :
206 *
207 * (a) CPU timestamps
208 * (b) CPU interrupts disabled time measurements
209 *
210 * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
211 * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
212 *
213 * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
214 * data type.
215 *
216 * (1) If timer has more bits, truncate timer values' higher-order bits greater
217 * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
218 *
219 * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
220 * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
221 * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
222 *
223 * In other words, if timer size is not a binary-multiple of 8-bit octets
224 * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
225 * octet word size SHOULD be configured (e.g. to 16-bits). However, the
226 * minimum supported word size for CPU timestamp timers is 8-bits.
227 *
228 * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
229 * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
230 *
231 * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
232 *
233 * (1) If timer is a 'down' counter whose values decrease with each time count,
234 * then the returned timer value MUST be ones-complemented.
235 *
236 * (c) (1) When applicable, the amount of time measured by CPU timestamps is
237 * calculated by either of the following equations :
238 *
239 * (A) Time measured = Number timer counts * Timer period
240 *
241 * where
242 *
243 * Number timer counts Number of timer counts measured
244 * Timer period Timer's period in some units of
245 * (fractional) seconds
246 * Time measured Amount of time measured, in same
247 * units of (fractional) seconds
248 * as the Timer period
249 *
250 * Number timer counts
251 * (B) Time measured = ---------------------
252 * Timer frequency
253 *
254 * where
255 *
256 * Number timer counts Number of timer counts measured
257 * Timer frequency Timer's frequency in some units
258 * of counts per second
259 * Time measured Amount of time measured, in seconds
260 *
261 * (2) Timer period SHOULD be less than the typical measured time but MUST be less
262 * than the maximum measured time; otherwise, timer resolution inadequate to
263 * measure desired times.
264 *********************************************************************************************************
265 */
266
267 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
268 CPU_TS_TMR CPU_TS_TmrRd (void)
269 {
270 CPU_TS_TMR ts_tmr_cnts;
271
272 ts_tmr_cnts = (CPU_TS_TMR) Chip_TIMER_ReadCount(LPC_TIMER0);
273
274 return (ts_tmr_cnts);
275 }
276 #endif
277
278 #if 0
279 /*$PAGE*/
280 /*
281 *********************************************************************************************************
282 * CPU_TSxx_to_uSec()
283 *
284 * Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
285 *
286 * Argument(s) : ts_cnts CPU timestamp (in timestamp timer counts [see Note #2aA]).
287 *
288 * Return(s) : Converted CPU timestamp (in microseconds [see Note #2aD]).
289 *
290 * Caller(s) : Application.
291 *
292 * This function is an (optional) CPU module application interface (API) function which
293 * MAY be implemented by application/BSP function(s) [see Note #1] & MAY be called by
294 * application function(s).
295 *
296 * Note(s) : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
297 * optionally defined by the developer when either of the following CPU features is
298 * enabled :
299 *
300 * (a) CPU timestamps
301 * (b) CPU interrupts disabled time measurements
302 *
303 * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
304 * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
305 *
306 * (2) (a) The amount of time measured by CPU timestamps is calculated by either of
307 * the following equations :
308 *
309 * 10^6 microseconds
310 * (1) Time measured = Number timer counts * ------------------- * Timer period
311 * 1 second
312 *
313 * Number timer counts 10^6 microseconds
314 * (2) Time measured = --------------------- * -------------------
315 * Timer frequency 1 second
316 *
317 * where
318 *
319 * (A) Number timer counts Number of timer counts measured
320 * (B) Timer frequency Timer's frequency in some units
321 * of counts per second
322 * (C) Timer period Timer's period in some units of
323 * (fractional) seconds
324 * (D) Time measured Amount of time measured,
325 * in microseconds
326 *
327 * (b) Timer period SHOULD be less than the typical measured time but MUST be less
328 * than the maximum measured time; otherwise, timer resolution inadequate to
329 * measure desired times.
330 *
331 * (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
332 * -- up to 32 or 64, respectively -- into microseconds.
333 *********************************************************************************************************
334 */
335
336 #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
337 CPU_INT64U CPU_TS32_to_uSec (CPU_TS32 ts_cnts)
338 {
339
340 return (0u);
341
342 }
343 #endif
344
345
346 #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
347 CPU_INT64U CPU_TS64_to_uSec (CPU_TS64 ts_cnts)
348 {
349
350 return (0u);
351
352 }
353 #endif
354 #endif