Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 <libopencm3/stm32/gpio.h>
23 #include <libopencm3/stm32/rcc.h>
24 
25 #include BOARD_CONFIG
26 #include "mcu.h"
27 #include "mcu_periph/sys_time.h"
28 #include "led.h"
29 
30 /* UART1 */
31 #define A_PERIPH RCC_APB2ENR_IOPAEN
32 #define A_PORT GPIOA
33 #define A_RX_PIN GPIO10
34 #define A_RX_PORT A_PORT
35 #define A_TX_PIN GPIO9
36 #define A_TX_PORT A_PORT
37 
38 /* UART2 */
39 #define B_PERIPH RCC_APB2ENR_IOPAEN
40 #define B_PORT GPIOA
41 #define B_RX_PIN GPIO3
42 #define B_RX_PORT B_PORT
43 #define B_TX_PIN GPIO2
44 #define B_TX_PORT B_PORT
45 
46 static inline void main_periodic( void );
47 static inline void main_event( void );
48 void Delay(volatile uint32_t nCount);
49 
50 void Delay(volatile uint32_t nCount) {
51  for(; nCount != 0; nCount--);
52 }
53 
54 int main(void) {
55 
56  mcu_init();
58 
59  /* init RCC */
60  rcc_peripheral_enable_clock(&RCC_APB2ENR, A_PERIPH);
61  // rccp_perihperal_enable_clock(&RCC_APB2ENR, B_PERIPH);
62 
63  /* Init GPIO for rx pins */
65  gpio_set_mode(A_RX_PORT, GPIO_MODE_INPUT,
66  GPIO_CNF_INPUT_PULL_UPDOWN, A_RX_PIN);
68  gpio_set_mode(B_RX_PORT, GPIO_MODE_INPUT,
69  GPIO_CNF_INPUT_PULL_UPDOWN, B_RX_PIN);
70 
71  /* Init GPIO for tx pins */
72  gpio_set_mode(A_RX_PORT, GPIO_MODE_OUTPUT_50_MHZ,
73  GPIO_CNF_OUTPUT_PUSHPULL, A_TX_PIN);
74  gpio_set_mode(B_RX_PORT, GPIO_MODE_OUTPUT_50_MHZ,
75  GPIO_CNF_OUTPUT_PUSHPULL, B_TX_PIN);
76 
78 
79  /* */
80  while (1) {
82  main_periodic();
83  main_event();
84  }
85 
86  return 0;
87 }
88 
89 
90 
91 static inline void main_periodic( void ) {
92  LED_PERIODIC();
93 }
94 
95 static inline void main_event( void ) {
96  // Delay(2000);
97  static uint8_t foo = 0;
98  foo++;
99 
100 #if 0
101  if (!(foo%2))
103  else
105 #endif
106 
107 #if 0
108  if (!(foo%2))
110  else
112 #endif
113 
114 #if 1
115  /* passthrough B_RX to A_TX */
116  if (GPIO_IDR(B_RX_PORT) & B_RX_PIN)
118  else
120 #endif
121  /* passthrough A_RX to B_TX */
122  if (gpio_get(A_RX_PORT, A_RX_PIN)) {
124  LED_ON(2);
125  }
126  else {
128  LED_OFF(2);
129  }
130 
131 
132 }
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:61
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
#define LED_ON(i)
Definition: led_hw.h:28
int main(int argc, char **argv)
Definition: uart_tunnel.c:14
#define B_TX_PORT
Definition: uart_tunnel.c:44
#define A_TX_PORT
Definition: uart_tunnel.c:36
#define B_TX_PIN
Definition: uart_tunnel.c:43
Architecture independent timing functions.
static void main_event(void)
Definition: uart_tunnel.c:95
unsigned long uint32_t
Definition: types.h:18
#define B_RX_PIN
Definition: uart_tunnel.c:41
uint16_t foo
Definition: main_demo5.c:54
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:37
static bool_t sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:111
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
#define B_RX_PORT
Definition: uart_tunnel.c:42
#define LED_PERIODIC()
Definition: led_hw.h:8
#define A_RX_PIN
Definition: uart_tunnel.c:33
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
static void main_periodic(void)
Definition: uart_tunnel.c:91
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:51
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
#define A_RX_PORT
Definition: uart_tunnel.c:34
#define A_TX_PIN
Definition: uart_tunnel.c:35
void Delay(volatile uint32_t nCount)
Definition: uart_tunnel.c:50
#define A_PERIPH
Definition: uart_tunnel.c:31
uint16_t gpio_get(uint32_t gpioport, uint16_t gpios)
Read a gpio value.