Improve the CC2538 extended RF API implementation
* Decouple 64-bit address from LINKADDR_SIZE * get and set object from/to the start/end of the src/dest buffer * We expect size == 8 (rather than size < 8) for both get_ and set_object. Error otherwise * The RF no longer sets parameters by itself. We let the platform do this, using the extended API.
This commit is contained in:
parent
49b6ad2af5
commit
08c884afa0
|
@ -872,13 +872,13 @@ get_object(radio_param_t param, void *dest, size_t size)
|
|||
int i;
|
||||
|
||||
if(param == RADIO_PARAM_64BIT_ADDR) {
|
||||
if(size < 8 || !dest || LINKADDR_SIZE != 8) {
|
||||
if(size != 8 || !dest) {
|
||||
return RADIO_RESULT_INVALID_VALUE;
|
||||
}
|
||||
|
||||
target = dest;
|
||||
for(i = 0; i < size; i++) {
|
||||
target[size - 1 - i] = ((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] & 0xFF;
|
||||
for(i = 0; i < 8; i++) {
|
||||
target[i] = ((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[7 - i] & 0xFF;
|
||||
}
|
||||
|
||||
return RADIO_RESULT_OK;
|
||||
|
@ -892,12 +892,12 @@ set_object(radio_param_t param, const void *src, size_t size)
|
|||
int i;
|
||||
|
||||
if(param == RADIO_PARAM_64BIT_ADDR) {
|
||||
if(size < 8 || !src || LINKADDR_SIZE != 8) {
|
||||
if(size != 8 || !src) {
|
||||
return RADIO_RESULT_INVALID_VALUE;
|
||||
}
|
||||
|
||||
for(i = 0; i < size; i++) {
|
||||
((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = ((uint8_t *)src)[size - 1 - i];
|
||||
for(i = 0; i < 8; i++) {
|
||||
((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = ((uint8_t *)src)[7 - i];
|
||||
}
|
||||
|
||||
return RADIO_RESULT_OK;
|
||||
|
@ -1022,23 +1022,4 @@ cc2538_rf_set_promiscous_mode(char p)
|
|||
set_frame_filtering(p);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
cc2538_rf_set_addr(uint16_t pan)
|
||||
{
|
||||
#if LINKADDR_SIZE == 8
|
||||
/* EXT_ADDR[7:0] is ignored when using short addresses */
|
||||
int i;
|
||||
|
||||
for(i = (LINKADDR_SIZE - 1); i >= 0; --i) {
|
||||
((uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] =
|
||||
linkaddr_node_addr.u8[LINKADDR_SIZE - 1 - i];
|
||||
}
|
||||
#endif
|
||||
|
||||
set_pan_id(pan);
|
||||
|
||||
REG(RFCORE_FFSM_SHORT_ADDR0) = linkaddr_node_addr.u8[LINKADDR_SIZE - 1];
|
||||
REG(RFCORE_FFSM_SHORT_ADDR1) = linkaddr_node_addr.u8[LINKADDR_SIZE - 2];
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -103,9 +103,18 @@ fade(unsigned char l)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_rime_addr()
|
||||
set_rf_params(void)
|
||||
{
|
||||
ieee_addr_cpy_to(&linkaddr_node_addr.u8[0], LINKADDR_SIZE);
|
||||
uint16_t short_addr;
|
||||
uint8_t ext_addr[8];
|
||||
|
||||
ieee_addr_cpy_to(ext_addr, 8);
|
||||
|
||||
short_addr = ext_addr[7];
|
||||
short_addr |= ext_addr[6] << 8;
|
||||
|
||||
/* Populate linkaddr_node_addr. Maintain endianness */
|
||||
memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], LINKADDR_SIZE);
|
||||
|
||||
#if STARTUP_CONF_VERBOSE
|
||||
{
|
||||
|
@ -118,6 +127,10 @@ set_rime_addr()
|
|||
}
|
||||
#endif
|
||||
|
||||
NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
|
||||
NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
|
||||
NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, CC2538_RF_CHANNEL);
|
||||
NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -185,9 +198,8 @@ main(void)
|
|||
process_start(&etimer_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
set_rime_addr();
|
||||
set_rf_params();
|
||||
netstack_init();
|
||||
cc2538_rf_set_addr(IEEE802154_PANID);
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
|
||||
|
|
Loading…
Reference in a new issue