RTC. API cnahge.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3376 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
42e2ea515d
commit
95713cae20
|
@ -75,8 +75,7 @@ extern "C" {
|
||||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
#endif /* RTC_SUPPORTS_CALLBACKS */
|
||||||
|
|
||||||
void rtcSetTime(uint32_t tv_sec);
|
void rtcSetTime(uint32_t tv_sec);
|
||||||
uint32_t rtcGetSec(void);
|
uint32_t rtcGetTime(uint16_t *msec);
|
||||||
uint16_t rtcGetMsec(void);
|
|
||||||
void rtcSetAlarm(uint32_t tv_alarm);
|
void rtcSetAlarm(uint32_t tv_alarm);
|
||||||
uint32_t rtcGetAlarm(void);
|
uint32_t rtcGetAlarm(void);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -125,6 +125,7 @@ void rtc_lld_init(void){
|
||||||
#if STM32_RTC == STM32_RTC_LSE
|
#if STM32_RTC == STM32_RTC_LSE
|
||||||
if (! ((RCC->BDCR & RCC_BDCR_RTCEN) || (RCC->BDCR & RCC_BDCR_LSEON))){
|
if (! ((RCC->BDCR & RCC_BDCR_RTCEN) || (RCC->BDCR & RCC_BDCR_LSEON))){
|
||||||
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))
|
while(!(RCC->BDCR & RCC_BDCR_LSERDY))
|
||||||
;
|
;
|
||||||
RCC->BDCR |= RCC_BDCR_RTCEN;
|
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
|
* @notapi
|
||||||
*/
|
*/
|
||||||
inline uint32_t rtc_lld_get_sec(void){
|
inline uint32_t rtc_lld_get_time(uint16_t *msec){
|
||||||
return ((RTC->CNTH << 16) + RTC->CNTL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return fractional part of current time (milliseconds).
|
|
||||||
*
|
|
||||||
* @notapi
|
|
||||||
*/
|
|
||||||
inline uint16_t rtc_lld_get_msec(void){
|
|
||||||
uint32_t time_frac = 0;
|
uint32_t time_frac = 0;
|
||||||
|
if(msec != NULL){
|
||||||
time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -100,8 +100,7 @@ extern "C" {
|
||||||
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflow_cb,
|
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflow_cb,
|
||||||
rtccb_t second_cb, rtccb_t alarm_cb);
|
rtccb_t second_cb, rtccb_t alarm_cb);
|
||||||
void rtc_lld_set_time(uint32_t tv_sec);
|
void rtc_lld_set_time(uint32_t tv_sec);
|
||||||
uint32_t rtc_lld_get_sec(void);
|
uint32_t rtc_lld_get_time(uint16_t *msec);
|
||||||
uint16_t rtc_lld_get_msec(void);
|
|
||||||
uint32_t rtc_lld_get_alarm(void);
|
uint32_t rtc_lld_get_alarm(void);
|
||||||
void rtc_lld_set_alarm(uint32_t);
|
void rtc_lld_set_alarm(uint32_t);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -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){
|
inline uint32_t rtcGetTime(uint16_t *msec){
|
||||||
return rtc_lld_get_sec();
|
return rtc_lld_get_time(msec);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return fractional part of current time (milliseconds).
|
|
||||||
*/
|
|
||||||
inline uint16_t rtcGetMsec(void){
|
|
||||||
return rtc_lld_get_msec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue