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
ms2100_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 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 
28 #include "peripherals/ms2100.h"
29 #include "mcu_periph/sys_time.h"
30 
31 #include <libopencm3/stm32/f1/rcc.h>
32 #include <libopencm3/stm32/f1/nvic.h>
33 #include <libopencm3/stm32/f1/gpio.h>
34 #include <libopencm3/stm32/exti.h>
35 
36 void ms2100_arch_init( void ) {
37 
38  /* set mag reset as output (reset on PC13) ----*/
39  rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN);
40  gpio_set(GPIOC, GPIO13);
41  gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
42  Ms2100Reset();
43 
44  /* configure data ready input on PB5 */
45  rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN);
46  gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO5);
47 
48  /* external interrupt for drdy pin */
49  exti_select_source(EXTI5, GPIOB);
50  exti_set_trigger(EXTI5, EXTI_TRIGGER_RISING);
51  exti_enable_request(EXTI5);
52 
53  nvic_set_priority(NVIC_EXTI9_5_IRQ, 0x0f);
54  nvic_enable_irq(NVIC_EXTI9_5_IRQ);
55 }
56 
57 void ms2100_reset_cb( struct spi_transaction * t __attribute__ ((unused)) ) {
58  // set RESET pin high for at least 100 nsec
59  // busy wait should not harm
60  Ms2100Set();
61 
62  // FIXME, make nanosleep funcion
63  uint32_t dt_ticks = cpu_ticks_of_nsec(110);
64  int32_t end_cpu_ticks = systick_get_value() - dt_ticks;
65  if (end_cpu_ticks < 0)
66  end_cpu_ticks += systick_get_reload();
67  while (systick_get_value() > end_cpu_ticks)
68  ;
69 
70  Ms2100Reset();
71 }
72 
73 void exti9_5_isr(void) {
75  exti_reset_request(EXTI5);
76 }
enum Ms2100Status status
Definition: ms2100.h:50
static uint32_t cpu_ticks_of_nsec(uint32_t nsec)
Definition: sys_time.h:172
Driver for the ms2100 magnetic sensor from PNI.
void ms2100_reset_cb(struct spi_transaction *t)
Reset callback.
Definition: ms2100_arch.c:69
Architecture independent timing functions.
void ms2100_arch_init(void)
Definition: ms2100_arch.c:38
#define Ms2100Set()
Definition: ms2100_arch.h:35
unsigned long uint32_t
Definition: types.h:18
struct Ms2100 ms2100
Definition: ms2100.c:44
int gpio_set(int nr, int val)
Definition: gpio_ardrone.c:32
signed long int32_t
Definition: types.h:19
void exti9_5_isr(void)
Definition: ms2100_arch.c:73
SPI transaction structure.
Definition: spi.h:142
#define Ms2100Reset()
Definition: ms2100_arch.h:34