Skip to content

Commit

Permalink
[superbitrf] Now got a full RC working, still needs testing.
Browse files Browse the repository at this point in the history
Binding could be improved but already works about 30% of the times you try.
  • Loading branch information
fvantienen committed Aug 29, 2013
1 parent 03c3b8f commit 55add10
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 28 deletions.
4 changes: 3 additions & 1 deletion conf/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,10 @@
</message>

<message name="SUPERBITRF" id="72">
<field name="status" type="uint8" values="UNINIT|INIT_BINDING|INIT_TRANSFER|BINDING|TRANSFER"/>
<field name="status" type="uint8" values="UNINIT|INIT_BINDING|INIT_TRANSFER|BINDING|SYNCING_A|SYNCING_B|TRANSFER"/>
<field name="cyrf_status" type="uint8" values="UNINIT|IDLE|GET_MFG_ID|MULTIWRITE|CHAN_SOP_DATA_CRC|RX_IRQ_STATUS_PACKET"/>
<field name="packet_count" type="uint32"/>
<field name="bind_mfg_id" type="uint32"/>
<field name="mfg_id" type="uint8[]"/>
</message>

Expand Down
2 changes: 1 addition & 1 deletion conf/telemetry/default_rotorcraft.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<message name="INS" period=".25"/>
<message name="I2C_ERRORS" period="4.1"/>
<message name="UART_ERRORS" period="3.1"/>
<message name="SUPERBITRF" period="1."/>
</mode>

<mode name="ppm">
Expand All @@ -26,7 +27,6 @@
<message name="RC" period="0.5"/>
<message name="ROTORCRAFT_RADIO_CONTROL" period="0.5"/>
<message name="ROTORCRAFT_STATUS" period="1"/>
<message name="SUPERBITRF" period="0.5"/>
</mode>

<mode name="raw_sensors">
Expand Down
2 changes: 2 additions & 0 deletions sw/airborne/firmwares/rotorcraft/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
DOWNLINK_SEND_SUPERBITRF(_trans, _dev, \
&superbitrf.status, \
&superbitrf.cyrf6936.status, \
&superbitrf.packet_count, \
&superbitrf.packet_count, \
6, \
superbitrf.cyrf6936.mfg_id);}
#else
Expand Down
37 changes: 19 additions & 18 deletions sw/airborne/peripherals/cyrf6936.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "mcu_periph/spi.h"
#include "mcu_periph/gpio.h"
#include "mcu_periph/gpio_arch.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/radio_control.h"

#include "mcu_periph/uart.h"
Expand All @@ -40,28 +41,14 @@ static bool_t cyrf6936_write_block(struct Cyrf6936 *cyrf, const uint8_t addr, co
static bool_t cyrf6936_read_register(struct Cyrf6936 *cyrf, const uint8_t addr);
static bool_t cyrf6936_read_block(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t length);

//FIXME
void Delay(uint32_t x);
void Delay(uint32_t x)
{
(void)x;
__asm ("mov r1, #24;"
"mul r0, r0, r1;"
"b _delaycmp;"
"_delayloop:"
"subs r0, r0, #1;"
"_delaycmp:;"
"cmp r0, #0;"
" bne _delayloop;");
}

/**
* Initializing the cyrf chip
*/
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) {
/* Set spi_peripheral and the status */
cyrf->spi_p = spi_p;
cyrf->status = CYRF6936_UNINIT;
cyrf->has_packet = FALSE;

/* Set the spi transaction */
cyrf->spi_t.cpol = SPICpolIdleLow;
Expand All @@ -78,12 +65,12 @@ void cyrf6936_init(struct Cyrf6936 *cyrf, struct spi_periph *spi_p, const uint8_
cyrf->spi_t.select = SPISelectUnselect;
cyrf->spi_t.status = SPITransDone;

/* Reset the CYRF6936 chip */
/* Reset the CYRF6936 chip (busy waiting) */
gpio_setup_output(rst_port, rst_pin);
gpio_output_high(rst_port, rst_pin);
Delay(100);
sys_time_usleep(100);
gpio_output_low(rst_port, rst_pin);
Delay(100);
sys_time_usleep(100);

/* Get the MFG ID */
cyrf->status = CYRF6936_GET_MFG_ID;
Expand Down Expand Up @@ -156,6 +143,10 @@ void cyrf6936_event(struct Cyrf6936 *cyrf) {
((uint8_t (*)[2])cyrf->buffer)[cyrf->buffer_idx][1]);
break;

/* Do a write of the data code */
case CYRF6936_DATA_CODE:
break;

/* Do a write of channel, sop, data and crc */
case CYRF6936_CHAN_SOP_DATA_CRC:
// When the last transaction isn't failed send the next
Expand Down Expand Up @@ -213,6 +204,7 @@ void cyrf6936_event(struct Cyrf6936 *cyrf) {
for(i = 0; i < 16; i++)
cyrf->rx_packet[i] = cyrf->input_buf[i+1];

cyrf->has_packet = TRUE;
cyrf->status = CYRF6936_IDLE;
break;
}
Expand Down Expand Up @@ -276,6 +268,15 @@ static bool_t cyrf6936_read_block(struct Cyrf6936 *cyrf, const uint8_t addr, con
return spi_submit(cyrf->spi_p, &(cyrf->spi_t));
}

/**
* Write to one register
*/
bool_t cyrf6936_write(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data) {
const uint8_t data_multi[][2] = {
{addr, data}
};
return cyrf6936_multi_write(cyrf, data_multi, 1);
}

/**
* Write to multiple registers one byte
Expand Down
3 changes: 3 additions & 0 deletions sw/airborne/peripherals/cyrf6936.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum Cyrf6936Status {
CYRF6936_IDLE, /**< The chip is idle and can be used */
CYRF6936_GET_MFG_ID, /**< The chip is busy with getting the manufacturer ID */
CYRF6936_MULTIWRITE, /**< The chip is writing multiple registers */
CYRF6936_DATA_CODE, /**< The chip is writing a data code */
CYRF6936_CHAN_SOP_DATA_CRC, /**< The chip is setting the channel, SOP code, DATA code and the CRC seed */
CYRF6936_RX_IRQ_STATUS_PACKET /**< The chip is getting the receive irq status, receive status and the receive packet */
};
Expand All @@ -54,6 +55,7 @@ struct Cyrf6936 {
uint8_t buffer_length; /**< The length of the buffer used for MULTIWRITE */
uint8_t buffer_idx; /**< The index of the buffer used for MULTIWRITE and used as sub-status for other statuses */

bool_t has_packet; /**< When the CYRF6936 is done reading the receive registers */
uint8_t mfg_id[6]; /**< The manufacturer id of the CYRF6936 chip */
uint8_t rx_irq_status; /**< The last receive interrupt status */
uint8_t rx_status; /**< The last receive status */
Expand All @@ -63,6 +65,7 @@ struct Cyrf6936 {
extern 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);
void cyrf6936_event(struct Cyrf6936 *cyrf);

bool_t cyrf6936_write(struct Cyrf6936 *cyrf, const uint8_t addr, const uint8_t data);
bool_t cyrf6936_multi_write(struct Cyrf6936 *cyrf, const uint8_t data[][2], const uint8_t length);
bool_t 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);
bool_t cyrf6936_read_rx_irq_status_packet(struct Cyrf6936 *cyrf);
Expand Down
Loading

0 comments on commit 55add10

Please sign in to comment.