From f3272ad5ba4875abde17758fe38ba0fddf39f363 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 7 Mar 2017 17:34:30 -0600 Subject: [PATCH] Updated to match API changes in mbed OS --- I2CEEBlockDevice.cpp | 30 +++++++++++++----------------- I2CEEBlockDevice.h | 24 ++++++++++-------------- TESTS/block_device/i2cee/main.cpp | 11 +++++------ 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/I2CEEBlockDevice.cpp b/I2CEEBlockDevice.cpp index 4ebfe2d245..3ae66fc3a3 100644 --- a/I2CEEBlockDevice.cpp +++ b/I2CEEBlockDevice.cpp @@ -26,22 +26,20 @@ I2CEEBlockDevice::I2CEEBlockDevice( _i2c.frequency(freq); } -bd_error_t I2CEEBlockDevice::init() +int I2CEEBlockDevice::init() { return _sync(); } -bd_error_t I2CEEBlockDevice::deinit() +int I2CEEBlockDevice::deinit() { return 0; } -bd_error_t I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) +int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) { // Check the address and size fit onto the chip. - if (!is_valid_read(addr, size)) { - return BD_ERROR_PARAMETER; - } + MBED_ASSERT(is_valid_read(addr, size)); _i2c.start(); if (!_i2c.write(_i2c_addr | 0) || @@ -58,12 +56,10 @@ bd_error_t I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) return 0; } -bd_error_t I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) +int I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) { // Check the addr and size fit onto the chip. - if (!is_valid_program(addr, size)) { - return BD_ERROR_PARAMETER; - } + MBED_ASSERT(is_valid_program(addr, size)); // While we have some more data to write. while (size > 0) { @@ -82,7 +78,7 @@ bd_error_t I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size } _i2c.stop(); - bd_error_t err = _sync(); + int err = _sync(); if (err) { return err; } @@ -95,13 +91,13 @@ bd_error_t I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size return 0; } -bd_error_t I2CEEBlockDevice::erase(bd_addr_t addr, bd_size_t size) +int I2CEEBlockDevice::erase(bd_addr_t addr, bd_size_t size) { // No erase needed return 0; } -bd_error_t I2CEEBlockDevice::_sync() +int I2CEEBlockDevice::_sync() { // The chip doesn't ACK while writing to the actual EEPROM // so loop trying to do a zero byte write until it is ACKed @@ -117,22 +113,22 @@ bd_error_t I2CEEBlockDevice::_sync() return BD_ERROR_DEVICE_ERROR; } -bd_size_t I2CEEBlockDevice::get_read_size() +bd_size_t I2CEEBlockDevice::get_read_size() const { return 1; } -bd_size_t I2CEEBlockDevice::get_program_size() +bd_size_t I2CEEBlockDevice::get_program_size() const { return 1; } -bd_size_t I2CEEBlockDevice::get_erase_size() +bd_size_t I2CEEBlockDevice::get_erase_size() const { return 1; } -bd_size_t I2CEEBlockDevice::size() +bd_size_t I2CEEBlockDevice::size() const { return _size; } diff --git a/I2CEEBlockDevice.h b/I2CEEBlockDevice.h index 417de6dd70..635ffd2d12 100644 --- a/I2CEEBlockDevice.h +++ b/I2CEEBlockDevice.h @@ -15,9 +15,6 @@ */ #ifndef MBED_I2CEEPROM_BLOCK_DEVICE_H #define MBED_I2CEEPROM_BLOCK_DEVICE_H - -/* If the target has no I2C support then I2CEEPROM is not supported */ -#ifdef DEVICE_I2C #include #include "BlockDevice.h" @@ -71,13 +68,13 @@ public: * * @return 0 on success or a negative error code on failure */ - virtual bd_error_t init(); + virtual int init(); /** Deinitialize a block device * * @return 0 on success or a negative error code on failure */ - virtual bd_error_t deinit(); + virtual int deinit(); /** Read blocks from a block device * @@ -86,7 +83,7 @@ public: * @param size Size to read in bytes, must be a multiple of read block size * @return 0 on success, negative error code on failure */ - virtual bd_error_t read(void *buffer, bd_addr_t addr, bd_size_t size); + virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); /** Program blocks to a block device * @@ -97,7 +94,7 @@ public: * @param size Size to write in bytes, must be a multiple of program block size * @return 0 on success, negative error code on failure */ - virtual bd_error_t program(const void *buffer, bd_addr_t addr, bd_size_t size); + virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); /** Erase blocks on a block device * @@ -107,33 +104,33 @@ public: * @param size Size to erase in bytes, must be a multiple of erase block size * @return 0 on success, negative error code on failure */ - virtual bd_error_t erase(bd_addr_t addr, bd_size_t size); + virtual int erase(bd_addr_t addr, bd_size_t size); /** Get the size of a readable block * * @return Size of a readable block in bytes */ - virtual bd_size_t get_read_size(); + virtual bd_size_t get_read_size() const; /** Get the size of a programable block * * @return Size of a programable block in bytes * @note Must be a multiple of the read size */ - virtual bd_size_t get_program_size(); + virtual bd_size_t get_program_size() const; /** Get the size of a eraseable block * * @return Size of a eraseable block in bytes * @note Must be a multiple of the program size */ - virtual bd_size_t get_erase_size(); + virtual bd_size_t get_erase_size() const; /** Get the total size of the underlying device * * @return Size of the underlying device in bytes */ - virtual bd_size_t size(); + virtual bd_size_t size() const; private: I2C _i2c; @@ -141,9 +138,8 @@ private: uint32_t _size; uint32_t _block; - bd_error_t _sync(); + int _sync(); }; -#endif /* DEVICE_SPI */ #endif /* MBED_SD_BLOCK_DEVICE_H */ diff --git a/TESTS/block_device/i2cee/main.cpp b/TESTS/block_device/i2cee/main.cpp index 4b80b4f676..2f191818cc 100644 --- a/TESTS/block_device/i2cee/main.cpp +++ b/TESTS/block_device/i2cee/main.cpp @@ -8,10 +8,6 @@ using namespace utest::v1; -//#if !I2CEE_INSTALLED -//#error [NOT_SUPPORTED] I2CEE Required -//#endif - #define TEST_PINS D14, D15 #define TEST_ADDR 0xa0 #define TEST_SIZE 32*1024 @@ -22,7 +18,7 @@ using namespace utest::v1; const struct { const char *name; - bd_size_t (BlockDevice::*method)(); + bd_size_t (BlockDevice::*method)() const; } ATTRS[] = { {"read size", &BlockDevice::get_read_size}, {"program size", &BlockDevice::get_program_size}, @@ -73,7 +69,10 @@ void test_read_write() { // Write, sync, and read the block printf("test %0*llx:%llu...\n", addrwidth, block, block_size); - err = bd.write(write_block, block, block_size); + err = bd.erase(block, block_size); + TEST_ASSERT_EQUAL(0, err); + + err = bd.program(write_block, block, block_size); TEST_ASSERT_EQUAL(0, err); printf("write %0*llx:%llu ", addrwidth, block, block_size);