akkera 102
/
gba_rpc
GameBoy Advance Multiboot & RPC
main.cpp@0:147f4cedc929, 2014-12-09 (annotated)
- Committer:
- akkera102
- Date:
- Tue Dec 09 08:58:06 2014 +0000
- Revision:
- 0:147f4cedc929
GameBoy Advance Multiboot & Dumper
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akkera102 | 0:147f4cedc929 | 1 | #include "main.h" |
akkera102 | 0:147f4cedc929 | 2 | #include "mbed_rpc.h" |
akkera102 | 0:147f4cedc929 | 3 | #include "multiboot.h" |
akkera102 | 0:147f4cedc929 | 4 | |
akkera102 | 0:147f4cedc929 | 5 | static Serial pc(USBTX, USBRX); |
akkera102 | 0:147f4cedc929 | 6 | |
akkera102 | 0:147f4cedc929 | 7 | int main(void) |
akkera102 | 0:147f4cedc929 | 8 | { |
akkera102 | 0:147f4cedc929 | 9 | if(MultiBoot("/local/test.gba") == 1) |
akkera102 | 0:147f4cedc929 | 10 | { |
akkera102 | 0:147f4cedc929 | 11 | SystemError("MultiBoot", 1); |
akkera102 | 0:147f4cedc929 | 12 | } |
akkera102 | 0:147f4cedc929 | 13 | |
akkera102 | 0:147f4cedc929 | 14 | RpcDigitalOut myled1(LED1, "myled1"); |
akkera102 | 0:147f4cedc929 | 15 | RpcDigitalOut myled2(LED2, "myled2"); |
akkera102 | 0:147f4cedc929 | 16 | |
akkera102 | 0:147f4cedc929 | 17 | int var = 0; |
akkera102 | 0:147f4cedc929 | 18 | RPCVariable<int> _var(&var, "var"); |
akkera102 | 0:147f4cedc929 | 19 | |
akkera102 | 0:147f4cedc929 | 20 | uint32_t r, cnt; |
akkera102 | 0:147f4cedc929 | 21 | char buf[256], outbuf[256]; |
akkera102 | 0:147f4cedc929 | 22 | |
akkera102 | 0:147f4cedc929 | 23 | pc.printf("RPC GBA start\n"); |
akkera102 | 0:147f4cedc929 | 24 | |
akkera102 | 0:147f4cedc929 | 25 | for(;;) |
akkera102 | 0:147f4cedc929 | 26 | { |
akkera102 | 0:147f4cedc929 | 27 | WaitSPI32(0x0, 0x00010000, "Wait start signature"); |
akkera102 | 0:147f4cedc929 | 28 | |
akkera102 | 0:147f4cedc929 | 29 | outbuf[0] = '\0'; |
akkera102 | 0:147f4cedc929 | 30 | cnt = 0; |
akkera102 | 0:147f4cedc929 | 31 | |
akkera102 | 0:147f4cedc929 | 32 | while((r = WriteSPI32NoDebug(0x0)) != 0x00020000) |
akkera102 | 0:147f4cedc929 | 33 | { |
akkera102 | 0:147f4cedc929 | 34 | *(uint32_t*)(&buf[cnt]) = r; |
akkera102 | 0:147f4cedc929 | 35 | cnt += 4; |
akkera102 | 0:147f4cedc929 | 36 | } |
akkera102 | 0:147f4cedc929 | 37 | |
akkera102 | 0:147f4cedc929 | 38 | RPC::call(buf, outbuf); |
akkera102 | 0:147f4cedc929 | 39 | pc.printf("buf:[%s]\n", buf); |
akkera102 | 0:147f4cedc929 | 40 | pc.printf("out:[%s]\n", outbuf); |
akkera102 | 0:147f4cedc929 | 41 | |
akkera102 | 0:147f4cedc929 | 42 | if(IsReadVariable(buf) == true) |
akkera102 | 0:147f4cedc929 | 43 | { |
akkera102 | 0:147f4cedc929 | 44 | WriteSPI32NoDebug(atoi(outbuf)); |
akkera102 | 0:147f4cedc929 | 45 | } |
akkera102 | 0:147f4cedc929 | 46 | } |
akkera102 | 0:147f4cedc929 | 47 | } |
akkera102 | 0:147f4cedc929 | 48 | |
akkera102 | 0:147f4cedc929 | 49 | bool IsReadVariable(const char* request) |
akkera102 | 0:147f4cedc929 | 50 | { |
akkera102 | 0:147f4cedc929 | 51 | if(request == NULL) |
akkera102 | 0:147f4cedc929 | 52 | { |
akkera102 | 0:147f4cedc929 | 53 | return false; |
akkera102 | 0:147f4cedc929 | 54 | } |
akkera102 | 0:147f4cedc929 | 55 | |
akkera102 | 0:147f4cedc929 | 56 | Arguments args(request); |
akkera102 | 0:147f4cedc929 | 57 | |
akkera102 | 0:147f4cedc929 | 58 | if(args.obj_name == NULL || args.method_name == NULL) |
akkera102 | 0:147f4cedc929 | 59 | { |
akkera102 | 0:147f4cedc929 | 60 | return false; |
akkera102 | 0:147f4cedc929 | 61 | } |
akkera102 | 0:147f4cedc929 | 62 | if(strcmp(args.method_name, "read") != 0) |
akkera102 | 0:147f4cedc929 | 63 | { |
akkera102 | 0:147f4cedc929 | 64 | return false; |
akkera102 | 0:147f4cedc929 | 65 | } |
akkera102 | 0:147f4cedc929 | 66 | |
akkera102 | 0:147f4cedc929 | 67 | return true; |
akkera102 | 0:147f4cedc929 | 68 | } |
akkera102 | 0:147f4cedc929 | 69 | |
akkera102 | 0:147f4cedc929 | 70 | void SystemError(char* str, uint32_t hex) |
akkera102 | 0:147f4cedc929 | 71 | { |
akkera102 | 0:147f4cedc929 | 72 | pc.printf("[Err][0x%x] %s\n", hex, str); |
akkera102 | 0:147f4cedc929 | 73 | |
akkera102 | 0:147f4cedc929 | 74 | for(;;) |
akkera102 | 0:147f4cedc929 | 75 | { |
akkera102 | 0:147f4cedc929 | 76 | wait(1); |
akkera102 | 0:147f4cedc929 | 77 | } |
akkera102 | 0:147f4cedc929 | 78 | } |