- UID
- 1029342
- 性别
- 男
|
94 /*******************************************************************************
95 * Function Name : Leave_LowPowerMode
96 * Description : Restores system clocks and power while exiting suspend mode
97 * Input : None.
98 * Return : None.
99 *******************************************************************************/
100 void Leave_LowPowerMode(void)
101 {
102 DEVICE_INFO *pInfo = &Device_Info;
103
104 /* Set the device state to the correct state */
105 if (pInfo->Current_Configuration != 0)
106 {
107 /* Device configured */
108 bDeviceState = CONFIGURED;
109 }
110 else
111 {
112 bDeviceState = ATTACHED;
113 }
114 /*Enable SystemCoreClock*/
115 // SystemInit();
116 }
117
118 /*******************************************************************************
119 * Function Name : USB_Interrupts_Config
120 * Description : Configures the USB interrupts
121 * Input : None.
122 * Return : None.
123 *******************************************************************************/
124 void USB_Interrupts_Config(void)
125 {
126 NVIC_InitTypeDef NVIC_InitStructure;
127
128 NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
129 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
130 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
131 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
132 NVIC_Init(&NVIC_InitStructure);
133
134 /* Enable the USB Wake-up interrupt */
135 NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
136 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
137 NVIC_Init(&NVIC_InitStructure);
138 }
139
140 /*******************************************************************************
141 * Function Name : USB_Cable_Config
142 * Description : Software Connection/Disconnection of USB Cable
143 * Input : None.
144 * Return : Status
145 *******************************************************************************/
146 void USB_Cable_Config (FunctionalState NewState)
147 {
148 if (NewState == DISABLE)
149 {
150 GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
151 }
152 else
153 {
154 GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
155 }
156 }
157
158 /*******************************************************************************
159 * Function Name : void USB_Config(void)
160 * Description : USB系统初始化
161 * Input :
162 * Output :
163 * Other :
164 * Date : 2014.11.28
165 *******************************************************************************/
166 void USB_Config(void)
167 {
168 Set_System();
169
170 Set_USBClock();
171
172 USB_Interrupts_Config();
173
174 USB_Init();
175 }
176
177 /*******************************************************************************
178 * Function Name : uint32_t USB_RxRead(uint8_t *buffter, uint32_t buffterSize)
179 * Description : 从USB接收缓存中读数据
180 * Input :
181 * Output :
182 * Other :
183 * Date : 2014.11.28
184 *******************************************************************************/
185 uint32_t USB_RxRead(uint8_t *buffter, uint32_t buffterSize)
186 {
187 return QUEUE_PacketOut(&m_QueueUsbComRx, buffter, buffterSize);
188 }
189 /*******************************************************************************
190 * Function Name : uint32_t USB_RxWrite(uint8_t *buffter, uint32_t writeLen)
191 * Description : 写数据到USB接收缓存中
192 * Input :
193 * Output :
194 * Other :
195 * Date : 2014.11.28
196 *******************************************************************************/
197 uint32_t USB_RxWrite(uint8_t *buffter, uint32_t writeLen)
198 {
199 return QUEUE_PacketIn(&m_QueueUsbComRx, buffter, writeLen);
200 }
201 /*******************************************************************************
202 * Function Name : uint32_t USB_TxRead(uint8_t *buffter, uint32_t buffterSize)
203 * Description : 从USB发送缓存中读数据
204 * Input :
205 * Output :
206 * Other :
207 * Date : 2014.11.28
208 *******************************************************************************/
209 uint32_t USB_TxRead(uint8_t *buffter, uint32_t buffterSize)
210 {
211 return QUEUE_PacketOut(&m_QueueUsbComTx, buffter, buffterSize);;
212 }
213 /*******************************************************************************
214 * Function Name : uint32_t USB_TxWrite(uint8_t *buffter, uint32_t writeLen)
215 * Description : 写数据到USB发送缓存中
216 * Input :
217 * Output :
218 * Other :
219 * Date : 2014.11.28
220 *******************************************************************************/
221 uint32_t USB_TxWrite(uint8_t *buffter, uint32_t writeLen)
222 {
223 return QUEUE_PacketIn(&m_QueueUsbComTx, buffter, writeLen);
224 }
225
226
227
228 /*******************************************************************************
229 * Function Name : Get_SerialNum.
230 * Description : Create the serial number string descriptor.
231 * Input : None.
232 * Output : None.
233 * Return : None.
234 *******************************************************************************/
235 void Get_SerialNum(void)
236 {
237 uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
238
239 Device_Serial0 = *(uint32_t*)ID1;
240 Device_Serial1 = *(uint32_t*)ID2;
241 Device_Serial2 = *(uint32_t*)ID3;
242
243 Device_Serial0 += Device_Serial2;
244
245 if (Device_Serial0 != 0)
246 {
247 IntToUnicode (Device_Serial0, &Virtual_Com_Port_StringSerial[2] , 8);
248 IntToUnicode (Device_Serial1, &Virtual_Com_Port_StringSerial[18], 4);
249 }
250 }
251
252 /*******************************************************************************
253 * Function Name : HexToChar.
254 * Description : Convert Hex 32Bits value into char.
255 * Input : None.
256 * Output : None.
257 * Return : None.
258 *******************************************************************************/
259 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
260 {
261 uint8_t idx = 0;
262
263 for( idx = 0 ; idx < len ; idx ++)
264 {
265 if( ((value >> 28)) < 0xA )
266 {
267 pbuf[ 2* idx] = (value >> 28) + '0';
268 }
269 else
270 {
271 pbuf[2* idx] = (value >> 28) + 'A' - 10;
272 }
273
274 value = value << 4;
275
276 pbuf[ 2* idx + 1] = 0;
277 }
278 }
279
280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|