CryptoAuthLib
Atmel CryptoAuthentication Library
i2c_bitbang_at88ck9000.h File Reference

definitions for bit-banged I2C More...

#include "atca_status.h"
#include "timer_utilities.h"

Go to the source code of this file.

Data Structures

struct  I2CBuses
 

Macros

#define MAX_I2C_BUSES   11
 AT88CK9000 has 11 sets of GPIO pins dedicated for I2C (including 1 for on-board SHA204A) More...
 
#define I2C_ENABLE()    pio_configure_pin(pin_sda, PIO_OUTPUT_0);pio_configure_pin(pin_scl, PIO_OUTPUT_0)
 
#define I2C_DISABLE()    pio_configure_pin(pin_sda, PIO_INPUT);pio_configure_pin(pin_scl, PIO_INPUT)
 
#define I2C_CLOCK_LOW()    pio_set_pin_low(pin_scl)
 
#define I2C_CLOCK_HIGH()    pio_set_pin_high(pin_scl)
 
#define I2C_DATA_LOW()    pio_set_pin_low(pin_sda)
 
#define I2C_DATA_HIGH()    pio_set_pin_high(pin_sda)
 
#define I2C_DATA_IN()    pio_get_pin_value(pin_sda)
 
#define I2C_SET_OUTPUT()    pio_configure_pin(pin_sda, PIO_OUTPUT_0)
 
#define I2C_SET_OUTPUT_HIGH()    I2C_SET_OUTPUT(); I2C_DATA_HIGH()
 
#define I2C_SET_OUTPUT_LOW()    I2C_SET_OUTPUT(); I2C_DATA_LOW()
 
#define I2C_SET_INPUT()    pio_configure_pin(pin_sda, PIO_INPUT)
 
#define DISABLE_INTERRUPT()    cpu_irq_disable()
 
#define ENABLE_INTERRUPT()    cpu_irq_enable()
 
#define I2C_CLOCK_DELAY_WRITE_LOW()   delay_us(1)
 
#define I2C_CLOCK_DELAY_WRITE_HIGH()   delay_us(1)
 
#define I2C_CLOCK_DELAY_READ_LOW()    delay_us(1)
 
#define I2C_CLOCK_DELAY_READ_HIGH()   delay_us(1)
 
#define I2C_CLOCK_DELAY_SEND_ACK()    delay_us(1)
 This delay plus I2C_CLOCK_HIGH and I2C_CLOCK_LOW takes about 1.3 us. More...
 
#define I2C_HOLD_DELAY()    i2c_delay()
 This delay is inserted to make the Start and Stop hold time at least 250 ns. More...
 
#define I2C_ACK_TIMEOUT   (4)
 loop count when waiting for an acknowledgment More...
 

Functions

void i2c_set_pin (uint32_t sda, uint32_t scl)
 Set I2C data and clock pin. Other functions will use these pins. More...
 
void i2c_enable (void)
 Configure GPIO pins for I2C clock and data as output. More...
 
void i2c_disable (void)
 Configure GPIO pins for I2C clock and data as input. More...
 
void i2c_send_start (void)
 Send a START condition. More...
 
void i2c_send_ack (uint8_t ack)
 Send an ACK or NACK (after receive). More...
 
void i2c_send_stop (void)
 Send a STOP condition. More...
 
void i2c_send_wake_token (void)
 Send a Wake Token. More...
 
ATCA_STATUS i2c_send_byte (uint8_t i2c_byte)
 Send one byte. More...
 
ATCA_STATUS i2c_send_bytes (uint8_t count, uint8_t *data)
 Send a number of bytes. More...
 
uint8_t i2c_receive_one_byte (uint8_t ack)
 Receive one byte (MSB first). More...
 
void i2c_receive_byte (uint8_t *data)
 Receive one byte and send ACK. More...
 
void i2c_receive_bytes (uint8_t count, uint8_t *data)
 Receive a number of bytes. More...
 

Variables

I2CBuses i2c_buses_default
 
uint32_t pin_sda
 
uint32_t pin_scl
 

Detailed Description

definitions for bit-banged I2C

Author
Atmel Crypto Group
Date
November 18, 2015

Macro Definition Documentation

#define DISABLE_INTERRUPT ( )    cpu_irq_disable()
#define ENABLE_INTERRUPT ( )    cpu_irq_enable()
#define I2C_ACK_TIMEOUT   (4)

loop count when waiting for an acknowledgment

