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

Committer:
DavidGilesHitex
Date:
Fri Nov 19 09:57:10 2010 +0000
Revision:
0:906fb336fd7a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidGilesHitex 0:906fb336fd7a 1 /* SD-Card Utility Program for RS-EDP and RS-EDP mbed adapter module */
DavidGilesHitex 0:906fb336fd7a 2 /* ***************************************************************** */
DavidGilesHitex 0:906fb336fd7a 3
DavidGilesHitex 0:906fb336fd7a 4 /* This application will create a file and write a few bytes to the SD Card on the mbed adapter board */
DavidGilesHitex 0:906fb336fd7a 5
DavidGilesHitex 0:906fb336fd7a 6
DavidGilesHitex 0:906fb336fd7a 7 #include "mbed.h"
DavidGilesHitex 0:906fb336fd7a 8
DavidGilesHitex 0:906fb336fd7a 9 #include "defines.h"
DavidGilesHitex 0:906fb336fd7a 10 #include "misra_types.h"
DavidGilesHitex 0:906fb336fd7a 11 #include "mbed_Port_Structure.h"
DavidGilesHitex 0:906fb336fd7a 12
DavidGilesHitex 0:906fb336fd7a 13 #include "SDFileSystem.h"
DavidGilesHitex 0:906fb336fd7a 14
DavidGilesHitex 0:906fb336fd7a 15
DavidGilesHitex 0:906fb336fd7a 16
DavidGilesHitex 0:906fb336fd7a 17
DavidGilesHitex 0:906fb336fd7a 18 /* Main Loop Here */
DavidGilesHitex 0:906fb336fd7a 19 int main(void)
DavidGilesHitex 0:906fb336fd7a 20 {
DavidGilesHitex 0:906fb336fd7a 21 FILE *MyNewFile;
DavidGilesHitex 0:906fb336fd7a 22 char file_name_with_root_and_path[30];
DavidGilesHitex 0:906fb336fd7a 23 char input_file_name[30];
DavidGilesHitex 0:906fb336fd7a 24 char *pointer1;
DavidGilesHitex 0:906fb336fd7a 25 char *pointer2;
DavidGilesHitex 0:906fb336fd7a 26 char n = 0;
DavidGilesHitex 0:906fb336fd7a 27
DavidGilesHitex 0:906fb336fd7a 28
DavidGilesHitex 0:906fb336fd7a 29 for (n = 0; n < 30; n++) /* initialise arrays to zero */
DavidGilesHitex 0:906fb336fd7a 30 {
DavidGilesHitex 0:906fb336fd7a 31 file_name_with_root_and_path[n] = 0;
DavidGilesHitex 0:906fb336fd7a 32 input_file_name[n] = 0;
DavidGilesHitex 0:906fb336fd7a 33 }
DavidGilesHitex 0:906fb336fd7a 34
DavidGilesHitex 0:906fb336fd7a 35 setup_mbed_ports(); /* Setup the I/O Structure of the mbed module */
DavidGilesHitex 0:906fb336fd7a 36
DavidGilesHitex 0:906fb336fd7a 37 pc.printf("\n\n\n\n\n\n\n\rWelcome the the RS-EDP platform\n\r");
DavidGilesHitex 0:906fb336fd7a 38 pc.printf("This software is for the MBED - LPC1768 Module\n\r");
DavidGilesHitex 0:906fb336fd7a 39 pc.printf("This software exercises the on board SD-CARD card via an SPI interface\n\r");
DavidGilesHitex 0:906fb336fd7a 40 pc.printf("The SD card slot is present on the reverse side of the MBED adapter board\n\r");
DavidGilesHitex 0:906fb336fd7a 41 pc.printf("\nSoftware Revision Number: %03d\n\r\n", FIRMWARE_VERSION);
DavidGilesHitex 0:906fb336fd7a 42
DavidGilesHitex 0:906fb336fd7a 43 pc.printf("This application writes a few bytes to a txt file on the SD-CARD\n\r");
DavidGilesHitex 0:906fb336fd7a 44 pc.printf("Make sure the LOCAL ECHO on your terminal emulator is turned ON\n\r");
DavidGilesHitex 0:906fb336fd7a 45
DavidGilesHitex 0:906fb336fd7a 46 User_Led1 = LED_OFF;
DavidGilesHitex 0:906fb336fd7a 47 User_Led2 = LED_OFF;
DavidGilesHitex 0:906fb336fd7a 48 User_Led3 = LED_OFF;
DavidGilesHitex 0:906fb336fd7a 49 User_Led4 = LED_OFF;
DavidGilesHitex 0:906fb336fd7a 50
DavidGilesHitex 0:906fb336fd7a 51 while(1)
DavidGilesHitex 0:906fb336fd7a 52 {
DavidGilesHitex 0:906fb336fd7a 53
DavidGilesHitex 0:906fb336fd7a 54 pointer1 = file_name_with_root_and_path; /* set pointer1 to point at the complete name and path array */
DavidGilesHitex 0:906fb336fd7a 55 strcpy(pointer1, "/sd/"); /* Start to build the root, directory and file name of the file we want to create */
DavidGilesHitex 0:906fb336fd7a 56
DavidGilesHitex 0:906fb336fd7a 57 pointer2 = input_file_name; /* set pointer2 to point at an empty string array to take the user input file name */
DavidGilesHitex 0:906fb336fd7a 58 pc.printf("Enter the file name you wish to create\n\r\n");
DavidGilesHitex 0:906fb336fd7a 59
DavidGilesHitex 0:906fb336fd7a 60 scanf("%s", pointer2); /* Get the file name into an array called 'input_file_name', pointed to by a pointer called pointer2 */
DavidGilesHitex 0:906fb336fd7a 61 strcat(pointer1, pointer2); /* Add on the entered file name to the root direcotry, and store in pointer1 */
DavidGilesHitex 0:906fb336fd7a 62
DavidGilesHitex 0:906fb336fd7a 63
DavidGilesHitex 0:906fb336fd7a 64 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 */
DavidGilesHitex 0:906fb336fd7a 65
DavidGilesHitex 0:906fb336fd7a 66 MyNewFile = fopen(file_name_with_root_and_path, "w"); /* attempt to open/create the file */
DavidGilesHitex 0:906fb336fd7a 67
DavidGilesHitex 0:906fb336fd7a 68
DavidGilesHitex 0:906fb336fd7a 69 if (MyNewFile == 0 )
DavidGilesHitex 0:906fb336fd7a 70 {
DavidGilesHitex 0:906fb336fd7a 71 /* Problems - can not create the file whos name we just inputed */
DavidGilesHitex 0:906fb336fd7a 72 pc.printf("Unable to create the file '%s'\n\r", file_name_with_root_and_path);
DavidGilesHitex 0:906fb336fd7a 73 pc.printf("Please try again\n\n\r");
DavidGilesHitex 0:906fb336fd7a 74 }
DavidGilesHitex 0:906fb336fd7a 75 else{
DavidGilesHitex 0:906fb336fd7a 76 /* ok file is now open - lets print the header file */
DavidGilesHitex 0:906fb336fd7a 77 pc.printf("Writing to the file...\n\r");
DavidGilesHitex 0:906fb336fd7a 78 fprintf(MyNewFile, "This text string has just been written to your file");
DavidGilesHitex 0:906fb336fd7a 79 pc.printf("Finished writing to the file...\n\n\r");
DavidGilesHitex 0:906fb336fd7a 80 fclose(MyNewFile); /* Close the file */
DavidGilesHitex 0:906fb336fd7a 81 }
DavidGilesHitex 0:906fb336fd7a 82 }
DavidGilesHitex 0:906fb336fd7a 83 }
DavidGilesHitex 0:906fb336fd7a 84