Subversion Repositories NaviCtrl

Rev

Rev 196 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
196 killagreg 1
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
1 ingob 2
* File Name          : usb_int.c
3
* Author             : MCD Application Team
196 killagreg 4
* Version            : V4.0.0
5
* Date               : 09/29/2008
6
* Description        : Endpoint CTR (Low and High) interrupt's service routines.
1 ingob 7
********************************************************************************
196 killagreg 8
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
1 ingob 9
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
10
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
11
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
12
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
13
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
14
*******************************************************************************/
15
 
16
/* Includes ------------------------------------------------------------------*/
17
#include "usb_lib.h"
18
/* Private typedef -----------------------------------------------------------*/
19
/* Private define ------------------------------------------------------------*/
20
/* Private macro -------------------------------------------------------------*/
21
/* Private variables ---------------------------------------------------------*/
22
u16 SaveRState;
23
u16 SaveTState;
24
/* Extern variables ----------------------------------------------------------*/
25
extern void (*pEpInt_IN[15])(void);    /*  Handles IN  interrupts   */
26
extern void (*pEpInt_OUT[15])(void);   /*  Handles OUT interrupts   */
27
/* Private function prototypes -----------------------------------------------*/
28
/* Private functions ---------------------------------------------------------*/
196 killagreg 29
 
1 ingob 30
/*******************************************************************************
196 killagreg 31
* Function Name  : CTR_LP.
32
* Description    : Low priority Endpoint Correct Transfer interrupt's service
33
*                  routine.
34
* Input          : None.
35
* Output         : None.
36
* Return         : None.
1 ingob 37
*******************************************************************************/
38
void CTR_LP(void)
39
{
196 killagreg 40
  u32 wEPVal = 0;
41
  /* stay in loop while pending ints */
42
  while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
43
  {
44
    _SetISTR((u16)CLR_CTR); /* clear CTR flag */
45
    /* extract highest priority endpoint number */
46
    EPindex = (u8)(wIstr & ISTR_EP_ID);
47
    if (EPindex == 0)
48
    {
49
      /* Decode and service control endpoint interrupt */
50
      /* calling related service routine */
51
      /* (Setup0_Process, In0_Process, Out0_Process) */
1 ingob 52
 
196 killagreg 53
      /* save RX & TX status */
54
      /* and set both to NAK */
55
      SaveRState = _GetEPRxStatus(ENDP0);
56
      SaveTState = _GetEPTxStatus(ENDP0);
57
      _SetEPRxStatus(ENDP0, EP_RX_NAK);
58
      _SetEPTxStatus(ENDP0, EP_TX_NAK);
1 ingob 59
 
60
 
196 killagreg 61
      /* DIR bit = origin of the interrupt */
1 ingob 62
 
196 killagreg 63
      if ((wIstr & ISTR_DIR) == 0)
64
      {
65
        /* DIR = 0 */
1 ingob 66
 
196 killagreg 67
        /* DIR = 0      => IN  int */
68
        /* DIR = 0 implies that (EP_CTR_TX = 1) always  */
1 ingob 69
 
70
 
196 killagreg 71
        _ClearEP_CTR_TX(ENDP0);
72
        In0_Process();
1 ingob 73
 
196 killagreg 74
           /* before terminate set Tx & Rx status */
75
          _SetEPRxStatus(ENDP0, SaveRState);
76
          _SetEPTxStatus(ENDP0, SaveTState);
77
          return;
78
      }
79
      else
80
      {
81
        /* DIR = 1 */
1 ingob 82
 
196 killagreg 83
        /* DIR = 1 & CTR_RX       => SETUP or OUT int */
84
        /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
1 ingob 85
 
196 killagreg 86
        wEPVal = _GetENDPOINT(ENDP0);
87
        if ((wEPVal & EP_CTR_TX) != 0)
88
        {
89
          _ClearEP_CTR_TX(ENDP0);
90
          In0_Process();
91
          /* before terminate set Tx & Rx status */
92
          _SetEPRxStatus(ENDP0, SaveRState);
93
          _SetEPTxStatus(ENDP0, SaveTState);
94
          return;
95
        }
96
        else if ((wEPVal &EP_SETUP) != 0)
97
        {
98
          _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
99
          Setup0_Process();
100
          /* before terminate set Tx & Rx status */
101
          _SetEPRxStatus(ENDP0, SaveRState);
102
          _SetEPTxStatus(ENDP0, SaveTState);
103
          return;
104
        }
1 ingob 105
 
196 killagreg 106
        else if ((wEPVal & EP_CTR_RX) != 0)
107
        {
108
          _ClearEP_CTR_RX(ENDP0);
109
          Out0_Process();
110
          /* before terminate set Tx & Rx status */
111
          _SetEPRxStatus(ENDP0, SaveRState);
112
          _SetEPTxStatus(ENDP0, SaveTState);
113
          return;
114
        }
115
      }
116
    }/* if(EPindex == 0) */
117
    else
118
    {
119
      /* Decode and service non control endpoints interrupt  */
1 ingob 120
 
196 killagreg 121
      /* process related endpoint register */
122
      wEPVal = _GetENDPOINT(EPindex);
123
      if ((wEPVal & EP_CTR_RX) != 0)
124
      {
125
        /* clear int flag */
126
        _ClearEP_CTR_RX(EPindex);
1 ingob 127
 
196 killagreg 128
        /* call OUT service function */
129
        (*pEpInt_OUT[EPindex-1])();
1 ingob 130
 
196 killagreg 131
      } /* if((wEPVal & EP_CTR_RX) */
1 ingob 132
 
196 killagreg 133
      if ((wEPVal & EP_CTR_TX) != 0)
134
      {
135
        /* clear int flag */
136
        _ClearEP_CTR_TX(EPindex);
137
 
138
        /* call IN service function */
139
        (*pEpInt_IN[EPindex-1])();
140
      } /* if((wEPVal & EP_CTR_TX) != 0) */
141
 
142
    }/* if(EPindex == 0) else */
143
 
144
  }/* while(...) */
145
}
146
 
