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
lisa_test_max1168.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2009 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/max1168.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  max1168_init();
62 }
63 
64 static inline void main_periodic_task( void ) {
65  // LED_TOGGLE(6);
66  max1168_read();
67  RunOnceEvery(10,
68  {
69  DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &sys_time.nb_sec);
70  LED_PERIODIC();
71  });
72 
73 }
74 
75 static inline void main_event_task( void ) {
77  RunOnceEvery(10, {
78  DOWNLINK_SEND_IMU_GYRO_RAW(DefaultChannel, DefaultDevice, &max1168_values[0], &max1168_values[1], &max1168_values[2]);
79  DOWNLINK_SEND_IMU_ACCEL_RAW(DefaultChannel, DefaultDevice, &max1168_values[3], &max1168_values[4], &max1168_values[6]);
80  // DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &max1168_values[7]); });
81  });
83  }
84 }
85 
86 
87 static inline void main_spi2_init( void ) {
88 
89  /* set mag ss as output and assert it (on PC12) ------------------------------*/
90  /* set mag reset as output and assert it (on PC13) ------------------------------*/
91  GPIOC->BSRR = GPIO_Pin_12;
92  GPIOC->BSRR = GPIO_Pin_13;
93 
94  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
95  GPIO_InitTypeDef GPIO_InitStructure;
96  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
97  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
98  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
99  GPIO_Init(GPIOC, &GPIO_InitStructure);
100 
101  /* Enable SPI2 Periph clock -------------------------------------------------*/
102  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
103 
104  /* Configure GPIOs: SCK, MISO and MOSI --------------------------------*/
105  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
106  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
107  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
108  GPIO_Init(GPIOB, &GPIO_InitStructure);
109 
110  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
111 
113 
114  /* Enable SPI */
115  SPI_Cmd(SPI2, ENABLE);
116 
117  /* Enable SPI_2 DMA clock ---------------------------------------------------*/
118  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
119 
120 }
121 
void max1168_init(void)
Definition: max1168.c:31
uint16_t max1168_values[MAX1168_NB_CHAN]
Definition: max1168.c:29
int main(void)
static void main_periodic_task(void)
#define STA_MAX1168_IDLE
Definition: max1168.h:33
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
Architecture independent timing functions.
static void main_spi2_init(void)
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_init(void)
volatile uint8_t max1168_status
Definition: max1168.c:28
#define LED_PERIODIC()
Definition: led_hw.h:8
arch independent mcu ( Micro Controller Unit ) utilities
#define STA_MAX1168_DATA_AVAILABLE
Definition: max1168.h:36
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:55
arch independent LED (Light Emitting Diodes) API
void max1168_read(void)
Definition: max1168_arch.c:52
#define Max1168ConfigureSPI()
Definition: max1168_arch.h:55
static void main_event_task(void)
void mcu_init(void)
Definition: mcu.c:57