FreeCalypso > hg > freecalypso-citrine
comparison bsp/timer.c @ 0:75a11d740a02
initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 Jun 2016 00:02:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:75a11d740a02 |
---|---|
1 /******************************************************************************* | |
2 TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION | |
3 | |
4 Property of Texas Instruments -- For Unrestricted Internal Use Only | |
5 Unauthorized reproduction and/or distribution is strictly prohibited. This | |
6 product is protected under copyright law and trade secret law as an | |
7 unpublished work. Created 1987, (C) Copyright 1997 Texas Instruments. All | |
8 rights reserved. | |
9 | |
10 | |
11 Filename : timer.c | |
12 | |
13 Description : timer.c | |
14 | |
15 Project : drivers | |
16 | |
17 Author : pmonteil@tif.ti.com Patrice Monteil. | |
18 | |
19 Version number : 1.3 | |
20 | |
21 Date and time : 07/23/98 16:25:32 | |
22 Previous delta : 07/23/98 16:25:32 | |
23 | |
24 SCCS file : /db/gsm_asp/db_ht96/dsp_0/gsw/rel_0/mcu_l1/release1.5/mod/emu/EMU_MCMP/eva3_drivers/source/SCCS/s.timer.c | |
25 | |
26 Sccs Id (SID) : '@(#) timer.c 1.3 07/23/98 16:25:32 ' | |
27 | |
28 | |
29 *****************************************************************************/ | |
30 | |
31 #include "../include/sys_types.h" | |
32 | |
33 #include "mem.h" | |
34 #include "iq.h" | |
35 #include "timer.h" | |
36 | |
37 | |
38 /*-------------------------------------------------------------- | |
39 * TIMER_Read() | |
40 *-------------------------------------------------------------- | |
41 * Parameters : num of the register to be read | |
42 * Return :value of the timer register read | |
43 * Functionality : read one of the TIMER register | |
44 *--------------------------------------------------------------*/ | |
45 SYS_UWORD16 TIMER_Read (unsigned short regNum) | |
46 { | |
47 SYS_UWORD16 timerReg; | |
48 | |
49 switch (regNum) { | |
50 case 0: | |
51 timerReg = ( * (volatile SYS_UWORD16 *) TIMER_CNTL_REG) & TIMER_CNTL_MASK; | |
52 break; | |
53 case 1: | |
54 timerReg = *(volatile SYS_UWORD16 *) TIMER_READ_REG; | |
55 break; | |
56 case 2: | |
57 timerReg = ( * (volatile SYS_UWORD16 *) TIMER_MODE_REG) & TIMER_MODE_MASK; | |
58 break; | |
59 default: | |
60 break; | |
61 } | |
62 return(timerReg); | |
63 } | |
64 /*-------------------------------------------------------------- | |
65 * TM_ResetTimer() | |
66 *-------------------------------------------------------------- | |
67 * Parameters : timer number (1 or 2) | |
68 * timer value, reload yes or not, scale | |
69 * Return : none | |
70 * Functionality : Give the timewr state | |
71 *--------------------------------------------------------------*/ | |
72 void TM_ResetTimer (SYS_UWORD16 timerNum, SYS_UWORD16 countValue, | |
73 SYS_UWORD16 autoReload, SYS_UWORD16 clockScale) | |
74 { | |
75 volatile SYS_UWORD16 *cntl; | |
76 | |
77 if (timerNum == 1) | |
78 { | |
79 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL; | |
80 | |
81 *cntl &= ~(START_STOP | PTV); /* stop and reset values */ | |
82 | |
83 (autoReload) ? (*cntl |= AR) : (*cntl &= ~AR); | |
84 | |
85 *cntl |= (clockScale << 2 ); | |
86 | |
87 /*load the value */ | |
88 *(volatile SYS_UWORD16 *) TIMER1_LOAD_TIM = countValue; | |
89 | |
90 *cntl |= START_STOP; | |
91 } | |
92 else | |
93 { | |
94 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL; | |
95 | |
96 *cntl &= ~(START_STOP | PTV); /* stop and reset values */ | |
97 | |
98 (autoReload) ? (*cntl |= AR) : (*cntl &= ~AR); | |
99 | |
100 *cntl |= (clockScale << 2 ); | |
101 | |
102 /*load the value */ | |
103 *(volatile SYS_UWORD16 *) TIMER2_LOAD_TIM = countValue; | |
104 | |
105 *cntl |= START_STOP; | |
106 } | |
107 } | |
108 | |
109 /* | |
110 * TM_StopTimer | |
111 * | |
112 * Parameters : timer number (1 or 2) | |
113 */ | |
114 void TM_StopTimer (int timerNum) | |
115 { | |
116 volatile SYS_UWORD16 *cntl; | |
117 | |
118 if (timerNum == 1) | |
119 { | |
120 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL; | |
121 } | |
122 else | |
123 { | |
124 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL; | |
125 } | |
126 *cntl &= ~START_STOP; | |
127 } | |
128 | |
129 /* | |
130 * TM_ReadTimer | |
131 * | |
132 * Returns current timer value | |
133 * | |
134 * Parameters : timer number (1 or 2) | |
135 * | |
136 */ | |
137 SYS_UWORD16 TM_ReadTimer (int timerNum) | |
138 { | |
139 if (timerNum == 1) | |
140 { | |
141 return (* (SYS_UWORD16 *) TIMER1_READ_TIM); | |
142 } | |
143 else | |
144 { | |
145 return (* (SYS_UWORD16 *) TIMER2_READ_TIM); | |
146 } | |
147 } | |
148 | |
149 | |
150 /* | |
151 * TM_StartTimer | |
152 * | |
153 * Parameters : timer number (1 or 2) | |
154 * | |
155 */ | |
156 void TM_StartTimer (int timerNum) | |
157 { | |
158 volatile SYS_UWORD16 *cntl; | |
159 | |
160 if (timerNum == 1) | |
161 { | |
162 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL; | |
163 } | |
164 else | |
165 { | |
166 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL; | |
167 } | |
168 *cntl |= START_STOP; | |
169 } | |
170 | |
171 void TM_DisableWatchdog (void) | |
172 { | |
173 /* volatile variable needed due C to optimization */ | |
174 volatile SYS_UWORD16 *reg = (volatile SYS_UWORD16 *) TIMER_MODE_REG; | |
175 | |
176 *reg = 0xf5; | |
177 *reg = 0xa0; | |
178 } | |
179 | |
180 | |
181 /* | |
182 * TM_EnableWatchdog | |
183 * | |
184 */ | |
185 void TM_EnableWatchdog(void) | |
186 { | |
187 * ((volatile SYS_UWORD16 *) TIMER_MODE_REG) = TIMER_WDOG; | |
188 } | |
189 | |
190 /* | |
191 * TM_ResetWatchdog | |
192 * | |
193 * Parameter : Tick count | |
194 * Use a different value each time, otherwise watchdog bites | |
195 */ | |
196 void TM_ResetWatchdog(SYS_UWORD16 count) | |
197 { | |
198 * ((volatile SYS_UWORD16 *) TIMER_LOAD_REG) = count; | |
199 } | |
200 | |
201 /* | |
202 * TM_EnableTimer (int TimerNum) | |
203 * | |
204 * Parameter : TimerNum : timer to enable (timer1 or timer2) | |
205 * | |
206 */ | |
207 void TM_EnableTimer (int TimerNum) | |
208 { | |
209 volatile SYS_UWORD16 *cntl; | |
210 | |
211 if (TimerNum == 1) | |
212 { | |
213 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL; | |
214 } | |
215 else | |
216 { | |
217 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL; | |
218 } | |
219 *cntl |= TIMER_CLK_EN; | |
220 } | |
221 | |
222 /* | |
223 * TM_DisableTimer (int TimerNum) | |
224 * | |
225 * Parameter : TimerNum : timer to enable (timer1 or timer2) | |
226 * | |
227 */ | |
228 void TM_DisableTimer (int TimerNum) | |
229 { | |
230 volatile SYS_UWORD16 *cntl; | |
231 | |
232 if (TimerNum == 1) | |
233 { | |
234 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL; | |
235 } | |
236 else | |
237 { | |
238 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL; | |
239 } | |
240 *cntl &= ~TIMER_CLK_EN; | |
241 } | |
242 | |
243 /*-------------------------------------------------------------- | |
244 * TIMER_ReadValue() | |
245 *-------------------------------------------------------------- | |
246 * Parameters : none | |
247 * Return : none | |
248 * Functionality : Read timer value | |
249 *--------------------------------------------------------------*/ | |
250 | |
251 unsigned short TIMER_ReadValue (void) | |
252 { | |
253 return(* (SYS_UWORD16 *) TIMER_READ_REG); | |
254 } | |
255 | |
256 /*-------------------------------------------------------------- | |
257 * TIMER_WriteValue() | |
258 *-------------------------------------------------------------- | |
259 * Parameters : none | |
260 * Return : none | |
261 * Functionality : Write timer value | |
262 *--------------------------------------------------------------*/ | |
263 | |
264 void TIMER_WriteValue (SYS_UWORD16 value) | |
265 { | |
266 * (SYS_UWORD16 *) TIMER_LOAD_REG = value; /*load the value */ | |
267 } |