센서보드 RF IRQ 테스트 중

Fork of stm-spirit1-rf-driver by ST

Revision:
62:44ab5af08199
Parent:
61:0e6aa2ea086f
Child:
63:d7530f62ed93
--- a/source/NanostackRfPhySpirit1.cpp	Wed May 31 11:59:00 2017 +0200
+++ b/source/NanostackRfPhySpirit1.cpp	Mon Jun 26 13:53:43 2017 +0200
@@ -17,8 +17,8 @@
 const phy_rf_channel_configuration_s phy_subghz = {868000000, 1000000, 250000, 11, M_GFSK};
 
 static phy_device_channel_page_s phy_channel_pages[] = {
-    {CHANNEL_PAGE_2, &phy_subghz},
-    {CHANNEL_PAGE_0, NULL}
+        {CHANNEL_PAGE_2, &phy_subghz},
+        {CHANNEL_PAGE_0, NULL}
 };
 
 static uint8_t tx_sequence = 0xff;
@@ -94,44 +94,44 @@
     /*Check if transmitter is busy*/
     if(rf_device->is_receiving()) { /* betzw - WAS: (rf_device->channel_clear() != 0)), do NOT use this but rather study and enable automatic CCA */
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d)", __func__, __LINE__);
+        tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	
-	/* Release Lock */
-	rf_if_unlock();
 
-	/*Return busy*/
-	return -1;
+        /* Release Lock */
+        rf_if_unlock();
+
+        /*Return busy*/
+        return -1;
     } else {
 #ifdef HEAVY_TRACING
-	uint16_t fcf = rf_read_16_bit(data_ptr);
-	uint16_t need_ack;
+        uint16_t fcf = rf_read_16_bit(data_ptr);
+        uint16_t need_ack;
 
-	/*Check if transmitted data needs to be acked*/
-	if((fcf & MAC_FCF_ACK_REQ_BIT_MASK) >> MAC_FCF_ACK_REQ_BIT_SHIFT)
-	    need_ack = 1;
-	else
-	    need_ack = 0;
+        /*Check if transmitted data needs to be acked*/
+        if((fcf & MAC_FCF_ACK_REQ_BIT_MASK) >> MAC_FCF_ACK_REQ_BIT_SHIFT)
+            need_ack = 1;
+        else
+            need_ack = 0;
 #endif
 
-	/*Store the sequence number for ACK handling*/
-	tx_sequence = *(data_ptr + 2);
+        /*Store the sequence number for ACK handling*/
+        tx_sequence = *(data_ptr + 2);
 
-	/*Store TX handle*/
-	mac_tx_handle = tx_handle;
+        /*Store TX handle*/
+        mac_tx_handle = tx_handle;
 
 #ifdef HEAVY_TRACING
-	tr_info("%s (%d), len=%d, tx_handle=%x, tx_seq=%x, need_ack=%d (%x:%x, %x:%x, %x:%x, %x:%x)", __func__, __LINE__,
-		data_length, tx_handle, tx_sequence, need_ack,
-		data_ptr[3], data_ptr[4], data_ptr[5], data_ptr[6],
-		data_ptr[7], data_ptr[8], data_ptr[9], data_ptr[10]);
+        tr_info("%s (%d), len=%d, tx_handle=%x, tx_seq=%x, need_ack=%d (%x:%x, %x:%x, %x:%x, %x:%x)", __func__, __LINE__,
+                data_length, tx_handle, tx_sequence, need_ack,
+                data_ptr[3], data_ptr[4], data_ptr[5], data_ptr[6],
+                data_ptr[7], data_ptr[8], data_ptr[9], data_ptr[10]);
 #endif
 
-	/*Send the packet*/
-	rf_device->send(data_ptr, data_length);
+        /*Send the packet*/
+        rf_device->send(data_ptr, data_length);
 
-	/* Release Lock */
-	rf_if_unlock();
+        /* Release Lock */
+        rf_if_unlock();
     }
 
     /*Return success*/
