Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
Functions
logical.c File Reference
#include <flash.h>
#include <string.h>
#include <memory.h>

Functions

devcall logicalRead (struct flash *flash, uchar *buffer, ulong block)
 
devcall logicalWrite (struct flash *flash, uchar *buffer, ulong block)
 
struct flash_block logicalMap (struct flash *flash, ulong block)
 

Detailed Description

This provides a more proper interface between driver calls and the physical layer of flash. It is possible to split the entire flash device into logical blocks of n bytes and this file provides the mappings from physical address to logical block.

Function Documentation

struct flash_block logicalMap ( struct flash *  flash,
ulong  block 
)

Given a flash structure and a logical block, this method will discover the physical erase-block (and region) of that block. Once the physical mapping is found it will return an incomplete flash_block structure with the region and erase-block filled in.

Parameters
*flashflash device to discover on.
blocklogical block to find.
Returns
flash_block structure with start_pos and size
devcall logicalRead ( struct flash *  flash,
uchar *  buffer,
ulong  block 
)

With a logical block address, read in the contents of the block into the buffer. This will check if the erase-block is already in memory and if so simply read from the cached copy, if it is not read it into memory and read the specified block. If there is no more room in memory to store an erase-block it will automatically write to the oldest erase-block to flash and read in the requested block.

Parameters
*flashflash device to read on.
*bufferbuffer to read into.
blockblock to read on device.
Returns
number of bytes read or SYSERR on failure
devcall logicalWrite ( struct flash *  flash,
uchar *  buffer,
ulong  block 
)

Translate a logical block number to a physical portion of flash and write the data. This function will check if the erase-block is in memory and store changes to the memory location to prevent too many writes to flash. If no more room is available it will evict the oldest erase-block and write it to flash.

Parameters
*flashflash device to write to
*bufferbuffer holding new data
blockblock to write to device
Returns
number of bytes written or SYSERR on failure