1 ingob 147
/*******************************************************************************
196 killagreg 148
* Function Name  : CTR_HP.
149
* Description    : High Priority Endpoint Correct Transfer interrupt's service
150
*                  routine.
151
* Input          : None.
152
* Output         : None.
153
* Return         : None.
1 ingob 154
*******************************************************************************/
155
void CTR_HP(void)
156
{
196 killagreg 157
  u32 wEPVal;
1 ingob 158
 
196 killagreg 159
  while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
160
  {
161
    _SetISTR((u16)CLR_CTR); /* clear CTR flag */
162
    /* extract highest priority endpoint number */
163
    EPindex = (u8)(wIstr & ISTR_EP_ID);
164
    /* process related endpoint register */
165
    wEPVal = _GetENDPOINT(EPindex);
166
    if ((wEPVal & EP_CTR_RX) != 0)
167
    {
168
      /* clear int flag */
169
      _ClearEP_CTR_RX(EPindex);
1 ingob 170
 
196 killagreg 171
      /* call OUT service function */
172
      (*pEpInt_OUT[EPindex-1])();
173
 
174
    } /* if((wEPVal & EP_CTR_RX) */
175
    if ((wEPVal & EP_CTR_TX) != 0)
176
    {
177
      /* clear int flag */
178
      _ClearEP_CTR_TX(EPindex);
179
 
180
      /* call IN service function */
181
      (*pEpInt_IN[EPindex-1])();
182
 
183
 
184
    } /* if((wEPVal & EP_CTR_TX) != 0) */
185
 
186
  }/* while(...) */
1 ingob 187
} /* CTR_HP */
188
 
196 killagreg 189
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
1 ingob 190