summaryrefslogtreecommitdiff
path: root/digital/avr/modules/flash/flash.avr.c
diff options
context:
space:
mode:
Diffstat (limited to 'digital/avr/modules/flash/flash.avr.c')
-rw-r--r--digital/avr/modules/flash/flash.avr.c139
1 files changed, 11 insertions, 128 deletions
diff --git a/digital/avr/modules/flash/flash.avr.c b/digital/avr/modules/flash/flash.avr.c
index bd053524..bcc81fa6 100644
--- a/digital/avr/modules/flash/flash.avr.c
+++ b/digital/avr/modules/flash/flash.avr.c
@@ -23,14 +23,14 @@
*
* }}} */
#include "flash.h"
-#include "modules/proto/proto.h"
+#include "flash_sst.h"
#include "modules/spi/spi.h"
-#include "modules/utils/utils.h"
uint8_t
flash_init (void)
{
uint8_t rsp[3];
+ uint8_t res;
AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS);
AC_FLASH_DDR |= _BV(AC_FLASH_BIT_SS);
@@ -40,138 +40,21 @@ flash_init (void)
SPI_FOSC_DIV16);
FLASH_CS_ENABLE;
- spi_send (FLASH_READ_ID);
+ spi_send (FLASH_SST_CMD_READ_ID);
rsp[0] = spi_recv ();
rsp[1] = spi_recv ();
rsp[2] = spi_recv ();
FLASH_CS_DISABLE;
- if (rsp[0] != 0xBF)
- return 0;
-
- if (flash_status_aai())
+ switch (rsp[0])
{
- flash_send_command (FLASH_WEDI);
+ case FLASH_SST_MANUFACTURER_ID:
+ flash_sst_init ();
+ flash_init_sst ();
+ res = 1;
+ break;
+ default:
+ res = 0;
}
-
- /* Enables the flash to be writable. */
- flash_send_command (FLASH_WREN);
-
- FLASH_CS_ENABLE;
- spi_send (FLASH_WRSR);
- spi_send (0);
- FLASH_CS_DISABLE;
-
- return 1;
-}
-
-void
-flash_address (uint32_t addr)
-{
- /* The address must be sent */
- spi_send ((addr >> 16) & 0x1f);
- spi_send (addr >> 8);
- spi_send (addr);
-}
-
-void
-flash_erase (uint8_t cmd, uint32_t start_addr)
-{
- flash_send_command (FLASH_WREN);
-
- FLASH_CS_ENABLE;
- /* 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);
- }
- FLASH_CS_DISABLE;
-
- while (flash_is_busy());
-}
-
-void
-flash_send_command (flash_cmd_t cmd)
-{
- FLASH_CS_ENABLE;
- spi_send (cmd);
- FLASH_CS_DISABLE;
-}
-
-uint8_t
-flash_read_status (void)
-{
- uint8_t res;
-
- FLASH_CS_ENABLE;
- spi_send (FLASH_RDSR);
- res = spi_recv();
- FLASH_CS_DISABLE;
-
return res;
}
-
-void
-flash_write (uint32_t addr, uint8_t data)
-{
- while (flash_is_busy ());
- flash_send_command (FLASH_WREN);
-
- FLASH_CS_ENABLE;
- /* Write instruction. */
- spi_send (FLASH_WRITE);
- flash_address (addr);
- spi_send (data);
- FLASH_CS_DISABLE;
-
- /* Wait for the flash until it is busy */
- while (flash_is_busy());
-}
-
-uint8_t
-flash_read (uint32_t addr)
-{
- uint8_t data;
-
- while (flash_is_busy ());
- FLASH_CS_ENABLE;
- /* Send the read instruction. */
- spi_send (FLASH_READ);
- flash_address (addr);
- data = spi_recv ();
- FLASH_CS_DISABLE;
- while (flash_is_busy ());
- return data;
-}
-
-void
-flash_read_array (uint32_t addr, uint8_t *buffer, uint32_t length)
-{
- uint8_t i;
-
- while (flash_is_busy ());
- FLASH_CS_ENABLE;
- spi_send (FLASH_READ);
- flash_address (addr);
- for (i = 0; i < length; i++)
- {
- buffer[i] = spi_recv ();
- }
- FLASH_CS_DISABLE;
- while (flash_is_busy ());
-}
-
-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]);
- }
-}