This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Migration to SD functions

I have to update my non soft device source code to SD because now I will use Radio.

My question is if it is necessary to rewrite all functions which are in SD API. Like:

NVIC_SetPriority(ADC_IRQn, APP_IRQ_PRIORITY_LOW);
NVIC_ClearPendingIRQ(ADC_IRQn);
NVIC_EnableIRQ(ADC_IRQn);
NRF_POWER->SYSTEMOFF = 1;	
NRF_CLOCK->TASKS_HFCLKSTART = 1;
NRF_RTC1->EVENTS_COMPARE[0] = 0;
__WFI();
__WFE();
and similiar

I'm assume that SD alternate function has just some assert to control if I'm passing right arguments or so. So if I'm sure I didn't use any resources against SD, is it necessary to use strictly only SD functions?

  • Don't quite understood the problem, can you give an example?

  • Sample code for that:

    void RTC1_IRQHandler(void)	/*lint !e765 !e714 */
    {  
    	/* Every 1ms */
    	if (NRF_RTC1->EVENTS_COMPARE[0] != 0)
      {
    		NRF_RTC1->EVENTS_COMPARE[0] = 0;
    		NRF_RTC1->TASKS_CLEAR = 1;  // Clear Counter		    
    				    
        flag_ms = 1;
        /* to avoid race condition */
    		__SEV(); /*lint !e718 !e746 */  // it's in assembler
      }
    }
    
    
    volatile u8 flag_ms=0;
    
    for(;;){
      while(flag_ms == 0) V_hw_WFE(); 
      flag_ms=0;
    }
    
    
    
    void V_hw_WFE(void)
    {
    	#ifdef NO_SD
    		__WFE();
    	#else     
    		(void)sd_app_evt_wait();	
    	#endif
    }
    

    BTW sd_app_evt_wait() automatically go to sleep mode until event will occure?

  • You don't need __SEV() with sd_app_evt_wait(), read its description:

    If an application interrupt has happened since the last time sd_app_evt_wait was called this function will return immediately and not go to sleep. This is to avoid race conditions that can occur when a flag is updated in the interrupt handler and processed in the main loop.

    BTW sd_app_evt_wait() automatically go to sleep mode until event will occure?

    Yes.

  • OK I was not sure about behaviour when IRQ will occure in this time sequence: while(flag_ms == 0) , IRQ Handler process , sd_app_evt_wait(). Meaning when IRQ occurs after flag was checked and before sd_app_evt_wait() is called again, not when it was already called.

Related