BeRTOS
Functions
flash25.c File Reference

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 KFileflash25_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.

Detailed Description

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.

Author:
Daniele Basile <asterix@develer.com>

Definition in file flash25.c.


Function Documentation

void flash25_chipErase ( Flash25 fd)

Chip erase function.

Erase all sector of serial flash memory.

Note:
This operation could take a while.

Definition at line 337 of file flash25.c.

static int flash25_close ( UNUSED_ARG(struct KFile *, fd)  ) [static]

Close a serial memory interface.

For serial memory this funtion do nothing, and return always 0.

Definition at line 152 of file flash25.c.

static bool flash25_pin_init ( Flash25 fd) [static]

flash25 init function.

This function init a comunication channel and try to read manufacturer id of serial memory, then check if is equal to selected type.

Definition at line 101 of file flash25.c.

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.

Returns:
the number of bytes read.

Definition at line 169 of file flash25.c.

static KFile* flash25_reopen ( struct KFile _fd) [static]

Reopen a serial memory interface.

For serial memory this function reinit only the size and seek_pos in kfile stucture. Return a kfile pointer, after assert check.

Definition at line 135 of file flash25.c.

void flash25_sectorErase ( Flash25 fd,
Flash25Sector  sector 
)

Sector erase function.

Erase a select sector of serial flash memory.

Note:
A sector size is FLASH25_SECTOR_SIZE. This operation could take a while.

Definition at line 291 of file flash25.c.

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.

Note:
: WARNING: you could write only on erased memory section! Each write time you could write max a memory page size, because if you write more than memory page size the address roll over to first byte of page.
Returns:
the number of bytes write.

Definition at line 219 of file flash25.c.