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
imu_crista_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include "subsystems/imu.h"
23 
24 #include "LPC21xx.h"
25 #include "armVIC.h"
26 #include "ssp_hw.h"
27 #include BOARD_CONFIG
28 
29 #define ADS8344_SS_IODIR IO0DIR
30 #define ADS8344_SS_IOSET IO0SET
31 #define ADS8344_SS_IOCLR IO0CLR
32 #define ADS8344_SS_PIN 20
33 
34 #define ADS8344Select() SetBit(ADS8344_SS_IOCLR,ADS8344_SS_PIN)
35 #define ADS8344Unselect() SetBit(ADS8344_SS_IOSET,ADS8344_SS_PIN)
36 
37 #define POWER_MODE (1 << 1 | 1)
38 #define SGL_DIF 1 // Single ended
39 
40 /* SSPCR0 settings */
41 #define SSP_DSS 0x07 << 0 /* data size : 8 bits */
42 #define SSP_FRF 0x00 << 4 /* frame format : SPI */
43 #define SSP_CPOL 0x00 << 6 /* clock polarity : idle low */
44 #define SSP_CPHA 0x00 << 7 /* clock phase : 1 */
45 #define SSP_SCR 0x09 << 8 /* serial clock rate : 1MHz */
46 
47 /* SSPCR1 settings */
48 #define SSP_LBM 0x00 << 0 /* loopback mode : disabled */
49 #define SSP_SSE 0x00 << 1 /* SSP enable : disabled */
50 #define SSP_MS 0x00 << 2 /* master slave mode : master */
51 #define SSP_SOD 0x00 << 3 /* slave output disable : disabled */
52 
53 static void SPI1_ISR(void) __attribute__((naked));
55 
56 #warning "This driver should be updated to use the new SPI peripheral"
57 
59 {
60  channel = 0;
61 
62  /* setup pins for SSP (SCK, MISO, MOSI) */
63  PINSEL1 |= 2 << 2 | 2 << 4 | 2 << 6;
64 
65  /* setup SSP */
68  SSPCPSR = 2; /* -> 50kHz */
69 
70  /* initialize interrupt vector */
71  VICIntSelect &= ~VIC_BIT(VIC_SPI1); // SPI1 selected as IRQ
72  VICIntEnable = VIC_BIT(VIC_SPI1); // SPI1 interrupt enabled
74  _VIC_ADDR(SPI1_VIC_SLOT) = (uint32_t)SPI1_ISR; // address of the ISR
75 
76  /* setup slave select */
77  /* configure SS pin */
78  SetBit(ADS8344_SS_IODIR, ADS8344_SS_PIN); /* pin is output */
79  ADS8344Unselect(); /* pin low */
80 }
81 
82 
83 static inline void read_values(void)
84 {
85  uint8_t foo __attribute__((unused)) = SSPDR;
86  uint8_t msb = SSPDR;
87  uint8_t lsb = SSPDR;
88  uint8_t llsb = SSPDR;
89  ADS8344_values[channel] = (msb << 8 | lsb) << 1 | llsb >> 7;
90 }
91 
92 static inline void send_request(void)
93 {
94  uint8_t control = 1 << 7 | channel << 4 | SGL_DIF << 2 | POWER_MODE;
95  SSP_Send(control);
96  SSP_Send(0);
97  SSP_Send(0);
98  SSP_Send(0);
99 }
100 
101 void ADS8344_start(void)
102 {
103  ADS8344Select();
104  SSP_ClearRti();
105  SSP_EnableRti();
106  SSP_Enable();
107  send_request();
108 }
109 
110 void SPI1_ISR(void)
111 {
112  ISR_ENTRY();
113  read_values();
114  channel++;
115  if (channel > 7 - 1) {
116  channel = 0;
117  ADS8344_available = true;
118  ADS8344Unselect();
119  } else {
120  send_request();
121  }
122 
123  SSP_ClearRti();
124 
125  VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
126  ISR_EXIT();
127 }
#define VICIntSelect
Definition: LPC21xx.h:430
#define SSP_LBM
#define ADS8344_SS_PIN
#define SSP_DSS
#define SSP_Send(_a)
Definition: ssp_hw.h:16
#define SSP_CPOL
#define SSP_SCR
#define SSP_MS
#define SSPCPSR
Definition: LPC21xx.h:226
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
#define SSP_FRF
#define ADS8344_SS_IODIR
#define ADS8344Select()
uint16_t ADS8344_values[NB_CHANNELS]
Definition: ADS8344.c:39
#define SSP_Enable()
Definition: max11040_hw.h:43
#define SSPCR0
Definition: LPC21xx.h:222
#define _VIC_ADDR(idx)
Definition: armVIC.h:20
#define SGL_DIF
#define SSP_CPHA
bool ADS8344_available
Definition: ADS8344.c:38
static void send_request(void)
#define VICVectAddr
Definition: LPC21xx.h:436
unsigned long uint32_t
Definition: types.h:18
uint16_t foo
Definition: main_demo5.c:59
Inertial Measurement Unit interface.
#define SSP_SOD
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
#define SSP_EnableRti()
Definition: max11040_hw.h:51
static void SPI1_ISR(void)
#define SPI1_VIC_SLOT
Definition: ADS8344.c:85
void ADS8344_start(void)
unsigned char uint8_t
Definition: types.h:14
#define SSPDR
Definition: LPC21xx.h:224
#define POWER_MODE
#define ISR_EXIT()
Definition: armVIC.h:61
#define SSP_ClearRti()
Definition: max11040_hw.h:53
void imu_crista_arch_init(void)
#define VICIntEnable
Definition: LPC21xx.h:431
#define PINSEL1
Definition: LPC21xx.h:348
#define VIC_SPI1
Definition: lpcVIC.h:81
#define ADS8344Unselect()
#define SSPCR1
Definition: LPC21xx.h:223
static uint8_t channel
#define ISR_ENTRY()
Definition: armVIC.h:40
static void read_values(void)
#define VIC_ENABLE
Definition: lpcVIC.h:102