Ejemplo n.º 1
0
static void spi_gpio_chipselect(struct spi_device *dev, int value)
{
	struct spi_gpio *sg = spidev_to_sg(dev);
        switch (value) {
        case BITBANG_CS_ACTIVE:
		gpio_set_out(sg->ce, 0);
                break;
        case BITBANG_CS_INACTIVE:
		gpio_set_out(sg->ce, 1);
                break;
        }

}
Ejemplo n.º 2
0
void act_linearAct_Init(void)
{
#if act_linearAct_USEEEPROM==1
	if (EEDATA_OK)
	{
	  ///TODO: Use stored data to set initial values for the module
	  pulses = eeprom_read_word(EEDATA16.pulses_ee);
	  min = eeprom_read_word(EEDATA16.min_ee);
	  low = eeprom_read_word(EEDATA16.low_ee);
	  high = eeprom_read_word(EEDATA16.high_ee);
	  max = eeprom_read_word(EEDATA16.max_ee);
	} else
	{	//The CRC of the EEPROM is not correct, store default values and update CRC
	  eeprom_write_word_crc(EEDATA16.pulses_ee, 1200, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.min_ee, 300, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.low_ee, 815, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.high_ee, 5600, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.max_ee, 6100, WITHOUT_CRC);
	  EEDATA_UPDATE_CRC;
	}
#else	
	// Only for testing/debugging...
	pulses = 1200;
	min = 300;
	low = 815;
	high = 5600;
	max = 6100;
#endif
	
	// PD5 (EXP_G) is used as Timer1 input. Hardwired, no move possible!
	gpio_set_in(EXP_G);
	gpio_set_pullup(EXP_G);
	
	//PORTD &= ~(_BV(DIR_RELAY) | _BV(ON_RELAY));
	gpio_clr_pin(RELAY_ON);
	gpio_clr_pin(RELAY_DIR);
	
	// initiera utgångar 
	//DDRD = (_BV(DIR_RELAY) | _BV(ON_RELAY));
	gpio_set_out(RELAY_ON);
	gpio_set_out(RELAY_DIR);

	// Start report timer
	Timer_SetTimeout(act_linearAct_TIMER_report, act_linearAct_ReportInterval*1000 , TimerTypeFreeRunning, 0);
#if (USE_STIMULI == 1)	
	// Set stimuli as an output
	gpio_set_out(STIMULI);
	Timer_SetTimeout(act_linearAct_TIMER_stimuli, 10, TimerTypeFreeRunning,0);
#endif
}
Ejemplo n.º 3
0
void tst_CoreLED_Init(void)
{
	/// Initialize hardware etc here

	Timer_SetTimeout(tst_CoreLED_Blink_TIMER, tst_CoreLED_Blink_Interval , TimerTypeFreeRunning, 0);
	
	gpio_set_out(tst_CoreLED_PIN);
	
}
Ejemplo n.º 4
0
int main(void)
{
	qm_rtc_config_t rtc_cfg;
	unsigned int count = 0;
	/* loop_max : Maximum number of iterations.
	 * A value of 50 will run the application for roughly 30s.
	 */
	const unsigned int loop_max = 50;
	gpio_init();
	pin_mux_setup();
	gpio_set_out(BOARD_LED_PIN, 0); /* Configure the onboard LED pin. */

	/* Clear Screen. */
	QM_PUTS("Starting: Power Profiler");
	QM_PUTS("Low power mode example.");
	QM_PRINTF("Increment = %d\n", QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1));

	clk_periph_enable(CLK_PERIPH_RTC_REGISTER | CLK_PERIPH_CLK);

	/* Initialise RTC configuration: Run, but don't interrupt. */
	rtc_cfg.init_val = 0;
	rtc_cfg.alarm_en = 0;
	rtc_cfg.alarm_val = QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1);
	rtc_cfg.callback = rtc_example_callback;
	rtc_cfg.prescaler = CLK_RTC_DIV_1;
	qm_rtc_set_config(QM_RTC_0, &rtc_cfg);

	QM_IR_UNMASK_INT(QM_IRQ_RTC_0_INT);
	QM_IRQ_REQUEST(QM_IRQ_RTC_0_INT, qm_rtc_0_isr);

#if (!QM_SENSOR)
	test_clock_rates();
