Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_rtc.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file rtc.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V3.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 7 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 15/08/11 10:26a $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief M451 series RTC driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #include "M451Series.h" |
sahilmgandhi | 18:6a4db94011d3 | 12 | |
sahilmgandhi | 18:6a4db94011d3 | 13 | |
sahilmgandhi | 18:6a4db94011d3 | 14 | /// @cond HIDDEN_SYMBOLS |
sahilmgandhi | 18:6a4db94011d3 | 15 | |
sahilmgandhi | 18:6a4db94011d3 | 16 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 17 | /* Macro, type and constant definitions */ |
sahilmgandhi | 18:6a4db94011d3 | 18 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 19 | #define RTC_GLOBALS |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 22 | /* Global file scope (static) variables */ |
sahilmgandhi | 18:6a4db94011d3 | 23 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 24 | static volatile uint32_t g_u32hiYear, g_u32loYear, g_u32hiMonth, g_u32loMonth, g_u32hiDay, g_u32loDay; |
sahilmgandhi | 18:6a4db94011d3 | 25 | static volatile uint32_t g_u32hiHour, g_u32loHour, g_u32hiMin, g_u32loMin, g_u32hiSec, g_u32loSec; |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | /// @endcond HIDDEN_SYMBOLS |
sahilmgandhi | 18:6a4db94011d3 | 28 | |
sahilmgandhi | 18:6a4db94011d3 | 29 | |
sahilmgandhi | 18:6a4db94011d3 | 30 | |
sahilmgandhi | 18:6a4db94011d3 | 31 | |
sahilmgandhi | 18:6a4db94011d3 | 32 | /** @addtogroup Standard_Driver Standard Driver |
sahilmgandhi | 18:6a4db94011d3 | 33 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 34 | */ |
sahilmgandhi | 18:6a4db94011d3 | 35 | |
sahilmgandhi | 18:6a4db94011d3 | 36 | /** @addtogroup RTC_Driver RTC Driver |
sahilmgandhi | 18:6a4db94011d3 | 37 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 38 | */ |
sahilmgandhi | 18:6a4db94011d3 | 39 | |
sahilmgandhi | 18:6a4db94011d3 | 40 | /** @addtogroup RTC_EXPORTED_FUNCTIONS RTC Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 41 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 42 | */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | /** |
sahilmgandhi | 18:6a4db94011d3 | 45 | * @brief Initialize RTC module and start counting |
sahilmgandhi | 18:6a4db94011d3 | 46 | * |
sahilmgandhi | 18:6a4db94011d3 | 47 | * @param[in] sPt Specify the time property and current date and time. It includes: \n |
sahilmgandhi | 18:6a4db94011d3 | 48 | * u32Year: Year value, range between 2000 ~ 2099. \n |
sahilmgandhi | 18:6a4db94011d3 | 49 | * u32Month: Month value, range between 1 ~ 12. \n |
sahilmgandhi | 18:6a4db94011d3 | 50 | * u32Day: Day value, range between 1 ~ 31. \n |
sahilmgandhi | 18:6a4db94011d3 | 51 | * u32DayOfWeek: Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY / |
sahilmgandhi | 18:6a4db94011d3 | 52 | * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY / |
sahilmgandhi | 18:6a4db94011d3 | 53 | * RTC_SATURDAY] \n |
sahilmgandhi | 18:6a4db94011d3 | 54 | * u32Hour: Hour value, range between 0 ~ 23. \n |
sahilmgandhi | 18:6a4db94011d3 | 55 | * u32Minute: Minute value, range between 0 ~ 59. \n |
sahilmgandhi | 18:6a4db94011d3 | 56 | * u32Second: Second value, range between 0 ~ 59. \n |
sahilmgandhi | 18:6a4db94011d3 | 57 | * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n |
sahilmgandhi | 18:6a4db94011d3 | 58 | * u8AmPm: [RTC_AM / RTC_PM] \n |
sahilmgandhi | 18:6a4db94011d3 | 59 | * |
sahilmgandhi | 18:6a4db94011d3 | 60 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 61 | * |
sahilmgandhi | 18:6a4db94011d3 | 62 | * @details This function is used to: \n |
sahilmgandhi | 18:6a4db94011d3 | 63 | * 1. Write initial key to let RTC start count. \n |
sahilmgandhi | 18:6a4db94011d3 | 64 | * 2. Input parameter indicates start date/time. \n |
sahilmgandhi | 18:6a4db94011d3 | 65 | * 3. User has to make sure that parameters of RTC date/time are reasonable. \n |
sahilmgandhi | 18:6a4db94011d3 | 66 | * @note Null pointer for using default starting date/time. |
sahilmgandhi | 18:6a4db94011d3 | 67 | */ |
sahilmgandhi | 18:6a4db94011d3 | 68 | void RTC_Open(S_RTC_TIME_DATA_T *sPt) |
sahilmgandhi | 18:6a4db94011d3 | 69 | { |
sahilmgandhi | 18:6a4db94011d3 | 70 | RTC->INIT = RTC_INIT_KEY; |
sahilmgandhi | 18:6a4db94011d3 | 71 | |
sahilmgandhi | 18:6a4db94011d3 | 72 | if(RTC->INIT != RTC_INIT_ACTIVE_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 73 | { |
sahilmgandhi | 18:6a4db94011d3 | 74 | RTC->INIT = RTC_INIT_KEY; |
sahilmgandhi | 18:6a4db94011d3 | 75 | while(RTC->INIT != RTC_INIT_ACTIVE_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 76 | } |
sahilmgandhi | 18:6a4db94011d3 | 77 | |
sahilmgandhi | 18:6a4db94011d3 | 78 | if(sPt == 0) |
sahilmgandhi | 18:6a4db94011d3 | 79 | return ; |
sahilmgandhi | 18:6a4db94011d3 | 80 | |
sahilmgandhi | 18:6a4db94011d3 | 81 | /* Set RTC date and time */ |
sahilmgandhi | 18:6a4db94011d3 | 82 | RTC_SetDateAndTime(sPt); |
sahilmgandhi | 18:6a4db94011d3 | 83 | |
sahilmgandhi | 18:6a4db94011d3 | 84 | /* Waiting for RTC settings stable */ |
sahilmgandhi | 18:6a4db94011d3 | 85 | while((RTC->RWEN & RTC_RWEN_RWENF_Msk) == RTC_RWEN_RWENF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 86 | } |
sahilmgandhi | 18:6a4db94011d3 | 87 | |
sahilmgandhi | 18:6a4db94011d3 | 88 | /** |
sahilmgandhi | 18:6a4db94011d3 | 89 | * @brief Disable RTC Clock |
sahilmgandhi | 18:6a4db94011d3 | 90 | * |
sahilmgandhi | 18:6a4db94011d3 | 91 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 92 | * |
sahilmgandhi | 18:6a4db94011d3 | 93 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 94 | * |
sahilmgandhi | 18:6a4db94011d3 | 95 | * @details This API will disable RTC peripheral clock and stops RTC counting. |
sahilmgandhi | 18:6a4db94011d3 | 96 | */ |
sahilmgandhi | 18:6a4db94011d3 | 97 | void RTC_Close(void) |
sahilmgandhi | 18:6a4db94011d3 | 98 | { |
sahilmgandhi | 18:6a4db94011d3 | 99 | CLK->APBCLK0 &= ~CLK_APBCLK0_RTCCKEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 100 | } |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | /** |
sahilmgandhi | 18:6a4db94011d3 | 103 | * @brief Set 32k Frequency Compensation Data |
sahilmgandhi | 18:6a4db94011d3 | 104 | * |
sahilmgandhi | 18:6a4db94011d3 | 105 | * @param[in] i32FrequencyX100 Specify the RTC clock X100, ex: 3277365 means 32773.65. |
sahilmgandhi | 18:6a4db94011d3 | 106 | * |
sahilmgandhi | 18:6a4db94011d3 | 107 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 108 | * |
sahilmgandhi | 18:6a4db94011d3 | 109 | * @details This API is used to compensate the 32 kHz frequency by current LXT frequency for RTC application. |
sahilmgandhi | 18:6a4db94011d3 | 110 | */ |
sahilmgandhi | 18:6a4db94011d3 | 111 | void RTC_32KCalibration(int32_t i32FrequencyX100) |
sahilmgandhi | 18:6a4db94011d3 | 112 | { |
sahilmgandhi | 18:6a4db94011d3 | 113 | int32_t i32RegInt, i32RegFra; |
sahilmgandhi | 18:6a4db94011d3 | 114 | |
sahilmgandhi | 18:6a4db94011d3 | 115 | /* Compute integer and fraction for RTC FCR register */ |
sahilmgandhi | 18:6a4db94011d3 | 116 | i32RegInt = (i32FrequencyX100 / 100) - RTC_FCR_REFERENCE; |
sahilmgandhi | 18:6a4db94011d3 | 117 | i32RegFra = (((i32FrequencyX100 % 100)) * 60) / 100; |
sahilmgandhi | 18:6a4db94011d3 | 118 | |
sahilmgandhi | 18:6a4db94011d3 | 119 | /* Judge Integer part is reasonable */ |
sahilmgandhi | 18:6a4db94011d3 | 120 | if((i32RegInt < 0) | (i32RegInt > 15)) |
sahilmgandhi | 18:6a4db94011d3 | 121 | { |
sahilmgandhi | 18:6a4db94011d3 | 122 | return ; |
sahilmgandhi | 18:6a4db94011d3 | 123 | } |
sahilmgandhi | 18:6a4db94011d3 | 124 | |
sahilmgandhi | 18:6a4db94011d3 | 125 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 126 | RTC->FREQADJ = (uint32_t)((i32RegInt << 8) | i32RegFra); |
sahilmgandhi | 18:6a4db94011d3 | 127 | } |
sahilmgandhi | 18:6a4db94011d3 | 128 | |
sahilmgandhi | 18:6a4db94011d3 | 129 | /** |
sahilmgandhi | 18:6a4db94011d3 | 130 | * @brief Get Current RTC Date and Time |
sahilmgandhi | 18:6a4db94011d3 | 131 | * |
sahilmgandhi | 18:6a4db94011d3 | 132 | * @param[out] sPt The returned pointer is specified the current RTC value. It includes: \n |
sahilmgandhi | 18:6a4db94011d3 | 133 | * u32Year: Year value \n |
sahilmgandhi | 18:6a4db94011d3 | 134 | * u32Month: Month value \n |
sahilmgandhi | 18:6a4db94011d3 | 135 | * u32Day: Day value \n |
sahilmgandhi | 18:6a4db94011d3 | 136 | * u32DayOfWeek: Day of week \n |
sahilmgandhi | 18:6a4db94011d3 | 137 | * u32Hour: Hour value \n |
sahilmgandhi | 18:6a4db94011d3 | 138 | * u32Minute: Minute value \n |
sahilmgandhi | 18:6a4db94011d3 | 139 | * u32Second: Second value \n |
sahilmgandhi | 18:6a4db94011d3 | 140 | * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n |
sahilmgandhi | 18:6a4db94011d3 | 141 | * u8AmPm: [RTC_AM / RTC_PM] \n |
sahilmgandhi | 18:6a4db94011d3 | 142 | * |
sahilmgandhi | 18:6a4db94011d3 | 143 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 144 | * |
sahilmgandhi | 18:6a4db94011d3 | 145 | * @details This API is used to get the current RTC date and time value. |
sahilmgandhi | 18:6a4db94011d3 | 146 | */ |
sahilmgandhi | 18:6a4db94011d3 | 147 | void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt) |
sahilmgandhi | 18:6a4db94011d3 | 148 | { |
sahilmgandhi | 18:6a4db94011d3 | 149 | uint32_t u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 150 | |
sahilmgandhi | 18:6a4db94011d3 | 151 | sPt->u32TimeScale = RTC->CLKFMT & RTC_CLKFMT_24HEN_Msk; /* 12/24-hour */ |
sahilmgandhi | 18:6a4db94011d3 | 152 | sPt->u32DayOfWeek = RTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk; /* Day of the week */ |
sahilmgandhi | 18:6a4db94011d3 | 153 | |
sahilmgandhi | 18:6a4db94011d3 | 154 | /* Get [Date digit] data */ |
sahilmgandhi | 18:6a4db94011d3 | 155 | g_u32hiYear = (RTC->CAL & RTC_CAL_TENYEAR_Msk) >> RTC_CAL_TENYEAR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 156 | g_u32loYear = (RTC->CAL & RTC_CAL_YEAR_Msk) >> RTC_CAL_YEAR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 157 | g_u32hiMonth = (RTC->CAL & RTC_CAL_TENMON_Msk) >> RTC_CAL_TENMON_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 158 | g_u32loMonth = (RTC->CAL & RTC_CAL_MON_Msk) >> RTC_CAL_MON_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 159 | g_u32hiDay = (RTC->CAL & RTC_CAL_TENDAY_Msk) >> RTC_CAL_TENDAY_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 160 | g_u32loDay = (RTC->CAL & RTC_CAL_DAY_Msk) >> RTC_CAL_DAY_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 161 | |
sahilmgandhi | 18:6a4db94011d3 | 162 | /* Get [Time digit] data */ |
sahilmgandhi | 18:6a4db94011d3 | 163 | g_u32hiHour = (RTC->TIME & RTC_TIME_TENHR_Msk) >> RTC_TIME_TENHR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 164 | g_u32loHour = (RTC->TIME & RTC_TIME_HR_Msk) >> RTC_TIME_HR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 165 | g_u32hiMin = (RTC->TIME & RTC_TIME_TENMIN_Msk) >> RTC_TIME_TENMIN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 166 | g_u32loMin = (RTC->TIME & RTC_TIME_MIN_Msk) >> RTC_TIME_MIN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 167 | g_u32hiSec = (RTC->TIME & RTC_TIME_TENSEC_Msk) >> RTC_TIME_TENSEC_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 168 | g_u32loSec = (RTC->TIME & RTC_TIME_SEC_Msk) >> RTC_TIME_SEC_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 169 | |
sahilmgandhi | 18:6a4db94011d3 | 170 | /* Compute to 20XX year */ |
sahilmgandhi | 18:6a4db94011d3 | 171 | u32Tmp = (g_u32hiYear * 10); |
sahilmgandhi | 18:6a4db94011d3 | 172 | u32Tmp += g_u32loYear; |
sahilmgandhi | 18:6a4db94011d3 | 173 | sPt->u32Year = u32Tmp + RTC_YEAR2000; |
sahilmgandhi | 18:6a4db94011d3 | 174 | |
sahilmgandhi | 18:6a4db94011d3 | 175 | /* Compute 0~12 month */ |
sahilmgandhi | 18:6a4db94011d3 | 176 | u32Tmp = (g_u32hiMonth * 10); |
sahilmgandhi | 18:6a4db94011d3 | 177 | sPt->u32Month = u32Tmp + g_u32loMonth; |
sahilmgandhi | 18:6a4db94011d3 | 178 | |
sahilmgandhi | 18:6a4db94011d3 | 179 | /* Compute 0~31 day */ |
sahilmgandhi | 18:6a4db94011d3 | 180 | u32Tmp = (g_u32hiDay * 10); |
sahilmgandhi | 18:6a4db94011d3 | 181 | sPt->u32Day = u32Tmp + g_u32loDay; |
sahilmgandhi | 18:6a4db94011d3 | 182 | |
sahilmgandhi | 18:6a4db94011d3 | 183 | /* Compute 12/24 hour */ |
sahilmgandhi | 18:6a4db94011d3 | 184 | if(sPt->u32TimeScale == RTC_CLOCK_12) |
sahilmgandhi | 18:6a4db94011d3 | 185 | { |
sahilmgandhi | 18:6a4db94011d3 | 186 | u32Tmp = (g_u32hiHour * 10); |
sahilmgandhi | 18:6a4db94011d3 | 187 | u32Tmp += g_u32loHour; |
sahilmgandhi | 18:6a4db94011d3 | 188 | sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */ |
sahilmgandhi | 18:6a4db94011d3 | 189 | |
sahilmgandhi | 18:6a4db94011d3 | 190 | if(sPt->u32Hour >= 21) |
sahilmgandhi | 18:6a4db94011d3 | 191 | { |
sahilmgandhi | 18:6a4db94011d3 | 192 | sPt->u32AmPm = RTC_PM; |
sahilmgandhi | 18:6a4db94011d3 | 193 | sPt->u32Hour -= 20; |
sahilmgandhi | 18:6a4db94011d3 | 194 | } |
sahilmgandhi | 18:6a4db94011d3 | 195 | else |
sahilmgandhi | 18:6a4db94011d3 | 196 | { |
sahilmgandhi | 18:6a4db94011d3 | 197 | sPt->u32AmPm = RTC_AM; |
sahilmgandhi | 18:6a4db94011d3 | 198 | } |
sahilmgandhi | 18:6a4db94011d3 | 199 | |
sahilmgandhi | 18:6a4db94011d3 | 200 | u32Tmp = (g_u32hiMin * 10); |
sahilmgandhi | 18:6a4db94011d3 | 201 | u32Tmp += g_u32loMin; |
sahilmgandhi | 18:6a4db94011d3 | 202 | sPt->u32Minute = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 203 | |
sahilmgandhi | 18:6a4db94011d3 | 204 | u32Tmp = (g_u32hiSec * 10); |
sahilmgandhi | 18:6a4db94011d3 | 205 | u32Tmp += g_u32loSec; |
sahilmgandhi | 18:6a4db94011d3 | 206 | sPt->u32Second = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 207 | } |
sahilmgandhi | 18:6a4db94011d3 | 208 | else |
sahilmgandhi | 18:6a4db94011d3 | 209 | { |
sahilmgandhi | 18:6a4db94011d3 | 210 | u32Tmp = (g_u32hiHour * 10); |
sahilmgandhi | 18:6a4db94011d3 | 211 | u32Tmp += g_u32loHour; |
sahilmgandhi | 18:6a4db94011d3 | 212 | sPt->u32Hour = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 213 | |
sahilmgandhi | 18:6a4db94011d3 | 214 | u32Tmp = (g_u32hiMin * 10); |
sahilmgandhi | 18:6a4db94011d3 | 215 | u32Tmp += g_u32loMin; |
sahilmgandhi | 18:6a4db94011d3 | 216 | sPt->u32Minute = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 217 | |
sahilmgandhi | 18:6a4db94011d3 | 218 | u32Tmp = (g_u32hiSec * 10); |
sahilmgandhi | 18:6a4db94011d3 | 219 | u32Tmp += g_u32loSec; |
sahilmgandhi | 18:6a4db94011d3 | 220 | sPt->u32Second = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 221 | } |
sahilmgandhi | 18:6a4db94011d3 | 222 | } |
sahilmgandhi | 18:6a4db94011d3 | 223 | |
sahilmgandhi | 18:6a4db94011d3 | 224 | /** |
sahilmgandhi | 18:6a4db94011d3 | 225 | * @brief Get RTC Alarm Date and Time |
sahilmgandhi | 18:6a4db94011d3 | 226 | * |
sahilmgandhi | 18:6a4db94011d3 | 227 | * @param[out] sPt The returned pointer is specified the RTC alarm value. It includes: \n |
sahilmgandhi | 18:6a4db94011d3 | 228 | * u32Year: Year value \n |
sahilmgandhi | 18:6a4db94011d3 | 229 | * u32Month: Month value \n |
sahilmgandhi | 18:6a4db94011d3 | 230 | * u32Day: Day value \n |
sahilmgandhi | 18:6a4db94011d3 | 231 | * u32DayOfWeek: Day of week \n |
sahilmgandhi | 18:6a4db94011d3 | 232 | * u32Hour: Hour value \n |
sahilmgandhi | 18:6a4db94011d3 | 233 | * u32Minute: Minute value \n |
sahilmgandhi | 18:6a4db94011d3 | 234 | * u32Second: Second value \n |
sahilmgandhi | 18:6a4db94011d3 | 235 | * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n |
sahilmgandhi | 18:6a4db94011d3 | 236 | * u8AmPm: [RTC_AM / RTC_PM] \n |
sahilmgandhi | 18:6a4db94011d3 | 237 | * |
sahilmgandhi | 18:6a4db94011d3 | 238 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 239 | * |
sahilmgandhi | 18:6a4db94011d3 | 240 | * @details This API is used to get the RTC alarm date and time setting. |
sahilmgandhi | 18:6a4db94011d3 | 241 | */ |
sahilmgandhi | 18:6a4db94011d3 | 242 | void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt) |
sahilmgandhi | 18:6a4db94011d3 | 243 | { |
sahilmgandhi | 18:6a4db94011d3 | 244 | uint32_t u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 245 | |
sahilmgandhi | 18:6a4db94011d3 | 246 | sPt->u32TimeScale = RTC->CLKFMT & RTC_CLKFMT_24HEN_Msk; /* 12/24-hour */ |
sahilmgandhi | 18:6a4db94011d3 | 247 | sPt->u32DayOfWeek = RTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk; /* Day of the week */ |
sahilmgandhi | 18:6a4db94011d3 | 248 | |
sahilmgandhi | 18:6a4db94011d3 | 249 | /* Get alarm [Date digit] data */ |
sahilmgandhi | 18:6a4db94011d3 | 250 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 251 | g_u32hiYear = (RTC->CALM & RTC_CALM_TENYEAR_Msk) >> RTC_CALM_TENYEAR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 252 | g_u32loYear = (RTC->CALM & RTC_CALM_YEAR_Msk) >> RTC_CALM_YEAR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 253 | g_u32hiMonth = (RTC->CALM & RTC_CALM_TENMON_Msk) >> RTC_CALM_TENMON_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 254 | g_u32loMonth = (RTC->CALM & RTC_CALM_MON_Msk) >> RTC_CALM_MON_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 255 | g_u32hiDay = (RTC->CALM & RTC_CALM_TENDAY_Msk) >> RTC_CALM_TENDAY_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 256 | g_u32loDay = (RTC->CALM & RTC_CALM_DAY_Msk) >> RTC_CALM_DAY_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 257 | |
sahilmgandhi | 18:6a4db94011d3 | 258 | /* Get alarm [Time digit] data */ |
sahilmgandhi | 18:6a4db94011d3 | 259 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 260 | g_u32hiHour = (RTC->TALM & RTC_TALM_TENHR_Msk) >> RTC_TALM_TENHR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 261 | g_u32loHour = (RTC->TALM & RTC_TALM_HR_Msk) >> RTC_TALM_HR_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 262 | g_u32hiMin = (RTC->TALM & RTC_TALM_TENMIN_Msk) >> RTC_TALM_TENMIN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 263 | g_u32loMin = (RTC->TALM & RTC_TALM_MIN_Msk) >> RTC_TALM_MIN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 264 | g_u32hiSec = (RTC->TALM & RTC_TALM_TENSEC_Msk) >> RTC_TALM_TENSEC_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 265 | g_u32loSec = (RTC->TALM & RTC_TALM_SEC_Msk) >> RTC_TALM_SEC_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 266 | |
sahilmgandhi | 18:6a4db94011d3 | 267 | /* Compute to 20XX year */ |
sahilmgandhi | 18:6a4db94011d3 | 268 | u32Tmp = (g_u32hiYear * 10); |
sahilmgandhi | 18:6a4db94011d3 | 269 | u32Tmp += g_u32loYear; |
sahilmgandhi | 18:6a4db94011d3 | 270 | sPt->u32Year = u32Tmp + RTC_YEAR2000; |
sahilmgandhi | 18:6a4db94011d3 | 271 | |
sahilmgandhi | 18:6a4db94011d3 | 272 | /* Compute 0~12 month */ |
sahilmgandhi | 18:6a4db94011d3 | 273 | u32Tmp = (g_u32hiMonth * 10); |
sahilmgandhi | 18:6a4db94011d3 | 274 | sPt->u32Month = u32Tmp + g_u32loMonth; |
sahilmgandhi | 18:6a4db94011d3 | 275 | |
sahilmgandhi | 18:6a4db94011d3 | 276 | /* Compute 0~31 day */ |
sahilmgandhi | 18:6a4db94011d3 | 277 | u32Tmp = (g_u32hiDay * 10); |
sahilmgandhi | 18:6a4db94011d3 | 278 | sPt->u32Day = u32Tmp + g_u32loDay; |
sahilmgandhi | 18:6a4db94011d3 | 279 | |
sahilmgandhi | 18:6a4db94011d3 | 280 | /* Compute 12/24 hour */ |
sahilmgandhi | 18:6a4db94011d3 | 281 | if(sPt->u32TimeScale == RTC_CLOCK_12) |
sahilmgandhi | 18:6a4db94011d3 | 282 | { |
sahilmgandhi | 18:6a4db94011d3 | 283 | u32Tmp = (g_u32hiHour * 10); |
sahilmgandhi | 18:6a4db94011d3 | 284 | u32Tmp += g_u32loHour; |
sahilmgandhi | 18:6a4db94011d3 | 285 | sPt->u32Hour = u32Tmp; /* AM: 1~12. PM: 21~32. */ |
sahilmgandhi | 18:6a4db94011d3 | 286 | |
sahilmgandhi | 18:6a4db94011d3 | 287 | if(sPt->u32Hour >= 21) |
sahilmgandhi | 18:6a4db94011d3 | 288 | { |
sahilmgandhi | 18:6a4db94011d3 | 289 | sPt->u32AmPm = RTC_PM; |
sahilmgandhi | 18:6a4db94011d3 | 290 | sPt->u32Hour -= 20; |
sahilmgandhi | 18:6a4db94011d3 | 291 | } |
sahilmgandhi | 18:6a4db94011d3 | 292 | else |
sahilmgandhi | 18:6a4db94011d3 | 293 | { |
sahilmgandhi | 18:6a4db94011d3 | 294 | sPt->u32AmPm = RTC_AM; |
sahilmgandhi | 18:6a4db94011d3 | 295 | } |
sahilmgandhi | 18:6a4db94011d3 | 296 | |
sahilmgandhi | 18:6a4db94011d3 | 297 | u32Tmp = (g_u32hiMin * 10); |
sahilmgandhi | 18:6a4db94011d3 | 298 | u32Tmp += g_u32loMin; |
sahilmgandhi | 18:6a4db94011d3 | 299 | sPt->u32Minute = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 300 | |
sahilmgandhi | 18:6a4db94011d3 | 301 | u32Tmp = (g_u32hiSec * 10); |
sahilmgandhi | 18:6a4db94011d3 | 302 | u32Tmp += g_u32loSec; |
sahilmgandhi | 18:6a4db94011d3 | 303 | sPt->u32Second = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 304 | |
sahilmgandhi | 18:6a4db94011d3 | 305 | } |
sahilmgandhi | 18:6a4db94011d3 | 306 | else |
sahilmgandhi | 18:6a4db94011d3 | 307 | { |
sahilmgandhi | 18:6a4db94011d3 | 308 | u32Tmp = (g_u32hiHour * 10); |
sahilmgandhi | 18:6a4db94011d3 | 309 | u32Tmp += g_u32loHour; |
sahilmgandhi | 18:6a4db94011d3 | 310 | sPt->u32Hour = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 311 | |
sahilmgandhi | 18:6a4db94011d3 | 312 | u32Tmp = (g_u32hiMin * 10); |
sahilmgandhi | 18:6a4db94011d3 | 313 | u32Tmp += g_u32loMin; |
sahilmgandhi | 18:6a4db94011d3 | 314 | sPt->u32Minute = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 315 | |
sahilmgandhi | 18:6a4db94011d3 | 316 | u32Tmp = (g_u32hiSec * 10); |
sahilmgandhi | 18:6a4db94011d3 | 317 | u32Tmp += g_u32loSec; |
sahilmgandhi | 18:6a4db94011d3 | 318 | sPt->u32Second = u32Tmp; |
sahilmgandhi | 18:6a4db94011d3 | 319 | } |
sahilmgandhi | 18:6a4db94011d3 | 320 | } |
sahilmgandhi | 18:6a4db94011d3 | 321 | |
sahilmgandhi | 18:6a4db94011d3 | 322 | /** |
sahilmgandhi | 18:6a4db94011d3 | 323 | * @brief Update Current RTC Date and Time |
sahilmgandhi | 18:6a4db94011d3 | 324 | * |
sahilmgandhi | 18:6a4db94011d3 | 325 | * @param[in] sPt Specify the time property and current date and time. It includes: \n |
sahilmgandhi | 18:6a4db94011d3 | 326 | * u32Year: Year value, range between 2000 ~ 2099. \n |
sahilmgandhi | 18:6a4db94011d3 | 327 | * u32Month: Month value, range between 1 ~ 12. \n |
sahilmgandhi | 18:6a4db94011d3 | 328 | * u32Day: Day value, range between 1 ~ 31. \n |
sahilmgandhi | 18:6a4db94011d3 | 329 | * u32DayOfWeek: Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY / |
sahilmgandhi | 18:6a4db94011d3 | 330 | * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY / |
sahilmgandhi | 18:6a4db94011d3 | 331 | * RTC_SATURDAY] \n |
sahilmgandhi | 18:6a4db94011d3 | 332 | * u32Hour: Hour value, range between 0 ~ 23. \n |
sahilmgandhi | 18:6a4db94011d3 | 333 | * u32Minute: Minute value, range between 0 ~ 59. \n |
sahilmgandhi | 18:6a4db94011d3 | 334 | * u32Second: Second value, range between 0 ~ 59. \n |
sahilmgandhi | 18:6a4db94011d3 | 335 | * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n |
sahilmgandhi | 18:6a4db94011d3 | 336 | * u8AmPm: [RTC_AM / RTC_PM] \n |
sahilmgandhi | 18:6a4db94011d3 | 337 | * |
sahilmgandhi | 18:6a4db94011d3 | 338 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 339 | * |
sahilmgandhi | 18:6a4db94011d3 | 340 | * @details This API is used to update current date and time to RTC. |
sahilmgandhi | 18:6a4db94011d3 | 341 | */ |
sahilmgandhi | 18:6a4db94011d3 | 342 | void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt) |
sahilmgandhi | 18:6a4db94011d3 | 343 | { |
sahilmgandhi | 18:6a4db94011d3 | 344 | uint32_t u32RegCAL, u32RegTIME; |
sahilmgandhi | 18:6a4db94011d3 | 345 | |
sahilmgandhi | 18:6a4db94011d3 | 346 | if(sPt == 0) |
sahilmgandhi | 18:6a4db94011d3 | 347 | return ; |
sahilmgandhi | 18:6a4db94011d3 | 348 | |
sahilmgandhi | 18:6a4db94011d3 | 349 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 350 | /* Set RTC 24/12 hour setting and Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 351 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 352 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 353 | if(sPt->u32TimeScale == RTC_CLOCK_12) |
sahilmgandhi | 18:6a4db94011d3 | 354 | { |
sahilmgandhi | 18:6a4db94011d3 | 355 | RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 356 | |
sahilmgandhi | 18:6a4db94011d3 | 357 | /*-------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 358 | /* Important, range of 12-hour PM mode is 21 up to 32 */ |
sahilmgandhi | 18:6a4db94011d3 | 359 | /*-------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 360 | if(sPt->u32AmPm == RTC_PM) |
sahilmgandhi | 18:6a4db94011d3 | 361 | sPt->u32Hour += 20; |
sahilmgandhi | 18:6a4db94011d3 | 362 | } |
sahilmgandhi | 18:6a4db94011d3 | 363 | else |
sahilmgandhi | 18:6a4db94011d3 | 364 | { |
sahilmgandhi | 18:6a4db94011d3 | 365 | RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 366 | } |
sahilmgandhi | 18:6a4db94011d3 | 367 | |
sahilmgandhi | 18:6a4db94011d3 | 368 | /* Set Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 369 | RTC->WEEKDAY = sPt->u32DayOfWeek; |
sahilmgandhi | 18:6a4db94011d3 | 370 | |
sahilmgandhi | 18:6a4db94011d3 | 371 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 372 | /* Set RTC Current Date and Time */ |
sahilmgandhi | 18:6a4db94011d3 | 373 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 374 | u32RegCAL = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20; |
sahilmgandhi | 18:6a4db94011d3 | 375 | u32RegCAL |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 376 | u32RegCAL |= ((sPt->u32Month / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 377 | u32RegCAL |= ((sPt->u32Month % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 378 | u32RegCAL |= ((sPt->u32Day / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 379 | u32RegCAL |= (sPt->u32Day % 10); |
sahilmgandhi | 18:6a4db94011d3 | 380 | |
sahilmgandhi | 18:6a4db94011d3 | 381 | u32RegTIME = ((sPt->u32Hour / 10) << 20); |
sahilmgandhi | 18:6a4db94011d3 | 382 | u32RegTIME |= ((sPt->u32Hour % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 383 | u32RegTIME |= ((sPt->u32Minute / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 384 | u32RegTIME |= ((sPt->u32Minute % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 385 | u32RegTIME |= ((sPt->u32Second / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 386 | u32RegTIME |= (sPt->u32Second % 10); |
sahilmgandhi | 18:6a4db94011d3 | 387 | |
sahilmgandhi | 18:6a4db94011d3 | 388 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 389 | /* Set RTC Calender and Time Loading */ |
sahilmgandhi | 18:6a4db94011d3 | 390 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 391 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 392 | RTC->CAL = (uint32_t)u32RegCAL; |
sahilmgandhi | 18:6a4db94011d3 | 393 | RTC->TIME = (uint32_t)u32RegTIME; |
sahilmgandhi | 18:6a4db94011d3 | 394 | } |
sahilmgandhi | 18:6a4db94011d3 | 395 | |
sahilmgandhi | 18:6a4db94011d3 | 396 | /** |
sahilmgandhi | 18:6a4db94011d3 | 397 | * @brief Update RTC Alarm Date and Time |
sahilmgandhi | 18:6a4db94011d3 | 398 | * |
sahilmgandhi | 18:6a4db94011d3 | 399 | * @param[in] sPt Specify the time property and alarm date and time. It includes: \n |
sahilmgandhi | 18:6a4db94011d3 | 400 | * u32Year: Year value, range between 2000 ~ 2099. \n |
sahilmgandhi | 18:6a4db94011d3 | 401 | * u32Month: Month value, range between 1 ~ 12. \n |
sahilmgandhi | 18:6a4db94011d3 | 402 | * u32Day: Day value, range between 1 ~ 31. \n |
sahilmgandhi | 18:6a4db94011d3 | 403 | * u32DayOfWeek: Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY / |
sahilmgandhi | 18:6a4db94011d3 | 404 | * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY / |
sahilmgandhi | 18:6a4db94011d3 | 405 | * RTC_SATURDAY] \n |
sahilmgandhi | 18:6a4db94011d3 | 406 | * u32Hour: Hour value, range between 0 ~ 23. \n |
sahilmgandhi | 18:6a4db94011d3 | 407 | * u32Minute: Minute value, range between 0 ~ 59. \n |
sahilmgandhi | 18:6a4db94011d3 | 408 | * u32Second: Second value, range between 0 ~ 59. \n |
sahilmgandhi | 18:6a4db94011d3 | 409 | * u32TimeScale: [RTC_CLOCK_12 / RTC_CLOCK_24] \n |
sahilmgandhi | 18:6a4db94011d3 | 410 | * u8AmPm: [RTC_AM / RTC_PM] \n |
sahilmgandhi | 18:6a4db94011d3 | 411 | * |
sahilmgandhi | 18:6a4db94011d3 | 412 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 413 | * |
sahilmgandhi | 18:6a4db94011d3 | 414 | * @details This API is used to update alarm date and time setting to RTC. |
sahilmgandhi | 18:6a4db94011d3 | 415 | */ |
sahilmgandhi | 18:6a4db94011d3 | 416 | void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt) |
sahilmgandhi | 18:6a4db94011d3 | 417 | { |
sahilmgandhi | 18:6a4db94011d3 | 418 | uint32_t u32RegCALM, u32RegTALM; |
sahilmgandhi | 18:6a4db94011d3 | 419 | |
sahilmgandhi | 18:6a4db94011d3 | 420 | if(sPt == 0) |
sahilmgandhi | 18:6a4db94011d3 | 421 | return ; |
sahilmgandhi | 18:6a4db94011d3 | 422 | |
sahilmgandhi | 18:6a4db94011d3 | 423 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 424 | /* Set RTC 24/12 hour setting and Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 425 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 426 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 427 | if(sPt->u32TimeScale == RTC_CLOCK_12) |
sahilmgandhi | 18:6a4db94011d3 | 428 | { |
sahilmgandhi | 18:6a4db94011d3 | 429 | RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 430 | |
sahilmgandhi | 18:6a4db94011d3 | 431 | /*-------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 432 | /* Important, range of 12-hour PM mode is 21 up to 32 */ |
sahilmgandhi | 18:6a4db94011d3 | 433 | /*-------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 434 | if(sPt->u32AmPm == RTC_PM) |
sahilmgandhi | 18:6a4db94011d3 | 435 | sPt->u32Hour += 20; |
sahilmgandhi | 18:6a4db94011d3 | 436 | } |
sahilmgandhi | 18:6a4db94011d3 | 437 | else |
sahilmgandhi | 18:6a4db94011d3 | 438 | { |
sahilmgandhi | 18:6a4db94011d3 | 439 | RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 440 | } |
sahilmgandhi | 18:6a4db94011d3 | 441 | |
sahilmgandhi | 18:6a4db94011d3 | 442 | /* Set Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 443 | RTC->WEEKDAY = sPt->u32DayOfWeek; |
sahilmgandhi | 18:6a4db94011d3 | 444 | |
sahilmgandhi | 18:6a4db94011d3 | 445 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 446 | /* Set RTC Alarm Date and Time */ |
sahilmgandhi | 18:6a4db94011d3 | 447 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 448 | u32RegCALM = ((sPt->u32Year - RTC_YEAR2000) / 10) << 20; |
sahilmgandhi | 18:6a4db94011d3 | 449 | u32RegCALM |= (((sPt->u32Year - RTC_YEAR2000) % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 450 | u32RegCALM |= ((sPt->u32Month / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 451 | u32RegCALM |= ((sPt->u32Month % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 452 | u32RegCALM |= ((sPt->u32Day / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 453 | u32RegCALM |= (sPt->u32Day % 10); |
sahilmgandhi | 18:6a4db94011d3 | 454 | |
sahilmgandhi | 18:6a4db94011d3 | 455 | u32RegTALM = ((sPt->u32Hour / 10) << 20); |
sahilmgandhi | 18:6a4db94011d3 | 456 | u32RegTALM |= ((sPt->u32Hour % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 457 | u32RegTALM |= ((sPt->u32Minute / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 458 | u32RegTALM |= ((sPt->u32Minute % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 459 | u32RegTALM |= ((sPt->u32Second / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 460 | u32RegTALM |= (sPt->u32Second % 10); |
sahilmgandhi | 18:6a4db94011d3 | 461 | |
sahilmgandhi | 18:6a4db94011d3 | 462 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 463 | RTC->CALM = (uint32_t)u32RegCALM; |
sahilmgandhi | 18:6a4db94011d3 | 464 | RTC->TALM = (uint32_t)u32RegTALM; |
sahilmgandhi | 18:6a4db94011d3 | 465 | } |
sahilmgandhi | 18:6a4db94011d3 | 466 | |
sahilmgandhi | 18:6a4db94011d3 | 467 | /** |
sahilmgandhi | 18:6a4db94011d3 | 468 | * @brief Update RTC Current Date |
sahilmgandhi | 18:6a4db94011d3 | 469 | * |
sahilmgandhi | 18:6a4db94011d3 | 470 | * @param[in] u32Year The year calendar digit of current RTC setting. |
sahilmgandhi | 18:6a4db94011d3 | 471 | * @param[in] u32Month The month calendar digit of current RTC setting. |
sahilmgandhi | 18:6a4db94011d3 | 472 | * @param[in] u32Day The day calendar digit of current RTC setting. |
sahilmgandhi | 18:6a4db94011d3 | 473 | * @param[in] u32DayOfWeek The Day of the week. [RTC_SUNDAY / RTC_MONDAY / RTC_TUESDAY / |
sahilmgandhi | 18:6a4db94011d3 | 474 | * RTC_WEDNESDAY / RTC_THURSDAY / RTC_FRIDAY / |
sahilmgandhi | 18:6a4db94011d3 | 475 | * RTC_SATURDAY] |
sahilmgandhi | 18:6a4db94011d3 | 476 | * |
sahilmgandhi | 18:6a4db94011d3 | 477 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 478 | * |
sahilmgandhi | 18:6a4db94011d3 | 479 | * @details This API is used to update current date to RTC. |
sahilmgandhi | 18:6a4db94011d3 | 480 | */ |
sahilmgandhi | 18:6a4db94011d3 | 481 | void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek) |
sahilmgandhi | 18:6a4db94011d3 | 482 | { |
sahilmgandhi | 18:6a4db94011d3 | 483 | uint32_t u32RegCAL; |
sahilmgandhi | 18:6a4db94011d3 | 484 | |
sahilmgandhi | 18:6a4db94011d3 | 485 | u32RegCAL = ((u32Year - RTC_YEAR2000) / 10) << 20; |
sahilmgandhi | 18:6a4db94011d3 | 486 | u32RegCAL |= (((u32Year - RTC_YEAR2000) % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 487 | u32RegCAL |= ((u32Month / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 488 | u32RegCAL |= ((u32Month % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 489 | u32RegCAL |= ((u32Day / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 490 | u32RegCAL |= (u32Day % 10); |
sahilmgandhi | 18:6a4db94011d3 | 491 | |
sahilmgandhi | 18:6a4db94011d3 | 492 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 493 | |
sahilmgandhi | 18:6a4db94011d3 | 494 | /* Set Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 495 | RTC->WEEKDAY = u32DayOfWeek & RTC_WEEKDAY_WEEKDAY_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 496 | |
sahilmgandhi | 18:6a4db94011d3 | 497 | /* Set RTC Calender Loading */ |
sahilmgandhi | 18:6a4db94011d3 | 498 | RTC->CAL = (uint32_t)u32RegCAL; |
sahilmgandhi | 18:6a4db94011d3 | 499 | } |
sahilmgandhi | 18:6a4db94011d3 | 500 | |
sahilmgandhi | 18:6a4db94011d3 | 501 | /** |
sahilmgandhi | 18:6a4db94011d3 | 502 | * @brief Update RTC Current Time |
sahilmgandhi | 18:6a4db94011d3 | 503 | * |
sahilmgandhi | 18:6a4db94011d3 | 504 | * @param[in] u32Hour The hour time digit of current RTC setting. |
sahilmgandhi | 18:6a4db94011d3 | 505 | * @param[in] u32Minute The minute time digit of current RTC setting. |
sahilmgandhi | 18:6a4db94011d3 | 506 | * @param[in] u32Second The second time digit of current RTC setting. |
sahilmgandhi | 18:6a4db94011d3 | 507 | * @param[in] u32TimeMode The 24-Hour / 12-Hour Time Scale Selection. [RTC_CLOCK_12 / RTC_CLOCK_24] |
sahilmgandhi | 18:6a4db94011d3 | 508 | * @param[in] u32AmPm 12-hour time scale with AM and PM indication. Only Time Scale select 12-hour used. [RTC_AM / RTC_PM] |
sahilmgandhi | 18:6a4db94011d3 | 509 | * |
sahilmgandhi | 18:6a4db94011d3 | 510 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 511 | * |
sahilmgandhi | 18:6a4db94011d3 | 512 | * @details This API is used to update current time to RTC. |
sahilmgandhi | 18:6a4db94011d3 | 513 | */ |
sahilmgandhi | 18:6a4db94011d3 | 514 | void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm) |
sahilmgandhi | 18:6a4db94011d3 | 515 | { |
sahilmgandhi | 18:6a4db94011d3 | 516 | uint32_t u32RegTIME; |
sahilmgandhi | 18:6a4db94011d3 | 517 | |
sahilmgandhi | 18:6a4db94011d3 | 518 | /* Important, range of 12-hour PM mode is 21 up to 32 */ |
sahilmgandhi | 18:6a4db94011d3 | 519 | if((u32TimeMode == RTC_CLOCK_12) && (u32AmPm == RTC_PM)) |
sahilmgandhi | 18:6a4db94011d3 | 520 | u32Hour += 20; |
sahilmgandhi | 18:6a4db94011d3 | 521 | |
sahilmgandhi | 18:6a4db94011d3 | 522 | u32RegTIME = ((u32Hour / 10) << 20); |
sahilmgandhi | 18:6a4db94011d3 | 523 | u32RegTIME |= ((u32Hour % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 524 | u32RegTIME |= ((u32Minute / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 525 | u32RegTIME |= ((u32Minute % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 526 | u32RegTIME |= ((u32Second / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 527 | u32RegTIME |= (u32Second % 10); |
sahilmgandhi | 18:6a4db94011d3 | 528 | |
sahilmgandhi | 18:6a4db94011d3 | 529 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 530 | /* Set RTC 24/12 hour setting and Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 531 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 532 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 533 | if(u32TimeMode == RTC_CLOCK_12) |
sahilmgandhi | 18:6a4db94011d3 | 534 | { |
sahilmgandhi | 18:6a4db94011d3 | 535 | RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 536 | } |
sahilmgandhi | 18:6a4db94011d3 | 537 | else |
sahilmgandhi | 18:6a4db94011d3 | 538 | { |
sahilmgandhi | 18:6a4db94011d3 | 539 | RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 540 | } |
sahilmgandhi | 18:6a4db94011d3 | 541 | |
sahilmgandhi | 18:6a4db94011d3 | 542 | RTC->TIME = (uint32_t)u32RegTIME; |
sahilmgandhi | 18:6a4db94011d3 | 543 | } |
sahilmgandhi | 18:6a4db94011d3 | 544 | |
sahilmgandhi | 18:6a4db94011d3 | 545 | /** |
sahilmgandhi | 18:6a4db94011d3 | 546 | * @brief Update RTC Alarm Date |
sahilmgandhi | 18:6a4db94011d3 | 547 | * |
sahilmgandhi | 18:6a4db94011d3 | 548 | * @param[in] u32Year The year calendar digit of RTC alarm setting. |
sahilmgandhi | 18:6a4db94011d3 | 549 | * @param[in] u32Month The month calendar digit of RTC alarm setting. |
sahilmgandhi | 18:6a4db94011d3 | 550 | * @param[in] u32Day The day calendar digit of RTC alarm setting. |
sahilmgandhi | 18:6a4db94011d3 | 551 | * |
sahilmgandhi | 18:6a4db94011d3 | 552 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 553 | * |
sahilmgandhi | 18:6a4db94011d3 | 554 | * @details This API is used to update alarm date setting to RTC. |
sahilmgandhi | 18:6a4db94011d3 | 555 | */ |
sahilmgandhi | 18:6a4db94011d3 | 556 | void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day) |
sahilmgandhi | 18:6a4db94011d3 | 557 | { |
sahilmgandhi | 18:6a4db94011d3 | 558 | uint32_t u32RegCALM; |
sahilmgandhi | 18:6a4db94011d3 | 559 | |
sahilmgandhi | 18:6a4db94011d3 | 560 | u32RegCALM = ((u32Year - RTC_YEAR2000) / 10) << 20; |
sahilmgandhi | 18:6a4db94011d3 | 561 | u32RegCALM |= (((u32Year - RTC_YEAR2000) % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 562 | u32RegCALM |= ((u32Month / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 563 | u32RegCALM |= ((u32Month % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 564 | u32RegCALM |= ((u32Day / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 565 | u32RegCALM |= (u32Day % 10); |
sahilmgandhi | 18:6a4db94011d3 | 566 | |
sahilmgandhi | 18:6a4db94011d3 | 567 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 568 | |
sahilmgandhi | 18:6a4db94011d3 | 569 | /* Set RTC Alarm Date */ |
sahilmgandhi | 18:6a4db94011d3 | 570 | RTC->CALM = (uint32_t)u32RegCALM; |
sahilmgandhi | 18:6a4db94011d3 | 571 | } |
sahilmgandhi | 18:6a4db94011d3 | 572 | |
sahilmgandhi | 18:6a4db94011d3 | 573 | /** |
sahilmgandhi | 18:6a4db94011d3 | 574 | * @brief Update RTC Alarm Time |
sahilmgandhi | 18:6a4db94011d3 | 575 | * |
sahilmgandhi | 18:6a4db94011d3 | 576 | * @param[in] u32Hour The hour time digit of RTC alarm setting. |
sahilmgandhi | 18:6a4db94011d3 | 577 | * @param[in] u32Minute The minute time digit of RTC alarm setting. |
sahilmgandhi | 18:6a4db94011d3 | 578 | * @param[in] u32Second The second time digit of RTC alarm setting. |
sahilmgandhi | 18:6a4db94011d3 | 579 | * @param[in] u32TimeMode The 24-Hour / 12-Hour Time Scale Selection. [RTC_CLOCK_12 / RTC_CLOCK_24] |
sahilmgandhi | 18:6a4db94011d3 | 580 | * @param[in] u32AmPm 12-hour time scale with AM and PM indication. Only Time Scale select 12-hour used. [RTC_AM / RTC_PM] |
sahilmgandhi | 18:6a4db94011d3 | 581 | * |
sahilmgandhi | 18:6a4db94011d3 | 582 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 583 | * |
sahilmgandhi | 18:6a4db94011d3 | 584 | * @details This API is used to update alarm time setting to RTC. |
sahilmgandhi | 18:6a4db94011d3 | 585 | */ |
sahilmgandhi | 18:6a4db94011d3 | 586 | void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm) |
sahilmgandhi | 18:6a4db94011d3 | 587 | { |
sahilmgandhi | 18:6a4db94011d3 | 588 | uint32_t u32RegTALM; |
sahilmgandhi | 18:6a4db94011d3 | 589 | |
sahilmgandhi | 18:6a4db94011d3 | 590 | /* Important, range of 12-hour PM mode is 21 up to 32 */ |
sahilmgandhi | 18:6a4db94011d3 | 591 | if((u32TimeMode == RTC_CLOCK_12) && (u32AmPm == RTC_PM)) |
sahilmgandhi | 18:6a4db94011d3 | 592 | u32Hour += 20; |
sahilmgandhi | 18:6a4db94011d3 | 593 | |
sahilmgandhi | 18:6a4db94011d3 | 594 | u32RegTALM = ((u32Hour / 10) << 20); |
sahilmgandhi | 18:6a4db94011d3 | 595 | u32RegTALM |= ((u32Hour % 10) << 16); |
sahilmgandhi | 18:6a4db94011d3 | 596 | u32RegTALM |= ((u32Minute / 10) << 12); |
sahilmgandhi | 18:6a4db94011d3 | 597 | u32RegTALM |= ((u32Minute % 10) << 8); |
sahilmgandhi | 18:6a4db94011d3 | 598 | u32RegTALM |= ((u32Second / 10) << 4); |
sahilmgandhi | 18:6a4db94011d3 | 599 | u32RegTALM |= (u32Second % 10); |
sahilmgandhi | 18:6a4db94011d3 | 600 | |
sahilmgandhi | 18:6a4db94011d3 | 601 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 602 | /* Set RTC 24/12 hour setting and Day of the Week */ |
sahilmgandhi | 18:6a4db94011d3 | 603 | /*-----------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 604 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 605 | if(u32TimeMode == RTC_CLOCK_12) |
sahilmgandhi | 18:6a4db94011d3 | 606 | { |
sahilmgandhi | 18:6a4db94011d3 | 607 | RTC->CLKFMT &= ~RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 608 | } |
sahilmgandhi | 18:6a4db94011d3 | 609 | else |
sahilmgandhi | 18:6a4db94011d3 | 610 | { |
sahilmgandhi | 18:6a4db94011d3 | 611 | RTC->CLKFMT |= RTC_CLKFMT_24HEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 612 | } |
sahilmgandhi | 18:6a4db94011d3 | 613 | |
sahilmgandhi | 18:6a4db94011d3 | 614 | /* Set RTC Alarm Time */ |
sahilmgandhi | 18:6a4db94011d3 | 615 | RTC->TALM = (uint32_t)u32RegTALM; |
sahilmgandhi | 18:6a4db94011d3 | 616 | } |
sahilmgandhi | 18:6a4db94011d3 | 617 | |
sahilmgandhi | 18:6a4db94011d3 | 618 | /** |
sahilmgandhi | 18:6a4db94011d3 | 619 | * @brief Get Day of the Week |
sahilmgandhi | 18:6a4db94011d3 | 620 | * |
sahilmgandhi | 18:6a4db94011d3 | 621 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 622 | * |
sahilmgandhi | 18:6a4db94011d3 | 623 | * @retval 0 Sunday |
sahilmgandhi | 18:6a4db94011d3 | 624 | * @retval 1 Monday |
sahilmgandhi | 18:6a4db94011d3 | 625 | * @retval 2 Tuesday |
sahilmgandhi | 18:6a4db94011d3 | 626 | * @retval 3 Wednesday |
sahilmgandhi | 18:6a4db94011d3 | 627 | * @retval 4 Thursday |
sahilmgandhi | 18:6a4db94011d3 | 628 | * @retval 5 Friday |
sahilmgandhi | 18:6a4db94011d3 | 629 | * @retval 6 Saturday |
sahilmgandhi | 18:6a4db94011d3 | 630 | * |
sahilmgandhi | 18:6a4db94011d3 | 631 | * @details This API is used to get day of the week of current RTC date. |
sahilmgandhi | 18:6a4db94011d3 | 632 | */ |
sahilmgandhi | 18:6a4db94011d3 | 633 | uint32_t RTC_GetDayOfWeek(void) |
sahilmgandhi | 18:6a4db94011d3 | 634 | { |
sahilmgandhi | 18:6a4db94011d3 | 635 | return (RTC->WEEKDAY & RTC_WEEKDAY_WEEKDAY_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 636 | } |
sahilmgandhi | 18:6a4db94011d3 | 637 | |
sahilmgandhi | 18:6a4db94011d3 | 638 | /** |
sahilmgandhi | 18:6a4db94011d3 | 639 | * @brief Set RTC Tick Period Time |
sahilmgandhi | 18:6a4db94011d3 | 640 | * |
sahilmgandhi | 18:6a4db94011d3 | 641 | * @param[in] u32TickSelection It is used to set the RTC tick period time for Periodic Time Tick request. \n |
sahilmgandhi | 18:6a4db94011d3 | 642 | * It consists of: \n |
sahilmgandhi | 18:6a4db94011d3 | 643 | * RTC_TICK_1_SEC: Time tick is 1 second \n |
sahilmgandhi | 18:6a4db94011d3 | 644 | * RTC_TICK_1_2_SEC: Time tick is 1/2 second \n |
sahilmgandhi | 18:6a4db94011d3 | 645 | * RTC_TICK_1_4_SEC: Time tick is 1/4 second \n |
sahilmgandhi | 18:6a4db94011d3 | 646 | * RTC_TICK_1_8_SEC: Time tick is 1/8 second \n |
sahilmgandhi | 18:6a4db94011d3 | 647 | * RTC_TICK_1_16_SEC: Time tick is 1/16 second \n |
sahilmgandhi | 18:6a4db94011d3 | 648 | * RTC_TICK_1_32_SEC: Time tick is 1/32 second \n |
sahilmgandhi | 18:6a4db94011d3 | 649 | * RTC_TICK_1_64_SEC: Time tick is 1/64 second \n |
sahilmgandhi | 18:6a4db94011d3 | 650 | * RTC_TICK_1_128_SEC: Time tick is 1/128 second |
sahilmgandhi | 18:6a4db94011d3 | 651 | * |
sahilmgandhi | 18:6a4db94011d3 | 652 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 653 | * |
sahilmgandhi | 18:6a4db94011d3 | 654 | * @details This API is used to set RTC tick period time for each tick interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 655 | */ |
sahilmgandhi | 18:6a4db94011d3 | 656 | void RTC_SetTickPeriod(uint32_t u32TickSelection) |
sahilmgandhi | 18:6a4db94011d3 | 657 | { |
sahilmgandhi | 18:6a4db94011d3 | 658 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 659 | |
sahilmgandhi | 18:6a4db94011d3 | 660 | RTC->TICK = (RTC->TICK & ~RTC_TICK_TICK_Msk) | u32TickSelection; |
sahilmgandhi | 18:6a4db94011d3 | 661 | } |
sahilmgandhi | 18:6a4db94011d3 | 662 | |
sahilmgandhi | 18:6a4db94011d3 | 663 | /** |
sahilmgandhi | 18:6a4db94011d3 | 664 | * @brief Enable RTC Interrupt |
sahilmgandhi | 18:6a4db94011d3 | 665 | * |
sahilmgandhi | 18:6a4db94011d3 | 666 | * @param[in] u32IntFlagMask Specify the interrupt source. It consists of: \n |
sahilmgandhi | 18:6a4db94011d3 | 667 | * RTC_INTEN_ALMIEN_Msk: Alarm interrupt \n |
sahilmgandhi | 18:6a4db94011d3 | 668 | * RTC_INTEN_TICKIEN_Msk: Tick interrupt \n |
sahilmgandhi | 18:6a4db94011d3 | 669 | * RTC_INTEN_SNPDIEN_Msk: Snooper Pin Event Detection interrupt \n |
sahilmgandhi | 18:6a4db94011d3 | 670 | * |
sahilmgandhi | 18:6a4db94011d3 | 671 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 672 | * |
sahilmgandhi | 18:6a4db94011d3 | 673 | * @details This API is used to enable the specify RTC interrupt function. |
sahilmgandhi | 18:6a4db94011d3 | 674 | */ |
sahilmgandhi | 18:6a4db94011d3 | 675 | void RTC_EnableInt(uint32_t u32IntFlagMask) |
sahilmgandhi | 18:6a4db94011d3 | 676 | { |
sahilmgandhi | 18:6a4db94011d3 | 677 | RTC->INTEN |= u32IntFlagMask; |
sahilmgandhi | 18:6a4db94011d3 | 678 | } |
sahilmgandhi | 18:6a4db94011d3 | 679 | |
sahilmgandhi | 18:6a4db94011d3 | 680 | /** |
sahilmgandhi | 18:6a4db94011d3 | 681 | * @brief Disable RTC Interrupt |
sahilmgandhi | 18:6a4db94011d3 | 682 | * |
sahilmgandhi | 18:6a4db94011d3 | 683 | * @param[in] u32IntFlagMask Specify the interrupt source. It consists of: \n |
sahilmgandhi | 18:6a4db94011d3 | 684 | * RTC_INTEN_ALMIEN_Msk: Alarm interrupt \n |
sahilmgandhi | 18:6a4db94011d3 | 685 | * RTC_INTEN_TICKIEN_Msk: Tick interrupt \n |
sahilmgandhi | 18:6a4db94011d3 | 686 | * RTC_INTEN_SNPDIEN_Msk: Snooper Pin Event Detection interrupt \n |
sahilmgandhi | 18:6a4db94011d3 | 687 | * |
sahilmgandhi | 18:6a4db94011d3 | 688 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 689 | * |
sahilmgandhi | 18:6a4db94011d3 | 690 | * @details This API is used to disable the specify RTC interrupt function. |
sahilmgandhi | 18:6a4db94011d3 | 691 | */ |
sahilmgandhi | 18:6a4db94011d3 | 692 | void RTC_DisableInt(uint32_t u32IntFlagMask) |
sahilmgandhi | 18:6a4db94011d3 | 693 | { |
sahilmgandhi | 18:6a4db94011d3 | 694 | if(u32IntFlagMask & RTC_INTEN_ALMIEN_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 695 | { |
sahilmgandhi | 18:6a4db94011d3 | 696 | RTC->INTEN &= ~RTC_INTEN_ALMIEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 697 | RTC->INTSTS = RTC_INTSTS_ALMIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 698 | } |
sahilmgandhi | 18:6a4db94011d3 | 699 | |
sahilmgandhi | 18:6a4db94011d3 | 700 | if(u32IntFlagMask & RTC_INTEN_TICKIEN_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 701 | { |
sahilmgandhi | 18:6a4db94011d3 | 702 | RTC->INTEN &= ~RTC_INTEN_TICKIEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 703 | RTC->INTSTS = RTC_INTSTS_TICKIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 704 | } |
sahilmgandhi | 18:6a4db94011d3 | 705 | |
sahilmgandhi | 18:6a4db94011d3 | 706 | if(u32IntFlagMask & RTC_INTEN_SNPDIEN_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 707 | { |
sahilmgandhi | 18:6a4db94011d3 | 708 | RTC->INTEN &= ~RTC_INTEN_SNPDIEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 709 | RTC->INTSTS = RTC_INTSTS_SNPDIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 710 | } |
sahilmgandhi | 18:6a4db94011d3 | 711 | } |
sahilmgandhi | 18:6a4db94011d3 | 712 | |
sahilmgandhi | 18:6a4db94011d3 | 713 | /** |
sahilmgandhi | 18:6a4db94011d3 | 714 | * @brief Enable Spare Registers Access |
sahilmgandhi | 18:6a4db94011d3 | 715 | * |
sahilmgandhi | 18:6a4db94011d3 | 716 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 717 | * |
sahilmgandhi | 18:6a4db94011d3 | 718 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 719 | * |
sahilmgandhi | 18:6a4db94011d3 | 720 | * @details This API is used to enable the spare registers 0~19 can be accessed. |
sahilmgandhi | 18:6a4db94011d3 | 721 | */ |
sahilmgandhi | 18:6a4db94011d3 | 722 | void RTC_EnableSpareAccess(void) |
sahilmgandhi | 18:6a4db94011d3 | 723 | { |
sahilmgandhi | 18:6a4db94011d3 | 724 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 725 | |
sahilmgandhi | 18:6a4db94011d3 | 726 | RTC->SPRCTL |= RTC_SPRCTL_SPRRWEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 727 | |
sahilmgandhi | 18:6a4db94011d3 | 728 | while(!(RTC->SPRCTL & RTC_SPRCTL_SPRRWRDY_Msk)); |
sahilmgandhi | 18:6a4db94011d3 | 729 | } |
sahilmgandhi | 18:6a4db94011d3 | 730 | |
sahilmgandhi | 18:6a4db94011d3 | 731 | /** |
sahilmgandhi | 18:6a4db94011d3 | 732 | * @brief Disable Spare Register |
sahilmgandhi | 18:6a4db94011d3 | 733 | * |
sahilmgandhi | 18:6a4db94011d3 | 734 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 735 | * |
sahilmgandhi | 18:6a4db94011d3 | 736 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 737 | * |
sahilmgandhi | 18:6a4db94011d3 | 738 | * @details This API is used to disable the spare register 0~19 cannot be accessed. |
sahilmgandhi | 18:6a4db94011d3 | 739 | */ |
sahilmgandhi | 18:6a4db94011d3 | 740 | void RTC_DisableSpareRegister(void) |
sahilmgandhi | 18:6a4db94011d3 | 741 | { |
sahilmgandhi | 18:6a4db94011d3 | 742 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 743 | |
sahilmgandhi | 18:6a4db94011d3 | 744 | RTC->SPRCTL &= ~RTC_SPRCTL_SPRRWEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 745 | } |
sahilmgandhi | 18:6a4db94011d3 | 746 | |
sahilmgandhi | 18:6a4db94011d3 | 747 | /** |
sahilmgandhi | 18:6a4db94011d3 | 748 | * @brief Enable Snooper Pin Detect |
sahilmgandhi | 18:6a4db94011d3 | 749 | * |
sahilmgandhi | 18:6a4db94011d3 | 750 | * @param[in] u32PinCondition Snooper pin trigger condition. Possible options are |
sahilmgandhi | 18:6a4db94011d3 | 751 | * - \ref RTC_SNOOPER_LOW_LEVEL |
sahilmgandhi | 18:6a4db94011d3 | 752 | * - \ref RTC_SNOOPER_HIGH_LEVEL |
sahilmgandhi | 18:6a4db94011d3 | 753 | * - \ref RTC_SNOOPER_FALLING_EDGE |
sahilmgandhi | 18:6a4db94011d3 | 754 | * - \ref RTC_SNOOPER_RISING_EDGE |
sahilmgandhi | 18:6a4db94011d3 | 755 | * |
sahilmgandhi | 18:6a4db94011d3 | 756 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 757 | * |
sahilmgandhi | 18:6a4db94011d3 | 758 | * @details This API is used to enable the snooper pin detect function with specify trigger condition. |
sahilmgandhi | 18:6a4db94011d3 | 759 | */ |
sahilmgandhi | 18:6a4db94011d3 | 760 | void RTC_EnableSnooperDetection(uint32_t u32PinCondition) |
sahilmgandhi | 18:6a4db94011d3 | 761 | { |
sahilmgandhi | 18:6a4db94011d3 | 762 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 763 | |
sahilmgandhi | 18:6a4db94011d3 | 764 | RTC->SPRCTL = ((RTC->SPRCTL & ~RTC_SNOOPER_DETECT_Msk) | u32PinCondition) | RTC_SPRCTL_SNPDEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 765 | } |
sahilmgandhi | 18:6a4db94011d3 | 766 | |
sahilmgandhi | 18:6a4db94011d3 | 767 | /** |
sahilmgandhi | 18:6a4db94011d3 | 768 | * @brief Disable Snooper Pin Detect |
sahilmgandhi | 18:6a4db94011d3 | 769 | * |
sahilmgandhi | 18:6a4db94011d3 | 770 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 771 | * |
sahilmgandhi | 18:6a4db94011d3 | 772 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 773 | * |
sahilmgandhi | 18:6a4db94011d3 | 774 | * @details This API is used to disable the snooper pin detect function. |
sahilmgandhi | 18:6a4db94011d3 | 775 | */ |
sahilmgandhi | 18:6a4db94011d3 | 776 | void RTC_DisableSnooperDetection(void) |
sahilmgandhi | 18:6a4db94011d3 | 777 | { |
sahilmgandhi | 18:6a4db94011d3 | 778 | RTC_WaitAccessEnable(); |
sahilmgandhi | 18:6a4db94011d3 | 779 | |
sahilmgandhi | 18:6a4db94011d3 | 780 | RTC->SPRCTL &= ~RTC_SPRCTL_SNPDEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 781 | } |
sahilmgandhi | 18:6a4db94011d3 | 782 | |
sahilmgandhi | 18:6a4db94011d3 | 783 | /*@}*/ /* end of group RTC_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 784 | |
sahilmgandhi | 18:6a4db94011d3 | 785 | /*@}*/ /* end of group RTC_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 786 | |
sahilmgandhi | 18:6a4db94011d3 | 787 | /*@}*/ /* end of group Standard_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 788 | |
sahilmgandhi | 18:6a4db94011d3 | 789 | /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/ |