#include #include #include #include #include #if __SCZ180 #include #include /* Declaration of system time */ #elif __HBIOS #include /* Declaration of system time */ #elif __RC2014 #warning No time possible #else #error Do you have time? #endif #include "ffconf.h" #if __SCZ180 //#include /* Declarations of FatFs API */ //#include /* Declarations of diskio functions */ //#include /* Declarations of SD functions */ //#elif __SCZ180 #include /* Declarations of FatFs API */ #include /* Declarations of diskio functions */ #include /* Declarations of HBIOS functions */ #elif __HBIOS #include /* Declarations of FatFs API */ #include /* Declarations of diskio functions */ #include /* Declarations of HBIOS functions */ #else #warning - no FatFs library available #endif #include "ffconf.h" #pragma output CRT_ORG_BSS = 0x9000 // move bss origin to address 0x9000 (check map to confirm there is no overlap between data and bss sections) #pragma printf = "%s %c %u %li %lu" // enables %s, %c, %u, %li, %lu only // zcc +scz180 -subtype=hbios -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/scz180/time -llib/scz180/diskio_sd -llib/scz180/ff fileCopyTest.c -o fileCopyTest -create-app // zcc +scz180 -subtype=hbios -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/scz180/time -llib/hbios/diskio_hbios -llib/hbios/ff fileCopyTest.c -o fileCopyTest -create-app // zcc +hbios -clib=sdcc_iy -SO3 -v -m --list --max-allocs-per-node100000 -llib/scz180/time -llib/hbios/diskio_hbios -llib/hbios/ff fileCopyTest.c -o fileCopyTest -create-app static FILINFO Finfo; static FATFS FatFs; /* FatFs work area needed for each volume */ static FIL FileIn, FileOut; /* File object needed for each open file */ static BYTE buffer[4096]; /* 4kB working buffer */ int main (void) { UINT bw; UINT br; DWORD bwt = 0; FRESULT res; struct timespec startTime, endTime, resTime; startTime.tv_sec = 1577836800 - UNIX_OFFSET; clock_settime(CLOCK_REALTIME, &startTime); /* Set the time of day, y2k epoch */ if ((res = f_mount(&FatFs, "2:", 1)) == FR_OK) { /* Give a work area to the correct drive */ printf("\r\n\nFatFs.fs_type %u\nFatFs.fsize %lu\n", FatFs.fs_type, FatFs.fsize); printf("\r\nOpening 2:random1.txt"); if ((res = f_open(&FileIn, "2:random1.txt", FA_READ)) == FR_OK) { printf(" - Opened"); if ((res = f_lseek(&FileIn, 0)) == FR_OK) { printf("\r\nCreating 2:random2.txt"); if ((res = f_open(&FileOut, "2:random2.txt", FA_CREATE_ALWAYS | FA_WRITE)) == FR_OK) { printf(" - Created\r\n\nCopying..."); clock_gettime(CLOCK_REALTIME,&startTime); for (;;) { res = f_read(&FileIn, buffer, sizeof(buffer), &br); if (res != FR_OK || br == 0) break; // eof or error res = f_write(&FileOut, buffer, br, &bw); bwt += bw; if (res != FR_OK || bw < br) break; // error or disk full } clock_gettime(CLOCK_REALTIME,&endTime); f_close(&FileOut); if ((res = f_unlink("2:random2.txt")) != FR_OK) { printf("\r\nCouldn't delete 2:random2.txt - f_unlink error #%u\r\n", res); } } else { printf("\r\nCouldn't open 2:random2.txt - f_open error #%u\r\n", res); } } else { printf("\r\nCouldn't seek 2:random1.txt - f_lseek error #%u\r\n", res); } f_close(&FileIn); } else { printf("\r\nCouldn't open 2:random1.txt - f_open error #%u\r\n", res); } timersub(&endTime, &startTime, &resTime); printf("\r\nCopied %lu bytes", bwt ); printf(", the time taken was %li.%.4lu seconds\n", resTime.tv_sec, resTime.tv_nsec/100000 ); f_mount(0, "2:", 0); /* Free work area */ } else { printf("\r\nCouldn't mount drive - f_mount error #%u\r\n", res); } return 0; }