LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 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 
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 */
167 
168  /* Get timer 0 peripheral clock rate */
169 #if defined(CHIP_LPC175X_6X)
170  fclk_freq = (CPU_INT32U) Chip_Clock_GetPeripheralClockRate(SYSCTL_PCLK_TIMER0);
171 #else
173 #endif
174 
175  /* Timer will recycle after 1s */
177  Chip_TIMER_SetMatch(LPC_TIMER0, 1, fclk_freq);
180 
181  CPU_TS_TmrFreqSet((CPU_TS_TMR_FREQ) fclk_freq);
182 }
183 #endif
184 
185 
186 /*$PAGE*/
187 /*
188 *********************************************************************************************************
189 * CPU_TS_TmrRd()
190 *
191 * Description : Get current CPU timestamp timer count value.
192 *
193 * Argument(s) : none.
194 *
195 * Return(s) : Timestamp timer count (see Notes #2a & #2b).
196 *
197 * Caller(s) : CPU_TS_Init(),
198 * CPU_TS_Get32(),
199 * CPU_TS_Get64(),
200 * CPU_IntDisMeasStart(),
201 * CPU_IntDisMeasStop().
202 *
203 * This function is an INTERNAL CPU module function & MUST be implemented by application/
204 * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
205 *
206 * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
207 * if either of the following CPU features is enabled :
208 *
209 * (a) CPU timestamps
210 * (b) CPU interrupts disabled time measurements
211 *
212 * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
213 * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
214 *
215 * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
216 * data type.
217 *
218 * (1) If timer has more bits, truncate timer values' higher-order bits greater
219 * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
220 *
221 * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
222 * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
223 * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
224 *
225 * In other words, if timer size is not a binary-multiple of 8-bit octets
226 * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
227 * octet word size SHOULD be configured (e.g. to 16-bits). However, the
228 * minimum supported word size for CPU timestamp timers is 8-bits.
229 *
230 * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
231 * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
232 *
233 * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
234 *
235 * (1) If timer is a 'down' counter whose values decrease with each time count,
236 * then the returned timer value MUST be ones-complemented.
237 *
238 * (c) (1) When applicable, the amount of time measured by CPU timestamps is
239 * calculated by either of the following equations :
240 *
241 * (A) Time measured = Number timer counts * Timer period
242 *
243 * where
244 *
245 * Number timer counts Number of timer counts measured
246 * Timer period Timer's period in some units of
247 * (fractional) seconds
248 * Time measured Amount of time measured, in same
249 * units of (fractional) seconds
250 * as the Timer period
251 *
252 * Number timer counts
253 * (B) Time measured = ---------------------
254 * Timer frequency
255 *
256 * where
257 *
258 * Number timer counts Number of timer counts measured
259 * Timer frequency Timer's frequency in some units
260 * of counts per second
261 * Time measured Amount of time measured, in seconds
262 *
263 * (2) Timer period SHOULD be less than the typical measured time but MUST be less
264 * than the maximum measured time; otherwise, timer resolution inadequate to
265 * measure desired times.
266 *********************************************************************************************************
267 */
268 
269 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
271 {
272  CPU_TS_TMR ts_tmr_cnts;
273 
274  ts_tmr_cnts = (CPU_TS_TMR) Chip_TIMER_ReadCount(LPC_TIMER0);
275 
276  return (ts_tmr_cnts);
277 }
278 #endif
279 
280 #if 0
281 /*$PAGE*/
282 /*
283 *********************************************************************************************************
284 * CPU_TSxx_to_uSec()
285 *
286 * Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
287 *
288 * Argument(s) : ts_cnts CPU timestamp (in timestamp timer counts [see Note #2aA]).
289 *
290 * Return(s) : Converted CPU timestamp (in microseconds [see Note #2aD]).
291 *
292 * Caller(s) : Application.
293 *
294 * This function is an (optional) CPU module application interface (API) function which
295 * MAY be implemented by application/BSP function(s) [see Note #1] & MAY be called by
296 * application function(s).
297 *
298 * Note(s) : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
299 * optionally defined by the developer when either of the following CPU features is
300 * enabled :
301 *
302 * (a) CPU timestamps
303 * (b) CPU interrupts disabled time measurements
304 *
305 * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
306 * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
307 *
308 * (2) (a) The amount of time measured by CPU timestamps is calculated by either of
309 * the following equations :
310 *
311 * 10^6 microseconds
312 * (1) Time measured = Number timer counts * ------------------- * Timer period
313 * 1 second
314 *
315 * Number timer counts 10^6 microseconds
316 * (2) Time measured = --------------------- * -------------------
317 * Timer frequency 1 second
318 *
319 * where
320 *
321 * (A) Number timer counts Number of timer counts measured
322 * (B) Timer frequency Timer's frequency in some units
323 * of counts per second
324 * (C) Timer period Timer's period in some units of
325 * (fractional) seconds
326 * (D) Time measured Amount of time measured,
327 * in microseconds
328 *
329 * (b) Timer period SHOULD be less than the typical measured time but MUST be less
330 * than the maximum measured time; otherwise, timer resolution inadequate to
331 * measure desired times.
332 *
333 * (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
334 * -- up to 32 or 64, respectively -- into microseconds.
335 *********************************************************************************************************
336 */
337 
338 #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
340 {
341 
342  return (0u);
343 
344 }
345 #endif
346 
347 
348 #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
350 {
351 
352  return (0u);
353 
354 }
355 #endif
356 #endif