RTC. API changes.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3405 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
5edc2c8b69
commit
41fd0fb5fb
|
@ -74,10 +74,20 @@ extern "C" {
|
|||
rtccb_t secondcb, rtccb_t alarmcb);
|
||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
||||
|
||||
void rtcSetTime(uint32_t tv_sec);
|
||||
uint32_t rtcGetTime(uint16_t *msec);
|
||||
void rtcSetAlarm(uint32_t tv_alarm);
|
||||
uint32_t rtcGetAlarm(void);
|
||||
void rtcSetTime(RTCDateTime *timespec);
|
||||
void rtcGetTime(RTCDateTime *timespec);
|
||||
|
||||
|
||||
|
||||
|
||||
void rtcSetAlarm(RTCDateTime *timespec);
|
||||
void rtcGetAlarm(RTCDateTime *timespec);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -245,18 +245,20 @@ void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflowcb,
|
|||
/**
|
||||
* @brief Set current time.
|
||||
*
|
||||
* @param[in] tv_sec time value in UNIX notation.
|
||||
* @param[in] timespec pointer to variable storing time.
|
||||
*
|
||||
* @note Fractional part will be silently ignored. There is no possibility
|
||||
* to change it on STM32F1xx platform.
|
||||
* @notapi
|
||||
*/
|
||||
void rtc_lld_set_time(uint32_t tv_sec){
|
||||
void rtc_lld_set_time(RTCDateTime *timespec){
|
||||
|
||||
while(!(RTC->CRL & RTC_CRL_RTOFF))
|
||||
;
|
||||
|
||||
RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */
|
||||
RTC->CNTH = (uint16_t)((tv_sec >> 16) & 0xFFFF); /* write time */
|
||||
RTC->CNTL = (uint16_t)(tv_sec & 0xFFFF);
|
||||
RTC->CNTH = (uint16_t)((timespec->tv_sec >> 16) & 0xFFFF);
|
||||
RTC->CNTL = (uint16_t)(timespec->tv_sec & 0xFFFF);
|
||||
RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */
|
||||
|
||||
while(!(RTC->CRL & RTC_CRL_RTOFF)) /* wait for completion */
|
||||
|
@ -264,36 +266,41 @@ void rtc_lld_set_time(uint32_t tv_sec){
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Return return seconds since UNIX epoch.
|
||||
* @brief Get current time.
|
||||
*
|
||||
* @param[in] msec pointer to variable for storing fractional part of
|
||||
* time (milliseconds).
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
inline uint32_t rtc_lld_get_time(uint16_t *msec){
|
||||
inline void rtc_lld_get_time(RTCDateTime *timespec){
|
||||
uint32_t time_frac = 0;
|
||||
if(msec != NULL){
|
||||
time_frac = (((uint32_t)RTC->DIVH) << 16) + (RTC->DIVL);
|
||||
*msec = (uint16_t)(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
|
||||
}
|
||||
return ((RTC->CNTH << 16) + RTC->CNTL);
|
||||
|
||||
timespec->tv_msec = (uint16_t)(((STM32_LSECLK - time_frac) * 1000) / STM32_LSECLK);
|
||||
timespec->tv_sec = (RTC->CNTH << 16) + RTC->CNTL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set alarm date in UNIX notation.
|
||||
* @brief Set alarm time.
|
||||
*
|
||||
* @param[in] timespec pointer to variable storing time of alarm.
|
||||
*
|
||||
* @note Fractional part will be silently ignored. There is no possibility
|
||||
* to change it on STM32F1xx platform.
|
||||
*
|
||||
* @note Default value after BKP domain reset is 0xFFFFFFFF
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void rtc_lld_set_alarm(uint32_t tv_alarm){
|
||||
void rtc_lld_set_alarm(RTCDateTime *timespec){
|
||||
|
||||
while(!(RTC->CRL & RTC_CRL_RTOFF))
|
||||
;
|
||||
|
||||
RTC->CRL |= RTC_CRL_CNF; /* switch on configure mode */
|
||||
RTC->ALRH = (uint16_t)((tv_alarm >> 16) & 0xFFFF); /* write time */
|
||||
RTC->ALRL = (uint16_t)(tv_alarm & 0xFFFF);
|
||||
RTC->ALRH = (uint16_t)((timespec->tv_sec >> 16) & 0xFFFF);
|
||||
RTC->ALRL = (uint16_t)(timespec->tv_sec & 0xFFFF);
|
||||
RTC->CRL &= ~RTC_CRL_CNF; /* switch off configure mode */
|
||||
|
||||
#if !(RTC_SUPPORTS_CALLBACKS)
|
||||
|
@ -306,13 +313,19 @@ void rtc_lld_set_alarm(uint32_t tv_alarm){
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Get current alarm date in UNIX notation.
|
||||
* @brief Get current alarm time.
|
||||
*
|
||||
* @param[in] timespec pointer to variable storing time of alarm.
|
||||
*
|
||||
* @note Fractional part will be silently ignored. There is no possibility
|
||||
* to change it on STM32F1xx platform.
|
||||
*
|
||||
* @note Default value after BKP domain reset is 0xFFFFFFFF
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
inline uint32_t rtc_lld_get_alarm(void){
|
||||
return ((RTC->ALRH << 16) + RTC->ALRL);
|
||||
inline void rtc_lld_get_alarm(RTCDateTime *timespec){
|
||||
timespec->tv_sec = ((RTC->ALRH << 16) + RTC->ALRL);
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +59,21 @@
|
|||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t tv_sec;
|
||||
uint32_t tv_msec;
|
||||
}RTCDateTime;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure representing an RTC driver.
|
||||
* @note This driver if dummy when callbacks disabled.
|
||||
|
@ -99,10 +114,12 @@ extern "C" {
|
|||
void rtc_lld_init(void);
|
||||
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_time(uint16_t *msec);
|
||||
uint32_t rtc_lld_get_alarm(void);
|
||||
void rtc_lld_set_alarm(uint32_t);
|
||||
|
||||
void rtc_lld_set_time(RTCDateTime *timespec);
|
||||
void rtc_lld_get_time(RTCDateTime *timespec);
|
||||
|
||||
void rtc_lld_get_alarm(RTCDateTime *timespec);
|
||||
void rtc_lld_set_alarm(RTCDateTime *timespec);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -15,11 +15,12 @@ PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/STM32F1xx/hal_lld.c \
|
|||
${CHIBIOS}/os/hal/platforms/STM32/GPIOv1/pal_lld.c \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/DMAv1/stm32_dma.c \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/USBv1/usb_lld.c \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/rtc_lld.c
|
||||
${CHIBIOS}/os/hal/platforms/STM32/RTCv1/rtc_lld.c
|
||||
|
||||
# Required include directories
|
||||
PLATFORMINC = ${CHIBIOS}/os/hal/platforms/STM32F1xx \
|
||||
${CHIBIOS}/os/hal/platforms/STM32 \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/GPIOv1 \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/DMAv1 \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/USBv1
|
||||
${CHIBIOS}/os/hal/platforms/STM32/USBv1 \
|
||||
${CHIBIOS}/os/hal/platforms/STM32/RTCv1
|
||||
|
|
|
@ -83,36 +83,42 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
|
|||
|
||||
/**
|
||||
* @brief Set current time.
|
||||
* @param[in] tv_sec - time value in UNIX notation.
|
||||
*/
|
||||
void rtcSetTime(uint32_t tv_sec){
|
||||
rtc_lld_set_time(tv_sec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return return seconds since UNIX epoch.
|
||||
*
|
||||
* @param[in] msec pointer to variable for storing fractional part of
|
||||
* time (milliseconds).
|
||||
* @param[in] timespec pointer to variable storing time.
|
||||
*/
|
||||
void rtcSetTime(RTCDateTime *timespec){
|
||||
chDbgCheck((timespec != NULL), "rtcSetTime");
|
||||
rtc_lld_set_time(timespec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current time.
|
||||
*
|
||||
* @notapi
|
||||
* @param[in] timespec pointer to variable storing time.
|
||||
*/
|
||||
inline uint32_t rtcGetTime(uint16_t *msec){
|
||||
return rtc_lld_get_time(msec);
|
||||
void rtcGetTime(RTCDateTime *timespec){
|
||||
chDbgCheck((timespec != NULL), "rtcGetTime");
|
||||
rtc_lld_get_time(timespec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set alarm date in UNIX notation.
|
||||
* @brief Set alarm time.
|
||||
*
|
||||
* @param[in] timespec pointer to variable storing time of alarm.
|
||||
*/
|
||||
void rtcSetAlarm(uint32_t tv_alarm){
|
||||
rtc_lld_set_alarm(tv_alarm);
|
||||
void rtcSetAlarm(RTCDateTime *timespec){
|
||||
chDbgCheck((timespec != NULL), "rtcSetAlarm");
|
||||
rtc_lld_set_alarm(timespec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current alarm date in UNIX notation.
|
||||
* @brief Get current alarm.
|
||||
*
|
||||
* @param[in] timespec pointer to variable to store alarm time.
|
||||
*/
|
||||
inline uint32_t rtcGetAlarm(void){
|
||||
return rtc_lld_get_alarm();
|
||||
void rtcGetAlarm(RTCDateTime *timespec){
|
||||
chDbgCheck((timespec != NULL), "rtcGetAlarm");
|
||||
rtc_lld_get_alarm(timespec);
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_RTC */
|
||||
|
|
Loading…
Reference in New Issue