static void init_tx_queue(void) { nano_fifo_init(&netdev.tx_queue); fiber_start(tx_fiber_stack, sizeof(tx_fiber_stack), (nano_fiber_entry_t) net_tx_fiber, 0, 0, 7, 0); }
static void fiber_cond_basic() { struct fiber_cond *cond = fiber_cond_new(); int check = 0; struct fiber *f1 = fiber_new("f1", fiber_cond_basic_f); assert(f1 != NULL); fiber_start(f1, cond, &check); fiber_set_joinable(f1, true); struct fiber *f2 = fiber_new("f2", fiber_cond_basic_f); assert(f2 != NULL); fiber_start(f2, cond, &check); fiber_set_joinable(f2, true); /* check timeout */ fiber_sleep(0.0); fiber_sleep(0.0); /* Wake up the first fiber */ fiber_cond_signal(cond); fiber_sleep(0.0); /* Wake ip the second fiber */ fiber_cond_signal(cond); fiber_sleep(0.0); /* Check that fiber scheduling is fair */ is(check, 2, "order"); fiber_cond_broadcast(cond); fiber_sleep(0.0); fiber_join(f1); fiber_join(f2); fiber_cond_delete(cond); }
static void h5_init(void) { BT_DBG(""); h5.link_state = UNINIT; h5.rx_state = START; h5.tx_win = 4; /* TX fiber */ nano_fifo_init(&h5.tx_queue); fiber_start(tx_stack, sizeof(tx_stack), (nano_fiber_entry_t)tx_fiber, 0, 0, 7, 0); /* RX fiber */ net_buf_pool_init(signal_pool); nano_fifo_init(&h5.rx_queue); fiber_start(rx_stack, sizeof(rx_stack), (nano_fiber_entry_t)rx_fiber, 0, 0, 7, 0); /* Unack queue */ nano_fifo_init(&h5.unack_queue); }
int tmp007_init_interrupt(struct device *dev) { struct tmp007_data *drv_data = dev->driver_data; int rc; rc = tmp007_reg_update(drv_data, TMP007_REG_CONFIG, TMP007_ALERT_EN_BIT, TMP007_ALERT_EN_BIT); if (rc != 0) { SYS_LOG_DBG("Failed to enable interrupt pin!"); return -EIO; } /* setup gpio interrupt */ drv_data->gpio = device_get_binding(CONFIG_TMP007_GPIO_DEV_NAME); if (drv_data->gpio == NULL) { SYS_LOG_DBG("Failed to get pointer to %s device!", CONFIG_TMP007_GPIO_DEV_NAME); return -EINVAL; } gpio_pin_configure(drv_data->gpio, CONFIG_TMP007_GPIO_PIN_NUM, GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL | GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE); gpio_init_callback(&drv_data->gpio_cb, tmp007_gpio_callback, BIT(CONFIG_TMP007_GPIO_PIN_NUM)); rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb); if (rc != 0) { SYS_LOG_DBG("Failed to set gpio callback!"); return -EIO; } #if defined(CONFIG_TMP007_TRIGGER_OWN_FIBER) nano_sem_init(&drv_data->gpio_sem); fiber_start(drv_data->fiber_stack, CONFIG_TMP007_FIBER_STACK_SIZE, (nano_fiber_entry_t)tmp007_fiber, POINTER_TO_INT(dev), 0, CONFIG_TMP007_FIBER_PRIORITY, 0); #elif defined(CONFIG_TMP007_TRIGGER_GLOBAL_FIBER) drv_data->work.handler = tmp007_fiber_cb; drv_data->work.arg = dev; #endif return 0; }
static int gpio_sch_set_callback(struct device *dev, gpio_callback_t callback) { struct gpio_sch_data *gpio = dev->driver_data; gpio->callback = callback; /* Start the fiber only when relevant */ if (callback && (gpio->cb_enabled || gpio->port_cb)) { if (!gpio->poll) { DBG("Starting SCH GPIO polling fiber\n"); gpio->poll = 1; fiber_start(gpio->polling_stack, GPIO_SCH_POLLING_STACK_SIZE, _gpio_sch_poll_status, POINTER_TO_INT(dev), 0, 0, 0); } } else { gpio->poll = 0; } return 0; }
int bma280_init_interrupt(struct device *dev) { struct bma280_data *drv_data = dev->driver_data; int rc; /* set latched interrupts */ rc = i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS, BMA280_REG_INT_RST_LATCH, BMA280_BIT_INT_LATCH_RESET | BMA280_INT_MODE_LATCH); if (rc != 0) { SYS_LOG_DBG("Could not set latched interrupts"); return -EIO; } /* setup data ready gpio interrupt */ drv_data->gpio = device_get_binding(CONFIG_BMA280_GPIO_DEV_NAME); if (drv_data->gpio == NULL) { SYS_LOG_DBG("Cannot get pointer to %s device", CONFIG_BMA280_GPIO_DEV_NAME); return -EINVAL; } gpio_pin_configure(drv_data->gpio, CONFIG_BMA280_GPIO_PIN_NUM, GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL | GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE); gpio_init_callback(&drv_data->gpio_cb, bma280_gpio_callback, BIT(CONFIG_BMA280_GPIO_PIN_NUM)); rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb); if (rc != 0) { SYS_LOG_DBG("Could not set gpio callback"); return -EIO; } /* map data ready interrupt to INT1 */ rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS, BMA280_REG_INT_MAP_1, BMA280_INT_MAP_1_BIT_DATA, BMA280_INT_MAP_1_BIT_DATA); if (rc != 0) { SYS_LOG_DBG("Could not map data ready interrupt pin"); return -EIO; } /* map any-motion interrupt to INT1 */ rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS, BMA280_REG_INT_MAP_0, BMA280_INT_MAP_0_BIT_SLOPE, BMA280_INT_MAP_0_BIT_SLOPE); if (rc != 0) { SYS_LOG_DBG("Could not map any-motion interrupt pin"); return -EIO; } /* disable data ready interrupt */ rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS, BMA280_REG_INT_EN_1, BMA280_BIT_DATA_EN, 0); if (rc != 0) { SYS_LOG_DBG("Could not disable data ready interrupt"); return -EIO; } /* disable any-motion interrupt */ rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS, BMA280_REG_INT_EN_0, BMA280_SLOPE_EN_XYZ, 0); if (rc != 0) { SYS_LOG_DBG("Could not disable data ready interrupt"); return -EIO; } #if defined(CONFIG_BMA280_TRIGGER_OWN_FIBER) nano_sem_init(&drv_data->gpio_sem); fiber_start(drv_data->fiber_stack, CONFIG_BMA280_FIBER_STACK_SIZE, (nano_fiber_entry_t)bma280_fiber, POINTER_TO_INT(dev), 0, CONFIG_BMA280_FIBER_PRIORITY, 0); #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_FIBER) drv_data->work.handler = bma280_fiber_cb; drv_data->work.arg = dev; #endif gpio_pin_enable_callback(drv_data->gpio, CONFIG_BMA280_GPIO_PIN_NUM); return 0; }
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) { bt_conn_state_t old_state; BT_DBG("%s -> %s", state2str(conn->state), state2str(state)); if (conn->state == state) { BT_WARN("no transition"); return; } old_state = conn->state; conn->state = state; /* Actions needed for exiting the old state */ switch (old_state) { case BT_CONN_DISCONNECTED: /* Take a reference for the first state transition after * bt_conn_add_le() and keep it until reaching DISCONNECTED * again. */ bt_conn_ref(conn); break; case BT_CONN_CONNECT: if (conn->timeout) { fiber_delayed_start_cancel(conn->timeout); conn->timeout = NULL; /* Drop the reference taken by timeout fiber */ bt_conn_unref(conn); } break; default: break; } /* Actions needed for entering the new state */ switch (conn->state) { case BT_CONN_CONNECTED: nano_fifo_init(&conn->tx_queue); fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber, (int)bt_conn_ref(conn), 0, 7, 0); bt_l2cap_connected(conn); notify_connected(conn); break; case BT_CONN_DISCONNECTED: /* Notify disconnection and queue a dummy buffer to wake * up and stop the tx fiber for states where it was * running. */ if (old_state == BT_CONN_CONNECTED || old_state == BT_CONN_DISCONNECT) { bt_l2cap_disconnected(conn); notify_disconnected(conn); nano_fifo_put(&conn->tx_queue, net_buf_get(&dummy, 0)); } else if (old_state == BT_CONN_CONNECT) { /* conn->err will be set in this case */ notify_connected(conn); } else if (old_state == BT_CONN_CONNECT_SCAN && conn->err) { /* this indicate LE Create Connection failed */ notify_connected(conn); } /* Release the reference we took for the very first * state transition. */ bt_conn_unref(conn); break; case BT_CONN_CONNECT_SCAN: break; case BT_CONN_CONNECT: /* * Timer is needed only for LE. For other link types controller * will handle connection timeout. */ if (conn->type != BT_CONN_TYPE_LE) { break; } /* Add LE Create Connection timeout */ conn->timeout = fiber_delayed_start(conn->stack, sizeof(conn->stack), timeout_fiber, (int)bt_conn_ref(conn), 0, 7, 0, CONN_TIMEOUT); break; case BT_CONN_DISCONNECT: break; default: BT_WARN("no valid (%u) state was set", state); break; } }