Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
uart_tunnel.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 The Paparazzi Team
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 #include BOARD_CONFIG
23 #include "mcu.h"
24 #include "mcu_periph/sys_time.h"
25 #include "mcu_periph/gpio.h"
26 #include "led.h"
27 
28 /* UART1 */
29 #define A_PORT GPIOA
30 #define A_RX_PIN GPIO10
31 #define A_RX_PORT A_PORT
32 #define A_TX_PIN GPIO9
33 #define A_TX_PORT A_PORT
34 
35 /* UART2 */
36 #define B_PORT GPIOA
37 #define B_RX_PIN GPIO3
38 #define B_RX_PORT B_PORT
39 #define B_TX_PIN GPIO2
40 #define B_TX_PORT B_PORT
41 
42 static inline void main_periodic(void);
43 static inline void main_event(void);
44 void Delay(volatile uint32_t nCount);
45 
46 void Delay(volatile uint32_t nCount)
47 {
48  for (; nCount != 0; nCount--);
49 }
50 
51 int main(void)
52 {
53 
54  mcu_init();
55  sys_time_register_timer((1. / PERIODIC_FREQUENCY), NULL);
56 
57  /* Init GPIO for rx pins */
60 
61  /* Init GPIO for tx pins */
64 
66 
67  /* */
68  while (1) {
70  main_periodic();
71  }
72  main_event();
73  }
74 
75  return 0;
76 }
77 
78 
79 
80 static inline void main_periodic(void)
81 {
82  LED_PERIODIC();
83 }
84 
85 static inline void main_event(void)
86 {
87  // Delay(2000);
88  static uint8_t foo = 0;
89  foo++;
90 
91 #if 0
92  if (!(foo % 2)) {
94  } else {
96  }
97 #endif
98 
99 #if 0
100  if (!(foo % 2)) {
102  } else {
104  }
105 #endif
106 
107 #if 1
108  /* passthrough B_RX to A_TX */
109  if (GPIO_IDR(B_RX_PORT) & B_RX_PIN) {
111  } else {
113  }
114 #endif
115  /* passthrough A_RX to B_TX */
116  if (gpio_get(A_RX_PORT, A_RX_PIN)) {
118  LED_ON(2);
119  } else {
121  LED_OFF(2);
122  }
123 
124 
125 }
LED_OFF
#define LED_OFF(i)
Definition: led_hw.h:52
A_RX_PORT
#define A_RX_PORT
Definition: uart_tunnel.c:31
Delay
void Delay(volatile uint32_t nCount)
Definition: uart_tunnel.c:46
main
int main(int argc, char **argv)
Definition: uart_tunnel.c:14
gpio_setup_output
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
uint32_t
unsigned long uint32_t
Definition: types.h:18
LED_ON
#define LED_ON(i)
Definition: led_hw.h:51
B_TX_PIN
#define B_TX_PIN
Definition: uart_tunnel.c:39
foo
uint16_t foo
Definition: main_demo5.c:59
B_RX_PIN
#define B_RX_PIN
Definition: uart_tunnel.c:37
gpio_clear
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
Definition: gpio_arch.h:108
A_RX_PIN
#define A_RX_PIN
Definition: uart_tunnel.c:30
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
sys_time.h
Architecture independent timing functions.
LED_PERIODIC
#define LED_PERIODIC()
Definition: led_hw.h:55
A_TX_PIN
#define A_TX_PIN
Definition: uart_tunnel.c:32
uint8_t
unsigned char uint8_t
Definition: types.h:14
led.h
arch independent LED (Light Emitting Diodes) API
B_RX_PORT
#define B_RX_PORT
Definition: uart_tunnel.c:38
gpio_get
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition: gpio_arch.h:88
gpio.h
main_event
static void main_event(void)
Definition: uart_tunnel.c:85
sys_time_register_timer
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43
gpio_setup_input_pullup
void gpio_setup_input_pullup(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull up resistor enabled.
Definition: gpio_arch.c:47
gpio_set
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
Definition: gpio_arch.h:98
mcu_init
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:87
sys_time_check_and_ack_timer
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:114
B_TX_PORT
#define B_TX_PORT
Definition: uart_tunnel.c:40
A_TX_PORT
#define A_TX_PORT
Definition: uart_tunnel.c:33
main_periodic
static void main_periodic(void)
Definition: uart_tunnel.c:80