;;******************************************************************** ;; by Andrew Chanler - Fall 2003 ;; Cricket bus interface for handybaord using port A pin 7 which is (digital input 9) as bus line ;; please refer to http://www.cs.uml.edu/~achanler/robotics ;; ;;******************************************************************** ;; .include "6811regs.asm" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .file "cbus-gel.s" .mode mshort .mode mlong-double ;;; some of the 68hc11 registers .set TMSK2,0x1024 .set TFLG2,0x1025 .set PACTL,0x1026 .set HPRIO,0x103C ;;; PAI interrupt .set PAIINT,0xDA ;;; .sect .text .globl install_PAI_interrupt .type install_PAI_interrupt,@function install_PAI_interrupt: ldx *_.frame pshx sts *_.frame LDAA HPRIO ANDA #0x40 ; test SMOD bit BNE spmiPAI LDX #0xFF00 ; normal mode interrupts BRA continuePAIinstall spmiPAI: LDX #0xBF00 ; special mode interrupts continuePAIinstall: ldd #interrupt_cbus_PAI std PAIINT,X ;; setup pulse accumulator interrupt vector ldaa PACTL oraa #0b01000000 anda #0b01001111 staa PACTL ;; turn on pulse accumulator with high to low trigger pulx stx *_.frame rts interrupt_cbus_PAI: sei clrb ldaa #8 ldx #0x1000 clr is_cbus_cmd ;; wait for begining of start bit pai_waithere: brclr 0,x 0x80 pai_waithere ;7 ;; at best, 7 eclocks have gone by since start of start bit ;; at worst, 15 eclocks have gone by since start of start bit ;; and first data bit will be from eclock 20 to eclock 40 ;; try to read in middle of bit(around eclock 30), if best 7 + 19 = 26; if worst 15 + 19 = 34 ;; therefore 19 e clocks must pass before bits are read. ;; wait 19 eclocks for start bit to pass and to get into the middle of bit zero pshx ;4 pulx ;5 nop ;2 nop ;2 nop ;2 nop ;2 nop ;2 ;; read one bit every 10us pai_next_bit: brset 0,x 0x80 pai_sc ;7 pai_cc: clc ;2 rorb ;2 nop ;2 nop ;2 deca ;2 bne pai_next_bit ;3 brset 0,x 0x80 pai_done ;; check command bit inc is_cbus_cmd bra pai_done pai_sc: sec ;2 rorb ;2 nop ;2 nop ;2 deca ;2 bne pai_next_bit ;3 brset 0,x 0x80 pai_done ;; check command bit inc is_cbus_cmd bra pai_done pai_done: ldaa #0b00010000 staa TFLG2 ;; clear pai flag clra stab cbus_byte cli rti .Lfe1: .size install_PAI_interrupt,.Lfe1-install_PAI_interrupt ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .globl is_cbus_cmd .sect .data .type is_cbus_cmd,@object .size is_cbus_cmd,1 is_cbus_cmd: .byte 0 .sect .text .globl cbus_byte .sect .data .type cbus_byte,@object .size cbus_byte,1 cbus_byte: .byte 0 .sect .text ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .globl ignore_cbus .type ignore_cbus,@function ignore_cbus: ldaa TMSK2 anda #0b11101111 ;; disable PAI interrupt staa TMSK2 rts .Lfe2: .size ignore_cbus,.Lfe2-ignore_cbus ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .globl listen_to_cbus .type listen_to_cbus,@function listen_to_cbus: ldab #0b00010000 stab TFLG2 ;; clear pai flag ldab TMSK2 orab #0b00010000 ;; enable PAI interrupt stab TMSK2 rts .Lfe3: .size listen_to_cbus,.Lfe3-listen_to_cbus ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .sect .text .globl cbus_send_cmd .type cbus_send_cmd,@function cbus_send_cmd: sei ;2 ldaa PACTL oraa #0x80 ;; set porta pin 7 to output; staa PACTL tba ; put b in a ldab #8 ldx #0x1000 ;; line low for 100 us bclr 0,x 0b10000000 ;;7 ldx #31 ;3 scb_delay: ;; 200 - 14 = 186 e clocks ;; note 6 * 31 = 186 eclocks dex ;3 bne scb_delay ;3 ldx #0x1000 ;3 ;; start bit for 10us bset 0,x 0b10000000 ;7 start bit ldx #0x1000 ;3 ldx #0x1000 ;3 nop ;2 ;; each data bit for 10us scb_bit_loop: rora ;2 bcs scb_bs ;3 scb_bc: bclr 0,x 0b10000000 ;7 ldx #0x1000 ;3 decb ;2 bne scb_bit_loop ;3 bra scb_byte_done ;3 scb_bs: bset 0,x 0b10000000 ;7 ldx #0x1000 ;3 decb ;2 bne scb_bit_loop ;3 bra scb_byte_done ;3 scb_byte_done: ;; command bit for 10us bclr 0,x 0b10000000 ;7 bclr 0,x 0b10000000 ;7 ldx #0x1000 ;3 ldx #0x1000 ;3 ;; line goes high when done: bset 0,x 0b10000000 ldab PACTL andb #0x7F ;; make porta pin 7 be an input stab PACTL ldaa #0b00010000 staa TFLG2 ;; clear pai flag cli rts .Lfe4: .size cbus_send_cmd,.Lfe4-cbus_send_cmd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .sect .text .globl cbus_send_data .type cbus_send_data,@function cbus_send_data: sei ;2 ldaa PACTL oraa #0x80 ;; set porta pin 7 to output; staa PACTL tba ; put b in a ldab #8 ldx #0x1000 ;; line low for 100 us bclr 0,x 0b10000000 ;;7 ldx #31 ;3 sdb_delay: ;; 200 - 14 = 186 e clocks ;; note 6 * 31 = 186 eclocks dex ;3 bne sdb_delay ;3 ldx #0x1000 ;3 ;; start bit for 10us bset 0,x 0b10000000 ;7 start bit ldx #0x1000 ;3 ldx #0x1000 ;3 nop ;2 ;; each data bit for 10us sdb_bit_loop: rora ;2 bcs sdb_bs ;3 sdb_bc: bclr 0,x 0b10000000 ;7 ldx #0x1000 ;3 decb ;2 bne sdb_bit_loop ;3 bra sdb_byte_done ;3 sdb_bs: bset 0,x 0b10000000 ;7 ldx #0x1000 ;3 decb ;2 bne sdb_bit_loop ;3 bra sdb_byte_done ;3 sdb_byte_done: ;; data bit for 10us bset 0,x 0b10000000 ;7 bset 0,x 0b10000000 ;7 ldx #0x1000 ;3 ldx #0x1000 ;3 ;; line goes high when done: bset 0,x 0b10000000 ldab PACTL andb #0x7F ;; make porta pin 7 be an input stab PACTL ldaa #0b00010000 staa TFLG2 ;; clear pai flag cli rts .Lfe5: .size cbus_send_data,.Lfe5-cbus_send_data ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;