This software is designed to write to an SD card on the mbed adapter module which is part of the RS-EDP system.

Dependencies:   mbed SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* SD-Card Utility Program for RS-EDP and RS-EDP mbed adapter module */
00002 /* ***************************************************************** */
00003 
00004 /* This application will create a file and write a few bytes to the SD Card on the mbed adapter board */
00005 
00006 
00007 #include "mbed.h"
00008 
00009 #include "defines.h"
00010 #include "misra_types.h"
00011 #include "mbed_Port_Structure.h"
00012 
00013 #include "SDFileSystem.h"
00014 
00015 
00016 
00017 
00018 /* Main Loop Here */
00019 int main(void) 
00020     {
00021         FILE *MyNewFile;
00022         char file_name_with_root_and_path[30];
00023         char input_file_name[30];
00024         char *pointer1;
00025         char *pointer2;
00026         char n = 0;
00027 
00028 
00029         for (n = 0; n < 30; n++)                                                       /* initialise arrays to zero */
00030             {
00031                 file_name_with_root_and_path[n] = 0;    
00032                 input_file_name[n] = 0;
00033             }
00034             
00035         setup_mbed_ports();                                                            /* Setup the I/O Structure of the mbed module */
00036 
00037         pc.printf("\n\n\n\n\n\n\n\rWelcome the the RS-EDP platform\n\r");
00038         pc.printf("This software is for the MBED - LPC1768 Module\n\r");
00039         pc.printf("This software exercises the on board SD-CARD card via an SPI interface\n\r");
00040         pc.printf("The SD card slot is present on the reverse side of the MBED adapter board\n\r");        
00041         pc.printf("\nSoftware Revision Number: %03d\n\r\n", FIRMWARE_VERSION);
00042         
00043         pc.printf("This application writes a few bytes to a txt file on the SD-CARD\n\r"); 
00044         pc.printf("Make sure the LOCAL ECHO on your terminal emulator is turned ON\n\r"); 
00045           
00046         User_Led1 = LED_OFF;
00047         User_Led2 = LED_OFF;
00048         User_Led3 = LED_OFF;
00049         User_Led4 = LED_OFF;    
00050         
00051         while(1)
00052             {            
00053 
00054                 pointer1 = file_name_with_root_and_path;                                  /* set pointer1 to point at the complete name and path array */
00055                 strcpy(pointer1, "/sd/");                                                 /* Start to build the root, directory and file name of the file we want to create */
00056        
00057                 pointer2 = input_file_name;                                               /* set pointer2 to point at an empty string array to take the user input file name */
00058                 pc.printf("Enter the file name you wish to create\n\r\n");
00059 
00060                 scanf("%s", pointer2);                                                    /* Get the file name into an array called 'input_file_name', pointed to by a pointer called pointer2 */
00061                 strcat(pointer1, pointer2);                                               /* Add on the entered file name to the root direcotry, and store in pointer1 */
00062 
00063 
00064                 pc.printf("Creating the file: %s\n\r", file_name_with_root_and_path);     /* Print the name including the root and path of the file */
00065 
00066                 MyNewFile = fopen(file_name_with_root_and_path, "w");                     /* attempt to open/create the file */
00067 
00068 
00069                 if (MyNewFile == 0 ) 
00070                     {
00071                         /* Problems - can not create the file whos name we just inputed */
00072                         pc.printf("Unable to create the file '%s'\n\r", file_name_with_root_and_path);
00073                         pc.printf("Please try again\n\n\r");                    
00074                     }
00075                 else{
00076                         /* ok file is now open - lets print the header file */
00077                         pc.printf("Writing to the file...\n\r");                    
00078                         fprintf(MyNewFile, "This text string has just been written to your file");
00079                         pc.printf("Finished writing to the file...\n\n\r");                    
00080                         fclose(MyNewFile);                                                  /* Close the file */
00081                     }
00082             }
00083       }
00084