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

📄 ocp.asm

📁 该程序为USB HUB程序
💻 ASM
字号:
;-------------------------------------------------------------------------
; Over current protection for individual type (Apple)
;-------------------------------------------------------------------------
; (Detection & Chattering)
; -In 1 ms timer ISR, Check and accumlate the over current status.
;-------------------------------------------------------------------------
; (Shutdown)
; -In main loop, it shut down power of the port that OCP is detected.
;-------------------------------------------------------------------------
; (Report)
;
;   wPortStatus                         wPortChange                    
;  *Bit 0:	PORT_CONNECTION  	0      *Bit 0:	C_PORT_CONNECTION  	1 
;  *Bit 1:	PORT_ENABLE      	0      *Bit 1:	C_PORT_ENABLE      	1 
;   Bit 2:	PORT_SUSPEND     	0       Bit 2:	C_PORT_SUSPEND     	0  
;  *Bit 3:	PORT_OVER_CURRENT	1      *Bit 3:	C_PORT_OVER_CURRENT	1 
;   Bit 4:	PORT_RESET       	0       Bit 4:	C_PORT_RESET       	0  
;
;  *Bit 8:	PORT_POWER       	0        
;   Bit 9:	PORT_LOW_SPEED   	0       (Newly changed *)
;
;-------------------------------------------------------------------------
; (While OCP event exist, ...)
;
;   ClearPortFeature(C_PORT_CONNECTION);
;   ClearPortFeature(C_PORT_ENABLE);
;   ClearPortFeature(C_PORT_OVER_CURRENT);
;   GetPortStatus(PortNumber);
;
;   wPortStatus                         wPortChange                    
;   Bit 0:	PORT_CONNECTION  	0       Bit 0:	C_PORT_CONNECTION  	0 
;   Bit 1:	PORT_ENABLE      	0       Bit 1:	C_PORT_ENABLE      	0 
;   Bit 2:	PORT_SUSPEND     	0       Bit 2:	C_PORT_SUSPEND     	0  
;   Bit 3:	PORT_OVER_CURRENT	1       Bit 3:	C_PORT_OVER_CURRENT	0 
;   Bit 4:	PORT_RESET       	0       Bit 4:	C_PORT_RESET       	0  
;
;   Bit 8:	PORT_POWER       	0 
;   Bit 9:	PORT_LOW_SPEED   	0 
;
;-------------------------------------------------------------------------
; (After OCP event is removed, ...)
;   It needs to be unplugged and plugged. so, nothing we need to do.
;
;   OR
;
;   If the host send SetPortPower() command, shutdown is removed.
;   so, overcurrent is checked again.
;-------------------------------------------------------------------------

;------------------------------------------------------------------------
TASK_OVERCURRENT:
; This task services the MIC2527 port power controller overcurrent detect
; flag outputs (FLG, active low).
; Due to "nuisance tripping" on port power assertion (inrush), the FLG outputs
; of the MIC2527 need to be debounced so as not to report overcurrent detects
; to the host on port power assertion. Debounce period is LIMIT_OVERCURRENT in mS.
;-------------------------------------------------------------------------
; Modified for MAX891L (500mA)
;------------------------------------------------------------------------
    IORD    OC_PORT                     ; read overcurrent data
    CPL     A                           ; complement to make active high
    AND     A, MASK_OVERCURRENT_INPUTS  ; mask off all but OC detect bits
    CMP     A,[SHADOW_PORT_OC]          ; compare with last sample
    JZ      TOC_DEBOUNCE                ; if not the same
    MOV     [SHADOW_PORT_OC],A          ; save new sample
    MOV     A,0                         ;
    MOV     [HUB_OVERCURRENT_COUNT],A   ; clear debounce counter
    JMP     TASK_OVERCURRENT_END        ;
    
TOC_DEBOUNCE:
    MOV     A, [HUB_OVERCURRENT_COUNT]  ; get counter
    INC     A                           ;
    JZ      TASK_OVERCURRENT_END        ;
    MOV     [HUB_OVERCURRENT_COUNT],A   ;
    JEQ     LIMIT_OVERCURRENT,TOC       ;
    JMP     TASK_OVERCURRENT_END        ;

TOC:
    MOV     A, [SHADOW_PORT_OC]         ; 
    JEQ     00h, TASK_OVERCURRENT_END   ;
IFNDEF   HubOnly
    RLC	                                ; Nibble swap
    RLC                                 ;
    RLC                                 ;
    RLC                                 ;
ENDIF
    MOV     [Tmp2], A                   ;
        
	MOV     X, (MAXPORT-1)
OC_Loop:
	DEC     X                           ; if PortNumber=<-1, 
	JC      OC_LoopEnd                  ; finish the loop.   
	                                
    MOV     A, [Tmp2]                   ; 
    RLC                                 ; if OC event is occurred, 
    MOV     [Tmp2], A                   ;
    JNC     OC_Loop                     ; 
                                    
    ; Port control                  
	MOV     A, X                        ; wIndex
IFDEF   HubOnly
    INDEX	PortBitMap2
ELSE
	INDEX	PortBitMap3
ENDIF	
	MOV     [Tmp1], A
	IORD	HubPortPower
	OR      A, [Tmp1]
	OR      A, MASK_OVERCURRENT_INPUTS  ; 	
	IOWR	HubPortPower
	
	; wPortStatus
	MOV     A, 00h
	MOV     [X + HubPortStatusHi], A
    MOV     [X + HubPortChangeHi], A
    MOV     A, 08h    
	MOV     [X + HubPortStatusLo], A    
	MOV     A, 0Bh
	MOV     [X + HubPortChangeLo], A
	
	; Clear PORT_ENABLE
	MOV     A, X
	INDEX	PortBitMap2
	CPL     A
	MOV     [Tmp1], A
	IORD	HubPortEnable
	AND     A, [Tmp1]
	MOV     [LastHubPortEnable], A
	IOWR	HubPortEnable
	
	; Clear PORT_CONNECT
	IORD	HubPortConnect
	AND     A, [Tmp1]
	MOV     [LastHubPortConnect], A
	IOWR	HubPortConnect
	
    ; Set the port status change bit
    MOV     A, [Tmp1]
    CPL
    ASL
    OR      [HubStatusChangeData], A
    
    JMP     OC_Loop
     	
OC_LoopEnd:
	
	MOV     A, AckIn
	IOWR	HubChangeMode
	
TASK_OVERCURRENT_END:
    RET

PortBitMap2:
;-------------------------------------------------------------------------
; Hub Ports Enable Register 0x49 (read/write), 1 = Enabled, 0 = Disabled
;-------------------------------------------------------------------------
;   7   6   5   4   3   2   1   0 
;                   4   3   2   1 Port
;-------------------------------------------------------------------------
IFNDEF  4PortHub
	DB	01h
	DB	02h
	DB	00h
ELSE
	DB	01h
	DB	02h
	DB	04h
	DB	08h
	DB	00h
ENDIF

PortBitMap3:
;-------------------------------------------------------------------------
; Hub Ports Enable Register 0x49 (read/write), 1 = Enabled, 0 = Disabled
;-------------------------------------------------------------------------
;   7   6   5   4   3   2   1   0 
;   4   3   2   1                  Port
;-------------------------------------------------------------------------
IFNDEF  4PortHub
	DB	10h
	DB	20h
	DB	00h
ELSE      
	DB	10h
	DB	20h
	DB	40h
	DB	80h
	DB	00h
ENDIF

⌨️ 快捷键说明

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