1 | /*
|
---|
2 | * Copyright (C) 2008-2017 by TOPPERS Project
|
---|
3 | *
|
---|
4 | * ä¸è¨èä½æ¨©è
|
---|
5 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
6 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
7 | * å¤ã»åé
|
---|
8 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
9 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
10 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
11 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
12 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
13 | * ç¨ã§ããå½¢ã§åé
|
---|
14 | å¸ããå ´åã«ã¯ï¼åé
|
---|
15 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
16 | * è
|
---|
17 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
18 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
19 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
20 | * ç¨ã§ããªãå½¢ã§åé
|
---|
21 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
22 | * ã¨ï¼
|
---|
23 | * (a) åé
|
---|
24 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
26 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
27 | * (b) åé
|
---|
28 | å¸ã®å½¢æ
|
---|
29 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
30 | * å ±åãããã¨ï¼
|
---|
31 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
32 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
33 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
34 | 責ãããã¨ï¼
|
---|
35 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
36 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
37 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
38 | * å
|
---|
39 | 責ãããã¨ï¼
|
---|
40 | *
|
---|
41 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
42 | ã
|
---|
43 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
44 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
45 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
46 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
47 | *
|
---|
48 | * @(#) $Id: nMruby_tMruby.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
49 | */
|
---|
50 |
|
---|
51 | /* #[<PREAMBLE>]#
|
---|
52 | * #[<...>]# ãã #[</...>]# ã§å²ã¾ããã³ã¡ã³ãã¯ç·¨éããªãã§ãã ãã
|
---|
53 | * tecsmerge ã«ãããã¼ã¸ã«ä½¿ç¨ããã¾ã
|
---|
54 | * å¼ã³å£é¢æ° #_TCPF_#
|
---|
55 | * call port : cSerialPort signature: sSerialPort context: task
|
---|
56 | * ER cSerialPort_open( );
|
---|
57 | * ER cSerialPort_close( );
|
---|
58 | * ER_UINT cSerialPort_read( char_t* buffer, uint_t length );
|
---|
59 | * ER_UINT cSerialPort_write( const char_t* buffer, uint_t length );
|
---|
60 | * ER cSerialPort_control( uint_t ioControl );
|
---|
61 | * ER cSerialPort_refer( T_SERIAL_RPOR* pk_rpor );
|
---|
62 | *
|
---|
63 | * #[</PREAMBLE>]# */
|
---|
64 |
|
---|
65 | /* ãããã¿ã¤ã宣è¨ãå¤æ°ã®å®ç¾©ãããã«æ¸ãã¾ã #_PAC_# */
|
---|
66 | #include "nMruby_tMruby_tecsgen.h"
|
---|
67 | #include <string.h>
|
---|
68 |
|
---|
69 | #include <mruby.h>
|
---|
70 | #include <mruby/proc.h>
|
---|
71 | #include <mruby/data.h>
|
---|
72 | #include <mruby/compile.h>
|
---|
73 |
|
---|
74 | #ifndef E_OK
|
---|
75 | #define E_OK 0 /* success */
|
---|
76 | #define E_ID (-18) /* illegal ID */
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | #define MEM_SIZE 1024*1024 // 1MB
|
---|
80 | //#define VM_EVAL
|
---|
81 | //#define MALLOC_EVAL
|
---|
82 |
|
---|
83 | #include <t_syslog.h>
|
---|
84 |
|
---|
85 | void mrb_init_mrb(CELLCB *p_cellcb, mrb_state *mrb);
|
---|
86 | /* åãå£é¢æ° #_TEPF_# */
|
---|
87 | /* #[<ENTRY_PORT>]# eMrubyBody
|
---|
88 | * entry port: eMrubyBody
|
---|
89 | * signature: sMrubyBody
|
---|
90 | * context: task
|
---|
91 | * #[</ENTRY_PORT>]# */
|
---|
92 |
|
---|
93 | /* #[<ENTRY_FUNC>]# eMrubyBody_main
|
---|
94 | * name: eMrubyBody_main
|
---|
95 | * global_name: nMruby_tMruby_eMrubyBody_main
|
---|
96 | * oneway: false
|
---|
97 | * #[</ENTRY_FUNC>]# */
|
---|
98 | void
|
---|
99 | eMrubyBody_main(CELLIDX idx)
|
---|
100 | {
|
---|
101 | #ifdef VM_EVAL
|
---|
102 | SYSUTM tstart, tend;
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | CELLCB *p_cellcb;
|
---|
106 | mrb_state *mrb;
|
---|
107 |
|
---|
108 | if (VALID_IDX(idx)) {
|
---|
109 | p_cellcb = GET_CELLCB(idx);
|
---|
110 | }
|
---|
111 | #ifdef VM_EVAL
|
---|
112 | get_utm(&tstart);
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | /* new interpreter instance */
|
---|
116 | mrb = mrb_open();
|
---|
117 | if (mrb == NULL) {
|
---|
118 | syslog(LOG_EMERG, "Invalid mrb_state, exiting test driver");
|
---|
119 | // cSerialPort_write("Invalid mrb_state, exiting test driver\n", 39);
|
---|
120 | return;
|
---|
121 | }
|
---|
122 |
|
---|
123 | #ifdef VM_EVAL
|
---|
124 | get_utm(&tend);
|
---|
125 | syslog(LOG_EMERG, "mrb_open time = %d micro sec", tend - tstart);
|
---|
126 | #endif
|
---|
127 | if(is_cInit_joined()){
|
---|
128 | // TECS Bridge
|
---|
129 | cInit_initializeBridge( mrb );
|
---|
130 | }
|
---|
131 | mrb_init_mrb(p_cellcb, mrb);
|
---|
132 | syslog(LOG_EMERG, "end of mruby program");
|
---|
133 | #ifdef VM_EVAL
|
---|
134 | get_utm(&tstart);
|
---|
135 | #endif
|
---|
136 | mrb_close(mrb);
|
---|
137 | #ifdef VM_EVAL
|
---|
138 | get_utm(&tend);
|
---|
139 | syslog(LOG_EMERG, "mrb_close time = %d micro sec", tend - tstart);
|
---|
140 | #endif
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | /* #[<POSTAMBLE>]#
|
---|
145 | * ããããä¸ã«éåãå£é¢æ°ãæ¸ãã¾ã
|
---|
146 | * #[</POSTAMBLE>]#*/
|
---|
147 |
|
---|
148 | void
|
---|
149 | mrb_init_mrb(CELLCB *p_cellcb, mrb_state *mrb)
|
---|
150 | {
|
---|
151 | mrb_irep *irep = mrb_read_irep(mrb, ATTR_irep);
|
---|
152 |
|
---|
153 | mrb_run(mrb, mrb_proc_new(mrb, irep), mrb_top_self(mrb));
|
---|
154 | if (mrb->exc) {
|
---|
155 | mrb_p(mrb, mrb_obj_value(mrb->exc));
|
---|
156 | exit(0);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | /*
|
---|
161 | extern void debug_print(char * str);
|
---|
162 | extern void debug_print_address(char * str, int address);
|
---|
163 | extern void debug_print_int(char * str, int data);
|
---|
164 | #include <errno.h>
|
---|
165 | void *
|
---|
166 | _sbrk(size_t incr)
|
---|
167 | {
|
---|
168 | // TODO: æ£ãããã¼ããµã¤ãºãæå®ããã㨠(EV3ã¯RAM 64MB)
|
---|
169 | extern char __heap_start;
|
---|
170 | static uint32_t cs3_heap_end = &__heap_start + MEM_SIZE; // ãã¼ãã®æå¾ã¢ãã¬ã¹
|
---|
171 | static char *heap_end = &__heap_start;
|
---|
172 | char *prev_heap_end;
|
---|
173 | uint16_t incr2;
|
---|
174 |
|
---|
175 | char str[20];
|
---|
176 |
|
---|
177 | #ifdef MALLOC_EVAL
|
---|
178 | syslog(LOG_EMERG, "heap_start = %x", &__heap_start);
|
---|
179 | #endif
|
---|
180 |
|
---|
181 | prev_heap_end = heap_end;
|
---|
182 | incr2 = (uint16_t)incr;
|
---|
183 |
|
---|
184 | if (heap_end + incr2 > cs3_heap_end) {
|
---|
185 | errno = ENOMEM;
|
---|
186 | return (void *)-1;
|
---|
187 | }
|
---|
188 | heap_end += incr2;
|
---|
189 |
|
---|
190 | #ifdef MALLOC_EVAL
|
---|
191 | syslog(LOG_EMERG, "heap_end = %x", heap_end);
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | #ifdef DEBUG_MALLOC
|
---|
195 | debug_print_int("incr",incr);
|
---|
196 | debug_print_address("prev_heap_end",(int) prev_heap_end);
|
---|
197 | dly_tsk(50);
|
---|
198 | #endif
|
---|
199 | return (void *) prev_heap_end;
|
---|
200 | }
|
---|
201 | */
|
---|
202 | extern intptr_t bt_snd_chr(intptr_t c);
|
---|
203 | extern intptr_t uart_snd_chr(intptr_t c) ;
|
---|
204 | extern void initialize_lcd_dri();
|
---|
205 | #define UART1 (*(volatile struct st_uart *)0x01D0C000)
|
---|
206 | size_t fwrite(const void *buf, size_t size, size_t n, FILE *fp){
|
---|
207 | intptr_t intp;
|
---|
208 | char *cp;
|
---|
209 | cp = (char*)buf;
|
---|
210 | /* ã·ãªã¢ã«ãã¼ããçµåããã¦ããå ´åã®ã¿å¼ã³åºã
|
---|
211 | if(is_cSerialPort_joined()){
|
---|
212 | //cSerialPort_write(buf, size);
|
---|
213 |
|
---|
214 | }*/
|
---|
215 |
|
---|
216 | for(int i = 0;i < size; i++){
|
---|
217 | intp = *cp++;
|
---|
218 | if (intp == '\n') {
|
---|
219 | bt_snd_chr('\r');
|
---|
220 | while(!uart_send(&UART1, '\r'));
|
---|
221 | }
|
---|
222 | bt_snd_chr(intp);
|
---|
223 | while(!uart_send(&UART1, intp));
|
---|
224 |
|
---|
225 | }
|
---|
226 | return size;
|
---|
227 | };
|
---|
228 |
|
---|
229 | #ifndef EV3_SOUND
|
---|
230 | void _write(){}
|
---|
231 | void _close(){}
|
---|
232 | void _lseek(){}
|
---|
233 | void _read(){}
|
---|
234 | //void _fstat(){}
|
---|
235 | //void _isatty(){}
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | //void _exit(){}
|
---|
239 | //void _getpid(){}
|
---|
240 | //void _kill(){}
|
---|
241 | void _gettimeofday(){}
|
---|
242 | void _fini(){}
|
---|
243 |
|
---|