Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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"
33 #include "generated/airframe.h"
34 
35 #define W5100_RX_BUFFER_SIZE 80
36 #define W5100_TX_BUFFER_SIZE 80
37 #define W5100_BUFFER_NUM 2
38 
43 };
44 
45 struct w5100_periph {
46  volatile enum W5100Status status;
47  int curbuf;
48  /* Receive buffer */
52  /* Transmit buffer */
56  volatile uint8_t work_tx[4];
57  volatile uint8_t work_rx[4];
58  volatile uint8_t tx_running;
60  struct link_device device;
61 };
62 
64 
65 extern struct w5100_periph chip0;
66 
67 void w5100_init(void);
68 void w5100_transmit(uint8_t data);
69 void w5100_transmit_buffer(uint8_t *data, uint16_t len);
71 void w5100_send(void);
73 bool w5100_ch_available(void);
74 
75 
76 // W5100 is using pprz_transport
77 // FIXME it should not appear here, this will be fixed with the rx improvements some day...
78 // W5100 needs a specific read_buffer function
79 #include "pprzlink/pprz_transport.h"
80 
81 static inline void w5100_read_buffer(struct pprz_transport *t)
82 {
83  while (w5100_ch_available()) {
85  int c = 0;
86  do {
87  parse_pprz(t, w5100_rx_buf[ c++ ]);
88  } while ((t->status != UNINIT) && !(t->trans_rx.msg_received));
89  }
90 }
91 
92 #define W5100CheckAndParse(_dev, _trans) w5100_check_and_parse(&(_dev).device, &(_trans))
93 
94 static inline void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
95 {
96  if (dev->char_available(dev->periph)) {
97  w5100_read_buffer(trans);
98  if (trans->trans_rx.msg_received) {
99  DatalinkFillDlBuffer(trans->trans_rx.payload, trans->trans_rx.payload_len);
100  trans->trans_rx.msg_received = false;
101  }
102  }
103 }
104 
105 #endif /* W5100_H */
106 
W5100Status
Definition: w5100.h:39
unsigned short uint16_t
Definition: types.h:16
volatile uint8_t work_tx[4]
Definition: w5100.h:56
#define W5100_TX_BUFFER_SIZE
Definition: w5100.h:36
void w5100_send(void)
Definition: w5100.c:285
volatile uint16_t rx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:50
uint8_t w5100_rx_buf[W5100_RX_BUFFER_SIZE]
Definition: w5100.c:91
#define W5100_RX_BUFFER_SIZE
Definition: w5100.h:35
#define W5100_BUFFER_NUM
Definition: w5100.h:37
uint16_t w5100_rx_size(uint8_t _s)
Definition: w5100.c:327
volatile uint8_t tx_buf[W5100_BUFFER_NUM][W5100_TX_BUFFER_SIZE]
Definition: w5100.h:53
volatile uint8_t rx_buf[W5100_BUFFER_NUM][W5100_RX_BUFFER_SIZE]
Definition: w5100.h:49
volatile uint16_t rx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:51
static void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
Definition: w5100.h:94
void w5100_transmit(uint8_t data)
Definition: w5100.c:262
volatile uint16_t tx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:54
volatile uint16_t tx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:55
volatile uint8_t work_rx[4]
Definition: w5100.h:57
enum W5100Status status
Definition: w5100.h:46
uint16_t w5100_receive(uint8_t *buf, uint16_t len)
Definition: w5100.c:382
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
unsigned char uint8_t
Definition: types.h:14
struct w5100_periph chip0
Definition: w5100.c:89
void w5100_init(void)
Definition: w5100.c:184
bool w5100_ch_available(void)
Definition: w5100.c:374
void w5100_transmit_buffer(uint8_t *data, uint16_t len)
Definition: w5100.c:277
static void w5100_read_buffer(struct pprz_transport *t)
Definition: w5100.h:81
volatile uint8_t tx_running
Definition: w5100.h:58
int curbuf
Definition: w5100.h:47
struct link_device device
Generic device interface.
Definition: w5100.h:60
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11