diff options
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/lib/peripherals/displays/hal_displays.h | 6 | ||||
-rw-r--r-- | os/hal/lib/peripherals/flash/hal_flash.h | 231 | ||||
-rw-r--r-- | os/hal/lib/peripherals/sensors/hal_accelerometer.h | 6 | ||||
-rw-r--r-- | os/hal/lib/peripherals/sensors/hal_compass.h | 6 | ||||
-rw-r--r-- | os/hal/lib/peripherals/sensors/hal_gyroscope.h | 6 | ||||
-rw-r--r-- | os/hal/lib/peripherals/sensors/hal_sensors.h | 6 | ||||
-rw-r--r-- | os/hal/lib/streams/chprintf.h | 6 | ||||
-rw-r--r-- | os/hal/lib/streams/memstreams.h | 6 | ||||
-rw-r--r-- | os/hal/lib/streams/nullstreams.h | 6 |
9 files changed, 255 insertions, 24 deletions
diff --git a/os/hal/lib/peripherals/displays/hal_displays.h b/os/hal/lib/peripherals/displays/hal_displays.h index 046e4e727..78ce1c9f7 100644 --- a/os/hal/lib/peripherals/displays/hal_displays.h +++ b/os/hal/lib/peripherals/displays/hal_displays.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/peripherals/flash/hal_flash.h b/os/hal/lib/peripherals/flash/hal_flash.h new file mode 100644 index 000000000..17ada6e6e --- /dev/null +++ b/os/hal/lib/peripherals/flash/hal_flash.h @@ -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 */
+
+/** @} */
diff --git a/os/hal/lib/peripherals/sensors/hal_accelerometer.h b/os/hal/lib/peripherals/sensors/hal_accelerometer.h index da6a58b4b..f5a3be39d 100644 --- a/os/hal/lib/peripherals/sensors/hal_accelerometer.h +++ b/os/hal/lib/peripherals/sensors/hal_accelerometer.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/peripherals/sensors/hal_compass.h b/os/hal/lib/peripherals/sensors/hal_compass.h index 83efc9852..a9366b2c6 100644 --- a/os/hal/lib/peripherals/sensors/hal_compass.h +++ b/os/hal/lib/peripherals/sensors/hal_compass.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/peripherals/sensors/hal_gyroscope.h b/os/hal/lib/peripherals/sensors/hal_gyroscope.h index 6e43929d4..66be13792 100644 --- a/os/hal/lib/peripherals/sensors/hal_gyroscope.h +++ b/os/hal/lib/peripherals/sensors/hal_gyroscope.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/peripherals/sensors/hal_sensors.h b/os/hal/lib/peripherals/sensors/hal_sensors.h index 8d0d230fa..db8d10269 100644 --- a/os/hal/lib/peripherals/sensors/hal_sensors.h +++ b/os/hal/lib/peripherals/sensors/hal_sensors.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/streams/chprintf.h b/os/hal/lib/streams/chprintf.h index 7aa3d5d44..a595249a6 100644 --- a/os/hal/lib/streams/chprintf.h +++ b/os/hal/lib/streams/chprintf.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/streams/memstreams.h b/os/hal/lib/streams/memstreams.h index ef06a5aa7..dad5ba677 100644 --- a/os/hal/lib/streams/memstreams.h +++ b/os/hal/lib/streams/memstreams.h @@ -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 */
/** @} */
diff --git a/os/hal/lib/streams/nullstreams.h b/os/hal/lib/streams/nullstreams.h index 37cb6a4e2..f174ee3a6 100644 --- a/os/hal/lib/streams/nullstreams.h +++ b/os/hal/lib/streams/nullstreams.h @@ -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 */
/** @} */
|