From 12a27f27734b18ba4dea8d411095cf53c3870ef2 Mon Sep 17 00:00:00 2001 From: "Leo C." Date: Thu, 25 Apr 2024 23:45:40 +0200 Subject: [PATCH] SVN --> GIT Add Version 3.5 --- avr/Makefile | 4 +- avr/Z80int-jmp.asm | 41 ++-- avr/config.inc | 90 +++++--- avr/dsk_fat16.asm | 15 +- avr/dsk_fsys.asm | 6 +- avr/i2c.asm | 419 +++++++++++++++++++++++++++++------- avr/init.asm | 27 ++- avr/macros.inc | 14 +- avr/svnrev.inc | 14 +- avr/sw-uart.asm | 3 +- avr/timer.asm | 12 +- avr/utils.asm | 60 +++++- avr/virt_ports.asm | 175 ++++++++++++++- cpm/utils/I2C_UART_DEMO.MAC | 50 +++++ 14 files changed, 742 insertions(+), 188 deletions(-) create mode 100644 cpm/utils/I2C_UART_DEMO.MAC diff --git a/avr/Makefile b/avr/Makefile index 5b5d3d7..0b82f24 100644 --- a/avr/Makefile +++ b/avr/Makefile @@ -99,8 +99,8 @@ CRCGEN = crcgen HEXTOBIN = $(OBJCOPY) -I ihex -O binary --gap-fill 0xff #(call conf-val,config-id,config-file) -#conf-val = $(shell awk -vID=$(strip $1) '$$0 ~ "^[ \t]*\#define[ \t]+" ID "[ \t]+" {print $$3}' $2 ) -conf-val = $(shell awk -vID=$(strip $1) '$$1$$2 ~ "\#define"ID {print $$3}' $2) +#conf-val = $(shell $(AWK) -vID=$(strip $1) '$$0 ~ "^[ \t]*\#define[ \t]+" ID "[ \t]+" {print $$3}' $2 ) +conf-val = $(shell $(AWK) -vID=$(strip $1) '$$1$$2 ~ "\#define"ID {print $$3}' $2) # Programming support using avrdude. Settings and variables. diff --git a/avr/Z80int-jmp.asm b/avr/Z80int-jmp.asm index ab544d8..40d5e3d 100644 --- a/avr/Z80int-jmp.asm +++ b/avr/Z80int-jmp.asm @@ -21,7 +21,7 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: Z80int-jmp.asm 93 2014-01-03 16:32:32Z rapid $ ; #if EM_Z80 @@ -582,11 +582,9 @@ do_store_pc: do_store_pcrel: ;add displacement to PC #if EM_Z80 - clr oph - tst opl ;sign extend - brpl stpcr1 - com oph -stpcr1: + mov oph,opl ;sign extend + lsl oph + sbc oph,oph add z_pcl,opl adc z_pch,oph ret @@ -2067,10 +2065,9 @@ opprxcb_fd: opprxcb_1: mem_read_s z_pc ;get displacement adiw z_pcl,1 ;++z_pc - clr temp2 ;sign extend - tst temp - brpl PC+2 - com temp2 + mov temp2,temp ;sign extend + lsl temp2 + sbc temp2,temp2 add xl,temp ;add displacement adc xh,temp2 mem_read_d opl @@ -2418,11 +2415,9 @@ fetchmxx_fd: fetchmxx1: mem_read_ds opl, z_pc ;get displacement adiw z_pcl,1 - clr oph ;sign extend - tst opl - brpl fetchmxx2 - com oph -fetchmxx2: + mov oph,opl ;sign extend + lsl oph + sbc oph,oph add xl,opl ;add displacement adc xh,oph mem_read_d opl ;get operand @@ -2474,11 +2469,9 @@ storemxx_fd: storemxx1: mem_read_s z_pc ;get displacement adiw z_pcl,1 - clr temp2 ;sign extend - tst temp - brpl storemxx2 - com temp2 -storemxx2: + mov temp2,temp ;sign extend + lsl temp2 + sbc temp2,temp2 add xl,temp ;add displacement adc xh,temp2 mem_write_s opl ;store operand @@ -2505,11 +2498,9 @@ storemxx21: mem_read_s z_pc ;get displacement adiw z_pcl,1 adiw z_pcl,1 - clr temp2 ;sign extend - tst temp - brpl storemxx22 - com temp2 -storemxx22: + mov temp2,temp ;sign extend + lsl temp2 + sbc temp2,temp2 add xl,temp ;add displacement adc xh,temp2 mem_write_s opl ;store operand diff --git a/avr/config.inc b/avr/config.inc index 4f928a5..38dc793 100644 --- a/avr/config.inc +++ b/avr/config.inc @@ -18,11 +18,13 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: config.inc 242 2015-12-11 16:05:52Z rapid $ -#define VMAJOR 3 /* Version number */ -#define VMINOR 2 +#define VMAJOR 3 /* Version number */ +#define VMINOR 5 +#define VERS_STR "3.5" + ;----------------------------------------------------------------------- ; @@ -47,6 +49,11 @@ ; or use the I2C pins for other purposes. ;#define I2C_SUPPORT +; Support for the SC16IS740 I2C UART chip is included automatically, when +; I2C support is enabled. Uncomment and set to 0 if you don't want support for +; the SC16IS740 I2C UART chip. +;#define I2C_UART_SUPPORT 1 + ; Emulate Z80 cpu if 1, 8080 otherwise. ; ;#define EM_Z80 1 @@ -72,23 +79,25 @@ ;----------------------------------------------------------------------- ;Debugging aids -.equ BOOTWAIT = 1 -.equ MEMTEST = 1 -.equ MEMFILL = 1 /* Fill DRAM */ -.equ SRAM_FILL = 1 /* Fill unused SRAM */ -.equ MMC_DEBUG = 0 /* Increase for more debugging */ -.equ MMC_DEBUG_RDW = 0 -.equ DSKSEL_DEBUG = 0 -.equ DISK_DEBUG = 0 /* 1 = BOOT/HOME debug, 2 = +R/W debug */ -.equ HOSTRW_DEBUG = 0 -.equ FAT16_DEBUG = 0 -.equ FAT16_DBG_FAT = 0 -.equ HEAP_DEBUG = 0 -.equ PORT_DEBUG = 0 -.equ INS_DEBUG = 0 -.equ STACK_DBG = 0 -.equ PRINT_PC = 0 -.equ TIMER_DEBUG = 0 +.equ BOOTWAIT = 1 +.equ MEMTEST = 1 +.equ MEMFILL = 1 /* Fill DRAM */ +.equ SRAM_FILL = 1 /* Fill unused SRAM */ +.equ MMC_DEBUG = 0 /* Increase for more debugging */ +.equ MMC_DEBUG_RDW = 0 +.equ DSKSEL_DEBUG = 0 +.equ DISK_DEBUG = 0 /* 1 = BOOT/HOME debug, 2 = +R/W debug */ +.equ HOSTRW_DEBUG = 0 +.equ FAT16_DEBUG = 0 +.equ FAT16_DBG_FAT = 0 +.equ HEAP_DEBUG = 0 +.equ PORT_DEBUG = 0 +.equ INS_DEBUG = 0 +.equ STACK_DBG = 0 +.equ PRINT_PC = 0 +.equ TIMER_DEBUG = 0 +.equ I2C_STATE_DEBUG = 0 +.equ MEMDUMP_DEBUG = 1 ;----------------------------------------------------------------------- ; Z80/8080 Virtual Ports @@ -114,11 +123,12 @@ #define printTimerCmd 15 #define uptimeCmd 16 -#define DEBUGPORT 0x4F +#define MEMDUMPPORT 0x09 +#define DEBUGPORT 0x4F -#define startTraceCmd 0x01 /* 'OUT (DEBUGPORT),startTraceCmd' starts tracing */ -#define stopTraceCmd 0x00 -#define PrintStackCmd 0x02 +#define startTraceCmd 0x01 /* 'OUT (DEBUGPORT),startTraceCmd' starts tracing */ +#define stopTraceCmd 0x00 +#define PrintStackCmd 0x02 ; Virtual I2C Interface #define I2CSTAT 0x05 @@ -135,6 +145,8 @@ #define ADCBGL 0x20 /* Read 1.1V Bandgap, 10 bit */ #define ADCBGH 0x21 /* Read 1.1V Bandgap, 10 bit */ +; ISC16IS740 UART +#define I2C_UART 0x50 /* ISC16IS740 base port */ ; Port-Expander PCF8574 #define PORT 0x80 @@ -156,10 +168,21 @@ #define REFR_RATE 64000 /* dram refresh rate in cycles/s. */ /* Most drams need 1/15.6µs. */ #define RXBUFSIZE 128 /* USART recieve buffer size. Must be power of 2 */ -#define TXBUFSIZE 32 /* USART transmit buffer size. Must be power of 2 */ +.if SRAM_SIZE > 1024 + .equ TXBUFSIZE = 128 /* USART transmit buffer size. Must be power of 2 */ +.else + .equ TXBUFSIZE = 32 /* USART transmit buffer size. Must be power of 2 */ +.endif + +.if SRAM_SIZE > 1024 + .equ FAT16_FATBUF = 1 +.else + .equ FAT16_FATBUF = 0 +.endif + #define I2C_CLOCK 100000 /* 100kHz */ -#define I2C_BUFSIZE 17 /* largest message size including address byte (SLA) */ +#define I2C_BUFSIZE 66 /* largest message size + slave address (SLA) + subaddress */ #define MMC_SPI2X 1 /* 0 = SPI CLK/4, 1 = SPI CLK/2 */ @@ -206,6 +229,13 @@ #ifndef ADC_SUPPORT #define ADC_SUPPORT 1 #endif +#ifndef I2C_UART_SUPPORT + #define I2C_UART_SUPPORT I2C_SUPPORT +#endif +#if I2C_UART_SUPPORT + #define SC16IS740_ADDR 0x90 /* SC16IS740 I2C address. (8bit, A0=VDD, A1=VDD) */ + #define SC16IS740_CLOCK 9216000 /* */ +#endif #ifndef EM_Z80 #define EM_Z80 1 /* Emulate Z80 if true, else 8080 */ @@ -234,6 +264,9 @@ #define TESTVERSION 0 #endif +#define TC_1MS (F_CPU/1000) +#define TC_1US (F_CPU/1000000) + ;----------------------------------------------------------------------- ; Port declarations @@ -279,11 +312,14 @@ .equ RAM_CAS = 1 .equ RAM_OE = 2 .equ RAM_W = 3 +.equ SDA = 4 +.equ SCL = 5 .equ P_RAS = PORTC .equ P_CAS = PORTC .equ P_OE = PORTC .equ P_W = PORTC +.equ P_I2C = PORTC #else /* 4 bit RAM, hardware uart */ @@ -424,7 +460,7 @@ #define CPUSTR "8080" #endif #if TESTVERSION - #define TESTSTR "Test" + #define TESTSTR " Test" #else #define TESTSTR "" #endif diff --git a/avr/dsk_fat16.asm b/avr/dsk_fat16.asm index aeb1e5a..b8b79f5 100644 --- a/avr/dsk_fat16.asm +++ b/avr/dsk_fat16.asm @@ -19,7 +19,7 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: dsk_fat16.asm 153 2014-11-12 12:59:42Z rapid $ ; ; ============================================================================ @@ -84,14 +84,14 @@ fat_clust_ptr: .byte 4 ; sector of last real cluster .equ o_fat_clust_offset= 17 .equ o_fat_clust_ptr = 18 -.if SRAM_SIZE > 1024 +.if FAT16_FATBUF fat_last_fatsect: .byte 1 .equ o_fat_last_fatsect = 22 fat_buf: .byte 512 -.endif +.endif /* FAT16_FATBUF */ ; ############################################################################ ; Start of Code Segment @@ -145,7 +145,7 @@ fat_reset_cache: std y+o_fat_log_clust ,_255 std y+o_fat_log_clust+1,_255 std y+o_fat_last_dsk ,_255 -.if SRAM_SIZE > 1024 +.if FAT16_FATBUF std y+o_fat_last_fatsect,_255 .endif @@ -802,7 +802,7 @@ fat_next_phsy_clust: lsl zl rol zh -.if SRAM_SIZE > 1024 +.if FAT16_FATBUF ; Check, if required fat sector allready in buffer @@ -850,6 +850,7 @@ fat_phys_1: ldd temp, z+0 ldd temp2,z+1 ldiw y,fat_vars + .else ldd xl,y+o_fat_ptr2fat ;get FAT start @@ -864,7 +865,9 @@ fat_phys_1: lcall mmcReadWord movw temp,z ldiw y,fat_vars -.endif + +.endif /* FAT16_FATBUF */ + pop xh pop xl diff --git a/avr/dsk_fsys.asm b/avr/dsk_fsys.asm index 057d523..0081468 100644 --- a/avr/dsk_fsys.asm +++ b/avr/dsk_fsys.asm @@ -283,7 +283,7 @@ dskDiskCheck: ldi temp,1 lcall clockput .endif - rcall mgr_init_partitions ;disk chanched? + rcall mgr_init_partitions ;disk changed? push temp .if 0 ldi temp2,0x40 @@ -1003,7 +1003,7 @@ dskdbgboot: dskdbg1: ldd temp,y+o_seekdsk subi temp,-('A') - rcall uartputc + lcall uartputc printstring ": trk " ldd temp2,y+o_seektrk+1 ldd temp,y+o_seektrk @@ -1385,7 +1385,7 @@ dsk_writehost: breq dsk_hstwr_err ldiw z,hostbuf - rcall mmcWriteSect + lcall mmcWriteSect tst temp brne dsk_hstwr_err diff --git a/avr/i2c.asm b/avr/i2c.asm index ee20d06..66ce006 100644 --- a/avr/i2c.asm +++ b/avr/i2c.asm @@ -18,11 +18,12 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: i2c.asm 242 2015-12-11 16:05:52Z rapid $ ; #if I2C_SUPPORT + /* General TWI Master status codes */ #define TWI_START 0x08 /* START has been transmitted */ #define TWI_REP_START 0x10 /* Repeated START has been transmitted */ @@ -77,11 +78,16 @@ ; ;---------------------------------------------------------------------- ; -;i2c_result < 0 Error. -; -1 general/unknown error -; -2 time out -; >= 0 No error -; > 0 status tbd. +;i2c_result +; +; 0b10000000 Busy (Transmission in progress) +; 0b01000000 Timeout +; 0b00010000 Read after Write +; 0b00001000 Start transmitted +; 0b00000100 Slave acknowledged address +; 0b00000010 Data byte(s) transmitted/received +; 0b00000001 Transmission completed +; ; ;---------------------------------------------------------------------- @@ -92,15 +98,18 @@ i2ci_idx: .byte 1 i2c_result: .byte 1 -i2c_bufcnt: +i2c_txcnt: + .byte 1 +i2c_rxcnt: .byte 1 i2c_buf: .byte I2C_BUFSIZE .equ oi2ci_idx = 0 .equ oi2c_result = 1 - .equ oi2c_bufcnt = 2 - .equ oi2c_buf = 3 + .equ oi2c_txcnt = 2 + .equ oi2c_rxcnt = 3 + .equ oi2c_buf = 4 ;------------------------------------------------------------------ @@ -112,14 +121,19 @@ i2c_buf: push temp in temp,sreg push temp + inm8 temp,TWSR +.if I2C_STATE_DEBUG + push temp +.endif push temp2 + push temp3 push zh push zl ldiw z,i2c_var ldd temp2,z+oi2ci_idx + ldd temp3,z+oi2c_result - inm8 temp,TWSR cpi temp,TWI_START breq i2ci_START cpi temp,TWI_REP_START @@ -128,21 +142,31 @@ i2c_buf: breq i2ci_MTX_ADR_ACK cpi temp,TWI_MTX_DATA_ACK breq i2ci_MTX_DATA_ACK + cpi temp,TWI_MTX_DATA_NACK + breq i2ci_MTX_DATA_NACK cpi temp,TWI_MRX_ADR_ACK breq i2ci_MRX_ADR_ACK cpi temp,TWI_MRX_DATA_ACK breq i2ci_MRX_DATA_ACK cpi temp,TWI_MRX_DATA_NACK breq i2ci_MRX_DATA_NACK + rjmp i2ci_default -i2ci_START: -i2ci_REP_START: - clr temp2 ;reset buffer pointer -i2ci_MTX_ADR_ACK: -i2ci_MTX_DATA_ACK: - ldd temp,z+oi2c_bufcnt - cp temp2,temp ;all bytes tranmited? +i2ci_REP_START: ;Repeated START has been transmitted + cbr temp3,0b00010000 +i2ci_START: ;START has been transmitted + clr temp2 ;reset buffer index + ori temp3,0b10001000 + rjmp i2ci_11 +i2ci_MTX_ADR_ACK: ;SLA+W has been transmitted and ACK received + ori temp3,0b00000100 + rjmp i2ci_11 +i2ci_MTX_DATA_ACK: ;Data byte has been transmitted and ACK received + ori temp3,0b00000010 +i2ci_11: + ldd temp,z+oi2c_txcnt + cp temp2,temp ;all bytes transmited? brsh i2ci_12 ; yes add zl,temp2 adc zh,_0 @@ -152,18 +176,31 @@ i2ci_MTX_DATA_ACK: ldi temp,(1< + sts i2c_buf,temp + ldi temp,(1< + std y+oi2c_buf,temp ; Enable TWI, TWI int and initiate start condition ldi temp,(1<. ; -; $Id$ +; $Id: init.asm 241 2015-12-10 09:38:25Z rapid $ ; #define REFR_PRE 8 /* timer prescale factor 1/8 */ @@ -66,10 +66,15 @@ cp_l: lpm xh,z+ out PORTD,_255 ;all pins high (enables pullup on input ports) out PORTB,_255 out PORTC,_255 - out DDRD,_255 ; all outputs - out DDRB,_255 - out DDRC,_255 - cbi P_RXD-1,RXD ; RXD pin is input + out DDRD,_255 ; PD all outputs +#if I2C_SUPPORT + ldi temp,~((1<. ; -; $Id$ +; $Id: macros.inc 241 2015-12-10 09:38:25Z rapid $ ; ;------------------------------------------------ @@ -209,6 +209,18 @@ .endif .endm +;------------------------------------------------ +; Make string. +; makestring "String" + +.macro makestring + .if strlen(@0) % 2 + .db @0,0 + .else + .db @0,0,0 + .endif +.endm + ;------------------------------------------------ ; Print string. ; printstring "String" diff --git a/avr/svnrev.inc b/avr/svnrev.inc index bf22bdf..ee10318 100644 --- a/avr/svnrev.inc +++ b/avr/svnrev.inc @@ -2,17 +2,17 @@ * (http://www.compuphase.com/svnrev.htm). * You should not modify it manually, as it may be re-generated. * - * $Revision: 215$ - * $Date: 2013-04-27$ + * $Revision: 242M$ + * $Date: 2015-12-11$ */ #ifndef SVN_REV_H #define SVN_REV_H -#define SVN_REV 215 -#define SVN_REVSTR "215" -#define SVN_REVDATE "2013-04-27" -#define SVN_REVSTAMP 20130427L -#define SVN_REVMODIFIED 0 +#define SVN_REV 242 +#define SVN_REVSTR "242M" +#define SVN_REVDATE "2015-12-11" +#define SVN_REVSTAMP 20151211L +#define SVN_REVMODIFIED 6 #endif /* SVN_REV_H */ diff --git a/avr/sw-uart.asm b/avr/sw-uart.asm index 7c59245..3fa59e1 100644 --- a/avr/sw-uart.asm +++ b/avr/sw-uart.asm @@ -525,6 +525,7 @@ sputc_l: cpi temp,TXBUFSIZE ; brsh sputc_l ;} while (txcount >= TXBUFSIZE) + cli ldi zl,low(txfifo) ; ldi zh,high(txfifo) ; lds temp,txidx_w ; @@ -535,7 +536,7 @@ sputc_l: sts txidx_w,temp ; txidx_w = ++txidx_w % TXBUFSIZE pop temp ; st z,temp ; txfifo[txidx_w] = char - cli +; cli lds zh,txcount inc zh sts txcount,zh diff --git a/avr/timer.asm b/avr/timer.asm index 4b25230..e64d081 100644 --- a/avr/timer.asm +++ b/avr/timer.asm @@ -17,7 +17,7 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: timer.asm 153 2014-11-12 12:59:42Z rapid $ ; .dseg @@ -80,7 +80,7 @@ clock: push zh inm8 zl,OCR1BL inm8 zh,OCR1BH - addiw z,F_CPU/1000 + addiw z,TC_1MS outm8 OCR1BH,zh outm8 OCR1BL,zl @@ -406,8 +406,8 @@ rtc_get: rcall i2c_write ldi temp2,3 rcall i2c_read ;get year (stored in RTC-RAM addr. 10h) - tst temp - brmi rtc_get_e ;i2c error + andi temp,0x3 + breq rtc_get_e ;i2c error ldd temp3,z+1 ;save year ldd xl, z+2 @@ -417,8 +417,8 @@ rtc_get: rcall i2c_write ldi temp2,6 rcall i2c_read - tst temp - brmi rtc_get_e + andi temp,0x3 + breq rtc_get_e ;i2c error mov temp2,xl ;year century ldd temp,z+4 ;get year diff --git a/avr/utils.asm b/avr/utils.asm index bd0d8d0..99c9e6f 100644 --- a/avr/utils.asm +++ b/avr/utils.asm @@ -17,7 +17,7 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: utils.asm 93 2014-01-03 16:32:32Z rapid $ ; @@ -265,20 +265,19 @@ stack_search_found: .endif +.if MEMDUMP_DEBUG ;----------------------------------------------------------------------- ; Prints 16 bytes RAM, pointed to by Z in hex. -#if 0 - dbg_hexdump_line: ;Address in z push temp2 push temp - printnewline +; printnewline movw temp,z ;Print address rcall printhexw + printstring ":" ldi temp2,16 ;16 byte per line - rcall printspace dbg_hdl1: cpi temp2,8 brne PC+2 @@ -297,12 +296,12 @@ dbg_hdl1: dbg_hdl2: ld temp,z+ cpi temp,' ' - brlo dbg_hdpd + brlo dbg_hdlpd cpi temp,0x7F - brlo dbg_hdp -dbg_hdpd: + brlo dbg_hdlp +dbg_hdlpd: ldi temp,'.' -dbg_hdp: +dbg_hdlp: rcall uartputc dec temp2 brne dbg_hdl2 @@ -310,8 +309,49 @@ dbg_hdp: rcall printspace pop temp pop temp2 + printnewline ret -#endif + + +; Prints temp2 bytes RAM, pointed to by Z in hex. + +dbg_hexdump: ;Address in z + push temp + push temp2 +; printnewline + movw temp,z ;Print address + rcall printhexw + printstring ":" + pop temp2 + push temp2 +dbg_hd1: + rcall printspace + ld temp,z+ + rcall printhex + dec temp2 + brne dbg_hd1 + pop temp2 + sub zl,temp2 + sbc zh,_0 + rcall printspace + rcall printspace +dbg_hd2: + ld temp,z+ + cpi temp,' ' + brlo dbg_hdpd + cpi temp,0x7F + brlo dbg_hdp +dbg_hdpd: + ldi temp,'.' +dbg_hdp: + rcall uartputc + dec temp2 + brne dbg_hd2 + pop temp + printnewline + ret + +.endif ;----------------------------------------------------------------------- ; Print a line with the 8080/Z80 registers diff --git a/avr/virt_ports.asm b/avr/virt_ports.asm index e9e7ddc..ca35d01 100644 --- a/avr/virt_ports.asm +++ b/avr/virt_ports.asm @@ -17,7 +17,7 @@ ; You should have received a copy of the GNU General Public License ; along with avrcpm. If not, see . ; -; $Id$ +; $Id: virt_ports.asm 242 2015-12-11 16:05:52Z rapid $ ; @@ -37,10 +37,20 @@ ;------------------------ Virtual I2C interface -------------------------- ;05 5 out - Control Port: 1 = Start read operation ; 2 = Start write operation -;05 5 in - Status of last Transfer: 0 = ok, else fail +; 3 = Write 1 byte subaddress, then read +;05 5 in - Status of last Transfer ;06 6 in/out - Number of bytes to transfer, including Slave address ;07,08 7,8 in/out - Read/Write address low/high ; +;------------------------ Debugging -------------------------------------- +;09 out - MEM dump: Number of bytes to print +;0A,0B in/out - MEM dump: Start address +; +;------------------------ Version Information ---------------------------- +;0C out - 1 = Read VMAJOR +; 2 = Read VMINOR +; 4 = Read Version String +; ;------------------------ Disk I/O --------------------------------------- ;0D,0E 13,14 in/out - Set address of Bios Controll Block ;0F 15 in/out - Disk select @@ -76,9 +86,34 @@ ;40 64-71 in/out - Timer/Clock control. ;41-46 ; -;47-4D clock - BCD format: ss, mm, hh, DD, MM, YYl, YYh +;47-4D in/out - clock in BCD format: ss, mm, hh, DD, MM, YYl, YYh +; +;------------------------ Debugging -------------------------------------- +;4F out - Debug: start/stop trace, print stack, ... ; -;4F debug - start/stop trace, print stack, ... +;------------------------ ISC16IS740 UART -------------------------------- +;50 RHR in Receive Holding +;50 THR out Transmit Holding +;51 IER in/out Interrupt Enable +;52 IIR in Interrupt Identification +;52 FCR out FIFO Control +;53 LCR in/out Line Control +;54 MCR in/out Modem Control +;55 LSR in Line Status +;56 MSR in Modem Status +;57 SPR in/out Scratchpad +;56 TCR in/out Transmission Control +;57 TLR in/out Trigger Level +;58 TXLVL in Transmit FIFO Level +;59 RXLVL in Receive FIFO Level +;5F EFCR in/out Extra Features +;50 DLL in/out divisor latch LSB +;51 DLH in/out divisor latch MSB +;52 EFR in/out Enhanced Feature +;54 XON1 in/out Xon1 word +;55 XON2 in/out Xon2 word +;56 XOFF1 in/out Xoff1 word +;57 XOFF2 in/out Xoff2 word ; ;------------------------ Ports ------------------------------------------ ;80-87 in/out - Port-Expander PCF8574 (max. 8 Chips) @@ -124,10 +159,6 @@ vport_tbl: .dw clockget .dw clockput - .db DEBUGPORT,1 - .dw dbg_stat - .dw dbg_ctrl - #if I2C_SUPPORT .db I2CCTRL,1 .dw vi2c_stat_get @@ -137,6 +168,12 @@ vport_tbl: .dw vi2c_param_get .dw vi2c_param_set +#if I2C_UART_SUPPORT + .db I2C_UART,16 + .dw SC16IS740_in + .dw SC16IS740_out +#endif + .db PORT,8 .dw pcf8574_in .dw pcf8574_out @@ -150,6 +187,19 @@ vport_tbl: .dw adc_readvcc .dw vport_out_dummy #endif + .db DEBUGPORT,1 + .dw dbg_stat + .dw dbg_ctrl + +.if MEMDUMP_DEBUG + .db MEMDUMPPORT,3 + .dw dbg_dump_rd + .dw dbg_dump +.endif + .db 0x0C,1 + .dw version_get + .dw version_ctrl + .db 0,0 ; Stop mark ;--------------------------------------------------------------------- @@ -291,6 +341,8 @@ conStatus: ret +;--------------------------------------------------------------------- + dbgOut: printnewline printstring "Debug: " @@ -309,6 +361,113 @@ dbg_ctrl: .endif ret +;--------------------------------------------------------------------- + +.if MEMDUMP_DEBUG + + .dseg + +dbg_dump_addr: + .byte 2 + + + .cseg + +dbg_dump_rd: + cpse temp3,_0 + rjmp dbg_dump_rdad + ldi temp,0 + ret + +dbg_dump_rdad: + dec temp3 + brne dbg_dump_rdad1 + lds temp,dbg_dump_addr+0 + ret +dbg_dump_rdad1: + lds temp,dbg_dump_addr+1 + ret + + +dbg_dump: + cpse temp3,_0 + rjmp dbg_dump_store + + mov temp3,temp + ldsw z,dbg_dump_addr + + tst temp3 + breq dbg_dumpl_1 +dbg_dumpl: + cpi temp3,16 + brlo dbg_dump_u16 +dbg_dumpl_1: + lcall dbg_hexdump_line + subi temp3,16 + adiw z,16 + rjmp dbg_dumpl + +dbg_dump_u16: + tst temp3 + breq dbg_dump_e + mov temp2,temp3 + lcall dbg_hexdump +dbg_dump_e: + ret + +dbg_dump_store: + dec temp3 + brne dbg_dump_st1 + sts dbg_dump_addr+0,temp + ret +dbg_dump_st1: + sts dbg_dump_addr+1,temp + ret + +.endif + +;--------------------------------------------------------------------- + + .dseg +vers_cmd: + .byte 1 +vers_pstr: + .byte 2 + + .cseg +version_ctrl: + sts vers_cmd,temp + cpi temp,4 + brne vc_e + + ldiw z,version_string*2 + stsw vers_pstr,z +vc_e: + ret + +version_get: + lds temp2,vers_cmd + ldi temp,0 + cpi temp2,0 + breq vc_g_e + ldi temp,VMAJOR + cpi temp2,1 + breq vc_g_e + ldi temp,VMINOR + cpi temp2,2 + breq vc_g_e + ldi temp,0xFF + cpi temp2,4 + brne vc_g_e + + ldsw z,vers_pstr + lpm temp,z+ + tst temp + breq vc_g_e + stsw vers_pstr,z + +vc_g_e: + ret ;--------------------------------------------------------------------- diff --git a/cpm/utils/I2C_UART_DEMO.MAC b/cpm/utils/I2C_UART_DEMO.MAC new file mode 100644 index 0000000..c9c888d --- /dev/null +++ b/cpm/utils/I2C_UART_DEMO.MAC @@ -0,0 +1,50 @@ + +;----------------------------- ISC16IS740 UART ------------------------------- +I2C_UART_PORT equ 50H + +I2C_UART_RHR equ I2C_UART_PORT+00H ;R Receive Holding +I2C_UART_THR equ I2C_UART_PORT+00H ;W Transmit Holding +I2C_UART_IER equ I2C_UART_PORT+01H ;R/W Interrupt Enable +I2C_UART_FCR equ I2C_UART_PORT+02H ;W FIFO Control +I2C_UART_IIR equ I2C_UART_PORT+02H ;R Interrupt Identification +I2C_UART_LCR equ I2C_UART_PORT+03H ;R/W Line Control +I2C_UART_MCR equ I2C_UART_PORT+04H ;R/W Modem Control +I2C_UART_LSR equ I2C_UART_PORT+05H ;R Line Status +I2C_UART_MSR equ I2C_UART_PORT+06H ;R Modem Status +I2C_UART_SPR equ I2C_UART_PORT+07H ;R/W Scratchpad +I2C_UART_TCR equ I2C_UART_PORT+06H ;R/W Transmission Control +I2C_UART_TLR equ I2C_UART_PORT+07H ;R/W Trigger Level +I2C_UART_TXLVL equ I2C_UART_PORT+08H ;R Transmit FIFO Level +I2C_UART_RXLVL equ I2C_UART_PORT+09H ;R Receive FIFO Level +I2C_UART_EFCR equ I2C_UART_PORT+0FH ;R/W Extra Features +I2C_UART_DLL equ I2C_UART_PORT+00H ;R/W divisor latch LSB +I2C_UART_DLH equ I2C_UART_PORT+01H ;R/W divisor latch MSB +I2C_UART_EFR equ I2C_UART_PORT+02H ;R/W Enhanced Feature +I2C_UART_XON1 equ I2C_UART_PORT+04H ;R/W Xon1 word +I2C_UART_XON2 equ I2C_UART_PORT+05H ;R/W Xon2 word +I2C_UART_XOFF1 equ I2C_UART_PORT+06H ;R/W Xoff1 word +I2C_UART_XOFF2 equ I2C_UART_PORT+07H ;R/W Xoff2 word + + +;----------------------------------------------------------------------------- +; Output character in C +; Return with character in C and A + +i2c_uart_out: + IN A,(I2C_UART_LSR) + AND 20H + JR Z,i2c_uart_out ; wait till ready + LD A,C + OUT (I2C_UART_THR),A + RET + +;----------------------------------------------------------------------------- +; Get character from I2C UART +; Return character in A + +i2c_uart_in: + IN A,(I2C_UART_LSR) + AND 01H + JR Z,i2c_uart_in ; wait till ready + IN (I2C_UART_RHR),A + RET -- 2.39.2