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; }
static int ethernet_recv(struct netbuf *pkt) { struct ethernet_header *ethhdr = (struct ethernet_header *)pkt->top; if (!initialized) return 0; if (!(ethhdr->dst_addr[0] & 1) && memcmp(ethhdr->dst_addr, my_macaddr, MACADDR_SIZE)) return 0; pkt->top += ETHERNET_HEADER_SIZE; pkt->size -= ETHERNET_HEADER_SIZE; switch (ethhdr->type) { case ETHERNET_TYPE_ARP: pkt->cmd = ARP_CMD_RECV; kz_send(MSGBOX_ID_ARPPROC, 0, (char *)pkt); break; case ETHERNET_TYPE_IP: pkt->cmd = IP_CMD_RECV; kz_send(MSGBOX_ID_IPPROC, 0, (char *)pkt); break; default: return 0; } return 1; }
static void arp_flush(int count) { struct netbuf *pkt; struct addrset *addr; while (1) { kz_recv(MSGBOX_ID_ARPPKTLIST, NULL, (void *)&pkt); if (pkt == NULL) { kz_send(MSGBOX_ID_ARPPKTLIST, 0, NULL); break; } addr = arp_getaddr(pkt->option.ethernet.send.dst_ipaddr); if (addr) { addr = (count == 0) ? NULL : addr; count = (count > 0) ? (count - 1) : count; } if (addr == NULL) { kz_send(MSGBOX_ID_ARPPKTLIST, 0, (char *)pkt); continue; } memcpy(pkt->option.ethernet.send.dst_macaddr, addr->macaddr, MACADDR_SIZE); pkt->cmd = ETHERNET_CMD_SEND; kz_send(MSGBOX_ID_ETHPROC, 0, (char *)pkt); } }
static int ethernet_send(struct netbuf *pkt) { struct ethernet_header *ethhdr; /* 送信先MACアドレスが不明なので,ARPタスクに転送して解決してもらう */ if (!memcmp(pkt->option.ethernet.send.dst_macaddr, "\x00\x00\x00\x00\x00\x00", MACADDR_SIZE)) { pkt->cmd = ARP_CMD_SEND; kz_send(MSGBOX_ID_ARPPROC, 0, (char *)pkt); return 1; } pkt->cmd = NETDRV_CMD_SEND; pkt->top -= ETHERNET_HEADER_SIZE; pkt->size += ETHERNET_HEADER_SIZE; ethhdr = (struct ethernet_header *)pkt->top; memcpy(ethhdr->dst_addr, pkt->option.ethernet.send.dst_macaddr, MACADDR_SIZE); memcpy(ethhdr->src_addr, my_macaddr, MACADDR_SIZE); ethhdr->type = pkt->option.ethernet.send.type; kz_send(MSGBOX_ID_NETPROC, 0, (char *)pkt); return 1; }
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 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; }
void ipc_display_clear(void) { char *p; p = kz_kmalloc(1); p[0] = DISPLAY_CMD_LCD_CLEAR; kz_send(MSGBOX_ID_DISPLAY, 1, p); }
static struct addrset *arp_getaddr(uint32 ipaddr) { struct addrset *addr, *ret = NULL; while (1) { kz_recv(MSGBOX_ID_ARPADRLIST, NULL, (void *)&addr); if (addr == NULL) { /* 終端まできた */ kz_send(MSGBOX_ID_ARPADRLIST, 0, NULL); break; } if (addr->ipaddr == ipaddr) { ret = addr; } kz_send(MSGBOX_ID_ARPADRLIST, 0, (char *)addr); } return ret; }
void ipc_display_led_toggle(int target) { char *p; p = kz_kmalloc(2); p[0] = DISPLAY_CMD_LED_TOGGLE; p[1] = '0' + target; kz_send(MSGBOX_ID_DISPLAY, 2, p); }
void ipc_display_led_write(int target, int state) { char *p; p = kz_kmalloc(2); p[0] = state ? DISPLAY_CMD_LED_ON : DISPLAY_CMD_LED_OFF; p[1] = '0' + target; kz_send(MSGBOX_ID_DISPLAY, 2, p); }
/* tftpの開始をtftpタスクに依頼する */ static void send_tftp() { struct netbuf *buf; buf = kz_kmalloc(sizeof(*buf)); buf->cmd = TFTP_CMD_START; buf->option.tftp.start.ipaddr = 0xc0a80a01; /* 192.168.10.1 */ kz_send(MSGBOX_ID_TFTP, 0, (char *)buf); }
static void send_close(int number) { struct netbuf *buf; buf = kz_kmalloc(sizeof(*buf)); buf->cmd = TCP_CMD_CLOSE; buf->option.tcp.close.number = number; kz_send(MSGBOX_ID_TCPPROC, 0, (char *)buf); }
/* タイマのカウント開始をタイマ・ドライバに依頼する */ static void send_start(int msec) { struct timerreq *req; req = kz_kmalloc(sizeof(*req)); req->id = MSGBOX_ID_CONSINPUT; req->msec = msec; kz_send(MSGBOX_ID_TIMDRIVE, TIMERDRV_CMD_START, (char *)req); }
/* pingの開始をicmpタスクに依頼する */ static void send_icmp() { struct netbuf *buf; buf = kz_kmalloc(sizeof(*buf)); buf->cmd = ICMP_CMD_SEND; buf->option.icmp.send.number = 3; buf->option.icmp.send.ipaddr = 0xc0a80a01; /* 192.168.10.1 */ kz_send(MSGBOX_ID_ICMPPROC, 0, (char *)buf); }
static void send_accept() { struct netbuf *buf; buf = kz_kmalloc(sizeof(*buf)); buf->cmd = TCP_CMD_ACCEPT; buf->option.tcp.accept.id = MSGBOX_ID_HTTPD; buf->option.tcp.accept.port = 80; kz_send(MSGBOX_ID_TCPPROC, 0, (char *)buf); }
/* コンソール・ドライバの使用開始をコンソール・ドライバに依頼する */ static void send_use(int index) { char *p; p = kz_kmalloc(3); p[0] = '0'; p[1] = CONSDRV_CMD_USE; p[2] = '0' + index; kz_send(MSGBOX_ID_CONSOUTPUT, 3, p); }
void ipc_display_draw_logo(int x, int y, int size) { char *p; p = kz_kmalloc(4); p[0] = DISPLAY_CMD_LCD_DRAW_LOGO; p[1] = x; p[2] = y; p[3] = size; kz_send(MSGBOX_ID_DISPLAY, 4, p); }
/* コンソールへの文字列出力をコンソール・ドライバに依頼する */ static void send_write(char *str) { char *p; int len; len = strlen(str); p = kz_kmalloc(len + 2); p[0] = '0'; p[1] = CONSDRV_CMD_WRITE; memcpy(&p[2], str, len); kz_send(MSGBOX_ID_CONSOUTPUT, len + 2, p); }
static void send_write(int number, int size, char *data) { struct netbuf *buf; buf = kz_kmalloc(DEFAULT_NETBUF_SIZE); memset(buf, 0, DEFAULT_NETBUF_SIZE); buf->cmd = TCP_CMD_SEND; buf->top = buf->data; buf->size = size; buf->option.tcp.send.number = number; memcpy(buf->top, data, size); kz_send(MSGBOX_ID_TCPPROC, 0, (char *)buf); }
void ipc_display_draw_box(int x1, int y1, int x2, int y2, int on) { char *p; p = kz_kmalloc(6); p[0] = DISPLAY_CMD_LCD_DRAW_BOX; p[1] = x1; p[2] = y1; p[3] = x2; p[4] = y2; p[5] = !on; kz_send(MSGBOX_ID_DISPLAY, 6, p); }
void ipc_display_draw_text(int x, int y, char *str) { char *p; int len; len = strlen(str); p = kz_kmalloc(3 + len + 1); p[0] = DISPLAY_CMD_LCD_DRAW_TEXT; p[1] = x; p[2] = y; memcpy(&p[3], str, len); p[3 + len] = '\0'; kz_send(MSGBOX_ID_DISPLAY, 3 + len + 1, p); }
static int send_use(serial_port port) { #define LEN 3 char * buffer = kz_kmalloc(LEN); buffer[0] = '0'; buffer[1] = CONSDRV_CMD_USE; buffer[2] = (char)('0' + get_port_index_from(port)); kz_send(MSGBOX_ID_CONSOUTPUT, LEN, buffer); #undef LEN 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); /* 送信 */ puts("test11_1 send out.\n"); /* メモリ解放は受信側で行うので,ここでは不要 */ puts("test11_1 exit.\n"); return 0; }
static int send_write(cString str) { char * buffer; int len = strlen(str) + 2; buffer = (char *)kz_kmalloc(len); buffer[0] = '0'; buffer[1] = (char)CONSDRV_CMD_WRITE; memcpy(&(buffer[2]), str, len); kz_send(MSGBOX_ID_CONSOUTPUT, len, buffer); return len; }
void ipc_display_draw_progressbar( int x1, int y1, int x2, int y2, int min, int max, int value) { char *p; p = kz_kmalloc(8); p[0] = DISPLAY_CMD_LCD_DRAW_PBAR; p[1] = x1; p[2] = y1; p[3] = x2; p[4] = y2; p[5] = min; p[6] = max; p[7] = value; kz_send(MSGBOX_ID_DISPLAY, 8, p); }
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; }
static struct addrset *arp_setaddr(uint32 ipaddr, uint8 macaddr[]) { struct addrset *addr; addr = arp_getaddr(ipaddr); if (addr == NULL) { addr = kz_kmalloc(sizeof(*addr)); memset(addr, 0, sizeof(*addr)); addr->ipaddr = ipaddr; kz_send(MSGBOX_ID_ARPADRLIST, 0, (char *)addr); /* * 終端のターミネータのさらに後に追加したので,もう一度一周させて * ターミネータが終端にくるようにする. */ arp_getaddr(ipaddr); } memcpy(addr->macaddr, macaddr, MACADDR_SIZE); return addr; }
static int arp_send(struct netbuf *pkt) { struct addrset *addr; kz_send(MSGBOX_ID_ARPPKTLIST, 0, (char *)pkt); arp_flush(0); /* 終端に追加したので1周させ頭出しを行う */ addr = arp_getaddr(pkt->option.ethernet.send.dst_ipaddr); if (addr) { arp_flush(-1); } else { /* ARP request を送信 */ arp_sendpkt(ARP_OPERATION_REQUEST, NULL, pkt->option.ethernet.send.dst_ipaddr); } return 1; }
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; }
/* スレッドからの要求を処理する */ static int netdrv_proc(struct netbuf *buf) { switch (buf->cmd) { case NETDRV_CMD_USE: /* イーサネット・ドライバの使用開始 */ /* rtl8019_init(0, my_macaddr); */ /* netdrv_init()で行っているので不要 */ rtl8019_intr_enable(0); /* 受信割込み有効化(受信開始) */ buf = kz_kmalloc(sizeof(*buf)); buf->cmd = ETHERNET_CMD_MACADDR; memcpy(buf->option.common.macaddr.addr, my_macaddr, MACADDR_SIZE); kz_send(MSGBOX_ID_ETHPROC, 0, (char *)buf); break; case NETDRV_CMD_SEND: /* イーサネットへのフレーム出力 */ rtl8019_send(0, buf->size, buf->top); break; default: break; } return 0; }