From 0f465e1ba9bef871ca685ea24565e724cc24e207 Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Tue, 12 Jan 2010 23:51:10 +0100 Subject: digital/avr/modules/flash: move init function --- digital/avr/modules/flash/flash.avr.c | 82 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'digital') diff --git a/digital/avr/modules/flash/flash.avr.c b/digital/avr/modules/flash/flash.avr.c index ef445918..9f944659 100644 --- a/digital/avr/modules/flash/flash.avr.c +++ b/digital/avr/modules/flash/flash.avr.c @@ -27,6 +27,47 @@ #include "modules/spi/spi.h" #include "modules/utils/utils.h" +/** 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; + + 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); + + return 1; +} + /** 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. @@ -93,47 +134,6 @@ flash_read_status (void) 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; - - 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); - - return 1; -} - /** Write in the flash byte provided in parameter. * \param data the buffer to store the data. */ -- cgit v1.2.3