semihost server example program

Dependencies:   SWD mbed USBLocalFileSystem BaseDAP USBDAP

/media/uploads/va009039/kl46z-lpc800-360x480.jpg

LPCXpresso
LPC11U68
LPCXpresso
LPC1549
FRDM-KL46ZEA LPC4088 QSB
app-board
LPC1768
app-board
LPC810LPC1114FN28
serverserverserverserverserverclientclient
SWDIOD12D12D12p25p21p4(P0_2)p12
SWCLKD10D10D10p26p22p3(P0_3)p3
nRESET
*option
D6D6D6p34p30p1(P0_5)p23
GNDGNDGNDGNDp1p1p7p22
3.3VP3V3P3V3P3V3p44p40p6p21
flash writeSW2(P0_1)SW3(P1_9)SW1p14
joystick
center
p14
joystick
center

client example:

Import programlpc810-semihost_helloworld

semihost client example program

Committer:
va009039
Date:
Sat Sep 14 12:55:29 2013 +0000
Revision:
5:2774358f5e4f
Parent:
2:32e9437348ad
Child:
9:7e71c20c96e4
deleted the code to access the data of unalignment.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 5:2774358f5e4f 1 // Semihost.h 2013/9/14
va009039 1:eb30547ba84d 2 #pragma once
va009039 1:eb30547ba84d 3 #include "Target2.h"
va009039 1:eb30547ba84d 4 #include "mydebug.h"
va009039 1:eb30547ba84d 5
va009039 5:2774358f5e4f 6 /** Semihosting
va009039 5:2774358f5e4f 7 */
va009039 1:eb30547ba84d 8 class Semihost {
va009039 1:eb30547ba84d 9 public:
va009039 1:eb30547ba84d 10 Semihost(Target2* target, Serial* usbpc);
va009039 1:eb30547ba84d 11 void mount(const char* dirpath);
va009039 1:eb30547ba84d 12 int poll();
va009039 2:32e9437348ad 13 enum Reason {
va009039 2:32e9437348ad 14 SYS_NONE = 0,
va009039 2:32e9437348ad 15 SYS_EXIT = 0x18,
va009039 2:32e9437348ad 16 };
va009039 1:eb30547ba84d 17 private:
va009039 1:eb30547ba84d 18 int exec(uint32_t reason, uint32_t arg);
va009039 1:eb30547ba84d 19
va009039 1:eb30547ba84d 20 int sys_open(uint32_t arg); // 0x01
va009039 1:eb30547ba84d 21 int sys_close(uint32_t arg); // 0x02
va009039 1:eb30547ba84d 22 int sys_writec(uint32_t arg); // 0x03
va009039 1:eb30547ba84d 23 int sys_write0(uint32_t arg); // 0x04
va009039 1:eb30547ba84d 24 int sys_write(uint32_t arg); // 0x05
va009039 1:eb30547ba84d 25 int sys_read(uint32_t arg); // 0x06
va009039 1:eb30547ba84d 26 int sys_readc(uint32_t arg); // 0x07
va009039 1:eb30547ba84d 27 int sys_istty(uint32_t arg); // 0x09
va009039 1:eb30547ba84d 28 int sys_fseek(uint32_t arg); // 0x0a
va009039 1:eb30547ba84d 29 int sys_ensure(uint32_t arg); // 0x0b
va009039 1:eb30547ba84d 30 int sys_flen(uint32_t arg); // 0x0c
va009039 1:eb30547ba84d 31 int sys_remove(uint32_t arg); // 0x0e
va009039 1:eb30547ba84d 32 int sys_rename(uint32_t arg); // 0x0f
va009039 1:eb30547ba84d 33 int sys_exit(uint32_t arg); // 0x18
va009039 1:eb30547ba84d 34
va009039 1:eb30547ba84d 35 int usr_xffind(uint32_t arg); // 0x100
va009039 1:eb30547ba84d 36 int usr_uid(uint32_t arg); // 0x101
va009039 1:eb30547ba84d 37 int usr_reset(uint32_t arg); // 0x102
va009039 1:eb30547ba84d 38 int usr_vbus(uint32_t arg); // 0x103
va009039 1:eb30547ba84d 39 int usr_powerdown(uint32_t arg); // 0x104
va009039 1:eb30547ba84d 40 int usr_disabledebug(uint32_t arg);// 0x105
va009039 1:eb30547ba84d 41
va009039 1:eb30547ba84d 42 void _build_name(char* buf, int size, uint32_t arg1, uint32_t arg2);
va009039 1:eb30547ba84d 43
va009039 1:eb30547ba84d 44 template<typename T>
va009039 1:eb30547ba84d 45 void wr(uint32_t addr, T data) {
va009039 1:eb30547ba84d 46 TEST_ASSERT(addr <= 0x10001fff);
va009039 1:eb30547ba84d 47 for(int i = 0; i < sizeof(T); i++) {
va009039 5:2774358f5e4f 48 _target->writeMemory8(addr+i, data);
va009039 5:2774358f5e4f 49 data >>= 8;
va009039 1:eb30547ba84d 50 }
va009039 1:eb30547ba84d 51 }
va009039 1:eb30547ba84d 52
va009039 1:eb30547ba84d 53 template<typename T>
va009039 1:eb30547ba84d 54 T rd(uint32_t addr) {
va009039 1:eb30547ba84d 55 TEST_ASSERT(addr <= 0x10001fff);
va009039 5:2774358f5e4f 56 T data = 0;
va009039 5:2774358f5e4f 57 for(int i = sizeof(T)-1; i >= 0; i--) {
va009039 5:2774358f5e4f 58 data <<= 8;
va009039 5:2774358f5e4f 59 data |= _target->readMemory8(addr+i);
va009039 1:eb30547ba84d 60 }
va009039 5:2774358f5e4f 61 return data;
va009039 1:eb30547ba84d 62 }
va009039 1:eb30547ba84d 63
va009039 1:eb30547ba84d 64 protected:
va009039 1:eb30547ba84d 65 Target2* _target;
va009039 1:eb30547ba84d 66 Serial* _pc;
va009039 1:eb30547ba84d 67 char* _dirpath;
va009039 1:eb30547ba84d 68 };