Added RTOS_1 basic test and RTOS_9 SD file write/read test to host test automation

pull/230/head
Przemek Wirkus 2014-03-24 17:05:32 +00:00
parent e8dcecba1b
commit a8c7e135f7
2 changed files with 59 additions and 27 deletions

View File

@ -1,6 +1,12 @@
#include "mbed.h" #include "mbed.h"
#include "rtos.h" #include "rtos.h"
void print_char(char c = '*')
{
printf("%c", c);
fflush(stdout);
}
DigitalOut led1(LED1); DigitalOut led1(LED1);
DigitalOut led2(LED2); DigitalOut led2(LED2);
@ -8,12 +14,13 @@ void led2_thread(void const *argument) {
while (true) { while (true) {
led2 = !led2; led2 = !led2;
Thread::wait(1000); Thread::wait(1000);
print_char();
} }
} }
int main() { int main() {
Thread thread(led2_thread); Thread thread(led2_thread);
while (true) { while (true) {
led1 = !led1; led1 = !led1;
Thread::wait(500); Thread::wait(500);

View File

@ -8,42 +8,67 @@ DigitalOut led2(LED2);
#define SIZE 120 #define SIZE 120
void sd_thread(void const *argument) { void sd_thread(void const *argument) {
const char *FILE_NAME = "/sd/out.txt";
#if defined(TARGET_KL25Z) #if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#else #else
SDFileSystem sd(p11, p12, p13, p14, "sd"); SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif #endif
FILE *f = fopen("/sd/out.txt", "w");
// Allocate data buffers
// allocate buffers uint8_t data_written[SIZE] = {0};
uint8_t data_written[SIZE]; uint8_t data_read[SIZE] = {0};
uint8_t data_read[SIZE];
{
// fill data_written buffer with random data // fill data_written buffer with random data
// write these data into the file FILE *f = fopen(FILE_NAME, "w");
printf("written: ["); if (f) {
for (int i = 0; i < SIZE; i++) { // write these data into the file
data_written[i] = rand() % 0xff; printf("Writing %d bytes to file:\r\n", SIZE);
fprintf(f, "%c", data_written[i]); for (int i = 0; i < SIZE; i++) {
printf("%d ", data_written[i]); data_written[i] = rand() % 0xff;
fprintf(f, "%c", data_written[i]);
printf("%02X ", data_written[i]);
if (i && ((i % 20) == 19)) {
printf("\r\n");
}
}
fclose(f);
}
else {
notify_completion(false);
return;
}
} }
printf("]\r\nclosing\r\n"); printf("\r\n\r\n");
fclose(f);
{
// read back the data from the file and store them in data_read // read back the data from the file and store them in data_read
f = fopen("/sd/out.txt", "r"); FILE *f = fopen(FILE_NAME, "r");
printf("read: ["); if (f) {
for (int i=0; i<SIZE; i++) { printf("Reading %d bytes from file:\r\n", SIZE);
data_read[i] = fgetc(f); for (int i = 0; i < SIZE; i++) {
printf("%d ", data_read[i]); data_read[i] = fgetc(f);
printf("%02X ", data_read[i]);
if (i && ((i % 20) == 19)) {
printf("\r\n");
}
}
fclose(f);
}
else {
notify_completion(false);
return;
}
} }
printf("]\r\nclosing\r\n"); printf("\r\nDone.\r\n");
fclose(f);
// check that the data written == data read // check that the data written == data read
for (int i = 0; i < SIZE; i++) { for (int i = 0; i < SIZE; i++) {
if (data_written[i] != data_read[i]) { if (data_written[i] != data_read[i]) {
notify_completion(false); notify_completion(false);
return;
} }
} }
notify_completion(true); notify_completion(true);
@ -51,7 +76,7 @@ void sd_thread(void const *argument) {
int main() { int main() {
Thread t(sd_thread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25)); Thread t(sd_thread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25));
while (true) { while (true) {
led2 = !led2; led2 = !led2;
Thread::wait(1000); Thread::wait(1000);