Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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 */
38void max1168_lock_cb(struct spi_transaction *t);
39
40extern 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
61 max1168_req_trans.output_length = 1;
62 max1168_req_trans.input_buf = NULL;
63 max1168_req_trans.input_length = 0;
66
72
75 // read 8 16bit frames
76 // FIXME should be function of control register options
77 max1168_read_trans.output_buf = NULL;
78 max1168_read_trans.output_length = 0;
80 max1168_read_trans.input_length = 8;
82
84}
85
86#include "led.h"
87void 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
102{
103 // handle request transaction
104 if (max1168_req_trans.status == SPITransSuccess) {
106 } else if (max1168_req_trans.status == SPITransFailed) {
111 }
112
113 // handle reading transaction
114 if (max1168_read_trans.status == SPITransSuccess) {
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
134void max1168_lock_cb(struct spi_transaction *t __attribute__((unused)))
135{
137}
138
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
Definition spi_arch.c:548
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
Definition spi_arch.c:707
void spi_slave_unselect(uint8_t slave)
spi_slave_unselect() function
Definition spi_arch.c:644
bool spi_resume(struct spi_periph *p, uint8_t slave)
spi_resume() function
Definition spi_arch.c:721
@ SPICphaEdge1
CPHA = 0.
Definition spi.h:70
@ SPITransFailed
Definition spi.h:96
@ SPITransSuccess
Definition spi.h:95
@ SPITransDone
Definition spi.h:97
@ SPICpolIdleLow
CPOL = 0.
Definition spi.h:79
@ SPISelect
slave is selected before transaction but not unselected
Definition spi.h:60
@ SPIUnselect
slave is not selected but unselected after transaction
Definition spi.h:61
@ SPIMSBFirst
Definition spi.h:108
@ SPIDiv64
Definition spi.h:121
@ SPIDss16bit
Definition spi.h:87
SPI transaction structure.
Definition spi.h:144
arch independent LED (Light Emitting Diodes) API
volatile uint8_t max1168_status
Definition max1168.c:27
void max1168_init(void)
Definition max1168.c:40
void max1168_lock_cb(struct spi_transaction *t)
Definition max1168.c:134
struct spi_transaction max1168_req_trans
Definition max1168.c:30
uint16_t max1168_conv_req
Definition max1168.c:33
void max1168_event(void)
Definition max1168.c:101
struct spi_transaction max1168_read_trans
Definition max1168.c:31
void max1168_read(void)
Definition max1168.c:87
uint16_t max1168_values[MAX1168_NB_CHAN]
Definition max1168.c:28
#define MAX1168_DATA_AVAILABLE
Definition max1168.h:63
#define MAX1168_CONF_CR
Definition max1168.h:53
#define MAX1168_READING_RES
Definition max1168.h:62
#define MAX1168_SPI_DEV
Definition max1168.h:35
#define MAX1168_GOT_EOC
Definition max1168.h:61
#define MAX1168_SLAVE_IDX
Definition max1168.h:31
#define MAX1168_IDLE
Definition max1168.h:59
#define MAX1168_NB_CHAN
Definition max1168.h:28
#define MAX1168_SENDING_REQ
Definition max1168.h:60
void max1168_arch_init(void)
Architecture independent SPI (Serial Peripheral Interface) API.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.