<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Timeslot / Radio signal callback hander sometimes called with 10us delay</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/58879/timeslot-radio-signal-callback-hander-sometimes-called-with-10us-delay</link><description>In a project based on Softdevice S132 7.0.1 employing the Softdevice timeslot API, I noticed that the nrf_radio_signal_callback_t function passed into sd_radio_session_open() sometimes seems to be invoked with a 10us delay compared to other occasions</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Mar 2020 14:23:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/58879/timeslot-radio-signal-callback-hander-sometimes-called-with-10us-delay" /><item><title>RE: Timeslot / Radio signal callback hander sometimes called with 10us delay</title><link>https://devzone.nordicsemi.com/thread/239364?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2020 14:23:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2bc6635-15f4-4507-8e44-d202ab719826</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Okay, perfect, thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timeslot / Radio signal callback hander sometimes called with 10us delay</title><link>https://devzone.nordicsemi.com/thread/239350?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2020 13:43:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a06e200-34ca-4458-a7f6-cda0b8ea8b29</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;If you use timeslot, it for sure will cause more latency as the interrupt will get to the softdevice first, after that be forwarded to the timeslot event.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;1us when using bare metal is more reasonable. It can be varied a bit chip to chip and by the sample rate + accuracy of logic analyzer. In my case it&amp;#39;s about 450ns.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timeslot / Radio signal callback hander sometimes called with 10us delay</title><link>https://devzone.nordicsemi.com/thread/239258?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2020 07:54:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d71a0fff-559c-4b00-af9d-d818c51a058f</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Hi Hung Bui,&lt;/p&gt;
&lt;p&gt;Thanks for your response. The wakeup from system ON IDLE indeed seems to be the cause for this!&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/58879/timeslot-radio-signal-callback-hander-sometimes-called-with-10us-delay/239155"]But 3.5 us is a little bit long from my experience.&amp;nbsp;[/quote]
&lt;p&gt;The above measurements were made in a timeslot based application and the delay is between the peripheral event and the invocation of the signal handler by the softdevice. I assume this brings some additional latency and could explain this discrepanc, couldn&amp;#39;t it?&lt;/p&gt;
&lt;p&gt;With a &amp;quot;bare metal&amp;quot; application, I measure about 1us from the peripheral event to the pin being set in the interrupt handler. Is that reasonable?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timeslot / Radio signal callback hander sometimes called with 10us delay</title><link>https://devzone.nordicsemi.com/thread/239155?ContentTypeID=1</link><pubDate>Tue, 10 Mar 2020 14:12:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a68fa60-6f33-4b8e-8845-d9b23dd3dd7f</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Michael,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The 10us delay extra is most likely the time it take for the CPU to wake up from system ON IDLE. Did you put the CPU to sleep (IDLE) ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When the debugger is connected the CPU is kept running all the time (including the HFCLK). This explain why you have shorter latency.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But 3.5 us is a little bit long from my experience.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I was using the following code and can see 0.5us latency if I don&amp;#39;t put the CPU to sleep about 11.8us if I put the CPU to sleep (with the __WFE and __SEV).&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;nrf.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#define PPI_CHANNEL (0)
#define PIN_GPIO    (17)
#define PIN_GPIO2    (18)
void RADIO_IRQHandler(void)
{
    if (NRF_RADIO-&amp;gt;EVENTS_DISABLED)
    {
        NRF_GPIO-&amp;gt;OUTCLR = (1UL &amp;lt;&amp;lt; PIN_GPIO2);  
        NRF_RADIO-&amp;gt;EVENTS_DISABLED=0;
    }
  /*  if (NRF_RADIO-&amp;gt;EVENTS_READY )
    {
        NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; PIN_GPIO2);  
        NRF_RADIO-&amp;gt;EVENTS_READY=0;
     }
    */

 }
