Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
|
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "ca821x-posix/ca821x-posix-settings.h"
#include "ca821x-posix/ca821x-types.h"
#include "cascoda-util/cascoda_flash.h"
Macros | |
#define | otEXPECT(aCondition) |
This checks for the specified condition, which is expected to commonly be true, and branches to the local label 'exit' if the condition is false. More... | |
#define | otEXPECT_ACTION(aCondition, aAction) |
This checks for the specified condition, which is expected to commonly be true, and both executes anAction and branches to the local label 'exit' if the condition is false. More... | |
Enumerations | |
enum | { FLASH_SIZE = 0x40000 , FLASH_PAGE_SIZE = 0x800 , FLASH_PAGE_NUM = 128 } |
Functions | |
char * | posixGetDataDir (uint32_t aNodeId) |
Find the best place to place the data files, and initialise the directory if it doesn't already exist. More... | |
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 *instance) |
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 *instance, 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... | |
void | BSP_GetFlashInfo (struct ca_flash_info *aFlashInfoOut) |
Get the flashinfo struct for the current platform. 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... | |
Variables | |
uint32_t | sEraseAddress |
#define otEXPECT | ( | aCondition | ) |
This checks for the specified condition, which is expected to commonly be true, and branches to the local label 'exit' if the condition is false.
[in] | aCondition | A Boolean expression to be evaluated. |
#define otEXPECT_ACTION | ( | aCondition, | |
aAction | |||
) |
This checks for the specified condition, which is expected to commonly be true, and both executes anAction
and branches to the local label 'exit' if the condition is false.
[in] | aCondition | A Boolean expression to be evaluated. |
[in] | aAction | An expression or block to execute when the assertion fails. |
char* posixGetDataDir | ( | uint32_t | aNodeId | ) |
Find the best place to place the data files, and initialise the directory if it doesn't already exist.
Get the directory where of the persistent storage file for a particular node.
ca_error utilsFlashDeinit | ( | struct ca821x_dev * | aInstance | ) |
Deinitialize the flash driver.
aInstance | Instance to deinitialize. Unused on baremetal. |
CA_ERROR_SUCCESS | Initialize flash driver success. |
CA_ERROR_FAIL | Initialize flash driver fail. |
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.
[in] | aInstance | API instance to initialize/whose storage to access. Unused on baremetal. |
[in] | aAddress | The start address of the flash to erase. |
CA_ERROR_SUCCESS | Erase flash operation is started. |
CA_ERROR_FAIL | Erase flash operation is not started. |
CA_ERROR_INVALID_ARGS | aAddress is out of range of flash or not aligend. |
uint32_t utilsFlashGetBaseAddress | ( | struct ca821x_dev * | aInstance | ) |
Internal function for getting the base address.
aInstance | The device to access |
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.
[in] | aInstance | API instance to initialize/whose storage to access. Unused on baremetal. |
uint32_t utilsFlashGetUsedSize | ( | struct ca821x_dev * | aInstance | ) |
Internal function for returning the amount of flash used.
aInstance | The device to access |
ca_error utilsFlashInit | ( | struct ca821x_dev * | aInstance, |
const char * | aApplicationName, | ||
uint32_t | aNodeId | ||
) |
Perform any initialization for flash driver.
[in] | aInstance | API instance to initialize/whose storage to access. Unused on baremetal. |
[in] | aApplicationName | Filename of the storage file, used to distinguish between storage applications. Unused on baremetal. |
[in] | aNodeId | Used to distinguish between different nodes on the same host. Unused on baremetal. |
CA_ERROR_SUCCESS | Initialize flash driver success. |
CA_ERROR_FAIL | Initialize flash driver fail. |
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.
[in] | aInstance | API instance to initialize/whose storage to access. Unused on baremetal. |
[in] | aAddress | The start address of the flash to read. |
[out] | aData | The pointer of buffer for reading. |
[in] | aSize | The size of the data to read. |
void utilsFlashSetBaseAddress | ( | struct ca821x_dev * | aInstance, |
uint32_t | aAddress | ||
) |
Internal function for setting the base address.
aInstance | The device to access |
aAddress | The address |
void utilsFlashSetUsedSize | ( | struct ca821x_dev * | aInstance, |
uint32_t | aSize | ||
) |
Internal function for setting the amount of flash used.
aInstance | The device to access |
aSize | The size |
ca_error utilsFlashStatusWait | ( | struct ca821x_dev * | aInstance, |
uint32_t | aTimeout | ||
) |
Check whether flash is ready or busy.
[in] | aInstance | API instance to initialize/whose storage to access. Unused on baremetal. |
[in] | aTimeout | The 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. |
CA_ERROR_SUCCESS | Flash is ready for any operation. |
CA_ERROR_BUSY | Flash is busy. |
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.
[in] | aInstance | API instance to initialize/whose storage to access. Unused on baremetal. |
[in] | aAddress | The start address of the flash to write. |
[in] | aData | The pointer of the data to write. |
[in] | aSize | The size of the data to write. |
uint32_t sEraseAddress |