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" .
Diff: main.cpp
- Revision:
- 3:5df725af50e0
- Parent:
- 1:913dfd59e25a
- Child:
- 4:6629544a482e
diff -r b8b4f07d4691 -r 5df725af50e0 main.cpp --- a/main.cpp Tue Aug 11 06:49:07 2015 +0900 +++ b/main.cpp Thu Aug 13 07:39:24 2015 +0900 @@ -1,55 +1,45 @@ -// main.cpp 2015/8/10 -#include "EMU81x.h" -#include "mbed_blinky_LPC812_bin.h" +// main.cpp 2015/8/13 +#include "EMU111x.h" -DigitalOut led1(LED1); +DigitalOut led1(LED1),led2(LED2); RawSerial pc(USBTX,USBRX); LocalFileSystem local("local"); -uint8_t flash[1024*16] __attribute__((section("AHBSRAM0"))); -uint8_t rom[1024*8] __attribute__((section("AHBSRAM1"))); +uint8_t* flash = (uint8_t*)0x2007c000; // AHBSRAM0,AHBSRAM1 -class MyEMU812 : public EMU81x { +class MyEMU1114 : public EMU111x { virtual void DigitalWrite_Callback(int port, int pin, int value) { - if (pin == 16) { // PIO0_16 - led1 = 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 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(); } }; -int load(uint8_t* buf, int size, const char* filename) { +uint8_t* load(uint8_t* buf, int size, const char* filename) { pc.printf("loading[%s]... ", filename); FileHandle* fh = local.open(filename, O_RDONLY); - if (fh == NULL) { - pc.printf("fail\n"); - return -1; - } + MBED_ASSERT(fh); int n = fh->read(buf, size); + pc.printf("%d bytes\n", n); fh->close(); - pc.printf("%d bytes\n", n); - return n; + return buf; } int main() { pc.baud(115200); - pc.puts("LPC812 emulator\n"); - - MyEMU812 mcu; - mcu.assign_flash(mbed_blinky_LPC812_bin); + pc.puts("LPC1114 emulator\n"); - if (load(flash, sizeof(flash), "LPC812.IMG") >= 0) { - load(rom, sizeof(rom), "LPC812.ROM"); - mcu.assign_flash(flash); - mcu.assign_rom(rom); - } + MyEMU1114 mcu; + mcu.assign_flash(load(flash, 32*1024, "LPC1114.IMG")); mcu.reset(); for(;;) { mcu.run(100); - mcu.clock_in(20000); + mcu.clock_in(250); } /* NOTREACHED */ }