コード例 #1
0
ファイル: main.c プロジェクト: jshowa/KetteringUniversity
void main(void) {
  
  int i;
  
  char* mystring1;
  char* mystring; 
  
  //volatile char a = '\0';
  //volatile int b = (int)a;
  
  
  
  mystring = string;
  mystring1 = string1;
  
  spi0_init();

  //spi_RAM_write(0x1000, 0x27);
  //spi_RAM_write(0x1002, 0x36);

  //data = spi_RAM_read(0x1000);
  //temp = data;
  //data = spi_RAM_read(0x1002);
  
  for (i = 0; i < 165; i++)
  {
    if (i == 164)
        string[i] = '\0';
    else if (i <= 160)
        string[i] = 'a';
    else if (i == 161)
        string[i] = 'b';
    else if (i == 162)
        string[i] = 'c';
    else if (i == 163)
        string[i] = 'd';
  }
  
  spi_RAM_write_string(0x1000, mystring);
  spi_RAM_read_string(0x1000, mystring1);
  
  for(;;) {
    
   
  } /* loop forever */
  /* please make sure that you never leave main */
}
コード例 #2
0
ファイル: sunxi_spi_spl.c プロジェクト: ahedlund/u-boot-xlnx
static int spl_spi_load_image(struct spl_image_info *spl_image,
			      struct spl_boot_device *bootdev)
{
	int err;
	struct image_header *header;
	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);

	spi0_init();

	spi0_read_data((void *)header, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40);
	err = spl_parse_image_header(spl_image, header);
	if (err)
		return err;

	spi0_read_data((void *)spl_image->load_addr, CONFIG_SYS_SPI_U_BOOT_OFFS,
		       spl_image->size);

	spi0_deinit();
	return 0;
}
コード例 #3
0
static int spl_spi_load_image(struct spl_image_info *spl_image,
			      struct spl_boot_device *bootdev)
{
	int ret = 0;
	struct image_header *header;
	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);

	spi0_init();

	spi0_read_data((void *)header, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40);

        if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
		image_get_magic(header) == FDT_MAGIC) {
		struct spl_load_info load;

		debug("Found FIT image\n");
		load.dev = NULL;
		load.priv = NULL;
		load.filename = NULL;
		load.bl_len = 1;
		load.read = spi_load_read;
		ret = spl_load_simple_fit(spl_image, &load,
					  CONFIG_SYS_SPI_U_BOOT_OFFS, header);
	} else {
		ret = spl_parse_image_header(spl_image, header);
		if (ret)
			return ret;

		spi0_read_data((void *)spl_image->load_addr,
			       CONFIG_SYS_SPI_U_BOOT_OFFS, spl_image->size);
	}

	spi0_deinit();

	return ret;
}
コード例 #4
0
ファイル: mcu.c プロジェクト: WenFly123/openPPZ
void mcu_init(void) 
{

  mcu_arch_init();

#ifdef PERIPHERALS_AUTO_INIT
  sys_time_init();
#ifdef USE_LED
  led_init();
#endif
  /* for now this means using spektrum */
#if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC
  RADIO_CONTROL_BIND_IMPL_FUNC();
#endif
#ifdef USE_UART0
  uart0_init();
#endif
#ifdef USE_UART1
  uart1_init();
#endif
#ifdef USE_UART2
  uart2_init();
#endif
#ifdef USE_UART3
  uart3_init();
#endif
#ifdef USE_UART4
  uart4_init();
#endif
#ifdef USE_UART5
  uart5_init();
#endif
#ifdef USE_I2C0
  i2c0_init();
#endif
#ifdef USE_I2C1
  i2c1_init();
#endif
#ifdef USE_I2C2
  i2c2_init();
#endif
#ifdef USE_ADC
  adc_init();
#endif
#ifdef USE_USB_SERIAL
  VCOM_init();
#endif

#if USE_SPI
#if SPI_MASTER

#if USE_SPI0
  spi0_init();
#endif
#if USE_SPI1
  spi1_init();
#endif
#if USE_SPI2
  spi2_init();
#endif
#if USE_SPI3
  spi3_init();
#endif
  spi_init_slaves();
#endif // SPI_MASTER

#if SPI_SLAVE
#if USE_SPI0_SLAVE
  spi0_slave_init();
#endif
#if USE_SPI1_SLAVE
  spi1_slave_init();
#endif
#if USE_SPI2_SLAVE
  spi2_slave_init();
#endif
#if USE_SPI3_SLAVE
  spi3_slave_init();
#endif
#endif // SPI_SLAVE
#endif // USE_SPI

#ifdef USE_DAC
  dac_init();
#endif
#else
INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.")
#endif /* PERIPHERALS_AUTO_INIT */

}
コード例 #5
0
/**
 * Initializes the High Level System such as IO Pins and Drivers
 */
