Update for Atmel radio part II

modified:   cpu/avr/radio/rf230bb/halbb.c
	modified:   cpu/avr/radio/rf230bb/rf230bb.c
This commit is contained in:
Robert Olsson 2017-03-31 18:38:27 +02:00
parent 4425a67433
commit 093550ecbf
2 changed files with 65 additions and 31 deletions

View file

@ -81,10 +81,10 @@ extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
#include "at86rf230_registermap.h" #include "at86rf230_registermap.h"
#endif #endif
extern void get_last_rx_packet_timestamp(void);
/*============================ VARIABLES =====================================*/ /*============================ VARIABLES =====================================*/
volatile extern signed char rf230_last_rssi; volatile extern signed char rf230_last_rssi;
/*============================ CALLBACKS =====================================*/ /*============================ CALLBACKS =====================================*/
@ -668,7 +668,7 @@ ISR(TRX24_RX_START_vect)
#if !RF230_CONF_AUTOACK #if !RF230_CONF_AUTOACK
rf230_last_rssi = 3 * hal_subregister_read(SR_RSSI); rf230_last_rssi = 3 * hal_subregister_read(SR_RSSI);
#endif #endif
get_last_rx_packet_timestamp();
} }
/* PLL has locked, either from a transition out of TRX_OFF or a channel change while on */ /* PLL has locked, either from a transition out of TRX_OFF or a channel change while on */

View file

@ -146,6 +146,8 @@ uint8_t ack_pending,ack_seqnum;
#warning RF230 Untested Configuration! #warning RF230 Untested Configuration!
#endif #endif
rtimer_clock_t last_rx_packet_timestamp;
struct timestamp { struct timestamp {
uint16_t time; uint16_t time;
uint8_t authority_level; uint8_t authority_level;
@ -317,6 +319,44 @@ get_auto_ack(void)
return 0; return 0;
return 1; return 1;
} }
uint16_t
rf230_get_panid(void)
{
unsigned pan;
uint8_t byte;
byte = hal_register_read(RG_PAN_ID_1);
pan = byte;
byte = hal_register_read(RG_PAN_ID_0);
pan = (pan << 8) + byte;
return pan;
}
void
rf230_set_panid(uint16_t pan)
{
hal_register_write(RG_PAN_ID_1, (pan >> 8));
hal_register_write(RG_PAN_ID_0, (pan & 0xFF));
}
uint16_t
rf230_get_short_addr(void)
{
unsigned char a0, a1;
a0 = hal_register_read(RG_SHORT_ADDR_0);
a1 = hal_register_read(RG_SHORT_ADDR_1);
return (a1 << 8) | a0;
}
void
rf230_set_short_addr(uint16_t addr)
{
hal_register_write(RG_SHORT_ADDR_0, (addr & 0xFF));
hal_register_write(RG_SHORT_ADDR_1, (addr >> 8));
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static radio_result_t static radio_result_t
get_value(radio_param_t param, radio_value_t *value) get_value(radio_param_t param, radio_value_t *value)
@ -338,10 +378,10 @@ get_value(radio_param_t param, radio_value_t *value)
*value = (radio_value_t)rf230_get_channel(); *value = (radio_value_t)rf230_get_channel();
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_PAN_ID: case RADIO_PARAM_PAN_ID:
/* *value = get_pan_id(); */ *value = rf230_get_panid();
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_16BIT_ADDR: case RADIO_PARAM_16BIT_ADDR:
/* *value = get_short_addr(); */ *value = rf230_get_short_addr();
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_RX_MODE: case RADIO_PARAM_RX_MODE:
*value = 0; *value = 0;
@ -410,10 +450,11 @@ set_value(radio_param_t param, radio_value_t value)
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_PAN_ID: case RADIO_PARAM_PAN_ID:
/* set_pan_id(value & 0xffff); */ rf230_set_panid(value & 0xffff);
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_16BIT_ADDR: case RADIO_PARAM_16BIT_ADDR:
/* set_short_addr(value & 0xffff); */ rf230_set_short_addr(value & 0xffff);
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_RX_MODE: case RADIO_PARAM_RX_MODE:
@ -444,6 +485,14 @@ set_value(radio_param_t param, radio_value_t value)
static radio_result_t static radio_result_t
get_object(radio_param_t param, void *dest, size_t size) get_object(radio_param_t param, void *dest, size_t size)
{ {
if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) {
if(size != sizeof(rtimer_clock_t) || !dest) {
return RADIO_RESULT_INVALID_VALUE;
}
*(rtimer_clock_t *)dest = last_rx_packet_timestamp;
return RADIO_RESULT_OK;
}
return RADIO_RESULT_NOT_SUPPORTED; return RADIO_RESULT_NOT_SUPPORTED;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -1466,38 +1515,15 @@ rf230_listen_channel(uint8_t c)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
unsigned
rf230_get_panid(void)
{
unsigned pan;
uint8_t byte;
byte = hal_register_read(RG_PAN_ID_1);
pan = byte;
byte = hal_register_read(RG_PAN_ID_0);
pan = (pan << 8) + byte;
return pan;
}
void void
rf230_set_pan_addr(unsigned pan, rf230_set_pan_addr(unsigned pan,
unsigned addr, unsigned addr,
const uint8_t ieee_addr[8]) const uint8_t ieee_addr[8])
//rf230_set_pan_addr(uint16_t pan,uint16_t addr,uint8_t *ieee_addr)
{ {
PRINTF("rf230: PAN=%x Short Addr=%x\n",pan,addr); PRINTF("rf230: PAN=%x Short Addr=%x\n",pan,addr);
uint8_t abyte; rf230_set_panid(pan);
abyte = pan & 0xFF; rf230_set_short_addr(addr);
hal_register_write(RG_PAN_ID_0,abyte);
abyte = (pan >> 8*1) & 0xFF;
hal_register_write(RG_PAN_ID_1, abyte);
abyte = addr & 0xFF;
hal_register_write(RG_SHORT_ADDR_0, abyte);
abyte = (addr >> 8*1) & 0xFF;
hal_register_write(RG_SHORT_ADDR_1, abyte);
if (ieee_addr != NULL) { if (ieee_addr != NULL) {
PRINTF("MAC=%x",*ieee_addr); PRINTF("MAC=%x",*ieee_addr);
@ -1519,6 +1545,14 @@ rf230_set_pan_addr(unsigned pan,
PRINTF("\n"); PRINTF("\n");
} }
} }
/* From ISR context */
void
get_last_rx_packet_timestamp(void)
{
last_rx_packet_timestamp = RTIMER_NOW();
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* /*
* Interrupt leaves frame intact in FIFO. * Interrupt leaves frame intact in FIFO.