EVE 1.0
SPI-based memory driver
Collaboration diagram for SPI-based memory driver:

Data Structures

struct  spi_memory_t
 
struct  spi_memory_data_buffer_header
 

Macros

#define SPI_MEMORY_HINT_GENERIC   0
 
#define SPI_MEMORY_HINT_GENERIC_SRAM   1
 
#define SPI_MEMORY_DATA_BUFFER_COMMAND_SIZE   4
 
#define SPI_MEMORY_DATA_BUFFER_TYPE(type, size)
 

Typedefs

typedef void(* spi_memory_completion_callback_t) (const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *BufferHeader)
 

Functions

 SPI_MEMORY_DATA_BUFFER_TYPE (spi_memory_generic_buffer_t, 0)
 

Functions called from application programs

bool SpiMemoryInit (const struct spi_memory_t *Memory)
 Name: SpiMemoryInit
Waits for power on and then release SPI memory from deep powerdown. KŲ!! ???????????? Called from main program level. More...
 
bool SpiMemoryDisable (const struct spi_memory_t *Memory)
 Name: SpiMemoryDisable
Sets SPI memory in deep powerdown. Called from main program level. More...
 
bool SpiMemorySetWriteProtection (const struct spi_memory_t *Memory, enum spi_memory_protection_t Protection)
 Name: SpiMemorySetWriteProtection
Sets write protection for SPI memory and waits for completion. Called from main program level. More...
 
bool SpiMemoryEraseSectorAsync (const struct spi_memory_t *Memory, uint32_t SectorIndex)
 Name: SpiMemoryEraseSectorAsync
Begines erasing given sector in SPI memory. Called from main program level. At function return SPI transfer is completed; erase is started, but not completed. Caller code should use SpiMemoryIsBusy to wait for the completion. More...
 
bool SpiMemoryEraseSector (const struct spi_memory_t *Memory, uint32_t SectorIndex)
 Name: SpiMemoryEraseSector
Erases given sector in SPI memory and waits for completion. Called from main program level. More...
 
bool SpiMemoryEraseBlockAsync (const struct spi_memory_t *Memory, uint32_t BlockIndex)
 Name: SpiMemoryEraseBlockAsync
Begines erasing given block in SPI memory. Called from main program level. At function return SPI transfer is completed; erase is started, but not completed. Caller code should use SpiMemoryIsBusy to wait for the completion. More...
 
bool SpiMemoryEraseBlock (const struct spi_memory_t *Memory, uint32_t BlockIndex)
 Name: SpiMemoryEraseBlock
Erases given block in SPI memory and waits for completion. Called from main program level. More...
 
bool SpiMemoryEraseAsync (const struct spi_memory_t *Memory)
 Name: SpiMemoryEraseAsync
Begines erasing the whole SPI memory. Called from main program level. At function return SPI transfer is completed; erase is started, but not completed. Caller code should use SpiMemoryIsBusy to wait for the completion. More...
 
bool SpiMemoryErase (const struct spi_memory_t *Memory)
 Name: SpiMemoryErase
Erases the whole SPI memory and waits for completion. Called from main program level. More...
 
bool SpiMemoryReadAsync (const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *DstBuffer, uint32_t SrcAddress, uint32_t ByteCount, spi_memory_completion_callback_t Callback)
 Name: SpiMemoryReadAsync
Reads bytes from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called. More...
 
bool SpiMemoryRead (const struct spi_memory_t *Memory, void *DstBuffer, uint32_t SrcAddress, uint32_t ByteCount)
 Name: SpiMemoryRead
Reads bytes from SPI memory to DstBuffer. Called from main program level. More...
 
static bool SpiMemoryReadPageAsync (const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *DstBuffer, uint32_t PageIndex, spi_memory_completion_callback_t Callback)
 Name: SpiMemoryReadPageAsync
Reads the page PageIndex from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called. More...
 
static bool SpiMemoryReadPage (const struct spi_memory_t *Memory, void *DstBuffer, uint32_t PageIndex)
 Name: SpiMemoryReadPage
Reads the page PageIndex from SPI memory to DstBuffer. Called from main program level. More...
 
static bool SpiMemoryReadPageWithOffsetAsync (const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *DstBuffer, uint32_t PageIndex, uint32_t PageOffset, uint32_t ByteCount, spi_memory_completion_callback_t Callback)
 Name: SpiMemoryReadPageWithOffsetAsync
