mirror of https://github.com/ARMmbed/mbed-os.git
Small refactoring + code indent
parent
4927a9d7e3
commit
5eb40d38ca
|
@ -1,73 +1,78 @@
|
||||||
#include "test_env.h"
|
#include "test_env.h"
|
||||||
#include "semihost_api.h"
|
#include "semihost_api.h"
|
||||||
|
|
||||||
|
|
||||||
Serial pc(USBTX, USBRX);
|
Serial pc(USBTX, USBRX);
|
||||||
|
|
||||||
#define FILENAME "/local/out.txt"
|
#define FILENAME "/local/out.txt"
|
||||||
#define TEST_STRING "Hello World!"
|
#define TEST_STRING "Hello World!"
|
||||||
|
|
||||||
FILE* test_open(const char* mode) {
|
FILE *test_open(const char *mode)
|
||||||
FILE *f;
|
{
|
||||||
f = fopen(FILENAME, mode);
|
FILE *f = fopen(FILENAME, mode);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
printf("Error opening file"NL);
|
printf("Error opening file"NL);
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_write(FILE* f, char* str, int str_len) {
|
void test_write(FILE *f, char *str, int str_len)
|
||||||
|
{
|
||||||
int n = fprintf(f, str);
|
int n = fprintf(f, str);
|
||||||
|
|
||||||
if (n != str_len) {
|
if (n != str_len) {
|
||||||
printf("Error writing file"NL);
|
printf("Error writing file"NL);
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_read(FILE* f, char* str, int str_len) {
|
void test_read(FILE *f, char *str, int str_len)
|
||||||
|
{
|
||||||
int n = fread(str, sizeof(unsigned char), str_len, f);
|
int n = fread(str, sizeof(unsigned char), str_len, f);
|
||||||
|
|
||||||
if (n != str_len) {
|
if (n != str_len) {
|
||||||
printf("Error reading file"NL);
|
printf("Error reading file"NL);
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_close(FILE* f) {
|
void test_close(FILE *f)
|
||||||
|
{
|
||||||
int rc = fclose(f);
|
int rc = fclose(f);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
printf("Error closing file"NL);
|
printf("Error closing file"NL);
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
pc.printf("Test the Stream class\n");
|
pc.printf("Test the Stream class\n");
|
||||||
|
|
||||||
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
|
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
|
||||||
|
|
||||||
char mac[16];
|
char mac[16];
|
||||||
mbed_mac_address(mac);
|
mbed_mac_address(mac);
|
||||||
printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
|
||||||
LocalFileSystem local("local");
|
LocalFileSystem local("local");
|
||||||
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char* str = TEST_STRING;
|
char *str = TEST_STRING;
|
||||||
char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING));
|
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
|
||||||
int str_len = strlen(TEST_STRING);
|
int str_len = strlen(TEST_STRING);
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
f = test_open("w");
|
f = test_open("w");
|
||||||
test_write(f, str, str_len);
|
test_write(f, str, str_len);
|
||||||
test_close(f);
|
test_close(f);
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
f = test_open("r");
|
f = test_open("r");
|
||||||
test_read(f, buffer, str_len);
|
test_read(f, buffer, str_len);
|
||||||
test_close(f);
|
test_close(f);
|
||||||
|
|
||||||
// Check the two strings are equal
|
// Check the two strings are equal
|
||||||
notify_completion((strncmp(buffer, str, str_len) == 0));
|
notify_completion((strncmp(buffer, str, str_len) == 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
#include "mbed.h"
|
#include "test_env.h"
|
||||||
|
|
||||||
DigitalOut myled(LED1);
|
int main()
|
||||||
|
{
|
||||||
int main() {
|
|
||||||
printf("Hello World\n");
|
printf("Hello World\n");
|
||||||
while (true) {
|
notify_completion(true);
|
||||||
wait(0.5);
|
|
||||||
myled = !myled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,18 +7,23 @@ 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";
|
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");
|
||||||
|
|
||||||
|
#elif defined(TARGET_KL46Z)
|
||||||
|
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||||
|
|
||||||
#else
|
#else
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Allocate data buffers
|
// Allocate data buffers
|
||||||
uint8_t data_written[SIZE] = {0};
|
uint8_t data_written[SIZE] = { 0 };
|
||||||
uint8_t data_read[SIZE] = {0};
|
uint8_t data_read[SIZE] = { 0 };
|
||||||
|
|
||||||
{
|
{
|
||||||
// fill data_written buffer with random data
|
// fill data_written buffer with random data
|
||||||
|
@ -30,13 +35,11 @@ void sd_thread(void const *argument) {
|
||||||
data_written[i] = rand() % 0xff;
|
data_written[i] = rand() % 0xff;
|
||||||
fprintf(f, "%c", data_written[i]);
|
fprintf(f, "%c", data_written[i]);
|
||||||
printf("%02X ", data_written[i]);
|
printf("%02X ", data_written[i]);
|
||||||
if (i && ((i % 20) == 19)) {
|
if (i && ((i % 20) == 19))
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -51,13 +54,11 @@ void sd_thread(void const *argument) {
|
||||||
for (int i = 0; i < SIZE; i++) {
|
for (int i = 0; i < SIZE; i++) {
|
||||||
data_read[i] = fgetc(f);
|
data_read[i] = fgetc(f);
|
||||||
printf("%02X ", data_read[i]);
|
printf("%02X ", data_read[i]);
|
||||||
if (i && ((i % 20) == 19)) {
|
if (i && ((i % 20) == 19))
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,8 @@ void sd_thread(void const *argument) {
|
||||||
notify_completion(true);
|
notify_completion(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
@ -329,7 +329,7 @@ TESTS = [
|
||||||
{
|
{
|
||||||
"id": "MBED_10", "description": "Hello World",
|
"id": "MBED_10", "description": "Hello World",
|
||||||
"source_dir": join(TEST_DIR, "mbed", "hello"),
|
"source_dir": join(TEST_DIR, "mbed", "hello"),
|
||||||
"dependencies": [MBED_LIBRARIES],
|
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||||
"automated": True,
|
"automated": True,
|
||||||
"host_test": "hello_auto",
|
"host_test": "hello_auto",
|
||||||
},
|
},
|
||||||
|
@ -339,7 +339,7 @@ TESTS = [
|
||||||
"dependencies": [MBED_LIBRARIES],
|
"dependencies": [MBED_LIBRARIES],
|
||||||
"automated": True,
|
"automated": True,
|
||||||
"host_test": "wait_us_auto",
|
"host_test": "wait_us_auto",
|
||||||
"duration": 20
|
"duration": 20,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "MBED_12", "description": "C++",
|
"id": "MBED_12", "description": "C++",
|
||||||
|
|
Loading…
Reference in New Issue