From: Nathael Pajani Date: Thu, 3 Jan 2019 16:54:16 +0000 (+0100) Subject: Add function to get back to normal state upon Rx error. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=9d13c3c06fc63f85779102cb8a16434a4ed86228;p=soft%2Flpc122x%2Fcore Add function to get back to normal state upon Rx error. --- diff --git a/extdrv/cc1101.c b/extdrv/cc1101.c index 9649da8..6ed1831 100644 --- a/extdrv/cc1101.c +++ b/extdrv/cc1101.c @@ -362,6 +362,42 @@ int cc1101_receive_packet(uint8_t* buffer, uint8_t size, uint8_t* status) return ret; } +int cc1101_handle_rx_err(uint8_t* status) +{ + uint8_t st_buff[2]; + uint8_t rx_status = 0, pkt_status = 0; + + /* Check that we are in an error state */ + rx_status = cc1101_read_reg(CC1101_STATUS(rx_bytes)); + if (rx_status != 0) { + return -CC1101_ERR_NO_RX_ERR; + } + pkt_status = cc1101_read_reg(CC1101_STATUS(packet_status)); + if (status != NULL) { + *status = pkt_status; + } + cc1101_read_burst_reg(CC1101_FIFO_BURST, st_buff, 2); + cc1101.link_quality = st_buff[1]; + cc1101.rx_sig_strength = st_buff[0]; + + rx_status = cc1101_read_reg(CC1101_STATUS(rx_bytes)); + if (rx_status == 0) { + cc1101_flush_rx_fifo(); + } + /* CRC error */ + if (!(cc1101.link_quality & CC1101_CRC_OK)) { + cc1101_flush_rx_fifo(); + return -CC1101_ERR_CRC; + } + /* Overflow ? */ + if (rx_status & CC1101_RX_FIFO_OVERFLOW) { + cc1101_flush_rx_fifo(); + return -CC1101_ERR_OVERFLOW; + } + return rx_status; +} + + /***************************************************************************** */ /* CC1101 Initialisation */ diff --git a/include/extdrv/cc1101.h b/include/extdrv/cc1101.h index 39bb688..b9fd283 100644 --- a/include/extdrv/cc1101.h +++ b/include/extdrv/cc1101.h @@ -143,6 +143,7 @@ struct cc1101_command_strobes { #define CC1101_ERR_INCOMPLET_PACKET (CC1101_ERR_BASE + 3) #define CC1101_ERR_OVERFLOW (CC1101_ERR_BASE + 4) #define CC1101_ERR_CRC (CC1101_ERR_BASE + 5) +#define CC1101_ERR_NO_RX_ERR (CC1101_ERR_BASE + 6) /* Definitions for chip status */ @@ -248,6 +249,7 @@ int cc1101_send_packet(uint8_t* buffer, uint8_t size); int cc1101_receive_packet(uint8_t* buffer, uint8_t size, uint8_t* status); +int cc1101_handle_rx_err(uint8_t* status); /***************************************************************************** */ /* CC1101 Initialisation */ @@ -261,7 +263,7 @@ int cc1101_receive_packet(uint8_t* buffer, uint8_t size, uint8_t* status); void cc1101_set_address(uint8_t address); /* Set current channel to use. - * The caller is responsible for checking that the channel spacing and channel bandwith are configures + * The caller is responsible for checking that the channel spacing and channel bandwith are configured * correctly to prevent overlaping channels, or to use only non-overlaping channel numbers. * This function places the CC1101 chip in idle state. */