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

📄 usbci.c

📁 周立功magic2410实验箱源码 第6章Linux高级实验(part1) 6.1 Linux内核编译实验 6.2 Linux根文件系统实验 6.3 CAT1025读/写实验. 6.4 ZL
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)****************************************************                               Guangzhou ZHIYUAN electronics Co.,LTD.**                                     **                                 http://www.zyinside.com****--------------File Info-------------------------------------------------------------------------------** File Name: 				USBCI.c** Last modified Date: 		2006.01.09** Last Version:			V1.0		** Description: 			USB 设备控制器接口命令层**                          USB Device Controller Interface command layer**------------------------------------------------------------------------------------------------------** Created By: 				MingYuan Zheng 郑明远** Created date: 			2006.01.09** Version: 				V1.0** Descriptions:			The original version 初始版本****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Description:**********************************************************************************************************/

#include "config.h"

		/********************************************************
		
			操作USB设备寄存器	operate USB device register
		
		*********************************************************/


/***************************************************************************************************************
** 函数名称 : USB_InterruptEnable()						Name	 : USB_InterruptEnable()
** 功能描述 : USB设备控制器中断使能					  	Function : USB device controller interrupt enable 
** 输	 入 : INT8U value: 使能值			 			Input	 : INT8U value: enable value
** 输	 出 : 无										Output	 : NULL 
****************************************************************************************************************/
void USB_InterruptEnable(INT8U bEpEnable, INT8U bUSBEnalbe)
{
	UD_INTE = bEpEnable;
	UD_USBINTE = bUSBEnalbe;
}

	/**************************************************************************
	
		S3C2410 USB 设备控制器相关命令	Related	Command of S3C2410 USB Device
	
	***************************************************************************/


/***************************************************************************************************************
** 函数名称 : USB_SetCurEndpoint()						Name	 : USB_SetCurEndpoint()
** 功能描述 : 设置当前端点	  			    			Function : get the endpoint information
** 输	 入 : INT8U endp: 物理端点号					Input	 : INT8U endp: the physical endpoint number
** 输	 出 : 对应端点的信息							Output	 : the endpoint information
****************************************************************************************************************/
void USB_SetCurEndpoint(INT8U endp)
{	
	UD_INDEX = endp;									/* 写端点索引寄存器 */
}

/***************************************************************************************************************
** 函数名称 : USB_ConfigEndpoint()						Name	 : USB_ConfigEndpoint()
** 功能描述 : 配置 USB 设备端点						    Function : Configurate the endpoint of the USB
** 输	 入 : INT8U endp      :  物理端点号	  			Input	 : INT8U endp:  the physical endpoint number
			  INT8U packetsize:  该端点的最大包大小				   INT8U packetsize: the max packet size of the endpoint														   INT8U packetsize: the max packet size of the endpoint	
** 输	 出 : 无										Output	 : NULL 
****************************************************************************************************************/
void USB_ConfigMaxPaketSize(INT8U endp, INT32U packetsize)
{
    USB_SetCurEndpoint(endp);							/* 选择端点.      select the endpoint */
   
    UD_MAXP = packetsize;								/* 最大包长度为32 Max Packet size */ 
}

/***************************************************************************************************************
** 函数名称 : USB_ConfigEndpoint()						Name	 : USB_ConfigEndpoint()
** 功能描述 : 配置 USB 设备端点						    Function : Configurate the endpoint of the USB
** 输	 入 : INT8U endp      :  物理端点号	  			Input	 : INT8U endp:  the physical endpoint number
			  INT8U packetsize:  该端点的最大包大小				   INT8U packetsize: the max packet size of the endpoint														   INT8U packetsize: the max packet size of the endpoint	
** 输	 出 : 无										Output	 : NULL 
****************************************************************************************************************/
void USB_ConfigEpControlStatus(INT8U endp, INT8U EpDir, INT8U EPI_Type, INT8U EPO_Type)
{
	USB_SetCurEndpoint(endp);

    
    UD_ICSR1 = EPI_FIFO_FLUSH | EPI_CDT | EPI_Type;	
    UD_ICSR2 = EpDir | EPI_IN_DMA_INT_MASK | EPI_Type;  //IN mode, IN_DMA_INT=masked    
    UD_OCSR1 = EPO_CDT;   	
    		//clear OUT_PKT_RDY, data_toggle_bit.
	//The data toggle bit should be cleared when initialization. 
    UD_OCSR2 = EPO_Type | EPO_OUT_DMA_INT_MASK; 
    
    
}


/***************************************************************************************************************
** 函数名称 : USB_SetAddressEnable()					Name	 : USB_SetAddressEnable()
** 功能描述 : 设置 USB 设备地址			  			    Function : set the USB device address 
** 输	 入 : INT8U bAddress: 主机分配的地址值 			Input	 : INT8U bAddress:  the address value
		   	  INT8U bEnable:  1 - 使能USB设备 					   INT8U bEnable:  1: enable the USB device   
							  0 - 禁止USB设备                                      0: disable the device
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_SetAddressEnable(INT8U bAddress, INT8U bEnable)
{
	if (bEnable)
		bAddress |= 0x80;

	UD_FUNC = bAddress;   
}	


/***************************************************************************************************************
** 函数名称 : USB_SelectClrIntEndpoint()				Name	 : USB_SelectClrIntEndpoint()
** 功能描述 : 选择端点,并获取端点信息和清除对应端点的	Function : select the endpoint, and get the endpoint information 
			  中断												   and clear the interrupt of the correspond endpoint
** 输	 入 : INT8U endp: 物理端点号					Input	 : INT8U endp: the physical endpoint number
** 输	 出 : 对应端点的信息							Output	 : the endpoint information
****************************************************************************************************************/
INT8U USB_SelectClrIntEndpoint(INT8U endp)
{
	UD_INT |= 0x01 << endp;

	return 0;
}


/***************************************************************************************************************
** 函数名称 : USB_SetEndpointStatus()					Name	 : USB_SetEndpointStatus()
** 功能描述 : 设置端点状态							 	Function : set endpoint status 
** 输	 入 : INT8U endp    : 物理端点号				Input	 : INT8U endp    : the physical endpoint number
			  INT8U bStalled: 1 - stall 端点		               INT8U bStalled: 1 - stall endpoint
					          0	- unstall 端点					   				   0 - unstall endpoint
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_SetEndpointStatus(INT8U endp, INT8U bStalled)
{	
	INT8U reg;
	
	if (bStalled == 1)
	{
		USB_SetCurEndpoint(endp);					    /* 选择端点.      select the endpoint */
		
		reg = UD_OCSR1;
		UD_OCSR1 = reg;	
	}
}


/***************************************************************************************************************
** 函数名称 : USB_ClearBuffer()							Name	 : USB_ClearBuffer()
** 功能描述 : 清除OUT端点缓冲区						 	Function : clear the OUT endpoint buffer
** 输	 入 : INT8U endp: 物理端点号   					Input	 : INT8U endp:  the physical endpoint number
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_ClearBuffer(INT8U endp)
{
	USB_SetCurEndpoint(endp);							/* 选择端点.      select the endpoint */

⌨️ 快捷键说明

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