Example #1
0
int
ble_hs_locked_by_cur_task(void)
{
    struct os_task *owner;

#if BLE_HS_DEBUG
    if (!os_started()) {
        return ble_hs_dbg_mutex_locked;
    }
#endif

    owner = ble_hs_mutex.mu_owner;
    return owner != NULL && owner == os_sched_get_current_task();
}
/**
 * Close the STM32F4 ADC device.
 *
 * This function unlocks the device.
 *
 * @param odev The device to close.
 */
static int
stm32f4_adc_close(struct os_dev *odev)
{
    struct adc_dev *dev;

    dev = (struct adc_dev *) odev;

    stm32f4_adc_uninit(dev);

    if (os_started()) {
        os_mutex_release(&dev->ad_lock);
    }

    return (OS_OK);
}
Example #3
0
void
ble_hs_unlock(void)
{
    int rc;

#if BLE_HS_DEBUG
    if (!os_started()) {
        BLE_HS_DBG_ASSERT(ble_hs_dbg_mutex_locked);
        ble_hs_dbg_mutex_locked = 0;
        return;
    }
#endif

    rc = os_mutex_release(&ble_hs_mutex);
    BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
Example #4
0
void
ble_hs_lock(void)
{
    int rc;

    BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());

#if BLE_HS_DEBUG
    if (!os_started()) {
        ble_hs_dbg_mutex_locked = 1;
        return;
    }
#endif

    rc = os_mutex_pend(&ble_hs_mutex, 0xffffffff);
    BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
/**
 * Close the NRF52 ADC device.
 *
 * This function unlocks the device.
 *
 * @param odev The device to close.
 */
static int
nrf52_adc_close(struct os_dev *odev)
{
    struct adc_dev *dev;

    dev = (struct adc_dev *) odev;

    nrfx_saadc_uninit();

    global_adc_dev = NULL;
    global_adc_config = NULL;

    if (os_started()) {
        os_mutex_release(&dev->ad_lock);
    }

    return (0);
}
Example #6
0
int 
cbmem_lock_release(struct cbmem *cbmem)
{
    int rc;

    if (!os_started()) {
        return (0);
    }

    rc = os_mutex_release(&cbmem->c_lock);
    if (rc != 0) {
        goto err;
    }

    return (0);
err:
    return (rc);
}
Example #7
0
int 
cbmem_lock_acquire(struct cbmem *cbmem) 
{
    int rc;

    if (!os_started()) {
        return (0);
    }

    rc = os_mutex_pend(&cbmem->c_lock, OS_WAIT_FOREVER);
    if (rc != 0) {
        goto err;
    }

    return (0);
err:
    return (rc);
}
static void
console_queue_char(char ch)
{
    struct console_tty *ct = &console_tty;
    int sr;

    OS_ENTER_CRITICAL(sr);
    while (CONSOLE_HEAD_INC(&ct->ct_tx) == ct->ct_tx.cr_tail) {
        /* TX needs to drain */
        hal_uart_start_tx(CONSOLE_UART);
        OS_EXIT_CRITICAL(sr);
	if (os_started()) {
            os_time_delay(1);
	}
        OS_ENTER_CRITICAL(sr);
    }
    console_add_char(&ct->ct_tx, ch);
    OS_EXIT_CRITICAL(sr);
}
/**
 * Open the NRF52 ADC device
 *
 * This function locks the device for access from other tasks.
 *
 * @param odev The OS device to open
 * @param wait The time in MS to wait.  If 0 specified, returns immediately
 *             if resource unavailable.  If OS_WAIT_FOREVER specified, blocks
 *             until resource is available.
 * @param arg  Argument provided by higher layer to open, in this case
 *             it can be a nrfx_saadc_config_t, to override the default
 *             configuration.
 *
 * @return 0 on success, non-zero on failure.
 */
static int
nrf52_adc_open(struct os_dev *odev, uint32_t wait, void *arg)
{
    struct adc_dev *dev;
    struct nrf52_adc_dev_cfg *cfg = arg;
    int rc;

    dev = (struct adc_dev *) odev;

    if (os_started()) {
        rc = os_mutex_pend(&dev->ad_lock, wait);
        if (rc != OS_OK) {
            goto err;
        }
    }

    if (odev->od_flags & OS_DEV_F_STATUS_OPEN) {
        os_mutex_release(&dev->ad_lock);
        rc = OS_EBUSY;
        goto err;
    }

    /* If user did not provide config let us use init */
    if (!cfg) {
        cfg = init_adc_config;
    }

    /* Initialize the device */
    rc = nrfx_saadc_init(&cfg->saadc_cfg, nrf52_saadc_event_handler);
    if (rc != NRFX_SUCCESS) {
        goto err;
    }

    global_adc_dev = dev;
    global_adc_config = arg;

    return (0);
err:
    return (rc);
}
/**
 * Open the STM32F4 ADC device
 *
 * This function locks the device for access from other tasks.
 *
 * @param odev The OS device to open
 * @param wait The time in MS to wait.  If 0 specified, returns immediately
 *             if resource unavailable.  If OS_WAIT_FOREVER specified, blocks
 *             until resource is available.
 * @param arg  Argument provided by higher layer to open.
 *
 * @return 0 on success, non-zero on failure.
 */
static int
stm32f4_adc_open(struct os_dev *odev, uint32_t wait, void *arg)
{
    DMA_HandleTypeDef *hdma;
    ADC_HandleTypeDef *hadc;
    struct stm32f4_adc_dev_cfg *cfg;
    struct adc_dev *dev;
    int rc;

    assert(odev);
    rc = OS_OK;
    dev = (struct adc_dev *) odev;

    if (os_started()) {
        rc = os_mutex_pend(&dev->ad_lock, wait);
        if (rc != OS_OK) {
            goto err;
        }
    }

    if (odev->od_flags & OS_DEV_F_STATUS_OPEN) {
        os_mutex_release(&dev->ad_lock);
        rc = OS_EBUSY;
        goto err;
    }

    stm32f4_adc_init(dev);

    cfg  = (struct stm32f4_adc_dev_cfg *)dev->ad_dev.od_init_arg;
    hadc = cfg->sac_adc_handle;
    hdma = hadc->DMA_Handle;

    adc_dma[stm32f4_resolve_dma_handle_idx(hdma)] = dev;

    return (OS_OK);
err:
    return (rc);
}
Example #11
0
int
ble_hs_thread_safe(void)
{
    return !os_started() || ble_hs_locked_by_cur_task();
}
Example #12
0
/**
 * Indicates whether the host's parent task is currently running.
 */
int
ble_hs_is_parent_task(void)
{
    return !os_started() || os_sched_get_current_task() == ble_hs_parent_task;
}