xeye_ atsu
/
FRDM_RaVem_JVM
JVM test
Diff: device_depend.cpp
- Revision:
- 6:b9d0d96b052f
- Parent:
- 5:047542b65d00
- Child:
- 7:2a384a077520
diff -r 047542b65d00 -r b9d0d96b052f device_depend.cpp --- a/device_depend.cpp Sat Aug 24 07:00:51 2013 +0000 +++ b/device_depend.cpp Mon Aug 26 15:02:07 2013 +0000 @@ -2,11 +2,18 @@ #include <string.h> #include "device_depend.h" +#define bc_str_length 1024 // from 32 to 1024 + + +Serial pc(USBTX, USBRX); // tx, rx +LocalFileSystem local("local"); +FILE* ReadFile; +Ticker tick; volatile static unsigned long msTicks; /* counts 1ms timeTicks */ +char bc_str[bc_str_length]; +int last_bc_num = 0; -Serial pc(USBTX, USBRX); // tx, rx -Ticker tick; void hardware_init(void){ setup_systick(); } @@ -32,6 +39,33 @@ //bit = value; } +void bytecode_read_init(void){ + + if(NULL == (ReadFile = fopen ("/local/Test.cla","rb"))){ uart_print(" ERROR:Can't read class File.\r\n"); while(1); } + fseek(ReadFile, 0, SEEK_SET); + // I don't know why, but fseek does not work right. So I use fgetc instead. + //fgets(bc_str, bc_str_length, ReadFile); + printf("loading..."); + for(int i = 0; i < bc_str_length; i++) bc_str[i] = fgetc(ReadFile); + printf("end\r\n"); + //last_bc_num = bc_str_length; +} + +char* bytecode_read(int bc_num, int length){ + + if((last_bc_num <= bc_num)&&(bc_num < last_bc_num + bc_str_length)&&(length <= bc_str_length)){ // exists data in buffer + return &bc_str[bc_num - last_bc_num]; + }else + { + fseek(ReadFile, bc_num, SEEK_SET); + for(int i = 0; i < bc_str_length; i++) + { + bc_str[i] = fgetc(ReadFile); + } + last_bc_num = bc_num; + } + return bc_str; +} /*---------------------------------------------------------------------------- SysTick_Handler