示例#1
0
/* スレッドからの要求を処理する */
static int consdrv_command(struct consreg *cons, kz_thread_id_t id,
    int index, int size, char *command)
{
  switch (command[0]) {
    case CONSDRV_CMD_USE: /* コンソール・ドライバの使用開始 */
      cons->id = id;
      cons->index = command[1] - '0';
      cons->send_buf = kz_kmalloc(CONS_BUFFER_SIZE);
      cons->recv_buf = kz_kmalloc(CONS_BUFFER_SIZE);
      cons->send_len = 0;
      cons->recv_len = 0;
      serial_init(cons->index);
      serial_intr_recv_enable(cons->index); /* 受信割込み有効化(受信開始) */
      break;

    case CONSDRV_CMD_WRITE: /* コンソールへの文字列出力 */
      /*
       * send_string()では送信バッファを操作しており再入不可なので,
       * 排他のために割込み禁止にして呼び出す.
       */
      INTR_DISABLE;
      send_string(cons, command + 1, size - 1); /* 文字列の送信 */
      INTR_ENABLE;
      break;

    default:
      break;
  }

  return 0;
}
示例#2
0
文件: test10_1.c 项目: katono/kozos
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_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;
}
示例#4
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;
}
示例#5
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);
}
示例#6
0
文件: command.c 项目: issy-kn/kozos
/* 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);
}
示例#7
0
文件: command.c 项目: issy-kn/kozos
/* タイマのカウント開始をタイマ・ドライバに依頼する */
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);
}
示例#8
0
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);
}
示例#9
0
文件: httpd.c 项目: forest1040/kozos
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);
}
示例#10
0
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);
}
示例#11
0
文件: command.c 项目: issy-kn/kozos
/* 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);
}
示例#12
0
/* コンソール・ドライバの使用開始をコンソール・ドライバに依頼する */
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);
}
示例#13
0
文件: httpd.c 项目: forest1040/kozos
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);
}
示例#14
0
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);
}
示例#15
0
文件: command.c 项目: tkysnj/myosmeta
static int command_init( char *cmd[COMMAND_WORD_NUM] )
{
  int i;

  cmd[0] = (char *)kz_kmalloc( COMMAND_BUFF_SIZE );
  for( i = 0; i < COMMAND_WORD_NUM-1; i++ ){
    cmd[i+1] = cmd[i] + COMMAND_WORD_LENGTH;
  }

  return 0;
}
示例#16
0
/* コンソールへの文字列出力をコンソール・ドライバに依頼する */
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);
}
示例#17
0
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);
}
示例#18
0
文件: httpd.c 项目: forest1040/kozos
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);
}
示例#19
0
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);
}
示例#20
0
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;
}
示例#21
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;
}
示例#22
0
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);
}
示例#23
0
文件: httpd.c 项目: forest1040/kozos
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;
}
示例#24
0
文件: ethernet.c 项目: nekogigi/kozos
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;
}
示例#25
0
文件: arp.c 项目: forest1040/kozos
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;
}
示例#26
0
文件: icmp.c 项目: forest1040/kozos
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;
}
示例#27
0
文件: netdrv.c 项目: nekogigi/kozos
/* スレッドからの要求を処理する */
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;
}
示例#28
0
文件: arp.c 项目: forest1040/kozos
static int arp_sendpkt(uint16 operation, uint8 macaddr[], uint32 ipaddr)
{
  struct netbuf *pkt;
  struct arp_header *arphdr;
  uint32 ipaddr_n;

  pkt = kz_kmalloc(DEFAULT_NETBUF_SIZE);
  memset(pkt, 0, DEFAULT_NETBUF_SIZE);
  pkt->cmd = ETHERNET_CMD_SEND;
  pkt->top = pkt->data + 64;
  pkt->size = sizeof(struct arp_header);

  arphdr = (struct arp_header *)pkt->top;

  arphdr->hardware = hton2(ARP_HARDWARE_ETHER);
  arphdr->protocol = hton2(ETHERNET_TYPE_IP);
  arphdr->macaddr_size = MACADDR_SIZE;
  arphdr->ipaddr_size = IPADDR_SIZE;
  arphdr->operation = hton2(operation);

  memcpy(arphdr->sender_macaddr, my_macaddr, MACADDR_SIZE);
  ipaddr_n = hton4(my_ipaddr);
  memcpy(arphdr->sender_ipaddr, &ipaddr_n, IPADDR_SIZE);
  memcpy(arphdr->target_macaddr,
	 (macaddr ? macaddr : (uint8 *)"\x00\x00\x00\x00\x00\x00"),
	 MACADDR_SIZE);
  ipaddr_n = hton4(ipaddr);
  memcpy(arphdr->target_ipaddr, &ipaddr_n, IPADDR_SIZE);

  memcpy(pkt->option.ethernet.send.dst_macaddr,
	 (macaddr ? macaddr : (uint8 *)"\xff\xff\xff\xff\xff\xff"),
	 MACADDR_SIZE);
  pkt->option.ethernet.send.type = ETHERNET_TYPE_ARP;

  kz_send(MSGBOX_ID_ETHPROC, 0, (char *)pkt);

  return 0;
}
示例#29
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;
}
示例#30
0
文件: icmp.c 项目: forest1040/kozos
static int icmp_sendpkt(uint32 ipaddr, uint8 type, uint8 code, uint16 id,
			uint16 sequence_number, int datasize, char *data)
{
  struct netbuf *pkt;
  struct icmp_header *icmphdr;
  int i;
  char c;

  pkt = kz_kmalloc(DEFAULT_NETBUF_SIZE);
  memset(pkt, 0, DEFAULT_NETBUF_SIZE);

  pkt->cmd = IP_CMD_SEND;
  pkt->top = pkt->data + 64;
  pkt->size = sizeof(struct icmp_header) + datasize;

  icmphdr = (struct icmp_header *)pkt->top;
  icmphdr->type = type;
  icmphdr->code = code;
  icmphdr->param.id = hton2(id);
  icmphdr->param.sequence_number = hton2(sequence_number);

  for (i = 0; i < datasize; i++) {
    c = data ? data[i] : (i & 0xff);
    ((char *)icmphdr + sizeof(*icmphdr))[i] = c;
  }

  icmphdr->checksum = 0;
  icmphdr->checksum = hton2(ip_calc_checksum(pkt->size, icmphdr));

  pkt->option.ip.send.protocol = IP_PROTOCOL_ICMP;
  pkt->option.ip.send.dst_addr = ipaddr;

  kz_send(MSGBOX_ID_IPPROC, 0, (char *)pkt);

  return 0;
}