@@ -143,41 +143,41 @@
     int8_t ret_val = 0;
     switch (new_state)
     {
-	/*Reset PHY driver and set to idle*/
-    case PHY_INTERFACE_RESET:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	rf_device->reset_board();
-	break;
-	/*Disable PHY Interface driver*/
-    case PHY_INTERFACE_DOWN:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	ret_val = rf_device->off();
-	if(ret_val != 0) ret_val = -1;
-	break;
-	/*Enable PHY Interface driver*/
-    case PHY_INTERFACE_UP:
-	ret_val = rf_device->on();
-	if(ret_val != 0) {
-	    tr_debug("%s (%d)", __func__, __LINE__);
-	    ret_val = -1;
-	    break;
-	}
-	tr_debug("%s (%d) - channel: %d", __func__, __LINE__, (int)rf_channel);
-	rf_device->set_channel(rf_channel);
-	break;
-	/*Enable wireless interface ED scan mode*/
-    case PHY_INTERFACE_RX_ENERGY_STATE:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	break;
-	/*Enable Sniffer state*/
-    case PHY_INTERFACE_SNIFFER_STATE:
-	// TODO - if we really need this - WAS: rf_setup_sniffer(rf_channel);
-	tr_debug("%s (%d)", __func__, __LINE__);
-	ret_val = -1;
-	break;
-    default:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	break;
+        /*Reset PHY driver and set to idle*/
+        case PHY_INTERFACE_RESET:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            rf_device->reset_board();
+            break;
+            /*Disable PHY Interface driver*/
+        case PHY_INTERFACE_DOWN:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            ret_val = rf_device->off();
+            if(ret_val != 0) ret_val = -1;
+            break;
+            /*Enable PHY Interface driver*/
+        case PHY_INTERFACE_UP:
+            ret_val = rf_device->on();
+            if(ret_val != 0) {
+                tr_debug("%s (%d)", __func__, __LINE__);
+                ret_val = -1;
+                break;
+            }
+            tr_debug("%s (%d) - channel: %d", __func__, __LINE__, (int)rf_channel);
+            rf_device->set_channel(rf_channel);
+            break;
+            /*Enable wireless interface ED scan mode*/
+        case PHY_INTERFACE_RX_ENERGY_STATE:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            break;
+            /*Enable Sniffer state*/
+        case PHY_INTERFACE_SNIFFER_STATE:
+            // TODO - if we really need this - WAS: rf_setup_sniffer(rf_channel);
+            tr_debug("%s (%d)", __func__, __LINE__);
+            ret_val = -1;
+            break;
+        default:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            break;
     }
     return ret_val;
 }
