diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-12-16 14:42:23 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-12-16 14:42:23 +0000 |
commit | 968d0cf6e9e8f362021e4288cd3336fe7922e00e (patch) | |
tree | be576765d1d02f9ad6b36f18542f0f4f06295740 | |
parent | 172680aea3057dcea62fc4a053510d2dd03bb911 (diff) | |
download | ChibiOS-968d0cf6e9e8f362021e4288cd3336fe7922e00e.tar.gz ChibiOS-968d0cf6e9e8f362021e4288cd3336fe7922e00e.tar.bz2 ChibiOS-968d0cf6e9e8f362021e4288cd3336fe7922e00e.zip |
RTC. High level API rolled back.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3619 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | os/hal/include/rtc.h | 11 | ||||
-rw-r--r-- | os/hal/platforms/STM32/RTCv1/rtc_lld.c | 28 | ||||
-rw-r--r-- | os/hal/src/rtc.c | 44 | ||||
-rw-r--r-- | testhal/STM32F1xx/RTC/main.c | 26 |
4 files changed, 33 insertions, 76 deletions
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index 354640a11..1264c5bd8 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -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
diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c index 2e95bc446..1097e1e9b 100644 --- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c @@ -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);
+ 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;
@@ -278,8 +279,8 @@ void rtc_lld_set_alarm(RTCDriver *rtcp, *
* @note Default value after BKP domain reset is 0xFFFFFFFF.
*
- * @param[in] rtcp pointer to RTC driver structure
- * @param[in] alarm alarm identifier
+ * @param[in] rtcp pointer to RTC driver structure
+ * @param[in] alarm alarm identifier
* @param[out] alarmspec pointer to a @p RTCAlarm structure
*
* @notapi
@@ -304,13 +305,14 @@ 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.*/
+ way there is no need to check for the NULL callback pointer inside
+ the IRQ handler.*/
rtc_lld_wait_write();
RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
rtc_lld_wait_write();
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 20a39ea7c..dda5a9c95 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -117,8 +117,8 @@ void rtcSetAlarm(RTCDriver *rtcp, * @note If an alarm has not been set then the returned alarm specification
* is not meaningful.
*
- * @param[in] rtcp pointer to RTC driver structure
- * @param[in] alarm alarm identifier
+ * @param[in] rtcp pointer to RTC driver structure
+ * @param[in] alarm alarm identifier
* @param[out] alarmspec pointer to a @p RTCAlarm structure
*
* @api
@@ -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 */
diff --git a/testhal/STM32F1xx/RTC/main.c b/testhal/STM32F1xx/RTC/main.c index e8e3480ec..ea7155f47 100644 --- a/testhal/STM32F1xx/RTC/main.c +++ b/testhal/STM32F1xx/RTC/main.c @@ -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){
+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);
}
|