Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lisa_test_ms2100.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
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/gpio.h>
25 #include <stm32/flash.h>
26 #include <stm32/misc.h>
27 #include <stm32/spi.h>
28 #include <stm32/dma.h>
29 #include <stm32/exti.h>
30 
31 #include BOARD_CONFIG
32 #include "mcu.h"
33 #include "mcu_periph/sys_time.h"
35 #include "peripherals/ms2100.h"
36 #include "led.h"
37 
38 static inline void main_init( void );
39 static inline void main_periodic_task( void );
40 static inline void main_event_task( void );
41 
42 static inline void main_spi2_init(void);
43 
44 int main(void) {
45  main_init();
46 
47  while(1) {
51  }
52 
53  return 0;
54 }
55 
56 
57 static inline void main_init( void ) {
58  mcu_init();
60  ms2100_init();
62 }
63 
64 static inline void main_periodic_task( void ) {
65  RunOnceEvery(10,
66  {
67  DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &sys_time.nb_sec);
68  LED_PERIODIC();
69  });
70 
71  switch(ms2100_status) {
72  case MS2100_IDLE:
73  Ms2100SendReq();
74  break;
75  case MS2100_WAITING_EOC:
76  if (Ms2100HasEOC()) {
77  Ms2100ReadRes();
78  }
79  break;
80  }
81 }
82 
83 static inline void main_event_task( void ) {
85  RunOnceEvery(10, {
86  DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice,
87  &ms2100_values[0],
88  &ms2100_values[1],
89  &ms2100_values[2]);
90  });
92  }
93 }
94 
95 static inline void main_spi2_init( void ) {
96 
97  /* set max1168 slave select as output and assert it ( on PB12) */
98  GPIOB->BSRR = GPIO_Pin_12;
99  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
100  GPIO_InitTypeDef GPIO_InitStructure;
101  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
102  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
103  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
104  GPIO_Init(GPIOB, &GPIO_InitStructure);
105 
106  /* Enable SPI2 Periph clock -------------------------------------------------*/
107  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
108 
109  /* Configure GPIOs: SCK, MISO and MOSI --------------------------------*/
110  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
111  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
112  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
113  GPIO_Init(GPIOB, &GPIO_InitStructure);
114 
115  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
116 
117 
118  /* Enable SPI_2 DMA clock ---------------------------------------------------*/
119  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
120 
121 
122 
123 }
124 
volatile int16_t ms2100_values[MS2100_NB_AXIS]
Definition: ms2100.c:27
static void main_init(void)
static void main_spi2_init(void)
int main(void)
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define Ms2100SendReq()
Definition: ms2100_arch.h:62
void ms2100_init(void)
Definition: ms2100.c:29
Architecture independent timing functions.
#define MS2100_WAITING_EOC
Definition: ms2100.h:38
#define MS2100_DATA_AVAILABLE
Definition: ms2100.h:41
#define Ms2100HasEOC()
Definition: ms2100_arch.h:39
volatile uint8_t ms2100_status
Definition: ms2100.c:26
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
static void main_periodic_task(void)
#define LED_PERIODIC()
Definition: led_hw.h:8
arch independent mcu ( Micro Controller Unit ) utilities
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:55
static void main_event_task(void)
arch independent LED (Light Emitting Diodes) API
#define MS2100_IDLE
Definition: ms2100.h:35
#define Ms2100ReadRes()
Definition: ms2100_arch.h:75
void mcu_init(void)
Definition: mcu.c:57