?? f34x_usb_isr.lst
字號:
263 4 {
264 5 TempReg |= rbDATAEND; // Add Data End bit to mask
265 5 Ep_Status[0] = EP_IDLE; // and return Endpoint 0 to an idle state
266 5 }
267 4 POLL_WRITE_BYTE(E0CSR, TempReg); // Write mask to E0CSR
268 4 }
269 3 }
270 2 }
271 1 }
272
273 //-----------------------------------------------------------------------------
274 // Handle_In1
275 //-----------------------------------------------------------------------------
276 //
277 // Return Value : None
278 // Parameters : None
279 //
280 // This routine loads the current value from In_Packet on the Endpoint 1 fifo,
281 // after an interrupt is received from the last packet being transmitted
282 //
283 //-----------------------------------------------------------------------------
284
285 void Handle_In1()
286 {
287 1 BYTE ControlReg;
288 1
289 1 POLL_WRITE_BYTE(INDEX, 1); // Set index to endpoint 1 registers
290 1 POLL_READ_BYTE(EINCSR1, ControlReg); // Read contol register for EP 1
291 1
292 1 if (Ep_Status[1] == EP_HALT) // If endpoint is currently halted,
293 1 // send a stall
294 1 {
295 2 POLL_WRITE_BYTE(EINCSR1, rbInSDSTL);
296 2 }
297 1
298 1 else // Otherwise send last updated
299 1 // data to host
300 1 {
301 2 if (ControlReg & rbInSTSTL) // Clear sent stall if last packet
302 2 // returned a stall
303 2 {
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 6
304 3 POLL_WRITE_BYTE(EINCSR1, rbInCLRDT);
305 3 }
306 2
307 2 if (ControlReg & rbInUNDRUN) // Clear underrun bit if it was set
308 2 {
309 3 POLL_WRITE_BYTE(EINCSR1, 0x00);
310 3 }
311 2
312 2 // Put new data on Fifo
313 2 Fifo_Write(FIFO_EP1, EP1_PACKET_SIZE, (BYTE *)IN_PACKET);
314 2 POLL_WRITE_BYTE(EINCSR1, rbInINPRDY);
315 2 // Set In Packet ready bit, indicating
316 2 } // fresh data on Fifo 1
317 1 }
318
319 //-----------------------------------------------------------------------------
320 // Handle_Out2
321 //-----------------------------------------------------------------------------
322 //
323 // Return Value : None
324 // Parameters : None
325 //
326 // Take the received packet from the host off the fifo and put it into
327 // the Out_Packet array
328 //
329 //-----------------------------------------------------------------------------
330
331 void Handle_Out2()
332 {
333 1 BYTE Count = 0;
334 1 BYTE ControlReg;
335 1
336 1 POLL_WRITE_BYTE(INDEX, 2); // Set index to endpoint 2 registers
337 1 POLL_READ_BYTE(EOUTCSR1, ControlReg);
338 1
339 1 if (Ep_Status[2] == EP_HALT) // If endpoint is halted, send a stall
340 1 {
341 2 POLL_WRITE_BYTE(EOUTCSR1, rbOutSDSTL);
342 2 }
343 1
344 1 else // Otherwise read packet from host
345 1 {
346 2 if (ControlReg & rbOutSTSTL) // Clear sent stall bit if last packet
347 2 // was a stall
348 2 {
349 3 POLL_WRITE_BYTE(EOUTCSR1, rbOutCLRDT);
350 3 }
351 2
352 2 POLL_READ_BYTE(EOUTCNTL, Count);
353 2 if (Count != EP2_PACKET_SIZE) // If host did not send correct packet
354 2 // size, flush buffer
355 2 {
356 3 POLL_WRITE_BYTE(EOUTCNTL, rbOutFLUSH);
357 3 }
358 2 else // Otherwise get the data packet
359 2 {
360 3 Fifo_Read(FIFO_EP2, EP2_PACKET_SIZE, (BYTE*)OUT_PACKET);
361 3 }
362 2 POLL_WRITE_BYTE(EOUTCSR1, 0); // Clear Out Packet ready bit
363 2 }
364 1 }
365
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 7
366 //-----------------------------------------------------------------------------
367 // Usb_Suspend
368 //-----------------------------------------------------------------------------
369 //
370 // Return Value : None
371 // Parameters : None
372 //
373 // Enter suspend mode after suspend signalling is present on the bus
374 //
375 //-----------------------------------------------------------------------------
376
377 void Usb_Suspend(void)
378 {
379 1 // Put the device in a low power configuration
380 1
381 1 P0MDIN = 0x00; // Port 0 configured as analog input
382 1 P1MDIN = 0x00; // Port 1 configured as analog input
383 1 P2MDIN = 0x00; // Port 2 configured as analog input
384 1 P3MDIN = 0x00; // Port 3 configured as analog input
385 1
386 1 ADC0CN &= ~0x80; // Disable ADC0
387 1 REF0CN = 0x00; // Disable voltage reference
388 1
389 1 OSCICN |= 0x20; // Put oscillator
390 1
391 1 // When the device receives a non-idle USB event, it will resume execution
392 1 // on the instruction that follows OSCICN |= 0x20.
393 1
394 1 // Re-enable everything that was disabled when going into Suspend
395 1
396 1 P0MDIN = 0xFF; // Port 0 configured as digital pins
397 1 P1MDIN = 0x7F; // Port 1 pin 7 set as digital pin
398 1 P2MDIN = 0xFF; // Port 2 configured as digital pins
399 1 P3MDIN = 0xFF; // Port 3 configured as digital pins
400 1
401 1 REF0CN = 0x0E; // Enable voltage reference VREF
402 1 ADC0CN |= 0x80; // Re-enable ADC0
403 1 }
404
405 //-----------------------------------------------------------------------------
406 // Usb_Resume
407 //-----------------------------------------------------------------------------
408 //
409 // Return Value : None
410 // Parameters : None
411 //
412 // Resume normal USB operation
413 //
414 //-----------------------------------------------------------------------------
415
416 void Usb_Resume(void)
417 {
418 1 volatile int k;
419 1
420 1 k++;
421 1
422 1 // Add code for resume
423 1 }
424
425 //-----------------------------------------------------------------------------
426 // Fifo_Read
427 //-----------------------------------------------------------------------------
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 8
428 //
429 // Return Value : None
430 // Parameters :
431 // 1) BYTE addr : target address
432 // 2) unsigned int uNumBytes : number of bytes to unload
433 // 3) BYTE * pData : read data destination
434 //
435 // Read from the selected endpoint FIFO
436 //
437 //-----------------------------------------------------------------------------
438
439 void Fifo_Read(BYTE addr, unsigned int uNumBytes, BYTE * pData)
440 {
441 1 int i;
442 1
443 1 if (uNumBytes) // Check if >0 bytes requested,
444 1 {
445 2 USB0ADR = (addr); // Set address
446 2 USB0ADR |= 0xC0; // Set auto-read and initiate
447 2 // first read
448 2
449 2 // Unload <NumBytes> from the selected FIFO
450 2 for(i=0;i<uNumBytes-1;i++)
451 2 {
452 3 while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
453 3 pData[i] = USB0DAT; // Copy data byte
454 3 }
455 2
456 2 USB0ADR = 0; // Clear auto-read
457 2
458 2 while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
459 2 pData[i] = USB0DAT; // Copy data byte
460 2 }
461 1 }
462
463 //-----------------------------------------------------------------------------
464 // Fifo_Write
465 //-----------------------------------------------------------------------------
466 //
467 // Return Value : None
468 // Parameters :
469 // 1) BYTE addr : target address
470 // 2) unsigned int uNumBytes : number of bytes to unload
471 // 3) BYTE * pData : location of source data
472 //
473 // Write to the selected endpoint FIFO
474 //
475 //-----------------------------------------------------------------------------
476
477 void Fifo_Write(BYTE addr, unsigned int uNumBytes, BYTE * pData)
478 {
479 1 int i;
480 1
481 1 // If >0 bytes requested,
482 1 if (uNumBytes)
483 1 {
484 2 while(USB0ADR & 0x80); // Wait for BUSY->'0'
485 2 // (register available)
486 2 USB0ADR = (addr); // Set address (mask out bits7-6)
487 2
488 2 // Write <NumBytes> to the selected FIFO
489 2 for(i=0;i<uNumBytes;i++)
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 9
490 2 {
491 3 USB0DAT = pData[i];
492 3 while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
493 3 }
494 2 }
495 1 }
496
497 //-----------------------------------------------------------------------------
498 // Force_Stall
499 //-----------------------------------------------------------------------------
500 //
501 // Return Value : None
502 // Parameters : None
503 //
504 // Force a procedural stall to be sent to the host
505 //
506 //-----------------------------------------------------------------------------
507
508 void Force_Stall(void)
509 {
510 1 POLL_WRITE_BYTE(INDEX, 0);
511 1 POLL_WRITE_BYTE(E0CSR, rbSDSTL); // Set the send stall bit
512 1 Ep_Status[0] = EP_STALL; // Put the endpoint in stall status
513 1 }
514
515 //-----------------------------------------------------------------------------
516 // End Of File
517 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1031 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 19 17
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 + -