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
baro_scp.c
Go to the documentation of this file.
1 #include "std.h"
2 #include "mcu_periph/sys_time.h"
3 #include "led.h"
4 #include "mcu.h"
5 #include "subsystems/abi.h"
6 
7 #include "mcu_periph/uart.h"
8 #include "messages.h"
10 
11 #include "mcu_periph/spi.h"
12 
14 
15 #ifndef SENSOR_SYNC_SEND
16 #warning set SENSOR_SYNC_SEND to use baro_scp
17 #endif
18 
19 
20 #define STA_UNINIT 0
21 #define STA_INITIALISING 1
22 #define STA_IDLE 2
23 
28 
29 static void baro_scp_start_high_res_measurement(void);
30 static void baro_scp_read(void);
31 static void EXTINT_ISR(void) __attribute__((naked));
32 static void SPI1_ISR(void) __attribute__((naked));
33 
34 void baro_scp_periodic(void) {
35  if (baro_scp_status == STA_UNINIT && sys_time.nb_sec > 1) {
38  }
39 }
40 
41 /* ssp input clock 468.75kHz, clock that divided by SCR+1 */
42 #define SSP_CLOCK 468750
43 
44 /* SSPCR0 settings */
45 #define SSP_DDS 0x07 << 0 /* data size : 8 bits */
46 #define SSP_FRF 0x00 << 4 /* frame format : SPI */
47 #define SSP_CPOL 0x00 << 6 /* clock polarity : data captured on first clock transition */
48 #define SSP_CPHA 0x00 << 7 /* clock phase : SCK idles low */
49 #define SSP_SCR 0x0F << 8 /* serial clock rate : divide by 16 */
50 
51 /* SSPCR1 settings */
52 #define SSP_LBM 0x00 << 0 /* loopback mode : disabled */
53 #define SSP_SSE 0x00 << 1 /* SSP enable : disabled */
54 #define SSP_MS 0x00 << 2 /* master slave mode : master */
55 #define SSP_SOD 0x00 << 3 /* slave output disable : don't care when master */
56 
57 #define SS_PIN 20
58 #define SS_IODIR IO0DIR
59 #define SS_IOSET IO0SET
60 #define SS_IOCLR IO0CLR
61 
62 #define ScpSelect() SetBit(SS_IOCLR,SS_PIN)
63 #define ScpUnselect() SetBit(SS_IOSET,SS_PIN)
64 
65 #warning "This driver should be updated to use the new SPI peripheral"
66 
67 #ifndef SPI1_VIC_SLOT
68 #define SPI1_VIC_SLOT 7
69 #endif
70 
71 void baro_scp_init( void ) {
72  /* setup pins for SSP (SCK, MISO, MOSI) */
73  PINSEL1 |= 2 << 2 | 2 << 4 | 2 << 6;
74 
75  /* setup SSP */
78  /* set prescaler for SSP clock */
80 
81  /* initialize interrupt vector */
82  VICIntSelect &= ~VIC_BIT(VIC_SPI1); // SPI1 selected as IRQ
83  VICIntEnable = VIC_BIT(VIC_SPI1); // SPI1 interrupt enabled
85  _VIC_CNTL(SPI1_VIC_SLOT) = (uint32_t)SPI1_ISR; /* address of the ISR */
86 
87  /* configure SS pin */
88  SetBit(SS_IODIR, SS_PIN); /* pin is output */
89  ScpUnselect(); /* pin idles high */
90 
91  /* configure DRDY pin */
92  /* connected pin to EXINT */
94  SetBit(EXTMODE, SPI1_DRDY_EINT); /* EINT is edge trigered */
95  SetBit(EXTPOLAR,SPI1_DRDY_EINT); /* EINT is trigered on rising edge */
96  SetBit(EXTINT,SPI1_DRDY_EINT); /* clear pending EINT */
97 
98  /* initialize interrupt vector */
99  VICIntSelect &= ~VIC_BIT( SPI1_DRDY_VIC_IT ); /* select EINT as IRQ source */
100  VICIntEnable = VIC_BIT( SPI1_DRDY_VIC_IT ); /* enable it */
102  VICVectAddr11 = (uint32_t)EXTINT_ISR; // address of the ISR
103 
105 }
106 
107 void SPI1_ISR(void) {
108  ISR_ENTRY();
109 
111  uint8_t foo1 = SSPDR;
112  uint8_t foo2 = SSPDR;
114  foo1=foo2;
115  }
116  else if (baro_scp_status == STA_IDLE) {
117 
118  uint8_t foo0 = SSPDR;
121  if (baro_scp_temperature & 0x2000) {
122  baro_scp_temperature |= 0xC000;
123  }
125 
126  uint8_t foo1 = SSPDR;
127  uint32_t datard8 = SSPDR<<16;
128  uint8_t foo2 = SSPDR;
131  baro_scp_pressure += datard8;
132  baro_scp_pressure *= 25;
134  foo1=foo2;
135  foo0=foo2;
136  }
137 
138  ScpUnselect();
139  SpiClearRti();
140  SpiDisable();
141 
142  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
143  ISR_EXIT();
144 }
145 
146 void EXTINT_ISR(void) {
147  ISR_ENTRY();
148  baro_scp_read();
149 
150  SetBit(EXTINT,SPI1_DRDY_EINT); /* clear EINT2 */
151  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
152  ISR_EXIT();
153 }
154 
155 /* write 0x0A to 0x03 */
157  uint8_t cmd = 0x03<<2|0x02;
158  uint8_t data = 0x0A;
159  ScpSelect();
160  SSPDR = cmd;
161  SSPDR = data;
162  SpiEnableRti();
163  SpiEnable();
164 }
165 
166 /* read 0x21 (TEMP), 0x1F (MSB) and 0x20 (LSB) */
167 static void baro_scp_read(void) {
168  uint8_t cmd0 = 0x21 << 2;
169  uint8_t cmd1 = 0x1F << 2;
170  uint8_t cmd2 = 0x20 << 2;
171  ScpSelect();
172  SSPDR = cmd0;
173  SSPDR = 0;
174  SSPDR = 0;
175  SSPDR = cmd1;
176  SSPDR = 0;
177  SSPDR = cmd2;
178  SSPDR = 0;
179  SSPDR = 0;
180  SpiEnable();
181 }
182 
183 void baro_scp_event( void ) {
184  if (baro_scp_available == TRUE) {
185  float pressure = (float)baro_scp_pressure;
186  AbiSendMsgBARO_ABS(BARO_SCP_SENDER_ID, &pressure);
187 #ifdef SENSOR_SYNC_SEND
189 #endif
191  }
192 }
#define VICIntSelect
Definition: LPC21xx.h:430
#define SPI1_DRDY_PINSEL_VAL
Definition: hbmini_1.0.h:90
unsigned short uint16_t
Definition: types.h:16
#define SPI1_DRDY_VIC_IT
Definition: hbmini_1.0.h:92
static void baro_scp_start_high_res_measurement(void)
Definition: baro_scp.c:156
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define STA_INITIALISING
Definition: baro_scp.c:21
#define SSP_SCR
Definition: baro_scp.c:49
struct Ms5611Data data
Definition: ms5611_spi.h:44
#define SSP_CLOCK
Definition: baro_scp.c:42
void baro_scp_init(void)
Definition: baro_scp.c:71
#define SS_PIN
Definition: baro_scp.c:57
#define VICVectAddr11
Definition: LPC21xx.h:449
static void SpiClearRti(struct spi_periph *p)
Definition: spi_arch.c:151
#define SSPCPSR
Definition: LPC21xx.h:226
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
#define SPI1_DRDY_PINSEL
Definition: hbmini_1.0.h:88
#define SSP_FRF
Definition: baro_scp.c:46
Main include for ABI (AirBorneInterface).
#define PCLK
Definition: booz_1.0.h:18
#define EXTMODE
Definition: LPC21xx.h:419
#define SPI1_DRDY_EINT
Definition: hbmini_1.0.h:91
static void baro_scp_read(void)
Definition: baro_scp.c:167
#define SpiDisable()
#define SSPCR0
Definition: LPC21xx.h:222
uint32_t baro_scp_pressure
Definition: baro_scp.c:25
static void SpiEnableRti(struct spi_periph *p)
Definition: spi_arch.c:143
void baro_scp_event(void)
Definition: baro_scp.c:183
#define FALSE
Definition: imu_chimu.h:141
#define STA_UNINIT
Definition: baro_scp.c:20
#define SSP_LBM
Definition: baro_scp.c:52
Architecture independent SPI (Serial Peripheral Interface) API.
#define SSP_CPHA
Definition: baro_scp.c:48
#define EXTPOLAR
Definition: LPC21xx.h:420
static void SPI1_ISR(void)
Definition: baro_scp.c:107
#define BARO_SCP_SENDER_ID
#define SSP_MS
Definition: baro_scp.c:54
#define EXTINT
Definition: LPC21xx.h:417
Architecture independent timing functions.
uint16_t baro_scp_temperature
Definition: baro_scp.c:26
#define VICVectAddr
Definition: LPC21xx.h:436
unsigned long uint32_t
Definition: types.h:18
#define SpiEnable()
#define SPI1_VIC_SLOT
Definition: baro_scp.c:68
#define SSP_CPOL
Definition: baro_scp.c:47
#define ScpSelect()
Definition: baro_scp.c:62
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
#define TRUE
Definition: imu_chimu.h:144
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
#define SSPDR
Definition: LPC21xx.h:224
#define ISR_EXIT()
Definition: armVIC.h:61
void baro_scp_periodic(void)
Definition: baro_scp.c:34
bool_t baro_scp_available
Definition: baro_scp.c:27
#define VICIntEnable
Definition: LPC21xx.h:431
#define PINSEL1
Definition: LPC21xx.h:348
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
#define VICVectCntl11
Definition: LPC21xx.h:465
#define VIC_SPI1
Definition: lpcVIC.h:81
#define ScpUnselect()
Definition: baro_scp.c:63
arch independent LED (Light Emitting Diodes) API
uint8_t baro_scp_status
Definition: baro_scp.c:24
#define SSPCR1
Definition: LPC21xx.h:223
#define STA_IDLE
Definition: baro_scp.c:22
#define SS_IODIR
Definition: baro_scp.c:58
#define SPI1_DRDY_PINSEL_BIT
Definition: hbmini_1.0.h:89
#define SSP_DDS
Definition: baro_scp.c:45
#define SSP_SOD
Definition: baro_scp.c:55
#define ISR_ENTRY()
Definition: armVIC.h:40
static void EXTINT_ISR(void)
Definition: baro_scp.c:146
#define VIC_ENABLE
Definition: lpcVIC.h:102