Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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) 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 "interrupt_hw.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  /* configure RESET pin */
41  Ms2100Reset(); /* pin idles low */
42  SetBit(MS2100_RESET_IODIR, MS2100_RESET_PIN); /* pin is output */
43 
44  /* configure DRDY pin */
45  /* connected pin to EXINT */
47  SetBit(EXTMODE, MS2100_DRDY_EINT); /* EINT is edge trigered */
48  SetBit(EXTPOLAR, MS2100_DRDY_EINT); /* EINT is trigered on rising edge */
49  SetBit(EXTINT, MS2100_DRDY_EINT); /* clear pending EINT */
50 
51  /* initialize interrupt vector */
52  VICIntSelect &= ~VIC_BIT( MS2100_DRDY_VIC_IT ); /* select EINT as IRQ source */
53  VICIntEnable = VIC_BIT( MS2100_DRDY_VIC_IT ); /* enable it */
54  _VIC_CNTL(MS2100_DRDY_VIC_SLOT) = VIC_ENABLE | MS2100_DRDY_VIC_IT;
55  _VIC_ADDR(MS2100_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; // address of the ISR
56 
57 }
58 
59 void EXTINT_ISR(void) {
60  ISR_ENTRY();
61  /* no, we won't do anything asynchronously, so just notify */
63  /* clear EINT */
64  EXTINT = (1<<MS2100_DRDY_EINT);
65  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
66  ISR_EXIT();
67 }
68 
69 void ms2100_reset_cb( struct spi_transaction * t __attribute__ ((unused)) ) {
70  // set RESET pin high for at least 100 nsec
71  // busy wait should not harm
72  // storing start and dt is probably long enough...
73  Ms2100Set();
74  uint32_t start = T0TC;
76  while ((uint32_t)(T0TC - start) < dt);
77  Ms2100Reset();
78 }
79 
#define VICIntSelect
Definition: LPC21xx.h:430
enum Ms2100Status status
Definition: ms2100.h:50
#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:172
#define MS2100_DRDY_EINT
Definition: booz_1.0.h:151
static const float dt
static void EXTINT_ISR(void)
Definition: ms2100_arch.c:59
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:69
#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
SPI transaction structure.
Definition: spi.h:142
#define Ms2100Reset()
Definition: ms2100_arch.h:34
#define MS2100_DRDY_PINSEL_BIT
Definition: booz_1.0.h:149
#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