void sns_inputAnalog_Init(void)
{
#ifdef sns_inputAnalog_USEEEPROM
	if (EEDATA_OK)
	{
		/* Use stored data to set initial values for the module */
		for (uint8_t i=0; i<sns_inputAnalog_NUM_SUPPORTED; i++)
		{
			//eeprom_write_block( &sns_inputAnalog_Config[i], &eeprom_sns_inputAnalog, sizeof(sns_inputAnalog_Config)*i );
			eeprom_read_block( &sns_inputAnalog_Config[i], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*i, sizeof(sns_inputAnalog_Config) );
		}
	} 
	else
	{
		/* The CRC of the EEPROM is not correct, store default values and update CRC */
		for (uint8_t i=0; i<sns_inputAnalog_NUM_SUPPORTED; i++)
		{
			sns_inputAnalog_Config[i].LowTh=50;			//Config, low level threshold voltage
			sns_inputAnalog_Config[i].HighTh=100;		//Config, high level threshold voltage
			sns_inputAnalog_Config[i].Periodicity=5000+i*100;	//Config, periodicity
			sns_inputAnalog_Config[i].Type=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_PERIODICMEASURE;	//Config, if sensor is of type periodic or digital input
			sns_inputAnalog_Config[i].PullupEnable=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_DISABLE;		//Config, if the pullup should be enabled
			sns_inputAnalog_Config[i].RefEnable=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_DISABLE;		//Config, if the reference to GND should be enabled
			
#if ((__AVR_LIBC_MAJOR__ == 1  && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >= 7)||(__AVR_LIBC_MAJOR__ == 1  && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1)
			eeprom_update_block( &sns_inputAnalog_Config[i], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*i, sizeof(sns_inputAnalog_Config) );
#else
			eeprom_write_block( &sns_inputAnalog_Config[i], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*i, sizeof(sns_inputAnalog_Config) );
			#warning Using old version of AVRlibc, does not support eeprom_update-functions
#endif
		}
		EEDATA_UPDATE_CRC;
	}
#endif  

#if sns_inputAnalog_ENABLE_PCA95xx==1
	Pca95xx_Init(0);
#endif 
	/* Initiate ADC */
	ADC_Init();
	/* Start timer for reading inputs */
	Timer_SetTimeout(sns_inputAnalog_TIMER, sns_inputAnalog_POLL_PERIOD_MS , TimerTypeFreeRunning, 0);
	/* Set pullups according config */
	setPullups();
	/* Set gnd references according config */
	setReferences();
}
Beispiel #2
0
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

}