Subversion Repositories NaviCtrl

Rev

Rev 111 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 111 Rev 275
Line 1... Line 1...
1
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
1
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
2
* File Name          : usb_pwr.c
2
* File Name          : usb_pwr.c
3
* Author             : MCD Application Team
3
* Author             : MCD Application Team
-
 
4
* Version            : V2.0.0
4
* Date First Issued  : 10/01/2006 : V1.0
5
* Date               : 09/29/2008
5
* Description        : Connection/disconnection & power management
6
* Description        : Connection/disconnection & power management
6
********************************************************************************
7
********************************************************************************
7
* History:
-
 
8
* 10/01/2006 : V1.0
-
 
9
********************************************************************************
-
 
10
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
8
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
11
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
9
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
12
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
10
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
13
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
11
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
14
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
12
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
15
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
13
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
16
*******************************************************************************/
14
*******************************************************************************/
-
 
15
 
17
/* Includes ------------------------------------------------------------------*/
16
/* Includes ------------------------------------------------------------------*/
-
 
17
#include "91x_lib.h"
18
#include "usb_lib.h"
18
#include "usb_lib.h"
-
 
19
#include "usb_conf.h"
19
#include "usb_pwr.h"
20
#include "usb_pwr.h"
20
#include "usb.h"
21
#include "usb.h"
-
 
22
 
21
/* Private typedef -----------------------------------------------------------*/
23
/* Private typedef -----------------------------------------------------------*/
22
/* Private define ------------------------------------------------------------*/
24
/* Private define ------------------------------------------------------------*/
23
/* Private macro -------------------------------------------------------------*/
25
/* Private macro -------------------------------------------------------------*/
24
/* Private variables ---------------------------------------------------------*/
26
/* Private variables ---------------------------------------------------------*/
25
volatile bool fCellSuspended;
-
 
26
volatile u8 bDeviceState=UNCONNECTED; /* USB device status */
27
vu32 bDeviceState = UNCONNECTED; /* USB device status */
27
volatile bool fSuspendEnabled=TRUE;  /* true when suspend is possible */
28
volatile bool fSuspendEnabled = TRUE;  /* true when suspend is possible */
Line 28... Line 29...
28
 
29
 
-
 
30
struct
29
struct {
31
{
30
        volatile RESUME_STATE eState;
32
  volatile RESUME_STATE eState;
-
 
33
  volatile u8 bESOFcnt;
31
        volatile u8 bESOFcnt;
34
}
-
 
35
ResumeS;
32
} ResumeS;
36
 
33
/* Extern variables ----------------------------------------------------------*/
37
/* Extern variables ----------------------------------------------------------*/
34
/* Private function prototypes -----------------------------------------------*/
38
/* Private function prototypes -----------------------------------------------*/
35
/* Extern function prototypes ------------------------------------------------*/
39
/* Extern function prototypes ------------------------------------------------*/
-
 
40
/* Private functions ---------------------------------------------------------*/
36
/* Private functions ---------------------------------------------------------*/
41
 
37
/*******************************************************************************
42
/*******************************************************************************
38
* Function Name  : PowerOn
43
* Function Name  : PowerOn
39
* Description    :
44
* Description    : USB IP power ON Routine.
40
* Input          : None.
45
* Input          : None.
41
* Output         : None.
46
* Output         : None.
42
* Return         : USB_SUCCESS.
47
* Return         : USB_SUCCESS.
43
*******************************************************************************/
48
*******************************************************************************/
44
RESULT PowerOn(void)
49
RESULT PowerOn(void)
45
{
50
{
Line 46... Line 51...
46
 u16 wRegVal;
51
  u16 wRegVal;
47
 
-
 
48
        /*** cable plugged-in ? ***/
52
 
Line 49... Line 53...
49
        /*while(!CablePluggedIn());*/
53
  /*** cable plugged-in ? ***/
50
    USB_CableConfig(ENABLE);
54
  USB_CableConfig(ENABLE);
51
               
55
 
Line 62... Line 66...
62
    wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
66
  wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
63
    _SetCNTR(wInterrupt_Mask);
67
  _SetCNTR(wInterrupt_Mask);
Line 64... Line 68...
64
 
68
 
65
        return USB_SUCCESS;
69
  return USB_SUCCESS;
-
 
70
}
66
}
71
 
67
/*******************************************************************************
72
/*******************************************************************************
68
* Function Name  : PowerOff
73
* Function Name  : PowerOff
69
* Description    : handles switch-off conditions
74
* Description    : handles switch-off conditions
70
* Input          : None.
75
* Input          : None.
Line 84... Line 89...
84
    /* sw variables reset */
89
  /* sw variables reset */
85
        /* ... */
90
  /* ... */
Line 86... Line 91...
86
 
91
 
87
        return USB_SUCCESS;
92
  return USB_SUCCESS;
-
 
93
}
88
}
94
 
