示例#1
0
int
main(void)
{
  u2_init();

  putstr("\nFactory Test, Board Rev 3.0\n");

  bool ok = true;
  unsigned char maj = HW_REV_MAJOR;
  unsigned char min = HW_REV_MINOR;
  ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_REV_MSB, &maj, 1);
  ok &= eeprom_write(I2C_ADDR_MBOARD, MBOARD_REV_LSB, &min, 1);

  putstr("\nset_hw_rev\n");
  if (ok)
    printf("OK: set h/w rev to %d.%d\n", HW_REV_MAJOR, HW_REV_MINOR);
  else {
    printf("FAILED to set h/w rev to %d.%d\n", HW_REV_MAJOR, HW_REV_MINOR);
    hal_finish();
    return 0;
  }

  if(test_sd())
    puts("SD OK\n");
  else {
    puts("SD FAIL\n");
    //hal_finish();
    //return 0;
  }
  if(test_ram())
    puts("RAM OK\n");
  else {
    puts("RAM FAIL\n");
    hal_finish();
    return 0;
  }

  print_mac_addr(ethernet_mac_addr()->addr);
  newline();

  clocks_mimo_config(MC_WE_LOCK_TO_SMA);

  while (!clocks_lock_detect()) {
    puts("No Lock");
    mdelay(1000);
  }
  puts("Clock Locked\n");

}
示例#2
0
int
dispose(dgram *dg) {
	int result;
	int dstport;
	switch (dg->prot) {
	case ETH:
		result = print_mac_addr(dg->buff);
		break;
	case ETHERTYPE_IP:
		result = print_ip_addr(dg->buff);
		break;
	case IPPROTO_TCP:
		printf("tcp包\n");
		result = print_tcp_udp_port(dg->buff);
		break;
	case IPPROTO_UDP:
		printf("udp包\n");
		result = print_tcp_udp_port(dg->buff);
		dstport = dg->buff[2];
		dstport <<= 8;
		dstport |= dg->buff[3];
		break;
	case IPPROTO_ICMP:
		printf("icmp包\n");
		result = 1;
		break;
	case HTTP:
		printf("http包\n");
		result = 1;
		break;
	default:
		printf("Unkown protocol.\n");
		result = 0;
		break;
	}
	if ((IPPROTO_UDP == dg->prot) && DEFAULT_PORT == dstport) {
		printf("%d端口来访!!!\n", DEFAULT_PORT);
		if(output_dgram(dg) == 0) {
			fprintf(stderr, "%s\n", strerror(errno));
			exit(1);
		}
	}
	return result;
}
示例#3
0
文件: txrx_uhd.c 项目: GREO/uhd
int
main(void)
{
  u2_init();
#ifdef BOOTLOADER
  putstr("\nUSRP N210 UDP bootloader\n");
#else
  putstr("\nTxRx-UHD-ZPU\n");
#endif
  printf("FPGA compatibility number: %d\n", USRP2_FPGA_COMPAT_NUM);
  printf("Firmware compatibility number: %d\n", USRP2_FW_COMPAT_NUM);
  
#ifdef BOOTLOADER
  //load the production FPGA image or firmware if appropriate
  do_the_bootload_thing();
  //if we get here we've fallen through to safe firmware
  set_default_mac_addr();
  set_default_ip_addr();
#endif

  print_mac_addr(ethernet_mac_addr()); newline();
  print_ip_addr(get_ip_addr()); newline();

  //1) register the addresses into the network stack
  register_addrs(ethernet_mac_addr(), get_ip_addr());
  pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_DSP0_PORT);

  //2) register callbacks for udp ports we service
  init_udp_listeners();
  register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet);
  register_udp_listener(USRP2_UDP_DSP0_PORT, handle_udp_data_packet);
  register_udp_listener(USRP2_UDP_ERR0_PORT, handle_udp_data_packet);
  register_udp_listener(USRP2_UDP_DSP1_PORT, handle_udp_data_packet);
#ifdef USRP2P
  register_udp_listener(USRP2_UDP_UPDATE_PORT, handle_udp_fw_update_packet);
