int test10_1_main(int argc, char *argv[]) { char *p1, *p2; int i, j; puts("test10_1 started.\n"); for (i = 4; i <= 56; i += 4) { p1 = kz_kmalloc(i); p2 = kz_kmalloc(i); for (j = 0; j < i - 1; j++) { p1[j] = 'a'; p2[j] = 'b'; } p1[j] = '\0'; p2[j] = '\0'; putxval((unsigned long)p1, 8); puts(" "); puts(p1); puts("\n"); putxval((unsigned long)p2, 8); puts(" "); puts(p2); puts("\n"); kz_kmfree(p1); kz_kmfree(p2); } puts("test10_1 exit.\n"); return 0; }
int test11_2_main( int argc, char* argv[] ) { char* p; int size; puts("test11_2 started.\n"); puts("test11_2 send in.\n"); kz_send(MSGBOX_ID_MSGBOX1, 15, "static memory\n"); puts("test11_2 send out.\n"); p = kz_kmalloc(18); strcpy(p, "allocated memory\n"); puts("test11_2 send in.\n"); kz_send(MSGBOX_ID_MSGBOX1, 18, p); puts("test11_2 send out.\n"); puts("test11_2 recv in.\n"); kz_recv(MSGBOX_ID_MSGBOX2, &size, &p); puts("test11_2 recv out.\n"); puts(p); puts("test11_2 recv in.\n"); kz_recv(MSGBOX_ID_MSGBOX2, &size, &p); puts("test11_2 recv out.\n"); puts(p); kz_kmfree(p); puts("test11_2 exit.\n"); return 0; }
int command_main(int argc, char * argv[]) { unsigned int size; char * str; send_use(SERIAL_DEFAULT_DEVICE); while(True) { send_write("command> "); kz_recv(MSGBOX_ID_CONSINPUT, &size, &str); str[size] = '\0'; if( strncmp((cString)str, "echo ", 5) == Same ) { send_write((str + 5)); send_write("\n"); } else { send_write("unkown\n"); } kz_kmfree(str); } return EXIT_SUCCESS; }
int test11_1_main(int argc, char *argv[]) { char *p; int size; puts("test11_1 started.\n"); /* 静的領域を受信 */ puts("test11_1 recv in.\n"); kz_recv(MSGBOX_ID_MSGBOX1, &size, &p); puts("test11_1 recv out.\n"); puts(p); /* 動的に確保した領域を受信 */ puts("test11_1 recv in.\n"); kz_recv(MSGBOX_ID_MSGBOX1, &size, &p); puts("test11_1 recv out.\n"); puts(p); kz_kmfree(p); /* 静的領域を送信 */ puts("test11_1 send in.\n"); kz_send(MSGBOX_ID_MSGBOX2, 15, "static memory\n"); puts("test11_1 send out.\n"); /* 動的領域を送信 */ p = kz_kmalloc(18); strcpy(p, "allocated memory\n"); puts("test11_1 send in.\n"); kz_send(MSGBOX_ID_MSGBOX2, 18, p); pust("test11_1 send out.\n"); puts("test11_1 exit.\n"); return 0; }
int command_main(int argc, char *argv[]) { char *p; int size; send_use(SERIAL_DEFAULT_DEVICE); while (1) { send_write("command> "); /* プロンプト表示 */ /* コンソールからの受信文字列を受け取る */ kz_recv(MSGBOX_ID_CONSINPUT, &size, &p); p[size] = '\0'; if (!strncmp(p, "echo", 4)) { /* echoコマンド */ send_write(p + 4); /* echoに続く文字列を出力する */ send_write("\n"); } else { send_write("unknown.\n"); } kz_kmfree(p); } return 0; }
static int command_terminate( char *cmd[COMMAND_WORD_NUM] ) { int i; for( i = 0; i < COMMAND_WORD_NUM; i++ ){ kz_kmfree( cmd[i] ); } return 0; }
/* スレッドからの要求を処理する */ static int display_cmdproc(char *p) { int cmd = p[0]; switch (cmd) { case DISPLAY_CMD_LCD_CLEAR: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_CLEAR); sg12232c_clear(); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_CLEAR); break; case DISPLAY_CMD_LCD_DRAW_BOX: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWBOX); sg12232c_draw_box(p[1], p[2], p[3], p[4], p[5]); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWBOX); break; case DISPLAY_CMD_LCD_DRAW_LOGO: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWLOGO); draw_logo(p[1], p[2], p[3]); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWLOGO); break; case DISPLAY_CMD_LCD_DRAW_TEXT: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWTEXT); sg12232c_draw_string(p[1], p[2], &p[3], 0); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWTEXT); break; case DISPLAY_CMD_LCD_DRAW_PBAR: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWPROG); sg12232c_draw_progressbar( p[1], p[2], p[3], p[4], p[5], p[6], p[7], 0); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWPROG); break; case DISPLAY_CMD_LED_ON: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDON); led_write(p[1] - '0', LedOn); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDON); break; case DISPLAY_CMD_LED_OFF: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDOFF); led_write(p[1] - '0', LedOff); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDOFF); break; case DISPLAY_CMD_LED_TOGGLE: NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDTOGGLE); led_toggle(p[1] - '0'); NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDTOGGLE); break; default: break; } kz_kmfree(p); return 0; }
int func_read(char *buf, int cnt) { int i; for (i = 0; i < cnt; i++) { char *p; int size; /* コンソールからの受信文字列を受け取る */ kz_recv(MSGBOX_ID_CONSINPUT, &size, &p); buf[i] = p[0]; kz_kmfree(p); } return 0; }
int command_main(int argc, char *argv[]) { char *p; int size; int num = 0; char *cmd[COMMAND_WORD_NUM]; int cmd_len = 0; int i, j; send_use(SERIAL_DEFAULT_DEVICE); command_init( cmd ); file_init(); while (1) { send_write("command> "); /* プロンプト表示 */ /* コマンド格納バッファを0クリアする */ for( j = 0; j < COMMAND_WORD_NUM; j++ ){ memset( cmd[j], 0, COMMAND_WORD_LENGTH ); } /* コンソールからの受信文字列を受け取る */ kz_recv(MSGBOX_ID_CONSINPUT, &size, &p); p[size] = '\0'; /* 入力文字列を分解する */ if( ( num = command_split( p, cmd ) ) == 0 ){ send_write("input nothing\n"); continue; } /* コマンドの実行 */ cmd_len = strlen( cmd[0] ); for( i = 0; command_table[i].cmd != NULL; i++ ){ if( !strncmp( cmd[0], command_table[i].cmd, (cmd_len>command_table[i].size?cmd_len:command_table[i].size) ) ){ command_table[i].func( num, cmd ); break; } } if( command_table[i].cmd == NULL ){ send_write("unknown.\n"); } kz_kmfree(p); } command_terminate( cmd ); return 0; }
int netdrv_main(int argc, char *argv[]) { struct netbuf *buf; netdrv_init(); kz_setintr(SOFTVEC_TYPE_ETHINTR, netdrv_intr); /* 割込みハンドラ設定 */ while (1) { kz_recv(MSGBOX_ID_NETPROC, NULL, (char **)&buf); netdrv_proc(buf); kz_kmfree(buf); } return 0; }
int command_main(int argc, char *argv[]) { char *p; int size; long prev_time; send_use(SERIAL_DEFAULT_DEVICE); while (1) { send_write("command> "); /* プロンプト表示 */ /* コンソールからの受信文字列を受け取る */ kz_recv(MSGBOX_ID_CONSINPUT, &size, &p); if (p == NULL) { send_write("expired.\n"); continue; } p[size] = '\0'; if (!strncmp(p, "echo", 4)) { /* echoコマンド */ send_write(p + 4); /* echoに続く文字列を出力する */ send_write("\n"); } else if (!strncmp(p, "timer", 5)) { /* timerコマンド */ send_write("timer start.\n"); send_start(1000); } else if (!strncmp(p, "ping", 4)) { /* pingコマンド */ send_write("ping start.\n"); send_icmp(); } else if (!strncmp(p, "tftp", 4)) { /* tftpコマンド */ send_write("tftp start.\n"); send_tftp(); } else if (!strncmp(p, "debug", 5)) { /* デバッガ起動 */ set_debug_traps(); force_break(); } else if (!strncmp(p, "call", 4)) { /* ダミー関数の呼び出し */ send_write(func(p + 4)); } else if (!strncmp(p, "get", 3)) { /* get */ prev_time = get_time(); putxval(prev_time, 8); puts("\n"); } else { send_write("unknown.\n"); } kz_kmfree(p); } return 0; }
int arp_main(int argc, char *argv[]) { struct netbuf *buf; int ret; kz_send(MSGBOX_ID_ARPADRLIST, 0, NULL); kz_send(MSGBOX_ID_ARPPKTLIST, 0, NULL); while (1) { kz_recv(MSGBOX_ID_ARPPROC, NULL, (void *)&buf); ret = arp_proc(buf); if (!ret) kz_kmfree(buf); } return 0; }
int httpd_main(int argc, char *argv[]) { char *p = NULL, *r; char *buffer; int number = 0, ret; struct netbuf *buf; send_accept(); buffer = kz_kmalloc(DEFAULT_NETBUF_SIZE); while (1) { kz_recv(MSGBOX_ID_HTTPD, NULL, (void *)&buf); switch (buf->cmd) { case TCP_CMD_ESTAB: number = buf->option.tcp.establish.number; p = buffer; break; case TCP_CMD_CLOSE: number = 0; send_accept(); break; case TCP_CMD_RECV: memcpy(p, buf->top, buf->size); p += buf->size; *p = '\0'; r = strchr(buffer, '\n'); if (r) { *r = '\0'; r++; ret = parse(number, buffer); memmove(buffer, r, p - r + 1); p -= (r - buffer); if (ret) send_close(number); } break; } kz_kmfree(buf); } return 0; }
int ethernet_main(int argc, char *argv[]) { struct netbuf *buf; int ret; buf = kz_kmalloc(sizeof(*buf)); buf->cmd = NETDRV_CMD_USE; kz_send(MSGBOX_ID_NETPROC, 0, (char *)buf); while (1) { kz_recv(MSGBOX_ID_ETHPROC, NULL, (char **)&buf); ret = ethernet_proc(buf); if (!ret) kz_kmfree(buf); } return 0; }
int consdrv_main(int argc, char *argv[]) { int size, index; kz_thread_id_t id; char *p; consdrv_init(); kz_setintr(SOFTVEC_TYPE_SERINTR, consdrv_intr); /* 割込みハンドラ設定 */ while (1) { id = kz_recv(MSGBOX_ID_CONSOUTPUT, &size, &p); index = p[0] - '0'; consdrv_command(&consreg[index], id, index, size - 1, p + 1); kz_kmfree(p); } return 0; }
int icmp_main(int argc, char *argv[]) { struct netbuf *buf; int ret; buf = kz_kmalloc(sizeof(*buf)); buf->cmd = IP_CMD_REGPROTO; buf->option.ip.regproto.protocol = IP_PROTOCOL_ICMP; buf->option.ip.regproto.cmd = ICMP_CMD_RECV; buf->option.ip.regproto.id = MSGBOX_ID_ICMPPROC; kz_send(MSGBOX_ID_IPPROC, 0, (char *)buf); while (1) { kz_recv(MSGBOX_ID_ICMPPROC, NULL, (void *)&buf); ret = icmp_proc(buf); if (!ret) kz_kmfree(buf); } return 0; }
int test11_1_main(int argc, char *argv[]) { char *p; int size; puts("test11_1 started.\n"); /* 静的領域をメッセージで受信 */ puts("test11_1 recv in.\n"); kz_recv(MSGBOX_ID_MSGBOX1, &size, &p); /* 受信 */ puts("test11_1 recv out.\n"); puts(p); /* 動的に獲得した領域をメッセージで受信 */ puts("test11_1 recv in.\n"); kz_recv(MSGBOX_ID_MSGBOX1, &size, &p); /* 受信 */ puts("test11_1 recv out.\n"); puts(p); kz_kmfree(p); /* メモリ解放 */ /* 静的領域をメッセージで送信 */ puts("test11_1 send in.\n"); kz_send(MSGBOX_ID_MSGBOX2, 15, "static memory\n"); /* 送信 */ puts("test11_1 send out.\n"); /* 動的に獲得した領域をメッセージで送信 */ p = kz_kmalloc(18); /* メモリ獲得 */ strcpy(p, "allocated memory\n"); puts("test11_1 send in.\n"); kz_send(MSGBOX_ID_MSGBOX2, 18, p); /* 送信 */ puts("test11_1 send out.\n"); /* メモリ解放は受信側で行うので,ここでは不要 */ puts("test11_1 exit.\n"); return 0; }