Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tunnel_hw.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 The Paparazzi Team
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #include <stm32/flash.h>
25 #include <stm32/misc.h>
26 #include <stm32/gpio.h>
27 #include <stm32/rcc.h>
28 
29 #include BOARD_CONFIG
30 #include "mcu.h"
31 #include "mcu_periph/sys_time.h"
32 #include "led.h"
33 
34 #define A_PERIPH RCC_APB2Periph_GPIOA
35 #define A_RX_PIN GPIO_Pin_10
36 #define A_RX_PORT GPIOA
37 #define A_TX_PIN GPIO_Pin_9
38 #define A_TX_PORT GPIOA
39 
40 #define B_PERIPH RCC_APB2Periph_GPIOA
41 #define B_RX_PIN GPIO_Pin_3
42 #define B_RX_PORT GPIOA
43 #define B_TX_PIN GPIO_Pin_2
44 #define B_TX_PORT GPIOA
45 
46 static inline void main_periodic( void );
47 static inline void main_event( void );
48 
49 void Delay(__IO uint32_t nCount) {
50  for(; nCount != 0; nCount--);
51 }
52 
53 int main(void) {
54 
55  mcu_init();
57 
58  /* init RCC */
59  RCC_APB2PeriphClockCmd(A_PERIPH , ENABLE);
60  // RCC_APB2PeriphClockCmd(B_PERIPH , ENABLE);
61  // GPIO_DeInit(A_RX_PORT);
62  /* Init GPIO for rx pins */
63  GPIO_InitTypeDef GPIO_InitStructure;
64  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
65  // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
66  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
67  GPIO_InitStructure.GPIO_Pin = A_RX_PIN;
68  GPIO_Init(A_RX_PORT, &GPIO_InitStructure);
69  GPIO_InitStructure.GPIO_Pin = B_RX_PIN;
70  GPIO_Init(B_RX_PORT, &GPIO_InitStructure);
71  /* Init GPIO for tx pins */
72  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
73  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
74  GPIO_InitStructure.GPIO_Pin = A_TX_PIN;
75  GPIO_Init(A_TX_PORT, &GPIO_InitStructure);
76  GPIO_InitStructure.GPIO_Pin = B_TX_PIN;
77  GPIO_Init(B_TX_PORT, &GPIO_InitStructure);
78 
79  A_TX_PORT->BRR = A_TX_PIN;
80 
81  /* */
82  while (1) {
84  main_periodic();
85  main_event();
86  }
87 
88  return 0;
89 }
90 
91 
92 
93 static inline void main_periodic( void ) {
94  LED_PERIODIC();
95 }
96 
97 static inline void main_event( void ) {
98  // Delay(2000);
99  static uint8_t foo = 0;
100  foo++;
101 
102 #if 0
103  if (!(foo%2))
104  GPIO_WriteBit(B_TX_PORT, B_TX_PIN, Bit_SET);
105  else
106  GPIO_WriteBit(B_TX_PORT, B_TX_PIN, Bit_RESET);
107 #endif
108 
109 #if 0
110  if (!(foo%2))
111  A_TX_PORT->BRR = A_TX_PIN;
112  else
113  A_TX_PORT->BSRR = A_TX_PIN;
114 #endif
115 
116 #if 1
117  GPIO_WriteBit(A_TX_PORT, A_TX_PIN, GPIO_ReadInputDataBit(B_RX_PORT, B_RX_PIN) );
118 #endif
119  if (GPIO_ReadInputDataBit(A_RX_PORT, A_RX_PIN)) {
120  GPIO_WriteBit(B_TX_PORT, B_TX_PIN, Bit_SET);
121  LED_ON(2);
122  }
123  else {
124  GPIO_WriteBit(B_TX_PORT, B_TX_PIN, Bit_RESET);
125  LED_OFF(2);
126  }
127 
128 
129 }
#define LED_ON(i)
Definition: led_hw.h:28
int main(void)
Definition: tunnel_hw.c:53
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
void Delay(__IO uint32_t nCount)
Definition: tunnel_hw.c:49
#define B_RX_PIN
Definition: tunnel_hw.c:41
static void main_event(void)
Definition: tunnel_hw.c:97
Architecture independent timing functions.
#define B_TX_PIN
Definition: tunnel_hw.c:43
unsigned long uint32_t
Definition: types.h:18
#define A_TX_PIN
Definition: tunnel_hw.c:37
uint16_t foo
Definition: main_demo5.c:54
static void main_periodic(void)
Definition: tunnel_hw.c:93
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:35
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
#define A_RX_PORT
Definition: tunnel_hw.c:36
#define LED_PERIODIC()
Definition: led_hw.h:8
arch independent mcu ( Micro Controller Unit ) utilities
#define A_RX_PIN
Definition: tunnel_hw.c:35
unsigned char uint8_t
Definition: types.h:14
#define B_TX_PORT
Definition: tunnel_hw.c:44
#define B_RX_PORT
Definition: tunnel_hw.c:42
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
#define A_PERIPH
Definition: tunnel_hw.c:34
#define A_TX_PORT
Definition: tunnel_hw.c:38
void mcu_init(void)
Definition: mcu.c:57