Mistake on this page?
Report an issue in GitHub or email us
ble_bufsize.h
1 /*****************************************************************************
2  * @file ble_bufsize.h
3  * @author MCD
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_SIZE: maximum attribute size.
30  */
31 #define BLE_DEFAULT_MAX_ATT_SIZE 512
32 
33 /*
34  * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to
35  * write a characteristic with size 'max_att' when the used ATT_MTU value is
36  * equal to BLE_DEFAULT_ATT_MTU (23).
37  */
38 #define BLE_PREP_WRITE_X_ATT(max_att) \
39  (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2)
40 
41 /*
42  * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size.
43  */
44 #define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \
45  BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE)
46 
47 /*
48  * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose
49  * an ATT packet with ATT_MTU=mtu.
50  */
51 #define BLE_MEM_BLOCK_SIZE 32
52 
53 #define BLE_MEM_BLOCK_X_TX(mtu) \
54  (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U)
55 
56 #define BLE_MEM_BLOCK_X_RX(mtu, n_link) \
57  ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1)
58 
59 #define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \
60  (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link))
61 
62 /*
63  * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for
64  * secure connections
65  */
66 #define BLE_MBLOCKS_SECURE_CONNECTIONS 4
67 
68 /*
69  * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack.
70  * This is the minimum racomanded value and depends on:
71  * - pw: size of Prepare Write List
72  * - mtu: ATT_MTU size
73  * - n_link: maximum number of simultaneous connections
74  */
75 #define BLE_MBLOCKS_CALC(pw, mtu, n_link) \
76  ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \
77  BLE_MBLOCKS_SECURE_CONNECTIONS))
78 
79 /*
80  * BLE_FIXED_BUFFER_SIZE_BYTES:
81  * A part of the RAM, is dinamically allocated by initilizing all the pointers
82  * defined in a global context variable "mem_alloc_ctx_p".
83  * This initialization is made in the Dynamic_allocator functions, which
84  * assing a portion of RAM given by the external application to the above
85  * mentioned "global pointers".
86  *
87  * The size of this Dynamic RAM is made of 2 main components:
88  * - a part that is parameters-dependent (num of links, GATT buffers, ...),
89  * and which value is explicited by the following macro;
90  * - a part, that may be considered "fixed", i.e. independent from the above
91  * mentioned parameters.
92 */
93 #if (BEACON_ONLY != 0)
94 #define BLE_FIXED_BUFFER_SIZE_BYTES 6212 /* Beacon only */
95 #elif (LL_ONLY != 0)
96 #define BLE_FIXED_BUFFER_SIZE_BYTES 6272 /* LL only */
97 #elif (SLAVE_ONLY != 0)
98 #define BLE_FIXED_BUFFER_SIZE_BYTES 6712 /* Peripheral only */
99 #elif (BASIC_FEATURES != 0)
100 #define BLE_FIXED_BUFFER_SIZE_BYTES 6972 /* Basic Features */
101 #else
102 #define BLE_FIXED_BUFFER_SIZE_BYTES 7240 /* Full stack */
103 #endif
104 
105 /*
106  * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link
107  */
108 #if (BEACON_ONLY != 0)
109 #define BLE_PER_LINK_SIZE_BYTES 148 /* Beacon only */
110 #elif (LL_ONLY != 0)
111 #define BLE_PER_LINK_SIZE_BYTES 196 /* LL only */
112 #elif (SLAVE_ONLY != 0)
113 #define BLE_PER_LINK_SIZE_BYTES 332 /* Peripheral only */
114 #elif (BASIC_FEATURES != 0)
115 #define BLE_PER_LINK_SIZE_BYTES 332 /* Basic Features */
116 #else
117 #define BLE_PER_LINK_SIZE_BYTES 384 /* Full stack */
118 #endif
119 
120 /*
121  * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes,
122  * needed for the storage of data structures (except GATT database elements)
123  * whose size depends on the number of supported connections.
124  *
125  * @param n_link: Maximum number of simultaneous connections that the device
126  * will support. Valid values are from 1 to 8.
127  *
128  * @param mblocks_count: Number of memory blocks allocated for packets.
129  */
130 #define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \
131  (BLE_FIXED_BUFFER_SIZE_BYTES + \
132  (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \
133  ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count)))
134 
135 /*
136  * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory,
137  * in bytes, needed for the storage of GATT database elements.
138  *
139  * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number
140  * of characteristic + the number of characteristic values + the number of
141  * descriptors, excluding the services) that can be stored in the GATT
142  * database. Note that certain characteristics and relative descriptors are
143  * added automatically during device initialization so this parameters should
144  * be 9 plus the number of user Attributes
145  *
146  * @param num_gatt_services: Maximum number of Services that can be stored in
147  * the GATT database. Note that the GAP and GATT services are automatically
148  * added so this parameter should be 2 plus the number of user services
149  *
150  * @param att_value_array_size: Size of the storage area for Attribute values.
151  */
152 #define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \
153  (((((att_value_array_size) - 1) | 3) + 1) + \
154  (40 * (num_gatt_attributes)) + (48 * (num_gatt_services)))
155 
156 
157 #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.