From 9bdd4cebbc322d96aa1afd6f1b3c919e3d6eba92 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 4 Nov 2014 15:10:18 +0100 Subject: [PATCH 1/5] drivers/at86rf231: change to PLL_ON to change address --- drivers/at86rf231/at86rf231.c | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/at86rf231/at86rf231.c b/drivers/at86rf231/at86rf231.c index 13a6e6d7ed..bc5b5a1fa3 100644 --- a/drivers/at86rf231/at86rf231.c +++ b/drivers/at86rf231/at86rf231.c @@ -250,9 +250,37 @@ radio_address_t at86rf231_set_address(radio_address_t address) { radio_address = address; + uint8_t old_state = at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS; + + /* Go to state PLL_ON */ + at86rf231_reg_write(AT86RF231_REG__TRX_STATE, AT86RF231_TRX_STATE__PLL_ON); + + /* wait until it is on PLL_ON state */ + do { + int max_wait = _MAX_RETRIES; + if (!--max_wait) { + DEBUG("at86rf231 : ERROR : could not enter PLL_ON mode\n"); + break; + } + } while ((at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS) + != AT86RF231_TRX_STATUS__PLL_ON); + at86rf231_reg_write(AT86RF231_REG__SHORT_ADDR_0, (uint8_t)(0x00FF & radio_address)); at86rf231_reg_write(AT86RF231_REG__SHORT_ADDR_1, (uint8_t)(radio_address >> 8)); + /* Go to state old state */ + at86rf231_reg_write(AT86RF231_REG__TRX_STATE, old_state); + + /* wait until it is on old state */ + do { + int max_wait = _MAX_RETRIES; + if (!--max_wait) { + DEBUG("at86rf231 : ERROR : could not enter old state %x\n", old_state); + break; + } + } while ((at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS) + != old_state); + return radio_address; } @@ -265,6 +293,21 @@ uint64_t at86rf231_set_address_long(uint64_t address) { radio_address_long = address; + uint8_t old_state = at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS; + + /* Go to state PLL_ON */ + at86rf231_reg_write(AT86RF231_REG__TRX_STATE, AT86RF231_TRX_STATE__PLL_ON); + + /* wait until it is on PLL_ON state */ + do { + int max_wait = _MAX_RETRIES; + if (!--max_wait) { + DEBUG("at86rf231 : ERROR : could not enter PLL_ON mode\n"); + break; + } + } while ((at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS) + != AT86RF231_TRX_STATUS__PLL_ON); + at86rf231_reg_write(AT86RF231_REG__IEEE_ADDR_0, (uint8_t)(0x00000000000000FF & radio_address_long)); at86rf231_reg_write(AT86RF231_REG__IEEE_ADDR_1, (uint8_t)(0x000000000000FF00 & radio_address_long >> 8)); at86rf231_reg_write(AT86RF231_REG__IEEE_ADDR_2, (uint8_t)(0x0000000000FF0000 & radio_address_long >> 16)); @@ -274,6 +317,19 @@ uint64_t at86rf231_set_address_long(uint64_t address) at86rf231_reg_write(AT86RF231_REG__IEEE_ADDR_6, (uint8_t)(0x00FF000000000000 & radio_address_long >> 48)); at86rf231_reg_write(AT86RF231_REG__IEEE_ADDR_7, (uint8_t)(radio_address_long >> 56)); + /* Go to state old state */ + at86rf231_reg_write(AT86RF231_REG__TRX_STATE, old_state); + + /* wait until it is on old state */ + do { + int max_wait = _MAX_RETRIES; + if (!--max_wait) { + DEBUG("at86rf231 : ERROR : could not enter old state %x\n", old_state); + break; + } + } while ((at86rf231_get_status() & AT86RF231_TRX_STATUS_MASK__TRX_STATUS) + != old_state); + return radio_address_long; } From 5b8231737be2b82f262b8b9a8dc69ecbe8a6a40b Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 4 Nov 2014 15:11:54 +0100 Subject: [PATCH 2/5] drivers/at86rf231: print raw packet when DEBUG_ENABLED --- drivers/at86rf231/at86rf231_rx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/at86rf231/at86rf231_rx.c b/drivers/at86rf231/at86rf231_rx.c index 11559cd886..8641de9bf7 100644 --- a/drivers/at86rf231/at86rf231_rx.c +++ b/drivers/at86rf231/at86rf231_rx.c @@ -65,6 +65,14 @@ void at86rf231_rx_handler(void) return; } +#ifdef DEBUG_ENABLED + DEBUG("pkg: "); + for (int i = 1; i < at86rf231_rx_buffer[rx_buffer_next].length; i++) { + DEBUG("%x ", buf[i]); + } + DEBUG("\n"); +#endif + /* read buffer into ieee802154_frame */ ieee802154_frame_read(&buf[1], &at86rf231_rx_buffer[rx_buffer_next].frame, at86rf231_rx_buffer[rx_buffer_next].length); From c16c2509e8daef566d3cab1ba2a699a243210c5b Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 4 Nov 2014 15:12:45 +0100 Subject: [PATCH 3/5] drivers/at86rf231: frame_type has to be set by upper layers --- drivers/at86rf231/at86rf231_tx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/at86rf231/at86rf231_tx.c b/drivers/at86rf231/at86rf231_tx.c index af9a931a44..855880c818 100644 --- a/drivers/at86rf231/at86rf231_tx.c +++ b/drivers/at86rf231/at86rf231_tx.c @@ -199,7 +199,6 @@ int16_t at86rf231_load(at86rf231_packet_t *packet) { // Set missing frame information packet->frame.fcf.frame_ver = 0; - packet->frame.fcf.frame_type = 0x1; packet->frame.src_pan_id = at86rf231_get_pan(); From 6a7cee294fb68f1f81ea40e00b3f92ce8e01bf80 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 4 Nov 2014 15:13:47 +0100 Subject: [PATCH 4/5] examples/default: print 16bit addresses --- examples/default/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/default/main.c b/examples/default/main.c index 6b464b5a7d..311a57605b 100644 --- a/examples/default/main.c +++ b/examples/default/main.c @@ -75,8 +75,8 @@ void *radio(void *arg) p = (ieee802154_packet_t*) m.content.ptr; printf("Got radio packet:\n"); printf("\tLength:\t%u\n", p->length); - printf("\tSrc:\t%u\n", p->frame.src_addr[0]); - printf("\tDst:\t%u\n", p->frame.dest_addr[0]); + printf("\tSrc:\t%u\n", (p->frame.src_addr[0])|(p->frame.src_addr[1]<<8)); + printf("\tDst:\t%u\n", (p->frame.dest_addr[0])|(p->frame.dest_addr[1]<<8)); printf("\tLQI:\t%u\n", p->lqi); printf("\tRSSI:\t%u\n", p->rssi); From 660f24405e770bb9b97b6a5d939bf52c3ed0ca49 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 4 Nov 2014 15:14:37 +0100 Subject: [PATCH 5/5] shell/transceiver: set 16 bit addresses and frame type --- sys/shell/commands/sc_transceiver.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/shell/commands/sc_transceiver.c b/sys/shell/commands/sc_transceiver.c index 16b1b264eb..5fa95f534f 100644 --- a/sys/shell/commands/sc_transceiver.c +++ b/sys/shell/commands/sc_transceiver.c @@ -225,6 +225,7 @@ void _transceiver_send_handler(int argc, char **argv) #if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X ieee802154_packet_t p; + uint16_t short_addr; #else radio_packet_t p; #endif @@ -241,9 +242,12 @@ void _transceiver_send_handler(int argc, char **argv) memset(&p, 0, sizeof(ieee802154_packet_t)); p.frame.payload = (uint8_t*) text_msg; p.frame.payload_len = strlen(text_msg) + 1; + p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME; p.frame.fcf.dest_addr_m = IEEE_802154_SHORT_ADDR_M; p.frame.fcf.src_addr_m = IEEE_802154_SHORT_ADDR_M; - p.frame.dest_addr[1] = atoi(argv[1]); + short_addr = atoi(argv[1]); + p.frame.dest_addr[1] = (short_addr&0xff); + p.frame.dest_addr[0] = (short_addr>>8); if (argc == 4) { p.frame.dest_pan_id = atoi(argv[3]); }