RTC. API cnahge.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3376 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
barthess 2011-09-21 12:46:09 +00:00
parent 42e2ea515d
commit 95713cae20
4 changed files with 21 additions and 27 deletions

View File

@ -75,8 +75,7 @@ extern "C" {
#endif /* RTC_SUPPORTS_CALLBACKS */
void rtcSetTime(uint32_t tv_sec);
uint32_t rtcGetSec(void);
uint16_t rtcGetMsec(void);
uint32_t rtcGetTime(uint16_t *msec);
void rtcSetAlarm(uint32_t tv_alarm);
uint32_t rtcGetAlarm(void);
#ifdef __cplusplus

View File

@ -125,6 +125,7 @@ void rtc_lld_init(void){
#if STM32_RTC == STM32_RTC_LSE
if (! ((RCC->BDCR & RCC_BDCR_RTCEN) || (RCC->BDCR & RCC_BDCR_LSEON))){
RCC->BDCR |= RCC_BDCR_LSEON;
/* Note: cold start time of LSE oscillator on STM32 is about 3 seconds. */
while(!(RCC->BDCR & RCC_BDCR_LSERDY))
;
RCC->BDCR |= RCC_BDCR_RTCEN;
@ -262,23 +263,20 @@ void rtc_lld_set_time(uint32_t tv_sec){
}
/**
* @brief Return current time in UNIX notation.
* @brief Return return seconds since UNIX epoch.
*
* @param[in] msec pointer to variable for storing fractional part of
* time (milliseconds).
*
* @notapi
*/
inline uint32_t rtc_lld_get_sec(void){
return ((RTC->CNTH << 16) + RTC->CNTL);
}
/**
* @brief Return fractional part of current time (milliseconds).
*
* @notapi
*/
inline uint16_t rtc_lld_get_msec(void){
inline uint32_t rtc_lld_get_time(uint16_t *msec){
uint32_t time_frac = 0;
if(msec != NULL){
time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL);
return(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
*msec = (uint16_t)(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
}
return ((RTC->CNTH << 16) + RTC->CNTL);
}
/**

View File

@ -100,8 +100,7 @@ extern "C" {
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflow_cb,
rtccb_t second_cb, rtccb_t alarm_cb);
void rtc_lld_set_time(uint32_t tv_sec);
uint32_t rtc_lld_get_sec(void);
uint16_t rtc_lld_get_msec(void);
uint32_t rtc_lld_get_time(uint16_t *msec);
uint32_t rtc_lld_get_alarm(void);
void rtc_lld_set_alarm(uint32_t);
#ifdef __cplusplus

View File

@ -90,17 +90,15 @@ void rtcSetTime(uint32_t tv_sec){
}
/**
* @brief Return current time in UNIX notation.
* @brief Return return seconds since UNIX epoch.
*
* @param[in] msec pointer to variable for storing fractional part of
* time (milliseconds).
*
* @notapi
*/
inline uint32_t rtcGetSec(void){
return rtc_lld_get_sec();
}
/**
* @brief Return fractional part of current time (milliseconds).
*/
inline uint16_t rtcGetMsec(void){
return rtc_lld_get_msec();
inline uint32_t rtcGetTime(uint16_t *msec){
return rtc_lld_get_time(msec);
}
/**