⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spdab.asm

📁 X86 GX1 BOOTLOAD代码 ,支持WINCE操作系统!
💻 ASM
字号:
;**************************************************************************
;*
;*  SPDAB.ASM
;*
;*  Copyright (c) 1998 - 2000 by National Semiconductor Corporation
;*  All rights reserved.
;*
;*  Function:
;*    Serial Presence Detect with I2C Interface based on Access.Bus of SIO
;*
;*  $Revision: 1 $
;*
;**************************************************************************

	.486P

	INCLUDE DEF.INC
	INCLUDE MACROS.INC
	INCLUDE PORT80.INC
	INCLUDE CPU.INC
	INCLUDE MPC.INC
	INCLUDE NSSIO.INC
	INCLUDE OPTIONS.INC
	INCLUDE BDCFG.INC

_TEXT SEGMENT PUBLIC use16 'CODE'

	EXTERN	ReadABData:NEAR
	EXTERN	WriteABData:NEAR
	EXTERN	StopSignalABData:NEAR
	EXTERN	StartSignalABData:NEAR
	EXTERN	SetACKABData:NEAR
	EXTERN	InitAB:NEAR
	EXTERN	SetOffsetAB:NEAR

	INSTALL_NSSIO SC1x00
;**************************************************************************
;*
;*	csGetSPDByte
;*
;*	For backward compatibility
;*
;*	Entry:
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
csGetSPDByte PROC NEAR PUBLIC
	mov	bp,MEM_ACCESS_BUS	; memory devices are on this access bus
	jmp	csReadINDEXEDbyteStack
csGetSPDByte ENDP

;**************************************************************************
;*
;*	csInitI2CStack
;*
;*	Initialize the I2C interface (calls stackless version)
;*
;*	Entry:
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
csInitI2CStack PROC NEAR PUBLIC
	push	esi
	NOSTACK	si, csInitI2C		; Call stackless version
	pop	esi
	ret
csInitI2CStack ENDP

;**************************************************************************
;*
;*	csReadINDEXEDbyte
;*
;*	(STACKLESS)
;*
;*	This routine reads a byte across the I2C bus. (stackless)
;*
;*	Entry:
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*	  BL = chip address
;*	  CL = byte address to access
;*	  DX = return address
;*
;*	Exit:
;*	  BL = byte read
;*
;*	Destroys:
;*	  EAX, EBX, ECX, EDX, BP, SI
;*
;**************************************************************************
csReadINDEXEDbyte PROC NEAR PUBLIC
	ror	ebp, 16			; Save BP
	mov	bp,  dx			; Save return address in BP
	ror	ebp, 16			; Restore the number of AB

	; Set Read direction and no ACK
	mov	bh, 1
	; Set bus mastership, slave device address and register offset
	NOSTACK	si, SetOffsetAB
	jnc		abortRead

	; Read byte
	NOSTACK	si, ReadABData
	jnc		abortRead

	mov	si, bx			; Store BX value - the read register
	; Stop transaction
	NOSTACK	bx, StopSignalABData
	mov	bx, si			; Restore BX value
	
abortRead:
	ror	ebp, 16			; Restore the return address
	mov	dx, bp
	ror	ebp, 16			; Restore the number of AB
	cmc
	jmp	dx			; Return to calling address
csReadINDEXEDbyte ENDP

;**************************************************************************
;*
;*	csWriteINDEXEDbyte
;*
;*	(STACKLESS)
;*
;*	This routine writes a byte across the I2C Bus, based on Access Bus.
;*	The protocol is as follows:
;*	  1) Request bus mastership
;*	  2) Set the slave device address
;*	  3) Set the address(offset) to write
;*	  4) Write out the data
;*	  5) Issue STOP
;*
;*	Entry:
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*	  BL = chip address
;*	  CL = byte address to access
;*	  AL = byte to write
;*	  DX = return address
;*
;*	Destroys:
;*	EAX, EBX, ECX, EDX, BP
;*
;**************************************************************************
csWriteINDEXEDbyte PROC NEAR PUBLIC
	ror	ebp, 16			; Save BP
	mov	bp,  dx			; Save return address in BP
	ror	ebp, 16			; Restore the number of AB
	mov	dx, ax
	ror	edx, 16			; Store data value
	
	; Set Write direction
	xor	bh, bh
	; Set bus mastership, slave device address and register offset
	NOSTACK	si, SetOffsetAB
	jnc		abortWrite		

	; Write the data
	ror	edx, 16			; Restore data value
	mov	bl, dl
	NOSTACK	si, WriteABData
	jnc		abortWrite		

	; Stop transaction
	NOSTACK	bx, StopSignalABData
	
abortWrite:
	ror	ebp, 16			; Restore the return address
	mov	dx, bp
	ror	ebp, 16			; Restore the number of AB
	cmc
	jmp	dx			; Return to calling address
csWriteINDEXEDbyte ENDP

