nodeapp.s
来自「mega128平台下」· S 代码 · 共 788 行
S
788 行
.module nodeapp.c
.area data(ram, con, rel)
_LOCAL_ID::
.blkb 1
.area idata
.byte 2
.area data(ram, con, rel)
_LOCAL_GID::
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
_slot_Tcluster::
.blkb 1
.area idata
.byte 244
.area data(ram, con, rel)
_SYNC_FLAG::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
_ALARM_TMP::
.blkb 1
.area idata
.byte 66
.area data(ram, con, rel)
_CYCLE_TIME::
.blkb 1
.area idata
.byte 224
.area data(ram, con, rel)
_OLD_CYCLE_TIME::
.blkb 1
.area idata
.byte 224
.area data(ram, con, rel)
_NEW_CYCLE_TIME::
.blkb 1
.area idata
.byte 184
.area data(ram, con, rel)
_T::
.blkb 2
.area idata
.word 24000
.area data(ram, con, rel)
_node_num::
.blkb 1
.area idata
.byte 4
.area data(ram, con, rel)
_timeout::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
_send_seq::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
_count::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
_sync_count::
.blkb 2
.area idata
.word 30
.area data(ram, con, rel)
.area text(rom, con, rel)
.even
_param_init::
L2:
.dbline 0 ; func end
ret
; data -> R18,R19
; addr -> R16,R17
.even
_eeprom_write::
; #include<iom128v.h>
; #include <macros.h>
; #include "app.h"
; #include "../api/timer.h"
; #include "stdio.h"
; extern int get_tmp(void);
;
; COMM_MSG cluster_msg;
; COMM_MSG node_data;
; char timeout=0;
; char send_seq=0;
; int count =0;
; unsigned char T_p_node;
; unsigned int sync_count = SYNC_COUNT;
; unsigned char sleep_flag;
; /********
; * param init
; */
;
; void param_init()
; {
; /* LOCAL_ID = m->data[0];
; LOCAL_GID = m->data[1];
; T=m->data[2];
; node_num =m->data[3];
; ALARM_TMP = m->data[4];
; */
; }
;
;
; /*******************************************
; * eeprom 存储
; */
;
; void eeprom_write(unsigned int addr,unsigned int data)
; {
L4:
L5:
; while(EECR&(1<<EEWE));
sbic 0x1c,1
rjmp L4
; EEAR=addr;
out 0x1f,R17
out 0x1e,R16
; EEDR=data;
out 0x1d,R18
; EECR|=(1<<EEMWE);
sbi 0x1c,2
; EECR|=(1<<EEWE);
sbi 0x1c,1
L3:
.dbline 0 ; func end
ret
; addr -> R16,R17
.even
_eeprom_read::
; }
;
; unsigned char eeprom_read(unsigned int addr)
; {
L8:
L9:
; while(EECR&(1<<EEWE));
sbic 0x1c,1
rjmp L8
; EEAR=addr;
out 0x1f,R17
out 0x1e,R16
; EECR|=(1<<EERE);
sbi 0x1c,0
; return EEDR;
in R16,0x1d
L7:
.dbline 0 ; func end
ret
.even
_T1_timeout::
; }
;
; /******************************************/
;
;
; void T1_timeout(){
;
; led1Toggle();
xcall _led1Toggle
; //sleep_flag =1;
; start_T0(1,T);
lds R18,_T
lds R19,_T+1
ldi R16,1
xcall _start_T0
; CC1100_sleep();
xcall _CC1100_sleep
L11:
.dbline 0 ; func end
ret
.even
_CC1100_sendDone::
; //sleep_flag =1;
; }
;
; unsigned char CC1100_sendDone()
; {
; //led1Toggle();
; //printf("count %d\n",count);
; send_seq ++;
lds R24,_send_seq
subi R24,255 ; addi 1
sts _send_seq,R24
L12:
.dbline 0 ; func end
ret
; source_id -> R12
; seqNO -> R10
; sreg -> R22
; type -> R22
; msg -> R22,R23
; m -> R20,R21
; node_id -> R10,R11
.even
_CC1100_receive::
xcall push_gset4
; }
;
; extern void mcu_sleep();
; extern unsigned char rxBuffer[32];
; void CC1100_receive()
; {
; char type,seqNO;
; unsigned int node_id;
; unsigned char source_id;
; unsigned char *msg =(&rxBuffer[0]);
ldi R22,<_rxBuffer
ldi R23,>_rxBuffer
; unsigned char sreg;
;
;
;
; COMM_MSG *m = (COMM_MSG *)(msg);
movw R20,R22
; type = m->type;
movw R30,R20
ldd R22,z+5
; node_id = m->DA;
movw R30,R20
ldd R10,z+3
ldd R11,z+4
; if ((node_id == IP)||( node_id ==0xffff) ||(node_id == CLUSTER_IP))
lds R2,_LOCAL_GID
clr R3
mov R3,R2
clr R2
lds R4,_LOCAL_ID
clr R5
movw R6,R2
add R6,R4
adc R7,R5
cp R10,R6
cpc R11,R7
breq L17
movw R24,R10
cpi R24,255
ldi R30,255
cpc R25,R30
breq L17
cp R24,R2
cpc R25,R3
breq X2
xjmp L14
X2:
L17:
; {
; switch(type)
clr R23
cpi R22,29
ldi R30,0
cpc R23,R30
brne X3
xjmp L31
X3:
ldi R24,29
ldi R25,0
cp R24,R22
cpc R25,R23
brlt L33
L32:
cpi R22,2
ldi R30,0
cpc R23,R30
breq L21
cpi R22,4
ldi R30,0
cpc R23,R30
breq L24
cpi R22,5
ldi R30,0
cpc R23,R30
brne X4
xjmp L19
X4:
xjmp L19
L33:
cpi R22,50
ldi R30,0
cpc R23,R30
breq L26
xjmp L19
X0:
; {
L21:
; case CLUSTER_NODE_SYNC:
; {
; sreg = SREG;
in R22,0x3f
; CLI();
cli
; if (!SYNC_FLAG) //下一次重新同步前将syncflag置为0
lds R2,_SYNC_FLAG
tst R2
brne L22
; {
; led0Toggle();
xcall _led0Toggle
; SYNC_FLAG =1;
ldi R24,1
sts _SYNC_FLAG,R24
; seqNO = m->data[0];
movw R30,R20
ldd R10,z+6
; start_T1(0,(LOCAL_ID *3000));
lds R18,_LOCAL_ID
clr R19
ldi R16,3000
ldi R17,11
xcall empy16s
movw R18,R16
clr R16
xcall _start_T1
; //start_T1(0,((LOCAL_ID * T_p_node) - (seqNO*slot_Tcluster)));
; CC1100_sleep();
xcall _CC1100_sleep
; //start_T1(0,(LOCAL_ID *3000));
; }
L22:
; SREG = sreg;
out 0x3f,R22
; break;
xjmp L19
L24:
; }
;
; case CLUSTER_NODE_ACK:
; {
; led0Toggle();
xcall _led0Toggle
; //printf("ack %d\n",m->data[0]);
; stop_T3();
xcall _stop_T3
; CC1100_sleep();
xcall _CC1100_sleep
; send_seq = 1;
ldi R24,1
sts _send_seq,R24
; //post(mcu_sleep);
; break;
xjmp L19
X1:
; }
; case NODE_CHECK_CMD:
; {
; break;
L26:
; }
; case NODE_DATA:
; {
; sreg = SREG;
in R22,0x3f
; CLI();
cli
; if (!SYNC_FLAG) //下一次重新同步前将syncflag置为0
lds R2,_SYNC_FLAG
tst R2
breq X5
xjmp L27
X5:
; {
; SYNC_FLAG =1;
ldi R24,1
sts _SYNC_FLAG,R24
; seqNO = m->data[0];
movw R30,R20
ldd R10,z+6
; source_id = m->ID;
movw R30,R20
ldd R12,z+1
; if (source_id >LOCAL_ID)
lds R2,_LOCAL_ID
cp R2,R12
brsh L29
; start_T1(0,(T -((source_id-LOCAL_ID) * T_p_node + seqNO*RE_SEND_DELAY)));
mov R3,R12
sub R3,R2
lds R2,_T_p_node
mul R3,R2
movw R2,R0
mov R18,R10
clr R19
ldi R16,500
ldi R17,1
xcall empy16s
add R2,R16
adc R3,R17
lds R18,_T
lds R19,_T+1
sub R18,R2
sbc R19,R3
clr R16
xcall _start_T1
xjmp L30
L29:
; else
; start_T1(0,((LOCAL_ID - source_id) * T_p_node - seqNO*RE_SEND_DELAY));
lds R2,_LOCAL_ID
sub R2,R12
lds R3,_T_p_node
mul R2,R3
movw R2,R0
mov R18,R10
clr R19
ldi R16,500
ldi R17,1
xcall empy16s
sub R2,R16
sbc R3,R17
movw R18,R2
clr R16
xcall _start_T1
L30:
; CC1100_sleep();
xcall _CC1100_sleep
; }
L27:
; SREG = sreg;
out 0x3f,R22
; break;
xjmp L19
L31:
; }
; case SINK_INIT_NODE:
; {
; LOCAL_ID = m->data[0];
movw R30,R20
ldd R2,z+6
sts _LOCAL_ID,R2
; eeprom_write(0,LOCAL_ID);
mov R18,R2
clr R19
clr R16
clr R17
xcall _eeprom_write
; LOCAL_GID = m->data[1];
movw R30,R20
ldd R2,z+7
sts _LOCAL_GID,R2
; eeprom_write(0,LOCAL_GID);
mov R18,R2
clr R19
clr R16
clr R17
xcall _eeprom_write
; T=m->data[2];
movw R30,R20
ldd R2,z+8
clr R3
sts _T+1,R3
sts _T,R2
; eeprom_write(0,T);
movw R18,R2
clr R16
clr R17
xcall _eeprom_write
; node_num =m->data[3];
movw R30,R20
ldd R2,z+9
sts _node_num,R2
; eeprom_write(0,node_num);
mov R18,R2
clr R19
clr R16
clr R17
xcall _eeprom_write
; ALARM_TMP = m->data[4];
movw R30,R20
ldd R2,z+10
sts _ALARM_TMP,R2
; eeprom_write(0,ALARM_TMP);
mov R18,R2
clr R19
clr R16
clr R17
xcall _eeprom_write
; // work_channel = m->data[5];//根据节点组号判断就可以
; // 存储配置信息
; break;
; }
;
; default :break;
L19:
; } //end switch
; }//end if
L14:
L13:
xcall pop_gset4
.dbline 0 ; func end
ret
.even
_resend::
; }
;
; /*
;
; void T2_timeout(){
; unsigned char tmp,bat,crc;
; //led0Toggle();
; tmp = 0x38;//get_tmp();
; bat = get_battle();
; node_data.len = 12;
; node_data.ID = LOCAL_ID;
; node_data.GID = LOCAL_GID;
; node_data.type = NODE_DATA;
; node_data.data[0] = send_seq;
; node_data.data[1] = (tmp>>8)&0xff;
; node_data.data[2] = tmp&0xff;
; node_data.data[3] = (bat>>8)&0xff;
; node_data.data[4] = bat&0xff;
; node_data.crc = 0xffff;
; //切换通道
; CC1100_send((unsigned char*)&node_data,node_data.len+1);
; //切换通道
; }
; */
; /*
; void cllect_send()
; {
; unsigned char tmp,bat,crc;
; tmp = 0x38;//get_tmp();
; if (tmp>ALARM_TMP)
; start_T2(0,300000);//CYCLE_TIME = NEW_CYCLE_TIME;
; bat = 0x33;//get_battle();
; node_data.len = 12;
; node_data.ID = LOCAL_ID;
; node_data.GID = LOCAL_GID;
; node_data.type = NODE_DATA;
; node_data.data[0] = send_seq;
; node_data.data[1] = (tmp>>8)&0xff;
; node_data.data[2] = tmp&0xff;
; node_data.data[3] = (bat>>8)&0xff;
; node_data.data[4] = bat&0xff;
; node_data.crc = 0xffff;
; CC1100_send((unsigned char*)&node_data,node_data.len+1);
; start_T0(1,300);
; led2Toggle();
;
; }
; */
;
;
; void resend()
; {
L34:
.dbline 0 ; func end
ret
; i -> R0,R1
.even
_T2_timeout::
;
; }
;
; void T2_timeout(){
; int i;
; //led0Toggle();
; //for(i=0;i<10000;i++)
; ;
L35:
.dbline 0 ; func end
ret
; i -> <dead>
.even
_T3_timeout::
; }
;
;
; void T3_timeout()
; { int i;
; timeout++;
lds R24,_timeout
subi R24,255 ; addi 1
sts _timeout,R24
; //led1Toggle();
;
; // CC1100_send((unsigned char*)&node_data,node_data.len+1);
; //start_T0(0,500);
; if (timeout <=2) //重发3次结束
ldi R24,2
lds R2,_timeout
cp R24,R2
brlo L37
; {
; CC1100_send((unsigned char*)&node_data,node_data.len+1);
lds R18,_node_data
clr R19
subi R18,255 ; offset = 1
sbci R19,255
ldi R16,<_node_data
ldi R17,>_node_data
xcall _CC1100_send
; start_T3(0,RE_SEND_DELAY);
ldi R18,500
ldi R19,1
clr R16
xcall _start_T3
; //post(resend);
; //printf("stop\n");
; }
xjmp L38
L37:
; else
; {
;
; stop_T3();
xcall _stop_T3
; //post(mcu_sleep);
; //for(i=0;i<10000;i++);
; CC1100_sleep();
xcall _CC1100_sleep
; timeout =0;
clr R2
sts _timeout,R2
; }
L38:
L36:
.dbline 0 ; func end
ret
; crc -> R10
; bat -> R10
; tmp -> R12
.even
_T0_timeout::
xcall push_gset4
; }
;
; void T0_timeout()
; {
; unsigned char tmp,bat,crc=0;
clr R10
; //led1Toggle();
; crc =1;
clr R10
inc R10
; printf("%d",crc);
mov R18,R10
clr R19
ldi R16,<L40
ldi R17,>L40
xcall _printf
; sync_count--;
lds R24,_sync_count
lds R25,_sync_count+1
sbiw R24,1
sts _sync_count+1,R25
sts _sync_count,R24
; if (sync_count == 0)
cpi R24,0
cpc R24,R25
brne L41
X6:
; {
; stop_T0();
xcall _stop_T0
; start_T0(0, T - (node_num * T_p_node));
lds R2,_T_p_node
lds R3,_node_num
mul R3,R2
lds R18,_T
lds R19,_T+1
sub R18,R0
sbc R19,R1
clr R16
xcall _start_T0
; SYNC_FLAG =0;
clr R2
sts _SYNC_FLAG,R2
; sync_count = SYNC_COUNT;
ldi R24,30
ldi R25,0
sts _sync_count+1,R25
sts _sync_count,R24
; CC1100_wakeup();
xcall _CC1100_wakeup
; }
L41:
; tmp = get_tmp();
xcall _get_tmp
mov R12,R16
; count ++;
lds R24,_count
lds R25,_count+1
adiw R24,1
sts _count+1,R25
sts _count,R24
; if (tmp>ALARM_TMP)
lds R2,_ALARM_TMP
cp R2,R16
brsh L43
; start_T3(0,300000);//CYCLE_TIME = NEW_CYCLE_TIME;
ldi R20,224
ldi R21,147
ldi R22,4
ldi R23,0
movw R18,R20
clr R16
xcall _start_T3
L43:
; bat = 0x33;//get_battle();
ldi R24,51
mov R10,R24
; node_data.len = 12;
ldi R24,12
sts _node_data,R24
; node_data.ID = LOCAL_ID;
lds R2,_LOCAL_ID
sts _node_data+1,R2
; node_data.GID = LOCAL_GID;
lds R2,_LOCAL_GID
sts _node_data+2,R2
; node_data.DA = CLUSTER_IP;
clr R3
mov R3,R2
clr R2
sts _node_data+3+1,R3
sts _node_data+3,R2
; node_data.type = NODE_DATA;
ldi R24,50
sts _node_data+5,R24
; node_data.data[0] = send_seq;
lds R2,_send_seq
sts _node_data+6,R2
; node_data.data[1] = tmp;
sts _node_data+6+1,R12
; node_data.data[2] = (bat>>8)&0xff;
mov R24,R10
clr R25
mov R24,R25
clr R25
sbrc R24,7
com R25
andi R25,0
sts _node_data+6+2,R24
; node_data.data[3] = bat&0xff;
mov R24,R10
andi R24,255
sts _node_data+6+3,R24
; node_data.crc = 0xffff;
ldi R24,65535
ldi R25,255
sts _node_data+10+1,R25
sts _node_data+10,R24
; led2Toggle();
xcall _led2Toggle
; CC1100_wakeup();
xcall _CC1100_wakeup
; CC1100_send((unsigned char*)&node_data,node_data.len+1);
lds R18,_node_data
clr R19
subi R18,255 ; offset = 1
sbci R19,255
ldi R16,<_node_data
ldi R17,>_node_data
xcall _CC1100_send
; //CC1100_sleep();
; start_T3(0,RE_SEND_DELAY);
ldi R18,500
ldi R19,1
clr R16
xcall _start_T3
L39:
xcall pop_gset4
.dbline 0 ; func end
ret
.area bss(ram, con, rel)
_sleep_flag::
.blkb 1
_T_p_node::
.blkb 1
_node_data::
.blkb 15
_cluster_msg::
.blkb 15
.area data(ram, con, rel)
L40:
.blkb 3
.area idata
.byte 37,'d,0
.area data(ram, con, rel)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?