mbed LPC1114 emulator pre-alpha version

Dependencies:   BaseV6M mbed F12RFileSystem F32RFileSystem ROMSLOT SDStorage

Fork of emu812 by Norimasa Okamoto

480
TOYOSHIKI TINY BASIC mbed Edition TTB_mbed_LPC1114.bin save as "LPC1114.IMG" .

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Sat Apr 09 16:49:02 2016 +0900
Parent:
8:e41167fe6dd8
Commit message:
update ROMSLOT.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main_L152RE.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e41167fe6dd8 -r ef9a58221fbe main.cpp
--- a/main.cpp	Sat Apr 09 07:44:46 2016 +0000
+++ b/main.cpp	Sat Apr 09 16:49:02 2016 +0900
@@ -1,4 +1,4 @@
-// main.cpp 2016/4/7
+// emu1114/main.cpp 2016/4/9
 #if defined(TARGET_LPC1768)
 #include "EMU111x.h"
 #include "SDStorage.h"
@@ -13,6 +13,7 @@
 #else
 LocalFileSystem local("local");
 #endif
+ROMSLOT slot;
 
 class MyEMU1114 : public EMU111x {
     virtual void DigitalWrite_Callback(int port, int pin, int value) {
@@ -26,20 +27,20 @@
     virtual int SerialReadable_Callback(int ch) { return pc.readable(); }
 };
 
-uint8_t* load(uint32_t addr, uint32_t limit, const char* filename) {
+uint8_t* load(size_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;) {
+    uint32_t addr = slot.New(limit);
+    for(size_t n = 0; n <= limit;) {
         uint8_t buf[256];
-        size_t n = fh->read(buf, sizeof(buf));
-        if (n == 0) {
-            pc.printf(" %d bytes\n", fileSize);
+        size_t r = fh->read(buf, sizeof(buf));
+        if (r == 0) {
+            pc.printf(" %u bytes\n", n);
             break;
         }
-        bool result = ROMSLOT::Write(addr + fileSize, (const uint8_t*)buf, sizeof(buf));
-        MBED_ASSERT(result);
-        fileSize += n;
+        slot.Write(addr + n, (const uint8_t*)buf, sizeof(buf));
+        n += r;
         pc.putc('.');
     }
     fh->close();
@@ -48,10 +49,10 @@
 
 int main() {
     pc.baud(115200);
-    pc.puts("mbed LPC1114 emulator pre-alpha version\n");
+    pc.puts("mbed LPC1114 emulator pre-alpha version 0.01\n");
 
     MyEMU1114 mcu;
-    mcu.assign_flash(load(0x00040000, 0x8000, "LPC1114.IMG"));
+    mcu.assign_flash(load(0x8000, "LPC1114.IMG"));
 
     mcu.reset();
     for(;;) {
diff -r e41167fe6dd8 -r ef9a58221fbe main_L152RE.cpp
--- a/main_L152RE.cpp	Sat Apr 09 07:44:46 2016 +0000
+++ b/main_L152RE.cpp	Sat Apr 09 16:49:02 2016 +0900
@@ -1,4 +1,4 @@
-// main_L152RE.cpp 2016/4/6
+// emu1114/main_L152RE.cpp 2016/4/9
 #if defined(TARGET_NUCLEO_L152RE)
 #include "EMU111x.h"
 #include "SDStorage.h"
@@ -9,6 +9,7 @@
 RawSerial pc(USBTX,USBRX);
 SDStorage storage(D11, D12, D13, D4); // mosi, miso, sclk, cs
 F32RFileSystem local(&storage, "local");
+ROMSLOT slot;
 
 class MyEMU1114 : public EMU111x {
     virtual void DigitalWrite_Callback(int port, int pin, int value) {
@@ -22,19 +23,20 @@
     virtual int SerialReadable_Callback(int ch) { return pc.readable(); }
 };
 
-uint8_t* load(uint32_t addr, uint32_t limit, const char* filename) {
+uint8_t* load(size_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;) {
+    uint32_t addr = slot.New(limit);
+    for(size_t n = 0; n <= limit;) {
         uint8_t buf[256];
-        size_t n = fh->read(buf, sizeof(buf));
-        if (n == 0) {
-            pc.printf(" %d bytes\n", fileSize);
+        size_t r = fh->read(buf, sizeof(buf));
+        if (r == 0) {
+            pc.printf(" %u bytes\n", n);
             break;
         }
-        ROMSLOT::Write(addr + fileSize, (const uint8_t*)buf, sizeof(buf));
-        fileSize += n;
+        slot.Write(addr + n, (const uint8_t*)buf, sizeof(buf));
+        n += r;
         pc.putc('.');
     }
     fh->close();
@@ -43,10 +45,10 @@
 
 int main() {
     pc.baud(115200);
-    pc.puts("mbed LPC1114 emulator pre-alpha version\n");
+    pc.puts("mbed LPC1114 emulator pre-alpha version 0.01\n");
 
     MyEMU1114 mcu;
-    mcu.assign_flash(load(0x00040000, 0x8000, "LPC1114.IMG"));
+    mcu.assign_flash(load(0x8000, "LPC1114.IMG"));
 
     mcu.reset();
     for(;;) {