Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
w5100.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Gerard Toonstra
3  * Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  */
22 
28 #ifndef W5100_H
29 #define W5100_H
30 
31 #include "pprzlink/pprzlink_device.h"
32 #include "pprzlink/pprz_transport.h"
34 #include "generated/airframe.h"
35 
36 #define W5100_RX_BUFFER_SIZE 80
37 #define W5100_TX_BUFFER_SIZE 80
38 #define W5100_BUFFER_NUM 2
39 
40 #ifndef W5100_UPDATE_DL
41 #define W5100_UPDATE_DL TRUE
42 #endif
43 
48 };
49 
50 struct w5100_periph {
51  volatile enum W5100Status status;
52  int curbuf;
53  /* Receive buffer */
57  /* Transmit buffer */
61  volatile uint8_t work_tx[4];
62  volatile uint8_t work_rx[4];
63  volatile uint8_t tx_running;
65  struct link_device device;
66 };
67 
69 
70 extern struct w5100_periph chip0;
71 
72 // W5100 is using pprz_transport
73 // FIXME it should not appear here, this will be fixed with the rx improvements some day...
74 // W5100 needs a specific read_buffer function
75 extern struct pprz_w5100_tp;
76 
77 void w5100_init(void);
78 void w5100_transmit(uint8_t data);
79 void w5100_transmit_buffer(uint8_t *data, uint16_t len);
81 void w5100_send(void);
83 bool w5100_ch_available(void);
84 
85 
86 static inline void w5100_read_buffer(struct pprz_transport *t)
87 {
88  while (w5100_ch_available()) {
90  int c = 0;
91  do {
92  parse_pprz(t, w5100_rx_buf[ c++ ]);
93  } while ((t->status != UNINIT) && !(t->trans_rx.msg_received));
94  }
95 }
96 
97 static inline void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
98 {
99  if (dev->char_available(dev->periph)) {
100  w5100_read_buffer(trans);
101  if (trans->trans_rx.msg_received) {
102  DatalinkFillDlBuffer(trans->trans_rx.payload, trans->trans_rx.payload_len);
103  trans->trans_rx.msg_received = false;
104  }
105  }
106 }
107 
108 static inline w5100_event(void)
109 {
110  w5100_check_and_parse(&(W5100).device, &pprz_w5100_tp);
111  DlCheckAndParse(&(W5100).device, &pprz_w5100_tp.trans_tx, dl_buffer, &dl_msg_available, W5100_UPDATE_DL);
112 }
113 
114 #endif /* W5100_H */
115 
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:63
bool dl_msg_available
Flag provided to control calls to dl_parse_msg.
Definition: main_demo5.c:60
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
#define W5100_TX_BUFFER_SIZE
Definition: w5100.h:37
volatile uint16_t tx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:60
volatile uint8_t work_tx[4]
Definition: w5100.h:61
W5100Status
Definition: w5100.h:44
@ W5100StatusReading
Definition: w5100.h:47
@ W5100StatusIdle
Definition: w5100.h:46
@ W5100StatusUninit
Definition: w5100.h:45
static void w5100_read_buffer(struct pprz_transport *t)
Definition: w5100.h:86
volatile uint16_t rx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:55
void w5100_transmit(uint8_t data)
Definition: w5100.c:266
void w5100_init(void)
Definition: w5100.c:185
volatile uint8_t work_rx[4]
Definition: w5100.h:62
void w5100_send(void)
Definition: w5100.c:289
struct link_device device
Generic device interface.
Definition: w5100.h:65
#define W5100_RX_BUFFER_SIZE
Definition: w5100.h:36
static w5100_event(void)
Definition: w5100.h:108
void w5100_transmit_buffer(uint8_t *data, uint16_t len)
Definition: w5100.c:281
uint16_t w5100_rx_size(uint8_t _s)
Definition: w5100.c:331
int curbuf
Definition: w5100.h:52
volatile uint8_t tx_buf[W5100_BUFFER_NUM][W5100_TX_BUFFER_SIZE]
Definition: w5100.h:58
bool w5100_ch_available(void)
Definition: w5100.c:378
struct w5100_periph chip0
Definition: w5100.c:90
uint8_t w5100_rx_buf[W5100_RX_BUFFER_SIZE]
Definition: w5100.c:92
#define W5100_UPDATE_DL
Definition: w5100.h:41
uint16_t w5100_receive(uint8_t *buf, uint16_t len)
Definition: w5100.c:386
#define W5100_BUFFER_NUM
Definition: w5100.h:38
volatile uint8_t tx_running
Definition: w5100.h:63
volatile uint16_t rx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:56
volatile uint16_t tx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:59
volatile uint8_t rx_buf[W5100_BUFFER_NUM][W5100_RX_BUFFER_SIZE]
Definition: w5100.h:54
enum W5100Status status
Definition: w5100.h:51
static void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
Definition: w5100.h:97