void act_output_Process(void) { #if act_output_USEEEPROM==1 if (Timer_Expired(act_output_STORE_VALUE_TIMEOUT)) { uint8_t index = 0; #ifdef act_output_CH0 eeprom_write_byte_crc(EEDATA.ch0, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH1 eeprom_write_byte_crc(EEDATA.ch1, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH2 eeprom_write_byte_crc(EEDATA.ch2, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH3 eeprom_write_byte_crc(EEDATA.ch3, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH4 eeprom_write_byte_crc(EEDATA.ch4, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH5 eeprom_write_byte_crc(EEDATA.ch5, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH6 eeprom_write_byte_crc(EEDATA.ch6, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH7 eeprom_write_byte_crc(EEDATA.ch7, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH8 eeprom_write_byte_crc(EEDATA.ch8, chnValue[index], WITHOUT_CRC); index++; #endif #ifdef act_output_CH9 eeprom_write_byte_crc(EEDATA.ch9, chnValue[index], WITHOUT_CRC); index++; #endif EEDATA_UPDATE_CRC; } #endif }
void sns_VoltageCurrent_Init(void) { #ifdef sns_VoltageCurrent_USEEEPROM if (EEDATA_OK) { ///TODO: Use stored data to set initial values for the module blablaX = eeprom_read_byte(EEDATA.x); blablaY = eeprom_read_word(EEDATA.y); } else { //The CRC of the EEPROM is not correct, store default values and update CRC eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC); eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC); EEDATA_UPDATE_CRC; } #endif // to use PCINt lib, call this function: (the callback function look as a timer callback function) // Pcint_SetCallbackPin(sns_VoltageCurrent_PCINT, EXP_C , &sns_VoltageCurrent_pcint_callback); ADC_Init(); #ifdef sns_VoltageCurrent_SEND_PERIOD Timer_SetTimeout(sns_VoltageCurrent_TIMER, sns_VoltageCurrent_SEND_PERIOD*1000 , TimerTypeFreeRunning, 0); #else #ifdef sns_VoltageCurrent_SEND_PERIOD_MS Timer_SetTimeout(sns_VoltageCurrent_TIMER, sns_VoltageCurrent_SEND_PERIOD_MS , TimerTypeFreeRunning, 0); #endif #endif }
uint8_t sns_counter_save_data(void) { #if sns_counter_USEEEPROM==1 eeprom_write_byte_crc(EEDATA.reportInterval, sns_counter_SEND_PERIOD, WITHOUT_CRC); #ifdef sns_counter_CH0 eeprom_write_dword_crc(EEDATA32.Count[0], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH1 eeprom_write_dword_crc(EEDATA32.Count[1], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH2 eeprom_write_dword_crc(EEDATA32.Count[2], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH3 eeprom_write_dword_crc(EEDATA32.Count[3], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH4 eeprom_write_dword_crc(EEDATA32.Count[4], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH5 eeprom_write_dword_crc(EEDATA32.Count[5], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH6 eeprom_write_dword_crc(EEDATA32.Count[6], 0, WITHOUT_CRC); #endif #ifdef sns_counter_CH7 eeprom_write_dword_crc(EEDATA32.Count[7], 0, WITHOUT_CRC); #endif EEDATA_UPDATE_CRC; return 0; #else return 2; #endif }
void sns_power_Init(void) { #ifdef sns_power_USEEEPROM if (EEDATA_OK) { ///TODO: Use stored data to set initial values for the module sns_power_ReportInterval = eeprom_read_byte(EEDATA.reportInterval); EnergyCounter = eeprom_read_word(EEDATA16.EnergyCounterLower); EnergyCounter += (((uint32_t)(eeprom_read_word(EEDATA16.EnergyCounterUpper)))<<16); #ifdef POWER_SNS_PIN_ch2 EnergyCounter_ch2 = eeprom_read_word(EEDATA16.EnergyCounterLower_ch2); EnergyCounter_ch2 += (((uint32_t)(eeprom_read_word(EEDATA16.EnergyCounterUpper_ch2)))<<16); #endif } else { //The CRC of the EEPROM is not correct, store default values and update CRC eeprom_write_byte_crc(EEDATA.reportInterval, sns_power_SEND_PERIOD, WITHOUT_CRC); eeprom_write_word_crc(EEDATA16.EnergyCounterUpper, 0, WITHOUT_CRC); eeprom_write_word_crc(EEDATA16.EnergyCounterLower, 0, WITHOUT_CRC); #ifdef POWER_SNS_PIN_ch2 eeprom_write_word_crc(EEDATA16.EnergyCounterUpper_ch2, 0, WITHOUT_CRC); eeprom_write_word_crc(EEDATA16.EnergyCounterLower_ch2, 0, WITHOUT_CRC); #endif EEDATA_UPDATE_CRC; sns_power_ReportInterval = eeprom_read_byte(EEDATA.reportInterval); } #endif ///Initialize hardware etc gpio_set_in(POWER_SNS_PIN); // Set to input gpio_set_pin(POWER_SNS_PIN); // Enable pull-up Pcint_SetCallbackPin(sns_power_PCINT, POWER_SNS_PIN, &sns_power_pcint_callback); MeasurmentBufferPointer = 0; #ifdef POWER_SNS_PIN_ch2 gpio_set_in(POWER_SNS_PIN_ch2); // Set to input gpio_set_pin(POWER_SNS_PIN_ch2); // Enable pull-up Pcint_SetCallbackPin(sns_power_PCINT_ch2, POWER_SNS_PIN_ch2, &sns_power_pcint_callback_ch2); MeasurmentBufferPointer_ch2 = 0; #endif Timer_SetTimeout(sns_power_SEND_TIMER, sns_power_ReportInterval*1000 , TimerTypeFreeRunning, 0); #if sns_power_SEND_1_MIN_AVG == 1 Timer_SetTimeout(sns_power_SEND_TIMER_1_MIN_AVG, 60000-10 , TimerTypeFreeRunning, &sns_power_timer_callback); #endif }
void chn_ChnMaster_Init(void) { #ifdef chn_ChnMaster_USEEEPROM if (EEDATA_OK) { ///TODO: Use stored data to set initial values for the module blablaX = eeprom_read_byte(EEDATA.x); blablaY = eeprom_read_word(EEDATA.y); } else { //The CRC of the EEPROM is not correct, store default values and update CRC eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC); eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC); EEDATA_UPDATE_CRC; } #endif ///TODO: Initialize hardware etc here // to use PCINt lib, call this function: (the callback function look as a timer callback function) // Pcint_SetCallbackPin(chn_ChnMaster_PCINT, EXP_C , &chn_ChnMaster_pcint_callback); }
void act_output_Init(void) { #if act_output_USEEEPROM==1 if (EEDATA_OK) { ///TODO: Use stored data to set initial values for the module uint8_t index = 0; #ifdef act_output_CH0 chnValue[index] = eeprom_read_byte(EEDATA.ch0); index++; #endif #ifdef act_output_CH1 chnValue[index] = eeprom_read_byte(EEDATA.ch1); index++; #endif #ifdef act_output_CH2 chnValue[index] = eeprom_read_byte(EEDATA.ch2); index++; #endif #ifdef act_output_CH3 chnValue[index] = eeprom_read_byte(EEDATA.ch3); index++; #endif #ifdef act_output_CH4 chnValue[index] = eeprom_read_byte(EEDATA.ch4); index++; #endif #ifdef act_output_CH5 chnValue[index] = eeprom_read_byte(EEDATA.ch5); index++; #endif #ifdef act_output_CH6 chnValue[index] = eeprom_read_byte(EEDATA.ch6); index++; #endif #ifdef act_output_CH7 chnValue[index] = eeprom_read_byte(EEDATA.ch7); index++; #endif #ifdef act_output_CH8 chnValue[index] = eeprom_read_byte(EEDATA.ch8); index++; #endif #ifdef act_output_CH9 chnValue[index] = eeprom_read_byte(EEDATA.ch9); index++; #endif } else { //The CRC of the EEPROM is not correct, store default values and update CRC #ifdef act_output_CH0 eeprom_write_byte_crc(EEDATA.ch0, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH1 eeprom_write_byte_crc(EEDATA.ch1, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH2 eeprom_write_byte_crc(EEDATA.ch2, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH3 eeprom_write_byte_crc(EEDATA.ch3, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH4 eeprom_write_byte_crc(EEDATA.ch4, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH5 eeprom_write_byte_crc(EEDATA.ch5, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH6 eeprom_write_byte_crc(EEDATA.ch6, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH7 eeprom_write_byte_crc(EEDATA.ch7, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH8 eeprom_write_byte_crc(EEDATA.ch8, 0x00, WITHOUT_CRC); #endif #ifdef act_output_CH9 eeprom_write_byte_crc(EEDATA.ch9, 0x00, WITHOUT_CRC); #endif EEDATA_UPDATE_CRC; } #endif ///Initialize hardware uint8_t index = 0; #if act_output_CH0PCA95xxIO==1 |act_output_CH1PCA95xxIO==1 | act_output_CH2PCA95xxIO==1 | act_output_CH3PCA95xxIO==1 | act_output_CH4PCA95xxIO==1 | act_output_CH5PCA95xxIO==1 | act_output_CH6PCA95xxIO==1 | act_output_CH7PCA95xxIO==1 Pca95xx_Init(0); #endif #ifdef act_output_CH0 #if act_output_CH0PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH0); gpio_set_out(act_output_CH0); #else Pca95xx_set_statement(chnValue[index],act_output_CH0); Pca95xx_set_out(act_output_CH0); #endif index++; #endif #ifdef act_output_CH1 #if act_output_CH1PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH1); gpio_set_out(act_output_CH1); #else Pca95xx_set_statement(chnValue[index],act_output_CH1); Pca95xx_set_out(act_output_CH1); #endif index++; #endif #ifdef act_output_CH2 #if act_output_CH2PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH2); gpio_set_out(act_output_CH2); #else Pca95xx_set_statement(chnValue[index],act_output_CH2); Pca95xx_set_out(act_output_CH2); #endif index++; #endif #ifdef act_output_CH3 #if act_output_CH3PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH3); gpio_set_out(act_output_CH3); #else Pca95xx_set_statement(chnValue[index],act_output_CH3); Pca95xx_set_out(act_output_CH3); #endif index++; #endif #ifdef act_output_CH4 #if act_output_CH4PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH4); gpio_set_out(act_output_CH4); #else Pca95xx_set_statement(chnValue[index],act_output_CH4); Pca95xx_set_out(act_output_CH4); #endif index++; #endif #ifdef act_output_CH5 #if act_output_CH5PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH5); gpio_set_out(act_output_CH5); #else Pca95xx_set_statement(chnValue[index],act_output_CH5); Pca95xx_set_out(act_output_CH5); #endif index++; #endif #ifdef act_output_CH6 #if act_output_CH6PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH6); gpio_set_out(act_output_CH6); #else Pca95xx_set_statement(chnValue[index],act_output_CH6); Pca95xx_set_out(act_output_CH6); #endif index++; #endif #ifdef act_output_CH7 #if act_output_CH7PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH7); gpio_set_out(act_output_CH7); #else Pca95xx_set_statement(chnValue[index],act_output_CH7); Pca95xx_set_out(act_output_CH7); #endif index++; #endif #ifdef act_output_CH8 #if act_output_CH8PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH8); gpio_set_out(act_output_CH8); #else Pca95xx_set_statement(chnValue[index],act_output_CH8); Pca95xx_set_out(act_output_CH8); #endif index++; #endif #ifdef act_output_CH9 #if act_output_CH9PCA95xxIO==0 gpio_set_statement(chnValue[index],act_output_CH9); gpio_set_out(act_output_CH9); #else Pca95xx_set_statement(chnValue[index],act_output_CH9); Pca95xx_set_out(act_output_CH9); #endif index++; #endif }
void act_protectedOutput_Process() { #if act_protectedOutput_EEPROM_ENABLED == 1 if (Timer_Expired(act_protectedOutput_STORE_VALUE_TIMEOUT)) { #if act_protectedOutput_CH_COUNT >= 1 eeprom_write_byte_crc(EEDATA.ch0, chTargetState[0], WITHOUT_CRC); #endif #if act_protectedOutput_CH_COUNT >= 2 eeprom_write_byte_crc(EEDATA.ch1, chTargetState[1], WITHOUT_CRC); #endif #if act_protectedOutput_CH_COUNT >= 3 eeprom_write_byte_crc(EEDATA.ch2, chTargetState[2], WITHOUT_CRC); #endif #if act_protectedOutput_CH_COUNT >= 4 eeprom_write_byte_crc(EEDATA.ch3, chTargetState[3], WITHOUT_CRC); #endif EEDATA_UPDATE_CRC; } #endif // shall we retry to set target output state? if (Timer_Expired(act_protectedOutput_RETRY_TIMER)) { // read DIAG pin again and update outputs accordingly readDiagPin(); #if act_protectedOutput_FORCED_RETRIES == 1 // forced retry to set output states, regardless of DIAG updateOutput(1); // read DIAG pin again and hope we have a better flag readDiagPin(); #else // if DIAG allows it, retry to set the output states updateOutput(0); #endif if (diagState == DIAG_ASSERTED) { // if DIAG was still asserted, initiate another timer run Timer_SetTimeout(act_protectedOutput_RETRY_TIMER, act_protectedOutput_RETRY_TIMER_TIME_S*1000, TimerTypeOneShot, 0); } else { // things went back to normal. report this diagReportPending = 1; } } // shall we report diag status to CAN? if (diagReportPending) { StdCan_Msg_t txMsg; StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_PROTECTEDOUTPUT; txMsg.Header.ModuleId = act_protectedOutput_ID; txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PINSTATUS; txMsg.Length = 2; txMsg.Data[0] = 0; //TODO: add support for more channels // we follow the standard SNS_INPUT format, but the data corresponds to the "health" rather than physical level if (diagState == DIAG_NORMAL) { txMsg.Data[1] = 1; //healthy, target output state stable } else { txMsg.Data[1] = 0; //not healthy, DIAG pin ASSERTED, not in target output state } while (StdCan_Put(&txMsg) != StdCan_Ret_OK); diagReportPending = 0; } }
void act_protectedOutput_Init() { /* * Init target state vector, in case EEPROM is disabled */ for (uint8_t i=0; i<act_protectedOutput_CH_COUNT; i++) { chTargetState[i] = 0; } /* * Configure DIAG input pin */ if (act_protectedOutput_DIAG_PIN_PULL_ENABLED) { // if DIAG is asserted low, we need pull-up gpio_set_statement(act_protectedOutput_DIAG_PIN_POLARITY == 0 ? 1 : 0, DIAG_PIN); } gpio_set_in(DIAG_PIN); Pcint_SetCallbackPin(act_protectedOutput_DIAG_PIN_PCINT, DIAG_PIN, &pcIntCallback); /* * Read EEPROM data */ #if act_protectedOutput_EEPROM_ENABLED == 1 if (EEDATA_OK) { #if act_protectedOutput_CH_COUNT >= 1 chTargetState[0] = eeprom_read_byte(EEDATA.ch0); #endif #if act_protectedOutput_CH_COUNT >= 2 chTargetState[1] = eeprom_read_byte(EEDATA.ch1); #endif #if act_protectedOutput_CH_COUNT >= 3 chTargetState[2] = eeprom_read_byte(EEDATA.ch2); #endif #if act_protectedOutput_CH_COUNT >= 4 chTargetState[3] = eeprom_read_byte(EEDATA.ch3); #endif } else { //The CRC of the EEPROM is not correct, store default values and update CRC #if act_protectedOutput_CH_COUNT >= 1 eeprom_write_byte_crc(EEDATA.ch0, 0x00, WITHOUT_CRC); #endif #if act_protectedOutput_CH_COUNT >= 2 eeprom_write_byte_crc(EEDATA.ch1, 0x00, WITHOUT_CRC); #endif #if act_protectedOutput_CH_COUNT >= 3 eeprom_write_byte_crc(EEDATA.ch2, 0x00, WITHOUT_CRC); #endif #if act_protectedOutput_CH_COUNT >= 4 eeprom_write_byte_crc(EEDATA.ch3, 0x00, WITHOUT_CRC); #endif EEDATA_UPDATE_CRC; } #endif /* * Configure OUTPUT pins */ #if act_protectedOutput_CH_COUNT >= 1 gpio_set_statement(CH0_OFF, CH0_PIN); gpio_set_out(act_protectedOutput_CH0); #endif #if act_protectedOutput_CH_COUNT >= 2 gpio_set_statement(CH1_OFF, CH1_PIN); gpio_set_out(act_protectedOutput_CH1); #endif #if act_protectedOutput_CH_COUNT >= 3 gpio_set_statement(CH2_OFF, CH2_PIN); gpio_set_out(act_protectedOutput_CH2); #endif #if act_protectedOutput_CH_COUNT >= 4 gpio_set_statement(CH3_OFF, CH3_PIN); gpio_set_out(act_protectedOutput_CH3); #endif diagState = DIAG_NORMAL; }