Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
Loading...
Searching...
No Matches
cascoda_bsp_flashdevice.c File Reference
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "M2351.h"
#include "cascoda-bm/cascoda_interface.h"
#include "cascoda-bm/cascoda_spi.h"
#include "cascoda-util/cascoda_tasklet.h"
#include "cascoda_chili.h"
#include "cascoda_chili_gpio.h"
#include "cascoda_secure.h"
Include dependency graph for cascoda_bsp_flashdevice.c:

Macros

#define EXTERNAL_FLASH_BASE   0xB0000000
#define DEV_W25Q80DVSNIG   0x13
#define DEV_MX25R8035FM1IL0   0x14
#define WRITE_ENABLE   0x06
#define WRITE_DISABLE   0x04
#define READ_STATUS_REGISTER_1   0x05
#define PAGE_PROGRAM   0x02
#define SECTOR_ERASE_4KB   0x20
#define BLOCK_ERASE_32KB   0x52
#define BLOCK_ERASE_64KB   0xD8
#define CHIP_ERASE   0xC7
#define POWER_DOWN   0xB9
#define READ_DATA   0x03
#define RELEASE_POWERDOWN_ID   0xAB
#define DUMMY_BYTE   0xFF
#define DONT_CARE_BYTE   0x00
#define INSTRUCTION_BYTE_LENGTH   1
#define ADDRESS_BYTE_LENGTH   3
#define NUM_OF_BYTES_IN_A_PAGE   256
#define PAGE_PROGRAM_MAX_BYTES_THEORETICAL   NUM_OF_BYTES_IN_A_PAGE
#define PAGE_PROGRAM_MAX_BYTES_ACTUAL   (PAGE_PROGRAM_MAX_BYTES_THEORETICAL / 2)
#define READ_DATA_MAX_BYTES_THEORETICAL   1048576
#define READ_DATA_MAX_BYTES_ACTUAL   PAGE_PROGRAM_MAX_BYTES_ACTUAL
#define PAGE_PROGRAM_MAX_TX_LEN   (INSTRUCTION_BYTE_LENGTH + ADDRESS_BYTE_LENGTH + PAGE_PROGRAM_MAX_BYTES_ACTUAL)
#define READ_DATA_MAX_RX_LEN   PAGE_PROGRAM_MAX_TX_LEN
#define T_PP_W25Q80DVSNIG   4
#define T_SE_W25Q80DVSNIG   300
#define T_CE_W25Q80DVSNIG   6000
#define T_BE1_W25Q80DVSNIG   800
#define T_BE2_W25Q80DVSNIG   1000
#define T_DP_W25Q80DVSNIG   4
#define T_RES1_W25Q80DVSNIG   4
#define T_PP_MX25R8035FM1IL0   10
#define T_SE_MX25R8035FM1IL0   240
#define T_CE_MX25R8035FM1IL0   30000
#define T_BE1_MX25R8035FM1IL0   1750
#define T_BE2_MX25R8035FM1IL0   3500
#define T_DP_MX25R8035FM1IL0   10
#define T_RDP_MX25R8035FM1IL0   35

Typedefs

typedef enum statusRegister1_masks statusRegister1_masks
 Masks for individual bits in Status Register 1.
typedef enum statusRegister1_pos statusRegister1_pos
 Bit positions for Status Register 1.

Enumerations

enum  statusRegister1_masks { WEL_mask = 0x02 }
 Masks for individual bits in Status Register 1. More...
enum  statusRegister1_pos { WEL_pos = 1 }
 Bit positions for Status Register 1. More...

Functions

void BSP_SetSPIMOSIOutput (void)
 Connect MOSI port to SPI MOSI and disable pull-up.
void BSP_SetSPIMOSITristate (void)
 Disconnect MOSI port from SPI MOSI and put to tristate with pull-up.
ca_error FLASHDEV_WriteEnable ()
 Set the Write Enable Latch bit in the Status Register to a 1.
ca_error FLASHDEV_WriteDisable ()
 Set the Write Enable Latch bit in the Status Register to a 0.
ca_error FLASHDEV_ReadStatusRegister1 (uint8_t *statusRegister1)
 Read the 8-bit Status Register 1.
ca_error FLASHDEV_PowerDown ()
 Put the external flash chip in power down mode.
ca_error FLASHDEV_ReleasePowerDown (void)
 Release the external flash chip from power down mode.
void BSP_ExternalFlashInit (void)
ca_error BSP_ExternalFlashProgram (uint32_t aStartAddress, uint8_t aNumOfBytes, uint8_t *aTxData)
ca_error BSP_ExternalFlashReadData (uint32_t aStartAddress, uint8_t aNumOfBytes, uint8_t *aRxData)
ca_error BSP_ExternalFlashPartialErase (ExternalFlashPartialEraseType aEraseType, uint32_t aAddress)
ca_error BSP_ExternalFlashChipErase (void)
ca_error BSP_ExternalFlashGetDeviceId (uint8_t *aId)
ca_error BSP_ExternalFlashGetStatus (struct ExternalFlashStatus *status)
ca_error BSP_ExternalFlashScheduleCallback (ExternalFlashCallback aCallback, void *aContext)
void BSP_ExternalFlashGetInfo (struct ExternalFlashInfo *aFlashInfoOut)

