/*! \brief  to disable compare interrupt
 */
void tmr_disable_cc_interrupt(void)
{
    tc_get_status(TIMER, TIMER_CHANNEL_ID);
#if SAM4E
    tc_disable_interrupt(TIMER, TIMER_CHANNEL_ID, TC_IDR_CPAS);
#else
    tc_disable_interrupt(TIMER, TIMER_CHANNEL_ID, TC_IDR_CPCS);
#endif
}
/*! \brief  to disable overflow interrupt
 */
void tmr_disable_ovf_interrupt(void)
{
    /*! \brief  to enable overflow interrupt
     */
    tc_get_status(TIMER, TIMER_CHANNEL_ID);
#if SAM4E
    tc_disable_interrupt(TIMER, TIMER_CHANNEL_ID, TC_IDR_CPCS);
#else
    tc_disable_interrupt(TIMER, TIMER_CHANNEL_ID, TC_IDR_COVFS);
#endif
}
Beispiel #3
0
void disable_timeoutcnt(void)
{
	tc_disable_interrupt(TC0, TC_CHANNEL_TICKCNT, TC_IER_CPCS);
	sysclk_disable_peripheral_clock(ID_TC0);
	
	timerEnabled = false;
}
Beispiel #4
0
void TC1_Handler(void)
{
	volatile uint32_t ul_dummy;
	/* Clear status bit to acknowledge interrupt */
	ul_dummy = tc_get_status(TC0,1);
	
	#if RTIMER_DEBUG
	if ((ul_dummy & TC_SR_CPCS) == TC_SR_CPCS) {
	#endif
		tc_stop(TC0,1);	// Crucial, since the execution may take long time
	#if RTIMER_DEBUG
		printf("Compare event %16x\r\n", ul_dummy);
	#endif
		tc_disable_interrupt(TC0,1,TC_IDR_CPCS);  // Disable the next compare interrupt XXX XXX
		ENERGEST_ON(ENERGEST_TYPE_IRQ);
		rtimer_run_next(); /* Run the posted task. */
		ENERGEST_OFF(ENERGEST_TYPE_IRQ);
		
	#if RTIMER_DEBUG
	}
	else {
		printf("Unknown interrupt.\n\n");
	}
	#endif
	
}
Beispiel #5
0
void
rtimer_arch_init(void)
{	
	/*
	 * In this implementation we will make use of two Timer Counters (TC).
	 * The first (TC0) is used to count the universal time, and triggers 
	 * an interrupt on overflow. The timer runs always, and counts the total 
	 * time elapsed since device boot. It is used to extract the current time 
	 * (now)
	 *
	 * The second timer (TC1) is used to schedule events in real time.
	 */
	
	/* Configure PMC: Enable peripheral clock on component: TC0, channel 0 [see sam3x8e.h] */
	pmc_enable_periph_clk(ID_TC0);
	/* Configure PMC: Enable peripheral clock on component: TC0, channel 1 [see sam3x8e.h] */
	pmc_enable_periph_clk(ID_TC1);
	
	/* Configure the TC0 for 10500000 Hz and trigger on RC register compare */
	tc_init(TC0, 0, RT_PRESCALER | TC_CMR_CPCTRG);
	/* Configure the TC1 for 10500000 Hz and trigger on RC register compare */
	tc_init(TC0, 1, RT_PRESCALER | TC_CMR_CPCTRG);
	
	/* Disable all interrupts on both counters*/
	tc_disable_interrupt(TC0,0,0b11111111);
	tc_disable_interrupt(TC0,1,0b11111111);
	
	/* Configure the main counter to trigger an interrupt on RC compare (overflow) */
	tc_write_rc(TC0, 0, 0xffffffff);
	
	/* Configure interrupt on the selected timer channel, setting the corresponding callback */
	NVIC_EnableIRQ((IRQn_Type) ID_TC0);
	/* Configure interrupt on the selected timer channel, setting the corresponding callback */
	NVIC_EnableIRQ((IRQn_Type) ID_TC1);
	
	/* Enable TC0 interrupt on RC Compare */
	tc_enable_interrupt(TC0, 0, TC_IER_CPCS);
	
	/* Start the universal time counter */
	tc_start(TC0, 0);
#if DEBUG	
	printf("DEBUG: Universal Real-Timer started.\n");
#endif	
}
Beispiel #6
0
/**
 * \brief Configure Timer Counter 0 to generate an interrupt with the specific
 * frequency.
 *
 * \param freq Timer counter frequency.
 */
