Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
I2C Interface
+ Collaboration diagram for I2C Interface:

Data Structures

struct  i2c_transaction
 I2C transaction structure. More...
 
struct  i2c_periph
 I2C peripheral structure. More...
 
struct  i2c_errors
 I2C errors counter. More...
 

Macros

#define I2C_BUF_LEN   32
 I2C buffer length. More...
 
#define I2C_TRANSACTION_QUEUE_LEN   8
 I2C transaction queue length. More...
 
#define ZEROS_ERR_COUNTER(_i2c_err)
 

Enumerations

enum  I2CTransactionType { I2CTransTx, I2CTransRx, I2CTransTxRx }
 I2C transaction type. More...
 
enum  I2CTransactionStatus {
  I2CTransPending, I2CTransRunning, I2CTransSuccess, I2CTransFailed,
  I2CTransDone
}
 I2C transaction status. More...
 
enum  I2CStatus {
  I2CIdle, I2CStartRequested, I2CAddrWrSent, I2CAddrRdSent,
  I2CSendingByte, I2CReadingByte, I2CReadingLastByte, I2CStopRequested,
  I2CRestartRequested, I2CComplete, I2CFailed
}
 I2C peripheral status. More...
 

Functions

void i2c_init (struct i2c_periph *p)
 Initialize I2C peripheral. More...
 
bool_t i2c_idle (struct i2c_periph *p)
 Check if I2C bus is idle. More...
 
bool_t i2c_submit (struct i2c_periph *p, struct i2c_transaction *t)
 Submit a I2C transaction. More...
 
void i2c_setbitrate (struct i2c_periph *p, int bitrate)
 Set I2C bitrate. More...
 
void i2c_event (void)
 
