Paparazzi UAS  v5.12_stable-4-g9b43e9b
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"
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 
44 };
45 
46 struct w5100_periph {
47  volatile enum W5100Status status;
48  int curbuf;
49  /* Receive buffer */
53  /* Transmit buffer */
57  volatile uint8_t work_tx[4];
58  volatile uint8_t work_rx[4];
59  volatile uint8_t tx_running;
61  struct link_device device;
62 };
63 
65 
66 extern struct w5100_periph chip0;
67 
68 // W5100 is using pprz_transport
69 // FIXME it should not appear here, this will be fixed with the rx improvements some day...
70 // W5100 needs a specific read_buffer function
71 extern struct pprz_w5100_tp;
72 
73 void w5100_init(void);
74 void w5100_transmit(uint8_t data);
75 void w5100_transmit_buffer(uint8_t *data, uint16_t len);
77 void w5100_send(void);
79 bool w5100_ch_available(void);
80 
81 
82 static inline void w5100_read_buffer(struct pprz_transport *t)
83 {
84  while (w5100_ch_available()) {
86  int c = 0;
87  do {
88  parse_pprz(t, w5100_rx_buf[ c++ ]);
89  } while ((t->status != UNINIT) && !(t->trans_rx.msg_received));
90  }
91 }
92 
93 static inline void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
94 {
95  if (dev->char_available(dev->periph)) {
96  w5100_read_buffer(trans);
97  if (trans->trans_rx.msg_received) {
98  DatalinkFillDlBuffer(trans->trans_rx.payload, trans->trans_rx.payload_len);
99  trans->trans_rx.msg_received = false;
100  }
101  }
102 }
103 
104 static inline w5100_event(void)
105 {
106  w5100_check_and_parse(&(W5100).device, &pprz_w5100_tp);
107  DlCheckAndParse(&(W5100).device, &pprz_w5100_tp.trans_tx, dl_buffer, &dl_msg_available);
108 }
109 
110 #endif /* W5100_H */
111 
W5100Status
Definition: w5100.h:40
unsigned short uint16_t
Definition: types.h:16
volatile uint8_t work_tx[4]
Definition: w5100.h:57
#define W5100_TX_BUFFER_SIZE
Definition: w5100.h:37
void w5100_send(void)
Definition: w5100.c:289
volatile uint16_t rx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:51
uint8_t w5100_rx_buf[W5100_RX_BUFFER_SIZE]
Definition: w5100.c:92
#define W5100_RX_BUFFER_SIZE
Definition: w5100.h:36
#define W5100_BUFFER_NUM
Definition: w5100.h:38
uint16_t w5100_rx_size(uint8_t _s)
Definition: w5100.c:331
bool dl_msg_available
Definition: main_demo5.c:61
volatile uint8_t tx_buf[W5100_BUFFER_NUM][W5100_TX_BUFFER_SIZE]
Definition: w5100.h:54
volatile uint8_t rx_buf[W5100_BUFFER_NUM][W5100_RX_BUFFER_SIZE]
Definition: w5100.h:50
volatile uint16_t rx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:52
static void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
Definition: w5100.h:93
void w5100_transmit(uint8_t data)
Definition: w5100.c:266
volatile uint16_t tx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:55
volatile uint16_t tx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:56
volatile uint8_t work_rx[4]
Definition: w5100.h:58
enum W5100Status status
Definition: w5100.h:47
uint16_t w5100_receive(uint8_t *buf, uint16_t len)
Definition: w5100.c:386
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:90
void w5100_init(void)
Definition: w5100.c:185
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
static w5100_event(void)
Definition: w5100.h:104
bool w5100_ch_available(void)
Definition: w5100.c:378
void w5100_transmit_buffer(uint8_t *data, uint16_t len)
Definition: w5100.c:281
static void w5100_read_buffer(struct pprz_transport *t)
Definition: w5100.h:82
volatile uint8_t tx_running
Definition: w5100.h:59
int curbuf
Definition: w5100.h:48
struct link_device device
Generic device interface.
Definition: w5100.h:61
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11