RTC. Setting and getting time now works.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3589 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
barthess 2011-12-09 22:14:09 +00:00
parent e7e63d88db
commit 7a78345272
3 changed files with 20 additions and 47 deletions

View File

@ -424,8 +424,9 @@
#define WWDG_IRQHandler Vector40 /**< Window Watchdog. */
#define PVD_IRQHandler Vector44 /**< PVD through EXTI Line
detect. */
#define TAMPER_IRQHandler Vector48 /**< Tamper. */
#define RTC_IRQHandler Vector4C /**< RTC. */
#define TAMP_STAMP_IRQHandler Vector48 /**< Tamper and TimeStamp
through EXTI Line. */
#define RTC_WKUP_IRQHandler Vector4C /**< RTC wakeup EXTI Line. */
#define FLASH_IRQHandler Vector50 /**< Flash. */
#define RCC_IRQHandler Vector54 /**< RCC. */
#define EXTI0_IRQHandler Vector58 /**< EXTI Line 0. */
@ -464,8 +465,8 @@
#define USART2_IRQHandler VectorD8 /**< USART2. */
#define USART3_IRQHandler VectorDC /**< USART3. */
#define EXTI15_10_IRQHandler VectorE0 /**< EXTI Line 15..10. */
#define RTC_Alarm_IRQHandler VectorE4 /**< RTC alarm through EXTI
line. */
#define RTC_Alarm_IRQHandler VectorE4 /**< RTC alarms (A and B)
through EXTI line. */
#define OTG_FS_WKUP_IRQHandler VectorE8 /**< USB OTG FS Wakeup through
EXTI line. */
#define TIM8_BRK_IRQHandler VectorEC /**< TIM8 Break. */

View File

@ -48,42 +48,10 @@ RTCDriver RTCD1;
/* Driver local functions. */
/*===========================================================================*/
/**
* @brief Shared IRQ handler.
*
* @param[in] rtcp pointer to a @p RTCDriver object
*
* @notapi
*/
static void rtc_lld_serve_interrupt(RTCDriver *rtcp) {
chSysLockFromIsr();
rtcp->rtc_cb(rtcp, RTC_EVENT_SECOND);
rtcp->rtc_cb(rtcp, RTC_EVENT_ALARM);
rtcp->rtc_cb(rtcp, RTC_EVENT_OVERFLOW);
chSysUnlockFromIsr();
}
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/**
* @brief RTC interrupt handler.
*
* @isr
*/
CH_IRQ_HANDLER(RTC_IRQHandler) {
CH_IRQ_PROLOGUE();
rtc_lld_serve_interrupt(&RTCD1);
CH_IRQ_EPILOGUE();
}
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
@ -137,18 +105,20 @@ void rtc_lld_init(void){
/* RTC enabled regardless its previous status.*/
RCC->BDCR |= RCC_BDCR_RTCEN;
/* Calendar not init yet. */
if (!(RTC->ISR & RTC_ISR_INITS)){
if (!(RTC->ISR & RTC_ISR_INITS)){/* Calendar not init yet. */
/* Disable write protection on RTC registers. */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Enter in init mode. */
RTC->ISR |= RTC_ISR_INIT;
while(!(RTC->ISR & RTC_ISR_INITF))
;
/* Prescaler registers must be written in by two separate writes. */
RTC->PRER = 0;
RTC->PRER = 0x007F00FF;
RTC->PRER = 0x007F00FF;
RTC->ISR &= ~RTC_ISR_INIT;
/* Wait until calendar data will updated. */
while(!(RTC->ISR & RTC_ISR_RSF))
;
@ -174,9 +144,9 @@ void rtc_lld_set_time(RTCDriver *rtcp, const RTCTime *timespec) {
RTC->ISR |= RTC_ISR_INIT;
while(!(RTC->ISR & RTC_ISR_INITF))
;
RTC->TR = timespec->tv_time;
RTC->DR = timespec->tv_date;
RTC->ISR &= ~RTC_ISR_INIT;
/* Wait until calendar data will updated. */
while(!(RTC->ISR & RTC_ISR_RSF))

View File

@ -43,7 +43,7 @@
/**
* @brief One alarm comparator available.
*/
#define RTC_ALARMS 1
#define RTC_ALARMS 2
/*===========================================================================*/
/* Driver pre-compile time settings. */
@ -80,9 +80,11 @@ typedef uint32_t rtcalarm_t;
* @brief Type of an RTC event.
*/
typedef enum {
RTC_EVENT_SECOND = 0, /** Triggered every second. */
RTC_EVENT_ALARM = 1, /** Triggered on alarm. */
RTC_EVENT_OVERFLOW = 2 /** Triggered on counter overflow. */
RTC_EVENT_WAKEUP = 0, /** Triggered every wakeup event. */
RTC_EVENT_ALARM_A = 1, /** Triggered on alarm A. */
RTC_EVENT_ALARM_B = 2, /** Triggered on alarm B. */
RTC_EVENT_TAMPER = 3, /** Triggered on Tamper event. */
RTC_EVENT_TIMESTAMP = 4, /** Triggered on TimeStamp event. */
} rtcevent_t;
/**
@ -105,17 +107,17 @@ struct RTCTime {
};
/**
* @brief Structure representing an RTC alarm specification.
*/
struct RTCAlarm {
/**
* @brief Seconds since UNIX epoch.
* @brief Date and time of alarm in BCD.
*/
uint32_t tv_sec;
uint32_t tv_datetime;
};
/**
* @brief Structure representing an RTC driver.
*/