1 /* Copyright 2011 Adam Green (http://mbed.org/users/AdamGreen/)
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
15 /* LocalFileSystem test modified to use SD cards instead. */
17 #include "SDFileSystem/SDFileSystem.h"
18 #include "../agutil/agutil.h"
21 extern "C" void HardFault_Handler(void)
24 error("\r\nHardFault\r\n");
27 extern "C" void MemManage_Handler(void)
30 error("\r\nMemManage\r\n");
33 extern "C" void BusFault_Handler(void)
36 error("\r\nBusFault\r\n");
39 extern "C" void UsageFault_Handler(void)
42 error("\r\nUsageFault\r\n");
45 extern "C" void SVC_Handler(void)
48 error("\r\nSVC Call\r\n");
51 extern "C" void DebugMon_Handler(void)
54 error("\r\nDebugMonitor\r\n");
57 extern "C" void PendSV_Handler(void)
60 error("\r\nPendSV\r\n");
63 extern "C" void SysTick_Handler(void)
70 void BreakHandler(void)
73 error("\r\nManual Break\r\n");
77 SDFileSystem
sd(p5
, p6
, p7
, p8
, "sd"); // the pinout on the mbed Cool Components workshop board
78 InterruptIn
BreakInterrupt(p9
);
83 // If you pull p9 low, then it should break into a running program and dump the stack.
84 BreakInterrupt
.mode(PullUp
);
85 BreakInterrupt
.fall(BreakHandler
);
90 printf("\r\n\r\nGCC4MBED Test Suite\r\n");
91 printf("sdFileSystem Unit Tests\r\n");
93 printf("Test 1: fopen() for write\r\n");
94 FILE *fp
= fopen("/sd/out.txt", "w"); // Open "out.txt" on the sd file system for writing
97 error("%s(%d) fopen() failed\r\n", __FILE__
, __LINE__
);
100 printf("Test 2: fprintf()\r\n");
101 Result
= fprintf(fp
, "Hello World!");
104 error("%s(%d) fprintf() failed\r\n", __FILE__
, __LINE__
);
107 printf("Test 3: fclose() on written file\r\n");
111 error("%s(%d) fclose() failed\r\n", __FILE__
, __LINE__
);
116 printf("Test 4: fopen() for read\r\n");
117 fp
= fopen("/sd/out.txt", "r");
120 error("%s(%d) fopen() failed\r\n", __FILE__
, __LINE__
);
123 printf("Test 5: fscanf()\r\n");
124 Result
= fscanf(fp
, "%31s", Buffer
);
127 error("%s(%d) fscanf() failed\r\n", __FILE__
, __LINE__
);
129 printf("Contents of /sd/out.txt: %s\r\n", Buffer
);
131 printf("Test 6: fclose() on read file\r\n");
135 error("%s(%d) fclose() failed\r\n", __FILE__
, __LINE__
);
140 printf("Test 7: remove()\r\n");
141 Result
= remove("/sd/out.txt"); // Removes the file "out.txt" from the sd file system
144 error("%s(%d) remove() failed\r\n", __FILE__
, __LINE__
);
148 printf("Test 8: opendir()\r\n");
149 DIR *d
= opendir("/sd"); // Opens the root directory of the sd file system
153 error("%s(%d) opendir() failed\r\n", __FILE__
, __LINE__
);
157 printf("Test 9: readir() for all entries\r\n");
158 while((p
= readdir(d
)) != NULL
)
159 { // Print the names of the files in the sd file system
160 printf("%s\r\n", p
->d_name
); // to stdout.
163 printf("Test 10: closedir\r\n");
168 printf("\r\nTest completed\r\n");