[279] | 1 | /*
|
---|
| 2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2014-2017 Cores Co., Ltd. Japan
|
---|
| 5 | *
|
---|
| 6 | * ä¸è¨èä½æ¨©è
|
---|
| 7 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 8 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 9 | * å¤ã»åé
|
---|
| 10 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 11 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 12 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 13 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 14 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 15 | * ç¨ã§ããå½¢ã§åé
|
---|
| 16 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 17 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 18 | * è
|
---|
| 19 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 20 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 21 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 22 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 23 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 24 | * ã¨ï¼
|
---|
| 25 | * (a) åé
|
---|
| 26 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 27 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 28 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 29 | * (b) åé
|
---|
| 30 | å¸ã®å½¢æ
|
---|
| 31 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 32 | * å ±åãããã¨ï¼
|
---|
| 33 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 34 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 35 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 36 | 責ãããã¨ï¼
|
---|
| 37 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 38 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 39 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 40 | * å
|
---|
| 41 | 責ãããã¨ï¼
|
---|
| 42 | *
|
---|
| 43 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 44 | ã
|
---|
| 45 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 46 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 47 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 48 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: main.c 279 2017-04-29 07:33:37Z coas-nagasima $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | /*
|
---|
| 54 | * ãµã³ãã«ããã°ã©ã (1)ã®æ¬ä½
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | #include <kernel.h>
|
---|
| 58 | #include <t_syslog.h>
|
---|
| 59 | #include <t_stdlib.h>
|
---|
| 60 | #include <sil.h>
|
---|
| 61 | #include <stdlib.h>
|
---|
| 62 | #include <string.h>
|
---|
| 63 | #include <stdio.h>
|
---|
| 64 | #include <setjmp.h>
|
---|
| 65 | #include "syssvc/serial.h"
|
---|
| 66 | #include "syssvc/syslog.h"
|
---|
| 67 | #include "kernel_cfg.h"
|
---|
| 68 | #include "main.h"
|
---|
| 69 | #include "rza1.h"
|
---|
| 70 | #include <tinet_config.h>
|
---|
| 71 | #include <netinet/in.h>
|
---|
| 72 | #include <netinet/in_itron.h>
|
---|
| 73 | #include <tinet_nic_defs.h>
|
---|
| 74 | #include <tinet_cfg.h>
|
---|
| 75 | #include <netinet/in_var.h>
|
---|
| 76 | #include <net/ethernet.h>
|
---|
| 77 | #include <net/if6_var.h>
|
---|
| 78 | #include <net/net.h>
|
---|
| 79 | #include <net/if_var.h>
|
---|
| 80 | #include <netinet/udp_var.h>
|
---|
| 81 | #include <ethernet_api.h>
|
---|
| 82 | #include "ffarch.h"
|
---|
| 83 | #include "gpio_api.h"
|
---|
| 84 | #include "ff.h"
|
---|
| 85 | #include "websocket_fbs.h"
|
---|
| 86 | #include "ntshell.h"
|
---|
| 87 | #include "ntstdio.h"
|
---|
| 88 | #include "usrcmd.h"
|
---|
| 89 | #include "ntopt.h"
|
---|
| 90 |
|
---|
| 91 | #ifndef _MSC_VER
|
---|
| 92 | void strcpy_s(char *dst, int size, const char *src);
|
---|
| 93 | #endif
|
---|
| 94 |
|
---|
| 95 | ID ws_api_mailboxid = MAIN_DATAQUEUE;
|
---|
| 96 | ID ws_mempoolid = MPF_NET_BUF_256;
|
---|
| 97 |
|
---|
| 98 | #define SIO_PORTID 1
|
---|
| 99 |
|
---|
| 100 | char command[NTOPT_TEXT_MAXLEN];
|
---|
| 101 | ntstdio_t ntstdio;
|
---|
| 102 |
|
---|
| 103 | const uint8_t mac_addr[6] = {0x00, 0x30, 0x13, 0x06, 0x62, 0xC0};
|
---|
| 104 | const char host_name[] = "GR-PEACH";
|
---|
| 105 |
|
---|
| 106 | static void netif_link_callback(T_IFNET *ether);
|
---|
| 107 | extern int execute_command(int wait);
|
---|
| 108 |
|
---|
| 109 | enum main_state_t {
|
---|
| 110 | main_state_start,
|
---|
| 111 | main_state_idle,
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | struct main_t {
|
---|
| 115 | TMO timer;
|
---|
| 116 | enum main_state_t state;
|
---|
| 117 | SYSTIM prev, now;
|
---|
| 118 | WS_FBS_ID rcvmsg;
|
---|
| 119 | T_WS_FBS_QUEUE wbs_queue;
|
---|
| 120 | WS_FBS_ID sndmsg;
|
---|
| 121 | };
|
---|
| 122 | struct main_t main_obj;
|
---|
| 123 |
|
---|
| 124 | static void main_initialize();
|
---|
| 125 | static TMO main_get_timer();
|
---|
| 126 | static void main_progress(TMO interval);
|
---|
| 127 | static void main_timeout();
|
---|
| 128 |
|
---|
| 129 | int uart_read(char *buf, int cnt, void *extobj)
|
---|
| 130 | {
|
---|
| 131 | return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
|
---|
| 132 | #if 0
|
---|
| 133 | int result = cnt;
|
---|
| 134 | ER ret;
|
---|
| 135 | bool_t tmo = false;
|
---|
| 136 |
|
---|
| 137 | while (cnt > 0) {
|
---|
| 138 | /* ã¿ã¤ã ã¢ã¦ãå¦ç */
|
---|
| 139 | if (tmo) {
|
---|
| 140 | tmo = false;
|
---|
| 141 | main_timeout();
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | if (main_obj.rcvmsg.ptr == NULL) {
|
---|
| 145 | ER ret2;
|
---|
| 146 | TMO timer;
|
---|
| 147 | WS_FBS_ID msg;
|
---|
| 148 |
|
---|
| 149 | main_obj.prev = main_obj.now;
|
---|
| 150 |
|
---|
| 151 | timer = main_get_timer();
|
---|
| 152 |
|
---|
| 153 | ret = trcv_dtq(MAIN_DATAQUEUE, (intptr_t *)&msg, timer);
|
---|
| 154 | if ((ret != E_OK) && (ret != E_TMOUT)) {
|
---|
| 155 | syslog(LOG_ERROR, "trcv_dtq => %d", ret);
|
---|
| 156 | ext_tsk();
|
---|
| 157 | return 0;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | ret2 = get_tim(&main_obj.now);
|
---|
| 161 | if (ret2 != E_OK) {
|
---|
| 162 | syslog(LOG_ERROR, "get_tim");
|
---|
| 163 | ext_tsk();
|
---|
| 164 | return 0;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | /* æéçµé */
|
---|
| 168 | main_progress(main_obj.now - main_obj.prev);
|
---|
| 169 |
|
---|
| 170 | if (ret == E_OK) {
|
---|
| 171 | /* ã¡ãã»ã¼ã¸åä¿¡å¦ç */
|
---|
| 172 | if (main_obj.rcvmsg.ptr == NULL) {
|
---|
| 173 | main_obj.rcvmsg = msg;
|
---|
| 174 | }
|
---|
| 175 | else {
|
---|
| 176 | ws_fbs_enqueue(&main_obj.wbs_queue, msg.ptr);
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | tmo = true;
|
---|
| 181 | }
|
---|
| 182 | else {
|
---|
| 183 | WS_FBS_SSIZE_T len, slen;
|
---|
| 184 |
|
---|
| 185 | len = _ws_fbs_get_datalen(main_obj.rcvmsg);
|
---|
| 186 | if (len > cnt)
|
---|
| 187 | len = cnt;
|
---|
| 188 |
|
---|
| 189 | ret = _ws_fbs_get_data(main_obj.rcvmsg, buf, len, &slen);
|
---|
| 190 | if (ret != E_OK) {
|
---|
| 191 | syslog(LOG_ERROR, "_ws_fbs_get_data msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);
|
---|
| 192 | ext_tsk();
|
---|
| 193 | }
|
---|
| 194 | cnt -= slen;
|
---|
| 195 |
|
---|
| 196 | /* ãã¼ã¿ã空ã®å ´å */
|
---|
| 197 | if (!_ws_fbs_exist_data(main_obj.rcvmsg)) {
|
---|
| 198 | ret = _ws_fbs_del(main_obj.rcvmsg);
|
---|
| 199 | if (ret != E_OK) {
|
---|
| 200 | syslog(LOG_ERROR, "trcv_dtq msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);
|
---|
| 201 | ext_tsk();
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | main_obj.rcvmsg.ptr = NULL;
|
---|
| 205 |
|
---|
| 206 | /* ãã¥ã¼ãããã¼ã¿ãåå¾ */
|
---|
| 207 | ret = ws_fbs_dequeue(&main_obj.wbs_queue, &main_obj.rcvmsg.ptr);
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | return result;
|
---|
| 213 | #endif
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | int uart_write(const char *buf, int cnt, void *extobj)
|
---|
| 217 | {
|
---|
| 218 | return serial_wri_dat(SIO_PORTID, buf, cnt);
|
---|
| 219 | #if 0
|
---|
| 220 | int result = cnt;
|
---|
| 221 | ER ret;
|
---|
| 222 |
|
---|
| 223 | while (cnt > 0) {
|
---|
| 224 | _ws_fbs_cre(cnt, &main_obj.sndmsg);
|
---|
| 225 |
|
---|
| 226 | //((ID *)main_obj.sndmsg.ptr->_gap)[0] = wbsid;
|
---|
| 227 | _ws_fbs_add_data(main_obj.sndmsg, buf, cnt);
|
---|
| 228 |
|
---|
| 229 | ret = psnd_dtq(WEBSOCKET_MBXID, (intptr_t)main_obj.sndmsg.ptr);
|
---|
| 230 | if (ret != E_OK) {
|
---|
| 231 | syslog(LOG_ERROR, "psnd_dtq(WEBSOCKET_MBXID) : result=%d", ret);
|
---|
| 232 | _ws_fbs_del(main_obj.sndmsg);
|
---|
| 233 | return ret;
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | return result;
|
---|
| 238 | #endif
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | unsigned char ntstdio_xi(struct ntstdio_t *handle)
|
---|
| 242 | {
|
---|
| 243 | char buf[1];
|
---|
| 244 | if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
|
---|
| 245 | return -1;
|
---|
| 246 | return buf[0];
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
|
---|
| 250 | {
|
---|
| 251 | char buf[1];
|
---|
| 252 | buf[0] = c;
|
---|
| 253 | serial_wri_dat(SIO_PORTID, buf, 1);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | ntshell_t ntshell;
|
---|
| 257 | static int cmd_execute(const char *text, void *extobj);
|
---|
| 258 |
|
---|
| 259 | /*
|
---|
| 260 | * ã¡ã¤ã³ã¿ã¹ã¯
|
---|
| 261 | */
|
---|
| 262 | void main_task(intptr_t exinf)
|
---|
| 263 | {
|
---|
| 264 | main_initialize();
|
---|
| 265 |
|
---|
| 266 | ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);
|
---|
| 267 | ntshell_set_prompt(&ntshell, "NTShell>");
|
---|
| 268 | ntshell_execute(&ntshell);
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /*
|
---|
| 272 | * åæå
|
---|
| 273 | */
|
---|
| 274 | static void main_initialize()
|
---|
| 275 | {
|
---|
| 276 | FILINFO fno;
|
---|
| 277 | #if _USE_LFN
|
---|
| 278 | char lfn[_MAX_LFN + 1];
|
---|
| 279 | fno.lfname = lfn;
|
---|
| 280 | fno.lfsize = _MAX_LFN + 1;
|
---|
| 281 | #endif
|
---|
| 282 | ER ret2;
|
---|
| 283 |
|
---|
| 284 | ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
|
---|
| 285 |
|
---|
| 286 | main_obj.timer = TMO_FEVR;
|
---|
| 287 | main_obj.state = main_state_start;
|
---|
| 288 |
|
---|
| 289 | gpio_t led_blue, led_green, led_red, sw;
|
---|
| 290 | gpio_init_out(&led_blue, LED_BLUE);
|
---|
| 291 | gpio_init_out(&led_green, LED_GREEN);
|
---|
| 292 | gpio_init_out(&led_red, LED_RED);
|
---|
| 293 | gpio_init_in(&sw, USER_BUTTON0);
|
---|
| 294 |
|
---|
| 295 | bool_t exec = gpio_read(&sw) == 1;
|
---|
| 296 |
|
---|
| 297 | gpio_write(&led_blue, 1);
|
---|
| 298 | gpio_write(&led_green, exec ? 1 : 0);
|
---|
| 299 | gpio_write(&led_red, 0);
|
---|
| 300 |
|
---|
| 301 | ether_set_link_callback(netif_link_callback);
|
---|
| 302 |
|
---|
| 303 | /* åæå */
|
---|
| 304 | if (mruby_arduino_init() == 0) {
|
---|
| 305 | gpio_write(&led_blue, 0);
|
---|
| 306 | }
|
---|
| 307 | else {
|
---|
| 308 | gpio_write(&led_blue, 0);
|
---|
| 309 | gpio_write(&led_red, 1);
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | gpio_write(&led_green, 0);
|
---|
| 313 |
|
---|
| 314 | act_tsk(HTTPD1_TASK);
|
---|
| 315 | act_tsk(HTTPD2_TASK);
|
---|
| 316 |
|
---|
| 317 | if (f_stat("1:/upload/main.mrb", &fno) != FR_OK) {
|
---|
| 318 | exec = false;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | if (exec) {
|
---|
| 322 | strcpy_s(command, sizeof(command), "mruby -b 1:/upload/main.mrb");
|
---|
| 323 |
|
---|
| 324 | execute_command(1);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | ret2 = get_tim(&main_obj.now);
|
---|
| 328 | if (ret2 != E_OK) {
|
---|
| 329 | syslog(LOG_ERROR, "get_tim");
|
---|
| 330 | ext_tsk();
|
---|
| 331 | return;
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | /*
|
---|
| 336 | * ã¿ã¤ãã¼åå¾
|
---|
| 337 | */
|
---|
| 338 | static TMO main_get_timer()
|
---|
| 339 | {
|
---|
| 340 | TMO timer = main_obj.timer;
|
---|
| 341 |
|
---|
| 342 | return timer;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | /*
|
---|
| 346 | * æéçµé
|
---|
| 347 | */
|
---|
| 348 | static void main_progress(TMO interval)
|
---|
| 349 | {
|
---|
| 350 | if (main_obj.timer != TMO_FEVR) {
|
---|
| 351 | main_obj.timer -= interval;
|
---|
| 352 | if (main_obj.timer < 0) {
|
---|
| 353 | main_obj.timer = 0;
|
---|
| 354 | }
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | /*
|
---|
| 359 | * ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
| 360 | */
|
---|
| 361 | static void main_timeout()
|
---|
| 362 | {
|
---|
| 363 | //if (main_obj.timer == 0) {
|
---|
| 364 | //}
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /* MACã¢ãã¬ã¹ã®è¨å®æã«å¼ã°ãã */
|
---|
| 368 | void mbed_mac_address(char *mac)
|
---|
| 369 | {
|
---|
| 370 | memcpy(mac, mac_addr, 6);
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | static void netif_link_callback(T_IFNET *ether)
|
---|
| 374 | {
|
---|
| 375 | FLGPTN flgptn;
|
---|
| 376 | T_RTSK rtsk;
|
---|
| 377 | ER ret;
|
---|
| 378 |
|
---|
| 379 | ret = ref_tsk(MRUBY_TASK, &rtsk);
|
---|
| 380 | if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT))
|
---|
| 381 | return;
|
---|
| 382 |
|
---|
| 383 | FD_SET(0, (fd_set *)&flgptn);
|
---|
| 384 |
|
---|
| 385 | set_flg(FLG_SELECT_WAIT, flgptn);
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | int gethostname(char *name, size_t len)
|
---|
| 389 | {
|
---|
| 390 | return strlcpy(name, host_name, len);
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj);
|
---|
| 394 | int mruby_exit_code;
|
---|
| 395 | volatile int mruby_state;
|
---|
| 396 | typedef void (*PowerOn_Reset_t)(int argc, char **argv);
|
---|
| 397 | jmp_buf process_exit;
|
---|
| 398 |
|
---|
| 399 | /*
|
---|
| 400 | * mrubyå®è¡ã¿ã¹ã¯
|
---|
| 401 | */
|
---|
| 402 | void mruby_task(intptr_t exinf)
|
---|
| 403 | {
|
---|
| 404 | mruby_state = 1;
|
---|
| 405 | mruby_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
|
---|
| 406 | mruby_state = 2;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj)
|
---|
| 410 | {
|
---|
| 411 | if (setjmp(process_exit) == 0) {
|
---|
| 412 | (*((PowerOn_Reset_t *)0x18200000))(argc, argv);
|
---|
| 413 | }
|
---|
| 414 | clean_fd();
|
---|
| 415 | return 0;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | void shellif_into()
|
---|
| 419 | {
|
---|
| 420 | /* ã¡ã¤ã³ã¿ã¹ã¯ã®åªå
|
---|
| 421 | 度ããé«ããã */
|
---|
| 422 | chg_pri(MRUBY_PRIORITY, MAIN_PRIORITY + 1);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | void shellif_outof()
|
---|
| 426 | {
|
---|
| 427 | /* mrubyå®è¡ã¿ã¹ã¯ã®åªå
|
---|
| 428 | 度ã«æ»ã */
|
---|
| 429 | chg_pri(MRUBY_PRIORITY, MRUBY_PRIORITY);
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | void shell_abort()
|
---|
| 433 | {
|
---|
| 434 | asm("bkpt #0");
|
---|
| 435 |
|
---|
| 436 | mruby_exit_code = -1;
|
---|
| 437 | longjmp(process_exit, 1);
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | void shell_exit(int exitcd)
|
---|
| 441 | {
|
---|
| 442 | mruby_exit_code = exitcd;
|
---|
| 443 | longjmp(process_exit, 1);
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | int execute_command(int wait)
|
---|
| 447 | {
|
---|
| 448 | ER ret;
|
---|
| 449 |
|
---|
| 450 | ret = ter_tsk(MRUBY_TASK);
|
---|
| 451 | if ((ret != E_OK) && (ret != E_OBJ)) {
|
---|
| 452 | syslog(LOG_ERROR, "ter_tsk => %d", ret);
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | tslp_tsk(100000);
|
---|
| 456 |
|
---|
| 457 | clean_fd();
|
---|
| 458 |
|
---|
| 459 | mruby_state = 0;
|
---|
| 460 | ret = act_tsk(MRUBY_TASK);
|
---|
| 461 | if (ret != E_OK) {
|
---|
| 462 | syslog(LOG_ERROR, "act_tsk => %d", ret);
|
---|
| 463 | }
|
---|
| 464 |
|
---|
| 465 | if (wait == 0)
|
---|
| 466 | return 0;
|
---|
| 467 |
|
---|
| 468 | do {
|
---|
| 469 | tslp_tsk(100000);
|
---|
| 470 | } while(mruby_state == 1);
|
---|
| 471 |
|
---|
| 472 | return mruby_exit_code;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | static int cmd_execute(const char *text, void *extobj)
|
---|
| 476 | {
|
---|
| 477 | strlcpy(command, text, sizeof(command));
|
---|
| 478 | return execute_command(1);
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | int stdio_close(struct _IO_FILE *fp)
|
---|
| 482 | {
|
---|
| 483 | return -1;
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
|
---|
| 487 | {
|
---|
| 488 | return -1;
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
|
---|
| 492 | {
|
---|
| 493 | return -1;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
|
---|
| 497 | {
|
---|
| 498 | int i = 0;
|
---|
| 499 | while (i < len) {
|
---|
| 500 | int c = ntstdio_getc(&ntstdio);
|
---|
| 501 | data[i++] = c;
|
---|
| 502 | if ((c == EOF) || (c == '\n'))
|
---|
| 503 | break;
|
---|
| 504 | }
|
---|
| 505 | return i;
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
|
---|
| 509 | {
|
---|
| 510 | for (int i = 0; i < len; i++) {
|
---|
| 511 | ntstdio_putc(&ntstdio, data[i]);
|
---|
| 512 | }
|
---|
| 513 | return len;
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
|
---|
| 517 | {
|
---|
| 518 | for (int i = 0; i < len; i++) {
|
---|
| 519 | ntstdio_putc(&ntstdio, data[i]);
|
---|
| 520 | }
|
---|
| 521 | return len;
|
---|
| 522 | }
|
---|
| 523 |
|
---|
| 524 | int sio_close(struct _IO_FILE *fp)
|
---|
| 525 | {
|
---|
| 526 | return -1;
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
|
---|
| 530 | {
|
---|
| 531 | return -1;
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
|
---|
| 535 | {
|
---|
| 536 | return -1;
|
---|
| 537 | }
|
---|