Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
19 static void SSP_ISR(void) {
20  ISR_ENTRY();
21 
22  MmOnSpiIt();
23 
24  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
25  ISR_EXIT();
26 }
27 
28 void EXTINT_ISR(void) {
29  ISR_ENTRY();
30 //LED_TOGGLE(3);
31 
32  /* no, we won't do anything asynchronously, so just notify */
34  /* clear EINT */
35  SetBit(EXTINT,MM_DRDY_EINT);
36 // EXTINT = (1<<MM_DRDY_EINT);
37  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
38  ISR_EXIT();
39 }
40 
41 void micromag_hw_init( void ) {
42  /* setup pins for SSP (SCK, MISO, MOSI, SSEL) */
44 
45  /* setup SSP */
46  SSPCR0 = SSPCR0_VAL;;
48  SSPCPSR = 0x02;
49 
50  /* initialize interrupt vector */
51  VICIntSelect &= ~VIC_BIT( VIC_SPI1 ); /* SPI1 selected as IRQ */
52  VICIntEnable = VIC_BIT( VIC_SPI1 ); /* enable it */
53  _VIC_CNTL(SSP_VIC_SLOT) = VIC_ENABLE | VIC_SPI1;
54  _VIC_ADDR(SSP_VIC_SLOT) = (uint32_t)SSP_ISR; /* address of the ISR */
55 
56  MmUnselect(); /* pin idles high */
57  /* configure SS pin */
58  SetBit(MM_SS_IODIR, MM_SS_PIN); /* pin is output */
59 
60  /* configure RESET pin */
61  SetBit(MM_RESET_IODIR, MM_RESET_PIN); /* pin is output */
62  MmReset(); /* pin idles low */
63 
64  /* configure DRDY pin */
65  /* connected pin to EXINT */
66  MM_DRDY_PINSEL |= MM_DRDY_PINSEL_VAL << MM_DRDY_PINSEL_BIT;
67  SetBit(EXTMODE, MM_DRDY_EINT); /* EINT is edge trigered */
68  SetBit(EXTPOLAR,MM_DRDY_EINT); /* EINT is trigered on rising edge */
69  SetBit(EXTINT,MM_DRDY_EINT); /* clear pending EINT */
70 
71  /* initialize interrupt vector */
72  VICIntSelect &= ~VIC_BIT( MM_DRDY_VIC_IT ); /* select EINT as IRQ source */
73  VICIntEnable = VIC_BIT( MM_DRDY_VIC_IT ); /* enable it */
74  _VIC_CNTL(MICROMAG_DRDY_VIC_SLOT) = VIC_ENABLE | MM_DRDY_VIC_IT;
75  _VIC_ADDR(MICROMAG_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; // address of the ISR
76 }
77 
78 
#define VICIntSelect
Definition: LPC21xx.h:398
#define MM_GOT_EOC
Definition: micromag.h:17
#define SSPCPSR
Definition: LPC21xx.h:226
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
#define MmUnselect()
Definition: micromag_hw.h:26
#define SSPCR0_VAL
#define MmReset()
Definition: micromag_hw.h:28
#define EXTMODE
Definition: LPC21xx.h:387
#define SSPCR1_VAL
#define SSPCR0
Definition: LPC21xx.h:222
#define _VIC_ADDR(idx)
Definition: armVIC.h:20
volatile uint8_t micromag_cur_axe
#define SSP_PINSEL1_SCK
#define EXTPOLAR
Definition: LPC21xx.h:388
#define EXTINT
Definition: LPC21xx.h:385
volatile uint8_t micromag_status
Definition: micromag.c:3
#define VICVectAddr
Definition: LPC21xx.h:404
unsigned long uint32_t
Definition: types.h:18
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
unsigned char uint8_t
Definition: types.h:14
#define ISR_EXIT()
Definition: armVIC.h:61
#define VICIntEnable
Definition: LPC21xx.h:399
void EXTINT_ISR(void)
#define PINSEL1
Definition: LPC21xx.h:316
#define MmOnSpiIt()
Definition: micromag_hw.h:31
#define SSP_PINSEL1_MOSI
#define VIC_SPI1
Definition: lpcVIC.h:81
arch independent LED (Light Emitting Diodes) API
#define SSP_PINSEL1_MISO
static void SSP_ISR(void)
#define SSPCR1
Definition: LPC21xx.h:223
__attribute__((always_inline))
Definition: i2c_arch.c:35
#define ISR_ENTRY()
Definition: armVIC.h:40
void micromag_hw_init(void)
#define VIC_ENABLE
Definition: lpcVIC.h:102