samples/userspace/prod_consumer: Use a sys_heap

This code used a sys_mem_pool directly.  Use a new-style heap instead
to do the same thing.

(Note that the usage is a little specious -- it allocates from the
heap but doesn't appear to fill or check any data therein, just that
the heap memory can be copied from the two memory domains.  It's
unclear exactly what this is trying to demonstrate and we might want
to improve the sample to do something less trivial.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2020-10-20 10:43:14 -07:00 committed by Anas Nashif
commit e7436f7c55
4 changed files with 13 additions and 14 deletions

View file

@ -16,7 +16,7 @@ back to the driver.
The goal here is to demonstrate:
- Multiple logical applications, each with their own memory domain
- Creation of a sys_mem_pool and assignment to a memory partition
- Creation of a sys_heap and assignment to a memory partition
- Use of APIs like ``k_queue_alloc_append()`` which require thread resource
pools to be configured
- Management of permissions for kernel objects and drivers

View file

@ -99,8 +99,8 @@ static void monitor_entry(void *p1, void *p2, void *p3)
}
while (monitor_count < NUM_LOOPS) {
payload = sys_mem_pool_alloc(&shared_pool,
SAMPLE_DRIVER_MSG_SIZE);
payload = sys_heap_alloc(&shared_pool,
SAMPLE_DRIVER_MSG_SIZE);
if (payload == NULL) {
LOG_ERR("couldn't alloc memory from shared pool");
k_oops();
@ -168,7 +168,7 @@ static void writeback_entry(void *p1, void *p2, void *p3)
LOG_INF("writing processed data back to the sample device");
sample_driver_write(sample_device, data);
sys_mem_pool_free(data);
sys_heap_free(&shared_pool, data);
pending_count--;
writeback_count++;
}

View file

@ -27,14 +27,13 @@ LOG_MODULE_REGISTER(app_main);
K_APPMEM_PARTITION_DEFINE(shared_partition);
/* Define a memory pool to place in the shared area.
*
* SYS_MEM_POOL_DEFINE() is special in that we don't use K_APP_DMEM()
* to route it to the shared partition, instead it takes a section parameter.
*/
#define BLK_SIZE (SAMPLE_DRIVER_MSG_SIZE + \
WB_UP(sizeof(struct sys_mem_pool_block)))
SYS_MEM_POOL_DEFINE(shared_pool, NULL, BLK_SIZE, BLK_SIZE, 8, 8,
K_APP_DMEM_SECTION(shared_partition));
#define BLK_SIZE (SAMPLE_DRIVER_MSG_SIZE + sizeof(void *))
#define HEAP_BYTES (BLK_SIZE * 16)
K_APP_DMEM(shared_partition) struct sys_heap shared_pool;
K_APP_DMEM(shared_partition) uint8_t shared_pool_mem[HEAP_BYTES];
/* queues for exchanging data between App A and App B */
K_QUEUE_DEFINE(shared_queue_incoming);
@ -57,7 +56,7 @@ void main(void)
LOG_INF("libc partition: %p %zu", (void *)z_libc_partition.start,
(size_t)z_libc_partition.size);
#endif
sys_mem_pool_init(&shared_pool);
sys_heap_init(&shared_pool, shared_pool_mem, HEAP_BYTES);
/* Spawn supervisor entry for application A */
k_thread_create(&app_a_thread, app_a_stack, APP_A_STACKSIZE,

View file

@ -9,13 +9,13 @@
#include <kernel.h>
#include <app_memory/app_memdomain.h>
#include <sys/mempool.h>
#include <sys/sys_heap.h>
extern struct k_mem_partition shared_partition;
#define SHARED_DATA K_APP_DMEM(shared_partition)
#define SHARED_BSS K_APP_BMEM(shared_partition)
extern struct sys_mem_pool shared_pool;
extern struct sys_heap shared_pool;
extern struct k_queue shared_queue_incoming;
extern struct k_queue shared_queue_outgoing;