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

This file implements the flash interface from flash.h. More...

#include <stdio.h>
#include <string.h>
#include "cascoda-bm/cascoda_interface.h"
#include "cascoda-bm/cascoda_types.h"
#include "cascoda-util/cascoda_flash.h"
Include dependency graph for cascoda_flash.c:

Macros

#define FLASH_BUFSIZE   4
 

Functions

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...
 
ca_error utilsFlashInit (struct ca821x_dev *instance, const char *aApplicationName, uint32_t aNodeId)
 Perform any initialization for flash driver. More...
 
uint32_t utilsFlashGetSize (struct ca821x_dev *instance)
 Get the size of flash that can be read/write by the caller. More...
 
ca_error utilsFlashErasePage (struct ca821x_dev *instance, uint32_t aAddress)
 Erase one flash page that include the input address. More...
 
ca_error utilsFlashStatusWait (struct ca821x_dev *instance, uint32_t aTimeout)
 Check whether flash is ready or busy. More...
 
uint32_t utilsFlashWrite (struct ca821x_dev *instance, uint32_t aAddress, const uint8_t *aData, uint32_t aSize)
 Write flash. More...
 
uint32_t utilsFlashRead (struct ca821x_dev *instance, uint32_t aAddress, uint8_t *aData, uint32_t aSize)
 Read flash. More...
 

Detailed Description

This file implements the flash interface from flash.h.

for a Nuvoton Nano120 device

Macro Definition Documentation

◆ FLASH_BUFSIZE

#define FLASH_BUFSIZE   4

Function Documentation

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