From 3a426a0b8570e22a6a900b62b7f0b6e8237d3c6d Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Tue, 10 Jun 2008 23:08:47 +0200 Subject: flash: Cleaning flash source and header. --- digital/avr/modules/flash/flash.c | 60 +++++++++++--------------------------- digital/avr/modules/flash/flash.h | 61 ++++++++++----------------------------- 2 files changed, 32 insertions(+), 89 deletions(-) (limited to 'digital/avr') diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c index ebde71f1..cee08e31 100644 --- a/digital/avr/modules/flash/flash.c +++ b/digital/avr/modules/flash/flash.c @@ -71,6 +71,18 @@ flash_erase (uint8_t cmd, uint32_t start_addr) 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. */ @@ -131,7 +143,9 @@ flash_init (void) /* Read the flash status. */ proto_send1b ('s', flash_read_status()); - /* TODO: disable flash usage if no flash is found? */ + /* If flash read status id not correct disable the flash */ + if (flash_read_status()) + flash_global.status = FLASH_DISABLE; /* Search for the next address to start writting. */ @@ -151,16 +165,6 @@ flash_init (void) return &flash_global; } -/* 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); -} /** Write in the flash byte provided in parameter. * \param data the buffer to store the data. @@ -204,6 +208,8 @@ flash_read (uint32_t addr) * \param address at wich the data should be read. * \param buffer the buffer to fill with the read data. * \param length the length of the data to read. + * + * TODO find why the read_array does not work. */ void flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length) @@ -247,35 +253,3 @@ flash_write_array (uint32_t addr, uint8_t *data, uint32_t length) } } -/** Read the memory from the address automaticaly managed, the offset of the - * data shall be provided to get the data. - * \param offset the offset from the current address managed. - * \return data read from the memory. - */ -uint8_t -flash_read_managed (uint32_t offset); - -/** Read an array of data from the memory starting at the address less the - * offset provided in parameters. The data read will be stored in the buffer - * provided in memory too. The buffer shall have at list the length of the - * offset provided. - * \param offset the offset of the current position to read the data. - * \param buffer the buffer to store the data. - */ -void -flash_read_managed_array (uint32_t offset, uint8_t *buffer); - -/** Write a data with a managed array. - * \param data to store in the memory. - */ -void -flash_write_managed (uint8_t data); - -/** Write an array of data to the flash memory. The length of the array shall - * be provided. - * \param buffer the buffer containing the data to write. - * \param length the data length to write. - */ -void -flash_write_managed_array (uint8_t *buffer, uint8_t length); - diff --git a/digital/avr/modules/flash/flash.h b/digital/avr/modules/flash/flash.h index 39fd366c..61fec8f5 100644 --- a/digital/avr/modules/flash/flash.h +++ b/digital/avr/modules/flash/flash.h @@ -51,19 +51,22 @@ #define FLASH_TBP_US 10 +enum flash_statu_t +{ + FLASH_DISABLE, + FLASH_ENABLE, + FLASH_ASSERT +}; + struct flash_t { /** Current Address in the flash memory. */ uint32_t addr; + /** Indicate the status of the flash memory. */ + bool flash_status; }; typedef struct flash_t flash_t; -/** Initialise the flsah memory. - * \return the flash context usefull to access to the addr for debug. - */ -flash_t * -flash_init (void); - /** 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. @@ -72,14 +75,6 @@ flash_init (void); void flash_address (uint32_t addr); -/** Flash init page. - * Initialise the page by write an value different of 0xFF to indicate that - * the page is use. - * \param addr - */ -void -flash_init_page (uint32_t addr); - /** Erase the memory. * \param erase_type the erase type.. * \param start_addr the start address. @@ -117,6 +112,12 @@ flash_status_aai (void) return flash_read_status () >> 6; } +/** Initialise the flsah memory. + * \return the flash context usefull to access to the addr for debug. + */ +flash_t * +flash_init (void); + /** Write in the flash byte provided in parameter. * \param data the buffer to store the data. */ @@ -147,36 +148,4 @@ flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length); void flash_write_array (uint32_t addr, uint8_t *data, uint32_t length); -/** Read the memory from the address automaticaly managed, the offset of the - * data shall be provided to get the data. - * \param offset the offset from the current address managed. - * \return data read from the memory. - */ -uint8_t -flash_read_managed (uint32_t offset); - -/** Read an array of data from the memory starting at the address less the - * offset provided in parameters. The data read will be stored in the buffer - * provided in memory too. The buffer shall have at list the length of the - * offset provided. - * \param offset the offset of the current position to read the data. - * \param buffer the buffer to store the data. - */ -void -flash_read_managed_array (uint32_t offset, uint8_t *buffer); - -/** Write a data with a managed array. - * \param data to store in the memory. - */ -void -flash_write_managed (uint8_t data); - -/** Write an array of data to the flash memory. The length of the array shall - * be provided. - * \param buffer the buffer containing the data to write. - * \param length the data length to write. - */ -void -flash_write_managed_array (uint8_t *buffer, uint8_t length); - #endif /* flash_h */ -- cgit v1.2.3