#endif

  //3) set the routing mode to slave to set defaults
  pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE);

  //4) setup ethernet hardware to bring the link up
  ethernet_register_link_changed_callback(link_changed_callback);
  ethernet_init();

  while(true){

    size_t num_lines;
    void *buff = pkt_ctrl_claim_incoming_buffer(&num_lines);
    if (buff != NULL){
        handle_inp_packet((uint32_t *)buff, num_lines);
        pkt_ctrl_release_incoming_buffer();
    }

    pic_interrupt_handler();
    int pending = pic_regs->pending;		// poll for under or overrun

    if (pending & PIC_UNDERRUN_INT){
      pic_regs->pending = PIC_UNDERRUN_INT;	// clear interrupt
      putchar('U');
    }

    if (pending & PIC_OVERRUN_INT){
      pic_regs->pending = PIC_OVERRUN_INT;	// clear interrupt
      putchar('O');
    }
  }
}
示例#4
0
文件: factory_test.c 项目: jinjoh/SDR
int
main(void)
{
  u2_init();

  putstr("\nFactory Test\n");

  print_mac_addr(ethernet_mac_addr()->addr);
  newline();

  if(test_sd())
    puts("SD OK\n");
  else {
    puts("SD FAIL\n");
    //    hal_finish();
    //return 0;
  }
  if(test_ram())
    puts("RAM OK\n");
  else {
    puts("RAM FAIL\n");
    hal_finish();
    return 0;
  }

  print_mac_addr(ethernet_mac_addr()->addr);
  newline();

  output_regs->led_src = 0x7;  // make bottom 3 controlled by HW

  ethernet_register_link_changed_callback(link_changed_callback);
  ethernet_init();

  clocks_enable_tx_dboard(true,1);
  clocks_mimo_config(MC_WE_LOCK_TO_SMA);
#if 0
  // make bit 15 of Tx gpio's be a s/w output
  hal_gpio_set_sel(GPIO_TX_BANK, 15, 's');
  hal_gpio_set_ddr(GPIO_TX_BANK, 0x8000, 0x8000);
#endif

  output_regs->debug_mux_ctrl = 1;
#if 0
  hal_gpio_set_sels(GPIO_TX_BANK, "1111111111111111");
  hal_gpio_set_sels(GPIO_RX_BANK, "1111111111111111");
  hal_gpio_set_ddr(GPIO_TX_BANK, 0xffff, 0xffff);
  hal_gpio_set_ddr(GPIO_RX_BANK, 0xffff, 0xffff);
#endif


  // initialize double buffering state machine for ethernet -> DSP Tx

  dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0,
	    &dsp_tx_recv_args, &dsp_tx_send_args,
	    eth_pkt_inspector);


  // initialize double buffering state machine for DSP RX -> Ethernet

  if (FW_SETS_SEQNO){
    dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0,
	      &dsp_rx_recv_args, &dsp_rx_send_args,
	      fw_sets_seqno_inspector);
  }
  else {
    dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0,
	      &dsp_rx_recv_args, &dsp_rx_send_args,
	      dbsm_nop_inspector);
  }

  // tell app_common that this dbsm could be sending to the ethernet
  ac_could_be_sending_to_eth = &dsp_rx_sm;


  // program tx registers
  setup_tx();

  // kick off the state machine
  dbsm_start(&dsp_tx_sm);

  //int which = 0;

  while(1){
    // hal_gpio_write(GPIO_TX_BANK, which, 0x8000);
    // which ^= 0x8000;

    buffer_irq_handler(0);

    int pending = pic_regs->pending;		// poll for under or overrun

    if (pending & PIC_UNDERRUN_INT){
      dbsm_handle_tx_underrun(&dsp_tx_sm);
      pic_regs->pending = PIC_UNDERRUN_INT;	// clear interrupt
      putchar('U');
    }

    if (pending & PIC_OVERRUN_INT){
      dbsm_handle_rx_overrun(&dsp_rx_sm);
      pic_regs->pending = PIC_OVERRUN_INT;	// clear pending interrupt

      // FIXME Figure out how to handle this robustly.
      // Any buffers that are emptying should be allowed to drain...

      if (streaming_p){
	// restart_streaming();
	// FIXME report error
      }
      else {
	// FIXME report error
      }
      putchar('O');
    }
  }
}
示例#5
0
int main(void)
{
	NetbootParam *param;

	// Initialize some consoles.
	serial_console_init();
	cbmem_console_init();
	video_console_init();
	input_init();

	printf("\n\nStarting netboot on " CONFIG_BOARD "...\n");

	timestamp_init();

	if (run_init_funcs())
		halt();

	// Make sure graphics are available if they aren't already.
	enable_graphics();

	dc_usb_initialize();

	srand(timer_raw_value());

	printf("Looking for network device... ");
	while (!net_get_device())
		usb_poll();
	printf("done.\n");

	printf("Waiting for link... ");
	int ready = 0;
	while (!ready) {
		if (net_ready(&ready))
			halt();
	}
	mdelay(200);	// some dongles need more time than they think
	printf("done.\n");

	// Start up the network stack.
	uip_init();

	// Plug in the MAC address.
	const uip_eth_addr *mac_addr = net_get_mac();
	if (!mac_addr)
		halt();
	printf("MAC: ");
	print_mac_addr(mac_addr);
	printf("\n");
	uip_setethaddr(*mac_addr);

	// Find out who we are.
	uip_ipaddr_t my_ip, next_ip, server_ip;
	const char *dhcp_bootfile;
	while (dhcp_request(&next_ip, &server_ip, &dhcp_bootfile))
		printf("Dhcp failed, retrying.\n");

	printf("My ip is ");
	uip_gethostaddr(&my_ip);
	print_ip_addr(&my_ip);
	printf("\nThe DHCP server ip is ");
	print_ip_addr(&server_ip);
	printf("\n");

	// Retrieve settings from the shared data area.
	FmapArea shared_data;
	if (fmap_find_area("SHARED_DATA", &shared_data)) {
		printf("Couldn't find the shared data area.\n");
		halt();
	}
	void *data = flash_read(shared_data.offset, shared_data.size);
	netboot_params_init(data, shared_data.size);

	// Get TFTP server IP and file name from params with DHCP as fallback
	uip_ipaddr_t *tftp_ip = NULL;
	param = netboot_params_val(NetbootParamIdTftpServerIp);
	if (param->data && param->size >= sizeof(uip_ipaddr_t)) {
		tftp_ip = (uip_ipaddr_t *)param->data;
		printf("TFTP server IP set from firmware parameters: ");
	} else {
		tftp_ip = &next_ip;
		printf("TFTP server IP supplied by DHCP server: ");
	}
	print_ip_addr(tftp_ip);
	printf("\n");

	const char *bootfile = NULL;
	param = netboot_params_val(NetbootParamIdBootfile);
	if (param->data && param->size > 0 && strnlen((const char *)param->data,
			param->size) < param->size) {
		bootfile = (const char *)param->data;
		printf("Bootfile set from firmware parameters: %s\n", bootfile);
	} else {
		bootfile = dhcp_bootfile;
		printf("Bootfile supplied by DHCP server: %s\n", bootfile);
	}

	// Download the bootfile.
	uint32_t size;
	if (tftp_read(payload, tftp_ip, bootfile, &size, MaxPayloadSize)) {
		printf("Tftp failed.\n");
		if (dhcp_release(server_ip))
			printf("Dhcp release failed.\n");
		halt();
	}
	printf("The bootfile was %d bytes long.\n", size);

	// Use command line from params when present (added to the default).
	param = netboot_params_val(NetbootParamIdKernelArgs);
	if (param->data && param->size > 0 && *(char *)param->data != '\0') {
		cmd_line[sizeof(def_cmd_line) - 1] = ' ';
		strncpy(&cmd_line[sizeof(def_cmd_line)], param->data,
			sizeof(cmd_line) - sizeof(def_cmd_line));
		printf("Command line set from firmware parameters.\n");
	// Otherwise, try to fetch it dynamically as a TFTP file.
	} else if (!(tftp_read(cmd_line, tftp_ip, "cmdline." CONFIG_BOARD,
			       &size, sizeof(cmd_line) - 1))) {
		while (cmd_line[size - 1] <= ' ')  // strip trailing whitespace
			if (!--size) break;	   // and control chars (\n, \r)
		cmd_line[size] = '\0';
		while (size--)			   // replace inline control
			if (cmd_line[size] < ' ')  // chars with spaces
				cmd_line[size] = ' ';
		printf("Command line loaded dynamically from TFTP server.\n");
	// If the file doesn't exist, finally fall back to built-in default.
	} else {
		printf("No command line from TFTP, falling back to default.\n");
	}
	cmd_line[sizeof(cmd_line) - 1] = '\0';

	// We're done on the network, so release our IP.
	if (dhcp_release(server_ip)) {
		printf("Dhcp release failed.\n");
		halt();
	}

	// Add tftp server IP into command line.
	static const char def_tftp_cmdline[] = " tftpserverip=xxx.xxx.xxx.xxx";
	const int tftp_cmdline_def_size = sizeof(def_tftp_cmdline) - 1;
	int cmd_line_size = strlen(cmd_line);
	if (cmd_line_size + tftp_cmdline_def_size >= sizeof(cmd_line)) {
		printf("Out of space adding TFTP server IP to the command line.\n");
		return 1;
	}
	sprintf(&cmd_line[cmd_line_size], " tftpserverip=%d.%d.%d.%d",
		uip_ipaddr1(tftp_ip), uip_ipaddr2(tftp_ip),
		uip_ipaddr3(tftp_ip), uip_ipaddr4(tftp_ip));
	printf("The command line is: %s\n", cmd_line);

	// Boot.
	boot(payload, cmd_line, NULL, NULL);

	// We should never get here.
	printf("Got to the end!\n");
	halt();
	return 0;
}