Variables

const struct ExternalFlashInfo BSP_ExternalFlashInfo

Macro Definition Documentation

◆ ADDRESS_BYTE_LENGTH

#define ADDRESS_BYTE_LENGTH   3

◆ BLOCK_ERASE_32KB

#define BLOCK_ERASE_32KB   0x52

◆ BLOCK_ERASE_64KB

#define BLOCK_ERASE_64KB   0xD8

◆ CHIP_ERASE

#define CHIP_ERASE   0xC7

◆ DEV_MX25R8035FM1IL0

#define DEV_MX25R8035FM1IL0   0x14

◆ DEV_W25Q80DVSNIG

#define DEV_W25Q80DVSNIG   0x13

◆ DONT_CARE_BYTE

#define DONT_CARE_BYTE   0x00

◆ DUMMY_BYTE

#define DUMMY_BYTE   0xFF

◆ EXTERNAL_FLASH_BASE

#define EXTERNAL_FLASH_BASE   0xB0000000

◆ INSTRUCTION_BYTE_LENGTH

#define INSTRUCTION_BYTE_LENGTH   1

◆ NUM_OF_BYTES_IN_A_PAGE

#define NUM_OF_BYTES_IN_A_PAGE   256

◆ PAGE_PROGRAM

#define PAGE_PROGRAM   0x02

◆ PAGE_PROGRAM_MAX_BYTES_ACTUAL

#define PAGE_PROGRAM_MAX_BYTES_ACTUAL   (PAGE_PROGRAM_MAX_BYTES_THEORETICAL / 2)

◆ PAGE_PROGRAM_MAX_BYTES_THEORETICAL

#define PAGE_PROGRAM_MAX_BYTES_THEORETICAL   NUM_OF_BYTES_IN_A_PAGE

◆ PAGE_PROGRAM_MAX_TX_LEN

◆ POWER_DOWN

#define POWER_DOWN   0xB9

◆ READ_DATA

#define READ_DATA   0x03

◆ READ_DATA_MAX_BYTES_ACTUAL

#define READ_DATA_MAX_BYTES_ACTUAL   PAGE_PROGRAM_MAX_BYTES_ACTUAL

◆ READ_DATA_MAX_BYTES_THEORETICAL

#define READ_DATA_MAX_BYTES_THEORETICAL   1048576

◆ READ_DATA_MAX_RX_LEN

#define READ_DATA_MAX_RX_LEN   PAGE_PROGRAM_MAX_TX_LEN

◆ READ_STATUS_REGISTER_1

#define READ_STATUS_REGISTER_1   0x05

◆ RELEASE_POWERDOWN_ID

#define RELEASE_POWERDOWN_ID   0xAB

◆ SECTOR_ERASE_4KB

#define SECTOR_ERASE_4KB   0x20

◆ T_BE1_MX25R8035FM1IL0

#define T_BE1_MX25R8035FM1IL0   1750

◆ T_BE1_W25Q80DVSNIG

#define T_BE1_W25Q80DVSNIG   800

◆ T_BE2_MX25R8035FM1IL0

#define T_BE2_MX25R8035FM1IL0   3500

◆ T_BE2_W25Q80DVSNIG

#define T_BE2_W25Q80DVSNIG   1000

◆ T_CE_MX25R8035FM1IL0

#define T_CE_MX25R8035FM1IL0   30000

◆ T_CE_W25Q80DVSNIG

#define T_CE_W25Q80DVSNIG   6000

◆ T_DP_MX25R8035FM1IL0

#define T_DP_MX25R8035FM1IL0   10

◆ T_DP_W25Q80DVSNIG

#define T_DP_W25Q80DVSNIG   4

◆ T_PP_MX25R8035FM1IL0

#define T_PP_MX25R8035FM1IL0   10

◆ T_PP_W25Q80DVSNIG

#define T_PP_W25Q80DVSNIG   4

◆ T_RDP_MX25R8035FM1IL0

#define T_RDP_MX25R8035FM1IL0   35

◆ T_RES1_W25Q80DVSNIG

#define T_RES1_W25Q80DVSNIG   4

◆ T_SE_MX25R8035FM1IL0

#define T_SE_MX25R8035FM1IL0   240

◆ T_SE_W25Q80DVSNIG

#define T_SE_W25Q80DVSNIG   300

◆ WRITE_DISABLE

#define WRITE_DISABLE   0x04

