dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_i2c_priv.h
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 #ifndef PIOS_I2C_PRIV_H
27 #define PIOS_I2C_PRIV_H
28 
29 #include <pios.h>
30 #include <pios_stm32.h>
31 #include <stdbool.h>
32 #include "pios_semaphore.h"
33 #include "pios_mutex.h"
34 #include <inttypes.h>
35 
37  I2C_TypeDef *regs;
38  uint32_t remap;
39  I2C_InitTypeDef init;
40 
42  struct stm32_gpio scl;
43  struct stm32_gpio sda;
44  struct stm32_irq event;
45  struct stm32_irq error;
46 };
47 
49  I2C_STATE_FSM_FAULT = 0, /* Must be zero so undefined transitions land here */
50 
52 
55 
57 
59 
60 #if defined(STM32F30X)
61  I2C_STATE_WRITE_BYTE,
62  I2C_STATE_READ_BYTE,
63 #elif defined(STM32F4XX)
64  I2C_STATE_STOPPING,
65 
66  I2C_STATE_R_MORE_TXN_ADDR,
67  I2C_STATE_R_MORE_TXN_PRE_ONE,
68  I2C_STATE_R_MORE_TXN_PRE_FIRST,
69  I2C_STATE_R_MORE_TXN_PRE_MIDDLE,
70  I2C_STATE_R_MORE_TXN_PRE_LAST,
71 
72  I2C_STATE_MORE_TXN_POST_LAST,
73 
74  I2C_STATE_R_LAST_TXN_ADDR,
75  I2C_STATE_R_LAST_TXN_PRE_ONE,
76  I2C_STATE_R_LAST_TXN_PRE_FIRST,
77  I2C_STATE_R_LAST_TXN_PRE_MIDDLE,
78  I2C_STATE_R_LAST_TXN_PRE_LAST,
79  I2C_STATE_R_LAST_TXN_POST_LAST,
80 
81  I2C_STATE_W_MORE_TXN_ADDR,
82  I2C_STATE_W_MORE_TXN_MIDDLE,
83  I2C_STATE_W_MORE_TXN_LAST,
84 
85  I2C_STATE_W_LAST_TXN_ADDR,
86  I2C_STATE_W_LAST_TXN_MIDDLE,
87  I2C_STATE_W_LAST_TXN_LAST,
88 
89  I2C_STATE_W_MORE_TXN_PRE,
90  I2C_STATE_W_LAST_TXN_PRE,
91  I2C_STATE_W_LAST_TXN_POST_LAST,
92 #endif // STM32F4XX
93 
94  I2C_STATE_NUM_STATES /* Must be last */
95 };
96 
104 
105 #if defined(STM32F30X)
106  I2C_EVENT_RECEIVER_BUFFER_NOT_EMPTY,
107  I2C_EVENT_TRANSMIT_BUFFER_EMPTY,
108  I2C_EVENT_TRANSFER_COMPLETE,
109 #elif defined(STM32F4XX)
110  I2C_EVENT_R_MORE_TXN_STARTED,
111  I2C_EVENT_W_MORE_TXN_STARTED,
112  I2C_EVENT_R_LAST_TXN_STARTED,
113  I2C_EVENT_W_LAST_TXN_STARTED,
114  I2C_EVENT_ADDR_SENT_LEN_EQ_0,
115  I2C_EVENT_ADDR_SENT_LEN_EQ_1,
116  I2C_EVENT_ADDR_SENT_LEN_EQ_2,
117  I2C_EVENT_ADDR_SENT_LEN_GT_2,
118  I2C_EVENT_TRANSFER_DONE_LEN_EQ_0,
119  I2C_EVENT_TRANSFER_DONE_LEN_EQ_1,
120  I2C_EVENT_TRANSFER_DONE_LEN_EQ_2,
121  I2C_EVENT_TRANSFER_DONE_LEN_GT_2,
122 #endif /* STM32F4XX */
123 
124  I2C_EVENT_NUM_EVENTS /* Must be last */
125 };
126 
128  PIOS_I2C_DEV_MAGIC = 0xa9a9b8b8,
129 };
130 
135 };
136 
137 #if defined(PIOS_I2C_DIAGNOSTICS)
138 #define I2C_LOG_DEPTH 20
139 
140 struct pios_i2c_fault_history {
142  uint32_t evirq[I2C_LOG_DEPTH];
143  uint32_t erirq[I2C_LOG_DEPTH];
144  enum i2c_adapter_event event[I2C_LOG_DEPTH];
145  enum i2c_adapter_state state[I2C_LOG_DEPTH];
146 };
147 #endif
148 
149 int32_t PIOS_I2C_Init(pios_i2c_t * i2c_id, const struct pios_i2c_adapter_cfg * cfg);
150 
151 #endif /* PIOS_I2C_PRIV_H */
Types that are specific to the STM32 peripherals.
struct stm32_irq error
Definition: pios_i2c_priv.h:45
Main PiOS header to include all the compiled in PiOS options.
i2c_adapter_state
Definition: pios_i2c_priv.h:48
I2C_TypeDef * regs
Definition: pios_i2c_priv.h:37
struct stm32_gpio scl
Definition: pios_i2c_priv.h:42
struct stm32_gpio sda
Definition: pios_i2c_priv.h:43
int32_t PIOS_I2C_Init(pios_i2c_t *i2c_id, const char *path)
static struct flyingpicmd_cfg_fa cfg
Definition: main.c:49
pios_i2c_adapter_magic
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
I2C_InitTypeDef init
Definition: pios_i2c_priv.h:39
pios_i2c_error_type
uint8_t type
i2c_adapter_event
Definition: pios_i2c_priv.h:97
uint32_t transfer_timeout_ms
Definition: pios_i2c_priv.h:41
struct stm32_irq event
Definition: pios_i2c_priv.h:44
enum arena_state state