|
| fs_spi_ProgramPage| Summary | |
#include <file_config.h>
int fs_spi_ProgramPage (
U32 adr, /* data page address */
U32 size, /* size of the data page */
U8 *buf); /* buffer containing the data */
| | Description | | The fs_spi_ProgramPage is a user-provided routine that programs the contents of buf into SPI Data Flash memory starting at address adr for size bytes. The adr must be 4-byte aligned, but buf may be not. The buffer size must be a multiple of 4. The fs_spi_ProgramPage function is part of RL-FlashFS. The prototype is defined in file_config.h. You can customize the function in fs_spi_flashprg.c. | | Return Value | | The fs_spi_ProgramPage function returns a value of 0 if successful or a value of 1 if unsuccessful. | | See Also | | finit, fs_spi_EraseSector, fs_spi_Init, fs_spi_ReadData | | Example | |
int fs_spi_ProgramPage (U32 adr, U32 sz, U8 *buf) {
U32 cnt;
U8 sr;
while (sz) {
cnt = PAGE_SZ - (adr & (PAGE_SZ - 1));
if (cnt > sz) cnt = sz;
/* Write Enable */
spi_ss (0);
spi_send (SPI_WRITE_ENABLE);
spi_ss (1);
/* Program Page */
spi_ss (0);
spi_send (SPI_PAGE_PROGRAM);
spi_send ((U8)(adr >> 16));
spi_send ((U8)(adr >> 8));
spi_send ((U8)(adr >> 0));
adr += cnt;
sz -= cnt;
while (cnt--) {
spi_send (*buf++);
}
spi_ss (1);
/* Wait until done */
spi_ss (0);
spi_send (SPI_READ_SR);
do {
sr = spi_send (0xFF);
} while (sr & SR_WIP);
spi_ss (1);
/* Check for Error */
if (sr & SR_P_FAIL) {
spi_ss (0);
spi_send (SPI_CLEAR_SR_FLAGS);
spi_ss (1);
return (1);
}
}
return (0);
}
|
|
|