@@ -186,96 +186,96 @@
 {
     switch (extension_type)
     {
-	/*Control MAC pending bit for Indirect data transmission*/
-    case PHY_EXTENSION_CTRL_PENDING_BIT:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	break;
+        /*Control MAC pending bit for Indirect data transmission*/
+        case PHY_EXTENSION_CTRL_PENDING_BIT:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            break;
 
-	/*Return frame pending status*/
-    case PHY_EXTENSION_READ_LAST_ACK_PENDING_STATUS:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	*data_ptr = 0;
-	break;
+            /*Return frame pending status*/
+        case PHY_EXTENSION_READ_LAST_ACK_PENDING_STATUS:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            *data_ptr = 0;
+            break;
 
-	/*Set channel, used for setting channel for energy scan*/
-    case PHY_EXTENSION_SET_CHANNEL:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	break;
+            /*Set channel, used for setting channel for energy scan*/
+        case PHY_EXTENSION_SET_CHANNEL:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            break;
 
-	/*Read energy on the channel*/
-    case PHY_EXTENSION_READ_CHANNEL_ENERGY:
-	// TODO: *data_ptr = rf_get_channel_energy();
-	tr_debug("%s (%d)", __func__, __LINE__);
-	*data_ptr = (int8_t)rf_device->get_last_rssi_dbm();
-	break;
+            /*Read energy on the channel*/
+        case PHY_EXTENSION_READ_CHANNEL_ENERGY:
+            // TODO: *data_ptr = rf_get_channel_energy();
+            tr_debug("%s (%d)", __func__, __LINE__);
+            *data_ptr = (int8_t)rf_device->get_last_rssi_dbm();
+            break;
 
-	/*Read status of the link*/
-    case PHY_EXTENSION_READ_LINK_STATUS:
-	// TODO: *data_ptr = rf_get_link_status();
-	tr_debug("%s (%d)", __func__, __LINE__);
-	*data_ptr = rf_device->get_last_sqi(); // use SQI as link quality
-	break;
+            /*Read status of the link*/
+        case PHY_EXTENSION_READ_LINK_STATUS:
+            // TODO: *data_ptr = rf_get_link_status();
+            tr_debug("%s (%d)", __func__, __LINE__);
+            *data_ptr = rf_device->get_last_sqi(); // use SQI as link quality
+            break;
 
-    default:
-	tr_debug("%s (%d)", __func__, __LINE__);
-	break;
+        default:
+            tr_debug("%s (%d)", __func__, __LINE__);
+            break;
     }
     return 0;
 }
 
 static inline void rf_set_mac_address(uint8_t *ptr) {
     tr_debug("%s (%d), adr0=%x, adr1=%x, adr2=%x, adr3=%x, adr4=%x, adr5=%x, adr6=%x, adr7=%x",
-	     __func__, __LINE__,
-	     ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]);
+             __func__, __LINE__,
+             ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]);
     for(int i = 0; i < 8; i++) {
-	stored_mac_address[i] = ptr[i];
+        stored_mac_address[i] = ptr[i];
     }
 }
 
 static inline void rf_get_mac_address(uint8_t *ptr) {
     for(int i = 0; i < 8; i++) {
-	ptr[i] = stored_mac_address[i];
+        ptr[i] = stored_mac_address[i];
     }
     tr_debug("%s (%d), adr0=%x, adr1=%x, adr2=%x, adr3=%x, adr4=%x, adr5=%x, adr6=%x, adr7=%x",
-	     __func__, __LINE__,
-	     ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]);
+             __func__, __LINE__,
+             ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]);
 }
 
 static inline void rf_set_short_adr(uint8_t *ptr) {
     stored_short_adr = (ptr[0] << 8) + ptr[1]; // big-endian
     tr_debug("%s (%d), adr0=%x, adr1=%x, val=%d",
-	     __func__, __LINE__,
-	     ptr[0], ptr[1], stored_short_adr);
+             __func__, __LINE__,
+             ptr[0], ptr[1], stored_short_adr);
 }
 
 static inline void rf_set_pan_id(uint8_t *ptr) {
     stored_pan_id = (ptr[0] << 8) + ptr[1]; // big-endian
     tr_debug("%s (%d), adr0=%x, adr1=%x, val=%d",
-	     __func__, __LINE__,
-	     ptr[0], ptr[1], stored_pan_id);
+             __func__, __LINE__,
+             ptr[0], ptr[1], stored_pan_id);
 }
 
 static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
 {
     switch (address_type)
     {
-	/*Set 48-bit address*/
-    case PHY_MAC_48BIT:
-	/* Not used in this example */
-	// betzw - WAS: rf_set_mac_48bit(address_ptr);
-	break;
-	/*Set 64-bit address*/
-    case PHY_MAC_64BIT:
-	rf_set_mac_address(address_ptr);
-	break;
-	/*Set 16-bit address*/
-    case PHY_MAC_16BIT:
-	rf_set_short_adr(address_ptr);
-	break;
-	/*Set PAN Id*/
-    case PHY_MAC_PANID:
-	rf_set_pan_id(address_ptr);
-	break;
+        /*Set 48-bit address*/
+        case PHY_MAC_48BIT:
+            /* Not used in this example */
+            // betzw - WAS: rf_set_mac_48bit(address_ptr);
+            break;
+            /*Set 64-bit address*/
+        case PHY_MAC_64BIT:
+            rf_set_mac_address(address_ptr);
+            break;
+            /*Set 16-bit address*/
+        case PHY_MAC_16BIT:
+            rf_set_short_adr(address_ptr);
+            break;
+            /*Set PAN Id*/
+        case PHY_MAC_PANID:
+            rf_set_pan_id(address_ptr);
+            break;
     }
 
     return 0;
@@ -284,7 +284,7 @@
 /* Note: we are in IRQ context */
 static inline void rf_send_signal(int32_t signal) {
 #ifdef HEAVY_TRACING
-	tr_info("%s (%d): %d", __func__, __LINE__, signal);
+    tr_info("%s (%d): %d", __func__, __LINE__, signal);
 #endif
     rf_ack_sender.signal_set(signal);
 }
@@ -297,17 +297,17 @@
     if(tx_sequence == seq_number)
     {
 #ifdef HEAVY_TRACING
-	tr_info("%s (%d)", __func__, __LINE__);
+        tr_info("%s (%d)", __func__, __LINE__);
 #endif
 
-	/*Call PHY TX Done API*/
-	if(device_driver.phy_tx_done_cb){
-	    phy_status = PHY_LINK_TX_DONE;
-	    rf_send_signal(RF_SIG_CB_TX_DONE);
-	}
+        /*Call PHY TX Done API*/
+        if(device_driver.phy_tx_done_cb){
+            phy_status = PHY_LINK_TX_DONE;
+            rf_send_signal(RF_SIG_CB_TX_DONE);
+        }
     } else {
 #ifdef HEAVY_TRACING
-	tr_info("%s (%d)", __func__, __LINE__);
+        tr_info("%s (%d)", __func__, __LINE__);
 #endif
     }
 }
