Paparazzi UAS v7.0_unstable
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#include <string.h>
31
32/* Print the configurations */
33#if USE_UDP0
34struct udp_periph udp0;
39#endif // USE_UDP0
40
41#if USE_UDP1
42struct udp_periph udp1;
47#endif // USE_UDP1
48
49#if USE_UDP2
50struct udp_periph udp2;
55#endif // USE_UDP2
56
60void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast)
61{
62 p->rx_insert_idx = 0;
63 p->rx_extract_idx = 0;
64 p->tx_insert_idx = 0;
65 p->device.periph = (void *)p;
66 p->device.check_free_space = (check_free_space_t) udp_check_free_space;
67 p->device.put_byte = (put_byte_t) udp_put_byte;
68 p->device.put_buffer = (put_buffer_t) udp_put_buffer;
69 p->device.send_message = (send_message_t) udp_send_message;
70 p->device.char_available = (char_available_t) udp_char_available;
71 p->device.get_byte = (get_byte_t) udp_getch;
72
73 // Arch dependent initialization
75}
76
83int WEAK udp_check_free_space(struct udp_periph *p, long *fd __attribute__((unused)), uint16_t len)
84{
85 int available = UDP_TX_BUFFER_SIZE - p->tx_insert_idx;
86 return available >= len ? available : 0;
87}
88
94void WEAK udp_put_byte(struct udp_periph *p, long fd __attribute__((unused)), uint8_t data)
95{
96 if (p->tx_insert_idx >= UDP_TX_BUFFER_SIZE) {
97 return; // no room
98 }
99
100 p->tx_buf[p->tx_insert_idx] = data;
101 p->tx_insert_idx++;
102}
103
104void WEAK udp_put_buffer(struct udp_periph *p, long fd __attribute__((unused)), const uint8_t *data, uint16_t len)
105{
106 if (p->tx_insert_idx + len >= UDP_TX_BUFFER_SIZE) {
107 return; // no room
108 }
109
110 memcpy(&(p->tx_buf[p->tx_insert_idx]), data, len);
111 p->tx_insert_idx += len;
112}
static float p[2][2]
void udp_arch_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast)
Initialize the UDP peripheral.
Definition udp_arch.c:71
uint8_t udp_getch(struct udp_periph *p)
Get the last character from the receive buffer.
Definition udp_arch.c:99
int udp_char_available(struct udp_periph *p)
Get number of bytes available in receive buffer.
Definition udp_arch.c:83
void udp_send_message(struct udp_periph *p, long fd)
Send a message.
Definition udp_arch.c:144
uint16_t foo
Definition main_demo5.c:58
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
int fd
Definition serial.c:26
void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in, bool broadcast)
Initialize the UDP peripheral.
Definition udp.c:60
void WEAK udp_put_buffer(struct udp_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition udp.c:104
int WEAK udp_check_free_space(struct udp_periph *p, long *fd, uint16_t len)
Check if there is enough free space in the transmit buffer.
Definition udp.c:83
void WEAK udp_put_byte(struct udp_periph *p, long fd, uint8_t data)
Add one data byte to the tx buffer.
Definition udp.c:94
arch independent UDP API
uint16_t rx_insert_idx
Definition udp.h:41
#define UDP_TX_BUFFER_SIZE
Definition udp.h:36
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.