Ejemplo n.º 1
0
hvmm_status_t hvmm_tests_gic_pwm_timer(void)
{
    /* Testing pwm timer event (timer1, Interrupt ID : 69), Cortex-A15 exynos5250
	 * - Periodically triggers timer interrupt
     * - Just print uart_print
     */
	HVMM_TRACE_ENTER();
    pwm_timer_init();
    pwm_timer_set_callback(&interrupt_pwmtimer);
    pwm_timer_enable_int();
	HVMM_TRACE_EXIT();
	return HVMM_STATUS_SUCCESS;
}
Ejemplo n.º 2
0
int
up_pwm_servo_init(uint32_t channel_mask)
{
	/* do basic timer initialisation first */
	for (unsigned i = 0; i < PWM_SERVO_MAX_TIMERS; i++) {
		if (pwm_timers[i].base != 0)
			pwm_timer_init(i);
	}

	/* now init channels */
	for (unsigned i = 0; i < PWM_SERVO_MAX_CHANNELS; i++) {
		/* don't do init for disabled channels; this leaves the pin configs alone */
		if (((1 << i) & channel_mask) && (pwm_channels[i].timer_channel != 0))
			pwm_channel_init(i);
	}

	return OK;
}
Ejemplo n.º 3
0
int
pwm_servo_init(const struct pwm_servo_config *config)
{
	/* save a pointer to the configuration */
	cfg = config;

	/* do basic timer initialisation first */
	for (unsigned i = 0; i < PWM_SERVO_MAX_TIMERS; i++) {
		if (cfg->timers[i].base != 0)
			pwm_timer_init(i);
	}

	/* now init channels */
	for (unsigned i = 0; i < PWM_SERVO_MAX_CHANNELS; i++) {
		if (cfg->channels[i].gpio != 0)
			pwm_channel_init(i);
	}

	/* register the device */
	return register_driver("/dev/pwm_servo", &pwm_servo_fops, 0666, NULL);
}
Ejemplo n.º 4
0
/**
 * \brief Initializes the TC subsystem ready to generate a LED PWM wave.
 *
 * Initializes the on-chip TC module in PWM generation mode, and configures the
 * board LED as an output so that the LED brightness can be adjusted.
 */
static void pwm_timer_init(void)
{
	// Assign output pin to timer/counter 0 channel B
	gpio_enable_module_pin(AVR32_TC0_B0_0_0_PIN,
			AVR32_TC0_B0_0_0_FUNCTION);

	// Timer waveform options
	const tc_waveform_opt_t waveform_options = {
		//! Channel selection.
		.channel  = 0,

		//! Software trigger effect on TIOB.
		.bswtrg   = TC_EVT_EFFECT_NOOP,
		//! External event effect on TIOB.
		.beevt    = TC_EVT_EFFECT_NOOP,
		//! RC compare effect on TIOB.
		.bcpc     = TC_EVT_EFFECT_CLEAR,
		//! RB compare effect on TIOB.
		.bcpb     = TC_EVT_EFFECT_SET,

		//! Software trigger effect on TIOA.
		.aswtrg   = TC_EVT_EFFECT_NOOP,
		//! External event effect on TIOA.
		.aeevt    = TC_EVT_EFFECT_NOOP,
		//! RC compare effect on TIOA.
		.acpc     = TC_EVT_EFFECT_NOOP,
		//! RA compare effect on TIOA.
		.acpa     = TC_EVT_EFFECT_NOOP,

		//! Waveform selection
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		//! External event trigger enable.
		.enetrg   = false,
		//! External event selection (non-zero for Channel B to work)
		.eevt     = !0,
		//! External event edge selection.
		.eevtedg  = TC_SEL_NO_EDGE,
		//! Counter disable when RC compare.
		.cpcdis   = false,
		//! Counter clock stopped with RC compare.
		.cpcstop  = false,

		//! Burst signal selection.
		.burst    = false,
		//! Clock inversion selection.
		.clki     = false,
		//! Internal source clock 5, fPBA/128.
		.tcclks   = TC_CLOCK_SOURCE_TC5,
	};

	// Setup timer/counter waveform mode
	sysclk_enable_peripheral_clock(&AVR32_TC0);
	tc_init_waveform(&AVR32_TC0, &waveform_options);

	// Write the TOP (RC) and COMPARE (RB) values
	tc_write_rb(&AVR32_TC0, 0, 1);   // Set RB value.
	tc_write_rc(&AVR32_TC0, 0, 255); // Set RC value.

	// Start the timer PWM channel
	tc_start(&AVR32_TC0, 0);
}

