static int dma_stm32_disable_stream(struct dma_stm32_device *ddata, u32_t id) { u32_t config; int count = 0; int ret = 0; for (;;) { config = dma_stm32_read(ddata, DMA_STM32_SCR(id)); /* Stream already disabled */ if (!(config & DMA_STM32_SCR_EN)) { return 0; } /* Try to disable stream */ dma_stm32_write(ddata, DMA_STM32_SCR(id), config &= ~DMA_STM32_SCR_EN); /* After trying for 5 seconds, give up */ k_sleep(K_SECONDS(5)); if (count++ > (5 * 1000) / 50) { SYS_LOG_ERR("DMA error: Stream in use\n"); return -EBUSY; } } return ret; }
static int secure_beacon_send(void) { static const struct bt_mesh_send_cb send_cb = { .end = beacon_complete, }; u32_t now = k_uptime_get_32(); int i; BT_DBG(""); for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; struct net_buf *buf; u32_t time_diff; if (sub->net_idx == BT_MESH_KEY_UNUSED) { continue; } time_diff = now - sub->beacon_sent; if (time_diff < K_SECONDS(600) && time_diff < BEACON_THRESHOLD(sub)) { continue; } buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, PROV_XMIT_COUNT, PROV_XMIT_INT, K_NO_WAIT); if (!buf) { BT_ERR("Unable to allocate beacon buffer"); return -ENOBUFS; } bt_mesh_beacon_create(sub, &buf->b); bt_mesh_adv_send(buf, &send_cb, sub); net_buf_unref(buf); } return 0; }