diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-09-07 12:53:27 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-09-07 12:53:27 +0000 |
commit | d0771593893ef9f8a9ae4ab689c569b88e3631a9 (patch) | |
tree | 8eaba6cc5552639a5f915193f7fee144da99b34b /os | |
parent | b8ad6dbae6914316f731c99324ccb5052018dfbf (diff) | |
download | ChibiOS-d0771593893ef9f8a9ae4ab689c569b88e3631a9.tar.gz ChibiOS-d0771593893ef9f8a9ae4ab689c569b88e3631a9.tar.bz2 ChibiOS-d0771593893ef9f8a9ae4ab689c569b88e3631a9.zip |
RTC. rtcStart() and rtcStop() functions replaced by rtcSetCallback()
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3293 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/include/rtc.h | 7 | ||||
-rw-r--r-- | os/hal/platforms/STM32/rtc_lld.c | 87 | ||||
-rw-r--r-- | os/hal/platforms/STM32/rtc_lld.h | 22 | ||||
-rw-r--r-- | os/hal/src/rtc.c | 29 |
4 files changed, 77 insertions, 68 deletions
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index 0c545c3a6..e0a2c50c5 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -70,11 +70,8 @@ extern "C" { void rtcInit(void);
#if RTC_SUPPORTS_CALLBACKS
- void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp);
- void rtcStop(void);
- #else /* RTC_SUPPORTS_CALLBACKS */
- #define rtcStart(rtcp, rtccfgp)
- #define rtcStop()
+ void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
+ rtccb_t secondcb, rtccb_t alarmcb);
#endif /* RTC_SUPPORTS_CALLBACKS */
void rtcSetTime(uint32_t tv_sec);
diff --git a/os/hal/platforms/STM32/rtc_lld.c b/os/hal/platforms/STM32/rtc_lld.c index a6032e0a4..4f404ab27 100644 --- a/os/hal/platforms/STM32/rtc_lld.c +++ b/os/hal/platforms/STM32/rtc_lld.c @@ -62,20 +62,20 @@ static void rtc_lld_serve_interrupt(RTCDriver *rtcp){ if ((RTC->CRH & RTC_CRH_SECIE) && \
(RTC->CRL & RTC_CRL_SECF) && \
- (rtcp->config->second_cb != NULL)){
- rtcp->config->second_cb(rtcp);
+ (rtcp->second_cb != NULL)){
+ rtcp->second_cb(rtcp);
RTC->CRL &= ~RTC_CRL_SECF;
}
if ((RTC->CRH & RTC_CRH_ALRIE) && \
(RTC->CRL & RTC_CRL_ALRF) && \
- (rtcp->config->alarm_cb != NULL)){
- rtcp->config->alarm_cb(rtcp);
+ (rtcp->alarm_cb != NULL)){
+ rtcp->alarm_cb(rtcp);
RTC->CRL &= ~RTC_CRL_ALRF;
}
if ((RTC->CRH & RTC_CRH_OWIE) && \
(RTC->CRL & RTC_CRL_OWF) && \
- (rtcp->config->overflow_cb != NULL)){
- rtcp->config->overflow_cb(rtcp);
+ (rtcp->overflow_cb != NULL)){
+ rtcp->overflow_cb(rtcp);
RTC->CRL &= ~RTC_CRL_OWF;
}
@@ -157,49 +157,72 @@ void rtc_lld_init(void){ RTC->CRH &= ~(RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE);
RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF);
- RTCD.config = NULL;
+#if RTC_SUPPORTS_CALLBACKS
+ RTCD.alarm_cb = NULL;
+ RTCD.overflow_cb = NULL;
+ RTCD.second_cb = NULL;
+#endif /* RTC_SUPPORTS_CALLBACKS */
}
/**
- * @brief Configure and start interrupt servicing routines.
- * This function do nothing if callbacks disabled.
+ * @brief Enables and disables callbacks on the fly.
*
- * @param[in] rtcp pointer to a @p RTCDriver object
- * @param[in] rtccfgp pointer to a @p RTCDriver config object
+ * @details Pass callback function(s) in argument(s) to enable callback(s).
+ * Pass NULL to disable callback.
+ *
+ * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS
+ * to @p TRUE.
+ *
+ * @param[in] rtcp pointer to RTC driver structure.
+ * @param[in] overflowcb overflow callback function.
+ * @param[in] secondcb every second callback function.
+ * @param[in] alarmcb alarm callback function.
*
* @notapi
*/
-void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp){
- uint16_t isr_flags = 0;
+#if RTC_SUPPORTS_CALLBACKS
+void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflowcb,
+ rtccb_t secondcb, rtccb_t alarmcb){
- NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
+ uint16_t isr_flags = 0;
- rtcp->config = rtccfgp;
- if (rtcp->config->overflow_cb != NULL){
+ if (overflowcb != NULL){
+ rtcp->overflow_cb = *overflowcb;
isr_flags |= RTC_CRH_OWIE;
}
- if (rtcp->config->alarm_cb != NULL){
+ else{
+ rtcp->overflow_cb = NULL;
+ isr_flags &= ~RTC_CRH_OWIE;
+ }
+
+ if (alarmcb != NULL){
+ rtcp->alarm_cb = *alarmcb;
isr_flags |= RTC_CRH_ALRIE;
}
- if (rtcp->config->second_cb != NULL){
- isr_flags |= RTC_CRH_SECIE;
+ else{
+ rtcp->alarm_cb = NULL;
+ isr_flags &= ~RTC_CRH_ALRIE;
}
- /* clear all event flags just to be safe */
- RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF);
- RTC->CRH |= isr_flags;
-}
+ if (secondcb != NULL){
+ rtcp->second_cb = *secondcb;
+ isr_flags |= RTC_CRH_SECIE;
+ }
+ else{
+ rtcp->second_cb = NULL;
+ isr_flags &= ~RTC_CRH_SECIE;
+ }
-/**
- * @brief Disable interrupt servicing routines.
- *
- * @notapi
- */
-void rtc_lld_stop(void){
- NVICDisableVector(RTC_IRQn);
- RTC->CRH = 0;
+ if(isr_flags != 0){
+ NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
+ RTC->CRH |= isr_flags;
+ }
+ else{
+ NVICDisableVector(RTC_IRQn);
+ RTC->CRH = 0;
+ }
}
-
+#endif /* RTC_SUPPORTS_CALLBACKS */
/**
* @brief Set current time.
diff --git a/os/hal/platforms/STM32/rtc_lld.h b/os/hal/platforms/STM32/rtc_lld.h index 3b4f69665..2ec4427d5 100644 --- a/os/hal/platforms/STM32/rtc_lld.h +++ b/os/hal/platforms/STM32/rtc_lld.h @@ -66,10 +66,12 @@ /*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
+
/**
- * @brief Structure representing an RTC driver config.
+ * @brief Structure representing an RTC driver.
*/
-typedef struct {
+struct RTCDriver{
+#if RTC_SUPPORTS_CALLBACKS
/**
* @brief Overflow callback. Set it to NULL if not used.
*/
@@ -84,17 +86,7 @@ typedef struct { * @brief Alarm callback. Set it to NULL if not used.
*/
rtccb_t alarm_cb;
-}RTCConfig;
-
-
-/**
- * @brief Structure representing an RTC driver.
- */
-struct RTCDriver{
- /**
- * @brief Pointer to RCT config.
- */
- const RTCConfig *config;
+#endif /* RTC_SUPPORTS_CALLBACKS */
};
/*===========================================================================*/
@@ -112,8 +104,8 @@ extern RTCDriver RTCD; extern "C" {
#endif
void rtc_lld_init(void);
- void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp);
- void rtc_lld_stop(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_sec(void);
uint16_t rtc_lld_get_msec(void);
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 8f9025364..ab916cf52 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -61,26 +61,23 @@ void rtcInit(void){ rtc_lld_init();
}
+#if RTC_SUPPORTS_CALLBACKS
/**
- * @brief Configure and start interrupt servicing routines.
- * This function do nothing if callbacks disabled.
+ * @brief Enables and disables callbacks on the fly.
+ * @details Pass callback function(s) in argument(s) to enable callback(s).
+ * Pass NULL to disable callback.
+ * @pre To use this function you must set @p RTC_SUPPORTS_CALLBACKS
+ * to @p TRUE.
*
* @param[in] rtcp - pointer to RTC driver structure.
- * @param[in] rtccfgp - pointer to RTC config structure.
- */
-#if RTC_SUPPORTS_CALLBACKS
-void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){
- chDbgCheckClassI();
- chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart");
- rtc_lld_start(rtcp, rtccfgp);
-}
-
-/**
- * @brief Stop interrupt servicing routines.
+ * @param[in] overflowcb - overflow callback function.
+ * @param[in] secondcb - every second callback function.
+ * @param[in] alarmcb - alarm callback function.
*/
-void rtcStopI(void){
- chDbgCheckClassI();
- rtc_lld_stop();
+void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
+ rtccb_t secondcb, rtccb_t alarmcb){
+ chDbgCheck((rtcp != NULL), "rtcStart");
+ rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb);
}
#endif /* RTC_SUPPORTS_CALLBACKS */
|