You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

elog_test.c 934B

123456789101112131415161718192021222324252627282930313233
  1. #include <elog.h>
  2. static elog_t *logger;
  3. static char arena[1024];
  4. static void log_to_semihost(elog_entry_t *e, int len, void *ctx)
  5. {
  6. // 发送出去
  7. uint32_t *p = (void *)e;
  8. int num = len / sizeof(uint32_t);
  9. rt_kprintf("num:%d\n", num);
  10. rt_kprintf("len:%d\n", MSGPTR_LEN(p[0])); // 通过msg->id解出参数个数
  11. for(int i = 0; i < num; i++)
  12. {
  13. if(0 == i)
  14. rt_kprintf("0x%08X ", MSGPTR_MSG(p[i])); // 通过msg_id解出参数内容
  15. rt_kprintf("%d ", p[i]);
  16. }
  17. rt_kprintf("\n\n");
  18. }
  19. int elog_test(void)
  20. {
  21. logger = elog_init(arena, sizeof(arena));
  22. ELOG(logger, "Hello world %d\n", 10); // 把字符串和参数放到内存中,(通过字符串 + 长度算法生成msg_id)和会形成一条msg_id和长度
  23. ELOG(logger, "test %d %d %c\n", 1, 2, 3);
  24. elog_flush(logger, log_to_semihost, NULL); // 将内存中的日志刷新到文件,也可以是传输到上位机。也就是之前(字符串和参数)生成的msg_id和长度
  25. return 0;
  26. }