Rev 1183 | Rev 1240 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1183 | Rev 1184 | ||
|---|---|---|---|
| Line 8... | Line 8... | ||
| 8 | uint8_t pwmDefaultState,pwmDefaultStartState,act_softPWM_ReportInterval; |
8 | uint8_t pwmDefaultState,pwmDefaultStartState,act_softPWM_ReportInterval; |
| 9 | uint16_t pwmDefaultValue; |
9 | uint16_t pwmDefaultValue; |
| 10 | uint16_t pwmPeriod; |
10 | uint16_t pwmPeriod; |
| 11 | uint8_t pwmStatus; |
11 | uint8_t pwmStatus; |
| 12 | uint8_t currentSendChannelId = 0; |
12 | uint8_t currentSendChannelId = 0; |
| 13 | - | ||
| 14 | #ifdef PIN_2_ID |
- | |
| 15 | #warning Hej2 |
- | |
| 16 | #endif |
- | |
| 17 | 13 | ||
| 18 | 14 | ||
| 19 | #ifdef act_softPWM_USEEEPROM |
15 | #ifdef act_softPWM_USEEEPROM |
| 20 | #include "act_softPWM_eeprom.h" |
16 | #include "act_softPWM_eeprom.h" |
| 21 | struct eeprom_act_softPWM EEMEM eeprom_act_softPWM = |
17 | struct eeprom_act_softPWM EEMEM eeprom_act_softPWM = |
| Line 63... | Line 59... | ||
| 63 | gpio_set_out(PIN_1); |
59 | gpio_set_out(PIN_1); |
| 64 | gpio_clr_pin(PIN_1); |
60 | gpio_clr_pin(PIN_1); |
| 65 | #endif |
61 | #endif |
| 66 | #ifdef PIN_2 |
62 | #ifdef PIN_2 |
| 67 | gpio_set_out(PIN_2); |
63 | gpio_set_out(PIN_2); |
| 68 | gpio_clr_pin(PIN_2); |
64 | gpio_clr_pin(PIN_2); |
| 69 | #endif |
65 | #endif |
| 70 | #ifdef PIN_3 |
66 | #ifdef PIN_3 |
| 71 | gpio_set_out(PIN_3); |
67 | gpio_set_out(PIN_3); |
| 72 | gpio_clr_pin(PIN_3); |
68 | gpio_clr_pin(PIN_3); |
| 73 | #endif |
69 | #endif |
| Line 112... | Line 108... | ||
| 112 | #ifdef PIN_3 |
108 | #ifdef PIN_3 |
| 113 | gpio_set_pin(PIN_3); |
109 | gpio_set_pin(PIN_3); |
| 114 | #endif |
110 | #endif |
| 115 | #ifdef PIN_4 |
111 | #ifdef PIN_4 |
| 116 | gpio_set_pin(PIN_4); |
112 | gpio_set_pin(PIN_4); |
| 117 | #endif |
113 | #endif |
| 118 | #ifdef PIN_5 |
114 | #ifdef PIN_5 |
| 119 | gpio_set_pin(PIN_5); |
115 | gpio_set_pin(PIN_5); |
| 120 | #endif |
116 | #endif |
| 121 | #ifdef PIN_6 |
117 | #ifdef PIN_6 |
| 122 | gpio_set_pin(PIN_6); |
118 | gpio_set_pin(PIN_6); |
| 123 | #endif |
119 | #endif |
| 124 | #ifdef PIN_7 |
120 | #ifdef PIN_7 |
| 125 | gpio_set_pin(PIN_7); |
121 | gpio_set_pin(PIN_7); |
| 126 | #endif |
122 | #endif |
| 127 | } |
123 | } |
| 128 | #ifdef PIN_0 |
124 | #ifdef PIN_0 |
| 129 | if (currentTimer >= pwmValue[ |
125 | if (currentTimer >= pwmValue[0]) { |
| 130 | gpio_clr_pin(PIN_0); |
126 | gpio_clr_pin(PIN_0); |
| 131 | } |
127 | } |
| 132 | #endif |
128 | #endif |
| 133 | #ifdef PIN_1 |
129 | #ifdef PIN_1 |
| 134 | if (currentTimer >= pwmValue[ |
130 | if (currentTimer >= pwmValue[1]) { |
| 135 | gpio_clr_pin(PIN_1); |
131 | gpio_clr_pin(PIN_1); |
| 136 | } |
132 | } |
| 137 | #endif |
133 | #endif |
| 138 | #ifdef PIN_2_ID |
- | |
| 139 | #warning Hej3 |
- | |
| 140 | #endif |
- | |
| 141 | - | ||
| 142 | #ifdef PIN_2 |
134 | #ifdef PIN_2 |
| 143 | if (currentTimer >= pwmValue[ |
135 | if (currentTimer >= pwmValue[2]) { |
| 144 | gpio_clr_pin(PIN_2); |
136 | gpio_clr_pin(PIN_2); |
| 145 | } |
137 | } |
| 146 | #endif |
138 | #endif |
| 147 | #ifdef PIN_3 |
139 | #ifdef PIN_3 |
| 148 | if (currentTimer >= pwmValue[ |
140 | if (currentTimer >= pwmValue[3]) { |
| 149 | gpio_clr_pin(PIN_3); |
141 | gpio_clr_pin(PIN_3); |
| 150 | } |
142 | } |
| 151 | #endif |
143 | #endif |
| 152 | #ifdef PIN_4 |
144 | #ifdef PIN_4 |
| 153 | if (currentTimer >= pwmValue[ |
145 | if (currentTimer >= pwmValue[4]) { |
| 154 | gpio_clr_pin(PIN_4); |
146 | gpio_clr_pin(PIN_4); |
| 155 | } |
147 | } |
| 156 | #endif |
148 | #endif |
| 157 | #ifdef PIN_5 |
149 | #ifdef PIN_5 |
| 158 | if (currentTimer >= pwmValue[ |
150 | if (currentTimer >= pwmValue[5]) { |
| 159 | gpio_clr_pin(PIN_5); |
151 | gpio_clr_pin(PIN_5); |
| 160 | } |
152 | } |
| 161 | #endif |
153 | #endif |
| 162 | #ifdef PIN_6 |
154 | #ifdef PIN_6 |
| 163 | if (currentTimer >= pwmValue[ |
155 | if (currentTimer >= pwmValue[6]) { |
| 164 | gpio_clr_pin(PIN_6); |
156 | gpio_clr_pin(PIN_6); |
| 165 | } |
157 | } |
| 166 | #endif |
158 | #endif |
| 167 | #ifdef PIN_7 |
159 | #ifdef PIN_7 |
| 168 | if (currentTimer >= pwmValue[ |
160 | if (currentTimer >= pwmValue[7]) { |
| 169 | gpio_clr_pin(PIN_7); |
161 | gpio_clr_pin(PIN_7); |
| 170 | } |
162 | } |
| 171 | #endif |
163 | #endif |
| 172 | } |
164 | } |
| 173 | if (Timer_Expired(act_softPWM_SEND_TIMER)) { |
165 | if (Timer_Expired(act_softPWM_SEND_TIMER)) { |
| - | 166 | while(1) |
|
| - | 167 | { |
|
| - | 168 | if (0 |
|
| - | 169 | #ifdef PIN_0 |
|
| - | 170 | || currentSendChannelId == 0 |
|
| - | 171 | #endif |
|
| - | 172 | #ifdef PIN_1 |
|
| - | 173 | || currentSendChannelId == 1 |
|
| - | 174 | #endif |
|
| - | 175 | #ifdef PIN_2 |
|
| - | 176 | || currentSendChannelId == 2 |
|
| - | 177 | #endif |
|
| - | 178 | #ifdef PIN_3 |
|
| - | 179 | || currentSendChannelId == 3 |
|
| - | 180 | #endif |
|
| - | 181 | #ifdef PIN_4 |
|
| - | 182 | || currentSendChannelId == 4 |
|
| - | 183 | #endif |
|
| - | 184 | #ifdef PIN_5 |
|
| - | 185 | || currentSendChannelId == 5 |
|
| - | 186 | #endif |
|
| - | 187 | #ifdef PIN_6 |
|
| - | 188 | || currentSendChannelId == 6 |
|
| - | 189 | #endif |
|
| - | 190 | #ifdef PIN_7 |
|
| - | 191 | || currentSendChannelId == 7 |
|
| - | 192 | #endif |
|
| - | 193 | ) { |
|
| - | 194 | break; |
|
| - | 195 | } |
|
| - | 196 | currentSendChannelId++; |
|
| - | 197 | if (currentSendChannelId >= NUMBEROFCHANNELS) |
|
| - | 198 | currentSendChannelId=0; |
|
| - | 199 | } |
|
| 174 | StdCan_Msg_t txMsg; |
200 | StdCan_Msg_t txMsg; |
| 175 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); |
201 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); |
| 176 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
202 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 177 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM; |
203 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM; |
| 178 | txMsg.Header.ModuleId = act_softPWM_ID; |
204 | txMsg.Header.ModuleId = act_softPWM_ID; |
| Line 198... | Line 224... | ||
| 198 | rxMsg->Header.ModuleId == act_softPWM_ID) |
224 | rxMsg->Header.ModuleId == act_softPWM_ID) |
| 199 | { |
225 | { |
| 200 | switch (rxMsg->Header.Command) |
226 | switch (rxMsg->Header.Command) |
| 201 | { |
227 | { |
| 202 | case CAN_MODULE_CMD_PHYSICAL_PWM: |
228 | case CAN_MODULE_CMD_PHYSICAL_PWM: |
| - | 229 | if (rxMsg->Length > 3) |
|
| - | 230 | { |
|
| 203 | if ((((uint16_t)rxMsg->Data[1])<8) + rxMsg->Data[2] > maxTimer) |
231 | if ((((uint16_t)rxMsg->Data[1])<8) + rxMsg->Data[2] > maxTimer) |
| 204 | { |
232 | { |
| 205 | rxMsg->Data[2] = maxTimer & 0x00ff; |
233 | rxMsg->Data[2] = maxTimer & 0x00ff; |
| 206 | rxMsg->Data[1] = (maxTimer>>8) & 0x00ff; |
234 | rxMsg->Data[1] = (maxTimer>>8) & 0x00ff; |
| 207 | } |
235 | } |
| 208 | switch (rxMsg->Data[0]) |
- | |
| 209 | { |
- | |
| 210 | #ifdef PIN_0 |
- | |
| 211 | case 0: |
- | |
| 212 | pwmValue[ |
236 | pwmValue[rxMsg->Data[0]] = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2]; |
| 213 | break; |
- | |
| 214 | #endif |
- | |
| 215 | #ifdef PIN_1 |
- | |
| 216 | case 1: |
- | |
| 217 |
|
237 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
| 218 | break; |
- | |
| 219 | #endif |
- | |
| 220 |
|
238 | rxMsg->Length = 3; |
| 221 | case 2: |
- | |
| 222 | pwmValue[PIN_2_ID] = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2]; |
- | |
| 223 | break; |
- | |
| 224 | #endif |
- | |
| 225 |
|
239 | StdCan_Put(rxMsg); |
| 226 | case 3: |
- | |
| 227 | pwmValue[PIN_3_ID] = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2]; |
- | |
| 228 | break; |
- | |
| 229 | #endif |
- | |
| 230 | |
240 | } else if (rxMsg->Length > 1) { |
| 231 | case 4: |
- | |
| 232 |
|
241 | rxMsg->Data[2] = pwmValue[rxMsg->Data[0]] & 0x00ff; |
| 233 | break; |
- | |
| 234 | #endif |
- | |
| 235 | #ifdef PIN_5 |
- | |
| 236 | case 5: |
- | |
| 237 |
|
242 | rxMsg->Data[1] = (pwmValue[rxMsg->Data[0]]>>8) & 0x00ff; |
| 238 | break; |
- | |
| 239 | #endif |
- | |
| 240 | #ifdef PIN_6 |
- | |
| 241 | case 6: |
- | |
| 242 |
|
243 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
| 243 |
|
244 | rxMsg->Length = 3; |
| 244 | #endif |
- | |
| 245 |
|
245 | StdCan_Put(rxMsg); |
| 246 | case 7: |
- | |
| 247 | pwmValue[PIN_7_ID] = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2]; |
- | |
| 248 | break; |
- | |
| 249 | #endif |
- | |
| 250 | } |
246 | } |
| 251 | break; |
247 | break; |
| 252 | case CAN_MODULE_CMD_SOFTPWM_CONFIG: |
248 | case CAN_MODULE_CMD_SOFTPWM_CONFIG: |
| 253 | maxTimer = (((uint16_t)rxMsg->Data[0])<<8) + rxMsg->Data[1]; |
249 | maxTimer = (((uint16_t)rxMsg->Data[0])<<8) + rxMsg->Data[1]; |
| 254 | resolution = rxMsg->Data[2]; |
250 | resolution = rxMsg->Data[2]; |