bool_t i2c_transmit (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
 Submit a write only transaction. More...
 
bool_t i2c_receive (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
 Submit a read only transaction. More...
 
bool_t i2c_transceive (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
 Submit a write/read transaction. More...
 

Detailed Description


Data Structure Documentation

struct i2c_transaction

I2C transaction structure.

Use this structure to store a request of I2C transaction and submit it using one of the convenience functions (i2c_receive, i2c_transmit or i2c_transceive) or the i2c_submit function.

Definition at line 93 of file i2c.h.

Data Fields
volatile uint8_t buf[I2C_BUF_LEN] Transaction buffer With I2C_BUF_LEN number of bytes.

Must be able to hold tranmitted + received bytes.

uint16_t len_r Number of bytes to read/receive.

Always set by i2c_receive, i2c_transmit and i2c_transceive, needs to be manually set if using i2c_submit.

uint8_t len_w Number of bytes to write/transmit.

Always set by i2c_receive, i2c_transmit and i2c_transceive, needs to be manually set if using i2c_submit.

uint8_t slave_addr Slave address.

Always set by i2c_receive, i2c_transmit and i2c_transceive, needs to be manually set if using i2c_submit.

enum I2CTransactionStatus status Transaction status.
enum I2CTransactionType type Transaction type.

Always set by i2c_receive, i2c_transmit and i2c_transceive, needs to be manually set every time if using i2c_submit.

struct i2c_periph

I2C peripheral structure.

Definition at line 138 of file i2c.h.

+ Collaboration diagram for i2c_periph:
Data Fields
struct i2c_errors * errors
volatile uint8_t idx_buf
void * init_struct
void * reg_addr
enum I2CStatus status
struct i2c_transaction * trans[I2C_TRANSACTION_QUEUE_LEN]
uint8_t trans_extract_idx
uint8_t trans_insert_idx
volatile int16_t watchdog
struct i2c_errors

I2C errors counter.

Definition at line 154 of file i2c.h.

Data Fields
volatile uint16_t ack_fail_cnt
volatile uint16_t arb_lost_cnt
volatile uint32_t er_irq_cnt
volatile uint32_t last_unexpected_event
volatile uint16_t miss_start_stop_cnt
volatile uint16_t over_under_cnt
volatile uint16_t pec_recep_cnt
volatile uint16_t queue_full_cnt
volatile uint16_t smbus_alert_cnt
volatile uint16_t timeout_tlow_cnt
volatile uint16_t unexpected_event_cnt
volatile uint16_t wd_reset_cnt

Macro Definition Documentation

#define I2C_BUF_LEN   32

I2C buffer length.

Number of bytes a transaction can hold.

Definition at line 84 of file i2c.h.

#define I2C_TRANSACTION_QUEUE_LEN   8

I2C transaction queue length.

Number of transactions that can be queued.

Definition at line 133 of file i2c.h.

Referenced by i2c_irq(), i2c_submit(), and I2cEndOfTransaction().

#define ZEROS_ERR_COUNTER (   _i2c_err)
Value:
{ \
_i2c_err.wd_reset_cnt = 0; \
_i2c_err.queue_full_cnt = 0; \
_i2c_err.ack_fail_cnt = 0; \
_i2c_err.miss_start_stop_cnt = 0; \
_i2c_err.arb_lost_cnt = 0; \
_i2c_err.over_under_cnt = 0; \
_i2c_err.pec_recep_cnt = 0; \
_i2c_err.timeout_tlow_cnt = 0; \
_i2c_err.smbus_alert_cnt = 0; \
_i2c_err.unexpected_event_cnt = 0; \
_i2c_err.last_unexpected_event = 0; \
_i2c_err.er_irq_cnt = 0; \
}

Definition at line 170 of file i2c.h.

Enumeration Type Documentation

enum I2CStatus

I2C peripheral status.

Used by each architecture specifc implementation.

Enumerator
I2CIdle 
I2CStartRequested 
I2CAddrWrSent 
I2CAddrRdSent 
I2CSendingByte 
I2CReadingByte 
I2CReadingLastByte 
I2CStopRequested 
I2CRestartRequested 
I2CComplete 
I2CFailed 

Definition at line 65 of file i2c.h.

I2C transaction status.

Enumerator
I2CTransPending 

transaction is pending in queue

I2CTransRunning 

transaction is currently ongoing

I2CTransSuccess 

transaction successfully finished by I2C driver

I2CTransFailed 

transaction failed

I2CTransDone 

transaction set to done by user level

Definition at line 54 of file i2c.h.

I2C transaction type.

Enumerator
I2CTransTx 

transmit only transaction

I2CTransRx 

receive only transaction

I2CTransTxRx 

transmit and receive transaction

Definition at line 46 of file i2c.h.

Function Documentation

void i2c_event ( void  )

Definition at line 37 of file i2c_arch.c.

References SysTimeTimer, and SysTimeTimerStart.

Referenced by mcu_event().

+ Here is the caller graph for this function:

bool_t i2c_idle ( struct i2c_periph p)

Check if I2C bus is idle.

Parameters
pi2c peripheral to be used
Returns
TRUE if idle

Definition at line 45 of file i2c_arch.c.

References BIT_X_IS_SET_IN_REG, FALSE, I2CIdle, if(), i2c_periph::reg_addr, i2c_periph::status, and TRUE.

Referenced by baro_periodic(), event_i2c_abuse_test(), hmc5843_idle_task(), hmc5843_periodic(), and i2c_setbitrate().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void i2c_init ( struct i2c_periph p)

Initialize I2C peripheral.

Definition at line 245 of file i2c.c.

References DefaultPeriodic, I2CIdle, register_periodic_telemetry(), i2c_periph::status, i2c_periph::trans_extract_idx, and i2c_periph::trans_insert_idx.

+ Here is the call graph for this function:

bool_t i2c_receive ( struct i2c_periph p,
struct i2c_transaction t,
uint8_t  s_addr,
uint16_t  len 
)

Submit a read only transaction.

Convenience function which is usually preferred over i2c_submit, as it explicitly sets the transaction type again.

Parameters
pi2c peripheral to be used
ti2c transaction
s_addrslave address
lennumber of bytes to receive
Returns
TRUE if insertion to the transaction queue succeded

Definition at line 268 of file i2c.c.

References i2c_submit(), I2CTransRx, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::slave_addr, and i2c_transaction::type.

Referenced by actuators_asctec_v2_set(), airspeed_amsys_read_periodic(), airspeed_ets_read_periodic(), ArduIMU_periodic(), baro_amsys_read_periodic(), baro_ets_read_periodic(), baro_hca_read_periodic(), charge_sens_periodic(), dpicco_periodic(), dust_gp2y_periodic(), ezcurrent_read_periodic(), geiger_counter_periodic(), humid_htm_read(), humid_sht_p_humid(), humid_sht_p_temp(), infrared_i2c_hor_event(), infrared_i2c_update(), MPPT_periodic(), ms45xx_i2c_periodic(), srf08_read(), temod_periodic(), and wind_gfi_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void i2c_setbitrate ( struct i2c_periph p,
int  bitrate 
)

Set I2C bitrate.

Parameters
pi2c peripheral to be used
bitratebitrate

Definition at line 41 of file i2c_arch.c.

References __disable_irq(), __enable_irq(), i2c_idle(), if(), LED1_OFF(), LED1_ON(), LED2_OFF(), LED2_ON(), and i2c_periph::reg_addr.

Referenced by event_i2c_abuse_test().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool_t i2c_transceive ( struct i2c_periph p,
struct i2c_transaction t,
uint8_t  s_addr,
uint8_t  len_w,
uint16_t  len_r 
)

Submit a write/read transaction.

Convenience function which is usually preferred over i2c_submit, as it explicitly sets the transaction type again.

Parameters
pi2c peripheral to be used
ti2c transaction
s_addrslave address
len_wnumber of bytes to transmit
len_rnumber of bytes to receive
Returns
TRUE if insertion to the transaction queue succeded

Definition at line 278 of file i2c.c.

References i2c_submit(), I2CTransTxRx, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::slave_addr, and i2c_transaction::type.

Referenced by actuators_bebop_commit(), ads1114_read(), ak8963_event(), ak8963_read(), atmega_i2c_cam_ctrl_send(), baro_scp_event(), baro_scp_periodic(), bmp085_periodic(), bmp085_read_eeprom_calib(), humid_sht_event_i2c(), humid_sht_periodic_i2c(), imu_periodic(), ir_mlx_event(), ir_mlx_periodic(), l3g4200_read(), lm75_periodic(), mpl3115_read(), mpu60x0_i2c_read(), mpu9250_i2c_read(), ms5611_i2c_event(), ms5611_i2c_periodic_check(), pbn_periodic(), pcap01readRegister(), readPCAP01_SRAM(), srf08_read_register(), and tmp102_periodic().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool_t i2c_transmit ( struct i2c_periph p,
struct i2c_transaction t,
uint8_t  s_addr,
uint8_t  len 
)