Paparazzi UAS  v5.15_devel-230-gc96ce27
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
 
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)
 

Typedefs

typedef bool i2c_idle_fn_t (struct i2c_periph *p)
 
typedef bool i2c_submit_fn_t (struct i2c_periph *p, struct i2c_transaction *t)
 
typedef void i2c_setbitrate_fn_t (struct i2c_periph *p, int bitrate)
 
typedef void i2c_spin_fn_t (struct i2c_periph *p)
 

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...
 
static bool i2c_idle (struct i2c_periph *p)
 Check if I2C bus is idle. More...
 
static bool i2c_submit (struct i2c_periph *p, struct i2c_transaction *t)
 Submit a I2C transaction. More...
 
static void i2c_setbitrate (struct i2c_periph *p, int bitrate)
 Set I2C bitrate. More...
 
void i2c_event (void)
 i2c_event() function More...
 
bool i2c_transmit (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
 Submit a write only transaction. More...
 
bool i2c_receive (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
 Submit a read only transaction. More...
 
bool 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...
 
bool i2c_blocking_transmit (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
 Submit a write only transaction and wait for it to complete. More...
 
bool i2c_blocking_receive (struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
 Submit a read only transaction and wait for it to complete. More...
 
bool i2c_blocking_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 and wait for it to complete. 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

Definition at line 144 of file i2c.h.

+ Collaboration diagram for i2c_periph:
Data Fields
struct i2c_errors * errors
i2c_idle_fn_t * idle
volatile uint8_t idx_buf
void * init_struct
void * reg_addr
i2c_setbitrate_fn_t * setbitrate
i2c_spin_fn_t * spin
enum I2CStatus status
i2c_submit_fn_t * submit
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 165 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.

Referenced by VL53L1_NonBlocking_ReadMulti(), VL53L1_NonBlocking_WriteMulti(), VL53L1_ReadMulti(), and VL53L1_WriteMulti().

#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_chibios_submit(), i2c_irq(), i2c_linux_submit(), i2c_lpc21_submit(), i2c_thread(), I2cEndOfTransaction(), softi2c_device_event(), and softi2c_submit().

#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 181 of file i2c.h.

Typedef Documentation

typedef bool i2c_idle_fn_t(struct i2c_periph *p)

Definition at line 139 of file i2c.h.

typedef void i2c_setbitrate_fn_t(struct i2c_periph *p, int bitrate)

Definition at line 141 of file i2c.h.

typedef void i2c_spin_fn_t(struct i2c_periph *p)

Definition at line 142 of file i2c.h.

typedef bool i2c_submit_fn_t(struct i2c_periph *p, struct i2c_transaction *t)

Definition at line 140 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

bool i2c_blocking_receive ( struct i2c_periph p,
struct i2c_transaction t,
uint8_t  s_addr,
uint16_t  len 
)

Submit a read only transaction and wait for it to complete.

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 succeeded

Definition at line 381 of file i2c.c.

References get_sys_time_float(), I2C_BLOCKING_TIMEOUT, i2c_submit(), I2CTransPending, I2CTransRunning, I2CTransRx, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::slave_addr, i2c_periph::spin, i2c_transaction::status, and i2c_transaction::type.

+ Here is the call graph for this function:

bool i2c_blocking_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 and wait for it to complete.

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 succeeded

Definition at line 403 of file i2c.c.

References get_sys_time_float(), I2C_BLOCKING_TIMEOUT, i2c_submit(), I2CTransPending, I2CTransRunning, I2CTransTxRx, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::slave_addr, i2c_periph::spin, i2c_transaction::status, and i2c_transaction::type.

Referenced by actuators_bebop_commit(), actuators_disco_commit(), read_reg(), and VL53L1_ReadMulti().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool i2c_blocking_transmit ( struct i2c_periph p,
struct i2c_transaction t,
uint8_t  s_addr,
uint8_t  len 
)

Submit a write only transaction and wait for it to complete.

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 transmit
Returns
TRUE if insertion to the transaction queue succeeded

Definition at line 359 of file i2c.c.

References get_sys_time_float(), I2C_BLOCKING_TIMEOUT, i2c_submit(), I2CTransPending, I2CTransRunning, I2CTransTx, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::slave_addr, i2c_periph::spin, i2c_transaction::status, and i2c_transaction::type.

Referenced by actuators_bebop_commit(), actuators_disco_commit(), mt9v117_write_patch(), pca95x4_configure(), pca95x4_set_output(), VL53L1_WriteMulti(), and write_reg().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void i2c_event ( void  )

i2c_event() function

Empty, for paparazzi compatibility only

Definition at line 428 of file i2c_arch.c.

References SysTimeTimer, and SysTimeTimerStart.

Referenced by mcu_event().

+ Here is the caller graph for this function:

static bool i2c_idle ( struct i2c_periph p)
inlinestatic

Check if I2C bus is idle.

Parameters
pi2c peripheral to be used
Returns
TRUE if idle

Definition at line 256 of file i2c.h.

References i2c_periph::idle.

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

+ Here is the caller graph for this function:

void i2c_init ( struct i2c_periph p)

Initialize I2C peripheral.

Definition at line 310 of file i2c.c.

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

Referenced by i2c_chibios_submit().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool 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 succeeded

Definition at line 334 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(), lidar_lite_periodic(), MPPT_periodic(), ms45xx_i2c_periodic(), sdp3x_periodic(), srf08_read(), temod_periodic(), teraranger_periodic(), and wind_gfi_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void i2c_setbitrate ( struct i2c_periph p,
int  bitrate 
)
inlinestatic

Set I2C bitrate.

Parameters
pi2c peripheral to be used
bitratebitrate

Definition at line 274 of file i2c.h.

References i2c_periph::setbitrate.

Referenced by event_i2c_abuse_test().

+ Here is the caller graph for this function:

bool 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 succeeded

Definition at line 344 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_md25_periodic(), ads1114_read(), ak8963_event(), ak8963_read(), ak8975_configure(), ak8975_event(), atmega_i2c_cam_ctrl_send(), baro_scp_event(), baro_scp_periodic(), battery_monitor_read_balance_ports(), battery_monitor_read_bus(), bmi088_i2c_read(), bmp085_periodic(), bmp085_read_eeprom_calib(), bmp3_i2c_periodic(), gps_ubx_i2c_periodic(), gps_ubx_i2c_read_event(), humid_sht_event_i2c(), humid_sht_periodic_i2c(), ir_mlx_event(), ir_mlx_periodic(), ist8310_event(), ist8310_read(), l3g4200_read(), lidar_sf11_periodic(), lis3mdl_read(), lm75_periodic(), mpl3115_read(), mpu60x0_i2c_read(), mpu9250_i2c_read(), ms5611_i2c_event(), ms5611_i2c_periodic_check(), pcap01readRegister(), px4flow_i2c_periodic(), readPCAP01_SRAM(), srf08_read_register(), tmp102_periodic(), and VL53L1_NonBlocking_ReadMulti().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Submit a write 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 transmit
Returns
TRUE if insertion to the transaction queue succeeded

Definition at line 324 of file i2c.c.

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

Referenced by actuators_asctec_set(), actuators_asctec_v2_set(), actuators_md25_periodic(), actuators_md25_set(), actuators_mkk_set(), ads1114_init(), ak8963_configure(), ak8975_configure(), ak8975_read(), ArduIMU_periodicGPS(), baro_scp_start_high_res_measurement(), bmi088_i2c_write_to_reg(), bmp085_event(), bmp085_periodic(), bmp3_i2c_periodic(), generic_com_periodic(), gps_ubx_i2c_periodic(), humid_htm_start(), humid_sht_event_i2c(), humid_sht_periodic_i2c(), infrared_i2c_hor_event(), infrared_i2c_update(), ir_mlx_periodic(), ist8310_configure(), l3g4200_i2c_tx_reg(), lidar_lite_periodic(), lis3mdl_configure(), mpl3115_read(), mpl3115_send_config(), MPPT_ask(), MPPT_periodic(), mpu60x0_i2c_write_to_reg(), mpu9250_i2c_write_to_reg(), ms5611_i2c_event(), ms5611_i2c_start_configure(), ms5611_i2c_start_conversion(), pca95x4_configure(), pca95x4_set_output(), PCAP01_Control(), pcap01writeRegister(), px4flow_i2c_periodic(), sdp3x_periodic(), srf08_init(), srf08_initiate_ranging(), srf08_receive(), stop_com(), tmp102_init(), VL53L1_NonBlocking_WriteMulti(), wind_gfi_event(), wind_gfi_periodic(), and writePCAP01_SRAM().

+ Here is the call graph for this function: