xeye_ atsu
/
FRDM_RaVem_JVM
JVM test
device_depend.cpp
- Committer:
- lynxeyed_atsu
- Date:
- 2013-08-26
- Revision:
- 6:b9d0d96b052f
- Parent:
- 5:047542b65d00
- Child:
- 7:2a384a077520
File content as of revision 6:b9d0d96b052f:
#include <stdio.h> #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; void hardware_init(void){ setup_systick(); } void uart_print(char *str){ pc.printf(str); return; } void uart_init(int baud_rate){ } int uart_read(void){ return pc.getc(); } int time_millis(void){ return msTicks; } void port_write(int port, int bit, int value){ //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 *----------------------------------------------------------------------------*/ void SysTickCount(void) { msTicks++; /* increment counter necessary in Delay() */ } void setup_systick (void) { msTicks = 0; tick.attach_us(&SysTickCount, 1000); //set 32kHz/8(word FIFO) sampling data } }