aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-10-14 05:08:01 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-10-14 05:08:01 +0000
commit8ec0f1a75387fadd2b0179a02b9f7f81e37b2fe1 (patch)
treeb085e5307d032d8a0e9f65c8aae3272aded28914
parent6f4b0b263e9dc7a0b6997ac1eeb3581f35ecf92e (diff)
downloadChibiOS-8ec0f1a75387fadd2b0179a02b9f7f81e37b2fe1.tar.gz
ChibiOS-8ec0f1a75387fadd2b0179a02b9f7f81e37b2fe1.tar.bz2
ChibiOS-8ec0f1a75387fadd2b0179a02b9f7f81e37b2fe1.zip
Persistent storage class added.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12365 110e8d01-0319-4d1e-a829-52ad28d1bb01
-rw-r--r--os/hal/include/hal.h1
-rw-r--r--os/hal/include/hal_persistent.h170
-rw-r--r--os/hal/lib/peripherals/flash/hal_flash.h3
-rw-r--r--readme.txt1
4 files changed, 173 insertions, 2 deletions
diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h
index 9ed5a0612..429b7d97d 100644
--- a/os/hal/include/hal.h
+++ b/os/hal/include/hal.h
@@ -128,6 +128,7 @@
#include "hal_files.h"
#include "hal_ioblock.h"
#include "hal_mmcsd.h"
+#include "hal_persistent.h"
/* Shared headers.*/
#include "hal_buffers.h"
diff --git a/os/hal/include/hal_persistent.h b/os/hal/include/hal_persistent.h
new file mode 100644
index 000000000..d0d6c4472
--- /dev/null
+++ b/os/hal/include/hal_persistent.h
@@ -0,0 +1,170 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file hal_persistent.h
+ * @brief Generic persistent storage class header.
+ *
+ * @addtogroup HAL_PERSISTENT
+ * @{
+ */
+
+#ifndef HAL_PERSISTENT_H
+#define HAL_PERSISTENT_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a persistent storage error code.
+ * @note Code values are kept equal to the equivalent codes in the flash
+ * interface, this is intentional.
+ */
+typedef enum {
+ PS_NO_ERROR = 0, /* No error. */
+ PS_ERROR_READ = 2, /* ECC or other error during read operation.*/
+ PS_ERROR_PROGRAM = 3, /* Program operation failed. */
+ PS_ERROR_VERIFY = 5, /* Verify operation failed. */
+ PS_ERROR_HW_FAILURE = 6 /* Controller or communication error. */
+} ps_error_t;
+
+/**
+ * @brief Type of a persistent storage offset.
+ */
+typedef uint32_t ps_offset_t;
+
+/**
+ * @brief @p BasePersistentStorage specific methods.
+ */
+#define _base_persistent_storage_methods_alone \
+ /* Storage size.*/ \
+ size_t (*getsize)(void *instance); \
+ /* Read operation.*/ \
+ ps_error_t (*read)(void *instance, ps_offset_t offset, \
+ size_t n, uint8_t *rp); \
+ /* Write operation.*/ \
+ ps_error_t (*write)(void *instance, ps_offset_t offset, \
+ size_t n, const uint8_t *wp);
+
+/**
+ * @brief @p BasePersistentStorage specific methods with inherited ones.
+ */
+#define _base_persistent_storage_methods \
+ _base_object_methods \
+ _base_persistent_storage_methods_alone
+
+/**
+ * @brief @p BasePersistentStorage virtual methods table.
+ */
+struct BasePersistentStorageVMT {
+ _base_persistent_storage_methods
+};
+
+/**
+ * @brief @p BasePersistentStorage specific data.
+ */
+#define _base_persistent_storage_data \
+ _base_object_data
+
+/**
+ * @extends BaseObject
+ *
+ * @brief Base persistent storage class.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BasePersistentStorageVMT *vmt;
+ _base_persistent_storage_data
+} BasePersistentStorage;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions (BasePersistentStorage)
+ * @{
+ */
+/**
+ * @brief Instance getter.
+ * @details This special method is used to get the instance of this class
+ * object from a derived class.
+ */
+#define getBasePersistentStorage(ip) ((BasePersistentStorage *)&(ip)->vmt)
+
+/**
+ * @brief Read operation.
+ *
+ * @param[in] ip pointer to a @p BasePersistentStorage or derived class
+ * @param[in] offset persistent storage offset
+ * @param[in] n number of bytes to be read
+ * @param[out] rp pointer to the data buffer
+ * @return An error code.
+ * @retval PS_NO_ERROR if there is no erase operation in progress.
+ * @retval PS_ERROR_READ if the read operation failed.
+ * @retval PS_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define psRead(ip, offset, n, rp) \
+ (ip)->vmt->read(ip, offset, n, rp)
+
+/**
+ * @brief Write operation.
+ *
+ * @param[in] ip pointer to a @p BasePersistentStorage or derived class
+ * @param[in] offset persistent storage offset
+ * @param[in] n number of bytes to be programmed
+ * @param[in] wp pointer to the data buffer
+ * @return An error code.
+ * @retval PS_NO_ERROR if there is no erase operation in progress.
+ * @retval PS_ERROR_WRITE if the write operation failed.
+ * @retval PS_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define psWrite(ip, offset, n, wp) \
+ (ip)->vmt->write(ip, offset, n, wp)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_PERSISTENT_H */
+
+/** @} */
diff --git a/os/hal/lib/peripherals/flash/hal_flash.h b/os/hal/lib/peripherals/flash/hal_flash.h
index b540b831d..325959b2b 100644
--- a/os/hal/lib/peripherals/flash/hal_flash.h
+++ b/os/hal/lib/peripherals/flash/hal_flash.h
@@ -138,7 +138,6 @@ typedef struct {
/**
* @brief @p BaseFlash specific methods.
- * @note No methods so far, just a common ancestor interface.
*/
#define _base_flash_methods_alone \
/* Get flash device attributes.*/ \
@@ -207,7 +206,7 @@ typedef struct {
#define getBaseFlash(ip) ((BaseFlash *)&(ip)->vmt)
/**
- * @brief Sensors get axes number.
+ * @brief Gets the flash descriptor structure.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @return A flash device descriptor.
diff --git a/readme.txt b/readme.txt
index 8655fe45b..b5f0c00e8 100644
--- a/readme.txt
+++ b/readme.txt
@@ -75,6 +75,7 @@
*****************************************************************************
*** Next ***
+- NEW: Added a new "persistent storage" base class to HAL.
- NEW: Added support for TIM21 and TIM22 in STM32 GPT driver.
- NEW: Reinforced checks in TIM-related drivers.
- NEW: Added support for STM32L072 and STM32L073.