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
lisa_test_max1168.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
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 <stm32/gpio.h>
23 #include <stm32/flash.h>
24 #include <stm32/misc.h>
25 #include <stm32/spi.h>
26 #include <stm32/dma.h>
27 #include <stm32/exti.h>
28 
29 #include BOARD_CONFIG
30 #include "mcu.h"
31 #include "mcu_periph/sys_time.h"
33 #include "peripherals/max1168.h"
34 #include "led.h"
35 
36 static inline void main_init( void );
37 static inline void main_periodic_task( void );
38 static inline void main_event_task( void );
39 
40 static inline void main_spi2_init(void);
41 
42 int main(void) {
43  main_init();
44 
45  while(1) {
49  }
50 
51  return 0;
52 }
53 
54 
55 static inline void main_init( void ) {
56  mcu_init();
58  max1168_init();
60 }
61 
62 static inline void main_periodic_task( void ) {
63  // LED_TOGGLE(6);
64  max1168_read();
65  RunOnceEvery(10,
66  {
67  DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &sys_time.nb_sec);
68  LED_PERIODIC();
69  });
70 
71 }
72 
73 static inline void main_event_task( void ) {
75  RunOnceEvery(10, {
76  DOWNLINK_SEND_IMU_GYRO_RAW(DefaultChannel, DefaultDevice, &max1168_values[0], &max1168_values[1], &max1168_values[2]);
77  DOWNLINK_SEND_IMU_ACCEL_RAW(DefaultChannel, DefaultDevice, &max1168_values[3], &max1168_values[4], &max1168_values[6]);
78  // DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &max1168_values[7]); });
79  });
81  }
82 }
83 
84 
85 static inline void main_spi2_init( void ) {
86 
87  /* set mag ss as output and assert it (on PC12) ------------------------------*/
88  /* set mag reset as output and assert it (on PC13) ------------------------------*/
89  GPIOC->BSRR = GPIO_Pin_12;
90  GPIOC->BSRR = GPIO_Pin_13;
91 
92  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
93  GPIO_InitTypeDef GPIO_InitStructure;
94  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
95  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
96  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
97  GPIO_Init(GPIOC, &GPIO_InitStructure);
98 
99  /* Enable SPI2 Periph clock -------------------------------------------------*/
100  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
101 
102  /* Configure GPIOs: SCK, MISO and MOSI --------------------------------*/
103  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
104  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
105  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
106  GPIO_Init(GPIOB, &GPIO_InitStructure);
107 
108  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
109 
110  Max1168ConfigureSPI();
111 
112  /* Enable SPI */
113  SPI_Cmd(SPI2, ENABLE);
114 
115  /* Enable SPI_2 DMA clock ---------------------------------------------------*/
116  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
117 
118 }
119 
void max1168_init(void)
Definition: max1168.c:40
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:61
uint16_t max1168_values[MAX1168_NB_CHAN]
Definition: max1168.c:28
int main(void)
static void main_periodic_task(void)
#define MAX1168_IDLE
Definition: max1168.h:59
Architecture independent timing functions.
static void main_spi2_init(void)
void max1168_read(void)
Definition: max1168_arch.c:26
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
static void main_init(void)
volatile uint8_t max1168_status
Definition: max1168.c:27
#define LED_PERIODIC()
Definition: led_hw.h:8
Arch independent mcu ( Micro Controller Unit ) utilities.
#define MAX1168_DATA_AVAILABLE
Definition: max1168.h:63
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
arch independent LED (Light Emitting Diodes) API
static void main_event_task(void)