Rev 1388 | Rev 1395 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1156 | linlun | 1 | |
| 2 | #include "act_softPWM.h" |
||
| 1183 | linlun | 3 | |
| 1394 | linlun | 4 | #if (act_softPWM_PIN_0_INVERT == 0) |
| 5 | #define set_pin_0_below_trigger gpio_set_pin(act_softPWM_PIN_0) |
||
| 6 | #define set_pin_0_above_trigger gpio_clr_pin(act_softPWM_PIN_0) |
||
| 7 | #else |
||
| 8 | #define set_pin_0_below_trigger gpio_set_pin(act_softPWM_PIN_0) |
||
| 9 | #define set_pin_0_above_trigger gpio_clr_pin(act_softPWM_PIN_0) |
||
| 10 | #endif |
||
| 1183 | linlun | 11 | |
| 1394 | linlun | 12 | #if (act_softPWM_PIN_1_INVERT == 0) |
| 13 | #define set_pin_1_below_trigger gpio_set_pin(act_softPWM_PIN_1) |
||
| 14 | #define set_pin_1_above_trigger gpio_clr_pin(act_softPWM_PIN_1) |
||
| 15 | #else |
||
| 16 | #define set_pin_1_below_trigger gpio_set_pin(act_softPWM_PIN_1) |
||
| 17 | #define set_pin_1_above_trigger gpio_clr_pin(act_softPWM_PIN_1) |
||
| 18 | #endif |
||
| 1156 | linlun | 19 | |
| 1394 | linlun | 20 | #if (act_softPWM_PIN_2_INVERT == 0) |
| 21 | #define set_pin_2_below_trigger gpio_set_pin(act_softPWM_PIN_2) |
||
| 22 | #define set_pin_2_above_trigger gpio_clr_pin(act_softPWM_PIN_2) |
||
| 23 | #else |
||
| 24 | #define set_pin_2_below_trigger gpio_set_pin(act_softPWM_PIN_2) |
||
| 25 | #define set_pin_2_above_trigger gpio_clr_pin(act_softPWM_PIN_2) |
||
| 26 | #endif |
||
| 1183 | linlun | 27 | |
| 1394 | linlun | 28 | #if (act_softPWM_PIN_3_INVERT == 0) |
| 29 | #define set_pin_3_below_trigger gpio_set_pin(act_softPWM_PIN_3) |
||
| 30 | #define set_pin_3_above_trigger gpio_clr_pin(act_softPWM_PIN_3) |
||
| 31 | #else |
||
| 32 | #define set_pin_3_below_trigger gpio_set_pin(act_softPWM_PIN_3) |
||
| 33 | #define set_pin_3_above_trigger gpio_clr_pin(act_softPWM_PIN_3) |
||
| 34 | #endif |
||
| 35 | |||
| 36 | #if (act_softPWM_PIN_4_INVERT == 0) |
||
| 37 | #define set_pin_4_below_trigger gpio_set_pin(act_softPWM_PIN_4) |
||
| 38 | #define set_pin_4_above_trigger gpio_clr_pin(act_softPWM_PIN_4) |
||
| 39 | #else |
||
| 40 | #define set_pin_4_below_trigger gpio_set_pin(act_softPWM_PIN_4) |
||
| 41 | #define set_pin_4_above_trigger gpio_clr_pin(act_softPWM_PIN_4) |
||
| 42 | #endif |
||
| 43 | |||
| 44 | #if (act_softPWM_PIN_5_INVERT == 0) |
||
| 45 | #define set_pin_5_below_trigger gpio_set_pin(act_softPWM_PIN_5) |
||
| 46 | #define set_pin_5_above_trigger gpio_clr_pin(act_softPWM_PIN_5) |
||
| 47 | #else |
||
| 48 | #define set_pin_5_below_trigger gpio_set_pin(act_softPWM_PIN_5) |
||
| 49 | #define set_pin_5_above_trigger gpio_clr_pin(act_softPWM_PIN_5) |
||
| 50 | #endif |
||
| 51 | |||
| 52 | #if (act_softPWM_PIN_6_INVERT == 0) |
||
| 53 | #define set_pin_6_below_trigger gpio_set_pin(act_softPWM_PIN_6) |
||
| 54 | #define set_pin_6_above_trigger gpio_clr_pin(act_softPWM_PIN_6) |
||
| 55 | #else |
||
| 56 | #define set_pin_6_below_trigger gpio_set_pin(act_softPWM_PIN_6) |
||
| 57 | #define set_pin_6_above_trigger gpio_clr_pin(act_softPWM_PIN_6) |
||
| 58 | #endif |
||
| 59 | |||
| 60 | #if (act_softPWM_PIN_7_INVERT == 0) |
||
| 61 | #define set_pin_7_below_trigger gpio_set_pin(act_softPWM_PIN_7) |
||
| 62 | #define set_pin_7_above_trigger gpio_clr_pin(act_softPWM_PIN_7) |
||
| 63 | #else |
||
| 64 | #define set_pin_7_below_trigger gpio_set_pin(act_softPWM_PIN_7) |
||
| 65 | #define set_pin_7_above_trigger gpio_clr_pin(act_softPWM_PIN_7) |
||
| 66 | #endif |
||
| 67 | |||
| 68 | static uint16_t currentTimer = 0; |
||
| 69 | static uint16_t maxTimer = 10; |
||
| 70 | static uint8_t resolution = 1; |
||
| 71 | static uint8_t act_softPWM_ReportInterval =0; |
||
| 72 | static uint8_t currentSendChannelId = 0; |
||
| 73 | |||
| 74 | |||
| 1156 | linlun | 75 | #ifdef act_softPWM_USEEEPROM |
| 76 | #include "act_softPWM_eeprom.h" |
||
| 77 | struct eeprom_act_softPWM EEMEM eeprom_act_softPWM = |
||
| 78 | { |
||
| 79 | { |
||
| 80 | ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file. |
||
| 1369 | linlun | 81 | 10000, // x |
| 82 | 10, |
||
| 1180 | linlun | 83 | 0x14 //Reportinteval 20 sec. |
| 1156 | linlun | 84 | }, |
| 85 | |||
| 86 | }; |
||
| 87 | #endif |
||
| 1183 | linlun | 88 | |
| 1394 | linlun | 89 | static uint16_t pwmValue[NUMBEROFCHANNELS]; |
| 90 | static uint16_t pwmValueCAN[NUMBEROFCHANNELS]; |
||
| 91 | |||
| 1370 | linlun | 92 | #if act_softPWM_ACTIVATE_AUTOOFF != 0 |
| 1394 | linlun | 93 | static uint8_t offCounter[NUMBEROFCHANNELS]; |
| 1370 | linlun | 94 | #endif |
| 1394 | linlun | 95 | |
| 1156 | linlun | 96 | void act_softPWM_Init(void) |
| 97 | { |
||
| 98 | #ifdef act_softPWM_USEEEPROM |
||
| 1379 | linlun | 99 | //if (EEDATA_OK) |
| 100 | //{ |
||
| 101 | // ; |
||
| 102 | //} else |
||
| 103 | //{ //The CRC of the EEPROM is not correct, store default values and update CRC |
||
| 1369 | linlun | 104 | eeprom_write_word_crc(EEDATA16.maxTimer, 10000 , WITHOUT_CRC); |
| 1379 | linlun | 105 | eeprom_write_byte_crc(EEDATA.resolution, 1 , WITHOUT_CRC); |
| 106 | eeprom_write_byte_crc(EEDATA.ReportInterval, 0x05 , WITHOUT_CRC); |
||
| 1180 | linlun | 107 | EEDATA_UPDATE_CRC; |
| 1379 | linlun | 108 | //} |
| 109 | act_softPWM_ReportInterval = eeprom_read_byte(EEDATA.ReportInterval); |
||
| 1369 | linlun | 110 | maxTimer = eeprom_read_word(EEDATA16.maxTimer); |
| 111 | resolution = eeprom_read_byte(EEDATA.resolution); |
||
| 1180 | linlun | 112 | Timer_SetTimeout(act_softPWM_SEND_TIMER, act_softPWM_ReportInterval*1000 , TimerTypeFreeRunning, 0); |
| 1156 | linlun | 113 | #endif |
| 114 | ///TODO: Initialize hardware etc here |
||
| 1369 | linlun | 115 | uint8_t i; |
| 1373 | linlun | 116 | for (i=0; i < NUMBEROFCHANNELS; i++) { |
| 1369 | linlun | 117 | pwmValue[i] = 0; |
| 1379 | linlun | 118 | pwmValueCAN[i] = 0; |
| 1369 | linlun | 119 | } |
| 1394 | linlun | 120 | #ifdef act_softPWM_PIN_0 |
| 121 | gpio_set_out(act_softPWM_PIN_0); |
||
| 122 | set_pin_0_below_trigger; |
||
| 1177 | linlun | 123 | #endif |
| 1394 | linlun | 124 | #ifdef act_softPWM_PIN_1 |
| 125 | gpio_set_out(act_softPWM_PIN_1); |
||
| 126 | set_pin_1_below_trigger; |
||
| 1177 | linlun | 127 | #endif |
| 1394 | linlun | 128 | #ifdef act_softPWM_PIN_2 |
| 129 | gpio_set_out(act_softPWM_PIN_2); |
||
| 130 | set_pin_2_below_trigger; |
||
| 1177 | linlun | 131 | #endif |
| 1394 | linlun | 132 | #ifdef act_softPWM_PIN_3 |
| 133 | gpio_set_out(act_softPWM_PIN_3); |
||
| 134 | set_pin_3_below_trigger; |
||
| 1177 | linlun | 135 | #endif |
| 1394 | linlun | 136 | #ifdef act_softPWM_PIN_4 |
| 137 | gpio_set_out(act_softPWM_PIN_4); |
||
| 138 | set_pin_4_below_trigger; |
||
| 1177 | linlun | 139 | #endif |
| 1394 | linlun | 140 | #ifdef act_softPWM_PIN_5 |
| 141 | gpio_set_out(act_softPWM_PIN_5); |
||
| 142 | set_pin_5_below_trigger; |
||
| 1177 | linlun | 143 | #endif |
| 1394 | linlun | 144 | #ifdef act_softPWM_PIN_6 |
| 145 | gpio_set_out(act_softPWM_PIN_6); |
||
| 146 | set_pin_6_below_trigger; |
||
| 1177 | linlun | 147 | #endif |
| 1394 | linlun | 148 | #ifdef act_softPWM_PIN_7 |
| 149 | gpio_set_out(act_softPWM_PIN_7); |
||
| 150 | set_pin_7_below_trigger; |
||
| 1177 | linlun | 151 | #endif |
| 1156 | linlun | 152 | |
| 1177 | linlun | 153 | Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL); |
| 1156 | linlun | 154 | } |
| 155 | |||
| 156 | void act_softPWM_Process(void) |
||
| 157 | { |
||
| 158 | if (Timer_Expired(act_softPWM_TIMER)) { |
||
| 159 | currentTimer++; |
||
| 1379 | linlun | 160 | if (currentTimer >= maxTimer) { |
| 161 | //printf("cleard Timer %d\n",pwmValue[0]); |
||
| 1156 | linlun | 162 | currentTimer=0; |
| 1394 | linlun | 163 | #ifdef act_softPWM_PIN_0 |
| 1379 | linlun | 164 | if (pwmValue[0]!=0) { |
| 1394 | linlun | 165 | set_pin_0_below_trigger; |
| 166 | } |
||
| 1177 | linlun | 167 | #endif |
| 1394 | linlun | 168 | #ifdef act_softPWM_PIN_1 |
| 169 | if (pwmValue[1]!=0) { |
||
| 170 | set_pin_1_below_trigger; |
||
| 171 | } |
||
| 1177 | linlun | 172 | #endif |
| 1394 | linlun | 173 | #ifdef act_softPWM_PIN_2 |
| 174 | if (pwmValue[2]!=0) { |
||
| 175 | set_pin_2_below_trigger; |
||
| 176 | } |
||
| 1177 | linlun | 177 | #endif |
| 1394 | linlun | 178 | #ifdef act_softPWM_PIN_3 |
| 179 | if (pwmValue[3]!=0) { |
||
| 180 | set_pin_3_below_trigger; |
||
| 181 | } |
||
| 1177 | linlun | 182 | #endif |
| 1394 | linlun | 183 | #ifdef act_softPWM_PIN_4 |
| 184 | if (pwmValue[4]!=0) { |
||
| 185 | set_pin_4_below_trigger; |
||
| 186 | } |
||
| 1177 | linlun | 187 | #endif |
| 1394 | linlun | 188 | #ifdef act_softPWM_PIN_5 |
| 189 | if (pwmValue[5]!=0) { |
||
| 190 | set_pin_5_below_trigger; |
||
| 191 | } |
||
| 1177 | linlun | 192 | #endif |
| 1394 | linlun | 193 | #ifdef act_softPWM_PIN_6 |
| 194 | if (pwmValue[6]!=0) { |
||
| 195 | set_pin_6_below_trigger; |
||
| 196 | } |
||
| 1177 | linlun | 197 | #endif |
| 1394 | linlun | 198 | #ifdef act_softPWM_PIN_7 |
| 199 | if (pwmValue[7]!=0) { |
||
| 200 | set_pin_7_below_trigger; |
||
| 201 | } |
||
| 1177 | linlun | 202 | #endif |
| 1156 | linlun | 203 | } |
| 1394 | linlun | 204 | #ifdef act_softPWM_PIN_0 |
| 205 | if (currentTimer >= pwmValue[0] && gpio_get_state(act_softPWM_PIN_0) != 0) { |
||
| 206 | set_pin_0_above_trigger; |
||
| 1156 | linlun | 207 | } |
| 1177 | linlun | 208 | #endif |
| 1394 | linlun | 209 | #ifdef act_softPWM_PIN_1 |
| 210 | if (currentTimer >= pwmValue[1] && gpio_get_state(act_softPWM_PIN_1) != 0) { |
||
| 211 | set_pin_1_above_trigger; |
||
| 1156 | linlun | 212 | } |
| 1177 | linlun | 213 | #endif |
| 1394 | linlun | 214 | #ifdef act_softPWM_PIN_2 |
| 215 | if (currentTimer >= pwmValue[2] && gpio_get_state(act_softPWM_PIN_2) != 0) { |
||
| 216 | set_pin_2_above_trigger; |
||
| 1156 | linlun | 217 | } |
| 1177 | linlun | 218 | #endif |
| 1394 | linlun | 219 | #ifdef act_softPWM_PIN_3 |
| 220 | if (currentTimer >= pwmValue[3] && gpio_get_state(act_softPWM_PIN_3) != 0) { |
||
| 221 | set_pin_3_above_trigger; |
||
| 1177 | linlun | 222 | } |
| 223 | #endif |
||
| 1394 | linlun | 224 | #ifdef act_softPWM_PIN_4 |
| 225 | if (currentTimer >= pwmValue[4] && gpio_get_state(act_softPWM_PIN_4) != 0) { |
||
| 226 | set_pin_4_above_trigger; |
||
| 1177 | linlun | 227 | } |
| 228 | #endif |
||
| 1394 | linlun | 229 | #ifdef act_softPWM_PIN_5 |
| 230 | if (currentTimer >= pwmValue[5] && gpio_get_state(act_softPWM_PIN_5) != 0) { |
||
| 231 | set_pin_5_above_trigger; |
||
| 1177 | linlun | 232 | } |
| 233 | #endif |
||
| 1394 | linlun | 234 | #ifdef act_softPWM_PIN_6 |
| 235 | if (currentTimer >= pwmValue[6] && gpio_get_state(act_softPWM_PIN_6) != 0) { |
||
| 236 | set_pin_6_above_trigger; |
||
| 1177 | linlun | 237 | } |
| 238 | #endif |
||
| 1394 | linlun | 239 | #ifdef act_softPWM_PIN_7 |
| 240 | if (currentTimer >= pwmValue[7] && gpio_get_state(act_softPWM_PIN_7) != 0) { |
||
| 241 | set_pin_7_above_trigger; |
||
| 1177 | linlun | 242 | } |
| 243 | #endif |
||
| 1156 | linlun | 244 | } |
| 1180 | linlun | 245 | if (Timer_Expired(act_softPWM_SEND_TIMER)) { |
| 1379 | linlun | 246 | //printf("sending...\n"); |
| 1184 | linlun | 247 | while(1) |
| 248 | { |
||
| 249 | if (0 |
||
| 1394 | linlun | 250 | #ifdef act_softPWM_PIN_0 |
| 1184 | linlun | 251 | || currentSendChannelId == 0 |
| 252 | #endif |
||
| 1394 | linlun | 253 | #ifdef act_softPWM_PIN_1 |
| 1184 | linlun | 254 | || currentSendChannelId == 1 |
| 255 | #endif |
||
| 1394 | linlun | 256 | #ifdef act_softPWM_PIN_2 |
| 1184 | linlun | 257 | || currentSendChannelId == 2 |
| 258 | #endif |
||
| 1394 | linlun | 259 | #ifdef act_softPWM_PIN_3 |
| 1184 | linlun | 260 | || currentSendChannelId == 3 |
| 261 | #endif |
||
| 1394 | linlun | 262 | #ifdef act_softPWM_PIN_4 |
| 1184 | linlun | 263 | || currentSendChannelId == 4 |
| 264 | #endif |
||
| 1394 | linlun | 265 | #ifdef act_softPWM_PIN_5 |
| 1184 | linlun | 266 | || currentSendChannelId == 5 |
| 267 | #endif |
||
| 1394 | linlun | 268 | #ifdef act_softPWM_PIN_6 |
| 1184 | linlun | 269 | || currentSendChannelId == 6 |
| 270 | #endif |
||
| 1394 | linlun | 271 | #ifdef act_softPWM_PIN_7 |
| 1184 | linlun | 272 | || currentSendChannelId == 7 |
| 273 | #endif |
||
| 274 | ) { |
||
| 275 | break; |
||
| 276 | } |
||
| 277 | currentSendChannelId++; |
||
| 278 | if (currentSendChannelId >= NUMBEROFCHANNELS) |
||
| 279 | currentSendChannelId=0; |
||
| 280 | } |
||
| 1379 | linlun | 281 | //printf(" %d\n",currentSendChannelId); |
| 1180 | linlun | 282 | StdCan_Msg_t txMsg; |
| 283 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); |
||
| 284 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 285 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM; |
||
| 286 | txMsg.Header.ModuleId = act_softPWM_ID; |
||
| 287 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PWM; |
||
| 288 | txMsg.Length = 3; |
||
| 289 | txMsg.Data[0] = currentSendChannelId; |
||
| 1394 | linlun | 290 | txMsg.Data[1] = (pwmValue[currentSendChannelId]>>8)&0xff; |
| 291 | txMsg.Data[2] = (pwmValue[currentSendChannelId])&0xff; |
||
| 1369 | linlun | 292 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |
| 1379 | linlun | 293 | //printf("sent pwm2: %d %d\n",pwmValueCAN[currentSendChannelId],currentSendChannelId); |
| 1370 | linlun | 294 | #if act_softPWM_ACTIVATE_AUTOOFF != 0 |
| 295 | offCounter[currentSendChannelId]--; |
||
| 296 | if (offCounter[currentSendChannelId] == 0) { |
||
| 297 | pwmValue[currentSendChannelId] = 0; |
||
| 1379 | linlun | 298 | pwmValueCAN[currentSendChannelId] = 0; |
| 1370 | linlun | 299 | offCounter[currentSendChannelId] = 1; |
| 300 | } |
||
| 301 | #endif |
||
| 1180 | linlun | 302 | currentSendChannelId++; |
| 303 | if (currentSendChannelId >= NUMBEROFCHANNELS) |
||
| 304 | currentSendChannelId=0; |
||
| 305 | } |
||
| 1156 | linlun | 306 | } |
| 307 | |||
| 1180 | linlun | 308 | |
| 309 | |||
| 1156 | linlun | 310 | void act_softPWM_HandleMessage(StdCan_Msg_t *rxMsg) |
| 311 | { |
||
| 312 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT && |
||
| 313 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
||
| 314 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_SOFTPWM && |
||
| 315 | rxMsg->Header.ModuleId == act_softPWM_ID) |
||
| 316 | { |
||
| 317 | switch (rxMsg->Header.Command) |
||
| 318 | { |
||
| 1379 | linlun | 319 | //printf("Got can\n"); |
| 1177 | linlun | 320 | case CAN_MODULE_CMD_PHYSICAL_PWM: |
| 1379 | linlun | 321 | //printf("Got pwm value\n"); |
| 1369 | linlun | 322 | if (rxMsg->Length == 3) |
| 1184 | linlun | 323 | { |
| 1379 | linlun | 324 | //printf("3\n"); |
| 1369 | linlun | 325 | if (rxMsg->Data[0] < NUMBEROFCHANNELS) { |
| 1379 | linlun | 326 | pwmValueCAN[rxMsg->Data[0]] = ((uint16_t)((rxMsg->Data[1]<<8) + rxMsg->Data[2])); |
| 1394 | linlun | 327 | if (pwmValueCAN[rxMsg->Data[0]] >= 10000) { |
| 328 | pwmValue[rxMsg->Data[0]] = maxTimer+1; |
||
| 329 | } else { |
||
| 330 | pwmValue[rxMsg->Data[0]] = ((uint16_t)((((uint32_t)pwmValueCAN[rxMsg->Data[0]])*(maxTimer))/10000)); |
||
| 331 | } |
||
| 1379 | linlun | 332 | rxMsg->Data[1] = (uint8_t)(0x00ff & (pwmValueCAN[rxMsg->Data[0]]>>8)); |
| 333 | rxMsg->Data[2] = (uint8_t)(0x00ff & pwmValueCAN[rxMsg->Data[0]]); |
||
| 1369 | linlun | 334 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
| 335 | rxMsg->Length = 3; |
||
| 336 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
||
| 1379 | linlun | 337 | //printf("sent pwm3: %d %d %d\n",pwmValue[rxMsg->Data[0]],maxTimer,resolution); |
| 1370 | linlun | 338 | #if act_softPWM_ACTIVATE_AUTOOFF != 0 |
| 339 | offCounter[rxMsg->Data[0]] = act_softPWM_ACTIVATE_AUTOOFF; |
||
| 340 | #endif |
||
| 1369 | linlun | 341 | } |
| 1243 | arune | 342 | } else if (rxMsg->Length == 1) { |
| 1379 | linlun | 343 | rxMsg->Data[1] = (uint8_t)(0x00ff & (pwmValueCAN[rxMsg->Data[0]]>>8)); |
| 344 | rxMsg->Data[2] = (uint8_t)(0x00ff & pwmValueCAN[rxMsg->Data[0]]); |
||
| 1184 | linlun | 345 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
| 1369 | linlun | 346 | rxMsg->Length = 3; |
| 347 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
||
| 1379 | linlun | 348 | } else { |
| 349 | rxMsg->Data[0] = (8); |
||
| 350 | rxMsg->Data[1] = (uint8_t)(0x00ff & (pwmValueCAN[0]>>8)); |
||
| 351 | rxMsg->Data[2] = (uint8_t)(0x00ff & pwmValueCAN[0]); |
||
| 352 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 353 | rxMsg->Length = 3; |
||
| 354 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
||
| 1177 | linlun | 355 | } |
| 356 | break; |
||
| 357 | case CAN_MODULE_CMD_SOFTPWM_CONFIG: |
||
| 358 | maxTimer = (((uint16_t)rxMsg->Data[0])<<8) + rxMsg->Data[1]; |
||
| 359 | resolution = rxMsg->Data[2]; |
||
| 360 | Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL); |
||
| 1369 | linlun | 361 | eeprom_write_word_crc(EEDATA16.maxTimer, maxTimer , WITHOUT_CRC); |
| 362 | eeprom_write_byte_crc(EEDATA.resolution, resolution , WITHOUT_CRC); |
||
| 363 | EEDATA_UPDATE_CRC; |
||
| 364 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 365 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
||
| 1177 | linlun | 366 | break; |
| 1180 | linlun | 367 | case CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL: |
| 368 | if (rxMsg->Length > 0) |
||
| 369 | { |
||
| 370 | act_softPWM_ReportInterval = rxMsg->Data[0]; |
||
| 1242 | arune | 371 | eeprom_write_byte_crc(EEDATA.ReportInterval, act_softPWM_ReportInterval , WITH_CRC); |
| 1180 | linlun | 372 | Timer_SetTimeout(act_softPWM_SEND_TIMER, act_softPWM_ReportInterval*1000 , TimerTypeFreeRunning, 0); |
| 373 | } |
||
| 1177 | linlun | 374 | |
| 1180 | linlun | 375 | StdCan_Msg_t txMsg; |
| 376 | |||
| 377 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); |
||
| 378 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 379 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM; |
||
| 380 | txMsg.Header.ModuleId = act_softPWM_ID; |
||
| 381 | txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL; |
||
| 382 | txMsg.Length = 1; |
||
| 383 | txMsg.Data[0] = act_softPWM_ReportInterval; |
||
| 1369 | linlun | 384 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |
| 1180 | linlun | 385 | break; |
| 1156 | linlun | 386 | } |
| 387 | } |
||
| 388 | } |
||
| 389 | |||
| 390 | void act_softPWM_List(uint8_t ModuleSequenceNumber) |
||
| 391 | { |
||
| 392 | StdCan_Msg_t txMsg; |
||
| 393 | |||
| 394 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); ///TODO: Change this to the actual class type |
||
| 395 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 396 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM; ///TODO: Change this to the actual module type |
||
| 397 | txMsg.Header.ModuleId = act_softPWM_ID; |
||
| 398 | txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST; |
||
| 399 | txMsg.Length = 6; |
||
| 400 | |||
| 401 | txMsg.Data[0] = NODE_HW_ID_BYTE0; |
||
| 402 | txMsg.Data[1] = NODE_HW_ID_BYTE1; |
||
| 403 | txMsg.Data[2] = NODE_HW_ID_BYTE2; |
||
| 404 | txMsg.Data[3] = NODE_HW_ID_BYTE3; |
||
| 405 | |||
| 406 | txMsg.Data[4] = NUMBER_OF_MODULES; |
||
| 407 | txMsg.Data[5] = ModuleSequenceNumber; |
||
| 408 | |||
| 409 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |
||
| 410 | } |