ll_buf.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #define BLE_PACKET_BUF_LEN 258 //(257+3-2) +2 to align word
  44. #define RX_BUF_LEN BLE_PACKET_BUF_LEN
  45. #define TX_BUF_LEN BLE_PACKET_BUF_LEN
  46. #define TX_CTRL_BUF_LEN 34 //(27+4+3)
  47. #define LL_PDU_LENGTH_SUPPORTED_MAX_TX_OCTECTS 251
  48. #define LL_PDU_LENGTH_SUPPORTED_MAX_RX_OCTECTS 251
  49. #define LL_PDU_LENGTH_SUPPORTED_MAX_TX_TIME 2120
  50. #define LL_PDU_LENGTH_SUPPORTED_MAX_RX_TIME 2120
  51. #define LL_PDU_LENGTH_INITIAL_MAX_TX_OCTECTS 27
  52. #define LL_PDU_LENGTH_INITIAL_MAX_RX_OCTECTS 27
  53. #define LL_PDU_LENGTH_INITIAL_MAX_TX_TIME 328
  54. #define LL_PDU_LENGTH_INITIAL_MAX_RX_TIME 328
  55. struct buf_rx_desc
  56. {
  57. uint32_t valid; // mean a valid data received from ble
  58. /// rx header
  59. uint16_t rxheader;
  60. uint8_t data[RX_BUF_LEN ]; // for v4.2 BLE, set to 256
  61. };
  62. struct buf_tx_desc
  63. {
  64. uint32_t valid; // means a valid data to wait for send to ble
  65. //uint32_t sent; // means tha data has been sent before
  66. /// tx header
  67. uint16_t txheader;
  68. /// data
  69. uint8_t data[TX_BUF_LEN];
  70. };
  71. typedef struct
  72. {
  73. uint16_t header;
  74. //uint8_t data[TX_BUF_LEN];
  75. uint8_t data[TX_CTRL_BUF_LEN];
  76. } ctrl_packet_buf;
  77. typedef struct
  78. {
  79. struct buf_tx_desc tx_adv_desc[MAX_ADV_BUF];
  80. struct buf_rx_desc rx_adv_desc[MAX_ADV_BUF];
  81. struct buf_tx_desc tx_scanRsp_desc;
  82. struct buf_tx_desc tx_conn_desc[MAX_LL_BUF_LEN]; // new Tx data buffer
  83. struct buf_rx_desc rx_conn_desc[MAX_LL_BUF_LEN];
  84. struct buf_tx_desc tx_not_ack_pkt;
  85. struct buf_tx_desc tx_ntrm_pkts[MAX_LL_BUF_LEN];
  86. uint8_t ntrm_cnt; // number of packets not transmit
  87. uint8_t tx_write;
  88. uint8_t tx_read;
  89. uint8_t tx_loop; // flag for write ptr & read ptr work in the same virtual buffer bank
  90. uint8_t rx_write;
  91. uint8_t rx_read;
  92. uint8_t rx_loop; // flag for write ptr & read ptr work in the same virtual buffer bank
  93. } llLinkBuf_t;
  94. #endif