Reads the page PageIndex with offset from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called. More...
 
static bool SpiMemoryReadPageWithOffset (const struct spi_memory_t *Memory, void *DstBuffer, uint32_t PageIndex, uint32_t PageOffset, uint32_t ByteCount)
 Name: SpiMemoryReadPageWithOffset
Reads the page PageIndex with offset from SPI memory to DstBuffer. Called from main program level. More...
 
bool SpiMemoryWriteAsync (const struct spi_memory_t *Memory, uint32_t DstAddress, struct spi_memory_data_buffer_header *SrcBuffer, uint32_t ByteCount, spi_memory_completion_callback_t Callback)
 Name: SpiMemoryWriteAsync
Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based, the data must fit into a single page, and the page must be erased before writing. Return after writing is finished. Called from main program level. Does not wait for completion, the completion callback is called instead when SPI transfer is finished. Calling code should not use SPI bus until the completion callback is called. Note that completion of the in-chip writing process is not indicated by any kind of callback. Calling code should use SpiMemoryIsBusy to wait for the completion. More...
 
bool SpiMemoryWrite (const struct spi_memory_t *Memory, uint32_t DstAddress, const void *SrcBuffer, uint32_t ByteCount)
 Name: SpiMemoryWrite
Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based, the data must fit into a single page, and the page must be erased before writing. Return after writing is finished. Called from main program level. More...
 
static bool SpiMemoryWritePageAsync (const struct spi_memory_t *Memory, uint32_t PageIndex, struct spi_memory_data_buffer_header *SrcBuffer, spi_memory_completion_callback_t Callback)
 Name: SpiMemoryWritePageAsync
Writes page data from SrcBuffer to page PageIndex in SPI memory. The page must be erased before writing. Return after writing is finished. Called from main program level. Does not wait for completion, the completion callback is called instead when SPI transfer is finished. Calling code should not use SPI bus until the completion callback is called. Note that completion of the in-chip writing process is not indicated by any kind of callback. Calling code should use SpiMemoryIsBusy to wait for the completion. More...
 
static bool SpiMemoryWritePage (const struct spi_memory_t *Memory, uint32_t PageIndex, const void *SrcBuffer)
 Name: SpiMemoryWritePage
Writes page data from SrcBuffer to page PageIndex in SPI memory. The page must be erased before writing. Return after writing is finished. Called from main program level. More...
 
bool SpiMemoryVerify (const struct spi_memory_t *Memory, uint32_t SrcAddress, const void *SrcBuffer, uint32_t ByteCount)
 Name: SpiMemoryVerify
Verifies data in SPI memory with SrcBuffer. Called from main program level. More...
 
static bool SpiMemoryVerifyPage (const struct spi_memory_t *Memory, uint32_t PageIndex, const void *SrcBuffer)
 Name: SpiMemoryVerifyPage
Verifies data in page PageIndex in SPI memory with SrcBuffer. Called from main program level. More...
 
bool SpiMemoryIsBusy (const struct spi_memory_t *Memory)
 Name: SpiMemoryIsBusy
Checks if the memory write or erase operation is in progress Called from main program level. More...
 
void SpiMemoryPowerUp (const struct spi_memory_t *Memory)
 Name: SpiMemoryPowerUp
Power up VCC for SPI memory. SpiEnable() must be called after this function to get SPI pin setup. Only to be used from EveSpiPowerUp() More...
 
void SpiMemoryPowerDown (const struct spi_memory_t *Memory)
 Name: SpiMemoryPowerDown
Power down VCC for SPI memory. SpiDisable() must be called prior to this function to get default pin setup. Only to be used from EveSpiPowerDown() More...
 

Detailed Description

This SPI Memory driver can be used for FLASH, EEPROM and SRAM configuration.

The configuration data is of type struct spi_memory_t, and is used to configure used memory.

Macro Definition Documentation

#define SPI_MEMORY_HINT_GENERIC   0

No special handling is needed

Definition at line 58 of file spi-memory.h.

#define SPI_MEMORY_HINT_GENERIC_SRAM   1

RAM status register is programmed for sequential access

Definition at line 59 of file spi-memory.h.

#define SPI_MEMORY_DATA_BUFFER_COMMAND_SIZE   4

Asynchronous data buffer header (command) size

Definition at line 61 of file spi-memory.h.

#define SPI_MEMORY_DATA_BUFFER_TYPE (   type,
  size 
)
Value:
typedef struct type \
{ \
uint8_t Data[(size)]; \
} type

