mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/rtc_api.c
- Revision:
- 135:067cc8ba23da
- Parent:
- 125:23cc3068a9e4
- Child:
- 162:937d965048d3
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/rtc_api.c Tue Mar 25 09:30:07 2014 +0000 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/rtc_api.c Tue Mar 25 10:15:07 2014 +0000 @@ -39,27 +39,27 @@ // Be sure to start correctly RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); - + // Note: the LSI is used as RTC source clock // The RTC Clock may vary due to LSI frequency dispersion. RCC_LSICmd(ENABLE); // Enable LSI - + while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} // Wait until ready - + RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); // Select LSI as RTC Clock Source - - RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock - + + RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock + RTC_WaitForSynchro(); // Wait for RTC registers synchronization uint32_t lsi_freq = 40000; // [TODO] To be measured precisely using a timer input capture RTC_InitTypeDef RTC_InitStructure; RTC_InitStructure.RTC_AsynchPrediv = 127; - RTC_InitStructure.RTC_SynchPrediv = (lsi_freq / 128) - 1; + RTC_InitStructure.RTC_SynchPrediv = (lsi_freq / 128) - 1; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); - + rtc_inited = 1; } @@ -93,11 +93,11 @@ RTC_DateTypeDef dateStruct; RTC_TimeTypeDef timeStruct; struct tm timeinfo; - + // Read actual date and time RTC_GetTime(RTC_Format_BIN, &timeStruct); RTC_GetDate(RTC_Format_BIN, &dateStruct); - + // Setup a tm structure based on the RTC timeinfo.tm_wday = dateStruct.RTC_WeekDay; timeinfo.tm_mon = dateStruct.RTC_Month - 1; @@ -106,11 +106,11 @@ timeinfo.tm_hour = timeStruct.RTC_Hours; timeinfo.tm_min = timeStruct.RTC_Minutes; timeinfo.tm_sec = timeStruct.RTC_Seconds; - + // Convert to timestamp time_t t = mktime(&timeinfo); - - return t; + + return t; } void rtc_write(time_t t) { @@ -119,7 +119,7 @@ // Convert the time into a tm struct tm *timeinfo = localtime(&t); - + // Fill RTC structures dateStruct.RTC_WeekDay = timeinfo->tm_wday; dateStruct.RTC_Month = timeinfo->tm_mon + 1; @@ -129,10 +129,10 @@ timeStruct.RTC_Minutes = timeinfo->tm_min; timeStruct.RTC_Seconds = timeinfo->tm_sec; timeStruct.RTC_H12 = RTC_HourFormat_24; - + // Change the RTC current date/time - PWR_BackupAccessCmd(ENABLE); // Enable access to RTC + PWR_BackupAccessCmd(ENABLE); // Enable access to RTC RTC_SetDate(RTC_Format_BIN, &dateStruct); - RTC_SetTime(RTC_Format_BIN, &timeStruct); + RTC_SetTime(RTC_Format_BIN, &timeStruct); PWR_BackupAccessCmd(DISABLE); // Disable access to RTC }