Persistent storage class added.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12365 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
Giovanni Di Sirio 2018-10-14 05:08:01 +00:00
parent 6f4b0b263e
commit 8ec0f1a753
4 changed files with 173 additions and 2 deletions

View File

@ -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"

View File

@ -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 */
/** @} */

View File

@ -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.

View File

@ -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.