@@ -315,7 +315,7 @@
 /* Note: we are in IRQ context */
 static inline bool rf_check_mac_address(uint8_t *dest) {
     for(int i = 0; i < 8; i++) {
-	if(dest[i] != stored_mac_address[7-i]) return false;
+        if(dest[i] != stored_mac_address[7-i]) return false;
     }
     return true;
 }
@@ -335,8 +335,8 @@
 #endif
 
     if(len < 3) {
-	tr_debug("%s (%d)", __func__, __LINE__);
-	return false;
+        tr_debug("%s (%d)", __func__, __LINE__);
+        return false;
     }
 
     uint16_t fcf = rf_read_16_bit(rf_rx_buf);
@@ -350,122 +350,122 @@
 
 #ifdef HEAVY_TRACING
     tr_info("%s (%d): len=%d, ftype=%x, snr=%x, ack=%d, dst=%x, src=%x, intra=%d", __func__, __LINE__, len, frame_type,
-	    rf_rx_buf[2], (*ack_requested), dst_addr_mode, src_addr_mode, panid_compr);
+            rf_rx_buf[2], (*ack_requested), dst_addr_mode, src_addr_mode, panid_compr);
 #endif
 
     if(frame_type == FC_ACK_FRAME) { // betzw: we support up to two different forms of ACK frames!
-	if((len == 3) && (dst_addr_mode == 0x0) && (src_addr_mode == 0x0)) {
-	    ret = true;
-	}
+        if((len == 3) && (dst_addr_mode == 0x0) && (src_addr_mode == 0x0)) {
+            ret = true;
+        }
 
 #ifdef HEAVY_TRACING
-	tr_info("%s (%d): ret=%d", __func__, __LINE__, ret);
+        tr_info("%s (%d): ret=%d", __func__, __LINE__, ret);
 #endif
-	(*ack_requested) = 0;  // Never acknowledge ACK frames
-	return ret;
+        (*ack_requested) = 0;  // Never acknowledge ACK frames
+        return ret;
     }
 
     switch(dst_addr_mode) {
-    case 0x00:
-	ret = true; // no check possible;
-	break;
-    case 0x02:
-	min_size += 4; // pan id + short dest adr
+        case 0x00:
+            ret = true; // no check possible;
+            break;
+        case 0x02:
+            min_size += 4; // pan id + short dest adr
 
-	if(len < 5) {
+            if(len < 5) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    return false;
-	}
+                return false;
+            }
 
-	dst_pan_id = rf_read_16_bit(&rf_rx_buf[3]);
-	if(dst_pan_id == 0xFFFF) {
+            dst_pan_id = rf_read_16_bit(&rf_rx_buf[3]);
+            if(dst_pan_id == 0xFFFF) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    ret = true;
-	    break;
-	}
+                ret = true;
+                break;
+            }
 
-	if(dst_pan_id == stored_pan_id) {
+            if(dst_pan_id == stored_pan_id) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    ret = true;
-	    break;
-	} else {
+                ret = true;
+                break;
+            } else {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d): %d!=%d", __func__, __LINE__, dst_pan_id, stored_pan_id);
+                tr_debug("%s (%d): %d!=%d", __func__, __LINE__, dst_pan_id, stored_pan_id);
 #endif
-	}
+            }
 
-	if(len < 7) {
+            if(len < 7) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    return false;
-	}
+                return false;
+            }
 
-	dst_short_adr = rf_read_16_bit(&rf_rx_buf[5]);
-	if(dst_short_adr == stored_short_adr) {
+            dst_short_adr = rf_read_16_bit(&rf_rx_buf[5]);
+            if(dst_short_adr == stored_short_adr) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    ret = true;
-	    break;
-	} else {
+                ret = true;
+                break;
+            } else {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d): %d!=%d", __func__, __LINE__, dst_short_adr, stored_short_adr);
+                tr_debug("%s (%d): %d!=%d", __func__, __LINE__, dst_short_adr, stored_short_adr);
 #endif
