aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/STM32/RT-STM32F407-DISCOVERY/halconf.h2
-rw-r--r--os/hal/include/hal_files.h16
-rw-r--r--os/hal/include/rtc.h1
-rw-r--r--os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c3
-rw-r--r--os/hal/ports/STM32/LLD/RTCv1/rtc_lld.h51
-rw-r--r--os/hal/ports/STM32/LLD/RTCv2/rtc_lld.c81
-rw-r--r--os/hal/ports/STM32/LLD/RTCv2/rtc_lld.h36
-rw-r--r--os/hal/src/rtc.c16
-rw-r--r--os/hal/templates/rtc_lld.c2
-rw-r--r--os/hal/templates/rtc_lld.h34
10 files changed, 217 insertions, 25 deletions
diff --git a/demos/STM32/RT-STM32F407-DISCOVERY/halconf.h b/demos/STM32/RT-STM32F407-DISCOVERY/halconf.h
index ab3a6629b..e9a4d5f25 100644
--- a/demos/STM32/RT-STM32F407-DISCOVERY/halconf.h
+++ b/demos/STM32/RT-STM32F407-DISCOVERY/halconf.h
@@ -111,7 +111,7 @@
* @brief Enables the RTC subsystem.
*/
#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
-#define HAL_USE_RTC FALSE
+#define HAL_USE_RTC TRUE
#endif
/**
diff --git a/os/hal/include/hal_files.h b/os/hal/include/hal_files.h
index c07e91bb7..aba8a7271 100644
--- a/os/hal/include/hal_files.h
+++ b/os/hal/include/hal_files.h
@@ -46,17 +46,17 @@
/**
* @brief No error return code.
*/
-#define FILE_OK (fileoffset_t)STM_OK
+#define FILE_OK STM_OK
/**
* @brief Error code from the file stream methods.
*/
-#define FILE_ERROR (fileoffset_t)STM_TIMEOUT
+#define FILE_ERROR STM_TIMEOUT
/**
* @brief End-of-file condition for file get/put methods.
*/
-#define FILE_EOF (fileoffset_t)STM_RESET
+#define FILE_EOF STM_RESET
/** @} */
/**
@@ -70,15 +70,15 @@ typedef uint32_t fileoffset_t;
#define _file_stream_methods \
_base_sequential_stream_methods \
/* File close method.*/ \
- uint32_t (*close)(void *instance); \
+ msg_t (*close)(void *instance); \
/* Get last error code method.*/ \
- int (*geterror)(void *instance); \
+ msg_t (*geterror)(void *instance); \
/* File get size method.*/ \
- fileoffset_t (*getsize)(void *instance); \
+ msg_t (*getsize)(void *instance); \
/* File get current position method.*/ \
- fileoffset_t (*getposition)(void *instance); \
+ msg_t (*getposition)(void *instance); \
/* File seek method.*/ \
- uint32_t (*lseek)(void *instance, fileoffset_t offset);
+ msg_t (*lseek)(void *instance, fileoffset_t offset);
/**
* @brief @p FileStream specific data.
diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h
index 2038ca9a9..a6730c2b2 100644
--- a/os/hal/include/rtc.h
+++ b/os/hal/include/rtc.h
@@ -115,6 +115,7 @@ typedef struct {
extern "C" {
#endif
void rtcInit(void);
+ void rtcObjectInit(RTCDriver *rtcp);
void rtcSetTime(RTCDriver *rtcp, const RTCDateTime *timespec);
void rtcGetTime(RTCDriver *rtcp, RTCDateTime *timespec);
#if RTC_ALARMS > 0
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
@@ -36,6 +36,9 @@
/*===========================================================================*/
/**
+ * @name Implementation capabilities
+ */
+/**
* @brief This RTC implementation supports callbacks.
*/
#define RTC_SUPPORTS_CALLBACKS TRUE
@@ -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.
@@ -106,16 +116,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.
*/
struct RTCAlarm {
@@ -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
@@ -36,6 +36,9 @@
/*===========================================================================*/
/**
+ * @name Implementation capabilities
+ */
+/**
* @brief Callback support int the driver.
*/
#define RTC_SUPPORTS_CALLBACKS STM32_RTC_HAS_INTERRUPTS
@@ -46,6 +49,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.
*/
#define RTC_PRER(a, s) ((((a) - 1) << 16) | ((s) - 1))
@@ -123,6 +132,12 @@
/*===========================================================================*/
/**
+ * @brief FileStream specific methods.
+ */
+#define _rtc_driver_methods \
+ _file_stream_methods
+
+/**
* @brief Type of an RTC alarm number.
*/
typedef uint32_t rtcalarm_t;
@@ -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
diff --git a/os/hal/src/rtc.c b/os/hal/src/rtc.c
index 68453e91b..e0c078ef2 100644
--- a/os/hal/src/rtc.c
+++ b/os/hal/src/rtc.c
@@ -74,6 +74,22 @@ void rtcInit(void) {
}
/**
+ * @brief Initializes a generic RTC driver object.
+ * @details The HW dependent part of the initialization has to be performed
+ * outside, usually in the hardware initialization code.
+ *
+ * @param[out] rtcp pointer to RTC driver structure
+ *
+ * @init
+ */
+void rtcObjectInit(RTCDriver *rtcp) {
+
+#if RTC_HAS_STORAGE
+ rtcp->vmt = &_rtc_lld_vmt;
+#endif
+}
+
+/**
* @brief Set current time.
* @note This function can be called from any context but limitations
* could be imposed by the low level implementation. It is
diff --git a/os/hal/templates/rtc_lld.c b/os/hal/templates/rtc_lld.c
index 11ca5d4e4..b63684699 100644
--- a/os/hal/templates/rtc_lld.c
+++ b/os/hal/templates/rtc_lld.c
@@ -66,6 +66,8 @@ RTCDriver RTCD1;
*/
void rtc_lld_init(void) {
+ /* RTC object initialization.*/
+ rtcObjectInit(&RTCD1);
}
/**
diff --git a/os/hal/templates/rtc_lld.h b/os/hal/templates/rtc_lld.h
index 4b00cc72a..81bcc346f 100644
--- a/os/hal/templates/rtc_lld.h
+++ b/os/hal/templates/rtc_lld.h
@@ -36,6 +36,9 @@
/*===========================================================================*/
/**
+ * @name Implementation capabilities
+ */
+/**
* @brief Callback support int the driver.
*/
#define RTC_SUPPORTS_CALLBACKS PLATFORM_RTC_HAS_INTERRUPTS
@@ -44,6 +47,11 @@
* @brief Number of alarms available.
*/
#define RTC_ALARMS PLATFORM_RTC_NUM_ALARMS
+
+/**
+ * @brief Presence of a local persistent storage.
+ */
+#define RTC_HAS_STORAGE FALSE
/** @} */
/*===========================================================================*/
@@ -65,6 +73,12 @@
/*===========================================================================*/
/**
+ * @brief FileStream specific methods.
+ */
+#define _rtc_driver_methods \
+ _file_stream_methods
+
+/**
* @brief Type of an RTC alarm number.
*/
typedef uint32_t rtcalarm_t;
@@ -77,10 +91,27 @@ typedef struct {
uint32_t dummy;
} RTCAlarm;
+#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.*/
uint32_t dummy;
};
@@ -95,6 +126,9 @@ struct RTCDriver {
#if !defined(__DOXYGEN__)
extern RTCDriver RTCD1;
+#if RTC_HAS_STORAGE
+extern struct RTCDriverVMT _rtc_lld_vmt;
+#endif
#endif
#ifdef __cplusplus