Lesson 03 - Blinky Pro/blinky_pro.c
void OnReset(void)
{
    /* Initialize LED pin as output */
    NRF_P0->PIN_CNF[LED_PIN] =
          (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
        | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_PULL_Pos);


    /* Select 32kHz crystal oscillator as clock source for RTC */
    NRF_CLOCK->LFCLKSRC =
        (CLOCK_LFCLKSRCCOPY_SRC_Xtal << CLOCK_LFCLKSRCCOPY_SRC_Pos);
    /* Reset 'Started' event just in case */
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    /* Spin up the low frequency clock */ 
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    /* Wait till the clock sis started, can easily take 100's of ms */
    while(!NRF_CLOCK->EVENTS_LFCLKSTARTED);
    /* Acknowledge clock start event */
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;


    /* Setup RTC0 timer to trigger twice per second */
    NRF_RTC0->PRESCALER = 32768/2-1;
    /* Enable interrupt on every increment of the RTC timer */ 
    NRF_RTC0->INTENSET =
        (RTC_INTENSET_TICK_Enabled << RTC_INTENSET_TICK_Pos);
    /* Tell CPU NVIC to actually listen to that interrupt */
    NVIC_EnableIRQ(RTC0_IRQn);
    /* And start RTC0 counting */
    NRF_RTC0->TASKS_START = 1;


    /* Actually put the CPU sleeping while waiting for the timer */
    while(true)
        __WFE();
}
/* reset function called by CPU upon start */
reset function called by CPU upon start
reset function called by CPU upon start
void OnReset(void)
{
    NRF_P0->PIN_CNF[LED_PIN] =
          (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
        | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_PULL_Pos);
    NRF_CLOCK->LFCLKSRC =
        (CLOCK_LFCLKSRCCOPY_SRC_Xtal << CLOCK_LFCLKSRCCOPY_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(!NRF_CLOCK->EVENTS_LFCLKSTARTED);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_RTC0->PRESCALER = 32768/2-1;
    NRF_RTC0->INTENSET =
        (RTC_INTENSET_TICK_Enabled << RTC_INTENSET_TICK_Pos);
    NVIC_EnableIRQ(RTC0_IRQn);
    NRF_RTC0->TASKS_START = 1;
    while(true)
        __WFE();
}
void OnReset ( void ) { NRF_P0 -> PIN_CNF [ LED_PIN ] = ( GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos ) | ( GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_PULL_Pos ) ; NRF_CLOCK -> LFCLKSRC = ( CLOCK_LFCLKSRCCOPY_SRC_Xtal << CLOCK_LFCLKSRCCOPY_SRC_Pos ) ; NRF_CLOCK -> EVENTS_LFCLKSTARTED = 0 ; NRF_CLOCK -> TASKS_LFCLKSTART = 1 ; while ( ! NRF_CLOCK -> EVENTS_LFCLKSTARTED ) ; NRF_CLOCK -> EVENTS_LFCLKSTARTED = 0 ; NRF_RTC0 -> PRESCALER = 32768 / 2 - 1 ; NRF_RTC0 -> INTENSET = ( RTC_INTENSET_TICK_Enabled << RTC_INTENSET_TICK_Pos ) ; NVIC_EnableIRQ ( RTC0_IRQn ) ; NRF_RTC0 -> TASKS_START = 1 ; while ( true ) __WFE ( ) ; }
reset function called by CPU upon start
reset function called by CPU upon start
/* Initialize LED pin as output */ /* Select 32kHz crystal oscillator as clock source for RTC */ /* Reset 'Started' event just in case */ /* Spin up the low frequency clock */ /* Wait till the clock sis started, can easily take 100's of ms */ /* Acknowledge clock start event */ /* Setup RTC0 timer to trigger twice per second */ /* Enable interrupt on every increment of the RTC timer */ /* Tell CPU NVIC to actually listen to that interrupt */ /* And start RTC0 counting */ /* Actually put the CPU sleeping while waiting for the timer */