Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / pios / inc / pios_i2c.h
blob2f5a99e12a4d60b94e791ba8fc38564b8bb212b4
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_I2C I2C Functions
6 * @{
8 * @file pios_i2c.h
9 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
10 * @brief I2C functions header.
11 * @see The GNU Public License (GPL) Version 3
13 *****************************************************************************/
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #ifndef PIOS_I2C_H
31 #define PIOS_I2C_H
33 #define PIOS_I2C_DIAGNOSTICS
35 #include <stdbool.h>
37 /* Global Types */
38 enum pios_i2c_txn_direction {
39 PIOS_I2C_TXN_READ,
40 PIOS_I2C_TXN_WRITE
43 struct pios_i2c_txn {
44 const char *info;
45 uint16_t addr;
46 enum pios_i2c_txn_direction rw;
47 uint32_t len;
48 uint8_t *buf;
51 #define I2C_LOG_DEPTH 20
52 enum pios_i2c_error_type {
53 PIOS_I2C_ERROR_EVENT,
54 PIOS_I2C_ERROR_FSM,
55 PIOS_I2C_ERROR_INTERRUPT
58 struct pios_i2c_fault_history {
59 enum pios_i2c_error_type type;
60 uint32_t evirq[I2C_LOG_DEPTH];
61 uint32_t erirq[I2C_LOG_DEPTH];
62 uint8_t event[I2C_LOG_DEPTH];
63 uint8_t state[I2C_LOG_DEPTH];
66 enum pios_i2c_error_count {
67 PIOS_I2C_BAD_EVENT_COUNTER,
68 PIOS_I2C_FSM_FAULT_COUNT,
69 PIOS_I2C_ERROR_INTERRUPT_COUNTER,
70 PIOS_I2C_NACK_COUNTER,
71 PIOS_I2C_TIMEOUT_COUNTER,
73 PIOS_I2C_ERROR_COUNT_NUMELEM,
76 enum pios_i2c_transfer_result {
77 PIOS_I2C_TRANSFER_OK = 0,
78 PIOS_I2C_TRANSFER_BUSY = -2,
79 PIOS_I2C_TRANSFER_BUS_ERROR = -1,
80 PIOS_I2C_TRANSFER_NACK = -3,
81 PIOS_I2C_TRANSFER_TIMEOUT = -4,
82 PIOS_I2C_TRANSFER_UNSPECIFIED_ERROR = -5,
83 PIOS_I2C_TRANSFER_DEVICE_ERROR = -6,
86 typedef bool (*pios_i2c_callback)(enum pios_i2c_transfer_result result);
88 /* Public Functions */
89 extern int32_t PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns);
90 extern int32_t PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, pios_i2c_callback callback);
91 extern int32_t PIOS_I2C_Transfer_CallbackFromISR(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, pios_i2c_callback callback, bool *woken);
93 extern void PIOS_I2C_EV_IRQ_Handler(uint32_t i2c_id);
94 extern void PIOS_I2C_ER_IRQ_Handler(uint32_t i2c_id);
95 extern void PIOS_I2C_IRQ_Handler(uint32_t i2c_id);
96 extern void PIOS_I2C_GetDiagnostics(struct pios_i2c_fault_history *data, uint8_t *error_counts);
98 #endif /* PIOS_I2C_H */
101 * @}
102 * @}