This is a simple benchmark of the SDFileSystem module. This will attempt to write bytes to the SD card, and will time the operation and display the bits/sec.
main.cpp@0:5e7c5b7321c9, 2011-02-14 (annotated)
- Committer:
- theterg
- Date:
- Mon Feb 14 22:12:09 2011 +0000
- Revision:
- 0:5e7c5b7321c9
1/14/10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
theterg | 0:5e7c5b7321c9 | 1 | #include "mbed.h" |
theterg | 0:5e7c5b7321c9 | 2 | |
theterg | 0:5e7c5b7321c9 | 3 | #include "SDFileSystem.h" |
theterg | 0:5e7c5b7321c9 | 4 | |
theterg | 0:5e7c5b7321c9 | 5 | Serial pc(USBTX, USBRX); // tx, rx |
theterg | 0:5e7c5b7321c9 | 6 | Serial device(p28, p27); // tx, rx |
theterg | 0:5e7c5b7321c9 | 7 | DigitalOut myled(LED4); |
theterg | 0:5e7c5b7321c9 | 8 | SDFileSystem sd(p11, p12, p13, p14, "sd"); |
theterg | 0:5e7c5b7321c9 | 9 | |
theterg | 0:5e7c5b7321c9 | 10 | long before; |
theterg | 0:5e7c5b7321c9 | 11 | long after; |
theterg | 0:5e7c5b7321c9 | 12 | char samp[3]; |
theterg | 0:5e7c5b7321c9 | 13 | char buff[100]; |
theterg | 0:5e7c5b7321c9 | 14 | Timer t; |
theterg | 0:5e7c5b7321c9 | 15 | |
theterg | 0:5e7c5b7321c9 | 16 | int getSample(); |
theterg | 0:5e7c5b7321c9 | 17 | void flush(); |
theterg | 0:5e7c5b7321c9 | 18 | |
theterg | 0:5e7c5b7321c9 | 19 | int main() { |
theterg | 0:5e7c5b7321c9 | 20 | FILE *header; |
theterg | 0:5e7c5b7321c9 | 21 | |
theterg | 0:5e7c5b7321c9 | 22 | pc.baud(19200); |
theterg | 0:5e7c5b7321c9 | 23 | device.baud(9600); |
theterg | 0:5e7c5b7321c9 | 24 | |
theterg | 0:5e7c5b7321c9 | 25 | while(1) { |
theterg | 0:5e7c5b7321c9 | 26 | memset(buff,'\0',10); |
theterg | 0:5e7c5b7321c9 | 27 | pc.printf("\r\nHow many bits would you like to test? "); |
theterg | 0:5e7c5b7321c9 | 28 | char temp = '\0'; |
theterg | 0:5e7c5b7321c9 | 29 | char idx = 0; |
theterg | 0:5e7c5b7321c9 | 30 | while (temp != '\r'){ |
theterg | 0:5e7c5b7321c9 | 31 | temp = pc.getc(); |
theterg | 0:5e7c5b7321c9 | 32 | buff[idx] = temp; |
theterg | 0:5e7c5b7321c9 | 33 | pc.putc(temp); |
theterg | 0:5e7c5b7321c9 | 34 | idx++; |
theterg | 0:5e7c5b7321c9 | 35 | } |
theterg | 0:5e7c5b7321c9 | 36 | long num = atol(buff); |
theterg | 0:5e7c5b7321c9 | 37 | pc.printf("testing %d bits",num); |
theterg | 0:5e7c5b7321c9 | 38 | t.start(); |
theterg | 0:5e7c5b7321c9 | 39 | header = fopen("/sd/config.txt","w"); |
theterg | 0:5e7c5b7321c9 | 40 | myled = 1; |
theterg | 0:5e7c5b7321c9 | 41 | before = t.read_us(); |
theterg | 0:5e7c5b7321c9 | 42 | unsigned char val = 0; |
theterg | 0:5e7c5b7321c9 | 43 | for (unsigned long i=0;i<num;i++){ |
theterg | 0:5e7c5b7321c9 | 44 | fputc(val,header); |
theterg | 0:5e7c5b7321c9 | 45 | val++; |
theterg | 0:5e7c5b7321c9 | 46 | } |
theterg | 0:5e7c5b7321c9 | 47 | after = t.read_us(); |
theterg | 0:5e7c5b7321c9 | 48 | fclose(header); |
theterg | 0:5e7c5b7321c9 | 49 | myled = 0; |
theterg | 0:5e7c5b7321c9 | 50 | pc.printf("\r\nIt took %d microseconds to write %d\r\n",(after-before),num); |
theterg | 0:5e7c5b7321c9 | 51 | pc.printf("aka, a rate of %f bits/sec\r\n",(float)num/((float)(after-before)/1000000)); |
theterg | 0:5e7c5b7321c9 | 52 | } |
theterg | 0:5e7c5b7321c9 | 53 | } |