mirror of https://github.com/rusefi/ChibiOS.git
RTC. Development suspended until EXTI driver API will changed.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rtc_dev@3600 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
ddff11cafe
commit
facfe77b18
|
@ -215,7 +215,7 @@ void rtc_lld_set_time(RTCDriver *rtcp, const RTCTime *timespec) {
|
|||
* @brief Get current time.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] timespec pointer to a @p RTCTime structure
|
||||
* @param[out] timespec pointer to a @p RTCTime structure
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
|
@ -280,9 +280,9 @@ 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] alarmspec pointer to a @p RTCAlarm structure
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] alarm alarm identifier
|
||||
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
|
|
|
@ -89,7 +89,7 @@ void rtc_lld_init(void){
|
|||
#define PREDIV_A ((uint32_t)0x7F)
|
||||
|
||||
/* Add async part to preload value. */
|
||||
uint32_t preload = PREDIV_A << 16;
|
||||
volatile uint32_t preload = PREDIV_A << 16;
|
||||
|
||||
/* Enables access to BKP registers.*/
|
||||
PWR->CR |= PWR_CR_DBP;
|
||||
|
@ -128,13 +128,12 @@ void rtc_lld_init(void){
|
|||
/* RTC enabled regardless its previous status.*/
|
||||
RCC->BDCR |= RCC_BDCR_RTCEN;
|
||||
|
||||
/* Disable write protection on RTC registers. */
|
||||
RTCD1.id_rtc->WPR = 0xCA;
|
||||
RTCD1.id_rtc->WPR = 0x53;
|
||||
|
||||
/* If calendar not init yet. */
|
||||
if (!(RTC->ISR & RTC_ISR_INITS)){
|
||||
/* Disable write protection on RTC registers. */
|
||||
|
||||
RTCD1.id_rtc->WPR = 0xCA;
|
||||
RTCD1.id_rtc->WPR = 0x53;
|
||||
|
||||
/* Enter in init mode. */
|
||||
RTCD1.id_rtc->ISR |= RTC_ISR_INIT;
|
||||
while(!(RTC->ISR & RTC_ISR_INITF))
|
||||
|
@ -146,6 +145,7 @@ void rtc_lld_init(void){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set current time.
|
||||
* @note Fractional part will be silently ignored. There is no possibility
|
||||
|
@ -229,9 +229,9 @@ void rtc_lld_set_alarm(RTCDriver *rtcp,
|
|||
/**
|
||||
* @brief Get alarm time.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] alarm alarm identifier
|
||||
* @param[in] alarmspec pointer to a @p RTCAlarm structure
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] alarm alarm identifier
|
||||
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
|
@ -255,14 +255,14 @@ void rtc_lld_get_alarm(RTCDriver *rtcp,
|
|||
* @notapi
|
||||
*/
|
||||
void rtc_lld_set_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){
|
||||
chDbgCheck((wakeupspec->wutr != 0) || ((wakeupspec->wucksel & 0x7) != 3),
|
||||
chDbgCheck((wakeupspec->wakeup != 0x30000),
|
||||
"rtc_lld_set_periodic_wakeup, forbidden combination");
|
||||
|
||||
rtcp->id_rtc->CR &= ~RTC_CR_WUTE;
|
||||
while(!(rtcp->id_rtc->ISR & RTC_ISR_WUTWF))
|
||||
;
|
||||
rtcp->id_rtc->WUTR = wakeupspec->wutr & 0xFFFF;
|
||||
rtcp->id_rtc->CR = wakeupspec->wucksel & 0x7;
|
||||
rtcp->id_rtc->WUTR = wakeupspec->wakeup & 0xFFFF;
|
||||
rtcp->id_rtc->CR = (wakeupspec->wakeup >> 16) & 0x7;
|
||||
rtcp->id_rtc->CR |= RTC_CR_WUTE;
|
||||
}
|
||||
|
||||
|
@ -271,20 +271,50 @@ void rtc_lld_set_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){
|
|||
*
|
||||
* @note Default value after BKP domain reset is 0x0000FFFF
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] wakeupspec pointer to a @p RTCWakeup structure
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[out] wakeupspec pointer to a @p RTCWakeup structure
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void rtc_lld_get_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){
|
||||
wakeupspec->wutr = rtcp->id_rtc->WUTR;
|
||||
wakeupspec->wucksel = rtcp->id_rtc->CR & 0x7;
|
||||
wakeupspec->wakeup = 0;
|
||||
wakeupspec->wakeup |= rtcp->id_rtc->WUTR;
|
||||
wakeupspec->wakeup |= (((uint32_t)rtcp->id_rtc->CR) & 0x7) << 16;
|
||||
}
|
||||
|
||||
|
||||
#if RTC_SUPPORTS_CALLBACKS
|
||||
|
||||
|
||||
|
||||
static const EXTConfig rtc_extcfg = {
|
||||
{
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_RISING_EDGE, NULL}, //17, RTC alarm
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_DISABLED, NULL},
|
||||
{EXT_CH_MODE_RISING_EDGE, NULL}, //21 RTC tamper
|
||||
{EXT_CH_MODE_RISING_EDGE, NULL} //22 RTC wakeup
|
||||
},
|
||||
EXT_MODE_EXTI(0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -293,30 +323,44 @@ void rtc_lld_get_periodic_wakeup(RTCDriver *rtcp, RTCWakeup *wakeupspec){
|
|||
* @details TODO:
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] callback callback function pointer or @p NULL
|
||||
* @param[in] cb_cfg pointer to configuration structure with callbacks
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void rtc_lld_set_callback(RTCDriver *rtcp, RTCCallbackConfig *cb_cfg) {
|
||||
(void)rtcp;
|
||||
(void)cb_cfg;
|
||||
// if (callback != NULL) {
|
||||
// rtcp->rtc_cb = callback;
|
||||
// NVICEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(STM32_RTC_IRQ_PRIORITY));
|
||||
//
|
||||
// /* 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.*/
|
||||
// RTC->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
|
||||
// RTC->CRH |= RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE;
|
||||
// }
|
||||
// else {
|
||||
// NVICDisableVector(RTC_IRQn);
|
||||
// RTC->CRL = 0;
|
||||
// RTC->CRH = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
/* To configure callback we must confugure EXTI interrupt on
|
||||
* corresponding line.
|
||||
* And then enable interrupts in RTC CR register. */
|
||||
|
||||
if (cb_cfg->alarm_cb != NULL){
|
||||
rtc_extcfg.channels[STM32_RTC_ALARM_EXTI_CH].cb = cb_cfg->alarm_cb;
|
||||
rtcp->id_rtc->CR |= RTC_CR_ALRBIE;
|
||||
rtcp->id_rtc->CR |= RTC_CR_ALRAIE;
|
||||
}
|
||||
else{
|
||||
extChannelDisable(&EXTD1, STM32_RTC_ALARM_EXTI_CH);
|
||||
}
|
||||
|
||||
if (cb_cfg->tamper_timestapm_cb != NULL){
|
||||
rtc_extcfg.channels[STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH].cb = cb_cfg->tamper_timestapm_cb;
|
||||
rtcp->id_rtc->CR |= RTC_CR_TSIE;
|
||||
}
|
||||
else{
|
||||
extChannelDisable(&EXTD1, STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH);
|
||||
}
|
||||
|
||||
if (cb_cfg->wakeup_cb != NULL){
|
||||
rtc_extcfg.channels[STM32_RTC_WAKEUP_EXTI_CH].cb = cb_cfg->wakeup_cb;
|
||||
rtcp->id_rtc->CR |= RTC_CR_WUTIE;
|
||||
}
|
||||
else{
|
||||
extChannelDisable(&EXTD1, STM32_RTC_WAKEUP_EXTI_CH);
|
||||
}
|
||||
|
||||
extStart(&EXTD1, &rtc_extcfg);
|
||||
}
|
||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
||||
|
||||
#endif /* HAL_USE_RTC */
|
||||
|
||||
|
|
|
@ -47,6 +47,13 @@
|
|||
*/
|
||||
#define RTC_ALARMS 2
|
||||
|
||||
/**
|
||||
* @brief EXTI channel numbers for different RTC events.
|
||||
*/
|
||||
#define STM32_RTC_ALARM_EXTI_CH 17
|
||||
#define STM32_RTC_TAMPER_TIMESTAMP_EXTI_CH 21
|
||||
#define STM32_RTC_WAKEUP_EXTI_CH 22
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
@ -143,13 +150,13 @@ struct RTCAlarm {
|
|||
*/
|
||||
struct RTCWakeup {
|
||||
/**
|
||||
* @brief RTC WUTR register.
|
||||
* @brief RTC WUTR register.
|
||||
* @details Bits [15:0] contain value of WUTR register
|
||||
* Bits [18:16] contain value of WUCKSEL bits in CR register
|
||||
*
|
||||
* @notes ((WUTR == 0) || (WUCKSEL == 3)) is forbidden combination.
|
||||
*/
|
||||
uint32_t wutr;
|
||||
/**
|
||||
* @brief RTC WUCKSEL bits of CR register.
|
||||
*/
|
||||
uint32_t wucksel;
|
||||
uint32_t wakeup;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,12 +134,6 @@ void rtcGetAlarm(RTCDriver *rtcp,
|
|||
}
|
||||
#endif /* RTC_ALARMS > 0 */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets periodic wakeup period.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue