Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_bsp_w25q80dlsnig.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_w25q80dlsnig.c:

Macros

#define EXTERNAL_FLASH_BASE   0xB0000000
 
#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   4
 
#define T_SE   300
 
#define T_CE   6000
 
#define T_BE1   800
 
#define T_BE2   1000
 
#define T_DP   4
 
#define T_RES1   4
 

Typedefs

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

Enumerations

enum  statusRegister1_masks {
  BUSY_mask = 0x01 , WEL_mask = 0x02 , BP0_mask = 0x04 , BP1_mask = 0x08 ,
  BP2_mask = 0x10 , TB_mask = 0x20 , SEC_mask = 0x40 , SRP0_mask = 0x80 ,
  WEL_mask = 0x02
}
 Masks for individual bits in Status Register 1. More...
 
enum  statusRegister1_pos {
  BUSY_pos = 0 , WEL_pos , BP0_pos , BP1_pos ,
  BP2_pos , TB_pos , SEC_pos , SRP0_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. More...
 
void BSP_SetSPIMOSITristate (void)
 Disconnect MOSI port from SPI MOSI and put to tristate with pull-up. More...
 
ca_error W25Q80DLSNIG_WriteEnable ()
 Set the Write Enable Latch bit in the Status Register to a 1. More...
 
ca_error W25Q80DLSNIG_WriteDisable ()
 Set the Write Enable Latch bit in the Status Register to a 0. More...
 
ca_error W25Q80DLSNIG_ReadStatusRegister1 (uint8_t *statusRegister1)
 Read the 8-bit Status Register 1. More...
 
ca_error W25Q80DLSNIG_PowerDown ()
 Put the external flash chip in power down mode. More...
 
ca_error W25Q80DLSNIG_ReleasePowerDown (void)
 Release the external flash chip from power down mode. More...
 
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

◆ 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

#define T_BE1   800

◆ T_BE2

#define T_BE2   1000

◆ T_CE

#define T_CE   6000

◆ T_DP

#define T_DP   4

◆ T_PP

#define T_PP   4

◆ T_RES1

#define T_RES1   4

◆ T_SE

#define T_SE   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
BUSY_mask 

S0.

WEL_mask 

S1.

BP0_mask 

S2.

BP1_mask 

S3.

BP2_mask 

S4.

TB_mask 

S5.

SEC_mask 

S6.

SRP0_mask 

S7.

WEL_mask 

S1 mask.

◆ statusRegister1_pos

Bit positions for Status Register 1.

Enumerator
BUSY_pos 

S0.

WEL_pos 

S1.

BP0_pos 

S2.

BP1_pos 

S3.

BP2_pos 

S4.

TB_pos 

S5.

SEC_pos 

S6.

SRP0_pos 

S7.

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 
)

◆ W25Q80DLSNIG_PowerDown()

ca_error W25Q80DLSNIG_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.

◆ W25Q80DLSNIG_ReadStatusRegister1()

ca_error W25Q80DLSNIG_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.

◆ W25Q80DLSNIG_ReleasePowerDown()

ca_error W25Q80DLSNIG_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.

◆ W25Q80DLSNIG_WriteDisable()

ca_error W25Q80DLSNIG_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.

◆ W25Q80DLSNIG_WriteEnable()

ca_error W25Q80DLSNIG_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_w25q80dlsnig.c:81
#define EXTERNAL_FLASH_BASE
Definition: cascoda_bsp_w25q80dlsnig.c:53
#define NUM_OF_BYTES_IN_A_PAGE
Definition: cascoda_bsp_w25q80dlsnig.c:77