summaryrefslogtreecommitdiffstats
path: root/uc_str912/prj_blinky_complex_startup/src/usb_int.c
blob: 28c956b38568977113c1867905868f1bb5de0767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : usb_int.c
* Author             : MCD Application Team
* Date First Issued  : 05/18/2006 : Version 1.0
* Description        : Endpoint CTR interrupt service routine
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS
* A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include "USB_lib.h"
extern void (*pEpInt[9])(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);
		if(EPindex == 0) /* Decode and service control endpoint interrupt */
		{
			/* 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);
			if((wIstr & ISTR_DIR) == 0)
			{
				/* DIR = 0      => IN  int */
				_ClearEP_CTR_TX(ENDP0);
				In0_Process();
				/* check if SETUP arrived during IN processing */
				wEPVal = _GetENDPOINT(ENDP0);
				if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0)
				{
					_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
					Setup0_Process();
				}
			}
			else
			{
				/* 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)
				{
					_ClearEP_CTR_TX(ENDP0);
					In0_Process();
				}
        if((wEPVal &EP_SETUP) != 0)
				{
					_ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
					Setup0_Process();
				}
				else if((wEPVal & EP_CTR_RX) != 0)
				{
					_ClearEP_CTR_RX(ENDP0);
					Out0_Process();
				}
			}
			/* before terminate set Tx & Rx status */
			_SetEPRxStatus(ENDP0, SaveRState);
			_SetEPTxStatus(ENDP0, SaveTState);
		}
		else /* Decode and service non control endpoints interrupt  */
		{
			/* process related endpoint register */
			wEPVal = _GetENDPOINT(EPindex);
			if((wEPVal & EP_CTR_RX) != 0)
			{
				/* clear int flag */
				_ClearEP_CTR_RX(EPindex);
			}
			if((wEPVal & EP_CTR_TX) != 0)
			{
				/* clear int flag */
				_ClearEP_CTR_TX(EPindex);
			}
			/* call service function */
			(*pEpInt[EPindex-1])();
		}
	}
} /* CTR_ISR */

OpenPOWER on IntegriCloud