int main(void)
{
  // Packet to send
  uint8_t packet[16] = &amp;quot;demopacket&amp;quot;;
  
  // Start HFCLK from crystal oscillator. The radio needs crystal to function correctly.
  NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
  while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);
  
  // Configure radio with 2Mbit Nordic proprietary mode
  NRF_RADIO-&amp;gt;MODE = RADIO_MODE_MODE_Nrf_2Mbit &amp;lt;&amp;lt; RADIO_MODE_MODE_Pos;
  
  // Configure packet with no S0,S1 or Length fields and 8-bit preamble.
  NRF_RADIO-&amp;gt;PCNF0 = (0 &amp;lt;&amp;lt; RADIO_PCNF0_LFLEN_Pos) |
                     (0 &amp;lt;&amp;lt; RADIO_PCNF0_S0LEN_Pos) |
                     (0 &amp;lt;&amp;lt; RADIO_PCNF0_S1LEN_Pos) | 
                     (RADIO_PCNF0_S1INCL_Automatic &amp;lt;&amp;lt; RADIO_PCNF0_S1INCL_Pos) |
                     (RADIO_PCNF0_PLEN_8bit &amp;lt;&amp;lt; RADIO_PCNF0_PLEN_Pos);
  
  // Configure static payload length of 16 bytes. 3 bytes address, little endian with whitening enabled.
  NRF_RADIO-&amp;gt;PCNF1 =  (16 &amp;lt;&amp;lt; RADIO_PCNF1_MAXLEN_Pos) |
                      (16 &amp;lt;&amp;lt; RADIO_PCNF1_STATLEN_Pos) |
                      (2  &amp;lt;&amp;lt; RADIO_PCNF1_BALEN_Pos) | 
                      (RADIO_PCNF1_ENDIAN_Little &amp;lt;&amp;lt; RADIO_PCNF1_ENDIAN_Pos) |
                      (RADIO_PCNF1_WHITEEN_Enabled &amp;lt;&amp;lt; RADIO_PCNF1_WHITEEN_Pos);
  
  // initialize whitening value
  NRF_RADIO-&amp;gt;DATAWHITEIV = 0x55;
  
  // Configure address Prefix0 + Base0
  NRF_RADIO-&amp;gt;BASE0   = 0x0000BABE;
  NRF_RADIO-&amp;gt;PREFIX0 = 0x41 &amp;lt;&amp;lt; RADIO_PREFIX0_AP0_Pos;
  
  // Use logical address 0 (BASE0 + PREFIX0 byte 0)
  NRF_RADIO-&amp;gt;TXADDRESS = 0 &amp;lt;&amp;lt; RADIO_TXADDRESS_TXADDRESS_Pos;
  
  // Initialize CRC (two bytes)
  NRF_RADIO-&amp;gt;CRCCNF = (RADIO_CRCCNF_LEN_Two &amp;lt;&amp;lt; RADIO_CRCCNF_LEN_Pos) |
                      (RADIO_CRCCNF_SKIPADDR_Skip &amp;lt;&amp;lt; RADIO_CRCCNF_SKIPADDR_Pos);
  NRF_RADIO-&amp;gt;CRCPOLY = 0x0000AAAA;
  NRF_RADIO-&amp;gt;CRCINIT = 0x12345678;
  
  // Enable fast rampup, new in nRF52
  NRF_RADIO-&amp;gt;MODECNF0 = (RADIO_MODECNF0_DTX_B0 &amp;lt;&amp;lt; RADIO_MODECNF0_DTX_Pos) |
                        (RADIO_MODECNF0_RU_Fast &amp;lt;&amp;lt; RADIO_MODECNF0_RU_Pos);
                        
  // 0dBm output power, sending packets at 2400MHz
  NRF_RADIO-&amp;gt;TXPOWER = RADIO_TXPOWER_TXPOWER_0dBm &amp;lt;&amp;lt; RADIO_TXPOWER_TXPOWER_Pos;
  NRF_RADIO-&amp;gt;FREQUENCY = 0 &amp;lt;&amp;lt; RADIO_FREQUENCY_FREQUENCY_Pos;
  
  // Configure address of the packet and logic address to use
  NRF_RADIO-&amp;gt;PACKETPTR = (uint32_t)&amp;amp;packet[0];
  
  // Configure shortcuts to start as soon as READY event is received, and disable radio as soon as packet is sent.
  NRF_RADIO-&amp;gt;SHORTS = (RADIO_SHORTS_READY_START_Enabled &amp;lt;&amp;lt; RADIO_SHORTS_READY_START_Pos) |
                      (RADIO_SHORTS_END_DISABLE_Enabled &amp;lt;&amp;lt; RADIO_SHORTS_END_DISABLE_Pos);
                      
                      
  NRF_GPIO-&amp;gt;DIRSET = (1UL &amp;lt;&amp;lt; PIN_GPIO);
  
  // Configure GPIOTE-&amp;gt;TASKS_OUT[0] to toggle PIN_GPIO
  NRF_GPIOTE-&amp;gt;CONFIG[0] = (GPIOTE_CONFIG_MODE_Task       &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos) |
                          (GPIOTE_CONFIG_OUTINIT_Low     &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos) |
                          (GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos) |
                          (PIN_GPIO                      &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos);   

  NRF_GPIO-&amp;gt;DIRSET = NRF_GPIO-&amp;gt;DIRSET|1UL &amp;lt;&amp;lt; PIN_GPIO2;
  NRF_GPIO-&amp;gt;PIN_CNF[PIN_GPIO2] = (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos) |
                                (GPIO_PIN_CNF_DRIVE_S0S1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos) |
                                (GPIO_PIN_CNF_INPUT_Connect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos) |
                                (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos) |
                                (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos);
  // Configure GPIOTE-&amp;gt;TASKS_OUT[0] to toggle PIN_GPIO
  
  NRF_PPI-&amp;gt;CH[PPI_CHANNEL].EEP = (uint32_t)&amp;amp;NRF_RADIO-&amp;gt;EVENTS_DISABLED ;
  NRF_PPI-&amp;gt;CH[PPI_CHANNEL].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0];
  
  // Enable PPI channel
  NRF_PPI-&amp;gt;CHENSET = (1UL &amp;lt;&amp;lt; PPI_CHANNEL);
  
  NVIC_ClearPendingIRQ(RADIO_IRQn);
  NVIC_EnableIRQ(RADIO_IRQn);  
  NRF_RADIO-&amp;gt;INTENSET      = RADIO_INTENSET_DISABLED_Msk;    

  // Continuously send the same packet
  while (1)
  { 
    NRF_RADIO-&amp;gt;TASKS_TXEN = 1;
    NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; PIN_GPIO2);  
    /*__SEV();
    __WFE();
    __WFE();*/
    
    nrf_delay_ms(500);
  }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>