mbed LPC1114 emulator pre-alpha version
Dependencies: BaseV6M mbed F12RFileSystem F32RFileSystem ROMSLOT SDStorage
Fork of emu812 by
TOYOSHIKI TINY BASIC mbed Edition TTB_mbed_LPC1114.bin save as "LPC1114.IMG" .
main.cpp
- Committer:
- va009039
- Date:
- 2016-04-08
- Revision:
- 6:41e64a077678
- Parent:
- 4:6629544a482e
- Child:
- 9:ef9a58221fbe
File content as of revision 6:41e64a077678:
// main.cpp 2016/4/7 #if defined(TARGET_LPC1768) #include "EMU111x.h" #include "SDStorage.h" #include "F32RFileSystem.h" #include "ROMSLOT.h" DigitalOut led1(LED1),led2(LED2); RawSerial pc(MBED_UARTUSB); #ifdef USE_SD SDStorage storage(MBED_SPI0); F32RFileSystem local(&storage, "local"); #else LocalFileSystem local("local"); #endif class MyEMU1114 : public EMU111x { virtual void DigitalWrite_Callback(int port, int pin, int value) { switch(port<<8|pin) { case 1<<8|5: led1 = value; break; // PIO1_5(LED1) case 0<<8|7: led2 = value; break; // PIO0_7(LED2) } } virtual void SerialPutc_Callback(int ch, uint8_t c) { pc.putc(c); } virtual int SerialGetc_Callback(int ch) { return pc.getc(); } virtual int SerialReadable_Callback(int ch) { return pc.readable(); } }; uint8_t* load(uint32_t addr, uint32_t limit, const char* filename) { pc.printf("loading[%s]", filename); FileHandle* fh = local.open(filename, O_RDONLY); MBED_ASSERT(fh); for(uint32_t fileSize = 0; fileSize <= limit;) { uint8_t buf[256]; size_t n = fh->read(buf, sizeof(buf)); if (n == 0) { pc.printf(" %d bytes\n", fileSize); break; } bool result = ROMSLOT::Write(addr + fileSize, (const uint8_t*)buf, sizeof(buf)); MBED_ASSERT(result); fileSize += n; pc.putc('.'); } fh->close(); return (uint8_t*)addr; } int main() { pc.baud(115200); pc.puts("mbed LPC1114 emulator pre-alpha version\n"); MyEMU1114 mcu; mcu.assign_flash(load(0x00040000, 0x8000, "LPC1114.IMG")); mcu.reset(); for(;;) { mcu.run(100); mcu.clock_in(250); } /* NOTREACHED */ } #endif // TARGET_LPC1768