git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7012 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2014-07-07 13:00:34 +00:00
parent 04683ac245
commit f7aebc96d5
7 changed files with 150 additions and 35 deletions

View File

@ -320,32 +320,32 @@ void rtc_lld_set_alarm(RTCDriver *rtcp,
rtcalarm_t alarm,
const RTCAlarm *alarmspec) {
if (alarm == 1){
if (alarmspec != NULL){
rtcp->id_rtc->CR &= ~RTC_CR_ALRAE;
while(!(rtcp->id_rtc->ISR & RTC_ISR_ALRAWF))
if (alarm == 1) {
if (alarmspec != NULL) {
rtcp->rtc->CR &= ~RTC_CR_ALRAE;
while (!(rtcp->rtc->ISR & RTC_ISR_ALRAWF))
;
rtcp->id_rtc->ALRMAR = alarmspec->tv_datetime;
rtcp->id_rtc->CR |= RTC_CR_ALRAE;
rtcp->id_rtc->CR |= RTC_CR_ALRAIE;
rtcp->rtc->ALRMAR = alarmspec->alrmr;
rtcp->rtc->CR |= RTC_CR_ALRAE;
rtcp->rtc->CR |= RTC_CR_ALRAIE;
}
else {
rtcp->id_rtc->CR &= ~RTC_CR_ALRAIE;
rtcp->id_rtc->CR &= ~RTC_CR_ALRAE;
rtcp->rtc->CR &= ~RTC_CR_ALRAIE;
rtcp->rtc->CR &= ~RTC_CR_ALRAE;
}
}
else{
if (alarmspec != NULL){
rtcp->id_rtc->CR &= ~RTC_CR_ALRBE;
while(!(rtcp->id_rtc->ISR & RTC_ISR_ALRBWF))
else {
if (alarmspec != NULL) {
rtcp->rtc->CR &= ~RTC_CR_ALRBE;
while (!(rtcp->rtc->ISR & RTC_ISR_ALRBWF))
;
rtcp->id_rtc->ALRMBR = alarmspec->tv_datetime;
rtcp->id_rtc->CR |= RTC_CR_ALRBE;
rtcp->id_rtc->CR |= RTC_CR_ALRBIE;
rtcp->rtc->ALRMBR = alarmspec->alrmr;
rtcp->rtc->CR |= RTC_CR_ALRBE;
rtcp->rtc->CR |= RTC_CR_ALRBIE;
}
else {
rtcp->id_rtc->CR &= ~RTC_CR_ALRBIE;
rtcp->id_rtc->CR &= ~RTC_CR_ALRBE;
rtcp->rtc->CR &= ~RTC_CR_ALRBIE;
rtcp->rtc->CR &= ~RTC_CR_ALRBE;
}
}
}
@ -363,12 +363,61 @@ void rtc_lld_get_alarm(RTCDriver *rtcp,
rtcalarm_t alarm,
RTCAlarm *alarmspec) {
if (alarm == 1)
alarmspec->tv_datetime = rtcp->id_rtc->ALRMAR;
alarmspec->alrmr = rtcp->rtc->ALRMAR;
else
alarmspec->tv_datetime = rtcp->id_rtc->ALRMBR;
alarmspec->alrmr = rtcp->rtc->ALRMBR;
}
#endif /* STM32_RTC_NUM_ALARMS > 0 */
#if STM32_RTC_HAS_PERIODIC_WAKEUPS || defined(__DOXYGEN__)
/**
* @brief Sets time of periodic wakeup.
*
* @note Default value after BKP domain reset is 0x0000FFFF
*
* @param[in] rtcp pointer to RTC driver structure
* @param[in] wakeupspec pointer to a @p RTCWakeup structure
*
* @api
*/
void rtcSTM32SetPeriodicWakeup(RTCDriver *rtcp, const RTCWakeup *wakeupspec) {
if (wakeupspec != NULL) {
osalDbgCheck(wakeupspec->wutr != 0x30000);
rtcp->rtc->CR &= ~RTC_CR_WUTE;
while (!(rtcp->rtc->ISR & RTC_ISR_WUTWF))
;
rtcp->rtc->WUTR = wakeupspec->wutr & 0xFFFF;
rtcp->rtc->CR = (wakeupspec->wutr >> 16) & 0x7;
rtcp->rtc->CR |= RTC_CR_WUTIE;
rtcp->rtc->CR |= RTC_CR_WUTE;
}
else {
rtcp->rtc->CR &= ~RTC_CR_WUTIE;
rtcp->rtc->CR &= ~RTC_CR_WUTE;
}
}
/**
* @brief Gets time of periodic wakeup.
*
* @note Default value after BKP domain reset is 0x0000FFFF
*
* @param[in] rtcp pointer to RTC driver structure
* @param[out] wakeupspec pointer to a @p RTCWakeup structure
*
* @api
*/
void rtcSTM32GetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
wakeupspec->wutr = 0;
wakeupspec->wutr |= rtcp->rtc->WUTR;
wakeupspec->wutr |= (((uint32_t)rtcp->rtc->CR) & 0x7) << 16;
}
#endif /* STM32_RTC_HAS_PERIODIC_WAKEUPS */
#endif /* HAL_USE_RTC */
/** @} */

View File

@ -38,12 +38,31 @@
/**
* @brief Callback support int the driver.
*/
#define RTC_SUPPORTS_CALLBACKS STM32_RTC_HAS_INTERRUPTS
#define RTC_SUPPORTS_CALLBACKS STM32_RTC_HAS_INTERRUPTS
/**
* @brief RTC PRER register initializer.
*/
#define RTC_PRER(a, s) ((((a) - 1) << 16) | ((s) - 1))
#define RTC_PRER(a, s) ((((a) - 1) << 16) | ((s) - 1))
/**
* @name Alarm helper macros
* @{
*/
#define RTC_ALRM_MSK4 (1U << 31)
#define RTC_ALRM_WDSEL (1U << 30)
#define RTC_ALRM_DT(n) ((n) << 28)
#define RTC_ALRM_DU(n) ((n) << 24)
#define RTC_ALRM_MSK3 (1U << 23)
#define RTC_ALRM_HT(n) ((n) << 20)
#define RTC_ALRM_HU(n) ((n) << 16)
#define RTC_ALRM_MSK2 (1U << 15)
#define RTC_ALRM_MNT(n) ((n) << 12)
#define RTC_ALRM_MNU(n) ((n) << 8)
#define RTC_ALRM_MSK1 (1U << 7)
#define RTC_ALRM_ST(n) ((n) << 4)
#define RTC_ALRM_SU(n) ((n) << 0)
/** @} */
/*===========================================================================*/
/* Driver pre-compile time settings. */
@ -98,12 +117,40 @@
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief Type of an RTC alarm number.
*/
typedef uint32_t rtcalarm_t;
/**
* @brief Type of a structure representing an RTC alarm time stamp.
*/
typedef struct {
/**
* @brief Type of an alarm as encoded in RTC ALRMxR registers.
*/
uint32_t alrmr;
} RTCAlarm;
#if STM32_RTC_HAS_PERIODIC_WAKEUPS
/**
* @brief Type of a wakeup as encoded in RTC WUTR register.
*/
typedef struct {
/**
* @brief Wakeup as encoded in RTC WUTR register.
* @note ((WUTR == 0) || (WUCKSEL == 3)) are a forbidden combination.
*/
uint32_t wutr;
} RTCWakeup;
#endif
/**
* @brief Structure representing an RTC driver.
*/
struct RTCDriver {
/**
* @brief Pointer to the RTC registers block.
* @brief Pointer to the RTC registers block.
*/
RTC_TypeDef *rtc;
};
@ -134,6 +181,10 @@ extern "C" {
rtcalarm_t alarm,
RTCAlarm *alarmspec);
#endif
#if STM32_RTC_HAS_PERIODIC_WAKEUPS
void rtcSTM32SetPeriodicWakeup(RTCDriver *rtcp, const RTCWakeup *wakeupspec);
void rtcSTM32GetPeriodicWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
#endif /* STM32_RTC_HAS_PERIODIC_WAKEUPS */
#ifdef __cplusplus
}
#endif

View File

@ -83,8 +83,10 @@
/* RTC attributes.*/
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_SUBSECONDS FALSE
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_HAS_SUBSECONDS TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 1
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO FALSE
@ -214,8 +216,10 @@
/* RTC attributes.*/
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_SUBSECONDS FALSE
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_HAS_SUBSECONDS TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 1
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO FALSE
@ -336,8 +340,10 @@
/* RTC attributes.*/
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_SUBSECONDS FALSE
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_HAS_SUBSECONDS TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS FALSE
#define STM32_RTC_NUM_ALARMS 1
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO FALSE

View File

@ -88,7 +88,9 @@
/* RTC attributes.*/
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_SUBSECONDS TRUE
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 1
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO FALSE

View File

@ -88,7 +88,9 @@
/* RTC attributes.*/
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_SUBSECONDS TRUE
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 1
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO FALSE

View File

@ -125,8 +125,8 @@
#else
#define STM32_RTC_HAS_SUBSECONDS FALSE
#endif
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_NUM_ALARMS /*2*/0
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 2
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/

View File

@ -90,7 +90,10 @@
#else
#define STM32_RTC_HAS_SUBSECONDS FALSE
#endif
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 2
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO TRUE
@ -231,7 +234,9 @@
/* RTC attributes.*/
#define STM32_HAS_RTC TRUE
#define STM32_RTC_HAS_SUBSECONDS TRUE
#define STM32_RTC_IS_CALENDAR TRUE
#define STM32_RTC_HAS_PERIODIC_WAKEUPS TRUE
#define STM32_RTC_NUM_ALARMS 2
#define STM32_RTC_HAS_INTERRUPTS FALSE
/* SDIO attributes.*/
#define STM32_HAS_SDIO TRUE