|
@@ -1,6 +1,6 @@
|
|
|
-//w25x20cl.c
|
|
|
+//xflash.c
|
|
|
|
|
|
-#include "w25x20cl.h"
|
|
|
+#include "xflash.h"
|
|
|
#include <avr/io.h>
|
|
|
#include <avr/pgmspace.h>
|
|
|
#include "spi.h"
|
|
@@ -31,8 +31,8 @@
|
|
|
#define _CMD_JEDEC_ID 0x9f
|
|
|
#define _CMD_RD_UID 0x4b
|
|
|
|
|
|
-#define _CS_LOW() WRITE(W25X20CL_PIN_CS, 0)
|
|
|
-#define _CS_HIGH() WRITE(W25X20CL_PIN_CS, 1)
|
|
|
+#define _CS_LOW() WRITE(XFLASH_PIN_CS, 0)
|
|
|
+#define _CS_HIGH() WRITE(XFLASH_PIN_CS, 1)
|
|
|
|
|
|
//#define _SPI_TX swspi_tx
|
|
|
//#define _SPI_RX swspi_rx
|
|
@@ -40,33 +40,33 @@
|
|
|
#define _SPI_RX() spi_txrx(0xff)
|
|
|
|
|
|
|
|
|
-int w25x20cl_mfrid_devid(void);
|
|
|
+int xflash_mfrid_devid(void);
|
|
|
|
|
|
|
|
|
-int8_t w25x20cl_init(void)
|
|
|
+int8_t xflash_init(void)
|
|
|
{
|
|
|
_CS_HIGH();
|
|
|
- SET_OUTPUT(W25X20CL_PIN_CS);
|
|
|
- W25X20CL_SPI_ENTER();
|
|
|
- if (!w25x20cl_mfrid_devid()) return 0;
|
|
|
+ SET_OUTPUT(XFLASH_PIN_CS);
|
|
|
+ XFLASH_SPI_ENTER();
|
|
|
+ if (!xflash_mfrid_devid()) return 0;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_enable_wr(void)
|
|
|
+void xflash_enable_wr(void)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_ENABLE_WR); // send command 0x06
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_disable_wr(void)
|
|
|
+void xflash_disable_wr(void)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_DISABLE_WR); // send command 0x04
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-uint8_t w25x20cl_rd_status_reg(void)
|
|
|
+uint8_t xflash_rd_status_reg(void)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_RD_STATUS_REG); // send command 0x90
|
|
@@ -75,6 +75,7 @@ uint8_t w25x20cl_rd_status_reg(void)
|
|
|
return val;
|
|
|
}
|
|
|
|
|
|
+#if 0
|
|
|
void w25x20cl_wr_status_reg(uint8_t val)
|
|
|
{
|
|
|
_CS_LOW();
|
|
@@ -82,8 +83,9 @@ void w25x20cl_wr_status_reg(uint8_t val)
|
|
|
_SPI_TX(val); // send value
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
-void w25x20cl_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
+void xflash_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_RD_DATA); // send command 0x03
|
|
@@ -95,7 +97,7 @@ void w25x20cl_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_page_program(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
+void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
|
|
@@ -107,7 +109,7 @@ void w25x20cl_page_program(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
+void xflash_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_PAGE_PROGRAM); // send command 0x02
|
|
@@ -119,7 +121,7 @@ void w25x20cl_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt)
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_erase(uint8_t cmd, uint32_t addr)
|
|
|
+void xflash_erase(uint8_t cmd, uint32_t addr)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(cmd); // send command 0x20
|
|
@@ -129,22 +131,22 @@ void w25x20cl_erase(uint8_t cmd, uint32_t addr)
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_sector_erase(uint32_t addr)
|
|
|
+void xflash_sector_erase(uint32_t addr)
|
|
|
{
|
|
|
- return w25x20cl_erase(_CMD_SECTOR_ERASE, addr);
|
|
|
+ return xflash_erase(_CMD_SECTOR_ERASE, addr);
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_block32_erase(uint32_t addr)
|
|
|
+void xflash_block32_erase(uint32_t addr)
|
|
|
{
|
|
|
- return w25x20cl_erase(_CMD_BLOCK32_ERASE, addr);
|
|
|
+ return xflash_erase(_CMD_BLOCK32_ERASE, addr);
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_block64_erase(uint32_t addr)
|
|
|
+void xflash_block64_erase(uint32_t addr)
|
|
|
{
|
|
|
- return w25x20cl_erase(_CMD_BLOCK64_ERASE, addr);
|
|
|
+ return xflash_erase(_CMD_BLOCK64_ERASE, addr);
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_chip_erase(void)
|
|
|
+void xflash_chip_erase(void)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_CHIP_ERASE); // send command 0xc7
|
|
@@ -152,7 +154,7 @@ void w25x20cl_chip_erase(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void w25x20cl_rd_uid(uint8_t* uid)
|
|
|
+void xflash_rd_uid(uint8_t* uid)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_RD_UID); // send command 0x4b
|
|
@@ -165,20 +167,20 @@ void w25x20cl_rd_uid(uint8_t* uid)
|
|
|
_CS_HIGH();
|
|
|
}
|
|
|
|
|
|
-int w25x20cl_mfrid_devid(void)
|
|
|
+int xflash_mfrid_devid(void)
|
|
|
{
|
|
|
_CS_LOW();
|
|
|
_SPI_TX(_CMD_MFRID_DEVID); // send command 0x90
|
|
|
uint8_t cnt = 3; // 3 address bytes
|
|
|
while (cnt--) // send address bytes
|
|
|
_SPI_TX(0x00);
|
|
|
- uint8_t w25x20cl_mfrid = _SPI_RX(); // receive mfrid
|
|
|
- uint8_t w25x20cl_devid = _SPI_RX(); // receive devid
|
|
|
+ uint8_t xflash_mfrid = _SPI_RX(); // receive mfrid
|
|
|
+ uint8_t xflash_devid = _SPI_RX(); // receive devid
|
|
|
_CS_HIGH();
|
|
|
- return ((w25x20cl_mfrid == _MFRID) && (w25x20cl_devid == _DEVID));
|
|
|
+ return ((xflash_mfrid == _MFRID) && (xflash_devid == _DEVID));
|
|
|
}
|
|
|
|
|
|
-void w25x20cl_wait_busy(void)
|
|
|
+void xflash_wait_busy(void)
|
|
|
{
|
|
|
- while (w25x20cl_rd_status_reg() & W25X20CL_STATUS_BUSY) ;
|
|
|
+ while (xflash_rd_status_reg() & XFLASH_STATUS_BUSY) ;
|
|
|
}
|