2 * Copyright (c) 2014, Texas Instruments Incorporated
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
9 * * Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\r
12 * * Redistributions in binary form must reproduce the above copyright
\r
13 * notice, this list of conditions and the following disclaimer in the
\r
14 * documentation and/or other materials provided with the distribution.
\r
16 * * Neither the name of Texas Instruments Incorporated nor the names of
\r
17 * its contributors may be used to endorse or promote products derived
\r
18 * from this software without specific prior written permission.
\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
\r
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
\r
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
\r
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 //*****************************************************************************
\r
34 // rtc_b.c - Driver for the rtc_b Module.
\r
36 //*****************************************************************************
\r
38 //*****************************************************************************
\r
40 //! \addtogroup rtc_b_api rtc_b
\r
43 //*****************************************************************************
\r
45 #include "inc/hw_regaccess.h"
\r
46 #include "inc/hw_memmap.h"
\r
48 #ifdef __MSP430_HAS_RTC_B__
\r
53 void RTC_B_startClock(uint16_t baseAddress)
\r
55 HWREG8(baseAddress + OFS_RTCCTL01_H) &= ~(RTCHOLD_H);
\r
58 void RTC_B_holdClock(uint16_t baseAddress)
\r
60 HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCHOLD_H;
\r
63 void RTC_B_setCalibrationFrequency(uint16_t baseAddress,
\r
64 uint16_t frequencySelect)
\r
66 HWREG16(baseAddress + OFS_RTCCTL23) &= ~(RTCCALF_3);
\r
67 HWREG16(baseAddress + OFS_RTCCTL23) |= frequencySelect;
\r
70 void RTC_B_setCalibrationData(uint16_t baseAddress,
\r
71 uint8_t offsetDirection,
\r
72 uint8_t offsetValue)
\r
74 HWREG8(baseAddress + OFS_RTCCTL23_L) = offsetValue + offsetDirection;
\r
77 void RTC_B_initCalendar(uint16_t baseAddress,
\r
78 Calendar *CalendarTime,
\r
79 uint16_t formatSelect)
\r
81 HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCHOLD_H;
\r
83 HWREG16(baseAddress + OFS_RTCCTL01) &= ~(RTCBCD);
\r
84 HWREG16(baseAddress + OFS_RTCCTL01) |= formatSelect;
\r
86 HWREG8(baseAddress + OFS_RTCTIM0_L) = CalendarTime->Seconds;
\r
87 HWREG8(baseAddress + OFS_RTCTIM0_H) = CalendarTime->Minutes;
\r
88 HWREG8(baseAddress + OFS_RTCTIM1_L) = CalendarTime->Hours;
\r
89 HWREG8(baseAddress + OFS_RTCTIM1_H) = CalendarTime->DayOfWeek;
\r
90 HWREG8(baseAddress + OFS_RTCDATE_L) = CalendarTime->DayOfMonth;
\r
91 HWREG8(baseAddress + OFS_RTCDATE_H) = CalendarTime->Month;
\r
92 HWREG16(baseAddress + OFS_RTCYEAR) = CalendarTime->Year;
\r
95 Calendar RTC_B_getCalendarTime(uint16_t baseAddress)
\r
99 while(!(HWREG16(baseAddress + OFS_RTCCTL01) & RTCRDY))
\r
104 tempCal.Seconds = HWREG8(baseAddress + OFS_RTCTIM0_L);
\r
105 tempCal.Minutes = HWREG8(baseAddress + OFS_RTCTIM0_H);
\r
106 tempCal.Hours = HWREG8(baseAddress + OFS_RTCTIM1_L);
\r
107 tempCal.DayOfWeek = HWREG8(baseAddress + OFS_RTCTIM1_H);
\r
108 tempCal.DayOfMonth = HWREG8(baseAddress + OFS_RTCDATE_L);
\r
109 tempCal.Month = HWREG8(baseAddress + OFS_RTCDATE_H);
\r
110 tempCal.Year = HWREG16(baseAddress + OFS_RTCYEAR);
\r
115 void RTC_B_configureCalendarAlarm(uint16_t baseAddress,
\r
116 RTC_B_configureCalendarAlarmParam *param)
\r
118 //Each of these is XORed with 0x80 to turn on if an integer is passed,
\r
119 //or turn OFF if RTC_B_ALARM_OFF (0x80) is passed.
\r
120 HWREG8(baseAddress + OFS_RTCAMINHR_L) = (param->minutesAlarm ^ 0x80);
\r
121 HWREG8(baseAddress + OFS_RTCAMINHR_H) = (param->hoursAlarm ^ 0x80);
\r
122 HWREG8(baseAddress + OFS_RTCADOWDAY_L) = (param->dayOfWeekAlarm ^ 0x80);
\r
123 HWREG8(baseAddress + OFS_RTCADOWDAY_H) = (param->dayOfMonthAlarm ^ 0x80);
\r
126 void RTC_B_setCalendarEvent(uint16_t baseAddress,
\r
127 uint16_t eventSelect)
\r
129 HWREG16(baseAddress + OFS_RTCCTL01) &= ~(RTCTEV_3); //Reset bits
\r
130 HWREG16(baseAddress + OFS_RTCCTL01) |= eventSelect;
\r
133 void RTC_B_definePrescaleEvent(uint16_t baseAddress,
\r
134 uint8_t prescaleSelect,
\r
135 uint8_t prescaleEventDivider)
\r
137 HWREG8(baseAddress + OFS_RTCPS0CTL_L + prescaleSelect) &= ~(RT0IP_7);
\r
138 HWREG8(baseAddress + OFS_RTCPS0CTL_L +
\r
139 prescaleSelect) |= prescaleEventDivider;
\r
142 uint8_t RTC_B_getPrescaleValue(uint16_t baseAddress,
\r
143 uint8_t prescaleSelect)
\r
145 if(RTC_B_PRESCALE_0 == prescaleSelect)
\r
147 return (HWREG8(baseAddress + OFS_RTCPS_L));
\r
149 else if(RTC_B_PRESCALE_1 == prescaleSelect)
\r
151 return (HWREG8(baseAddress + OFS_RTCPS_H));
\r
159 void RTC_B_setPrescaleValue(uint16_t baseAddress,
\r
160 uint8_t prescaleSelect,
\r
161 uint8_t prescaleCounterValue)
\r
163 if(RTC_B_PRESCALE_0 == prescaleSelect)
\r
165 HWREG8(baseAddress + OFS_RTCPS_L) = prescaleCounterValue;
\r
167 else if(RTC_B_PRESCALE_1 == prescaleSelect)
\r
169 HWREG8(baseAddress + OFS_RTCPS_H) = prescaleCounterValue;
\r
173 void RTC_B_enableInterrupt(uint16_t baseAddress,
\r
174 uint8_t interruptMask)
\r
176 if(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE))
\r
178 HWREG8(baseAddress + OFS_RTCCTL01_L) |=
\r
179 (interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE));
\r
182 if(interruptMask & RTC_B_PRESCALE_TIMER0_INTERRUPT)
\r
184 HWREG8(baseAddress + OFS_RTCPS0CTL) |= RT0PSIE;
\r
187 if(interruptMask & RTC_B_PRESCALE_TIMER1_INTERRUPT)
\r
189 HWREG8(baseAddress + OFS_RTCPS1CTL) |= RT1PSIE;
\r
193 void RTC_B_disableInterrupt(uint16_t baseAddress,
\r
194 uint8_t interruptMask)
\r
196 if(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE))
\r
198 HWREG8(baseAddress + OFS_RTCCTL01_L) &=
\r
199 ~(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE));
\r
202 if(interruptMask & RTC_B_PRESCALE_TIMER0_INTERRUPT)
\r
204 HWREG8(baseAddress + OFS_RTCPS0CTL) &= ~(RT0PSIE);
\r
207 if(interruptMask & RTC_B_PRESCALE_TIMER1_INTERRUPT)
\r
209 HWREG8(baseAddress + OFS_RTCPS1CTL) &= ~(RT1PSIE);
\r
213 uint8_t RTC_B_getInterruptStatus(uint16_t baseAddress,
\r
214 uint8_t interruptFlagMask)
\r
216 uint8_t tempInterruptFlagMask = 0x0000;
\r
218 tempInterruptFlagMask |= (HWREG8(baseAddress + OFS_RTCCTL01_L)
\r
219 & ((interruptFlagMask >> 4)
\r
225 tempInterruptFlagMask = tempInterruptFlagMask << 4;
\r
227 if(interruptFlagMask & RTC_B_PRESCALE_TIMER0_INTERRUPT)
\r
229 if(HWREG8(baseAddress + OFS_RTCPS0CTL) & RT0PSIFG)
\r
231 tempInterruptFlagMask |= RTC_B_PRESCALE_TIMER0_INTERRUPT;
\r
235 if(interruptFlagMask & RTC_B_PRESCALE_TIMER1_INTERRUPT)
\r
237 if(HWREG8(baseAddress + OFS_RTCPS1CTL) & RT1PSIFG)
\r
239 tempInterruptFlagMask |= RTC_B_PRESCALE_TIMER1_INTERRUPT;
\r
243 return (tempInterruptFlagMask);
\r
246 void RTC_B_clearInterrupt(uint16_t baseAddress,
\r
247 uint8_t interruptFlagMask)
\r
249 if(interruptFlagMask & (RTC_B_TIME_EVENT_INTERRUPT +
\r
250 RTC_B_CLOCK_ALARM_INTERRUPT +
\r
251 RTC_B_CLOCK_READ_READY_INTERRUPT +
\r
252 RTC_B_OSCILLATOR_FAULT_INTERRUPT))
\r
254 HWREG8(baseAddress + OFS_RTCCTL01_L) &=
\r
255 ~((interruptFlagMask >> 4) & (RTCOFIFG +
\r
261 if(interruptFlagMask & RTC_B_PRESCALE_TIMER0_INTERRUPT)
\r
263 HWREG8(baseAddress + OFS_RTCPS0CTL) &= ~(RT0PSIFG);
\r
266 if(interruptFlagMask & RTC_B_PRESCALE_TIMER1_INTERRUPT)
\r
268 HWREG8(baseAddress + OFS_RTCPS1CTL) &= ~(RT1PSIFG);
\r
272 uint16_t RTC_B_convertBCDToBinary(uint16_t baseAddress,
\r
273 uint16_t valueToConvert)
\r
275 HWREG16(baseAddress + OFS_BCD2BIN) = valueToConvert;
\r
276 return (HWREG16(baseAddress + OFS_BCD2BIN));
\r
279 uint16_t RTC_B_convertBinaryToBCD(uint16_t baseAddress,
\r
280 uint16_t valueToConvert)
\r
282 HWREG16(baseAddress + OFS_BIN2BCD) = valueToConvert;
\r
283 return (HWREG16(baseAddress + OFS_BIN2BCD));
\r
287 //*****************************************************************************
\r
289 //! Close the doxygen group for rtc_b_api
\r
292 //*****************************************************************************
\r