Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 
uint16_t
unsigned short uint16_t
Definition: types.h:16
spi_transaction::cdiv
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
Definition: spi.h:159
spi_transaction::cpol
enum SPIClockPolarity cpol
clock polarity control
Definition: spi.h:155
max1168_lock_cb
void max1168_lock_cb(struct spi_transaction *t)
Definition: max1168.c:134
max1168_values
uint16_t max1168_values[MAX1168_NB_CHAN]
Definition: max1168.c:28
max1168_event
void max1168_event(void)
Definition: max1168.c:101
spi_transaction::output_length
uint16_t output_length
number of data words to write
Definition: spi.h:152
MAX1168_SLAVE_IDX
#define MAX1168_SLAVE_IDX
Definition: max1168.h:31
spi.h
spi_transaction
SPI transaction structure.
Definition: spi.h:148
MAX1168_IDLE
#define MAX1168_IDLE
Definition: max1168.h:59
MAX1168_SENDING_REQ
#define MAX1168_SENDING_REQ
Definition: max1168.h:60
SPITransSuccess
@ SPITransSuccess
Definition: spi.h:99
spi_transaction::bitorder
enum SPIBitOrder bitorder
MSB/LSB order.
Definition: spi.h:158
max1168.h
spi_transaction::output_buf
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
Definition: spi.h:150
spi_transaction::select
enum SPISlaveSelect select
slave selection behavior
Definition: spi.h:154
SPICphaEdge1
@ SPICphaEdge1
CPHA = 0.
Definition: spi.h:74
SPIUnselect
@ SPIUnselect
slave is not selected but unselected after transaction
Definition: spi.h:65
SPIMSBFirst
@ SPIMSBFirst
Definition: spi.h:112
SPICpolIdleLow
@ SPICpolIdleLow
CPOL = 0.
Definition: spi.h:83
MAX1168_READING_RES
#define MAX1168_READING_RES
Definition: max1168.h:62
spi_transaction::cpha
enum SPIClockPhase cpha
clock phase control
Definition: spi.h:156
spi_transaction::after_cb
SPICallback after_cb
NULL or function called after the transaction.
Definition: spi.h:161
spi_submit
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
Definition: spi_arch.c:511
max1168_conv_req
uint16_t max1168_conv_req
Definition: max1168.c:33
SPITransFailed
@ SPITransFailed
Definition: spi.h:100
spi_resume
bool spi_resume(struct spi_periph *p, uint8_t slave)
spi_resume() function
Definition: spi_arch.c:643
max1168_status
volatile uint8_t max1168_status
Definition: max1168.c:27
spi_slave_unselect
void spi_slave_unselect(uint8_t slave)
spi_slave_unselect() function
Definition: spi_arch.c:586
uint8_t
unsigned char uint8_t
Definition: types.h:14
MAX1168_NB_CHAN
#define MAX1168_NB_CHAN
Definition: max1168.h:28
MAX1168_DATA_AVAILABLE
#define MAX1168_DATA_AVAILABLE
Definition: max1168.h:63
max1168_arch_init
void max1168_arch_init(void)
Definition: max1168_arch.c:31
led.h
arch independent LED (Light Emitting Diodes) API
SPIDiv64
@ SPIDiv64
Definition: spi.h:125
MAX1168_SPI_DEV
#define MAX1168_SPI_DEV
Definition: max1168.h:35
max1168_req_trans
struct spi_transaction max1168_req_trans
Definition: max1168.c:30
spi_lock
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
Definition: spi_arch.c:629
MAX1168_GOT_EOC
#define MAX1168_GOT_EOC
Definition: max1168.h:61
spi_transaction::input_length
uint16_t input_length
number of data words to read
Definition: spi.h:151
max1168_read
void max1168_read(void)
Definition: max1168.c:87
spi_transaction::dss
enum SPIDataSizeSelect dss
data transfer word size
Definition: spi.h:157
spi_transaction::slave_idx
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:153
SPITransDone
@ SPITransDone
Definition: spi.h:101
SPISelect
@ SPISelect
slave is selected before transaction but not unselected
Definition: spi.h:64
spi_transaction::input_buf
volatile uint8_t * input_buf
pointer to receive buffer for DMA
Definition: spi.h:149
max1168_read_trans
struct spi_transaction max1168_read_trans
Definition: max1168.c:31
max1168_init
void max1168_init(void)
Definition: max1168.c:40
MAX1168_CONF_CR
#define MAX1168_CONF_CR
Definition: max1168.h:53
spi_transaction::status
enum SPITransactionStatus status
Definition: spi.h:162
SPIDss16bit
@ SPIDss16bit
Definition: spi.h:91