/* main ***********************************************************************/ int main(void) { CO_NMT_reset_cmd_t reset = CO_RESET_NOT; InitCanLeds(); DBGU_Configure(115200); TRACE_INFO_WP("\n\rCanOpenNode %s (%s %s)\n\r", cVer, __DATE__, __TIME__); /* Configure Timer interrupt function for execution every 1 millisecond */ if (SysTick_Config(SysTick_1ms)) TRACE_FATAL("SysTick_Config\n\r"); initTimer(getTimer_us); /* Todo: initialize EEPROM */ /* Todo: Loading COD */ TRACE_INFO("Loading COD\n\r"); /* Verify, if OD structures have proper alignment of initial values */ TRACE_DEBUG("Checking COD in RAM (size=%d)\n\r", &CO_OD_RAM.LastWord - &CO_OD_RAM.FirstWord); if (CO_OD_RAM.FirstWord != CO_OD_RAM.LastWord) TRACE_FATAL("Err COD in RAM\n\r"); TRACE_DEBUG("Checking COD in EEPROM (size=%d)\n\r", &CO_OD_EEPROM.LastWord - &CO_OD_EEPROM.FirstWord); if (CO_OD_EEPROM.FirstWord != CO_OD_EEPROM.LastWord) TRACE_FATAL("Err COD in EEPROM\n\r"); TRACE_DEBUG("Checking COD in ROM (size=%d)\n\r", &CO_OD_ROM.LastWord - &CO_OD_ROM.FirstWord); if (CO_OD_ROM.FirstWord != CO_OD_ROM.LastWord) TRACE_FATAL("Err COD in ROM\n\r"); /* increase variable each startup. Variable is stored in eeprom. */ OD_powerOnCounter++; TRACE_INFO("CO power-on (BTR=%dk Node=0x%x)\n\r", CO_OD_ROM.CANBitRate, CO_OD_ROM.CANNodeID); ttimer tprof; while (reset != CO_RESET_APP) { /* CANopen communication reset - initialize CANopen objects *******************/ static uint32_t timer1msPrevious; CO_ReturnError_t err; /* disable timer interrupts, turn on red LED */ canTimerOff = 1; CanLedsSet(eCoLed_Red); /* initialize CANopen */ err = CO_init(); if (err) { TRACE_FATAL("CO_init\n\r"); /* CO_errorReport(CO->em, CO_EM_MEMORY_ALLOCATION_ERROR, CO_EMC_SOFTWARE_INTERNAL, err); */ } /* start Timer */ canTimerOff = 0; reset = CO_RESET_NOT; timer1msPrevious = CO_timer1ms; TRACE_INFO("CO (re)start\n\r"); while (reset == CO_RESET_NOT) { saveTime(&tprof); /* loop for normal program execution ******************************************/ uint32_t timer1msDiff; timer1msDiff = CO_timer1ms - timer1msPrevious; timer1msPrevious = CO_timer1ms; ClearWDT(); /* CANopen process */ reset = CO_process(CO, timer1msDiff); CanLedsSet((LED_GREEN_RUN(CO->NMT)>0 ? eCoLed_Green : 0) | (LED_RED_ERROR(CO->NMT)>0 ? eCoLed_Red : 0)); ClearWDT(); /* (not implemented) eeprom_process(&eeprom); */ uint32_t t = getTime_us(&tprof); OD_performance[ODA_performance_mainCycleTime] = t; if (t > OD_performance[ODA_performance_mainCycleMaxTime]) OD_performance[ODA_performance_mainCycleMaxTime] = t; } /* while (reset != 0) */ } /* while (reset != 2) */ /* program exit ***************************************************************/ /* save variables to eeprom */ CO_DISABLE_INTERRUPTS(); CanLedsSet(eCoLed_None); /* (not implemented) eeprom_saveAll(&eeprom); */ CanLedsSet(eCoLed_Red); /* delete CANopen object from memory */ CO_delete(); /* reset - by WD */ return 0; }
int main(void) { uint32_t timer1msDiff; uint32_t t; static uint32_t timer1msPrevious; CO_NMT_reset_cmd_t reset = CO_RESET_NOT; HAL_Init(); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /* Enable GPIOA Clock */ LED_GPIOA_CLK_ENABLE(); /* Enable CAN peripherals */ CAN_CLK_ENABLE(); CAN_GPIO_CLK_ENABLE(); // debug_printf("This is a pass test"); /* Initialize LEDs */ InitCanLeds(); /* -3- Toggle IOs in an infinite loop */ CanLedsSet(CoLed_Green); // CanLedsSet(CoLed_Red); // CanLedsSet(CoLed_Blue); // CanLedsSet(CoLed_Yellow); /* Configure Timer interrupt function for execution every 1 ms*/ TIMER_InitRCC(); TIMER_InitGeneral(); /* Program start - Application Call */ programStart(); while (reset != CO_RESET_APP) { /* disable timer interrupts */ NVIC_DisableIRQ(TIM2_IRQn); /* CANopen communication reset - initialize CANopen objects; CanOpen is initialized from within communication reset function */ communicationReset(); /* start Timer interupts*/ NVIC_EnableIRQ(TIM2_IRQn); reset = CO_RESET_NOT; timer1msPrevious = timer1ms; while (reset == CO_RESET_NOT) { /* loop for normal program execution */ timer1msDiff = timer1ms - timer1msPrevious; timer1msPrevious = timer1ms; /* Program Async for SDO and NMT messages */ reset = programAsync(timer1msDiff); // t = getTime_us(&tprof); // t = 100; OD_performance[ODA_performance_mainCycleTime] = t; if (t > OD_performance[ODA_performance_mainCycleMaxTime]) OD_performance[ODA_performance_mainCycleMaxTime] = t; } /* while (reset != 0) */ } /* while (reset != 2) */ /* program exit */ CO_DISABLE_INTERRUPTS(); CanLedsSet(CoLed_None); CanLedsSet(CoLed_Red); /* delete CANopen object from memory */ CO_delete(); }