1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - RTC - libraries
3   File:     internal.c
4 
5   Copyright 2003-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-18#$
14   $Rev: 8573 $
15   $Author:$
16  *---------------------------------------------------------------------------*/
17 
18 #include	<nitro/rtc/ARM9/api.h>
19 #include	<nitro/pxi.h>
20 
21 
22 /*---------------------------------------------------------------------------*
23 	Internal Function Definitions
24  *---------------------------------------------------------------------------*/
25 static BOOL RtcSendPxiCommand(u32 command);
26 
27 
28 /*---------------------------------------------------------------------------*
29   Name:         RTCi_ResetAsync
30 
31   Description:  Asynchronously reset RTC.
32                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
33 
34   Arguments:    None.
35 
36   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
37 
38  *---------------------------------------------------------------------------*/
RTCi_ResetAsync(void)39 BOOL RTCi_ResetAsync(void)
40 {
41     return RtcSendPxiCommand(RTC_PXI_COMMAND_RESET);
42 }
43 
44 /*---------------------------------------------------------------------------*
45   Name:         RTCi_SetHourFormatAsync
46 
47   Description:  Asynchronously change the time format.
48                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
49                 Sets arguments with status1 in OS_GetSystemWork()->real_time_clock.
50 
51   Arguments:    None.
52 
53   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
54 
55  *---------------------------------------------------------------------------*/
RTCi_SetHourFormatAsync(void)56 BOOL RTCi_SetHourFormatAsync(void)
57 {
58     return RtcSendPxiCommand(RTC_PXI_COMMAND_SET_HOUR_FORMAT);
59 }
60 
61 /*---------------------------------------------------------------------------*
62   Name:         RTCi_ReadRawDateTimeAsync
63 
64   Description:  Asynchronously obtain unprocessed date/time data.
65                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
66                 Data will be stored in OS_GetSystemWork()->real_time_clock.
67 
68   Arguments:    None.
69 
70   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
71 
72  *---------------------------------------------------------------------------*/
RTCi_ReadRawDateTimeAsync(void)73 BOOL RTCi_ReadRawDateTimeAsync(void)
74 {
75     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_DATETIME);
76 }
77 
78 /*---------------------------------------------------------------------------*
79   Name:         RTCi_WriteRawDateTimeAsync
80 
81   Description:  Asynchronously write unprocessed date/time data to device.
82                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
83                 The data in OS_GetSystemWork()->real_time_clock will be written.
84 
85   Arguments:    None.
86 
87   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
88 
89  *---------------------------------------------------------------------------*/
RTCi_WriteRawDateTimeAsync(void)90 BOOL RTCi_WriteRawDateTimeAsync(void)
91 {
92     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_DATETIME);
93 }
94 
95 /*---------------------------------------------------------------------------*
96   Name:         RTCi_ReadRawDateAsync
97 
98   Description:  Asynchronously obtain unprocessed date data.
99                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
100                 Data will be stored in OS_GetSystemWork()->real_time_clock.
101 
102   Arguments:    None.
103 
104   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
105 
106  *---------------------------------------------------------------------------*/
RTCi_ReadRawDateAsync(void)107 BOOL RTCi_ReadRawDateAsync(void)
108 {
109     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_DATE);
110 }
111 
112 /*---------------------------------------------------------------------------*
113   Name:         RTCi_WriteRawDateAsync
114 
115   Description:  Asynchronously write unprocessed date data to device.
116                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
117                 The data in OS_GetSystemWork()->real_time_clock will be written.
118 
119   Arguments:    None.
120 
121   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
122 
123  *---------------------------------------------------------------------------*/
RTCi_WriteRawDateAsync(void)124 BOOL RTCi_WriteRawDateAsync(void)
125 {
126     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_DATE);
127 }
128 
129 /*---------------------------------------------------------------------------*
130   Name:         RTCi_ReadRawTimeAsync
131 
132   Description:  Asynchronously obtain unprocessed time data.
133                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
134                 Data will be stored in OS_GetSystemWork()->real_time_clock.
135 
136   Arguments:    None.
137 
138   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
139 
140  *---------------------------------------------------------------------------*/
RTCi_ReadRawTimeAsync(void)141 BOOL RTCi_ReadRawTimeAsync(void)
142 {
143     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_TIME);
144 }
145 
146 /*---------------------------------------------------------------------------*
147   Name:         RTCi_WriteRawTimeAsync
148 
149   Description:  Asynchronously write unprocessed time data to device.
150                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
151                 The data in OS_GetSystemWork()->real_time_clock will be written.
152 
153   Arguments:    None.
154 
155   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
156 
157  *---------------------------------------------------------------------------*/
RTCi_WriteRawTimeAsync(void)158 BOOL RTCi_WriteRawTimeAsync(void)
159 {
160     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_TIME);
161 }
162 
163 /*---------------------------------------------------------------------------*
164   Name:         RTCi_ReadRawPulseAsync
165 
166   Description:  Asynchronously obtain steady interrupt setting values for unprocessed frequencies.
167                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
168                 Data will be stored in OS_GetSystemWork()->real_time_clock.
169 
170   Arguments:    None.
171 
172   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
173 
174  *---------------------------------------------------------------------------*/
RTCi_ReadRawPulseAsync(void)175 BOOL RTCi_ReadRawPulseAsync(void)
176 {
177     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_PULSE);
178 }
179 
180 /*---------------------------------------------------------------------------*
181   Name:         RTCi_WriteRawPulseAsync
182 
183   Description:  Asynchronously write steady interrupt setting values for unprocessed frequencies to device.
184                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
185                 The data in OS_GetSystemWork()->real_time_clock will be written.
186 
187   Arguments:    None.
188 
189   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
190 
191  *---------------------------------------------------------------------------*/
RTCi_WriteRawPulseAsync(void)192 BOOL RTCi_WriteRawPulseAsync(void)
193 {
194     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_PULSE);
195 }
196 
197 /*---------------------------------------------------------------------------*
198   Name:         RTCi_ReadRawAlarm1Async
199 
200   Description:  Asynchronously obtains unprocessed alarm 1 interrupt setting values.
201                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
202                 Data will be stored in OS_GetSystemWork()->real_time_clock.
203 
204   Arguments:    None.
205 
206   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
207 
208  *---------------------------------------------------------------------------*/
RTCi_ReadRawAlarm1Async(void)209 BOOL RTCi_ReadRawAlarm1Async(void)
210 {
211     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_ALARM1);
212 }
213 
214 /*---------------------------------------------------------------------------*
215   Name:         RTCi_WriteRawAlarm1Async
216 
217   Description:  Asynchronously writes unprocessed alarm 1 interrupt setting values to the device.
218                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
219                 The data in OS_GetSystemWork()->real_time_clock will be written.
220 
221   Arguments:    None.
222 
223   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
224 
225  *---------------------------------------------------------------------------*/
RTCi_WriteRawAlarm1Async(void)226 BOOL RTCi_WriteRawAlarm1Async(void)
227 {
228     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_ALARM1);
229 }
230 
231 /*---------------------------------------------------------------------------*
232   Name:         RTCi_ReadRawAlarm2Async
233 
234   Description:  Asynchronously obtains unprocessed alarm 2 interrupt setting values.
235                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
236                 Data will be stored in OS_GetSystemWork()->real_time_clock.
237 
238   Arguments:    None.
239 
240   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
241 
242  *---------------------------------------------------------------------------*/
RTCi_ReadRawAlarm2Async(void)243 BOOL RTCi_ReadRawAlarm2Async(void)
244 {
245     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_ALARM2);
246 }
247 
248 /*---------------------------------------------------------------------------*
249   Name:         RTCi_WriteRawAlarm2Async
250 
251   Description:  Asynchronously writes unprocessed alarm 2 interrupt setting values to the device.
252                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
253                 The data in OS_GetSystemWork()->real_time_clock will be written.
254 
255   Arguments:    None.
256 
257   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
258 
259  *---------------------------------------------------------------------------*/
RTCi_WriteRawAlarm2Async(void)260 BOOL RTCi_WriteRawAlarm2Async(void)
261 {
262     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_ALARM2);
263 }
264 
265 /*---------------------------------------------------------------------------*
266   Name:         RTCi_ReadRawStatus1Async
267 
268   Description:  Asynchronously obtains unprocessed status 1 register setting values.
269                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
270                 Data will be stored in OS_GetSystemWork()->real_time_clock.
271 
272   Arguments:    None.
273 
274   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
275 
276  *---------------------------------------------------------------------------*/
RTCi_ReadRawStatus1Async(void)277 BOOL RTCi_ReadRawStatus1Async(void)
278 {
279     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_STATUS1);
280 }
281 
282 /*---------------------------------------------------------------------------*
283   Name:         RTCi_WriteRawStatus1Async
284 
285   Description:  Asynchronously writes unprocessed status 1 register setting values to the device.
286                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
287                 The data in OS_GetSystemWork()->real_time_clock will be written.
288 
289   Arguments:    None.
290 
291   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
292 
293  *---------------------------------------------------------------------------*/
RTCi_WriteRawStatus1Async(void)294 BOOL RTCi_WriteRawStatus1Async(void)
295 {
296     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_STATUS1);
297 }
298 
299 /*---------------------------------------------------------------------------*
300   Name:         RTCi_ReadRawStatus2Async
301 
302   Description:  Asynchronously obtains unprocessed status 2 register setting values.
303                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
304                 Data will be stored in OS_GetSystemWork()->real_time_clock.
305 
306   Arguments:    None.
307 
308   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
309 
310  *---------------------------------------------------------------------------*/
RTCi_ReadRawStatus2Async(void)311 BOOL RTCi_ReadRawStatus2Async(void)
312 {
313     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_STATUS2);
314 }
315 
316 /*---------------------------------------------------------------------------*
317   Name:         RTCi_WriteRawStatus2Async
318 
319   Description:  Asynchronously writes unprocessed status 2 register setting values to the device.
320                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
321                 The data in OS_GetSystemWork()->real_time_clock will be written.
322 
323   Arguments:    None.
324 
325   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
326 
327  *---------------------------------------------------------------------------*/
RTCi_WriteRawStatus2Async(void)328 BOOL RTCi_WriteRawStatus2Async(void)
329 {
330     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_STATUS2);
331 }
332 
333 /*---------------------------------------------------------------------------*
334   Name:         RTCi_ReadRawAdjustAsync
335 
336   Description:  Asynchronously obtain unprocessed clock adjustment register setting values.
337                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
338                 Data will be stored in OS_GetSystemWork()->real_time_clock.
339 
340   Arguments:    None.
341 
342   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
343 
344  *---------------------------------------------------------------------------*/
RTCi_ReadRawAdjustAsync(void)345 BOOL RTCi_ReadRawAdjustAsync(void)
346 {
347     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_ADJUST);
348 }
349 
350 /*---------------------------------------------------------------------------*
351   Name:         RTCi_WriteRawAdjustAsync
352 
353   Description:  Asynchronously write unprocessed clock adjustment register setting values to device.
354                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
355                 The data in OS_GetSystemWork()->real_time_clock will be written.
356 
357   Arguments:    None.
358 
359   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
360 
361  *---------------------------------------------------------------------------*/
RTCi_WriteRawAdjustAsync(void)362 BOOL RTCi_WriteRawAdjustAsync(void)
363 {
364     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_ADJUST);
365 }
366 
367 /*---------------------------------------------------------------------------*
368   Name:         RTCi_ReadRawFreeAsync
369 
370   Description:  Asynchronously obtain unprocessed free register setting values.
371                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
372                 Data will be stored in OS_GetSystemWork()->real_time_clock.
373 
374   Arguments:    None.
375 
376   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
377 
378  *---------------------------------------------------------------------------*/
RTCi_ReadRawFreeAsync(void)379 BOOL RTCi_ReadRawFreeAsync(void)
380 {
381     return RtcSendPxiCommand(RTC_PXI_COMMAND_READ_FREE);
382 }
383 
384 /*---------------------------------------------------------------------------*
385   Name:         RTCi_WriteRawFreeAsync
386 
387   Description:  Asynchronously write unprocessed free register setting values to device.
388                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
389                 The data in OS_GetSystemWork()->real_time_clock will be written.
390 
391   Arguments:    None.
392 
393   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
394 
395  *---------------------------------------------------------------------------*/
RTCi_WriteRawFreeAsync(void)396 BOOL RTCi_WriteRawFreeAsync(void)
397 {
398     return RtcSendPxiCommand(RTC_PXI_COMMAND_WRITE_FREE);
399 }
400 
401 /*---------------------------------------------------------------------------*
402   Name:         RtcSendPxiCommand
403 
404   Description:  Send specified command to ARM7 via PXI.
405 
406   Arguments:    None.
407 
408   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
409 
410  *---------------------------------------------------------------------------*/
RtcSendPxiCommand(u32 command)411 static BOOL RtcSendPxiCommand(u32 command)
412 {
413     if (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_RTC,
414                                ((command << RTC_PXI_COMMAND_SHIFT) & RTC_PXI_COMMAND_MASK), 0))
415     {
416         return FALSE;
417     }
418     return TRUE;
419 }
420 
421 /*---------------------------------------------------------------------------*
422   End of file
423  *---------------------------------------------------------------------------*/
424