void high_level_init(void)
{
    // Initialize all board pins (early) that are connected internally.
    board_io_pins_initialize();
    
    #if ENABLE_TELEMETRY
        /* Add default telemetry components */
        tlm_component_add("disk");
        tlm_component_add("debug");
    #endif

    /**
     * Set-up Timer0 so that delay_ms(us) functions will work.
     * This function is used by FreeRTOS run time statistics.
     * If FreeRTOS is used, timer will be set-up anyway.
     * If FreeRTOS is not used, call it here such that delay_ms(us) functions will work.
     */
    vConfigureTimerForRunTimeStats();

    /**
     * Intentional delay here because this gives the user some time to
     * close COM Port at Hyperload and Open it at Hercules
     */
    delay_ms(STARTUP_DELAY_MS);
    hl_print_line();

    /* Print boot info */
    const unsigned int cpuClock = sys_get_cpu_clock();
    const unsigned int sig = cpuClock / (1000 * 1000);
    const unsigned int fraction = (cpuClock - (sig*1000*1000)) / 1000;;
    printf("\nSystem Boot @ %u.%u Mhz\n", sig, fraction);

    if(SysBootType_watchdog_recover == sys_get_boot_type()) {
        hl_print_line();
        printf("System rebooted after crash.  Relevant info:\n"
               "PC: 0x%08X.  LR: 0x%08X.  PSR: 0x%08X\n",
                (unsigned int)FAULT_PC, (unsigned int)FAULT_LR, (unsigned int)FAULT_PSR);
        hl_print_line();
    }

    /**
     * Initialize the Peripherals used in the system
     * I2C2 : Used by LED Display, Acceleration Sensor, Temperature Sensor
     * ADC0 : Used by Light Sensor
     * SPI0 : Used by Nordic
     * SPI1 : Used by SD Card & External SPI Flash Memory
     */
    adc0_init();
    spi1_init();
    spi0_init(SPI0_CLOCK_SPEED_MHZ);
    if (!I2C2::getInstance().init(I2C2_CLOCK_SPEED_KHZ)) {
        puts("I2C #2: ERROR: Possible short on SDA or SCL wire!");
    }

    /* Initialize nordic wireless mesh network before setting up sys_setup_rit()
     * callback since it may access NULL function pointers.
     */
    if (!wireless_init()) {
        puts("ERROR: Failed to initialize wireless");
    }

    /* Set-up our RIT callback to perform some background book-keeping
     * If FreeRTOS is running, this service is disabled and FreeRTOS
     * tick hook will call hl_periodic_service()
     * @warning RIT interrupt should be setup before SD card is mounted
     *           since it relies on our timer.
     */
    sys_rit_setup(hl_periodic_service, m_time_per_rit_isr_ms);

    /**
     * If Flash is not mounted, it is probably a new board and the flash is not
     * formatted so format it, alert the user, and try to re-mount it
     */
    bool flashMounted = hl_mount_storage(Storage::getFlashDrive(), " Flash ");
    if(!flashMounted)
    {
        printf("FLASH not formatted, formatting now ... ");
        printf("%s\n", FR_OK == Storage::getFlashDrive().format() ? "Done" : "Error");
        flashMounted = hl_mount_storage(Storage::getFlashDrive(), " Flash ");
    }

    /**
     * If SD Card is present, try to copy log file from Flash to SD Card
     */
    const bool sdMounted = hl_mount_storage(Storage::getSDDrive(),    "SD Card");
    if(flashMounted && sdMounted)
    {
        hl_move_log_file();
    }

	/* After SD card is initted, set desired speed for spi1 */
    spi1_set_max_clock(SPI1_CLOCK_SPEED_MHZ);
    hl_print_line();

    #if LOG_BOOT_INFO_TO_FILE
    log_boot_info(__DATE__);
    #endif

    /**
     * Print discovered I2C devices.
     * But not really useful if no external I2C device attached.
     * If we do find an external device though, we will print a line after the output.
     */
    if(hl_discover_external_i2c_devs()) {
        hl_print_line();
    }

    /* Initialize all sensors of this board. */
    if(!hl_init_board_io()) {
        hl_print_line();
        LD.setLeftDigit('-');
        LD.setRightDigit('-');
        LE.setAll(0xFF);
    }
    else {
        LD.setNumber(TS.getFarenheit());
    }

    /* Print memory information before we call main() */
    do {
        char buff[512] = { 0 };
        sys_get_mem_info_str(buff);
        puts(buff);
        hl_print_line();
    } while(0);

    /* After Flash memory is mounted, try to set node address from a file */
    wireless_set_addr_from_file();
    srand(LS.getRawValue());

    // Display CPU speed in Mhz on LED display
    // LD.setNumber(sys_get_cpu_clock()/(1000*1000));

    puts("Calling your main()");
    hl_print_line();
}