;;; -*- Mode: LISP; Syntax: Common-Lisp -*- ;Serial net downloader for processors ;Should take 15 ms per byte, but measured at 24 bytes/sec (35% efficient) ;Typical sequence: ; ; 11 00 04 - says to load processor 4 ; 11 80 - erase entire eeprom and reset configuration ; 11 FF 00 F8 - set load address to #xF800 ; 76 85 AB ... - program op-codes and data ; 11 11 - a single byte = #x11 (data or op-code for CBA) ; 32 A5 ... - more op-codes and data ; 11 00 0A - says to load processor 10 now ;Processor echoes all bytes unless it can't store to EEPROM. (defprog NET-DLOAD :machine m68hc11 :start 0 ;write this into internal RAM :code ( ;EEPROM stuff (=v bprot #x1035) ;eeprom block protection on E2's (=v eeprom #x103B) (=v config #x103F) (=c eelatch #x02) ;for a single byte (=c eeprogram #x03) (=c bulk-erase #x06) ;for whole thing (=c high-volts #x07) ;memory mapping (=c stack #xFF) ;serial protocol (=c escape #x11) ;special escape character (=c escape-dest #x00) ;load different processor (=c escape-clr #x80) ;erase all eeprom (=c escape-addr #xFF) ;set address as specified ;serial communications (=v baud #x102B) ;UART registers (=v sccr2 #x102D) (=v scdat #x102F) (=v scsr #x102E) (=c iscsr #x2E) ;index off #x1000 (=v spcr #x1028) ;output D mode control (=v porta #x1000) ;for dual processors (=v portd #x1008) ;dip switches (=c 1200baud #xB3) (=c trena #x0C) ;enable input and output (=c rdrf #x20) ;receiver full (=c wired-or #x24) ;prevent collisions ;-------------------------------------------------------------------------------- START (lds ! stack) ;start from top of RAM (clra) ;unprotect eeprom blocks early (staa bprot) (ldaa ! wired-or) ;open drain serial outputs (staa spcr) (ldaa ! 1200baud) ;set baud rate (staa baud) (ldaa ! trena) ;enable transmit and receive (staa sccr2) await-summons (jsr serial-read) ;get a byte from the host (cmpa ! escape) ;see if special action code (bne await-summons) check-action (jsr serial-read) ;get action code from host (cmpa ! escape-dest) ;see if new processor addressed (beq recipient?) (cmpa ! escape-addr) ;see if address being sent (bne await-summons) ;op-code or erase command (jsr serial-read) ;ignore address bytes (jsr serial-read) (bra await-summons) recipient? (ldab portd) ;look at dip switch settings (andb ! #b00111100) (lsrb) (lsrb) (ldaa porta) ;for dual processor units (coma) (anda ! #b00000001) (asla) (asla) (asla) (asla) (aba) (tab) ;address = 16*A + D (jsr serial-read) ;see who is being loaded (cba) ;see if address matches (bne await-summons) active-loop (jsr serial-read) ;get program byte from host (cmpa ! escape) ;may be a command instead (bne store-byte) parse-escape (jsr serial-read) ;which special action (if any) (cmpa ! escape-dest) (beq recipient?) ;different processor addressed (cmpa ! escape-clr) (beq clear-eeprom) ;erase all of memory (cmpa ! escape-addr) (beq set-address) ;adjust eeprom fill pointer store-byte (jsr eeprom-write) ;write data to eeprom (cmpa &y 0) ;make sure it got there (bne forever) ;if not, hang (iny) ;point to next location (bra active-loop) set-address (jsr serial-read) ;low order byte first (tab) ;save in B (jsr serial-read) ;then high order byte (xgdy) ;move into fill pointer (bra active-loop) clear-eeprom (ldab ! bulk-erase) ;set up to erase everything (stab eeprom) (stab config) ;required mystery??? (ldab ! high-volts) ;turn on charge pump (stab eeprom) (ldx ! 3500.) ;delay 10.5 milliseconds erase-wait (dex) (bne erase-wait) (clr eeprom) ;no more erasing (bra active-loop) forever ;error loop - stops echoing (bra forever) ;-------------------------------------------------------------------------------- ;read a byte from serial stream, returned in A (X bashed) SERIAL-READ (ldx ! #x1000) read-byte-wait (brclr &x iscsr rdrf read-byte-wait) ;wait for arrival (ldaa scdat) ;get shifted in byte (staa scdat) ;echo back to host (rts) ;write a byte into EEPROM, Y has address while A has byte (B and X bashed) EEPROM-WRITE (ldab ! eelatch) ;set for programming (stab eeprom) (staa &y 0) ;move data (ldab ! eeprogram) ;turn on charge pump (stab eeprom) (ldx ! 3500.) ;wait 10.5 ms write-wait (dex) (bne write-wait) (clr eeprom) ;turn off programming (rts) ))