Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
udp.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van tienen <freek.v.tienen@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
28 #include "mcu_periph/udp.h"
29 
30 /* Print the configurations */
31 #if USE_UDP0
32 struct udp_periph udp0;
33 PRINT_CONFIG_VAR(UDP0_HOST)
34 PRINT_CONFIG_VAR(UDP0_PORT_OUT)
35 PRINT_CONFIG_VAR(UDP0_PORT_IN)
36 PRINT_CONFIG_VAR(UDP0_BROADCAST)
37 #endif // USE_UDP0
38 
39 #if USE_UDP1
40 struct udp_periph udp1;
41 PRINT_CONFIG_VAR(UDP1_HOST)
42 PRINT_CONFIG_VAR(UDP1_PORT_OUT)
43 PRINT_CONFIG_VAR(UDP1_PORT_IN)
44 PRINT_CONFIG_VAR(UDP1_BROADCAST)
45 #endif // USE_UDP1
46 
47 #if USE_UDP2
48 struct udp_periph udp2;
49 PRINT_CONFIG_VAR(UDP2_HOST)
50 PRINT_CONFIG_VAR(UDP2_PORT_OUT)
51 PRINT_CONFIG_VAR(UDP2_PORT_IN)
52 PRINT_CONFIG_VAR(UDP2_BROADCAST)
53 #endif // USE_UDP2
54 
58 void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool_t broadcast)
59 {
60  p->rx_insert_idx = 0;
61  p->rx_extract_idx = 0;
62  p->tx_insert_idx = 0;
63  p->device.periph = (void *)p;
69 
70  // Arch dependent initialization
71  udp_arch_periph_init(p, host, port_out, port_in, broadcast);
72 }
73 
81 {
82  return (UDP_TX_BUFFER_SIZE - p->tx_insert_idx) >= len;
83 }
84 
90 void udp_put_byte(struct udp_periph *p, uint8_t data)
91 {
93  return; // no room
94  }
95 
96  p->tx_buf[p->tx_insert_idx] = data;
97  p->tx_insert_idx++;
98 }
99 
bool_t udp_check_free_space(struct udp_periph *p, uint8_t len)
Check if there is enough free space in the transmit buffer.
Definition: udp.c:80
void udp_put_byte(struct udp_periph *p, uint8_t data)
Add one data byte to the tx buffer.
Definition: udp.c:90
uint8_t tx_buf[UDP_TX_BUFFER_SIZE]
Transmit buffer.
Definition: udp.h:44
void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool_t broadcast)
Initialize the UDP peripheral.
Definition: udp.c:58
void udp_arch_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool_t broadcast)
Initialize the UDP peripheral.
Definition: udp_arch.c:69
void udp_send_message(struct udp_periph *p)
Send a message.
Definition: udp_arch.c:142
uint16_t rx_extract_idx
Definition: udp.h:42
uint16_t udp_char_available(struct udp_periph *p)
Get number of bytes available in receive buffer.
Definition: udp_arch.c:81
uint16_t tx_insert_idx
Definition: udp.h:45
Definition: udp.h:38
#define UDP_TX_BUFFER_SIZE
Definition: udp.h:36
unsigned char uint8_t
Definition: types.h:14
uint16_t rx_insert_idx
Definition: udp.h:41
static float p[2][2]
uint8_t udp_getch(struct udp_periph *p)
Get the last character from the receive buffer.
Definition: udp_arch.c:97
struct link_device device
Generic device interface.
Definition: udp.h:49
arch independent UDP API