BeRTOS
|
Function library for serial Flash memory. More...
#include "hw/hw_spi.h"
#include <cfg/macros.h>
#include <cfg/debug.h>
#include <drv/timer.h>
#include <drv/flash25.h>
#include <io/kfile.h>
#include <cpu/power.h>
Go to the source code of this file.
Functions | |
static void | flash25_waitReady (Flash25 *fd) |
Wait until flash memory is ready. | |
static void | flash25_sendCmd (Flash25 *fd, Flash25Opcode cmd) |
Send a single command to serial flash memory. | |
static bool | flash25_pin_init (Flash25 *fd) |
flash25 init function. | |
static KFile * | flash25_reopen (struct KFile *_fd) |
Reopen a serial memory interface. | |
static int | flash25_close (UNUSED_ARG(struct KFile *, fd)) |
Close a serial memory interface. | |
static size_t | flash25_read (struct KFile *_fd, void *buf, size_t size) |
Read _buf lenght size byte from serial flash memmory. | |
static size_t | flash25_write (struct KFile *_fd, const void *_buf, size_t size) |
Write _buf in serial flash memory. | |
void | flash25_sectorErase (Flash25 *fd, Flash25Sector sector) |
Sector erase function. | |
void | flash25_chipErase (Flash25 *fd) |
Chip erase function. | |
void | flash25_init (Flash25 *fd, KFile *ch) |
Init data flash memory interface. |
Function library for serial Flash memory.
Module provide a kfile interface, that ensure an abstraction from comunication channel and give a standard interface. Typicaly this kind of memory use an SPI bus, but you should use another comunication channel you have defined.
Definition in file flash25.c.
void flash25_chipErase | ( | Flash25 * | fd | ) |
static int flash25_close | ( | UNUSED_ARG(struct KFile *, fd) | ) | [static] |
static bool flash25_pin_init | ( | Flash25 * | fd | ) | [static] |
static size_t flash25_read | ( | struct KFile * | _fd, |
void * | buf, | ||
size_t | size | ||
) | [static] |
Read _buf lenght size byte from serial flash memmory.
For read in serial flash memory we enble cs pin and send one byte of read opcode, and then 3 byte of address of memory cell we want to read. After the last byte of address we can read data from so pin.
void flash25_sectorErase | ( | Flash25 * | fd, |
Flash25Sector | sector | ||
) |
static size_t flash25_write | ( | struct KFile * | _fd, |
const void * | _buf, | ||
size_t | size | ||
) | [static] |
Write _buf in serial flash memory.
Before to write data into flash we must enable memory writing. To do this we send a WRE command opcode. After this command the flash is ready to be write, and so we send a PROGRAM opcode followed to 3 byte of address memory, at the end of last address byte we can send the data. When we finish to send all data, we disable cs and flash write received data bytes on its memory.