User`s manual

Dynamic C Users Manual digi.com 153
The outer while loop controls when to stop reading records from the file. After the last record is read, the
fat_Read() function is called once more, returning an end-of-file error. This causes the if statements
that are checking for this error to return TRUE, which resets filestate to zero, breaking out of the
outer while loop and freeing the lock for the putdata costatement to use.
The other costatement in the endless while loop is the one that blinks the LED. It illustrates that while
using the file system in non-blocking mode, there is still plenty of time for other tasks.
while (filestate){
icount = 0;
iptr = ibuf;
while (icount < REC_LEN) {
waitfor((rc = fat_Read(&file, iptr, REC_LEN-icount)) != -EBUSY);
if (rc < 0)
{
if (rc == -EEOF)
{
filestate = 0;
break;
}
printf("fat_Read: rc = %d\n",rc);
while ((rc=fat_UnmountDevice(first_part->dev)) == -EBUSY);
return rc;
}
iptr += rc;
icount += rc;
} // end of inner while loop
if (filestate)
{
printf("%s", ibuf);
readto += REC_LEN;
}
} // end of outer while loop