Beispiel #1
0
void profile_timer_init(void){
	/* Initialize the HF clock if it is not already running*/
	hfclk_xtal_init();

    NRF_TIMER0->TASKS_STOP	   = 1;                    		// Stop timer.
	NRF_TIMER0->MODE           = TIMER_MODE_MODE_Timer;  	// Set the timer in Timer Mode.
	NRF_TIMER0->PRESCALER      = TIMER0_PRESCALER;			// Prescaler 0 produces 16 MHz.
	NRF_TIMER0->BITMODE        = TIMER0_BITSIZE;  			// 32 bit mode.
	NRF_TIMER0->TASKS_CLEAR    = 1;                         // clear the task first to be usable for later.

    NRF_TIMER0->TASKS_START   = 1;                    		// Start timer.
}
Beispiel #2
0
/* Initialize the RTIMER using TIMER0 */
void timer_init(void){
	/* Initialize the HF clock if it is not already running*/
	hfclk_xtal_init();

    NRF_TIMER0->TASKS_STOP	   = 1;                    		// Stop timer.
	NRF_TIMER0->MODE           = TIMER_MODE_MODE_Timer;  	// Set the timer in Timer Mode.
	NRF_TIMER0->PRESCALER      = TIMER_PRESCALER;			// Prescaler 0 produces 16 MHz.
	NRF_TIMER0->BITMODE        = TIMER_BITSIZE;  			// 32 bit mode.
	NRF_TIMER0->TASKS_CLEAR    = 1;                         // clear the task first to be usable for later.

/*	NRF_TIMER0->EVENTS_COMPARE[0]  = 0;

    NRF_TIMER0->CC[0]          = 128;

    // Enable overflow event and overflow interrupt:
    NRF_TIMER0->INTENSET      = TIMER_INTENSET_COMPARE0_Msk;

    NVIC_EnableIRQ(TIMER0_IRQn);    // Enable Interrupt for TIMER0 in the core. */

    NRF_TIMER0->TASKS_START   = 1;                    		// Start timer.
}
Beispiel #3
0
/** \brief Initialize the RTIMER using TIMER0.
* This function makes sure the high frequency clock is running,
* initializes TIMER0 based on the parameters defined in
* \ref nrf-rtimer-definitions "Macros for RTIMER using nrf51822"
* and initializes the compare 0 interrupt.
 */
void
rtimer_arch_init (void)
{
  /* Check if the HF clock is running*/
  if ((NRF_CLOCK->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) == 0)
    {
      hfclk_xtal_init ();
    }

  /* Clear the task to make sure the timer is stopped */
  NRF_TIMER0->TASKS_CLEAR = 1;
  /* Set the timer in Timer Mode */
  NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer;
  /* Prescaler 0 produces 16MHz timer tick frequency */
  NRF_TIMER0->PRESCALER = TIMER_PRESCALER;
  /* 32 bit mode */
  NRF_TIMER0->BITMODE = TIMER_BITSIZE;
  /* Enable the Compare event on 0th channel */
  NRF_TIMER0->EVENTS_COMPARE[0] = 0;

  /* Enable overflow event and overflow interrupt */
  NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Msk;

  /* Enable shorts for auto-reset
   *
   * This messes with the timestamping and RTIMER_NOW()
   * Maybe not particulary needed right now.
   *
   * */
  //NRF_TIMER0->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;

  NVIC_SetPriority (TIMER0_IRQn, TIMER0_IRQ_PRI);

  /* Start the timer */
  NRF_TIMER0->TASKS_START = 1;
}