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 rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec);
|
||||
void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec);
|
||||
void rtcSetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
|
||||
void rtcGetWakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec);
|
||||
|
||||
#if RTC_ALARMS > 0
|
||||
void rtcSetAlarm(RTCDriver *rtcp,
|
||||
rtcalarm_t alarm,
|
||||
const RTCAlarm *alarmspec);
|
||||
void rtcGetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec);
|
||||
#endif /* RTC_ALARMS > 0 */
|
||||
|
||||
#endif
|
||||
#if RTC_SUPPORTS_CALLBACKS
|
||||
void rtcSetCallback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg);
|
||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
||||
|
||||
void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -60,16 +60,16 @@ static void rtc_lld_serve_interrupt(RTCDriver *rtcp) {
|
|||
chSysLockFromIsr();
|
||||
|
||||
if ((RTC->CRH & RTC_CRH_SECIE) && (RTC->CRL & RTC_CRL_SECF)) {
|
||||
RTC->CRL &= ~RTC_CRL_SECF;
|
||||
rtcp->rtc_cb(rtcp, RTC_EVENT_SECOND);
|
||||
RTC->CRL &= ~RTC_CRL_SECF;
|
||||
}
|
||||
if ((RTC->CRH & RTC_CRH_ALRIE) && (RTC->CRL & RTC_CRL_ALRF)) {
|
||||
RTC->CRL &= ~RTC_CRL_ALRF;
|
||||
rtcp->rtc_cb(rtcp, RTC_EVENT_ALARM);
|
||||
RTC->CRL &= ~RTC_CRL_ALRF;
|
||||
}
|
||||
if ((RTC->CRH & RTC_CRH_OWIE) && (RTC->CRL & RTC_CRL_OWF)) {
|
||||
RTC->CRL &= ~RTC_CRL_OWF;
|
||||
rtcp->rtc_cb(rtcp, RTC_EVENT_OVERFLOW);
|
||||
RTC->CRL &= ~RTC_CRL_OWF;
|
||||
}
|
||||
|
||||
chSysUnlockFromIsr();
|
||||
|
@ -138,6 +138,7 @@ void rtc_lld_init(void){
|
|||
while (!(RCC->BDCR & RCC_BDCR_LSERDY))
|
||||
;
|
||||
}
|
||||
preload = STM32_LSECLK - 1;
|
||||
#elif STM32_RTC == STM32_RTC_LSI
|
||||
#define RTC_CLK STM32_LSICLK
|
||||
/* 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;
|
||||
while (tmo--)
|
||||
;
|
||||
preload = STM32_LSICLK - 1;
|
||||
#elif STM32_RTC == STM32_RTC_HSE
|
||||
#define RTC_CLK (STM32_HSECLK / 128)
|
||||
preload = (STM32_HSECLK / 128) - 1;
|
||||
#endif
|
||||
|
||||
preload = RTC_CLK - 1;
|
||||
|
||||
/* Selects clock source (previously enabled and stabilized).*/
|
||||
RCC->BDCR = (RCC->BDCR & ~RCC_BDCR_RTCSEL) | STM32_RTC;
|
||||
|
||||
|
@ -304,10 +305,11 @@ void rtc_lld_get_alarm(RTCDriver *rtcp,
|
|||
*
|
||||
* @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
|
||||
way there is no need to check for the NULL callback pointer inside
|
||||
the IRQ handler.*/
|
||||
|
|
|
@ -134,50 +134,22 @@ void rtcGetAlarm(RTCDriver *rtcp,
|
|||
}
|
||||
#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__)
|
||||
/**
|
||||
* @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] cb_cfg callback configuration struct
|
||||
* @param[in] callback callback function pointer or @p NULL
|
||||
*
|
||||
* @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 */
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ int main(void) {
|
|||
|
||||
chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL);
|
||||
/* set alarm in near future */
|
||||
rtcGetTime(&RTCD1, ×pec);
|
||||
rtcGetTime(×pec);
|
||||
alarmspec.tv_sec = timespec.tv_sec + 60;
|
||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
||||
rtcSetAlarm(&alarmspec);
|
||||
|
||||
while (TRUE){
|
||||
chThdSleepSeconds(10);
|
||||
|
@ -63,10 +63,8 @@ int main(void) {
|
|||
|
||||
#else /* TEST_ALARM_WAKEUP */
|
||||
|
||||
/**
|
||||
* Callback function for RTC.
|
||||
*/
|
||||
static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
|
||||
|
||||
(void)rtcp;
|
||||
|
||||
switch (event) {
|
||||
|
@ -79,31 +77,21 @@ static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
|
|||
case RTC_EVENT_ALARM:
|
||||
palTogglePad(GPIOC, GPIOC_LED);
|
||||
rtcGetTime(&RTCD1, ×pec);
|
||||
alarmspec.tv_sec = timespec.tv_sec + 5;
|
||||
alarmspec.tv_sec = timespec.tv_sec + 10;
|
||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration structure with all callbacks supported by platform.
|
||||
*/
|
||||
static RTCCallbackConfig rtc_cb_cfg = {
|
||||
my_cb
|
||||
};
|
||||
|
||||
/**
|
||||
* Main function.
|
||||
*/
|
||||
int main(void) {
|
||||
halInit();
|
||||
chSysInit();
|
||||
|
||||
rtcGetTime(&RTCD1, ×pec);
|
||||
alarmspec.tv_sec = timespec.tv_sec + 5;
|
||||
alarmspec.tv_sec = timespec.tv_sec + 10;
|
||||
rtcSetAlarm(&RTCD1, 0, &alarmspec);
|
||||
|
||||
rtcSetCallback(&RTCD1, &rtc_cb_cfg);
|
||||
rtcSetCallback(&RTCD1, my_cb);
|
||||
while (TRUE){
|
||||
chThdSleepMilliseconds(500);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue