![](/media/cache/profiles/98c39996bf1543e974747a2549b3107c.50x50_q85.png)
JVM test
device_depend.cpp@7:2a384a077520, 2013-08-29 (annotated)
- Committer:
- lynxeyed_atsu
- Date:
- Thu Aug 29 13:31:23 2013 +0000
- Revision:
- 7:2a384a077520
- Parent:
- 6:b9d0d96b052f
- Child:
- 8:d9e205196dfc
fixed memory pool manager to re-use freed memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lynxeyed_atsu | 5:047542b65d00 | 1 | #include <stdio.h> |
lynxeyed_atsu | 5:047542b65d00 | 2 | #include <string.h> |
lynxeyed_atsu | 5:047542b65d00 | 3 | #include "device_depend.h" |
lynxeyed_atsu | 5:047542b65d00 | 4 | |
lynxeyed_atsu | 6:b9d0d96b052f | 5 | #define bc_str_length 1024 // from 32 to 1024 |
lynxeyed_atsu | 6:b9d0d96b052f | 6 | |
lynxeyed_atsu | 6:b9d0d96b052f | 7 | |
lynxeyed_atsu | 6:b9d0d96b052f | 8 | Serial pc(USBTX, USBRX); // tx, rx |
lynxeyed_atsu | 6:b9d0d96b052f | 9 | LocalFileSystem local("local"); |
lynxeyed_atsu | 6:b9d0d96b052f | 10 | FILE* ReadFile; |
lynxeyed_atsu | 6:b9d0d96b052f | 11 | Ticker tick; |
lynxeyed_atsu | 5:047542b65d00 | 12 | |
lynxeyed_atsu | 5:047542b65d00 | 13 | volatile static unsigned long msTicks; /* counts 1ms timeTicks */ |
lynxeyed_atsu | 6:b9d0d96b052f | 14 | char bc_str[bc_str_length]; |
lynxeyed_atsu | 6:b9d0d96b052f | 15 | int last_bc_num = 0; |
lynxeyed_atsu | 5:047542b65d00 | 16 | |
lynxeyed_atsu | 5:047542b65d00 | 17 | void hardware_init(void){ |
lynxeyed_atsu | 5:047542b65d00 | 18 | setup_systick(); |
lynxeyed_atsu | 5:047542b65d00 | 19 | } |
lynxeyed_atsu | 5:047542b65d00 | 20 | |
lynxeyed_atsu | 5:047542b65d00 | 21 | void uart_print(char *str){ |
lynxeyed_atsu | 5:047542b65d00 | 22 | pc.printf(str); |
lynxeyed_atsu | 5:047542b65d00 | 23 | return; |
lynxeyed_atsu | 5:047542b65d00 | 24 | } |
lynxeyed_atsu | 5:047542b65d00 | 25 | |
lynxeyed_atsu | 5:047542b65d00 | 26 | void uart_init(int baud_rate){ |
lynxeyed_atsu | 5:047542b65d00 | 27 | |
lynxeyed_atsu | 5:047542b65d00 | 28 | } |
lynxeyed_atsu | 5:047542b65d00 | 29 | |
lynxeyed_atsu | 5:047542b65d00 | 30 | int uart_read(void){ |
lynxeyed_atsu | 5:047542b65d00 | 31 | return pc.getc(); |
lynxeyed_atsu | 5:047542b65d00 | 32 | } |
lynxeyed_atsu | 5:047542b65d00 | 33 | |
lynxeyed_atsu | 5:047542b65d00 | 34 | int time_millis(void){ |
lynxeyed_atsu | 5:047542b65d00 | 35 | return msTicks; |
lynxeyed_atsu | 5:047542b65d00 | 36 | } |
lynxeyed_atsu | 5:047542b65d00 | 37 | |
lynxeyed_atsu | 5:047542b65d00 | 38 | void port_write(int port, int bit, int value){ |
lynxeyed_atsu | 5:047542b65d00 | 39 | //bit = value; |
lynxeyed_atsu | 7:2a384a077520 | 40 | return; |
lynxeyed_atsu | 5:047542b65d00 | 41 | } |
lynxeyed_atsu | 5:047542b65d00 | 42 | |
lynxeyed_atsu | 6:b9d0d96b052f | 43 | void bytecode_read_init(void){ |
lynxeyed_atsu | 6:b9d0d96b052f | 44 | |
lynxeyed_atsu | 6:b9d0d96b052f | 45 | if(NULL == (ReadFile = fopen ("/local/Test.cla","rb"))){ uart_print(" ERROR:Can't read class File.\r\n"); while(1); } |
lynxeyed_atsu | 6:b9d0d96b052f | 46 | fseek(ReadFile, 0, SEEK_SET); |
lynxeyed_atsu | 6:b9d0d96b052f | 47 | // I don't know why, but fseek does not work right. So I use fgetc instead. |
lynxeyed_atsu | 6:b9d0d96b052f | 48 | //fgets(bc_str, bc_str_length, ReadFile); |
lynxeyed_atsu | 6:b9d0d96b052f | 49 | printf("loading..."); |
lynxeyed_atsu | 6:b9d0d96b052f | 50 | for(int i = 0; i < bc_str_length; i++) bc_str[i] = fgetc(ReadFile); |
lynxeyed_atsu | 6:b9d0d96b052f | 51 | printf("end\r\n"); |
lynxeyed_atsu | 6:b9d0d96b052f | 52 | //last_bc_num = bc_str_length; |
lynxeyed_atsu | 6:b9d0d96b052f | 53 | } |
lynxeyed_atsu | 6:b9d0d96b052f | 54 | |
lynxeyed_atsu | 6:b9d0d96b052f | 55 | char* bytecode_read(int bc_num, int length){ |
lynxeyed_atsu | 6:b9d0d96b052f | 56 | |
lynxeyed_atsu | 6:b9d0d96b052f | 57 | if((last_bc_num <= bc_num)&&(bc_num < last_bc_num + bc_str_length)&&(length <= bc_str_length)){ // exists data in buffer |
lynxeyed_atsu | 6:b9d0d96b052f | 58 | return &bc_str[bc_num - last_bc_num]; |
lynxeyed_atsu | 6:b9d0d96b052f | 59 | }else |
lynxeyed_atsu | 6:b9d0d96b052f | 60 | { |
lynxeyed_atsu | 6:b9d0d96b052f | 61 | fseek(ReadFile, bc_num, SEEK_SET); |
lynxeyed_atsu | 6:b9d0d96b052f | 62 | for(int i = 0; i < bc_str_length; i++) |
lynxeyed_atsu | 6:b9d0d96b052f | 63 | { |
lynxeyed_atsu | 6:b9d0d96b052f | 64 | bc_str[i] = fgetc(ReadFile); |
lynxeyed_atsu | 6:b9d0d96b052f | 65 | } |
lynxeyed_atsu | 6:b9d0d96b052f | 66 | last_bc_num = bc_num; |
lynxeyed_atsu | 6:b9d0d96b052f | 67 | } |
lynxeyed_atsu | 6:b9d0d96b052f | 68 | return bc_str; |
lynxeyed_atsu | 6:b9d0d96b052f | 69 | } |
lynxeyed_atsu | 5:047542b65d00 | 70 | |
lynxeyed_atsu | 5:047542b65d00 | 71 | /*---------------------------------------------------------------------------- |
lynxeyed_atsu | 5:047542b65d00 | 72 | SysTick_Handler |
lynxeyed_atsu | 5:047542b65d00 | 73 | *----------------------------------------------------------------------------*/ |
lynxeyed_atsu | 5:047542b65d00 | 74 | void SysTickCount(void) { |
lynxeyed_atsu | 5:047542b65d00 | 75 | msTicks++; /* increment counter necessary in Delay() */ |
lynxeyed_atsu | 5:047542b65d00 | 76 | } |
lynxeyed_atsu | 5:047542b65d00 | 77 | |
lynxeyed_atsu | 5:047542b65d00 | 78 | void setup_systick (void) { |
lynxeyed_atsu | 5:047542b65d00 | 79 | msTicks = 0; |
lynxeyed_atsu | 5:047542b65d00 | 80 | tick.attach_us(&SysTickCount, 1000); //set 32kHz/8(word FIFO) sampling data } |
lynxeyed_atsu | 5:047542b65d00 | 81 | } |
lynxeyed_atsu | 5:047542b65d00 | 82 |