Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
cyrf6936.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Freek van Tienen <freek.v.tienen@gmail.com>
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 
27 #ifndef CYRF6936_H
28 #define CYRF6936_H
29 
30 #include "cyrf6936_regs.h"
31 #include "mcu_periph/spi.h"
32 
33 #define CYRF6936_MAX_BUFFER 80
35 /* The different statuses the cyrf6936 chip can be in */
45 };
46 
47 /* The structure for the cyrf6936 chip that handles all the buffers and requests */
48 struct Cyrf6936 {
49  struct spi_periph *spi_p;
50  struct spi_transaction spi_t;
51  volatile enum Cyrf6936Status status;
59  bool has_irq;
66 };
67 
68 extern void cyrf6936_init(struct Cyrf6936 *cyrf, struct spi_periph *spi_p, const uint8_t slave_idx,
69  const uint32_t rst_port, const uint16_t rst_pin);
70 void cyrf6936_event(struct Cyrf6936 *cyrf);
71 
72 bool cyrf6936_write(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data);
73 bool cyrf6936_multi_write(struct Cyrf6936 *cyrf, const uint8_t data[][2], const uint8_t length);
74 bool cyrf6936_write_chan_sop_data_crc(struct Cyrf6936 *cyrf, const uint8_t chan, const uint8_t sop_code[],
75  const uint8_t data_code[], const uint16_t crc_seed);
77 bool cyrf6936_send(struct Cyrf6936 *cyrf, const uint8_t data[], const uint8_t length);
78 
79 #endif /* CYRF6936_H */
struct spi_transaction spi_t
The SPI transaction used for the writing and reading of registers.
Definition: cyrf6936.h:50
void cyrf6936_event(struct Cyrf6936 *cyrf)
The on event call for the CYRF6936 chip.
Definition: cyrf6936.c:86
Cyrf6936Status
Definition: cyrf6936.h:36
@ CYRF6936_DATA_CODE
The chip is writing a data code.
Definition: cyrf6936.h:41
@ CYRF6936_IDLE
The chip is idle and can be used.
Definition: cyrf6936.h:38
@ CYRF6936_GET_MFG_ID
The chip is busy with getting the manufacturer ID.
Definition: cyrf6936.h:39
@ CYRF6936_MULTIWRITE
The chip is writing multiple registers.
Definition: cyrf6936.h:40
@ CYRF6936_RX_IRQ_STATUS_PACKET
The chip is getting the receive irq status, receive status and the receive packet.
Definition: cyrf6936.h:43
@ CYRF6936_UNINIT
The chip isn't initialized.
Definition: cyrf6936.h:37
@ CYRF6936_SEND
The chip is busy sending a packet.
Definition: cyrf6936.h:44
@ CYRF6936_CHAN_SOP_DATA_CRC
The chip is setting the channel, SOP code, DATA code and the CRC seed.
Definition: cyrf6936.h:42
struct spi_periph * spi_p
The SPI peripheral for the connection.
Definition: cyrf6936.h:49
void cyrf6936_init(struct Cyrf6936 *cyrf, struct spi_periph *spi_p, const uint8_t slave_idx, const uint32_t rst_port, const uint16_t rst_pin)
Initializing the cyrf chip.
Definition: cyrf6936.c:47
uint8_t rx_status
The last receive status.
Definition: cyrf6936.h:63
uint8_t buffer_idx
The index of the buffer used for MULTIWRITE and used as sub-status for other statuses.
Definition: cyrf6936.h:57
bool cyrf6936_multi_write(struct Cyrf6936 *cyrf, const uint8_t data[][2], const uint8_t length)
Write to multiple registers one byte.
Definition: cyrf6936.c:341
uint8_t rx_count
The length of the received packet.
Definition: cyrf6936.h:64
bool cyrf6936_write_chan_sop_data_crc(struct Cyrf6936 *cyrf, const uint8_t chan, const uint8_t sop_code[], const uint8_t data_code[], const uint16_t crc_seed)
Set the channel, SOP code, DATA code and the CRC seed.
Definition: cyrf6936.c:373
uint8_t buffer_length
The length of the buffer used for MULTIWRITE.
Definition: cyrf6936.h:56
enum Cyrf6936Status status
The status of the CYRF6936 chip.
Definition: cyrf6936.h:51
bool cyrf6936_write(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data)
Write to one register.
Definition: cyrf6936.c:330
bool has_irq
When the CYRF6936 is done reading the irq.
Definition: cyrf6936.h:59
uint8_t buffer[CYRF6936_MAX_BUFFER]
The buffer used to write/read multiple registers.
Definition: cyrf6936.h:55
bool cyrf6936_read_rx_irq_status_packet(struct Cyrf6936 *cyrf)
Read the RX IRQ status register, the rx status register and the rx packet.
Definition: cyrf6936.c:412
uint8_t input_buf[17]
The input buffer for the SPI transaction.
Definition: cyrf6936.h:52
#define CYRF6936_MAX_BUFFER
The max buffer size in the cyrf6936 structure.
Definition: cyrf6936.h:33
bool cyrf6936_send(struct Cyrf6936 *cyrf, const uint8_t data[], const uint8_t length)
Send a packet with a certain length.
Definition: cyrf6936.c:432
uint8_t tx_irq_status
The last send interrupt status.
Definition: cyrf6936.h:61
uint8_t mfg_id[6]
The manufacturer id of the CYRF6936 chip.
Definition: cyrf6936.h:60
uint8_t output_buf[17]
The output buffer for the SPI transaction.
Definition: cyrf6936.h:53
uint8_t rx_packet[16]
The last received packet.
Definition: cyrf6936.h:65
uint8_t rx_irq_status
The last receive interrupt status.
Definition: cyrf6936.h:62
Register defines for the CYRF6936 2.4GHz radio chip.
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:153
SPI peripheral structure.
Definition: spi.h:174
SPI transaction structure.
Definition: spi.h:148
Architecture independent SPI (Serial Peripheral Interface) API.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98