-	}
-	break;
-    case 0x03:
-	min_size += 10; // pan id + dest mac addr
+            }
+            break;
+        case 0x03:
+            min_size += 10; // pan id + dest mac addr
 
-	if(len < 5) {
+            if(len < 5) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    return false;
-	}
+                return false;
+            }
 
-	dst_pan_id = rf_read_16_bit(&rf_rx_buf[3]);
-	if(dst_pan_id == 0xFFFF) {
+            dst_pan_id = rf_read_16_bit(&rf_rx_buf[3]);
+            if(dst_pan_id == 0xFFFF) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    ret = true;
-	    break;
-	}
+                ret = true;
+                break;
+            }
 
-	if(dst_pan_id == stored_pan_id) {
+            if(dst_pan_id == stored_pan_id) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    ret = true;
-	    break;
-	}
+                ret = true;
+                break;
+            }
 
-	if(len < 13) {
+            if(len < 13) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+                tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    return false;
-	}
+                return false;
+            }
 
-	ret = rf_check_mac_address(&rf_rx_buf[5]);
-	break;
-    default:
-	/* not supported */
+            ret = rf_check_mac_address(&rf_rx_buf[5]);
+            break;
+        default:
+            /* not supported */
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d)", __func__, __LINE__);
+            tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	return false;
+            return false;
     }
 
     if(ret && (*ack_requested)) {
-	rf_rx_sequence = rf_rx_buf[2];
+        rf_rx_sequence = rf_rx_buf[2];
     }
 
 #ifdef HEAVY_TRACING
@@ -485,7 +485,7 @@
     /* Get received data */
     rf_buffer_len = rf_device->read(rf_rx_buf, MAX_PACKET_LEN);
     if(!rf_buffer_len)
-	return;
+        return;
 
 #ifdef HEAVY_TRACING
     tr_debug("%s (%d)", __func__, __LINE__);
@@ -494,28 +494,28 @@
     /* Check if packet should be accepted */
     if(!rf_check_destination(rf_buffer_len, &ack_requested)) {
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d)", __func__, __LINE__);
+        tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	return;
+        return;
     }
 
     /* If waiting for ACK, check here if the packet is an ACK to a message previously sent */
     uint16_t fcf = rf_read_16_bit(rf_rx_buf);
     if(((fcf & MAC_FCF_FRAME_TYPE_MASK) >> MAC_FCF_FRAME_TYPE_SHIFT) == FC_ACK_FRAME) {
-	/*Send sequence number in ACK handler*/
+        /*Send sequence number in ACK handler*/
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d), len=%u", __func__, __LINE__, (unsigned int)rf_buffer_len);
+        tr_debug("%s (%d), len=%u", __func__, __LINE__, (unsigned int)rf_buffer_len);
 #endif
-	rf_handle_ack(rf_rx_buf[2]);
-	return;
+        rf_handle_ack(rf_rx_buf[2]);
+        return;
     }
 
     /* Kick off ACK sending */
     if(ack_requested) {
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d), len=%u", __func__, __LINE__, (unsigned int)rf_buffer_len);
+        tr_debug("%s (%d), len=%u", __func__, __LINE__, (unsigned int)rf_buffer_len);
 #endif
-	rf_send_signal(RF_SIG_ACK_NEEDED);
+        rf_send_signal(RF_SIG_ACK_NEEDED);
     }
 
     /* Get link information */
@@ -531,7 +531,7 @@
 
     /* Send received data and link information to the network stack */
     if( device_driver.phy_rx_cb ){
-	rf_send_signal(RF_SIG_CB_RX_RCVD);
+        rf_send_signal(RF_SIG_CB_RX_RCVD);
     }
 }
 
@@ -540,17 +540,17 @@
 {
     /* Check if this is an ACK sending which is still pending */
     if(rf_ack_sent) {
-	rf_ack_sent = false;
+        rf_ack_sent = false;
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d)", __func__, __LINE__);
+        tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	return; // no need to inform stack
+        return; // no need to inform stack
     }
 
     /*Call PHY TX Done API*/
     if(device_driver.phy_tx_done_cb){
-	phy_status = PHY_LINK_TX_SUCCESS;
-	rf_send_signal(RF_SIG_CB_TX_DONE);
+        phy_status = PHY_LINK_TX_SUCCESS;
+        rf_send_signal(RF_SIG_CB_TX_DONE);
     }
 }
 
