1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - RTC - libraries
3   File:     internal_ex.c
4 
5   Copyright 2007-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: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #include    <twl/rtc/common/fifo_ex.h>
19 #include    <nitro/pxi.h>
20 #include	"private.h"
21 
22 /*---------------------------------------------------------------------------*
23     Internal Function Definitions
24  *---------------------------------------------------------------------------*/
25 static BOOL     RtcexSendPxiCommand(u32 command);
26 
27 /*---------------------------------------------------------------------------*
28   Name:         RTCEXi_ReadRawCounterAsync
29 
30   Description:  Asynchronously gets the unprocessed Up Counter register setting value.
31                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
32                 Data will be stored in OS_GetSystemWork()->real_time_clock.
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  *---------------------------------------------------------------------------*/
39 BOOL
RTCEXi_ReadRawCounterAsync(void)40 RTCEXi_ReadRawCounterAsync(void)
41 {
42     return RtcexSendPxiCommand(RTC_PXI_COMMAND_READ_COUNTER);
43 }
44 
45 /*---------------------------------------------------------------------------*
46   Name:         RTCEXi_ReadRawFoutAsync
47 
48   Description:  Asynchronously gets the unprocessed FOUT1/FOUT2 register setting values.
49                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
50                 Data will be stored in OS_GetSystemWork()->real_time_clock.
51 
52   Arguments:    None.
53 
54   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
55 
56  *---------------------------------------------------------------------------*/
RTCEXi_ReadRawFoutAsync(void)57 BOOL RTCEXi_ReadRawFoutAsync(void)
58 {
59     return RtcexSendPxiCommand(RTC_PXI_COMMAND_READ_FOUT);
60 }
61 
62 /*---------------------------------------------------------------------------*
63   Name:         RTCEXi_WriteRawFoutAsync
64 
65   Description:  Asynchronously writes unprocessed FOUT1/FOUT2 setting values to the device.
66                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
67                 The data in OS_GetSystemWork()->real_time_clock will be written.
68 
69   Arguments:    None.
70 
71   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
72 
73  *---------------------------------------------------------------------------*/
RTCEXi_WriteRawFoutAsync(void)74 BOOL RTCEXi_WriteRawFoutAsync(void)
75 {
76     return RtcexSendPxiCommand(RTC_PXI_COMMAND_WRITE_FOUT);
77 }
78 
79 /*---------------------------------------------------------------------------*
80   Name:         RTCEXi_ReadRawAlarmEx1Async
81 
82   Description:  Asynchronously gets the unprocessed Extended Alarm 1 register setting value.
83                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
84                 Data will be stored in OS_GetSystemWork()->real_time_clock.
85 
86   Arguments:    None.
87 
88   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
89 
90  *---------------------------------------------------------------------------*/
RTCEXi_ReadRawAlarmEx1Async(void)91 BOOL RTCEXi_ReadRawAlarmEx1Async(void)
92 {
93     return RtcexSendPxiCommand(RTC_PXI_COMMAND_READ_ALARM_EX1);
94 }
95 
96 /*---------------------------------------------------------------------------*
97   Name:         RTCEXi_WriteRawAlarmEx1Async
98 
99   Description:  Asynchronously writes the unprocessed Extended Alarm 1 register to the device.
100                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
101                 The data in OS_GetSystemWork()->real_time_clock will be written.
102 
103   Arguments:    None.
104 
105   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
106 
107  *---------------------------------------------------------------------------*/
RTCEXi_WriteRawAlarmEx1Async(void)108 BOOL RTCEXi_WriteRawAlarmEx1Async(void)
109 {
110     return RtcexSendPxiCommand(RTC_PXI_COMMAND_WRITE_ALARM_EX1);
111 }
112 
113 /*---------------------------------------------------------------------------*
114   Name:         RTCEXi_ReadRawAlarmEx2Async
115 
116   Description:  Asynchronously gets the unprocessed Extended Alarm �Q register setting value.
117                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
118                 Data will be stored in OS_GetSystemWork()->real_time_clock.
119 
120   Arguments:    None.
121 
122   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
123 
124  *---------------------------------------------------------------------------*/
RTCEXi_ReadRawAlarmEx2Async(void)125 BOOL RTCEXi_ReadRawAlarmEx2Async(void)
126 {
127     return RtcexSendPxiCommand(RTC_PXI_COMMAND_READ_ALARM_EX2);
128 }
129 
130 /*---------------------------------------------------------------------------*
131   Name:         RTCEXi_WriteRawAlarmEx2Async
132 
133   Description:  Asynchronously writes the unprocessed Extended Alarm �Q register to the device.
134                 The notification of a response from ARM7 is done by the PXI callback (tag:RTC).
135                 The data in OS_GetSystemWork()->real_time_clock will be written.
136 
137   Arguments:    None.
138 
139   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
140 
141  *---------------------------------------------------------------------------*/
RTCEXi_WriteRawAlarmEx2Async(void)142 BOOL RTCEXi_WriteRawAlarmEx2Async(void)
143 {
144     return RtcexSendPxiCommand(RTC_PXI_COMMAND_WRITE_ALARM_EX2);
145 }
146 
147 /*---------------------------------------------------------------------------*
148   Name:         RtcexSendPxiCommand
149 
150   Description:  Send specified command to ARM7 via PXI.
151 
152   Arguments:    None.
153 
154   Returns:      BOOL     - Returns TRUE if a send for PXI completed, and FALSE if send by PXI failed.
155 
156  *---------------------------------------------------------------------------*/
RtcexSendPxiCommand(u32 command)157 static BOOL RtcexSendPxiCommand(u32 command)
158 {
159     if (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_RTC,
160                                ((command << RTC_PXI_COMMAND_SHIFT) & RTC_PXI_COMMAND_MASK), 0))
161     {
162         return FALSE;
163     }
164     return TRUE;
165 }
166