示例#1
0
int main(void)
{
	uint8_t result;
	
	///////////////////////////////////////
	sys_state = SYS_INIT;
	sd_avlb = 1;
	speeder_avlb = 1;
	gps_avlb = 1;
	///////////////////////////////////////
	
/////////////////////////////////////////////////////////////
	result = init();
	if(result)
	{
#if DEBUG
		uart_puts_p(PSTR("\nINIT Failed! \n\n"));
#endif		
		Disp_Clear();
		XY_Str_P(0,0,PSTR("NO SD Card! -"));
		XY_Num(13,0,result);
		XY_Char(11,1,m_arrow);
		XY_Str_P(12,1,PSTR("SKIP"));
		//XY_Str_P(12,1,m_item[4]);
		sd_avlb = 0;
		timer1_start();
		
		while(!(key_scan() == KEY_OK))
			_delay_ms(100);
		sei();
	}
#if DEBUG
	else
		uart_puts_p(PSTR("\nINIT Completed! \n\n"));
#endif
	sys_state = SYS_READY;
/////////////////////////////////////////////////////////////


	while(1)
	{
	/////////////////////////////////////////////////////////////	
#if DEBUG	
		uart_puts_p(PSTR("get_ready() start! \n"));
#endif
		while(sys_state == SYS_READY)
			get_ready();
	/////////////////////////////////////////////////////////////

				
	/////////////////////////////////////////////////////////////	
#if DEBUG	
		uart_puts_p(PSTR("task() start! \n"));
#endif	
		while(sys_state == SYS_WORKING)
			task();
	/////////////////////////////////////////////////////////////
	}
	return 0;
}
示例#2
0
void SD_task(void)
{
	if(gps_avlb)
	{
		if(gps_msg_ready)
		{
			gps_msg_ready++;
			
			if(sd_avlb)
			{
				if(timer1_flag && gpsraw_flag == 2)
				{
					timer1_flag++;
					write_gps_msg();
				}
				else
				{
					//if(gpsraw_flag == 0)
					if(gpsraw_flag == 0 && gps_state == 'A')
					{
						new_logfile();
						write_gps_head();
						write_gps_msg();
						timer1_start();
					}
				}
			}
		}
	}
}
示例#3
0
void irmsg_uartTxCompleteCallback() {
    /* This callback is executed after the last character has been sent from
     * the UART's transmit FIFO. */
		
    if (!m_flashIRLEDsPostTx) {
	/* If we have been instructed not to flash the IR LED in a pattern 
	 * which allows the receiver to determine its relative orientation, we
	 * indicate that we are no longer busy transmitting a message */
	m_txActive = false;
	return;
    }
	
    /* Otherwise, if we are going to flash the IR LEDs in a distinctive pattern
     * which the receiver can use to determine its relative orientation, we 
     * disable the 36kHz IR carrier and the UART transmitter circuit, so that 
     * the OR gated connected to all of the IR LEDs' cathodes will pull low. */
    timer0_disableCarrierOutput();
    uart0_disableTx();
	
    /* Set the flag which causes the irmsg_flashIRLEDsPostTxCallback to be 
     * executed each time Timer1 overflows and then start the timer (if it is
     * not already running). */
    g_postTxIRLEDsFlashingStart = true;
    timer1_start();
}
示例#4
0
void r3d2_init(void)
{
	NOTICE(0,"Initializing timer");
	// initialise timer used to get ticks of sensor detection and motor rotation
	timer_init();

	NOTICE(0,"timer1 starting");
	timer1_start();
	
	// initialise port to power on and get signal of the sensor 
	NOTICE(0,"Initializing sensor");	
	init_sensor();
	
	// power on the motor that drive the mirror
	NOTICE(0,"Initializing motor");
	motor_init();

	// first there is no robot detected, neither motor error
	robot_detected_value = robot_not_detected;
	motor_error_value = no_motor_error;

	robot_detected_timout_treshold = eeprom_read_byte(&eep_robot_detected_timout_treshold);
	surface_reflection_ratio = eeprom_read_float((float*)&eep_surface_reflection_ratio);
	robot_detected_angle_offset = eeprom_read_float((float*)&eep_robot_detected_angle_offset); 
	motor_rotating_timout_treshold = eeprom_read_byte(&eep_motor_rotating_timout_treshold);

	motor_rotating_timout_value = motor_rotating_timout_treshold;
	robot_detected_timout_value = 0;
}
void init_devices(void)
{
    // --------------------------------------------------------------
    // DDR and core CPU init
    // --------------------------------------------------------------

    // stop errant interrupts until set up
    cli();

    MCUCR = 0;
    TIMSK = 0;
    //GICR  = 0x00;

#if HALF_DUPLEX
    HALF_DUPLEX_DDR |= _BV(HALF_DUPLEX_PIN);
#endif

    LED1_DDR |= _BV(LED1);
    LED2_DDR |= _BV(LED2);


    // --------------------------------------------------------------
    // initialize subsystems
    // --------------------------------------------------------------

    lcd_init();
    uart_init();

    adc_init();

#if SERVANT_NPWM > 0
    timer1_init();      	// timers 0, 1
#endif

    timer0_init();
    sei(); 			// re-enable interrupts

    modbus_init();

    lcd_clear();
    lcd_gotoxy( 0, 0 );
    lcd_puts("Scan 1Wire:");
    lcd_gotoxy( 0, 1 );
    init_temperature();


    menu_init();

    // --------------------------------------------------------------
    // all peripherals are now initialized, start 'em
    // --------------------------------------------------------------

    adc_start();

#if SERVANT_NPWM > 0
    timer1_start();
#endif

}
示例#6
0
文件: ltc3675.c 项目: 211217613/uhd
/* PD(3) ONSWITCH_DB (PB_STAT), any change */
irqreturn_t ltc3675_button_change_irq_handler(void)
{
	bool pin_state;

	pin_state = io_test_pin(ONSWITCH_DB);

	/* the pushbutton is active low, therefore backwards logic */
	if (pin_state && !button.onswitch_last_state) {
		button.onswitch_release_event = true;
		timer1_stop();
	} else if (!pin_state && button.onswitch_last_state) {
		button.onswitch_press_event = true;
		timer1_start();
	}
	button.onswitch_last_state = pin_state;

	return IRQ_HANDLED;
}
示例#7
0
void irmsg_uartRxCallback(uint8_t c) {
    /* This callback is executed every time the UART receives a character.   */
	
    if (m_rxBufFull) {
	/* If the message receive buffer is marked full, we return immediately.
	 * It must be emptied with an I2C command before we can accept another
	 * message. */ 
	return;
    }
	
    /* Since we just received a character, reset the counter which we use to 
     * determine what constitutes the end of a message.  Since the transmitter
     * should have the complete messages queued before it starts sending, we
     * interpret even relatively small breaks between characters as the end of
     * one message and the start of another. */
    m_ambientLightSamplePeriodsWithoutNewCharacter = 0;
	
    /* If we are not already sampling the ambient light sensor, we set the 
     * start flag so that we will begin to do so the next time Timer1 
     * overflows. */
    if (!g_postRxAmbientLightSamplingActive) {
	g_postRxAmbientLightSamplingStart = true;
	/* Ensure that the timer is actually running */
	timer1_start();
		
	/* Reset the received message buffer pointer.  */
	m_rxBufLength = 0;
    }
	
    /* Save the received character */
    if (m_rxBufLength < sizeof(m_rxBuf)) {
	m_rxBuf[m_rxBufLength++] = c;
    }
	
    /* Mark the buffer full if we're out of space. */
    if (m_rxBufLength >= sizeof(m_rxBuf)) {
	m_rxBufFull = true;
    }
}