comparison src/cs/drivers/drv_core/timer/timer.c @ 0:b6a5e36de839

src/cs: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:39:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
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 "l1sw.cfg"
32
33 #if (OP_L1_STANDALONE == 0)
34 #include "main/sys_types.h"
35 #else
36 #include "sys_types.h"
37 #endif
38 #include "memif/mem.h"
39 #include "inth/iq.h"
40 #include "timer.h"
41
42
43 /*--------------------------------------------------------------
44 * TIMER_Read()
45 *--------------------------------------------------------------
46 * Parameters : num of the register to be read
47 * Return :value of the timer register read
48 * Functionality : read one of the TIMER register
49 *--------------------------------------------------------------*/
50 SYS_UWORD16 TIMER_Read (unsigned short regNum)
51 {
52 volatile SYS_UWORD16 timerReg;
53
54 switch (regNum) {
55 case 0:
56 timerReg = (( * (SYS_UWORD16 *) TIMER_CNTL_REG) & TIMER_CNTL_MASK);
57 break;
58 case 1:
59 timerReg = ( * (SYS_UWORD16 *) TIMER_READ_REG);
60 break;
61 case 2:
62 timerReg = (( * (SYS_UWORD16 *) TIMER_MODE_REG) & TIMER_MODE_MASK);
63 break;
64 default:
65 break;
66 }
67 return(timerReg);
68 }
69 /*--------------------------------------------------------------
70 * TM_ResetTimer()
71 *--------------------------------------------------------------
72 * Parameters : timer number (1 or 2)
73 * timer value, reload yes or not, scale
74 * Return : none
75 * Functionality : Give the timewr state
76 *--------------------------------------------------------------*/
77 void TM_ResetTimer (SYS_UWORD16 timerNum, SYS_UWORD16 countValue,
78 SYS_UWORD16 autoReload, SYS_UWORD16 clockScale)
79 {
80 volatile SYS_UWORD16 *cntl;
81
82 if (timerNum == 1)
83 {
84 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL;
85
86 *cntl &= ~(START_STOP | PTV); /* stop and reset values */
87
88 (autoReload) ? (*cntl |= AR) : (*cntl &= ~AR);
89
90 *cntl |= (clockScale << 2 );
91
92
93 * (SYS_UWORD16 *) TIMER1_LOAD_TIM = countValue; /*load the value */
94
95 *cntl |= START_STOP;
96 }
97 else
98 {
99 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL;
100
101 *cntl &= ~(START_STOP | PTV); /* stop and reset values */
102
103 (autoReload) ? (*cntl |= AR) : (*cntl &= ~AR);
104
105 *cntl |= (clockScale << 2 );
106
107
108 * (SYS_UWORD16 *) TIMER2_LOAD_TIM = countValue; /*load the value */
109
110 *cntl |= START_STOP;
111 }
112 }
113
114 /*
115 * TM_StopTimer
116 *
117 * Parameters : timer number (1 or 2)
118 */
119 void TM_StopTimer (int timerNum)
120 {
121
122 volatile SYS_UWORD16 *cntl;
123
124 if (timerNum == 1)
125 {
126 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL;
127 }
128 else
129 {
130 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL;
131 }
132 *cntl &= ~START_STOP;
133
134 }
135
136 /*
137 * TM_ReadTimer
138 *
139 * Returns current timer value
140 *
141 * Parameters : timer number (1 or 2)
142 *
143 */
144 SYS_UWORD16 TM_ReadTimer (int timerNum)
145 {
146 if (timerNum == 1)
147 {
148 return (* (SYS_UWORD16 *) TIMER1_READ_TIM);
149 }
150 else
151 {
152 return (* (SYS_UWORD16 *) TIMER2_READ_TIM);
153 }
154 }
155
156
157 /*
158 * TM_StartTimer
159 *
160 * Parameters : timer number (1 or 2)
161 *
162 */
163 void TM_StartTimer (int timerNum)
164 {
165 volatile SYS_UWORD16 *cntl;
166
167 if (timerNum == 1)
168 {
169 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL;
170 }
171 else
172 {
173 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL;
174 }
175 *cntl |= START_STOP;
176 }
177
178 void TM_DisableWatchdog (void)
179 {
180 /* volatile variable needed due C to optimization */
181 volatile SYS_UWORD16 *reg = (volatile SYS_UWORD16 *) TIMER_MODE_REG;
182
183 *reg = 0xf5;
184 *reg = 0xa0;
185 }
186
187
188 /*
189 * TM_EnableWatchdog
190 *
191 */
192 void TM_EnableWatchdog(void)
193 {
194 * ((volatile SYS_UWORD16 *) TIMER_MODE_REG) = TIMER_WDOG;
195 }
196
197 /*
198 * TM_ResetWatchdog
199 *
200 * Parameter : Tick count
201 * Use a different value each time, otherwise watchdog bites
202 */
203 void TM_ResetWatchdog(SYS_UWORD16 count)
204 {
205 * ((volatile SYS_UWORD16 *) TIMER_LOAD_REG) = count;
206 }
207
208 /*
209 * TM_EnableTimer (int TimerNum)
210 *
211 * Parameter : TimerNum : timer to enable (timer1 or timer2)
212 *
213 */
214 void TM_EnableTimer (int TimerNum)
215 {
216 volatile SYS_UWORD16 *cntl;
217
218 if (TimerNum == 1)
219 {
220 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL;
221 }
222 else
223 {
224 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL;
225 }
226 *cntl |= TIMER_CLK_EN;
227
228 }
229
230 /*
231 * TM_DisableTimer (int TimerNum)
232 *
233 * Parameter : TimerNum : timer to enable (timer1 or timer2)
234 *
235 */
236 void TM_DisableTimer (int TimerNum)
237 {
238 volatile SYS_UWORD16 *cntl;
239
240 if (TimerNum == 1)
241 {
242 cntl = (volatile SYS_UWORD16 *) TIMER1_CNTL;
243 }
244 else
245 {
246 cntl = (volatile SYS_UWORD16 *) TIMER2_CNTL;
247 }
248 *cntl &= ~TIMER_CLK_EN;
249 }
250
251 /*--------------------------------------------------------------
252 * TIMER_ReadValue()
253 *--------------------------------------------------------------
254 * Parameters : none
255 * Return : none
256 * Functionality : Read timer value
257 *--------------------------------------------------------------*/
258
259 unsigned short TIMER_ReadValue (void)
260 {
261 return(* (SYS_UWORD16 *) TIMER_READ_REG);
262
263 }
264
265 /*--------------------------------------------------------------
266 * TIMER_WriteValue()
267 *--------------------------------------------------------------
268 * Parameters : none
269 * Return : none
270 * Functionality : Write timer value
271 *--------------------------------------------------------------*/
272
273 void TIMER_WriteValue (SYS_UWORD16 value)
274 {
275 * (SYS_UWORD16 *) TIMER_LOAD_REG = value; /*load the value */
276
277 }