Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_chili_secure.c File Reference
#include <stdio.h>
#include "M2351.h"
#include "eadc.h"
#include "fmc.h"
#include "gpio.h"
#include "spi.h"
#include "sys.h"
#include "timer.h"
#include "usbd.h"
#include "cascoda_chili.h"
#include "cascoda-bm/cascoda_interface.h"
#include "cascoda-bm/cascoda_types.h"
#include "cascoda-bm/cascoda_usbhid.h"
#include "cascoda_chili_config.h"
#include "cascoda_chili_gpio.h"
#include "cascoda_chili_usb.h"
#include "cascoda_secure.h"
Include dependency graph for cascoda_chili_secure.c:

Macros

#define CLKCFG_ENPLL   0x01
 
#define CLKCFG_ENHXT   0x02
 
#define CLKCFG_ENHIRC   0x04
 
#define CLKCFG_ENHIRC48   0x08
 
#define EP0_MAX_PKT_SIZE   HID_CTRL_MAX_SIZE
 
#define EP1_MAX_PKT_SIZE   EP0_MAX_PKT_SIZE
 
#define EP2_MAX_PKT_SIZE   HID_FRAGMENT_SIZE
 
#define EP3_MAX_PKT_SIZE   HID_FRAGMENT_SIZE
 
#define SETUP_BUF_BASE   0
 
#define SETUP_BUF_LEN   8
 
#define EP0_BUF_BASE   (SETUP_BUF_BASE + SETUP_BUF_LEN)
 
#define EP0_BUF_LEN   EP0_MAX_PKT_SIZE
 
#define EP1_BUF_BASE   (SETUP_BUF_BASE + SETUP_BUF_LEN)
 
#define EP1_BUF_LEN   EP1_MAX_PKT_SIZE
 
#define EP2_BUF_BASE   (EP1_BUF_BASE + EP1_BUF_LEN)
 
#define EP2_BUF_LEN   EP2_MAX_PKT_SIZE
 
#define EP3_BUF_BASE   (EP2_BUF_BASE + EP2_BUF_LEN)
 
#define EP3_BUF_LEN   EP3_MAX_PKT_SIZE
 
#define TBUFFS   (8) /* Number of HID transmit buffers */
 
#define RBUFFS   (8) /* Number of HID receive buffers */
 

Functions

__NONSECURE_ENTRY ca_error BSP_SetBootMode (sysreset_mode bootMode)
 Set the default boot mode for the device. More...
 
__NONSECURE_ENTRY void CHILI_InitADC (u32_t reference)
 Initialise ADC peripheral. More...
 
__NONSECURE_ENTRY void CHILI_DeinitADC ()
 Deinitialise ADC peripheral. More...
 
__NONSECURE_ENTRY void CHILI_GPIOInitClock ()
 Initialise GPIO peripheral clock. More...
 
__NONSECURE_ENTRY void CHILI_SetClockExternalCFGXT1 (u8_t clk_external)
 Configure CFGXT1 bit for HXT mode in CONFIG0. More...
 
u8_t CHILI_GetClockConfigMask (fsys_mhz fsys, u8_t enable_comms)
 System Clock. More...
 
__NONSECURE_ENTRY ca_error CHILI_ClockInit (fsys_mhz fsys, u8_t enable_comms)
 Select System Clocks depending on Power Source. More...
 
__NONSECURE_ENTRY void CHILI_SetSysTickFreq (uint32_t freqHz)
 Set the SysTick frequency in Hz. More...
 
__NONSECURE_ENTRY void CHILI_CompleteClockInit (fsys_mhz fsys, u8_t enable_comms)
 Completes Clock (Re-)Initialisation. More...
 
__NONSECURE_ENTRY void CHILI_EnableIntOscCal (void)
 Enable Internal Oscillator Calibration. More...
 
__NONSECURE_ENTRY void CHILI_DisableIntOscCal (void)
 Disable Internal Oscillator Calibration. More...
 
__NONSECURE_ENTRY void CHILI_TimersInit (void)
 (Re-)Initialise System Timers More...
 
