예제 #1
0
int main(void) {
	struct b_pool* pbuf;
	struct head* h;
	init_pools_buffers();
	//configure NVIC
	NVIC_Configuration();
	//start time
	start_timer();
	//configure adc
	ADC_config();
	//configure pwm
	pwm_Config();
	//ETHERNET INITIALIZATION
	ETH_BSP_Config();
	/* Initilaize the LwIP stack */
  LwIP_Init();
	//enable clock
	/*__disable_irq();
	clockHseInit();
	__enable_irq();*/
	/*Initilaize the PTP stack*/
	PTPd_Init();
	//udp initialization
	udp_echoserver_init();
	//configure state
	//init_current_state(&cur);
	cur.status = STOP;
	cur.id_sig = 0;
  while (1)
  {  
    //PROCESSING OF PEREODIC TASKS FOR LWIP
    LwIP_Periodic_Handle(gettime());
		//PROCESSING OF PEREODIC TASKS FOR PTP
		ptpd_Periodic_Handle(gettime());
		//PROCESSING OF QUEUING BUFFERS
		pbuf = pull_out_queue();
		if(pbuf != NULL) {
			h = (struct head*)pbuf->pbuf;
			if(h->dst & SLAVE) {
				if(h->type == COMMAND)
					handl_command(pbuf);
			} else
				transPackage(pbuf, eth_write);
			free_buf(pbuf);
		}
		//PROCESSING OF DEBUG_INFO
		if(debug.time > 0) {
			if(debug.num == -1 || debug.num > 0)  {
				debug_info();
			}
			else
				debug.time = 0;
			if (debug.num > 0)
				debug.num --;
		}
		//PROCESSING OF TEMP BUFFER
		
  }   
}
예제 #2
0
파일: main.c 프로젝트: westonb/ionophoney
int main(){

	
	
	Delay_init(8928); //1ms period
	GPIO_config();
	led_on();
	RF_config();
	ADC_config();
	SMPS_config();
	RF_enable();
	
	int i = 0;
	while(1){
		//code goes here
		i++;
		//led_on();
		//led_off();

	}


	return 0;
}
int main(void)
{
	//Calibração do sensor
	/*configPWM();
	setServoAngle(0);
	while(1){
	}*/
	double dt = 0.0;
	double curr_err = 0;
	float PID_Input = 0;
	float PID_Output = 0;
	int i_PID_Input = 0;
	int i_Output = 0;
	char c_PID_Input[4];
	char c_Output[4];
	char c_adc_value[4];
	float gain = -20.0;
	
	
	ADC_config();
	ADC_Start();
	USART_config();
	
	configPWM();
	setServoAngle(0);
	ConfigSerie_BT();
	pid_start();
	pid_timer_config();
	configMotorPWM(500);
	setMotorDirection(1);
	duty_cycle = 10;
	while(1)
	{
		
		if(mode == 1)
		{
			
			if(all_read == 1)
			{
				
				PID_Input = Centroid_Algorithm();
				curr_err = (3.5 - PID_Input);
				dt = TCNT5;
				dt = (dt*16)/1000000;
				
				pid_update(ptr, curr_err,dt);
				PID_Output = PID.control;
				itoa(i_Output, c_Output, 10);
				SendString((char*)"\n-------------------\n");
				SendString((char*)"\nSaída_PID 1: ");
				SendString(c_Output);
				
			
				PID_Output = PID_Output*gain;
				if(PID_Output > 75)
					PID_Output = 75;
				if(PID_Output < -75)
					PID_Output = -75;
			
				setServoAngle(PID_Output);
			
				i_PID_Input = (int) PID_Input;
				i_Output = (int) PID_Output;
				itoa(i_PID_Input, c_PID_Input ,10);
				itoa(i_Output, c_Output, 10);
				SendString((char*)"\nLeituras: "); 
				for(int i = 0; i < 8; i++)
					{
						itoa(adc_value[i], c_adc_value, 10); 
						SendString(c_adc_value);
						UsartSendByte(' ');
					}
				SendString((char*)"\nEntrada PID: "); 
				SendString(c_PID_Input); 
				SendString((char*)"\nSaída_PID 2: "); 
				SendString(c_Output); 
				all_read = 0; 
				ADMUX &= 0XE0; //Limpa ADMUX 
				ADMUX |= channel; //Selecciona o canal 0 
				ADCSRA |= (1<<ADSC); //Inicia conversão
			}
		}
		if(mode == 0)
		{
			//
		}

	}
}
예제 #4
0
void vmisc_tasks()
{
	uint8_t time_count,time_200ms;
	portTickType ticks_now,ticks_old = 0;
	uint16_t time_elapsed = 0;

	modem_config();
	ublox_init();
//	debug_config();			//configure debug serial port
	/*
	 * data from external sensors initialized, version M21
	 * can disable it by commenting here and changing dataFromInternalSensors from 0 to 1
	 * check externalPackets.h for more information
	 */
		if (!(dataFromInternalSensors))
	/*	initialize external sensors data UART3, debug port and this can't be enabled together		*/
	externalDataPortInit();
	RPM_config();

	ADC_config();
	ADC_SoftwareStartConv(ADC1);
	ADC_3_config();
	ADC_SoftwareStartConv(ADC3);
	PWM_out_config();

	for(;;)
	{
		if(WDT_status == 1)
		{
			IWDG_ReloadCounter();
			WDT_status = 0;		//clear it so that it can be set again if all is OK
		}
		if(xbee_tx_count>0)								//enable TX interrupts if transmit data is present
			USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
		if(gps_tx.count >0)								//enable TX interrupts if transmit data is present
			USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
		if(debug_tx_count >0)								//enable TX interrupts if transmit data is present
			USART_ITConfig(USART3, USART_IT_TXE, ENABLE);

		parse_gps_data();
		if(xbee_rx_count)
			parse_modem_data();

		if(xbee_fresh_data)	//if received fresh data
		{
			calculate_xbee();		//call appropriate function based on received data
			xbee_fresh_data = 0;
		}

		if(log_init_flag)
		{
			if(write_buff_to_card == 1)		//if one buffer is full
			{
				res = f_open(&fil, file_name, FA_OPEN_ALWAYS | FA_WRITE |FA_READ);
				f_lseek(&fil, cursor_pos);
				if(log_buff_status == 1)
				{
					f_write(&fil, SD_buffer2.BUFFER, SD_buffer2.write_count, &bw);
					cursor_pos += SD_buffer2.write_count;
				}
				else if(log_buff_status == 2)
				{
					f_write(&fil, SD_buffer1.BUFFER, SD_buffer1.write_count, &bw);
					cursor_pos += SD_buffer1.write_count;
				}
				write_buff_to_card = 0;
				f_close(&fil);
				GPIOF->ODR ^= GPIO_Pin_12;
			}
		}

    	ticks_now = xTaskGetTickCount()*2;
    	if((ticks_now - ticks_old) >=100)		//do the following every 100ms
    	{
    		time_elapsed = ticks_now - ticks_old;
    	   	rpm = pulse_cnt*2*60/MOTOR_POLES*(1000/time_elapsed);

    	   	pulse_cnt = 0;

    		ticks_old = ticks_now;
    		air_speed_indicator();
    		send_status();
    		if(link_count >= 5 )		//no data from more than 500ms
    		{
    			modem_link_active = 0;	//indicate absence of GIB
    			link_count = 0;
    		}
    		else
    			link_count++;

    		if(time_200ms == 2)			//do the following every 200ms
    		{
    			send_gps_data();
    			time_200ms = 0;
    		}
    		else
    			time_200ms++;

		    if(time_count == 5)			//do the following every 500ms
		    {
		    	queue_data();			//append debug data for transmission
		    	update_battery();
		    	update_RPM();
		    	send_press_temp();
		    	send_defections();
		    	send_power_propulsion();
		    	time_count = 0;
		    }
		    else
		    	time_count++;
    	}
	}
}