DRESULT disk_write(BYTE drv, BYTE const *buff, DWORD sector, UINT count) { #if ACCESS_MEM_TO_RAM uint8_t uc_sector_size = mem_sector_size(drv); uint32_t i; uint32_t ul_last_sector_num; if (uc_sector_size == 0) { return RES_ERROR; } /* Check valid address */ mem_read_capacity(drv, &ul_last_sector_num); if ((sector + count * uc_sector_size) > (ul_last_sector_num + 1) * uc_sector_size) { return RES_PARERR; } /* Write the data */ for (i = 0; i < count; i++) { if (ram_2_memory(drv, sector + uc_sector_size * i, buff + uc_sector_size * SECTOR_SIZE_DEFAULT * i) != CTRL_GOOD) { return RES_ERROR; } } return RES_OK; #else return RES_ERROR; #endif }
//! This fonction copy a data from memory to other memory //! //! @param src_lun The LUN of the source //! @param src_addr The address of the source //! @param dest_lun The LUN of the destination //! @param dest_addr The address of the destination //! @param nb_sector Number of sectors to transfer //! U8 stream_mem_to_mem( U8 src_lun , U32 src_addr , U8 dest_lun , U32 dest_addr , U16 nb_sector ) { while(nb_sector) { memory_2_ram( src_lun , &src_addr , buf_sector ); ram_2_memory( dest_lun , &dest_addr , buf_sector ); src_addr++; dest_addr++; nb_sector--; } return CTRL_GOOD; }
DRESULT disk_write(BYTE drv, BYTE const *buff, DWORD sector, BYTE count) { if (reprap.Debug(moduleStorage)) { debugPrintf("Write %u %u %lu\n", drv, count, sector); } #if ACCESS_MEM_TO_RAM MutexLocker lock((drv >= SD_MMC_HSMCI_MEM_CNT) ? Tasks::GetSpiMutex() : nullptr); const uint8_t uc_sector_size = mem_sector_size(drv); if (uc_sector_size == 0) { return RES_ERROR; } /* Check valid address */ uint32_t ul_last_sector_num; mem_read_capacity(drv, &ul_last_sector_num); if ((sector + count * uc_sector_size) > (ul_last_sector_num + 1) * uc_sector_size) { return RES_PARERR; } /* Write the data */ unsigned int retryNumber = 0; while (ram_2_memory(drv, sector, buff, count) != CTRL_GOOD) { ++retryNumber; if (retryNumber == MaxSdCardTries) { return RES_ERROR; } delay(SdCardRetryDelay); } if (retryNumber > highestSdRetriesDone) { highestSdRetriesDone = retryNumber; } return RES_OK; #else return RES_ERROR; #endif }
void ushell_cmd_perform_access( bool b_sens_write, Fs_file_segment seg ) { uint16_t u16_trans; uint32_t u32_tmp, u32_time; fat_cache_flush(); fat_cache_reset(); u32_time = Get_sys_count(); for( u16_trans=0; u16_trans<seg.u16_size; u16_trans++ ) { if( b_sens_write ) { if( CTRL_GOOD != ram_2_memory( seg.u8_lun , seg.u32_addr , fs_g_sector )) { printf( "Transfer error\r\n"); return; } }else{ if( CTRL_GOOD != memory_2_ram( seg.u8_lun , seg.u32_addr , fs_g_sector )) { printf( "Transfer error\r\n"); return; } } seg.u32_addr++; if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) ) { // Stop access after 8s break; } } u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz); u32_tmp = ((uint32_t)u16_trans*(1000000/2))/u32_time; if( b_sens_write ) printf( "Transfer rate - WRITE %4luKB/s\r\n", u32_tmp ); else printf( "Transfer rate - READ %4luKB/s\r\n", u32_tmp ); }