📄 usb_drv.lst
字号:
232 * data_length: number of bytes to read
233 * return: address of the next Ucharto send
234 *----------------------------------------------------------------------------
235 * PURPOSE:
236 * This function moves the data stored in the selected endpoint fifo to
237 * the address specified by *rbuf.
238 *----------------------------------------------------------------------------
239 * EXAMPLE:
240 * while(!(Usb_rx_complete)); // wait new packet received
C51 COMPILER V7.06 USB_DRV 01/29/2008 10:59:25 PAGE 5
241 * usb_read_packet(4,&first_data,usb_get_nb_byte); // read packet from ep 4
242 * Usb_clear_rx(); // acknowledge the transmit
243 *----------------------------------------------------------------------------
244 * NOTE:
245 * rbuf is incremented of 'data_length'.
246 *----------------------------------------------------------------------------
247 * REQUIREMENTS:
248 *****************************************************************************/
249 Uchar* usb_read_packet (Uchar ep_num, Uchar* rbuf, Uchar data_length)
250 {
251 1 Uchar i;
252 1
253 1 Usb_select_ep(ep_num);
254 1
255 1 for (i = data_length; i != 0 ; i--, rbuf++) { *rbuf = Usb_read_byte(); }
256 1
257 1 return rbuf;
258 1 }
259
260 /*F**************************************************************************
261 * NAME: usb_halt_endpoint
262 *----------------------------------------------------------------------------
263 * PARAMS:
264 * ep_num: number of the addressed endpoint
265 * return: none
266 *----------------------------------------------------------------------------
267 * PURPOSE:
268 * This function sends a STALL handshake for the next Host request. A STALL
269 * handshake will be send for each next request untill a SETUP or a Clear Halt
270 * Feature occurs for this endpoint.
271 *----------------------------------------------------------------------------
272 * EXAMPLE:
273 *----------------------------------------------------------------------------
274 * NOTE:
275 *----------------------------------------------------------------------------
276 * REQUIREMENTS:
277 *****************************************************************************/
278 void usb_halt_endpoint (Uchar ep_num)
279 {
280 1 Usb_select_ep(ep_num);
281 1 UEPSTAX = 0x00;
282 1 Usb_set_stall_request();
283 1 }
284
285 /*F**************************************************************************
286 * NAME: usb_reset_endpoint
287 *----------------------------------------------------------------------------
288 * PARAMS:
289 * return: none
290 *----------------------------------------------------------------------------
291 * PURPOSE:
292 * This function resets the endpoint fifo. This should be performed before
293 * the first use of an endpoint and after a Clear Halt Feature for the
294 * endpoint
295 *----------------------------------------------------------------------------
296 * EXAMPLE:
297 *----------------------------------------------------------------------------
298 * NOTE:
299 *----------------------------------------------------------------------------
300 * REQUIREMENTS:
301 *****************************************************************************/
302 void usb_reset_endpoint (Uchar ep_num)
C51 COMPILER V7.06 USB_DRV 01/29/2008 10:59:25 PAGE 6
303 {
304 1 UEPRST = 0x01 << ep_num ;
305 1 UEPRST = 0x00;
306 1 }
307
308 /*F**************************************************************************
309 * NAME: configure_usb_clock
310 *----------------------------------------------------------------------------
311 * PARAMS:
312 * return: none
313 * The possible value for FOSC are :
314 * 3000 ( 3MHz)
315 * 6000 ( 6MHz)
316 * 8000 ( 8MHz)
317 * 12000 (12MHz)
318 * 16000 (16MHz)
319 * 18000 (18MHz)
320 * 20000 (20MHz)
321 * 24000 (24MHz)
322 * 32000 (32MHz)
323 * 40000 (40MHz)
324 * 48000 (48MHz)
325 * 0000 (frequency auto-dectection)
326 *----------------------------------------------------------------------------
327 * PURPOSE:
328 * This function configure the PLL to generate the 48MHz clock required by
329 * the USB controller, considering the FOSC defined in the "config.h" file.
330 *----------------------------------------------------------------------------
331 * EXAMPLE:
332 * #define FOSC 8000 // 8MHz
333 * configure_usb_clock();
334 *----------------------------------------------------------------------------
335 * NOTE:
336 *----------------------------------------------------------------------------
337 * REQUIREMENTS:
338 *****************************************************************************/
339 void configure_usb_clock(void)
340 {
341 1 #if FOSC == 3000
Pll_set_div(PLL_3MHz);
Pll_enable();
#endif
345 1
346 1 #if FOSC == 4000
Pll_set_div(PLL_4MHz);
Pll_enable();
#endif
350 1
351 1 #if FOSC == 6000
Pll_set_div(PLL_6MHz);
Pll_enable();
#endif
355 1
356 1 #if FOSC == 8000
Pll_set_div(PLL_8MHz);
Pll_enable();
#endif
360 1
361 1 #if FOSC == 12000
Pll_set_div(PLL_12MHz);
Pll_enable();
#endif
C51 COMPILER V7.06 USB_DRV 01/29/2008 10:59:25 PAGE 7
365 1
366 1 #if FOSC == 16000
Pll_set_div(PLL_16MHz);
Pll_enable();
#endif
370 1
371 1 #if FOSC == 18000
Pll_set_div(PLL_18MHz);
Pll_enable();
#endif
375 1
376 1 #if FOSC == 20000
377 1 Pll_set_div(PLL_20MHz);
378 1 Pll_enable();
379 1 #endif
380 1
381 1 #if FOSC == 24000
Pll_set_div(PLL_24MHz);
Pll_enable();
#endif
385 1
386 1 #if FOSC == 32000
Pll_set_div(PLL_32MHz);
Pll_enable();
#endif
390 1
391 1 #if FOSC == 40000
Pll_set_div(PLL_40MHz);
Pll_enable();
#endif
395 1
396 1 #if FOSC == 48000
Usb_set_EXT48()
#endif
399 1
400 1 #if FOSC == 0000 /* frequency Auto-detection */
Uchar i;
Uchar reload;
PLLCON = 0x00;
if (CKCON0 & MSK_X2)
{
CKCON0 |= MSK_T0X2;
reload = 6;
}
else
{
CKCON0 &= ~MSK_T0X2;
reload = 9;
}
TMOD = 0x01; /* put Timer 0 in mode 1 */
USBINT = 0x00;
i=reload;
while (!(USBINT & MSK_SOFINT)) /* Do until Start Of Frame detection */
{
if (i==9)
{
Pll_stop(); /* external 48 MHz supposed */
C51 COMPILER V7.06 USB_DRV 01/29/2008 10:59:25 PAGE 8
Usb_set_EXT48();
}
else
{
Usb_clear_EXT48(); /* PLL output supposed */
Pll_set_div(pll_value[i]); /* configure PLL */
Pll_enable();
}
TH0 = TH0_value[i]; /* Run Timer 0 */
TL0 = TL0_value[i];
TCON |= 0x10;
while(((TCON & 0x20) != 0x20)); /* Wait Timer 0 Overflow */
TCON &= ~(0x30);
if (i==0)
{
i=reload;
}
else
{
i--;
}
}
TH0 = 0; /* Reset Timer 0 Registers */
TL0 = 0;
TCON = 0;
TMOD = 0;
#endif
455 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 180 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 10
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -