BeRTOS
Functions | Variables
dataflash.c File Reference

Function library for dataflash AT45DB family (implementation). More...

#include "dataflash.h"
#include "cfg/cfg_dataflash.h"
#include <cfg/macros.h>
#include <cfg/debug.h>
#include <cfg/module.h>
#include <cfg/log.h>
#include <drv/timer.h>
#include <fs/battfs.h>
#include <io/kfile.h>
#include <cpu/power.h>
#include <string.h>

Go to the source code of this file.

Functions

void CS_TOGGLE (DataFlash *fd)
 Macro that toggle CS of dataflash.
static void send_cmd (DataFlash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode)
 Send a generic command to dataflash memory.
static void dataflash_reset (DataFlash *fd)
 Reset dataflash memory function.
static uint8_t dataflash_stat (DataFlash *fd)
 Read status register of dataflah memory.
static uint8_t dataflash_cmd (DataFlash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode)
 Send one command to data flash memory, and return status register value.
static void dataflash_readBlock (DataFlash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, uint8_t *block, dataflash_size_t len)
 Read len bytes from main data flash memory or buffer data flash memory, and put it in *block.
static void dataflash_writeBlock (DataFlash *fd, dataflash_offset_t offset, const uint8_t *block, dataflash_size_t len)
 Write len bytes in dataflash memory buffer.
static void dataflash_loadPage (DataFlash *fd, dataflash_page_t page_addr)
 Load selected page from dataflash memory to buffer.
static int dataflash_flush (KFile *_fd)
 Flush select page (stored in buffer) in data flash main memory page.
static int dataflash_close (struct KFile *_fd)
 Close file fd.
static KFiledataflash_reopen (KFile *_fd)
 Reopen dataflash file fd.
static size_t dataflash_read (struct KFile *_fd, void *buf, size_t size)
 Read in buf size bytes from dataflash memmory.
static size_t dataflash_write (struct KFile *_fd, const void *_buf, size_t size)
 Write _buf in dataflash memory.
bool dataflash_init (DataFlash *fd, KFile *ch, DataflashType dev, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset)
 Dataflash init function.

Variables

static const DataflashInfo mem_info []
 Array used to describe dataflash memory devices currently supported.

Detailed Description

Function library for dataflash AT45DB family (implementation).

Author:
Daniele Basile <asterix@develer.com>
Francesco Sacchi <batt@develer.com>

Definition in file dataflash.c.


Function Documentation

void CS_TOGGLE ( DataFlash fd) [inline]

Macro that toggle CS of dataflash.

Note:
This is equivalent to fd->setCS(false) immediately followed by fd->setCS(true).

Definition at line 106 of file dataflash.c.

bool dataflash_init ( DataFlash fd,
KFile ch,
DataflashType  dev,
dataflash_setCS_t *  setCS,
dataflash_setReset_t *  setReset 
)

Dataflash init function.

This function initialize fd with SPI channel ch and test if data flash memory density is the same specified by device dev. setCS is a callback used to set/reset CS line. setReset is a callback used to set/reset the dataflash (can be NULL if reset is unconnected)

Returns:
true if ok, false if memory density read from dataflash is not compliant with the configured one.

Definition at line 545 of file dataflash.c.

static size_t dataflash_read ( struct KFile _fd,
void *  buf,
size_t  size 
) [static]

Read in buf size bytes from dataflash memmory.

Note:
For reading data flash memory, we check flag page_dirty, if is true (that mean we have written a byte in buffer memory) we flush current page in main memory and then read from memory, else we read byte directly from data flash main memory.
Returns:
the number of bytes read.

Definition at line 429 of file dataflash.c.

static void dataflash_reset ( DataFlash fd) [static]

Reset dataflash memory function.

If fd->setReset function is not NULL, this function resets data flash memory with one pulse reset long about 10usec.

Definition at line 166 of file dataflash.c.

static size_t dataflash_write ( struct KFile _fd,
const void *  _buf,
size_t  size 
) [static]

Write _buf in dataflash memory.

Note:
For writing _buf in dataflash memory, we must first write in buffer data flash memory. At the end of write, we can put page in dataflash main memory. If we write in two contiguous pages, we put in main memory current page and then reload the page which we want to write.
Returns:
the number of bytes write.

Definition at line 479 of file dataflash.c.

static void dataflash_writeBlock ( DataFlash fd,
dataflash_offset_t  offset,
const uint8_t *  block,
dataflash_size_t  len 
) [static]

Write len bytes in dataflash memory buffer.

Note:
Is not possible to write directly in dataflash main memory. To perform a write in main memory you must first write in dataflash buffer memory and then send a command to write the page in main memory.

Definition at line 258 of file dataflash.c.

static void send_cmd ( DataFlash fd,
dataflash_page_t  page_addr,
dataflash_offset_t  byte_addr,
DataFlashOpcode  opcode 
) [static]

Send a generic command to dataflash memory.

This function send only 4 byte: opcode, page address and byte address.

Definition at line 117 of file dataflash.c.