diff --git a/libraries/tests/rtos/mbed/basic/main.cpp b/libraries/tests/rtos/mbed/basic/main.cpp index eeecd160a5..8cd33bd692 100644 --- a/libraries/tests/rtos/mbed/basic/main.cpp +++ b/libraries/tests/rtos/mbed/basic/main.cpp @@ -1,6 +1,12 @@ #include "mbed.h" #include "rtos.h" +void print_char(char c = '*') +{ + printf("%c", c); + fflush(stdout); +} + DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -8,12 +14,13 @@ void led2_thread(void const *argument) { while (true) { led2 = !led2; Thread::wait(1000); + print_char(); } } int main() { Thread thread(led2_thread); - + while (true) { led1 = !led1; Thread::wait(500); diff --git a/libraries/tests/rtos/mbed/file/main.cpp b/libraries/tests/rtos/mbed/file/main.cpp index 56d328bb59..dd08557142 100644 --- a/libraries/tests/rtos/mbed/file/main.cpp +++ b/libraries/tests/rtos/mbed/file/main.cpp @@ -8,42 +8,67 @@ DigitalOut led2(LED2); #define SIZE 120 void sd_thread(void const *argument) { + const char *FILE_NAME = "/sd/out.txt"; + #if defined(TARGET_KL25Z) SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); #else SDFileSystem sd(p11, p12, p13, p14, "sd"); #endif - FILE *f = fopen("/sd/out.txt", "w"); - - // allocate buffers - uint8_t data_written[SIZE]; - uint8_t data_read[SIZE]; - - // fill data_written buffer with random data - // write these data into the file - printf("written: ["); - for (int i = 0; i < SIZE; i++) { - data_written[i] = rand() % 0xff; - fprintf(f, "%c", data_written[i]); - printf("%d ", data_written[i]); + + // Allocate data buffers + uint8_t data_written[SIZE] = {0}; + uint8_t data_read[SIZE] = {0}; + + { + // fill data_written buffer with random data + FILE *f = fopen(FILE_NAME, "w"); + if (f) { + // write these data into the file + printf("Writing %d bytes to file:\r\n", SIZE); + for (int i = 0; i < SIZE; 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"); - fclose(f); - - // read back the data from the file and store them in data_read - f = fopen("/sd/out.txt", "r"); - printf("read: ["); - for (int i=0; i