__NONSECURE_ENTRY void CHILI_PDMAInit (void)
 Initialise PDMA. More...
 
__NONSECURE_ENTRY void CHILI_ReInitSetTimerPriority ()
 Initialise Timer IRQ priorities. More...
 
int32_t SH_Return (int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
 
__NONSECURE_ENTRY uint32_t HardFault_Handler (uint32_t lr, uint32_t msp, uint32_t psp)
 
__NONSECURE_ENTRY void ProcessHardFault ()
 
__NONSECURE_ENTRY void CHILI_CRYPTOEnableClock (void)
 Enable CRYPTO Module clock. More...
 
__NONSECURE_ENTRY void CHILI_CRYPTODisableClock (void)
 Disable CRYPTO Module clock. More...
 
__NONSECURE_ENTRY void CHILI_ModuleSetMFP (enPortnum portnum, u8_t portbit, u8_t func)
 Sets MFP Functionality. More...
 
__NONSECURE_ENTRY void CHILI_EnableTemperatureSensor ()
 Enable internal temperature sensor. More...
 
__NONSECURE_ENTRY void CHILI_DisableTemperatureSensor ()
 Disable internal temperature sensor. More...
 
__NONSECURE_ENTRY void CHILI_PowerDownSelectClock (u8_t use_timer0)
 Configure clock for power down. More...
 
__NONSECURE_ENTRY u32_t CHILI_PowerDownSecure (u32_t sleeptime_ms, u8_t use_timer0, dpd_flag dpd)
 Process all of the secure-only power down routines. More...
 
__NONSECURE_ENTRY void CHILI_SetWakeup (u8_t new_wakeup)
 Set wake up state. More...
 
__NONSECURE_ENTRY u8_t CHILI_GetWakeup ()
 Should the Chili wake up? More...
 
__NONSECURE_ENTRY void CHILI_SetAsleep (u8_t new_asleep)
 Set asleep state. More...
 
__NONSECURE_ENTRY u8_t CHILI_GetAsleep ()
 Is chili currently asleep? More...
 
__NONSECURE_ENTRY void CHILI_SetGPIOInt (u8_t new_gpioint)
 Set gpio interrrupt occured during power-down sequence flag. More...
 
__NONSECURE_ENTRY u8_t CHILI_GetGPIOInt ()
 Has gpio interrupt occured during power-down sequence? More...
 
__NONSECURE_ENTRY void CHILI_SetPowerDown (u8_t new_powerdown)
 Set power-down flag. More...
 
__NONSECURE_ENTRY u8_t CHILI_GetPowerDown (void)
 Get power-down flag (device is powering down) ? More...
 
__NONSECURE_ENTRY void CHILI_WaitForSystemStable (void)
 Wait until system is stable after potential usb plug-in. More...
 
__NONSECURE_ENTRY void BSP_WaitUs (u32_t us)
 Wait for specified Time in Microseconds (max. More...
 
__NONSECURE_ENTRY void CHILI_EnableTRNGClk (void)
 Enable the TRNG Module Clock. More...
 
__NONSECURE_ENTRY void CHILI_DisableTRNGClk (void)
 Disable the TRNG Module Clock. More...
 

Macro Definition Documentation

◆ CLKCFG_ENHIRC

#define CLKCFG_ENHIRC   0x04

◆ CLKCFG_ENHIRC48

#define CLKCFG_ENHIRC48   0x08

◆ CLKCFG_ENHXT

#define CLKCFG_ENHXT   0x02

◆ CLKCFG_ENPLL

#define CLKCFG_ENPLL   0x01

◆ EP0_BUF_BASE

#define EP0_BUF_BASE   (SETUP_BUF_BASE + SETUP_BUF_LEN)

◆ EP0_BUF_LEN

#define EP0_BUF_LEN   EP0_MAX_PKT_SIZE

◆ EP0_MAX_PKT_SIZE

#define EP0_MAX_PKT_SIZE   HID_CTRL_MAX_SIZE

◆ EP1_BUF_BASE

#define EP1_BUF_BASE   (SETUP_BUF_BASE + SETUP_BUF_LEN)

◆ EP1_BUF_LEN

#define EP1_BUF_LEN   EP1_MAX_PKT_SIZE

◆ EP1_MAX_PKT_SIZE

#define EP1_MAX_PKT_SIZE   EP0_MAX_PKT_SIZE

◆ EP2_BUF_BASE

#define EP2_BUF_BASE   (EP1_BUF_BASE + EP1_BUF_LEN)

◆ EP2_BUF_LEN

#define EP2_BUF_LEN   EP2_MAX_PKT_SIZE

◆ EP2_MAX_PKT_SIZE

#define EP2_MAX_PKT_SIZE   HID_FRAGMENT_SIZE

◆ EP3_BUF_BASE

#define EP3_BUF_BASE   (EP2_BUF_BASE + EP2_BUF_LEN)

◆ EP3_BUF_LEN

#define EP3_BUF_LEN   EP3_MAX_PKT_SIZE

◆ EP3_MAX_PKT_SIZE

#define EP3_MAX_PKT_SIZE   HID_FRAGMENT_SIZE

◆ RBUFFS

#define RBUFFS   (8) /* Number of HID receive buffers */

◆ SETUP_BUF_BASE

#define SETUP_BUF_BASE   0

◆ SETUP_BUF_LEN

#define SETUP_BUF_LEN   8

◆ TBUFFS

#define TBUFFS   (8) /* Number of HID transmit buffers */

Function Documentation

◆ CHILI_ClockInit()

__NONSECURE_ENTRY ca_error CHILI_ClockInit ( fsys_mhz  fsys,
u8_t  enable_comms 
)

Select System Clocks depending on Power Source.

◆ CHILI_CompleteClockInit()

__NONSECURE_ENTRY void CHILI_CompleteClockInit ( fsys_mhz  fsys,
u8_t  enable_comms 
)

Completes Clock (Re-)Initialisation.

◆ CHILI_CRYPTODisableClock()

__NONSECURE_ENTRY void CHILI_CRYPTODisableClock ( void  )

Disable CRYPTO Module clock.

◆ CHILI_CRYPTOEnableClock()

__NONSECURE_ENTRY void CHILI_CRYPTOEnableClock ( void  )

Enable CRYPTO Module clock.

◆ CHILI_DeinitADC()

__NONSECURE_ENTRY void CHILI_DeinitADC ( )

Deinitialise ADC peripheral.

◆ CHILI_DisableIntOscCal()

__NONSECURE_ENTRY void CHILI_DisableIntOscCal ( void  )

Disable Internal Oscillator Calibration.

◆ CHILI_DisableTemperatureSensor()

__NONSECURE_ENTRY void CHILI_DisableTemperatureSensor ( )

Disable internal temperature sensor.

◆ CHILI_DisableTRNGClk()

__NONSECURE_ENTRY void CHILI_DisableTRNGClk ( void  )

Disable the TRNG Module Clock.

◆ CHILI_EnableIntOscCal()

__NONSECURE_ENTRY void CHILI_EnableIntOscCal ( void  )

Enable Internal Oscillator Calibration.

◆ CHILI_EnableTemperatureSensor()

__NONSECURE_ENTRY void CHILI_EnableTemperatureSensor ( )

Enable internal temperature sensor.

◆ CHILI_EnableTRNGClk()

__NONSECURE_ENTRY void CHILI_EnableTRNGClk ( void  )

Enable the TRNG Module Clock.

◆ CHILI_GetAsleep()

__NONSECURE_ENTRY u8_t CHILI_GetAsleep ( )

Is chili currently asleep?

◆ CHILI_GetClockConfigMask()

u8_t CHILI_GetClockConfigMask ( fsys_mhz  fsys,
u8_t  enable_comms 
)

System Clock.

◆ CHILI_GetGPIOInt()

__NONSECURE_ENTRY u8_t CHILI_GetGPIOInt ( )

Has gpio interrupt occured during power-down sequence?

◆ CHILI_GetPowerDown()

__NONSECURE_ENTRY u8_t CHILI_GetPowerDown ( void  )

Get power-down flag (device is powering down) ?

◆ CHILI_GetWakeup()

__NONSECURE_ENTRY u8_t CHILI_GetWakeup ( )

Should the Chili wake up?

◆ CHILI_GPIOInitClock()

__NONSECURE_ENTRY void CHILI_GPIOInitClock ( )

Initialise GPIO peripheral clock.

◆ CHILI_InitADC()

__NONSECURE_ENTRY void CHILI_InitADC ( u32_t  reference)

Initialise ADC peripheral.

◆ CHILI_ModuleSetMFP()

__NONSECURE_ENTRY void CHILI_ModuleSetMFP ( enPortnum  portnum,
u8_t  portbit,
u8_t  func 
)

Sets MFP Functionality.

Parameters
portnum- returned port number
portbit- returned port b
func- function to set the pin to

◆ CHILI_PDMAInit()

__NONSECURE_ENTRY void CHILI_PDMAInit ( void  )

Initialise PDMA.

◆ CHILI_PowerDownSecure()

__NONSECURE_ENTRY u32_t CHILI_PowerDownSecure ( u32_t  sleeptime_ms,
u8_t  use_timer0,
dpd_flag  dpd 
)

Process all of the secure-only power down routines.

◆ CHILI_PowerDownSelectClock()

__NONSECURE_ENTRY void CHILI_PowerDownSelectClock ( u8_t  use_timer0)

Configure clock for power down.

◆ CHILI_ReInitSetTimerPriority()

__NONSECURE_ENTRY void CHILI_ReInitSetTimerPriority ( )

Initialise Timer IRQ priorities.

◆ CHILI_SetAsleep()

__NONSECURE_ENTRY void CHILI_SetAsleep ( u8_t  new_asleep)

Set asleep state.

◆ CHILI_SetClockExternalCFGXT1()

__NONSECURE_ENTRY void CHILI_SetClockExternalCFGXT1 ( u8_t  clk_external)

Configure CFGXT1 bit for HXT mode in CONFIG0.

This isn't specifically related to dataflash, but in order to set the clock on the M2351, the config is loaded into the flash.

Parameters
clk_external- 1: external clock input on HXT, 0: HXT is crystal osc.

◆ CHILI_SetGPIOInt()

__NONSECURE_ENTRY void CHILI_SetGPIOInt ( u8_t  new_gpioint)

Set gpio interrrupt occured during power-down sequence flag.

◆ CHILI_SetPowerDown()

__NONSECURE_ENTRY void CHILI_SetPowerDown ( u8_t  new_powerdown)

Set power-down flag.

◆ CHILI_SetSysTickFreq()

__NONSECURE_ENTRY void CHILI_SetSysTickFreq ( uint32_t  freqHz)

Set the SysTick frequency in Hz.

Parameters
freqHzFrequency of the system tick in Hz, or 0 to disable

◆ CHILI_SetWakeup()

__NONSECURE_ENTRY void CHILI_SetWakeup ( u8_t  new_wakeup)

Set wake up state.

◆ CHILI_TimersInit()

__NONSECURE_ENTRY void CHILI_TimersInit ( void  )

(Re-)Initialise System Timers

◆ CHILI_WaitForSystemStable()

__NONSECURE_ENTRY void CHILI_WaitForSystemStable ( void  )

Wait until system is stable after potential usb plug-in.

◆ HardFault_Handler()

__NONSECURE_ENTRY uint32_t HardFault_Handler ( uint32_t  lr,
uint32_t  msp,
uint32_t  psp 
)

◆ ProcessHardFault()

__NONSECURE_ENTRY void ProcessHardFault ( void  )

◆ SH_Return()

int32_t SH_Return ( int32_t  n32In_R0,
int32_t  n32In_R1,
int32_t *  pn32Out_R0 
)