Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sd_card.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 ENAC
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 
28 #include "sd_card.h"
29 #include "spi.h"
30 
32 
33 static bool_t status_read_data;
34 
35 #define CMD_INIT_1 0x24 // set chanel AIN1/AIN2 and next operation on filter high
36 #define CMD_INIT_2 0xCF // set unipolar mode, 24 bits, no boost, filter high
37 #define CMD_INIT_3 0x34 // set chanel AIN1/AIN2 and next operation on filter low
38 #define CMD_INIT_4 0x00 // set low filter
39 #define CMD_INIT_5 0x14 // set chanel AIN1/AIN2 and next operation on mode register
40 #define CMD_INIT_6 0x20 // set gain to 1, burnout current off, no filter sync, self calibration
41 #define CMD_MEASUREMENT 0x54 // set chanel AIN1/AIN2 and next operation on data register
42 
43 
46 
47 
48 static void send1_on_spi(uint8_t d) {
49  buf_output[0] = d;
50  spi_buffer_length = 1;
51 
52  spi_buffer_input = (uint8_t*)&buf_input;
53  spi_buffer_output = (uint8_t*)&buf_output;
54  SpiStart();
55 }
56 
57 
58 void sd_card_init( void ) {
59 
66 
69 
70 }
71 
72 void sd_card_periodic(void) {
73  if (!SpiCheckAvailable()) {
74  SpiOverRun();
75  return;
76  }
77 
78  if (status_read_data) {
79  buf_output[0] = buf_output[1] = buf_output[2] = 0;
80  spi_buffer_length = 3;
81  }
82  else {
84  spi_buffer_length = 1;
85  }
86 
87  spi_buffer_input = (uint8_t*)&buf_input;
88  spi_buffer_output = (uint8_t*)&buf_output;
89  //if (status_read_data)
90  // SpiSetCPHA();
91  //else
92  // SpiClrCPHA();
93  SpiStart();
94 }
95 
96 /* Handle the SPI message, i.e. store the received values in variables */
97 void sd_card_event( void ) {
98 
99  if (status_read_data) {
100  } /* else nothing to read */
101 
103 
104 }
105 
uint8_t buf_output[3]
Definition: sd_card.c:45
void sd_card_init(void)
Definition: sd_card.c:58
#define CMD_INIT_1
Definition: sd_card.c:35
static void SpiStart(struct spi_periph *p, struct spi_transaction *t)
Definition: spi_arch.c:233
#define CMD_MEASUREMENT
Definition: sd_card.c:41
uint8_t buf_input[3]
Definition: sd_card.c:44
#define FALSE
Definition: imu_chimu.h:141
Architecture independent SPI (Serial Peripheral Interface) API.
#define CMD_INIT_6
Definition: sd_card.c:40
#define CMD_INIT_4
Definition: sd_card.c:38
void sd_card_periodic(void)
Definition: sd_card.c:72
void sd_card_event(void)
Definition: sd_card.c:97
#define CMD_INIT_5
Definition: sd_card.c:39
bool_t sd_card_available
Definition: sd_card.c:31
#define CMD_INIT_2
Definition: sd_card.c:36
unsigned char uint8_t
Definition: types.h:14
static bool_t status_read_data
Definition: sd_card.c:33
#define CMD_INIT_3
Definition: sd_card.c:37
static void send1_on_spi(uint8_t d)
Definition: sd_card.c:48