From e40082e1d66e963a16ef36ad2231dd40b56bdf7c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 27 Nov 2014 15:07:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7543 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c | 3 ++ os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h | 51 ++++++++++++++------- os/hal/ports/STM32/LLD/RTCv2/rtc_lld.c | 81 ++++++++++++++++++++++++++++++++++ os/hal/ports/STM32/LLD/RTCv2/rtc_lld.h | 36 +++++++++++++++ 4 files changed, 155 insertions(+), 16 deletions(-) (limited to 'os/hal/ports/STM32') diff --git a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c index 87fc6b763..1d02c353b 100644 --- a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c +++ b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c @@ -204,6 +204,9 @@ void rtc_lld_set_prescaler(void) { */ void rtc_lld_init(void) { + /* RTC object initialization.*/ + rtcObjectInit(&RTCD1); + /* RTC pointer initialization.*/ RTCD1.rtc = RTC; diff --git a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h index 0685ef6bc..7a3ec6eec 100644 --- a/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h +++ b/os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h @@ -35,6 +35,9 @@ /* Driver constants. */ /*===========================================================================*/ +/** + * @name Implementation capabilities + */ /** * @brief This RTC implementation supports callbacks. */ @@ -45,6 +48,12 @@ */ #define RTC_ALARMS 1 +/** + * @brief Presence of a local persistent storage. + */ +#define RTC_HAS_STORAGE FALSE +/** @} */ + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -76,14 +85,15 @@ /*===========================================================================*/ /** - * @brief Type of a structure representing an RTC alarm time stamp. + * @brief FileStream specific methods. */ -typedef struct RTCAlarm RTCAlarm; +#define _rtc_driver_methods \ + _file_stream_methods /** - * @brief Type of a structure representing an RTC callbacks config. + * @brief Type of a structure representing an RTC alarm time stamp. */ -typedef struct RTCCallbackConfig RTCCallbackConfig; +typedef struct RTCAlarm RTCAlarm; /** * @brief Type of an RTC alarm. @@ -105,16 +115,6 @@ typedef enum { */ typedef void (*rtccb_t)(RTCDriver *rtcp, rtcevent_t event); -/** - * @brief Structure representing an RTC callbacks config. - */ -struct RTCCallbackConfig{ - /** - * @brief Generic RTC callback pointer. - */ - rtccb_t callback; -}; - /** * @brief Structure representing an RTC alarm time stamp. */ @@ -125,17 +125,33 @@ struct RTCAlarm { uint32_t tv_sec; }; +#if RTC_HAS_STORAGE || defined(__DOXYGEN__) +/** + * @extends FileStream + * + * @brief @p RTCDriver virtual methods table. + */ +struct RTCDriverVMT { + _rtc_driver_methods +}; +#endif + /** * @brief Structure representing an RTC driver. */ struct RTCDriver{ +#if RTC_HAS_STORAGE || defined(__DOXYGEN__) + /** + * @brief Virtual Methods Table. + */ + const struct RTCDriverVMT *vmt; +#endif /** * @brief Pointer to the RTC registers block. */ RTC_TypeDef *rtc; - /** - * @brief Callback pointer. + * @brief Callback pointer. */ rtccb_t callback; }; @@ -150,6 +166,9 @@ struct RTCDriver{ #if !defined(__DOXYGEN__) extern RTCDriver RTCD1; +#if RTC_HAS_STORAGE +extern struct RTCDriverVMT _rtc_lld_vmt; +#endif #endif #ifdef __cplusplus diff --git a/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.c b/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.c index 6e706e3c8..563e5ecc6 100644 --- a/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.c +++ b/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.c @@ -197,6 +197,84 @@ static uint32_t rtc_encode_date(const RTCDateTime *timespec) { return dr; } +static size_t _write(void *instance, const uint8_t *bp, size_t n) { + + (void)instance; + (void)bp; + (void)n; + + return 0; +} + +static size_t _read(void *instance, uint8_t *bp, size_t n) { + + (void)instance; + (void)bp; + (void)n; + + return 0; +} + +static msg_t _put(void *instance, uint8_t b) { + + (void)instance; + (void)b; + + return FILE_OK; +} + +static msg_t _get(void *instance) { + + (void)instance; + + return FILE_OK; +} + +static msg_t _close(void *instance) { + + /* Close is not supported.*/ + (void)instance; + + return FILE_OK; +} + +static msg_t _geterror(void *instance) { + + (void)instance; + + return (msg_t)0; +} + +static msg_t _getsize(void *instance) { + + (void)instance; + + return 0; +} + +static msg_t _getposition(void *instance) { + + (void)instance; + + return 0; +} + +static msg_t _lseek(void *instance, fileoffset_t offset) { + + (void)instance; + (void)offset; + + return FILE_OK; +} + +/** + * @brief VMT for the RTC storage file interface. + */ +struct RTCDriverVMT _rtc_lld_vmt = { + _write, _read, _put, _get, + _close, _geterror, _getsize, _getposition, _lseek +}; + /*===========================================================================*/ /* Driver interrupt handlers. */ /*===========================================================================*/ @@ -212,6 +290,9 @@ static uint32_t rtc_encode_date(const RTCDateTime *timespec) { */ void rtc_lld_init(void) { + /* RTC object initialization.*/ + rtcObjectInit(&RTCD1); + /* RTC pointer initialization.*/ RTCD1.rtc = RTC; diff --git a/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.h b/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.h index 2c6c5509b..6d86f68a5 100644 --- a/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.h +++ b/os/hal/ports/STM32/LLD/RTCv2/rtc_lld.h @@ -35,6 +35,9 @@ /* Driver constants. */ /*===========================================================================*/ +/** + * @name Implementation capabilities + */ /** * @brief Callback support int the driver. */ @@ -45,6 +48,12 @@ */ #define RTC_ALARMS STM32_RTC_NUM_ALARMS +/** + * @brief Presence of a local persistent storage. + */ +#define RTC_HAS_STORAGE TRUE +/** @} */ + /** * @brief RTC PRER register initializer. */ @@ -122,6 +131,12 @@ /* Driver data structures and types. */ /*===========================================================================*/ +/** + * @brief FileStream specific methods. + */ +#define _rtc_driver_methods \ + _file_stream_methods + /** * @brief Type of an RTC alarm number. */ @@ -150,10 +165,28 @@ typedef struct { } RTCWakeup; #endif +#if RTC_HAS_STORAGE || defined(__DOXYGEN__) +/** + * @extends FileStream + * + * @brief @p RTCDriver virtual methods table. + */ +struct RTCDriverVMT { + _rtc_driver_methods +}; +#endif + /** * @brief Structure representing an RTC driver. */ struct RTCDriver { +#if RTC_HAS_STORAGE || defined(__DOXYGEN__) + /** + * @brief Virtual Methods Table. + */ + const struct RTCDriverVMT *vmt; +#endif + /* End of the mandatory fields.*/ /** * @brief Pointer to the RTC registers block. */ @@ -170,6 +203,9 @@ struct RTCDriver { #if !defined(__DOXYGEN__) extern RTCDriver RTCD1; +#if RTC_HAS_STORAGE +extern struct RTCDriverVMT _rtc_lld_vmt; +#endif #endif #ifdef __cplusplus -- cgit v1.2.3