diff --git a/bsp/qemu-vexpress-a9/applications/channel_memory.c b/bsp/qemu-vexpress-a9/applications/channel_memory.c new file mode 100644 index 0000000000000000000000000000000000000000..b01cc555e2c8da8219fa859ca9d4d86877816519 --- /dev/null +++ b/bsp/qemu-vexpress-a9/applications/channel_memory.c @@ -0,0 +1,65 @@ +#include +#include +#include + +#define DBG_TAG "DTAG" +#define DBG_LVL DBG_INFO +#include + +/* put memory informations into buf */ +void rt_memory_get(void* buf) +{ + rt_uint32_t total_mem,used_mem,max_mem; + rt_memory_info(&total_mem,&used_mem,&max_mem); + size_t total_pages = 0, free_pages = 0; + rt_page_get_info(&total_pages, &free_pages); + total_mem = total_mem + total_pages * ARCH_PAGE_SIZE; + used_mem = used_mem + (total_pages - free_pages) * ARCH_PAGE_SIZE; + int size = sizeof(rt_uint32_t); + memcpy(buf, &total_mem, size); + memcpy(buf+size, &used_mem, size); + memcpy(buf+size*2, &max_mem, size); +} + +/* given information(memory) with channel */ +void rt_memory_transinformation_entry(void) +{ + int ch; + struct rt_channel_msg msg_text; + char* channel_msg; + int shmid; + /* create channel called 'channel_memory' to transmitting memory informations */ + ch = rt_channel_open("channel_memory",O_CREAT); + if (ch == -1) + { + LOG_D("Error: rt_channel_open: fail to create the IPC channel for memory!"); + return; + } + while (1) + { + rt_channel_recv(ch,&msg_text); + shmid = (int)msg_text.u.d; + if (shmid < 0 || !(channel_msg = lwp_shminfo(shmid))) + { + msg_text.u.d = (void*)-1; + LOG_D("memory:receive an invalid shared-memory page."); + rt_channel_reply(ch,&msg_text); + continue; + } + /* get memory informations and copy them into the shared memory */ + int len = sizeof(rt_uint32_t)*3; + char memory_buf[len]; + rt_memory_get(memory_buf); + memcpy((void*)channel_msg,memory_buf,len); + rt_channel_reply(ch,&msg_text); + } + rt_channel_close(ch); +} + +void rt_memory_transinformation_thread(void) +{ + rt_thread_t tid = rt_thread_create("channel_trans_memory_thread", rt_memory_transinformation_entry, RT_NULL, LWP_TASK_STACK_SIZE, 25, 300); + rt_thread_startup(tid); +} +INIT_APP_EXPORT(rt_memory_transinformation_thread); +