; --------------------------------------------------------------------------
;| Project : WatchDog pro rack |
;| Name : WD |
;| Procesor : 89c2051 - 11.0592MHz |
;| Ordered : GLOBE Internet |
;| Created : (c) ADC Systems |
;| Vers/date : 1.01.003 / 10.01.2001 |
; --------------------------------------------------------------------------
$nolist
$nosymbols
$nopaging
$mod51
;{Constants}
tIntCL equ 0 ;-46080=50ms int
tIntCH equ 76
;{Bytes}
Buff equ 30h
Pos equ 34h
Cmd equ 35h
Par equ 36h
Wd equ 37h
WdDiv equ 38h
WdSet equ 39h
ResLen equ 3ah
;{Bits}
xRes equ 0
xLed equ 1
xCikCak equ 2
xLed1 equ 3
;{-----------------------------------------------------}
;{format prikazu do watchdogu
;
; async 9600/8/N/1 Byte: 0 1 2 3
;
; 1. nastaveni watchdogu $ff + $1x + tim + sum
; 2. impuls do watchdogu $ff + $2x + $00 + sum
; 3. nastaveni delky resetu $ff + $3x + res + sum
; 4. reset natvrdo $ff + $5x + $00 + sum
;
; x = cislo zarizeni [0-15] .. muze byt az 16 watchdogu na jednom portu
; tim = timeout watchdogu [0-254 sec] 0=vypnuto, default=0
; res = delka reset impulsu [1-255 sec] default=1
; sum = kontrolni soucet bajtu 1+2 modulo 128 (and $7f)
;
; watchdog zasila zpet echo (zkrz procesor, nikoli jenom propojením TxD a RxD
; lze teda detekovat cinnost a zivot watchdogu)
;
;}
;{-----------------------------------------------------}
org 0
jmp Init
org 0bh
jmp Timer
org 23h
jmp RSint
;{-----------------------------------------------------}
RSint: jnb ri,RSEnd ; int z RS
push acc
push b
push psw
mov psw,#8h
mov a,sbuf
mov sbuf,a
mov b,a
cjne a,#255,RSint_0 ; 255 nuluje buffer
mov Pos,#0
jmp RSE
RSint_0: mov a,#Buff ; prida bajt do bufferu
add a,Pos
mov r0,a
mov @r0,b
mov a,Pos ; posune ukazatel
inc a
anl a,#3
mov Pos,a
cjne a,#3,RSE ; jsou-li 3 bajty, spusti test paketu
mov Pos,#0
mov a,Buff+0
add a,Buff+1
anl a,#7fh
xrl a,Buff+2 ; test sumy
jnz RSE
mov a,p1 ; test shody ID
cpl a
swap a
xrl a,Buff
anl a,#0fh
jnz RSE
mov Cmd,Buff ; vse ok
mov Par,Buff+1
RSE: pop psw
pop b
pop acc
clr ri
RSEnd: clr ti
reti
;{-----------------------------------------------------}
Timer: mov th0,#tIntCH ; int od timeru 50ms
mov tl0,#tIntCL
clr tf0
push acc
push psw
mov psw,#10h
cpl xCikCak
jnb xCikCak,TimE
mov c,xLed ; LED 50ms blikne po prijeti spravnyho paketu
orl c,xLed1 ; + sviti behem generovani resetu
cpl c
mov p3.4,c
clr xLed
mov a,WdSet ; WD neni zapnut
jz TimE
dec WdDiv
mov a,WdDiv
jnz TimE
mov WdDiv,#10 ; delic na 1s
dec Wd
mov a,Wd
jnz TimE
setb xRes ; WD dojde k 0 -> reset
TimE: pop psw
pop acc
reti
;{-----------------------------------------------------}
Init: mov p1,#0ffh
mov p3,#0ffh
mov sp,#60h
mov Pos,#0
mov Wd,#0
mov WdDiv,#10
mov WdSet,#0
mov ResLen,#1
clr xRes
setb xLed
clr xLed1
clr xCikCak
mov tmod,#21h
mov th0,#tIntCH
mov tl0,#tIntCL
mov th1,#0fdh
mov tl1,#0fdh
mov scon,#50h ; 9600 Bd
mov ie,#10010010b
setb tr0
setb tr1
Loop: mov a,Cmd ; test prikazu
mov Cmd,#0
anl a,#0f0h
cjne a,#10h,Cmd_1 ; wd set
clr ea
mov WdSet,Par
mov Wd,WdSet
mov WdDiv,#10
setb ea
setb xLed
jmp Cmd_E
Cmd_1: cjne a,#20h,Cmd_2 ; wd pulse
clr ea
mov Wd,WdSet
mov WdDiv,#10
setb ea
setb xLed
jmp Cmd_E
Cmd_2: cjne a,#30h,Cmd_3 ; reset len
mov a,par
jz Cmd_E
mov ResLen,a
setb xLed
jmp Cmd_E
Cmd_3: cjne a,#50h,Cmd_E ; force hw reset
setb xRes
setb xLed
jmp Cmd_E
Cmd_E:
jnb xRes,Loop
clr xRes
setb xLed1
mov WdSet,#0
clr p3.5
mov r4,ResLen
Del_500ms: mov r5,#7
mov r6,#0
mov r7,#0
Del_500msx: djnz r7,Del_500msx
djnz r6,Del_500msx
djnz r5,Del_500msx
djnz r4,Del_500ms
setb p3.5
clr xLed1
jmp Loop
end