Rev 1512 | Rev 1532 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1512 | Rev 1528 | ||
|---|---|---|---|
| Line 5... | Line 5... | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | /*----------------------------------------------------------------------------- |
7 | /*----------------------------------------------------------------------------- |
| 8 | * Defines |
8 | * Defines |
| 9 | *---------------------------------------------------------------------------*/ |
9 | *---------------------------------------------------------------------------*/ |
| 10 | #define |
10 | #define OUTPUT0_ON (act_protectedOutput_OUTPUT0_PIN_ACTIVE_STATE) |
| - | 11 | #define OUTPUT0_OFF (1 - OUTPUT0_ON) |
|
| - | 12 | #define OUTPUT0_PIN act_protectedOutput_OUTPUT0_PIN |
|
| - | 13 | ||
| - | 14 | #define OUTPUT1_ON (act_protectedOutput_OUTPUT1_PIN_ACTIVE_STATE) |
|
| - | 15 | #define OUTPUT1_OFF (1 - OUTPUT1_ON) |
|
| - | 16 | #define OUTPUT1_PIN act_protectedOutput_OUTPUT1_PIN |
|
| - | 17 | ||
| - | 18 | #define OUTPUT2_ON (act_protectedOutput_OUTPUT2_PIN_ACTIVE_STATE) |
|
| - | 19 | #define OUTPUT2_OFF (1 - OUTPUT2_ON) |
|
| - | 20 | #define OUTPUT2_PIN act_protectedOutput_OUTPUT2_PIN |
|
| - | 21 | ||
| - | 22 | #define OUTPUT3_ON (act_protectedOutput_OUTPUT3_PIN_ACTIVE_STATE) |
|
| 11 | #define |
23 | #define OUTPUT3_OFF (1 - OUTPUT3_ON) |
| 12 | #define |
24 | #define OUTPUT3_PIN act_protectedOutput_OUTPUT3_PIN |
| 13 | 25 | ||
| 14 | #define DIAG_ASSERTED (act_protectedOutput_DIAG_PIN_ASSERTED_STATE) |
26 | #define DIAG_ASSERTED (act_protectedOutput_DIAG_PIN_ASSERTED_STATE) |
| 15 | #define DIAG_NORMAL (1 - DIAG_ASSERTED) |
27 | #define DIAG_NORMAL (1 - DIAG_ASSERTED) |
| 16 | #define DIAG_PIN act_protectedOutput_DIAG_PIN |
28 | #define DIAG_PIN act_protectedOutput_DIAG_PIN |
| 17 | 29 | ||
| 18 | 30 | ||
| 19 | /*----------------------------------------------------------------------------- |
31 | /*----------------------------------------------------------------------------- |
| 20 | * Types |
32 | * Types |
| 21 | *---------------------------------------------------------------------------*/ |
33 | *---------------------------------------------------------------------------*/ |
| 22 | 34 | ||
| 23 | 35 | ||
| 24 | /*----------------------------------------------------------------------------- |
36 | /*----------------------------------------------------------------------------- |
| 25 | * Variables |
37 | * Variables |
| 26 | *---------------------------------------------------------------------------*/ |
38 | *---------------------------------------------------------------------------*/ |
| - | 39 | ||
| 27 | static uint8_t |
40 | static uint8_t outputStateTarget[act_protectedOutput_NR_OUTPUT_PINS]; |
| - | 41 | ||
| 28 | static uint8_t diagState = DIAG_NORMAL; |
42 | static uint8_t diagState = DIAG_NORMAL; |
| 29 | 43 | ||
| 30 | // is there a recent status change that we should report via CAN? |
44 | // is there a recent status change that we should report via CAN? |
| 31 | static uint8_t diagReportPending = 0; |
45 | static uint8_t diagReportPending = 0; |
| 32 | 46 | ||
| 33 | 47 | ||
| 34 | /*----------------------------------------------------------------------------- |
48 | /*----------------------------------------------------------------------------- |
| 35 | * Internal Function Prototypes |
49 | * Internal Function Prototypes |
| 36 | *---------------------------------------------------------------------------*/ |
50 | *---------------------------------------------------------------------------*/ |
| 37 | static void updateOutput(void); |
51 | static void updateOutput(void); |
| 38 | static void readDiagPin(void); |
52 | static void readDiagPin(void); |
| Line 42... | Line 56... | ||
| 42 | /*----------------------------------------------------------------------------- |
56 | /*----------------------------------------------------------------------------- |
| 43 | * Function Implementations |
57 | * Function Implementations |
| 44 | *---------------------------------------------------------------------------*/ |
58 | *---------------------------------------------------------------------------*/ |
| 45 | 59 | ||
| 46 | static void updateOutput() { |
60 | static void updateOutput() { |
| - | 61 | ||
| - | 62 | #if act_protectedOutput_NR_OUTPUT_PINS >= 1 |
|
| - | 63 | if (outputStateTarget[0] == 0) { |
|
| - | 64 | gpio_set_statement(OUTPUT0_OFF, OUTPUT0_PIN); |
|
| - | 65 | } |
|
| - | 66 | else if (outputStateTarget[0] == 1) { |
|
| - | 67 | if (diagState == DIAG_NORMAL) { |
|
| - | 68 | gpio_set_statement(OUTPUT0_ON, OUTPUT0_PIN); |
|
| - | 69 | } |
|
| - | 70 | else { |
|
| - | 71 | // DIAG override, we cannot set ON state right now |
|
| - | 72 | gpio_set_statement(OUTPUT0_OFF, OUTPUT0_PIN); |
|
| - | 73 | } |
|
| - | 74 | } |
|
| - | 75 | #endif |
|
| - | 76 | ||
| - | 77 | #if act_protectedOutput_NR_OUTPUT_PINS >= 2 |
|
| - | 78 | if (outputStateTarget[1] == 0) { |
|
| - | 79 | gpio_set_statement(OUTPUT1_OFF, OUTPUT1_PIN); |
|
| - | 80 | } |
|
| - | 81 | else if (outputStateTarget[1] == 1) { |
|
| - | 82 | if (diagState == DIAG_NORMAL) { |
|
| - | 83 | gpio_set_statement(OUTPUT1_ON, OUTPUT1_PIN); |
|
| - | 84 | } |
|
| - | 85 | else { |
|
| - | 86 | // DIAG override, we cannot set ON state right now |
|
| - | 87 | gpio_set_statement(OUTPUT1_OFF, OUTPUT1_PIN); |
|
| - | 88 | } |
|
| - | 89 | } |
|
| - | 90 | #endif |
|
| - | 91 | ||
| - | 92 | #if act_protectedOutput_NR_OUTPUT_PINS >= 3 |
|
| - | 93 | if (outputStateTarget[2] == 0) { |
|
| - | 94 | gpio_set_statement(OUTPUT2_OFF, OUTPUT2_PIN); |
|
| - | 95 | } |
|
| - | 96 | else if (outputStateTarget[2] == 1) { |
|
| - | 97 | if (diagState == DIAG_NORMAL) { |
|
| - | 98 | gpio_set_statement(OUTPUT2_ON, OUTPUT2_PIN); |
|
| - | 99 | } |
|
| - | 100 | else { |
|
| - | 101 | // DIAG override, we cannot set ON state right now |
|
| - | 102 | gpio_set_statement(OUTPUT2_OFF, OUTPUT2_PIN); |
|
| - | 103 | } |
|
| - | 104 | } |
|
| - | 105 | #endif |
|
| - | 106 | ||
| - | 107 | #if act_protectedOutput_NR_OUTPUT_PINS >= 4 |
|
| 47 | if ( |
108 | if (outputStateTarget[3] == 0) { |
| 48 | gpio_set_statement( |
109 | gpio_set_statement(OUTPUT3_OFF, OUTPUT3_PIN); |
| 49 | } |
110 | } |
| 50 | else if ( |
111 | else if (outputStateTarget[3] == 1) { |
| 51 | if (diagState == DIAG_NORMAL) { |
112 | if (diagState == DIAG_NORMAL) { |
| 52 | gpio_set_statement( |
113 | gpio_set_statement(OUTPUT3_ON, OUTPUT3_PIN); |
| 53 | } |
114 | } |
| 54 | else { |
115 | else { |
| 55 | // DIAG override, we cannot set ON state right now |
116 | // DIAG override, we cannot set ON state right now |
| 56 | gpio_set_statement( |
117 | gpio_set_statement(OUTPUT3_OFF, OUTPUT3_PIN); |
| 57 | } |
- | |
| 58 | } |
118 | } |
| - | 119 | } |
|
| - | 120 | #endif |
|
| 59 | } |
121 | } |
| 60 | 122 | ||
| 61 | 123 | ||
| 62 | static void readDiagPin() { |
124 | static void readDiagPin() { |
| 63 | diagState = gpio_get_state(DIAG_PIN); |
125 | diagState = gpio_get_state(DIAG_PIN); |
| Line 75... | Line 137... | ||
| 75 | if (act_protectedOutput_RETRY_TIMER_TIME_S > 0) { |
137 | if (act_protectedOutput_RETRY_TIMER_TIME_S > 0) { |
| 76 | Timer_SetTimeout(act_protectedOutput_RETRY_TIMER, act_protectedOutput_RETRY_TIMER_TIME_S*1000, TimerTypeOneShot, 0); |
138 | Timer_SetTimeout(act_protectedOutput_RETRY_TIMER, act_protectedOutput_RETRY_TIMER_TIME_S*1000, TimerTypeOneShot, 0); |
| 77 | } |
139 | } |
| 78 | // if the retry-mechanism is disabled, change the target output state to OFF |
140 | // if the retry-mechanism is disabled, change the target output state to OFF |
| 79 | else { |
141 | else { |
| - | 142 | for (uint8_t i=0; i<act_protectedOutput_NR_OUTPUT_PINS; i++) { |
|
| 80 |
|
143 | outputStateTarget[i] = 0; |
| - | 144 | } |
|
| 81 | } |
145 | } |
| 82 | } |
146 | } |
| 83 | // something interesting obviously happened. let's report it |
147 | // something interesting obviously happened. let's report it |
| 84 | diagReportPending = 1; |
148 | diagReportPending = 1; |
| 85 | } |
149 | } |
| 86 | } |
150 | } |
| 87 | 151 | ||
| 88 | 152 | ||
| 89 | void act_protectedOutput_Init() { |
153 | void act_protectedOutput_Init() { |
| - | 154 | /* |
|
| - | 155 | * Configure DIAG input pin |
|
| - | 156 | */ |
|
| 90 | if (act_protectedOutput_DIAG_PIN_PULL_ENABLED) { |
157 | if (act_protectedOutput_DIAG_PIN_PULL_ENABLED) { |
| 91 | // if DIAG is asserted low, we need pull-up |
158 | // if DIAG is asserted low, we need pull-up |
| 92 | gpio_set_statement(act_protectedOutput_DIAG_PIN_ASSERTED_STATE == 0 ? 1 : 0, DIAG_PIN); |
159 | gpio_set_statement(act_protectedOutput_DIAG_PIN_ASSERTED_STATE == 0 ? 1 : 0, DIAG_PIN); |
| 93 | } |
160 | } |
| 94 | gpio_set_in(DIAG_PIN); |
161 | gpio_set_in(DIAG_PIN); |
| 95 | Pcint_SetCallbackPin(act_protectedOutput_DIAG_PIN_PCINT, DIAG_PIN, &pcIntCallback); |
162 | Pcint_SetCallbackPin(act_protectedOutput_DIAG_PIN_PCINT, DIAG_PIN, &pcIntCallback); |
| 96 | 163 | ||
| - | 164 | /* |
|
| - | 165 | * Configure OUTPUT pins |
|
| - | 166 | */ |
|
| - | 167 | #if act_protectedOutput_NR_OUTPUT_PINS >= 1 |
|
| 97 | gpio_set_statement( |
168 | gpio_set_statement(OUTPUT0_OFF, OUTPUT0_PIN); |
| - | 169 | gpio_set_out(act_protectedOutput_OUTPUT0_PIN); |
|
| - | 170 | #endif |
|
| - | 171 | ||
| - | 172 | #if act_protectedOutput_NR_OUTPUT_PINS >= 2 |
|
| - | 173 | gpio_set_statement(OUTPUT1_OFF, OUTPUT1_PIN); |
|
| 98 | gpio_set_out( |
174 | gpio_set_out(act_protectedOutput_OUTPUT1_PIN); |
| - | 175 | #endif |
|
| - | 176 | ||
| - | 177 | #if act_protectedOutput_NR_OUTPUT_PINS >= 3 |
|
| - | 178 | gpio_set_statement(OUTPUT2_OFF, OUTPUT2_PIN); |
|
| - | 179 | gpio_set_out(act_protectedOutput_OUTPUT2_PIN); |
|
| - | 180 | #endif |
|
| - | 181 | ||
| - | 182 | #if act_protectedOutput_NR_OUTPUT_PINS >= 4 |
|
| - | 183 | gpio_set_statement(OUTPUT3_OFF, OUTPUT3_PIN); |
|
| - | 184 | gpio_set_out(act_protectedOutput_OUTPUT3_PIN); |
|
| - | 185 | #endif |
|
| - | 186 | ||
| - | 187 | for (uint8_t i=0; i<act_protectedOutput_NR_OUTPUT_PINS; i++) { |
|
| - | 188 | outputStateTarget[i] = 0; |
|
| - | 189 | } |
|
| 99 | 190 | ||
| 100 | outputTargetState = OUTPUT_OFF; |
- | |
| 101 | diagState = DIAG_NORMAL; |
191 | diagState = DIAG_NORMAL; |
| 102 | } |
192 | } |
| 103 | 193 | ||
| 104 | 194 | ||
| 105 | void act_protectedOutput_Process() { |
195 | void act_protectedOutput_Process() { |
| Line 150... | Line 240... | ||
| 150 | switch (rxMsg->Header.Command) { |
240 | switch (rxMsg->Header.Command) { |
| 151 | 241 | ||
| 152 | case CAN_MODULE_CMD_PHYSICAL_SETPIN: |
242 | case CAN_MODULE_CMD_PHYSICAL_SETPIN: |
| 153 | 243 | ||
| 154 | if (rxMsg->Length == 2) { |
244 | if (rxMsg->Length == 2) { |
| 155 |
|
245 | uint8_t channel = rxMsg->Data[0]; |
| 156 | if ( |
246 | if (channel >= 0 && channel < act_protectedOutput_NR_OUTPUT_PINS) { |
| 157 |
|
247 | outputStateTarget[channel] = rxMsg->Data[1]; |
| 158 | readDiagPin(); |
248 | readDiagPin(); |
| 159 | updateOutput(); |
249 | updateOutput(); |
| 160 | } |
250 | } |
| 161 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
251 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
| 162 | rxMsg->Length = 2; |
252 | rxMsg->Length = 2; |