Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
max1168.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
3  * Copyright (C) 2012 Gautier Hattenberger
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  */
23 
24 #include "peripherals/max1168.h"
25 #include "mcu_periph/spi.h"
26 
29 
32 
34 
35 /* callback function to lock the spi fifo
36  * after the first transaction
37  */
38 void max1168_lock_cb(struct spi_transaction *t);
39 
40 extern void max1168_init(void)
41 {
42 
44 
45  uint8_t i;
46  for (i = 0; i < MAX1168_NB_CHAN; i++) {
47  max1168_values[i] = 0;
48  }
49 
50  // init spi transaction parameters
56 
66 
72 
75  // read 8 16bit frames
76  // FIXME should be function of control register options
82 
84 }
85 
86 #include "led.h"
87 void max1168_read(void)
88 {
89  //ASSERT((max1168_status == MAX1168_IDLE), DEBUG_MAX_1168, MAX1168_ERR_READ_OVERUN);
90 
91  /* set SPI transaction */
92  /* SPI is locked between the two transactions (callback) */
93  /* SPI is unlocked when EOC is received */
94 
97 
99 }
100 
101 void max1168_event(void)
102 {
103  // handle request transaction
106  } else if (max1168_req_trans.status == SPITransFailed) {
111  }
112 
113  // handle reading transaction
116  // result was already written to max1168_values by DMA
119  }
120  } else if (max1168_read_trans.status == SPITransFailed) {
124  }
125  // Waiting for EOC
126  // FIXME possible race condition, should suspend external int ?
128  // eoc occurs, unlock SPI
131  }
132 }
133 
134 void max1168_lock_cb(struct spi_transaction *t __attribute__((unused)))
135 {
137 }
138 
void max1168_init(void)
Definition: max1168.c:40
void max1168_event(void)
Definition: max1168.c:101
unsigned short uint16_t
Definition: types.h:16
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:155
#define MAX1168_CONF_CR
Definition: max1168.h:53
uint16_t max1168_values[MAX1168_NB_CHAN]
Definition: max1168.c:28
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
Definition: spi.h:159
uint16_t output_length
number of data words to write
Definition: spi.h:152
#define MAX1168_SLAVE_IDX
Definition: max1168.h:31
slave is selected before transaction but not unselected
Definition: spi.h:64
slave is not selected but unselected after transaction
Definition: spi.h:65
SPI transaction structure.
Definition: spi.h:148
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
Definition: spi_arch.c:511
#define MAX1168_SENDING_REQ
Definition: max1168.h:60
enum SPIBitOrder bitorder
MSB/LSB order.
Definition: spi.h:158
void max1168_lock_cb(struct spi_transaction *t)
Definition: max1168.c:134
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:150
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:154
#define MAX1168_IDLE
Definition: max1168.h:59
Architecture independent SPI (Serial Peripheral Interface) API.
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:156
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
Definition: spi_arch.c:629
void spi_slave_unselect(uint8_t slave)
spi_slave_unselect() function
Definition: spi_arch.c:586
uint16_t max1168_conv_req
Definition: max1168.c:33
SPICallback after_cb
NULL or function called after the transaction.
Definition: spi.h:161
#define MAX1168_SPI_DEV
Definition: max1168.h:35
void max1168_read(void)
Definition: max1168.c:87
#define MAX1168_NB_CHAN
Definition: max1168.h:28
CPOL = 0.
Definition: spi.h:83
#define MAX1168_READING_RES
Definition: max1168.h:62
void max1168_arch_init(void)
Definition: max1168_arch.c:31
uint16_t input_length
number of data words to read
Definition: spi.h:151
struct spi_transaction max1168_req_trans
Definition: max1168.c:30
volatile uint8_t max1168_status
Definition: max1168.c:27
unsigned char uint8_t
Definition: types.h:14
#define MAX1168_DATA_AVAILABLE
Definition: max1168.h:63
CPHA = 0.
Definition: spi.h:74
bool spi_resume(struct spi_periph *p, uint8_t slave)
spi_resume() function
Definition: spi_arch.c:643
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:157
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:153
Definition: spi.h:125
arch independent LED (Light Emitting Diodes) API
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:149
#define MAX1168_GOT_EOC
Definition: max1168.h:61
struct spi_transaction max1168_read_trans
Definition: max1168.c:31
enum SPITransactionStatus status
Definition: spi.h:162