Moderators: roger, 99jonathan, imaqine

lawrie wrote:MAX_VM_PAGES is in 256 byte pages, so the limit for the VM size is 32kb.


char *ham_bc; /* Pointer to bytecode */
U16 ham_bc_len;
extern U32 __free_ram_start__;
extern U32 __free_ram_end__;
#ifdef BYTECODE_IN_RAM
#define dataGet(t, ofs) *((t*)(ham_bc + ofs))
#else /*BYTECODE_IN_RAM*/
#define dataGet(t, ofs) *((t*)(((char*)FLASH_BASE) + ofs))
#endif /*BYTECODE_IN_RAM*/
/**
* Wait for a file and receive it through the USB connection.
* The wait can be aborted by pressing enter and escape simultaneously.
*
*
* @return the length of the file in bytes or -1 in case of user abort
*/
int receive_file() {
U8 buf[64];
int bytes = 0;
int size = 0;
int sending = 0;
U8 reply[32];
int replyLen;
int i;
int dataLen = 0;
#ifndef BYTECODE_IN_RAM
U8 fbuf[256];
#endif /*BYTECODE_IN_RAM*/
udp_reset();
ham_bc = (char*)&__free_ram_start__;
do {
dataLen = udp_read(buf, 64);
} while ((dataLen == 0) && (buttons_get() != 0x09));
if (buttons_get() == 0x09) return -1;
do {
for (i = 0; i < 32; i++) reply[i] = 0;
reply[0] = 0x02;
reply[1] = buf[1];
replyLen = 3;
if (sending) {
for (i = 0; i < dataLen; i++) {
#ifdef BYTECODE_IN_RAM
ham_bc[bytes++] = buf[i];
#else /*BYTECODE_IN_RAM*/
fbuf[(bytes++) & 0xff] = buf[i];
if ((bytes & 0xff) == 0) {
flash_write_page((U32*)fbuf, (bytes >> 8) - 1);
}
#endif /*BYTECODE_IN_RAM*/
}
if (bytes == size) {
sending = 0;
reply[2] = 0x83;
buf[0] = 0x01;
replyLen = 6;
}
} else if (buf[1] == 0x81) {
/* Open write */
size = buf[22];
size += buf[23] << 8;
size += buf[24] << 16;
size += buf[25] << 24;
buf[21] = 0;
display_goto_xy(0, 2);
display_string((char*)buf + 2);
bytes = 0;
replyLen = 4;
} else if (buf[1] == 0x83) {
/* Write */
replyLen = 6;
sending = 1;
} else if (buf[1] == 0x84) {
/* Close */
replyLen = 4;
}
if (!sending && ((buf[0] & 0x80) == 0)) {
udp_write(reply, replyLen);
}
systick_wait_ms(10);
dataLen = udp_read(buf, 64);
} while (dataLen > 0);
#ifndef BYTECODE_IN_RAM
if ((bytes & 0xff) != 0) {
flash_write_page((U32*)fbuf, bytes >> 8);
}
#endif /*BYTECODE_IN_RAM*/
display_goto_xy(0, 3);
display_string("Bytecode: ");
display_unsigned(bytes, 0);
#ifdef BYTECODE_IN_RAM
ham_bc_len = bytes;
#else /*BYTECODE_IN_RAM*/
ham_bc_len = 0;
#endif /*BYTECODE_IN_RAM*/
return bytes;
}

Users browsing this forum: No registered users and 1 guest