keil_examples/USBMem/mscuser.c
/*
 *  MSC Memory Read Callback
 *   Called automatically on Memory Read Event
 *    Parameters:      None (global variables)
 *    Return Value:    None
 */
MSC Memory Read Callback
Called automatically on Memory Read Event
Parameters:      None (global variables)
Return Value:    None
MSC Memory Read Callback Called automatically on Memory Read Event Parameters : None ( global variables ) Return Value : None
void MSC_MemoryRead (void) {
  uint32_t n;
#if USB_DMA
  uint32_t i;
#endif
  if (Length > MSC_MAX_PACKET) {
    n = MSC_MAX_PACKET;
  } else {
    n = Length;
  }
  if ((Offset + n) > MSC_MemorySize) {
    n = MSC_MemorySize - Offset;
    BulkStage = MSC_BS_DATA_IN_LAST_STALL;
  }
#if USB_DMA
  if (USB_DMA_IsUsed (MSC_EP_IN)) {                     
    for (i = 0; i < n; i++)                             
      BulkBuf[i] = Memory[Offset+i];                    
    USB_WriteEP(MSC_EP_IN, BulkBuf, n);
  } else
    USB_WriteEP(MSC_EP_IN, &Memory[Offset], n);
#else
  USB_WriteEP(MSC_EP_IN, &Memory[Offset], n);
#endif
  Offset += n;
  Length -= n;
  CSW.dDataResidue -= n;
  if (Length == 0) {
    BulkStage = MSC_BS_DATA_IN_LAST;
  }
  if (BulkStage != MSC_BS_DATA_IN) {
    CSW.bStatus = CSW_CMD_PASSED;
  }
}
void MSC_MemoryRead ( void ) { uint32_t n ; #if USB_DMA uint32_t i ; #endif if ( Length > MSC_MAX_PACKET ) { n = MSC_MAX_PACKET ; } else { n = Length ; } if ( ( Offset + n ) > MSC_MemorySize ) { n = MSC_MemorySize - Offset ; BulkStage = MSC_BS_DATA_IN_LAST_STALL ; } #if USB_DMA if ( USB_DMA_IsUsed ( MSC_EP_IN ) ) { for ( i = 0 ; i < n ; i ++ ) BulkBuf [ i ] = Memory [ Offset + i ] ; USB_WriteEP ( MSC_EP_IN , BulkBuf , n ) ; } else USB_WriteEP ( MSC_EP_IN , & Memory [ Offset ] , n ) ; #else USB_WriteEP ( MSC_EP_IN , & Memory [ Offset ] , n ) ; #endif Offset += n ; Length -= n ; CSW . dDataResidue -= n ; if ( Length == 0 ) { BulkStage = MSC_BS_DATA_IN_LAST ; } if ( BulkStage != MSC_BS_DATA_IN ) { CSW . bStatus = CSW_CMD_PASSED ; } }
MSC Memory Read Callback
   Called automatically on Memory Read Event
    Parameters:      None (global variables)
    Return Value:    None
MSC Memory Read Callback Called automatically on Memory Read Event Parameters : None ( global variables ) Return Value : None
// Check if EP is used for DMA // copy data to USB DMA RAM // would be better if data is already in USB DMA RAM