Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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/rcc.h>
32 #include <libopencm3/stm32/gpio.h>
33 #include <libopencm3/stm32/exti.h>
34 #include <libopencm3/cm3/nvic.h>
35 
36 #ifndef STM32F1
37 #error "MS2100 arch currently only implemented for STM32F1"
38 #endif
39 
40 void ms2100_arch_init(void)
41 {
42 
43  /* set mag reset as output (reset on PC13) ----*/
44  rcc_periph_clock_enable(RCC_GPIOC);
45  rcc_periph_clock_enable(RCC_AFIO);
47  gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
48  Ms2100Reset();
49 
50  /* configure data ready input on PB5 */
51  rcc_periph_clock_enable(RCC_GPIOB);
52  gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO5);
53 
54  /* external interrupt for drdy pin */
55  exti_select_source(EXTI5, GPIOB);
56  exti_set_trigger(EXTI5, EXTI_TRIGGER_RISING);
57  exti_enable_request(EXTI5);
58 
59  nvic_set_priority(NVIC_EXTI9_5_IRQ, 0x0f);
60  nvic_enable_irq(NVIC_EXTI9_5_IRQ);
61 }
62 
63 void ms2100_reset_cb(struct spi_transaction *t __attribute__((unused)))
64 {
65  // set RESET pin high for at least 100 nsec
66  // busy wait should not harm
67  Ms2100Set();
68 
69  // FIXME, make nanosleep funcion
70  uint32_t dt_ticks = cpu_ticks_of_nsec(110);
71  int32_t end_cpu_ticks = systick_get_value() - dt_ticks;
72  if (end_cpu_ticks < 0) {
73  end_cpu_ticks += systick_get_reload();
74  }
75  while (systick_get_value() > (uint32_t)end_cpu_ticks)
76  ;
77 
78  Ms2100Reset();
79 }
80 
81 void exti9_5_isr(void)
82 {
84  exti_reset_request(EXTI5);
85 }
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
Definition: gpio_arch.h:104
#define GPIO5
Definition: gpio_def.h:36
#define GPIO13
Definition: gpio_def.h:44
SPI transaction structure.
Definition: spi.h:148
struct Ms2100 ms2100
Definition: ms2100.c:44
Driver for the ms2100 magnetic sensor from PNI.
@ MS2100_GOT_EOC
Definition: ms2100.h:39
enum Ms2100Status status
Definition: ms2100.h:50
void ms2100_arch_init(void)
Definition: ms2100_arch.c:40
void exti9_5_isr(void)
Definition: ms2100_arch.c:81
void ms2100_reset_cb(struct spi_transaction *t)
Reset callback.
Definition: ms2100_arch.c:63
static void Ms2100Set(void)
Here Set indicates the Ms2100 is in reset state, i.e.
Definition: ms2100_arch.h:47
static void Ms2100Reset(void)
Here Reset indicates the Ms2100 is in normal state, i.e.
Definition: ms2100_arch.h:38
#define GPIOC
Definition: gpio_arch.h:36
#define GPIOB
Definition: gpio_arch.h:35
Architecture independent timing functions.
static uint32_t cpu_ticks_of_nsec(uint32_t nsec)
Definition: sys_time.h:197
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78