Prototype RF driver for STM Sub-1 GHz RF expansion board based on the SPSGRF-868 module for STM32 Nucleo.

Dependents:   DISCO_IOT-wifi_client

Fork of stm-spirit1-rf-driver by ST

Files at this revision

API Documentation at this revision

Comitter:
Wolfgang Betz
Date:
Thu Jan 12 08:20:43 2017 +0100
Parent:
47:3a30b960a8c2
Child:
49:d017830c0c67
Commit message:
Insert 'MAX_PACKET_LEN' checks when receiving

Changed in this revision

source/SimpleSpirit1.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/source/SimpleSpirit1.cpp	Thu Dec 22 08:25:22 2016 +0100
+++ b/source/SimpleSpirit1.cpp	Thu Jan 12 08:20:43 2017 +0100
@@ -525,10 +525,10 @@
 			spirit_rx_len = pkt_basic_get_received_pkt_length();
 
 #ifdef DEBUG_IRQ
-			debug_if(!(spirit_rx_len <= MAX_PACKET_LEN), "\n\rAssert failed in: %s (%d)\n\r", __func__, __LINE__);
+			debug_if(!(spirit_rx_len <= MAX_PACKET_LEN), "\n\r%s (%d): irq=%x\n\r", __func__, __LINE__, *tmp);
 #endif
 
-			for(; _spirit_rx_pos < spirit_rx_len;) {
+			if(spirit_rx_len <= MAX_PACKET_LEN) {
 				uint8_t to_receive = spirit_rx_len - _spirit_rx_pos;
 				if(to_receive > 0) {
 					spi_read_linear_fifo(to_receive, &spirit_rx_buf[_spirit_rx_pos]);
@@ -542,7 +542,7 @@
 			last_sqi  = qi_get_sqi();  //MGR
 
 			/* call user callback */
-			if(_current_irq_callback) {
+			if((_spirit_rx_pos == spirit_rx_len) && _current_irq_callback) {
 				_current_irq_callback(RX_DONE);
 			}
 
@@ -564,8 +564,14 @@
 #endif
 		} else {
 			uint8_t fifo_available = linear_fifo_read_num_elements_rx_fifo();
-			spi_read_linear_fifo(fifo_available, &spirit_rx_buf[_spirit_rx_pos]);
-			_spirit_rx_pos += fifo_available;
+			if((fifo_available + _spirit_rx_pos) <= MAX_PACKET_LEN) {
+				spi_read_linear_fifo(fifo_available, &spirit_rx_buf[_spirit_rx_pos]);
+				_spirit_rx_pos += fifo_available;
+			} else {
+#ifdef DEBUG_IRQ
+				debug("\n\r%s (%d): irq=%x\n\r", __func__, __LINE__, *tmp);
+#endif
+			}
 		}
 	}
 #endif // !RX_FIFO_THR_WA