CryptoAuthLib
Microchip CryptoAuthentication Library
swi_bitbang_samd21.h File Reference

Hardware Interface Functions - SWI bit-banged. More...

#include "atca_status.h"
#include <delay.h>

Go to the source code of this file.

Data Structures

struct  SWIBuses
 

Macros

#define MAX_SWI_BUSES   36
 SAMD21 xplainned pro has 36 free GPIO pins available. More...
 
Macros for Bit-Banged SWI Timing

Times to drive bits at 230.4 kbps.

#define BIT_DELAY_1L   delay_us(3)
 
#define BIT_DELAY_1H   delay_us(3)
 should be 4.34 us, is 4.05us More...
 
#define BIT_DELAY_5   delay_us(26)
 
#define BIT_DELAY_7   delay_us(34)
 
#define RX_TX_DELAY   delay_us(65)
 
#define START_PULSE_TIME_OUT   (600)
 
#define ZERO_PULSE_TIME_OUT   (40)
 

Functions

void swi_set_pin (uint8_t id)
 Set SWI signal pin. Other functions will use this pin. More...
 
void swi_enable (void)
 Configure GPIO pin for SWI signal as output. More...
 
void swi_disable (void)
 Configure GPIO pin for SWI signal as input. More...
 
void swi_set_signal_pin (uint8_t is_high)
 Set signal pin Low or High. More...
 
void swi_send_wake_token (void)
 Send a Wake Token. More...
 
void swi_send_bytes (uint8_t count, uint8_t *buffer)
 Send a number of bytes.This function should not be called directly ,instead should use hal_swi_send() which call this function. More...
 
void swi_send_byte (uint8_t byte)
 Send one byte. More...
 
ATCA_STATUS swi_receive_bytes (uint8_t count, uint8_t *buffer)
 Receive a number of bytes.This function should not be called directly ,instead should use hal_swi_receive() which call this function. More...
 

Variables

SWIBuses swi_buses_default
 

Detailed Description

Hardware Interface Functions - SWI bit-banged.

Macro Definition Documentation

◆ BIT_DELAY_1H

#define BIT_DELAY_1H   delay_us(3)

should be 4.34 us, is 4.05us

◆ BIT_DELAY_1L

#define BIT_DELAY_1L   delay_us(3)

delay macro for width of one pulse (start pulse or zero pulse) should be 4.34 us, is 4.05 us

◆ BIT_DELAY_5

#define BIT_DELAY_5   delay_us(26)

time to keep pin high for five pulses plus stop bit (used to bit-bang CryptoAuth 'zero' bit) should be 26.04 us, is 26.92 us

◆ BIT_DELAY_7

#define BIT_DELAY_7   delay_us(34)

time to keep pin high for seven bits plus stop bit (used to bit-bang CryptoAuth 'one' bit) should be 34.72 us, is 35.13 us

◆ MAX_SWI_BUSES

#define MAX_SWI_BUSES   36

SAMD21 xplainned pro has 36 free GPIO pins available.

◆ RX_TX_DELAY

#define RX_TX_DELAY   delay_us(65)

turn around time when switching from receive to transmit should be 93 us (Setting little less value as there would be other process before these steps)

◆ START_PULSE_TIME_OUT

#define START_PULSE_TIME_OUT   (600)

Lets set the timeout value for start pulse detection to the uint8_t maximum. This value is decremented while waiting for the falling edge of a start pulse.

◆ ZERO_PULSE_TIME_OUT

#define ZERO_PULSE_TIME_OUT   (40)

Maximum time between rising edge of start pulse and falling edge of zero pulse is 8.6 us. Therefore, a value of 40 (around 15 us) gives ample time to detect a zero pulse and also leaves enough time to detect the following start pulse. This value is decremented while waiting for the falling edge of a zero pulse.

Function Documentation

◆ swi_disable()

void swi_disable ( void  )

Configure GPIO pin for SWI signal as input.

◆ swi_enable()

void swi_enable ( void  )

Configure GPIO pin for SWI signal as output.

◆ swi_receive_bytes()

ATCA_STATUS swi_receive_bytes ( uint8_t  count,
uint8_t *  buffer 
)

Receive a number of bytes.This function should not be called directly ,instead should use hal_swi_receive() which call this function.

Parameters
[in]countnumber of bytes to receive
[out]bufferpointer to receive buffer
Returns
ATCA_SUCCESS on success, otherwise an error code.

Receive bits and store in buffer.

Detect start bit.

Wait for falling edge.

Wait for rising edge.

let's just wait the maximum time for the falling edge of a zero bit to arrive after we have detected the rising edge of the start bit.




Detect possible edge indicating zero bit.

Wait for rising edge of zero pulse before returning. Otherwise we might interpret its rising edge as the next start pulse.


Update byte at current buffer index.

received "one" bit

Indicate that we timed out after having received at least one byte.

◆ swi_send_byte()

void swi_send_byte ( uint8_t  byte)

Send one byte.

Parameters
[in]bytebyte to send

◆ swi_send_bytes()

void swi_send_bytes ( uint8_t  count,
uint8_t *  buffer 
)

Send a number of bytes.This function should not be called directly ,instead should use hal_swi_send() which call this function.

Parameters
[in]countnumber of bytes to send.
[in]bufferpointer to buffer containing bytes to send

< Send Logic 1 (7F)

< Send Logic 0 (7D)

◆ swi_send_wake_token()

void swi_send_wake_token ( void  )

Send a Wake Token.

◆ swi_set_pin()

void swi_set_pin ( uint8_t  id)

Set SWI signal pin. Other functions will use this pin.

Parameters
[in]iddefinition of GPIO pin to be used

◆ swi_set_signal_pin()

void swi_set_signal_pin ( uint8_t  is_high)

Set signal pin Low or High.

Parameters
[in]is_high0: Low, else: High.

Variable Documentation

◆ swi_buses_default

SWIBuses swi_buses_default