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