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

\param[in] MSInterfaceInfo  Pointer to a structure containing a Mass Storage Class configuration
and state
\param[in] BlockAddress  Data block starting address for the write sequence
\param[in] TotalBlocks   Number of blocks of data to write
Writes blocks ( OS blocks not Dataflash pages ) to the storage medium the board Dataflash IC ( s ) from the pre - selected data OUT endpoint . This routine reads in OS sized blocks from the endpoint and writes them to the Dataflash in Dataflash page sized blocks . \ param [ in ] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state \ param [ in ] BlockAddress Data block starting address for the write sequence \ param [ in ] TotalBlocks Number of blocks of data to write
void SDCardManager_WriteBlocks(USB_ClassInfo_MS_Device_t *const MSInterfaceInfo,
                               uint32_t BlockAddress, uint16_t TotalBlocks) 
{
#ifdef SDCARD_DRIVER_DEBUG
  Serial1.print("W ");
  Serial1.print(BlockAddress);
  Serial1.write(' ');
  Serial1.println(TotalBlocks);
#endif
  if (Endpoint_WaitUntilReady())
    return;
  while (TotalBlocks) {
    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_ClearOUT();
        if (Endpoint_WaitUntilReady())
          break;
      }
      for (uint8_t i = 0; i < MASS_STORAGE_IO_EPSIZE; ++i, ++buffer)
        *buffer = Endpoint_Read_8();
      if (MSInterfaceInfo->State.IsMassStoreReset)
        return;
    }
    if (!s_sdcard_driver.writeBlock(BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE, s_sd_raw_block))
      break;
    BlockAddress++;
    TotalBlocks--;
  }
  if (!(Endpoint_IsReadWriteAllowed()))
      Endpoint_ClearOUT();
}
void SDCardManager_WriteBlocks ( 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 ) { 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_ClearOUT ( ) ; if ( Endpoint_WaitUntilReady ( ) ) break ; } for ( uint8_t i = 0 ; i < MASS_STORAGE_IO_EPSIZE ; ++ i , ++ buffer ) * buffer = Endpoint_Read_8 ( ) ; if ( MSInterfaceInfo -> State . IsMassStoreReset ) return ; } if ( ! s_sdcard_driver . writeBlock ( BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE , s_sd_raw_block ) ) break ; BlockAddress ++ ; TotalBlocks -- ; } if ( ! ( Endpoint_IsReadWriteAllowed ( ) ) ) Endpoint_ClearOUT ( ) ; }
Writes blocks (OS blocks, not Dataflash pages) to the storage medium, the board Dataflash IC(s),
 from
  the pre-selected data OUT endpoint.
Writes blocks ( OS blocks not Dataflash pages ) to the storage medium the board Dataflash IC ( s ) from the pre - selected data OUT endpoint .
/* Wait until endpoint is ready before continuing */ /* Check if the current command is being aborted by the host */ /* Decrement the blocks remaining counter */ /* If the endpoint is empty, clear it ready for the next packet from the host */