]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/file/main.cpp
2 #include "SDFileSystem.h"
11 // Allocate data buffers
12 uint8_t data_written
[SIZE
] = { 0 };
13 uint8_t data_read
[SIZE
] = { 0 };
16 void sd_thread(void const *argument
)
18 const char *FILE_NAME
= "/sd/rtos9_test.txt";
20 #if defined(TARGET_KL25Z)
21 SDFileSystem
sd(PTD2
, PTD3
, PTD1
, PTD0
, "sd");
23 #elif defined(TARGET_KL46Z)
24 SDFileSystem
sd(PTD6
, PTD7
, PTD5
, PTD4
, "sd");
26 #elif defined(TARGET_K64F)
27 SDFileSystem
sd(PTD2
, PTD3
, PTD1
, PTD0
, "sd");
29 #elif defined(TARGET_RZ_A1H)
30 SDFileSystem
sd(P8_5
, P8_6
, P8_3
, P8_4
, "sd");
33 SDFileSystem
sd(p11
, p12
, p13
, p14
, "sd");
37 // fill data_written buffer with random data
38 FILE *f
= fopen(FILE_NAME
, "w+");
40 // write these data into the file
41 printf("Writing %d bytes to file:" NL
, SIZE
);
42 for (int i
= 0; i
< SIZE
; i
++) {
43 data_written
[i
] = rand() % 0xff;
44 fprintf(f
, "%c", data_written
[i
]);
45 printf("%02X ", data_written
[i
]);
46 if (i
&& ((i
% 20) == 19))
50 printf("MBED: Done" NL
);
52 printf("MBED: Can't open '%s'" NL
, FILE_NAME
);
53 MBED_HOSTTEST_RESULT(false);
60 // read back the data from the file and store them in data_read
61 FILE *f
= fopen(FILE_NAME
, "r");
63 printf("MBED: Reading %d bytes from file:" NL
, SIZE
);
64 for (int i
= 0; i
< SIZE
; i
++) {
65 data_read
[i
] = fgetc(f
);
66 printf("%02X ", data_read
[i
]);
67 if (i
&& ((i
% 20) == 19))
71 printf("MBED: Done\r\n");
73 printf("MBED: Can't open '%s'" NL
, FILE_NAME
);
74 MBED_HOSTTEST_RESULT(false);
78 // check that the data written == data read
79 for (int i
= 0; i
< SIZE
; i
++) {
80 if (data_written
[i
] != data_read
[i
]) {
81 printf("MBED: Data index=%d: w[0x%02X] != r[0x%02X]" NL
, i
, data_written
[i
], data_read
[i
]);
82 MBED_HOSTTEST_RESULT(false);
85 MBED_HOSTTEST_RESULT(true);
89 MBED_HOSTTEST_TIMEOUT(20);
90 MBED_HOSTTEST_SELECT(default_auto
);
91 MBED_HOSTTEST_DESCRIPTION(SD File write read
);
92 MBED_HOSTTEST_START("RTOS_9");
94 Thread
t(sd_thread
, NULL
, osPriorityNormal
, (DEFAULT_STACK_SIZE
* 2.25));