Esempio n. 1
0
static void timer2_setup ( void ) {

  //timer_reset ( TIM2 );
  //timer_set_mode
  //timer_continuous_mode ( TIM2 );

  /* Set timer start value. */
  TIM_CNT(TIM2) = 1;

  /* Set timer prescaler. 72MHz/1440 => 50000 counts per second. */
  TIM_PSC(TIM2) = 300; // 280K/s or 0.000 003 571

  /* End timer value. If this is reached an interrupt is generated. */
  TIM_ARR(TIM2) = 8; //

  // o-scope reports:
  // prescale 2000, 1->600 should be 100/sec; in fact, we're exactly 20ms between which is exactly 50 .. so callback is 60MHz, not 120MHz
  // manual says:
  //  The reference manual (see page 133) states that the GPIO is capable of:
  //  Fast toggle capable of changing every two clock cycles
  // --> okay so at 120MHz, the best we can do is 60MHz of GPIO. But thats different than here, where the timer seems halved..

  /* Update interrupt enable. */
  TIM_DIER(TIM2) |= TIM_DIER_UIE;

  //timer_set_repetition_counter ( TIM2, 100 );

  /* Start timer. */
  TIM_CR1(TIM2) |= TIM_CR1_CEN;

  return;
}
Esempio n. 2
0
int main(void)
{
        rcc_clock_setup_in_hse_16mhz_out_72mhz();
	gpio_setup();
	nvic_setup();

	gpio_clear(GPIOB, GPIO7);	/* LED1 on */
	gpio_set(GPIOB, GPIO6);		/* LED2 off */
	
	rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN);

	/* the goal is to let the LED2 glow for a second and then be off for a second */	

	/* Set timer start value */
	TIM_CNT(TIM2) = 1;

	/* Set timer prescaler. 72MHz/1440 => 50000 counts per second */
	TIM_PSC(TIM2) = 1440;

	/* End timer value. If this value is reached an interrupt is generated */
	TIM_ARR(TIM2) = 50000;

	/* Update interrupt enable */
	TIM_DIER(TIM2) |= TIM_DIER_UIE;

	/* Start timer */
	TIM_CR1(TIM2) |= TIM_CR1_CEN;

	while(1); /* Halt. */

	return 0;
}
Esempio n. 3
0
bool timer_get_flag(u32 timer_peripheral, u32 flag)
{
	if (((TIM_SR(timer_peripheral) & flag) != 0) &&
	    ((TIM_DIER(timer_peripheral) & flag) != 0)) {
		return true;
	}

	return false;
}
Esempio n. 4
0
/**
 * @brief Initializes the AEAT9000 SSI Link
 * @param u16 clk_speed SSI Clock Speed in 100bps LSB units
 */
void ssi_initialize(u16 clk_speed)
{
	rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN); // Initialize timer clk
	// Initialize I/O Pins
	gpio_set_mode(SSI_GPIO, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, SSI_CLK_PIN);
	gpio_set_mode(SSI_GPIO, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, SSI_DATA_PIN);
	gpio_set_mode(SSI_GPIO, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, SSI_NCS_PIN);
	// Initialize clock timer on TIM1
	TIM_DIER(SSI_TIMER) = TIM_DIER_UIE;
	TIM_PSC(SSI_TIMER) = 1; // 24MHz Clock
	TIM_ARR(SSI_TIMER) = TIMER_MAX; // Update at 500kHz
	// Initialize NVIC
	nvic_enable_irq(NVIC_TIM2_IRQ);
	nvic_set_priority(NVIC_TIM2_IRQ, 1);
	ssi_state = SSI_IDLE;
	ssi_data_ready_flag = false;
}
Esempio n. 5
0
void timer_enable_irq(u32 timer_peripheral, u32 irq)
{
	TIM_DIER(timer_peripheral) |= irq;
}
Esempio n. 6
0
void timer_disable_irq(u32 timer_peripheral, u32 irq)
{
	TIM_DIER(timer_peripheral) &= ~irq;
}