34
34
35
35
LOG_MODULE_REGISTER (wifi_nrf , CONFIG_WIFI_NRF70_LOG_LEVEL );
36
36
37
- #if !defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
37
+ /* Memory pool management - unified pool-based API */
38
+ #if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
39
+ /* Use global system heap */
40
+ extern struct sys_heap _system_heap ;
41
+ static struct k_heap * const wifi_ctrl_pool = & _system_heap ;
42
+ static struct k_heap * const wifi_data_pool = & _system_heap ;
43
+ #else
44
+ /* Use dedicated heaps */
38
45
#if defined(CONFIG_NOCACHE_MEMORY )
39
46
K_HEAP_DEFINE_NOCACHE (wifi_drv_ctrl_mem_pool , CONFIG_NRF_WIFI_CTRL_HEAP_SIZE );
40
47
K_HEAP_DEFINE_NOCACHE (wifi_drv_data_mem_pool , CONFIG_NRF_WIFI_DATA_HEAP_SIZE );
41
48
#else
42
49
K_HEAP_DEFINE (wifi_drv_ctrl_mem_pool , CONFIG_NRF_WIFI_CTRL_HEAP_SIZE );
43
50
K_HEAP_DEFINE (wifi_drv_data_mem_pool , CONFIG_NRF_WIFI_DATA_HEAP_SIZE );
44
51
#endif /* CONFIG_NOCACHE_MEMORY */
52
+ static struct k_heap * const wifi_ctrl_pool = & wifi_drv_ctrl_mem_pool ;
53
+ static struct k_heap * const wifi_data_pool = & wifi_drv_data_mem_pool ;
45
54
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
46
55
47
56
#define WORD_SIZE 4
@@ -52,22 +61,14 @@ static void *zep_shim_mem_alloc(size_t size)
52
61
{
53
62
size_t size_aligned = ROUND_UP (size , 4 );
54
63
55
- #if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
56
- return k_malloc (size_aligned );
57
- #else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
58
- return k_heap_aligned_alloc (& wifi_drv_ctrl_mem_pool , WORD_SIZE , size_aligned , K_FOREVER );
59
- #endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
64
+ return k_heap_aligned_alloc (wifi_ctrl_pool , WORD_SIZE , size_aligned , K_FOREVER );
60
65
}
61
66
62
67
static void * zep_shim_data_mem_alloc (size_t size )
63
68
{
64
69
size_t size_aligned = ROUND_UP (size , 4 );
65
70
66
- #if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
67
- return k_malloc (size_aligned );
68
- #else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
69
- return k_heap_aligned_alloc (& wifi_drv_data_mem_pool , WORD_SIZE , size_aligned , K_FOREVER );
70
- #endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
71
+ return k_heap_aligned_alloc (wifi_data_pool , WORD_SIZE , size_aligned , K_FOREVER );
71
72
}
72
73
73
74
static void * zep_shim_mem_zalloc (size_t size )
@@ -111,22 +112,14 @@ static void *zep_shim_data_mem_zalloc(size_t size)
111
112
static void zep_shim_mem_free (void * buf )
112
113
{
113
114
if (buf ) {
114
- #if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
115
- k_free (buf );
116
- #else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
117
- k_heap_free (& wifi_drv_ctrl_mem_pool , buf );
118
- #endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
115
+ k_heap_free (wifi_ctrl_pool , buf );
119
116
}
120
117
}
121
118
122
119
static void zep_shim_data_mem_free (void * buf )
123
120
{
124
121
if (buf ) {
125
- #if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
126
- k_free (buf );
127
- #else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
128
- k_heap_free (& wifi_drv_data_mem_pool , buf );
129
- #endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
122
+ k_heap_free (wifi_data_pool , buf );
130
123
}
131
124
}
132
125
@@ -211,21 +204,21 @@ static void *zep_shim_spinlock_alloc(void)
211
204
{
212
205
struct zep_shim_spinlock * slock = NULL ;
213
206
214
- slock = k_calloc ( sizeof (* slock ), sizeof ( char ) );
207
+ slock = k_heap_aligned_alloc ( wifi_ctrl_pool , WORD_SIZE , sizeof (* slock ), K_FOREVER );
215
208
if (!slock ) {
216
209
LOG_ERR ("%s: Unable to allocate memory for spinlock" , __func__ );
210
+ } else {
211
+ memset (slock , 0 , sizeof (* slock ));
217
212
}
218
213
219
214
return slock ;
220
215
}
221
216
222
217
static void zep_shim_spinlock_free (void * lock )
223
218
{
224
- #if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP )
225
- k_free (lock );
226
- #else
227
- k_heap_free (& wifi_drv_ctrl_mem_pool , lock );
228
- #endif
219
+ if (lock ) {
220
+ k_heap_free (wifi_ctrl_pool , lock );
221
+ }
229
222
}
230
223
231
224
static void zep_shim_spinlock_init (void * lock )
0 commit comments