luat_msgbus_air101.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_malloc.h"
  4. #include "wm_osal.h"
  5. static tls_os_queue_t *queue = NULL;
  6. void luat_msgbus_init(void)
  7. {
  8. if (queue == NULL)
  9. {
  10. tls_os_queue_create(&queue, 256);
  11. }
  12. }
  13. uint32_t luat_msgbus_put(rtos_msg_t *msg, size_t timeout)
  14. {
  15. if (queue == NULL)
  16. {
  17. return 1;
  18. }
  19. rtos_msg_t* dst = (rtos_msg_t*)luat_heap_malloc(sizeof(rtos_msg_t));
  20. memcpy(dst, msg, sizeof(rtos_msg_t));
  21. int ret = tls_os_queue_send(queue, (void *)dst, sizeof(rtos_msg_t));
  22. return ret;
  23. }
  24. uint32_t luat_msgbus_get(rtos_msg_t *_msg, size_t timeout)
  25. {
  26. if (queue == NULL)
  27. {
  28. return 1;
  29. }
  30. void* msg;
  31. int ret = tls_os_queue_receive(queue, (void **)&msg, sizeof(rtos_msg_t), timeout);
  32. if (ret == TLS_OS_SUCCESS) {
  33. memcpy(_msg, (rtos_msg_t*)msg, sizeof(rtos_msg_t));
  34. luat_heap_free(msg);
  35. return 0;
  36. }
  37. return -1;
  38. }
  39. uint32_t luat_msgbus_freesize(void)
  40. {
  41. if (queue == NULL)
  42. {
  43. return 1;
  44. }
  45. return 1;
  46. }