Node ID is stored in external flash and restored on bootup
This commit is contained in:
parent
3bee71ad81
commit
91be7cebc4
2 changed files with 22 additions and 5 deletions
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)$Id: contiki-z1-main.c,v 1.3 2010/08/26 16:01:20 joxe Exp $
|
* @(#)$Id: contiki-z1-main.c,v 1.4 2010/08/26 22:08:11 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -231,7 +231,7 @@ 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 */
|
||||||
//Enric node_id_restore();
|
node_id_restore();
|
||||||
|
|
||||||
|
|
||||||
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
|
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: node-id.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
|
* $Id: node-id.c,v 1.2 2010/08/26 22:08:11 nifi Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +40,8 @@
|
||||||
|
|
||||||
#include "node-id.h"
|
#include "node-id.h"
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
|
#include "dev/xmem.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
unsigned short node_id = 0;
|
unsigned short node_id = 0;
|
||||||
|
@ -49,12 +51,27 @@ unsigned char node_mac[8];
|
||||||
void
|
void
|
||||||
node_id_restore(void)
|
node_id_restore(void)
|
||||||
{
|
{
|
||||||
//TODO
|
unsigned char buf[12];
|
||||||
|
xmem_pread(buf, 12, NODE_ID_XMEM_OFFSET);
|
||||||
|
if(buf[0] == 0xad &&
|
||||||
|
buf[1] == 0xde) {
|
||||||
|
node_id = (buf[2] << 8) | buf[3];
|
||||||
|
memcpy(node_mac, &buf[4], 8);
|
||||||
|
} else {
|
||||||
|
node_id = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
node_id_burn(unsigned short id)
|
node_id_burn(unsigned short id)
|
||||||
{
|
{
|
||||||
//TODO
|
unsigned char buf[12];
|
||||||
|
buf[0] = 0xad;
|
||||||
|
buf[1] = 0xde;
|
||||||
|
buf[2] = id >> 8;
|
||||||
|
buf[3] = id & 0xff;
|
||||||
|
memcpy(&buf[4], node_mac, 8);
|
||||||
|
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
|
||||||
|
xmem_pwrite(buf, 12, NODE_ID_XMEM_OFFSET);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue