Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 int WEAK pipe_check_free_space(struct pipe_periph *p, long *fd __attribute__((unused)), uint16_t len)
95 {
96  int available = PIPE_TX_BUFFER_SIZE - p->tx_insert_idx;
97  return available >= len ? available : 0;
98 }
99 
105 void WEAK pipe_put_byte(struct pipe_periph *p, long fd __attribute__((unused)), uint8_t data)
106 {
107  if (p->tx_insert_idx >= PIPE_TX_BUFFER_SIZE) {
108  return; // no room
109  }
110 
111  p->tx_buf[p->tx_insert_idx] = data;
112  p->tx_insert_idx++;
113 }
114 
115 void WEAK pipe_put_buffer(struct pipe_periph *p, long fd __attribute__((unused)), const uint8_t *data, uint16_t len)
116 {
117  if (p->tx_insert_idx + len >= PIPE_TX_BUFFER_SIZE) {
118  return; // no room
119  }
120 
121  memcpy(&(p->tx_buf[p->tx_insert_idx]), data, len);
122  p->tx_insert_idx += len;
123 }
static float p[2][2]
int pipe_char_available(struct pipe_periph *p)
Get number of bytes available in receive buffer.
Definition: pipe_arch.c:104
uint8_t pipe_getch(struct pipe_periph *p)
Get the last character from the receive buffer.
Definition: pipe_arch.c:120
void pipe_arch_periph_init(struct pipe_periph *p, char *read_name, char *write_name)
Initialize the PIPE peripheral.
Definition: pipe_arch.c:76
void pipe_send_message(struct pipe_periph *p, long fd)
Send a message.
Definition: pipe_arch.c:160
#define PIPE_TX_BUFFER_SIZE
Definition: pipe_arch.h:34
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
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:105
void pipe_periph_init(struct pipe_periph *p, char *read_name, char *write_name)
Initialize the PIPE peripheral.
Definition: pipe.c:72
void WEAK pipe_put_buffer(struct pipe_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition: pipe.c:115
int 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
arch independent PIPE API
int fd
Definition: serial.c:26
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98