Ejemplo n.º 1
0
uint32_t nrf_drv_ppi_channel_alloc(nrf_ppi_channel_t * p_channel)
{
    uint32_t err_code;
    nrf_ppi_channel_t channel;
    uint32_t mask = 0;

    err_code = NRF_ERROR_NO_MEM;

    mask = NRF_PPI_PROG_APP_CHANNELS_MASK;
    for (channel = NRF_PPI_CHANNEL0; mask != 0; mask &= ~nrf_drv_ppi_channel_to_mask(channel), channel++)
    {
        CRITICAL_REGION_ENTER();
        if ((mask & nrf_drv_ppi_channel_to_mask(channel)) && (!is_allocated_channel(channel)))
        {
            channel_allocated_set(channel);
            *p_channel = channel;
            err_code   = NRF_SUCCESS;
        }
        CRITICAL_REGION_EXIT();
        if (err_code == NRF_SUCCESS)
        {
            break;
        }
    }

    return err_code;
}
Ejemplo n.º 2
0
uint32_t nrf_drv_ppi_channel_alloc(nrf_ppi_channel_t * p_channel)
{
    uint32_t err_code = NRF_SUCCESS;
    nrf_ppi_channel_t channel;
    uint32_t mask = 0;

    err_code = NRF_ERROR_NO_MEM;

    mask = NRF_PPI_PROG_APP_CHANNELS_MASK;
    for (channel = NRF_PPI_CHANNEL0; mask != 0; mask &= ~nrf_drv_ppi_channel_to_mask(channel), channel++)
    {
        CRITICAL_REGION_ENTER();
        if ((mask & nrf_drv_ppi_channel_to_mask(channel)) && (!is_allocated_channel(channel)))
        {
            channel_allocated_set(channel);
            *p_channel = channel;
            err_code   = NRF_SUCCESS;
        }
        CRITICAL_REGION_EXIT();
        if (err_code == NRF_SUCCESS)
        {
            NRF_LOG_INFO("Allocated channel: %d.\r\n", channel);
            break;
        }
    }

    NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code));
    return err_code;
}
Ejemplo n.º 3
0
uint32_t nrf_drv_ppi_channel_disable(nrf_ppi_channel_t channel)
{
    uint32_t err_code;

    if (!is_app_channel(channel))
    {
        err_code = NRF_ERROR_INVALID_PARAM;
    }
    else if (is_programmable_app_channel(channel) && !is_allocated_channel(channel))
    {
        err_code = NRF_ERROR_INVALID_STATE;
    }
    else
    {
#if (NRF_PPI_RESTRICTED > 0)
        err_code = sd_ppi_channel_enable_clr(nrf_drv_ppi_channel_to_mask(channel));
#else
        nrf_ppi_channel_disable(channel);
        err_code = NRF_SUCCESS;
#endif
    }

    return err_code;
}
Ejemplo n.º 4
0
uint32_t nrf_drv_ppi_channel_free(nrf_ppi_channel_t channel)
{
    uint32_t err_code;

    if (!is_programmable_app_channel(channel))
    {
        err_code = NRF_ERROR_INVALID_PARAM;
    }
    else
    {
        // First disable this channel
#if (NRF_PPI_RESTRICTED > 0)
        err_code = sd_ppi_channel_enable_clr(nrf_drv_ppi_channel_to_mask(channel));
#else
        nrf_ppi_channel_disable(channel);
        err_code = NRF_SUCCESS;
#endif
        CRITICAL_REGION_ENTER();
        channel_allocated_clr(channel);
        CRITICAL_REGION_EXIT();
    }

    return err_code;
}
Ejemplo n.º 5
0
/**@brief  Check whether a channel is a programmable channel and can be used by an application.
 * @param[in]  channel  Channel to check.
 * @retval     true     The channel is a programmable application channel.
 *             false    The channel is used by a SoftDevice or is preprogrammed.
 */
__STATIC_INLINE bool is_programmable_app_channel(nrf_ppi_channel_t channel)
{
    return ((NRF_PPI_PROG_APP_CHANNELS_MASK & nrf_drv_ppi_channel_to_mask(channel)) != 0);
}
Ejemplo n.º 6
0
/**@brief  Set channel allocated indication.
 * @param[in]  channel_num  Specifies the channel to set the "allocated" indication.
 */
__STATIC_INLINE void channel_allocated_set(nrf_ppi_channel_t channel)
{
    m_channels_allocated |= nrf_drv_ppi_channel_to_mask(channel);
}
Ejemplo n.º 7
0
/**@brief  Check whether a channel is allocated.
 * @param[in]  channel_num  Channel number to check.
 * @retval     true         The channel is allocated.
 *             false        The channel is not allocated.
 */
__STATIC_INLINE bool is_allocated_channel(nrf_ppi_channel_t channel)
{
    return ((m_channels_allocated & nrf_drv_ppi_channel_to_mask(channel)) != 0);
}
Ejemplo n.º 8
0
/**@brief  Check whether a channel can be used by an application.
 * @param[in]  channel  Channel to check.
 * @retval     true     The channel can be used by an application.
 *             false    The channel is used by a SoftDevice.
 */
__STATIC_INLINE bool is_app_channel(nrf_ppi_channel_t channel)
{
    return are_app_channels(nrf_drv_ppi_channel_to_mask(channel));
}