Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 131 lines (112 sloc) 3.237 kb
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
1 /*
2 * FAN_Subsystem.c
3 *
4 * Created: 11/02/2013 23:10:36
Nasser64
Working on latency
Nasser64 authored
168e37a
5 * Author: NASSER GHOSEIRI
Luke-Jr
Add Company line to comments per request
luke-jr authored
6434e15
6 * Company: Butterfly Labs
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
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"
Nasser64
Working on latency
Nasser64 authored
168e37a
18 #include "ASIC_Engine.h"
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
19
20 // Now to our codes
21 volatile void FAN_SUBSYS_Initialize(void)
22 {
23 // Initialize state to 0
Nasser64
Before refactoring
Nasser64 authored
e46cf74
24 __AVR32_FAN_Initialize();
25 FAN_SUBSYS_SetFanState(FAN_STATE_AUTO);
26 GLOBAL_CRITICAL_TEMPERATURE = FALSE;
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
27 }
28
29 volatile void FAN_SUBSYS_IntelligentFanSystem_Spin(void)
30 {
Nasser64
Back from Italy; before modifications
Nasser64 authored
71b6193
31
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
32 // Check temperature
33 volatile int iTemp1 = __AVR32_A2D_GetTemp1();
34 volatile int iTemp2 = __AVR32_A2D_GetTemp2();
GuardMoony
Jala Only
authored
369fba7
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; }
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
41
GuardMoony
Jala Only
authored
369fba7
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 )
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
44 {
45 // Holy jesus! We're in a critical situation...
Nasser64
16us latency; most transactions are ok; optimization -O2
Nasser64 authored
1da417a
46 GLOBAL_CRITICAL_TEMPERATURE = TRUE;
GuardMoony
Jala Only
authored
369fba7
47 // Set max fan speed
48 __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_REMAIN_FULL_SPEED);
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
49
Nasser64
Theoretically finished firmware, subject to tests
Nasser64 authored
73590d0
50 }
GuardMoony
Jala Only
authored
369fba7
51
52 if (GLOBAL_CRITICAL_TEMPERATURE == TRUE)
Nasser64
Theoretically finished firmware, subject to tests
Nasser64 authored
73590d0
53 {
GuardMoony
Jala Only
authored
369fba7
54 if (iTempHigh < 60) // Hysterysis
55 {
56 GLOBAL_CRITICAL_TEMPERATURE = FALSE;
Nasser64
Working on latency
Nasser64 authored
168e37a
57
GuardMoony
Jala Only
authored
369fba7
58 // Increase thermal cycle counter
59 GLOBAL_TOTAL_THERMAL_CYCLES++;
Nasser64
Auto-restart in some conditions, and XLINK debug stuff
Nasser64 authored
b042821
60
GuardMoony
Jala Only
authored
369fba7
61 // Also, restart the ASICs
62 #if defined(__ASICS_RESTART_AFTER_HIGH_TEMP_RECOVERY)
63 init_ASIC();
64 #endif
Nasser64
Before refactoring
Nasser64 authored
e46cf74
65 }
GuardMoony
Jala Only
authored
369fba7
66 }
67
Nasser64
Theoretically finished firmware, subject to tests
Nasser64 authored
73590d0
68
Nasser64
Before refactoring
Nasser64 authored
e46cf74
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;
GuardMoony
Removed some single code
authored
4fdf9e6
73 #endif
74
75 #if defined(FAN_SUBSYSTEM_AUTO_MODE)
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
76
GuardMoony
Fan Auto Mode
authored
4d0f820
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
GuardMoony
Jala Only
authored
369fba7
99
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
100 // Ok, now set the FAN speed according to our setting
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
101 switch (FAN_ActualState)
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
102 {
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
103 case FAN_STATE_VERY_SLOW:
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
104 // Set the fan speed
105 __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_SLOW);
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
106 break;
107 case FAN_STATE_SLOW:
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
108 __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_SLOW);
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
109 break;
110 case FAN_STATE_MEDIUM:
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
111 __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_MEDIUM);
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
112 break;
113 case FAN_STATE_FAST:
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
114 __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_FAST);
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
115 break;
116 case FAN_STATE_VERY_FAST:
GuardMoony
Jala Only
authored
369fba7
117 default:
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
118 __AVR32_FAN_SetSpeed(FAN_CONTROL_BYTE_VERY_FAST);
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
119 break;
GuardMoony
Fan Auto Mode
authored
4d0f820
120 }
121
Nasser64
Backup on 13th Feb 2013 before adding dynamic chain feature
Nasser64 authored
5e6b3e1
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;
GuardMoony
Update FAN_Subsystem.c
authored
9f4e914
130 }
Something went wrong with that request. Please try again.