From cadf1a3749fc51d266e9672fdecf1c8cd69c92a3 Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Mon, 11 May 2009 22:06:51 +0200 Subject: * digital/avr/modules/flash: (Closes #68). * Removed the flash stub sub directory and add a real stub in flash.host.c file. --- digital/avr/modules/flash/Makefile.module | 2 +- digital/avr/modules/flash/flash.avr.c | 262 +++++++++++++++++++++++ digital/avr/modules/flash/flash.c | 262 ----------------------- digital/avr/modules/flash/flash.host.c | 71 ++++++ digital/avr/modules/flash/stub/Makefile.module | 1 - digital/avr/modules/flash/stub/doc/stub.txt | 11 - digital/avr/modules/flash/stub/flash.c | 240 --------------------- digital/avr/modules/flash/stub/test/Makefile | 12 -- digital/avr/modules/flash/stub/test/test_flash.c | 57 ----- digital/avr/modules/flash/test/Makefile | 8 +- digital/avr/modules/flash/test/test-flash.c | 10 - 11 files changed, 340 insertions(+), 596 deletions(-) create mode 100644 digital/avr/modules/flash/flash.avr.c delete mode 100644 digital/avr/modules/flash/flash.c create mode 100644 digital/avr/modules/flash/flash.host.c delete mode 100644 digital/avr/modules/flash/stub/Makefile.module delete mode 100644 digital/avr/modules/flash/stub/doc/stub.txt delete mode 100644 digital/avr/modules/flash/stub/flash.c delete mode 100644 digital/avr/modules/flash/stub/test/Makefile delete mode 100644 digital/avr/modules/flash/stub/test/test_flash.c (limited to 'digital/avr') diff --git a/digital/avr/modules/flash/Makefile.module b/digital/avr/modules/flash/Makefile.module index 210dcb85..988bbbc7 100644 --- a/digital/avr/modules/flash/Makefile.module +++ b/digital/avr/modules/flash/Makefile.module @@ -1 +1 @@ -flash_SOURCES=flash.c +flash_SOURCES=flash.avr.c flash.host.c diff --git a/digital/avr/modules/flash/flash.avr.c b/digital/avr/modules/flash/flash.avr.c new file mode 100644 index 00000000..7b563bc6 --- /dev/null +++ b/digital/avr/modules/flash/flash.avr.c @@ -0,0 +1,262 @@ +/* flash.c */ +/* {{{ + * + * 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 "flash.h" +#include "modules/proto/proto.h" +#include "modules/spi/spi.h" +#include "modules/utils/utils.h" + +#define FLASH_LOG_PAGE_SIZE 0x80000 +#define FLASH_LOG_BUFFER_SIZE 128 + +/** Flash access. + * The flash contains an address of 21 bits in a range from 0x0-0x1fffff. + * This function shall access the memory directly by the SPI. + * \param addr the address to provide to the flash memory. + */ +void +flash_address (uint32_t addr) +{ + /* The address must be sent */ + spi_send ((addr >> 16) & 0x1f); + spi_send (addr >> 8); + spi_send (addr); +} + +/** Erase the memory. + * \param erase_type the erase type.. + * \param start_addr the start address. + */ +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. */ + spi_send (cmd); + + /* verify if the cmd is the full erase. */ + if (cmd != FLASH_ERASE_FULL) + { + /* Send the start address */ + flash_address (start_addr); + } + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + + while (flash_is_busy()); +} + +/* Send a flash command to the flash memory (only a command). + * \param cmd the command to send. + */ +void +flash_send_command (uint8_t cmd) +{ + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + spi_send (cmd); + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); +} + + +/** Poll the busy bit in the Software Status Register of the flash memory. + * \return the status register. + */ +uint8_t +flash_read_status (void) +{ + uint8_t res; + + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + spi_send (FLASH_RDSR); + res = spi_recv(); + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + + return res; +} + +/** Initialise the flash memory. + * \return true if the flash is present, false otherwise. + */ +uint8_t +flash_init (void) +{ + uint8_t rsp[3]; + + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + AC_FLASH_DDR |= _BV(AC_FLASH_BIT_SS); + + /* send the read-ID instruction. */ + spi_init (SPI_MASTER, SPI_CPOL_FALLING | SPI_CPHA_SETUP, SPI_MSB_FIRST, + SPI_FOSC_DIV16); + + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + spi_send (FLASH_READ_ID); + rsp[0] = spi_recv (); + rsp[1] = spi_recv (); + rsp[2] = spi_recv (); + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + + if (rsp[0] != 0xBF) + return 0; + + proto_send3b ('f',rsp[0], rsp[1], rsp[2]); + + if (flash_status_aai()) + { + flash_send_command (FLASH_WEDI); + } + + /* 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()); + + return 1; +} + +/** Write in the flash byte provided in parameter. + * \param data the buffer to store the data. + */ +void +flash_write (uint32_t addr, uint8_t data) +{ + while (flash_is_busy ()); + flash_send_command (FLASH_WREN); + + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + /* Write instruction. */ + spi_send (FLASH_WRITE); + flash_address (addr); + spi_send (data); + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + + /* Wait for the flash until it is busy */ + while (flash_is_busy()); +} + +/** Read the data at the address provided. + * \return the data read. + */ +uint8_t +flash_read (uint32_t addr) +{ + uint8_t data; + + while (flash_is_busy ()); + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + /* Send the read instruction. */ + spi_send (FLASH_READ); + flash_address (addr); + data = spi_recv (); + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + while (flash_is_busy ()); + return data; +} + +/** Read a data from the flash memory from the address provided and for a + * length of the number of bytes provided. + * \param address at which the data should be read. + * \param buffer the buffer to fill with the read data. + * \param length the length of the data to read. + * + */ +void +flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length) +{ + uint8_t i; + + while (flash_is_busy ()); + AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); + spi_send (FLASH_READ); + flash_address (addr); + for (i = 0; i < length; i++) + { + buffer[i] = spi_recv (); + } + AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); + while (flash_is_busy ()); +} + +/** Write in the flash byte provided in parameter. + * \param addr the address to store the data. + * \param data the array to store. + * \param length the array length + */ +void +flash_write_array (uint32_t addr, uint8_t *data, uint32_t length) +{ + uint32_t i; + + for (i = 0; i < length; i++) + { + flash_write (addr + i, data[i]); + } +} + +int8_t +flash_log (uint8_t size, uint8_t *args) +{ + uint8_t buf[FLASH_LOG_BUFFER_SIZE+1]; + int8_t error = 0x0; + uint32_t addr = 0; + + if (size >= 4) + addr = (((uint32_t) args[1]) << 16) + | (((uint32_t) args[2]) << 8) | args[3]; + + switch (args[0]) + { + case FLASH_CMD_INIT: + error = !flash_init (); + proto_send1b ('s', error ? 0 : 1); + break; + case FLASH_CMD_READ: + if ((size == 5) + && (args[4] <= sizeof(buf))) + { + flash_read_array (addr, buf, args[4]); + proto_send ('r', args[4], buf); + error = 0; + } + else if (size == 4) + { + proto_send1b ('r', flash_read (addr)); + error = 0; + } + else + error = 2; + break; + default: + return 3; + } + + return error; +} diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c deleted file mode 100644 index 7b563bc6..00000000 --- a/digital/avr/modules/flash/flash.c +++ /dev/null @@ -1,262 +0,0 @@ -/* flash.c */ -/* {{{ - * - * 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 "flash.h" -#include "modules/proto/proto.h" -#include "modules/spi/spi.h" -#include "modules/utils/utils.h" - -#define FLASH_LOG_PAGE_SIZE 0x80000 -#define FLASH_LOG_BUFFER_SIZE 128 - -/** Flash access. - * The flash contains an address of 21 bits in a range from 0x0-0x1fffff. - * This function shall access the memory directly by the SPI. - * \param addr the address to provide to the flash memory. - */ -void -flash_address (uint32_t addr) -{ - /* The address must be sent */ - spi_send ((addr >> 16) & 0x1f); - spi_send (addr >> 8); - spi_send (addr); -} - -/** Erase the memory. - * \param erase_type the erase type.. - * \param start_addr the start address. - */ -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. */ - spi_send (cmd); - - /* verify if the cmd is the full erase. */ - if (cmd != FLASH_ERASE_FULL) - { - /* Send the start address */ - flash_address (start_addr); - } - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - - while (flash_is_busy()); -} - -/* Send a flash command to the flash memory (only a command). - * \param cmd the command to send. - */ -void -flash_send_command (uint8_t cmd) -{ - AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); - spi_send (cmd); - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); -} - - -/** Poll the busy bit in the Software Status Register of the flash memory. - * \return the status register. - */ -uint8_t -flash_read_status (void) -{ - uint8_t res; - - AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); - spi_send (FLASH_RDSR); - res = spi_recv(); - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - - return res; -} - -/** Initialise the flash memory. - * \return true if the flash is present, false otherwise. - */ -uint8_t -flash_init (void) -{ - uint8_t rsp[3]; - - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - AC_FLASH_DDR |= _BV(AC_FLASH_BIT_SS); - - /* send the read-ID instruction. */ - spi_init (SPI_MASTER, SPI_CPOL_FALLING | SPI_CPHA_SETUP, SPI_MSB_FIRST, - SPI_FOSC_DIV16); - - AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); - spi_send (FLASH_READ_ID); - rsp[0] = spi_recv (); - rsp[1] = spi_recv (); - rsp[2] = spi_recv (); - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - - if (rsp[0] != 0xBF) - return 0; - - proto_send3b ('f',rsp[0], rsp[1], rsp[2]); - - if (flash_status_aai()) - { - flash_send_command (FLASH_WEDI); - } - - /* 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()); - - return 1; -} - -/** Write in the flash byte provided in parameter. - * \param data the buffer to store the data. - */ -void -flash_write (uint32_t addr, uint8_t data) -{ - while (flash_is_busy ()); - flash_send_command (FLASH_WREN); - - AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); - /* Write instruction. */ - spi_send (FLASH_WRITE); - flash_address (addr); - spi_send (data); - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - - /* Wait for the flash until it is busy */ - while (flash_is_busy()); -} - -/** Read the data at the address provided. - * \return the data read. - */ -uint8_t -flash_read (uint32_t addr) -{ - uint8_t data; - - while (flash_is_busy ()); - AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); - /* Send the read instruction. */ - spi_send (FLASH_READ); - flash_address (addr); - data = spi_recv (); - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - while (flash_is_busy ()); - return data; -} - -/** Read a data from the flash memory from the address provided and for a - * length of the number of bytes provided. - * \param address at which the data should be read. - * \param buffer the buffer to fill with the read data. - * \param length the length of the data to read. - * - */ -void -flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length) -{ - uint8_t i; - - while (flash_is_busy ()); - AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS); - spi_send (FLASH_READ); - flash_address (addr); - for (i = 0; i < length; i++) - { - buffer[i] = spi_recv (); - } - AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS); - while (flash_is_busy ()); -} - -/** Write in the flash byte provided in parameter. - * \param addr the address to store the data. - * \param data the array to store. - * \param length the array length - */ -void -flash_write_array (uint32_t addr, uint8_t *data, uint32_t length) -{ - uint32_t i; - - for (i = 0; i < length; i++) - { - flash_write (addr + i, data[i]); - } -} - -int8_t -flash_log (uint8_t size, uint8_t *args) -{ - uint8_t buf[FLASH_LOG_BUFFER_SIZE+1]; - int8_t error = 0x0; - uint32_t addr = 0; - - if (size >= 4) - addr = (((uint32_t) args[1]) << 16) - | (((uint32_t) args[2]) << 8) | args[3]; - - switch (args[0]) - { - case FLASH_CMD_INIT: - error = !flash_init (); - proto_send1b ('s', error ? 0 : 1); - break; - case FLASH_CMD_READ: - if ((size == 5) - && (args[4] <= sizeof(buf))) - { - flash_read_array (addr, buf, args[4]); - proto_send ('r', args[4], buf); - error = 0; - } - else if (size == 4) - { - proto_send1b ('r', flash_read (addr)); - error = 0; - } - else - error = 2; - break; - default: - return 3; - } - - return error; -} diff --git a/digital/avr/modules/flash/flash.host.c b/digital/avr/modules/flash/flash.host.c new file mode 100644 index 00000000..37abfe05 --- /dev/null +++ b/digital/avr/modules/flash/flash.host.c @@ -0,0 +1,71 @@ +/* flash.host.c */ +/* avr.flash - AVR Flash SPI use. {{{ + * + * Copyright (C) 2009 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 "flash.h" + +void +flash_address (uint32_t addr){} + +void +flash_erase (uint8_t cmd, uint32_t start_addr){} + +void +flash_send_command (uint8_t cmd){} + +uint8_t +flash_read_status (void) +{ + return 0; +} + +/** Initialise the flash memory. + * \return true if the flash is present, false otherwise. + */ +uint8_t +flash_init (void) +{ + return 0; +} + +void +flash_write (uint32_t addr, uint8_t data) {} + +uint8_t +flash_read (uint32_t addr) { return 0xff; } + +void +flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length) +{ + memset (buffer, 0xFF, length); +} + +void +flash_write_array (uint32_t addr, uint8_t *data, uint32_t length) +{} + +int8_t +flash_log (uint8_t size, uint8_t *args) +{ + return 1; +} diff --git a/digital/avr/modules/flash/stub/Makefile.module b/digital/avr/modules/flash/stub/Makefile.module deleted file mode 100644 index f35b0ca8..00000000 --- a/digital/avr/modules/flash/stub/Makefile.module +++ /dev/null @@ -1 +0,0 @@ -flash_stub_SOURCES=flash.c diff --git a/digital/avr/modules/flash/stub/doc/stub.txt b/digital/avr/modules/flash/stub/doc/stub.txt deleted file mode 100644 index 59a42c2f..00000000 --- a/digital/avr/modules/flash/stub/doc/stub.txt +++ /dev/null @@ -1,11 +0,0 @@ -Flash Stub -========== - -The flash stub is a source file which emulate the flash memory of the bot in -a simple text file. - -To use the stub a default file shall be create in the current directory using -touch for example. - -The source stub memory use a file flash.apb, to use it correctly create the -file with this name. diff --git a/digital/avr/modules/flash/stub/flash.c b/digital/avr/modules/flash/stub/flash.c deleted file mode 100644 index d3751502..00000000 --- a/digital/avr/modules/flash/stub/flash.c +++ /dev/null @@ -1,240 +0,0 @@ -/* flash.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 "modules/flash/flash.h" -#include "stdio.h" -#include "string.h" -#include "unistd.h" -#include "sys/types.h" -#include "fcntl.h" -#include "stdlib.h" - -#define FLASH_STUB_DATA_LEN (2 * sizeof (uint8_t)) - -struct flash_t -{ - /* The file descriptor simulating the Flash memory. */ - int file; - /* The flash current status. */ - uint8_t status; -}; -typedef struct flash_t flash_t; - - -/* Global declaration. */ -static flash_t flash_global; - -void -flash_erase (uint8_t cmd, uint32_t start_addr) -{ - const char data = 'F'; - uint8_t res; - - if (flash_global.status) - { - if (cmd == FLASH_ERASE_FULL) - { - uint32_t i; - res = 1; - - lseek (flash_global.file, 0, SEEK_SET); - for (i = 0; i <= (FLASH_ADDRESS_HIGH * 2) && res != 0; i++) - res = write (flash_global.file, &data, sizeof (char)); - } - else - { - uint32_t i; - uint32_t length; - - switch (cmd) - { - case FLASH_ERASE_4K: - length = 4096 * 2; - break; - case FLASH_ERASE_32K: - length = 32768 * 2; - break; - case FLASH_ERASE_64K: - length = 65536 * 2; - break; - default: - length = 0; - } - - res = lseek (flash_global.file, FLASH_PAGE (start_addr), SEEK_SET); - for (i = 0, res = 1; i <= length && res == 1; i++) - res = write (flash_global.file, &data, sizeof (char)); - res = lseek (flash_global.file, FLASH_PAGE (start_addr), SEEK_SET); - } - } -} - -uint8_t -flash_read_status (void) -{ - return flash_global.status; -} - -uint8_t -flash_init (void) -{ - uint8_t res = 0x0; - uint8_t nb_bytes; - - memset (&flash_global, 0, sizeof (flash_t)); - - /* Open the file. */ - flash_global.file = open ("flash.apb", O_CREAT | O_RDWR); - - if (flash_global.file) - { - lseek (flash_global.file, 0, SEEK_SET); - nb_bytes = read (flash_global.file, &res, 1); - lseek (flash_global.file, 0, SEEK_SET); - - flash_global.status = !(flash_global.file == -1); - } - - return flash_global.status; -} - -uint32_t -flash_first_sector (void) -{ - uint32_t addr; - - for (addr = 0x0; - addr < FLASH_ADDRESS_HIGH - && flash_read (addr) != 0xFF; - addr += FLASH_PAGE_SIZE); - - return addr; -} - -/** convert a 4 bits value to the character associated in ASCII. - * \param data the value to convert. - * \return the character corresponding to the data. - */ -char -flash_data_convert_to_char (uint8_t data) -{ - char res = '0'; - - if (data <= 9) - res = data + '0'; - else - res = (data - 10) + 'A'; - - return res; -} - -/** convert a ASCII value to the 4 bytes value. - * \param data the character to convert. - * \return the 4 bits value corresponding to the data. - */ -uint8_t -flash_data_convert_from_char (char data) -{ - uint8_t res = 0x0; - - if ((data >= '0') && (data <= '9')) - res = data - '0'; - else - res = (data + 10) - 'A'; - - return res; -} - -void -flash_write (uint32_t addr, uint8_t data) -{ - char car[2]; - - /* Multiply per two the addr. */ - addr *= 2; - - car[0] = flash_data_convert_to_char (data & 0xF); - car[1] = flash_data_convert_to_char (data >> 4); - - if (flash_global.status - && FLASH_ADDRESS_HIGH > addr) - { - uint8_t nb_bytes; - - /* Jump to the address requested. */ - lseek (flash_global.file, addr, SEEK_SET); - nb_bytes = write (flash_global.file, car, 2 * sizeof (uint8_t)); - - flash_global.status = !(nb_bytes == 0); - } -} - -uint8_t -flash_read (uint32_t addr) -{ - uint8_t res = 0x0; - addr *= 2; - - if (flash_global.status - && FLASH_ADDRESS_HIGH > addr) - { - uint8_t nb_bytes = 0; - uint8_t error_nb; - char car[2]; - - /* Jump to the address requested. */ - lseek (flash_global.file, addr, SEEK_SET); - for (error_nb = 0; (error_nb < 3) && (nb_bytes == 0); error_nb ++) - { - nb_bytes = read (flash_global.file, car, 2 * sizeof (uint8_t)); - } - - res = flash_data_convert_from_char (car[0]); - res |= (flash_data_convert_from_char (car[1]) << 4); - - if (nb_bytes == 2) - return res; - else - return 0xFF; - } - - return res; -} - -void -flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length) -{ - uint32_t i; - - if (buffer != NULL && length != 0) - { - for (i = 0; i < length; i++) - { - buffer[i] = flash_read (addr + i); - } - } -} - -void -flash_write_array (uint32_t addr, uint8_t *data, uint32_t length); diff --git a/digital/avr/modules/flash/stub/test/Makefile b/digital/avr/modules/flash/stub/test/Makefile deleted file mode 100644 index 096fbe3f..00000000 --- a/digital/avr/modules/flash/stub/test/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -BASE = ../../../.. -HOST_PROGS = test_flash - -test_flash_SOURCES = test_flash.c - -MODULES = utils flash/stub -OPTIMIZE = -O2 - -include $(BASE)/make/Makefile.gen - -all: - touch flash.apb diff --git a/digital/avr/modules/flash/stub/test/test_flash.c b/digital/avr/modules/flash/stub/test/test_flash.c deleted file mode 100644 index 4c7cfb16..00000000 --- a/digital/avr/modules/flash/stub/test/test_flash.c +++ /dev/null @@ -1,57 +0,0 @@ -/* test-flash.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 "modules/flash/flash.h" -#include - -int -main (void) -{ - uint8_t status; - uint32_t addr; - uint8_t i; - - status = flash_init (); - printf ("Flash status : %d\n", status); - - flash_erase (FLASH_ERASE_FULL, 0); - - for (i = 0; i < 10; i++) - { - status = flash_init (); - printf ("Flash status : %d\n", status); - - // Get the first sector to begin. - addr = flash_first_sector (); - printf ("First sector : %x\n", addr); - - flash_write (addr, 0xA); - flash_write (addr + 1, 0xB); - - printf ("First data in the flash memory : %x\n", flash_read (addr)); - printf ("Second data in the flash memory : %x\n", flash_read (addr + 1)); - } - - return 0; -} diff --git a/digital/avr/modules/flash/test/Makefile b/digital/avr/modules/flash/test/Makefile index 33ad8001..0201fdff 100644 --- a/digital/avr/modules/flash/test/Makefile +++ b/digital/avr/modules/flash/test/Makefile @@ -1,8 +1,12 @@ BASE = ../../.. -AVR_PROGS = test-flash flash_dump + +HOST_PROGS = test_flash +test_flash_SOURCES = test-flash.c + +AVR_PROGS = test-flash flash-dump test-flash_SOURCES = test-flash.c -flash_dump_SOURCES = flash-dump.c +flash-dump_SOURCES = flash-dump.c MODULES = utils spi flash proto uart CONFIGFILE = avrconfig.h diff --git a/digital/avr/modules/flash/test/test-flash.c b/digital/avr/modules/flash/test/test-flash.c index a504d6c1..461096c3 100644 --- a/digital/avr/modules/flash/test/test-flash.c +++ b/digital/avr/modules/flash/test/test-flash.c @@ -86,16 +86,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) * - 1b: byte. */ flash_write (addr, args[3]); break; - case c ('p', 0): - /* Find the next page to write. */ - addr = flash_first_sector (); - proto_send3b ('p', addr >> 16, addr >> 8, addr); - break; - case c ('c', 3): - /* Compute the next page. */ - addr = FLASH_PAGE (addr); - proto_send3b ('c', addr >> 16, addr >> 8, addr); - break; default: if (cmd == 'w' && size > 4) { -- cgit v1.2.3