EFFS from multiple tasks

Discussion to talk about software related topics only.
Post Reply
User avatar
mx270a
Posts: 80
Joined: Tue Jan 19, 2010 6:55 pm

EFFS from multiple tasks

Post by mx270a »

Greetings. I'm having trouble figuring out how to make external flash work on my MOD5270. Here is the relevant code:

in the main.cpp file:

Code: Select all

void UserMain(void *pd) {
	OSChangePrio(MAIN_PRIO);
	f_enterFS();
	InitExtFlash();
	f_releaseFS();

	StartDHCPServer();

	while (1) {
		OSTimeDly(TICKS_PER_SECOND);
	}
}
in another.cpp file:

Code: Select all

void WaitForDHCPPackets(void * pd) {
	f_enterFS();
	DisplayEffsSpaceStats(); //This works

	char* FileName = "testfile.txt";
	ReadWriteTest(FileName); //This throws an error.

	<... more code here ...>
}
void StartDHCPServer() {
	#define DHCPSERVER_PRIO (MAIN_PRIO - 5)
	OSTaskCreate(WaitForDHCPPackets, (void *)67, &DHCPServerUDPStk[USER_TASK_STK_SIZE], DHCPServerUDPStk, DHCPSERVER_PRIO);
}
My problem is that the ReadWriteTest fails with error message:
*** Error in f_open(testfile.txt) during task(45)
F_ERR_INVALIDNAME

I have found that if I move the "InitExtFlash();" command from the main.cpp file into my other .cpp file right after "f_enterFS();", then the ReadWriteTest completes fine. However, this doesn't seem like a good solution to initialize the flash in one task if I'm going to have multiple tasks accessing the flash. If InitExtFlash() is supposed to be called from the main task, how would I get the readwrite test to work in another task?

Thanks,
Lance
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: EFFS from multiple tasks

Post by Ridgeglider »

The 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(). I do this in one function that manages EFFS access for up to 10 tasks and takes a form something like this:

Code: Select all

	f_enterFS();
	OSChangePrio(MY_TASK_A_PRIO);

	f_enterFS();
	OSChangePrio( MY_TASK_B_PRIO);

	//....
	f_enterFS();
	OSChangePrio( FTP_PRIO );

	f_enterFS();
	OSChangePrio( HTTP_PRIO );

	f_enterFS();
	OSChangePrio( MAIN_PRIO );
Next, you must call f_chdrive() from each task. I do this like this:

Code: Select all

void PrepTaskForEFFSaccess(void) {		// EFFS DOES NOT WORK in a task w/o
    char driveType[20];					// calling f_chdrive() in the task 1st.
    siprintf(driveType, "SD/MMC");
    int rv = f_chdrive( EXT_FLASH_DRV_NUM );

    if ( rv == F_NO_ERROR ) {
        iprintf( "%s drive change successful\r\n", driveType );
    } else {
        iprintf( "%s drive change failed: ", driveType );
        DisplayEffsErrorCode( rv );
    }
}
where EXT_FLASH_DRV_NUM is defined in cardtype.h.
ecasey
Posts: 164
Joined: Sat Mar 26, 2011 9:34 pm

Re: EFFS from multiple tasks

Post by ecasey »

Lance,

I had a similar problem some time back. I looked back a the code and saw this after the f_enterFS() int the task:

f_chdrive( EXT_FLASH_DRV_NUM );/* Check the Drive - otherwise it doesn't work in this task */

I don't recall why this worked but it did.

Ed
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: EFFS from multiple tasks

Post by v8dave »

Hi Ed,

I have the exact same call in my tasks. Without, you can't do any file access.

Code: Select all

    f_enterFS();

    f_chdrive(MMC_DRV_NUM);				// We need to access this drive from this task
Dave...
ecasey
Posts: 164
Joined: Sat Mar 26, 2011 9:34 pm

Re: EFFS from multiple tasks

Post by ecasey »

Dave,

Some bad commenting on my part: ch_drive() is "change drive", not "check drive". I makes sense that you have to tell the Task which drive to use.
It wasn't obvious (or emphasized enough) that you have to do this from the example or the documentation.

Ed
User avatar
mx270a
Posts: 80
Joined: Tue Jan 19, 2010 6:55 pm

Re: EFFS from multiple tasks

Post by mx270a »

Thanks everyone. I had tried to run InitExtFlash() in my second task, but it was aborting when f_mountfat() tried to run a second time, so it wasn't getting to the f_chdrive() part. Now that I added f_chdrive() by itself, I can access files in more than one task.

-Lance
Post Reply