;------------------------------------------------------------- ; ps2 isr -- LPC-2478-STK, TINY-2138 ; Version for MCUs with appropriate Timer/Counters ;------------------------------------------------------------- ;;; uses vector-append defined in lcd-init-draw ;;; (if not using lcd, copy vector-append below) ; open the init-console file (define p (open-output-file "init-lcd-ps2")) ; LPC2478-STK ; P2.14 = PS2 IO pin, CAP2[0] (timer/counter 2, capture channel 0) ; P2.15 = PS2 CLK pin, CAP2[1] (timer/counter 2, capture channel 1) (write '(begin (define ps2_timer #x0e007000) ; timer 2 base address (define ps2_tmisr 26) ; timer 2 isr index in VicIntEnable (define ps2_tmpwr 22) ; timer 2 power-up bit in PCONP (define ps2_match 11) ; match at 11 CLK (define ps2_iopcf #x10) ; IO pin function/mode set by pinsel4/pinmode4 (define ps2_iopin 14) ; P2.14 is PS2 IO pin (define ps2_iocha 0) ; channel 0 is timer 2 capture channel for PS2 IO (define ps2_iocfg #b10) ; #b10 configures P2.14 to CAP2[0] in pinsel4 (define ps2_ckpcf #x10) ; CLOCK pin function/mode set by pinsel4/pinmode4 (define ps2_ckpin 15) ; P2.15 is PS2 CLOCK pin (define ps2_ckcha 1) ; channel 1 is timer 2 capture channel for PS2 CLOCK (define ps2_ckcfg #b10) ; #b10 configures P2.15 to CAP2[1] in pinsel4 (define Vic_iclr #x0f00) ; interrupt clear offset (define pinmod #x0E002C04)) ; pinmode register base address to set pull-up/down resistors p) ; TINY-2138 ; P0.19 = PS2 IO pin, CAP1[2] (timer/counter 1, capture channel 2) ; P0.11 = PS2 CLK pin, CAP1[1] (timer/counter 1, capture channel 1) (write '(begin (define ps2_timer #x0e000800) ; tmr 1 base (define ps2_tmisr 5) ; tmr 1 isr index (define ps2_tmpwr 2) ; tmr 1 PCONP power bit (define ps2_match 10) ; match at 10 CLK (define ps2_iopcf #x04) ; pnsl1 for IO pin (define ps2_iopin 19) ; P0.19 = IO (define ps2_iocha 2) ; 2 = IO capt chan (define ps2_iocfg #b11) ; #b11 => P0.19 to CAP1[2] (define ps2_ckpcf #x00) ; pnsl0 for CLK pin (define ps2_ckpin 11) ; P0.11 = CLK (define ps2_ckcha 1) ; 1 = CLK capt chan (define ps2_ckcfg #b10) ; #b10 => P0.11 to CAP1[1] (define Vic_iclr #x30) ; interrupt clear offset (define pinmod #f)) ; no pinmode p) ; build the PS/2 ISR ; part 1 (due to limitations in read buffer size) (write '(define temp '#(0 0 #xeb 0 #xEE2A #xE28F #x3000 #xE59E #x20FF #xE3A0 #xCFAA #xE28F #xC000 #xE59C #x1000 #xE59C #x1 #xE311 #xF048 #x128F #x2C0F #xE382 #x8 #xE59C #x3012 #xE023 #xEF9D #xE28F #x3000 #xE58E #x1000 #xE58C #x24FF #xE3A0 #x2642 #xE1A0 #xCF9A #xE28F #xC000 #xE59C #x200C #xE082 #xC000 #xE3A0 #xC000 #xE582 #xC01C #xE59D #xF00C #xE16F #x500F #xE8DD #xD018 #xE28D #x4000 #xE8BD #xF00E #xE1B0 #x3 #xE1E0 #x20A0 #xE002 #x34FF #xE203 #xF0 #xE332 #x3302 #x383 #xE0 #x1332 #xF060 #x24F #xAA #xE332 #x3000 #x3A0 #xF06C #x24F #x14 #xE332 #x402 #x3A0 #x301 #x13A0)) p) ; part 2 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#x12 #x1332 #x59 #x1332 #xF010 #x128F #x302 #xE313 #x3000 #x11C3 #x3000 #x183 #x3302 #xE3C3 #xF098 #xE24F #x302 #xE313 #x3302 #x1223 #xF0A4 #x124F #x2080 #xE3C2 #xD05 #xE28F #x2002 #xE7D0 #x406 #xE313 #xF050 #x28F #x301 #xE313 #xE0 #x3A0 #xA0 #x13A0 #x61 #xE352 #x2000 #x51C2 #xF038 #x528F #x27 #xE332 #x2022 #x3A0 #xF02C #x28F #x3D #xE332 #x202B #x3A0 #xF020 #x28F #x40 #xE352 #x202C #x4242 #x200F #x4202 #xF5D #x428F #x2002 #x47D0 #xF008 #x428F #x60 #xE332 #x207E #x3A0 #x2020 #x1382 #xF5E #xE28F #x0 #xE590 #x3 #xE332))) p) ; part 3 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#xF098 #x28F #x10AC #xE92D #x1000 #xE590 #x1C01 #xE281 #x1000 #xE580 #x1421 #xE1A0 #x1003 #xE281 #x2001 #xE7C0 #x3002 #xE1A0 #x30FF #xE203 #x5F52 #xE28F #x5000 #xE595 #xC004 #xE595 #xC014 #xE59C #xC004 #xE28C #xE00F #xE1A0 #xF00C #xE1A0 #x30FF #xE203 #x8 #xE333 #xF040 #x128F #x3020 #xE3A0 #xC004 #xE595 #xC014 #xE59C #xC004 #xE28C #xE00F #xE1A0 #xF00C #xE1A0 #x3008 #xE3A0 #xC004 #xE595 #xC014 #xE59C #xC004 #xE28C #xE00F #xE1A0 #xF00C #xE1A0 #x1000 #xE590 #x1C02 #xE241 #x53 #xE351 #x1053 #x43A0 #x1000 #xE580 #x10AC #xE8BD #x1000 #xE59C #xFF6E #xE24F))) p) ; part 4 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#x2053 #xE3A0 #x2000 #xE580 #x3000 #xE58E #x1000 #xE58C #x24FF #xE3A0 #x2642 #xE1A0 #xC0B0 #xE28F #xC000 #xE59C #x200C #xE082 #xC000 #xE3A0 #xC000 #xE582 #xE098 #xE28F #xE000 #xE59E #xF00E #xE1A0 #xFFFF #xFFFF #xFFFF #xFFFF #xFFFF #xFFFF #x9FF #xFF60 #xFFFF #xFFFF #x71FF #xFF31 #xFFFF #x737A #x7761 #xFF32 #x63FF #x6478 #x3465 #xFF33 #x20FF #x6676 #x7274 #xFF35 #x6EFF #x6862 #x7967 #xFF36 #xFFFF #x6A6D #x3775 #xFF38 #x2CFF #x696B #x306F #xFF39 #x2EFF #x6C2F #x703B #xFF2D #xFFFF #xFF27 #x3D5B #xFFFF #xFFFF #x5D0D #x5CFF #xFFFF #xFFFF #xFFFF #xFFFF #xFF08))) p) ; part 5 (due to limitations in read buffer size) (write '(begin (vector-set! _ISR ps2_tmisr (install (vector-append temp (vector #x15FF #x11FF #xFF12 #xFFFF #x7FFF #xFF19 #x1810 #xFF1B #xFFFF #xFF14 #x13FF #xFFFF #x5F3C #x3F3E #x2129 #x2340 #x2524 #x265E #x282A #x3AFF #x0 #x0 #x07a4 #x0 (logand #xffff Vic_iclr) (logand #xffff (ash Vic_iclr -16)) (logand #xffff (ash _RBF 2)) (logand #xffff (ash _RBF -14)) (logand #xffff (ash lcop 2)) (logand #xffff (ash lcop -14)) (logand #xffff (ash ps2_timer 4)) (logand #xffff (ash ps2_timer -12)))))) (set! temp #t)) p) ; define the bit-set and bit-clear utility functions ; (bit-set bit reg ofst) ; (bit-clear bit reg ofst) ; For arm7tdmi, arm9tdmi. (write '(begin (define bit-set (install '#(#x27 0 #x03eb 0 #x2144 #xE1A0 #x3145 #xE1A0 #xC146 #xE1A0 #x3203 #xE08C #xC001 #xE3A0 #xC21C #xE1A0 #x2000 #xE593 #x200C #xE182 #x2000 #xE583 #x400F #xE3A0 #xF001 #xE1A0))) (define bit-clear (install '#(#x27 0 #x03eb 0 #x2144 #xE1A0 #x3145 #xE1A0 #xC146 #xE1A0 #x3203 #xE08C #xC001 #xE3A0 #xC21C #xE1A0 #x2000 #xE593 #x200C #xE1C2 #x2000 #xE583 #x400F #xE3A0 #xF001 #xE1A0)))) p) ; define the word-copy utility function ; (word-copy dest-reg dest-ofst src-reg src-ofst) ; For arm7tdmi, arm9tdmi. (write '(define word-copy (install '#(#x27 0 #x04eb 0 #x3146 #xE1A0 #xC147 #xE1A0 #x3203 #xE08C #x2000 #xE593 #x3144 #xE1A0 #xC145 #xE1A0 #x3203 #xE08C #x2000 #xE583 #x400F #xE3A0 #xF001 #xE1A0))) p) ; power-up and configure PS2 counter ; VicIntEnClr <- disable timer interrupts ; PCONP <- PS2 timer/counter power enabled ; TnCTCR <- count on rising edge of PS2_CLK ; TnMR0 <- set match to count 11 received bits (clock pulses) ; TnMCR <- interrupt and reset on MR0 match ; TnCCR <- capture+interrupt on PS2_IO edges ; TnIR <- clear interrupts (write '(begin (define pconp #x0e01fc00) ; PCONP base address (define pinsel #x0E002C00) ; PINSEL base address (define VIC #x0fffff00) ; VIC base address (VicIRQStatus) (bit-set ps2_tmisr VIC #x14) (bit-set ps2_tmpwr pconp #xc4) (write (logior #x01 (ash ps2_ckcha 2)) ps2_timer #x70) (write ps2_match ps2_timer #x18) (write #x03 ps2_timer #x14) (write (ash #x07 (* 3 ps2_iocha)) ps2_timer #x28) (write #xff ps2_timer #x00)) p) ; configure ps2 io and ck pins, and pull-up/down resistors if needed (write '(let ((iobt (ash (modulo ps2_iopin 16) 1)) (ckbt (ash (modulo ps2_ckpin 16) 1)) (bcfg (lambda (a1 a2 a3 a4) (apply (if (zero? (logand a1 a2)) bit-clear bit-set) (list a3 pinsel a4))))) (bcfg #b01 ps2_iocfg iobt ps2_iopcf) (bcfg #b10 ps2_iocfg (+ 1 iobt) ps2_iopcf) (bcfg #b01 ps2_ckcfg ckbt ps2_ckpcf) (bcfg #b10 ps2_ckcfg (+ 1 ckbt) ps2_ckpcf) (if pinmod (begin (bit-clear iobt pinmod ps2_iopcf) (bit-set (+ 1 iobt) pinmod ps2_iopcf) (bit-clear ckbt pinmod ps2_ckpcf) (bit-set (+ 1 ckbt) pinmod ps2_ckpcf)))) p) ; configure VIC, enable PS2 counter (write '(begin (word-copy VIC (logior #x100 (ash ps2_tmisr 2)) VIC #x110) (write #xff ps2_timer #x00) (bit-set ps2_tmisr VIC #x10) (write 1 ps2_timer #x04)) p) ; set output port to LCD (write '(begin (define ocop (current-output-port)) (define (current-output-port) lcop)) p) ; close the file (close-output-port p)