Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ms2100_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
3  * Copyright (C) 2012 Gautier Hattenberger
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
29 #include "peripherals/ms2100.h"
30 
31 #include "LPC21xx.h"
32 #include "armVIC.h"
33 #include "mcu_periph/sys_time.h"
34 #include BOARD_CONFIG
35 
36 static void EXTINT_ISR(void) __attribute__((naked));
37 
38 void ms2100_arch_init(void)
39 {
40 
41  /* configure RESET pin */
42  Ms2100Reset(); /* pin idles low */
43  SetBit(MS2100_RESET_IODIR, MS2100_RESET_PIN); /* pin is output */
44 
45  /* configure DRDY pin */
46  /* connected pin to EXINT */
48  SetBit(EXTMODE, MS2100_DRDY_EINT); /* EINT is edge trigered */
49  SetBit(EXTPOLAR, MS2100_DRDY_EINT); /* EINT is trigered on rising edge */
50  SetBit(EXTINT, MS2100_DRDY_EINT); /* clear pending EINT */
51 
52  /* initialize interrupt vector */
53  VICIntSelect &= ~VIC_BIT(MS2100_DRDY_VIC_IT); /* select EINT as IRQ source */
54  VICIntEnable = VIC_BIT(MS2100_DRDY_VIC_IT); /* enable it */
55  _VIC_CNTL(MS2100_DRDY_VIC_SLOT) = VIC_ENABLE | MS2100_DRDY_VIC_IT;
56  _VIC_ADDR(MS2100_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; // address of the ISR
57 
58 }
59 
60 void EXTINT_ISR(void)
61 {
62  ISR_ENTRY();
63  /* no, we won't do anything asynchronously, so just notify */
65  /* clear EINT */
66  EXTINT = (1 << MS2100_DRDY_EINT);
67  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
68  ISR_EXIT();
69 }
70 
71 void ms2100_reset_cb(struct spi_transaction *t __attribute__((unused)))
72 {
73  // set RESET pin high for at least 100 nsec
74  // busy wait should not harm
75  // storing start and dt is probably long enough...
76  Ms2100Set();
77  uint32_t start = T0TC;
78  uint32_t dt = cpu_ticks_of_nsec(110);
79  while ((uint32_t)(T0TC - start) < dt);
80  Ms2100Reset();
81 }
82 
#define VICIntSelect
Definition: LPC21xx.h:430
#define MS2100_DRDY_PINSEL_VAL
Definition: booz_1.0.h:150
static uint32_t cpu_ticks_of_nsec(uint32_t nsec)
Definition: sys_time.h:188
#define MS2100_DRDY_EINT
Definition: booz_1.0.h:151
static void EXTINT_ISR(void)
Definition: ms2100_arch.c:60
Driver for the ms2100 magnetic sensor from PNI.
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
void ms2100_reset_cb(struct spi_transaction *t)
Reset callback.
Definition: ms2100_arch.c:71
SPI transaction structure.
Definition: spi.h:142
#define EXTMODE
Definition: LPC21xx.h:419
#define _VIC_ADDR(idx)
Definition: armVIC.h:20
#define EXTPOLAR
Definition: LPC21xx.h:420
#define EXTINT
Definition: LPC21xx.h:417
#define MS2100_RESET_PIN
Definition: booz_1.0.h:142
Architecture independent timing functions.
void ms2100_arch_init(void)
Definition: ms2100_arch.c:38
#define MS2100_DRDY_VIC_IT
Definition: booz_1.0.h:152
#define T0TC
Definition: LPC21xx.h:52
#define Ms2100Set()
Definition: ms2100_arch.h:35
#define VICVectAddr
Definition: LPC21xx.h:436
unsigned long uint32_t
Definition: types.h:18
struct Ms2100 ms2100
Definition: ms2100.c:44
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
#define ISR_EXIT()
Definition: armVIC.h:61
#define VICIntEnable
Definition: LPC21xx.h:431
#define Ms2100Reset()
Definition: ms2100_arch.h:34
#define MS2100_DRDY_PINSEL_BIT
Definition: booz_1.0.h:149
enum Ms2100Status status
Definition: ms2100.h:50
#define MS2100_RESET_IODIR
Definition: booz_1.0.h:143
#define MS2100_DRDY_PINSEL
Definition: booz_1.0.h:148
#define ISR_ENTRY()
Definition: armVIC.h:40
#define VIC_ENABLE
Definition: lpcVIC.h:102