/*! * brief Main function. Execution starts here. */ int main(void) { // Reset RIMA counter DEBUG_TotalRIMA_Count = 0; // Initialize everything here... init_mcu(); // Continue... init_mcu_led(); init_pipe_job_system(); init_XLINK(); init_USB(); // Initialize A2D a2d_init(); a2d_get_temp(0); // This is to clear the first invalid conversion result... a2d_get_temp(1); // This is to clear the first invalid conversion result... a2d_get_voltage(0); // This is to clear the first invalid conversion result... a2d_get_voltage(1); // This is to clear the first invalid conversion result... a2d_get_voltage(2); // This is to clear the first invalid conversion result... // Initialize timer MCU_Timer_Initialize(); MCU_Timer_SetInterval(10); MCU_Timer_Start(); // Turn on the front LED MCU_MainLED_Initialize(); MCU_MainLED_Set(); // Initialize flash-saving sequence __AVR32_Flash_Initialize(); // Initialize FAN subsystem FAN_SUBSYS_Initialize(); // Initialize Global Activity Chip LEDs GLOBAL_ChipActivityLEDCounter[0] = 0; GLOBAL_ChipActivityLEDCounter[1] = 0; GLOBAL_ChipActivityLEDCounter[2] = 0; GLOBAL_ChipActivityLEDCounter[3] = 0; GLOBAL_ChipActivityLEDCounter[4] = 0; GLOBAL_ChipActivityLEDCounter[5] = 0; GLOBAL_ChipActivityLEDCounter[6] = 0; GLOBAL_ChipActivityLEDCounter[7] = 0; // Reset the total number of engines detected on startup GLOBAL_TotalEnginesDetectedOnStartup = 0; // Initialize total thermal cycles GLOBAL_TOTAL_THERMAL_CYCLES = 0; // Last time JobIssue was called. GLOBAL_LastJobIssueToAllEngines = 0; // Wait for 500ms before doing anything volatile unsigned int iHolder = MACRO_GetTickCountRet; while (MACRO_GetTickCountRet + 2 - iHolder < 500000) WATCHDOG_RESET; // Perform an ASIC GET CHIP COUNT init_ASIC(); // Now set the side-led's accordingly #if defined(__PRODUCT_MODEL_LITTLE_SINGLE) || defined(__PRODUCT_MODEL_JALAPENO) if (ASIC_does_chip_exist(0) == TRUE) MCU_LED_Set(1); if (ASIC_does_chip_exist(1) == TRUE) MCU_LED_Set(2); if (ASIC_does_chip_exist(2) == TRUE) MCU_LED_Set(3); if (ASIC_does_chip_exist(3) == TRUE) MCU_LED_Set(4); if (ASIC_does_chip_exist(4) == TRUE) MCU_LED_Set(5); if (ASIC_does_chip_exist(5) == TRUE) MCU_LED_Set(6); if (ASIC_does_chip_exist(6) == TRUE) MCU_LED_Set(7); if (ASIC_does_chip_exist(7) == TRUE) MCU_LED_Set(8); #endif // Detect if we're chain master or not [MODIFY] XLINK_ARE_WE_MASTER = XLINK_detect_if_we_are_master(); // For the moment we're the chain master [MODIFY] if (XLINK_ARE_WE_MASTER) { // Wait for a small time blink_medium(); WATCHDOG_RESET; blink_medium(); WATCHDOG_RESET; blink_medium(); WATCHDOG_RESET; blink_medium(); WATCHDOG_RESET; blink_medium(); WATCHDOG_RESET; blink_medium(); WATCHDOG_RESET; // Initialize the XLINK. Interrogate all devices in the chain and assign then addresses if (XLINK_is_cpld_present() == TRUE) { // We're the master, set proper configuration XLINK_set_cpld_id(0); XLINK_set_cpld_master(TRUE); XLINK_set_cpld_passthrough(FALSE); if (XLINK_MASTER_Start_Chain() == FALSE) { // Ok this can be bad, we failed the chain initialization } } } else { if (XLINK_is_cpld_present() == TRUE) { // Disable pass-through and set our cpld-address = 0x1E // We will await enumeration XLINK_set_cpld_id(XLINK_GENERAL_DISPATCH_ADDRESS); XLINK_set_cpld_master(FALSE); XLINK_set_cpld_passthrough(FALSE); } } // Reset global values global_vals[0] = 0; global_vals[1] = 0; global_vals[2] = 0; global_vals[3] = 0; global_vals[4] = 0; global_vals[5] = 0; GLOBAL_BLINK_REQUEST = 0; GLOBAL_PULSE_BLINK_REQUEST = 0; // Clear ASIC Results... This will make sure the diagnostic nonces are cleared unsigned int iNonceValues[16]; unsigned int iNonceCount; ASIC_get_job_status(iNonceValues, &iNonceCount, FALSE, 0); // Did we reset the ASICs internally? GLOBAL_INTERNAL_ASIC_RESET_EXECUTED = FALSE; // Go to our protocol main loop MCU_Main_Loop(); return(0); }
void FAN_SUBSYS_IntelligentFanSystem_Spin(void) { // We execute this function every 50th call /* static char __attempt = 0; if (__attempt++ < 10) return; // It is the 50th call __attempt = 0; */ // Check temperature //int iTemp1 = __AVR32_A2D_GetTemp1(); //int iTemp2 = __AVR32_A2D_GetTemp2(); int iTemp1 = __ARM_A2D_GetTemp1(); int iTemp2 = __ARM_A2D_GetTemp2(); int iTempAveraged = (iTemp1 > iTemp2) ? iTemp1 : iTemp2; // (iTemp2 + iTemp1) / 2; if (iTempAveraged > 90) { // Holy jesus! We're in a critical situation... GLOBAL_CRITICAL_TEMPERATURE = TRUE; } else { if (GLOBAL_CRITICAL_TEMPERATURE == TRUE) { if (iTempAveraged < 60) // Hysterysis { GLOBAL_CRITICAL_TEMPERATURE = FALSE; // Also, restart the ASICs #if defined(__ASICS_RESTART_AFTER_HIGH_TEMP_RECOVERY) init_ASIC(); #endif } } else { // If we're here, it means we're not critical anymore GLOBAL_CRITICAL_TEMPERATURE = FALSE; } } // Do we remain at full speed? If so, get it done and return #if defined(FAN_SUBSYSTEM_REMAIN_AT_FULL_SPEED) __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_REMAIN_FULL_SPEED); return; #endif // Are we close to the critical temperature? Override FAN if necessary if (iTempAveraged > 70) { // Override fan, set it to maximum __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_FAST); // We're done. The device will no longer process nonces return; } // Ok, now set the FAN speed according to our setting if (FAN_ActualState == FAN_STATE_VERY_SLOW) { // Set the fan speed __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_SLOW); return; } else if (FAN_ActualState == FAN_STATE_SLOW) { // Set the fan speed __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_SLOW); return; } else if (FAN_ActualState == FAN_STATE_MEDIUM) { // Set the fan speed __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_MEDIUM); return; } else if (FAN_ActualState == FAN_STATE_FAST) { // Set the fan speed __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_FAST); return; } else if (FAN_ActualState == FAN_STATE_VERY_FAST) { // Set the fan speed __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_FAST); return; } // We're in AUTO mode... There are rules to respect form here... if (iTempAveraged <= 30) { __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_SLOW); } else if ((iTempAveraged > 35) && (iTempAveraged <= 42)) { __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_SLOW); } else if ((iTempAveraged > 45) && (iTempAveraged <= 53)) { __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_MEDIUM); } else if ((iTempAveraged > 57) && (iTempAveraged <= 67)) { __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_FAST); } else if (iTempAveraged > 70) { __ARM_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_FAST); } // Ok, We're done... }