comparison g23m-glue/gdi/rtc.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 +-----------------------------------------------------------------------------
3 | Project : GSM-PS
4 | Modul : DRV_RTC
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This Module defines the real time clock
18 | driver interface for the G23 protocol stack.
19 MC SPR 1725, re-wrote for new driver
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef DRV_RTC_C
24 #define DRV_RTC_C
25
26 #define ENTITY_CST
27 /*==== INCLUDES ===================================================*/
28
29 #include "config.h"
30 #include "fixedconf.h"
31 #include "condat-features.h"
32
33 #include <string.h>
34 #include "typedefs.h"
35 #include "vsi.h"
36 #include "custom.h"
37 #include "prim.h"
38 #include "gsm.h"
39 #include "tok.h"
40 #include "../cst/cst.h"
41 #include "gdi.h"
42 #include "rtc.h"
43
44 #ifdef _SIMULATION_
45 #define _WINDOWS
46 #endif
47
48 #include "../../riviera/rvf/rvf_api.h"
49
50 #ifndef _SIMULATION_
51 #include "../../bsp/rtc/rtc_api.h"
52 #endif
53 #include "rtcdrv.h"
54 /*==== EXPORT =====================================================*/
55 /*==== VARIABLES ==================================================*/
56
57
58
59 /*
60 +--------------------------------------------------------------------+
61 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
62 | STATE : code ROUTINE : rtc_clock_cleared |
63 +--------------------------------------------------------------------+
64
65 PURPOSE : returns true if clcok has been reset
66
67
68 */
69 BOOL rtc_clock_cleared()
70 {
71 #ifndef _SIMULATION_
72 return RTC_RtcReset();
73 #endif /* _SIMULATION_ */
74 }
75 /*
76 +--------------------------------------------------------------------+
77 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
78 | STATE : code ROUTINE : rtc_set_time_date |
79 +--------------------------------------------------------------------+
80
81 PURPOSE : set the time and date
82
83
84 */
85 UBYTE rtc_set_time_date(T_RTC_DATE* date, T_RTC_TIME* time )
86 {
87 #ifndef _SIMULATION_
88 T_RTC_DATE_TIME time_and_date;
89
90 time_and_date.second = 0;
91 time_and_date.minute = time->minute;
92 if (time->format== RTC_TIME_FORMAT_12HOUR)
93 time_and_date.hour = (time->hour)% 12;
94 else
95 time_and_date.hour = time->hour;
96 time_and_date.second= time->second;
97 time_and_date.day = date->day;
98 time_and_date.month = date->month;
99 time_and_date.wday = 3;
100 time_and_date.year = (date->year - 2000) %100;
101 if (time->format== RTC_TIME_FORMAT_12HOUR)
102 time_and_date.mode_12_hour = TRUE;
103 else
104 time_and_date.mode_12_hour = FALSE;
105
106 time_and_date.PM_flag = time->PM_flag % 2;
107
108
109 return RTC_SetDateTime(time_and_date);
110 #endif /* _SIMULATION_ */
111
112 }
113 /*
114 +--------------------------------------------------------------------+
115 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
116 | STATE : code ROUTINE : rtc_get_time_date |
117 +--------------------------------------------------------------------+
118
119 PURPOSE : get the time and date
120
121
122 */
123 UBYTE rtc_get_time_date(T_RTC_DATE* date , T_RTC_TIME* time)
124 {
125 #ifndef _SIMULATION_
126 T_RTC_DATE_TIME time_and_date;
127
128 if (RTC_GetDateTime(&time_and_date) != RVF_OK)
129 DRV_INTERNAL_ERROR; /*error*/
130 date->year = 2000+ time_and_date.year;
131 date->month = time_and_date.month;
132 date->day = time_and_date.day;
133
134 time->minute = time_and_date.minute;
135 time->hour = time_and_date.hour;
136 time->second = time_and_date.second;
137 if ( time_and_date.mode_12_hour == TRUE)
138 time->format = RTC_TIME_FORMAT_12HOUR;
139 else
140 time->format = RTC_TIME_FORMAT_24HOUR;
141 time->PM_flag = time_and_date.PM_flag;
142 return DRV_OK;
143 #endif /* _SIMULATION_ */
144 }
145
146 void empty_callback_func(void* data)
147 {
148 TRACE_EVENT("empty_callback_func");
149
150 }
151
152 /*
153 +--------------------------------------------------------------------+
154 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
155 | STATE : code ROUTINE : rtc_set_alarm |
156 +--------------------------------------------------------------------+
157
158 PURPOSE : set the alarm
159
160
161 */
162 UBYTE rtc_set_alarm(T_RTC_DATE* date , T_RTC_TIME* time, RtcCallback callback_func )
163 {
164 #ifndef _SIMULATION_
165 T_RTC_DATE_TIME time_and_date;
166 T_RV_RETURN return_path;
167
168 memset(&return_path, 0, sizeof(T_RV_RETURN));
169
170
171 time_and_date.second = time->second;
172 time_and_date.minute = time->minute;
173 if (time->format== RTC_TIME_FORMAT_12HOUR)
174 time_and_date.hour = (time->hour)% 12;
175 else
176 time_and_date.hour = time->hour;
177 time_and_date.day = date->day;
178 time_and_date.month = date->month;
179 time_and_date.wday = 3;
180 time_and_date.year = (date->year - 2000) %100;
181 if (time->format== RTC_TIME_FORMAT_12HOUR)
182 time_and_date.mode_12_hour = TRUE;
183 else
184 time_and_date.mode_12_hour = FALSE;
185
186 time_and_date.PM_flag = time->PM_flag % 2;
187 return_path.addr_id = RVF_INVALID_ADDR_ID;
188 return_path.callback_func = (RtcCallback)callback_func;
189 return RTC_SetAlarm(time_and_date, return_path);
190 #endif /* _SIMULATION_ */
191 }
192 /*
193 +--------------------------------------------------------------------+
194 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
195 | STATE : code ROUTINE : rtc_get_alarm |
196 +--------------------------------------------------------------------+
197
198 PURPOSE : retrieve alarm setting
199
200
201 */
202 UBYTE rtc_get_alarm(T_RTC_DATE* date, T_RTC_TIME* time )
203 {
204 #ifndef _SIMULATION_
205 T_RTC_DATE_TIME time_and_date;
206
207 if (RTC_GetAlarm(&time_and_date) != RVF_OK)
208 DRV_INTERNAL_ERROR; /*ERROR*/
209 date->year = 2000+ time_and_date.year;
210 date->month = time_and_date.month;
211 date->day = time_and_date.day;
212
213 time->second = time_and_date.second;
214 time->minute = time_and_date.minute;
215 time->hour = time_and_date.hour;
216 if ( time_and_date.PM_flag == TRUE)
217 time->format = RTC_TIME_FORMAT_12HOUR;
218 else
219 time->format = RTC_TIME_FORMAT_24HOUR;
220 time->PM_flag = time_and_date.PM_flag;
221 return DRV_OK;
222 #endif /* _SIMULATION_ */
223 }
224
225 /*
226 +--------------------------------------------------------------------+
227 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
228 | STATE : code ROUTINE : rtc_unset_alarm |
229 +--------------------------------------------------------------------+
230
231 PURPOSE : unset alarm
232
233
234 */
235 UBYTE rtc_unset_alarm()
236 {
237 #ifndef _SIMULATION_
238 return RTC_UnsetAlarm();
239 #endif /* _SIMULATION_ */
240 }
241 /*
242 +--------------------------------------------------------------------+
243 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
244 | STATE : code ROUTINE : rtc_set_time_format |
245 +--------------------------------------------------------------------+
246
247 PURPOSE : unset alarm
248
249
250 */
251 UBYTE rtc_set_time_format(T_RTC_TIME_FORMAT format)
252 { BOOL twelve_hour;
253
254 #ifndef _SIMULATION_
255 if (format == RTC_TIME_FORMAT_12HOUR)
256 twelve_hour = TRUE;
257 else
258 twelve_hour = FALSE;
259
260 RTC_Set12HourMode(twelve_hour);
261 #endif /* _SIMULATION_ */
262
263 return DRV_OK;
264 }
265
266 /*
267 +--------------------------------------------------------------------+
268 | PROJECT : GSM-PS (6103) MODULE : DRV_RTC |
269 | STATE : code ROUTINE : vmd_primitive |
270 +--------------------------------------------------------------------+
271
272 PURPOSE : This function get the date and time.
273 and is backawrd compatible
274 if year >= 70 then 19year
275 if year < 70 then 20year
276 */
277
278 GLOBAL UBYTE rtc_read_time ( rtc_time_type *rtc_time )
279 {
280 #ifndef _SIMULATION_
281 T_RTC_DATE_TIME time_and_date;
282 if ( rtc_time EQ NULL )
283 return ( FALSE );
284
285
286
287 if (RTC_GetDateTime(&time_and_date) != RVF_OK)
288 return FALSE;
289 rtc_time->year = time_and_date.year;
290 rtc_time->month = time_and_date.month;
291 rtc_time->day = time_and_date.day;
292
293 rtc_time->minute = time_and_date.minute;
294 rtc_time->hour = time_and_date.hour;
295 rtc_time->second = time_and_date.second;
296
297 #endif /* _SIMULATION_ */
298
299 return ( TRUE );
300 }
301
302 #endif /* #ifndef DRV_RTC_C */