semihost server example program

Dependencies:   SWD mbed USBLocalFileSystem BaseDAP USBDAP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_Semihost.cpp Source File

test_Semihost.cpp

00001 // test_Semihost.cpp 2013/9/14
00002 #if 0
00003 #include "Semihost.h"
00004 #include "Flash.h"
00005 #include "mytest.h"
00006 
00007 LocalFileSystem local("local");
00008 Serial pc(USBTX, USBRX);
00009 Target2 target(p21,p22,p17); // SWDIO(dp12),SWCLK(dp3),nReset(dp23)
00010 Serial target_uart(p9,p10); // RXD(dp15),TXD(dp16)
00011 
00012 Semihost* sh;
00013 
00014 TEST(Target2,setup) {
00015     ASSERT_TRUE(target.setup());
00016     target.halt();
00017     target.wait_status(TARGET_HALTED);
00018 }
00019 
00020 #define RAM 0x10000000
00021 
00022 TEST(Target2,readMemory8_1) {
00023     target.writeMemory(RAM, 0x12345678);
00024     ASSERT_TRUE(0x12345678 == target.readMemory(RAM));
00025     
00026     ASSERT_TRUE(0x78 == target.readMemory8(RAM));
00027     ASSERT_TRUE(0x56 == target.readMemory8(RAM+1));
00028     ASSERT_TRUE(0x34 == target.readMemory8(RAM+2));
00029     ASSERT_TRUE(0x12 == target.readMemory8(RAM+3));
00030 }
00031 
00032 TEST(Target2,writeMemory8_1) {
00033     target.writeMemory(RAM, 0xfefefefe);
00034     ASSERT_TRUE(0xfefefefe == target.readMemory(RAM));
00035     
00036     target.writeMemory8(RAM, 0x78);
00037     ASSERT_TRUE(0xfefefe78 == target.readMemory(RAM));
00038     
00039     target.writeMemory8(RAM+1, 0x56);
00040     ASSERT_TRUE(0xfefe5678 == target.readMemory(RAM));
00041        
00042     target.writeMemory8(RAM+2, 0x34);
00043     ASSERT_TRUE(0xfe345678 == target.readMemory(RAM));
00044 
00045     target.writeMemory8(RAM+3, 0x12);
00046     ASSERT_TRUE(0x12345678 == target.readMemory(RAM));
00047 }
00048 
00049 #if 1
00050 TEST(Flash1,flash1) {
00051     Flash flash(&target, &pc);
00052     bool r = flash.init();
00053     ASSERT_TRUE(r);
00054     r = flash.eraseAll();
00055     ASSERT_TRUE(r);
00056     r = flash.write("/local/SEMIHOST.LPC");
00057     ASSERT_TRUE(r);
00058 }
00059 #endif
00060 
00061 TEST(Semihost1,poll) {
00062     target.SoftwareReset();
00063     target.setup();
00064     sh = new Semihost(&target, &pc);
00065     sh->mount("/local");
00066     Timer t;
00067     t.reset();
00068     t.start();
00069     while(t.read_ms() < 1000*15) {
00070         if (target_uart.readable()) {
00071             pc.putc(target_uart.getc());
00072         }
00073         if (sh->poll() == Semihost::SYS_EXIT) {
00074             break;
00075         }
00076     }
00077 }
00078 
00079 int main() {
00080     pc.baud(921600);
00081     //pc.baud(9600);
00082     DBG("%s", __FILE__);
00083 
00084     RUN_ALL_TESTS();
00085     exit(0);
00086 }
00087 #endif