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

📄 usbdriver.c

📁 SmartARM2400系列开发板全套资料
💻 C
📖 第 1 页 / 共 3 页
字号:
** 函数名称: USB_RW_Result()									Name:		USB_RW_Result()
** 功能描述: USB 读写端点后处理									Function:	process it after the read/write port
** 输	 入: INT8U endp		  : 端点索引号						Input:		INT8U endp		 :  the index of endpoint
			 INT8U buffnums	  : 该端点缓冲区个数							INT8U buffnums	 :  numbers of endpoint buffer
			 CTRL_USB *pUsb   : USB接收或发送控制块指针						CTRL_USB *pUsb   :	the pointer of CTRL_USB struct
			 INT8U bread	  : 当前任务状态(1:接收 0:发送)					INT8U bread	     :  status of current task(1:receive 0:transmit)
			 INT8U berr		  : 数据收发有错误								INT8U berr		 :	there is error during receving or sending	 
** 输	 出: 无													Output:		NULL
***************************************************************************************************************************************/
#if (!DMA_ENGINE_EN)
void USB_RW_Result(INT8U endp, INT8U buffnums, CTRL_USB *pUsb, INT8U bread, INT8U berr)
{	
	INT8U i,endpstatus;
	
	OS_ENTER_CRITICAL();
	if (berr == 1)
	{
		for (i = 0; i < buffnums; i++)
		{
			endpstatus = USB_SelectEndpoint(endp);
			if ((endpstatus & 0x60) != 0)					/* 接收/发送缓冲区不空  receiving/transmission buffer is not empty */
			{												
				if (bread == 1)
		   		{											/* 当前为接收状态		receiving currently */			
					USB_SelectEndpoint(endp);
					USB_ClearBuffer();						/* 清空OUT 端点缓冲区	clear OUT endpoint buffer */
				}
				else
			   		USB_SetEndpointStatus(endp, 0);			/* 解禁 IN 端点			unstall IN endpoint */
			}
		}		
	}
	
	pUsb->bEpUsed = 0;										/* 标识本任务不占用该端点   flag the task not use the endpoint */	
	pUsb->bTaskWaiting = 0;									/* 标识任务未进入等待状态   flag no task does not enter waiting status */
	OS_EXIT_CRITICAL();
}
#endif

/***************************************************************************************************************
** 函数名称 : USB_ConfigEndpoint()						Name	 : USB_ConfigEndpoint()
** 功能描述 : 配置所有端点的最大包大小	  			    Function : config the maxpacket size of all endpoint
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_ConfigEndpoint(void)
{
	USB_ConfigMaxPaketSize(0,EP0_PACKET_SIZE);
	USB_ConfigMaxPaketSize(1,EP0_PACKET_SIZE);

	USB_ConfigMaxPaketSize(2,EP1_PACKET_SIZE);
	USB_ConfigMaxPaketSize(3,EP1_PACKET_SIZE);
	
	USB_ConfigMaxPaketSize(4,EP2_PACKET_SIZE);
	USB_ConfigMaxPaketSize(5,EP2_PACKET_SIZE);
}

/***************************************************************************************************************
** 函数名称 : Usb_Exception()							Name	 : Usb_Exception()
** 功能描述 : USB 中断服务程序			  			    Function : USB Interrupt Service Program
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void Usb_Exception (void) 
{
	INT32U dev_ints,devstatus;
	INT32U usb_ints;
	
	OS_ENTER_CRITICAL();
	VICVectAddr = 0;
	/****** USB status interrupt ******/
	dev_ints = USBDevIntSt;			    /* 读设备中断状态寄存器  read device interrupt status register */
	if (dev_ints & DEVINT_STATUS_DEVSTAT)			
	{
		devstatus = USB_GetDevStatus();
		if ((devstatus & 0x10) != 0)
			USB_BusReset();								/* 总线复位处理   		 process the bus reset      */

		if ((devstatus & 0x08) != 0)
			USB_SuspendChange();						/* 挂起改变处理   		 process the suspend change */

		if ((devstatus & 0x02) != 0)
			USB_ConnectChange();						/* 连接改变处理   		 process the connect change */
		
		USBDevIntClr = DevStatusInterrupt;
		OS_EXIT_CRITICAL();
		return;								/* 退出中断服务程序      exit the interrupt service */
	}	
	
	/****** data transmission interrupt ******/
	usb_ints = (INT32U)USBIntSt;
	if (usb_ints & USBINT_STATUS_HP)
		Usb_HPService();					   		/* 高优先级中断处理    process High priority Interrupt */
	
	if (usb_ints & USBINT_STATUS_LP)
		Usb_LPService();							/* 低优先级中断处理    process Slow priority Interrupt */

#if DMA_ENGINE_EN		
	if (usb_ints & USBINT_STATUS_DMA)
		USB_DMAService();							/* DMA中断处理         process DMA Interrupt */
#endif
    OS_EXIT_CRITICAL();
}