#endif

	/* Enable the RTC Interrupt. */
	rtc_cfg.alarm_en = 1;
	qm_rtc_set_config(QM_RTC_0, &rtc_cfg);

	count = 0;
	while (++count < loop_max) {
		QM_PRINTF("\nC:%d R:%d => ", count, rtc_tick);

		slow_mode_test();
		halt_test();
		core_sleep_test();
		/* TODO : Enable soc_sleep test for c1000. */
		soc_sleep_test();
		/* TODO : Enable soc_deep_sleep test for d2000 and c1000. */
		soc_deep_sleep_test();
	}
	SOC_WATCH_TRIGGER_FLUSH();
	QM_PUTS("Finished: Power Profiler");
	return 0;
}
Ejemplo n.º 5
0
void calibrate(){

	//For current, set Muxctrl mode to ouput, then set output to 0
	gpio_set_mode(&PORTD, 0b0, 1);
	gpio_set_out(&PORTD, 0b0, 0);

	//Set voltage input to Pin7 GND
	ADCB_CH1_MUXCTRL |= 0b111000; //Set voltage input to gnd

	printf("===BEGIN CALIBRATION===");
	while(numSamples < 1000){
		blinkAndSample();
	}
	printf("===END CALIBRATION===");
	
	//For current, set muxctrl input high
	gpio_set_out(&PORTD, 0b0, 1);
	//Return voltage back to where it was before
	ADCB_CH1_MUXCTRL = (ADCB_CH1_MUXCTRL & 0b111) | 0b10000; //Pin 2 is voltage
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: jeez/qmsi
int main(void)
{
	qm_rtc_config_t rtc_cfg;
	unsigned int count = 0;
	/* Maximum number of 3-second iterations. */
	const unsigned int loop_max = 5;
	gpio_init();
	gpio_set_out(BOARD_LED_PIN, 0); /* Configure the onboard LED pin. */

	/* Clear Screen. */
	QM_PUTS("Starting: Power Profiler");
	QM_PUTS("Low power mode example.");
	QM_PRINTF("Increment = %d\n", QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1));

	clk_periph_enable(CLK_PERIPH_RTC_REGISTER | CLK_PERIPH_CLK);

	/* Initialise RTC configuration: Run, but don't interrupt. */
	rtc_cfg.init_val = 0;
	rtc_cfg.alarm_en = 0;
	rtc_cfg.alarm_val = QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1);
	rtc_cfg.callback = rtc_example_callback;
	rtc_cfg.prescaler = CLK_RTC_DIV_1;
	qm_rtc_set_config(QM_RTC_0, &rtc_cfg);

	qm_irq_request(QM_IRQ_RTC_0_INT, qm_rtc_0_isr);

	test_clock_rates();

	/* Enable the RTC Interrupt. */
	rtc_cfg.alarm_en = 1;
	qm_rtc_set_config(QM_RTC_0, &rtc_cfg);

	count = 0;
	while (++count < loop_max) {
		QM_PRINTF("\nC:%d R:%d => ", count, rtc_tick);

		slow_mode_test();
		halt_test();
		sleep_test();
#if DEEP_SLEEP
		deep_sleep_test();
#endif
	}
	QM_PUTS("Finished: Power Profiler");
	return 0;
}
Ejemplo n.º 7
0
/* Will set up pullup enable outputs according config */
void setPullups(void)
{
	if (sns_inputAnalog_Config[0].PullupEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_ENABLE)
	{
#if sns_inputAnalog0PullupPCA95xx==0
		gpio_set_pin(sns_inputAnalog0Pullup);
		gpio_set_out(sns_inputAnalog0Pullup);
#else
		Pca95xx_set_pin(sns_inputAnalog0Pullup);
		Pca95xx_set_out(sns_inputAnalog0Pullup);
#endif
	}
	else
	{
#if sns_inputAnalog0PullupPCA95xx==0
		gpio_clr_pin(sns_inputAnalog0Pullup);
		gpio_set_out(sns_inputAnalog0Pullup);
#else
		Pca95xx_clr_pin(sns_inputAnalog0Pullup);
		Pca95xx_set_out(sns_inputAnalog0Pullup);
#endif
	}
	
#if sns_inputAnalog_NUM_SUPPORTED>=2
	if (sns_inputAnalog_Config[1].PullupEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_ENABLE)
	{
#if sns_inputAnalog1PullupPCA95xx==0
		gpio_set_pin(sns_inputAnalog1Pullup);
		gpio_set_out(sns_inputAnalog1Pullup);
#else
		Pca95xx_set_pin(sns_inputAnalog1Pullup);
		Pca95xx_set_out(sns_inputAnalog1Pullup);
#endif
	}
	else
	{
#if sns_inputAnalog1PullupPCA95xx==0
		gpio_clr_pin(sns_inputAnalog1Pullup);
		gpio_set_out(sns_inputAnalog1Pullup);
#else
		Pca95xx_clr_pin(sns_inputAnalog1Pullup);
		Pca95xx_set_out(sns_inputAnalog1Pullup);
#endif
	}
#endif

#if sns_inputAnalog_NUM_SUPPORTED>=3
	if (sns_inputAnalog_Config[2].PullupEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_ENABLE)
	{
#if sns_inputAnalog2PullupPCA95xx==0
		gpio_set_pin(sns_inputAnalog2Pullup);
		gpio_set_out(sns_inputAnalog2Pullup);
#else
		Pca95xx_set_pin(sns_inputAnalog2Pullup);
		Pca95xx_set_out(sns_inputAnalog2Pullup);
#endif
	}
	else
	{
#if sns_inputAnalog2PullupPCA95xx==0
		gpio_clr_pin(sns_inputAnalog2Pullup);
		gpio_set_out(sns_inputAnalog2Pullup);
#else
		Pca95xx_clr_pin(sns_inputAnalog2Pullup);
		Pca95xx_set_out(sns_inputAnalog2Pullup);
#endif
	}
#endif

#if sns_inputAnalog_NUM_SUPPORTED>=4
	if (sns_inputAnalog_Config[3].PullupEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_ENABLE)
	{
#if sns_inputAnalog3PullupPCA95xx==0
		gpio_set_pin(sns_inputAnalog3Pullup);
		gpio_set_out(sns_inputAnalog3Pullup);
#else
		Pca95xx_set_pin(sns_inputAnalog3Pullup);
		Pca95xx_set_out(sns_inputAnalog3Pullup);
#endif
	}
	else
	{
#if sns_inputAnalog3PullupPCA95xx==0
		gpio_clr_pin(sns_inputAnalog3Pullup);
		gpio_set_out(sns_inputAnalog3Pullup);
#else
		Pca95xx_clr_pin(sns_inputAnalog3Pullup);
		Pca95xx_set_out(sns_inputAnalog3Pullup);
#endif
	}
#endif
}
Ejemplo n.º 8
0
/* Will set up reference enable outputs according config */
void setReferences(void)
{
	if (sns_inputAnalog_Config[0].RefEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_ENABLE)
	{
#if sns_inputAnalog0RefPCA95xx==0
		gpio_set_pin(sns_inputAnalog0Ref);
		gpio_set_out(sns_inputAnalog0Ref);
#else
		Pca95xx_set_pin(sns_inputAnalog0Ref);
		Pca95xx_set_out(sns_inputAnalog0Ref);
#endif
	}
	else
	{
#if sns_inputAnalog0RefPCA95xx==0
		gpio_clr_pin(sns_inputAnalog0Ref);
		gpio_set_out(sns_inputAnalog0Ref);
#else
		Pca95xx_clr_pin(sns_inputAnalog0Ref);
		Pca95xx_set_out(sns_inputAnalog0Ref);
#endif
	}
	
#if sns_inputAnalog_NUM_SUPPORTED>=2
	if (sns_inputAnalog_Config[1].RefEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_ENABLE)
	{
#if sns_inputAnalog1RefPCA95xx==0
		gpio_set_pin(sns_inputAnalog1Ref);
		gpio_set_out(sns_inputAnalog1Ref);
#else
		Pca95xx_set_pin(sns_inputAnalog1Ref);
		Pca95xx_set_out(sns_inputAnalog1Ref);
#endif
	}
	else
	{
#if sns_inputAnalog1RefPCA95xx==0
		gpio_clr_pin(sns_inputAnalog1Ref);
		gpio_set_out(sns_inputAnalog1Ref);
#else
		Pca95xx_clr_pin(sns_inputAnalog1Ref);
		Pca95xx_set_out(sns_inputAnalog1Ref);
#endif
	}
#endif

#if sns_inputAnalog_NUM_SUPPORTED>=3
	if (sns_inputAnalog_Config[2].RefEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_ENABLE)
	{
#if sns_inputAnalog2RefPCA95xx==0
		gpio_set_pin(sns_inputAnalog2Ref);
		gpio_set_out(sns_inputAnalog2Ref);
#else
		Pca95xx_set_pin(sns_inputAnalog2Ref);
		Pca95xx_set_out(sns_inputAnalog2Ref);
#endif
	}
	else
	{
#if sns_inputAnalog2RefPCA95xx==0
		gpio_clr_pin(sns_inputAnalog2Ref);
		gpio_set_out(sns_inputAnalog2Ref);
#else
		Pca95xx_clr_pin(sns_inputAnalog2Ref);
		Pca95xx_set_out(sns_inputAnalog2Ref);
#endif
	}
#endif

#if sns_inputAnalog_NUM_SUPPORTED>=4
	if (sns_inputAnalog_Config[3].RefEnable==CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_ENABLE)
	{
#if sns_inputAnalog3RefPCA95xx==0
		gpio_set_pin(sns_inputAnalog3Ref);
		gpio_set_out(sns_inputAnalog3Ref);
#else
		Pca95xx_set_pin(sns_inputAnalog3Ref);
		Pca95xx_set_out(sns_inputAnalog3Ref);
#endif
	}
	else
	{
#if sns_inputAnalog3RefPCA95xx==0
		gpio_clr_pin(sns_inputAnalog3Ref);
		gpio_set_out(sns_inputAnalog3Ref);
#else
		Pca95xx_clr_pin(sns_inputAnalog3Ref);
		Pca95xx_set_out(sns_inputAnalog3Ref);
#endif
	}
#endif	
}
Ejemplo n.º 9
0
static inline void setmosi(struct spi_device *dev, int on)
{
	struct spi_gpio *sg = spidev_to_sg(dev);

	gpio_set_out(sg->dt, on ? 1 : 0);
}
Ejemplo n.º 10
0
static int spi_gpio_probe(struct platform_device *dev)
{
	struct spi_master	*master;
	struct spi_gpio  *sp;
	int ret;


	master = spi_alloc_master(&dev->dev, sizeof(struct spi_gpio));
	if (master == NULL) {
		dev_err(&dev->dev, "failed to allocate spi master\n");
		ret = -ENOMEM;
		goto err;
	}

	sp = spi_master_get_devdata(master);

	platform_set_drvdata(dev, sp);

	sp->clk = gpio_request( NXC2600_SPI_CLK_GPIO_PIN,
				GPIO_DIR_OUT,
				&(dev->dev));
	sp->ce  = gpio_request( NXC2600_SPI_CE_GPIO_PIN,
				GPIO_DIR_OUT,
				&(dev->dev));
	sp->dt  = gpio_request( NXC2600_SPI_DT_GPIO_PIN,
				GPIO_DIR_OUT,
				&(dev->dev));
	sp->dr	= gpio_request( NXC2600_SPI_DR_GPIO_PIN,
				GPIO_DIR_IN,
				&(dev->dev));
	/* setup spi bitbang adaptor */
	sp->bitbang.master = spi_master_get(master);
	sp->bitbang.chipselect = spi_gpio_chipselect;

	sp->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_mode0;
	sp->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_mode1;
	sp->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_mode2;
	sp->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_mode3;

	/* set state of spi pins */
	gpio_set_out(sp->clk, 0);
	gpio_set_out(sp->dt, 0);
	gpio_set_out(sp->ce, 1);


	master->bus_num = 0;
        master->num_chipselect = 1;


	ret = spi_bitbang_start(&sp->bitbang);
	if (ret)
		goto err_no_bitbang;

	printk("NXC2600 GPIO SPI initialed.\n");
	return 0;

 err_no_bitbang:
	spi_master_put(sp->bitbang.master);
 err:
	return ret;

}
Ejemplo n.º 11
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;
		}
  
	}
}
Ejemplo n.º 12
0
void sns_rfid_Init(void)
{
    rfid_init();

    gpio_set_out( sns_rfid_STATUS_LED );
}
Ejemplo n.º 13
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

}
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;
}