This function is the program entry point. After setting up the hardware, initiating all software modules and displaying firmware information on serial out the function will enter the application loop. What operations the application loop executes: Always:
Every 256ms:
Every 512ms:
Every 1024ms:
The application loop never returns.
Definition at line 141 of file ula_repl.c. References adc_Read(), ADC_SWITCH, ALL_LEDS_OFF, S_MEM_STRUCTRUE::bIsPedelec, COND_TEMP_ERR, current_GetValue(), current_Update(), current_UpdateAvg(), current_UpdateSum(), FALSE, fan_Set(), init_InitIO(), init_InitModules(), memory_Get(), mg_bIsPedelec, mg_RelayControl(), mg_u16FanTemp, mg_u16SpeedLimitMax, mg_u16SpeedLimitMin, mg_u8NumMagnetsPedal, mg_u8NumMagnetsTacho, OFF, ON, pedal_GetRpm(), pedal_GetTimeout(), relay_Enable(), safety_GetCondition(), safety_GetCRC(), safety_MemoryTest(), speaker_Off(), speed_CheckTimeout(), SPEED_GET, speed_GetDistance(), temp_Check(), temp_GetAvg(), temp_GetCelsius(), temp_Update(), timer_GetSystemTime(), TIMER_IS_TICK1024, TIMER_IS_TICK128, TIMER_IS_TICK256, TIMER_IS_TICK512, timer_LockTicks(), S_MEM_STRUCTRUE::u16SpeedLimitMax, S_MEM_STRUCTRUE::u16SpeedLimitMin, S_MEM_STRUCTRUE::u16TempFan, S_MEM_STRUCTRUE::u8NumMagnetsPedal, S_MEM_STRUCTRUE::u8NumMagnetsTacho, voltage_GetRef(), voltage_GetValue(), voltage_Update(), and voltage_UpdateAvg(). { UINT8 u8Help = 0U; E_BOOL bMotorEnabled = FALSE; /* init IO ports */ init_InitIO(); /* init modules */ cli(); init_InitModules(); sei(); ALL_LEDS_OFF(); /* get settings from EEPROM memory */ mg_bIsPedelec = memory_Get()->bIsPedelec; mg_u16SpeedLimitMax = memory_Get()->u16SpeedLimitMax; mg_u16SpeedLimitMin = memory_Get()->u16SpeedLimitMin; mg_u16FanTemp = memory_Get()->u16TempFan; mg_u8NumMagnetsTacho = memory_Get()->u8NumMagnetsTacho; mg_u8NumMagnetsPedal = memory_Get()->u8NumMagnetsPedal; /* print firmware version on serial out */ printf("ULA replacement V%d\n\n", pgm_read_word(MEMPOS_VER)); printf("CRC: 0x%08lX\n\n", safety_GetCRC()); /* print settings on serial out */ printf("PM: %d\n", mg_bIsPedelec); printf("WS: %umm\n", memory_Get()->u16WheelSize); printf("LMX: %u\n", mg_u16SpeedLimitMax); printf("LMN: %u\n", mg_u16SpeedLimitMin); printf("FT: %u\n", mg_u16FanTemp); printf("NMT: %u\n", mg_u8NumMagnetsTacho); printf("NMP: %u\n\n", mg_u8NumMagnetsPedal); /* put relay and speaker to default conditions */ relay_Enable(FALSE); speaker_Off(); /* reset watchdog before entering the main loop */ wdt_reset(); // zum testen: while(1) { asm("nop"); } /* application loop */ while (1) { /* lock the timer bits during this while loop cycle */ timer_LockTicks(); /* meassure momentary voltage and current values */ voltage_Update(); current_Update(); /* meassure the motor temperature */ temp_Update(); /* every 1024ms: check temperature for overheating */ if(TIMER_IS_TICK1024()) { temp_Check(); } /* activate the fan if the average temperature exeeds or equals the configurated temperature threshold */ if(temp_GetCelsius(temp_GetAvg()) >= mg_u16FanTemp) { fan_Set(ON); } /* check every 10240ms if we can deactivate the fan */ if(TIMER_IS_TICK1024()) { u8Help++; if(u8Help >= 10U) { u8Help = 0U; if(temp_GetCelsius(temp_GetAvg()) < mg_u16FanTemp) { /* fan may be deactivated only if there is no temperature error condition set */ if((safety_GetCondition() & COND_TEMP_ERR) == 0U) { fan_Set(OFF); } } } } /* every 512ms: calculate average voltage and current draw */ if(TIMER_IS_TICK512()) { voltage_UpdateAvg(); current_UpdateSum(); } /* every 256ms: update average motor current */ if(TIMER_IS_TICK128()) { current_UpdateAvg(); } /* always check for speed and pedal signal timeouts */ speed_CheckTimeout(timer_GetSystemTime()); pedal_GetTimeout(); /* after all checks and data updates above, we are ready to determine wether the relay has to be enabled or disabled */ bMotorEnabled = mg_RelayControl(); /* Memory test. The memory range to be tested is byte address 0 to 7164 (3582 words). Note: This function will not return in case of a memory failure. */ safety_MemoryTest(); /* every 256ms: handle further jobs */ if(TIMER_IS_TICK256()) { /* reset watchdog */ wdt_reset(); /* print information on serial out */ printf("#"); printf("%lu|", speed_GetDistance()); // distance printf("%lu|", SPEED_GET()); // speed (10th of km/h) printf("%lu|", pedal_GetRpm()); // upm printf("%lu|", pedal_GetTimeout()); // timeout printf("%u|", adc_Read(ADC_SWITCH)); // switch printf("%u|", temp_GetAvg()); // vth printf("%u|", voltage_GetValue()); // voltage printf("%u|", voltage_GetRef()); // vref printf("%u|", current_GetValue()); // current printf("%u|", bMotorEnabled); // motor enabled? printf("%u|", safety_GetCondition()); // condition printf("%lu|", timer_GetSystemTime()); // timestamp printf("\n"); } } /* end of: while(1) application loop */ return (1); /* never reached */ } /* End: main() */
Here is the call graph for this function:
![]() |