i2c.h
Go to the documentation of this file.
1 /*
2 Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
3 Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
4 Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
35 #ifndef I2C_H_
36 #define I2C_H_
37 
44 #define E_NO_ERR -1
45 
51 #define I2C_MTU 256
52 
58 #define I2C_MASTER 0
59 #define I2C_SLAVE 1
60 
66 typedef struct __attribute__((packed)) i2c_frame_s {
67  uint8_t padding;
68  uint8_t retries;
69  uint32_t reserved;
70  uint8_t dest;
71  uint8_t len_rx;
72  uint16_t len;
73  uint8_t data[I2C_MTU];
74 } i2c_frame_t;
75 
90 typedef void (*i2c_callback_t) (i2c_frame_t * frame, void * pxTaskWoken);
91 
92 
98 int i2c_init(int handle, int mode, uint8_t addr, uint16_t speed, int queue_len_tx, int queue_len_rx, i2c_callback_t callback);
99 
110 int i2c_send(int handle, i2c_frame_t * frame, uint16_t timeout);
111 
112 #endif /* I2C_H_ */
113 
114 /* @} */
Data structure for I2C frames.
Definition: i2c.h:66
void(* i2c_callback_t)(i2c_frame_t *frame, void *pxTaskWoken)
Initialise the I2C driver.
Definition: i2c.h:90
uint8_t len_rx
Definition: i2c.h:71
uint16_t len
Definition: i2c.h:72
struct i2c_frame_s i2c_frame_t
Data structure for I2C frames.
uint8_t dest
Definition: i2c.h:70
#define I2C_MTU
Maximum transfer length on I2C.
Definition: i2c.h:51
int i2c_send(int handle, i2c_frame_t *frame, uint16_t timeout)
Send I2C frame via the selected device.
uint8_t retries
Definition: i2c.h:68
uint32_t reserved
Definition: i2c.h:69
uint8_t padding
Definition: i2c.h:67
int i2c_init(int handle, int mode, uint8_t addr, uint16_t speed, int queue_len_tx, int queue_len_rx, i2c_callback_t callback)