From 6a31d8d9d3f012e783a67c1155a192e9ad869083 Mon Sep 17 00:00:00 2001 From: kirkscheper Date: Mon, 2 Jul 2018 10:25:44 +0200 Subject: [PATCH] fix pipe --- conf/modules/pipe.xml | 2 +- sw/airborne/arch/linux/mcu_periph/pipe_arch.c | 42 +++++++++++-------- sw/airborne/mcu_periph/pipe.c | 18 ++++---- sw/airborne/mcu_periph/pipe.h | 6 +-- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/conf/modules/pipe.xml b/conf/modules/pipe.xml index c969dde6ac..37ebba6693 100644 --- a/conf/modules/pipe.xml +++ b/conf/modules/pipe.xml @@ -7,7 +7,7 @@ Each pipe is comprised of two half-duplex fifos, one for reading from the client and one for writing to them. To activate a specific pipe peripheral, define flag USE_PIPEX_WRITER with the file path to the - location where paparazzi whoudl wrtie to and USE_PIPEX_READER for the file location where + location where paparazzi would wrtie to and USE_PIPEX_READER for the file location where it should read from, where X is your pipe peripheral number. You can also configure the size of the incoming and outgoing buffer using PIPE_RX_BUFFER_SIZE and PIPE_TX_BUFFER_SIZE diff --git a/sw/airborne/arch/linux/mcu_periph/pipe_arch.c b/sw/airborne/arch/linux/mcu_periph/pipe_arch.c index 151182e284..5550ead749 100644 --- a/sw/airborne/arch/linux/mcu_periph/pipe_arch.c +++ b/sw/airborne/arch/linux/mcu_periph/pipe_arch.c @@ -49,13 +49,13 @@ void pipe_arch_init(void) { pthread_mutex_init(&pipe_mutex, NULL); -#if USE_PIPE0_WRITER || USE_PIPE0_READER +#if defined(USE_PIPE0_WRITER) || defined(USE_PIPE0_READER) PIPE0Init(); #endif -#if USE_PIPE1_WRITER || USE_PIPE1_READER +#if defined(USE_PIPE1_WRITER) || defined(USE_PIPE1_READER) PIPE1Init(); #endif -#if USE_PIPE2_WRITER || USE_PIPE2_READER +#if defined(USE_PIPE2_WRITER) || defined(USE_PIPE2_READER) PIPE2Init(); #endif @@ -203,22 +203,28 @@ static void *pipe_thread(void *data __attribute__((unused))) FD_ZERO(&fds_master); /* add used file descriptors */ int fd __attribute__((unused)); -#if USE_PIPE0_READER - FD_SET(pipe0.fd_read, &fds_master); - if (pipe0.fd_read > fdmax) { - fdmax = pipe0.fd_read; +#ifdef USE_PIPE0_READER + if (pipe0.fd_read >= 0){ + FD_SET(pipe0.fd_read, &fds_master); + if (pipe0.fd_read > fdmax) { + fdmax = pipe0.fd_read; + } } #endif -#if USE_PIPE1_READER - FD_SET(pipe1.fd_read, &socks_master); - if (pipe1.fd_read > fdmax) { - fdmax = pipe1.fd_read; +#ifdef USE_PIPE1_READER + if(pipe1.fd_read >= 0){ + FD_SET(pipe1.fd_read, &socks_master); + if (pipe1.fd_read > fdmax) { + fdmax = pipe1.fd_read; + } } #endif -#if USE_PIPE2_READER - FD_SET(pipe2.fd_read, &socks_master); - if (pipe2.fd_read > fdmax) { - fdmax = pipe2.fd_read; +#ifdef USE_PIPE2_READER + if(pipe2.fd_read >= 0){ + FD_SET(pipe2.fd_read, &socks_master); + if (pipe2.fd_read > fdmax) { + fdmax = pipe2.fd_read; + } } #endif @@ -232,17 +238,17 @@ static void *pipe_thread(void *data __attribute__((unused))) if (select(fdmax + 1, &fds, NULL, NULL, NULL) < 0) { fprintf(stderr, "pipe_thread: select failed!"); } else { -#if USE_PIPE0_READER +#ifdef USE_PIPE0_READER if (FD_ISSET(pipe0.fd_read, &fds)) { pipe_receive(&pipe0); } #endif -#if USE_PIPE1_READER +#ifdef USE_PIPE1_READER if (FD_ISSET(pipe1.fd_read, &fds)) { pipe_receive(&pipe1); } #endif -#if USE_PIPE2_READER +#ifdef USE_PIPE2_READER if (FD_ISSET(pipe2.fd_read, &fds)) { pipe_receive(&pipe2); } diff --git a/sw/airborne/mcu_periph/pipe.c b/sw/airborne/mcu_periph/pipe.c index 6dd3882dd7..ad331a0f8c 100644 --- a/sw/airborne/mcu_periph/pipe.c +++ b/sw/airborne/mcu_periph/pipe.c @@ -30,39 +30,39 @@ #include /* Print the configurations */ -#if USE_PIPE0_WRITER || USE_PIPE0_READER +#if defined(USE_PIPE0_WRITER) || defined(USE_PIPE0_READER) struct pipe_periph pipe0; #endif -#if USE_PIPE0_WRITER +#ifdef USE_PIPE0_WRITER PRINT_CONFIG_VAR(USE_PIPE0_WRITER) #endif -#if USE_PIPE0_READER +#ifdef USE_PIPE0_READER PRINT_CONFIG_VAR(USE_PIPE0_READER) #endif -#if USE_PIPE1_WRITER || USE_PIPE1_READER +#if defined(USE_PIPE1_WRITER) || defined(USE_PIPE1_READER) struct pipe_periph pipe1; #endif -#if USE_PIPE1_WRITER +#ifdef USE_PIPE1_WRITER PRINT_CONFIG_VAR(USE_PIPE1_WRITER) #endif -#if USE_PIPE1_READER +#ifdef USE_PIPE1_READER PRINT_CONFIG_VAR(USE_PIPE1_READER) #endif -#if USE_PIPE2_WRITER || USE_PIPE2_READER +#if defined(USE_PIPE2_WRITER) || defined(USE_PIPE2_READER) struct pipe_periph pipe2; #endif -#if USE_PIPE2_WRITER +#ifdef USE_PIPE2_WRITER PRINT_CONFIG_VAR(USE_PIPE2_WRITER) #endif -#if USE_PIPE2_READER +#ifdef USE_PIPE2_READER PRINT_CONFIG_VAR(USE_PIPE2_READER) #endif diff --git a/sw/airborne/mcu_periph/pipe.h b/sw/airborne/mcu_periph/pipe.h index 9489c73853..098f87a554 100644 --- a/sw/airborne/mcu_periph/pipe.h +++ b/sw/airborne/mcu_periph/pipe.h @@ -59,7 +59,7 @@ extern bool pipe_check_free_space(struct pipe_periph *p, long *fd, uint16_t extern void pipe_put_byte(struct pipe_periph *p, long fd, uint8_t data); extern void pipe_put_buffer(struct pipe_periph *p, long fd, const uint8_t *data,uint16_t len); -#if USE_PIPE0_WRITER || USE_PIPE0_READER +#if defined(USE_PIPE0_WRITER) || defined(USE_PIPE0_READER) extern struct pipe_periph pipe0; #ifndef USE_PIPE0_WRITER @@ -73,7 +73,7 @@ extern struct pipe_periph pipe0; #define PIPE0Init() pipe_periph_init(&pipe0, STRINGIFY(USE_PIPE0_READER), STRINGIFY(USE_PIPE0_WRITER)) #endif // USE_PIPE0 -#if USE_PIPE1_WRITER || USE_PIPE1_READER +#if defined(USE_PIPE1_WRITER) || defined(USE_PIPE1_READER) extern struct pipe_periph pipe1; #ifndef USE_PIPE1_WRITER @@ -87,7 +87,7 @@ extern struct pipe_periph pipe1; #define PIPE1Init() pipe_periph_init(&pipe1, STRINGIFY(USE_PIPE1_READER), STRINGIFY(USE_PIPE1_WRITER)) #endif // USE_PIPE1 -#if USE_PIPE2_WRITER || USE_PIPE2_READER +#if defined(USE_PIPE2_WRITER) || defined(USE_PIPE2_READER) extern struct pipe_periph pipe2; #ifndef USE_PIPE2_WRITER