Paparazzi UAS  v5.14.0_stable-0-g3f680d1
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 i2c_idle (struct i2c_periph *p)
 Check if I2C bus is idle. More...
 
bool 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)
 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

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(), i2c_thread(), 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

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 316 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_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 337 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_transaction::status, and i2c_transaction::type.

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

+ 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 295 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_transaction::status, and i2c_transaction::type.

Referenced by actuators_bebop_commit(), actuators_disco_commit(), mt9v117_write_patch(), 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 347 of file i2c_arch.c.

References SysTimeTimer, and SysTimeTimerStart.

Referenced by mcu_event().

+ Here is the caller graph for this function:

bool i2c_idle ( struct i2c_periph p)

Check if I2C bus is idle.

Parameters
pi2c peripheral to be used
Returns
TRUE if idle

Check if I2C bus is idle.

Empty, for paparazzi compatibility only

Definition at line 413 of file i2c_arch.c.

References BIT_X_IS_SET_IN_REG, FALSE, I2CIdle, i2c_periph::reg_addr, and i2c_periph::status.

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

+ Here is the caller graph for this function:

void i2c_init ( struct i2c_periph p)

Initialize I2C peripheral.

Definition at line 246 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_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 270 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(), 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:

void i2c_setbitrate ( struct i2c_periph p,
int  bitrate 
)

Set I2C bitrate.

Parameters
pi2c peripheral to be used
bitratebitrate

Set I2C bitrate.

Empty, for paparazzi compatibility only. Bitrate is already set in i2cX_hw_init()

Definition at line 355 of file i2c_arch.c.

References __disable_irq(), __enable_irq(), i2c_idle(), 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 i2c_submit ( struct i2c_periph p,
struct i2c_transaction t 
)

Submit a I2C transaction.

Must be implemented by the underlying architecture

Parameters
pi2c peripheral to be used
ti2c transaction
Returns
TRUE if insertion to the transaction queue succeeded

Submit a I2C transaction.

Provides interface between high-level paparazzi i2c functions (such as i2c_transmit(), i2c_transcieve()) and ChibiOS i2c transmit function i2cMasterTransmitTimeout()

Note that we are using the same buffer for transmit and recevive. It is OK because in i2c transaction is Tx always before Rx.

I2C calls are synchronous, timeout is set to 1/PERIODIC_FREQUENCY seconds TODO: Note that on STM32F1xx such as Lia board I2C bus can easily hang in an interrupt (see issue #531). Use I2C bus with care and caution.

Parameters
[in]ppointer to a i2c_periph struct
[in]tpointer to a i2c_transaction struct

Definition at line 374 of file i2c_arch.c.

References __disable_irq(), __enable_irq(), i2c_thread_t::condition, disableIRQ(), enableIRQ(), i2c_periph::errors, FALSE, i2c_init(), I2C_TRANSACTION_QUEUE_LEN, I2CIdle, I2cSendStart(), I2CTransFailed, I2CTransPending, idx, i2c_periph::init_struct, PPRZ_I2C_SEND_START(), i2c_errors::queue_full_cnt, i2c_transaction::status, i2c_periph::status, i2c_periph::trans, i2c_periph::trans_extract_idx, i2c_periph::trans_insert_idx, TRUE, i2c_periph::watchdog, and WD_DELAY.

Referenced by actuators_asctec_v2_set(), actuators_mkk_v2_set(), actuators_skiron_set(), adxl345_i2c_read(), adxl345_i2c_tx_reg(), ami601_read(), baro_board_read_from_current_register(), baro_board_read_from_register(), baro_board_send_reset(), baro_board_set_current_register(), baro_board_write_to_register(), config_mkk_v2_read_eeprom(), config_mkk_v2_send_eeprom(), event_i2c_abuse_test(), hmc5843_idle_task(), hmc5843_periodic(), hmc58xx_i2c_tx_reg(), hmc58xx_read(), i2c_abuse_send_transaction(), i2c_blocking_receive(), i2c_blocking_transceive(), i2c_blocking_transmit(), i2c_receive(), i2c_transceive(), i2c_transmit(), itg3200_i2c_tx_reg(), itg3200_read(), lsm303dlhc_i2c_read(), lsm303dlhc_i2c_tx_reg(), and send_config().

+ Here is the call graph for this function:

+ 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 280 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(), bmp085_periodic(), bmp085_read_eeprom_calib(), gps_ubx_i2c_periodic(), gps_ubx_i2c_read_event(), humid_sht_event_i2c(), humid_sht_periodic_i2c(), ir_mlx_event(), ir_mlx_periodic(), l3g4200_read(), lidar_sf11_periodic(), 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(), and tmp102_periodic().

+ 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 260 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(), bmp085_event(), bmp085_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(), l3g4200_i2c_tx_reg(), lidar_lite_periodic(), 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(), PCAP01_Control(), pcap01writeRegister(), px4flow_i2c_periodic(), srf08_init(), srf08_initiate_ranging(), srf08_receive(), stop_com(), tmp102_init(), wind_gfi_event(), wind_gfi_periodic(), and writePCAP01_SRAM().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: