Problems using f_stat, f_findfirst and f_tell

Discussion to talk about software related topics only.
Post Reply
lslarry86
Posts: 24
Joined: Tue Jul 18, 2017 12:28 pm

Problems using f_stat, f_findfirst and f_tell

Post by lslarry86 »

I am getting a decimal 37 return code from each of the library functions f_tell, f_stat and f_findfirst. I don't know how to interpret the number. If it corresponds to:
"F_ERR_TASKNOTFOUND", // 37
I still don't know what that means despite its appearance in fwerr.h.

The big picture is that my code opens a file called "data.csv" on onboard mmc. In response to a trigger, the next text line is sent to UART 1. The idea is to inject CSV lines instead of barcode strings, which come in UART 0. That file is currently just sequential numbers in ASCII:
00000001
00000002
00000003
00000004
00000005

I can send 1, 2, 3, then login to ftp and run ls, which triggers this code. Then I can continue, injecting 4, 5, ..., even though the code below uses ftell and fseek to read the file size. This code is called from FTPD_GetFileSize:

Code: Select all

	if (NULL != DataCsvFile_p)
	{
		if (!strcmp(pFn, DataCsvFileName))
		{
			unsigned long pos0 = f_tell(DataCsvFile_p);
			f_seek(DataCsvFile_p, 0, SEEK_END);
			ret = f_tell(DataCsvFile_p);
			f_seek(DataCsvFile_p, pos0, 0);
		}
	}
The file read uses the same global file pointer, as long as it is not NULL.

f_tell returns 37 in both places. It returns 37 if I send a few lines and try again. f_stat and f_findfirst also return 37 with junk in the structures.

The fact that correct text lines are coming out when I trigger tells me that I am opening the mmc and the file correctly.

Can anyone give me a hint or example of the proper use of seek/tell or stat in Netburner EFFS? I am using chip 54415 with Netburner IDE 2.8.2 on Win10.

Thanks,
Larry
ecasey
Posts: 164
Joined: Sat Mar 26, 2011 9:34 pm

Re: Problems using f_stat, f_findfirst and f_tell

Post by ecasey »

Are you making a call to f_enterFS() in the task that that originates the calls to f_seek and f_tell?
The error seems to indicate that the calling task is not initialized for the file system.
lslarry86
Posts: 24
Joined: Tue Jul 18, 2017 12:28 pm

Re: Problems using f_stat, f_findfirst and f_tell

Post by lslarry86 »

I am making that call from UserMain. It sounds like that may be a different task than the FTP Server. I'll look harder at the FTP example in StandardStack\EFFS\EFFS-FTP

I hope I don't lose the use of the filesystem from UserMain when I move the f_enterFS call.

Thanks!
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Problems using f_stat, f_findfirst and f_tell

Post by TomNB »

I would try experimenting with the examples first. With regard to the fs_enter call, from the example:

/* The following call to f_enterFS() must be called in every task that accesses
the file system. This must only be called once in each task and must be done before
any other file system functions are used. Up to 10 tasks can be assigned to use
the file system. Any task may also be removed from accessing the file system with a
call to the function f_releaseFS(). */
f_enterFS();
lslarry86
Posts: 24
Joined: Tue Jul 18, 2017 12:28 pm

Re: Problems using f_stat, f_findfirst and f_tell

Post by lslarry86 »

That made it work, thanks very much! This is the new code in UserMain():

Code: Select all

    /*
     * The following call to f_enterFS() must be called in every task that
     * accesses the file system.  This must only be called once in each task
     * and must be done before any other file system functions are used.  Up to
     * 10 tasks can be assigned to use the file system.  Any task may also be
     * removed from accessing the file system with a call to the function
     * f_releaseFS().
     */
    f_enterFS();
    // We now must also enter the file system for the FTP task
    OSChangePrio( FTP_PRIO ); // This somehow makes UserMain the same as the uCOS FTP task,
    f_enterFS();              // and attaches the filesystem to that task too,
    OSChangePrio( MAIN_PRIO );// finally returning to execute the main task.
Before I was just doing the first call to f_enterFS, so FTP did not have access to the filesystem. Just like the error code said. f_stat is complaining about something else, but I'm past the 37 errcode. And UserMain still steps through the file data the way I want.
Post Reply