Added support for reading MAC from the cc253x flash
We still use the primary location by default (Info Page) but this is now configurable. This change is useful for users who wish to specify their own MAC address. Since the Info Page is read-only, they need to be able to use the secondary location
This commit is contained in:
parent
29090a3dda
commit
e95f94a9a8
3 changed files with 48 additions and 6 deletions
|
@ -46,6 +46,7 @@
|
|||
|
||||
#include "net/packetbuf.h"
|
||||
#include "net/rime/rimestats.h"
|
||||
#include "net/rime/rimeaddr.h"
|
||||
#include "net/netstack.h"
|
||||
|
||||
#include <string.h>
|
||||
|
@ -142,13 +143,18 @@ cc2530_rf_power_set(uint8_t new_power)
|
|||
void
|
||||
cc2530_rf_set_addr(uint16_t pan)
|
||||
{
|
||||
#if RIMEADDR_SIZE==8 /* EXT_ADDR[7:0] is ignored when using short addresses */
|
||||
int i;
|
||||
for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) {
|
||||
((uint8_t *)&EXT_ADDR0)[i] = rimeaddr_node_addr.u8[RIMEADDR_SIZE - 1 - i];
|
||||
}
|
||||
#endif
|
||||
|
||||
PAN_ID0 = pan & 0xFF;
|
||||
PAN_ID1 = pan >> 8;
|
||||
|
||||
SHORT_ADDR0 = ((uint8_t *)&X_IEEE_ADDR)[0];
|
||||
SHORT_ADDR1 = ((uint8_t *)&X_IEEE_ADDR)[1];
|
||||
|
||||
memcpy(&EXT_ADDR0, &X_IEEE_ADDR, 8);
|
||||
SHORT_ADDR0 = rimeaddr_node_addr.u8[RIMEADDR_SIZE - 1];
|
||||
SHORT_ADDR1 = rimeaddr_node_addr.u8[RIMEADDR_SIZE - 2];
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Netstack API radio driver functions */
|
||||
|
|
|
@ -83,6 +83,15 @@
|
|||
*/
|
||||
#define NETSTACK_CONF_SHORTCUTS 1
|
||||
|
||||
/*
|
||||
* By default we read our MAC from the (read-only) Information Page (primary
|
||||
* location). In order to have a user-programmable mac, define this as 0 to
|
||||
* use the secondary location (addresses 0xFFE8 - 0xFFEF on the last flash page)
|
||||
*/
|
||||
#ifndef CC2530_CONF_MAC_FROM_PRIMARY
|
||||
#define CC2530_CONF_MAC_FROM_PRIMARY 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sensors
|
||||
* It is harmless to #define XYZ 1
|
||||
|
|
|
@ -80,23 +80,50 @@ fade(int l)
|
|||
static void
|
||||
set_rime_addr(void)
|
||||
{
|
||||
uint8_t *addr_long = NULL;
|
||||
uint16_t addr_short = 0;
|
||||
char i;
|
||||
|
||||
#if CC2530_CONF_MAC_FROM_PRIMARY
|
||||
__xdata unsigned char * macp = &X_IEEE_ADDR;
|
||||
#else
|
||||
__code unsigned char * macp = (__code unsigned char *) 0xFFE8;
|
||||
#endif
|
||||
|
||||
PUTSTRING("Rime is 0x");
|
||||
PUTHEX(sizeof(rimeaddr_t));
|
||||
PUTSTRING(" bytes long\n");
|
||||
|
||||
#if CC2530_CONF_MAC_FROM_PRIMARY
|
||||
PUTSTRING("Reading MAC from Info Page\n");
|
||||
#else
|
||||
PUTSTRING("Reading MAC from flash\n");
|
||||
|
||||
/*
|
||||
* The MAC is always stored in 0xFFE8 of the highest BANK of our flash. This
|
||||
* maps to address 0xFFF8 of our CODE segment, when this BANK is selected.
|
||||
* Load the bank, read 8 bytes starting at 0xFFE8 and restore last BANK.
|
||||
* Since we are called from main(), this MUST be BANK1 or something is very
|
||||
* wrong. This code can be used even without a bankable firmware.
|
||||
*/
|
||||
|
||||
/* Don't interrupt us to make sure no BANK switching happens while working */
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
/* Switch to the BANKn,
|
||||
* map CODE: 0x8000 - 0xFFFF to FLASH: 0xn8000 - 0xnFFFF */
|
||||
FMAP = CC2530_LAST_FLASH_BANK;
|
||||
#endif
|
||||
|
||||
for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) {
|
||||
rimeaddr_node_addr.u8[i] = *macp;
|
||||
macp++;
|
||||
}
|
||||
|
||||
#if !CC2530_CONF_MAC_FROM_PRIMARY
|
||||
/* Remap 0x8000 - 0xFFFF to BANK1 */
|
||||
FMAP = 1;
|
||||
ENABLE_INTERRUPTS();
|
||||
#endif
|
||||
|
||||
/* Now the address is stored MSB first */
|
||||
#if STARTUP_CONF_VERBOSE
|
||||
PUTSTRING("Rime configured with address ");
|
||||
|
|
Loading…
Reference in a new issue