Skip to content

Commit

Permalink
test: Zephyr: Replace k_mem_block usage
Browse files Browse the repository at this point in the history
The k_mem_block structure is obsolete for some years
replace it by a "void *" pointer. as done in Zephyr.

Signed-off-by: Arnaud Pouliquen <[email protected]>
  • Loading branch information
arnopo committed Oct 13, 2023
1 parent fb8b04f commit a27943a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/system/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define BLK_NUM_MAX 16

K_HEAP_DEFINE(kmpool, BLK_SIZE_MAX * BLK_NUM_MAX);
struct k_mem_block block[BLK_NUM_MAX];
void *block[BLK_NUM_MAX];

extern int init_system(void);
extern void metal_generic_default_poll(void);
Expand All @@ -29,15 +29,15 @@ extern void metal_test_add_mutex();
extern void *metal_zephyr_allocate_memory(unsigned int size)
{
int i;
struct k_mem_block *blk;
void **blk;

for (i = 0; i < sizeof(block)/sizeof(block[0]); i++) {
blk = &block[i];
if (!blk->data) {
blk->data = k_heap_alloc(&kmpool, size, K_NO_WAIT);
if (!blk->data)
if (!blk) {
*blk = k_heap_alloc(&kmpool, size, K_NO_WAIT);
if (!*blk)
printk("Failed to alloc 0x%x memory.\n", size);
return blk->data;
return *blk;
}
}

Expand All @@ -48,13 +48,13 @@ extern void *metal_zephyr_allocate_memory(unsigned int size)
extern void metal_zephyr_free_memory(void *ptr)
{
int i;
struct k_mem_block *blk;
void **blk;

for (i = 0; i < sizeof(block)/sizeof(block[0]); i++) {
blk = &block[i];
if (blk->data == ptr) {
k_heap_free(&kmpool, blk);
blk->data = NULL;
if (*blk == ptr) {
k_heap_free(&kmpool, *blk);
*blk = NULL;
return;
}
}
Expand Down

0 comments on commit a27943a

Please sign in to comment.