bt_queue.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /****************************************************************************
  2. * wireless/bluetooth/bt_queue.h
  3. * Inter-thread buffer queue management
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one or more
  6. * contributor license agreements. See the NOTICE file distributed with
  7. * this work for additional information regarding copyright ownership. The
  8. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance with the
  10. * License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. * License for the specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. ****************************************************************************/
  21. #ifndef __WIRELESS_BLUETOOTH_BT_QUEUE_H
  22. #define __WIRELESS_BLUETOOTH_BT_QUEUE_H
  23. /****************************************************************************
  24. * Included Files
  25. ****************************************************************************/
  26. #include <nuttx/config.h>
  27. #include <nuttx/compiler.h>
  28. #include <nuttx/mqueue.h>
  29. #include <limits.h>
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /* Names of all POSIX message queues. */
  34. #define BT_CONN_TX "btconntx"
  35. #define BT_HCI_TX "bthcitx"
  36. /* All messages are sent FIFO at the mid-message priorities except for high-
  37. * priority messages received from the Bluetooth driver.
  38. */
  39. #define BT_PRIO_MAX MQ_PRIO_MAX
  40. #define BT_PRIO_MIN 0
  41. #define BT_NORMAL_PRIO (BT_PRIO_MIN + (BT_PRIO_MAX - BT_PRIO_MIN) / 2)
  42. #define BT_HIGH_PRIO (BT_PRIO_MIN + 3 * (BT_PRIO_MAX - BT_PRIO_MIN) / 4)
  43. /* Verify that enough messages have been allocated */
  44. #define BT_NMSGS (CONFIG_BLUETOOTH_TXCMD_NMSGS + \
  45. CONFIG_BLUETOOTH_TXCONN_NMSGS)
  46. #if BT_NMSGS > CONFIG_PREALLOC_MQ_MSGS
  47. # warning WARNING: not enough pre-allocated messages
  48. #endif
  49. /****************************************************************************
  50. * Public Function Prototypes
  51. ****************************************************************************/
  52. struct bt_buf_s; /* Forward Reference */
  53. /****************************************************************************
  54. * Name: bt_queue_open
  55. *
  56. * Description:
  57. * Open a message queue for read or write access.
  58. *
  59. * Input Parameters:
  60. * name - The name of the message queue to open
  61. * oflags - Open flags with access mode
  62. * nmsgs - Max number of messages in queue before bt_queue_send() blocks.
  63. * mqd - The location in which to return the message queue descriptor
  64. *
  65. * Returned Value:
  66. * Zero is returned on success; a negated errno value is returned on any
  67. * failure;
  68. *
  69. ****************************************************************************/
  70. int bt_queue_open(FAR const char *name, int oflags, int nmsgs,
  71. FAR struct file *mqd);
  72. /****************************************************************************
  73. * Name: bt_queue_receive
  74. *
  75. * Description:
  76. * Block until the next buffer is received on the queue.
  77. *
  78. * Input Parameters:
  79. * mqd - The message queue descriptor previously returned by
  80. * bt_open_*queue.
  81. * buf - The location in which to return the received buffer.
  82. *
  83. * Returned Value:
  84. * Zero is returned on success; a negated errno value is returned on any
  85. * failure;
  86. *
  87. ****************************************************************************/
  88. int bt_queue_receive(struct file *mqd, FAR struct bt_buf_s **buf);
  89. /****************************************************************************
  90. * Name: bt_queue_send
  91. *
  92. * Description:
  93. * Send the buffer to the specified message queue
  94. *
  95. * Input Parameters:
  96. * mqd - The message queue descriptor previously returned by
  97. * bt_open_*queue.
  98. * buf - A reference to the buffer to be sent
  99. * priority - Either BT_NORMAL_PRIO or BT_NORMAL_HIGH. NOTE:
  100. * BT_NORMAL_HIGHis only for use within the stack. Drivers
  101. * should always use BT_NORMAL_PRIO.
  102. *
  103. * Returned Value:
  104. * Zero is returned on success; a negated errno value is returned on any
  105. * failure;
  106. *
  107. ****************************************************************************/
  108. int bt_queue_send(struct file *mqd,
  109. FAR struct bt_buf_s *buf,
  110. unsigned int priority);
  111. #endif /* __WIRELESS_BLUETOOTH_BT_QUEUE_H */