Paparazzi UAS  v5.18.0_stable
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 
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
dl_buffer
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
w5100_periph::tx_insert_idx
volatile uint16_t tx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:59
W5100StatusUninit
@ W5100StatusUninit
Definition: w5100.h:45
uint16_t
unsigned short uint16_t
Definition: types.h:16
w5100_periph::curbuf
int curbuf
Definition: w5100.h:52
UNINIT
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11
w5100_periph::device
struct link_device device
Generic device interface.
Definition: w5100.h:65
w5100_transmit_buffer
void w5100_transmit_buffer(uint8_t *data, uint16_t len)
Definition: w5100.c:281
W5100StatusIdle
@ W5100StatusIdle
Definition: w5100.h:46
w5100_receive
uint16_t w5100_receive(uint8_t *buf, uint16_t len)
Definition: w5100.c:386
w5100_rx_buf
uint8_t w5100_rx_buf[W5100_RX_BUFFER_SIZE]
Definition: w5100.c:92
w5100_transmit
void w5100_transmit(uint8_t data)
Definition: w5100.c:266
W5100_BUFFER_NUM
#define W5100_BUFFER_NUM
Definition: w5100.h:38
W5100Status
W5100Status
Definition: w5100.h:44
w5100_periph::rx_insert_idx
volatile uint16_t rx_insert_idx[W5100_BUFFER_NUM]
Definition: w5100.h:55
w5100_periph::status
enum W5100Status status
Definition: w5100.h:51
w5100_read_buffer
static void w5100_read_buffer(struct pprz_transport *t)
Definition: w5100.h:86
w5100_periph
Definition: w5100.h:50
w5100_periph::rx_buf
volatile uint8_t rx_buf[W5100_BUFFER_NUM][W5100_RX_BUFFER_SIZE]
Definition: w5100.h:54
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
w5100_periph::work_tx
volatile uint8_t work_tx[4]
Definition: w5100.h:61
uint8_t
unsigned char uint8_t
Definition: types.h:14
W5100_UPDATE_DL
#define W5100_UPDATE_DL
Definition: w5100.h:41
w5100_periph::tx_buf
volatile uint8_t tx_buf[W5100_BUFFER_NUM][W5100_TX_BUFFER_SIZE]
Definition: w5100.h:58
w5100_ch_available
bool w5100_ch_available(void)
Definition: w5100.c:378
dl_msg_available
bool dl_msg_available
Definition: main_demo5.c:61
w5100_periph::tx_extract_idx
volatile uint16_t tx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:60
w5100_rx_size
uint16_t w5100_rx_size(uint8_t _s)
Definition: w5100.c:331
W5100_RX_BUFFER_SIZE
#define W5100_RX_BUFFER_SIZE
Definition: w5100.h:36
w5100_periph::work_rx
volatile uint8_t work_rx[4]
Definition: w5100.h:62
W5100_TX_BUFFER_SIZE
#define W5100_TX_BUFFER_SIZE
Definition: w5100.h:37
w5100_init
void w5100_init(void)
Definition: w5100.c:185
w5100_send
void w5100_send(void)
Definition: w5100.c:289
w5100_event
static w5100_event(void)
Definition: w5100.h:108
W5100StatusReading
@ W5100StatusReading
Definition: w5100.h:47
w5100_periph::tx_running
volatile uint8_t tx_running
Definition: w5100.h:63
chip0
struct w5100_periph chip0
Definition: w5100.c:90
w5100_periph::rx_extract_idx
volatile uint16_t rx_extract_idx[W5100_BUFFER_NUM]
Definition: w5100.h:56
w5100_check_and_parse
static void w5100_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
Definition: w5100.h:97