From 2b35b5a2a5a9484332edebaca861a87910cf6715 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 8 Mar 2012 19:52:44 +0000 Subject: SDC. Added RTC support. Improved testhal. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/sdc_dev2@4031 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/rtc.h | 1 + os/hal/platforms/STM32/RTCv1/rtc_lld.c | 24 ++++++++++++++++++++++++ os/hal/platforms/STM32/RTCv1/rtc_lld.h | 1 + os/hal/platforms/STM32/RTCv2/rtc_lld.c | 23 +++++++++++++++++++++++ os/hal/platforms/STM32/RTCv2/rtc_lld.h | 1 + os/hal/platforms/STM32/sdc_lld.c | 12 ++++++------ os/hal/platforms/STM32F1xx/hal_lld.h | 14 ++++++++++++++ os/hal/platforms/STM32F1xx/hal_lld_f100.h | 3 --- os/hal/platforms/STM32F1xx/hal_lld_f103.h | 4 ---- os/hal/platforms/STM32F1xx/hal_lld_f105_f107.h | 4 ---- os/hal/platforms/STM32F2xx/hal_lld.h | 1 + os/hal/platforms/STM32F4xx/hal_lld.h | 1 + os/hal/platforms/STM32L1xx/hal_lld.h | 1 + os/hal/src/rtc.c | 20 ++++++++++++++++++++ 14 files changed, 93 insertions(+), 17 deletions(-) (limited to 'os') diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h index 9b5cba848..3acce33e4 100644 --- a/os/hal/include/rtc.h +++ b/os/hal/include/rtc.h @@ -151,6 +151,7 @@ extern "C" { void rtcInit(void); void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec); void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec); + uint32_t rtcGetFatTime(RTCDriver *rtcp); #if RTC_ALARMS > 0 void rtcSetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.c b/os/hal/platforms/STM32/RTCv1/rtc_lld.c index 066e0f659..6496cfae9 100644 --- a/os/hal/platforms/STM32/RTCv1/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.c @@ -30,6 +30,8 @@ * @{ */ +#include + #include "ch.h" #include "hal.h" @@ -290,6 +292,28 @@ void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) { } } +/** + * @brief Get current time in format suitable for usage in FatFS. + * + * @param[in] timespec pointer to RTCTime structure + * @return FAT time value. + * + * @api + */ +uint32_t rtc_lld_calc_fat_time(RTCTime *timespec){ + uint32_t fattime = 0; + struct tm *timp; + + timp = localtime((time_t *)(timespec->tv_sec)); + + fattime |= (timp->tm_sec / 2); + fattime |= (timp->tm_min) << 5; + fattime |= (timp->tm_hour) << 11; + fattime |= (timp->tm_mday) << 16; + fattime |= (timp->tm_mon + 1) << 21; + fattime |= (timp->tm_year - 80) << 25; + return fattime; +} #endif /* HAL_USE_RTC */ /** @} */ diff --git a/os/hal/platforms/STM32/RTCv1/rtc_lld.h b/os/hal/platforms/STM32/RTCv1/rtc_lld.h index 4944ff735..64287d978 100644 --- a/os/hal/platforms/STM32/RTCv1/rtc_lld.h +++ b/os/hal/platforms/STM32/RTCv1/rtc_lld.h @@ -178,6 +178,7 @@ extern "C" { rtcalarm_t alarm, RTCAlarm *alarmspec); void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback); + uint32_t rtc_lld_calc_fat_time(RTCTime *timespec); #ifdef __cplusplus } #endif diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/os/hal/platforms/STM32/RTCv2/rtc_lld.c index cae3f812b..c2268fd82 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.c +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.c @@ -264,6 +264,29 @@ void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec){ wakeupspec->wakeup |= (((uint32_t)rtcp->id_rtc->CR) & 0x7) << 16; } +/** + * @brief Get current time in format suitable for usage in FatFS. + * + * @param[in] timespec pointer to RTCTime structure + * @return FAT time value. + * + * @api + */ +uint32_t rtc_lld_calc_fat_time(RTCTime *timespec){ + uint32_t fattime = 0; + struct tm timp; + + stm32_rtc_bcd2tm(&timp, timespec); + + fattime |= (timp.tm_sec / 2); + fattime |= (timp.tm_min) << 5; + fattime |= (timp.tm_hour) << 11; + fattime |= (timp.tm_mday) << 16; + fattime |= (timp.tm_mon + 1) << 21; + fattime |= (timp.tm_year - 80) << 25; + return fattime; +} + /** * @brief Converts from STM32 BCD to canonicalized time format. * diff --git a/os/hal/platforms/STM32/RTCv2/rtc_lld.h b/os/hal/platforms/STM32/RTCv2/rtc_lld.h index 3f0139f00..88959294c 100644 --- a/os/hal/platforms/STM32/RTCv2/rtc_lld.h +++ b/os/hal/platforms/STM32/RTCv2/rtc_lld.h @@ -200,6 +200,7 @@ extern "C" { RTCAlarm *alarmspec); void rtcSetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec); void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec); + uint32_t rtc_lld_calc_fat_time(RTCTime *timespec); void stm32_rtc_bcd2tm(struct tm *timp, RTCTime *timespec); void stm32_rtc_tm2bcd(struct tm *timp, RTCTime *timespec); #ifdef __cplusplus diff --git a/os/hal/platforms/STM32/sdc_lld.c b/os/hal/platforms/STM32/sdc_lld.c index f74d06c9e..c42867ffe 100644 --- a/os/hal/platforms/STM32/sdc_lld.c +++ b/os/hal/platforms/STM32/sdc_lld.c @@ -56,7 +56,7 @@ SDCDriver SDCD1; /* Driver local variables. */ /*===========================================================================*/ -#if STM32_SDC_UNALIGNED_SUPPORT +#if STM32_SDC_SDIO_UNALIGNED_SUPPORT /** * @brief Buffer for temporary storage during unaligned transfers. */ @@ -64,7 +64,7 @@ static union { uint32_t alignment; uint8_t buf[SDC_BLOCK_SIZE]; } u; -#endif +#endif /* STM32_SDC_SDIO_UNALIGNED_SUPPORT */ /*===========================================================================*/ /* Driver local functions. */ @@ -706,7 +706,7 @@ error: bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n) { -#if STM32_SDC_UNALIGNED_SUPPORT +#if STM32_SDC_SDIO_UNALIGNED_SUPPORT if (((unsigned)buf & 3) != 0) { uint32_t i; for (i = 0; i < n; i++) { @@ -718,7 +718,7 @@ bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, } return SDC_SUCCESS; } -#endif +#endif /* STM32_SDC_SDIO_UNALIGNED_SUPPORT */ return sdc_lld_read_aligned(sdcp, startblk, buf, n); } @@ -739,7 +739,7 @@ bool_t sdc_lld_read(SDCDriver *sdcp, uint32_t startblk, bool_t sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n) { - #if STM32_SDC_UNALIGNED_SUPPORT +#if STM32_SDC_SDIO_UNALIGNED_SUPPORT if (((unsigned)buf & 3) != 0) { uint32_t i; for (i = 0; i < n; i++) { @@ -751,7 +751,7 @@ bool_t sdc_lld_write(SDCDriver *sdcp, uint32_t startblk, } return SDC_SUCCESS; } -#endif +#endif /* STM32_SDC_SDIO_UNALIGNED_SUPPORT */ return sdc_lld_write_aligned(sdcp, startblk, buf, n); } diff --git a/os/hal/platforms/STM32F1xx/hal_lld.h b/os/hal/platforms/STM32F1xx/hal_lld.h index c79769e80..4a375ab4e 100644 --- a/os/hal/platforms/STM32F1xx/hal_lld.h +++ b/os/hal/platforms/STM32F1xx/hal_lld.h @@ -77,6 +77,20 @@ #define STM32_PLS_LEV7 (7 << 5) /**< PVD level 7. */ /** @} */ +/*===========================================================================*/ +/* Platform capabilities. */ +/*===========================================================================*/ + +/** + * @name STM32F1xx capabilities + * @{ + */ +/* RTC attributes.*/ +#define STM32_HAS_RTC TRUE +#define STM32_RTC_HAS_SUBSECONDS TRUE +#define STM32_RTC_IS_CALENDAR TRUE +/** @} */ + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ diff --git a/os/hal/platforms/STM32F1xx/hal_lld_f100.h b/os/hal/platforms/STM32F1xx/hal_lld_f100.h index 509b20054..25dd3a186 100644 --- a/os/hal/platforms/STM32F1xx/hal_lld_f100.h +++ b/os/hal/platforms/STM32F1xx/hal_lld_f100.h @@ -239,9 +239,6 @@ #define STM32_SPI3_TX_DMA_MSK 0 #define STM32_SPI3_TX_DMA_CHN 0x00000000 -#define STM32_HAS_RTC TRUE -#define STM32_RTCSEL_HAS_SUBSECONDS TRUE - /* SDIO attributes.*/ #define STM32_HAS_SDIO FALSE diff --git a/os/hal/platforms/STM32F1xx/hal_lld_f103.h b/os/hal/platforms/STM32F1xx/hal_lld_f103.h index 7bcbb3043..deda9f67a 100644 --- a/os/hal/platforms/STM32F1xx/hal_lld_f103.h +++ b/os/hal/platforms/STM32F1xx/hal_lld_f103.h @@ -249,10 +249,6 @@ #define STM32_SPI3_TX_DMA_MSK 0 #define STM32_SPI3_TX_DMA_CHN 0x00000000 -/* RTC attributes.*/ -#define STM32_HAS_RTC TRUE -#define STM32_RTCSEL_HAS_SUBSECONDS TRUE - /* SDIO attributes.*/ #define STM32_HAS_SDIO FALSE diff --git a/os/hal/platforms/STM32F1xx/hal_lld_f105_f107.h b/os/hal/platforms/STM32F1xx/hal_lld_f105_f107.h index 88193fa8a..57b47f003 100644 --- a/os/hal/platforms/STM32F1xx/hal_lld_f105_f107.h +++ b/os/hal/platforms/STM32F1xx/hal_lld_f105_f107.h @@ -266,10 +266,6 @@ #define STM32_I2C3_TX_DMA_MSK 0 #define STM32_I2C3_TX_DMA_CHN 0x00000000 -/* RTC attributes.*/ -#define STM32_HAS_RTC TRUE -#define STM32_RTCSEL_HAS_SUBSECONDS TRUE - /* SDIO attributes.*/ #define STM32_HAS_SDIO FALSE diff --git a/os/hal/platforms/STM32F2xx/hal_lld.h b/os/hal/platforms/STM32F2xx/hal_lld.h index ae60b7806..165a10448 100644 --- a/os/hal/platforms/STM32F2xx/hal_lld.h +++ b/os/hal/platforms/STM32F2xx/hal_lld.h @@ -337,6 +337,7 @@ /* RTC attributes.*/ #define STM32_HAS_RTC TRUE #define STM32_RTC_HAS_SUBSECONDS TRUE +#define STM32_RTC_IS_CALENDAR TRUE /* SDIO attributes.*/ #define STM32_HAS_SDIO TRUE diff --git a/os/hal/platforms/STM32F4xx/hal_lld.h b/os/hal/platforms/STM32F4xx/hal_lld.h index a058e848a..3585379e4 100644 --- a/os/hal/platforms/STM32F4xx/hal_lld.h +++ b/os/hal/platforms/STM32F4xx/hal_lld.h @@ -336,6 +336,7 @@ /* RTC attributes.*/ #define STM32_HAS_RTC TRUE #define STM32_RTC_HAS_SUBSECONDS TRUE +#define STM32_RTC_IS_CALENDAR TRUE /* SDIO attributes.*/ #define STM32_HAS_SDIO TRUE diff --git a/os/hal/platforms/STM32L1xx/hal_lld.h b/os/hal/platforms/STM32L1xx/hal_lld.h index 9f47c4da5..f7402dfe6 100644 --- a/os/hal/platforms/STM32L1xx/hal_lld.h +++ b/os/hal/platforms/STM32L1xx/hal_lld.h @@ -233,6 +233,7 @@ /* RTC attributes.*/ #define STM32_HAS_RTC TRUE #define STM32_RTC_HAS_SUBSECONDS FALSE +#define STM32_RTC_IS_CALENDAR TRUE /* SDIO attributes.*/ #define STM32_HAS_SDIO FALSE diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c index 01f88e82d..a6601fd1c 100644 --- a/os/hal/src/rtc.c +++ b/os/hal/src/rtc.c @@ -101,6 +101,26 @@ void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { chSysUnlock(); } +/** + * @brief Get current time in format suitable for usage in FatFS. + * + * @param[in] rtcp pointer to RTC driver structure + * @return FAT time value. + * + * @api + */ +uint32_t rtcGetFatTime(RTCDriver *rtcp) { + RTCTime timespec; + + chDbgCheck((rtcp != NULL), "rtcGetTime"); + + chSysLock(); + rtcGetTimeI(rtcp, ×pec); + chSysUnlock(); + + return rtc_lld_calc_fat_time(×pec); +} + #if (RTC_ALARMS > 0) || defined(__DOXYGEN__) /** * @brief Set alarm time. -- cgit v1.2.3