⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 route.lst

📁 一个WSN的树状路由,对于那些学WSN路由方面的朋友应该有说帮助.
💻 LST
📖 第 1 页 / 共 5 页
字号:
   1               		.file	"route.c"
   2               		.arch atmega128
   3               	__SREG__ = 0x3f
   4               	__SP_H__ = 0x3e
   5               	__SP_L__ = 0x3d
   6               	__tmp_reg__ = 0
   7               	__zero_reg__ = 1
   8               		.global __do_copy_data
   9               		.global __do_clear_bss
  11               		.text
  12               	.Ltext0:
  93               	.global	RoutInit
  95               	RoutInit:
   1:route.c       **** /*
   2:route.c       **** ****************************************************************************
   3:route.c       **** *              宁波中科集成电路设计中心  版权所有 Copyright 2005
   4:route.c       **** *						http:\\www.nbicc.com
   5:route.c       **** *文件名:  route.h
   6:route.c       **** *程序员:  蒋文丰
   7:route.c       **** *主要内容  路由算法
   8:route.c       **** 
   9:route.c       **** *如有问题或BUG,请登录www.wsn.net.cn 提问或用邮件和作者联系
  10:route.c       **** ****************************************************************************
  11:route.c       **** */
  12:route.c       **** #include "type.h"
  13:route.c       **** #include "message.h"
  14:route.c       **** #include "global.h"
  15:route.c       **** #include "led.h"
  16:route.c       **** #include "timer.h"
  17:route.c       **** #include "os.h"
  18:route.c       **** #include "route.h"
  19:route.c       **** #include "dataqueue.h"
  20:route.c       **** #include "app.h"
  21:route.c       **** 
  22:route.c       **** static void routeBroadcast(void);
  23:route.c       **** static void UpdateTable(void);
  24:route.c       **** static void tablemanage(uint8_t outdegree,bool acceptable,uint8_t sourceaddr,uint8_t hopcount,uint1
  25:route.c       **** static uint8_t GetLocation(uint8_t addr);
  26:route.c       **** static result_t ReceiveInLocal(uint8_t sourceaddr);
  27:route.c       **** static result_t LocalAddrInReceive(OSMACMsgPtr receivemsg);
  28:route.c       **** static void InParentBool(uint8_t addr,uint8_t location);
  29:route.c       **** static void UpdateParentPool(void);
  30:route.c       **** static uint8_t GetLocalOutDegree(void);
  31:route.c       **** static uint8_t OutMapping(uint8_t i);
  32:route.c       **** 
  33:route.c       **** static uint8_t GetAnFreePlace(void);
  34:route.c       **** static uint8_t GetAnPlace(void);
  35:route.c       **** static uint8_t GetNoSym(void);
  36:route.c       **** static uint8_t GetEqualMetric(void);
  37:route.c       **** //static uint8_t GetLowMetric(void);
  38:route.c       **** 
  39:route.c       **** static void ChooseParent(void);
  40:route.c       **** static uint8_t GetPerfect(void);
  41:route.c       **** static bool HaveCircle(OSMACMsgPtr Msg,uint8_t nextAddr);
  42:route.c       **** //static void FreshReceiveTime(void);
  43:route.c       **** 
  44:route.c       **** enum {NOSYMMETRICAL,SYMMETRICAL,CHANGEABLE};
  45:route.c       **** uint8_t currentparent;
  46:route.c       **** static uint8_t parentpool[MAXNEIGHBOR]; //下一跳节点备选缓冲池
  47:route.c       **** static uint8_t EraserCount;//定期请空计数器
  48:route.c       **** static uint8_t metric; //节点层号
  49:route.c       **** static uint8_t freerecorder;//邻居表是否还有空间
  50:route.c       **** static uint16_t broadseqno; //路由包号
  51:route.c       **** static uint8_t  flag;//用于替换的时候从头或尾挑选,0为头1为尾
  52:route.c       **** static OSMACMsg  routeMsg;
  53:route.c       **** static OSMACMsgPtr routeMsgPtr;
  54:route.c       **** static uint8_t DegreeTable[6];//注意要配合sink节点的梯度为1的不变得限制
  55:route.c       **** /*************************************************************************
  56:route.c       **** *功能描述:初始化路由
  57:route.c       **** *参数说明:
  58:route.c       **** *返回值:
  59:route.c       **** *************************************************************************/
  60:route.c       **** void RoutInit(void){
  97               	.LM1:
  98               	/* prologue: frame size=0 */
  99               	/* prologue end (size=0) */
  61:route.c       ****     uint8_t i;
  62:route.c       **** 	broadseqno = 0;          //路由广播包的序列号
 101               	.LM2:
 102 0000 1092 0000 		sts (broadseqno)+1,__zero_reg__
 103 0004 1092 0000 		sts broadseqno,__zero_reg__
  63:route.c       ****     routeMsgPtr = &routeMsg; //获得路由广播包指针
 105               	.LM3:
 106 0008 80E0      		ldi r24,lo8(routeMsg)
 107 000a 90E0      		ldi r25,hi8(routeMsg)
 108 000c 9093 0000 		sts (routeMsgPtr)+1,r25
 109 0010 8093 0000 		sts routeMsgPtr,r24
  64:route.c       ****     currentparent = INVALID_NODE_ID; 
 111               	.LM4:
 112 0014 9FEF      		ldi r25,lo8(-1)
 113 0016 9093 0000 		sts currentparent,r25
  65:route.c       **** 	freerecorder = MAXNEIGHBOR;
 115               	.LM5:
 116 001a 8EE1      		ldi r24,lo8(30)
 117 001c 8093 0000 		sts freerecorder,r24
  66:route.c       **** 	flag = 0;
 119               	.LM6:
 120 0020 1092 0000 		sts flag,__zero_reg__
  67:route.c       **** 	EraserCount = 0;
 122               	.LM7:
 123 0024 1092 0000 		sts EraserCount,__zero_reg__
  68:route.c       ****     if (OS_LOCAL_ADDRESS == SINKNODE) {
 125               	.LM8:
 126 0028 8091 0000 		lds r24,OS_LOCAL_ADDRESS
 127 002c 8130      		cpi r24,lo8(1)
 128 002e 19F4      		brne .L2
  69:route.c       **** 		metric = 1; //SINK始终为1,不能改动
 130               	.LM9:
 131 0030 8093 0000 		sts metric,r24
 132 0034 02C0      		rjmp .L3
 133               	.L2:
  70:route.c       **** 	} else {
  71:route.c       **** 		metric = INVALID_NODE_ID; //其它节点初始为最大
 135               	.LM10:
 136 0036 9093 0000 		sts metric,r25
 137               	.L3:
 138 003a 9FEF      		ldi r25,lo8(-1)
 139 003c 22E0      		ldi r18,lo8(2)
 140 003e A0E0      		ldi r26,lo8(parentpool)
 141 0040 B0E0      		ldi r27,hi8(parentpool)
 142 0042 E0E0      		ldi r30,lo8(nbrTable)
 143 0044 F0E0      		ldi r31,hi8(nbrTable)
 144 0046 8DE1      		ldi r24,lo8(29)
 145               	.L7:
  72:route.c       **** 	} 
  73:route.c       **** 	//路由表初始化
  74:route.c       **** 	for (i = 0; i < MAXNEIGHBOR; i++) {
  75:route.c       **** 		nbrTable[i].addr = INVALID_NODE_ID;
 147               	.LM11:
 148 0048 9083      		st Z,r25
  76:route.c       **** 		nbrTable[i].state = CHANGEABLE;
 150               	.LM12:
 151 004a 2183      		std Z+1,r18
  77:route.c       **** 		nbrTable[i].metric = INVALID_NODE_ID;
 153               	.LM13:
 154 004c 9283      		std Z+2,r25
  78:route.c       **** 		nbrTable[i].broadseqno = 0;
 156               	.LM14:
 157 004e 1382      		std Z+3,__zero_reg__
 158 0050 1482      		std Z+4,__zero_reg__
  79:route.c       **** 		nbrTable[i].prebroadseqno = 0;
 160               	.LM15:
 161 0052 1582      		std Z+5,__zero_reg__
 162 0054 1682      		std Z+6,__zero_reg__
  80:route.c       **** 		nbrTable[i].sendfailtime = 0;
 164               	.LM16:
 165 0056 1782      		std Z+7,__zero_reg__
  81:route.c       **** 		///////
  82:route.c       **** 		nbrTable[i].outdegree = 0;
 167               	.LM17:
 168 0058 1086      		std Z+8,__zero_reg__
  83:route.c       **** 		parentpool[i] = INVALID_NODE_ID;
 170               	.LM18:
 171 005a 9D93      		st X+,r25
 173               	.LM19:
 174 005c 8150      		subi r24,lo8(-(-1))
 175 005e 3996      		adiw r30,9
 176 0060 87FF      		sbrs r24,7
 177 0062 F2CF      		rjmp .L7
  84:route.c       **** 	}
  85:route.c       **** 	/////////出度映射表
  86:route.c       **** 	DegreeTable[0] = 20;
 179               	.LM20:
 180 0064 84E1      		ldi r24,lo8(20)
 181 0066 8093 0000 		sts DegreeTable,r24
  87:route.c       **** 	DegreeTable[1] = 20;
 183               	.LM21:
 184 006a 8093 0000 		sts DegreeTable+1,r24
  88:route.c       **** 	DegreeTable[2] = 10;
 186               	.LM22:
 187 006e 8AE0      		ldi r24,lo8(10)
 188 0070 8093 0000 		sts DegreeTable+2,r24
  89:route.c       **** 	DegreeTable[3] = 5;
 190               	.LM23:
 191 0074 85E0      		ldi r24,lo8(5)
 192 0076 8093 0000 		sts DegreeTable+3,r24
  90:route.c       **** 	DegreeTable[4] = 3;
 194               	.LM24:
 195 007a 83E0      		ldi r24,lo8(3)
 196 007c 8093 0000 		sts DegreeTable+4,r24
  91:route.c       **** 	DegreeTable[5] = 2;
 198               	.LM25:
 199 0080 2093 0000 		sts DegreeTable+5,r18
 200               	/* epilogue: frame size=0 */
 201 0084 0895      		ret
 202               	/* epilogue end (size=1) */
 203               	/* function RoutInit size 67 (66) */
 207               	.global	routeTimerTask
 209               	routeTimerTask:
  92:route.c       **** }
  93:route.c       **** /*************************************************************************
  94:route.c       **** *功能描述:完成路由表的定期发送任务
  95:route.c       **** *参数说明:
  96:route.c       **** *返回值:
  97:route.c       **** *************************************************************************/
  98:route.c       **** void routeTimerTask(void) {
 211               	.LM26:
 212               	/* prologue: frame size=0 */
 213               	/* prologue end (size=0) */
  99:route.c       ****     EraserCount++;
 215               	.LM27:
 216 0086 8091 0000 		lds r24,EraserCount
 217 008a 8F5F      		subi r24,lo8(-(1))
 218 008c 8093 0000 		sts EraserCount,r24
 100:route.c       **** 	if(EraserCount >= 5) {
 220               	.LM28:
 221 0090 8530      		cpi r24,lo8(5)
 222 0092 50F1      		brlo .L11
 101:route.c       **** 	EraserCount = 0;
 224               	.LM29:
 225 0094 1092 0000 		sts EraserCount,__zero_reg__
 226 0098 62E0      		ldi r22,lo8(2)
 227 009a 4091 0000 		lds r20,freerecorder
 228 009e A0E0      		ldi r26,lo8(parentpool)
 229 00a0 B0E0      		ldi r27,hi8(parentpool)
 230 00a2 E0E0      		ldi r30,lo8(nbrTable)
 231 00a4 F0E0      		ldi r31,hi8(nbrTable)
 232 00a6 5DE1      		ldi r21,lo8(29)
 233               	.L18:
 234               	.LBB2:
 235               	.LBB3:
 102:route.c       **** 	UpdateTable(); //清理路由表
 103:route.c       **** 	}
 104:route.c       **** 	UpdateParentPool();//修改缓冲池的数据
 105:route.c       **** 	OSPostTask(routeBroadcast); //发送广播包
 106:route.c       **** } 
 107:route.c       **** 
 108:route.c       **** static void UpdateTable(void){
 109:route.c       ****    uint8_t i;
 110:route.c       ****    for (i = 0; i < MAXNEIGHBOR; i++) {
 111:route.c       ****         if( nbrTable[i].broadseqno == nbrTable[i].prebroadseqno ){ //在指定的时间中没有收到该节点的
 237               	.LM30:
 238 00a8 2381      		ldd r18,Z+3
 239 00aa 3481      		ldd r19,Z+4
 240 00ac 8581      		ldd r24,Z+5
 241 00ae 9681      		ldd r25,Z+6
 242 00b0 2817      		cp r18,r24
 243 00b2 3907      		cpc r19,r25
 244 00b4 81F4      		brne .L15
 112:route.c       **** 		nbrTable[i].addr = INVALID_NODE_ID;
 246               	.LM31:
 247 00b6 9FEF      		ldi r25,lo8(-1)
 248 00b8 9083      		st Z,r25
 113:route.c       **** 		if(nbrTable[i].state != CHANGEABLE ) freerecorder++;
 250               	.LM32:
 251 00ba 8181      		ldd r24,Z+1
 252 00bc 8230      		cpi r24,lo8(2)
 253 00be 09F0      		breq .L16
 254 00c0 4F5F      		subi r20,lo8(-(1))
 255               	.L16:
 114:route.c       **** 		nbrTable[i].state = CHANGEABLE;
 257               	.LM33:
 258 00c2 6183      		std Z+1,r22
 115:route.c       **** 		nbrTable[i].metric = INVALID_NODE_ID;
 260               	.LM34:
 261 00c4 9283      		std Z+2,r25
 116:route.c       **** 		nbrTable[i].broadseqno = 0;
 263               	.LM35:
 264 00c6 1382      		std Z+3,__zero_reg__
 265 00c8 1482      		std Z+4,__zero_reg__
 117:route.c       **** 		nbrTable[i].prebroadseqno = 0;
 267               	.LM36:
 268 00ca 1582      		std Z+5,__zero_reg__
 269 00cc 1682      		std Z+6,__zero_reg__
 118:route.c       **** 		nbrTable[i].sendfailtime = 0;
 271               	.LM37:
 272 00ce 1782      		std Z+7,__zero_reg__
 119:route.c       **** 		nbrTable[i].outdegree = 0;
 274               	.LM38:
 275 00d0 1086      		std Z+8,__zero_reg__
 120:route.c       **** 		parentpool[i] = INVALID_NODE_ID;
 277               	.LM39:
 278 00d2 9C93      		st X,r25
 279 00d4 02C0      		rjmp .L14
 280               	.L15:
 121:route.c       **** 		} else {
 122:route.c       **** 		nbrTable[i].prebroadseqno = nbrTable[i].broadseqno;
 282               	.LM40:
 283 00d6 2583      		std Z+5,r18
 284 00d8 3683      		std Z+6,r19
 285               	.L14:
 287               	.LM41:
 288 00da 5150      		subi r21,lo8(-(-1))
 289 00dc 3996      		adiw r30,9
 290 00de 1196      		adiw r26,1
 291 00e0 57FF      		sbrs r21,7
 292 00e2 E2CF      		rjmp .L18
 293 00e4 4093 0000 		sts freerecorder,r20
 294               	.L11:
 295 00e8 2091 0000 		lds r18,metric
 296 00ec 3FEF      		ldi r19,lo8(-1)
 297 00ee A0E0      		ldi r26,lo8(parentpool)
 298 00f0 B0E0      		ldi r27,hi8(parentpool)
 299 00f2 E0E0      		ldi r30,lo8(nbrTable)
 300 00f4 F0E0      		ldi r31,hi8(nbrTable)
 301 00f6 9DE1      		ldi r25,lo8(29)
 302               	.L25:
 303               	.LBE3:
 304               	.LBE2:
 305               	.LBB4:
 306               	.LBB5:
 123:route.c       **** 		}
 124:route.c       ****    }
 125:route.c       **** }
 126:route.c       **** 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -