3434
3535LOG_MODULE_REGISTER (wifi_nrf , CONFIG_WIFI_NRF70_LOG_LEVEL );
3636
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 */
3845#if defined(CONFIG_NOCACHE_MEMORY )
3946K_HEAP_DEFINE_NOCACHE (wifi_drv_ctrl_mem_pool , CONFIG_NRF_WIFI_CTRL_HEAP_SIZE );
4047K_HEAP_DEFINE_NOCACHE (wifi_drv_data_mem_pool , CONFIG_NRF_WIFI_DATA_HEAP_SIZE );
4148#else
4249K_HEAP_DEFINE (wifi_drv_ctrl_mem_pool , CONFIG_NRF_WIFI_CTRL_HEAP_SIZE );
4350K_HEAP_DEFINE (wifi_drv_data_mem_pool , CONFIG_NRF_WIFI_DATA_HEAP_SIZE );
4451#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 ;
4554#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
4655
4756#define WORD_SIZE 4
@@ -52,22 +61,14 @@ static void *zep_shim_mem_alloc(size_t size)
5261{
5362 size_t size_aligned = ROUND_UP (size , 4 );
5463
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 );
6065}
6166
6267static void * zep_shim_data_mem_alloc (size_t size )
6368{
6469 size_t size_aligned = ROUND_UP (size , 4 );
6570
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 );
7172}
7273
7374static void * zep_shim_mem_zalloc (size_t size )
@@ -111,22 +112,14 @@ static void *zep_shim_data_mem_zalloc(size_t size)
111112static void zep_shim_mem_free (void * buf )
112113{
113114 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 );
119116 }
120117}
121118
122119static void zep_shim_data_mem_free (void * buf )
123120{
124121 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 );
130123 }
131124}
132125
@@ -211,21 +204,21 @@ static void *zep_shim_spinlock_alloc(void)
211204{
212205 struct zep_shim_spinlock * slock = NULL ;
213206
214- slock = k_calloc ( sizeof (* slock ), sizeof ( char ) );
207+ slock = k_heap_aligned_alloc ( wifi_ctrl_pool , WORD_SIZE , sizeof (* slock ), K_FOREVER );
215208 if (!slock ) {
216209 LOG_ERR ("%s: Unable to allocate memory for spinlock" , __func__ );
210+ } else {
211+ memset (slock , 0 , sizeof (* slock ));
217212 }
218213
219214 return slock ;
220215}
221216
222217static void zep_shim_spinlock_free (void * lock )
223218{
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+ }
229222}
230223
231224static void zep_shim_spinlock_init (void * lock )
0 commit comments