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
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 
43 
44  uint8_t i;
45  for (i=0; i<MAX1168_NB_CHAN; i++)
46  max1168_values[i] = 0;
47 
48  // init spi transaction parameters
54 
64 
70 
73  // read 8 16bit frames
74  // FIXME should be function of control register options
80 
82 }
83 
84 #include "led.h"
85 void max1168_read( void ) {
86  //ASSERT((max1168_status == MAX1168_IDLE), DEBUG_MAX_1168, MAX1168_ERR_READ_OVERUN);
87 
88  /* set SPI transaction */
89  /* SPI is locked between the two transactions (callback) */
90  /* SPI is unlocked when EOC is received */
91 
94 
96 }
97 
98 void max1168_event( void ) {
99  // handle request transaction
102  }
108  }
109 
110  // handle reading transaction
113  // result was already written to max1168_values by DMA
116  }
117  }
122  }
123  // Waiting for EOC
124  // FIXME possible race condition, should suspend external int ?
126  // eoc occurs, unlock SPI
129  }
130 }
131 
132 void max1168_lock_cb(struct spi_transaction * t __attribute__ ((unused))) {
134 }
135 
void max1168_init(void)
Definition: max1168.c:40
enum SPIBitOrder bitorder
MSB/LSB order.
Definition: spi.h:152
void max1168_event(void)
Definition: max1168.c:98
unsigned short uint16_t
Definition: types.h:16
#define MAX1168_CONF_CR
Definition: max1168.h:53
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:149
uint16_t max1168_values[MAX1168_NB_CHAN]
Definition: max1168.c:28
bool_t spi_lock(struct spi_periph *p, uint8_t slave)
Lock the SPI fifo.
Definition: spi_arch.c:535
uint8_t input_length
number of data words to read
Definition: spi.h:145
#define MAX1168_SLAVE_IDX
Definition: max1168.h:31
slave is selected before transaction but not unselected
Definition: spi.h:58
slave is not selected but unselected after transaction
Definition: spi.h:59
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:150
#define MAX1168_SENDING_REQ
Definition: max1168.h:60
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:143
void max1168_lock_cb(struct spi_transaction *t)
Definition: max1168.c:132
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:148
#define MAX1168_IDLE
Definition: max1168.h:59
enum SPITransactionStatus status
Definition: spi.h:156
Architecture independent SPI (Serial Peripheral Interface) API.
void spi_slave_unselect(uint8_t slave)
Unselect a slave.
Definition: spi_arch.c:531
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
Definition: spi.h:153
bool_t spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit a spi transaction.
Definition: spi_arch.c:469
uint16_t max1168_conv_req
Definition: max1168.c:33
#define MAX1168_SPI_DEV
Definition: max1168.h:35
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:151
uint8_t output_length
number of data words to write
Definition: spi.h:146
void max1168_read(void)
Definition: max1168.c:85
#define MAX1168_NB_CHAN
Definition: max1168.h:28
CPOL = 0.
Definition: spi.h:77
#define MAX1168_READING_RES
Definition: max1168.h:62
void max1168_arch_init(void)
Definition: max1168_arch.c:31
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:68
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:147
Definition: spi.h:119
arch independent LED (Light Emitting Diodes) API
bool_t spi_resume(struct spi_periph *p, uint8_t slave)
Resume the SPI fifo.
Definition: spi_arch.c:547
SPI transaction structure.
Definition: spi.h:142
#define MAX1168_GOT_EOC
Definition: max1168.h:61
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:144
struct spi_transaction max1168_read_trans
Definition: max1168.c:31
SPICallback after_cb
NULL or function called after the transaction.
Definition: spi.h:155