ll_buf.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. #ifndef _LL_BUF_H_
  29. #define _LL_BUF_H_
  30. #include <stdint.h>
  31. #define MAX_ADV_BUF 1 // buffer advertisement packet
  32. #define TYP_CONN_BUF_LEN 4 // typical packet number per connection event
  33. #define MAX_LL_BUF_LEN 8 // maximum LL buffer for Rx/Tx packet
  34. //#define LL_CTRL_PDU_LEN 29 //V4.0/4.2: 2octets header + 27 octets payload
  35. //#define LL_ADV_PDU_LEN 39 //V4.0/4.2: 2octets header + 37 octets payload
  36. //#define LL_DATA_PDU_LEN 33 //V4.0 : 2octets header + 31 octets payload
  37. // for Rx FIFO, HW will pack zero bytes to align 4bytes boarder
  38. // BLE 4.0, PDU length < 39, 3Bytes CRC will also be read.
  39. // note that PDU head is write in "rxheader/txheader" field, the buffer need (39 + 3 - 2) = 40 bytes,
  40. // add 2 bytes to align 4 bytes edge
  41. //#define BLE_PACKET_BUF_LEN 42
  42. //257+3-2=256
  43. // BLE5.0, PDU length: maximum 257 octets, 3 octets CRC, 2 octets PDU head is write in "rxheader/txheader" field
  44. //#define BLE_PACKET_BUF_LEN 258 //(257+3-2)
  45. // BLE 5.1, PDU length: 2-258 octets, 3 octets CRC, 2 octets PDU head is write in "rxheader/txheader" field
  46. // length should align to word edge, so + 3 octet
  47. #define BLE_PACKET_BUF_LEN 262 //(258+3-2) + 3
  48. #define RX_BUF_LEN BLE_PACKET_BUF_LEN
  49. #define TX_BUF_LEN BLE_PACKET_BUF_LEN
  50. #define TX_CTRL_BUF_LEN 34 //(27+4+3)
  51. #define LL_PDU_LENGTH_SUPPORTED_MAX_TX_OCTECTS 251
  52. #define LL_PDU_LENGTH_SUPPORTED_MAX_RX_OCTECTS 251
  53. #define LL_PDU_LENGTH_SUPPORTED_MAX_TX_TIME 2120
  54. #define LL_PDU_LENGTH_SUPPORTED_MAX_RX_TIME 2120
  55. #define LL_PDU_LENGTH_INITIAL_MAX_TX_OCTECTS 27
  56. #define LL_PDU_LENGTH_INITIAL_MAX_RX_OCTECTS 27
  57. #define LL_PDU_LENGTH_INITIAL_MAX_TX_TIME 328
  58. #define LL_PDU_LENGTH_INITIAL_MAX_RX_TIME 328
  59. // BBB update
  60. struct ll_pkt_desc
  61. {
  62. uint32_t valid; // mean a valid data received from ble
  63. uint16_t header;
  64. uint8_t data[2];
  65. };
  66. struct buf_rx_desc
  67. {
  68. uint32_t valid; // mean a valid data received from ble
  69. /// rx header
  70. uint16_t rxheader;
  71. uint8_t data[RX_BUF_LEN ]; // for v4.2 BLE, set to 256
  72. };
  73. struct buf_tx_desc
  74. {
  75. uint32_t valid; // means a valid data to wait for send to ble
  76. //uint32_t sent; // means tha data has been sent before
  77. /// tx header
  78. uint16_t txheader;
  79. /// data
  80. uint8_t data[TX_BUF_LEN];
  81. };
  82. typedef struct
  83. {
  84. uint16_t header;
  85. //uint8_t data[TX_BUF_LEN];
  86. uint8_t data[TX_CTRL_BUF_LEN];
  87. } __attribute__((aligned(4))) ctrl_packet_buf;
  88. typedef struct
  89. {
  90. #if 0
  91. struct buf_tx_desc tx_conn_desc[MAX_LL_BUF_LEN]; // new Tx data buffer
  92. struct buf_rx_desc rx_conn_desc[MAX_LL_BUF_LEN];
  93. struct buf_tx_desc tx_not_ack_pkt;
  94. struct buf_tx_desc tx_ntrm_pkts[MAX_LL_BUF_LEN];
  95. #endif
  96. struct ll_pkt_desc *tx_conn_desc[MAX_LL_BUF_LEN]; // new Tx data buffer
  97. struct ll_pkt_desc *rx_conn_desc[MAX_LL_BUF_LEN];
  98. struct ll_pkt_desc *tx_not_ack_pkt;
  99. struct ll_pkt_desc *tx_ntrm_pkts[MAX_LL_BUF_LEN];
  100. uint8_t ntrm_cnt; // number of packets not transmit
  101. uint8_t tx_write;
  102. uint8_t tx_read;
  103. uint8_t tx_loop; // flag for write ptr & read ptr work in the same virtual buffer bank
  104. uint8_t rx_write;
  105. uint8_t rx_read;
  106. uint8_t rx_loop; // flag for write ptr & read ptr work in the same virtual buffer bank
  107. } llLinkBuf_t;
  108. #endif