Defines a new type for the asynchronous SPI memory buffer of the desired size.

Parameters
typeTypename of the newly created type.
sizeAmount of bytes in the 'data' part of the message.

Definition at line 130 of file spi-memory.h.

Typedef Documentation

typedef void(* spi_memory_completion_callback_t) (const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *BufferHeader)

Asynchronous callback type

Parameters
MemoryPointer to the SPI memory instance object
BufferHeaderPointer to the header of the buffer object. To be up-casted to the target type by container_of.

Definition at line 72 of file spi-memory.h.

Function Documentation

SPI_MEMORY_DATA_BUFFER_TYPE ( spi_memory_generic_buffer_t  ,
 
)

Defines a type for a generic buffer with unknown size.

bool SpiMemoryInit ( const struct spi_memory_t Memory)

Name: SpiMemoryInit
Waits for power on and then release SPI memory from deep powerdown. KŲ!! ???????????? Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
Returns
true if SPI memory was initialized, else false
bool SpiMemoryDisable ( const struct spi_memory_t Memory)

Name: SpiMemoryDisable
Sets SPI memory in deep powerdown. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
Returns
true if SPI memory was set disabled, else false
bool SpiMemorySetWriteProtection ( const struct spi_memory_t Memory,
enum spi_memory_protection_t  Protection 
)

Name: SpiMemorySetWriteProtection
Sets write protection for SPI memory and waits for completion. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
ProtectionParameters for protection to be used
Returns
true if SPI memory protection was set properly, else false
bool SpiMemoryEraseSectorAsync ( const struct spi_memory_t Memory,
uint32_t  SectorIndex 
)

Name: SpiMemoryEraseSectorAsync
Begines erasing given sector in SPI memory. Called from main program level. At function return SPI transfer is completed; erase is started, but not completed. Caller code should use SpiMemoryIsBusy to wait for the completion.

Parameters
MemoryPointer to the SPI memory instance object
SectorIndexIndex for sector to be erased (0 to < (.MemorySize / .SectorSize))
Returns
true if SPI memory sector erase command was sent, else false
bool SpiMemoryEraseSector ( const struct spi_memory_t Memory,
uint32_t  SectorIndex 
)

Name: SpiMemoryEraseSector
Erases given sector in SPI memory and waits for completion. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
SectorIndexIndex for sector to be erased (0 to < (.MemorySize / .SectorSize))
Returns
true if SPI memory sector was erased, else false
bool SpiMemoryEraseBlockAsync ( const struct spi_memory_t Memory,
uint32_t  BlockIndex 
)

Name: SpiMemoryEraseBlockAsync
Begines erasing given block in SPI memory. Called from main program level. At function return SPI transfer is completed; erase is started, but not completed. Caller code should use SpiMemoryIsBusy to wait for the completion.

Parameters
MemoryPointer to the SPI memory instance object
BlockIndexIndex for block to be erased (0 to < (.MemorySize / .BlockSize))
Returns
true if SPI memory block erase command was sent, else false
bool SpiMemoryEraseBlock ( const struct spi_memory_t Memory,
uint32_t  BlockIndex 
)

Name: SpiMemoryEraseBlock
Erases given block in SPI memory and waits for completion. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
BlockIndexIndex for block to be erased (0 to < (.MemorySize / .BlockSize))
Returns
true if SPI memory block was erased, else false
bool SpiMemoryEraseAsync ( const struct spi_memory_t Memory)

Name: SpiMemoryEraseAsync
Begines erasing the whole SPI memory. Called from main program level. At function return SPI transfer is completed; erase is started, but not completed. Caller code should use SpiMemoryIsBusy to wait for the completion.

Parameters
MemoryPointer to the SPI memory instance object
Returns
true if SPI memory erase command was sent, else false
bool SpiMemoryErase ( const struct spi_memory_t Memory)

Name: SpiMemoryErase
Erases the whole SPI memory and waits for completion. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
Returns
true if SPI memory was erased, else false
bool SpiMemoryReadAsync ( const struct spi_memory_t Memory,
struct spi_memory_data_buffer_header DstBuffer,
uint32_t  SrcAddress,
uint32_t  ByteCount,
spi_memory_completion_callback_t  Callback 
)

Name: SpiMemoryReadAsync
Reads bytes from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called.

