semihost server example program

Dependencies:   SWD mbed USBLocalFileSystem BaseDAP USBDAP

/media/uploads/va009039/kl46z-lpc800-360x480.jpg

LPCXpresso
LPC11U68
LPCXpresso
LPC1549
FRDM-KL46ZEA LPC4088 QSB
app-board
LPC1768
app-board
LPC810LPC1114FN28
serverserverserverserverserverclientclient
SWDIOD12D12D12p25p21p4(P0_2)p12
SWCLKD10D10D10p26p22p3(P0_3)p3
nRESET
*option
D6D6D6p34p30p1(P0_5)p23
GNDGNDGNDGNDp1p1p7p22
3.3VP3V3P3V3P3V3p44p40p6p21
flash writeSW2(P0_1)SW3(P1_9)SW1p14
joystick
center
p14
joystick
center

client example:

Import programlpc810-semihost_helloworld

semihost client example program

tests/mytest.h

Committer:
va009039
Date:
2014-06-22
Revision:
18:5ed1759e863b
Parent:
1:eb30547ba84d

File content as of revision 18:5ed1759e863b:

// mytest.h 2013/6/28
#pragma once
#include "mbed_debug.h"

class BaseTest {
public:
    virtual void _run() = 0;
    char* m_a;
    char* m_b;
    int m_line;
    char* m_file;
    BaseTest* next;
};

class reg {
    BaseTest* head;
    BaseTest* tail;
    reg() {
        head = NULL;
        tail = NULL;
    }
public:
    static reg* inst() {
        static reg regtest;
        return &regtest;
    }
    void add(BaseTest* test) {
        test->next = NULL;
        if (head == NULL) {
            head = test;
            tail = test;
        } else {
            tail->next = test;
            tail = test;
        }
    }
    int run_all_tests(char* a = "") {
        BaseTest* test = head;
        int pass = 0;
        int count = 0;
        char* file = "";
        while(test) {
            if (strcmp(a, "") == 0 || strcmp(a, test->m_a) == 0) {
                if (strcmp(file, test->m_file) != 0) {
                    file = test->m_file;
                    debug("%s\n", file);
                }
                debug("TEST(%s,%s)@%d ... ",test->m_a, test->m_b, test->m_line);
                Timer t; t.start();
                test->_run();
                debug("OK (%d ms)\n", t.read_ms());
                pass++;
            }    
            test = test->next;
            count++;
        }
        debug("%d/%d TESTS PASSED!!!\n", pass, count);
        return 0;
    }
};

#define TEST(A,B) \
class class_##A##_##B : public BaseTest { \
public: \
    class_##A##_##B(char* a, char* b, char* file, int line) { \
        m_a = a; m_b = b; \
        m_file = file; m_line = line; \
        reg::inst()->add(this); \
    } \
    virtual void _run(); \
}; \
class_##A##_##B instance_##A##_##B(#A,#B,__FILE__,__LINE__); \
void class_##A##_##B::_run()

#define RUN_TEST(A,B) instance_##A##_##B._run()
#define RUN_ALL_TESTS(A) reg::inst()->run_all_tests(#A)
#define ASSERT_TRUE(A) if(A){}else{debug("\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};

#ifndef DBG
#define DBG(FMT, ...) do{debug("[%s:%d]"FMT"\r\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0);
#endif
#define TEST_PRINT(FMT, ...) do{debug("[TEST: %d]"FMT"\r\n", __LINE__, ##__VA_ARGS__);}while(0);