Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_ubx_i2c.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 ENAC, Pascal Brisset, Michel Gorraz,Gautier Hattenberger,
3 * 2016 Michael Sierra <sierramichael.a@gmail.com>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 */
23
32#include "mcu_periph/i2c.h"
35#include <math.h>
36#include <string.h>
37
38// ublox i2c address
39#define GPS_I2C_SLAVE_ADDR (0x42 << 1)
40
41#ifndef GPS_UBX_I2C_DEV
42#error "GPS_UBX_I2C_DEV needs to be defined (e.g. to i2c1)"
43#endif
45
46#define GPS_I2C_ADDR_NB_AVAIL_BYTES 0xFD
47#define GPS_I2C_ADDR_DATA 0xFF
48
49// Global variables
51
52// Local variables
55
60
66int gps_i2c_check_free_space(struct GpsUbxI2C *p, long *fd, uint16_t len);
67
73void gps_i2c_put_byte(struct GpsUbxI2C *p, long fd, uint8_t data);
74
80void gps_i2c_put_buffer(struct GpsUbxI2C *p, long fd, uint8_t *data, uint16_t len);
81
85void gps_i2c_msg_ready(struct GpsUbxI2C *p, long fd);
86
91
96
123
125
126int gps_i2c_check_free_space(struct GpsUbxI2C *p __attribute__((unused)), long *fd __attribute__((unused)), uint16_t len)
127{
128 return (GPS_I2C_BUF_SIZE - gps_i2c.tx_buf_idx) >= len;
129}
130
131void gps_i2c_put_buffer(struct GpsUbxI2C *p, long fd, uint8_t *data, uint16_t len)
132{
133 int i = 0;
134 for (i = 0; i < len; i++) {
135 gps_i2c_put_byte(p, fd, data[i]);
136 }
137}
138
139void gps_i2c_put_byte(struct GpsUbxI2C *p __attribute__((unused)), long fd __attribute__((unused)), uint8_t data)
140{
142}
143
144void gps_i2c_msg_ready(struct GpsUbxI2C *p __attribute__((unused)), long fd __attribute__((unused)))
145{
148}
149
151{
152 return (((int)gps_i2c.rx_buf_avail - (int)gps_i2c.rx_buf_idx) > 0);
153}
154
156{
157 return gps_i2c.tx_rdy;
158}
159
161{
163}
164
166{
168}
169
208
210{
211 switch(gps_i2c.read_state)
212 {
214 break;
215 break;
216
217 // how many bytes are available
221 if (gps_ubx_i2c_bytes_to_read == 0xFFFF || gps_ubx_i2c_bytes_to_read == 0x0000)
222 {
224 return;
226 {
230 } else
231 {
235 return;
236 }
237 break;
240 {
244 } else
245 {
249 }
250
253 break;
254
255 default:
256 break;
257 }
258
259 // Transaction has been read
261}
void gps_ubx_i2c_init(void)
init function
Definition gps_ubx_i2c.c:97
#define GPS_I2C_ADDR_DATA
data stream register
Definition gps_ubx_i2c.c:47
void gps_i2c_begin(void)
config is done, begin reading messages
int gps_i2c_check_free_space(struct GpsUbxI2C *p, long *fd, uint16_t len)
Check available space in transmit buffer.
uint8_t gps_i2c_getch(struct GpsUbxI2C *p)
get a new char
struct GpsUbxI2C gps_i2c
Definition gps_ubx_i2c.c:50
bool gps_ubx_i2c_ucenter_done
ucenter finished configuring flag
Definition gps_ubx_i2c.c:53
uint16_t gps_ubx_i2c_bytes_to_read
ublox bytes to read
Definition gps_ubx_i2c.c:54
bool gps_i2c_tx_is_ready(void)
is driver ready to send a message
#define GPS_I2C_ADDR_NB_AVAIL_BYTES
number of bytes available register
Definition gps_ubx_i2c.c:46
void gps_ubx_i2c_periodic(void)
handle message sending
#define GPS_I2C_SLAVE_ADDR
Definition gps_ubx_i2c.c:39
void gps_ubx_i2c_read_event(void)
handle message reception
void gps_i2c_put_byte(struct GpsUbxI2C *p, long fd, uint8_t data)
Put byte into transmit buffer.
void gps_i2c_msg_ready(struct GpsUbxI2C *p, long fd)
send buffer when ready
int gps_i2c_char_available(struct GpsUbxI2C *p)
check if a new character is available
void gps_i2c_put_buffer(struct GpsUbxI2C *p, long fd, uint8_t *data, uint16_t len)
Put bytes into transmit buffer.
void null_function(struct GpsUbxI2C *p, uint32_t baudrate)
null function
pprz link device for Ublox over I2C
struct i2c_transaction trans
i2c transaction
Definition gps_ubx_i2c.h:75
uint16_t rx_buf_avail
how many bytes are waiting to be read
Definition gps_ubx_i2c.h:69
uint16_t tx_buf_idx
tx buf index
Definition gps_ubx_i2c.h:71
uint16_t rx_buf_idx
rx buf index
Definition gps_ubx_i2c.h:70
@ gps_i2c_read_data
read data from ubx buffer
Definition gps_ubx_i2c.h:47
@ gps_i2c_read_standby
dont read anything
Definition gps_ubx_i2c.h:45
@ gps_i2c_read_sizeof
read size of ubx buffer
Definition gps_ubx_i2c.h:46
bool tx_rdy
are we ready to transmit
Definition gps_ubx_i2c.h:73
uint8_t tx_buf[GPS_I2C_BUF_SIZE]
transmit buffer
Definition gps_ubx_i2c.h:67
#define GPS_I2C_BUF_SIZE
Definition gps_ubx_i2c.h:39
struct link_device device
ppz link device
Definition gps_ubx_i2c.h:79
uint8_t rx_buf[GPS_I2C_BUF_SIZE]
receive buffer
Definition gps_ubx_i2c.h:66
@ gps_i2c_write_cfg
send a config msg and get reply
Definition gps_ubx_i2c.h:56
@ gps_i2c_write_request_size
request size of ubx buffer
Definition gps_ubx_i2c.h:55
@ gps_i2c_write_standby
wait for gps_ubx to read buffer or ucenter to transmit
Definition gps_ubx_i2c.h:54
GpsI2CReadState read_state
Definition gps_ubx_i2c.h:63
int baudrate
baudrate, unused
Definition gps_ubx_i2c.h:77
GpsI2CWriteState write_state
Definition gps_ubx_i2c.h:64
ubx_i2c state
Definition gps_ubx_i2c.h:62
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition i2c.c:202
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.
Definition i2c.c:222
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:59
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
static float p[2][2]
uint16_t foo
Definition main_demo5.c:58
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
int fd
Definition serial.c:26
#define TRUE
Definition std.h:4
#define FALSE
Definition std.h:5
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.