Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 
SSP_ISR
static void SSP_ISR(void)
Definition: mag_micromag_fw_hw.c:24
SSPCR1
#define SSPCR1
Definition: LPC21xx.h:223
EXTINT_ISR
static void EXTINT_ISR(void)
Definition: mag_micromag_fw_hw.c:34
VICIntSelect
#define VICIntSelect
Definition: LPC21xx.h:430
VIC_SPI1
#define VIC_SPI1
Definition: lpcVIC.h:81
SSPCR0
#define SSPCR0
Definition: LPC21xx.h:222
EXTMODE
#define EXTMODE
Definition: LPC21xx.h:419
mag_micromag_fw.h
SSPCPSR
#define SSPCPSR
Definition: LPC21xx.h:226
uint32_t
unsigned long uint32_t
Definition: types.h:18
SSP_PINSEL1_MOSI
#define SSP_PINSEL1_MOSI
Definition: spi_arch.c:387
SSPCR0_VAL
#define SSPCR0_VAL
Definition: spi_slave_hs_arch.c:60
_VIC_ADDR
#define _VIC_ADDR(idx)
Definition: armVIC.h:20
VIC_BIT
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
EXTINT
#define EXTINT
Definition: LPC21xx.h:417
MmOnSpiIt
#define MmOnSpiIt()
Definition: mag_micromag_fw_hw.h:31
micromag_cur_axe
volatile uint8_t micromag_cur_axe
Definition: mag_micromag_fw_hw.c:13
uint8_t
unsigned char uint8_t
Definition: types.h:14
mag_micromag_fw_hw.h
VICVectAddr
#define VICVectAddr
Definition: LPC21xx.h:436
EXTPOLAR
#define EXTPOLAR
Definition: LPC21xx.h:420
led.h
arch independent LED (Light Emitting Diodes) API
ISR_ENTRY
#define ISR_ENTRY()
Definition: armVIC.h:40
ISR_EXIT
#define ISR_EXIT()
Definition: armVIC.h:61
SSPCR1_VAL
#define SSPCR1_VAL
Definition: spi_slave_hs_arch.c:68
SSP_PINSEL1_MISO
#define SSP_PINSEL1_MISO
Definition: spi_arch.c:386
SPI1_VIC_SLOT
#define SPI1_VIC_SLOT
Definition: mag_micromag_fw_hw.c:21
VIC_ENABLE
#define VIC_ENABLE
Definition: lpcVIC.h:102
VICIntEnable
#define VICIntEnable
Definition: LPC21xx.h:431
micromag_status
volatile uint8_t micromag_status
Definition: mag_micromag_fw.c:9
PINSEL1
#define PINSEL1
Definition: LPC21xx.h:348
micromag_hw_init
void micromag_hw_init(void)
Definition: mag_micromag_fw_hw.c:48
MmUnselect
#define MmUnselect()
Definition: mag_micromag_fw_hw.h:26
MM_GOT_EOC
#define MM_GOT_EOC
Definition: mag_micromag_fw.h:19
_VIC_CNTL
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
SSP_PINSEL1_SCK
#define SSP_PINSEL1_SCK
Definition: spi_arch.c:385
MmReset
#define MmReset()
Definition: mag_micromag_fw_hw.h:28