예제 #1
0
void tst_Benchmark_Init(void)
{
	/* Set up benchmark timer (timer1, 16bit) */
	//Normal port operation, Normal mode
	TCCR1A = ((0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<WGM11)|(0<<WGM10));
	TCCR1B = ((0<<ICNC1)|(0<<ICES1)|(0<<WGM12)|(0<<WGM13));
	
	/* Start timer */
	//prescaler /8
	TCCR1B |= ((0<<CS12)|(1<<CS11)|(0<<CS10));

#if tst_Benchmark_CanSend_TestActive == 1
	StdCan_Set_class(tst_Benchmark_CanSend_txMsg.Header, CAN_MODULE_CLASS_SNS);
	StdCan_Set_direction(tst_Benchmark_CanSend_txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	tst_Benchmark_CanSend_txMsg.Header.ModuleType = CAN_MODULE_TYPE_TST_DEBUG;
	tst_Benchmark_CanSend_txMsg.Header.ModuleId = tst_Benchmark_ID;
	tst_Benchmark_CanSend_txMsg.Header.Command = CAN_MODULE_CMD_DEBUG_BENCHMARK;
	tst_Benchmark_CanSend_txMsg.Length = 8;

	Timer_SetTimeout(tst_Benchmark_CanSend_TIMER, tst_Benchmark_CanSend_PERIOD_MS , TimerTypeFreeRunning, 0);
#endif

#if tst_Benchmark_CpuTime_TestActive == 1
	StdCan_Set_class(tst_Benchmark_CpuTime_txMsg.Header, CAN_MODULE_CLASS_SNS);
	StdCan_Set_direction(tst_Benchmark_CpuTime_txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	tst_Benchmark_CpuTime_txMsg.Header.ModuleType = CAN_MODULE_TYPE_TST_DEBUG;
	tst_Benchmark_CpuTime_txMsg.Header.ModuleId = tst_Benchmark_ID;
	tst_Benchmark_CpuTime_txMsg.Header.Command = CAN_MODULE_CMD_DEBUG_BENCHMARK;
	tst_Benchmark_CpuTime_txMsg.Length = 8;

	Timer_SetTimeout(tst_Benchmark_CpuTime_SEND_TIMER, tst_Benchmark_CpuTime_SEND_PERIOD_MS , TimerTypeFreeRunning, 0);
#endif
}
예제 #2
0
  void sns_power_timer_callback(uint8_t timer) 
  {
	  StdCan_Msg_t txMsg;
	  StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
	  StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	  txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_POWER; ///TODO: Change this to the actual module type
	  txMsg.Header.ModuleId = sns_power_ID;
	  txMsg.Header.Command = CAN_MODULE_CMD_POWER_AVGPOWER;
	  txMsg.Length = 2;
	  cli();
	  txMsg.Data[0] = (uint8_t)((avgCounter>>8) & 0xff);
	  txMsg.Data[1] = (uint8_t)(avgCounter & 0xff);
	  avgCounter = 0;
	  sei();
	  while (StdCan_Put(&txMsg) != StdCan_Ret_OK);

	  #ifdef POWER_SNS_PIN_ch2
	    txMsg.Length = 2;
	    txMsg.Header.ModuleId = sns_power_ID_ch2;
	    cli();
	    txMsg.Data[0] = (uint8_t)((avgCounter_ch2>>8) & 0xff);
	    txMsg.Data[1] = (uint8_t)(avgCounter_ch2 & 0xff);
	    avgCounter = 0;
	    sei();
	    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);

	  #endif
  }
예제 #3
0
void sns_BusVoltage_HandleMessage(StdCan_Msg_t *rxMsg)
{
	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_BUSVOLTAGE &&
		rxMsg->Header.ModuleId == sns_BusVoltage_ID)
	{
		switch (rxMsg->Header.Command)
		{
		case CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL:
		if (rxMsg->Length > 0)
		{
			sns_BusVoltage_ReportInterval = rxMsg->Data[0];
			Timer_SetTimeout(sns_BusVoltage_TIMER, sns_BusVoltage_ReportInterval*1000 , TimerTypeFreeRunning, 0);
		}

		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_BUSVOLTAGE;
		txMsg.Header.ModuleId = sns_BusVoltage_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL;
		txMsg.Length = 1;

		txMsg.Data[0] = sns_BusVoltage_ReportInterval;

		StdCan_Put(&txMsg);
		break;
		}
	}
}
예제 #4
0
void ReadTemperature(void)
{
	static uint8_t SearchSensorsTimeout = sns_ds18x20_SEARCH_TIMEOUT;
	static uint8_t CurrentSensor = 0;
	uint8_t subzero, cel, cel_frac_bits = 0;
	StdCan_Msg_t txMsg;

	StdCan_Set_class(txMsg.Header, CAN_CLASS_MODULE_SNS);
	StdCan_Set_direction(txMsg.Header, DIR_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_TYPE_MODULE_sns_ds18x20;
	txMsg.Header.ModuleId = sns_ds18x20_ID;
	txMsg.Header.Command = CAN_CMD_MODULE_PHYS_TEMPERATURE_CELSIUS;
	txMsg.Length = 3;

	txMsg.Data[0] = SensorIds[CurrentSensor];

	if (DS18X20_read_meas(&gSensorIDs[CurrentSensor][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK)
	{
		int16_t temp = cel;

		temp = temp << 6;

		temp += (cel_frac_bits << 2);

		if (subzero)
		{
			temp = -temp;
		}

		txMsg.Data[1] = (uint8_t)(temp >> 8);
		txMsg.Data[2] = (uint8_t)(temp & 0xff);
	}
예제 #5
0
void chn_ChnMaster_UpdateChannel( uint16_t channel_id, uint16_t value ) {
    StdCan_Msg_t txMsg;
    txMsg.Id = 0;
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_CHN);

    txMsg.Id |= channel_id << 8;
    txMsg.Id |= chn_ChnMaster_ID;

    txMsg.Length = 2;
    txMsg.Data[0] = (value     >>8)&0xFF;
    txMsg.Data[1] = (value        )&0xFF;

    while( StdCan_Put(&txMsg) != StdCan_Ret_OK );
}
예제 #6
0
void sns_counter_send_counter(uint8_t index)
{
	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_COUNTER;
	txMsg.Header.ModuleId = sns_counter_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_COUNTER;
	txMsg.Length = 5;
	txMsg.Data[0] = index;
	txMsg.Data[4] = (uint8_t)Count[index] & 0xff;
	txMsg.Data[3] = (uint8_t)(Count[index] >> 8) & 0xff;
	txMsg.Data[2] = (uint8_t)(Count[index] >> 16) & 0xff;
	txMsg.Data[1] = (uint8_t)(Count[index] >> 24) & 0xff;
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
예제 #7
0
void sendPID(void)
{
	if (eeprom_read_byte(EEDATA.actuatorModuleType) != 0) {	
		StdCan_Msg_t txMsg;
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); ///TODO: Change this to the actual class type
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_TO_OWNER);
		txMsg.Header.ModuleType = eeprom_read_byte(EEDATA.actuatorModuleType); ///TODO: Change this to the actual module type
		txMsg.Header.ModuleId = eeprom_read_byte(EEDATA.actuatorModuleId);
		txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PWM;
		txMsg.Length = 3;
		txMsg.Data[0] = eeprom_read_byte(EEDATA.actuatorId);
		//uint16_t tempPWM =(uint16_t) (pwmValue*10000);
		txMsg.Data[1] = ( ((uint16_t)outputValue)>>8)&0xff;
		txMsg.Data[2] = ( ((uint16_t)outputValue))&0xff;
		while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
	}
void sns_VoltageCurrent_Process(void)
{
	if (Timer_Expired(sns_VoltageCurrent_TIMER)) {
		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_VOLTAGECURRENT;
		txMsg.Header.ModuleId = sns_VoltageCurrent_ID;
		txMsg.Length = 3;
		uint16_t ADvalue;
		
#ifdef sns_VoltageCurrent0AD
		if (VoltageCurrentChannelToSend==0)
		{
			ADvalue = ADC_Get(sns_VoltageCurrent0AD);
			ADvalue = ADvalue * sns_VoltageCurrent0Factor;
#if sns_VoltageCurrent0VorA==0
			txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_VOLTAGE;
#else
			txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_CURRENT;
#endif
			txMsg.Data[0] = 0;
			txMsg.Data[1] = (ADvalue>>(sns_VoltageCurrent0Scale-6+8))&0xff;
			txMsg.Data[2] = (ADvalue>>(sns_VoltageCurrent0Scale-6))&0xff;

			while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
		}
#endif

#ifdef sns_VoltageCurrent1AD
		if (VoltageCurrentChannelToSend==1)
		{
			ADvalue = ADC_Get(sns_VoltageCurrent1AD);
			ADvalue = ADvalue * sns_VoltageCurrent1Factor;
#if sns_VoltageCurrent1VorA==0
			txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_VOLTAGE;
#else
			txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_CURRENT;
#endif
			txMsg.Data[0] = 1;
			txMsg.Data[1] = (ADvalue>>(sns_VoltageCurrent1Scale-6+8))&0xff;
			txMsg.Data[2] = (ADvalue>>(sns_VoltageCurrent1Scale-6))&0xff;

			while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
		}
예제 #9
0
void sns_rfid_HandleCardEvent( uint8_t event ) {
    StdCan_Msg_t txMsg;

    gpio_set_statement( event, sns_rfid_STATUS_LED );

    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFID; ///TODO: Change this to the actual module type
    txMsg.Header.ModuleId = sns_rfid_ID;
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
    txMsg.Length = 6;

    txMsg.Data[0] = event;
    txMsg.Data[1] =  sns_rfid_card.version;
    txMsg.Data[2] =  sns_rfid_card.id&0xff;
    txMsg.Data[3] = (sns_rfid_card.id>>8)&0xff;
    txMsg.Data[4] = (sns_rfid_card.id>>16)&0xff;
    txMsg.Data[5] = (sns_rfid_card.id>>24)&0xff;

    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
예제 #10
0
void act_output_List(uint8_t ModuleSequenceNumber)
{
	StdCan_Msg_t txMsg;
	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_OUTPUT;
	txMsg.Header.ModuleId = act_output_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
	txMsg.Length = 6;

	uint32_t HwId=BIOS_GetHwId();
	txMsg.Data[0] = HwId&0xff;
	txMsg.Data[1] = (HwId>>8)&0xff;
	txMsg.Data[2] = (HwId>>16)&0xff;
	txMsg.Data[3] = (HwId>>24)&0xff;
	
	txMsg.Data[4] = NUMBER_OF_MODULES;
	txMsg.Data[5] = ModuleSequenceNumber;
	
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
예제 #11
0
void sns_BusVoltage_Process(void)
{
	///TODO: Stuff that needs doing is done here
	if (Timer_Expired(sns_BusVoltage_TIMER)) {
		uint16_t busVoltage = ADC_Get(BUSVOLTAGEAD);
		busVoltage = (busVoltage & 0x03ff) * ADC_FACTOR;
		
		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_BUSVOLTAGE;
		txMsg.Header.ModuleId = sns_BusVoltage_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_VOLTAGE;
		txMsg.Length = 3;
		txMsg.Data[0] = 0;
		txMsg.Data[1] = (busVoltage>>(ADC_SCALE-6+8))&0xff;
		txMsg.Data[2] = (busVoltage>>(ADC_SCALE-6))&0xff;

		StdCan_Put(&txMsg);
	}
}
예제 #12
0
void linearAct_sendPosition(uint8_t dummy) {
	StdCan_Msg_t txMsg;
	uint16_t w_tmp;
	
	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); 
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_LINEARACT; 
	txMsg.Header.ModuleId = act_linearAct_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_LINEARACT_POSITION;	
	txMsg.Length = 3;
	
	w_tmp = linearAct_getPosition();
	
	txMsg.Data[0] = w_tmp >> 8;
	txMsg.Data[1] = w_tmp;
	
	txMsg.Data[2] = direction;									

	//while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
	StdCan_Put(&txMsg);										// No problem if we miss one	
}
예제 #13
0
void tst_CoreLED_List(uint8_t ModuleSequenceNumber)
{
	StdCan_Msg_t txMsg;
	
	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_TST);
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_TST_DEBUG;
	txMsg.Header.ModuleId = tst_CoreLED_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
	txMsg.Length = 6;

	txMsg.Data[0] = NODE_HW_ID_BYTE0;
	txMsg.Data[1] = NODE_HW_ID_BYTE1;
	txMsg.Data[2] = NODE_HW_ID_BYTE2;
	txMsg.Data[3] = NODE_HW_ID_BYTE3;
	
	txMsg.Data[4] = NUMBER_OF_MODULES;
	txMsg.Data[5] = ModuleSequenceNumber;
	
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
예제 #14
0
void ReadTemperature(void)
{
	static uint8_t SearchSensorsTimeout = sns_ds18x20_SEARCH_TIMEOUT;
	static uint8_t CurrentSensor = 0;
	uint8_t subzero, cel, cel_frac_bits = 0;
	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_DS18X20;
	txMsg.Header.ModuleId = sns_ds18x20_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
	txMsg.Length = 3;

	txMsg.Data[0] = SensorIds[CurrentSensor];

	if (DS18X20_read_meas(&gSensorIDs[CurrentSensor][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK)
	{
		int16_t temp = cel;

		temp = temp << 6;

		temp += (cel_frac_bits << 2);

		if (subzero)
		{
			temp = -temp;
		}

		txMsg.Data[1] = (uint8_t)(temp >> 8);
		txMsg.Data[2] = (uint8_t)(temp & 0xff);

#ifdef CHN_LOADED
		for( uint8_t i=0; i<DS18x20_MAXSENSORS; i++) {
			if( sns_ds18s20_sensorids[i] == SensorIds[CurrentSensor] ) {
			        chn_ChnMaster_UpdateChannel( sns_ds18x20_CHN_CHANNEL + i, (temp<<2) + 25600 );
			}
		}
#endif
	}
예제 #15
0
void sns_rfid_List(uint8_t ModuleSequenceNumber)
{
    StdCan_Msg_t txMsg;

    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFID; ///TODO: Change this to the actual module type
    txMsg.Header.ModuleId = sns_rfid_ID;
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
    txMsg.Length = 6;

    uint32_t HwId=BIOS_GetHwId();
    txMsg.Data[0] = HwId&0xff;
    txMsg.Data[1] = (HwId>>8)&0xff;
    txMsg.Data[2] = (HwId>>16)&0xff;
    txMsg.Data[3] = (HwId>>24)&0xff;

    txMsg.Data[4] = NUMBER_OF_MODULES;
    txMsg.Data[5] = ModuleSequenceNumber;

    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
예제 #16
0
void linearAct_sendLimits (uint8_t dummy) {
	StdCan_Msg_t txMsg;

	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); 
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_LINEARACT; 
	txMsg.Header.ModuleId = act_linearAct_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_LINEARACT_LIMITS;	
	txMsg.Length = 8;
	
	txMsg.Data[0] = min >> 8;
	txMsg.Data[1] = min;
		
	txMsg.Data[2] = low >> 8;
	txMsg.Data[3] = low;
			
	txMsg.Data[4] = high >> 8;
	txMsg.Data[5] = high;

	txMsg.Data[6] = max >> 8;
	txMsg.Data[7] = max;
		
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
예제 #17
0
void send_debug(uint16_t *buffer, uint8_t len) {

	/* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */

	StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS);
	StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	irTxMsg.Length = 8;
	irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRRECEIVE;
	irTxMsg.Header.ModuleId = sns_irReceive_ID;
	irTxMsg.Header.Command = CAN_MODULE_CMD_IRRECEIVE_IRRAW;
	for (uint8_t i = 0; i < len>>2; i++) {
		uint8_t index = i<<2;

		irTxMsg.Data[0] = (buffer[index]>>8)&0xff;
		irTxMsg.Data[1] = (buffer[index]>>0)&0xff;
		irTxMsg.Data[2] = (buffer[index+1]>>8)&0xff;
		irTxMsg.Data[3] = (buffer[index+1]>>0)&0xff;
		irTxMsg.Data[4] = (buffer[index+2]>>8)&0xff;
		irTxMsg.Data[5] = (buffer[index+2]>>0)&0xff;
		irTxMsg.Data[6] = (buffer[index+3]>>8)&0xff;
		irTxMsg.Data[7] = (buffer[index+3]>>0)&0xff;
				
		/* buffers will be filled when sending more than 2-3 messages, so retry until sent */
		while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {}
	}
	
	uint8_t lastpacketcnt = len&0x03;
	if (lastpacketcnt > 0) {
		irTxMsg.Length = lastpacketcnt<<1;
		for (uint8_t i = 0; i < lastpacketcnt; i++) {
			irTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff;
			irTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff;
		}
		/* buffers will be filled when sending more than 2-3 messages, so retry until sent */
		while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {}
	}
예제 #18
0
void sns_inputAnalog_Process(void)
{
	/* When the timer has overflowed the AD channels shall be read */
	if (Timer_Expired(sns_inputAnalog_TIMER)) 
	{
		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_INPUTANALOG;
		txMsg.Header.ModuleId = sns_inputAnalog_ID;

		uint16_t AdValue=0;
		/* For each channel */
		for (uint8_t i=0; i<sns_inputAnalog_NUM_SUPPORTED; i++)
		{
			/* Do reading of AD channel */
			switch (i)
			{
				case 0:
					AdValue = ADC_Get(sns_inputAnalog0AD);
					break;
				case 1:
					AdValue = ADC_Get(sns_inputAnalog1AD);
					break;
				case 2:
					AdValue = ADC_Get(sns_inputAnalog2AD);
					break;
				case 3:
					AdValue = ADC_Get(sns_inputAnalog3AD);
					break;
			}
			
			/* If this channel is configured as periodic transmission of voltage */
			if (sns_inputAnalog_Config[i].Type == CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_PERIODICMEASURE)
			{
				/* Count periodicity */
				sns_inputAnalog_Sensor[i].PeriodCnt += sns_inputAnalog_POLL_PERIOD_MS;
				/* If periodicity overflowed or AD value changed more than threshold since last sent value */
				if (sns_inputAnalog_Sensor[i].PeriodCnt >= sns_inputAnalog_Config[i].Periodicity ||
					MAX(AdValue,sns_inputAnalog_Sensor[i].LastSentAdVal)-MIN(AdValue,sns_inputAnalog_Sensor[i].LastSentAdVal) > sns_inputAnalog_Config[i].LowTh)
				//if (sns_inputAnalog_Sensor[i].PeriodCnt >= sns_inputAnalog_Config[i].Periodicity ||
				//	abs(AdValue-sns_inputAnalog_Sensor[i].LastSentAdVal) > sns_inputAnalog_Config[i].LowTh)
				{
					/* Reset periodicity counter */
					sns_inputAnalog_Sensor[i].PeriodCnt = 0;
					/* Store value as last sent */
					sns_inputAnalog_Sensor[i].LastSentAdVal = AdValue;
					
					/* send sensor value on CAN with command CAN_MODULE_CMD_PHYSICAL_VOLTAGE */
					txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_VOLTAGE;
					txMsg.Length = 3;
					/* The channel should be transmitted in byte 0 */
					txMsg.Data[0] = i;
					
					uint8_t analogScale = 10;
					/* Select parameters for AD conversion */
					switch (i)
					{
						case 0:
							analogScale = sns_inputAnalog0Scale;
							AdValue = AdValue * sns_inputAnalog0Factor;
							break;
						case 1:
							analogScale = sns_inputAnalog1Scale;
							AdValue = AdValue * sns_inputAnalog1Factor;
							break;
						case 2:
							analogScale = sns_inputAnalog2Scale;
							AdValue = AdValue * sns_inputAnalog2Factor;
							break;
						case 3:
							analogScale = sns_inputAnalog3Scale;
							AdValue = AdValue * sns_inputAnalog3Factor;
							break;
					}
					txMsg.Data[1] = (AdValue>>(analogScale-6+8))&0xff;
					txMsg.Data[2] = (AdValue>>(analogScale-6))&0xff;
					
					/* Send value on CAN */
					while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
				}
			}
			/* If this channel is configured as digital input */
			else if (sns_inputAnalog_Config[i].Type == CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_DIGITALINPUT)
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;
	}
}
예제 #20
0
void act_hd44780_Process(void)
{
#if act_hd44780_USE_AUTO_BL == 1
  if (autoMode == CAN_MODULE_ENUM_HD44789_LCD_BACKLIGHT_AUTOLIGHT_ON) {
    #if (act_hd44780_TYPE==0)
      if ( OCR0A == 0) {
    #else
      if ( OCR0B == 0) {
    #endif

      } else {
      uint16_t Voltage = (0x3ff & ADC_Get(act_hd44780_LIGHTSENSOR_AD));
    #if (act_hd44780_TYPE==0)
	OCR0A = Voltage/4;
	if (OCR0A == 0) {
	  OCR0A = 1;
	}
    #else
	OCR0B = Voltage/4;
	if (OCR0B == 0) {
	  OCR0B = 1;
	}
    #endif
      }
  }
#endif


#if (act_hd44780_TYPE==0)
	if (OCR0A==0 && (TCCR0A & ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00))) == ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00)))
	{
		TCCR0A &= ~((1<<COM0A1)|(1<<WGM01)|(1<<WGM00));
	}
	if (OCR0A!=0 && (TCCR0A & ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00))) != ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00)))
	{
		TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00);
	}
#endif
		
		

		
		
}

void act_hd44780_HandleMessage(StdCan_Msg_t *rxMsg)
{
	StdCan_Msg_t txMsg;
	uint8_t n = 0;

	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_HD44789 &&
		rxMsg->Header.ModuleId == act_hd44780_ID)
	{
		switch (rxMsg->Header.Command)
		{
		case CAN_MODULE_CMD_HD44789_LCD_CLEAR:
		lcd_clrscr();
		break;

		case CAN_MODULE_CMD_HD44789_LCD_CURSOR:
		lcd_gotoxy(rxMsg->Data[0], rxMsg->Data[1]);
		break;

		case CAN_MODULE_CMD_HD44789_LCD_TEXTAT:
		lcd_gotoxy(rxMsg->Data[0], rxMsg->Data[1]);
		for (n = 2; n < rxMsg->Length; n++)
		{
			lcd_putc((char)rxMsg->Data[n]);
		}
		break;
/*
		case CAN_MODULE_CMD_HD44789_LCD_CLEARROW:
		lcd_gotoxy(0, rxMsg->Data[0]);
		for (n = 0; n < act_hd44780_WIDTH; n++)
		{
			lcd_putc(' ');
		}
		break;
*/
		case CAN_MODULE_CMD_HD44789_LCD_TEXT:
		for (n = 0; n < rxMsg->Length; n++)
		{
			lcd_putc((char)rxMsg->Data[n]);
		}
		break;

		case CAN_MODULE_CMD_HD44789_LCD_SIZE:
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
		txMsg.Header.ModuleId = act_hd44780_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_HD44789_LCD_SIZE;
		txMsg.Length = 2;

		txMsg.Data[0] = act_hd44780_WIDTH;
		txMsg.Data[1] = act_hd44780_HEIGHT;

		while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
		break;

		case CAN_MODULE_CMD_HD44789_LCD_BACKLIGHT:
		if (rxMsg->Length > 0) {
#if (act_hd44780_TYPE==0)
			OCR0A = rxMsg->Data[0];
#else
			OCR0B = rxMsg->Data[0];
#endif
#if act_hd44780_USE_AUTO_BL == 1
			if (rxMsg->Length == 2) {
				autoMode = rxMsg->Data[0]; 
			}
#endif
		}

		StdCan_Msg_t txMsg;

		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
		txMsg.Header.ModuleId = act_hd44780_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_HD44789_LCD_BACKLIGHT;
		txMsg.Length = 1;

#if (act_hd44780_TYPE==0)
			txMsg.Data[0] = OCR0A;
#else
			txMsg.Data[0] = OCR0B;
#endif
#if act_hd44780_USE_AUTO_BL == 1
		txMsg.Data[1] = autoMode;
		txMsg.Length = 2;
#endif
		while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
		break;
		}
	}
}
예제 #21
0
void sns_counter_HandleMessage(StdCan_Msg_t *rxMsg)
{
	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_COUNTER &&
		rxMsg->Header.ModuleId == sns_counter_ID)
	{
		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_COUNTER;
		txMsg.Header.ModuleId = sns_counter_ID;

		switch (rxMsg->Header.Command)
		{
		case CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL:
			if (rxMsg->Length > 0)
			{
				sns_counter_ReportInterval = rxMsg->Data[0];
				Timer_SetTimeout(sns_counter_SEND_TIMER, sns_counter_ReportInterval*1000 , TimerTypeFreeRunning, 0);
			}
			txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL;
			txMsg.Length = 1;
			txMsg.Data[0] = sns_counter_ReportInterval;
			StdCan_Put(&txMsg);
			break;
		case CAN_MODULE_CMD_COUNTER_SETCOUNTER:
			if (rxMsg->Length != 5)
				break;
			if (
#ifdef sns_counter_CH0
				(rxMsg->Data[0] != 0) &&
#endif
#ifdef sns_counter_CH1
				(rxMsg->Data[0] != 1) &&
#endif
#ifdef sns_counter_CH2
				(rxMsg->Data[0] != 2) &&
#endif
#ifdef sns_counter_CH3
				(rxMsg->Data[0] != 3) &&
#endif
#ifdef sns_counter_CH4
				(rxMsg->Data[0] != 4) &&
#endif
#ifdef sns_counter_CH5
				(rxMsg->Data[0] != 5) &&
#endif
#ifdef sns_counter_CH6
				(rxMsg->Data[0] != 6) &&
#endif
#ifdef sns_counter_CH7
				(rxMsg->Data[0] != 7) &&
#endif
				1)
				break;
			Count[rxMsg->Data[0]] = rxMsg->Data[4];
			Count[rxMsg->Data[0]] += ((uint32_t)rxMsg->Data[3])<<8;
			Count[rxMsg->Data[0]] += ((uint32_t)rxMsg->Data[2])<<16;
			Count[rxMsg->Data[0]] += ((uint32_t)rxMsg->Data[1])<<24;
			txMsg.Header.Command = CAN_MODULE_CMD_COUNTER_SETCOUNTER;
			txMsg.Length = 5;
			txMsg.Data[0] = rxMsg->Data[0];	// CH
			txMsg.Data[4] = (uint8_t)Count[rxMsg->Data[0]] & 0xff;
			txMsg.Data[3] = (uint8_t)(Count[rxMsg->Data[0]] >> 8) & 0xff;
			txMsg.Data[2] = (uint8_t)(Count[rxMsg->Data[0]] >> 16) & 0xff;
			txMsg.Data[1] = (uint8_t)(Count[rxMsg->Data[0]] >> 24) & 0xff;
			StdCan_Put(&txMsg);
			break;
		}
	}
예제 #22
0
void sns_flower_Process(void)
{
	static uint8_t measureState=0;
	static uint16_t results[6];
	static uint16_t resultsInv[6];
	uint16_t temp;
	static uint8_t flowerChannelToSend = 0;
  
	
	if (Timer_Expired(sns_flower_WAIT_TIMER)) {
		
		gpio_set_out(sns_flower_highSide_PIN);
		gpio_set_out(sns_flower_lowSide_PIN);
		gpio_set_pin(sns_flower_highSide_PIN);
		gpio_clr_pin(sns_flower_lowSide_PIN);
		measureState=0;
		Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_MEASUREMENT_PERIOD_MS , TimerTypeOneShot, 0);
	}
	
	if (Timer_Expired(sns_flower_MEASUREMENT_TIMER)) {
		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_VOLTAGECURRENT;
		txMsg.Header.ModuleId = sns_flower_ID;
		txMsg.Length = 3;
		switch (measureState) {
			case 0:
#ifdef sns_flower0AD
				results[0] = ADC_Get(sns_flower0AD);
#endif
#ifdef sns_flower1AD
				results[1] = ADC_Get(sns_flower1AD);
#endif
#ifdef sns_flower2AD
				results[2] = ADC_Get(sns_flower2AD);
#endif
#ifdef sns_flower3AD
				results[3] = ADC_Get(sns_flower3AD);
#endif
#ifdef sns_flower4AD
				results[4] = ADC_Get(sns_flower4AD);
#endif
#ifdef sns_flower5AD
				results[5] = ADC_Get(sns_flower5AD);
#endif	
				gpio_clr_pin(sns_flower_highSide_PIN);
				gpio_set_pin(sns_flower_lowSide_PIN);
				measureState=1;
				Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_MEASUREMENT_PERIOD_MS , TimerTypeOneShot, 0);
				break;
			case 1:
#ifdef sns_flower0AD
				resultsInv[0] = 1023-ADC_Get(sns_flower0AD);
#endif
#ifdef sns_flower1AD
				resultsInv[1] = 1023-ADC_Get(sns_flower1AD);
#endif
#ifdef sns_flower2AD
				resultsInv[2] = 1023-ADC_Get(sns_flower2AD);
#endif
#ifdef sns_flower3AD
				resultsInv[3] = 1023-ADC_Get(sns_flower3AD);
#endif
#ifdef sns_flower4AD
				resultsInv[4] = 1023-ADC_Get(sns_flower4AD);
#endif
#ifdef sns_flower5AD
				resultsInv[5] = 1023-ADC_Get(sns_flower5AD);
#endif	
				gpio_clr_pin(sns_flower_highSide_PIN);
				gpio_clr_pin(sns_flower_lowSide_PIN);
				gpio_set_in(sns_flower_highSide_PIN);
				gpio_set_in(sns_flower_lowSide_PIN);
				measureState=2;
				flowerChannelToSend=0;
				Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_MEASUREMENT_PERIOD_MS , TimerTypeOneShot, 0);
				break;
			case 2:	
				  switch(flowerChannelToSend) {
					  case 0:
#ifdef sns_flower0AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 0;
						temp = (uint16_t)((float)(results[0]+resultsInv[0])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 1;
# if  !(defined(sns_flower1AD) || defined(sns_flower2AD) || defined(sns_flower3AD) || defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
# endif
						break;
#endif
					case 1:
#ifdef sns_flower1AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 1;
						temp = (uint16_t)((float)(results[1]+resultsInv[1])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 2;
# if  !(defined(sns_flower2AD) || defined(sns_flower3AD) || defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
# endif
						break;
#endif
					case 2:
#ifdef sns_flower2AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 2;
						temp = (uint16_t)((float)(results[2]+resultsInv[2])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 3;
#if  !(defined(sns_flower3AD) || defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
#endif
						break;
#endif
					case 3:
#ifdef sns_flower3AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 3;
						temp = (uint16_t)((float)(results[3]+resultsInv[3])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 4;
#if  !( defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
#endif
						break;
#endif
					case 4:
#ifdef sns_flower4AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 4;
						temp = (uint16_t)((float)(results[4]+resultsInv[4])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 5;
#if  !(defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
#endif
						break;
#endif
					case 5:
#ifdef sns_flower5AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 5;
						temp = (uint16_t)((float)(results[5]+resultsInv[5])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 0;
						measureState=0;
						break;
#endif
					default:
						measureState=0;
						break;
				}
				if (measureState != 0) {
					Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_CAN_MSG_PAUS_MS , TimerTypeOneShot, 0);
				}
				break;
		}
  
	}
}