Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 {
26  ISR_ENTRY();
27 
28  MmOnSpiIt();
29 
30  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
31  ISR_EXIT();
32 }
33 
34 void EXTINT_ISR(void)
35 {
36  ISR_ENTRY();
37 //LED_TOGGLE(3);
38 
39  /* no, we won't do anything asynchronously, so just notify */
41  /* clear EINT */
42  SetBit(EXTINT, MM_DRDY_EINT);
43 // EXTINT = (1<<MM_DRDY_EINT);
44  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
45  ISR_EXIT();
46 }
47 
48 void micromag_hw_init(void)
49 {
50  /* setup pins for SSP (SCK, MISO, MOSI, SSEL) */
52 
53  /* setup SSP */
54  SSPCR0 = SSPCR0_VAL;;
56  SSPCPSR = 0x02;
57 
58  /* initialize interrupt vector */
59  VICIntSelect &= ~VIC_BIT(VIC_SPI1); /* SPI1 selected as IRQ */
60  VICIntEnable = VIC_BIT(VIC_SPI1); /* enable it */
62  _VIC_ADDR(SPI1_VIC_SLOT) = (uint32_t)SSP_ISR; /* address of the ISR */
63 
64  MmUnselect(); /* pin idles high */
65  /* configure SS pin */
66  SetBit(MM_SS_IODIR, MM_SS_PIN); /* pin is output */
67 
68  /* configure RESET pin */
69  SetBit(MM_RESET_IODIR, MM_RESET_PIN); /* pin is output */
70  MmReset(); /* pin idles low */
71 
72  /* configure DRDY pin */
73  /* connected pin to EXINT */
74  MM_DRDY_PINSEL |= MM_DRDY_PINSEL_VAL << MM_DRDY_PINSEL_BIT;
75  SetBit(EXTMODE, MM_DRDY_EINT); /* EINT is edge trigered */
76  SetBit(EXTPOLAR, MM_DRDY_EINT); /* EINT is trigered on rising edge */
77  SetBit(EXTINT, MM_DRDY_EINT); /* clear pending EINT */
78 
79  /* initialize interrupt vector */
80  VICIntSelect &= ~VIC_BIT(MM_DRDY_VIC_IT); /* select EINT as IRQ source */
81  VICIntEnable = VIC_BIT(MM_DRDY_VIC_IT); /* enable it */
82  _VIC_CNTL(MICROMAG_DRDY_VIC_SLOT) = VIC_ENABLE | MM_DRDY_VIC_IT;
83  _VIC_ADDR(MICROMAG_DRDY_VIC_SLOT) = (uint32_t)EXTINT_ISR; // address of the ISR
84 }
85 
86 
#define VICIntSelect
Definition: LPC21xx.h:430
#define SSP_PINSEL1_MOSI
Definition: spi_arch.c:387
#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:385
#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:386
#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