@@ -558,108 +558,108 @@
 static inline void rf_handle_tx_err(void) {
     /*Call PHY TX Done API*/
     if(device_driver.phy_tx_done_cb){
-	phy_status = PHY_LINK_TX_FAIL;
-	rf_send_signal(RF_SIG_CB_TX_DONE);
+        phy_status = PHY_LINK_TX_FAIL;
+        rf_send_signal(RF_SIG_CB_TX_DONE);
     }
 }
 
 /* Note: we are in IRQ context */
 static void rf_callback_func(int event) {
     switch(event) {
-    case SimpleSpirit1::RX_DONE:
-	rf_handle_rx_end();
-	break;
-    case SimpleSpirit1::TX_DONE:
-	rf_handle_tx_end();
-	break;
-    case SimpleSpirit1::TX_ERR:
+        case SimpleSpirit1::RX_DONE:
+            rf_handle_rx_end();
+            break;
+        case SimpleSpirit1::TX_DONE:
+            rf_handle_tx_end();
+            break;
+        case SimpleSpirit1::TX_ERR:
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d): TX_ERR!!!", __func__, __LINE__);
+            tr_debug("%s (%d): TX_ERR!!!", __func__, __LINE__);
 #endif
-	rf_handle_tx_err();
-	break;
+            rf_handle_tx_err();
+            break;
     }
 }
 
 static void rf_ack_loop(void) {
     static uint16_t buffer[2] = {
-	(FC_ACK_FRAME << MAC_FCF_FRAME_TYPE_SHIFT),
-	0x0
+            (FC_ACK_FRAME << MAC_FCF_FRAME_TYPE_SHIFT),
+            0x0
     };
 
     tr_debug("%s (%d)", __func__, __LINE__);
 
     do {
-	/* Wait for signal */
-	osEvent event = rf_ack_sender.signal_wait(0);
+        /* Wait for signal */
+        osEvent event = rf_ack_sender.signal_wait(0);
 
-	if(event.status != osEventSignal) {
+        if(event.status != osEventSignal) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+            tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	    continue;
-	}
+            continue;
+        }
 
-	int32_t signals = event.value.signals;
+        int32_t signals = event.value.signals;
 
 #ifdef HEAVY_TRACING
-    	tr_debug("%s (%d)", __func__, __LINE__);
+        tr_debug("%s (%d)", __func__, __LINE__);
 #endif
 
-    	/* Get Lock */
-	rf_if_lock();
+        /* Get Lock */
+        rf_if_lock();
 
-	if(signals & RF_SIG_ACK_NEEDED) {
+        if(signals & RF_SIG_ACK_NEEDED) {
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d)", __func__, __LINE__);
+            tr_debug("%s (%d)", __func__, __LINE__);
 #endif
 
-	    /* Prepare payload */
-	    uint8_t *ptr = (uint8_t*)&buffer[1];
-	    ptr[0] = rf_rx_sequence;   // Sequence number
+            /* Prepare payload */
+            uint8_t *ptr = (uint8_t*)&buffer[1];
+            ptr[0] = rf_rx_sequence;   // Sequence number
 
-	    /* Wait for device not receiving */
-	    while(rf_device->is_receiving()) {
+            /* Wait for device not receiving */
+            while(rf_device->is_receiving()) {
 #ifdef HEAVY_TRACING
-		tr_info("%s (%d)", __func__, __LINE__);
+                tr_info("%s (%d)", __func__, __LINE__);
 #endif
-		wait_us(10);
-	    }
+                wait_us(10);
+            }
 
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d), hdr=%x, nr=%x", __func__, __LINE__, buffer[0], ptr[0]);
+            tr_debug("%s (%d), hdr=%x, nr=%x", __func__, __LINE__, buffer[0], ptr[0]);
 #endif
 
-	    /* Set information that we have sent an ACK */
-	    rf_ack_sent = true;
+            /* Set information that we have sent an ACK */
+            rf_ack_sent = true;
 
-	    /*Send the packet*/
-	    rf_device->send((uint8_t*)buffer, 3);
+            /*Send the packet*/
+            rf_device->send((uint8_t*)buffer, 3);
 
 #ifdef HEAVY_TRACING
-	    tr_debug("%s (%d), hdr=%x, nr=%x", __func__, __LINE__, buffer[0], ptr[0]);
+            tr_debug("%s (%d), hdr=%x, nr=%x", __func__, __LINE__, buffer[0], ptr[0]);
 #endif
-	}
+        }
 
