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

📄 usb_int.c

📁 arm(str710)usb功能的实现
💻 C
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name          : usb_int.c
* Author             : MCD Application Team
* Date First Issued  : 27/10/2003
* Description        : Endpoint CTR interrupt service routine
*
********************************************************************************/




#include "USB_lib.h"




extern void const (*pEpInt[15])(void);

/*------------------------------------------------------------------------------*/
void CTR_ISR()
{
 WORD wEPVal;
 	/* stay in loop while pending ints */
	while(((wIstr = _GetISTR()) & ISTR_CTR)!= 0)
	{
	    _SetISTR((WORD)CLR_CTR); /* clear CTR flag */
		/* extract highest priority endpoint number */
		EPindex = (BYTE)(wIstr & ISTR_EP_ID);
		//uart_printf("ep%d rev ",EPindex);
		if(EPindex == 0)
		{
		//uart_printf("EPindex=%d ",EPindex);
/*==================================================================*/
/* Decode and service control endpoint interrupt */
/* calling related service routine */
/* (Setup0_Process, In0_Process, Out0_Process) */
/*==================================================================*/

			/* save RX & TX status */
			/* and set both to NAK */
			SaveRState = _GetEPRxStatus(ENDP0);
			SaveTState = _GetEPTxStatus(ENDP0);
			_SetEPRxStatus(ENDP0, EP_RX_NAK);
			_SetEPTxStatus(ENDP0, EP_TX_NAK);

		    /*-------------------------------------------------*/
			/* DIR bit = origin of the interrupt */
		    /*-------------------------------------------------*/
			if((wIstr & ISTR_DIR) == 0)
			{/* DIR = 0	*/
			    /*-------------------------------------------------*/
				/* DIR = 0      => IN  int */
				/* DIR = 0 implies that (EP_CTR_TX = 1) always  */
			    /*-------------------------------------------------*/
				/*		wEPVal = GetENDPOINT(ENDP0); */
				/*		if((wEPVal & EP_CTR_TX) != 0) */
				/*		{ */
							//uart_printf("ep%d in rev ",EPindex);
							_ClearEP_CTR_TX(ENDP0);
							In0_Process();
				/*		} */
				/* check if SETUP arrived during IN processing */
				wEPVal = _GetENDPOINT(ENDP0);
				
				if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0)
				{
					//uart_printf("ep%d stetup rev ",EPindex);
					_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
					Setup0_Process();
				}

			}/* DIR = 0	*/
			else
			{/* DIR = 1 */

			    /*-------------------------------------------------*/
				/* DIR = 1 & CTR_RX       => SETUP or OUT int */
				/* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
			    /*-------------------------------------------------*/
				wEPVal = _GetENDPOINT(ENDP0);
				if((wEPVal & EP_CTR_TX) != 0)
				{
					//uart_printf("ep%d in rev ",EPindex);
					_ClearEP_CTR_TX(ENDP0);
					In0_Process();
				}
				if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0)
				{
					//uart_printf("ep%d stetup rev ",EPindex);
					_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
					Setup0_Process();
				}
				else if((wEPVal & EP_CTR_RX) != 0)
				{
					//uart_printf("ep%d out rev ",EPindex);
					_ClearEP_CTR_RX(ENDP0);
					Out0_Process();
				}
			}/* DIR = 1 */

			/* before terminate set Tx & Rx status */
			_SetEPRxStatus(ENDP0, SaveRState);
			_SetEPTxStatus(ENDP0, SaveTState);
		}/* if(EPindex == 0) */
		else if (EPindex == 1)
		{//in
/*===============================================================*/
/* Decode and service non control endpoints interrupt  */
/*===============================================================*/
			/* process related endpoint register */
		pInformation->Ctrl_Info.Endpn = ENDP1;
				uart_printf("ep%d in rev ",EPindex);

			wEPVal = _GetENDPOINT(EPindex);
					SaveRState = _GetEPRxStatus(ENDP1);
			SaveTState = _GetEPTxStatus(ENDP1);
			_SetEPRxStatus(ENDP1, EP_RX_NAK);
			_SetEPTxStatus(ENDP1, EP_TX_NAK);

		    /*-------------------------------------------------*/
			/* DIR bit = origin of the interrupt */
		    /*-------------------------------------------------*/
			if((wIstr & ISTR_DIR) == 0)
			{/* DIR = 0	*/
			    /*-------------------------------------------------*/
				/* DIR = 0      => IN  int */
				/* DIR = 0 implies that (EP_CTR_TX = 1) always  */
			    /*-------------------------------------------------*/
				/*		wEPVal = GetENDPOINT(ENDP0); */
			    		uart_printf("ep%d in rev ",EPindex);
				if((wEPVal & EP_CTR_TX) != 0) 
				{ 
					_ClearEP_CTR_TX(ENDP1);
					//Setup1_Process();
					In1_Process();
				} 
				else if((wEPVal & EP_CTR_RX) != 0)
				{
					uart_printf("ep%d out rev ",EPindex);
					_ClearEP_CTR_RX(ENDP1);
					//Setup1_Process();
					Out1_Process();
				}


			}/* DIR = 0	*/
			else
			{/* DIR = 1 */

			    /*-------------------------------------------------*/
				/* DIR = 1 & CTR_RX       => SETUP or OUT int */
				/* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
			    /*-------------------------------------------------*/
			    uart_printf("ep%d out rev ",EPindex);

				wEPVal = _GetENDPOINT(ENDP1);
				if((wEPVal & EP_CTR_TX) != 0)
				{
					uart_printf("ep%d in rev ",EPindex);
					_ClearEP_CTR_TX(ENDP1);
					In1_Process();
				}
				else if((wEPVal & EP_CTR_RX) != 0)
				{
					//uart_printf("ep%d out rev ",EPindex);
					_ClearEP_CTR_RX(ENDP1);
					Setup1_Process();
					//Out1_Process();
				}
			}/* DIR = 1 */

			/* before terminate set Tx & Rx status */
			_SetEPRxStatus(ENDP1, SaveRState);
			_SetEPTxStatus(ENDP1, SaveTState);
			/*
			if((wEPVal & EP_CTR_RX) != 0)
			{
					// clear int flag 
					_ClearEP_CTR_RX(EPindex);

			} // if((wEPVal & EP_CTR_RX) 
			if((wEPVal & EP_CTR_TX) != 0)
			{
					// clear int flag 
					_ClearEP_CTR_TX(EPindex);
			} // if((wEPVal & EP_CTR_TX) != 0) 
*/
			/* call service function */
			(*pEpInt[EPindex-1])();
		}/* if(EPindex == 0) else	*/
		else if (EPindex == 2)
		{//in
/*===============================================================*/
/* Decode and service non control endpoints interrupt  */
/*===============================================================*/
			/* process related endpoint register */
		pInformation->Ctrl_Info.Endpn = ENDP2;

			wEPVal = _GetENDPOINT(EPindex);
					SaveRState = _GetEPRxStatus(ENDP2);
			SaveTState = _GetEPTxStatus(ENDP2);
			_SetEPRxStatus(ENDP2, EP_RX_NAK);
			_SetEPTxStatus(ENDP2, EP_TX_NAK);

		    /*-------------------------------------------------*/
			/* DIR bit = origin of the interrupt */
		    /*-------------------------------------------------*/
			if((wIstr & ISTR_DIR) == 0)
			{/* DIR = 0	*/
			    /*-------------------------------------------------*/
				/* DIR = 0      => IN  int */
				/* DIR = 0 implies that (EP_CTR_TX = 1) always  */
			    /*-------------------------------------------------*/
				/*		wEPVal = GetENDPOINT(ENDP0); */
			    		uart_printf("ep%d in rev ",EPindex);
				if((wEPVal & EP_CTR_TX) != 0) 
				{ 
					_ClearEP_CTR_TX(ENDP2);
					//Setup1_Process();
					In1_Process();
				} 
				else if((wEPVal & EP_CTR_RX) != 0)
				{
					uart_printf("ep%d out rev ",EPindex);
					_ClearEP_CTR_RX(ENDP2);
					//Setup1_Process();
					Out1_Process();
				}


			}/* DIR = 0	*/
			else
			{/* DIR = 1 */

			    /*-------------------------------------------------*/
				/* DIR = 1 & CTR_RX       => SETUP or OUT int */
				/* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
			    /*-------------------------------------------------*/
			    uart_printf("ep%d out rev ",EPindex);

				wEPVal = _GetENDPOINT(ENDP2);
				if((wEPVal & EP_CTR_TX) != 0)
				{
					uart_printf("ep%d in rev ",EPindex);
					_ClearEP_CTR_TX(ENDP2);
					In1_Process();
				}
				else if((wEPVal & EP_CTR_RX) != 0)
				{
					//uart_printf("ep%d out rev ",EPindex);
					_ClearEP_CTR_RX(ENDP2);
					Setup1_Process();
					//Out1_Process();
				}
			}/* DIR = 1 */

			/* before terminate set Tx & Rx status */
			_SetEPRxStatus(ENDP2, SaveRState);
			_SetEPTxStatus(ENDP2, SaveTState);
			/*
			if((wEPVal & EP_CTR_RX) != 0)
			{
					// clear int flag 
					_ClearEP_CTR_RX(EPindex);

			} // if((wEPVal & EP_CTR_RX) 
			if((wEPVal & EP_CTR_TX) != 0)
			{
					// clear int flag 
					_ClearEP_CTR_TX(EPindex);
			} // if((wEPVal & EP_CTR_TX) != 0) 
*/
			/* call service function */
			(*pEpInt[EPindex-1])();
		}/* if(EPindex == 0) else	*/
		else
		{
			uart_printf("ep%d inter ",EPindex);
			//pInformation->Ctrl_Info.Endpn = ENDP3;

		}

	}/* while(...)	*/
	
	//uart_printf("bbbbbbbbbbbbb: %d",wEPVal);	
} /* CTR_ISR */

⌨️ 快捷键说明

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