|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 1 | /* | |
| 2 | * FAN_Subsystem.c | |
| 3 | * | |
| 4 | * Created: 11/02/2013 23:10:36 | |
|
Working on latency
Nasser64 authored
|
||
| 5 | * Author: NASSER GHOSEIRI | |
|
Add Company line to comments per request
luke-jr authored
|
||
| 6 | * Company: Butterfly Labs | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 7 | */ | |
| 8 | ||
| 9 | // Include standard definitions | |
| 10 | #include "std_defs.h" | |
| 11 | #include "Generic_Module.h" | |
| 12 | #include "ChainProtocol_Module.h" | |
| 13 | #include <string.h> | |
| 14 | #include "AVR32X\AVR32_Module.h" | |
| 15 | #include <avr32/io.h> | |
| 16 | #include "AVR32_OptimizedTemplates.h" | |
| 17 | #include "FAN_Subsystem.h" | |
|
Working on latency
Nasser64 authored
|
||
| 18 | #include "ASIC_Engine.h" | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 19 | ||
| 20 | // Now to our codes | |
| 21 | volatile void FAN_SUBSYS_Initialize(void) | |
| 22 | { | |
| 23 | // Initialize state to 0 | |
|
Before refactoring
Nasser64 authored
|
||
| 24 | __AVR32_FAN_Initialize(); | |
| 25 | FAN_SUBSYS_SetFanState(FAN_STATE_AUTO); | |
| 26 | GLOBAL_CRITICAL_TEMPERATURE = FALSE; | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 27 | } | |
| 28 | ||
| 29 | volatile void FAN_SUBSYS_IntelligentFanSystem_Spin(void) | |
| 30 | { | |
|
Back from Italy; before modifications
Nasser64 authored
|
||
| 31 | ||
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 32 | // Check temperature | |
| 33 | volatile int iTemp1 = __AVR32_A2D_GetTemp1(); | |
| 34 | volatile int iTemp2 = __AVR32_A2D_GetTemp2(); | |
|
Jala Only
GuardMoony authored
|
||
| 35 | volatile int iTempHigh = 80; // VERY HIGH SPEED MODE ( In case of problems with temp sensors ) | |
| 36 | ||
| 37 | // Using averaged temp is risky. Preferring highest temp reading | |
| 38 | //volatile int iTempAveraged = (iTemp1 > iTemp2) ? iTemp1 : iTemp2; // (iTemp2 + iTemp1) / 2; | |
| 39 | if ( iTemp1 >= iTemp2 ){ iTempHigh = iTemp1; } | |
| 40 | else { iTempHigh = iTemp2; } | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 41 | ||
|
Jala Only
GuardMoony authored
|
||
| 42 | // Check for critical temperature on either sensor | |
| 43 | if ( iTempHigh >= 90 ) //Do this if only 1 reaches 90° ( in case 1 has a low amount of engines or ) | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 44 | { | |
| 45 | // Holy jesus! We're in a critical situation... | |
|
16us latency; most transactions are ok; optimization -O2
Nasser64 authored
|
||
| 46 | GLOBAL_CRITICAL_TEMPERATURE = TRUE; | |
|
Jala Only
GuardMoony authored
|
||
| 47 | // Set max fan speed | |
| 48 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_REMAIN_FULL_SPEED); | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 49 | ||
|
Theoretically finished firmware, subject to tests
Nasser64 authored
|
||
| 50 | } | |
|
Jala Only
GuardMoony authored
|
||
| 51 | ||
| 52 | if (GLOBAL_CRITICAL_TEMPERATURE == TRUE) | |
|
Theoretically finished firmware, subject to tests
Nasser64 authored
|
||
| 53 | { | |
|
Jala Only
GuardMoony authored
|
||
| 54 | if (iTempHigh < 60) // Hysterysis | |
| 55 | { | |
| 56 | GLOBAL_CRITICAL_TEMPERATURE = FALSE; | |
|
Working on latency
Nasser64 authored
|
||
| 57 | ||
|
Jala Only
GuardMoony authored
|
||
| 58 | // Increase thermal cycle counter | |
| 59 | GLOBAL_TOTAL_THERMAL_CYCLES++; | |
|
Auto-restart in some conditions, and XLINK debug stuff
Nasser64 authored
|
||
| 60 | ||
|
Jala Only
GuardMoony authored
|
||
| 61 | // Also, restart the ASICs | |
| 62 | #if defined(__ASICS_RESTART_AFTER_HIGH_TEMP_RECOVERY) | |
| 63 | init_ASIC(); | |
| 64 | #endif | |
|
Before refactoring
Nasser64 authored
|
||
| 65 | } | |
|
Jala Only
GuardMoony authored
|
||
| 66 | } | |
| 67 | ||
|
Theoretically finished firmware, subject to tests
Nasser64 authored
|
||
| 68 | ||
|
Before refactoring
Nasser64 authored
|
||
| 69 | // Do we remain at full speed? If so, get it done and return | |
| 70 | #if defined(FAN_SUBSYSTEM_REMAIN_AT_FULL_SPEED) | |
| 71 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_REMAIN_FULL_SPEED); | |
| 72 | return; | |
|
Removed some single code
GuardMoony authored
|
||
| 73 | #endif | |
| 74 | ||
| 75 | #if defined(FAN_SUBSYSTEM_AUTO_MODE) | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 76 | ||
|
Fan Auto Mode
GuardMoony authored
|
||
| 77 | // We're in AUTO mode... There are rules to respect form here... | |
| 78 | if (iTempHigh <= 32) | |
| 79 | { | |
| 80 | FAN_ActualState = FAN_STATE_VERY_SLOW; | |
| 81 | } | |
| 82 | else if ((iTempHigh > 35) && (iTempHigh <= 42)) | |
| 83 | { | |
| 84 | FAN_ActualState = FAN_STATE_SLOW; | |
| 85 | } | |
| 86 | else if ((iTempHigh > 45) && (iTempHigh <= 53)) | |
| 87 | { | |
| 88 | FAN_ActualState = FAN_STATE_MEDIUM; | |
| 89 | } | |
| 90 | else if ((iTempHigh > 57) && (iTempHigh <= 67)) | |
| 91 | { | |
| 92 | FAN_ActualState = FAN_STATE_FAST; | |
| 93 | } | |
| 94 | else if (iTempHigh > 70) | |
| 95 | { | |
| 96 | FAN_ActualState = FAN_STATE_VERY_FAST; | |
| 97 | } | |
| 98 | #endif | |
|
Jala Only
GuardMoony authored
|
||
| 99 | ||
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 100 | // Ok, now set the FAN speed according to our setting | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 101 | switch (FAN_ActualState) | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 102 | { | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 103 | case FAN_STATE_VERY_SLOW: | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 104 | // Set the fan speed | |
| 105 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_SLOW); | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 106 | break; | |
| 107 | case FAN_STATE_SLOW: | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 108 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_SLOW); | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 109 | break; | |
| 110 | case FAN_STATE_MEDIUM: | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 111 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_MEDIUM); | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 112 | break; | |
| 113 | case FAN_STATE_FAST: | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 114 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_FAST); | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 115 | break; | |
| 116 | case FAN_STATE_VERY_FAST: | |
|
Jala Only
GuardMoony authored
|
||
| 117 | default: | |
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 118 | __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_FAST); | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 119 | break; | |
|
Fan Auto Mode
GuardMoony authored
|
||
| 120 | } | |
| 121 | ||
|
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
|
||
| 122 | ||
| 123 | // Ok, We're done... | |
| 124 | } | |
| 125 | ||
| 126 | volatile void FAN_SUBSYS_SetFanState(char iState) | |
| 127 | { | |
| 128 | FAN_ActualState = iState; | |
| 129 | FAN_ActualState_EnteredTick = MACRO_GetTickCountRet; | |
|
Update FAN_Subsystem.c
GuardMoony authored
|
||
| 130 | } |