Parameters
MemoryPointer to the SPI memory instance object
DstBufferDestination buffer for read data.
SrcAddressAddress of first byte to read from SPI memory
ByteCountNumber of bytes to read from SPI memory
CallbackCompletion callback
Returns
true if SPI memory read command was sent, else false

Referenced by SpiMemoryReadPageAsync(), and SpiMemoryReadPageWithOffsetAsync().

bool SpiMemoryRead ( const struct spi_memory_t Memory,
void *  DstBuffer,
uint32_t  SrcAddress,
uint32_t  ByteCount 
)

Name: SpiMemoryRead
Reads bytes from SPI memory to DstBuffer. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
DstBufferDestination buffer for read data
SrcAddressAddress of first byte to read from SPI memory
ByteCountNumber of bytes to read from SPI memory
Returns
true if SPI memory was read, else false

Referenced by SpiMemoryReadPage(), and SpiMemoryReadPageWithOffset().

static bool SpiMemoryReadPageAsync ( const struct spi_memory_t Memory,
struct spi_memory_data_buffer_header DstBuffer,
uint32_t  PageIndex,
spi_memory_completion_callback_t  Callback 
)
inlinestatic

Name: SpiMemoryReadPageAsync
Reads the page PageIndex from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called.

Parameters
MemoryPointer to the SPI memory instance object
DstBufferDestination buffer for read data
PageIndexIndex of page to read from SPI memory
CallbackCompletion callback
Returns
true if SPI memory was read, else false

Definition at line 316 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, and SpiMemoryReadAsync().

static bool SpiMemoryReadPage ( const struct spi_memory_t Memory,
void *  DstBuffer,
uint32_t  PageIndex 
)
inlinestatic

Name: SpiMemoryReadPage
Reads the page PageIndex from SPI memory to DstBuffer. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
DstBufferDestination buffer for read data
PageIndexIndex of page to read from SPI memory
Returns
true if SPI memory was read, else false

Definition at line 335 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, and SpiMemoryRead().

static bool SpiMemoryReadPageWithOffsetAsync ( const struct spi_memory_t Memory,
struct spi_memory_data_buffer_header DstBuffer,
uint32_t  PageIndex,
uint32_t  PageOffset,
uint32_t  ByteCount,
spi_memory_completion_callback_t  Callback 
)
inlinestatic

Name: SpiMemoryReadPageWithOffsetAsync
Reads the page PageIndex with offset from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called.

Parameters
MemoryPointer to the SPI memory instance object
DstBufferDestination buffer for read data
PageIndexIndex of page to read from SPI memory
PageOffsetOffset in page, must be < .PageSize
ByteCountNumber of bytes to read from SPI memory
CallbackCompletion callback
Returns
true if SPI memory was read, else false

Definition at line 359 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, and SpiMemoryReadAsync().

static bool SpiMemoryReadPageWithOffset ( const struct spi_memory_t Memory,
void *  DstBuffer,
uint32_t  PageIndex,
uint32_t  PageOffset,
uint32_t  ByteCount 
)
inlinestatic

Name: SpiMemoryReadPageWithOffset
Reads the page PageIndex with offset from SPI memory to DstBuffer. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
DstBufferDestination buffer for read data
PageIndexIndex of page to read from SPI memory
PageOffsetOffset in page, must be < .PageSize
ByteCountNumber of bytes to read from SPI memory
Returns
true if SPI memory was read, else false

Definition at line 382 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, SpiMemoryRead(), SpiMemoryWrite(), and SpiMemoryWriteAsync().

bool SpiMemoryWriteAsync ( const struct spi_memory_t Memory,
uint32_t  DstAddress,
struct spi_memory_data_buffer_header SrcBuffer,
uint32_t  ByteCount,
spi_memory_completion_callback_t  Callback 
)

Name: SpiMemoryWriteAsync
Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based, the data must fit into a single page, and the page must be erased before writing. Return after writing is finished. Called from main program level. Does not wait for completion, the completion callback is called instead when SPI transfer is finished. Calling code should not use SPI bus until the completion callback is called. Note that completion of the in-chip writing process is not indicated by any kind of callback. Calling code should use SpiMemoryIsBusy to wait for the completion.

Parameters
MemoryPointer to the SPI memory instance object
DstAddressAddress of first byte to write to SPI memory
SrcBufferSource buffer for the data to be written
ByteCountNumber of bytes to write to SPI memory
CallbackCompletion callback
Returns
true if SPI memory was written, else false

Referenced by SpiMemoryReadPageWithOffset(), and SpiMemoryWritePageAsync().