-	if(signals & RF_SIG_CB_TX_DONE) {
-	    device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, phy_status, 0, 0);
+        if(signals & RF_SIG_CB_TX_DONE) {
+            device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, phy_status, 0, 0);
 #ifdef HEAVY_TRACING
-    	tr_debug("%s (%d)", __func__, __LINE__);
+            tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	}
+        }
 
-	if(signals & RF_SIG_CB_RX_RCVD) {
-	    device_driver.phy_rx_cb(rf_rx_buf, rf_buffer_len, rf_sqi, rf_rssi, rf_radio_driver_id);
+        if(signals & RF_SIG_CB_RX_RCVD) {
+            device_driver.phy_rx_cb(rf_rx_buf, rf_buffer_len, rf_sqi, rf_rssi, rf_radio_driver_id);
 #ifdef HEAVY_TRACING
-    	tr_debug("%s (%d)", __func__, __LINE__);
+            tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-	}
+        }
 
-	/* Release Lock */
-	rf_if_unlock();
+        /* Release Lock */
+        rf_if_unlock();
 
 #ifdef HEAVY_TRACING
-	tr_debug("%s (%d)", __func__, __LINE__);
+        tr_debug("%s (%d)", __func__, __LINE__);
 #endif
     } while(true);
 }
@@ -670,29 +670,29 @@
 #endif
 
     if(rf_device == NULL) {
-	rf_device = &SimpleSpirit1::CreateInstance(_spi_mosi, _spi_miso, _spi_sclk, _dev_irq, _dev_cs, _dev_sdn, _brd_led);
-	rf_device->attach_irq_callback(rf_callback_func);
+        rf_device = &SimpleSpirit1::CreateInstance(_spi_mosi, _spi_miso, _spi_sclk, _dev_irq, _dev_cs, _dev_sdn, _brd_led);
+        rf_device->attach_irq_callback(rf_callback_func);
 
 #ifndef NDEBUG
-	ret =
+        ret =
 #endif
-	    rf_ack_sender.start(rf_ack_loop);
+                rf_ack_sender.start(rf_ack_loop);
 
 #ifndef NDEBUG
-	debug_if(!(ret == osOK), "\n\rassert failed in: %s (%d)\n\r", __func__, __LINE__);
+        debug_if(!(ret == osOK), "\n\rassert failed in: %s (%d)\n\r", __func__, __LINE__);
 #endif
     }
 }
 
 NanostackRfPhySpirit1::NanostackRfPhySpirit1(PinName spi_mosi, PinName spi_miso, PinName spi_sclk,
-					     PinName dev_irq,  PinName dev_cs, PinName dev_sdn, PinName brd_led) :
-    _spi_mosi(spi_mosi),
-    _spi_miso(spi_miso),
-    _spi_sclk(spi_sclk),
-    _dev_irq(dev_irq),
-    _dev_cs(dev_cs),
-    _dev_sdn(dev_sdn),
-    _brd_led(brd_led)
+                                             PinName dev_irq,  PinName dev_cs, PinName dev_sdn, PinName brd_led) :
+            _spi_mosi(spi_mosi),
+            _spi_miso(spi_miso),
+            _spi_sclk(spi_sclk),
+            _dev_irq(dev_irq),
+            _dev_cs(dev_cs),
+            _dev_sdn(dev_sdn),
+            _brd_led(brd_led)
 {
     /* Nothing to do */
     tr_debug("%s (%d)", __func__, __LINE__);
@@ -781,7 +781,7 @@
     rf_if_lock();
 
     if(rf_radio_driver_id >= 0) {
-	rf_get_mac_address(mac);
+        rf_get_mac_address(mac);
     } else {
         error("NanostackRfPhySpirit1 must be registered to read mac address");
     }
@@ -798,7 +798,7 @@
     rf_if_lock();
 
     if(rf_radio_driver_id < 0) {
-	rf_set_mac_address(mac);
+        rf_set_mac_address(mac);
     } else {
         error("NanostackRfPhySpirit1 cannot change mac address when running");
     }