Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pipe.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Kirk Scheper <kirkscheper@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/pipe.h"
29 
30 #include <string.h>
31 
32 /* Print the configurations */
33 #if defined(USE_PIPE0_WRITER) || defined(USE_PIPE0_READER)
34 struct pipe_periph pipe0;
35 #endif
36 
37 #ifdef USE_PIPE0_WRITER
38 PRINT_CONFIG_VAR(USE_PIPE0_WRITER)
39 #endif
40 
41 #ifdef USE_PIPE0_READER
42 PRINT_CONFIG_VAR(USE_PIPE0_READER)
43 #endif
44 
45 #if defined(USE_PIPE1_WRITER) || defined(USE_PIPE1_READER)
46 struct pipe_periph pipe1;
47 #endif
48 
49 #ifdef USE_PIPE1_WRITER
50 PRINT_CONFIG_VAR(USE_PIPE1_WRITER)
51 #endif
52 
53 #ifdef USE_PIPE1_READER
54 PRINT_CONFIG_VAR(USE_PIPE1_READER)
55 #endif
56 
57 #if defined(USE_PIPE2_WRITER) || defined(USE_PIPE2_READER)
58 struct pipe_periph pipe2;
59 #endif
60 
61 #ifdef USE_PIPE2_WRITER
62 PRINT_CONFIG_VAR(USE_PIPE2_WRITER)
63 #endif
64 
65 #ifdef USE_PIPE2_READER
66 PRINT_CONFIG_VAR(USE_PIPE2_READER)
67 #endif
68 
72 void pipe_periph_init(struct pipe_periph *p, char *read_name, char *write_name)
73 {
74  p->rx_insert_idx = 0;
75  p->rx_extract_idx = 0;
76  p->tx_insert_idx = 0;
77  p->device.periph = (void *)p;
78  p->device.check_free_space = (check_free_space_t) pipe_check_free_space;
79  p->device.put_byte = (put_byte_t) pipe_put_byte;
80  p->device.put_buffer = (put_buffer_t) pipe_put_buffer;
81  p->device.send_message = (send_message_t) pipe_send_message;
82  p->device.char_available = (char_available_t) pipe_char_available;
83  p->device.get_byte = (get_byte_t) pipe_getch;
84 
85  pipe_arch_periph_init(p, read_name, write_name);
86 }
87 
94 bool WEAK pipe_check_free_space(struct pipe_periph *p, long *fd __attribute__((unused)), uint16_t len)
95 {
96  return (PIPE_TX_BUFFER_SIZE - p->tx_insert_idx) >= len;
97 }
98 
104 void WEAK pipe_put_byte(struct pipe_periph *p, long fd __attribute__((unused)), uint8_t data)
105 {
107  return; // no room
108  }
109 
110  p->tx_buf[p->tx_insert_idx] = data;
111  p->tx_insert_idx++;
112 }
113 
114 void WEAK pipe_put_buffer(struct pipe_periph *p, long fd __attribute__((unused)), const uint8_t *data, uint16_t len)
115 {
116  if (p->tx_insert_idx + len >= PIPE_TX_BUFFER_SIZE) {
117  return; // no room
118  }
119 
120  memcpy(&(p->tx_buf[p->tx_insert_idx]), data, len);
121  p->tx_insert_idx += len;
122 }
unsigned short uint16_t
Definition: types.h:16
arch independent PIPE API
uint16_t tx_insert_idx
Definition: pipe.h:42
uint16_t rx_extract_idx
Definition: pipe.h:39
void pipe_arch_periph_init(struct pipe_periph *p, char *read_name, char *write_name)
Initialize the PIPE peripheral.
Definition: pipe_arch.c:76
bool WEAK pipe_check_free_space(struct pipe_periph *p, long *fd, uint16_t len)
Check if there is enough free space in the transmit buffer.
Definition: pipe.c:94
#define PIPE_TX_BUFFER_SIZE
Definition: pipe_arch.h:34
uint16_t rx_insert_idx
Definition: pipe.h:38
void WEAK pipe_put_buffer(struct pipe_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition: pipe.c:114
void pipe_periph_init(struct pipe_periph *p, char *read_name, char *write_name)
Initialize the PIPE peripheral.
Definition: pipe.c:72
uint8_t tx_buf[PIPE_TX_BUFFER_SIZE]
Transmit buffer.
Definition: pipe.h:41
unsigned char uint8_t
Definition: types.h:14
struct link_device device
Generic device interface.
Definition: pipe.h:47
int fd
Definition: serial.c:26
static float p[2][2]
uint8_t pipe_getch(struct pipe_periph *p)
Get the last character from the receive buffer.
Definition: pipe_arch.c:120
uint16_t pipe_char_available(struct pipe_periph *p)
Get number of bytes available in receive buffer.
Definition: pipe_arch.c:104
void pipe_send_message(struct pipe_periph *p, long fd)
Send a message.
Definition: pipe_arch.c:160
void WEAK pipe_put_byte(struct pipe_periph *p, long fd, uint8_t data)
Add one data byte to the tx buffer.
Definition: pipe.c:104