Paparazzi UAS  v5.18.0_stable
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;
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 */
Cyrf6936::tx_irq_status
uint8_t tx_irq_status
The last send interrupt status.
Definition: cyrf6936.h:61
uint16_t
unsigned short uint16_t
Definition: types.h:16
CYRF6936_IDLE
@ CYRF6936_IDLE
The chip is idle and can be used.
Definition: cyrf6936.h:38
Cyrf6936::rx_count
uint8_t rx_count
The length of the received packet.
Definition: cyrf6936.h:64
Cyrf6936::buffer_length
uint8_t buffer_length
The length of the buffer used for MULTIWRITE.
Definition: cyrf6936.h:56
cyrf6936_write_chan_sop_data_crc
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
spi.h
spi_transaction
SPI transaction structure.
Definition: spi.h:148
uint32_t
unsigned long uint32_t
Definition: types.h:18
Cyrf6936::buffer
uint8_t buffer[CYRF6936_MAX_BUFFER]
The buffer used to write/read multiple registers.
Definition: cyrf6936.h:55
cyrf6936_regs.h
Cyrf6936::rx_status
uint8_t rx_status
The last receive status.
Definition: cyrf6936.h:63
Cyrf6936::rx_packet
uint8_t rx_packet[16]
The last received packet.
Definition: cyrf6936.h:65
spi_periph
SPI peripheral structure.
Definition: spi.h:174
Cyrf6936::spi_p
struct spi_periph * spi_p
The SPI peripheral for the connection.
Definition: cyrf6936.h:49
cyrf6936_send
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
Cyrf6936::buffer_idx
uint8_t buffer_idx
The index of the buffer used for MULTIWRITE and used as sub-status for other statuses.
Definition: cyrf6936.h:57
uint8_t
unsigned char uint8_t
Definition: types.h:14
CYRF6936_UNINIT
@ CYRF6936_UNINIT
The chip isn't initialized.
Definition: cyrf6936.h:37
Cyrf6936::output_buf
uint8_t output_buf[17]
The output buffer for the SPI transaction.
Definition: cyrf6936.h:53
Cyrf6936::has_irq
bool has_irq
When the CYRF6936 is done reading the irq.
Definition: cyrf6936.h:59
cyrf6936_init
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
CYRF6936_CHAN_SOP_DATA_CRC
@ CYRF6936_CHAN_SOP_DATA_CRC
The chip is setting the channel, SOP code, DATA code and the CRC seed.
Definition: cyrf6936.h:42
cyrf6936_write
bool cyrf6936_write(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data)
Write to one register.
Definition: cyrf6936.c:330
CYRF6936_MAX_BUFFER
#define CYRF6936_MAX_BUFFER
The max buffer size in the cyrf6936 structure.
Definition: cyrf6936.h:33
cyrf6936_multi_write
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
Cyrf6936::mfg_id
uint8_t mfg_id[6]
The manufacturer id of the CYRF6936 chip.
Definition: cyrf6936.h:60
Cyrf6936
Definition: cyrf6936.h:48
spi_transaction::slave_idx
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:153
cyrf6936_event
void cyrf6936_event(struct Cyrf6936 *cyrf)
The on event call for the CYRF6936 chip.
Definition: cyrf6936.c:86
CYRF6936_DATA_CODE
@ CYRF6936_DATA_CODE
The chip is writing a data code.
Definition: cyrf6936.h:41
CYRF6936_RX_IRQ_STATUS_PACKET
@ CYRF6936_RX_IRQ_STATUS_PACKET
The chip is getting the receive irq status, receive status and the receive packet.
Definition: cyrf6936.h:43
cyrf6936_read_rx_irq_status_packet
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
CYRF6936_SEND
@ CYRF6936_SEND
The chip is busy sending a packet.
Definition: cyrf6936.h:44
Cyrf6936::rx_irq_status
uint8_t rx_irq_status
The last receive interrupt status.
Definition: cyrf6936.h:62
Cyrf6936::spi_t
struct spi_transaction spi_t
The SPI transaction used for the writing and reading of registers.
Definition: cyrf6936.h:50
Cyrf6936::status
enum Cyrf6936Status status
The status of the CYRF6936 chip.
Definition: cyrf6936.h:51
CYRF6936_MULTIWRITE
@ CYRF6936_MULTIWRITE
The chip is writing multiple registers.
Definition: cyrf6936.h:40
CYRF6936_GET_MFG_ID
@ CYRF6936_GET_MFG_ID
The chip is busy with getting the manufacturer ID.
Definition: cyrf6936.h:39
Cyrf6936Status
Cyrf6936Status
Definition: cyrf6936.h:36
Cyrf6936::input_buf
uint8_t input_buf[17]
The input buffer for the SPI transaction.
Definition: cyrf6936.h:52