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