/ * @brief * Initialize all RTC module related hardware and register RTC device to kernel * * @details * * @note ******************************************************************************/
| 130 | * @note |
| 131 | ******************************************************************************/ |
| 132 | void rt_hw_rtc_init(void) |
| 133 | { |
| 134 | rt_uint32_t reset; |
| 135 | |
| 136 | reset = RMU_ResetCauseGet(); |
| 137 | |
| 138 | // TODO: What is the current reset mode? |
| 139 | if (reset & RMU_RSTCAUSE_PORST || reset & RMU_RSTCAUSE_EXTRST) |
| 140 | { |
| 141 | RTC_Init_TypeDef rtcInit; |
| 142 | efm32_irq_hook_init_t hook; |
| 143 | |
| 144 | rtcInit.enable = true; |
| 145 | rtcInit.debugRun = false; |
| 146 | rtcInit.comp0Top = false; |
| 147 | |
| 148 | rtc_time = 0UL; |
| 149 | |
| 150 | rt_kprintf("rtc is not configured\n"); |
| 151 | rt_kprintf("please configure with set_date and set_time\n"); |
| 152 | |
| 153 | /* Configuring clock */ |
| 154 | CMU_ClockDivSet(cmuClock_RTC,cmuClkDiv_32768); |
| 155 | CMU_ClockEnable(cmuClock_RTC, true); |
| 156 | |
| 157 | /* Initialize and enable RTC */ |
| 158 | RTC_Reset(); |
| 159 | RTC_Init(&rtcInit); |
| 160 | |
| 161 | hook.type = efm32_irq_type_rtc; |
| 162 | hook.unit = 0; |
| 163 | hook.cbFunc = rt_hw_rtc_isr; |
| 164 | hook.userPtr = RT_NULL; |
| 165 | efm32_irq_hook_register(&hook); |
| 166 | |
| 167 | /* Enabling Interrupt from RTC */ |
| 168 | RTC_IntEnable(RTC_IFC_OF); |
| 169 | RTC_IntClear(RTC_IFC_OF); |
| 170 | |
| 171 | NVIC_ClearPendingIRQ(RTC_IRQn); |
| 172 | NVIC_SetPriority(RTC_IRQn, EFM32_IRQ_PRI_DEFAULT); |
| 173 | NVIC_EnableIRQ(RTC_IRQn); |
| 174 | } |
| 175 | |
| 176 | /* register rtc device */ |
| 177 | rtc.type = RT_Device_Class_RTC; |
| 178 | rtc.rx_indicate = RT_NULL; |
| 179 | rtc.tx_complete = RT_NULL; |
| 180 | rtc.init = RT_NULL; |
| 181 | rtc.open = rt_rtc_open; |
| 182 | rtc.close = RT_NULL; |
| 183 | rtc.read = rt_rtc_read; |
| 184 | rtc.write = RT_NULL; |
| 185 | rtc.control = rt_rtc_control; |
| 186 | rtc.user_data = RT_NULL; /* no private */ |
| 187 | |
| 188 | rt_device_register(&rtc, RT_RTC_NAME, RT_DEVICE_FLAG_RDWR | EFM32_NO_DATA); |
| 189 | } |
no test coverage detected