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
mag_micromag_fw_hw.c
Go to the documentation of this file.
1 /* PNI micromag3 connected on SPI1 */
2 /*
3  Tiny2 (fixed wing)
4  SS on P0.20 (SSEL)
5  RESET on P0.29 (ADC5)
6  DRDY on P0.16 ( EINT0 )
7 */
8 
9 #include "led.h"
12 
14 
15 static void SSP_ISR(void) __attribute__((naked));
16 static void EXTINT_ISR(void) __attribute__((naked));
17 
18 #warning "This driver should be updated to use the new SPI peripheral"
19 
20 #ifndef SPI1_VIC_SLOT
21 #define SPI1_VIC_SLOT 7
22 #endif
23 
24 static void SSP_ISR(void) {
25  ISR_ENTRY();
26 
27  MmOnSpiIt();
28 
29  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
30  ISR_EXIT();
31 }
32 
33 void EXTINT_ISR(void) {
34  ISR_ENTRY();
35 //LED_TOGGLE(3);
36 
37  /* no, we won't do anything asynchronously, so just notify */
39  /* clear EINT */
40  SetBit(EXTINT,MM_DRDY_EINT);
41 // EXTINT = (1<<MM_DRDY_EINT);
42  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
43  ISR_EXIT();
44 }
45 
46 void micromag_hw_init( void ) {
47  /* setup pins for SSP (SCK, MISO, MOSI, SSEL) */
49 
50  /* setup SSP */
51  SSPCR0 = SSPCR0_VAL;;
53  SSPCPSR = 0x02;
54 
55  /* initialize interrupt vector */
56  VICIntSelect &= ~VIC_BIT( VIC_SPI1 ); /* SPI1 selected as IRQ */
57  VICIntEnable = VIC_BIT( VIC_SPI1 ); /* enable it */
59  _VIC_ADDR(SPI1_VIC_SLOT) = (uint32_t)SSP_ISR; /* address of the ISR */
60 
61  MmUnselect(); /* pin idles high */
62  /* configure SS pin */
63  SetBit(MM_SS_IODIR, MM_SS_PIN); /* pin is output */
64 
65  /* configure RESET pin */
66  SetBit(MM_RESET_IODIR, MM_RESET_PIN); /* pin is output */
67  MmReset(); /* pin idles low */
68 
69  /* configure DRDY pin */
70  /* connected pin to EXINT */
71  MM_DRDY_PINSEL |= MM_DRDY_PINSEL_VAL << MM_DRDY_PINSEL_BIT;
72  SetBit(EXTMODE, MM_DRDY_EINT); /* EINT is edge trigered */
73  SetBit(EXTPOLAR,MM_DRDY_EINT); /* EINT is trigered on rising edge */
74  SetBit(EXTINT,MM_DRDY_EINT); /* clear pending EINT */
75 
76  /* initialize interrupt vector */
77  VICIntSelect &= ~VIC_BIT( MM_DRDY_VIC_IT ); /* select EINT as IRQ source */
78  VICIntEnable = VIC_BIT( MM_DRDY_VIC_IT ); /* enable it */
79  _VIC_CNTL(MICROMAG_DRDY_VIC_SLOT) = VIC_ENABLE | MM_DRDY_VIC_IT;
80  _VIC_ADDR(MICROMAG_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; // address of the ISR
81 }
82 
83 
#define VICIntSelect
Definition: LPC21xx.h:430
#define SSP_PINSEL1_MOSI
Definition: spi_arch.c:367
#define MmReset()
#define MmUnselect()
#define SSPCPSR
Definition: LPC21xx.h:226
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
#define SSPCR0_VAL
#define EXTMODE
Definition: LPC21xx.h:419
#define SSPCR1_VAL
#define SSPCR0
Definition: LPC21xx.h:222
#define _VIC_ADDR(idx)
Definition: armVIC.h:20
volatile uint8_t micromag_cur_axe
#define EXTPOLAR
Definition: LPC21xx.h:420
#define EXTINT
Definition: LPC21xx.h:417
#define SPI1_VIC_SLOT
#define VICVectAddr
Definition: LPC21xx.h:436
unsigned long uint32_t
Definition: types.h:18
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
#define MM_GOT_EOC
unsigned char uint8_t
Definition: types.h:14
#define ISR_EXIT()
Definition: armVIC.h:61
#define SSP_PINSEL1_SCK
Definition: spi_arch.c:365
#define VICIntEnable
Definition: LPC21xx.h:431
static void EXTINT_ISR(void)
#define PINSEL1
Definition: LPC21xx.h:348
#define VIC_SPI1
Definition: lpcVIC.h:81
arch independent LED (Light Emitting Diodes) API
static void SSP_ISR(void)
#define SSPCR1
Definition: LPC21xx.h:223
#define SSP_PINSEL1_MISO
Definition: spi_arch.c:366
#define ISR_ENTRY()
Definition: armVIC.h:40
void micromag_hw_init(void)
#define VIC_ENABLE
Definition: lpcVIC.h:102
#define MmOnSpiIt()
volatile uint8_t micromag_status