This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Semaphore implementation for the Radio

Dear Nordic developers,

In my project there is a possibility that CPU and RADIO EasyDMA peripheral can access to the same memory RAM locations in parallel. I read from the manual that RADIO EasyDMA unit is accessing to a RAM location between READY and DISABLED radio events.

Is there any mechanism like semaphore hardware unit SPIS to prevent simultaneous access to a specified RAM location. I don't want to copy memory locations, beacause of my timing requirements.

I'd really appreciate any advice.

Best regards, Harut

Parents
  • I think you can implement your own MUTual EXclusion semaphore and change the micro lib library where RADIO transaction is enabled to fetch this mutex first.

    uint32_t mutex_acquire(uint8_t * p_mutex)
    {
      bool success;
      int irq_was_masked;
      
      /* Disable Interrupts if not */
      irq_was_masked = __disable_irq(); 
    
      success = (*p_mutex != MUTEX_TAKEN);
      *p_mutex = MUTEX_TAKEN;
      
      /* Enable Interrupts if disabled by this function */
      if (!irq_was_masked)
      {
        __enable_irq();
      }
      
      if (success)
      {
        return UESB_SUCCESS;
      }
      else
      {
        return UESB_MUTEX_ALREADY_TAKEN_ERROR;
      }  
    }
    
    uint32_t mutex_release(uint8_t * p_mutex)
    {
      int irq_was_masked;
    
      /* Disable Interrupts if not */
      irq_was_masked = __disable_irq(); 
    
      *p_mutex = MUTEX_FREE;
    
      /* Enable Interrupts if disabled by this function */
      if (!irq_was_masked)
      {
        __enable_irq();
      }
      
      return UESB_SUCCESS;
    }
    

    Keep in mind the possibility of a deadlock as mentioned here which you need to handle.

Reply
  • I think you can implement your own MUTual EXclusion semaphore and change the micro lib library where RADIO transaction is enabled to fetch this mutex first.

    uint32_t mutex_acquire(uint8_t * p_mutex)
    {
      bool success;
      int irq_was_masked;
      
      /* Disable Interrupts if not */
      irq_was_masked = __disable_irq(); 
    
      success = (*p_mutex != MUTEX_TAKEN);
      *p_mutex = MUTEX_TAKEN;
      
      /* Enable Interrupts if disabled by this function */
      if (!irq_was_masked)
      {
        __enable_irq();
      }
      
      if (success)
      {
        return UESB_SUCCESS;
      }
      else
      {
        return UESB_MUTEX_ALREADY_TAKEN_ERROR;
      }  
    }
    
    uint32_t mutex_release(uint8_t * p_mutex)
    {
      int irq_was_masked;
    
      /* Disable Interrupts if not */
      irq_was_masked = __disable_irq(); 
    
      *p_mutex = MUTEX_FREE;
    
      /* Enable Interrupts if disabled by this function */
      if (!irq_was_masked)
      {
        __enable_irq();
      }
      
      return UESB_SUCCESS;
    }
    

    Keep in mind the possibility of a deadlock as mentioned here which you need to handle.

Children
No Data
Related