Bluetooth: Simplify ncmd handling
With k_sem API it is possible to specify maximum sempahore value so we no longer need to track semaphore count. Change-Id: I86744ba63bd3207051ca3466d4f81b816d24f5ad Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
parent
a081e0a57f
commit
70417f1fce
2 changed files with 10 additions and 31 deletions
|
@ -2308,7 +2308,6 @@ static void hci_cmd_complete(struct net_buf *buf)
|
||||||
struct bt_hci_evt_cmd_complete *evt = (void *)buf->data;
|
struct bt_hci_evt_cmd_complete *evt = (void *)buf->data;
|
||||||
uint16_t opcode = sys_le16_to_cpu(evt->opcode);
|
uint16_t opcode = sys_le16_to_cpu(evt->opcode);
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
int key;
|
|
||||||
|
|
||||||
BT_DBG("opcode 0x%04x", opcode);
|
BT_DBG("opcode 0x%04x", opcode);
|
||||||
|
|
||||||
|
@ -2321,25 +2320,16 @@ static void hci_cmd_complete(struct net_buf *buf)
|
||||||
|
|
||||||
hci_cmd_done(opcode, status, buf);
|
hci_cmd_done(opcode, status, buf);
|
||||||
|
|
||||||
key = irq_lock();
|
|
||||||
|
|
||||||
if (!evt->ncmd || bt_dev.ncmd) {
|
|
||||||
irq_unlock(key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allow next command to be sent */
|
/* Allow next command to be sent */
|
||||||
bt_dev.ncmd = 1;
|
if (evt->ncmd) {
|
||||||
irq_unlock(key);
|
|
||||||
|
|
||||||
k_sem_give(&bt_dev.ncmd_sem);
|
k_sem_give(&bt_dev.ncmd_sem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void hci_cmd_status(struct net_buf *buf)
|
static void hci_cmd_status(struct net_buf *buf)
|
||||||
{
|
{
|
||||||
struct bt_hci_evt_cmd_status *evt = (void *)buf->data;
|
struct bt_hci_evt_cmd_status *evt = (void *)buf->data;
|
||||||
uint16_t opcode = sys_le16_to_cpu(evt->opcode);
|
uint16_t opcode = sys_le16_to_cpu(evt->opcode);
|
||||||
int key;
|
|
||||||
|
|
||||||
BT_DBG("opcode 0x%04x", opcode);
|
BT_DBG("opcode 0x%04x", opcode);
|
||||||
|
|
||||||
|
@ -2347,19 +2337,11 @@ static void hci_cmd_status(struct net_buf *buf)
|
||||||
|
|
||||||
hci_cmd_done(opcode, evt->status, buf);
|
hci_cmd_done(opcode, evt->status, buf);
|
||||||
|
|
||||||
key = irq_lock();
|
|
||||||
|
|
||||||
if (!evt->ncmd || bt_dev.ncmd) {
|
|
||||||
irq_unlock(key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allow next command to be sent */
|
/* Allow next command to be sent */
|
||||||
bt_dev.ncmd = 1;
|
if (evt->ncmd) {
|
||||||
irq_unlock(key);
|
|
||||||
|
|
||||||
k_sem_give(&bt_dev.ncmd_sem);
|
k_sem_give(&bt_dev.ncmd_sem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int prng_reseed(struct tc_hmac_prng_struct *h)
|
static int prng_reseed(struct tc_hmac_prng_struct *h)
|
||||||
{
|
{
|
||||||
|
@ -2759,7 +2741,6 @@ static void hci_cmd_tx_thread(void)
|
||||||
/* Get next command - wait if necessary */
|
/* Get next command - wait if necessary */
|
||||||
BT_DBG("calling net_buf_get_timeout");
|
BT_DBG("calling net_buf_get_timeout");
|
||||||
buf = net_buf_get_timeout(&bt_dev.cmd_tx_queue, 0, K_FOREVER);
|
buf = net_buf_get_timeout(&bt_dev.cmd_tx_queue, 0, K_FOREVER);
|
||||||
bt_dev.ncmd = 0;
|
|
||||||
|
|
||||||
/* Clear out any existing sent command */
|
/* Clear out any existing sent command */
|
||||||
if (bt_dev.sent_cmd) {
|
if (bt_dev.sent_cmd) {
|
||||||
|
@ -3665,16 +3646,15 @@ int bt_enable(bt_ready_cb_t cb)
|
||||||
#endif /* CONFIG_BLUETOOTH_CONN */
|
#endif /* CONFIG_BLUETOOTH_CONN */
|
||||||
#endif /* CONFIG_BLUETOOTH_HOST_BUFFERS */
|
#endif /* CONFIG_BLUETOOTH_HOST_BUFFERS */
|
||||||
|
|
||||||
k_sem_init(&bt_dev.ncmd_sem, 0, 1);
|
|
||||||
|
|
||||||
/* Give cmd_sem allowing to send first HCI_Reset cmd, the only
|
/* Give cmd_sem allowing to send first HCI_Reset cmd, the only
|
||||||
* exception is if the controller requests to wait for an
|
* exception is if the controller requests to wait for an
|
||||||
* initial Command Complete for NOP.
|
* initial Command Complete for NOP.
|
||||||
*/
|
*/
|
||||||
#if !defined(CONFIG_BLUETOOTH_WAIT_NOP)
|
#if !defined(CONFIG_BLUETOOTH_WAIT_NOP)
|
||||||
bt_dev.ncmd = 1;
|
k_sem_init(&bt_dev.ncmd_sem, 1, 1);
|
||||||
k_sem_give(&bt_dev.ncmd_sem);
|
#else
|
||||||
#endif /* !CONFIG_BLUETOOTH_WAIT_NOP */
|
k_sem_init(&bt_dev.ncmd_sem, 0, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* TX thread */
|
/* TX thread */
|
||||||
k_fifo_init(&bt_dev.cmd_tx_queue);
|
k_fifo_init(&bt_dev.cmd_tx_queue);
|
||||||
|
|
|
@ -103,7 +103,6 @@ struct bt_dev {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Number of commands controller can accept */
|
/* Number of commands controller can accept */
|
||||||
uint8_t ncmd;
|
|
||||||
struct k_sem ncmd_sem;
|
struct k_sem ncmd_sem;
|
||||||
|
|
||||||
/* Last sent HCI command */
|
/* Last sent HCI command */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue