summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-01-12 23:51:10 +0100
committerNélio Laranjeiro2010-01-12 23:51:10 +0100
commit0f465e1ba9bef871ca685ea24565e724cc24e207 (patch)
tree276eb32227af098192dbf8c47828b0de65463f2b /digital
parent0be48d417e4a32c4815cbe37be57f5639a6cddc4 (diff)
digital/avr/modules/flash: move init function
Diffstat (limited to 'digital')
-rw-r--r--digital/avr/modules/flash/flash.avr.c82
1 files changed, 41 insertions, 41 deletions
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.
*/