/**
 * \brief Application main routine
 */
int main(void)
{
	board_init();
	sysclk_init();

	irq_initialize_vectors();
	cpu_irq_enable();

	pwm_timer_init();
	touch_init();

	while (true) {
		touch_handler();
	}
}
Ejemplo n.º 5
0
int main()
{
	seed_rand();
	setup_mcu();
	led_driver_init();
	pwm_timer_init();
	pir_init();
	
	// the PIR sensor takes a few seconds
	_delay_ms(5000);
	
	sei();
	
	uint8_t lower_pwm= 1;
	uint8_t upper_pwm= 70;
	uint8_t base_delay_interval= 10;
	
	while(1)
	{
		while( !(PIND && PD2) );
		
		uint8_t pins[4]= { PB1, PB2, PB3, PB4 };
		uint8_t pin_starts[4];
		uint8_t pin_pwm[4];
		uint16_t delay_count= 0;
		uint8_t still_fading= 1;
			
		for( uint8_t i= 0; i < 4; ++i )
		{
			// number of base_delay_interval intervals to wait before lighting them up
			pin_starts[i]= range_rand(50);
			pin_pwm[i]= lower_pwm;
		}
			
		// fade them up
		delay_count= 0;
		still_fading= 1;
		while( still_fading )
		{
			still_fading= 0;
				
			for( uint8_t i= 0; i < 4; ++i )
			{
				if( delay_count >= pin_starts[i] && pin_pwm[i] < upper_pwm )
				{
					pin_pwm[i]++;
					start_pwm( pins[i], pin_pwm[i] );
				}
					
				if( pin_pwm[i] < upper_pwm )
					still_fading= 1;
			}
				
			_delay_ms( base_delay_interval );
			delay_count++;
		}
			
		// wait for no more motion for 5 seconds
		delay_count= 0;
		while( delay_count < (5000/base_delay_interval) )
		{
			if( PIND && PD2 )
			{
				delay_count= 0;
				continue;
			}
			
			_delay_ms( base_delay_interval );
			delay_count++;
		}
		
		// fade them off
		for( uint8_t i= 0; i < 4; ++i )
		{
			// number of base_delay_interval intervals to wait before shutting them down
			pin_starts[i]= range_rand(60);
			pin_pwm[i]= upper_pwm;
		}
		
		delay_count= 0;
		still_fading= 1;
		while( still_fading )
		{
			still_fading= 0;
			
			for( uint8_t i= 0; i < 4; ++i )
			{
				if( delay_count >= pin_starts[i] )
				{
					if( pin_pwm[i] > lower_pwm )
					{
						pin_pwm[i]--;
					
						start_pwm( pins[i], pin_pwm[i] );
					}
					
					if( pin_pwm[i] <= lower_pwm )
						stop_pwm( pins[i] );
				}
				
				if( pin_pwm[i] > lower_pwm )
					still_fading= 1;
			}
			
			_delay_ms( base_delay_interval );
			delay_count++;
		}
		
		_delay_ms(2000);
	}
	
	return 0;
}
Ejemplo n.º 6
0
void pwm_init(pwm_callback update_callback) {
  pwm_timer_init(update_callback);
  pwm_gpio_init();
}