Paparazzi UAS  v6.2_unstable
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 }
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
B_TX_PORT
#define B_TX_PORT
Definition: uart_tunnel.c:40
spektrum
static struct spektrum_t spektrum
Definition: spektrum.c:87
main_event
static void main_event(void)
Definition: uart_tunnel.c:85
UART1_RX
#define UART1_RX
Definition: board.h:62
LED_OFF
#define LED_OFF(i)
Definition: led_hw.h:52
B_RX_PIN
#define B_RX_PIN
Definition: uart_tunnel.c:37
A_TX_PIN
#define A_TX_PIN
Definition: uart_tunnel.c:32
USE_AD_TIM4
#define USE_AD_TIM4
Definition: apogee_1.0.h:162
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
SERVO6
#define SERVO6
Definition: board.h:565
A_RX_PIN
#define A_RX_PIN
Definition: uart_tunnel.c:30
LED_ON
#define LED_ON(i)
Definition: led_hw.h:51
foo
uint16_t foo
Definition: main_demo5.c:58
PWM_USE_TIM2
#define PWM_USE_TIM2
Definition: apogee_1.0.h:226
B_RX_PORT
#define B_RX_PORT
Definition: uart_tunnel.c:38
USE_AD_TIM2
#define USE_AD_TIM2
Definition: matek_f405_wing_v1.h:196
gpio_clear
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
Definition: gpio_arch.h:108
PWM_USE_TIM1
#define PWM_USE_TIM1
Definition: cc3d.h:148
PWM_USE_TIM3
#define PWM_USE_TIM3
Definition: apogee_1.0.h:227
A_TX_PORT
#define A_TX_PORT
Definition: uart_tunnel.c:33
PWM_USE_TIM12
#define PWM_USE_TIM12
Definition: matek_f405_wing_v1.h:299
main_periodic
static void main_periodic(void)
Definition: uart_tunnel.c:80
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
config
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200
sys_time.h
Architecture independent timing functions.
LED_PERIODIC
#define LED_PERIODIC()
Definition: led_hw.h:55
led.h
arch independent LED (Light Emitting Diodes) API
Delay
void Delay(volatile uint32_t nCount)
Definition: uart_tunnel.c:46
USE_AD_TIM1
#define USE_AD_TIM1
Definition: cjmcu.h:138
B_TX_PIN
#define B_TX_PIN
Definition: uart_tunnel.c:39
gpio_get
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition: gpio_arch.h:88
pwm
timer subsystem PPM input on SERVO6 pin actuators pwm(if PWM_USE_TIM1) TIM8 radio_control/ppm(if USE_PPM_TIM8)(non-advanced timers using RCC_APB2) TIM2 adc(if USE_AD_TIM2
USE_PPM_TIM8
#define USE_PPM_TIM8
Definition: navstik_1.0.h:114
gpio.h
USE_PPM_TIM1
#define USE_PPM_TIM1
Definition: apogee_1.0.h:342
A_RX_PORT
#define A_RX_PORT
Definition: uart_tunnel.c:31
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
type
timer subsystem type(config options) --------------------------------------------(advanced timers using RCC_APB1) TIM1 adc(if USE_AD_TIM1) radio_control/ppm(if USE_PPM_TIM1
ppm
timer subsystem PPM input on SERVO6 pin actuators default radio_control ppm(if USE_PPM_TIM2, PPM input on UART1_RX pin) actuators/pwm(if PWM_USE_TIM2) TIM3 actuators/pwm(if PWM_USE_TIM3
USE_PPM_TIM2
#define USE_PPM_TIM2
Definition: cc3d.h:107
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
main
int main(void)
Definition: uart_tunnel.c:51
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:97
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:123
radio_control
struct RadioControl radio_control
Definition: radio_control.c:33