◆ WRITE_ENABLE

#define WRITE_ENABLE   0x06

Typedef Documentation

◆ statusRegister1_masks

Masks for individual bits in Status Register 1.

◆ statusRegister1_pos

Bit positions for Status Register 1.

Enumeration Type Documentation

◆ statusRegister1_masks

Masks for individual bits in Status Register 1.

Enumerator
WEL_mask 

S1 mask.

◆ statusRegister1_pos

Bit positions for Status Register 1.

Enumerator
WEL_pos 

S1 position.

Function Documentation

◆ BSP_ExternalFlashChipErase()

ca_error BSP_ExternalFlashChipErase ( void )

◆ BSP_ExternalFlashGetDeviceId()

ca_error BSP_ExternalFlashGetDeviceId ( uint8_t * aId)

◆ BSP_ExternalFlashGetInfo()

void BSP_ExternalFlashGetInfo ( struct ExternalFlashInfo * aFlashInfoOut)

◆ BSP_ExternalFlashGetStatus()

ca_error BSP_ExternalFlashGetStatus ( struct ExternalFlashStatus * status)

◆ BSP_ExternalFlashInit()

void BSP_ExternalFlashInit ( void )

◆ BSP_ExternalFlashPartialErase()

ca_error BSP_ExternalFlashPartialErase ( ExternalFlashPartialEraseType aEraseType,
uint32_t aAddress )

◆ BSP_ExternalFlashProgram()

ca_error BSP_ExternalFlashProgram ( uint32_t aStartAddress,
uint8_t aNumOfBytes,
uint8_t * aTxData )

◆ BSP_ExternalFlashReadData()

ca_error BSP_ExternalFlashReadData ( uint32_t aStartAddress,
uint8_t aNumOfBytes,
uint8_t * aRxData )

◆ BSP_ExternalFlashScheduleCallback()

ca_error BSP_ExternalFlashScheduleCallback ( ExternalFlashCallback aCallback,
void * aContext )

◆ FLASHDEV_PowerDown()

ca_error FLASHDEV_PowerDown ( )

Put the external flash chip in power down mode.

When in power down mode, the external flash chip consumes less power and will ignore all instructions except for RELEASE_POWERDOWN_ID.

Returns
Status of the command.
Return values
CA_ERROR_SUCCESSSuccess.
CA_ERROR_BUSYSPI is currently being used to communicate with the RF chip.

◆ FLASHDEV_ReadStatusRegister1()

ca_error FLASHDEV_ReadStatusRegister1 ( uint8_t * statusRegister1)

Read the 8-bit Status Register 1.

(Function used internally by BSP_ExternalFlashGetStatus)

Parameters
statusRegister1Stores the value of Status Register 1 that was read.
Returns
Status of the command.
Return values
CA_ERROR_SUCCESSSuccess.
CA_ERROR_BUSYSPI is currently being used to communicate with the RF chip.

◆ FLASHDEV_ReleasePowerDown()

ca_error FLASHDEV_ReleasePowerDown ( void )

Release the external flash chip from power down mode.

This is a multi-purpose instruction, because it can also get the ID of the device at the same time.

Returns
Status of the command.
Return values
CA_ERROR_SUCCESSSuccess.
CA_ERROR_BUSYSPI is currently being used to communicate with the RF chip.

◆ FLASHDEV_WriteDisable()

ca_error FLASHDEV_WriteDisable ( )

Set the Write Enable Latch bit in the Status Register to a 0.

(Function used for testing purposes).

Returns
Status of the command.
Return values
CA_ERROR_SUCCESSSuccess.
CA_ERROR_BUSYSPI is currently being used to communicate with the RF chip.

◆ FLASHDEV_WriteEnable()

ca_error FLASHDEV_WriteEnable ( )

Set the Write Enable Latch bit in the Status Register to a 1.

Forward declarations for non-BSP functions.

The WEL bit must be set prior to every Page Program, Sector Erase, Block Erase, Chip Erase and Write Status Register instruction. The WEL bit is reset to 0 upon completion of every aforementioned instruction. (Function used internally by BSP_ExternalFlashChipErase, BSP_ExternalFlashPartialErase and BSP_ExternalFlashProgram)

Returns
Status of the command.
Return values
CA_ERROR_SUCCESSSuccess.
CA_ERROR_BUSYSPI is currently being used to communicate with the RF chip.

Variable Documentation

◆ BSP_ExternalFlashInfo

const struct ExternalFlashInfo BSP_ExternalFlashInfo
Initial value:
#define PAGE_PROGRAM_MAX_BYTES_ACTUAL
Definition cascoda_bsp_flashdevice.c:89
#define EXTERNAL_FLASH_BASE
Definition cascoda_bsp_flashdevice.c:56
#define NUM_OF_BYTES_IN_A_PAGE
Definition cascoda_bsp_flashdevice.c:85