Added flash interface.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9419 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2016-05-05 09:44:28 +00:00
parent cd7b481ded
commit 4c093804c0
9 changed files with 255 additions and 24 deletions

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _HAL_DISPLAYS_H_
#define _HAL_DISPLAYS_H_
#ifndef HAL_DISPLAYS_H
#define HAL_DISPLAYS_H
/*===========================================================================*/
/* Driver constants. */
@ -107,6 +107,6 @@ extern "C" {
}
#endif
#endif /* _HAL_DISPLAYS_H_ */
#endif /* HAL_DISPLAYS_H */
/** @} */

View File

@ -0,0 +1,231 @@
/*
ChibiOS - Copyright (C) 2006..2016 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_flash.h
* @brief Generic flash interface header.
*
* @addtogroup HAL_FLASH
* @{
*/
#ifndef HAL_FLASH_H
#define HAL_FLASH_H
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @name Flash attributes
* @{
*/
#define FLASH_ATTR_ERASED_ONE 0x00000001
#define FLASH_ATTR_MEMORY_MAPPED 0x00000002
#define FLASH_ATTR_REWRITABLE 0x00000004
/** @} */
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief @p BaseFlash specific methods.
* @note No methods so far, just a common ancestor interface.
*/
#define _base_flash_methods_alone \
/* Get flash device attributes.*/ \
const flash_descriptor_t * (*get_attributes)(void *instance); \
/* Erase whole flash device.*/ \
flash_error_t erase_all(void *instance); \
/* Erase single sector.*/ \
flash_error_t erase_sector(void *instance, unsigned sector); \
/* Write operation.*/ \
flash_error_t write(void *instance, const uint8_t *wp, size_t n); \
/* Read operation.*/ \
flash_error_t read(void *instance, uint8_t *rp, size_t n);
/**
* @brief @p BaseFlash specific methods with inherited ones.
*/
#define _base_flash_methods \
_base_flash_methods_alone
/**
* @brief @p BaseFlash virtual methods table.
*/
struct BaseFlashVMT {
_base_flash_methods
};
/**
* @brief @p BaseFlash specific data.
* @note It is empty because @p BaseFlash is only an interface
* without implementation.
*/
#define _base_flash_data
/**
* @brief Base flash class.
*/
typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseFlashVMT *vmt_baseflash;
_base_flash_data
} BaseFlash;
/**
* @brief Flash sector descriptor.
*/
typedef struct {
/**
* @brief Sector address.
*/
uint8_t *address;
/**
* @brief Secotr size.
*/
size_t size;
} flash_sector_t;
/**
* @brief Type of a flash device descriptor.
*/
typedef struct {
/**
* @brief Device_attributes.
*/
uint32_t attributes;
/**
* @brief Size of write page.
*/
size_t page_size;
/**
* @brief Number of sectors in the device.
*/
unsigned sectors_count;
/**
* @brief List of flash sectors for devices with non-uniform sector sizes.
* @note If @p NULL then the device has uniform sectors size equal
* to @p sector_size.
*/
flash_sector_t *sectors;
/**
* @brief Size of flash sectors for devices with uniform sector size.
* @note If zero then the device has non uniform sectos described by
* the @p sectors array.
*/
size_t sectors_size;
/**
* @brief Flash address if memory mapped or zero.
* @note Conventionally, non memory mapped devices have address zero.
*/
uint8_t *address;
} flash_descriptor_t;
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/**
* @name Macro Functions (BaseFlash)
* @{
*/
/**
* @brief Sensors get axes number.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @return An error code.
*
* @api
*/
#define flashGetType(ip) \
(ip)->vmt_baseflash->get_attributes(ip)
/**
* @brief Whole device erase operation.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @return An error code.
*
* @api
*/
#define flashEraseAll(ip) \
(ip)->vmt_baseflash->erase_all(ip)
/**
* @brief Single sector erase operation.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @return An error code.
*
* @api
*/
#define flashEraseSector(ip) \
(ip)->vmt_baseflash->erase_sector(ip, sector)
/**
* @brief Write operation.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @param[in] wp pointer to the data buffer
* @param[in] n number of bytes to be written
* @return An error code.
*
* @api
*/
#define flashWrite(ip) \
(ip)->vmt_baseflash->write(ip, wp, n)
/**
* @brief Read operation.
*
* @param[in] ip pointer to a @p BaseFlash or derived class
* @param[out] rp pointer to the data buffer
* @param[in] n number of bytes to be read
* @return An error code.
*
* @api
*/
#define flashRead(ip) \
(ip)->vmt_baseflash->read(ip, rp, n)
/** @} */
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* HAL_FLASH_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _HAL_ACCELEROMETER_H_
#define _HAL_ACCELEROMETER_H_
#ifndef HAL_ACCELEROMETER_H
#define HAL_ACCELEROMETER_H
#include "hal_sensors.h"
@ -213,6 +213,6 @@ extern "C" {
}
#endif
#endif /* _HAL_ACCELEROMETER_H_ */
#endif /* HAL_ACCELEROMETER_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _HAL_COMPASS_H_
#define _HAL_COMPASS_H_
#ifndef HAL_COMPASS_H
#define HAL_COMPASS_H
#include "hal_sensors.h"
@ -212,6 +212,6 @@ extern "C" {
}
#endif
#endif /* _HAL_COMPASS_H_ */
#endif /* HAL_COMPASS_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _HAL_GYROSCOPE_H_
#define _HAL_GYROSCOPE_H_
#ifndef HAL_GYROSCOPE_H
#define HAL_GYROSCOPE_H
#include "hal_sensors.h"
@ -232,6 +232,6 @@ extern "C" {
}
#endif
#endif /* _HAL_GYROSCOPE_H_ */
#endif /* HAL_GYROSCOPE_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _HAL_SENSORS_H_
#define _HAL_SENSORS_H_
#ifndef HAL_SENSORS_H
#define HAL_SENSORS_H
/*===========================================================================*/
/* Driver constants. */
@ -142,6 +142,6 @@ extern "C" {
}
#endif
#endif /* _HAL_SENSORS_H_ */
#endif /* HAL_SENSORS_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _CHPRINTF_H_
#define _CHPRINTF_H_
#ifndef CHPRINTF_H
#define CHPRINTF_H
#include <stdarg.h>
@ -44,6 +44,6 @@ extern "C" {
}
#endif
#endif /* _CHPRINTF_H_ */
#endif /* CHPRINTF_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _MEMSTREAMS_H_
#define _MEMSTREAMS_H_
#ifndef MEMSTREAMS_H
#define MEMSTREAMS_H
/*===========================================================================*/
/* Driver constants. */
@ -90,6 +90,6 @@ extern "C" {
}
#endif
#endif /* _MEMSTREAMS_H_ */
#endif /* MEMSTREAMS_H */
/** @} */

View File

@ -22,8 +22,8 @@
* @{
*/
#ifndef _NULLSTREAMS_H_
#define _NULLSTREAMS_H_
#ifndef NULLSTREAMS_H
#define NULLSTREAMS_H
/*===========================================================================*/
/* Driver constants. */
@ -81,6 +81,6 @@ extern "C" {
}
#endif
#endif /* _NULLSTREAMS_H_ */
#endif /* NULLSTREAMS_H */
/** @} */