#define I2C_CLOCK_DELAY_READ_HIGH ( )    delay_us(1)
#define I2C_CLOCK_DELAY_READ_LOW ( )    delay_us(1)
#define I2C_CLOCK_DELAY_SEND_ACK ( )    delay_us(1)

This delay plus I2C_CLOCK_HIGH and I2C_CLOCK_LOW takes about 1.3 us.

#define I2C_CLOCK_DELAY_WRITE_HIGH ( )    delay_us(1)
#define I2C_CLOCK_DELAY_WRITE_LOW ( )    delay_us(1)
#define I2C_CLOCK_HIGH ( )    pio_set_pin_high(pin_scl)
#define I2C_CLOCK_LOW ( )    pio_set_pin_low(pin_scl)
#define I2C_DATA_HIGH ( )    pio_set_pin_high(pin_sda)
#define I2C_DATA_IN ( )    pio_get_pin_value(pin_sda)
#define I2C_DATA_LOW ( )    pio_set_pin_low(pin_sda)
#define I2C_DISABLE ( )    pio_configure_pin(pin_sda, PIO_INPUT);pio_configure_pin(pin_scl, PIO_INPUT)
#define I2C_ENABLE ( )    pio_configure_pin(pin_sda, PIO_OUTPUT_0);pio_configure_pin(pin_scl, PIO_OUTPUT_0)
#define I2C_HOLD_DELAY ( )    i2c_delay()

This delay is inserted to make the Start and Stop hold time at least 250 ns.

#define I2C_SET_INPUT ( )    pio_configure_pin(pin_sda, PIO_INPUT)
#define I2C_SET_OUTPUT ( )    pio_configure_pin(pin_sda, PIO_OUTPUT_0)
#define I2C_SET_OUTPUT_HIGH ( )    I2C_SET_OUTPUT(); I2C_DATA_HIGH()
#define I2C_SET_OUTPUT_LOW ( )    I2C_SET_OUTPUT(); I2C_DATA_LOW()
#define MAX_I2C_BUSES   11

AT88CK9000 has 11 sets of GPIO pins dedicated for I2C (including 1 for on-board SHA204A)

Function Documentation

void i2c_disable ( void  )

Configure GPIO pins for I2C clock and data as input.

void i2c_enable ( void  )

Configure GPIO pins for I2C clock and data as output.

void i2c_receive_byte ( uint8_t *  data)

Receive one byte and send ACK.

Parameters
[out]datapointer to received byte
void i2c_receive_bytes ( uint8_t  count,
uint8_t *  data 
)

Receive a number of bytes.

Parameters
[out]datapointer to receive buffer
[in]countnumber of bytes to receive
uint8_t i2c_receive_one_byte ( uint8_t  ack)

Receive one byte (MSB first).

Parameters
[in]ack0:NACK, else:ACK
Returns
byte received

We don't need to delay after the last bit because it takes time to switch the pin to output for acknowledging.

void i2c_send_ack ( uint8_t  ack)

Send an ACK or NACK (after receive).

Parameters
[in]ack0: NACK, else: ACK

< Low data line indicates an ACK.

< High data line indicates a NACK.

Clock out acknowledgment.

ATCA_STATUS i2c_send_byte ( uint8_t  i2c_byte)

Send one byte.

Parameters
[in]i2c_bytebyte to write
Returns
ATCA_STATUS

This avoids spikes but adds an if condition. We could parametrize the call to I2C_SET_OUTPUT and translate the msb to OUTSET or OUTCLR, but then the code would become target specific.

Send 8 bits of data.

Clock out the data bit.

Shifting while clock is high compensates for the time it takes to evaluate the bit while clock is low. That way, the low and high time of the clock pin is almost equal.

Clock in last data bit.

Set data line to be an input.

Wait for the ack.

ATCA_STATUS i2c_send_bytes ( uint8_t  count,
uint8_t *  data 
)

Send a number of bytes.

Parameters
[in]countnumber of bytes to send
[in]datapointer to buffer containing bytes to send
Returns
ATCA_STATUS
void i2c_send_start ( void  )

Send a START condition.

Set clock high in case we re-start.

void i2c_send_stop ( void  )

Send a STOP condition.

void i2c_send_wake_token ( void  )

Send a Wake Token.

void i2c_set_pin ( uint32_t  sda,
uint32_t  scl 
)

Set I2C data and clock pin. Other functions will use these pins.

Parameters
[in]sdadefinition of GPIO pin to be used as data pin
[in]scldefinition of GPIO pin to be used as clock pin

Variable Documentation

I2CBuses i2c_buses_default
uint32_t pin_scl
uint32_t pin_sda