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
master
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);
#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);

View File

@ -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){
#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;
NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
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.

View File

@ -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);

View File

@ -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.
* @param[in] overflowcb - overflow callback function.
* @param[in] secondcb - every second callback function.
* @param[in] alarmcb - alarm callback function.
*/
#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.
*/
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 */