Use the Z1 product ID as MAC/Node ID if no value is found in the XMEM
This commit is contained in:
parent
4cc1762851
commit
cceb97059c
|
@ -65,8 +65,16 @@ ifeq ($(HOST_OS),Darwin)
|
||||||
BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1
|
BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1
|
||||||
BSL_FILETYPE = -I
|
BSL_FILETYPE = -I
|
||||||
MOTES = $(shell $(MOTELIST) -c 2>&- | \
|
MOTES = $(shell $(MOTELIST) -c 2>&- | \
|
||||||
cut -f 2 -d ,)
|
cut -f 2 -d ,)
|
||||||
CMOTES=$(MOTES)
|
CMOTES=$(MOTES)
|
||||||
|
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
|
||||||
|
cut -f 1 -d , | tail -c5)
|
||||||
|
ifneq (,$(REFNUM))
|
||||||
|
# No device fo-und
|
||||||
|
ifeq (,$(findstring und, $(REFNUM)))
|
||||||
|
CFLAGS += -DSERIALNUM=$(REFNUM)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
# If we are not running under Mac, we assume Linux
|
# If we are not running under Mac, we assume Linux
|
||||||
|
@ -77,9 +85,17 @@ else
|
||||||
BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1
|
BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1
|
||||||
BSL_FILETYPE = -I
|
BSL_FILETYPE = -I
|
||||||
MOTES = $(shell $(MOTELIST) -c 2>&- | \
|
MOTES = $(shell $(MOTELIST) -c 2>&- | \
|
||||||
cut -f 2 -d , | \
|
cut -f 2 -d , | \
|
||||||
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
|
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
|
||||||
CMOTES=$(MOTES)
|
CMOTES=$(MOTES)
|
||||||
|
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
|
||||||
|
cut -f 1 -d , | tail -c5 )
|
||||||
|
ifneq (,$(REFNUM))
|
||||||
|
# No device fo-und
|
||||||
|
ifeq (,$(findstring und, $(REFNUM)))
|
||||||
|
CFLAGS += -DSERIALNUM=$(REFNUM)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "cc2420.h"
|
#include "cc2420.h"
|
||||||
|
@ -80,9 +80,9 @@ static struct timer mgt_timer;
|
||||||
#include "net/uip-fw-drv.h"
|
#include "net/uip-fw-drv.h"
|
||||||
#include "net/ipv4/uip-over-mesh.h"
|
#include "net/ipv4/uip-over-mesh.h"
|
||||||
static struct uip_fw_netif slipif =
|
static struct uip_fw_netif slipif =
|
||||||
{UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
|
{ UIP_FW_NETIF(192, 168, 1, 2, 255, 255, 255, 255, slip_send) };
|
||||||
static struct uip_fw_netif meshif =
|
static struct uip_fw_netif meshif =
|
||||||
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
|
{ UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
|
||||||
|
|
||||||
#endif /* WITH_UIP */
|
#endif /* WITH_UIP */
|
||||||
|
|
||||||
|
@ -119,7 +119,11 @@ force_float_inclusion()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void uip_log(char *msg) { puts(msg); }
|
void
|
||||||
|
uip_log(char *msg)
|
||||||
|
{
|
||||||
|
puts(msg);
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#if 0
|
#if 0
|
||||||
void
|
void
|
||||||
|
@ -157,7 +161,7 @@ set_rime_addr(void)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
print_processes(struct process * const processes[])
|
print_processes(struct process *const processes[])
|
||||||
{
|
{
|
||||||
/* const struct process * const * p = processes;*/
|
/* const struct process * const * p = processes;*/
|
||||||
printf("Starting");
|
printf("Starting");
|
||||||
|
@ -175,9 +179,9 @@ set_gateway(void)
|
||||||
if(!is_gateway) {
|
if(!is_gateway) {
|
||||||
leds_on(LEDS_RED);
|
leds_on(LEDS_RED);
|
||||||
printf("%d.%d: making myself the IP network gateway.\n\n",
|
printf("%d.%d: making myself the IP network gateway.\n\n",
|
||||||
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
|
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
|
||||||
printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n",
|
printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n",
|
||||||
uip_ipaddr_to_quad(&uip_hostaddr));
|
uip_ipaddr_to_quad(&uip_hostaddr));
|
||||||
uip_over_mesh_set_gateway(&linkaddr_node_addr);
|
uip_over_mesh_set_gateway(&linkaddr_node_addr);
|
||||||
uip_over_mesh_make_announced_gateway();
|
uip_over_mesh_make_announced_gateway();
|
||||||
is_gateway = 1;
|
is_gateway = 1;
|
||||||
|
@ -213,9 +217,16 @@ main(int argc, char **argv)
|
||||||
/* Restore node id if such has been stored in external mem */
|
/* Restore node id if such has been stored in external mem */
|
||||||
node_id_restore();
|
node_id_restore();
|
||||||
|
|
||||||
/* If no MAC address was burned, we use the node ID. */
|
/* If no MAC address was burned, we use the node id or the Z1 product ID */
|
||||||
if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
|
if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
|
||||||
node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
|
node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
|
||||||
|
|
||||||
|
#ifdef SERIALNUM
|
||||||
|
if(!node_id) {
|
||||||
|
PRINTF("Node id is not set, using Z1 product ID\n");
|
||||||
|
node_id = SERIALNUM;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
|
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
|
||||||
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
|
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
|
||||||
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
|
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
|
||||||
|
@ -231,7 +242,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
/* Overwrite node MAC if desired at compile time */
|
/* Overwrite node MAC if desired at compile time */
|
||||||
#ifdef MACID
|
#ifdef MACID
|
||||||
#warning "***** CHANGING DEFAULT MAC *****"
|
#warning "***** CHANGING DEFAULT MAC *****"
|
||||||
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
|
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
|
||||||
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
|
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
|
||||||
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
|
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
|
||||||
|
@ -254,7 +265,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
#endif /* IEEE_802154_MAC_ADDRESS */
|
#endif /* IEEE_802154_MAC_ADDRESS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize Contiki and our processes.
|
* Initialize Contiki and our processes.
|
||||||
*/
|
*/
|
||||||
process_init();
|
process_init();
|
||||||
|
@ -262,7 +273,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
ctimer_init();
|
ctimer_init();
|
||||||
|
|
||||||
init_platform();
|
init_platform();
|
||||||
|
|
||||||
set_rime_addr();
|
set_rime_addr();
|
||||||
|
|
||||||
|
@ -272,7 +283,7 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
uint8_t longaddr[8];
|
uint8_t longaddr[8];
|
||||||
uint16_t shortaddr;
|
uint16_t shortaddr;
|
||||||
|
|
||||||
shortaddr = (linkaddr_node_addr.u8[0] << 8) +
|
shortaddr = (linkaddr_node_addr.u8[0] << 8) +
|
||||||
linkaddr_node_addr.u8[1];
|
linkaddr_node_addr.u8[1];
|
||||||
memset(longaddr, 0, sizeof(longaddr));
|
memset(longaddr, 0, sizeof(longaddr));
|
||||||
|
@ -280,21 +291,23 @@ main(int argc, char **argv)
|
||||||
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
||||||
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
||||||
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
||||||
|
|
||||||
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
leds_off(LEDS_ALL);
|
leds_off(LEDS_ALL);
|
||||||
|
|
||||||
|
#ifdef SERIALNUM
|
||||||
|
PRINTF("Ref ID: %u\n", SERIALNUM);
|
||||||
|
#endif
|
||||||
PRINTF(CONTIKI_VERSION_STRING " started. ");
|
PRINTF(CONTIKI_VERSION_STRING " started. ");
|
||||||
|
|
||||||
if(node_id > 0) {
|
if(node_id) {
|
||||||
PRINTF("Node id is set to %u.\n", node_id);
|
PRINTF("Node id is set to %u.\n", node_id);
|
||||||
} else {
|
} else {
|
||||||
PRINTF("Node id is not set.\n");
|
PRINTF("Node id not set\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if WITH_UIP6
|
#if WITH_UIP6
|
||||||
memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
|
memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
|
||||||
/* Setup nullmac-like MAC for 802.15.4 */
|
/* Setup nullmac-like MAC for 802.15.4 */
|
||||||
|
@ -310,7 +323,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
|
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
|
||||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
|
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
|
||||||
NETSTACK_RDC.channel_check_interval()),
|
NETSTACK_RDC.channel_check_interval()),
|
||||||
CC2420_CONF_CHANNEL);
|
CC2420_CONF_CHANNEL);
|
||||||
|
|
||||||
|
@ -327,7 +340,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!UIP_CONF_IPV6_RPL) {
|
if(!UIP_CONF_IPV6_RPL) {
|
||||||
uip_ipaddr_t ipaddr;
|
uip_ipaddr_t ipaddr;
|
||||||
int i;
|
int i;
|
||||||
|
@ -351,7 +364,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
|
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
|
||||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
|
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
|
||||||
NETSTACK_RDC.channel_check_interval()),
|
NETSTACK_RDC.channel_check_interval()),
|
||||||
CC2420_CONF_CHANNEL);
|
CC2420_CONF_CHANNEL);
|
||||||
#endif /* WITH_UIP6 */
|
#endif /* WITH_UIP6 */
|
||||||
|
@ -370,7 +383,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
#if WITH_UIP
|
#if WITH_UIP
|
||||||
process_start(&tcpip_process, NULL);
|
process_start(&tcpip_process, NULL);
|
||||||
process_start(&uip_fw_process, NULL); /* Start IP output */
|
process_start(&uip_fw_process, NULL); /* Start IP output */
|
||||||
process_start(&slip_process, NULL);
|
process_start(&slip_process, NULL);
|
||||||
|
|
||||||
slip_set_input_callback(set_gateway);
|
slip_set_input_callback(set_gateway);
|
||||||
|
@ -380,9 +393,9 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
uip_init();
|
uip_init();
|
||||||
|
|
||||||
uip_ipaddr(&hostaddr, 172,16,
|
uip_ipaddr(&hostaddr, 172, 16,
|
||||||
linkaddr_node_addr.u8[0],linkaddr_node_addr.u8[1]);
|
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
|
||||||
uip_ipaddr(&netmask, 255,255,0,0);
|
uip_ipaddr(&netmask, 255, 255, 0, 0);
|
||||||
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
|
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
|
||||||
|
|
||||||
uip_sethostaddr(&hostaddr);
|
uip_sethostaddr(&hostaddr);
|
||||||
|
@ -393,7 +406,7 @@ main(int argc, char **argv)
|
||||||
uip_fw_default(&meshif);
|
uip_fw_default(&meshif);
|
||||||
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
|
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
|
||||||
printf("uIP started with IP address %d.%d.%d.%d\n",
|
printf("uIP started with IP address %d.%d.%d.%d\n",
|
||||||
uip_ipaddr_to_quad(&hostaddr));
|
uip_ipaddr_to_quad(&hostaddr));
|
||||||
}
|
}
|
||||||
#endif /* WITH_UIP */
|
#endif /* WITH_UIP */
|
||||||
|
|
||||||
|
@ -422,18 +435,18 @@ main(int argc, char **argv)
|
||||||
/*
|
/*
|
||||||
* Idle processing.
|
* Idle processing.
|
||||||
*/
|
*/
|
||||||
int s = splhigh(); /* Disable interrupts. */
|
int s = splhigh(); /* Disable interrupts. */
|
||||||
/* uart0_active is for avoiding LPM3 when still sending or receiving */
|
/* uart0_active is for avoiding LPM3 when still sending or receiving */
|
||||||
if(process_nevents() != 0 || uart0_active()) {
|
if(process_nevents() != 0 || uart0_active()) {
|
||||||
splx(s); /* Re-enable interrupts. */
|
splx(s); /* Re-enable interrupts. */
|
||||||
} else {
|
} else {
|
||||||
static unsigned long irq_energest = 0;
|
static unsigned long irq_energest = 0;
|
||||||
|
|
||||||
#if DCOSYNCH_CONF_ENABLED
|
#if DCOSYNCH_CONF_ENABLED
|
||||||
/* before going down to sleep possibly do some management */
|
/* before going down to sleep possibly do some management */
|
||||||
if (timer_expired(&mgt_timer)) {
|
if(timer_expired(&mgt_timer)) {
|
||||||
timer_reset(&mgt_timer);
|
timer_reset(&mgt_timer);
|
||||||
msp430_sync_dco();
|
msp430_sync_dco();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -441,19 +454,19 @@ main(int argc, char **argv)
|
||||||
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
||||||
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
||||||
/* We only want to measure the processing done in IRQs when we
|
/* We only want to measure the processing done in IRQs when we
|
||||||
are asleep, so we discard the processing time done when we
|
are asleep, so we discard the processing time done when we
|
||||||
were awake. */
|
were awake. */
|
||||||
energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
|
energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
|
||||||
watchdog_stop();
|
watchdog_stop();
|
||||||
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
||||||
statement will block
|
statement will block
|
||||||
until the CPU is
|
until the CPU is
|
||||||
woken up by an
|
woken up by an
|
||||||
interrupt that sets
|
interrupt that sets
|
||||||
the wake up flag. */
|
the wake up flag. */
|
||||||
|
|
||||||
/* We get the current processing time for interrupts that was
|
/* We get the current processing time for interrupts that was
|
||||||
done during the LPM and store it for next time around. */
|
done during the LPM and store it for next time around. */
|
||||||
dint();
|
dint();
|
||||||
irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
|
irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
|
||||||
eint();
|
eint();
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include "dev/xmem.h"
|
#include "dev/xmem.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
unsigned short node_id = 0;
|
unsigned short node_id = 0;
|
||||||
unsigned char node_mac[8];
|
unsigned char node_mac[8];
|
||||||
|
|
||||||
|
@ -65,11 +64,11 @@ void
|
||||||
node_id_burn(unsigned short id)
|
node_id_burn(unsigned short id)
|
||||||
{
|
{
|
||||||
unsigned char buf[12];
|
unsigned char buf[12];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
buf[0] = 0xad;
|
buf[0] = 0xad;
|
||||||
buf[1] = 0xde;
|
buf[1] = 0xde;
|
||||||
buf[2] = id >> 8;
|
buf[2] = id >> 8;
|
||||||
buf[3] = id & 0xff;
|
buf[3] = id & 0xff;
|
||||||
memcpy(&buf[4], node_mac, 8);
|
|
||||||
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
|
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
|
||||||
xmem_pwrite(buf, 12, NODE_ID_XMEM_OFFSET);
|
xmem_pwrite(buf, 12, NODE_ID_XMEM_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue