/**
 * \brief The call back function for CCA interrupt
 *  - This function sets phase0 and clears phase90
 *  - If round passed, sets index signal also
 */
void generator_qenc_timer_ccaint_handler(void)
{
	/* Static variable to store pulse count */
	static uint16_t pulse_count = 0;
	static uint8_t quadrature_steps[4] = {
		0,
		QENC_PH90_PIN,
		QENC_PH0_PIN | QENC_PH90_PIN,
		QENC_PH0_PIN,
	};

	tc_clear_overflow(generator_qenc_timer);

	/* Increment pulse count */
	if (generator_qenc_dir) {
		pulse_count++;
		if (pulse_count == generator_qenc_revolution) {
			pulse_count = 0;
		}
	} else {
		if (pulse_count == 0) {
			pulse_count = generator_qenc_revolution - 1;
		} else {
			pulse_count--;
		}
	}

	generator_qenc_port->OUT
			= (generator_qenc_port->OUT & ~(QENC_PH0_PH90_INDEX_PINS
			<< generator_qenc_pins_base))
			| (quadrature_steps[pulse_count % 4]
			 << generator_qenc_pins_base)
			| ((pulse_count == 0) ?
			 (QENC_INDEX_PIN << generator_qenc_pins_base) : 0);
}
Exemple #2
0
void app_cpu_load_task(void)
{
	static uint8_t bar_pos_last = 0;
	uint8_t bar_pos;

	/* Wait a total time > 250ms to update display each 250ms */
	if ((app_cpu_load_time_actif + app_cpu_load_time_sleep)
			< ((24000lu / 256lu) * 250)) {
		return;
	}

	/* Compute CPU load */
	if (tc_is_overflow(&TCC1)) {
		tc_clear_overflow(&TCC1);
		bar_pos = DISPLAY_CPU_LOAD_PROBAR_MAX_SIZE_X;
	} else {
		bar_pos = (app_cpu_load_time_actif *
				DISPLAY_CPU_LOAD_PROBAR_MAX_SIZE_X)
				/ (app_cpu_load_time_actif +
				app_cpu_load_time_sleep);
	}

	/* Update progress bar */
	if (bar_pos_last < bar_pos) {
		gfx_mono_draw_filled_rect(
				DISPLAY_CPU_LOAD_PROBAR_POS_X + bar_pos_last,
				DISPLAY_CPU_LOAD_PROBAR_POS_Y,
				bar_pos - bar_pos_last,
				DISPLAY_CPU_LOAD_PROBAR_SIZE_Y,
				GFX_PIXEL_SET);
	} else if (bar_pos_last > bar_pos) {
		gfx_mono_draw_filled_rect(
				DISPLAY_CPU_LOAD_PROBAR_POS_X + bar_pos,
				DISPLAY_CPU_LOAD_PROBAR_POS_Y,
				bar_pos_last - bar_pos,
				DISPLAY_CPU_LOAD_PROBAR_SIZE_Y,
				GFX_PIXEL_CLR);
	}

	bar_pos_last = bar_pos;

	/* Reset counters */
	app_cpu_load_time_actif = 0;
	app_cpu_load_time_sleep = 0;
}
Exemple #3
0
/*! \brief  to disable overflow interrupt
 */
void tmr_disable_ovf_interrupt(void)
{
	tc_set_overflow_interrupt_level(TIMER, TC_INT_LVL_OFF);
	tc_clear_overflow(TIMER);
}