summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/flash/flash.avr.c
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-01-12 23:51:26 +0100
committerNélio Laranjeiro2010-01-12 23:51:26 +0100
commit32ed04c7e1435b8019974ac0671a6896e2786f31 (patch)
treed3e9300a81c32838a938d4b6ec827611f8871b46 /digital/avr/modules/flash/flash.avr.c
parent0f278970130103b1df4a2b308359943520f10987 (diff)
digital/avr/modules/flash: flash sst driver
Modify flash source code to initialise the SPI interface and detect the flash type using JDEC. Once the JDEC is read the flash driver initialise functions pointers to pilot the flash memory. The final objective is to have several flash support.
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]);
- }
-}