SDCardManager.cpp
/** Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board Dataflash
 * IC(s), into
 *  the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the
 * Dataflash
 *  and writes them in OS sized blocks to the endpoint.
 *
 *  \param[in] MSInterfaceInfo  Pointer to a structure containing a Mass Storage Class configuration
 * and state
 *  \param[in] BlockAddress  Data block starting address for the read sequence
 *  \param[in] TotalBlocks   Number of blocks of data to read
 */
Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board Dataflash
IC(s), into
the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the
Dataflash
and writes them in OS sized blocks to the endpoint.

\param[in] MSInterfaceInfo  Pointer to a structure containing a Mass Storage Class configuration
and state
\param[in] BlockAddress  Data block starting address for the read sequence
\param[in] TotalBlocks   Number of blocks of data to read
Reads blocks ( OS blocks not Dataflash pages ) from the storage medium the board Dataflash IC ( s ) into the pre - selected data IN endpoint . This routine reads in Dataflash page sized blocks from the Dataflash and writes them in OS sized blocks to the endpoint . \ param [ in ] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state \ param [ in ] BlockAddress Data block starting address for the read sequence \ param [ in ] TotalBlocks Number of blocks of data to read
void SDCardManager_ReadBlocks(USB_ClassInfo_MS_Device_t *const MSInterfaceInfo,
                          uint32_t BlockAddress, uint16_t TotalBlocks) 
{
#ifdef SDCARD_DRIVER_DEBUG
  Serial1.print("R ");
  Serial1.print(BlockAddress);
  Serial1.write(' ');
  Serial1.println(TotalBlocks);
#endif
  if (Endpoint_WaitUntilReady())
    return;
  while (TotalBlocks) {
    if (!s_sdcard_driver.readBlock(BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE, s_sd_raw_block))
      break;
    uint8_t *buffer = s_sd_raw_block;
    for (uint16_t offset = 0; offset < VIRTUAL_MEMORY_BLOCK_SIZE; offset += MASS_STORAGE_IO_EPSIZE) {
      if (!Endpoint_IsReadWriteAllowed())  {
        Endpoint_ClearIN();
        if (Endpoint_WaitUntilReady())
          break;
      }
      for (uint8_t i = 0; i < MASS_STORAGE_IO_EPSIZE; ++i, ++buffer)
        Endpoint_Write_8(*buffer);
    }
    BlockAddress++;
    TotalBlocks--;
  }
  if (!(Endpoint_IsReadWriteAllowed()))
    Endpoint_ClearOUT();
}
void SDCardManager_ReadBlocks ( USB_ClassInfo_MS_Device_t * const MSInterfaceInfo , uint32_t BlockAddress , uint16_t TotalBlocks ) { #ifdef SDCARD_DRIVER_DEBUG Serial1 . print ( " " ) ; Serial1 . print ( BlockAddress ) ; Serial1 . write ( ' ' ) ; Serial1 . println ( TotalBlocks ) ; #endif if ( Endpoint_WaitUntilReady ( ) ) return ; while ( TotalBlocks ) { if ( ! s_sdcard_driver . readBlock ( BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE , s_sd_raw_block ) ) break ; uint8_t * buffer = s_sd_raw_block ; for ( uint16_t offset = 0 ; offset < VIRTUAL_MEMORY_BLOCK_SIZE ; offset += MASS_STORAGE_IO_EPSIZE ) { if ( ! Endpoint_IsReadWriteAllowed ( ) ) { Endpoint_ClearIN ( ) ; if ( Endpoint_WaitUntilReady ( ) ) break ; } for ( uint8_t i = 0 ; i < MASS_STORAGE_IO_EPSIZE ; ++ i , ++ buffer ) Endpoint_Write_8 ( * buffer ) ; } BlockAddress ++ ; TotalBlocks -- ; } if ( ! ( Endpoint_IsReadWriteAllowed ( ) ) ) Endpoint_ClearOUT ( ) ; }
Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board Dataflash
 IC(s), into
  the pre-selected data IN endpoint.
Reads blocks ( OS blocks not Dataflash pages ) from the storage medium the board Dataflash IC ( s ) into the pre - selected data IN endpoint .
/* Wait until endpoint is ready before continuing */ /* Decrement the blocks remaining counter and reset the sub block counter */ /* If the endpoint is empty, clear it ready for the next packet from the host */