/***************************************************************************************************************
** 函数名称 : Usb_HPService()							Name	 : Usb_HPService()
** 功能描述 : USB 端点高速中断服务程序	  			    Function : USB endpoint fast Interrupt Service Program
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void Usb_HPService(void)
{
	INT32U ep_st,i;
	
	ep_st = USBEpIntSt;									/* 读端点中断状态寄存器      read endpoint interrupt status register */

	if(ep_st & USB_ENDP00)
		ep0_rxdone();									/* 控制端点接收数据处理 	 process controll endpoint receive data */
	if(ep_st & USB_ENDP01) 
		ep0_txdone();									/* 控制端点发送数据处理 	 process controll endpoint transmit data */

	for (i = 2; i <= 5; i++)
	{
		if ((ep_st & (0x01 << i)) != 0)
			 Usb_EpISR(i);								/* 其它端点接收/发送数据处理 process other endpoint recevie and transmit data */
	}
		
	USBDevIntClr = FASTINTERRUPT;

	USBINTDEBUG_SENDSTR("\r\nUsb_HPService\r\n");
}


/***************************************************************************************************************
** 函数名称 : Usb_LPService()							Name	 : Usb_LPService()
** 功能描述 : USB 端点慢速中断服务程序	  			    Function : USB endpoint slow Interrupt Service Program
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void Usb_LPService(void)
{
	INT32U ep_st,i;
	
	ep_st = USBEpIntSt;									/* 读端点中断状态寄存器      read endpoint interrupt status register */

	if(ep_st & USB_ENDP00)
		ep0_rxdone();									/* 控制端点接收数据处理 	 process controll endpoint receive data */
	if(ep_st & USB_ENDP01) 
		ep0_txdone();									/* 控制端点发送数据处理 	 process controll endpoint transmit data */

	for (i = 2; i <= 5; i++)
	{
		if ((ep_st & (0x01 << i)) != 0)
			 Usb_EpISR(i);								/* 其它端点接收/发送数据处理 process other endpoint recevie and transmit data */
	}	
    
	USBDevIntClr = SLOWINTERRUPT;
	
	USBINTDEBUG_SENDSTR("\r\nUsb_LPService\r\n");
}

/***************************************************************************************************************
** 函数名称 : Usb_EpISR()								Name	 : Usb_EpISR()
** 功能描述 : 端点接收/发送数据处理		  		    	Function : proecess endpoint receive/transmit
** 输	 入 : INT8U endp: 物理端点号		 			Input	 : INT8U endp: physical endpoint number
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void Usb_EpISR(INT8U endp)
{
	USB_SelectClrIntEndpoint(endp);						/* 选择端点并清除中断  		        select endpoint/clear interrupt */

#if (!DMA_ENGINE_EN)
	if (Ctrl_Usb[endp - 2].bTaskWaiting == 0)			/* 任务未等待进入等待接收/发送状态  there is no task waiting for receiving data */
		Ctrl_Usb[endp - 2].bEpReady = 1;				/* 置位标志 				        set the flag the endpoint is ready */
	else
		OSSemPost(Ctrl_Usb[endp - 2].Ep_Sem);			/* 使等待接收/发送数据的任务就绪    send semaphore to the task waiting for receiving or transmitting data */
#endif
}


/***************************************************************************************************************
** 函数名称 : USB_BusReset()							Name	 : USB_BusReset()
** 功能描述 : USB 总线复位处理				  			Function : process USB bus reset  
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_BusReset(void)
{
    usbFunBusRestDeal();

	bEPPflags.value = 0;	                            /* 置USB事件标志为0   	 set USB event flags to zero */
	USB_USBDevIntConfig();
	USB_ConfigEndpoint();								/* 重新配置所有端点最大包大小 */
	USBDEBUG_SENDSTR("\r\nBus Reset\r\n"); 
}


/***************************************************************************************************************
** 函数名称 : USB_Suspend()								Name	 : USB_Suspend()
** 功能描述 : USB 总线挂起改变				  			Function : process USB bus suspend change 
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_SuspendChange(void)
{
    USBDEBUG_SENDSTR("\r\nSuspend change\r\n"); 
}

/***************************************************************************************************************
** 函数名称 : IsUsbDevConfig()							
** 功能描述 : 设备是否被配置
** 输	 入 : 无							 			
** 输	 出 : 1: 已被配置,  0: 未被配置
****************************************************************************************************************/
INT8U IsUsbDevConfig (void)
{
    return bEPPflags.bits.configuration;
}

/***************************************************************************************************************
** 函数名称 : USB_ConnectChange()						Name	 : USB_ConnectChange()
** 功能描述 : USB 总线连接改变				  			Function : process USB bus connect change
** 输	 入 : 无							 			Input	 : NULL
** 输	 出 : 无										Output	 : NULL
****************************************************************************************************************/
void USB_ConnectChange(void)
{
    USBDEBUG_SENDSTR("\r\nConnect change\r\n"); 
}


/*******************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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