Das Lesen einer Datei über Blockread bricht bei mir nach 24477696 gelesenen Bytes ab.
Die Funktion liefert ein false zurück, obwohl die Datei noch nicht komplett gelesen wurde.
Kann das jemand bestätigen?
Gruß
Thomas
Ausgabe Terminalprogramm
size of Alarm1.wav = 38400124<r><n>
calculate crc of Alarm1.wav<r><n>
file system io error while calculating CRC<r><n>
block count = 47808<r><n>
byte count old = 512<r><n>
byte count = 0<r><n>
Testcode
program calcCRC;
Device = xmega128A4U, VCC = 3.3; // only USB version supports crc module
define_fuses
Override_Fuses;
NoteBook = A;
COMport = USB;
FuseBits1 = [WDPER0, WDPER2]; // watchdog = 8s
FuseBits4 = [WDLOCK];
FuseBits5 = [BODACT0, BODLEVEL0, BODLEVEL1, BODLEVEL2]; // BOD = 3V
ProgFuses = true;
Import SysTick, SerportE0, FAT16_32, XMega_CRC;
From SysTick Import SystemTime16;
From System Import longword;
define
OSCtype = extXTAL = 4096000, PLLmul = 15, prescA = 2, prescB = 1, prescC = 1;
SysTick = 10;
StackSize = 256, iData;
FrameSize = 384, iData;
SerPortE0 = 115200, Stop1; // debug connection
FAT16 = SPI_D, PortD.4, iData; // SPI_X, SS-Port, SS-PIN, data area
F16_FileHandles = 4;
F16_DirLevels = 2;
F16_MMCspeed = superfast; // standard, slow, fast, superfast (fat32)
F16_StrLen = 80; // buffer for Writeln to files
uses UFAT16_32;
implementation
const
BLOCKSIZE : word = 512;
type
tFileBuffer = array[0..BLOCKSIZE-1] of byte;
var
{$IDATA}
fileforCRC : file of byte;
filebuffer : tFileBuffer;
{------------------------------------------------------------------------------}
function calculateCRC : boolean;
var
fname : TFileName;
blockCount : longWord;
fSize : longword;
byteCount_old : word;
byteCount : word;
fsStatus : boolean;
begin
fname := 'Alarm1.wav';
if F16_FileSize('', fname, fSize) then
Writeln(SeroutE0, 'size of ' + fname + ' = ' + LongToStr(fSize));
else
Writeln(SeroutE0, 'F16_fileSize failed');
endif;
Writeln(SeroutE0, 'calculate crc of ' + fname);
if not F16_FileAssign(fileforCRC, '', fname) then
Writeln(SeroutE0, 'open ' + fname + ' failed');
return(false);
endif;
if not F16_FileReset(fileforCRC) then
Writeln(SeroutE0, 'file reset failed');
F16_FileClose(fileforCRC);
return(false);
endif;
// calculate crc
blockCount := 0;
while not F16_EndOfFile(fileforCRC) do
ASM: WDR;
fsStatus := F16_BlockRead(fileforCRC, @filebuffer, Sizeof(filebuffer), byteCount); // long timeout
if fsStatus = false then
// file system io error
F16_FileClose(fileforCRC);
Writeln(SeroutE0, 'file system io error while calculating CRC');
Writeln(SeroutE0, 'block count = ' + LongToStr(blockCount));
Writeln(SeroutE0, 'byte count old = ' + IntToStr(byteCount_old));
Writeln(SeroutE0, 'byte count = ' + IntToStr(byteCount));
return(false);
else
inc(blockCount);
// add bytes to crc calculation
endif;
byteCount_old := byteCount;
endwhile;
F16_FileClose(fileforCRC);
return(true);
end;
//------------------------------------------------------------------------------
// main
begin
loop
ASM: WDR;
while not F16_DiskInit do
Writeln(SeroutE0, 'disk init failed');
mDelay(1000);
endwhile;
if not F16_DiskReset then
Writeln(SeroutE0, 'disk failed');
else
calculateCRC;
endif;
endloop;
end.
Die Funktion liefert ein false zurück, obwohl die Datei noch nicht komplett gelesen wurde.
Kann das jemand bestätigen?
Gruß
Thomas
Ausgabe Terminalprogramm
Code
size of Alarm1.wav = 38400124<r><n>
calculate crc of Alarm1.wav<r><n>
file system io error while calculating CRC<r><n>
block count = 47808<r><n>
byte count old = 512<r><n>
byte count = 0<r><n>
Testcode
Code
program calcCRC;
Device = xmega128A4U, VCC = 3.3; // only USB version supports crc module
define_fuses
Override_Fuses;
NoteBook = A;
COMport = USB;
FuseBits1 = [WDPER0, WDPER2]; // watchdog = 8s
FuseBits4 = [WDLOCK];
FuseBits5 = [BODACT0, BODLEVEL0, BODLEVEL1, BODLEVEL2]; // BOD = 3V
ProgFuses = true;
Import SysTick, SerportE0, FAT16_32, XMega_CRC;
From SysTick Import SystemTime16;
From System Import longword;
define
OSCtype = extXTAL = 4096000, PLLmul = 15, prescA = 2, prescB = 1, prescC = 1;
SysTick = 10;
StackSize = 256, iData;
FrameSize = 384, iData;
SerPortE0 = 115200, Stop1; // debug connection
FAT16 = SPI_D, PortD.4, iData; // SPI_X, SS-Port, SS-PIN, data area
F16_FileHandles = 4;
F16_DirLevels = 2;
F16_MMCspeed = superfast; // standard, slow, fast, superfast (fat32)
F16_StrLen = 80; // buffer for Writeln to files
uses UFAT16_32;
implementation
const
BLOCKSIZE : word = 512;
type
tFileBuffer = array[0..BLOCKSIZE-1] of byte;
var
{$IDATA}
fileforCRC : file of byte;
filebuffer : tFileBuffer;
{------------------------------------------------------------------------------}
function calculateCRC : boolean;
var
fname : TFileName;
blockCount : longWord;
fSize : longword;
byteCount_old : word;
byteCount : word;
fsStatus : boolean;
begin
fname := 'Alarm1.wav';
if F16_FileSize('', fname, fSize) then
Writeln(SeroutE0, 'size of ' + fname + ' = ' + LongToStr(fSize));
else
Writeln(SeroutE0, 'F16_fileSize failed');
endif;
Writeln(SeroutE0, 'calculate crc of ' + fname);
if not F16_FileAssign(fileforCRC, '', fname) then
Writeln(SeroutE0, 'open ' + fname + ' failed');
return(false);
endif;
if not F16_FileReset(fileforCRC) then
Writeln(SeroutE0, 'file reset failed');
F16_FileClose(fileforCRC);
return(false);
endif;
// calculate crc
blockCount := 0;
while not F16_EndOfFile(fileforCRC) do
ASM: WDR;
fsStatus := F16_BlockRead(fileforCRC, @filebuffer, Sizeof(filebuffer), byteCount); // long timeout
if fsStatus = false then
// file system io error
F16_FileClose(fileforCRC);
Writeln(SeroutE0, 'file system io error while calculating CRC');
Writeln(SeroutE0, 'block count = ' + LongToStr(blockCount));
Writeln(SeroutE0, 'byte count old = ' + IntToStr(byteCount_old));
Writeln(SeroutE0, 'byte count = ' + IntToStr(byteCount));
return(false);
else
inc(blockCount);
// add bytes to crc calculation
endif;
byteCount_old := byteCount;
endwhile;
F16_FileClose(fileforCRC);
return(true);
end;
//------------------------------------------------------------------------------
// main
begin
loop
ASM: WDR;
while not F16_DiskInit do
Writeln(SeroutE0, 'disk init failed');
mDelay(1000);
endwhile;
if not F16_DiskReset then
Writeln(SeroutE0, 'disk failed');
else
calculateCRC;
endif;
endloop;
end.