;**************************************************************************
;*
;*	csWriteINDEXEDbyteStack
;*
;*	This routine calls csWriteSPDByteJDX (above) and saves/restores
;*	registers
;*
;*	Entry:
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*	  BL = chip address
;*	  CL = register address
;*	  AL = byte to write
;*
;*	Exit:
;*	Destroys
;*
;**************************************************************************
csWriteINDEXEDbyteStack PROC NEAR PUBLIC
	push	edi
	push	esi
	push	edx
	push	ebp
	push	ebx
	push	eax
	push	ecx
	push	gs
	
	NOSTACK	dx, csWriteINDEXEDbyte
	
	pop	gs
	pop	ecx
	pop	eax
	pop	ebx
	pop	ebp
	pop	edx
	pop	esi
	pop	edi
	ret
csWriteINDEXEDbyteStack ENDP

;**************************************************************************
;*
;*	csReadINDEXEDbyteStack
;*
;*	This routine calls csReadSPDByteJDX (above) and saves/restores
;*	registers
;*
;*	Entry:
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*	  BL = chip address
;*	  CL = register address
;
;*	Exit:
;*	  BL = byte read
;*
;*	Destroys:
;*
;**************************************************************************
csReadINDEXEDbyteStack PROC NEAR PUBLIC
	push	eax
	push	ecx
	push	edi
	push	esi
	push	edx
	push	ebp
	push	gs
	push	ebx

	NOSTACK	dx, csReadINDEXEDbyte

	mov	al, bl
	pop	ebx
	mov	bl, al

	pop	gs
	pop	ebp
	pop	edx
	pop	esi
	pop	edi
	pop	ecx
	pop	eax
	ret
csReadINDEXEDbyteStack ENDP

;**************************************************************************
;*
;*	csInitI2CStack
;*
;*	Initialize the I2C interface (calls stackless version)
;*
;*	Entry:
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*	Exit:
;*	Destroys:
;*
;**************************************************************************
csInitI2C PROC NEAR PUBLIC
	jmp InitAB			; Call stackless version
csInitI2C ENDP



;**************************************************************************
;*
;*	csWriteI2CBlockStack 
;*
;*	Entry:  
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*		CH = chip address
;*		CL = register
;*		DL = number of bytes to transfer
;*		DS:SI = pointer to data to write to device 
;*	Exit:
;*	Destroys: Nothing - only flags are changed.
;*
;**************************************************************************
csWriteI2CBlockStack PROC NEAR PUBLIC
	pushad
	push	gs
	mov	bl, ch	; bl = chip address
	mov	bh, cl	; bh = chip register
	mov	cx, dx	; Use cl to count number of bytes to write
	push	cx
	mov	di, si	; di = pointer to data to copy
	
;
; Call I2C Initialization Procedure
;
	NOSTACK	si, csInitI2C

	; Set Write direction
	xor	bh, bh
	; Set bus mastership, slave device address and register offset
	NOSTACK	si, SetOffsetAB
	jnc	DoneI2CWr		  ; abort

;
; Loop through data.  Number of bytes to write is in dl.
;
	pop	cx
WriteI2CDataAgain:
	mov	bl,[di]
	inc	di
	dec	cl
	push  cx
	NOSTACK	si, WriteABData ; BL = Write data
	jnc	DoneI2CWr		; Carry is CLEARED on error!
	pop	cx
	cmp	cl,00h
	jnz	WriteI2CDataAgain
	push	cx
;
; Stop Condition
;
	NOSTACK	bx, StopSignalABData
	clc
	
DoneI2CWr:
	pop	cx
	pop	gs
	popad
	ret
csWriteI2CBlockStack ENDP


;**************************************************************************
;*
;*	csReadI2CBlockStack 
;*
;*	Entry:  
;*		BP = number of Access.bus: ACCESS_BUS1_DEVICE or ACCESS_BUS2_DEVICE
;*		CH = chip address
;*		CL = register
;*		DL = number of bytes to transfer
;*		ES:DI = pointer to data to write to device 
;*	Exit:
;*	Destroys: Nothing - only flags are changed.
;*
;**************************************************************************
csReadI2CBlockStack PROC NEAR PUBLIC
	pushad
	push	gs
	mov	bl, ch	; bl = chip address
	mov	bh, cl	; bh = chip register
	mov	cx, dx	; Use cl to count number of bytes to write
	push	cx

;
; Call I2C Initialization Procedure
;
	NOSTACK	si, csInitI2C

	; Set Read direction
	mov	bh, 1
	; Set bus mastership, slave device address and register offset
	NOSTACK	si, SetOffsetAB
	jnc	DoneI2CRd		  ; abort

;
; Loop through data.  Number of bytes to write is in dl.
;
	pop	cx
ReadI2CDataAgain:
	dec	cl
	push  cx
	xor	cx, cx				; 
	NOSTACK	si, ReadABData 
	jnc	DoneI2CRd			; Carry is CLEARED on error!

	mov	bl,es:[di]
	inc	di
	cmp	di, 0h
	je	FailSegmentEnd		;don't wrap back to beginning of segment

	pop	cx
	cmp	cl,00h
	jnz	ReadI2CDataAgain
	push	cx
;
; Stop Condition
;
	NOSTACK	bx, StopSignalABData
	clc
	jmp DoneI2CRd

FailSegmentEnd:
	NOSTACK	si, StopSignalABData
	stc
;	jmp Done I2CRd

DoneI2CRd:
	pop	cx
	pop	gs
	popad
	ret
csReadI2CBlockStack ENDP


_TEXT ENDS

	END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -