Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of EV-COG-AD3029LZ by
Diff: SimpleSpirit1.cpp
- Revision:
- 12:b8056eda4028
- Parent:
- 11:b769d6caad82
- Child:
- 14:898a9d48dd03
--- a/SimpleSpirit1.cpp Wed Oct 26 15:08:44 2016 +0200
+++ b/SimpleSpirit1.cpp Fri Oct 28 14:14:03 2016 +0200
@@ -83,7 +83,6 @@
packet_is_prepared = 0;
just_got_an_ack = 0;
#endif // CONTIKI
- receiving_packet = 0;
last_rssi = 0 ; //MGR
last_lqi = 0 ; //MGR
@@ -133,11 +132,11 @@
irq_clear_status();
irq_set_status(TX_DATA_SENT, S_ENABLE);
irq_set_status(RX_DATA_READY,S_ENABLE);
- irq_set_status(VALID_SYNC,S_ENABLE);
irq_set_status(RX_DATA_DISC, S_ENABLE);
irq_set_status(TX_FIFO_ERROR, S_ENABLE);
irq_set_status(RX_FIFO_ERROR, S_ENABLE);
irq_set_status(RX_FIFO_ALMOST_FULL, S_ENABLE);
+ irq_set_status(VALID_SYNC, S_ENABLE);
/* Configure Spirit1 */
radio_persisten_rx(S_ENABLE);
@@ -155,6 +154,7 @@
CLEAR_RXBUF();
_spirit_tx_started = false;
_spirit_rx_err = false;
+ _is_receiving = false;
/* Configure the radio to route the IRQ signal to its GPIO 3 */
SGpioInit x_gpio_init = {
@@ -325,10 +325,11 @@
disable_spirit_irq();
+ _is_receiving = false;
+
if(SPIRIT1_STATUS() == SPIRIT1_STATE_STANDBY) {
cmd_strobe(SPIRIT1_STROBE_READY);
} else if(SPIRIT1_STATUS() == SPIRIT1_STATE_RX) {
- receiving_packet = 0;
cmd_strobe(SPIRIT1_STROBE_SABORT);
}
irq_clear_status();
@@ -345,7 +346,6 @@
disable_spirit_irq();
/* first stop rx/tx */
- receiving_packet = 0;
cmd_strobe(SPIRIT1_STROBE_SABORT);
/* Clear any pending irqs */
@@ -368,6 +368,8 @@
spirit_on = OFF;
_nr_of_irq_disables = 1;
_spirit_tx_started = false;
+ _is_receiving = false;
+
CLEAR_TXBUF();
CLEAR_RXBUF();
}
@@ -399,8 +401,8 @@
//return 1;
}
CLEAR_RXBUF();
- receiving_packet = 0;
_spirit_rx_err = false;
+ _is_receiving = false;
/* Enables the mcu to get IRQ from the SPIRIT1 */
spirit_on = ON;
@@ -442,7 +444,6 @@
/* Checks if the RX buffer is empty */
if(IS_RXBUF_EMPTY()) {
CLEAR_RXBUF();
- receiving_packet = 0;
cmd_strobe(SPIRIT1_STROBE_SABORT);
wait_us(SABORT_WAIT_US);
cmd_strobe(SPIRIT1_STROBE_READY);
@@ -451,6 +452,7 @@
cmd_strobe(SPIRIT1_STROBE_RX);
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 1);
_spirit_rx_err = false;
+ _is_receiving = false;
PRINTF("READ OUT RX BUF EMPTY\n");
enable_spirit_irq();
return 0;
@@ -472,6 +474,7 @@
#endif
bufsize = spirit_rx_len;
+ _is_receiving = false;
CLEAR_RXBUF();
enable_spirit_irq();
@@ -528,6 +531,7 @@
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 5);
CLEAR_RXBUF();
_spirit_rx_err = false;
+ _is_receiving = false;
enable_spirit_irq();
}
@@ -557,8 +561,8 @@
/* Reception errors */
if((x_irq_status.IRQ_RX_FIFO_ERROR) || (x_irq_status.IRQ_RX_DATA_DISC) || (x_irq_status.IRQ_RX_TIMEOUT)) {
- receiving_packet = 0;
_spirit_rx_err = true;
+ _is_receiving = false;
CLEAR_RXBUF();
cmd_strobe(SPIRIT1_STROBE_FRX);
if(_spirit_tx_started) {
@@ -574,7 +578,7 @@
/* Transmission error */
if(x_irq_status.IRQ_TX_FIFO_ERROR) {
error("IRQ_TX_FIFO_ERROR should never happen!\n");
- receiving_packet = 0;
+
cmd_strobe(SPIRIT1_STROBE_FTX);
if(_spirit_tx_started) {
_spirit_tx_started = false;
@@ -588,28 +592,21 @@
/* The IRQ_VALID_SYNC is used to notify a new packet is coming */
if(x_irq_status.IRQ_VALID_SYNC) {
- receiving_packet = 1;
- _spirit_rx_err = false;
- CLEAR_RXBUF();
- if(_spirit_tx_started) { // betzw - TOCHECK: is this really correct to be done here?
- _spirit_tx_started = false;
- CLEAR_TXBUF();
- /* call user callback */
- if(_current_irq_callback) {
- _current_irq_callback(TX_ERR);
- }
- }
+ _is_receiving = true;
+ _spirit_rx_err = false;
+ CLEAR_RXBUF();
+ MBED_ASSERT(!_spirit_tx_started);
}
/* RX FIFO almost full */
if(x_irq_status.IRQ_RX_FIFO_ALMOST_FULL) {
+ _is_receiving = true;
if(_spirit_rx_err) {
cmd_strobe(SPIRIT1_STROBE_FRX);
} else {
uint8_t fifo_available = linear_fifo_read_num_elements_rx_fifo();
unsigned int remaining = MAX_PACKET_LEN - _spirit_rx_pos;
if(fifo_available > remaining) {
- receiving_packet = 0;
_spirit_rx_err = true;
CLEAR_RXBUF();
cmd_strobe(SPIRIT1_STROBE_FRX);
@@ -640,8 +637,9 @@
/* The IRQ_RX_DATA_READY notifies a new packet arrived */
if(x_irq_status.IRQ_RX_DATA_READY) {
+ _is_receiving = false; // Finished receiving
+
if(_spirit_rx_err) {
- receiving_packet = 0;
_spirit_rx_err = false;
CLEAR_RXBUF();
cmd_strobe(SPIRIT1_STROBE_FRX);
@@ -668,8 +666,6 @@
last_rssi = qi_get_rssi(); //MGR
last_lqi = qi_get_lqi(); //MGR
- receiving_packet = 0;
-
#if NULLRDC_CONF_802154_AUTOACK
if (spirit_rxbuf[0] == ACK_LEN) {
/* For debugging purposes we assume this is an ack for us */
