diff options
Diffstat (limited to 'os/hal/include')
-rw-r--r-- | os/hal/include/ee24xx.h | 64 | ||||
-rw-r--r-- | os/hal/include/ee25xx.h | 63 | ||||
-rw-r--r-- | os/hal/include/eeprom.h | 147 | ||||
-rw-r--r-- | os/hal/include/hal_community.h | 1 |
4 files changed, 275 insertions, 0 deletions
diff --git a/os/hal/include/ee24xx.h b/os/hal/include/ee24xx.h new file mode 100644 index 0000000..ab12fd1 --- /dev/null +++ b/os/hal/include/ee24xx.h @@ -0,0 +1,64 @@ +/* + Copyright 2012 Uladzimir Pylinski aka barthess. + You may use this work without restrictions, as long as this notice is included. + The work is provided "as is" without warranty of any kind, neither express nor implied. +*/ + +#ifndef EE24XX_H +#define EE24XX_H + +#include "hal.h" + +#if defined(HAL_USE_EEPROM) && HAL_USE_EEPROM && EEPROM_USE_EE24XX + +#define EEPROM_DEV_24XX 24 + +/** + * @extends EepromFileConfig + */ +typedef struct { + _eeprom_file_config_data + /** + * Driver connected to IC. + */ + I2CDriver *i2cp; + /** + * Address of IC on I2C bus. + */ + i2caddr_t addr; + /** + * Pointer to write buffer. The safest size is (pagesize + 2) + */ + uint8_t *write_buf; +} I2CEepromFileConfig; + +/** + * @brief @p I2CEepromFileStream specific data. + */ +#define _eeprom_file_stream_data_i2c \ + _eeprom_file_stream_data + +/** + * @extends EepromFileStream + * + * @brief EEPROM file stream driver class for I2C device. + */ +typedef struct { + const struct EepromFileStreamVMT *vmt; + _eeprom_file_stream_data_i2c + /* Overwritten parent data member. */ + const I2CEepromFileConfig *cfg; +} I2CEepromFileStream; + + +/** + * Open I2C EEPROM IC as file and return pointer to the file stream object + * @note Fucntion allways successfully open file. All checking makes + * in read/write functions. + */ +#define I2CEepromFileOpen(efs, eepcfg, eepdev) \ + EepromFileOpen((EepromFileStream *)efs, (EepromFileConfig *)eepcfg, eepdev); + +#endif /* #if defined(EEPROM_USE_EE24XX) && EEPROM_USE_EE24XX */ + +#endif // EE24XX_H diff --git a/os/hal/include/ee25xx.h b/os/hal/include/ee25xx.h new file mode 100644 index 0000000..fc2ad6f --- /dev/null +++ b/os/hal/include/ee25xx.h @@ -0,0 +1,63 @@ +/* + Copyright 2012 Uladzimir Pylinski aka barthess. + You may use this work without restrictions, as long as this notice is included. + The work is provided "as is" without warranty of any kind, neither express nor implied. +*/ + +#ifndef EE25XX_H +#define EE25XX_H + +#include "hal.h" + +#if defined(HAL_USE_EEPROM) && HAL_USE_EEPROM && EEPROM_USE_EE25XX + +#define EEPROM_DEV_25XX 25 + +/** + * @extends EepromFileConfig + */ +typedef struct { + _eeprom_file_config_data + /** + * Driver connected to IC. + */ + SPIDriver *spip; + /** + * Config associated with SPI driver. + */ + const SPIConfig *spicfg; +} SPIEepromFileConfig; + +/** + * @brief @p SPIEepromFileStream specific data. + */ +#define _eeprom_file_stream_data_spi \ + _eeprom_file_stream_data + +/** + * @extends EepromFileStream + * + * @brief EEPROM file stream driver class for SPI device. + */ +typedef struct { + const struct EepromFileStreamVMT *vmt; + _eeprom_file_stream_data_spi + /* Overwritten parent data member. */ + const SPIEepromFileConfig *cfg; +} SPIEepromFileStream; + +/** + * Open SPI EEPROM IC as file and return pointer to the file stream object + * @note Fucntion allways successfully open file. All checking makes + * in read/write functions. + */ +EepromFileStream *SPIEepromFileOpen(SPIEepromFileStream *efs, + const SPIEepromFileConfig *eepcfg, + const EepromDevice *eepdev); + +#define SPIEepromFileOpen(efs, eepcfg, eepdev) \ + EepromFileOpen((EepromFileStream *)efs, (EepromFileConfig *)eepcfg, eepdev); + +#endif /* #if defined(EEPROM_USE_EE25XX) && EEPROM_USE_EE25XX */ + +#endif // EE25XX_H diff --git a/os/hal/include/eeprom.h b/os/hal/include/eeprom.h new file mode 100644 index 0000000..b0fd360 --- /dev/null +++ b/os/hal/include/eeprom.h @@ -0,0 +1,147 @@ +/* + Copyright (c) 2013 Timon Wong + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/* + Copyright 2012 Uladzimir Pylinski aka barthess. + You may use this work without restrictions, as long as this notice is included. + The work is provided "as is" without warranty of any kind, neither express nor implied. +*/ + +#ifndef __EEPROM_H__ +#define __EEPROM_H__ + +#include "ch.h" +#include "hal.h" + +#ifndef HAL_USE_EEPROM +#define HAL_USE_EEPROM FALSE +#endif + +#ifndef EEPROM_USE_EE25XX +#define EEPROM_USE_EE25XX FALSE +#endif + +#ifndef EEPROM_USE_EE24XX +#define EEPROM_USE_EE24XX FALSE +#endif + +#if HAL_USE_EEPROM + +#if EEPROM_USE_EE25XX && EEPROM_USE_EE24XX +#define EEPROM_TABLE_SIZE 2 +#elif EEPROM_USE_EE25XX || EEPROM_USE_EE24XX +#define EEPROM_TABLE_SIZE 1 +#else +#error "No EEPROM device selected!" +#endif + +#if EEPROM_USE_EE25XX && !HAL_USE_SPI +#error "25xx enabled but SPI driver is disabled!" +#endif + +#if EEPROM_USE_EE24XX && !HAL_USE_I2C +#error "24xx enabled but I2C driver is disabled!" +#endif + +#define _eeprom_file_config_data \ + /* Lower barrier of file in EEPROM memory array. */ \ + uint32_t barrier_low; \ + /* Higher barrier of file in EEPROM memory array. */ \ + uint32_t barrier_hi; \ + /* Size of memory array in bytes. */ \ + uint32_t size; \ + /* Size of single page in bytes. */ \ + uint16_t pagesize; \ + /* Time needed by IC for single byte/page writing. */ \ + systime_t write_time; + +typedef uint32_t fileoffset_t; + +typedef struct { + _eeprom_file_config_data +} EepromFileConfig; + +/** + * @brief @p EepromFileStream specific data. + */ +#define _eeprom_file_stream_data \ + _base_sequential_stream_data \ + uint32_t errors; \ + uint32_t position; \ + +/** + * @extends BaseFileStreamVMT + * + * @brief @p EepromFileStream virtual methods table. + */ +struct EepromFileStreamVMT { + _file_stream_methods +}; + +/** + * @extends BaseFileStream + * + * @brief EEPROM file stream driver class. + * @details This class extends @p BaseFileStream by adding some fields. + */ +typedef struct { + /** @brief Virtual Methods Table.*/ + const struct EepromFileStreamVMT *vmt; + _eeprom_file_stream_data + /** pointer to config object, must be overwritten by all derived classes.*/ + const EepromFileConfig *cfg; +} EepromFileStream; + +/** + * @brief Low level device descriptor. + */ +typedef struct { + const uint8_t id; + const struct EepromFileStreamVMT *efsvmt; +} EepromDevice; + +const EepromDevice *EepromFindDevice(uint8_t id); + +EepromFileStream *EepromFileOpen(EepromFileStream *efs, + const EepromFileConfig *eepcfg, + const EepromDevice *eepdev); + +uint8_t EepromReadByte(EepromFileStream *efs); +uint16_t EepromReadHalfword(EepromFileStream *efs); +uint32_t EepromReadWord(EepromFileStream *efs); +size_t EepromWriteByte(EepromFileStream *efs, uint8_t data); +size_t EepromWriteHalfword(EepromFileStream *efs, uint16_t data); +size_t EepromWriteWord(EepromFileStream *efs, uint32_t data); + +msg_t eepfs_getsize(void *ip); +msg_t eepfs_getposition(void *ip); +msg_t eepfs_lseek(void *ip, fileoffset_t offset); +msg_t eepfs_close(void *ip); +msg_t eepfs_geterror(void *ip); +msg_t eepfs_put(void *ip, uint8_t b); +msg_t eepfs_get(void *ip); + +#include "ee24xx.h" +#include "ee25xx.h" + +#endif /* #if defined(HAL_USE_EEPROM) && HAL_USE_EEPROM */ +#endif /* __EEPROM_H__ */ diff --git a/os/hal/include/hal_community.h b/os/hal/include/hal_community.h index 8a17765..5ed561f 100644 --- a/os/hal/include/hal_community.h +++ b/os/hal/include/hal_community.h @@ -37,6 +37,7 @@ /* Complex drivers.*/
#include "onewire.h"
#include "crc.h"
+#include "eeprom.h"
/*===========================================================================*/
/* Driver constants. */
|