bool SpiMemoryWrite ( const struct spi_memory_t Memory,
uint32_t  DstAddress,
const void *  SrcBuffer,
uint32_t  ByteCount 
)

Name: SpiMemoryWrite
Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based, the data must fit into a single page, and the page must be erased before writing. Return after writing is finished. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
DstAddressAddress of first byte to write to SPI memory
SrcBufferSource buffer for the data to be written
ByteCountNumber of bytes to write to SPI memory
Returns
true if SPI memory was written, else false

Referenced by SpiMemoryReadPageWithOffset(), and SpiMemoryWritePage().

static bool SpiMemoryWritePageAsync ( const struct spi_memory_t Memory,
uint32_t  PageIndex,
struct spi_memory_data_buffer_header SrcBuffer,
spi_memory_completion_callback_t  Callback 
)
inlinestatic

Name: SpiMemoryWritePageAsync
Writes page data from SrcBuffer to page PageIndex in SPI memory. The page must be erased before writing. Return after writing is finished. Called from main program level. Does not wait for completion, the completion callback is called instead when SPI transfer is finished. Calling code should not use SPI bus until the completion callback is called. Note that completion of the in-chip writing process is not indicated by any kind of callback. Calling code should use SpiMemoryIsBusy to wait for the completion.

Parameters
MemoryPointer to the SPI memory instance object
PageIndexIndex of page to write to SPI memory
SrcBufferSource buffer for page data to be written
CallbackCompletion callback
Returns
true if SPI memory was written, else false

Definition at line 457 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, and SpiMemoryWriteAsync().

static bool SpiMemoryWritePage ( const struct spi_memory_t Memory,
uint32_t  PageIndex,
const void *  SrcBuffer 
)
inlinestatic

Name: SpiMemoryWritePage
Writes page data from SrcBuffer to page PageIndex in SPI memory. The page must be erased before writing. Return after writing is finished. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
PageIndexIndex of page to write to SPI memory
SrcBufferSource buffer for page data to be written
Returns
true if SPI memory was written, else false

Definition at line 478 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, SpiMemoryVerify(), and SpiMemoryWrite().

bool SpiMemoryVerify ( const struct spi_memory_t Memory,
uint32_t  SrcAddress,
const void *  SrcBuffer,
uint32_t  ByteCount 
)

Name: SpiMemoryVerify
Verifies data in SPI memory with SrcBuffer. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
SrcAddressFirst address to be verified in SPI memory
SrcBufferSource buffer for data to be verified
ByteCountNumber of bytes to verify in SPI memory
Returns
true if flash is accessable and verify OK, else false

Referenced by SpiMemoryVerifyPage(), and SpiMemoryWritePage().

static bool SpiMemoryVerifyPage ( const struct spi_memory_t Memory,
uint32_t  PageIndex,
const void *  SrcBuffer 
)
inlinestatic

Name: SpiMemoryVerifyPage
Verifies data in page PageIndex in SPI memory with SrcBuffer. Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
PageIndexIndex of page to be verified in SPI memory
SrcBufferSource buffer for data to be verified
Returns
true if flash is accessable and verify OK, else false

Definition at line 508 of file spi-memory.h.

References spi_memory_t::PageSizeExponent, SpiMemoryIsBusy(), SpiMemoryPowerDown(), SpiMemoryPowerUp(), and SpiMemoryVerify().

bool SpiMemoryIsBusy ( const struct spi_memory_t Memory)

Name: SpiMemoryIsBusy
Checks if the memory write or erase operation is in progress Called from main program level.

Parameters
MemoryPointer to the SPI memory instance object
Returns
true if flash is busy, else false

Referenced by SpiMemoryVerifyPage().

void SpiMemoryPowerUp ( const struct spi_memory_t Memory)

Name: SpiMemoryPowerUp
Power up VCC for SPI memory. SpiEnable() must be called after this function to get SPI pin setup. Only to be used from EveSpiPowerUp()

Parameters
MemoryPointer to the SPI memory instance object

Referenced by SpiMemoryVerifyPage().

void SpiMemoryPowerDown ( const struct spi_memory_t Memory)

Name: SpiMemoryPowerDown
Power down VCC for SPI memory. SpiDisable() must be called prior to this function to get default pin setup. Only to be used from EveSpiPowerDown()

Parameters
MemoryPointer to the SPI memory instance object

Referenced by SpiMemoryVerifyPage().