1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #1934 from thomaseichinger/at86rf231_robustnes

drivers/at86rf231: improve deployment by default example
This commit is contained in:
Oleg Hahm 2014-11-05 19:59:11 +01:00
commit f777f23a89
5 changed files with 71 additions and 4 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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]);
}