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

📄 sn8_usb_module.lib

📁 sonix系列mcu USB库汇编代码,用于进行2250系列mcu
💻 LIB
字号:
;**************************************************************************************
;
;			<USB MODULE> USB SIE
;--------------------------------------------------------------------------------------
;EP0  
;---
;Include	1. Control_Handler (For EP0 setup token)
;		2. Standard_Request (For USB standard command)
;		3. HID_Request	(USB HID command)
;		4. Data_structure (EP0 SETUP, IN , OUT)
;		5. Bus Reset function
;		6. USB suspend function
;		7. Remote wakeup function
;		8. USB EP0~EP2's FIFO R/W function 
;---------------------------------------------------------------------------------------
;Other Endpoints
;---------------
;EP1 
;EP2
;***************************************************************************************

Bus_Reset:
;---------------------------------------------------------------
;NOTE!! Keep USB enable after Bus_reset and set USB address to 0
;---------------------------------------------------------------	
		mov	a,#0x80		;enable USB & and set USB address = 0	
		b0mov	UDA,a		
		clr	UDP0		;set FIFO address to EP0
		clr	UDR0_R
		clr	UDR0_W
		b0bclr	bSetAddress	;bus reset clear bSet_address	
		b0bclr	bAlreadySetAddr	
		b0bclr	bSuspend	;clear bSuspend flag
		clr	BSetConfiguration
		clr	UStatus
		clr	EP0OUT_CNT	
		mov	a, #0x0
		b0mov	UE0R,a		
		b0mov	UE1R,a
		b0mov	UE2R,a
		jmp	isr_90

// ---------------------- //
//  USB Suspend function  //
// ---------------------- //
USB_Suspend:	
;------------------------------------------------------------------
;NOTE!!	USER can define MCU's mode when USB suspend occur.
;	This demo code set the MCU go into SLEEP.
;------------------------------------------------------------------
		b0mov	a, P0
		b0mov	Wakeup_IO_status,a
		b0bclr	bSuspend
		
		b0bset	FCLKMD		; Enter Slow Mode
		b0bset	FSTPHX
USB_Suspend_10:
		@RST_WDT
		b0bts1	FSUSPEND
		jmp	USB_Suspend_20	
		b0bts1	bRemote_Wakeup	; Check if support Remote wakeup
		jmp	USB_Suspend_10
		b0mov	a, P0		; Check if P0 status changes
		cmprs	a, Wakeup_IO_status
		jmp	USB_Suspend_90	
		jmp	USB_Suspend_10

USB_Suspend_20:
		b0bclr	FSTPHX
;------------------------------------------------------------------
; NOTE! From Slow to Normal Mode, the 6M X'tal stable time needs 
;	almost 7ms. The delay function below delays almost 8ms.
;------------------------------------------------------------------
		mov	a,#0x07
		b0mov	z,a
@@:
		decms	z
		jmp	@b
		b0bclr	FCLKMD
		ret

USB_Suspend_90:
		b0bclr	FSTPHX
;------------------------------------------------------------------
; NOTE! From Slow to Normal Mode, the 6M X'tal stable time needs 
;	almost 7ms. The delay function below delays almost 8ms.
;------------------------------------------------------------------
		mov	a,#0x07
		b0mov	z,a
@@:
		decms	z
		jmp	@b
		b0bclr	FCLKMD		
		jmp	Remote_Wakeup

// ------------------- //
//  USB Remote_wakeup  //
// ------------------- //
Remote_Wakeup:	
		mov	a,#0x01
		cmprs	a,bSetConfiguration	; Check if Configured_State
		jmp	USB_Suspend

		b0bclr	FGIE
		mov	a, #11000110b	 ;j state ;Full speed D+ > 0, D- <0		
		b0mov	upid, a		 
		call	delay_for_j_state		
		mov	a, #11000101b	 ;k state	
		b0mov	upid, a	
		call	delay_for_k_state;SPEC require 1ms ~ 15ms			
		mov	a, #11000010b	 ;recovery, disable driving USB BUS
		b0mov	upid,a		
		b0bclr	INTRQ.0		 ;clear Key wakeup 
		b0bclr	INTRQ.6		 ;clear USB interrupt request
		b0bset	FGIE
		ret


;**************************************************************************************
;	USB Delay function for remote wakeup control D+ D-
;======================================================================================
; User must define the parameter USB_REMOTE_WAKEUP_K_STATE_DELAY in SN8_USB_Setting.asm
;**************************************************************************************

delay_for_j_state:
	mov	a,#0ffh
	b0mov	z,a
	mov	a,#0X01
	b0mov	r,a
@@:	DECMS	Z
	jmp @B
	DECMS	R
	jmp @B
	ret

delay_for_k_state:
	mov	a,#0ffh
	b0mov	z,a
	mov	a,#USB_REMOTE_WAKEUP_K_STATE_DELAY
	b0mov	r,a
@@:	DECMS	Z
	jmp @B
	DECMS	R
	jmp @B
	ret


// ====================================================================== //
//  		EP1 & EP2 ACK transcation.			 	  //
// ====================================================================== //
EP1_ACK:	
		b0bclr	EP_ACK.0
		jmp	isr_90

EP2_ACK:	
		b0bclr	EP_ACK.1
		jmp	isr_90

include SN8_USB_SIE_Enc.lib

// ---------------------- //
//  USB Descriptor table  //
// ---------------------- //
include	SN8_USB_Descriptor_Table.lib

// ===================================================================== //
// 			USB End Points function				 //
// ===================================================================== //
include	SN8_USB_EP1.asm
include	SN8_USB_EP2.asm


⌨️ 快捷键说明

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