RTC. High level API rolled back.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3619 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
172680aea3
commit
968d0cf6e9
|
@ -85,20 +85,15 @@ extern "C" {
|
||||||
void rtcInit(void);
|
void rtcInit(void);
|
||||||
void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec);
|
void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec);
|
||||||
void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec);
|
void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec);
|
||||||
void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
|
|
||||||
void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
|
|
||||||
|
|
||||||
#if RTC_ALARMS > 0
|
#if RTC_ALARMS > 0
|
||||||
void rtcSetAlarm(RTCDriver *rtcp,
|
void rtcSetAlarm(RTCDriver *rtcp,
|
||||||
rtcalarm_t alarm,
|
rtcalarm_t alarm,
|
||||||
const RTCAlarm *alarmspec);
|
const RTCAlarm *alarmspec);
|
||||||
void rtcGetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec);
|
void rtcGetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec);
|
||||||
#endif /* RTC_ALARMS > 0 */
|
#endif
|
||||||
|
|
||||||
#if RTC_SUPPORTS_CALLBACKS
|
#if RTC_SUPPORTS_CALLBACKS
|
||||||
void rtcSetCallback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg);
|
void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback);
|
||||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,16 +60,16 @@ static void rtc_lld_serve_interrupt(RTCDriver *rtcp) {
|
||||||
chSysLockFromIsr();
|
chSysLockFromIsr();
|
||||||
|
|
||||||
if ((RTC->CRH & RTC_CRH_SECIE) && (RTC->CRL & RTC_CRL_SECF)) {
|
if ((RTC->CRH & RTC_CRH_SECIE) && (RTC->CRL & RTC_CRL_SECF)) {
|
||||||
RTC->CRL &= ~RTC_CRL_SECF;
|
|
||||||
rtcp->rtc_cb(rtcp, RTC_EVENT_SECOND);
|
rtcp->rtc_cb(rtcp, RTC_EVENT_SECOND);
|
||||||
|
RTC->CRL &= ~RTC_CRL_SECF;
|
||||||
}
|
}
|
||||||
if ((RTC->CRH & RTC_CRH_ALRIE) && (RTC->CRL & RTC_CRL_ALRF)) {
|
if ((RTC->CRH & RTC_CRH_ALRIE) && (RTC->CRL & RTC_CRL_ALRF)) {
|
||||||
RTC->CRL &= ~RTC_CRL_ALRF;
|
rtcp->rtc_cb(rtcp, RTC_EVENT_ALARM);
|
||||||
rtcp->rtc_cb(rtcp, RTC_EVENT_ALARM);
|
RTC->CRL &= ~RTC_CRL_ALRF;
|
||||||
}
|
}
|
||||||
if ((RTC->CRH & RTC_CRH_OWIE) && (RTC->CRL & RTC_CRL_OWF)) {
|
if ((RTC->CRH & RTC_CRH_OWIE) && (RTC->CRL & RTC_CRL_OWF)) {
|
||||||
RTC->CRL &= ~RTC_CRL_OWF;
|
|
||||||
rtcp->rtc_cb(rtcp, RTC_EVENT_OVERFLOW);
|
rtcp->rtc_cb(rtcp, RTC_EVENT_OVERFLOW);
|
||||||
|
RTC->CRL &= ~RTC_CRL_OWF;
|
||||||
}
|
}
|
||||||
|
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
|
@ -138,6 +138,7 @@ void rtc_lld_init(void){
|
||||||
while (!(RCC->BDCR & RCC_BDCR_LSERDY))
|
while (!(RCC->BDCR & RCC_BDCR_LSERDY))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
preload = STM32_LSECLK - 1;
|
||||||
#elif STM32_RTC == STM32_RTC_LSI
|
#elif STM32_RTC == STM32_RTC_LSI
|
||||||
#define RTC_CLK STM32_LSICLK
|
#define RTC_CLK STM32_LSICLK
|
||||||
/* TODO: Move the LSI clock initialization in the HAL low level driver.*/
|
/* TODO: Move the LSI clock initialization in the HAL low level driver.*/
|
||||||
|
@ -150,12 +151,12 @@ void rtc_lld_init(void){
|
||||||
volatile uint32_t tmo = (STM32_SYSCLK / 1000000) * 100;
|
volatile uint32_t tmo = (STM32_SYSCLK / 1000000) * 100;
|
||||||
while (tmo--)
|
while (tmo--)
|
||||||
;
|
;
|
||||||
|
preload = STM32_LSICLK - 1;
|
||||||
#elif STM32_RTC == STM32_RTC_HSE
|
#elif STM32_RTC == STM32_RTC_HSE
|
||||||
#define RTC_CLK (STM32_HSECLK / 128)
|
#define RTC_CLK (STM32_HSECLK / 128)
|
||||||
|
preload = (STM32_HSECLK / 128) - 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
preload = RTC_CLK - 1;
|
|
||||||
|
|
||||||
/* Selects clock source (previously enabled and stabilized).*/
|
/* Selects clock source (previously enabled and stabilized).*/
|
||||||
RCC->BDCR = (RCC->BDCR & ~RCC_BDCR_RTCSEL) | STM32_RTC;
|
RCC->BDCR = (RCC->BDCR & ~RCC_BDCR_RTCSEL) | STM32_RTC;
|
||||||
|
|
||||||
|
@ -278,8 +279,8 @@ void rtc_lld_set_alarm(RTCDriver *rtcp,
|
||||||
*
|
*
|
||||||
* @note Default value after BKP domain reset is 0xFFFFFFFF.
|
* @note Default value after BKP domain reset is 0xFFFFFFFF.
|
||||||
*
|
*
|
||||||
* @param[in] rtcp pointer to RTC driver structure
|
* @param[in] rtcp pointer to RTC driver structure
|
||||||
* @param[in] alarm alarm identifier
|
* @param[in] alarm alarm identifier
|
||||||
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
|
@ -304,13 +305,14 @@ void rtc_lld_get_alarm(RTCDriver *rtcp,
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) {
|
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
|
||||||
|
|
||||||
|
if (callback != NULL) {
|
||||||
|
rtcp->rtc_cb = callback;
|
||||||
|
|
||||||
if (cb_cfg->rtc_cb != NULL) {
|
|
||||||
rtcp->rtc_cb = cb_cfg->rtc_cb;
|
|
||||||
/* Interrupts are enabled only after setting up the callback, this
|
/* Interrupts are enabled only after setting up the callback, this
|
||||||
way there is no need to check for the NULL callback pointer inside
|
way there is no need to check for the NULL callback pointer inside
|
||||||
the IRQ handler.*/
|
the IRQ handler.*/
|
||||||
rtc_lld_wait_write();
|
rtc_lld_wait_write();
|
||||||
RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
|
RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
|
||||||
rtc_lld_wait_write();
|
rtc_lld_wait_write();
|
||||||
|
|
|
@ -117,8 +117,8 @@ void rtcSetAlarm(RTCDriver *rtcp,
|
||||||
* @note If an alarm has not been set then the returned alarm specification
|
* @note If an alarm has not been set then the returned alarm specification
|
||||||
* is not meaningful.
|
* is not meaningful.
|
||||||
*
|
*
|
||||||
* @param[in] rtcp pointer to RTC driver structure
|
* @param[in] rtcp pointer to RTC driver structure
|
||||||
* @param[in] alarm alarm identifier
|
* @param[in] alarm alarm identifier
|
||||||
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
|
@ -134,50 +134,22 @@ void rtcGetAlarm(RTCDriver *rtcp,
|
||||||
}
|
}
|
||||||
#endif /* RTC_ALARMS > 0 */
|
#endif /* RTC_ALARMS > 0 */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set periodic wakeup period.
|
|
||||||
*
|
|
||||||
* @param[in] rtcp pointer to RTC driver structure
|
|
||||||
* @param[in] wakeupspec pointer to a @p RTCWakeup structure
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
|
|
||||||
|
|
||||||
chDbgCheck((rtcp != NULL), "rtcGetAlarm");
|
|
||||||
rtc_lld_set_periodic_wakeup(rtcp, wakeupspec);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get periodic wakeup period.
|
|
||||||
*
|
|
||||||
* @param[in] rtcp pointer to RTC driver structure
|
|
||||||
* @param[out] wakeupspec pointer to a @p RTCWakeup structure
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec) {
|
|
||||||
|
|
||||||
chDbgCheck((rtcp != NULL), "rtcGetAlarm");
|
|
||||||
rtc_lld_get_periodic_wakeup(rtcp, wakeupspec);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__)
|
#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Enables or disables RTC callbacks.
|
* @brief Enables or disables RTC callbacks.
|
||||||
|
* @details This function enables or disables callbacks, use a @p NULL pointer
|
||||||
|
* in order to disable a callback.
|
||||||
*
|
*
|
||||||
* @param[in] rtcp pointer to RTC driver structure
|
* @param[in] rtcp pointer to RTC driver structure
|
||||||
* @param[in] cb_cfg callback configuration struct
|
* @param[in] callback callback function pointer or @p NULL
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void rtcSetCallback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) {
|
void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) {
|
||||||
|
|
||||||
chDbgCheck(((rtcp != NULL) && (cb_cfg != NULL)), "rtcSetCallback");
|
chDbgCheck((rtcp != NULL), "rtcSetCallback");
|
||||||
|
|
||||||
rtc_lld_set_callback(rtcp, cb_cfg);
|
rtc_lld_set_callback(rtcp, callback);
|
||||||
}
|
}
|
||||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
#endif /* RTC_SUPPORTS_CALLBACKS */
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ int main(void) {
|
||||||
|
|
||||||
chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL);
|
chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL);
|
||||||
/* set alarm in near future */
|
/* set alarm in near future */
|
||||||
rtcGetTime(&RTCD1, ×pec);
|
rtcGetTime(×pec);
|
||||||
alarmspec.tv_sec = timespec.tv_sec + 60;
|
alarmspec.tv_sec = timespec.tv_sec + 60;
|
||||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
rtcSetAlarm(&alarmspec);
|
||||||
|
|
||||||
while (TRUE){
|
while (TRUE){
|
||||||
chThdSleepSeconds(10);
|
chThdSleepSeconds(10);
|
||||||
|
@ -63,10 +63,8 @@ int main(void) {
|
||||||
|
|
||||||
#else /* TEST_ALARM_WAKEUP */
|
#else /* TEST_ALARM_WAKEUP */
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback function for RTC.
|
|
||||||
*/
|
|
||||||
static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
|
static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
|
||||||
|
|
||||||
(void)rtcp;
|
(void)rtcp;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
@ -79,31 +77,21 @@ static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
|
||||||
case RTC_EVENT_ALARM:
|
case RTC_EVENT_ALARM:
|
||||||
palTogglePad(GPIOC, GPIOC_LED);
|
palTogglePad(GPIOC, GPIOC_LED);
|
||||||
rtcGetTime(&RTCD1, ×pec);
|
rtcGetTime(&RTCD1, ×pec);
|
||||||
alarmspec.tv_sec = timespec.tv_sec + 5;
|
alarmspec.tv_sec = timespec.tv_sec + 10;
|
||||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int main(void) {
|
||||||
* Configuration structure with all callbacks supported by platform.
|
|
||||||
*/
|
|
||||||
static RTCCallbackConfig rtc_cb_cfg = {
|
|
||||||
my_cb
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main function.
|
|
||||||
*/
|
|
||||||
int main(void){
|
|
||||||
halInit();
|
halInit();
|
||||||
chSysInit();
|
chSysInit();
|
||||||
|
|
||||||
rtcGetTime(&RTCD1, ×pec);
|
rtcGetTime(&RTCD1, ×pec);
|
||||||
alarmspec.tv_sec = timespec.tv_sec + 5;
|
alarmspec.tv_sec = timespec.tv_sec + 10;
|
||||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
||||||
|
|
||||||
rtcSetCallback(&RTCD1, &rtc_cb_cfg);
|
rtcSetCallback(&RTCD1, my_cb);
|
||||||
while (TRUE){
|
while (TRUE){
|
||||||
chThdSleepMilliseconds(500);
|
chThdSleepMilliseconds(500);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue