CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with mmd stack

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Problem with mmd stack
PostPosted: Tue Feb 26, 2013 2:06 am     Reply with quote

Hi! I have a PIC18F66J60 connected to a SD card. I`m using CCS mmd stack form 22.06.2012. I have a problem. I can make new files, to add data to them. But when I try to make a new folder it doesn`t work.
I`m using FSmkdir(dir) as the example file says. dir is a char array:
Code:

char dir[6]="folder";

I tried many options: sending a pointer to the char array. Making unlimited array(char dir[]="folder";). But finally I don`t have new folder in the sd card.
Can you tell me what the problem is???
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 2:51 am     Reply with quote

Several things:

First:
Code:

char dir[6]="folder";


How long is the string "folder"?. It is _not_ six characters long, but seven. _Strings must always have space for the terminating null character_. Basic C.

Second:
Read the comments at the top of the CCS library:
"
//// Any function with an argument taking in a directory name must ////
//// be in the form of... ////
//// "/Dirname/" for a directory in the root directory ////
//// "/Dirname/Subdirname/" for a directory in a subdirectory of ////
//// root and so on... "

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 4:19 am     Reply with quote

I tried but again nothing. Here is my whole program:
Code:

void MountMedia(void)
{
   g_IsMounted = FALSE;
   
   MDD_InitIO();
   
   if (!MDD_MediaDetect())
   {
     
      reset_cpu();
   }
   
   if (FSInit())
   {
      g_IsMounted = TRUE;
   }
   else
   {
      reset_cpu();
   }
}

void main(void)
{
   char folderName[9]="/FOLDER/";
   int status=0;
   MountMedia();
   delay_ms(100);
   status=FSmkdir(folderName);
   while(1);
}

May be there is something else?! If I add the string directly to the function like this : FSmkdir("Folder"); everything is OK. It`s making a new folder. Can you give me an example for char array containing valid folder name??
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 4:56 am     Reply with quote

The 'MDD stack', is _not_ CCS. It's Microchip.
Use the CCS mdd driver, this works with the commands as outlined. If you are using the Microchip stack, then ask them.....

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 5:28 am     Reply with quote

But I have this stack from CCS!
I fixed it. I have to pass pointer to the function, not a string!
Thanks, anyway!
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 1:33 am     Reply with quote

I have another question! FSchdir(char *pointer) is changing the active directory. But how can I go back to the root directory?
I tried to pass an empty string to FSchdir but this is not working...
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 2:48 am     Reply with quote

Root directory is normally "\".

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 3:45 am     Reply with quote

OK, but FSchdir('\') is not throughing an error. "\" too...
I saught the most function are working with the path to the concrete file.
For example:
Code:

char filePath[]="root/secondFolder/file.txt";
char *filePathPointer=&filePath[0];

AppendFile(filePathPointer,infoPointer);

So I`m making changes to filePath I can move through the folders without using FSchdir(). But this is little bit more complicated because I have to do more string operations.
Any other ideas how to go up through the filetree with FSchdir()???
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 4:06 am     Reply with quote

You probably need to use "/". I'm used to OS's that use "\" (Linux/Unix/Mac etc...).

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 4:20 am     Reply with quote

I tried it too.. No success.
I think I have to use something more special. For example in CMD cd .. is the command from level up...
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 11:58 am     Reply with quote

RTFM !
I'm sorry to say so, but have you even tried looking into the manual provided by Microchip?
AN1045 - File I/O Functions Using Microchip's Memory Disk Drive File System Library

It took me just 10 seconds scrolling to arrive on page 6 where I found:
Quote:
TABLE 7: EXAMPLE DIRECTORY PATH STRINGS

"\" The root directory.
"." Current directory.
".." Previous directory.
"ONE" Directory ONE in the current directory
....


Pay special attention to the bold printed note:
Quote:
Note:
When hard-coding the string in C, double
backslashes are required. Refer to the API
descriptions of FSmkdir, FSchdir, FSrmdir and FSgetcwd
This text is repeated in other wordings in the same page. And this is a common practice in all C compilers, not only for this Microchip library. I guess it is even mentioned in the CCS manual.

So, to return to the directory home your string should look like:
Code:
"\\"       ; root directory
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 3:58 am     Reply with quote

Thanks, ckielstra! I haven`t seen this AN, but there are many interesting things in it!
Can I ask one more thing?
Here is the code of PrintFile function from ex_fat.c in the mdd library:
Code:

void PrintFile(char *fileName, int1 startFromEnd)
{
   char scr[65];
   size_t len;
   FSFILE* f;

   if (!g_IsMounted)
   {
      printf("\r\nMedia not mounted, not going to display file!");
      return;
   }

   f = FSfopen(fileName, "r");
   if (!f)
   {
      printf("\r\nError opening file (Error %X)", FSerrno);
      return;
   }

   printf("\r\n");

   if(startFromEnd)
      FSfseek(f, 80, SEEK_END);

   do
   {
      len = FSfread(scr, sizeof(char), (sizeof(scr)-1), f);
      if (FSerrno && (FSerrno != CE_EOF))
      {
         printf("\r\n!!! Error reading file (Error %X)", FSerrno);
         len = 0;     
      }
      scr[len] = 0;
      //DEBUG_STR("PrintFile() got", len);
      printf("%s", scr);
   } while(FSerrno != CE_EOF);

   FSfclose(f);
}

This code returns the first 80 characters from a file if there are so many. I want to rework this function so it to return a single row of data from a file. Here is my problem - the function is waiting for character for end of file(CE_EOF==61), but the symbols for end of row is "\r\n". So there are 4 characters but FSerrno is contaning only 1. Can you tell me a simple way to achieve this?
Thanks!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 01, 2013 9:30 am     Reply with quote

stoyanoff wrote:
Thanks, ckielstra! I haven`t seen this AN, but there are many interesting things in it!
Unbelievable you are working on this library for 10 weeks now and didn't find the AN. In this thread of yours I already pointed to the page where all Microchip information regarding this library is located.

Quote:
... the symbols for end of row is "\r\n". So there are 4 characters ...
Sigh.... Rolling Eyes
Your knowledge is lacking some of the basic C language features. I know you are a beginner but to me this really feels like I'm spoon feeding you with little bits of knowledge and you are just repeating the 'trick' without understanding what is going on.
The above quote contains an error, there are not 4 characters but only 2 in '\r\n'. What is really annoying is that exactly 1 post ago I explained to you that in order to get a '\' character printed you have to write '\\'. I didn't say with so many words that the first '\' character is used as an 'escape sequence' for denoting special characters, but that was because I referred to the AN and the CCS manual where this is all described in more detail. I hoped you would go and look up this information. You didn't. I'm wasting my time here.

Quote:
Can I ask one more thing?
No, I'm out of here.

P.S.: for printing 80 characters your buffer length of 65 is wrong.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Tue Mar 05, 2013 5:20 am     Reply with quote

OK! I made. This AN was very helpful! Now I'm trying to do something more complicated. My problem is I can't use the value of file size.
First I'm opening a file:
Code:

    f = FSfopen(fileName, "r");
   if (!f)
   {
      return 2;
   }

Next I want to use the f.size option. My file has 0x00000080 chars size. But when I try to take this value, for example
Code:
long fileSize=f.size;

fileSize incorrect value = 0x00000172.
If I try to use directly f.size like this:
Code:

if(number>=f.size)
{
    .....
}

It`s not working properly.
What am I doing wrong?
Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group