Changeset 279
- Timestamp:
- Apr 29, 2017, 4:33:37 PM (6 years ago)
- Location:
- EcnlProtoTool/trunk
- Files:
-
- 412 added
- 8 deleted
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/arch/arm_gcc/common/core_support.S
r270 r279 267 267 #else /* TOPPERS_CUSTOM_IDLE */ 268 268 msr cpsr_c, #CPSR_SVC_MODE /* å²è¾¼ã¿ã許å¯ï¼ã¹ã¼ããã¤ã¶ã¢ã¼ãï¼*/ 269 ALABEL(dispatcher_2) 270 b dispatcher_ 2/* å²è¾¼ã¿å¾269 #endif /* TOPPERS_CUSTOM_IDLE */ 270 b dispatcher_1 /* å²è¾¼ã¿å¾ 271 271 ã¡ */ 272 #endif /* TOPPERS_CUSTOM_IDLE */273 272 274 273 /* -
EcnlProtoTool/trunk/asp3_dcre/arch/arm_gcc/common/gic_support.S
r270 r279 5 5 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory 6 6 * Toyohashi Univ. of Technology, JAPAN 7 * Copyright (C) 2006-201 6by Embedded and Real-Time Systems Laboratory7 * Copyright (C) 2006-2017 by Embedded and Real-Time Systems Laboratory 8 8 * Graduate School of Information Science, Nagoya Univ., JAPAN 9 9 * -
EcnlProtoTool/trunk/asp3_dcre/arch/arm_gcc/rza1/chip_timer.c
r270 r279 4 4 * Advanced Standard Profile Kernel 5 5 * 6 * Copyright (C) 2006-201 6by Embedded and Real-Time Systems Laboratory6 * Copyright (C) 2006-2017 by Embedded and Real-Time Systems Laboratory 7 7 * Graduate School of Information Science, Nagoya Univ., JAPAN 8 8 * -
EcnlProtoTool/trunk/asp3_dcre/kernel/dataqueue.c
r270 r279 6 6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory 7 7 * Toyohashi Univ. of Technology, JAPAN 8 * Copyright (C) 2005-201 6by Embedded and Real-Time Systems Laboratory8 * Copyright (C) 2005-2017 by Embedded and Real-Time Systems Laboratory 9 9 * Graduate School of Information Science, Nagoya Univ., JAPAN 10 10 * … … 612 612 CHECK_ID(VALID_DTQID(dtqid)); 613 613 p_dtqcb = get_dtqcb(dtqid); 614 CHECK_ILUSE(p_dtqcb->p_dtqinib->dtqcnt > 0U);615 614 616 615 lock_cpu(); 617 616 if (p_dtqcb->p_dtqinib->dtqatr == TA_NOEXS) { 618 617 ercd = E_NOEXS; 618 } 619 else if (!(p_dtqcb->p_dtqinib->dtqcnt > 0U)) { 620 ercd = E_ILUSE; 619 621 } 620 622 else { … … 628 630 } 629 631 } 630 }631 632 ercd = E_OK; 633 } 632 634 unlock_cpu(); 633 635 -
EcnlProtoTool/trunk/asp3_dcre/kernel/eventflag.c
r270 r279 6 6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory 7 7 * Toyohashi Univ. of Technology, JAPAN 8 * Copyright (C) 2005-201 6by Embedded and Real-Time Systems Laboratory8 * Copyright (C) 2005-2017 by Embedded and Real-Time Systems Laboratory 9 9 * Graduate School of Information Science, Nagoya Univ., JAPAN 10 10 * … … 250 250 ercd = FLGID(p_flgcb); 251 251 } 252 unlock_cpu(); 252 253 253 254 error_exit: -
EcnlProtoTool/trunk/asp3_dcre/kernel/task_manage.c
r270 r279 388 388 ercd = E_NOEXS; /*ï¼»NGKI3617ï¼½*/ 389 389 } 390 else if (TSTAT_DORMANT(tstat)) { /*ï¼»NGKI3620ï¼½*/ 391 *p_tskstat = TTS_DMT; 392 } 393 else if (TSTAT_SUSPENDED(tstat)) { 394 if (TSTAT_WAITING(tstat)) { 395 *p_tskstat = TTS_WAS; 390 else { 391 if (TSTAT_DORMANT(tstat)) { /*ï¼»NGKI3620ï¼½*/ 392 *p_tskstat = TTS_DMT; 393 } 394 else if (TSTAT_SUSPENDED(tstat)) { 395 if (TSTAT_WAITING(tstat)) { 396 *p_tskstat = TTS_WAS; 397 } 398 else { 399 *p_tskstat = TTS_SUS; 400 } 401 } 402 else if (TSTAT_WAITING(tstat)) { 403 *p_tskstat = TTS_WAI; 404 } 405 else if (p_tcb == p_runtsk) { 406 *p_tskstat = TTS_RUN; 396 407 } 397 408 else { 398 *p_tskstat = TTS_SUS; 399 } 400 } 401 else if (TSTAT_WAITING(tstat)) { 402 *p_tskstat = TTS_WAI; 403 } 404 else if (p_tcb == p_runtsk) { 405 *p_tskstat = TTS_RUN; 406 } 407 else { 408 *p_tskstat = TTS_RDY; 409 } 410 ercd = E_OK; 409 *p_tskstat = TTS_RDY; 410 } 411 ercd = E_OK; 412 } 411 413 unlock_cpu(); 412 414 -
EcnlProtoTool/trunk/asp3_dcre/kernel/time_manage.c
r270 r279 6 6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory 7 7 * Toyohashi Univ. of Technology, JAPAN 8 * Copyright (C) 2005-201 5by Embedded and Real-Time Systems Laboratory8 * Copyright (C) 2005-2017 by Embedded and Real-Time Systems Laboratory 9 9 * Graduate School of Information Science, Nagoya Univ., JAPAN 10 10 * … … 280 280 } 281 281 switch (p_nfyinfo->nfymode & ~0x0fU) { 282 case 0: 283 break; 282 284 case TENFY_SETVAR: 283 285 CHECK_PAR(INTPTR_ALIGN(p_nfyinfo->enfy.setvar.p_var)); … … 352 354 break; 353 355 case TNFY_SNDDTQ: 354 ercd = snd_dtq(p_nfyinfo->nfy.snddtq.dtqid,356 ercd = psnd_dtq(p_nfyinfo->nfy.snddtq.dtqid, 355 357 p_nfyinfo->nfy.snddtq.data); 356 358 break; … … 384 386 break; 385 387 case TENFY_SNDDTQ: 386 (void) snd_dtq(p_nfyinfo->enfy.snddtq.dtqid, (intptr_t) ercd);388 (void) psnd_dtq(p_nfyinfo->enfy.snddtq.dtqid, (intptr_t) ercd); 387 389 break; 388 390 default: -
EcnlProtoTool/trunk/asp3_dcre/library/vasyslog.c
r270 r279 66 66 67 67 void 68 syslog(uint_t prio, const char *format, ...)68 vsyslog(uint_t prio, const char *format, va_list ap) 69 69 { 70 70 SYSLOG logbuf; 71 va_list ap;72 71 uint_t i; 73 72 char sz; … … 77 76 logbuf.logpar[0] = (LOGPAR) format; 78 77 i = 1U; 79 va_start(ap, format);80 78 81 79 while ((c = *format++) != '\0' && i < TNUM_LOGPAR) { … … 124 122 } 125 123 } 126 va_end(ap);127 124 (void) tSysLog_eSysLog_write(prio, &logbuf); 128 125 } 129 126 127 void 128 syslog(uint_t prio, const char *format, ...) 129 { 130 va_list ap; 131 va_start(ap, format); 132 vsyslog(prio, format, ap); 133 va_end(ap); 134 } 135 136 /* mbed weak error function */ 137 void 138 error(const char* format, ...) { 139 va_list arg; 140 va_start(arg, format); 141 vsyslog(LOG_ERROR, format, arg); 142 va_end(arg); 143 ext_ker(); 144 } 145 130 146 #endif /* TOPPERS_OMIT_SYSLOG */ -
EcnlProtoTool/trunk/asp3_dcre/mbed/Makefile.mbed
r270 r279 61 61 START_OBJS = startup_RZ1AH.o 62 62 SYSSVC_COBJS := $(SYSSVC_COBJS)\ 63 assert.o board.o error.ogpio.o lp_ticker_api.o mbed_interface.o\63 assert.o board.o gpio.o lp_ticker_api.o mbed_interface.o\ 64 64 pinmap_common.o rtc_time.o semihost_api.o ticker_api.o us_ticker_api.o\ 65 65 RZ_A1_Init.o cmsis_nvic.o gic.o mbed_sf_boot.o mmu_Renesas_RZ_A1.o\ -
EcnlProtoTool/trunk/asp3_dcre/mbed/targets/cmsis/TARGET_RENESAS/TARGET_RZ_A1H/mmu_Renesas_RZ_A1.c
r270 r279 160 160 //Define Image 161 161 __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RO_DATA$$Base, RO_DATA_SIZE, Sect_Normal_RO); 162 __TTSection (&Image$$TTB$$ZI$$Base, 0x18200000, 4, Sect_Normal_Cod); 162 163 __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$VECTORS$$Base, VECTORS_SIZE, Sect_Normal_Cod); 163 164 __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RW_DATA$$Base, RW_DATA_SIZE, Sect_Normal_RW); -
EcnlProtoTool/trunk/asp3_dcre/target/gr_peach_gcc/target_kernel_impl.c
r270 r279 298 298 target_exit(void) 299 299 { 300 static int first = 1; 301 300 302 /* 301 303 * ãããä¾åã®çµäºå¦ç … … 306 308 * bkptå½ä»¤ã«ãããããã¬ã«å¶å¾¡ãç§»ãï¼ãã©ã¡ã¼ã¿ãä½ãè¯ããæªæ¤è¨ï¼ 307 309 */ 308 Asm("bkpt #0"); 310 if (first){ 311 first = 0; 312 Asm("bkpt #0"); 313 } 309 314 310 315 while (true) ; -
EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/udp_usrreq.c
r270 r279 485 485 return E_NOEXS; 486 486 487 return E_ PAR;487 return E_OK/*E_PAR*/; 488 488 } 489 489 … … 518 518 return E_NOEXS; 519 519 520 return E_ PAR;520 return E_OK/*E_PAR*/; 521 521 } 522 522 -
EcnlProtoTool/trunk/asp3_dcre/tinet/tcpip_api.def
r270 r279 5 5 UDP_CRE_CEP #udp4_cepid* { .udp4_cepatr { &ipv4addr &portno } &callback } 6 6 UDP6_CRE_CEP #udp6_cepid* { .udp6_cepatr { &ipv6addr &portno } &callback } 7 VRID_TCP _REP #vrid_tcp4_repid*8 VRID_TCP _CEP #vrid_tcp4_cepid*7 VRID_TCP4_REP #vrid_tcp4_repid* 8 VRID_TCP4_CEP #vrid_tcp4_cepid* 9 9 VRID_TCP6_REP #vrid_tcp6_repid* 10 10 VRID_TCP6_CEP #vrid_tcp6_cepid* 11 VRID_UDP _CEP #vrid_udp4_cepid*11 VRID_UDP4_CEP #vrid_udp4_cepid* 12 12 VRID_UDP6_CEP #vrid_udp6_cepid* -
EcnlProtoTool/trunk/asp3_dcre/tinet/tinet.trb
r270 r279 78 78 $tinetCfgH.add("#define #{params[:udp6_cepid]} #{params[:udp6_cepid].val}") 79 79 end 80 $cfgData[:VRID_TCP _REP].each do |key, params|81 $tinetCfgH.add("#define #{params[: tcp4_repid]} #{params[:tcp4_repid].val + $cfgData[:TCP_CRE_REP].size}")82 end 83 $cfgData[:VRID_TCP _CEP].each do |key, params|84 $tinetCfgH.add("#define #{params[: tcp4_cepid]} #{params[:tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}")80 $cfgData[:VRID_TCP4_REP].each do |key, params| 81 $tinetCfgH.add("#define #{params[:vrid_tcp4_repid]} #{params[:vrid_tcp4_repid].val + $cfgData[:TCP_CRE_REP].size}") 82 end 83 $cfgData[:VRID_TCP4_CEP].each do |key, params| 84 $tinetCfgH.add("#define #{params[:vrid_tcp4_cepid]} #{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}") 85 85 end 86 86 $cfgData[:VRID_TCP6_REP].each do |key, params| 87 $tinetCfgH.add("#define #{params[: tcp6_repid]} #{params[:tcp6_repid].val + $cfgData[:TCP6_CRE_REP].size}")87 $tinetCfgH.add("#define #{params[:vrid_tcp6_repid]} #{params[:vrid_tcp6_repid].val + $cfgData[:TCP6_CRE_REP].size}") 88 88 end 89 89 $cfgData[:VRID_TCP6_CEP].each do |key, params| 90 $tinetCfgH.add("#define #{params[: tcp6_cepid]} #{params[:tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}")91 end 92 $cfgData[:VRID_UDP _CEP].each do |key, params|93 $tinetCfgH.add("#define #{params[: udp4_cepid]} #{params[:udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size}")90 $tinetCfgH.add("#define #{params[:vrid_tcp6_cepid]} #{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}") 91 end 92 $cfgData[:VRID_UDP4_CEP].each do |key, params| 93 $tinetCfgH.add("#define #{params[:vrid_udp4_cepid]} #{params[:vrid_udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size}") 94 94 end 95 95 $cfgData[:VRID_UDP6_CEP].each do |key, params| 96 $tinetCfgH.add("#define #{params[: udp6_cepid]} #{params[:udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size}")96 $tinetCfgH.add("#define #{params[:vrid_udp6_cepid]} #{params[:vrid_udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size}") 97 97 end 98 98 $tinetCfgH.add() … … 144 144 145 145 # // TCP (IPv4) åä»å£ 146 if $cfgData[:TCP_CRE_REP].size > 0 || $cfgData[:VRID_TCP _REP].size > 0147 $tinetCfgC.add() 148 $tinetCfgC.add("#define TNUM_TCP_REPID #{$cfgData[:TCP_CRE_REP].size + $cfgData[:VRID_TCP _REP].size}")146 if $cfgData[:TCP_CRE_REP].size > 0 || $cfgData[:VRID_TCP4_REP].size > 0 147 $tinetCfgC.add() 148 $tinetCfgC.add("#define TNUM_TCP_REPID #{$cfgData[:TCP_CRE_REP].size + $cfgData[:VRID_TCP4_REP].size}") 149 149 $tinetCfgC.add() 150 150 $tinetCfgC.add("const ID tmax_tcp_repid = (TMIN_TCP_REPID + TNUM_TCP_REPID - 1);") … … 161 161 $tinetCfgC.add("\t\t},") 162 162 end 163 $cfgData[:VRID_TCP _REP].each do |key, params|163 $cfgData[:VRID_TCP4_REP].each do |key, params| 164 164 $tinetCfgC.add("\t{") 165 165 $tinetCfgC.add("\t\t0,") … … 167 167 $tinetCfgC.add("#if defined(TCP_CFG_EXTENTIONS)") 168 168 $tinetCfgC.add("\t\tTCP_REP_FLG_DYNAMIC,") 169 $tinetCfgC.add("\t\tSEM_TCP_REP_LOCK#{params[: tcp4_repid].val + $cfgData[:TCP_CRE_REP].size},")169 $tinetCfgC.add("\t\tSEM_TCP_REP_LOCK#{params[:vrid_tcp4_repid].val + $cfgData[:TCP_CRE_REP].size},") 170 170 $tinetCfgC.add("#endif") 171 171 $tinetCfgC.add("\t\t},") … … 198 198 $tinetCfgC.add("#if defined(TCP_CFG_EXTENTIONS)") 199 199 $tinetCfgC.add("\t\tTCP_REP_FLG_DYNAMIC,") 200 $tinetCfgC.add("\t\tSEM_TCP_REP_LOCK#{params[: tcp6_repid].val + $cfgData[:TCP6_CRE_REP].size},")200 $tinetCfgC.add("\t\tSEM_TCP_REP_LOCK#{params[:vrid_tcp6_repid].val + $cfgData[:TCP6_CRE_REP].size},") 201 201 $tinetCfgC.add("#endif") 202 202 $tinetCfgC.add("\t\t},") … … 206 206 207 207 # // TCP (IPv4) éä¿¡ç«¯ç¹ 208 if $cfgData[:TCP_CRE_CEP].size > 0 || $cfgData[:VRID_TCP _CEP].size > 0209 $tinetCfgC.add() 210 $tinetCfgC.add("#define TNUM_TCP_CEPID #{$cfgData[:TCP_CRE_CEP].size + $cfgData[:VRID_TCP _CEP].size}")208 if $cfgData[:TCP_CRE_CEP].size > 0 || $cfgData[:VRID_TCP4_CEP].size > 0 209 $tinetCfgC.add() 210 $tinetCfgC.add("#define TNUM_TCP_CEPID #{$cfgData[:TCP_CRE_CEP].size + $cfgData[:VRID_TCP4_CEP].size}") 211 211 $tinetCfgC.add() 212 212 $tinetCfgC.add("const ID tmax_tcp_cepid = (TMIN_TCP_CEPID + TNUM_TCP_CEPID - 1);") … … 228 228 $tinetCfgC.add("\t\t},") 229 229 end 230 $cfgData[:VRID_TCP _CEP].each do |key, params|230 $cfgData[:VRID_TCP4_CEP].each do |key, params| 231 231 $tinetCfgC.add("\t{") 232 232 $tinetCfgC.add("\t\t0,") … … 237 237 $tinetCfgC.add("\t\t(t_tcp_callback)(FP)NULL,") 238 238 $tinetCfgC.add("\t\tTCP_CEP_FLG_DYNAMIC,") 239 $tinetCfgC.add("\t\tSEM_TCP_CEP_LOCK#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},")240 $tinetCfgC.add("\t\tFLG_TCP_CEP_EST#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},")241 $tinetCfgC.add("\t\tFLG_TCP_CEP_SND#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},")242 $tinetCfgC.add("\t\tFLG_TCP_CEP_RCV#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},")239 $tinetCfgC.add("\t\tSEM_TCP_CEP_LOCK#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},") 240 $tinetCfgC.add("\t\tFLG_TCP_CEP_EST#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},") 241 $tinetCfgC.add("\t\tFLG_TCP_CEP_SND#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},") 242 $tinetCfgC.add("\t\tFLG_TCP_CEP_RCV#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size},") 243 243 $tinetCfgC.add("\t\t},") 244 244 end … … 278 278 $tinetCfgC.add("\t\t(t_tcp_callback)(FP)NULL,") 279 279 $tinetCfgC.add("\t\tTCP_CEP_FLG_DYNAMIC,") 280 $tinetCfgC.add("\t\tSEM_TCP_CEP_LOCK#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},")281 $tinetCfgC.add("\t\tFLG_TCP_CEP_EST#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},")282 $tinetCfgC.add("\t\tFLG_TCP_CEP_SND#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},")283 $tinetCfgC.add("\t\tFLG_TCP_CEP_RCV#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},")280 $tinetCfgC.add("\t\tSEM_TCP_CEP_LOCK#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},") 281 $tinetCfgC.add("\t\tFLG_TCP_CEP_EST#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},") 282 $tinetCfgC.add("\t\tFLG_TCP_CEP_SND#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},") 283 $tinetCfgC.add("\t\tFLG_TCP_CEP_RCV#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size},") 284 284 $tinetCfgC.add("\t\t},") 285 285 end … … 288 288 289 289 # // UDP (IPv4) éä¿¡ç«¯ç¹ 290 if $cfgData[:UDP_CRE_CEP].size > 0 || $cfgData[:VRID_UDP _CEP].size > 0291 $tinetCfgC.add() 292 $tinetCfgC.add("#define TNUM_UDP_CEPID #{$cfgData[:UDP_CRE_CEP].size + $cfgData[:VRID_UDP _CEP].size}")290 if $cfgData[:UDP_CRE_CEP].size > 0 || $cfgData[:VRID_UDP4_CEP].size > 0 291 $tinetCfgC.add() 292 $tinetCfgC.add("#define TNUM_UDP_CEPID #{$cfgData[:UDP_CRE_CEP].size + $cfgData[:VRID_UDP4_CEP].size}") 293 293 $tinetCfgC.add() 294 294 $tinetCfgC.add("const ID tmax_udp_cepid = (TMIN_UDP_CEPID + TNUM_UDP_CEPID - 1);") … … 307 307 $tinetCfgC.add("\t\t},") 308 308 end 309 $cfgData[:VRID_UDP _CEP].each do |key, params|309 $cfgData[:VRID_UDP4_CEP].each do |key, params| 310 310 $tinetCfgC.add("\t{") 311 311 $tinetCfgC.add("\t\t0,") … … 313 313 $tinetCfgC.add("\t\t(t_udp_callback)(FP)NULL,") 314 314 $tinetCfgC.add("\t\tUDP_CEP_FLG_DYNAMIC,") 315 $tinetCfgC.add("\t\tSEM_UDP_CEP_LOCK#{params[: udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size},")316 $tinetCfgC.add("\t\tTA_NULL,") 317 $tinetCfgC.add("\t\tTA_NULL,") 318 $tinetCfgC.add("\t\tDTQ_UDP_RCVQ#{params[: udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size},")315 $tinetCfgC.add("\t\tSEM_UDP_CEP_LOCK#{params[:vrid_udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size},") 316 $tinetCfgC.add("\t\tTA_NULL,") 317 $tinetCfgC.add("\t\tTA_NULL,") 318 $tinetCfgC.add("\t\tDTQ_UDP_RCVQ#{params[:vrid_udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size},") 319 319 $tinetCfgC.add("\t\t},") 320 320 end … … 348 348 $tinetCfgC.add("\t\t(t_udp_callback)(FP)NULL,") 349 349 $tinetCfgC.add("\t\tUDP_CEP_FLG_DYNAMIC,") 350 $tinetCfgC.add("\t\tSEM_UDP_CEP_LOCK#{params[: udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size},")351 $tinetCfgC.add("\t\tTA_NULL,") 352 $tinetCfgC.add("\t\tTA_NULL,") 353 $tinetCfgC.add("\t\tDTQ_UDP_RCVQ#{params[: udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size},")350 $tinetCfgC.add("\t\tSEM_UDP_CEP_LOCK#{params[:vrid_udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size},") 351 $tinetCfgC.add("\t\tTA_NULL,") 352 $tinetCfgC.add("\t\tTA_NULL,") 353 $tinetCfgC.add("\t\tDTQ_UDP_RCVQ#{params[:vrid_udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size},") 354 354 $tinetCfgC.add("\t\t},") 355 355 end … … 362 362 363 363 # // TCP (IPv4) åä»å£ 364 if $cfgData[:TCP_CRE_REP].size > 0 || $cfgData[:VRID_TCP _REP].size > 0364 if $cfgData[:TCP_CRE_REP].size > 0 || $cfgData[:VRID_TCP4_REP].size > 0 365 365 $cfgData[:TCP_CRE_REP].each do |key, params| 366 366 cfgInfo = { APINAME: "CRE_SEM" } … … 371 371 $cfgFileInfo.push(cfgInfo) 372 372 end 373 $cfgData[:VRID_TCP _REP].each do |key, params|374 cfgInfo = { APINAME: "CRE_SEM" } 375 cfgInfo["semid"] = "SEM_TCP_REP_LOCK#{params[: tcp4_repid].val + $cfgData[:TCP_CRE_REP].size}"373 $cfgData[:VRID_TCP4_REP].each do |key, params| 374 cfgInfo = { APINAME: "CRE_SEM" } 375 cfgInfo["semid"] = "SEM_TCP_REP_LOCK#{params[:vrid_tcp4_repid].val + $cfgData[:TCP_CRE_REP].size}" 376 376 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 377 377 cfgInfo["isemcnt"] = 1 … … 393 393 $cfgData[:VRID_TCP6_REP].each do |key, params| 394 394 cfgInfo = { APINAME: "CRE_SEM" } 395 cfgInfo["semid"] = "SEM_TCP_REP_LOCK#{params[: tcp6_repid].val + $cfgData[:TCP6_CRE_REP].size}"395 cfgInfo["semid"] = "SEM_TCP_REP_LOCK#{params[:vrid_tcp6_repid].val + $cfgData[:TCP6_CRE_REP].size}" 396 396 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 397 397 cfgInfo["isemcnt"] = 1 … … 402 402 403 403 # // TCP (IPv4) éä¿¡ç«¯ç¹ 404 if $cfgData[:TCP_CRE_CEP].size > 0 || $cfgData[:VRID_TCP _CEP].size > 0404 if $cfgData[:TCP_CRE_CEP].size > 0 || $cfgData[:VRID_TCP4_CEP].size > 0 405 405 $cfgData[:TCP_CRE_CEP].each do |key, params| 406 406 cfgInfo = { APINAME: "CRE_SEM" } … … 429 429 $cfgFileInfo.push(cfgInfo) 430 430 end 431 $cfgData[:VRID_TCP _CEP].each do |key, params|432 cfgInfo = { APINAME: "CRE_SEM" } 433 cfgInfo["semid"] = "SEM_TCP_CEP_LOCK#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}"434 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 435 cfgInfo["isemcnt"] = 1 436 cfgInfo["maxsem"] = 1 437 $cfgFileInfo.push(cfgInfo) 438 439 cfgInfo = { APINAME: "CRE_FLG" } 440 cfgInfo["flgid"] = "FLG_TCP_CEP_EST#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}"441 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 442 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 443 $cfgFileInfo.push(cfgInfo) 444 445 cfgInfo = { APINAME: "CRE_FLG" } 446 cfgInfo["flgid"] = "FLG_TCP_CEP_SND#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}"447 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 448 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 449 $cfgFileInfo.push(cfgInfo) 450 451 cfgInfo = { APINAME: "CRE_FLG" } 452 cfgInfo["flgid"] = "FLG_TCP_CEP_RCV#{params[: tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}"431 $cfgData[:VRID_TCP4_CEP].each do |key, params| 432 cfgInfo = { APINAME: "CRE_SEM" } 433 cfgInfo["semid"] = "SEM_TCP_CEP_LOCK#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}" 434 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 435 cfgInfo["isemcnt"] = 1 436 cfgInfo["maxsem"] = 1 437 $cfgFileInfo.push(cfgInfo) 438 439 cfgInfo = { APINAME: "CRE_FLG" } 440 cfgInfo["flgid"] = "FLG_TCP_CEP_EST#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}" 441 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 442 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 443 $cfgFileInfo.push(cfgInfo) 444 445 cfgInfo = { APINAME: "CRE_FLG" } 446 cfgInfo["flgid"] = "FLG_TCP_CEP_SND#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}" 447 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 448 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 449 $cfgFileInfo.push(cfgInfo) 450 451 cfgInfo = { APINAME: "CRE_FLG" } 452 cfgInfo["flgid"] = "FLG_TCP_CEP_RCV#{params[:vrid_tcp4_cepid].val + $cfgData[:TCP_CRE_CEP].size}" 453 453 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 454 454 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") … … 487 487 $cfgData[:VRID_TCP6_CEP].each do |key, params| 488 488 cfgInfo = { APINAME: "CRE_SEM" } 489 cfgInfo["semid"] = "SEM_TCP_CEP_LOCK#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}"490 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 491 cfgInfo["isemcnt"] = 1 492 cfgInfo["maxsem"] = 1 493 $cfgFileInfo.push(cfgInfo) 494 495 cfgInfo = { APINAME: "CRE_FLG" } 496 cfgInfo["flgid"] = "FLG_TCP_CEP_EST#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}"497 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 498 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 499 $cfgFileInfo.push(cfgInfo) 500 501 cfgInfo = { APINAME: "CRE_FLG" } 502 cfgInfo["flgid"] = "FLG_TCP_CEP_SND#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}"503 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 504 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 505 $cfgFileInfo.push(cfgInfo) 506 507 cfgInfo = { APINAME: "CRE_FLG" } 508 cfgInfo["flgid"] = "FLG_TCP_CEP_RCV#{params[: tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}"489 cfgInfo["semid"] = "SEM_TCP_CEP_LOCK#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}" 490 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 491 cfgInfo["isemcnt"] = 1 492 cfgInfo["maxsem"] = 1 493 $cfgFileInfo.push(cfgInfo) 494 495 cfgInfo = { APINAME: "CRE_FLG" } 496 cfgInfo["flgid"] = "FLG_TCP_CEP_EST#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}" 497 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 498 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 499 $cfgFileInfo.push(cfgInfo) 500 501 cfgInfo = { APINAME: "CRE_FLG" } 502 cfgInfo["flgid"] = "FLG_TCP_CEP_SND#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}" 503 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 504 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") 505 $cfgFileInfo.push(cfgInfo) 506 507 cfgInfo = { APINAME: "CRE_FLG" } 508 cfgInfo["flgid"] = "FLG_TCP_CEP_RCV#{params[:vrid_tcp6_cepid].val + $cfgData[:TCP6_CRE_CEP].size}" 509 509 cfgInfo["flgatr"] = NumStr.new($TA_TFIFO | $TA_WSGL, "TA_TFIFO|TA_WSGL") 510 510 cfgInfo["iflgptn"] = NumStr.new($TCP_CEP_EVT_CLOSED, "TCP_CEP_EVT_CLOSED") … … 514 514 515 515 # // UDP (IPv4) éä¿¡ç«¯ç¹ 516 if $cfgData[:UDP_CRE_CEP].size > 0 || $cfgData[:VRID_UDP _CEP].size > 0516 if $cfgData[:UDP_CRE_CEP].size > 0 || $cfgData[:VRID_UDP4_CEP].size > 0 517 517 $cfgData[:UDP_CRE_CEP].each do |key, params| 518 518 cfgInfo = { APINAME: "CRE_SEM" } … … 530 530 $cfgFileInfo.push(cfgInfo) 531 531 end 532 $cfgData[:VRID_UDP _CEP].each do |key, params|533 cfgInfo = { APINAME: "CRE_SEM" } 534 cfgInfo["semid"] = "SEM_UDP_CEP_LOCK#{params[: udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size}"532 $cfgData[:VRID_UDP4_CEP].each do |key, params| 533 cfgInfo = { APINAME: "CRE_SEM" } 534 cfgInfo["semid"] = "SEM_UDP_CEP_LOCK#{params[:vrid_udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size}" 535 535 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 536 536 cfgInfo["isemcnt"] = 1 … … 539 539 540 540 cfgInfo = { APINAME: "CRE_DTQ" } 541 cfgInfo["dtqid"] = "DTQ_UDP_RCVQ#{params[: udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size}"541 cfgInfo["dtqid"] = "DTQ_UDP_RCVQ#{params[:vrid_udp4_cepid].val + $cfgData[:UDP_CRE_CEP].size}" 542 542 cfgInfo["dtqatr"] = NumStr.new($TA_TFIFO, "TA_TFIFO") 543 543 cfgInfo["dtqcnt"] = NumStr.new($NUM_DTQ_UDP_RCVQ, "NUM_DTQ_UDP_RCVQ") … … 566 566 $cfgData[:VRID_UDP6_CEP].each do |key, params| 567 567 cfgInfo = { APINAME: "CRE_SEM" } 568 cfgInfo["semid"] = "SEM_UDP_CEP_LOCK#{params[: udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size}"568 cfgInfo["semid"] = "SEM_UDP_CEP_LOCK#{params[:vrid_udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size}" 569 569 cfgInfo["sematr"] = NumStr.new($TA_TPRI, "TA_TPRI") 570 570 cfgInfo["isemcnt"] = 1 … … 573 573 574 574 cfgInfo = { APINAME: "CRE_DTQ" } 575 cfgInfo["dtqid"] = "DTQ_UDP_RCVQ#{params[: udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size}"575 cfgInfo["dtqid"] = "DTQ_UDP_RCVQ#{params[:vrid_udp6_cepid].val + $cfgData[:UDP6_CRE_CEP].size}" 576 576 cfgInfo["dtqatr"] = NumStr.new($TA_TFIFO, "TA_TFIFO") 577 577 cfgInfo["dtqcnt"] = NumStr.new($NUM_DTQ_UDP_RCVQ, "NUM_DTQ_UDP_RCVQ") -
EcnlProtoTool/trunk/mruby-1.2.0/Makefile
r270 r279 3 3 # codebase. 4 4 5 RAKE = ruby ./minirake5 RAKE = ruby -Eutf-8 ./minirake 6 6 7 7 all : -
EcnlProtoTool/trunk/mruby-1.2.0/build_config.rb
r270 r279 152 152 conf.cc.defines << %w(MRB_GC_STRESS) 153 153 #conf.cc.defines << %w(DISABLE_STDIO) 154 conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK) 154 155 155 156 conf.build_mrbtest_lib_only 156 157 158 conf.gem "#{root}/mrbgems/mruby-compiler" 157 159 conf.gem "#{root}/mrbgems/mruby-numeric-ext" 158 160 conf.gem "#{root}/mrbgems/mruby-string-ext" 161 conf.gem '../mrbgems/mruby-onig-regexp' do |g| 162 g.cc.include_paths << "../onigmo-5.15.0/src" 163 end 159 164 conf.gem "#{root}/../mrbgems/mruby-blockly" 160 conf.gem "#{root}/../mrbgems/gr_peach" do |g| 161 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/api" 162 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/hal" 163 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/cmsis" 164 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/cmsis/TARGET_RENESAS/TARGET_RZ_A1H" 165 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/cmsis/TARGET_RENESAS/TARGET_RZ_A1H/inc" 166 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/cmsis/TARGET_RENESAS/TARGET_RZ_A1H/inc/iodefines" 167 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/hal/TARGET_RENESAS/TARGET_RZ_A1H" 168 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/hal/TARGET_RENESAS/TARGET_RZ_A1H/TARGET_MBED_MBRZA1H" 165 conf.gem "#{root}/../mrbgems/mruby-io" 166 conf.gem "#{root}/../mrbgems/mruby-dir" do |g| 167 g.cc.defines = %w(__NEWLIB__=2) 168 g.cc.include_paths << "#{g.dir}/../../musl-1.1.12/include" 169 end 170 conf.gem "#{root}/../mrbgems/mruby-pack" 171 conf.gem "#{root}/../mrbgems/mruby-socket" do |g| 172 g.cc.include_paths << "#{g.dir}/../../musl-1.1.12/include" 169 173 end 170 174 conf.gem "#{root}/../mrbgems/mruby-arduino" do |g| … … 177 181 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/hal/TARGET_RENESAS/TARGET_RZ_A1H" 178 182 g.cc.include_paths << "#{g.dir}/../../asp3_dcre/mbed/targets/hal/TARGET_RENESAS/TARGET_RZ_A1H/TARGET_MBED_MBRZA1H" 179 g.cc.include_paths << "#{g.dir}/../../mrbgems/gr_peach/src" 183 g.cc.include_paths << "#{g.dir}/../../sample/gr_peach" 184 g.cc.include_paths << "#{g.dir}/../../prototool/src" 180 185 end 181 186 conf.gem "#{root}/../mrbgems/mruby-ecnl" -
EcnlProtoTool/trunk/mruby-1.2.0/include/mruby.h
r270 r279 859 859 * Pointer to the newly created mrb_state. 860 860 */ 861 MRB_API mrb_state* mrb_open_allocf(mrb_allocf f, void *ud );861 MRB_API mrb_state* mrb_open_allocf(mrb_allocf f, void *ud, mrb_bool disable_gems); 862 862 863 863 /** -
EcnlProtoTool/trunk/mruby-1.2.0/src/state.c
r270 r279 97 97 mrb_open(void) 98 98 { 99 mrb_state *mrb = mrb_open_allocf(mrb_default_allocf, NULL );99 mrb_state *mrb = mrb_open_allocf(mrb_default_allocf, NULL, FALSE); 100 100 101 101 return mrb; … … 103 103 104 104 MRB_API mrb_state* 105 mrb_open_allocf(mrb_allocf f, void *ud )105 mrb_open_allocf(mrb_allocf f, void *ud, mrb_bool disable_gems) 106 106 { 107 107 mrb_state *mrb = mrb_open_core(f, ud); … … 111 111 } 112 112 113 #ifndef DISABLE_GEMS 114 mrb_init_mrbgems(mrb);115 mrb_gc_arena_restore(mrb, 0);116 #endif 113 if (!disable_gems) { 114 mrb_init_mrbgems(mrb); 115 mrb_gc_arena_restore(mrb, 0); 116 } 117 117 return mrb; 118 118 } -
EcnlProtoTool/trunk/ntshell/fatfs/ccsbcs.c
r278 r279 266 266 267 267 268 #if !_TBLDEF || !_USE_LFN268 #if _CODE_PAGE != 65001 && (!_TBLDEF || !_USE_LFN) 269 269 #error This file is not needed at current configuration. Remove from the project. 270 270 #endif … … 272 272 273 273 274 274 #if _CODE_PAGE != 65001 275 275 WCHAR ff_convert ( /* Converted character, Returns zero on error */ 276 276 WCHAR chr, /* Character code to be converted */ … … 298 298 return c; 299 299 } 300 300 #endif 301 301 302 302 -
EcnlProtoTool/trunk/ntshell/fatfs/diskio.c
r278 r279 15 15 #define MAX_DRIVES 1 /* Max number of physical drives to be used */ 16 16 17 unsigned char RamDisk[SZ_RAMDISK * 1024]; 17 #define RamDisk _binary____webserver_httpd_fs_bin_start 18 extern unsigned char RamDisk[]; 18 19 19 20 typedef struct { -
EcnlProtoTool/trunk/ntshell/fatfs/ff.c
r278 r279 314 314 #endif 315 315 #define _DF1S 0 316 317 #elif _CODE_PAGE == 65001 /* UTF-8 */ 318 #if _LFN_UNICODE 319 #error Cannot use LFN_UNICODE feature without valid code page. 320 #endif 321 #define _DF1S 0 322 323 void Utf16_to_Utf8(unsigned char *ret_code, int *ret_size, UINT chr) 324 { 325 ret_code[0] = ret_code[1] = ret_code[2] = ret_code[3] = 0; 326 327 if (chr <= 0x7f) { // ASCIIäºæ 328 ret_code[0] = chr; 329 *ret_size = 1; 330 return; 331 } 332 333 if (chr <= 0x7ff) { 334 ret_code[1] = (0x80 | (chr & 0x3f)); 335 ret_code[0] = (0xc0 | (chr >> 6)); 336 *ret_size = 2; 337 return; 338 } 339 340 if (chr <= 0xffff) { 341 ret_code[2] = (0x80 | (chr & 0x3f)); 342 ret_code[1] = (0x80 | ((chr >> 6) & 0x3f)); 343 ret_code[0] = (0xe0 | ((chr >> 12) & 0x0f)); 344 *ret_size = 3; 345 return; 346 } 347 348 if (chr <= 0x1fffff) { 349 ret_code[3] = (0x80 | (chr & 0x3f)); 350 ret_code[2] = (0x80 | ((chr >> 6) & 0x3f)); 351 ret_code[1] = (0x80 | ((chr >> 12) & 0x3f)); 352 ret_code[0] = (0xf0 | ((chr >> 18) & 0x07)); 353 *ret_size = 4; 354 return; 355 } 356 357 if (chr <= 0x3ffffff) { 358 ret_code[4] = (0x80 | (chr & 0x3f)); 359 ret_code[3] = (0x80 | ((chr >> 6) & 0x3f)); 360 ret_code[2] = (0x80 | ((chr >> 12) & 0x3f)); 361 ret_code[1] = (0x80 | ((chr >> 18) & 0x3f)); 362 ret_code[0] = (0xf8 | ((chr >> 24) & 0x03)); 363 *ret_size = 5; 364 return; 365 } 366 367 ret_code[5] = (0x80 | (chr & 0x3f)); 368 ret_code[4] = (0x80 | ((chr >> 6) & 0x3f)); 369 ret_code[3] = (0x80 | ((chr >> 12) & 0x3f)); 370 ret_code[2] = (0x80 | ((chr >> 18) & 0x3f)); 371 ret_code[1] = (0x80 | ((chr >> 24) & 0x3f)); 372 ret_code[0] = (0xfc | ((chr >> 30) & 0x01)); 373 *ret_size = 6; 374 return; 375 } 376 377 //2ãã¤ãã®UTF-16ã³ã¼ããå¾ããã 378 WCHAR Utf8_to_Utf16(const char *src, int *code_size) 379 { 380 int i; 381 unsigned int uc = 0; 382 unsigned char len = 0; 383 384 len = 0; 385 if ((src[0] & 0x80) == 0) { uc = src[0] & 0x7F; len = 0; } 386 else if ((src[0] & 0xE0) == 0xC0) { uc = src[0] & 0x1F; len = 1; } 387 else if ((src[0] & 0xF0) == 0xE0) { uc = src[0] & 0x0F; len = 2; } 388 else if ((src[0] & 0xF8) == 0xF0) { uc = src[0] & 0x07; len = 3; } 389 else if ((src[0] & 0xFC) == 0xF8) { uc = src[0] & 0x03; len = 4; } 390 else if ((src[0] & 0xFE) == 0xFC) { uc = src[0] & 0x01; len = 5; } 391 392 i = 1; 393 while ((i <= len) && ((src[i] & 0xC0) == 0x80)) { 394 uc = (uc << 6) | (src[i] & 0x3F); 395 i++; 396 } 397 398 //æ¶è²»æåæ°è¨å® 399 *code_size = i; 400 401 //ç¾ç¶ã2ãã¤ãéå® 402 return uc; 403 } 316 404 317 405 #else … … 1712 1800 WCHAR w, *lfn; 1713 1801 #endif 1802 #if _CODE_PAGE == 65001 1803 unsigned char utf8_code[6]; 1804 int code_size; 1805 #endif 1714 1806 1715 1807 p = fno->fname; … … 1748 1840 while ((w = *lfn++) != 0) { /* Get an LFN character */ 1749 1841 #if !_LFN_UNICODE 1842 #if _CODE_PAGE == 65001 1843 Utf16_to_Utf8(utf8_code, &code_size, w); 1844 for (int j = 0; j < code_size - 1; j++) { 1845 p[i++] = utf8_code[j]; 1846 } 1847 w = utf8_code[code_size - 1]; 1848 #else 1750 1849 w = ff_convert(w, 0); /* Unicode -> OEM */ 1751 1850 if (!w) { i = 0; break; } /* No LFN if it could not be converted */ … … 1753 1852 p[i++] = (TCHAR)(w >> 8); 1754 1853 #endif 1854 #endif 1755 1855 if (i >= fno->lfsize - 1) { i = 0; break; } /* No LFN if buffer overflow */ 1756 1856 p[i++] = (TCHAR)w; … … 1778 1878 1779 1879 #if !_LFN_UNICODE 1880 #if _CODE_PAGE == 65001 1881 int code_size; 1882 chr = Utf8_to_Utf16(*ptr, &code_size); 1883 (*ptr) += code_size; 1884 #else 1780 1885 chr = (BYTE)*(*ptr)++; /* Get a byte */ 1781 1886 if (IsLower(chr)) chr -= 0x20; /* To upper ASCII char */ 1782 1887 if (IsDBCS1(chr) && IsDBCS2(**ptr)) /* Get DBC 2nd byte if needed */ 1783 1888 chr = chr << 8 | (BYTE)*(*ptr)++; 1889 #endif 1784 1890 #ifdef _EXCVT 1785 1891 if (chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ … … 1851 1957 UINT i, ni, si, di; 1852 1958 const TCHAR *p; 1853 1959 #if _CODE_PAGE == 65001 1960 char utf8_code[6]; 1961 int code_size; 1962 #endif 1854 1963 /* Create LFN in Unicode */ 1855 1964 for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */ … … 1862 1971 return FR_INVALID_NAME; 1863 1972 #if !_LFN_UNICODE 1973 #if _CODE_PAGE == 65001 1974 w = Utf8_to_Utf16(&p[si - 1], &code_size); 1975 si += code_size - 1; 1976 #else 1864 1977 w &= 0xFF; 1865 1978 if (IsDBCS1(w)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ … … 1871 1984 w = ff_convert(w, 1); /* Convert ANSI/OEM to Unicode */ 1872 1985 if (!w) return FR_INVALID_NAME; /* Reject invalid code */ 1986 #endif 1873 1987 #endif 1874 1988 if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) /* Reject illegal characters for LFN */ … … 1925 2039 if (w) w = ExCvt[w - 0x80]; /* Convert extended character to upper (SBCS) */ 1926 2040 #else 2041 #if _CODE_PAGE == 65001 2042 Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w)); 2043 #else 1927 2044 w = ff_convert(ff_wtoupper(w), 0); /* Upper converted Unicode -> OEM code */ 1928 2045 #endif 2046 #endif 1929 2047 cf |= NS_LFN; /* Force create LFN entry */ 1930 2048 } 1931 2049 #if _CODE_PAGE == 65001 2050 else 2051 code_size = 1; 2052 #endif 2053 2054 #if _CODE_PAGE == 65001 2055 if (code_size > 1) { /* Is this DBC? (always false at SBCS cfg) */ 2056 if (i >= ni - 1) { 2057 cf |= NS_LOSS | NS_LFN; i = ni; continue; 2058 } 2059 for (int j = 0; j < code_size; j++) { 2060 dp->fn[i++] = (BYTE)utf8_code[j]; 2061 } 2062 } 2063 else { /* SBC */ 2064 if (!w || chk_chr("+,;=[]", w)) { /* Replace illegal characters for SFN */ 2065 w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ 2066 } 2067 else { 2068 if (IsUpper(w)) { /* ASCII large capital */ 2069 b |= 2; 2070 } 2071 else { 2072 if (IsLower(w)) { /* ASCII small capital */ 2073 b |= 1; w -= 0x20; 2074 } 2075 } 2076 } 2077 dp->fn[i++] = (BYTE)w; 2078 } 2079 #else 1932 2080 if (_DF1S && w >= 0x100) { /* Is this DBC? (always false at SBCS cfg) */ 1933 2081 if (i >= ni - 1) { … … 1949 2097 } 1950 2098 dp->fn[i++] = (BYTE)w; 2099 #endif 1951 2100 } 1952 2101 … … 3178 3327 } 3179 3328 3180 3329 FRESULT f_seek(FIL* fp, DWORD ofs, BYTE mode) 3330 { 3331 switch (mode) { 3332 case F_SEEK_SET: 3333 return f_lseek((fp), ofs); 3334 case F_SEEK_CUR: 3335 return f_lseek((fp), (fp)->fptr + ofs); 3336 case F_SEEK_END: 3337 return f_lseek((fp), (fp)->fsize - ofs); 3338 default: 3339 return FR_INVALID_PARAMETER; 3340 } 3341 } 3181 3342 3182 3343 #if _FS_MINIMIZE <= 1 … … 3719 3880 DWORD dw; 3720 3881 DEFINE_NAMEBUF; 3882 TCHAR *temp_new_path = 0; 3721 3883 3722 3884 … … 3742 3904 else 3743 3905 res = FR_INVALID_DRIVE; 3744 if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */ 3906 if (res == FR_OK) { 3907 res = FR_EXIST; /* The new object name is already existing */ 3908 dir = djn.dir; 3909 if (dir[DIR_Attr] & AM_DIR) { /* The new object is a directory */ 3910 temp_new_path = (TCHAR *)ff_memalloc((_MAX_LFN + 1) * sizeof(WCHAR)); 3911 snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old)); 3912 res = follow_path(&djn, temp_new_path); 3913 } 3914 } 3745 3915 if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ 3746 3916 res = dir_register(&djn); /* Register the new entry */ … … 3777 3947 } 3778 3948 3949 if (temp_new_path != 0) ff_memfree(temp_new_path); 3950 3779 3951 LEAVE_FF(djo.fs, res); 3780 3952 } … … 3912 4084 WCHAR w; 3913 4085 DWORD tm; 3914 4086 #if _CODE_PAGE == 65001 4087 int code_size; 4088 char utf8_code[6]; 4089 #endif 3915 4090 3916 4091 /* Get logical drive number */ … … 3925 4100 i = j = 0; 3926 4101 do { 4102 #if _CODE_PAGE == 65001 4103 w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size)); 4104 i += code_size; 4105 Utf16_to_Utf8(utf8_code, &code_size, w); 4106 if (!w || chk_chr("\"*+,.:;<=>\?[]|\x7F", w) || j >= sizeof(vn) - code_size) /* Reject invalid characters for volume label */ 4107 LEAVE_FF(dj.fs, FR_INVALID_NAME); 4108 for (int k = 0; k < code_size; k++) 4109 vn[j++] = utf8_code[k]; 4110 #else 3927 4111 #if _USE_LFN && _LFN_UNICODE 3928 4112 w = ff_convert(ff_wtoupper(label[i++]), 0); … … 3946 4130 if (w >= 0x100) vn[j++] = (BYTE)(w >> 8); 3947 4131 vn[j++] = (BYTE)w; 4132 #endif 3948 4133 } while (i < sl); 3949 4134 while (j < 11) vn[j++] = ' '; /* Fill remaining name field */ -
EcnlProtoTool/trunk/ntshell/fatfs/ff.h
r278 r279 143 143 /* Directory object structure (DIR) */ 144 144 145 typedef struct {145 typedef struct __dirstream { 146 146 FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */ 147 147 WORD id; /* Owner file system mount ID (**do not change order**) */ … … 162 162 const TCHAR* pat; /* Pointer to the name matching pattern */ 163 163 #endif 164 struct dirent *dirent; 164 165 } DIR; 165 166 … … 252 253 #define f_rewind(fp) f_lseek((fp), 0) 253 254 #define f_rewinddir(dp) f_readdir((dp), 0) 254 #define f_flush(fp) 255 #define f_flush(fp) (FR_OK) 255 256 256 257 #define F_SEEK_SET 1 257 258 #define F_SEEK_CUR 2 258 259 #define F_SEEK_END 3 259 static FRESULT f_seek(FIL* fp, DWORD ofs, BYTE mode) 260 { 261 switch (mode) { 262 case F_SEEK_SET: 263 return f_lseek((fp), ofs); 264 case F_SEEK_CUR: 265 return f_lseek((fp), (fp)->fptr + ofs); 266 case F_SEEK_END: 267 return f_lseek((fp), (fp)->fsize - ofs); 268 default: 269 return FR_INVALID_PARAMETER; 270 } 271 } 260 FRESULT f_seek(FIL* fp, DWORD ofs, BYTE mode); 272 261 273 262 #ifndef EOF -
EcnlProtoTool/trunk/ntshell/fatfs/ffarch.c
r278 r279 56 56 #include <kernel.h> 57 57 #include <stdlib.h> 58 #include <errno.h>59 #include <sys/types.h>60 58 #include <string.h> 61 59 #include "t_stdlib.h" 60 #include "syssvc/serial.h" 62 61 #include "syssvc/syslog.h" 63 62 #include "kernel_cfg.h" … … 65 64 #include "sdfs.h" 66 65 #include "ff.h" 66 #include "tlsf.h" 67 #include "ntstdio.h" 68 69 #define SIO_PORTID 1 70 extern ntstdio_t ntstdio; 71 72 static tlsf_t sys_tlsf; 73 static pool_t sys_pool; 74 75 uint32_t __HeapBase; 76 uint32_t __HeapLimit; 77 FATFS RomDisk; 67 78 68 79 gpio_t ins; … … 70 81 #define WP() false 71 82 72 extern FATFS RomDisk; 73 extern unsigned char RamDisk[SZ_RAMDISK * 1024]; 74 83 typedef struct SD { 84 DSTATUS dst; 85 BYTE type; 86 FATFS FatFs; 87 } SD; 88 SD Sd; 89 90 void sys_init(void); 75 91 bool_t romdisk_init(); 92 bool_t SD_begin(); 76 93 77 94 int mruby_arduino_init() 78 95 { 79 96 int result = -1; 97 98 sys_init(); 80 99 81 100 /* SD_CD */ … … 85 104 sdfs_init(&sdfs, P8_5, P8_6, P8_3, P8_4, "sd"); 86 105 87 SD_begin(); 88 89 FIL fd; 90 UINT rlen = 0; 91 memset(&fd, 0, sizeof(fd)); 92 if (f_open(&fd, "1:/httpd-fs.bin", FA_OPEN_EXISTING | FA_READ) == FR_OK) { 93 f_read(&fd, RamDisk, SZ_RAMDISK * 1024, &rlen); 94 f_close(&fd); 95 if (romdisk_init()) 96 result = 0; 97 } 98 106 result = SD_begin() ? 0 : -1; 99 107 if (result == 0) { 100 syslog(LOG_NOTICE, "ramdisk ok!");108 ntstdio_printf(&ntstdio, "SD card (1:) OK!\n"); 101 109 } 102 110 else { 103 syslog(LOG_NOTICE, "ramdisk ng!"); 104 } 105 106 arduino_init(); 111 ntstdio_printf(&ntstdio, "SD card (1:) NG!\n"); 112 } 113 sta_cyc(SDFS_CYC); 114 115 if (romdisk_init()) 116 result = 0; 117 118 if (result == 0) { 119 ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n"); 120 } 121 else { 122 ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n"); 123 } 124 125 /* uploadãã£ã¬ã¯ããªã使ãã¦ãã */ 126 f_mkdir("1:/upload"); 127 128 serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV); 107 129 108 130 return result; 131 } 132 133 void sys_init(void) 134 { 135 sys_tlsf = tlsf_create(&__HeapBase); 136 if (sys_tlsf == NULL) 137 return; 138 139 sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((size_t)&__HeapLimit - (size_t)&__HeapBase) - tlsf_size()); 140 } 141 142 void sys_fini(void) 143 { 144 tlsf_destroy(sys_tlsf); 145 } 146 147 void *sys_malloc(size_t size) 148 { 149 return tlsf_malloc(sys_tlsf, size); 150 } 151 152 void *sys_calloc(size_t size, size_t count) 153 { 154 void *result = tlsf_malloc(sys_tlsf, count * size); 155 memset(result, 0, count * size); 156 return result; 157 } 158 159 void *sys_realloc(void *ptr, size_t size) 160 { 161 return tlsf_realloc(sys_tlsf, ptr, size); 162 } 163 164 void sys_free(void *ptr) 165 { 166 tlsf_free(sys_tlsf, ptr); 109 167 } 110 168 … … 122 180 123 181 if ((res = f_mount(&RomDisk, "0:", 1)) != FR_OK) { 182 return false; 183 } 184 185 return true; 186 } 187 188 bool_t SD_begin() 189 { 190 DSTATUS dst; 191 FRESULT res; 192 BYTE pdrv = 1, type; 193 194 if (Sd.FatFs.fs_type != 0) 195 return true; 196 197 if ((dst = disk_initialize(pdrv)) != RES_OK) { 198 return false; 199 } 200 201 if ((dst = disk_ioctl(pdrv, MMC_GET_TYPE, &type)) != RES_OK) { 202 Sd.dst = dst; 203 Sd.type = 0; 204 } 205 else { 206 Sd.dst = RES_OK; 207 Sd.type = type; 208 } 209 210 if ((res = f_mount(&Sd.FatFs, "1:", 1)) != FR_OK) { 124 211 return false; 125 212 } … … 207 294 } 208 295 209 static int lock[TNUM_TSKID]; 210 static int stack_pos[TNUM_TSKID]; 211 212 void __malloc_lock(struct _reent *a) 213 { 214 ID tskid; 296 int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj) 297 { 298 return 1; 299 } 300 301 int ff_req_grant(_SYNC_t sobj) 302 { 215 303 ER ret; 216 int count, sp; 217 218 ret = get_tid(&tskid); 219 if (ret != E_OK) { 220 /*syslog(LOG_DEBUG, "get_tid %s", itron_strerror(ret));*/ 221 Asm("bkpt #0"); 222 } 223 224 Asm("mov %0, sp" : "=r"(sp) :); 225 if ((stack_pos[tskid - 1] == 0) || (stack_pos[tskid - 1] < sp)) 226 stack_pos[tskid - 1] = sp; 227 228 count = ++lock[tskid - 1]; 229 if (count != 1) 230 return; 231 232 ret = wai_sem(SEM_MALLOC); 233 if (ret != E_OK) { 234 /*syslog(LOG_DEBUG, "wai_sem %s", itron_strerror(ret));*/ 235 Asm("bkpt #0"); 236 } 237 } 238 239 void __malloc_unlock(struct _reent *a) 240 { 241 ID tskid; 242 ER ret; 243 int count; 244 245 ret = get_tid(&tskid); 246 if (ret != E_OK) { 247 /*syslog(LOG_DEBUG, "get_tid %s", itron_strerror(ret));*/ 248 Asm("bkpt #0"); 249 } 250 251 count = --lock[tskid - 1]; 252 if(count != 0) 253 return; 254 255 ret = sig_sem(SEM_MALLOC); 256 if (ret != E_OK) { 257 /*syslog(LOG_DEBUG, "sig_sem %s", itron_strerror(ret));*/ 258 Asm("bkpt #0"); 259 } 260 } 261 262 // Provide implementation of _sbrk (low-level dynamic memory allocation 263 // routine) for GCC_ARM which compares new heap pointer with MSP instead of 264 // SP. This make it compatible with RTX RTOS thread stacks. 265 266 // Linker defined symbol used by _sbrk to indicate where heap should start. 267 int __end__; 268 uint32_t __HeapLimit; 269 270 // Turn off the errno macro and use actual global variable instead. 271 #undef errno 272 int errno; 273 274 static unsigned char* heap = (unsigned char*)&__end__; 275 276 // Dynamic memory allocation related syscall. 277 caddr_t _sbrk(int incr) { 278 unsigned char* prev_heap = heap; 279 unsigned char* new_heap = heap + incr; 280 281 if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */ 282 errno = ENOMEM; 283 return (caddr_t)-1; 284 } 285 286 heap = new_heap; 287 return (caddr_t) prev_heap; 288 } 289 290 void reset_heap() 291 { 292 // .data 293 extern uint8_t __malloc_av_[0x408]; 294 extern uint8_t __malloc_sbrk_base[0x4]; 295 extern uint8_t __malloc_trim_threshold[0x4]; 296 // .bss 297 extern uint8_t __malloc_top_pad[0x4]; 298 extern uint8_t __malloc_current_mallinfo[0x28]; 299 extern uint8_t __malloc_max_sbrked_mem[0x4]; 300 extern uint8_t __malloc_max_total_mem[0x4]; 301 // 302 extern void *__etext; 303 extern void *__data_start__; 304 305 int offset = (int)&__etext - (int)&__data_start__; 306 307 __malloc_lock(_REENT); 308 309 memcpy(__malloc_av_, &__malloc_av_[offset], sizeof(__malloc_av_)); 310 memcpy(__malloc_sbrk_base, &__malloc_sbrk_base[offset], sizeof(__malloc_sbrk_base)); 311 memcpy(__malloc_trim_threshold, &__malloc_trim_threshold[offset], sizeof(__malloc_trim_threshold)); 312 313 memset(__malloc_top_pad, 0, sizeof(__malloc_top_pad)); 314 memset(__malloc_current_mallinfo, 0, sizeof(__malloc_current_mallinfo)); 315 memset(__malloc_max_sbrked_mem, 0, sizeof(__malloc_max_sbrked_mem)); 316 memset(__malloc_max_total_mem, 0, sizeof(__malloc_max_total_mem)); 317 318 heap = (unsigned char*)&__end__; 319 320 __malloc_unlock(_REENT); 321 } 322 323 void exit(int return_code) { 324 Asm("bkpt #0"); 325 reset_heap(); 326 ext_tsk(); 327 for(;;); 328 } 304 ret = wai_sem(SEM_FILESYSTEM); 305 return ret == E_OK; 306 } 307 308 void ff_rel_grant(_SYNC_t sobj) 309 { 310 sig_sem(SEM_FILESYSTEM); 311 } 312 313 int ff_del_syncobj(_SYNC_t sobj) 314 { 315 return 1; 316 } 317 318 void* ff_memalloc (UINT msize) 319 { 320 return sys_malloc(msize); 321 } 322 323 void ff_memfree (void* mblock) 324 { 325 sys_free(mblock); 326 } -
EcnlProtoTool/trunk/ntshell/fatfs/ffarch.cfg
r278 r279 51 51 */ 52 52 53 #include " mruby_arduino.h"53 #include "ffarch.h" 54 54 55 CRE_CYC(SDFS_CYC, { TA_NULL, { TNFY_HANDLER, 0, sdfs_cychdr }, 1000 , 0 });55 CRE_CYC(SDFS_CYC, { TA_NULL, { TNFY_HANDLER, 0, sdfs_cychdr }, 1000000, 0 }); 56 56 57 57 CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 }); -
EcnlProtoTool/trunk/ntshell/fatfs/ffarch.h
r278 r279 54 54 55 55 int mruby_arduino_init(); 56 void reset_heap();57 56 void sdfs_cychdr(intptr_t exinf); 58 57 -
EcnlProtoTool/trunk/ntshell/fatfs/ffconf.h
r278 r279 62 62 /---------------------------------------------------------------------------*/ 63 63 64 #define _CODE_PAGE 43764 #define _CODE_PAGE 65001 65 65 /* This option specifies the OEM code page to be used on the target system. 66 66 / Incorrect setting of the code page can cause a file open failure. … … 91 91 92 92 93 #define _USE_LFN 193 #define _USE_LFN 3 94 94 #define _MAX_LFN 255 95 95 /* The _USE_LFN option switches the LFN feature. … … 227 227 228 228 229 #define _FS_REENTRANT 0229 #define _FS_REENTRANT 1 230 230 #define _FS_TIMEOUT 1000 231 #define _SYNC_t HANDLE231 #define _SYNC_t unsigned int 232 232 /* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs 233 233 / module itself. Note that regardless of this option, file access to different -
EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c
r270 r279 60 60 #include "kernel_cfg.h" 61 61 #include "syssvc/syslog.h" 62 #include " arduino.h"62 #include "ntstdio.h" 63 63 64 64 #ifndef _MSC_VER … … 96 96 fn = fno.fname; 97 97 if (fno.fattrib & AM_DIR) { 98 sprintf(&path[i], "0:/%s", fn);98 ntstdio_sprintf(&path[i], "0:/%s", fn); 99 99 res = scan_files(path, size); 100 100 if (res != FR_OK) break; … … 112 112 /*-----------------------------------------------------------------------------------*/ 113 113 int 114 httpd_fs_open _ul(char *name, int len, struct httpd_fs_file *file)114 httpd_fs_open(char *name, int len, struct httpd_fs_file *file) 115 115 { 116 116 FRESULT res; … … 157 157 } 158 158 159 int 160 httpd_fs_open(char *name, int len, struct httpd_fs_file *file) 161 { 162 int result; 163 164 wai_sem(SEM_FILESYSTEM); 165 166 result = httpd_fs_open_ul(name, len, file); 167 168 sig_sem(SEM_FILESYSTEM); 169 170 return result; 171 } 172 /*-----------------------------------------------------------------------------------*/ 173 int 174 httpd_fs_create_ul(char *name, struct httpd_fs_file *file) 159 /*-----------------------------------------------------------------------------------*/ 160 int 161 httpd_fs_create(char *name, struct httpd_fs_file *file) 175 162 { 176 163 FRESULT res; … … 196 183 } 197 184 198 int 199 httpd_fs_create(char *name, struct httpd_fs_file *file) 200 { 201 int result; 202 203 wai_sem(SEM_FILESYSTEM); 204 205 result = httpd_fs_create_ul(name, file); 206 207 sig_sem(SEM_FILESYSTEM); 208 209 return result; 210 } 211 /*-----------------------------------------------------------------------------------*/ 212 int 213 httpd_fs_read_ul(struct httpd_fs_file *file, void *dst, int len) 185 /*-----------------------------------------------------------------------------------*/ 186 int 187 httpd_fs_read(struct httpd_fs_file *file, void *dst, int len) 214 188 { 215 189 FRESULT ret; … … 236 210 } 237 211 238 int 239 httpd_fs_read(struct httpd_fs_file *file, void *dst, int len) 240 { 241 int result; 242 243 wai_sem(SEM_FILESYSTEM); 244 245 result = httpd_fs_read_ul(file, dst, len); 246 247 sig_sem(SEM_FILESYSTEM); 248 249 return result; 250 } 251 /*-----------------------------------------------------------------------------------*/ 252 int 253 httpd_fs_write_ul(struct httpd_fs_file *file, const void *src, int len) 212 /*-----------------------------------------------------------------------------------*/ 213 int 214 httpd_fs_write(struct httpd_fs_file *file, const void *src, int len) 254 215 { 255 216 FRESULT ret; … … 279 240 } 280 241 281 int 282 httpd_fs_write(struct httpd_fs_file *file, const void *src, int len) 283 { 284 int result; 285 286 wai_sem(SEM_FILESYSTEM); 287 288 result = httpd_fs_write_ul(file, src, len); 289 290 sig_sem(SEM_FILESYSTEM); 291 292 return result; 293 } 294 /*-----------------------------------------------------------------------------------*/ 295 int httpd_fs_close_ul(struct httpd_fs_file *file) 242 /*-----------------------------------------------------------------------------------*/ 243 int httpd_fs_close(struct httpd_fs_file *file) 296 244 { 297 245 FRESULT ret; … … 307 255 return 1; 308 256 } 309 310 int httpd_fs_close(struct httpd_fs_file *file)311 {312 int result;313 314 wai_sem(SEM_FILESYSTEM);315 316 result = httpd_fs_close_ul(file);317 318 sig_sem(SEM_FILESYSTEM);319 320 return result;321 } -
EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.h
r270 r279 4 4 * Copyright (C) 2017 Cores Co., Ltd. Japan 5 5 * 6 * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF 7 * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü 8 * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD 9 * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì 10 * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[ 11 * XR[hÉÜÜêĢ鱯D 12 * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg 13 * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL 14 gip 15 * Ò}j 16 AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL 17 * Ì³ÛØKèðfÚ·é±ÆD 18 * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg 19 * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·± 20 * ÆD 21 * (a) Äzzɺ¤hL 22 gipÒ}j 23 AÈÇjÉCãLÌ 24 * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD 25 * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ 26 * ñ·é±ÆD 27 * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹ 28 * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD 29 * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé 30 * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð 31 * ÆÓ·é±ÆD 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 責ãããã¨ï¼ 32 42 * 33 * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨ 34 * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI 35 * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF 36 * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC» 37 * ÌÓCðíÈ¢D 43 * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è 44 ã 45 * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç 46 * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ 47 * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ã 48 * ã®è²¬ä»»ãè² ããªãï¼ 38 49 * 39 50 * @(#) $Id$ -
EcnlProtoTool/trunk/ntshell/webserver/httpd.c
r270 r279 54 54 #include <string.h> 55 55 #include <stdlib.h> 56 #include "kernel_cfg.h" 57 #include "tinet_cfg.h" 56 58 #include "syssvc/syslog.h" 57 59 #include "http-strings.h" 58 60 #include "netinet/in.h" 59 #include "arduino.h" 61 #include "netinet/in_var.h" 62 #include "httpd.h" 63 #include "httpd-fs.h" 64 #include "http-strings.h" 65 #include "base64.h" 66 #include "sha1.h" 67 #include "ntstdio.h" 60 68 61 69 #define TRUE 1 62 70 #define FALSE 0 71 72 extern ntstdio_t ntstdio; 73 SYSTIM httpd_time; 74 struct httpd_state *uploding; 75 extern char command[256]; 76 77 extern int execute_command(int wait); 78 79 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */ 80 uint8_t tcp_swbuf1[TCP_SWBUF_SIZE]; 81 uint8_t tcp_rwbuf1[TCP_RWBUF_SIZE]; 82 uint8_t tcp_swbuf2[TCP_SWBUF_SIZE]; 83 uint8_t tcp_rwbuf2[TCP_RWBUF_SIZE]; 84 85 #define ISO_nl 0x0a 86 #define ISO_space 0x20 87 #define ISO_bang 0x21 88 #define ISO_percent 0x25 89 #define ISO_period 0x2e 90 #define ISO_slash 0x2f 91 #define ISO_colon 0x3a 92 93 struct httpd_state httpd_state[2] = { 94 { HTTPD1_TASK, TCP_CEPID1 }, 95 { HTTPD2_TASK, TCP_CEPID2 }, 96 }; 63 97 64 98 #ifndef _MSC_VER … … 147 181 return ncpy; 148 182 } 149 150 extern struct httpd_state *uploding;151 183 152 184 int websvr_message_begin(http_parser *p) … … 306 338 ã¯SDã«ã¼ã 307 339 s->filename[0] = '1'; 308 syslog(LOG_NOTICE, "create: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);340 ntstdio_printf(&ntstdio, "create: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 309 341 if (!httpd_fs_create(s->filename, &s->file)) { 310 342 goto error; … … 314 346 } 315 347 else if (strcmp(s->filename, uploding->filename) == 0) { 316 syslog(LOG_NOTICE, "collision: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);348 ntstdio_printf(&ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 317 349 goto error; 318 350 } … … 359 391 360 392 if (s->message.body_is_final) { 361 syslog(LOG_NOTICE, "close: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);393 ntstdio_printf(&ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 362 394 httpd_fs_close(&s->file); 363 395 memset(&s->file, 0, sizeof(s->file)); 364 396 365 strcpy_s(RubyFilename, sizeof(RubyFilename), s->filename); 397 strcpy_s(command, sizeof(command), "mruby -b "); 398 strcat_s(command, sizeof(command), s->filename); 366 399 s->reset = 1; 367 400 … … 413 446 websvr_message_complete, 414 447 }; 448 449 /* 450 * ãããã¯ã¼ã¯å±¤ã®é¸æ 451 */ 452 453 #ifdef SUPPORT_INET6 454 455 #define TCP_ACP_CEP(c,r,d,t) tcp6_acp_cep(c,r,d,t) 456 #define IP2STR(s,a) ipv62str(s,a) 457 458 #else /* of #ifdef SUPPORT_INET6 */ 459 460 #ifdef SUPPORT_INET4 461 462 #define TCP_ACP_CEP(c,r,d,t) tcp_acp_cep(c,r,d,t) 463 #define IP2STR(s,a) ip2str(s,a) 464 465 #endif /* of #ifdef SUPPORT_INET4 */ 466 467 #endif /* of #ifdef SUPPORT_INET6 */ 468 469 struct httpd_state *get_httpd(ID cepid) 470 { 471 for (int i = 0; i < 2; i++) { 472 if (httpd_state[i].cepid != cepid) 473 continue; 474 475 return &httpd_state[i]; 476 } 477 return NULL; 478 } 479 480 struct websocket *websocket_getws(ID wbsid) 481 { 482 for (int i = 0; i < 2; i++) { 483 if (httpd_state[i].websocket.wbsid != wbsid) 484 continue; 485 486 return &httpd_state[i].websocket; 487 } 488 return NULL; 489 } 490 491 void send_file(struct httpd_state *s) 492 { 493 char *buf; 494 int len, slen; 495 496 while (s->file.len > 0) { 497 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 498 if (slen < 0) { 499 syslog(LOG_ERROR, "send_file#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 500 s->state = STATE_CLOSING; 501 break; 502 } 503 if (slen == 0) 504 return; 505 506 len = s->file.len; 507 if (len > slen) 508 len = slen; 509 510 len = httpd_fs_read(&s->file, buf, len); 511 if (len <= 0) { 512 syslog(LOG_ERROR, "send_file#httpd_fs_read(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, len); 513 break; 514 } 515 516 s->file.len -= len; 517 s->file.pos += len; 518 519 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 520 syslog(LOG_ERROR, "send_file#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 521 s->state = STATE_CLOSING; 522 break; 523 } 524 } 525 526 ntstdio_printf(&ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 527 httpd_fs_close(&s->file); 528 s->file.len = 0; 529 s->file.pos = 0; 530 531 s->out.state = OUT_STATE_SEND_END; 532 } 533 534 void send_data(struct httpd_state *s) 535 { 536 char *buf; 537 int len, slen; 538 539 while (s->response_len > 0) { 540 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 541 if (slen < 0) { 542 syslog(LOG_ERROR, "send_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 543 s->state = STATE_CLOSING; 544 break; 545 } 546 if (slen == 0) 547 return; 548 549 len = s->response_len; 550 if (len > slen) 551 len = slen; 552 553 memcpy(buf, &s->response_body[s->response_pos], len); 554 555 s->response_len -= len; 556 s->response_pos += len; 557 558 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 559 syslog(LOG_ERROR, "send_data#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 560 s->state = STATE_CLOSING; 561 break; 562 } 563 } 564 565 s->response_body = NULL; 566 s->response_len = 0; 567 s->response_pos = 0; 568 569 s->out.state = OUT_STATE_SEND_END; 570 } 571 572 void send_headers(struct httpd_state *s, const char *statushdr) 573 { 574 int len; 575 char *ptr; 576 577 len = strlen(statushdr); 578 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 579 580 if ((s->filename[0] == '0') && (s->file.len > 0)) { 581 len = sizeof(http_content_encoding_gzip) - 1; 582 tcp_snd_dat(s->cepid, (void *)http_content_encoding_gzip, len, TMO_FEVR); 583 } 584 585 if (s->file.redirect) { 586 len = sizeof(http_location) - 1; 587 tcp_snd_dat(s->cepid, (void *)http_location, len, TMO_FEVR); 588 if (s->filename[0] == '1') { 589 len = 2; 590 tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR); 591 } 592 len = strlen(s->filename); 593 tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR); 594 if (s->query != NULL) { 595 tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR); 596 len = strlen(s->query); 597 tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR); 598 } 599 len = 2; 600 tcp_snd_dat(s->cepid, "\r", len, TMO_FEVR); 601 } 602 603 ptr = strrchr(s->filename, ISO_period); 604 if (ptr == NULL) { 605 len = sizeof(http_content_type_binary) - 1; 606 tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR); 607 } 608 else if (strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 || 609 strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) { 610 len = sizeof(http_content_type_html) - 1; 611 tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR); 612 } 613 else if (strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) { 614 len = sizeof(http_content_type_css) - 1; 615 tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR); 616 } 617 else if (strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) { 618 len = sizeof(http_content_type_js) - 1; 619 tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR); 620 } 621 else if (strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) { 622 len = sizeof(http_content_type_json) - 1; 623 tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR); 624 } 625 else if (strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) { 626 len = sizeof(http_content_type_png) - 1; 627 tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR); 628 } 629 else if (strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) { 630 len = sizeof(http_content_type_gif) - 1; 631 tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR); 632 } 633 else if (strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) { 634 len = sizeof(http_content_type_jpg) - 1; 635 tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR); 636 } 637 else if (strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) { 638 len = sizeof(http_content_type_svg) - 1; 639 tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR); 640 } 641 else if (strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) { 642 len = sizeof(http_content_type_text) - 1; 643 tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR); 644 } 645 else if (strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) { 646 len = sizeof(http_content_type_eot) - 1; 647 tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR); 648 } 649 else if (strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) { 650 len = sizeof(http_content_type_ttf) - 1; 651 tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR); 652 } 653 else if (strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) { 654 len = sizeof(http_content_type_woff) - 1; 655 tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR); 656 } 657 else if (strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) { 658 len = sizeof(http_content_type_woff2) - 1; 659 tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR); 660 } 661 else if (strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) { 662 len = sizeof(http_content_type_ico) - 1; 663 tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR); 664 } 665 else { 666 len = sizeof(http_content_type_plain) - 1; 667 tcp_snd_dat(s->cepid, (void *)http_content_type_plain, len, TMO_FEVR); 668 } 669 670 if (s->file.len > 0) { 671 len = sizeof(http_content_length) - 1; 672 tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR); 673 ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len); 674 tcp_snd_dat(s->cepid, (void *)s->temp, strlen(s->temp), TMO_FEVR); 675 } 676 677 if (s->message.should_keep_alive && s->reset == 0) { 678 len = sizeof(http_connection_keep_alive) - 1; 679 tcp_snd_dat(s->cepid, (void *)http_connection_keep_alive, len, TMO_FEVR); 680 } 681 else { 682 len = sizeof(http_connection_close) - 1; 683 tcp_snd_dat(s->cepid, (void *)http_connection_close, len, TMO_FEVR); 684 } 685 686 tcp_snd_dat(s->cepid, (void *)http_crnl, 2, TMO_FEVR); 687 688 if (s->filename != NULL) { 689 s->out.state = OUT_STATE_SEND_FILE; 690 } 691 else { 692 s->out.state = OUT_STATE_SEND_DATA; 693 } 694 } 695 696 void handle_output(struct httpd_state *s) 697 { 698 s->out.wait = false; 699 700 switch (s->out.state) { 701 case OUT_STATE_WAIT_REQUEST: 702 s->out.wait = true; 703 break; 704 case OUT_STATE_OPEN_GET_FILE: 705 ntstdio_printf(&ntstdio, "open: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 706 if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) { 707 s->filename = NULL; 708 s->response_body = http_content_404; 709 s->response_pos = 0; 710 s->response_len = sizeof(http_content_403) - 1; 711 s->out.statushdr = http_header_404; 712 } 713 else { 714 s->out.statushdr = s->file.redirect ? http_header_301 : http_header_200; 715 } 716 s->out.state = OUT_STATE_SEND_HEADER; 717 break; 718 case OUT_STATE_WAIT_POST_BODY: 719 s->out.wait = true; 720 break; 721 case OUT_STATE_BODY_RECEIVED: 722 s->out.statushdr = http_header_200; 723 s->out.state = OUT_STATE_SEND_HEADER; 724 break; 725 case OUT_STATE_SEND_HEADER: 726 send_headers(s, s->out.statushdr); 727 break; 728 case OUT_STATE_SEND_FILE: 729 send_file(s); 730 break; 731 case OUT_STATE_SEND_DATA: 732 send_data(s); 733 break; 734 case OUT_STATE_SEND_END: 735 s->out.wait = true; 736 if (s->message.should_keep_alive && s->reset == 0) { 737 s->out.state = OUT_STATE_WAIT_REQUEST; 738 } 739 else { 740 s->state = STATE_CLOSING; 741 } 742 break; 743 } 744 } 745 746 void send_ws_headers(struct httpd_state *s, const char *statushdr) 747 { 748 int len; 749 750 len = strlen(statushdr); 751 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 752 753 len = sizeof(http_upgrade) - 1; 754 tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR); 755 len = strlen(s->message.upgrade); 756 tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR); 757 len = sizeof(http_crnl) - 1; 758 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 759 760 len = sizeof(http_connection) - 1; 761 tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR); 762 len = strlen(s->message.connection); 763 tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR); 764 len = sizeof(http_crnl) - 1; 765 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 766 767 len = sizeof(http_sec_websocket_accept) - 1; 768 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR); 769 len = strlen(s->message.response_key); 770 tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR); 771 len = sizeof(http_crnl) - 1; 772 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 773 774 len = sizeof(http_sec_websocket_protocol) - 1; 775 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR); 776 len = strlen(s->message.sec_websocket_protocol); 777 tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR); 778 len = sizeof(http_crnl) - 1; 779 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 780 781 len = sizeof(http_crnl) - 1; 782 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 783 } 784 785 void send_ws_data(struct httpd_state *s) 786 { 787 char *buf; 788 int slen; 789 790 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 791 if (slen < 0) { 792 syslog(LOG_ERROR, "send_ws_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 793 return; 794 } 795 796 websocket_output(&s->websocket, buf, slen); 797 } 798 799 void handle_ws_output(struct httpd_state *s) 800 { 801 char shaHash[20]; 802 SHA_CTX sha1; 803 int len; 804 805 strlncat(s->message.response_key, sizeof(s->message.response_key), 806 s->message.sec_websocket_key, sizeof(s->message.sec_websocket_key)); 807 len = strlncat(s->message.response_key, sizeof(s->message.response_key), 808 http_websocket_guid, sizeof(http_websocket_guid)); 809 memset(shaHash, 0, sizeof(shaHash)); 810 SHA1_Init(&sha1); 811 SHA1_Update(&sha1, (sha1_byte *)s->message.response_key, len); 812 SHA1_Final((sha1_byte *)shaHash, &sha1); 813 base64_encode((unsigned char *)s->message.response_key, 814 sizeof(s->message.response_key), (unsigned char *)shaHash, sizeof(shaHash)); 815 816 send_ws_headers(s, http_header_101); 817 818 s->message.response_key[0] = '\0'; 819 820 do { 821 while (!websocket_newdata(&s->websocket)) 822 slp_tsk(); 823 824 send_ws_data(s); 825 } while ((s->state == STATE_CONNECTED) && (!s->close_req)); 826 s->state = STATE_DISCONNECTED; 827 websocket_destroy(&s->websocket); 828 s->close_req = 0; 829 830 s->state = STATE_CLOSING; 831 } 832 833 void handle_input(struct httpd_state *s) 834 { 835 size_t done; 836 int len; 837 838 s->in.wait = false; 839 840 switch (s->in.state) { 841 case IN_STATE_START: 842 http_parser_init(&s->parser, HTTP_REQUEST); 843 s->in.state = IN_STATE_REQUEST; 844 break; 845 case IN_STATE_REQUEST: 846 case IN_STATE_RESPONSE: 847 case IN_STATE_UPLOAD: 848 if ((len = tcp_rcv_buf(s->cepid, (void **)&s->in.data, TMO_POL)) <= 0) { 849 if ((len == E_TMOUT) || (len == 0)) { 850 // 3ç§ã¯å¾ 851 㤠852 //if (httpd_time - s->in.timer < 30000000) { 853 s->in.wait = true; 854 break; 855 //} 856 } 857 syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 858 uploding = NULL; 859 s->state = STATE_CLOSING; 860 return; 861 } 862 done = http_parser_execute(&s->parser, &websvr_settings, s->in.data, len); 863 tcp_rel_buf(s->cepid, done); 864 if (s->parser.http_errno != HPE_OK) { 865 syslog(LOG_ERROR, "http_parser error %s.%d => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno); 866 uploding = NULL; 867 s->state = STATE_CLOSING; 868 return; 869 } 870 871 s->parse_pos = done; 872 s->parse_len = len - done; 873 break; 874 case IN_STATE_UPLOAD_WAIT: 875 if (uploding != NULL) { 876 s->in.wait = true; 877 } 878 else { 879 uploding = s; 880 s->in.state = IN_STATE_UPLOAD; 881 } 882 break; 883 case IN_STATE_WEBSOCKET: 884 if (s->parse_len <= 0) { 885 if ((len = tcp_rcv_buf(s->cepid, (void **)&s->in.data, TMO_POL)) <= 0) { 886 if ((len == E_TMOUT) || (len == 0)) { 887 s->in.wait = true; 888 break; 889 } 890 syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 891 s->state = STATE_CLOSING; 892 break; 893 } 894 895 s->parse_pos = 0; 896 s->parse_len = len; 897 } 898 else 899 len = s->parse_len; 900 done = websocket_input(&s->websocket, (void *)s->in.data, s->parse_len); 901 tcp_rel_buf(s->cepid, done); 902 if ((done != 0) || (s->websocket.rstate.opecode == connection_close)) { 903 s->close_req = 1; 904 s->state = STATE_CLOSING; 905 break; 906 } 907 s->parse_pos = done; 908 s->parse_len -= done; 909 break; 910 case IN_STATE_END: 911 s->in.wait = true; 912 break; 913 default: 914 s->state = STATE_CLOSING; 915 break; 916 } 917 } 918 919 /* 920 * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ° 921 */ 922 ER 923 callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk) 924 { 925 struct httpd_state *s = get_httpd(cepid); 926 927 if (s == NULL) 928 ntstdio_printf(&ntstdio, "callback_nblk_tcp(%d, %d)\n", fncd, cepid); 929 else 930 ntstdio_printf(&ntstdio, "callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno); 931 932 return E_PAR; 933 } 934 935 /* 936 * HTTPãµã¼ãã¼ã¿ã¹ã¯ 937 */ 938 void httpd_task(intptr_t exinf) 939 { 940 ER ret, ret2; 941 struct httpd_state *s = &httpd_state[exinf]; 942 943 for (;;) { 944 ret2 = get_tim(&httpd_time); 945 if (ret2 != E_OK) { 946 syslog(LOG_ERROR, "get_tim"); 947 return; 948 } 949 950 switch (s->state) { 951 case STATE_DISCONNECTED: 952 memset(&s->dst, 0, sizeof(s->dst)); 953 if ((ret = TCP_ACP_CEP(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) { 954 syslog(LOG_ERROR, "tcp_acp_cep(%d) => %d", s->cepid, ret); 955 tslp_tsk(100); // TODO 956 s->state = STATE_CLOSING; 957 break; 958 } 959 IP2STR(s->addr, &((T_IPV4EP *)s->dst)->ipaddr); 960 ntstdio_printf(&ntstdio, "connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 961 memset(&s->in, 0, sizeof(s->in)); 962 memset(&s->out, 0, sizeof(s->out)); 963 s->in.timer = httpd_time; 964 s->state = STATE_CONNECTED; 965 break; 966 case STATE_CONNECTED: 967 handle_input(s); 968 handle_output(s); 969 break; 970 case STATE_WEBSOCKET: 971 handle_input(s); 972 handle_ws_output(s); 973 break; 974 case STATE_CLOSING: 975 ntstdio_printf(&ntstdio, "close: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 976 tcp_sht_cep(s->cepid); 977 tcp_cls_cep(s->cepid, TMO_FEVR); 978 979 if (s->reset) { 980 s->reset = 0; 981 s->state = STATE_RESET; 982 } 983 else { 984 s->state = STATE_DISCONNECTED; 985 } 986 break; 987 case STATE_RESET: 988 execute_command(0); 989 s->state = STATE_DISCONNECTED; 990 break; 991 } 992 993 if (s->in.wait && s->out.wait) { 994 tslp_tsk(100); 995 } 996 } 997 } -
EcnlProtoTool/trunk/ntshell/webserver/httpd.h
r270 r279 4 4 * Copyright (C) 2017 Cores Co., Ltd. Japan 5 5 * 6 * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF 7 * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü 8 * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD 9 * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì 10 * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[ 11 * XR[hÉÜÜêĢ鱯D 12 * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg 13 * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL 14 gip 15 * Ò}j 16 AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL 17 * Ì³ÛØKèðfÚ·é±ÆD 18 * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg 19 * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·± 20 * ÆD 21 * (a) Äzzɺ¤hL 22 gipÒ}j 23 AÈÇjÉCãLÌ 24 * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD 25 * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ 26 * ñ·é±ÆD 27 * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹ 28 * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD 29 * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé 30 * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð 31 * ÆÓ·é±ÆD 32 * 33 * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨ 34 * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI 35 * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF 36 * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC» 37 * ÌÓCðíÈ¢D 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 * ã®è²¬ä»»ãè² ããªãï¼ 38 49 * 39 50 * @(#) $Id$ … … 43 54 #define __HTTPD_H__ 44 55 56 /* 57 * ã¿ã¼ã²ããä¾åã®å®ç¾© 58 */ 59 #include <kernel.h> 45 60 #include "httpd-fs.h" 46 61 #include "http_parser.h" 47 62 #include "websocket.h" 63 64 /* 65 * åã¿ã¹ã¯ã®åªå 66 度ã®å®ç¾© 67 */ 68 69 #define HTTPD_PRIORITY 5 /* HTTPãµã¼ãã¼ã¿ã¹ã¯ã®åªå 70 度 */ 71 72 #define HTTPD_STACK_SIZE 1024 /* HTTPãµã¼ãã¼ã¿ã¹ã¯ã®ã¹ã¿ãã¯é åã®ãµã¤ãº */ 73 74 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ãµã¤ãº */ 75 76 #define TCP_SWBUF_SIZE 512 77 #define TCP_RWBUF_SIZE 512 78 79 /* 80 * 颿°ã®ãããã¿ã¤ãå®£è¨ 81 */ 82 #ifndef TOPPERS_MACRO_ONLY 83 84 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */ 85 86 extern uint8_t tcp_swbuf1[]; 87 extern uint8_t tcp_rwbuf1[]; 88 extern uint8_t tcp_swbuf2[]; 89 extern uint8_t tcp_rwbuf2[]; 90 91 /* HTTPãµã¼ãã¼ã¿ã¹ã¯ */ 92 extern void httpd_task(intptr_t exinf); 48 93 49 94 #define MAX_ELEMENT_SIZE 256 … … 81 126 82 127 typedef enum httpd_state_t { 83 STATE_DISCONNECTED, /* Øf*/84 STATE_CONNECTED, /* Ú±*/85 STATE_WEBSOCKET, /* WebSocket ÊM*/86 STATE_CLOSING, /* Øf*/87 STATE_RESET, /* mruby N®Ì½ßÌZbg*/128 STATE_DISCONNECTED, /* åæä¸ */ 129 STATE_CONNECTED, /* æ¥ç¶ä¸ */ 130 STATE_WEBSOCKET, /* WebSocketéä¿¡ä¸ */ 131 STATE_CLOSING, /* åæå¦çä¸ */ 132 STATE_RESET, /* mrubyèµ·åã®ããã®ãªã»ãã */ 88 133 } httpd_state_t; 89 134 … … 155 200 #define get_context(p) (struct httpd_state *)((intptr_t)p - (intptr_t)&((struct httpd_state *)0)->parser) 156 201 202 /* 203 * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ° 204 */ 205 extern ER callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk); 206 207 #endif /* TOPPERS_MACRO_ONLY */ 208 157 209 #endif /* __HTTPD_H__ */ -
EcnlProtoTool/trunk/ntshell/webserver/websocket.c
r270 r279 57 57 #include "syssvc/syslog.h" 58 58 59 static ECN_FBS_ID cur_out_msg;59 static WS_FBS_ID cur_out_msg; 60 60 61 61 void websocket_init(struct websocket *ws, ID wbsid) … … 69 69 if ((cur_out_msg.ptr != NULL) && (((ID *)cur_out_msg.ptr->_gap)[0] == ws->wbsid)) 70 70 { 71 _ ecn_fbs_del(cur_out_msg);71 _ws_fbs_del(cur_out_msg); 72 72 memset(&cur_out_msg, 0, sizeof(cur_out_msg)); 73 73 } 74 74 75 75 if (ws->cur_in_msg.ptr != NULL) { 76 _ ecn_fbs_del(ws->cur_in_msg);76 _ws_fbs_del(ws->cur_in_msg); 77 77 memset(&ws->cur_in_msg, 0, sizeof(ws->cur_in_msg)); 78 78 } … … 136 136 } 137 137 else { 138 _ ecn_fbs_cre(1, &ws->cur_in_msg);138 _ws_fbs_cre(1, &ws->cur_in_msg); 139 139 s->state++; 140 140 } … … 143 143 default: 144 144 if(ws->cur_in_msg.ptr != NULL) 145 _ ecn_fbs_poke(ws->cur_in_msg, s->data_pos, *pos ^ s->masking_key[s->data_pos % 4]);145 _ws_fbs_poke(ws->cur_in_msg, s->data_pos, *pos ^ s->masking_key[s->data_pos % 4]); 146 146 147 147 s->data_pos++; … … 152 152 if (ws->cur_in_msg.ptr != NULL) { 153 153 ((ID *)ws->cur_in_msg.ptr->_gap)[0] = ws->wbsid; 154 ret = psnd_dtq( ecn_api_mailboxid, (intptr_t)ws->cur_in_msg.ptr);154 ret = psnd_dtq(ws_api_mailboxid, (intptr_t)ws->cur_in_msg.ptr); 155 155 if (ret != E_OK) { 156 syslog(LOG_WARNING, "websocket_input() : psnd_dtq(%d) result = %d", ecn_api_mailboxid, ret);157 _ ecn_fbs_del(ws->cur_in_msg);156 syslog(LOG_WARNING, "websocket_input() : psnd_dtq(%d) result = %d", ws_api_mailboxid, ret); 157 _ws_fbs_del(ws->cur_in_msg); 158 158 } 159 159 } … … 172 172 struct websocket *mws; 173 173 ER ret; 174 ECN_FBS_ID data;174 WS_FBS_ID data; 175 175 ID wbsid; 176 176 … … 196 196 break; 197 197 198 _ ecn_fbs_del(cur_out_msg);198 _ws_fbs_del(cur_out_msg); 199 199 } 200 200 … … 217 217 return (intptr_t)pos - (intptr_t)data; 218 218 219 s->payload_len = _ ecn_fbs_get_datalen(cur_out_msg);219 s->payload_len = _ws_fbs_get_datalen(cur_out_msg); 220 220 if(s->payload_len == 0){ 221 221 goto next; … … 281 281 // Payload buffer 282 282 default: 283 *pos = _ ecn_fbs_peek(cur_out_msg, s->data_pos) ^ s->masking_key[s->data_pos % 4];283 *pos = _ws_fbs_peek(cur_out_msg, s->data_pos) ^ s->masking_key[s->data_pos % 4]; 284 284 285 285 s->data_pos++; … … 289 289 break; 290 290 next: 291 _ ecn_fbs_del(cur_out_msg);291 _ws_fbs_del(cur_out_msg); 292 292 memset(&cur_out_msg, 0, sizeof(cur_out_msg)); 293 293 s->state = 0; -
EcnlProtoTool/trunk/ntshell/webserver/websocket.h
r270 r279 58 58 #include "t_stddef.h" 59 59 60 #define NUM_ECHONET_MEMPOOL_BLOCK (60) /* 黿ç¨ã¡ã¢ãªãããã¯ã®æ° */ 61 #define ECHONET_MEMPOOL_BLOCK_SIZE (256) /* 黿ç¨ã¡ã¢ãªãããã¯ã®ãµã¤ãº */ 60 #define NUM_WEBSOCKET_MBXID 2 62 61 63 /* T_EDATA管çé åãµã¤ãº */ 64 # define DEF_ECN_EDT_HDR_LEN (sizeof(intptr_t))62 #ifndef TOPPERS_MACRO_ONLY 63 #include "websocket_fbs.h" 65 64 66 /* 管çé åãµã¤ãº(64byte - sizeof(T_MSG)) */ 67 /* #define DEF_ECN_FBS_LIB_HDR_LEN ((ECHONET_MEMPOOL_BLOCK_SIZE + sizeof(int) - 1)>> 2) // */ 68 #define DEF_ECN_FBS_LIB_HDR_LEN (64 - DEF_ECN_EDT_HDR_LEN) 69 70 /* 管çé åãå«ããããã¯ã«ä¿æãããã¼ã¿ãµã¤ãº */ 71 #define DEF_ECN_FBS_FST_DAT_LEN (64) 72 73 /* ãªã³ã¯ãã¤ã³ã¿é 74 åã®ãµã¤ãº(byte) */ 75 #define DEF_ECN_FBS_LNK_LEN (ECHONET_MEMPOOL_BLOCK_SIZE - DEF_ECN_EDT_HDR_LEN - DEF_ECN_FBS_LIB_HDR_LEN - DEF_ECN_FBS_FST_DAT_LEN) 76 77 /* åºå®é·ãããã¡æå¤§ãµã¤ãº */ 78 #define DEF_ECN_FBS_BUF_MAXLEN ((DEF_ECN_FBS_LNK_LEN / sizeof(void *)) * ECHONET_MEMPOOL_BLOCK_SIZE + DEF_ECN_FBS_FST_DAT_LEN) 79 80 /* åè¦ç´ ãããã¡ã®ãµã¤ãº */ 81 #define DEF_ECN_FBS_SUB_BUF_LEN ECHONET_MEMPOOL_BLOCK_SIZE 82 83 /* ãªã³ã¯ãã¤ã³ã¿é 84 åã«åæããããåè¦ç´ ãããã¡ */ 85 typedef struct { 86 uint8_t payload[ECHONET_MEMPOOL_BLOCK_SIZE]; 87 } T_ECN_SUB_BLK; 88 89 /* ãªã³ã¯ãã¤ã³ã¿é 90 å */ 91 typedef union { 92 T_ECN_SUB_BLK *p_sub[DEF_ECN_FBS_LNK_LEN / sizeof(T_ECN_SUB_BLK *)]; 93 uint8_t bin[DEF_ECN_FBS_LNK_LEN]; 94 } T_ECN_FBS_LNK; 95 96 /* 管çé å(64byte - sizeof(T_MSG)) */ 97 typedef struct { 98 uint16_t length; /* ã¡ãã»ã¼ã¸é· */ 99 uint16_t type; /* ã¡ãã»ã¼ã¸ã¿ã¤ã */ 100 union { 101 ID mbxid; /* éä¿¡å 102 ã¡ã¼ã«ããã¯ã¹IDï¼å 103 é¨ã¡ãã»ã¼ã¸ï¼ */ 104 }sender; 105 union { 106 ID mbxid; /* éä¿¡å 107 ã¡ã¼ã«ããã¯ã¹IDï¼å 108 é¨ã¡ãã»ã¼ã¸ï¼ */ 109 }target; 110 union { 111 ID mbxid; /* è¿ä¿¡å 112 ã¡ã¼ã«ããã¯ã¹IDï¼å 113 é¨ã¡ãã»ã¼ã¸ï¼ */ 114 }reply; 115 116 int rd; /* èªã¿åããããæ 117 å ± */ 118 int wr; /* æ¸ãè¾¼ã¿ãããæ 119 å ± */ 120 } T_ECN_FBS_HDR; 121 122 /* 管çé åãå«ããããã¯ã®æ§é */ 123 typedef struct { 124 uint8_t _msg[DEF_ECN_EDT_HDR_LEN]; /* T_MSG */ 125 T_ECN_FBS_HDR hdr; /* 管çé å 64byte - sizeof(T_MSG) */ 126 uint8_t _gap[DEF_ECN_FBS_LIB_HDR_LEN - sizeof(T_ECN_FBS_HDR)]; 127 T_ECN_FBS_LNK lnk; /* ãªã³ã¯ãã¤ã³ã¿é 128 å 128byte */ 129 uint8_t payload[DEF_ECN_FBS_FST_DAT_LEN]; 130 } T_ECN_FST_BLK; 131 132 /* FBS-ID */ 133 typedef struct ecn_fbs_id_strc { 134 T_ECN_FST_BLK *ptr; 135 } ECN_FBS_ID; 136 137 ER _ecn_fbs_cre(size_t fa_req_size, ECN_FBS_ID *fp_id); 138 ER _ecn_fbs_del(ECN_FBS_ID fa_id); 139 size_t _ecn_fbs_get_datalen(ECN_FBS_ID fa_id); 140 int _ecn_fbs_peek(ECN_FBS_ID fa_id, size_t fa_seek); 141 ER _ecn_fbs_poke(ECN_FBS_ID fa_id, size_t fa_seek, int fa_val); 142 143 extern ID ecn_api_mailboxid; 144 extern ID WEBSOCKET_MBXID; 65 extern ID ws_api_mailboxid; 145 66 146 67 typedef struct ws_state … … 168 89 ws_state_t wstate; 169 90 ws_state_t rstate; 170 ECN_FBS_ID cur_in_msg;91 WS_FBS_ID cur_in_msg; 171 92 }; 172 93 … … 179 100 int websocket_output(struct websocket *ws, void *data, int len); 180 101 102 #endif /* TOPPERS_MACRO_ONLY */ 103 181 104 #endif /* WEBSOCKET_H */ -
EcnlProtoTool/trunk/prototool/src/arduino.c
r278 r279 1 1 #include <arduino.h> 2 2 #include <mruby.h> 3 #include <stdlib.h> 4 #include <stdio.h> 5 #include <fcntl.h> 3 6 #include "../llbruby.h" 4 7 … … 16 19 i2c_t Wire5; 17 20 18 FATFS RomDisk;19 SD Sd;20 21 21 char ExeFilename[64]; 22 22 … … 27 27 void randomSeed(long seed) 28 28 { 29 srand(seed); 29 30 } 30 31 31 32 long arduino_random(long min, long max) 32 33 { 33 return min;34 return (long)(((double)rand() / (double)RAND_MAX) / ((double)max - (double)min)) + min; 34 35 } 35 36 … … 223 224 int EEP_fopen(FILEEEP *fp, const char *str, char mode) 224 225 { 225 FRESULTret;226 BYTEfm;226 int ret; 227 int fm; 227 228 228 229 switch (mode){ 229 230 case 0: 230 fm = FA_READ;231 fm = O_RDONLY; 231 232 break; 232 233 case 1: 233 fm = FA_READ | FA_WRITE | FA_CREATE_NEW;234 fm = O_RDWR | O_CREAT; 234 235 break; 235 236 case 2: 236 fm = FA_READ | FA_WRITE;237 fm = O_RDWR; 237 238 break; 238 239 default: … … 240 241 } 241 242 242 ret = f_open(&fp->fp, str, fm); 243 244 return (ret == FR_OK) ? 0 : -1; 243 ret = open(str, fm); 244 if (ret < 0) { 245 fp->fd = 0; 246 return -1; 247 } 248 fp->fd = ret; 249 250 return 0; 245 251 } 246 252 247 253 int EEP_fwrite(FILEEEP *fp, byte *data, int *len) 248 254 { 249 FRESULT ret; 250 251 ret = f_write(&fp->fp, data, (UINT)*len, (UINT *)len); 252 253 return (ret == FR_OK) ? 1 : -1; 255 int ret; 256 257 ret = write(fp->fd, data, *len); 258 if (ret < 0) { 259 *len = 0; 260 return -1; 261 } 262 *len = ret; 263 264 return 0; 254 265 } 255 266 256 267 int EEP_fread(FILEEEP *fp) 257 268 { 258 FRESULTret;269 int ret; 259 270 char c; 260 UINT br; 261 262 ret = f_read(&fp->fp, &c, 1, &br); 263 if (ret != FR_OK) 271 272 ret = read(fp->fd, &c, 1); 273 if (ret < 0) 264 274 return -1; 265 275 … … 269 279 void EEP_fclose(FILEEEP *fp) 270 280 { 271 f_close(&fp->fp);281 close(fp->fd); 272 282 } 273 283 274 284 int EEP_fseek(FILEEEP *fp, int pos, int mode) 275 285 { 276 FRESULTret;286 int ret; 277 287 278 288 switch (mode){ 279 289 case EEP_SEEKTOP: 280 ret = f_lseek(&fp->fp, pos);290 ret = lseek(fp->fd, pos, SEEK_SET); 281 291 break; 282 292 case EEP_SEEKCUR: 283 ret = f_lseek(&fp->fp, fp->fp.fptr + pos);293 ret = lseek(fp->fd, pos, SEEK_CUR); 284 294 break; 285 295 case EEP_SEEKEND: 286 ret = f_lseek(&fp->fp, fp->fp.fsize - pos);296 ret = lseek(fp->fd, pos, SEEK_END); 287 297 break; 288 298 default: 289 ret = FR_INVALID_PARAMETER;290 break; 291 } 292 293 if (ret != FR_OK)294 f_lseek(&fp->fp, 0);295 296 return fp->fp.fptr;299 return -1; 300 break; 301 } 302 303 if (ret < 0) 304 return false; 305 306 return true; 297 307 } 298 308 299 309 int EEP_ffilesize(const char *str) 300 310 { 301 FRESULTret;302 FILINFOfno;303 304 ret = f_stat(str, &fno);305 if (ret != FR_OK)311 int ret; 312 struct stat fno; 313 314 ret = stat(str, &fno); 315 if (ret < 0) 306 316 return 0; 307 317 308 return fno. fsize;318 return fno.st_size; 309 319 } 310 320 311 321 bool EEP_fEof(FILEEEP *fp) 312 322 { 313 return f_tell(&fp->fp) == f_size(&fp->fp); 323 int ret, pos; 324 struct stat fno; 325 326 ret = fstat(fp->fd, &fno); 327 if (ret < 0) 328 return false; 329 330 pos = lseek(fp->fd, 0, SEEK_CUR); 331 332 return pos == fno.st_size; 314 333 } 315 334 316 335 bool EEP_fexist(const char *path) 317 336 { 318 FRESULTret;319 FILINFOfno;320 321 ret = f_stat(path, &fno);322 323 return (ret == FR_OK);337 int ret; 338 struct stat fno; 339 340 ret = stat(path, &fno); 341 342 return (ret == 0); 324 343 } 325 344 326 345 bool EEP_fcopy(const char *src, const char *dst) 327 346 { 328 FILfsrc, fdst;329 BYTEbuffer[512];330 FRESULT res;331 UINTbr, bw;332 333 res = f_open(&fsrc, src, FA_OPEN_EXISTING | FA_READ);334 if ( res != FR_OK)335 return false; 336 337 res = f_open(&fdst, dst, FA_CREATE_ALWAYS | FA_WRITE);338 if ( res != FR_OK){339 f_close(&fsrc);347 int fsrc, fdst; 348 unsigned char buffer[512]; 349 int res = true; 350 int br, bw; 351 352 fsrc = open(src, O_RDONLY); 353 if (fsrc < 0) 354 return false; 355 356 fdst = open(dst, O_RDWR | O_CREAT); 357 if (fdst < 0){ 358 close(fsrc); 340 359 return false; 341 360 } 342 361 343 362 for (;;) { 344 res = f_read(&fsrc, buffer, sizeof(buffer), &br); 345 if ((res != FR_OK) || br == 0) 363 br = read(fsrc, buffer, sizeof(buffer)); 364 if (br < 0) { 365 res = false; 346 366 break; 347 348 res = f_write(&fdst, buffer, br, &bw); 349 if ((res != FR_OK) || bw < br) 367 } 368 if (br == 0) 350 369 break; 351 } 352 353 f_close(&fsrc); 354 f_close(&fdst); 355 356 return (res == FR_OK); 370 371 bw = write(fdst, buffer, br); 372 if ((bw < 0) || bw < br) { 373 res = false; 374 break; 375 } 376 } 377 378 close(fsrc); 379 close(fdst); 380 381 return res; 357 382 } 358 383 359 384 bool EEP_fdelete(const char *path) 360 385 { 361 FRESULT res; 362 363 res = f_unlink(path); 364 365 return (res == FR_OK); 366 } 367 368 bool SD_begin() 369 { 370 DSTATUS dst; 371 FRESULT res; 372 BYTE pdrv = 1, type; 373 374 if (Sd.FatFs.fs_type != 0) 375 return true; 376 377 if ((dst = disk_initialize(pdrv)) != RES_OK) { 378 return false; 379 } 380 381 if ((dst = disk_ioctl(pdrv, MMC_GET_TYPE, &type)) != RES_OK) { 382 Sd.dst = dst; 383 Sd.type = 0; 384 } 385 else { 386 Sd.dst = RES_OK; 387 Sd.type = type; 388 } 389 390 if ((res = f_mount(&Sd.FatFs, "1:", 1)) != FR_OK) { 391 return false; 392 } 393 386 int res; 387 388 res = unlink(path); 389 390 return (res == 0); 391 } 392 393 bool SD_open(File *file, const char *path, int mode) 394 { 395 int ret; 396 397 if (!SD_begin()) 398 return false; 399 400 ret = open(path, mode); 401 if (ret < 0) { 402 file->fd = 0; 403 return false; 404 } 405 406 file->fd = ret; 394 407 return true; 395 408 } 396 409 397 bool SD_ open(File *file, const char *path, int mode)398 { 399 FRESULTret;410 bool SD_rmdir(const char *path) 411 { 412 int ret; 400 413 401 414 if (!SD_begin()) 402 415 return false; 403 416 404 ret = f_open(&file->fp, path, mode);405 406 return ret == FR_OK;407 } 408 409 bool SD_r mdir(const char *path)410 { 411 FRESULTret;417 ret = rmdir(path); 418 419 return ret == 0; 420 } 421 422 bool SD_rename(const char *path1, const char *path2) 423 { 424 int ret; 412 425 413 426 if (!SD_begin()) 414 427 return false; 415 428 416 ret = f_unlink(path);417 418 return ret == FR_OK;419 } 420 421 bool SD_re name(const char *path1, const char *path2)422 { 423 FRESULTret;429 ret = rename(path1, path2); 430 431 return ret == 0; 432 } 433 434 bool SD_remove(const char *path) 435 { 436 int ret; 424 437 425 438 if (!SD_begin()) 426 439 return false; 427 440 428 ret = f_rename(path1, path2); 429 430 return ret == FR_OK; 431 } 432 433 bool SD_remove(const char *path) 434 { 435 FRESULT ret; 441 ret = unlink(path); 442 443 return ret == 0; 444 } 445 446 bool SD_exists(const char *path) 447 { 448 int ret; 449 struct stat fno; 436 450 437 451 if (!SD_begin()) 438 452 return false; 439 453 440 ret = f_unlink(path); 441 442 return ret == FR_OK; 443 } 444 445 bool SD_exists(const char *path) 446 { 447 FRESULT ret; 448 FILINFO fno; 454 ret = stat(path, &fno); 455 456 return ret == 0; 457 } 458 459 bool SD_mkdir(const char *path) 460 { 461 int ret; 449 462 450 463 if (!SD_begin()) 451 464 return false; 452 465 453 ret = f_stat(path, &fno); 454 455 return ret == FR_OK; 456 } 457 458 bool SD_mkdir(const char *path) 459 { 460 FRESULT ret; 461 462 if (!SD_begin()) 463 return false; 464 465 ret = f_mkdir(path); 466 467 return ret == FR_OK; 468 } 469 470 int file_write(File *fd, unsigned char *str, int len) 471 { 472 FRESULT ret; 473 UINT bw; 474 475 ret = f_write(&fd->fp, str, len, &bw); 476 if (ret != FR_OK) 477 return -1; 478 479 return bw; 480 } 481 482 void file_close(File *fd) 483 { 484 f_close(&fd->fp); 485 } 486 487 int file_size(File *fd) 488 { 489 return f_size(&fd->fp); 490 } 491 492 int file_position(File *fd) 493 { 494 return fd->fp.fptr; 495 } 496 497 void file_flush(File *fd) 498 { 499 f_flush(&fd->fp); 500 } 501 502 bool file_seek(File *fd, int pos) 503 { 504 FRESULT ret; 505 506 ret = f_lseek(&fd->fp, pos); 507 508 return ret != FR_OK; 509 } 510 511 int file_read(File *fd) 512 { 513 FRESULT ret; 466 ret = mkdir(path, 0777); 467 468 return ret == 0; 469 } 470 471 int file_write(File *fp, unsigned char *str, int len) 472 { 473 int ret; 474 475 ret = write(fp->fd, str, len); 476 if (ret < 0) 477 return -1; 478 479 return ret; 480 } 481 482 void file_close(File *fp) 483 { 484 close(fp->fd); 485 } 486 487 int file_size(File *fp) 488 { 489 int ret; 490 struct stat fno; 491 492 ret = fstat(fp->fd, &fno); 493 if (ret < 0) 494 return -1; 495 496 return fno.st_size; 497 } 498 499 int file_position(File *fp) 500 { 501 int ret; 502 struct stat fno; 503 504 ret = lseek(fp->fd, 0, SEEK_CUR); 505 if (ret < 0) 506 return -1; 507 508 return ret; 509 } 510 511 void file_flush(File *fp) 512 { 513 fsync(fp->fd); 514 } 515 516 bool file_seek(File *fp, int pos) 517 { 518 int ret; 519 520 ret = lseek(fp->fd, pos, SEEK_SET); 521 522 return ret == 0; 523 } 524 525 int file_read(File *fp) 526 { 527 int ret; 514 528 char c; 515 UINT br; 516 517 ret = f_read(&fd->fp, &c, 1, &br); 518 if (ret != FR_OK) 529 530 ret = read(fp->fd, &c, 1); 531 if (ret < 0) 519 532 return -1; 520 533 … … 524 537 void system_reboot(int mode) 525 538 { 526 539 exit(mode); 527 540 } 528 541 … … 531 544 return 0; 532 545 } 533 534 DWORD get_fattime(void)535 {536 time_t temp;537 struct tm _tm;538 539 time(&temp);540 gmtime_r(&temp, &_tm);541 542 return ((DWORD)(_tm.tm_year - 1980) << 25)543 | ((DWORD)_tm.tm_mon << 21)544 | ((DWORD)_tm.tm_mday << 16)545 | ((DWORD)_tm.tm_hour << 11)546 | ((DWORD)_tm.tm_min << 5)547 | ((DWORD)_tm.tm_sec >> 1);548 }549 550 void mrb_gr_peach_gem_init(mrb_state *mrb)551 {552 }553 554 void mrb_gr_peach_gem_final(mrb_state *mrb)555 {556 557 } -
EcnlProtoTool/trunk/prototool/src/arduino.h
r278 r279 30 30 #include <us_ticker_api.h> 31 31 #include <wait_api.h> 32 #include "diskio.h"33 #include "ff.h"34 32 35 33 #ifndef bool … … 116 114 117 115 typedef struct File { 118 FIL fp;116 int fd; 119 117 } File; 120 118 … … 130 128 int file_read(File *fd); 131 129 132 typedef struct SD {133 DSTATUS dst;134 BYTE type;135 FATFS FatFs;136 } SD;137 138 extern SD Sd;139 140 130 bool SD_begin(); 141 131 bool SD_open(File *file, const char *path, int mode); … … 147 137 148 138 typedef struct FILEEEP { 149 FIL fp;139 int fd; 150 140 } FILEEEP; 151 141 -
EcnlProtoTool/trunk/prototool/src/main.c
r270 r279 1 1 /* 2 2 * TOPPERS ECHONET Lite Communication Middleware 3 * 4 * Copyright (C) 2014-201 7Cores Co., Ltd. Japan5 * 3 * 4 * Copyright (C) 2014-2016 Cores Co., Ltd. Japan 5 * 6 6 * ä¸è¨è使¨©è 7 7 ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ … … 40 40 * å 41 41 責ãããã¨ï¼ 42 * 42 * 43 43 * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è 44 44 ã … … 47 47 * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ã 48 48 * ã®è²¬ä»»ãè² ããªãï¼ 49 * 49 * 50 50 * @(#) $Id$ 51 51 */ 52 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> 53 /* 54 * ãµã³ãã«ããã°ã©ã (1)ã®æ¬ä½ 55 */ 56 57 #include <sys/types.h> 58 #include <sys/socket.h> 59 #include <sys/un.h> 60 #include <netinet/in.h> 61 #include <netinet/tcp.h> 62 #include <arpa/inet.h> 63 #include <fcntl.h> 64 #include <netdb.h> 65 #include <unistd.h> 66 #include <setjmp.h> 67 #include <signal.h> 68 #include <time.h> 69 #include <sys/time.h> 70 #include <sys/unistd.h> 71 #include <errno.h> 72 62 73 #include <string.h> 63 #include "syssvc/serial.h"64 #include "syssvc/syslog.h"65 #include "kernel_cfg.h"66 #include "main.h"67 #include "rza1.h"68 74 #include <mruby.h> 69 75 #include <mruby/compile.h> … … 74 80 #include <mruby/dump.h> 75 81 #include <mruby/string.h> 76 #include <tinet_config.h> 77 #include <netinet/in.h> 78 #include <netinet/in_itron.h> 79 #include <tinet_nic_defs.h> 80 #include <tinet_cfg.h> 81 #include <netinet/in_var.h> 82 #include <net/ethernet.h> 83 #include <net/if6_var.h> 84 #include <net/net.h> 85 #include <net/if_var.h> 86 #include <netinet/udp_var.h> 87 #include <ethernet_api.h> 88 #include "../webserver/httpd.h" 89 #include "../webserver/httpd-fs.h" 90 #include "../webserver/http-strings.h" 91 #include "../webserver/base64.h" 92 #include "../webserver/sha1.h" 93 #include "mruby_arduino.h" 94 #include "gpio_api.h" 95 #include "arduino.h" 96 #include "ff.h" 97 98 #ifndef _MSC_VER 99 void strcpy_s(char *dst, int size, const char *src); 100 void strcat_s(char *dst, int size, const char *src); 101 #endif 102 103 uint8_t mac_addr[6] = {0x00, 0x30, 0x13, 0x06, 0x62, 0xC0}; 104 105 SYSTIM main_time; 106 struct httpd_state *uploding; 107 108 static void netif_link_callback(T_IFNET *ether); 109 static void execute_ruby(); 110 111 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */ 112 uint8_t tcp_swbuf1[TCP_SWBUF_SIZE]; 113 uint8_t tcp_rwbuf1[TCP_RWBUF_SIZE]; 114 uint8_t tcp_swbuf2[TCP_SWBUF_SIZE]; 115 uint8_t tcp_rwbuf2[TCP_RWBUF_SIZE]; 116 117 #define ISO_nl 0x0a 118 #define ISO_space 0x20 119 #define ISO_bang 0x21 120 #define ISO_percent 0x25 121 #define ISO_period 0x2e 122 #define ISO_slash 0x2f 123 #define ISO_colon 0x3a 124 125 ID ecn_api_mailboxid; 126 ID WEBSOCKET_MBXID; 127 128 struct httpd_state httpd_state[2] = { 129 {MAIN1_TASK, TCP_CEPID1}, 130 {MAIN2_TASK, TCP_CEPID2}, 131 }; 132 133 /* 134 * ãããã¯ã¼ã¯å±¤ã®é¸æ 135 */ 136 137 #ifdef SUPPORT_INET6 138 139 #define TCP_ACP_CEP(c,r,d,t) tcp6_acp_cep(c,r,d,t) 140 #define IP2STR(s,a) ipv62str(s,a) 141 142 #else /* of #ifdef SUPPORT_INET6 */ 143 144 #ifdef SUPPORT_INET4 145 146 #define TCP_ACP_CEP(c,r,d,t) tcp_acp_cep(c,r,d,t) 147 #define IP2STR(s,a) ip2str(s,a) 148 149 #endif /* of #ifdef SUPPORT_INET4 */ 150 151 #endif /* of #ifdef SUPPORT_INET6 */ 152 153 struct httpd_state *get_httpd(ID cepid) 154 { 155 for (int i = 0; i < 2; i++) { 156 if (httpd_state[i].cepid != cepid) 157 continue; 158 159 return &httpd_state[i]; 160 } 161 return NULL; 162 } 163 164 struct websocket *websocket_getws(ID wbsid) 165 { 166 for (int i = 0; i < 2; i++) { 167 if (httpd_state[i].websocket.wbsid != wbsid) 168 continue; 169 170 return &httpd_state[i].websocket; 171 } 172 return NULL; 173 } 174 175 void send_file(struct httpd_state *s) 176 { 177 char *buf; 178 int len, slen; 179 180 while (s->file.len > 0) { 181 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 182 if (slen < 0) { 183 syslog(LOG_ERROR, "send_file#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 184 s->state = STATE_CLOSING; 185 break; 186 } 187 if (slen == 0) 188 return; 189 190 len = s->file.len; 191 if (len > slen) 192 len = slen; 193 194 len = httpd_fs_read(&s->file, buf, len); 195 if (len <= 0) { 196 syslog(LOG_ERROR, "send_file#httpd_fs_read(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, len); 197 break; 198 } 199 200 s->file.len -= len; 201 s->file.pos += len; 202 203 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 204 syslog(LOG_ERROR, "send_file#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 205 s->state = STATE_CLOSING; 206 break; 207 } 208 } 209 210 syslog(LOG_NOTICE, "close: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 211 httpd_fs_close(&s->file); 212 s->file.len = 0; 213 s->file.pos = 0; 214 215 s->out.state = OUT_STATE_SEND_END; 216 } 217 218 void send_data(struct httpd_state *s) 219 { 220 char *buf; 221 int len, slen; 222 223 while (s->response_len > 0) { 224 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 225 if (slen < 0) { 226 syslog(LOG_ERROR, "send_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 227 s->state = STATE_CLOSING; 228 break; 229 } 230 if (slen == 0) 231 return; 232 233 len = s->response_len; 234 if (len > slen) 235 len = slen; 236 237 memcpy(buf, &s->response_body[s->response_pos], len); 238 239 s->response_len -= len; 240 s->response_pos += len; 241 242 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 243 syslog(LOG_ERROR, "send_data#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 244 s->state = STATE_CLOSING; 245 break; 246 } 247 } 248 249 s->response_body = NULL; 250 s->response_len = 0; 251 s->response_pos = 0; 252 253 s->out.state = OUT_STATE_SEND_END; 254 } 255 256 void send_headers(struct httpd_state *s, const char *statushdr) 257 { 258 int len; 259 char *ptr; 260 261 len = strlen(statushdr); 262 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 263 264 if ((s->filename[0] == '0') && (s->file.len > 0)) { 265 len = sizeof(http_content_encoding_gzip) - 1; 266 tcp_snd_dat(s->cepid, (void *)http_content_encoding_gzip, len, TMO_FEVR); 267 } 268 269 if (s->file.redirect) { 270 len = sizeof(http_location) - 1; 271 tcp_snd_dat(s->cepid, (void *)http_location, len, TMO_FEVR); 272 if (s->filename[0] == '1') { 273 len = 2; 274 tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR); 275 } 276 len = strlen(s->filename); 277 tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR); 278 if (s->query != NULL) { 279 tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR); 280 len = strlen(s->query); 281 tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR); 282 } 283 len = 2; 284 tcp_snd_dat(s->cepid, "\r", len, TMO_FEVR); 285 } 286 287 ptr = strrchr(s->filename, ISO_period); 288 if (ptr == NULL) { 289 len = sizeof(http_content_type_binary) - 1; 290 tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR); 291 } 292 else if (strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 || 293 strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) { 294 len = sizeof(http_content_type_html) - 1; 295 tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR); 296 } 297 else if (strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) { 298 len = sizeof(http_content_type_css) - 1; 299 tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR); 300 } 301 else if (strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) { 302 len = sizeof(http_content_type_js) - 1; 303 tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR); 304 } 305 else if (strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) { 306 len = sizeof(http_content_type_json) - 1; 307 tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR); 308 } 309 else if (strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) { 310 len = sizeof(http_content_type_png) - 1; 311 tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR); 312 } 313 else if (strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) { 314 len = sizeof(http_content_type_gif) - 1; 315 tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR); 316 } 317 else if (strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) { 318 len = sizeof(http_content_type_jpg) - 1; 319 tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR); 320 } 321 else if (strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) { 322 len = sizeof(http_content_type_svg) - 1; 323 tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR); 324 } 325 else if (strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) { 326 len = sizeof(http_content_type_text) - 1; 327 tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR); 328 } 329 else if (strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) { 330 len = sizeof(http_content_type_eot) - 1; 331 tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR); 332 } 333 else if (strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) { 334 len = sizeof(http_content_type_ttf) - 1; 335 tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR); 336 } 337 else if (strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) { 338 len = sizeof(http_content_type_woff) - 1; 339 tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR); 340 } 341 else if (strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) { 342 len = sizeof(http_content_type_woff2) - 1; 343 tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR); 344 } 345 else if (strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) { 346 len = sizeof(http_content_type_ico) - 1; 347 tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR); 348 } 349 else { 350 len = sizeof(http_content_type_plain) - 1; 351 tcp_snd_dat(s->cepid, (void *)http_content_type_plain, len, TMO_FEVR); 352 } 353 354 if (s->file.len > 0) { 355 len = sizeof(http_content_length) - 1; 356 tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR); 357 sprintf(s->temp, "%d\r\n", s->file.len); 358 tcp_snd_dat(s->cepid, (void *)s->temp, strlen(s->temp), TMO_FEVR); 359 } 360 361 if (s->message.should_keep_alive && s->reset == 0) { 362 len = sizeof(http_connection_keep_alive) - 1; 363 tcp_snd_dat(s->cepid, (void *)http_connection_keep_alive, len, TMO_FEVR); 364 } 365 else { 366 len = sizeof(http_connection_close) - 1; 367 tcp_snd_dat(s->cepid, (void *)http_connection_close, len, TMO_FEVR); 368 } 369 370 tcp_snd_dat(s->cepid, (void *)http_crnl, 2, TMO_FEVR); 371 372 if (s->filename != NULL) { 373 s->out.state = OUT_STATE_SEND_FILE; 374 } 375 else { 376 s->out.state = OUT_STATE_SEND_DATA; 377 } 378 } 379 380 void handle_output(struct httpd_state *s) 381 { 382 s->out.wait = false; 383 384 switch (s->out.state) { 385 case OUT_STATE_WAIT_REQUEST: 386 s->out.wait = true; 387 break; 388 case OUT_STATE_OPEN_GET_FILE: 389 syslog(LOG_NOTICE, "open: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 390 if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) { 391 s->filename = NULL; 392 s->response_body = http_content_404; 393 s->response_pos = 0; 394 s->response_len = sizeof(http_content_403) - 1; 395 s->out.statushdr = http_header_404; 396 } 397 else { 398 s->out.statushdr = s->file.redirect ? http_header_301 : http_header_200; 399 } 400 s->out.state = OUT_STATE_SEND_HEADER; 401 break; 402 case OUT_STATE_WAIT_POST_BODY: 403 s->out.wait = true; 404 break; 405 case OUT_STATE_BODY_RECEIVED: 406 s->out.statushdr = http_header_200; 407 s->out.state = OUT_STATE_SEND_HEADER; 408 break; 409 case OUT_STATE_SEND_HEADER: 410 send_headers(s, s->out.statushdr); 411 break; 412 case OUT_STATE_SEND_FILE: 413 send_file(s); 414 break; 415 case OUT_STATE_SEND_DATA: 416 send_data(s); 417 break; 418 case OUT_STATE_SEND_END: 419 s->out.wait = true; 420 if (s->message.should_keep_alive && s->reset == 0) { 421 s->out.state = OUT_STATE_WAIT_REQUEST; 422 } 423 else { 424 s->state = STATE_CLOSING; 425 } 426 break; 427 } 428 } 429 430 void send_ws_headers(struct httpd_state *s, const char *statushdr) 431 { 432 int len; 433 434 len = strlen(statushdr); 435 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 436 437 len = sizeof(http_upgrade) - 1; 438 tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR); 439 len = strlen(s->message.upgrade); 440 tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR); 441 len = sizeof(http_crnl) - 1; 442 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 443 444 len = sizeof(http_connection) - 1; 445 tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR); 446 len = strlen(s->message.connection); 447 tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR); 448 len = sizeof(http_crnl) - 1; 449 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 450 451 len = sizeof(http_sec_websocket_accept) - 1; 452 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR); 453 len = strlen(s->message.response_key); 454 tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR); 455 len = sizeof(http_crnl) - 1; 456 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 457 458 len = sizeof(http_sec_websocket_protocol) - 1; 459 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR); 460 len = strlen(s->message.sec_websocket_protocol); 461 tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR); 462 len = sizeof(http_crnl) - 1; 463 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 464 465 len = sizeof(http_crnl) - 1; 466 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 467 } 468 469 void send_ws_data(struct httpd_state *s) 470 { 471 char *buf; 472 int slen; 473 474 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 475 if (slen < 0) { 476 syslog(LOG_ERROR, "send_ws_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 477 return; 478 } 479 480 websocket_output(&s->websocket, buf, slen); 481 } 482 483 void handle_ws_output(struct httpd_state *s) 484 { 485 char shaHash[20]; 486 SHA_CTX sha1; 487 int len; 488 489 strlncat(s->message.response_key, sizeof(s->message.response_key), 490 s->message.sec_websocket_key, sizeof(s->message.sec_websocket_key)); 491 len = strlncat(s->message.response_key, sizeof(s->message.response_key), 492 http_websocket_guid, sizeof(http_websocket_guid)); 493 memset(shaHash, 0, sizeof(shaHash)); 494 SHA1_Init(&sha1); 495 SHA1_Update(&sha1, (sha1_byte *)s->message.response_key, len); 496 SHA1_Final((sha1_byte *)shaHash, &sha1); 497 base64_encode((unsigned char *)s->message.response_key, 498 sizeof(s->message.response_key), (unsigned char *)shaHash, sizeof(shaHash)); 499 500 send_ws_headers(s, http_header_101); 501 502 s->message.response_key[0] = '\0'; 503 504 do { 505 while (!websocket_newdata(&s->websocket)) 506 slp_tsk(); 507 508 send_ws_data(s); 509 } while ((s->state == STATE_CONNECTED) && (!s->close_req)); 510 s->state = STATE_DISCONNECTED; 511 websocket_destroy(&s->websocket); 512 s->close_req = 0; 513 514 s->state = STATE_CLOSING; 515 } 516 517 void handle_input(struct httpd_state *s) 518 { 519 size_t done; 520 int len; 521 522 s->in.wait = false; 523 524 switch (s->in.state) { 525 case IN_STATE_START: 526 http_parser_init(&s->parser, HTTP_REQUEST); 527 s->in.state = IN_STATE_REQUEST; 528 break; 529 case IN_STATE_REQUEST: 530 case IN_STATE_RESPONSE: 531 case IN_STATE_UPLOAD: 532 if ((len = tcp_rcv_buf(s->cepid, (void **)&s->in.data, TMO_POL)) <= 0) { 533 if ((len == E_TMOUT) || (len == 0)) { 534 // 3ç§ã¯å¾ 535 㤠536 if (main_time - s->in.timer < 30000000) { 537 s->in.wait = true; 538 break; 539 } 540 } 541 syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 542 uploding = NULL; 543 s->state = STATE_CLOSING; 544 return; 545 } 546 done = http_parser_execute(&s->parser, &websvr_settings, s->in.data, len); 547 tcp_rel_buf(s->cepid, done); 548 if (s->parser.http_errno != HPE_OK) { 549 syslog(LOG_ERROR, "http_parser error %s.%d => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno); 550 uploding = NULL; 551 s->state = STATE_CLOSING; 552 return; 553 } 554 555 s->parse_pos = done; 556 s->parse_len = len - done; 557 break; 558 case IN_STATE_UPLOAD_WAIT: 559 if (uploding != NULL) { 560 s->in.wait = true; 561 } 562 else { 563 uploding = s; 564 s->in.state = IN_STATE_UPLOAD; 565 } 566 break; 567 case IN_STATE_WEBSOCKET: 568 if (s->parse_len <= 0) { 569 if ((len = tcp_rcv_buf(s->cepid, (void **)&s->in.data, TMO_POL)) <= 0) { 570 if ((len == E_TMOUT) || (len == 0)) { 571 s->in.wait = true; 572 break; 573 } 574 syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 575 s->state = STATE_CLOSING; 576 break; 577 } 578 579 s->parse_pos = 0; 580 s->parse_len = len; 581 } 582 else 583 len = s->parse_len; 584 done = websocket_input(&s->websocket, (void *)s->in.data, s->parse_len); 585 tcp_rel_buf(s->cepid, done); 586 if ((done != 0) || (s->websocket.rstate.opecode == connection_close)) { 587 s->close_req = 1; 588 s->state = STATE_CLOSING; 589 break; 590 } 591 s->parse_pos = done; 592 s->parse_len -= done; 593 break; 594 case IN_STATE_END: 595 s->in.wait = true; 596 break; 597 default: 598 s->state = STATE_CLOSING; 599 break; 600 } 601 } 602 603 /* 604 * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ° 605 */ 606 ER 607 callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk) 608 { 609 struct httpd_state *s = get_httpd(cepid); 610 611 if (s == NULL) 612 syslog(LOG_NOTICE, "callback_nblk_tcp(%d, %d)", fncd, cepid); 613 else 614 syslog(LOG_NOTICE, "callback_nblk_tcp(%d, %s.%d)", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno); 615 616 return E_PAR; 617 } 618 619 /* 620 * ã¡ã¤ã³ã¿ã¹ã¯ 621 */ 622 void main_task(intptr_t exinf) 623 { 624 ER ret, ret2; 625 struct httpd_state *s = &httpd_state[exinf]; 626 627 if (exinf == 0) { 628 gpio_t led_blue, led_green, led_red, sw; 629 gpio_init_out(&led_blue, LED_BLUE); 630 gpio_init_out(&led_green, LED_GREEN); 631 gpio_init_out(&led_red, LED_RED); 632 gpio_init_in(&sw, USER_BUTTON0); 633 634 bool_t exec = gpio_read(&sw) == 1; 635 636 gpio_write(&led_blue, 1); 637 gpio_write(&led_green, exec ? 1 : 0); 638 gpio_write(&led_red, 0); 639 640 /* åæå */ 641 if (mruby_arduino_init() == 0) { 642 gpio_write(&led_blue, 0); 643 } 644 else { 645 gpio_write(&led_blue, 0); 646 gpio_write(&led_red, 1); 647 } 648 649 gpio_write(&led_green, 0); 650 651 /* TINETãèµ·åããã¾ã§å¾ 652 㤠*/ 653 ether_set_link_callback(netif_link_callback); 654 655 act_tsk(MAIN2_TASK); 656 657 if (exec) { 658 strcpy_s(RubyFilename, sizeof(RubyFilename), "1:/upload/main.mrb"); 659 660 execute_ruby(); 661 } 662 } 663 664 for (;;) { 665 ret2 = get_tim(&main_time); 666 if (ret2 != E_OK) { 667 syslog(LOG_ERROR, "get_tim"); 668 return; 669 } 670 671 switch (s->state) { 672 case STATE_DISCONNECTED: 673 memset(&s->dst, 0, sizeof(s->dst)); 674 if ((ret = TCP_ACP_CEP(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) { 675 syslog(LOG_ERROR, "tcp_acp_cep(%d) => %d", s->cepid, ret); 676 tslp_tsk(100000); // TODO 677 s->state = STATE_CLOSING; 678 break; 679 } 680 IP2STR(s->addr, &((T_IPV4EP *)s->dst)->ipaddr); 681 syslog(LOG_NOTICE, "connected: %s.%d", s->addr, ((T_IPV4EP *)s->dst)->portno); 682 memset(&s->in, 0, sizeof(s->in)); 683 memset(&s->out, 0, sizeof(s->out)); 684 s->in.timer = main_time; 685 s->state = STATE_CONNECTED; 686 break; 687 case STATE_CONNECTED: 688 handle_input(s); 689 handle_output(s); 690 break; 691 case STATE_WEBSOCKET: 692 handle_input(s); 693 handle_ws_output(s); 694 break; 695 case STATE_CLOSING: 696 syslog(LOG_NOTICE, "close: %s.%d", s->addr, ((T_IPV4EP *)s->dst)->portno); 697 tcp_sht_cep(s->cepid); 698 tcp_cls_cep(s->cepid, TMO_FEVR); 699 700 if (s->reset) { 701 s->reset = 0; 702 s->state = STATE_RESET; 703 } 704 else{ 705 s->state = STATE_DISCONNECTED; 706 } 707 break; 708 case STATE_RESET: 709 execute_ruby(); 710 s->state = STATE_DISCONNECTED; 711 break; 712 } 713 714 if (s->in.wait && s->out.wait) { 715 tslp_tsk(100000); 716 } 717 } 718 } 719 720 struct udp_msg { 721 T_IPV4EP dst; 82 #include <usrcmd.h> 83 84 #define ETHER_MAX_LEN 1518 85 #define IF_FLAG_UP 1 86 #define IF_FLAG_LINK_UP 2 87 #define MAKE_IPV4_ADDR(a,b,c,d) htonl(((uint32_t)(a)<<24)|((uint32_t)(b)<<16)|((uint32_t)(c)<<8)|(d)) 88 89 struct udp_msg 90 { 91 struct sockaddr_in dst; 722 92 int len; 723 93 uint8_t buffer[ETHER_MAX_LEN]; 724 94 }; 725 95 726 SYSTIM mruby_time; 96 typedef struct 97 { 98 cmd_table_t *table; 99 cmd_table_t *count; 100 } cmd_table_info_t; 101 102 extern int mrbc_main(int argc, char **argv); 103 extern int mrdb_main(int argc, char **argv); 104 extern int mruby_main(int argc, char **argv); 105 extern int mirb_main(int argc, char **argv); 106 extern int tcc_main(int argc, char **argv); 107 extern int vi_main(int argc, char **argv); 108 extern int onitest_main(int argc, char **argv); 109 extern int tcp_echo_main(int argc, char **argv); 110 extern int echo_client_main(int argc, char **argv); 111 extern int mrdb_break(void); 112 113 static const cmd_table_t cmdlist[] = { 114 {"mrbc", "mruby compiler executable", mrbc_main}, 115 {"mrdb","mruby debugger command", mrdb_main}, 116 {"mruby","mruby command", mruby_main}, 117 {"mirb", "Embeddable Interactive Ruby Shell", mirb_main}, 118 {"tcc", "Tiny C compiler", tcc_main}, 119 {"vi", "Text editor", vi_main}, 120 {"cd", "change directory", usrcmd_cd }, 121 {"ls", "list files", usrcmd_ls }, 122 {"cp", "copy file", usrcmd_cp }, 123 {"rm", "remove file", usrcmd_rm }, 124 {"mv", "move file", usrcmd_mv }, 125 {"mkdir", "Make directory", usrcmd_mkdir}, 126 {"hexdump", "Hex dump", usrcmd_hexdump}, 127 {"onitest", "Onigumo Test", onitest_main}, 128 {"tcp_echo", "TCP echo server/client", tcp_echo_main}, 129 {"help", "This is a description text string for help command.", usrcmd_help}, 130 {"info", "This is a description text string for info command.", usrcmd_info}, 131 {"exit", "Exit Natural Tyny Shell", usrcmd_exit}, 132 }; 133 cmd_table_info_t cmd_table_info = { &cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) }; 134 135 int echonet = 1; 136 struct timeval main_time; 727 137 struct RClass *_module_target_board; 728 729 extern const uint8_t main_rb_code[]; 730 uint8_t RubyCode[16 * 1024]; 731 732 /* MACã¢ãã¬ã¹ã®è¨å®æã«å¼ã°ãã */ 733 void mbed_mac_address(char *mac) 734 { 735 memcpy(mac, mac_addr, 6); 736 } 737 738 /* 739 * mrubyå®è¡ã¿ã¹ã¯ 740 */ 741 void mruby_task(intptr_t exinf) 742 { 743 ER ret; 138 int sock; 139 140 int main(int argc, char **argv) 141 { 142 if (argc == 0) { 143 return 0; 144 } 145 const cmd_table_t *p = cmd_table_info.table; 146 for (int i = 0; i < cmd_table_info.count; i++) { 147 if (strcmp((const char *)argv[0], p->cmd) == 0) { 148 return p->func(argc, argv); 149 } 150 p++; 151 } 152 printf("Unknown command found.\n"); 153 return 0; 154 } 155 156 int run_mruby_code(int argc, char **argv, const uint8_t *code, const char *cmdline) 157 { 158 mrb_state *mrb; 744 159 struct RProc* n; 745 160 struct mrb_irep *irep; 746 mrb_state *mrb; 747 748 syslog(LOG_NOTICE, "mruby_task"); 161 mrb_value ARGV; 162 mrbc_context *c; 163 mrb_value v; 164 mrb_sym zero_sym; 165 166 echonet = 0; 749 167 750 168 /* mrubyã®åæå */ 751 169 mrb = mrb_open(); 752 170 if (mrb == NULL) 753 abort(); 754 755 ret = get_tim(&mruby_time); 756 if (ret != E_OK) { 757 syslog(LOG_ERROR, "get_tim => %d", ret); 758 return; 759 } 760 761 irep = mrb_read_irep(mrb, RubyCode); 171 return -1; 172 173 int ai = mrb_gc_arena_save(mrb); 174 ARGV = mrb_ary_new_capa(mrb, argc); 175 for (int i = 0; i < argc; i++) { 176 mrb_ary_push(mrb, ARGV, mrb_str_new_cstr(mrb, argv[i])); 177 } 178 mrb_define_global_const(mrb, "ARGV", ARGV); 179 180 c = mrbc_context_new(mrb); 181 c->dump_result = TRUE; 182 183 /* Set $0 */ 184 zero_sym = mrb_intern_lit(mrb, "$0"); 185 mrbc_filename(mrb, c, cmdline); 186 mrb_gv_set(mrb, zero_sym, mrb_str_new_cstr(mrb, cmdline)); 187 188 irep = mrb_read_irep(mrb, code); 762 189 n = mrb_proc_new(mrb, irep); 763 190 mrb_run(mrb, n, mrb_nil_value()); 764 191 192 mrb_gc_arena_restore(mrb, ai); 193 mrbc_context_free(mrb, c); 194 if (mrb->exc) { 195 if (!mrb_undef_p(v)) { 196 mrb_print_error(mrb); 197 } 198 n = -1; 199 } 200 765 201 mrb_close(mrb); 766 } 767 768 static void execute_ruby() 769 { 770 FIL fd; 771 FRESULT res; 772 ER ret; 773 774 syslog(LOG_NOTICE, "execute_ruby"); 775 776 ret = ter_tsk(MRUBY_TASK); 777 if ((ret != E_OK) && (ret != E_OBJ)) { 778 syslog(LOG_ERROR, "ter_tsk => %d", ret); 779 } 780 781 tslp_tsk(100000); 782 783 reset_heap(); 784 785 strcpy_s(ExeFilename, sizeof(ExeFilename), RubyFilename); 786 RubyFilename[0] = '\0'; 787 ExeFilename[sizeof(ExeFilename) - 1] = '\0'; 788 789 if (ExeFilename[0] == '\0') { 202 return 0; 203 } 204 205 int tcp_echo_main(int argc, char **argv) 206 { 207 extern const uint8_t echo_server_code[]; 208 extern const uint8_t echo_client_code[]; 209 210 if (argc >= 2) { 211 if (strcmp(argv[1], "-s") == 0) { 212 return run_mruby_code(argc - 2, &argv[2], echo_server_code, "echo_server"); 213 } 214 else if (strcmp(argv[1], "-c") == 0) { 215 return run_mruby_code(argc - 2, &argv[2], echo_client_code, "echo_client"); 216 } 217 } 218 219 printf("tcp_echo -s port\n"); 220 printf("tcp_echo -c ipaddr port\n"); 221 222 return 0; 223 } 224 225 int usrcmd_help(int argc, char **argv) 226 { 227 const cmd_table_t *p = cmd_table_info.table; 228 for (int i = 0; i < cmd_table_info.count; i++) { 229 printf(p->cmd); 230 printf("\t:"); 231 printf(p->desc); 232 printf("\n"); 233 p++; 234 } 235 return 0; 236 } 237 238 void sigusr1_handler(int sig) 239 { 240 printf("signal called\n"); 241 } 242 243 void mrb_target_board_init() 244 { 245 int ret; 246 struct sockaddr_in ep; 247 struct ip_mreq mreq; 248 249 signal(SIGUSR1, sigusr1_handler); 250 251 sock = socket(AF_INET, SOCK_DGRAM, 0); 252 253 memset(&ep, 0, sizeof(ep)); 254 ep.sin_family = AF_INET; 255 ep.sin_port = htons(3610); 256 ep.sin_addr.s_addr = INADDR_ANY; 257 //ep.sin_addr.s_addr = MAKE_IPV4_ADDR(192,168,137,200); 258 259 ret = bind(sock, &ep, sizeof(ep)); 260 if (ret != 0) { 261 printf("bind %d", ret); 790 262 return; 791 263 } 792 264 793 syslog(LOG_NOTICE, "%s", ExeFilename); 794 795 wai_sem(SEM_FILESYSTEM); 796 797 if ((res = f_open(&fd, ExeFilename, FA_OPEN_EXISTING | FA_READ)) == FR_OK) { 798 if (fd.fsize < sizeof(RubyCode)) { 799 int len = fd.fsize; 800 for (int pos = 0; pos < fd.fsize; pos += len) { 801 if (len > 1024) 802 len = 1024; 803 804 UINT rlen; 805 if ((res = f_read(&fd, &RubyCode[pos], len, &rlen)) != FR_OK) 806 break; 807 808 // ä»ã«ä½¿ã人ã®ããã«è§£æ¾ 809 sig_sem(SEM_FILESYSTEM); 810 wai_sem(SEM_FILESYSTEM); 811 } 812 } 813 f_close(&fd); 814 } 815 816 sig_sem(SEM_FILESYSTEM); 817 818 if (res == FR_OK) { 819 ret = act_tsk(MRUBY_TASK); 820 if (ret != E_OK) { 821 syslog(LOG_ERROR, "act_tsk => %d", ret); 822 } 823 } 824 } 825 826 ER callback_nblk_udp(ID cepid, FN fncd, void *p_parblk) 827 { 828 static struct udp_msg msg_inst[2]; 829 static int msg_no = 0; 830 struct udp_msg *msg = &msg_inst[msg_no]; 831 ER error = E_OK; 832 833 switch (fncd) { 834 case TFN_UDP_CRE_CEP: 835 case TFN_UDP_RCV_DAT: 836 /* ECN_CAP_PUT("[UDP ECHO SRV] callback_nblk_udp() recv: %u", *(int *)p_parblk); */ 837 memset(msg, 0, sizeof(struct udp_msg)); 838 if ((msg->len = udp_rcv_dat(cepid, &msg->dst, msg->buffer, sizeof(msg->buffer), 0)) < 0) { 839 syslog(LOG_WARNING, "[UDP ECHO SRV] recv, error: %s", itron_strerror(msg->len)); 840 return msg->len; 841 } 842 msg_no = (msg_no + 1) % 2; 843 return snd_dtq(MRUBY_DATAQUEUE, (intptr_t)msg); 844 845 case TFN_UDP_SND_DAT: 846 break; 847 default: 848 syslog(LOG_WARNING, "[UDP ECHO SRV] fncd:0x%04X(%s)", -fncd, 849 (fncd == TFN_UDP_CRE_CEP ? "TFN_UDP_CRE_CEP" : 850 (fncd == TFN_UDP_RCV_DAT ? "TFN_UDP_RCV_DAT" : 851 (fncd == TFN_UDP_SND_DAT ? "TFN_UDP_SND_DAT" : "undef")))); 852 853 error = E_PAR; 854 break; 855 } 856 return error; 857 } 858 859 static void netif_link_callback(T_IFNET *ether) 860 { 861 static struct udp_msg msg_inst[2]; 862 static int msg_no = 0; 863 struct udp_msg *msg = &msg_inst[msg_no]; 864 T_RTSK rtsk; 865 ER ret; 866 867 ret = ref_tsk(MRUBY_TASK, &rtsk); 868 if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT)) 265 mreq.imr_interface.s_addr = INADDR_ANY; 266 mreq.imr_multiaddr.s_addr = MAKE_IPV4_ADDR(224, 0, 23, 0); 267 268 ret = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq)); 269 if (ret != 0) { 270 printf("setsockopt %d", ret); 869 271 return; 870 871 memset(msg, 0, sizeof(struct udp_msg)); 872 873 msg->len = 1; 874 msg->buffer[0] = ether->flags; 875 876 msg_no = (msg_no + 1) % 2; 877 snd_dtq(MRUBY_DATAQUEUE, (intptr_t)msg); 272 } 273 274 ret = gettimeofday(&main_time, NULL); 275 if (ret != 0) { 276 printf("gettimeofday"); 277 return; 278 } 279 } 280 281 void mrb_target_board_final() 282 { 283 close(sock); 284 } 285 286 void mrb_target_board_break() 287 { 288 raise(SIGUSR1); 878 289 } 879 290 … … 883 294 static mrb_value mrb_target_board_wait_msg(mrb_state *mrb, mrb_value self) 884 295 { 885 TMO timer; 886 SYSTIM now; 887 ER ret, ret2; 888 struct udp_msg *msg; 296 int tmr; 297 struct timeval timer, *ptimer; 298 struct timeval now, elps; 299 int ret, ret2; 300 struct udp_msg _msg; 301 struct udp_msg *msg = &_msg; 889 302 mrb_value arv[3]; 890 static int first = 1; 891 892 mrb_get_args(mrb, "i", &timer); 893 if (timer != TMO_FEVR) 894 timer *= 1000; 895 896 if (first) { 897 first = 0; 898 syslog(LOG_NOTICE, "wait_msg"); 899 } 303 fd_set readfds, writefds, errorfds; 304 305 mrb_get_args(mrb, "i", &tmr); 306 307 if (tmr < 0) 308 ptimer = NULL; 309 else { 310 timer.tv_sec = tmr / 1000; 311 timer.tv_usec = (tmr % 1000) * 1000; 312 ptimer = &timer; 313 } 314 315 FD_ZERO(&readfds); 316 FD_ZERO(&writefds); 317 FD_ZERO(&errorfds); 318 FD_SET(sock, &readfds); 319 FD_SET(sock, &writefds); 320 FD_SET(sock, &errorfds); 900 321 901 322 /* ã¡ãã»ã¼ã¸å¾ 902 323 ã¡ */ 903 ret = trcv_dtq(MRUBY_DATAQUEUE, (intptr_t *)&msg, timer); 904 if ((ret != E_OK) && (ret != E_TMOUT)) { 905 syslog(LOG_ERROR, "trcv_dtq => %d", ret); 324 memset(msg, 0, sizeof(*msg)); 325 ret = select(sock + 1, &readfds, &writefds, &errorfds, ptimer); 326 if (ret < 0) 327 mrb_raise(mrb, E_RUNTIME_ERROR, "socket select error"); 328 if (FD_ISSET(sock, &readfds)) { 329 int fromlen = sizeof(msg->dst); 330 msg->len = recvfrom(sock, msg->buffer, sizeof(msg->buffer), 0, &msg->dst, &fromlen); 331 if (msg->len < 0) { 332 printf("recvfrom %d", msg->len); 333 return mrb_nil_value(); 334 } 335 } 336 337 ret2 = gettimeofday(&now, NULL); 338 if (ret2 != 0) { 339 printf("gettimeofday"); 906 340 return mrb_nil_value(); 907 341 } 908 342 909 ret2 = get_tim(&now); 910 if (ret2 != E_OK) { 911 syslog(LOG_ERROR, "get_tim => %d", ret); 912 return mrb_nil_value(); 913 } 914 915 arv[0] = mrb_fixnum_value((now - mruby_time) / 1000); 916 mruby_time = now; 343 timersub(&now, &main_time, &elps); 344 arv[0] = mrb_fixnum_value(elps.tv_sec); 345 main_time = now; 917 346 918 347 /* ã¿ã¤ã ã¢ã¦ãã®å ´å */ 919 if (ret == E_TMOUT) {348 if (ret == 0) { 920 349 return mrb_ary_new_from_values(mrb, 1, arv); 921 350 } … … 923 352 /* å 924 353 é¨ã¤ãã³ãã®å ´å */ 925 if (msg->dst. ipaddr == 0) {354 if (msg->dst.sin_addr.s_addr == 0) { 926 355 /* Ethernet Link up */ 927 356 if (msg->buffer[0] & IF_FLAG_LINK_UP) { … … 931 360 else if (msg->buffer[0] & IF_FLAG_UP) { 932 361 arv[1] = mrb_fixnum_value(2); 933 }934 else {935 arv[1] = mrb_fixnum_value(0);936 362 } 937 363 … … 967 393 mrb_value rep; 968 394 mrb_value rdat; 969 T_IPV4EP*ep;970 ER_UINTret;395 struct sockaddr_in *ep; 396 int ret; 971 397 972 398 mrb_get_args(mrb, "SS", &rep, &rdat); 973 399 974 if (RSTRING_LEN(rep) != sizeof( T_IPV4EP)) {400 if (RSTRING_LEN(rep) != sizeof(struct sockaddr_in)) { 975 401 mrb_raise(mrb, E_RUNTIME_ERROR, "snd_msg"); 976 402 return mrb_nil_value(); 977 403 } 978 404 979 ep = ( T_IPV4EP*)RSTRING_PTR(rep);980 981 ret = udp_snd_dat(MRUBY_ECNL_UDP_CEPID, ep, RSTRING_PTR(rdat), RSTRING_LEN(rdat), TMO_FEVR);405 ep = (struct sockaddr_in *)RSTRING_PTR(rep); 406 407 ret = sendto(sock, RSTRING_PTR(rdat), RSTRING_LEN(rdat), 0, (struct sockaddr *)ep, sizeof(*ep)); 982 408 if (ret < 0) { 983 mrb_raise(mrb, E_RUNTIME_ERROR, "s nd_msg");409 mrb_raise(mrb, E_RUNTIME_ERROR, "sendto"); 984 410 return mrb_nil_value(); 985 411 } … … 994 420 { 995 421 mrb_value rep; 996 T_IPV4EP*ep;422 struct sockaddr_in *ep; 997 423 998 424 mrb_get_args(mrb, "S", &rep); 999 425 1000 if (RSTRING_LEN(rep) < sizeof( T_IPV4EP)) {426 if (RSTRING_LEN(rep) < sizeof(struct sockaddr_in)) { 1001 427 mrb_raise(mrb, E_RUNTIME_ERROR, "is_local_addr"); 1002 428 return mrb_nil_value(); 1003 429 } 1004 430 1005 ep = ( T_IPV4EP*)RSTRING_PTR(rep);1006 1007 return (ep-> ipaddr == MAKE_IPV4_ADDR(127, 0, 0, 1)) ? mrb_true_value() : mrb_false_value();431 ep = (struct sockaddr_in *)RSTRING_PTR(rep); 432 433 return (ep->sin_addr.s_addr == MAKE_IPV4_ADDR(127, 0, 0, 1)) ? mrb_true_value() : mrb_false_value(); 1008 434 } 1009 435 … … 1014 440 { 1015 441 mrb_value rep; 1016 T_IPV4EP*ep;442 struct sockaddr_in *ep; 1017 443 1018 444 mrb_get_args(mrb, "S", &rep); 1019 445 1020 if (RSTRING_LEN(rep) < sizeof( T_IPV4EP)) {446 if (RSTRING_LEN(rep) < sizeof(struct sockaddr_in)) { 1021 447 mrb_raise(mrb, E_RUNTIME_ERROR, "is_multicast_addr"); 1022 448 return mrb_nil_value(); 1023 449 } 1024 450 1025 ep = ( T_IPV4EP*)RSTRING_PTR(rep);1026 1027 return (ep-> ipaddr == MAKE_IPV4_ADDR(224, 0, 23, 0)) ? mrb_true_value() : mrb_false_value();451 ep = (struct sockaddr_in *)RSTRING_PTR(rep); 452 453 return (ep->sin_addr.s_addr == MAKE_IPV4_ADDR(224, 0, 23, 0)) ? mrb_true_value() : mrb_false_value(); 1028 454 } 1029 455 … … 1034 460 { 1035 461 mrb_value rep1, rep2; 1036 T_IPV4EP*ep1, *ep2;462 struct sockaddr_in *ep1, *ep2; 1037 463 1038 464 mrb_get_args(mrb, "SS", &rep1, &rep2); 1039 465 1040 if ((RSTRING_LEN(rep1) != sizeof( T_IPV4EP)) || (RSTRING_LEN(rep2) != sizeof(T_IPV4EP))) {466 if ((RSTRING_LEN(rep1) != sizeof(struct sockaddr_in)) || (RSTRING_LEN(rep2) != sizeof(struct sockaddr_in))) { 1041 467 mrb_raise(mrb, E_RUNTIME_ERROR, "equals_addr"); 1042 468 return mrb_nil_value(); 1043 469 } 1044 470 1045 ep1 = ( T_IPV4EP*)RSTRING_PTR(rep1);1046 ep2 = ( T_IPV4EP*)RSTRING_PTR(rep2);1047 1048 return (ep1-> ipaddr == ep2->ipaddr) ? mrb_true_value() : mrb_false_value();471 ep1 = (struct sockaddr_in *)RSTRING_PTR(rep1); 472 ep2 = (struct sockaddr_in *)RSTRING_PTR(rep2); 473 474 return (ep1->sin_addr.s_addr == ep2->sin_addr.s_addr) ? mrb_true_value() : mrb_false_value(); 1049 475 } 1050 476 … … 1054 480 static mrb_value mrb_target_board_get_local_addr(mrb_state *mrb, mrb_value self) 1055 481 { 1056 T_IPV4EPep;482 struct sockaddr_in ep; 1057 483 mrb_value rep; 1058 484 1059 ep.ipaddr = MAKE_IPV4_ADDR(127, 0, 0, 1); 1060 ep.portno = 3610; 485 memset(&ep, 0, sizeof(ep)); 486 ep.sin_family = AF_INET; 487 ep.sin_addr.s_addr = MAKE_IPV4_ADDR(127, 0, 0, 1); 488 ep.sin_port = htons(3610); 1061 489 1062 490 rep = mrb_str_new(mrb, (char *)&ep, sizeof(ep)); … … 1070 498 static mrb_value mrb_target_board_get_multicast_addr(mrb_state *mrb, mrb_value self) 1071 499 { 1072 T_IPV4EPep;500 struct sockaddr_in ep; 1073 501 mrb_value rep; 1074 502 1075 ep.ipaddr = MAKE_IPV4_ADDR(224, 0, 23, 0); 1076 ep.portno = 3610; 503 memset(&ep, 0, sizeof(ep)); 504 ep.sin_family = AF_INET; 505 ep.sin_addr.s_addr = MAKE_IPV4_ADDR(224, 0, 23, 0); 506 ep.sin_port = htons(3610); 1077 507 1078 508 rep = mrb_str_new(mrb, (char *)&ep, sizeof(ep)); … … 1083 513 void mrb_mruby_others_gem_init(mrb_state* mrb) 1084 514 { 515 if (!echonet) 516 return; 517 1085 518 _module_target_board = mrb_define_module(mrb, "TargetBoard"); 1086 1087 // mbed Pin Names1088 mrb_define_const(mrb, _module_target_board, "LED1", mrb_fixnum_value(LED1));1089 mrb_define_const(mrb, _module_target_board, "LED2", mrb_fixnum_value(LED2));1090 mrb_define_const(mrb, _module_target_board, "LED3", mrb_fixnum_value(LED3));1091 mrb_define_const(mrb, _module_target_board, "LED4", mrb_fixnum_value(LED4));1092 1093 mrb_define_const(mrb, _module_target_board, "LED_RED", mrb_fixnum_value(LED_RED));1094 mrb_define_const(mrb, _module_target_board, "LED_GREEN", mrb_fixnum_value(LED_GREEN));1095 mrb_define_const(mrb, _module_target_board, "LED_BLUE", mrb_fixnum_value(LED_BLUE));1096 mrb_define_const(mrb, _module_target_board, "LED_USER", mrb_fixnum_value(LED_USER));1097 1098 mrb_define_const(mrb, _module_target_board, "USBTX", mrb_fixnum_value(USBTX));1099 mrb_define_const(mrb, _module_target_board, "USBRX", mrb_fixnum_value(USBRX));1100 1101 // Arduiono Pin Names1102 mrb_define_const(mrb, _module_target_board, "D0", mrb_fixnum_value(D0));1103 mrb_define_const(mrb, _module_target_board, "D1", mrb_fixnum_value(D1));1104 mrb_define_const(mrb, _module_target_board, "D2", mrb_fixnum_value(D2));1105 mrb_define_const(mrb, _module_target_board, "D3", mrb_fixnum_value(D3));1106 mrb_define_const(mrb, _module_target_board, "D4", mrb_fixnum_value(D4));1107 mrb_define_const(mrb, _module_target_board, "D5", mrb_fixnum_value(D5));1108 mrb_define_const(mrb, _module_target_board, "D6", mrb_fixnum_value(D6));1109 mrb_define_const(mrb, _module_target_board, "D7", mrb_fixnum_value(D7));1110 mrb_define_const(mrb, _module_target_board, "D8", mrb_fixnum_value(D8));1111 mrb_define_const(mrb, _module_target_board, "D9", mrb_fixnum_value(D9));1112 mrb_define_const(mrb, _module_target_board, "D10", mrb_fixnum_value(D10));1113 mrb_define_const(mrb, _module_target_board, "D11", mrb_fixnum_value(D11));1114 mrb_define_const(mrb, _module_target_board, "D12", mrb_fixnum_value(D12));1115 mrb_define_const(mrb, _module_target_board, "D13", mrb_fixnum_value(D13));1116 mrb_define_const(mrb, _module_target_board, "D14", mrb_fixnum_value(D14));1117 mrb_define_const(mrb, _module_target_board, "D15", mrb_fixnum_value(D15));1118 1119 mrb_define_const(mrb, _module_target_board, "A0", mrb_fixnum_value(A0));1120 mrb_define_const(mrb, _module_target_board, "A1", mrb_fixnum_value(A1));1121 mrb_define_const(mrb, _module_target_board, "A2", mrb_fixnum_value(A2));1122 mrb_define_const(mrb, _module_target_board, "A3", mrb_fixnum_value(A3));1123 mrb_define_const(mrb, _module_target_board, "A4", mrb_fixnum_value(A4));1124 mrb_define_const(mrb, _module_target_board, "A5", mrb_fixnum_value(A5));1125 1126 mrb_define_const(mrb, _module_target_board, "I2C_SCL", mrb_fixnum_value(I2C_SCL));1127 mrb_define_const(mrb, _module_target_board, "I2C_SDA", mrb_fixnum_value(I2C_SDA));1128 1129 mrb_define_const(mrb, _module_target_board, "USER_BUTTON0", mrb_fixnum_value(USER_BUTTON0));1130 1131 // Not connected1132 mrb_define_const(mrb, _module_target_board, "NC", mrb_fixnum_value(NC));1133 519 1134 520 mrb_define_class_method(mrb, _module_target_board, "wait_msg", mrb_target_board_wait_msg, MRB_ARGS_REQ(1)); … … 1140 526 mrb_define_class_method(mrb, _module_target_board, "get_local_addr", mrb_target_board_get_local_addr, MRB_ARGS_NONE()); 1141 527 mrb_define_class_method(mrb, _module_target_board, "get_multicast_addr", mrb_target_board_get_multicast_addr, MRB_ARGS_NONE()); 528 529 mrb_target_board_init(); 1142 530 } 1143 531 1144 532 void mrb_mruby_others_gem_final(mrb_state* mrb) 1145 533 { 1146 } 534 if (!echonet) 535 return; 536 537 mrb_target_board_final(); 538 } 539 540 // Provide implementation of _sbrk (low-level dynamic memory allocation 541 // routine) for GCC_ARM which compares new heap pointer with MSP instead of 542 // SP. This make it compatible with RTX RTOS thread stacks. 543 544 // Linker defined symbol used by _sbrk to indicate where heap should start. 545 int _end; 546 uint32_t _stack; 547 548 // Turn off the errno macro and use actual global variable instead. 549 #undef errno 550 int errno; 551 552 static unsigned char* heap = (unsigned char*)&_end; 553 554 // Dynamic memory allocation related syscall. 555 caddr_t _sbrk(int incr) { 556 unsigned char* prev_heap = heap; 557 unsigned char* new_heap = heap + incr; 558 559 if (new_heap >= (unsigned char*)&_stack) { /* _stack is end of heap section */ 560 errno = ENOMEM; 561 return (caddr_t)-1; 562 } 563 564 heap = new_heap; 565 return (caddr_t) prev_heap; 566 } 567 568 char *optarg; 569 int _data, _mdata, _edata; 570 int _bss, _ebss; 571 572 int _PowerON_Reset(int argc, char **argv) 573 { 574 memcpy(&_data, &_mdata, (size_t)&_edata - (size_t)&_data); 575 memset(&_bss, 0, (size_t)&_ebss - (size_t)&_bss); 576 577 optarg = *argv; 578 return main(argc, argv); 579 } 580 581 #define FVECT_SECT __attribute__ ((section (".fvectors"))) 582 const void *HardwareVectors[] FVECT_SECT = { 583 _PowerON_Reset, 584 mrdb_break, 585 }; 586 587 char stack_space[0x100000] __attribute__ ((section (".stack")));
Note:
See TracChangeset
for help on using the changeset viewer.