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
This commit is contained in:
barthess 2011-09-07 12:53:27 +00:00
parent b8ad6dbae6
commit d077159389
4 changed files with 77 additions and 68 deletions

View File

@ -70,11 +70,8 @@ extern "C" {
void rtcInit(void); void rtcInit(void);
#if RTC_SUPPORTS_CALLBACKS #if RTC_SUPPORTS_CALLBACKS
void rtcStart(RTCDriver *rtcp, const RTCConfig *rtccfgp); void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
void rtcStop(void); rtccb_t secondcb, rtccb_t alarmcb);
#else /* RTC_SUPPORTS_CALLBACKS */
#define rtcStart(rtcp, rtccfgp)
#define rtcStop()
#endif /* RTC_SUPPORTS_CALLBACKS */ #endif /* RTC_SUPPORTS_CALLBACKS */
void rtcSetTime(uint32_t tv_sec); void rtcSetTime(uint32_t tv_sec);

View File

@ -62,20 +62,20 @@ static void rtc_lld_serve_interrupt(RTCDriver *rtcp){
if ((RTC->CRH & RTC_CRH_SECIE) && \ if ((RTC->CRH & RTC_CRH_SECIE) && \
(RTC->CRL & RTC_CRL_SECF) && \ (RTC->CRL & RTC_CRL_SECF) && \
(rtcp->config->second_cb != NULL)){ (rtcp->second_cb != NULL)){
rtcp->config->second_cb(rtcp); rtcp->second_cb(rtcp);
RTC->CRL &= ~RTC_CRL_SECF; RTC->CRL &= ~RTC_CRL_SECF;
} }
if ((RTC->CRH & RTC_CRH_ALRIE) && \ if ((RTC->CRH & RTC_CRH_ALRIE) && \
(RTC->CRL & RTC_CRL_ALRF) && \ (RTC->CRL & RTC_CRL_ALRF) && \
(rtcp->config->alarm_cb != NULL)){ (rtcp->alarm_cb != NULL)){
rtcp->config->alarm_cb(rtcp); rtcp->alarm_cb(rtcp);
RTC->CRL &= ~RTC_CRL_ALRF; RTC->CRL &= ~RTC_CRL_ALRF;
} }
if ((RTC->CRH & RTC_CRH_OWIE) && \ if ((RTC->CRH & RTC_CRH_OWIE) && \
(RTC->CRL & RTC_CRL_OWF) && \ (RTC->CRL & RTC_CRL_OWF) && \
(rtcp->config->overflow_cb != NULL)){ (rtcp->overflow_cb != NULL)){
rtcp->config->overflow_cb(rtcp); rtcp->overflow_cb(rtcp);
RTC->CRL &= ~RTC_CRL_OWF; 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->CRH &= ~(RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE);
RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF); 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. * @brief Enables and disables callbacks on the fly.
* This function do nothing if callbacks disabled.
* *
* @param[in] rtcp pointer to a @p RTCDriver object * @details Pass callback function(s) in argument(s) to enable callback(s).
* @param[in] rtccfgp pointer to a @p RTCDriver config object * 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 * @notapi
*/ */
void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp){ #if RTC_SUPPORTS_CALLBACKS
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflowcb,
rtccb_t secondcb, rtccb_t alarmcb){
uint16_t isr_flags = 0; uint16_t isr_flags = 0;
NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY)); if (overflowcb != NULL){
rtcp->overflow_cb = *overflowcb;
rtcp->config = rtccfgp;
if (rtcp->config->overflow_cb != NULL){
isr_flags |= RTC_CRH_OWIE; 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; isr_flags |= RTC_CRH_ALRIE;
} }
if (rtcp->config->second_cb != NULL){ else{
isr_flags |= RTC_CRH_SECIE; rtcp->alarm_cb = NULL;
isr_flags &= ~RTC_CRH_ALRIE;
} }
/* clear all event flags just to be safe */ if (secondcb != NULL){
RTC->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF); rtcp->second_cb = *secondcb;
RTC->CRH |= isr_flags; isr_flags |= RTC_CRH_SECIE;
} }
else{
rtcp->second_cb = NULL;
isr_flags &= ~RTC_CRH_SECIE;
}
/** if(isr_flags != 0){
* @brief Disable interrupt servicing routines. NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
* RTC->CRH |= isr_flags;
* @notapi }
*/ else{
void rtc_lld_stop(void){ NVICDisableVector(RTC_IRQn);
NVICDisableVector(RTC_IRQn); RTC->CRH = 0;
RTC->CRH = 0; }
} }
#endif /* RTC_SUPPORTS_CALLBACKS */
/** /**
* @brief Set current time. * @brief Set current time.

View File

@ -66,10 +66,12 @@
/*===========================================================================*/ /*===========================================================================*/
/* Driver data structures and types. */ /* 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. * @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. * @brief Alarm callback. Set it to NULL if not used.
*/ */
rtccb_t alarm_cb; rtccb_t alarm_cb;
}RTCConfig; #endif /* RTC_SUPPORTS_CALLBACKS */
/**
* @brief Structure representing an RTC driver.
*/
struct RTCDriver{
/**
* @brief Pointer to RCT config.
*/
const RTCConfig *config;
}; };
/*===========================================================================*/ /*===========================================================================*/
@ -112,8 +104,8 @@ extern RTCDriver RTCD;
extern "C" { extern "C" {
#endif #endif
void rtc_lld_init(void); void rtc_lld_init(void);
void rtc_lld_start(RTCDriver *rtcp, const RTCConfig *rtccfgp); void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t overflow_cb,
void rtc_lld_stop(void); rtccb_t second_cb, rtccb_t alarm_cb);
void rtc_lld_set_time(uint32_t tv_sec); void rtc_lld_set_time(uint32_t tv_sec);
uint32_t rtc_lld_get_sec(void); uint32_t rtc_lld_get_sec(void);
uint16_t rtc_lld_get_msec(void); uint16_t rtc_lld_get_msec(void);

View File

@ -61,26 +61,23 @@ void rtcInit(void){
rtc_lld_init(); rtc_lld_init();
} }
#if RTC_SUPPORTS_CALLBACKS
/** /**
* @brief Configure and start interrupt servicing routines. * @brief Enables and disables callbacks on the fly.
* This function do nothing if callbacks disabled. * @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] rtcp - pointer to RTC driver structure.
* @param[in] rtccfgp - pointer to RTC config structure. * @param[in] overflowcb - overflow callback function.
* @param[in] secondcb - every second callback function.
* @param[in] alarmcb - alarm callback function.
*/ */
#if RTC_SUPPORTS_CALLBACKS void rtcSetCallback(RTCDriver *rtcp, rtccb_t overflowcb,
void rtcStartI(RTCDriver *rtcp, const RTCConfig *rtccfgp){ rtccb_t secondcb, rtccb_t alarmcb){
chDbgCheckClassI(); chDbgCheck((rtcp != NULL), "rtcStart");
chDbgCheck(((rtcp != NULL) && (rtccfgp != NULL)), "rtcStart"); rtc_lld_set_callback(rtcp, overflowcb, secondcb, alarmcb);
rtc_lld_start(rtcp, rtccfgp);
}
/**
* @brief Stop interrupt servicing routines.
*/
void rtcStopI(void){
chDbgCheckClassI();
rtc_lld_stop();
} }
#endif /* RTC_SUPPORTS_CALLBACKS */ #endif /* RTC_SUPPORTS_CALLBACKS */