Milosch Meriac
/
cthunk_example
Test function for CThunk class
Diff: main.cpp
- Revision:
- 3:c929fd5a4d3d
- Parent:
- 1:2e8f85f1ed3e
- Child:
- 4:97c886c2d89b
--- a/main.cpp Wed Aug 13 09:16:12 2014 +0000 +++ b/main.cpp Fri Aug 15 16:05:12 2014 +0000 @@ -1,6 +1,10 @@ #include <mbed.h> #include <CThunk.h> +DigitalOut g_led1(LED1); +DigitalOut g_led2(LED2); +DigitalOut g_led3(LED3); +DigitalOut g_led4(LED4); Serial pc(USBTX, USBRX); class CTest @@ -15,20 +19,17 @@ uint32_t counter; CThunk<CTest> thunk; - -private: - DigitalOut m_led; }; CTest::CTest(void) - :m_led(LED1) + :thunk(this) { counter = 0; } void CTest::callback1(void) { - pc.printf("callback1 called\n"); + pc.printf("callback1 called (this=0x%0X\n", this); /* increment member variable */ // counter++; @@ -44,11 +45,7 @@ void CTest::callback3(void* context) { - Ticker* sender = static_cast<Ticker*>(context); - - pc.printf("Called by ticker object 0x%08X: \n", sender); - - // m_led = !m_led; + pc.printf("Called by ticker object 0x%08X: \n", context); } void CTest::callback4(uint32_t r0, uint32_t r1) @@ -69,35 +66,30 @@ else if((i%8) == 0) pc.printf(" - "); - pc.printf("0x%02X ", ((uint8_t*)data)[i]); } pc.printf("\n"); } -int main(void) +static void test(void) { - Ticker tick; CThunkEntry entry; CTest test; - /* set meaningful baud rate for CMSIS DAP */ - pc.baud(115200); - pc.printf("Starting CTHunk tests...\n"); - /* get 32 bit entry point pointer from thunk */ entry = test.thunk; - - pc.printf(" - thunk entry at 0x%08X\n", entry); - /* TEST1: */ /* assign callback1 to thunk - no context needed */ test.thunk = (void*)0xDEADBEEF; test.thunk = &CTest::callback1; - hexdump((const void*)entry, CTHUNK_OPCODES_SIZE+3*4); + hexdump((const void*)entry, 16); /* call entry point */ + + pc.printf("before entry 1\n"); + g_led2 = 1; entry(); + pc.printf("after entry 1\n"); /* TEST2: */ @@ -106,17 +98,22 @@ /* and switch callback to callback2 */ test.thunk = &CTest::callback2; /* call entry point */ + pc.printf("before entry 2\n"); + g_led3 = 1; entry(); + pc.printf("after entry 2\n"); +} - - /* TEST3: */ +int main(void) +{ + g_led1 = 1; - /* try ticker */ - tick.attach(test.thunk, 1.0); - /* assign a context ... */ - test.thunk = (void*)&tick; - /* change the callback function */ - test.thunk = &CTest::callback3; - /* call entry point */ - entry(); -} \ No newline at end of file + /* run tests */ + test(); + + /* turn both LED's on */ + g_led4 = 1; + while(1) + __WFI(); + return 0; +}