diff options
Diffstat (limited to 'drivers/eeprom')
-rw-r--r-- | drivers/eeprom/eeprom_custom.c-template | 46 | ||||
-rw-r--r-- | drivers/eeprom/eeprom_i2c.c | 12 | ||||
-rw-r--r-- | drivers/eeprom/eeprom_transient.c | 2 | ||||
-rw-r--r-- | drivers/eeprom/eeprom_transient.h | 3 |
4 files changed, 55 insertions, 8 deletions
diff --git a/drivers/eeprom/eeprom_custom.c-template b/drivers/eeprom/eeprom_custom.c-template new file mode 100644 index 0000000000..5f915f7fab --- /dev/null +++ b/drivers/eeprom/eeprom_custom.c-template @@ -0,0 +1,46 @@ +/* Copyright 2019 Nick Brassel (tzarc) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdint.h> +#include <string.h> + +#include "eeprom_driver.h" + +void eeprom_driver_init(void) { + /* Any initialisation code */ + } + +void eeprom_driver_erase(void) { + /* Wipe out the EEPROM, setting values to zero */ +} + +void eeprom_read_block(void *buf, const void *addr, size_t len) { + /* + Read a block of data: + buf: target buffer + addr: 0-based offset within the EEPROM + len: length to read + */ +} + +void eeprom_write_block(const void *buf, void *addr, size_t len) { + /* + Write a block of data: + buf: target buffer + addr: 0-based offset within the EEPROM + len: length to write + */ +} diff --git a/drivers/eeprom/eeprom_i2c.c b/drivers/eeprom/eeprom_i2c.c index 10bd4a1be1..03dbc5e516 100644 --- a/drivers/eeprom/eeprom_i2c.c +++ b/drivers/eeprom/eeprom_i2c.c @@ -76,11 +76,11 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) { i2c_receive(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), buf, len, 100); #ifdef DEBUG_EEPROM_OUTPUT - uprintf("[EEPROM R] 0x%04X: ", ((int)addr)); + dprintf("[EEPROM R] 0x%04X: ", ((int)addr)); for (size_t i = 0; i < len; ++i) { - uprintf(" %02X", (int)(((uint8_t *)buf)[i])); + dprintf(" %02X", (int)(((uint8_t *)buf)[i])); } - uprintf("\n"); + dprintf("\n"); #endif // DEBUG_EEPROM_OUTPUT } @@ -103,11 +103,11 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) { } #ifdef DEBUG_EEPROM_OUTPUT - uprintf("[EEPROM W] 0x%04X: ", ((int)target_addr)); + dprintf("[EEPROM W] 0x%04X: ", ((int)target_addr)); for (uint8_t i = 0; i < write_length; i++) { - uprintf(" %02X", (int)(read_buf[i])); + dprintf(" %02X", (int)(read_buf[i])); } - uprintf("\n"); + dprintf("\n"); #endif // DEBUG_EEPROM_OUTPUT i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE + write_length, 100); diff --git a/drivers/eeprom/eeprom_transient.c b/drivers/eeprom/eeprom_transient.c index 318a827900..b4c78c6f40 100644 --- a/drivers/eeprom/eeprom_transient.c +++ b/drivers/eeprom/eeprom_transient.c @@ -20,7 +20,7 @@ #include "eeprom_driver.h" #include "eeprom_transient.h" -static uint8_t transientBuffer[TRANSIENT_EEPROM_SIZE] = {0}; +__attribute__((aligned(4))) static uint8_t transientBuffer[TRANSIENT_EEPROM_SIZE] = {0}; size_t clamp_length(intptr_t offset, size_t len) { if (offset + len > TRANSIENT_EEPROM_SIZE) { diff --git a/drivers/eeprom/eeprom_transient.h b/drivers/eeprom/eeprom_transient.h index a739fe393a..d06189b246 100644 --- a/drivers/eeprom/eeprom_transient.h +++ b/drivers/eeprom/eeprom_transient.h @@ -20,5 +20,6 @@ The size of the transient EEPROM buffer size. */ #ifndef TRANSIENT_EEPROM_SIZE -# define TRANSIENT_EEPROM_SIZE 64 +# include "eeconfig.h" +# define TRANSIENT_EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO #endif |