CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
aon_rtc.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: aon_rtc.c
3 * Revised: 2015-01-13 16:59:55 +0100 (ti, 13 jan 2015)
4 * Revision: 42365
5 *
6 * Description: Driver for the AON RTC.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 #include <driverlib/aon_rtc.h>
40 
41 //*****************************************************************************
42 //
43 // Handle support for DriverLib in ROM:
44 // This section will undo prototype renaming made in the header file
45 //
46 //*****************************************************************************
47 #ifndef DRIVERLIB_GENERATE_ROM
48  #undef AONRTCStatus
49  #define AONRTCStatus NOROM_AONRTCStatus
50  #undef AONRTCEventClear
51  #define AONRTCEventClear NOROM_AONRTCEventClear
52  #undef AONRTCEventGet
53  #define AONRTCEventGet NOROM_AONRTCEventGet
54  #undef AONRTCModeCh1Set
55  #define AONRTCModeCh1Set NOROM_AONRTCModeCh1Set
56  #undef AONRTCModeCh1Get
57  #define AONRTCModeCh1Get NOROM_AONRTCModeCh1Get
58  #undef AONRTCModeCh2Set
59  #define AONRTCModeCh2Set NOROM_AONRTCModeCh2Set
60  #undef AONRTCModeCh2Get
61  #define AONRTCModeCh2Get NOROM_AONRTCModeCh2Get
62  #undef AONRTCChannelEnable
63  #define AONRTCChannelEnable NOROM_AONRTCChannelEnable
64  #undef AONRTCChannelDisable
65  #define AONRTCChannelDisable NOROM_AONRTCChannelDisable
66  #undef AONRTCCompareValueSet
67  #define AONRTCCompareValueSet NOROM_AONRTCCompareValueSet
68  #undef AONRTCCompareValueGet
69  #define AONRTCCompareValueGet NOROM_AONRTCCompareValueGet
70 #endif
71 
72 //*****************************************************************************
73 //
75 //
76 //*****************************************************************************
77 uint32_t
79 {
80  uint32_t ui32ChannelStatus;
81  uint32_t ui32RtcStatus;
82 
83  //
84  // Read out the status'
85  //
86  ui32ChannelStatus = HWREG(AON_RTC_BASE + AON_RTC_O_CHCTL);
87  ui32RtcStatus = HWREG(AON_RTC_BASE + AON_RTC_O_CTL) &
89 
90  //
91  // Return the status
92  //
93  ui32RtcStatus |= (ui32ChannelStatus & AON_RTC_CHCTL_CH2_EN ?
94  AON_RTC_CH2 : 0) |
95  (ui32ChannelStatus & AON_RTC_CHCTL_CH1_EN ?
96  AON_RTC_CH1 : 0) |
97  (ui32ChannelStatus & AON_RTC_CHCTL_CH0_EN ?
98  AON_RTC_CH0 : 0);
99  return ui32RtcStatus;
100 }
101 
102 //*****************************************************************************
103 //
105 //
106 //*****************************************************************************
107 void
108 AONRTCEventClear(uint32_t ui32Channel)
109 {
110  //
111  // Check the arguments.
112  //
113  ASSERT((ui32Channel == AON_RTC_CH0) ||
114  (ui32Channel == AON_RTC_CH1) ||
115  (ui32Channel == AON_RTC_CH2));
116 
117  if(ui32Channel & AON_RTC_CH0)
118  {
120  }
121  else if(ui32Channel & AON_RTC_CH1)
122  {
124  }
125  else if(ui32Channel & AON_RTC_CH2)
126  {
128  }
129 }
130 
131 //*****************************************************************************
132 //
134 //
135 //*****************************************************************************
136 bool
137 AONRTCEventGet(uint32_t ui32Channel)
138 {
139  //
140  // Check the arguments.
141  //
142  ASSERT((ui32Channel == AON_RTC_CH0) ||
143  (ui32Channel == AON_RTC_CH1) ||
144  (ui32Channel == AON_RTC_CH2));
145 
146  if(ui32Channel & AON_RTC_CH0)
147  {
148  return ((HWREG(AON_RTC_BASE + AON_RTC_O_EVFLAGS) &
149  AON_RTC_EVFLAGS_CH0) ? true : false);
150  }
151  else if(ui32Channel & AON_RTC_CH1)
152  {
153  return ((HWREG(AON_RTC_BASE + AON_RTC_O_EVFLAGS) &
154  AON_RTC_EVFLAGS_CH1) ? true : false);
155  }
156  else if(ui32Channel & AON_RTC_CH2)
157  {
158  return ((HWREG(AON_RTC_BASE + AON_RTC_O_EVFLAGS) &
159  AON_RTC_EVFLAGS_CH2) ? true : false);
160  }
161 
162  return(false);
163 }
164 
165 //*****************************************************************************
166 //
168 //
169 //*****************************************************************************
170 void
171 AONRTCModeCh1Set(uint32_t ui32Mode)
172 {
173  //
174  // Check the arguments.
175  //
176  ASSERT((ui32Mode == AON_RTC_MODE_CH1_CAPTURE) ||
177  (ui32Mode == AON_RTC_MODE_CH1_COMPARE));
178 
179  if(ui32Mode == AON_RTC_MODE_CH1_CAPTURE)
180  {
182  }
183  else if(ui32Mode == AON_RTC_MODE_CH1_COMPARE)
184  {
186  }
187 }
188 
189 //*****************************************************************************
190 //
192 //
193 //*****************************************************************************
194 uint32_t
196 {
198  {
199  return(AON_RTC_MODE_CH1_CAPTURE);
200  }
201  else
202  {
203  return(AON_RTC_MODE_CH1_COMPARE);
204  }
205 }
206 
207 //*****************************************************************************
208 //
210 //
211 //*****************************************************************************
212 void
213 AONRTCModeCh2Set(uint32_t ui32Mode)
214 {
215  //
216  // Check the arguments.
217  //
218  ASSERT((ui32Mode == AON_RTC_MODE_CH2_CONTINUOUS) ||
219  (ui32Mode == AON_RTC_MODE_CH2_NORMALCOMPARE));
220 
221  if(ui32Mode == AON_RTC_MODE_CH2_CONTINUOUS)
222  {
224  }
225  else if(ui32Mode == AON_RTC_MODE_CH2_NORMALCOMPARE)
226  {
228  }
229 }
230 
231 //*****************************************************************************
232 //
234 //
235 //*****************************************************************************
236 uint32_t
238 {
240  {
242  }
243  else
244  {
246  }
247 }
248 
249 //*****************************************************************************
250 //
252 //
253 //*****************************************************************************
254 void
255 AONRTCChannelEnable(uint32_t ui32Channel)
256 {
257  //
258  // Check the arguments.
259  //
260  ASSERT((ui32Channel == AON_RTC_CH0) ||
261  (ui32Channel == AON_RTC_CH1) ||
262  (ui32Channel == AON_RTC_CH2));
263 
264  if(ui32Channel & AON_RTC_CH0)
265  {
267  }
268  else if(ui32Channel & AON_RTC_CH1)
269  {
271  }
272  else if(ui32Channel & AON_RTC_CH2)
273  {
275  }
276 }
277 
278 //*****************************************************************************
279 //
281 //
282 //*****************************************************************************
283 void
284 AONRTCChannelDisable(uint32_t ui32Channel)
285 {
286  //
287  // Check the arguments.
288  //
289  ASSERT((ui32Channel == AON_RTC_CH0) ||
290  (ui32Channel == AON_RTC_CH1) ||
291  (ui32Channel == AON_RTC_CH2));
292 
293  if(ui32Channel & AON_RTC_CH0)
294  {
296  }
297  else if(ui32Channel & AON_RTC_CH1)
298  {
300  }
301  else if(ui32Channel & AON_RTC_CH2)
302  {
304  }
305 }
306 
307 //*****************************************************************************
308 //
310 //
311 //*****************************************************************************
312 void
313 AONRTCCompareValueSet(uint32_t ui32Channel, uint32_t ui32CompValue)
314 {
315  //
316  // Check the arguments.
317  //
318  ASSERT((ui32Channel == AON_RTC_CH0) ||
319  (ui32Channel == AON_RTC_CH1) ||
320  (ui32Channel == AON_RTC_CH2));
321 
322  if(ui32Channel & AON_RTC_CH0)
323  {
324  HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP) = ui32CompValue;
325  }
326  else if(ui32Channel & AON_RTC_CH1)
327  {
328  HWREG(AON_RTC_BASE + AON_RTC_O_CH1CMP) = ui32CompValue;
329  }
330  else if(ui32Channel & AON_RTC_CH2)
331  {
332  HWREG(AON_RTC_BASE + AON_RTC_O_CH2CMP) = ui32CompValue;
333  }
334 }
335 
336 //*****************************************************************************
337 //
339 //
340 //*****************************************************************************
341 uint32_t
342 AONRTCCompareValueGet(uint32_t ui32Channel)
343 {
344  //
345  // Check the arguments
346  //
347  ASSERT((ui32Channel == AON_RTC_CH0) ||
348  (ui32Channel == AON_RTC_CH1) ||
349  (ui32Channel == AON_RTC_CH2));
350 
351  if(ui32Channel & AON_RTC_CH0)
352  {
353  return(HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP));
354  }
355  else if(ui32Channel & AON_RTC_CH1)
356  {
357  return(HWREG(AON_RTC_BASE + AON_RTC_O_CH1CMP));
358  }
359  else if(ui32Channel & AON_RTC_CH2)
360  {
361  return(HWREG(AON_RTC_BASE + AON_RTC_O_CH2CMP));
362  }
363  //
364  // Should never return from here!
365  //
366  return(0);
367 }
#define AON_RTC_ACTIVE
Definition: aon_rtc.h:106
#define AON_RTC_CH1
Definition: aon_rtc.h:104
uint32_t AONRTCModeCh1Get(void)
Get operational mode of channel 1.
Definition: aon_rtc.c:195
void AONRTCCompareValueSet(uint32_t ui32Channel, uint32_t ui32CompValue)
Set the compare value for the given channel.
Definition: aon_rtc.c:313
bool AONRTCEventGet(uint32_t ui32Channel)
Get event status for a specified channel.
Definition: aon_rtc.c:137
uint32_t AONRTCCompareValueGet(uint32_t ui32Channel)
Get the compare value for the given channel.
Definition: aon_rtc.c:342
void AONRTCModeCh2Set(uint32_t ui32Mode)
Set operational mode of channel 2.
Definition: aon_rtc.c:213
#define ASSERT(expr)
Definition: debug.h:65
void AONRTCChannelDisable(uint32_t ui32Channel)
Disable event operation for the specified channel.
Definition: aon_rtc.c:284
#define AON_RTC_CH2
Definition: aon_rtc.h:105
#define AON_RTC_MODE_CH1_CAPTURE
Definition: aon_rtc.h:136
uint32_t AONRTCStatus(void)
Check if the AON Real Time Clock is running.
Definition: aon_rtc.c:78
#define AON_RTC_CH0
Definition: aon_rtc.h:103
uint32_t AONRTCModeCh2Get(void)
Get operational mode of channel 2.
Definition: aon_rtc.c:237
#define AON_RTC_MODE_CH2_NORMALCOMPARE
Definition: aon_rtc.h:146
#define AON_RTC_MODE_CH1_COMPARE
Definition: aon_rtc.h:137
void AONRTCEventClear(uint32_t ui32Channel)
Clear event from a specified channel.
Definition: aon_rtc.c:108
void AONRTCModeCh1Set(uint32_t ui32Mode)
Set operational mode of channel 1.
Definition: aon_rtc.c:171
void AONRTCChannelEnable(uint32_t ui32Channel)
Enable event operation for the specified channel.
Definition: aon_rtc.c:255
#define AON_RTC_MODE_CH2_CONTINUOUS
Definition: aon_rtc.h:145