Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pipe.h
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 #ifndef MCU_PERIPH_PIPE_H
29 #define MCU_PERIPH_PIPE_H
30 
31 #include "std.h"
32 #include "mcu_periph/pipe_arch.h"
33 #include "pprzlink/pprzlink_device.h"
34 
35 struct pipe_periph {
44  int fd_read;
45  int fd_write;
47  struct link_device device;
48 };
49 
50 extern void pipe_arch_init(void);
51 extern void pipe_arch_periph_init(struct pipe_periph *p, char *read_name, char* write_name);
52 extern void pipe_periph_init(struct pipe_periph *p, char *name, char* write_name);
53 extern int pipe_char_available(struct pipe_periph *p);
54 extern uint8_t pipe_getch(struct pipe_periph *p);
55 extern void pipe_receive(struct pipe_periph *p);
56 extern void pipe_send_message(struct pipe_periph *p, long fd);
57 extern void pipe_send_raw(struct pipe_periph *p, long fd, uint8_t *buffer, uint16_t size);
58 extern int pipe_check_free_space(struct pipe_periph *p, long *fd, uint16_t len);
59 extern void pipe_put_byte(struct pipe_periph *p, long fd, uint8_t data);
60 extern void pipe_put_buffer(struct pipe_periph *p, long fd, const uint8_t *data,uint16_t len);
61 
62 #if defined(USE_PIPE0_WRITER) || defined(USE_PIPE0_READER)
63 extern struct pipe_periph pipe0;
64 
65 #ifndef USE_PIPE0_WRITER
66 #define USE_PIPE0_WRITER NULL
67 #endif
68 
69 #ifndef USE_PIPE0_READER
70 #define USE_PIPE0_READER NULL
71 #endif
72 
73 #define PIPE0Init() pipe_periph_init(&pipe0, STRINGIFY(USE_PIPE0_READER), STRINGIFY(USE_PIPE0_WRITER))
74 #endif // USE_PIPE0
75 
76 #if defined(USE_PIPE1_WRITER) || defined(USE_PIPE1_READER)
77 extern struct pipe_periph pipe1;
78 
79 #ifndef USE_PIPE1_WRITER
80 #define USE_PIPE1_WRITER NULL
81 #endif
82 
83 #ifndef USE_PIPE1_READER
84 #define USE_PIPE1_READER NULL
85 #endif
86 
87 #define PIPE1Init() pipe_periph_init(&pipe1, STRINGIFY(USE_PIPE1_READER), STRINGIFY(USE_PIPE1_WRITER))
88 #endif // USE_PIPE1
89 
90 #if defined(USE_PIPE2_WRITER) || defined(USE_PIPE2_READER)
91 extern struct pipe_periph pipe2;
92 
93 #ifndef USE_PIPE2_WRITER
94 #define USE_PIPE2_WRITER NULL
95 #endif
96 
97 #ifndef USE_PIPE2_READER
98 #define USE_PIPE2_READER NULL
99 #endif
100 
101 #define PIPE2Init() pipe_periph_init(&pipe2, STRINGIFY(USE_PIPE2_READER), STRINGIFY(USE_PIPE2_WRITER))
102 #endif // USE_PIPE2
103 
104 #endif /* MCU_PERIPH_PIPE_H */
void pipe_put_buffer(struct pipe_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition: pipe.c:115
unsigned short uint16_t
Definition: types.h:16
void pipe_send_message(struct pipe_periph *p, long fd)
Send a message.
Definition: pipe_arch.c:160
void pipe_arch_periph_init(struct pipe_periph *p, char *read_name, char *write_name)
Initialize the PIPE peripheral.
Definition: pipe_arch.c:76
uint16_t tx_insert_idx
Definition: pipe.h:42
uint8_t rx_buf[PIPE_RX_BUFFER_SIZE]
Receive buffer.
Definition: pipe.h:37
void pipe_periph_init(struct pipe_periph *p, char *name, char *write_name)
Initialize the PIPE peripheral.
Definition: pipe.c:72
void pipe_put_byte(struct pipe_periph *p, long fd, uint8_t data)
Add one data byte to the tx buffer.
Definition: pipe.c:105
uint16_t rx_extract_idx
Definition: pipe.h:39
int 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
int pipe_char_available(struct pipe_periph *p)
Get number of bytes available in receive buffer.
Definition: pipe_arch.c:104
#define PIPE_TX_BUFFER_SIZE
Definition: pipe_arch.h:34
uint8_t pipe_getch(struct pipe_periph *p)
Get the last character from the receive buffer.
Definition: pipe_arch.c:120
uint16_t rx_insert_idx
Definition: pipe.h:38
int fd_read
PIPE file descriptor.
Definition: pipe.h:44
void pipe_arch_init(void)
Definition: pipe_arch.c:48
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
#define PIPE_RX_BUFFER_SIZE
Definition: pipe_arch.h:31
static float p[2][2]
int fd_write
Definition: pipe.h:45
void pipe_receive(struct pipe_periph *p)
Read bytes from PIPE.
Definition: pipe_arch.c:132
void pipe_send_raw(struct pipe_periph *p, long fd, uint8_t *buffer, uint16_t size)
Send a packet from another buffer.
Definition: pipe_arch.c:182