Ejemplo n.º 1
0
void __attribute__((__interrupt__,__no_auto_psv__)) _T1Interrupt(void) 
// excute whatever needs to run in the background, once every 0.5 seconds
{
	// interrupt_save_extended_state ;
	_T1IF = 0 ;			// clear the interrupt
	
	indicate_loading_inter ;

#if ( BOARD_TYPE == ASPG_BOARD )
	if ( ++timer1_counts < TMR1_CNTS  )	// actually interrupts every 0.1 sec
		return;
	else timer1_counts = 0;	// reset counter
#endif

	// capture cpu_timer once per second.
	if (skip_timer_reset )
	{
		// catch another 1/2 second in timer 5
		skip_timer_reset = 0;
	}
	else
	{
#if ( BOARD_TYPE == ASPG_BOARD )
		_DI();
		cpu_counter += TMR5 ;			// add last bit + calc %
		cpu_timer = (int)((cpu_counter / CPU_LOAD_PERCENT));
		old_cpu_counter = cpu_counter;
		cpu_counter = 0;				// clear it after
		_EI();
#else
		cpu_timer = TMR5 ;
#endif
		T5CONbits.TON = 0 ;		// turn off timer 5 
		TMR5 = 0 ;				// reset timer 5 to 0
		T5CONbits.TON = 1 ;		// turn on timer 5
		timer_5_on = 1;
		skip_timer_reset = 1;
	}
	
	udb_background_callback_periodic() ;
	
	
	// interrupt_restore_extended_state ;
	return ;
}
Ejemplo n.º 2
0
void udb_run(void)
{
	uint16_t currentTime;
	uint16_t nextHeartbeatTime;
	
	
	if (strlen(SILSIM_SERIAL_RC_INPUT_DEVICE) == 0) {
		udb_pwIn[THROTTLE_INPUT_CHANNEL] = 2000;
		udb_pwTrim[THROTTLE_INPUT_CHANNEL] = 2000;
	}
	
	nextHeartbeatTime = get_current_milliseconds();
	
	while (1) {
		if (!handleUDBSockets()) {
			sleep_milliseconds(1);
		}
		
		currentTime = get_current_milliseconds();
		
		if (currentTime >= nextHeartbeatTime && !(nextHeartbeatTime <= UDB_STEP_TIME && currentTime >= UDB_WRAP_TIME-UDB_STEP_TIME)) {
			udb_callback_read_sensors();
			
			udb_flags._.radio_on = (sil_radio_on && udb_pwIn[FAILSAFE_INPUT_CHANNEL] >= FAILSAFE_INPUT_MIN && udb_pwIn[FAILSAFE_INPUT_CHANNEL] <= FAILSAFE_INPUT_MAX);
			LED_GREEN = (udb_flags._.radio_on) ? LED_ON : LED_OFF ;

			if (udb_heartbeat_counter % 20 == 0) udb_background_callback_periodic(); // Run at 2Hz
			udb_servo_callback_prepare_outputs();
			
			sil_ui_update();
			
			if (udb_heartbeat_counter % 80 == 0) writeEEPROMFileIfNeeded(); // Run at 0.5Hz
			
			udb_heartbeat_counter++;
			nextHeartbeatTime = nextHeartbeatTime + UDB_STEP_TIME;
			if (nextHeartbeatTime > UDB_WRAP_TIME) nextHeartbeatTime -= UDB_WRAP_TIME;
		}
		process_queued_events();
	}
}