📄 node_id.c
字号:
// This file is part of MANTIS OS, Operating System// See http://mantis.cs.colorado.edu///// Copyright (C) 2003,2004,2005 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the mos license (see file LICENSE)/**************************************************************************//* File: node_id.c *//* Author Charles Gruenwald III : gruenwal@colorado.edu *//* Date: 04/14/2004 *//* *//* Description: this uses the eeprom to get and set the node id. *//**************************************************************************/#include "mos.h"#include "dev.h"#include "avr-eeprom.h"#ifdef ARCH_MSP430#include "telos-flash.h"#endifstatic uint16_t global_node_id = -1;void mos_node_id_init(void){#ifdef ARCH_AVR dev_open(DEV_AVR_EEPROM); dev_ioctl(DEV_AVR_EEPROM, DEV_SEEK, 0); dev_read(DEV_AVR_EEPROM, (uint8_t *)&global_node_id, sizeof(global_node_id)); dev_close(DEV_AVR_EEPROM);#elif defined(ARCH_MSP430) dev_open(DEV_TELOS_FLASH); dev_ioctl(DEV_TELOS_FLASH, DEV_SEEK, (uint32_t)0); dev_read(DEV_TELOS_FLASH, (uint8_t *)&global_node_id, sizeof(global_node_id)); dev_close(DEV_TELOS_FLASH); #else global_node_id = -1;#endif }uint16_t mos_node_id_get(void){ return global_node_id;}void mos_node_id_set (uint16_t new_node_id){ #ifdef ARCH_AVR dev_open(DEV_AVR_EEPROM); dev_ioctl(DEV_AVR_EEPROM, DEV_SEEK, 0); dev_write(DEV_AVR_EEPROM, (uint8_t *)&new_node_id, sizeof(new_node_id)); dev_close(DEV_AVR_EEPROM);#elif defined(ARCH_MSP430) dev_open(DEV_TELOS_FLASH); dev_mode(DEV_TELOS_FLASH, DEV_MODE_ON); dev_ioctl(DEV_TELOS_FLASH, TELOS_FLASH_SECT_ERASE, (uint32_t)0); dev_ioctl(DEV_TELOS_FLASH, DEV_SEEK, (uint32_t)0); dev_write(DEV_TELOS_FLASH, (uint8_t *)&new_node_id, sizeof(new_node_id)); dev_close(DEV_TELOS_FLASH); dev_mode(DEV_TELOS_FLASH, DEV_MODE_OFF); #endif global_node_id = new_node_id;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -