Mistake on this page?
Report an issue in GitHub or email us
ble_bufsize.h
1 /*****************************************************************************
2  * @file ble_bufsize.h
3  * @author MCD Application Team
4  * @brief Definition of BLE stack buffers size
5  *****************************************************************************
6  * @attention
7  *
8  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
9  * All rights reserved.</center></h2>
10  *
11  * This software component is licensed by ST under BSD 3-Clause license,
12  * the "License"; You may not use this file except in compliance with the
13  * License. You may obtain a copy of the License at:
14  * opensource.org/licenses/BSD-3-Clause
15  *
16  *****************************************************************************
17  */
18 
19 #ifndef BLE_BUFSIZE_H__
20 #define BLE_BUFSIZE_H__
21 
22 
23 /*
24  * BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support.
25  */
26 #define BLE_DEFAULT_ATT_MTU 23
27 
28 /*
29  * BLE_DEFAULT_MAX_ATT_MTU: maximum supported ATT MTU size.
30  */
31 #define BLE_DEFAULT_MAX_ATT_MTU 158
32 
33 /*
34  * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size.
35  */
36 #define BLE_DEFAULT_MAX_ATT_SIZE 512
37 
38 /*
39  * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to
40  * write a characteristic with size 'max_att' when the used ATT_MTU value is
41  * equal to BLE_DEFAULT_ATT_MTU (23).
42  */
43 #define BLE_PREP_WRITE_X_ATT(max_att) \
44  (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2)
45 
46 /*
47  * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size.
48  */
49 #define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \
50  BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE)
51 
52 /*
53  * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose
54  * an ATT packet with ATT_MTU=mtu.
55  */
56 #define BLE_MEM_BLOCK_SIZE 32
57 
58 #define BLE_MEM_BLOCK_X_TX(mtu) \
59  (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U)
60 
61 #define BLE_MEM_BLOCK_X_RX(mtu, n_link) \
62  ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1)
63 
64 #define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \
65  (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link))
66 
67 /*
68  * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for
69  * secure connections
70  */
71 #define BLE_MBLOCKS_SECURE_CONNECTIONS 4
72 
73 /*
74  * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack.
75  * This is the minimum racomanded value and depends on:
76  * - pw: size of Prepare Write List
77  * - mtu: ATT_MTU size
78  * - n_link: maximum number of simultaneous connections
79  */
80 #define BLE_MBLOCKS_CALC(pw, mtu, n_link) \
81  ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \
82  BLE_MBLOCKS_SECURE_CONNECTIONS))
83 
84 /*
85  * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count
86  */
87 #define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \
88  BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \
89  BLE_DEFAULT_MAX_ATT_MTU, n_link)
90 
91 /*
92  * BLE_FIXED_BUFFER_SIZE_BYTES:
93  * A part of the RAM, is dinamically allocated by initilizing all the pointers
94  * defined in a global context variable "mem_alloc_ctx_p".
95  * This initialization is made in the Dynamic_allocator functions, which
96  * assing a portion of RAM given by the external application to the above
97  * mentioned "global pointers".
98  *
99  * The size of this Dynamic RAM is made of 2 main components:
100  * - a part that is parameters-dependent (num of links, GATT buffers, ...),
101  * and which value is explicited by the following macro;
102  * - a part, that may be considered "fixed", i.e. independent from the above
103  * mentioned parameters.
104 */
105 #if (SLAVE_ONLY == 0) && (LL_ONLY == 0)
106 #define BLE_FIXED_BUFFER_SIZE_BYTES 6960 /* Full stack */
107 #elif SLAVE_ONLY == 0
108 #define BLE_FIXED_BUFFER_SIZE_BYTES 6256 /* LL only */
109 #else
110 #define BLE_FIXED_BUFFER_SIZE_BYTES 6696 /* Slave only */
111 #endif
112 
113 /*
114  * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link
115  */
116 #if (SLAVE_ONLY == 0) && (LL_ONLY == 0)
117 #define BLE_PER_LINK_SIZE_BYTES 380 /* Full stack */
118 #elif SLAVE_ONLY == 0
119 #define BLE_PER_LINK_SIZE_BYTES 196 /* LL only */
120 #else
121 #define BLE_PER_LINK_SIZE_BYTES 332 /* Slave only */
122 #endif
123 
124 /*
125  * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes,
126  * needed for the storage of data structures (except GATT database elements)
127  * whose size depends on the number of supported connections.
128  *
129  * @param num_links: Maximum number of simultaneous connections that the device
130  * will support. Valid values are from 1 to 8.
131  *
132  * @param mblocks_count: Number of memory blocks allocated for packets.
133  */
134 #define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \
135  (BLE_FIXED_BUFFER_SIZE_BYTES + \
136  (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \
137  ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count)))
138 
139 /*
140  * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory,
141  * in bytes, needed for the storage of GATT database elements.
142  *
143  * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number
144  * of characteristic + the number of characteristic values + the number of
145  * descriptors, excluding the services) that can be stored in the GATT
146  * database. Note that certain characteristics and relative descriptors are
147  * added automatically during device initialization so this parameters should
148  * be 9 plus the number of user Attributes
149  *
150  * @param num_gatt_services: Maximum number of Services that can be stored in
151  * the GATT database. Note that the GAP and GATT services are automatically
152  * added so this parameter should be 2 plus the number of user services
153  *
154  * @param att_value_array_size: Size of the storage area for Attribute values.
155  */
156 #define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \
157  (((((att_value_array_size) - 1) | 3) + 1) + \
158  (40 * (num_gatt_attributes)) + (48 * (num_gatt_services)))
159 
160 
161 #endif /* ! BLE_BUFSIZE_H__ */
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.