Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_flash.h File Reference

This file defines the flash interface used by settings.cpp. More...

#include <stdint.h>
#include "ca821x_api.h"
Include dependency graph for cascoda_flash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ca_flash_info
 Description of the internal flash. More...
 

Functions

ca_error utilsFlashInit (struct ca821x_dev *aInstance, const char *aApplicationName, uint32_t aNodeId)
 Perform any initialization for flash driver. More...
 
ca_error utilsFlashDeinit (struct ca821x_dev *aInstance)
 Deinitialize the flash driver. More...
 
uint32_t utilsFlashGetSize (struct ca821x_dev *aInstance)
 Get the size of flash that can be read/write by the caller. More...
 
ca_error utilsFlashErasePage (struct ca821x_dev *aInstance, uint32_t aAddress)
 Erase one flash page that include the input address. More...
 
ca_error utilsFlashStatusWait (struct ca821x_dev *aInstance, uint32_t aTimeout)
 Check whether flash is ready or busy. More...
 
uint32_t utilsFlashWrite (struct ca821x_dev *aInstance, uint32_t aAddress, const uint8_t *aData, uint32_t aSize)
 Write flash. More...
 
uint32_t utilsFlashRead (struct ca821x_dev *aInstance, uint32_t aAddress, uint8_t *aData, uint32_t aSize)
 Read flash. More...
 
uint32_t utilsFlashGetBaseAddress (struct ca821x_dev *aInstance)
 Internal function for getting the base address. More...
 
uint32_t utilsFlashGetUsedSize (struct ca821x_dev *aInstance)
 Internal function for returning the amount of flash used. More...
 
void utilsFlashSetBaseAddress (struct ca821x_dev *aInstance, uint32_t aAddress)
 Internal function for setting the base address. More...
 
void utilsFlashSetUsedSize (struct ca821x_dev *aInstance, uint32_t aSize)
 Internal function for setting the amount of flash used. More...
 

Detailed Description

This file defines the flash interface used by settings.cpp.

Function Documentation

◆ utilsFlashDeinit()

ca_error utilsFlashDeinit ( struct ca821x_dev aInstance)

Deinitialize the flash driver.

Parameters
aInstanceInstance to deinitialize. Unused on baremetal.
Return values
CA_ERROR_SUCCESSInitialize flash driver success.
CA_ERROR_FAILInitialize flash driver fail.

◆ utilsFlashErasePage()

ca_error utilsFlashErasePage ( struct ca821x_dev aInstance,
uint32_t  aAddress 
)

Erase one flash page that include the input address.

This is a non-blocking function. It can work with utilsFlashStatusWait to check when erase is done.

The flash address starts from 0, and this function maps the input address to the physical address of flash for erasing. 0 is always mapped to the beginning of one flash page. The input address should never be mapped to the firmware space or any other protected flash space.

Parameters
[in]aInstanceAPI instance to initialize/whose storage to access. Unused on baremetal.
[in]aAddressThe start address of the flash to erase.
Return values
CA_ERROR_SUCCESSErase flash operation is started.
CA_ERROR_FAILErase flash operation is not started.
CA_ERROR_INVALID_ARGSaAddress is out of range of flash or not aligend.

◆ utilsFlashGetBaseAddress()

uint32_t utilsFlashGetBaseAddress ( struct ca821x_dev aInstance)

Internal function for getting the base address.

Parameters
aInstanceThe device to access
Returns
uint32_t The base address

◆ utilsFlashGetSize()

uint32_t utilsFlashGetSize ( struct ca821x_dev aInstance)

Get the size of flash that can be read/write by the caller.

The usable flash size is always the multiple of flash page size.

Parameters
[in]aInstanceAPI instance to initialize/whose storage to access. Unused on baremetal.
Returns
The size of the flash.

◆ utilsFlashGetUsedSize()

uint32_t utilsFlashGetUsedSize ( struct ca821x_dev aInstance)

Internal function for returning the amount of flash used.

Parameters
aInstanceThe device to access
Returns
uint32_t How much flash is used starting from the base address

◆ utilsFlashInit()

ca_error utilsFlashInit ( struct ca821x_dev aInstance,
const char *  aApplicationName,
uint32_t  aNodeId 
)

Perform any initialization for flash driver.

Parameters
[in]aInstanceAPI instance to initialize/whose storage to access. Unused on baremetal.
[in]aApplicationNameFilename of the storage file, used to distinguish between storage applications. Unused on baremetal.
[in]aNodeIdUsed to distinguish between different nodes on the same host. Unused on baremetal.
Return values
CA_ERROR_SUCCESSInitialize flash driver success.
CA_ERROR_FAILInitialize flash driver fail.

◆ utilsFlashRead()

uint32_t utilsFlashRead ( struct ca821x_dev aInstance,
uint32_t  aAddress,
uint8_t *  aData,
uint32_t  aSize 
)

Read flash.

The flash address starts from 0, and this function maps the input address to the physical address of flash for reading. 0 is always mapped to the beginning of one flash page. The input address should never be mapped to the firmware space or any other protected flash space.

Parameters
[in]aInstanceAPI instance to initialize/whose storage to access. Unused on baremetal.
[in]aAddressThe start address of the flash to read.
[out]aDataThe pointer of buffer for reading.
[in]aSizeThe size of the data to read.
Returns
The actual size of octets read to buffer. It is expected the same as aSize, and may be less than aSize. 0 indicates that something wrong happens when reading.

◆ utilsFlashSetBaseAddress()

void utilsFlashSetBaseAddress ( struct ca821x_dev aInstance,
uint32_t  aAddress 
)

Internal function for setting the base address.

Parameters
aInstanceThe device to access
aAddressThe address

◆ utilsFlashSetUsedSize()

void utilsFlashSetUsedSize ( struct ca821x_dev aInstance,
uint32_t  aSize 
)

Internal function for setting the amount of flash used.

Parameters
aInstanceThe device to access
aSizeThe size

◆ utilsFlashStatusWait()

ca_error utilsFlashStatusWait ( struct ca821x_dev aInstance,
uint32_t  aTimeout 
)

Check whether flash is ready or busy.

Parameters
[in]aInstanceAPI instance to initialize/whose storage to access. Unused on baremetal.
[in]aTimeoutThe interval in milliseconds waiting for the flash operation to be done and become ready again. zero indicates that it is a polling function, and returns current status of flash immediately. non-zero indicates that it is blocking there until the operation is done and become ready, or timeout expires.
Return values
CA_ERROR_SUCCESSFlash is ready for any operation.
CA_ERROR_BUSYFlash is busy.

◆ utilsFlashWrite()

uint32_t utilsFlashWrite ( struct ca821x_dev aInstance,
uint32_t  aAddress,
const uint8_t *  aData,
uint32_t  aSize 
)

Write flash.

The write operation only clears bits, but never set bits.

The flash address starts from 0, and this function maps the input address to the physical address of flash for writing. 0 is always mapped to the beginning of one flash page. The input address should never be mapped to the firmware space or any other protected flash space.

Parameters
[in]aInstanceAPI instance to initialize/whose storage to access. Unused on baremetal.
[in]aAddressThe start address of the flash to write.
[in]aDataThe pointer of the data to write.
[in]aSizeThe size of the data to write.
Returns
The actual size of octets write to flash. It is expected the same as aSize, and may be less than aSize. 0 indicates that something wrong happens when writing.