Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystemCpp SDHC_FileSystem mbed
Diff: main.cpp
- Revision:
- 0:58238bb83503
- Child:
- 1:2b18f6628bc1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 08 01:42:33 2013 +0000 @@ -0,0 +1,64 @@ +#include "mbed.h" +#include "SDHCFileSystem.h" + +#define SIZE 10240 // KB + +Serial pc(USBTX, USBRX); +DigitalOut myled(LED1); +SDFileSystem sd(p5, p6, p7, p8, "sd"); +Timer t; + +float wtest (int b, int d) { + int i; + int s = b / d; + char buf[d]; + FILE *fp; + + fp = fopen("/sd/sdhc_test.dat", "w"); + if (!fp) return 0; + myled = 1; + t.reset(); + t.start(); + for (i = 0; i < s; i ++) { + fwrite(buf, sizeof(unsigned char), d, fp); + } + fclose(fp); + t.stop(); + myled = 0; + return t.read(); +} + +float rtest (int b, int d) { + int i; + int s = b / d; + char buf[d]; + FILE *fp; + + fp = fopen("/sd/test.dat", "r"); + if (!fp) return 0; + myled = 1; + t.reset(); + t.start(); + for (i = 0; i < s; i ++) { + fread(buf, sizeof(unsigned char), d, fp); + } + fclose(fp); + t.stop(); + myled = 0; + return t.read(); +} + +int main() { + + pc.baud(115200); + pc.printf("start\r\n"); + + pc.printf("write 1: %f KB/sec\r\n", (float)SIZE / wtest(SIZE * 1024, 1)); + pc.printf("read 1: %f KB/sec\r\n", (float)SIZE / rtest(SIZE * 1024, 1)); + pc.printf("write 100: %f KB/sec\r\n", (float)SIZE / wtest(SIZE * 1024, 100)); + pc.printf("read 100: %f KB/sec\r\n", (float)SIZE / rtest(SIZE * 1024, 100)); + pc.printf("write 10k: %f KB/sec\r\n", (float)SIZE / wtest(SIZE * 1024, 10000)); + pc.printf("read 10k: %f KB/sec\r\n", (float)SIZE / rtest(SIZE * 1024, 10000)); + + return 0; +}