Пример #1
0
void app_cpu_load_init(void)
{
	/* Reset counters */
	app_cpu_load_time_active = 0;
	app_cpu_load_time_sleep = 0;
	/* Start Timer counter used to monitor CPU timing */
	tc45_enable(&TCC4);
	tc45_write_clock_source(&TCC4, TC45_CLKSEL_DIV256_gc); /* 24MHz / 256 */
	tc45_set_direction(&TCC4, TC45_UP);
	/* Display static background */
	gfx_mono_draw_string(DISPLAY_CPU_LOAD_TEXT,
			DISPLAY_CPU_LOAD_TEXT_POS_X,
			DISPLAY_CPU_LOAD_TEXT_POS_Y,
			&sysfont);
	gfx_mono_draw_filled_rect(
			DISPLAY_CPU_LOAD_PROBAR_START_POS_X,
			DISPLAY_CPU_LOAD_PROBAR_START_POS_Y,
			DISPLAY_CPU_LOAD_PROBAR_START_SIZE_X,
			DISPLAY_CPU_LOAD_PROBAR_START_SIZE_Y,
			GFX_PIXEL_SET);
	gfx_mono_draw_filled_rect(
			DISPLAY_CPU_LOAD_PROBAR_STOP_POS_X,
			DISPLAY_CPU_LOAD_PROBAR_STOP_POS_Y,
			DISPLAY_CPU_LOAD_PROBAR_STOP_SIZE_X,
			DISPLAY_CPU_LOAD_PROBAR_STOP_SIZE_Y,
			GFX_PIXEL_SET);
}
Пример #2
0
// setup the board instead of board_init() as recommended by ASF.. because christmas lights, that's why.
void init (void) {
	static usart_serial_options_t usart_options = {
		.baudrate = USART_SERIAL_BAUDRATE,
		.charlength = USART_SERIAL_CHAR_LENGTH,
		.paritytype = USART_SERIAL_PARITY,
		.stopbits = USART_SERIAL_STOP_BIT
	};
	
	// initialize ASF stuff
	board_init();
	sysclk_init();
	ioport_init();
	pmic_init();
	pmic_set_scheduling(PMIC_SCH_FIXED_PRIORITY);
	
	// remap, enable TX, and configure USART on PORT C
	PORTC.REMAP |= PR_USART0_bm;
	PORTC.DIR |= (1 << PIN7_bp);
		
	sysclk_enable_module(SYSCLK_PORT_C, PR_USART0_bm);
	usart_init_rs232(USART_SERIAL, &usart_options);
	
	// setup timer for PWM
	tc45_enable(&TCC4);
	tc45_set_overflow_interrupt_callback(&TCC4, pwm_callback);
	tc45_set_wgm(&TCC4, TC45_WG_NORMAL);
	tc45_write_period(&TCC4, 256);
	tc45_set_overflow_interrupt_level(&TCC4, TC45_INT_LVL_MED);
		
	// enable all channels and turn off (high)
	ioport_set_port_dir(IOPORT_PORTA, PORTA_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_dir(IOPORT_PORTD, PORTD_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_dir(IOPORT_PORTR, PORTR_MASK, IOPORT_DIR_OUTPUT);
	ioport_set_port_level(IOPORT_PORTA, PORTA_MASK, 0xFF);
	ioport_set_port_level(IOPORT_PORTD, PORTD_MASK, 0xFF);
	ioport_set_port_level(IOPORT_PORTR, PORTR_MASK, 0xFF);
	for (uint8_t i=0; i<NUM_CHANNELS; i++) {
		compare[i] = 0;
		compbuff[i] = 0;
	}
	
	// enable status LEDs and turn off
	ioport_set_pin_dir(LED_STATUS, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(LED_DATA, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(LED_STATUS, 1);
	ioport_set_pin_level(LED_DATA, 1);
	
	// enable interrupts and start timer for PWM
	cpu_irq_enable();
	tc45_write_clock_source(&TCC4, TC45_CLKSEL_DIV2_gc);	
}
/**
 * \brief This function configure and start timer1,which is TC4
 *  - Enable timer-1
 *  - Configure as pulse-width capture event action with event channel 1
 *    as event selection
 *  - Configure clock source as system clock with prescalar 1 and start on
 *    next event
 *  - Enable capture channel A
 */
void rtccalib_config_start_timer_one(void)
{
	/* Enable Timer-1 */
	tc45_enable(&TIMER1_FOR_CALIB);

	/* Configure event action as pulse-width capture with event channel 1
	 * as event selection */
	tc45_set_input_capture(&TIMER1_FOR_CALIB, TC45_EVSEL_CH1_gc,
			TC45_EVACT_PWF_gc);

	/* Configure timer-1 clock source */
	tc45_write_clock_source(&TIMER1_FOR_CALIB, TC45_CLKSEL_DIV1_gc);

	/* Configure to start on next event */
	tc45_set_evstart(&TIMER1_FOR_CALIB);

	/* Enable capture channel A */
	tc45_enable_cc_channels(&TIMER1_FOR_CALIB, TC45_CCACAPT);
}