Ejemplo n.º 1
0
int sdramc_start (void)
{
	sdr_cfg_t cfg;

	/* enable lvcmos */
	REGD(0x08100828) = 0x02000000;

	if (sdr_init (SDR_REG_BASE) < 0)
	{
		printf ("sdramc initialisation failed\n");
		return -1;
	}

	if (sdr_reset () < 0)
	{
		printf ("sdramc reset failed\n");
		return -1;
	}

	sdr_enable ();	  // clk running, cke low for 200us
	udelay (200);
	sdr_power_up ();	// clk running, cke high for 200us
	udelay (200);

	// configure cs0
	cfg.cs = 0;
	cfg.dsz = 1;	// 1=32-bit, 0=16-bit
	cfg.row = 13;
	cfg.col = 9;
	cfg.bl = 8;
	cfg.cas = 3;

	if (sdr_start (&cfg) < 0)
	{
		printf ("sdramc csd0 start up failed\n");
		return -1;
	}

	// configure cs1
	cfg.cs = 1;
	if (sdr_start (&cfg) < 0)
	{
		printf ("sdramc csd1 start up failed\n");
		return -1;
	}

	return 0;
}
Ejemplo n.º 2
0
/**
 * Starts the initialization, the tasks and then the scheduler.
 */
int main(void)
{	
	/* disable ETM at very first */
	PINSEL10 &= ~((unsigned int)(1 << 3));

	/* Initialize BMC hardware */
	global_data.bmc_resetcause = 0x00;

	/* IPMI message sequence counter */
	global_data.seq_counter = 0x00;

	/* site number used for entity instance */
	global_data.bmc_siteno = 0x00;

	/* reset sdr list */
	sdr_list.sdr_count = 0;

	/* init PLL */
	init_clock();
	
	/* init interrupts */
	init_irq();

	/* get reset cause */
	init_resetcause();
	
	/* init port pins */
	init_portpins();
	
	/* CUSTOM BOARD INIT CODE LOCATION 1 */
	custom_init_1();
	
	/* get HW and IPMB address */
	custom_get_hw_ipmb_address();

	uptime_init();

	/* init RTC */
	rtc_init();

	/* create the FreeRTOS queues */
	create_queues();

	uart_init(UART_DEBUG_CONNECTOR, 115200);

	uart_printf("Firmware started...\n");

	/* init SPI/SSP controllers */
	spi_init();

	/* init SPI FLASH */
    spi_flash_init_devices();
	spi_flash_init(&spi_flash);
	
#ifdef CFG_MMC_I2C_MASTER
	/* init BMC master I2C bus */
	master_i2c_init(MASTER_BUS_I2C);
#endif
	/* init EEPROM file system */
	//spi_eeprom_init(&spi_eeprom);

#ifdef CFG_FS
	if (fs_init(&efs, &spi_eeprom) != 0)
	{
		uart_printf("\nEEPROM not accesable!\n");
		/* reboot bmc */
		lpc_watchdog_start(CFG_BL_WATCHDOG_TIMEOUT, WD_RESET_MODE);
		while (1);
	}
#endif

	/* init leds */
	//led_init();	
	
#ifndef CFG_ONCHIP_FLASH_GLOBAL_CONF
	/* check EEPROM areas */
	//eeprom_integrity_check_areas();
#endif

	/* init CLI (and debug console) */
	cli_uart_init(115200);

	/* handle reset type warm/cold? */
	//fru_handle_reset_type();
	
#ifdef CFG_CM
	cm_fru_get_last_known_state();
#endif

#ifdef CFG_EXT_INT
	/* init external interrupts */
	external_interrupt_init();
#endif
	
#ifdef CFG_HELPER
	/* init the helper task */
	helper_init();
#endif

#ifdef CFG_BIOS_FLASH
	/* init BIOS FLASH */
	spi_flash_init(&bios_flash);

	/* init FPGA BIOS flash selection */
	bios_restore_active_flash_from_eeprom();
#endif

	/* CUSTOM BOARD INIT CODE LOCATION 2 */
	//custom_init_2();

	/* get global configuration from EEPROM */
	global_config();
	
	/* CUSTOM BOARD INIT CODE LOCATION 3 */
	//custom_init_3();

	/* parse FRU */
	fru_init(0);

#if defined (CFG_CM) || defined (CFG_MMC) || defined (CFG_IRTM) || defined(CFG_MCMC)
	/* init the IPMB-L interface(s) */
	ipmbl_init();
#endif


#ifdef CFG_LAN
	/* read and set ncsi mac address from fru */
	custom_set_ncsi_mac();
#endif

	/* create message pool for IPMI messages */
	message_pool_init();

    /* init board task */
	board_init();

	/* init the BMC task */
	bmc_init();

#ifdef CFG_PI_SERIAL_BASIC
	/* init the payload interface */
	pi_uart_b_init(CFG_PI_PORT_RATE);
#endif /* CFG_PI_SERIAL_BASIC */

#ifdef CFG_PI_SERIAL_TERMINAL
	/* init the payload interface */
	pi_uart_t_init(CFG_PI_PORT_RATE);
#endif /* CFG_PI_SERIAL_TERMINAL */

#ifdef CFG_PI_KCS
	/* initialise kcs interface */
	kcs_init();
#endif /* CFG_PI_KCS */

#ifdef CFG_ATCA
	if (global_conf.operation_mode == OPERATION_MODE_STANDALONE)
	{
		/* configure IPMB-A and IPMB-B as master only in stanalone mode */
		master_i2c_init(IPMB0A_I2C);
		master_i2c_init(IPMB0B_I2C);

		/* enable IPMB-0 pull ups and buffer */
		ipmb0_bus_ctrl(IPMB0_A, IPMB_ENABLE);
		ipmb0_bus_ctrl(IPMB0_B, IPMB_ENABLE);
	}
	else
	{
		/* init the IPMB-0 interface */
		ipmb0_init();
	}
#endif

#ifdef CFG_LAN_PLUS
	sol_init();
#endif

#ifdef CFG_LAN
	/* init ethernet hardware and Task */
	eth_start();
#endif

	/* init the SDR task */
	/* PORT_NOTE: Needs to be started AFTER BMC task because of Semaphore dependency */
	sdr_init();

	/* parse all PICMG Records in FRU data and store relevant information */
	//fru_parse_picmg();

	/* init the IPMI message hub */
	msg_hub_init();

	/* init the event task */
	event_init();


#ifdef CFG_CM
	/* init the CM task */
	init_cm();
#endif


#ifdef CFG_COOLING_MANAGER
	cool_init();
#endif
	/* do all post tests */
	//post_test();

	/* needs to be done after sdr initialization */
	//hpm_check_bl_flags();

#ifdef CFG_BIOS_FLASH
	/* collect BIOS/NVRAM version info (if payload power is off) */
	if (!(signal_read(&sig_payload_power_enable)))
	{
		bios_redundancy_get_versions();
	}
#endif


#ifdef CFG_WATCHDOG
	/* start the FW watchdog */
	lpc_watchdog_start(CFG_FW_WATCHDOG_TIMEOUT, WD_RESET_MODE);
#endif

	/* set desired debug output mode before starting scheduler */
	global_debug_uart_enabled = CFG_GLOBAL_DEBUG_UART;

	/* all tasks have been initialized, start the scheduler */
	vTaskStartScheduler();

	/* Should never reach here! */
	while (1);
}
Ejemplo n.º 3
0
static int do_sdr_decode(struct dab_state_t* dab, int frequency, int gain)
{
  struct sigaction sigact;
  uint32_t dev_index = 0;
  int32_t device_count;
  int i,r;
  char vendor[256], product[256], serial[256];
  uint32_t samp_rate = 2048000;

  memset(&sdr,0,sizeof(struct sdr_state_t));

  sdr.frequency = frequency;

  //fprintf(stderr,"%i\n",sdr.frequency);

  /*---------------------------------------------------
    Looking for device and open connection
    ----------------------------------------------------*/
  device_count = rtlsdr_get_device_count();
  if (!device_count) {
    fprintf(stderr, "No supported devices found.\n");
    exit(1);
  }

  fprintf(stderr, "Found %d device(s):\n", device_count);
  for (i = 0; i < device_count; i++) {
    rtlsdr_get_device_usb_strings(i, vendor, product, serial);
    fprintf(stderr, "  %d:  %s, %s, SN: %s\n", i, vendor, product, serial);
  }
  fprintf(stderr, "\n");
  
  fprintf(stderr, "Using device %d: %s\n",dev_index, rtlsdr_get_device_name(dev_index));
  
  r = rtlsdr_open(&dev, dev_index);
  if (r < 0) {
    fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
    exit(1);
  }

  int gains[100];
  int count = rtlsdr_get_tuner_gains(dev, gains);
  fprintf(stderr, "Supported gain values (%d): ", count);
  for (i = 0; i < count; i++)
    fprintf(stderr, "%.1f ", gains[i] / 10.0);
  fprintf(stderr, "\n");

  /*-------------------------------------------------
    Set Frequency & Sample Rate
    --------------------------------------------------*/
  /* Set the sample rate */
  r = rtlsdr_set_sample_rate(dev, samp_rate);
  if (r < 0)
    fprintf(stderr, "WARNING: Failed to set sample rate.\n");
  
  /* Set the frequency */
  r = rtlsdr_set_center_freq(dev, sdr.frequency);
  if (r < 0)
    fprintf(stderr, "WARNING: Failed to set center freq.\n");
  else
    fprintf(stderr, "Tuned to %u Hz.\n", sdr.frequency);

  /*------------------------------------------------
    Setting gain  
    -------------------------------------------------*/
  if (gain == AUTO_GAIN) {
    r = rtlsdr_set_tuner_gain_mode(dev, 0);
  } else {
    r = rtlsdr_set_tuner_gain_mode(dev, 1);
    r = rtlsdr_set_tuner_gain(dev, gain);
  }
  if (r != 0) {
    fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
  } else if (gain == AUTO_GAIN) {
    fprintf(stderr, "Tuner gain set to automatic.\n");
  } else {
    fprintf(stderr, "Tuner gain set to %0.2f dB.\n", gain/10.0);
  }
  /*-----------------------------------------------
  /  Reset endpoint (mandatory) 
  ------------------------------------------------*/
  r = rtlsdr_reset_buffer(dev);
  /*-----------------------------------------------
  / Signal handler
  ------------------------------------------------*/
  sigact.sa_handler = sighandler;
  sigemptyset(&sigact.sa_mask);
  sigact.sa_flags = 0;
  sigaction(SIGINT, &sigact, NULL);
  sigaction(SIGTERM, &sigact, NULL);
  sigaction(SIGQUIT, &sigact, NULL);
  sigaction(SIGPIPE, &sigact, NULL);
  /*-----------------------------------------------
  / start demod thread & rtl read 
  -----------------------------------------------*/

  fprintf(stderr,"Waiting for sync...\n");

  sdr_init(&sdr);
  //dab_fic_parser_init(&sinfo);
  //dab_analyzer_init(&ana);
  pthread_create(&demod_thread, NULL, demod_thread_fn, (void *)(dab));
  rtlsdr_read_async(dev, rtlsdr_callback, (void *)(&sdr),
			      DEFAULT_ASYNC_BUF_NUMBER, DEFAULT_BUF_LENGTH);

  if (do_exit) {
    fprintf(stderr, "\nUser cancel, exiting...\n");}
  else {
    fprintf(stderr, "\nLibrary error %d, exiting...\n", r);}
  rtlsdr_cancel_async(dev);
  //dab_demod_close(&dab);
  rtlsdr_close(dev);
  return 1;
}
Ejemplo n.º 4
0
int
main (void)
{
  int s, s2, t, len;
  struct sockaddr_un local, remote;
  pthread_t tid;
  int *p_s2;
  int rc = 0;

  daemon(1, 1);
  openlog("ipmid", LOG_CONS, LOG_DAEMON);


  plat_fruid_init();
  plat_sensor_init();
  plat_lan_init(&g_lan_config);

  sdr_init();
  sel_init();

  pthread_mutex_init(&m_chassis, NULL);
  pthread_mutex_init(&m_sensor, NULL);
  pthread_mutex_init(&m_app, NULL);
  pthread_mutex_init(&m_storage, NULL);
  pthread_mutex_init(&m_transport, NULL);
  pthread_mutex_init(&m_oem, NULL);
  pthread_mutex_init(&m_oem_1s, NULL);

  if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1)
  {
    syslog(LOG_WARNING, "ipmid: socket() failed\n");
    exit (1);
  }

  local.sun_family = AF_UNIX;
  strcpy (local.sun_path, SOCK_PATH_IPMI);
  unlink (local.sun_path);
  len = strlen (local.sun_path) + sizeof (local.sun_family);
  if (bind (s, (struct sockaddr *) &local, len) == -1)
  {
    syslog(LOG_WARNING, "ipmid: bind() failed\n");
    exit (1);
  }

  if (listen (s, 5) == -1)
  {
    syslog(LOG_WARNING, "ipmid: listen() failed\n");
    exit (1);
  }

  while(1) {
    int n;
    t = sizeof (remote);
    // TODO: seen accept() call fails and need further debug
    if ((s2 = accept (s, (struct sockaddr *) &remote, &t)) < 0) {
      rc = errno;
      syslog(LOG_WARNING, "ipmid: accept() failed with ret: %x, errno: %x\n", s2, rc);
      sleep(5);
      continue;
    }

    // Creating a worker thread to handle the request
    // TODO: Need to monitor the server performance with higher load and
    // see if we need to create pre-defined number of workers and schedule
    // the requests among them.
    p_s2 = malloc(sizeof(int));
    *p_s2 = s2;
    if (pthread_create(&tid, NULL, conn_handler, (void*) p_s2) < 0) {
        syslog(LOG_WARNING, "ipmid: pthread_create failed\n");
        close(s2);
        continue;
    }

    pthread_detach(tid);
  }

  close(s);

  pthread_mutex_destroy(&m_chassis);
  pthread_mutex_destroy(&m_sensor);
  pthread_mutex_destroy(&m_app);
  pthread_mutex_destroy(&m_storage);
  pthread_mutex_destroy(&m_transport);
  pthread_mutex_destroy(&m_oem);
  pthread_mutex_destroy(&m_oem_1s);

  return 0;
}
Ejemplo n.º 5
0
static int do_sdr_decode(struct dab_state_t* dab, int frequency, int gain)
{
  struct sigaction sigact;
  uint32_t dev_index = 0;
  int32_t device_count;
  int i,r;
  char vendor[256], product[256], serial[256];
  uint32_t samp_rate = 2048000;

  memset(&sdr,0,sizeof(struct sdr_state_t));

  sdr.frequency = frequency;

  //fprintf(stderr,"%i\n",sdr.frequency);

  /*---------------------------------------------------
    Looking for device and open connection
    ----------------------------------------------------*/
  if (dab->device_type == DAB_DEVICE_RTLSDR) {
    sdr.convert_unsigned = 1;

    device_count = rtlsdr_get_device_count();
    if (!device_count) {
      fprintf(stderr, "No supported devices found.\n");
      exit(1);
    }

    fprintf(stderr, "Found %d device(s):\n", device_count);
    for (i = 0; i < device_count; i++) {
      rtlsdr_get_device_usb_strings(i, vendor, product, serial);
      fprintf(stderr, "  %d:  %s, %s, SN: %s\n", i, vendor, product, serial);
    }
    fprintf(stderr, "\n");

    fprintf(stderr, "Using device %d: %s\n",dev_index, rtlsdr_get_device_name(dev_index));

    r = rtlsdr_open(&dev, dev_index);
    if (r < 0) {
      fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
      exit(1);
    }

    int gains[100];
    int count = rtlsdr_get_tuner_gains(dev, gains);
    fprintf(stderr, "Supported gain values (%d): ", count);
    for (i = 0; i < count; i++)
      fprintf(stderr, "%.1f ", gains[i] / 10.0);
    fprintf(stderr, "\n");
  }
  else if (dab->device_type == DAB_DEVICE_HACKRF) {
    sdr.convert_unsigned = 0;
    r = hackrf_init();
    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_init() failed", r);
      return EXIT_FAILURE;
    }

    const char* serial_number = nullptr;
    r = hackrf_open_by_serial(serial_number, &hackrf);
    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_open() failed", r);
      return EXIT_FAILURE;
    }
  }
  else
  {
    r = -1;
    return EXIT_FAILURE;
  }

  /*-------------------------------------------------
    Set Frequency & Sample Rate
    --------------------------------------------------*/
  if (dab->device_type == DAB_DEVICE_RTLSDR) {
    /* Set the sample rate */
    r = rtlsdr_set_sample_rate(dev, samp_rate);
    if (r < 0)
      fprintf(stderr, "WARNING: Failed to set sample rate.\n");

    /* Set the frequency */
    r = rtlsdr_set_center_freq(dev, sdr.frequency);
    if (r < 0)
      fprintf(stderr, "WARNING: Failed to set center freq.\n");
    else
      fprintf(stderr, "Tuned to %u Hz.\n", sdr.frequency);

    /*------------------------------------------------
      Setting gain  
      -------------------------------------------------*/
    if (gain == AUTO_GAIN) {
      r = rtlsdr_set_tuner_gain_mode(dev, 0);
    } else {
      r = rtlsdr_set_tuner_gain_mode(dev, 1);
      r = rtlsdr_set_tuner_gain(dev, gain);
    }
    if (r != 0) {
      fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
    } else if (gain == AUTO_GAIN) {
      fprintf(stderr, "Tuner gain set to automatic.\n");
    } else {
      fprintf(stderr, "Tuner gain set to %0.2f dB.\n", gain/10.0);
    }
    /*-----------------------------------------------
      /  Reset endpoint (mandatory) 
      ------------------------------------------------*/
    r = rtlsdr_reset_buffer(dev);
  }
  else if (dab->device_type == DAB_DEVICE_HACKRF) {
    int sample_rate_hz = samp_rate;
    fprintf(stderr, "call hackrf_sample_rate_set(%u Hz/%.03f MHz)\n", sample_rate_hz, (sample_rate_hz/1e6));
    int r = hackrf_set_sample_rate_manual(hackrf, sample_rate_hz, 1);
    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_sample_rate_set() failed", r);
      return EXIT_FAILURE;
    }

    /* possible settings 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28 */
    int baseband_filter_bw_hz = 2500000;
    fprintf(stderr, "call hackrf_baseband_filter_bandwidth_set(%d Hz/%.03f MHz)\n",
        baseband_filter_bw_hz, ((float)baseband_filter_bw_hz/1e6));
    r = hackrf_set_baseband_filter_bandwidth(hackrf, baseband_filter_bw_hz);
    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_baseband_filter_bandwidth_set()", r);
      return EXIT_FAILURE;
    }

    r = hackrf_set_vga_gain(hackrf, hackrf_vga_gain);
    r |= hackrf_set_lna_gain(hackrf, hackrf_lna_gain);

    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_vga gain/lna gain", r);
      return EXIT_FAILURE;
    }

    r = hackrf_set_freq(hackrf, sdr.frequency);
    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_set_freq()", r);
      return EXIT_FAILURE;
    }
  }
  /*-----------------------------------------------
  / Signal handler
  ------------------------------------------------*/
  sigact.sa_handler = sighandler;
  sigemptyset(&sigact.sa_mask);
  sigact.sa_flags = 0;
  sigaction(SIGINT, &sigact, NULL);
  sigaction(SIGTERM, &sigact, NULL);
  sigaction(SIGQUIT, &sigact, NULL);
  sigaction(SIGPIPE, &sigact, NULL);
  /*-----------------------------------------------
  / start demod thread & rtl read 
  -----------------------------------------------*/

  fprintf(stderr,"Waiting for sync...\n");

  sdr_init(&sdr);
  //dab_fic_parser_init(&sinfo);
  //dab_analyzer_init(&ana);
  pthread_create(&demod_thread, NULL, demod_thread_fn, (void *)(dab));
  if (dab->device_type == DAB_DEVICE_RTLSDR) {
    rtlsdr_read_async(dev, rtlsdr_callback, (void *)(&sdr),
        DEFAULT_ASYNC_BUF_NUMBER, DEFAULT_BUF_LENGTH);
  }
  else if (dab->device_type == DAB_DEVICE_HACKRF) {
    r = hackrf_start_rx(hackrf, hackrf_callback, (void *)(&sdr));

    if( r != HACKRF_SUCCESS ) {
      hackrf_err("hackrf_start_x()", r);
      return EXIT_FAILURE;
    }

    while( ((r=hackrf_is_streaming(hackrf)) == HACKRF_TRUE) &&
        (do_exit == false) ) {
      sleep(1);
      fprintf(stderr, "samples: low: %02.2f%%, saturating: %02.2f%%\n",
          num_low_power * 100.0 / DEFAULT_BUF_LENGTH,
          num_saturated * 100.0 / DEFAULT_BUF_LENGTH);
    }
    hackrf_err("hackrf_is_streaming", r);
  }


  if (do_exit) {
    fprintf(stderr, "\nUser cancel, exiting...\n");}
  else {
    fprintf(stderr, "\nLibrary error %d, exiting...\n", r);}
  if (dab->device_type == DAB_DEVICE_RTLSDR) {
    rtlsdr_cancel_async(dev);
    //dab_demod_close(&dab);
    rtlsdr_close(dev);
  }
  else if (dab->device_type == DAB_DEVICE_HACKRF) {
    if (hackrf != NULL)
    {
      r = hackrf_stop_rx(hackrf);
      if( r != HACKRF_SUCCESS ) {
        hackrf_err("hackrf_stop_rx() failed", r);
      }
      else {
        fprintf(stderr, "hackrf_stop_rx() done\n");
      }

      r = hackrf_close(hackrf);
      if( r != HACKRF_SUCCESS )
      {
        hackrf_err("hackrf_close() failed", r);
      }
      else {
        fprintf(stderr, "hackrf_close() done\n");
      }
    }

    hackrf_exit();
  }
  return 1;
}