89
/*******************************************************************************
95
/*******************************************************************************
90
* Function Name  : Suspend
96
* Function Name  : Suspend
91
* Description    : sets suspend mode operating conditions
97
* Description    : sets suspend mode operating conditions
92
* Input          : None.
98
* Input          : None.
93
* Output         : None.
99
* Output         : None.
94
* Return         : USB_SUCCESS.
100
* Return         : USB_SUCCESS.
95
*******************************************************************************/
101
*******************************************************************************/
96
void Suspend(void)
102
void Suspend(void)
97
{
103
{
98
 u16 wCNTR;
-
 
99
    fCellSuspended= TRUE;
104
  u16 wCNTR;
100
        /* suspend preparation */
105
  /* suspend preparation */
Line 101... Line 106...
101
        /* ... */
106
  /* ... */
102
 
107
 
Line 107... Line 112...
107
 
112
 
108
/* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
113
  /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
109
        /* power reduction */
114
  /* power reduction */
Line -... Line 115...
-
 
115
  /* ... on connected devices */
110
        /* ... on connected devices */
116
 
111
 
117
 
112
    /* force low-power mode in the macrocell */
118
  /* force low-power mode in the macrocell */
113
    wCNTR = _GetCNTR();
119
  wCNTR = _GetCNTR();
Line 114... Line 120...
114
    wCNTR |= CNTR_LPMODE;
120
  wCNTR |= CNTR_LPMODE;
115
    _SetCNTR(wCNTR);
121
  _SetCNTR(wCNTR);
116
 
-
 
117
    /* switch-off the clocks */
-
 
-
 
122
 
118
    /* ... */
123
  /* switch-off the clocks */
-
 
124
  /* ... */
119
 
125
  USB_EnterLowPowerMode();
120
 
126
}
121
}
127
 
122
/*******************************************************************************
128
/*******************************************************************************
123
* Function Name  : Resume_Init
129
* Function Name  : Resume_Init
124
* Description    : Handles wake-up restoring normal operations
130
* Description    : Handles wake-up restoring normal operations
125
* Input          : None.
131
* Input          : None.
126
* Output         : None.
132
* Output         : None.
127
* Return         : USB_SUCCESS.
133
* Return         : USB_SUCCESS.
128
*******************************************************************************/
134
*******************************************************************************/
129
void Resume_Init(void)
-
 
130
{
-
 
131
  u16 wCNTR;
-
 
132
 
135
void Resume_Init(void)
133
    fCellSuspended= FALSE;
136
{
134
 
137
  u16 wCNTR;
Line 135... Line 138...
135
/* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
138
  /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
Line 141... Line 144...
141
    wCNTR &= (~CNTR_LPMODE);
144
  wCNTR &= (~CNTR_LPMODE);
142
    _SetCNTR(wCNTR);
145
  _SetCNTR(wCNTR);
Line 143... Line 146...
143
 
146
 
144
        /* restore full power */
147
  /* restore full power */
-
 
148
  /* ... on connected devices */
Line 145... Line 149...
145
        /* ... on connected devices */
149
  USB_LeaveLowPowerMode();
146
 
150
 
Line 147... Line 151...
147
        /* reset FSUSP bit */
151
  /* reset FSUSP bit */
148
        _SetCNTR(IMR_MSK);
152
  _SetCNTR(IMR_MSK);
149
 
-
 
150
        /* reverse suspend preparation */
153
 
-
 
154
  /* reverse suspend preparation */
151
        /* ... */
155
  /* ... */
152
 
156
}
153
}
157
 
154
/*******************************************************************************
158
/*******************************************************************************
155
* Function Name  : Resume
159
* Function Name  : Resume
Line 164... Line 168...
164
* Return         : None.
168
* Return         : None.
165
*******************************************************************************/
169
*******************************************************************************/
166
void Resume(RESUME_STATE eResumeSetVal)
170
void Resume(RESUME_STATE eResumeSetVal)
167
{
171
{
168
 u16 wCNTR;
172
  u16 wCNTR;
169
 u16 wRegVal;
-
 
Line 170... Line 173...
170
 
173
 
171
        if(eResumeSetVal != RESUME_ESOF)
174
  if (eResumeSetVal != RESUME_ESOF)
Line 172... Line 175...
172
                        ResumeS.eState = eResumeSetVal;
175
    ResumeS.eState = eResumeSetVal;
173
 
176
 
174
        switch(ResumeS.eState)
177
  switch (ResumeS.eState)
175
        {
178
  {
176
                case RESUME_EXTERNAL:
-
 
177
                Resume_Init();
-
 
178
          wRegVal = GetFNR();
-
 
179
                if(wRegVal & FNR_RXDP) //10 & 11 false conditions
-
 
180
                {
-
 
181
                        Suspend();
179
    case RESUME_EXTERNAL:
182
                }
180
      Resume_Init();
183
                    ResumeS.eState = RESUME_OFF;
181
      ResumeS.eState = RESUME_OFF;
184
                        break;
182
      break;
185
                case RESUME_INTERNAL:
183
    case RESUME_INTERNAL:
Line 217... Line 215...
217
                default:
215
    default:
218
                    ResumeS.eState = RESUME_OFF;
216
      ResumeS.eState = RESUME_OFF;
219
                        break;
217
      break;
220
        }
218
  }
221
}
219
}
-
 
220
 
222
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
221
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/