📄 sisi2c.inc
字号:
;------------------------------------------------------------------------------;
; SIS_READ_I2C_DATA_BLOCK ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = device register index (command code) ;
; Output: ZF = 0 : fail ;
; ZF = 1 : success and CL = byte data read ;
; Modified: CL ;
;------------------------------------------------------------------------------;
public sis_read_i2c_data_block
sis_read_i2c_data_block proc near
pusha
sti
;; Don't Destory CX
;Reset Host Status Registers
call sis_clear_hst_sts
;Clock Generator Address = D3h
or dx,04h
lea si,SlaveAddress
mov al,ds:[si]
or al,01h
out dx,al
jmp short $+2
jmp short $+2
; Write 00h to Host Command Register
and dl,0f0h
or dx,05h
mov al,000h ;start Byte0
out dx,al
jmp short $+2
jmp short $+2
; Number Of Bytes to Program (07h)
and dl,0f0h
or dx,07h
mov al,80h
out dx,al
jmp short $+2
jmp short $+2
; Start Block Write Command
and dl,0f0h
or dx,03h
mov al,15h;;;;;;;;;;
out dx,al
jmp short $+2
jmp short $+2
call sischeck_rbdsx
and dl,0f0h
or dx,07h
in al,dx
cmp al,0
jz sisskip_program_loopr
movzx ax,al
lea si,ReadDataRow
mov cl,ds:[si]
movzx cx,cl
sisloop_block_row:
push cx
mov cx,2
start_block_read_1:
push cx
mov cx,8
lea si,SmbusAddress
mov dx,ds:[si]
or dx,08h
start_block_read_sis:
push cx
push dx
in al,dx
call DisplayDataAttribute
mov al,' '
call DisplayChar
jmp $+2
jmp $+2
call sis_check_send_done
pop dx
inc dx
pop cx
loop start_block_read_sis
pop cx
loop start_block_read_1
lea si,crlf
call DisplayString
call GetCursor
mov dl,ValueStartCol
call SetCursor
pop cx
loop sisloop_block_row
sisskip_program_loopr:
popa
ret
sis_read_i2c_data_block endp
;------------------------------------------------------------------------------;
sischeck_rbdsx:
mov cx,12
sisrdd_1:
out 0e0h,al
jmp $+2
loop sisrdd_1
and dl,0f0h
mov cx,2000h
sischeck_rbds1:
in al,dx
jmp short $+2
test al,80h
out 0e0h,al
loopz short sischeck_rbds1
ret
;------------------------------------------------------------------------------;
sis_clear_hst_sts:
lea si,SmbusAddress
mov dx,ds:[si]
mov al,0ffh
out dx,al
@@:
out 0e0h,al
out 0e0h,al
out 0e0h,al
out 0e0h,al
out 0e0h,al
out 0e0h,al
dec al
jnz short @B
@@:
in al,dx
out 0e0h,al
out 0e0h,al
out 0e0h,al
;out 80h,al
test al,80h
jz short @B ;zr, bus not ready
ret
;------------------------------------------------------------------------------;
; SIS_WRITE_I2C_DATA_BLOCK ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = device register index (command code) ;
; Output: ZF = 0 : fail ;
; ZF = 1 : success and CL = byte data read ;
; Modified: CL ;
;------------------------------------------------------------------------------;
public sis_write_i2c_data_block
sis_write_i2c_data_block proc near
;Reset Host Status Registers
push cx
push si
call sis_clear_hst_sts
;Clock Generator Address = D2h
lea si,SmbusAddress
mov dx,ds:[si]
or dx,04h
lea si,SlaveAddress
mov al,ds:[si]
out dx,al
jmp $+2
; Write 00h to Host Command Register
and dl,0f0h
or dx,05h
mov al,000h
out dx,al
jmp short $+2
jmp short $+2
; Number Of Bytes to Program (06h)
and dl,0f0h
or dx,07h
call GetBlockSendCounts
out dx,al
jmp short $+2
jmp short $+2
; Write Byte 0 Control Register
mov dx,(ValueStartCol+ValueStartRow)
call CalaFixedCursorposn
call GetFixCursorValue
mov al,bl
lea si,SmbusAddress
mov dx,ds:[si]
and dl,0f0h
or dx,08h
out dx,al
jmp short $+2
jmp short $+2
; call sis_clear_hst_sts
; Start Block Write Command
and dl,0f0h
or dx,03h
mov al,15h
out dx,al
jmp short $+2
jmp short $+2
call sischeck_rbdsx
mov cx, 12*20 ; 3ms
loop $
mov cx,WriteBlockRow
mov dx,(ValueStartCol+ValueStartRow)+0003h
sispost_start_block_write_row:
push cx
cmp cx,WriteBlockRow
mov cx,15
jz sispost_start_block_write
inc cx
;;; [KenWang] 02/28/2002 --->>>>>>
mov ax,cx
mov bl,8
div bl
movzx cx,al
sispost_start_block_write0:
push cx
movzx cx,ah
lea si,SmbusAddress
mov dx,ds:[si]
and dl,0f0h
or dx,08h
lea si,SmbusBDataPort
mov ds:[si],dx
;;; [KenWang] 02/28/2002 <<<<<<---
sispost_start_block_write:
push cx
push dx
call CalaFixedCursorposn
call GetFixCursorValue
mov al,bl
;;; [KenWang] 02/28/2002 --->>>>>>
lea si,SmbusBDataPort
mov dx,ds:[si]
;;; [KenWang] 02/28/2002 <<<<<<---
out dx,al
jmp $+2
jmp $+2
call sis_check_send_done
pop dx
add dl,3
;;; [KenWang] 02/28/2002 --->>>>>>
lea si,SmbusBDataPort
mov ax,ds:[si]
inc ax
mov ds:[si],ax
;;; [KenWang] 02/28/2002 <<<<<<---
pop cx
loop sispost_start_block_write
;;; [KenWang] 02/28/2002 --->>>>>>
pop cx
loop sispost_start_block_write0
;;; [KenWang] 02/28/2002 --->>>>>>
inc dh
mov dl,ValueStartCol
pop cx
loop sispost_start_block_write_row
call sis_clear_hst_sts
sispost_skip_program_loop:
pop si
pop cx
ret
sis_write_i2c_data_block endp
;------------------------------------------------------------------------------;
; SISREAD_I2C_DATA_BYTE ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = device register index (command code) ;
; Output: ZF = 0 : fail ;
; ZF = 1 : success and CL = byte data read ;
; Modified: CL ;
;------------------------------------------------------------------------------;
public SISread_i2c_data_byte
SISread_i2c_data_byte proc near
; pushf
push ax
push dx
push bx
cli
or ah,01h ; Read Command
call SISreset_smbus_host
mov al,12h ; byte access
call SISaccess_i2c_device
mov cl,0ffh
jnz SISread_i2c_byte_error
and dl,0f0h
or dl,08h ;base + 08h
in al,dx
mov cl,al
cmp sp,sp ;ZF = 1 for success
SISread_i2c_byte_error:
pop bx
pop dx
pop ax
; popf
ret
SISread_i2c_data_byte endp
;------------------------------------------------------------------------------;
; SISWRITE_I2C_DATA_BYTE ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = device register index (command code) ;
; CL = byte data to write ;
; Output: ZF = 0 : fail ;
; ZF = 1 : success ;
; Modified: nothing ;
;------------------------------------------------------------------------------;
public SISwrite_i2c_data_byte
SISwrite_i2c_data_byte proc near
; pushf
push ax
push dx
push bx
cli
call SISreset_smbus_host
and dl,0f0h
or dl,08h ;base + 05h
mov al,cl
out dx,al
jmp $+2
jmp $+2
mov al,12h ;byte access
and ah,0feh
call SISaccess_i2c_device
jnz SISwrite_i2c_byte_error
cmp sp,sp ;ZF = 1 for success
SISwrite_i2c_byte_error:
pop bx
pop dx
pop ax
; popf
ret
SISwrite_i2c_data_byte endp
;------------------------------------------------------------------------------;
; SISACCESS_I2C_DEVICE ;
;------------------------------------------------------------------------------;
; Input: AH = Slave address ;
; AL = 48h/4ch for byte/word ;
; DX = sMBUS ADDRESS
; Output: ZF = 0 : fail ;
; ZF = 1 : success ;
; Modified: AL, DX ;
;------------------------------------------------------------------------------;
SISaccess_i2c_device proc near
xchg al,ah
lea si,SmbusAddress
mov dx,ds:[si]
or dl,04h ;base + 04h
out dx,al ;Program the Address
jmp $+2
jmp $+2
xchg al,ah
and dl,0f0h
or dl,03h ;base + 03h
out dx,al
out 0e0h,al
jmp $+2
jmp $+2
push cx
xor cx,cx
mov cx,8000h
and dl,0f0h ;base + 00h
SIScheck_host_status:
in al,dx
out 0e0h,al
out 0e0h,al
jmp $+2
jmp $+2
dec cx
jz SIStime_out
test al,00000010b ;error?
jnz SISaccess_i2c_device_error
test al, 018h ;if not complete then wait i2c data complete
jz short SIScheck_host_status
out dx,al ;Reset Host Status Registers
cmp sp,sp ;ZF = 1 for success
SISaccess_i2c_device_error:
pop cx
ret
SIStime_out:
or al,0ffh
jmp short SISaccess_i2c_device_error
SISaccess_i2c_device endp
;------------------------------------------------------------------------------;
; SISRESET_SMBUS_HOST ;
;------------------------------------------------------------------------------;
; Input: AL = command byte ;
; Output: nothing ;
; Modified: nothing ;
;------------------------------------------------------------------------------;
SISreset_smbus_host proc near
push ax
push cx
lea si,SmbusAddress
mov dx,ds:[si]
mov al,0ffh
out dx,al ;Reset Host Status Registers
jmp $+2
out dx,al ;Reset Host Status Registers
jmp $+2
out dx,al ;Reset Host Status Registers
jmp $+2
add dl,03h
mov al,20h
out dx,al ;Stop all SMBus operation
pop cx
pop ax
sub dl,03h
add dl,05h ;base + 05h
out dx,al ;Program the index
jmp $+2
jmp $+2
ret
SISreset_smbus_host endp
;------------------------------------------------------------------------------;
public sis_check_send_done
sis_check_send_done:
push dx
push cx
push si
; Clear Byte Done Status for Next Transmission.
lea si,SmbusAddress
mov dx,ds:[si]
mov al,0ffh
out dx,al
jmp short $+2
jmp short $+2
mov cx,100h
sis_check_byte_done_sts_post:
push cx
mov cx,6
sis_wait_cls_post:
in al,80h
jmp $+2
out 80h,al
jmp $+2
in al,80h
jmp $+2
loop sis_wait_cls_post
pop cx
in al,dx
test al,80h
jnz sis_byte_done_post
loop sis_check_byte_done_sts_post
sis_byte_done_post:
pop si
pop cx
pop dx
ret
;---------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -