From 9290d7eed268d4bd96829dcbae839b5d6b11dad1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 13 Mar 2008 13:55:14 +0100 Subject: * digital/avr/modules/flash: - fixed erase command. - fixed init (actually, SR should be cleared). - merged all tests in one. --- digital/avr/modules/flash/flash.c | 13 ++- digital/avr/modules/flash/test/Makefile | 6 +- digital/avr/modules/flash/test/test-erase.c | 74 --------------- digital/avr/modules/flash/test/test-flash.c | 56 ++++++++++- digital/avr/modules/flash/test/test-init.c | 68 -------------- .../avr/modules/flash/test/test-write-anarray.c | 103 --------------------- .../avr/modules/flash/test/test-write-onebyte.c | 88 ------------------ 7 files changed, 64 insertions(+), 344 deletions(-) delete mode 100644 digital/avr/modules/flash/test/test-erase.c delete mode 100644 digital/avr/modules/flash/test/test-init.c delete mode 100644 digital/avr/modules/flash/test/test-write-anarray.c delete mode 100644 digital/avr/modules/flash/test/test-write-onebyte.c diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c index 61403e35..ebde71f1 100644 --- a/digital/avr/modules/flash/flash.c +++ b/digital/avr/modules/flash/flash.c @@ -50,8 +50,11 @@ flash_address (uint32_t addr) void flash_erase (uint8_t cmd, uint32_t start_addr) { + flash_send_command (FLASH_WREN); + + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); /* send the command. */ - flash_send_command (cmd); + spi_send (cmd); /* verify if the cmd is the full erase. */ if (cmd != FLASH_ERASE_FULL) @@ -63,6 +66,9 @@ flash_erase (uint8_t cmd, uint32_t start_addr) { flash_global.addr = 0x0; } + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + + while (flash_is_busy()); } /** Poll the busy bit in the Software Status Register of the flash memory. @@ -116,6 +122,11 @@ flash_init (void) /* Enables the flash to be writable. */ flash_send_command (FLASH_WREN); + + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + spi_send (FLASH_WRSR); + spi_send (0); + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); /* Read the flash status. */ proto_send1b ('s', flash_read_status()); diff --git a/digital/avr/modules/flash/test/Makefile b/digital/avr/modules/flash/test/Makefile index 422e7b54..aec41f98 100644 --- a/digital/avr/modules/flash/test/Makefile +++ b/digital/avr/modules/flash/test/Makefile @@ -1,10 +1,6 @@ BASE = ../../.. -AVR_PROGS = test-flash test-write-onbyte test-erase test-write-anarray test-init +AVR_PROGS = test-flash -test-write-onbyte_SOURCES = test-write-onebyte.c -test-erase_SOURCES = test-erase.c -test-write-anarray_SOURCES = test-write-anarray.c -test-init_SOURCES = test-init.c test-flash_SOURCES = test-flash.c MODULES = utils spi flash proto uart diff --git a/digital/avr/modules/flash/test/test-erase.c b/digital/avr/modules/flash/test/test-erase.c deleted file mode 100644 index 3c4312e0..00000000 --- a/digital/avr/modules/flash/test/test-erase.c +++ /dev/null @@ -1,74 +0,0 @@ -/* test-erase.c */ -/* avr.flash - AVR Flash SPI use. {{{ - * - * Copyright (C) 2008 Nélio Laranjeiro - * - * APBTeam: - * Web: http://apbteam.org/ - * Email: team AT apbteam DOT org - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * }}} */ -#include "common.h" -#include "io.h" -#include "../flash.h" -#include "modules/proto/proto.h" -#include "modules/utils/utils.h" -#include "modules/uart/uart.h" - -#define TEST_BASE 0x50 - -void -proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) -{ -#define c(cmd, size) (cmd << 8 | size) - switch (c (cmd, size)) - { - case c ('z', 0): - /* Reset */ - utils_reset (); - break; - default: - /* Error */ - proto_send0 ('?'); - return; - } - /* Acknowledge what has been done */ - proto_send (cmd, size, args); -} - -int -main (void) -{ - uart0_init (); - proto_send0 ('z'); - proto_send0 ('c'); - flash_init (); - proto_send0 ('f'); - - flash_erase (FLASH_ERASE_FULL, 0); - - while (flash_is_busy ()) - { - utils_delay_ms (10); - proto_send0 ('o'); - } - proto_send0 ('e'); - - while (1) - proto_accept (uart0_getc ()); -} - diff --git a/digital/avr/modules/flash/test/test-flash.c b/digital/avr/modules/flash/test/test-flash.c index fc786858..546ce71b 100644 --- a/digital/avr/modules/flash/test/test-flash.c +++ b/digital/avr/modules/flash/test/test-flash.c @@ -27,13 +27,15 @@ #include "../flash.h" #include "modules/proto/proto.h" #include "modules/utils/utils.h" +#include "modules/utils/byte.h" #include "modules/uart/uart.h" -#define TEST_BASE 0x300 - void proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) { + /* May be unused. */ + uint32_t addr = v8_to_v32 (0, args[0], args[1], args[2]); + uint8_t buf[16]; #define c(cmd, size) (cmd << 8 | size) switch (c (cmd, size)) { @@ -45,16 +47,60 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) /* Erase full */ flash_erase (FLASH_ERASE_FULL, 0); break; + case c ('e', 3): + /* Erase 4k: + * - 3b: address. */ + flash_erase (FLASH_ERASE_4K, addr); + break; case c ('s', 0): /* print flash status */ proto_send1b ('s', flash_read_status()); + break; case c ('w', 0): /* Send the write enable flash command. */ flash_send_command (FLASH_WREN); + break; + case c ('r', 3): + /* Read one byte: + * - 3b: address. */ + proto_send1b ('r', flash_read (addr)); + break; + case c ('r', 4): + /* Read several bytes: + * - 3b: address. + * - 1b: number of bytes. */ + if (args[3] > sizeof (buf)) + { + proto_send0 ('?'); + return; + } + else + { + flash_read_array (addr, buf, args[3]); + proto_send ('r', args[3], buf); + } + break; + case c ('w', 4): + /* Write one byte: + * - 3b: address. + * - 1b: byte. */ + flash_write (addr, args[3]); + break; default: - /* Error */ - proto_send0 ('?'); - return; + if (cmd == 'w' && size > 4) + { + /* Write several bytes: + * - 3b: address. + * - nb: bytes. */ + flash_write_array (addr, args + 3, size - 3); + } + else + { + /* Error */ + proto_send0 ('?'); + return; + } + break; } /* Acknowledge what has been done */ proto_send (cmd, size, args); diff --git a/digital/avr/modules/flash/test/test-init.c b/digital/avr/modules/flash/test/test-init.c deleted file mode 100644 index ec8c3e83..00000000 --- a/digital/avr/modules/flash/test/test-init.c +++ /dev/null @@ -1,68 +0,0 @@ -/* test-erase.c */ -/* avr.flash - AVR Flash SPI use. {{{ - * - * Copyright (C) 2008 Nélio Laranjeiro - * - * APBTeam: - * Web: http://apbteam.org/ - * Email: team AT apbteam DOT org - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * }}} */ -#include "common.h" -#include "io.h" -#include "../flash.h" -#include "modules/proto/proto.h" -#include "modules/utils/utils.h" -#include "modules/uart/uart.h" - -void -proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) -{ -#define c(cmd, size) (cmd << 8 | size) - switch (c (cmd, size)) - { - case c ('z', 0): - /* Reset */ - utils_reset (); - break; - default: - /* Error */ - proto_send0 ('?'); - return; - } - /* Acknowledge what has been done */ - proto_send (cmd, size, args); -} - -int -main (void) -{ - flash_t *flash; - - uart0_init (); - proto_send0 ('z'); - proto_send0 ('c'); - flash = flash_init (); - proto_send0 ('f'); - - proto_send1b ('s', flash_read_status()); - proto_send3b ('e', (flash->addr >> 16) & 0x1f, (flash->addr >> 8), flash->addr); - - while (1) - proto_accept (uart0_getc ()); -} - diff --git a/digital/avr/modules/flash/test/test-write-anarray.c b/digital/avr/modules/flash/test/test-write-anarray.c deleted file mode 100644 index 65540cea..00000000 --- a/digital/avr/modules/flash/test/test-write-anarray.c +++ /dev/null @@ -1,103 +0,0 @@ -/* test-write-anarray.c */ -/* avr.flash - AVR Flash SPI use. {{{ - * - * Copyright (C) 2008 Nélio Laranjeiro - * - * APBTeam: - * Web: http://apbteam.org/ - * Email: team AT apbteam DOT org - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * }}} */ -#include "common.h" -#include "io.h" -#include "../flash.h" -#include "modules/proto/proto.h" -#include "modules/utils/utils.h" -#include "modules/uart/uart.h" - -uint32_t addr = 0; - -void -proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) -{ -#define c(cmd, size) (cmd << 8 | size) - switch (c (cmd, size)) - { - case c ('z', 0): - /* Reset */ - utils_reset (); - break; - case c ('e', 0): - /* Erase full */ - flash_erase (FLASH_ERASE_FULL, 0); - break; - case c ('s', 0): - /* print flash status */ - proto_send1b ('s', flash_read_status()); - case c ('w', 0): - /* Send the write enable flash command. */ - flash_send_command (FLASH_WREN); - case c ('a', 3): - /* get the addr */ - addr = ((uint32_t) (args[0] & 0x1F) << 16) | ((uint32_t) args[1] << 8) - | args[2]; - default: - /* Error */ - proto_send0 ('?'); - return; - } - /* Acknowledge what has been done */ - proto_send (cmd, size, args); -} - -int -main (void) -{ - uint8_t data[5]; - uint8_t data_rsp[5]; - uint8_t i; - - uart0_init (); - proto_send0 ('z'); - proto_send0 ('c'); - flash_init (); - proto_send0 ('f'); - - proto_send1b ('s', flash_read_status ()); - - for (i = 0; i < 5; i++) - { - data[i] = i + 'a'; - } - - /* Write a full array. */ - flash_write_array (addr, data, 5); - - proto_send1b ('p', flash_read_status()); - - /* Read a full array. */ - flash_read_array (addr , data_rsp, 5); - - /* Print the data_rsp to the i2c */ - proto_send ('g', 5, data_rsp); - - addr += 5; - - while (1) - proto_accept (uart0_getc ()); -} - diff --git a/digital/avr/modules/flash/test/test-write-onebyte.c b/digital/avr/modules/flash/test/test-write-onebyte.c deleted file mode 100644 index 0c27c86a..00000000 --- a/digital/avr/modules/flash/test/test-write-onebyte.c +++ /dev/null @@ -1,88 +0,0 @@ -/* test-write-onebyte.c */ -/* avr.flash - AVR Flash SPI use. {{{ - * - * Copyright (C) 2008 Nélio Laranjeiro - * - * APBTeam: - * Web: http://apbteam.org/ - * Email: team AT apbteam DOT org - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * }}} */ -#include "common.h" -#include "io.h" -#include "../flash.h" -#include "modules/proto/proto.h" -#include "modules/utils/utils.h" -#include "modules/uart/uart.h" - -#define TEST_BASE 0x224 - -void -proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) -{ -#define c(cmd, size) (cmd << 8 | size) - switch (c (cmd, size)) - { - case c ('z', 0): - /* Reset */ - utils_reset (); - break; - case c ('e', 0): - /* Erase full */ - flash_erase (FLASH_ERASE_FULL, 0); - break; - case c ('s', 0): - /* print flash status */ - proto_send1b ('s', flash_read_status()); - case c ('w', 0): - /* Send the write enable flash command. */ - flash_send_command (FLASH_WREN); - default: - /* Error */ - proto_send0 ('?'); - return; - } - /* Acknowledge what has been done */ - proto_send (cmd, size, args); -} - -int -main (void) -{ - uart0_init (); - proto_send0 ('z'); - proto_send0 ('c'); - flash_init (); - proto_send0 ('f'); - - flash_send_command (FLASH_WREN); - proto_send1b ('s', flash_read_status ()); - - flash_write (TEST_BASE, 'a'); - proto_send2b ('o', flash_read_status (), flash_read(TEST_BASE)); - - flash_write (TEST_BASE + 1, 'a'); - proto_send2b ('o', flash_read_status (), flash_read(TEST_BASE + 1)); - - /* read */ - proto_send1b ('r', flash_read (TEST_BASE)); - proto_send1b ('r', flash_read (TEST_BASE + 1)); - - while (1) - proto_accept (uart0_getc ()); -} - -- cgit v1.2.3