;---------------------------------------------------------------------------; ; RS-232 Data Switch Firmware ; ; ; ; File: INIT.ASM ; ; ; ; This file contains system initialization code. ; ;---------------------------------------------------------------------------; ; This file is an absolute module, as it must be located at ; address zero. All other modules are relocatable. cseg at 0h $nolist $include(globals.asm) $list extrn code(idle) extrn code(tick_isr) ; Reset and interrupt vectors ; --------------------------- ; The 8031 reset vector is at 0, and the timer 0 interrupt ; vector is at 0BH. ljmp start nop nop nop nop nop nop nop nop ljmp tick_isr ; CPU initialization ; ------------------ ; Initialize CPU registers. start: mov sp,#2fh ; Stack at 30H mov psw,#0 ; Registers at 0H mov tcon,#0 ; Disable timers mov ie,#0 ; Disable all interrupts mov ip,#0 mov pcon,#0 ; Initialize other registers. mov p1,#0ffh mov p3,#0ffh ; Data area initialization ; ------------------------ ; Initialize the date to 12:00 AM, Jan. 1, 1980 clr a mov hours,a mov minutes,a mov seconds,a inc a mov day,a mov month,a mov year,#80 ; Initialize break timers, timeouts, and flags. The default ; timeout is 100 ms (10 ticks). mov dptr,#brktimtbl mov a,#10 mov r0,#maxport brkloop1: movx @dptr,a inc dptr djnz r0,brkloop1 mov dptr,#brkcnttbl clr a mov r0,#maxport brkloop2: movx @dptr,a inc dptr djnz r0,brkloop2 mov dptr,#brkflagtbl mov r0,#maxport brkloop3: movx @dptr,a inc dptr djnz r0,brkloop3 ; Initialize auxiliary input timers and timeouts. The default ; is to ignore all the auxiliary inputs (no response to DTR ; or DCD going away). mov dptr,#dtrtimtbl clr a mov r0,#maxport dtrloop_1: movx @dptr,a inc dptr djnz r0,dtrloop_1 mov dptr,#dtrcnttbl mov r0,#maxport dtrloop_2: movx @dptr,a inc dptr djnz r0,dtrloop_2 mov dptr,#dtrflagtbl mov r0,#maxport dtrloop_3: movx @dptr,a inc dptr djnz r0,dtrloop_3 ; Initialize auxiliary output defaults. The default is ; for each port to have DTR/DCD asserted when not connected. mov dptr,#dtrdeftbl mov a,#1 mov r0,#4 dtrloop_4: movx @dptr,a inc dptr djnz r0,dtrloop_4 ; Initialize the DTR/DCD override mask. The default is for each ; port to obtain DTR/DCD from its corresponding input port, ; rather than to have those outputs forced to 1. mov dtr_mask_and,#0ffh ; Initialize port names to "P1", "P2", etc. mov dptr,#nametbl mov r0,#maxport mov r1,#'1' initname: mov a,#'P' movx @dptr,a inc dptr mov a,r1 movx @dptr,a inc dptr clr a movx @dptr,a inc dptr inc r1 mov r2,#6 inc a initloop: movx @dptr,a inc dptr djnz r2,initloop djnz r0,initname ; Initialize baud rate lists. They are initialized to the ; following sequence: 3,4,5,6,7,2,1. This corresponds to ; the following sequence of baud rates: 1200, 2400, 4800, ; 9600, 19200, 300, 110. This is the order they will be ; tried in when a port initially enters command mode. mov dptr,#baudtbl mov r0,#maxport biloop: mov a,#3 mov r2,#5 biloop2: movx @dptr,a inc dptr inc a djnz r2,biloop2 mov a,#2 movx @dptr,a inc dptr dec a movx @dptr,a inc dptr djnz r0,biloop ; Initialize physical connection table. All connection ; registers are initialized to 15, meaning "no connection". ; The second half of the last connection register, which is ; the DTR/DCD output controls, is also initialized to 15, ; meaning "no DTR/DCD". The interrupt routine will change ; this. mov dptr,#connectbl mov a,#15 mov r0,#8 cloop1: movx @dptr,a inc dptr djnz r0,cloop1 ; Initialize logical connection table. All ports are ; initialized to "no connection". mov dptr,#c_sourcetbl mov a,#15 mov r0,#maxport cloop3: movx @dptr,a inc dptr djnz r0,cloop3 ; Set all connection registers to unconnected. mov dptr,#connregbase mov a,#0ffh mov r0,#4 cloop2: movx @dptr,a inc dptr djnz r0,cloop2 ; Clear the break queue and flag. mov dptr,#brkqueue clr a movx @dptr,a clr queueflag ; Set all ports to unrestricted access. mov dptr,#restrictbl mov r0,#maxport clr a rloop: movx @dptr,a inc dptr djnz r0,rloop ; Initialize all the masks to 003F, i.e. able to access ; all 6 ports currently present. mov dptr,#masktbl mov r0,#maxport rloop2: clr a movx @dptr,a inc dptr mov a,#3fh movx @dptr,a inc dptr djnz r0,rloop2 ; Initialize all ports to "no autoconnect". mov dptr,#autoconntbl mov r0,#maxport clr a acloop: movx @dptr,a inc dptr djnz r0,acloop ; Interrupt and serial port initialization ; ---------------------------------------- ; Set both timers to free running, 8 bit auto reload. mov tmod,#22h ; Initialize the external intercept vectors to just ; "RET". mov a,#22h mov dptr,#extisr movx @dptr,a mov dptr,#extdec movx @dptr,a ; Set up timer 0 to generate tick interrupts at the ; slowest possible rate (3600/sec). mov th0,#0h setb ip.1 setb ie.1 setb ie.7 setb tcon.4 ; Start baud rate generator and initialize serial port. mov th1,#0fdh setb tcon.6 mov scon,#52h ; Indicate that the signon procedure has not yet been ; executed, and that no events are pending from the interrupt ; routine. clr signonflag clr attnflag ; Go into idle mode, waiting for a "break" request. ljmp idle end