Atmel Software Framework

twi.c File Reference
#include <avr32/io.h>
#include "compiler.h"
#include "twi.h"

Macros

#define CONF_TWI_IRQ_GROUP   AVR32_TWI_IRQ_GROUP
 
#define CONF_TWI_IRQ_LINE   AVR32_TWI_IRQ
 

Functions

 ISR (twi_master_interrupt_handler, CONF_TWI_IRQ_GROUP, CONF_TWI_IRQ_LEVEL)
 TWI interrupt handler. More...
 
 ISR (twi_slave_interrupt_handler, AVR32_TWI_IRQ_GROUP, CONF_TWI_IRQ_LEVEL)
 TWI interrupt handler. More...
 
void twi_disable_interrupt (volatile avr32_twi_t *twi)
 Disable all TWI interrupts. More...
 
bool twi_is_busy (void)
 Test if a TWI read/write is pending. More...
 
int twi_master_init (volatile avr32_twi_t *twi, const twi_options_t *opt)
 Initialize the twi master module. More...
 
int twi_master_read (volatile avr32_twi_t *twi, const twi_package_t *package)
 Read multiple bytes from a TWI compatible slave device. More...
 
int twi_master_write (volatile avr32_twi_t *twi, const twi_package_t *package)
 Write multiple bytes to a TWI compatible slave device. More...
 
int twi_master_write_ex (volatile avr32_twi_t *twi, const twi_package_t *package)
 This function is not blocking. More...
 
static uint32_t twi_mk_addr (const uint8_t *addr, int len)
 Construct the TWI module address register field. More...
 
int twi_probe (volatile avr32_twi_t *twi, char chip_addr)
 Test if a chip answers for a given twi address. More...
 
static int twi_set_speed (volatile avr32_twi_t *twi, unsigned int speed, unsigned long pba_hz)
 Set the twi bus speed in conjunction with the clock frequency. More...
 
int twi_slave_init (volatile avr32_twi_t *twi, const twi_options_t *opt, const twi_slave_fct_t *slave_fct)
 Initialize the twi slave module. More...
 

Variables

static volatile bool twi_busy = false
 Signal end of transaction. More...
 
static volatile avr32_twi_t * twi_inst
 Pointer to the instance of the TWI registers for IT. More...
 
static volatile unsigned long twi_it_mask
 IT mask. More...
 
static volatile bool twi_nack = false
 Add NACK boolean. More...
 
static volatile unsigned char
*volatile 
twi_rx_data = NULL
 Pointer to the applicative TWI receive buffer. More...
 
static volatile int twi_rx_nb_bytes = 0
 Remaining number of bytes to receive. More...
 
static twi_slave_fct_t twi_slave_fct
 Pointer on TWI slave application routines. More...
 
static const unsigned char
*volatile 
twi_tx_data = NULL
 Pointer to the applicative TWI transmit buffer. More...
 
static volatile int twi_tx_nb_bytes = 0
 Remaining number of bytes to transmit. More...
 

#define CONF_TWI_IRQ_GROUP   AVR32_TWI_IRQ_GROUP
#define CONF_TWI_IRQ_LINE   AVR32_TWI_IRQ

Referenced by twi_master_init(), and twi_slave_init().

ISR ( twi_master_interrupt_handler  ,
CONF_TWI_IRQ_GROUP  ,
CONF_TWI_IRQ_LEVEL   
)
ISR ( twi_slave_interrupt_handler  ,
AVR32_TWI_IRQ_GROUP  ,
CONF_TWI_IRQ_LEVEL   
)
static uint32_t twi_mk_addr ( const uint8_t *  addr,
int  len 
)
static

Construct the TWI module address register field.

The TWI module address register is sent out MSB first. And the size controls which byte is the MSB to start with.

Please see the device datasheet for details on this.

References val.

Referenced by twi_master_read(), twi_master_write(), and twi_master_write_ex().

static int twi_set_speed ( volatile avr32_twi_t *  twi,
unsigned int  speed,
unsigned long  pba_hz 
)
static

Set the twi bus speed in conjunction with the clock frequency.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
speedThe desired twi bus speed
pba_hzThe current running PBA clock frequency
Returns
TWI_SUCCESS

References TWI_SUCCESS.

Referenced by twi_master_init().

volatile bool twi_busy = false
static

Signal end of transaction.

Referenced by ISR(), twi_is_busy(), twi_master_read(), and twi_master_write().

volatile avr32_twi_t* twi_inst
static

Pointer to the instance of the TWI registers for IT.

Referenced by ISR(), twi_master_init(), twi_master_read(), twi_master_write(), twi_master_write_ex(), and twi_slave_init().

volatile unsigned long twi_it_mask
static
volatile bool twi_nack = false
static

Add NACK boolean.

Referenced by ISR(), twi_master_read(), twi_master_write(), and twi_master_write_ex().

volatile unsigned char* volatile twi_rx_data = NULL
static

Pointer to the applicative TWI receive buffer.

Referenced by ISR(), and twi_master_read().

volatile int twi_rx_nb_bytes = 0
static

Remaining number of bytes to receive.

Referenced by ISR(), and twi_master_read().

twi_slave_fct_t twi_slave_fct
static

Pointer on TWI slave application routines.

Referenced by main().

const unsigned char* volatile twi_tx_data = NULL
static

Pointer to the applicative TWI transmit buffer.

Referenced by ISR(), twi_master_write(), and twi_master_write_ex().

volatile int twi_tx_nb_bytes = 0
static

Remaining number of bytes to transmit.

Referenced by ISR(), twi_master_write(), and twi_master_write_ex().