X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao_ee.c;h=a0f2e23a3f9392e4d1ed781d156f43c6cdf815d1;hp=8e2e94d55be133ea8eec40ae664fa0346a929ed8;hb=c3fec2c4c65db71e88ef0c05c69463438a7cfc6c;hpb=ac99982b10fd5772218660137ee21db9b90cd885 diff --git a/ao_ee.c b/ao_ee.c index 8e2e94d5..a0f2e23a 100644 --- a/ao_ee.c +++ b/ao_ee.c @@ -3,8 +3,7 @@ * * 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. + * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -171,9 +170,9 @@ ao_ee_wrsr(uint8_t status) #define EE_BLOCK_NONE 0xffff -__xdata uint8_t ao_ee_data[EE_BLOCK]; -__data uint16_t ao_ee_block = EE_BLOCK_NONE; -__data uint8_t ao_ee_block_dirty; +static __xdata uint8_t ao_ee_data[EE_BLOCK]; +static __pdata uint16_t ao_ee_block = EE_BLOCK_NONE; +static __pdata uint8_t ao_ee_block_dirty; /* Write the current block to the EEPROM */ static void @@ -216,27 +215,27 @@ ao_ee_read_block(void) ao_ee_cs_high(); } -void -ao_ee_flush(void) +static void +ao_ee_flush_internal(void) { if (ao_ee_block_dirty) { ao_ee_write_block(); ao_ee_block_dirty = 0; } } - + static void ao_ee_fill(uint16_t block) { if (block != ao_ee_block) { - ao_ee_flush(); + ao_ee_flush_internal(); ao_ee_block = block; ao_ee_read_block(); } } uint8_t -ao_ee_write(uint32_t pos, uint8_t *buf, uint16_t len) +ao_ee_write(uint32_t pos, uint8_t *buf, uint16_t len) __reentrant { uint16_t block; uint16_t this_len; @@ -262,7 +261,7 @@ ao_ee_write(uint32_t pos, uint8_t *buf, uint16_t len) if (this_len != 256) ao_ee_fill(block); else { - ao_ee_flush(); + ao_ee_flush_internal(); ao_ee_block = block; } memcpy(ao_ee_data + this_off, buf, this_len); @@ -277,7 +276,7 @@ ao_ee_write(uint32_t pos, uint8_t *buf, uint16_t len) } uint8_t -ao_ee_read(uint32_t pos, uint8_t *buf, uint16_t len) +ao_ee_read(uint32_t pos, uint8_t *buf, uint16_t len) __reentrant { uint16_t block; uint16_t this_len; @@ -311,12 +310,20 @@ ao_ee_read(uint32_t pos, uint8_t *buf, uint16_t len) return 1; } +void +ao_ee_flush(void) __reentrant +{ + ao_mutex_get(&ao_ee_mutex); { + ao_ee_flush_internal(); + } ao_mutex_put(&ao_ee_mutex); +} + /* * Read/write the config block, which is in * the last block of the ao_eeprom */ uint8_t -ao_ee_write_config(uint8_t *buf, uint16_t len) +ao_ee_write_config(uint8_t *buf, uint16_t len) __reentrant { if (len > AO_EE_BLOCK_SIZE) return 0; @@ -324,12 +331,13 @@ ao_ee_write_config(uint8_t *buf, uint16_t len) ao_ee_fill(AO_EE_CONFIG_BLOCK); memcpy(ao_ee_data, buf, len); ao_ee_block_dirty = 1; + ao_ee_flush_internal(); } ao_mutex_put(&ao_ee_mutex); return 1; } uint8_t -ao_ee_read_config(uint8_t *buf, uint16_t len) +ao_ee_read_config(uint8_t *buf, uint16_t len) __reentrant { if (len > AO_EE_BLOCK_SIZE) return 0; @@ -340,6 +348,67 @@ ao_ee_read_config(uint8_t *buf, uint16_t len) return 1; } +static void +ee_dump(void) +{ + __xdata uint8_t b; + __xdata uint16_t block; + __xdata uint8_t i; + + ao_cmd_hex(); + block = ao_cmd_lex_i; + if (ao_cmd_status != ao_cmd_success) + return; + i = 0; + do { + if ((i & 7) == 0) { + if (i) + putchar('\n'); + ao_cmd_put16((uint16_t) i); + } + putchar(' '); + ao_ee_read(((uint32_t) block << 8) | i, &b, 1); + ao_cmd_put8(b); + ++i; + } while (i != 0); + putchar('\n'); +} + +static void +ee_store(void) +{ + __xdata uint16_t block; + __xdata uint8_t i; + __xdata uint16_t len; + __xdata uint8_t b; + __xdata uint32_t addr; + + ao_cmd_hex(); + block = ao_cmd_lex_i; + ao_cmd_hex(); + i = ao_cmd_lex_i; + addr = ((uint32_t) block << 8) | i; + ao_cmd_hex(); + len = ao_cmd_lex_i; + if (ao_cmd_status != ao_cmd_success) + return; + while (len--) { + ao_cmd_hex(); + if (ao_cmd_status != ao_cmd_success) + return; + b = ao_cmd_lex_i; + ao_ee_write(addr, &b, 1); + addr++; + } + ao_ee_flush(); +} + +__code struct ao_cmds ao_ee_cmds[] = { + { 'e', ee_dump, "e Dump a block of EEPROM data" }, + { 'w', ee_store, "w ... Write data to EEPROM" }, + { 0, ee_store, NULL }, +}; + /* * To initialize the chip, set up the CS line and * the SPI interface @@ -386,4 +455,5 @@ ao_ee_init(void) UxGCR_CPHA_FIRST_EDGE | UxGCR_ORDER_MSB | (17 << UxGCR_BAUD_E_SHIFT)); + ao_cmd_register(&ao_ee_cmds[0]); }