void init( int argc, char * argv[] ) { if(argc > 1) if(Serial.init_tty(argv[1]) != 0) return; if(Serial1.init_tty(LINUX_SERIAL1_TTY) != 0) return; if(Serial2.init_tty(LINUX_SERIAL2_TTY) != 0) return; sizeof_g_APinDescription = sizeof(g_APinDescription)/sizeof(struct _PinDescription); sizeof_g_APinState = sizeof(g_APinState)/sizeof(struct _PinState); pinInit(); /* Initialize fast path to GPIO */ if (fastGpioPciInit()) trace_error("Unable to initialize fast GPIO mode!"); sizeof_g_APwmDescription = sizeof(g_APwmDescription)/sizeof(struct _PwmDescription); pwmInit(); sizeof_g_AdcDescription = sizeof(g_AdcDescription)/sizeof(struct _AdcDescription); adcInit(); eepromInit(); }
int main(void) { initMyExtIRQ(); eepromInit(); buttonsInit(); ledInit(); timerInit(); loggerInit(); loggerWriteToMarker((LogMesT)" \nStarting program \n*", '*'); initNockMachine_0(); while(1) { userCommandMachine_1(); nockMachine_2(); radioSendMachine_3(); } }
/****************************************************************************** Function Name : main Description : Main task Arguments : none Return value : none ******************************************************************************/ void main(void) { lvd_err_t err; lvd_config_t channel1_cfg; channel1_cfg.e_action = LVD_ACTION_RESET; channel1_cfg.e_trigger = LVD_TRIGGER_FALL; channel1_cfg.e_voltage_level =LVD_VOLTAGE_CH1_2_95; err = R_LVD_Open(LVD_CHANNEL_1, &channel1_cfg, NULL); bool ret = false; /* Reserve the CMT0 for FreeRTOS */ ret = R_BSP_HardwareLock((mcu_lock_t)(BSP_LOCK_CMT0)); while (false == ret) /* can't lock the CMT0 resource */ { while (1); } WDT_FEED /* Inicialização das variaveis EEPROM */ eepromInit(); eepromConsistencyCheck(); /* Initialize USB */ usb_main(); /* Initialize RTOS */ FreeRTOSConfig(); /* Start tasks - only returns if something bad happened! */ vTaskStartScheduler(); while (1) { } }
EEPROM *eepromOpen(EEPROM_COGDRIVER *eeprom, int scl, int sda, int freq, int address) { I2C *dev; if (!(dev = i2cOpen(&eeprom->dev, scl, sda, freq))) return NULL; eepromInit(&eeprom->state, dev, address); return (EEPROM *)eeprom; }
EEPROM *eepromBootOpen(EEPROM_BOOT *eeprom, int address) { I2C *dev; if (!(dev = i2cBootOpen())) return NULL; eepromInit(&eeprom->state, dev, address); return (EEPROM *)eeprom; }
EEPROM *simple_eepromOpen(EEPROM_SIMPLE *eeprom, int scl, int sda, int address) { I2C *dev; if (!(dev = simple_i2cOpen(&eeprom->dev, scl, sda))) return NULL; eepromInit(&eeprom->state, dev, address); return (EEPROM *)eeprom; }
//----------------------------------------------------------------- // Main //----------------------------------------------------------------- int main(void) { uint8_t uiResult; pllInit(); // Turn off analogue inputs ANSELB = PORTB_ANSEL; ANSELC = 0x0000; ANSELD = PORTD_ANSEL; ANSELE = 0x0000; ANSELG = 0x0000; memset(lastestDmxBuffer, 0, NUM_DIMMER_CHANNELS); memset(lastOutputBuffer, 0, NUM_DIMMER_CHANNELS); // Startup ioMuxInit(); eepromInit(); eepromLoad(); lcdInit(); buttonsInit(); uiInit(); ledsInit(); phaseAngleInit(); dmxInit(eepromGetDmxAddress()); // Timer 1 setup - overflow at 100Hz TMR1 = 0; PR1 = 25000; T1CON = 0x8010; // 1:8 prescale (2.5MHz) _T1IF = 0; while(1) { if(_T1IF) { // 100 Hz Timer stuff _T1IF = 0; buttonsCheck(); ledsCheck(); uiResult = uiCheck(); } else { uiResult = 0; } if(uiResult || dmxCheck()) { updateDimmers(); } lcdCheck(); } }
bool init() { rom = (u8 *)malloc(0x2000000); if (!rom) { systemMessage("Failed to allocate memory for %s", "ROM"); return false; } flashInit(); sramInit(); eepromInit(); return true; }
// Get the Leonardo ready for USB communication void setupHardware(void) { // Disable the watch-dog timer if enabled by boot-loader or fuses MCUSR &= ~(1 << WDRF); wdt_disable(); // Disable clock division clock_prescale_set(clock_div_1); // Initialise the hardware USART module #ifdef USART_DEBUG Serial_Init(115200, true); Serial_CreateStream(NULL); printf("USART Debug enabled\r\n"); #endif // Initialise the EEPROM settings eepromInit(); // Initialise the LUFA board driver and USB library LEDs_Init(); USB_Init(); }
static void main_task(void *pvParameters) { int i; char ch; bool selftestPasses = true; /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); MX_SPI1_Init(); MX_USB_DEVICE_Init(); // Light up all LEDs to test ledOn(ledRanging); ledOn(ledSync); ledOn(ledMode); printf("\r\n\r\n====================\r\n"); printf("SYSTEM\t: CPU-ID: "); for (i=0; i<12; i++) { printf("%02x", uid[i]); } printf("\r\n"); // Initializing pressure sensor (if present ...) lps25hInit(&hi2c1); testSupportPrintStart("Initializing pressure sensor"); if (lps25hTestConnection()) { printf("[OK]\r\n"); lps25hSetEnabled(true); } else { printf("[FAIL] (%u)\r\n", (unsigned int)hi2c1.ErrorCode); selftestPasses = false; } testSupportPrintStart("Pressure sensor self-test"); testSupportReport(&selftestPasses, lps25hSelfTest()); // Initializing i2c eeprom eepromInit(&hi2c1); testSupportPrintStart("EEPROM self-test"); testSupportReport(&selftestPasses, eepromTest()); cfgInit(); // Initialising radio testSupportPrintStart("Initialize UWB "); uwbInit(); if (uwbTest()) { printf("[OK]\r\n"); } else { printf("[ERROR]: %s\r\n", uwbStrError()); selftestPasses = false; } if (!selftestPasses) { printf("TEST\t: One or more self-tests failed, blocking startup!\r\n"); usbcommSetSystemStarted(true); } // Printing UWB configuration struct uwbConfig_s * uwbConfig = uwbGetConfig(); printf("CONFIG\t: Address is 0x%X\r\n", uwbConfig->address[0]); printf("CONFIG\t: Mode is %s\r\n", uwbAlgorithmName(uwbConfig->mode)); printf("CONFIG\t: Tag mode anchor list (%i): ", uwbConfig->anchorListSize); for (i = 0; i < uwbConfig->anchorListSize; i++) { printf("0x%02X ", uwbConfig->anchors[i]); } printf("\r\n"); HAL_Delay(500); ledOff(ledRanging); ledOff(ledSync); ledOff(ledMode); printf("SYSTEM\t: Node started ...\r\n"); printf("SYSTEM\t: Press 'h' for help.\r\n"); usbcommSetSystemStarted(true); // Starts UWB protocol uwbStart(); // Main loop ... while(1) { usbcommPrintWelcomeMessage(); ledTick(); // // Measure pressure // if (uwbConfig.mode != modeSniffer) { // if(lps25hGetData(&pressure, &temperature, &asl)) { // pressure_ok = true; // } else { // printf("Fail reading pressure\r\n"); // printf("pressure not ok\r\n"); // } // } // Accepts serial commands #ifdef USE_FTDI_UART if (HAL_UART_Receive(&huart1, (uint8_t*)&ch, 1, 0) == HAL_OK) { #else if(usbcommRead(&ch, 1)) { #endif handleInput(ch); } } } /* Function required to use "printf" to print on serial console */ int _write (int fd, const void *buf, size_t count) { // stdout if (fd == 1) { #ifdef USE_FTDI_UART HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY); #else usbcommWrite(buf, count); #endif } // stderr if (fd == 2) { HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY); } return count; } static void handleInput(char ch) { bool configChanged = true; static enum menu_e {mainMenu, modeMenu} currentMenu = mainMenu; switch (currentMenu) { case mainMenu: switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': changeAddress(ch - '0'); break; case 'a': changeMode(MODE_ANCHOR); break; case 't': changeMode(MODE_TAG); break; case 's': changeMode(MODE_SNIFFER); break; case 'm': printModeList(); printf("Type 0-9 to choose new mode...\r\n"); currentMenu = modeMenu; configChanged = false; break; case 'd': restConfig(); break; case 'h': help(); configChanged = false; break; case '#': productionTestsRun(); printf("System halted, reset to continue\r\n"); while(true){} break; default: configChanged = false; break; } break; case modeMenu: switch(ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': changeMode(ch - '0'); currentMenu = mainMenu; break; default: printf("Incorrect mode '%c'\r\n", ch); currentMenu = mainMenu; configChanged = false; break; } break; } if (configChanged) { printf("EEPROM configuration changed, restart for it to take effect!\r\n"); } }
void dIMUInit(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; NVIC_InitTypeDef NVIC_InitStructure; #ifdef DIMU_HAVE_MPU6000 mpu6000PreInit(); #endif #ifdef DIMU_HAVE_MAX21100 max21100PreInit(); #endif #ifdef DIMU_HAVE_EEPROM eepromPreInit(); #endif #ifdef DIMU_HAVE_HMC5983 hmc5983PreInit(); #endif #ifdef DIMU_HAVE_MS5611 ms5611PreInit(); #endif #ifdef DIMU_HAVE_MPU6000 mpu6000Init(); #endif #ifdef DIMU_HAVE_MAX21100 max21100Init(); #endif #ifdef DIMU_HAVE_EEPROM eepromInit(); // dIMUWriteCalib(); dIMUReadCalib(); #endif #ifdef DIMU_HAVE_HMC5983 if (hmc5983Init() == 0) AQ_NOTICE("DIMU: MAG sensor init failed!\n"); #endif #ifdef DIMU_HAVE_MS5611 if (ms5611Init() == 0) AQ_NOTICE("DIMU: PRES sensor init failed!\n"); #endif dIMUTaskStack = aqStackInit(DIMU_STACK_SIZE, "DIMU"); dImuData.flag = CoCreateFlag(1, 0); dImuData.task = CoCreateTask(dIMUTaskCode, (void *)0, DIMU_PRIORITY, &dIMUTaskStack[DIMU_STACK_SIZE-1], DIMU_STACK_SIZE); // setup digital IMU timer DIMU_EN; // Time base configuration for 1MHz (us) TIM_TimeBaseStructure.TIM_Period = 0xffff; TIM_TimeBaseStructure.TIM_Prescaler = (DIMU_CLOCK / 1000000) - 1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(DIMU_TIM, &TIM_TimeBaseStructure); // reset TIM_SetCounter(DIMU_TIM, 0); // Output Compare for alarms TIM_OCStructInit(&TIM_OCInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Inactive; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(DIMU_TIM, &TIM_OCInitStructure); TIM_OC1PreloadConfig(DIMU_TIM, TIM_OCPreload_Disable); TIM_OC2Init(DIMU_TIM, &TIM_OCInitStructure); TIM_OC2PreloadConfig(DIMU_TIM, TIM_OCPreload_Disable); // Enable the global Interrupt NVIC_InitStructure.NVIC_IRQChannel = DIMU_IRQ_CH; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // reset TIM_SetCounter(DIMU_TIM, 0); dIMUCancelAlarm1(); // go... TIM_Cmd(DIMU_TIM, ENABLE); #ifdef DIMU_HAVE_MPU6000 mpu6000Enable(); #endif #ifdef DIMU_HAVE_MAX21100 max21100Enable(); #endif #ifdef DIMU_HAVE_HMC5983 hmc5983Enable(); #endif #ifdef DIMU_HAVE_MS5611 ms5611Enable(); #endif // setup IMU timestep alarm dImuData.nextPeriod = DIMU_TIM->CCR2 + DIMU_INNER_PERIOD; DIMU_TIM->CCR2 = dImuData.nextPeriod; DIMU_TIM->DIER |= TIM_IT_CC2; #ifdef DIMU_HAVE_MPU6000 mpu6600InitialBias(); #endif #ifdef DIMU_HAVE_MAX21100 max21100InitialBias(); #endif #ifdef DIMU_HAVE_MS5611 ms5611InitialBias(); #endif }
//---------------------------------------------------------- // System initialization //---------------------------------------------------------- static inline void initSystem(void) { bool success; (void)success; // disable interrupts: disabled on msp430 by default, but other systems might need this DISABLE_INTS(); // stop the watchdog: GCC disables it by default, but other compilers might not be so helpful watchdogStop(); // TODO: init dynamic memory // platformMemInit(); // basic, platform-specific initialization: timers, platform-specific drivers (?) initPlatform(); // start energy accounting (as soon as timers are initialized) energyConsumerOn(ENERGY_CONSUMER_MCU); #ifdef USE_PRINT // init printing to serial (makes sense only after clock has been calibrated) if (printInit != NULL) printInit(); #endif INIT_PRINTF("starting MansOS...\n"); #ifdef USE_LEDS INIT_PRINTF("init LED(s)...\n"); ledsInit(); #endif #ifdef USE_BEEPER beeperInit(); #endif #ifdef RAMTEXT_START if ((MemoryAddress_t)&_end > RAMTEXT_START) { // Panic right aways on RAM overflow. // In case this happens, you might want to increase the address // specified by CONST_RAMTEXT_START in config file assertionFailed("Overflow between .data and .ramtext sections", __FILE__, __LINE__); } #endif #ifdef USE_ADC if (adcInit != NULL) { INIT_PRINTF("init ADC...\n"); adcInit(); } #endif #ifdef USE_RANDOM INIT_PRINTF("init RNG...\n"); randomInit(); #endif #if USE_ALARMS INIT_PRINTF("init alarms...\n"); initAlarms(); #endif #ifdef USE_RADIO INIT_PRINTF("init radio...\n"); radioInit(); #endif #ifdef USE_ADDRESSING INIT_PRINTF("init communication stack...\n"); networkingInit(); #endif #ifdef USE_EXT_FLASH INIT_PRINTF("init external flash...\n"); extFlashInit(); #endif #ifdef USE_SDCARD INIT_PRINTF("init SD card...\n"); sdcardInit(); #endif #ifdef USE_EEPROM INIT_PRINTF("init EEPROM...\n"); eepromInit(); #endif #ifdef USE_ISL29003 INIT_PRINTF("init ISL light sensor...\n"); success = islInit(); if (!success) { INIT_PRINTF("ISL init failed!\n"); } #endif #ifdef USE_ADS1115 INIT_PRINTF("init ADS111x ADC converter chip...\n"); adsInit(); #endif #if USE_ADS8638 INIT_PRINTF("init ADS8638 ADC converter chip...\n"); ads8638Init(); #endif #if USE_ADS8328 INIT_PRINTF("init ADS8328 ADC converter chip...\n"); ads8328Init(); #endif #if USE_AD5258 INIT_PRINTF("init AD5258 digital potentiometer...\n"); ad5258Init(); #endif #if USE_DAC7718 INIT_PRINTF("init DAC7718 DAC converter chip...\n"); dac7718Init(); #endif #if USE_ISL1219 INIT_PRINTF("init ISL1219 real-time clock chip...\n"); isl1219Init(); #endif #ifdef USE_HUMIDITY INIT_PRINTF("init humidity sensor...\n"); humidityInit(); #endif #ifdef USE_ACCEL INIT_PRINTF("init accelerometer...\n"); accelInit(); #endif #ifdef USE_TIMESYNC INIT_PRINTF("init base station time sync...\n"); timesyncInit(); #endif #ifdef USE_SMP INIT_PRINTF("init SSMP...\n"); smpInit(); #endif #ifdef USE_REPROGRAMMING INIT_PRINTF("init reprogramming...\n"); bootParamsInit(); #endif #ifdef USE_DCO_RECALIBRATION extern void dcoRecalibrationInit(void); INIT_PRINTF("init DCO recalibration...\n"); dcoRecalibrationInit(); #endif #ifdef USE_FS INIT_PRINTF("init file system...\n"); fsInit(); #endif #ifdef USE_FATFS INIT_PRINTF("init FAT file system...\n"); fatFsInit(); INIT_PRINTF("init POSIX-like file routines...\n"); posixStdioInit(); #endif #ifdef USE_WMP INIT_PRINTF("init WMP...\n"); wmpInit(); #endif #ifdef USE_SEAL_NET INIT_PRINTF("init SEAL networking...\n"); sealNetInit(); #endif INIT_PRINTF("starting the application...\n"); }