/* One start -----------------------------------------------------------------*/ static void startup() { unsigned char err = 0; init_hardware(); dbg_init(); dbg_print_app_ver(); crc32_init(); pins_init(); //spi0_init(); // used in m25pexx.c (FLASH) spi1_init(); adc_init(); err = memory_init(); // memory initialization, external EEPROM (used in pref.c, orion.c), external FLASH, internal FLASH if (err) goto err; pref_init(); ds1390_init(); evt_fifo_init(); GPS_init(); //SIM900_init(); light_init(); saveDatePorojectIP();//новые параметры связи vpu_init(); /*VPU start*/ //Init_USB(); //if (PROJ.jornal.power_on) //Event_Push_Str("СТАРТ"); return; err: Err_led(err); }
static void en28j60_reset(u8 lag) { spi1_init(); enc28j60_rst = 0; delay_ms(lag); enc28j60_rst = 1; delay_ms(lag); }
/** * @brief * @param * @retval */ static void device_init(void) { port_init(); #ifdef INTERFACE_4WIRE_SPI spi1_init(); #endif iic_init(); adc1_init(); }
int main() { /* Semaphore creation */ vSemaphoreCreateBinary(ahrs_task_semaphore); vSemaphoreCreateBinary(flight_control_task_semaphore); /* Peripheral initialization */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); led_init(); debug_port_init(); usart3_init(57600); i2c1_init(); spi1_init(); timer1_init(); pwm_timer4_init(); pwm_timer5_init(); pwm_capture_timer2_init(); pwm_capture_timer3_init(); pwm_capture_timer8_init(); //Make sure all the peripheral is finished the initialization delay_ms(5); /* Device initialization */ while(mpu6050_init()); while(hmc5983_init()); nrf24l01_init(); motor_init(); /* Task creation */ //Attitude and Heading Reference System (AHRS) task xTaskCreate(ahrs_task, (portCHAR *)"AHRS task", 4096, NULL, tskIDLE_PRIORITY + 3, NULL); xTaskCreate(flight_control_task, (portCHAR *)"Flight control task", 4096, NULL, tskIDLE_PRIORITY + 2, NULL); #ifndef DEBUG_PRINT //USART plot task xTaskCreate(usart_plot_task, (portCHAR *)"USART plot task", 2048, NULL, tskIDLE_PRIORITY + 1, NULL); #endif /* Start schedule */ vTaskStartScheduler(); return 0; }
int main() { spi1_init (); while (1) { for (int8_t i=0;i<8;++i) { spi1_transmit (1<<i); delay_ms(200); } for (int8_t i=6;i>0;--i) { spi1_transmit (1<<i); delay_ms(100); } } }
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 */ }
/** * 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(); }
void fpga_config(void) { FIL fp; int i, retv, addr; u32 rv; u8 fbuf[256]; // 检查是否有升级文件. 如果有,就升级. 如果没有,就继续. retv = f_open(&fp, "/SSMaster.rbf", FA_READ); if(retv){ printk("NO FPGA config file found!\n"); return; } printk("Found FPGA config file.\n"); printk(" Size %08x\n", f_size(&fp)); // 发现升级文件 spi1_init(); // 启动配置 fpga_set_config(0); os_dly_wait(1); fpga_set_config(1); while(fpga_status()==1); os_dly_wait(1); // 写配置数据 for(addr=0; addr<f_size(&fp); addr+=256){ rv = 0; f_read(&fp, fbuf, 256, &rv); for(i=0; i<rv; i++){ spi1_trans(fbuf[i]); } } spi1_trans(0xff); // 等待FPGA配置完成 for(i=0; i<10; i++){ if(fpga_config_done()) break; os_dly_wait(10); } if(i==10){ printk("FPGA config timeout!\n"); }else{ printk("FPGA config done!\n"); } for(i=0; i<10; i++){ if(fpga_init_done()) break; os_dly_wait(10); } if(i==10){ printk("FPGA init timeout!\n"); }else{ printk("FPGA init done!\n"); } // 关闭升级文件 f_close(&fp); // FPGA_nRESET = 1; GPIOC->BSRR = 0x0020; printk("FPGA state:\n"); printk(" config done: %d\n", fpga_config_done()); printk(" init done: %d\n", fpga_init_done()); printk(" status: %d\n", fpga_status()); printk("\n"); }