static void configure_tc(uint32_t freq)
{
	uint32_t ul_div;
	uint32_t ul_tcclks;
	uint32_t ul_sysclk = sysclk_get_cpu_hz();

	/* Disable TC first */
	tc_stop(TC0, 0);
	tc_disable_interrupt(TC0, 0, TC_IER_CPCS);

	/** Configure TC with the frequency and trigger on RC compare. */
	tc_find_mck_divisor(freq, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk);
	tc_init(TC0, 0, ul_tcclks | TC_CMR_CPCTRG);
	tc_write_rc(TC0, 0, (ul_sysclk / ul_div) / 4);

	/* Configure and enable interrupt on RC compare */
	NVIC_EnableIRQ((IRQn_Type)ID_TC0);
	tc_enable_interrupt(TC0, 0, TC_IER_CPCS);

	/** Start the counter. */
	tc_start(TC0, 0);
}
Beispiel #7
0
/**
 * \brief Application entry point for tc_capture_waveform example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t key;
	uint16_t frequence, dutycycle;

	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the console uart */
	configure_console();

	/* Output example information */
	printf("-- TC capture waveform Example --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Configure PIO Pins for TC */
#if (SAM4L || SAM4E)
	ioport_set_pin_mode(PIN_TC_WAVEFORM, PIN_TC_WAVEFORM_FLAGS);
	ioport_disable_pin(PIN_TC_WAVEFORM); // Disable IO (but enable peripheral mode)
	ioport_set_pin_mode(PIN_TC_CAPTURE, PIN_TC_CAPTURE_FLAGS);
	ioport_disable_pin(PIN_TC_CAPTURE); // Disable IO (but enable peripheral mode)
#else
	gpio_configure_pin(PIN_TC_WAVEFORM, PIN_TC_WAVEFORM_FLAGS);
	gpio_configure_pin(PIN_TC_CAPTURE, PIN_TC_CAPTURE_FLAGS);
#endif

	/* Configure TC TC_CHANNEL_WAVEFORM as waveform operating mode */
	printf("Configure TC%d channel %d as waveform operating mode \n\r",
			TC_PERIPHERAL, TC_CHANNEL_WAVEFORM);
	tc_waveform_initialize();
	/* Configure TC TC_CHANNEL_CAPTURE as capture operating mode */
	printf("Configure TC%d channel %d as capture operating mode \n\r",
			TC_PERIPHERAL, TC_CHANNEL_CAPTURE);
	tc_capture_initialize();

	/* Configure TC interrupts for TC TC_CHANNEL_CAPTURE only */
	NVIC_DisableIRQ(TC_IRQn);
	NVIC_ClearPendingIRQ(TC_IRQn);
	NVIC_SetPriority(TC_IRQn, 0);
	NVIC_EnableIRQ(TC_IRQn);

	/* Display menu */
	display_menu();

	while (1) {
		scanf("%c", (char *)&key);

		switch (key) {
		case 'h':
			display_menu();
			break;

		case 's':
			if (gs_ul_captured_pulses) {
				tc_disable_interrupt(TC, TC_CHANNEL_CAPTURE, TC_IDR_LDRBS);
				printf("Captured %u pulses from TC%d channel %d, RA = %u, RB = %u \n\r",
						gs_ul_captured_pulses, TC_PERIPHERAL,
						TC_CHANNEL_CAPTURE,	gs_ul_captured_ra,
						gs_ul_captured_rb);
#if (SAM4L)
				frequence = (sysclk_get_peripheral_bus_hz(TC) /
						divisors[TC_CAPTURE_TIMER_SELECTION]) /
						gs_ul_captured_rb;
#else
				frequence = (sysclk_get_peripheral_hz() /
						divisors[TC_CAPTURE_TIMER_SELECTION]) /
						gs_ul_captured_rb;
#endif
				dutycycle
					= (gs_ul_captured_rb - gs_ul_captured_ra) * 100 /
						gs_ul_captured_rb;
				printf("Captured wave frequency = %d Hz, Duty cycle = %d%% \n\r",
						frequence, dutycycle);

				gs_ul_captured_pulses = 0;
				gs_ul_captured_ra = 0;
				gs_ul_captured_rb = 0;
			} else {
				puts("No waveform has been captured\r");
			}

			puts("\n\rPress 'h' to display menu\r");
			break;

		case 'c':
			puts("Start capture, press 's' to stop \r");
			tc_enable_interrupt(TC, TC_CHANNEL_CAPTURE, TC_IER_LDRBS);
			/* Start the timer counter on TC TC_CHANNEL_CAPTURE */
			tc_start(TC, TC_CHANNEL_CAPTURE);
			break;

		default:
			/* Set waveform configuration #n */
			if ((key >= '0') && (key <= ('0' + gc_uc_nbconfig - 1))) {
				if (!gs_ul_captured_pulses) {
					gs_uc_configuration = key - '0';
					tc_waveform_initialize();
				} else {
					puts("Capturing ... , press 's' to stop capture first \r");
				}
			}

			break;
		}
	}
}
Beispiel #8
0
void lp_ticker_disable_interrupt(void)
{
    tc_stop(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2);
    tc_disable_interrupt(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2, TC_IDR_CPCS);
    NVIC_DisableIRQ(TICKER_COUNTER_IRQn2);
}