luat_msgbus_air101.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. if (dst == NULL)
  21. {
  22. return 1;
  23. }
  24. memcpy(dst, msg, sizeof(rtos_msg_t));
  25. int ret = tls_os_queue_send(queue, (void *)dst, sizeof(rtos_msg_t));
  26. return ret;
  27. }
  28. uint32_t luat_msgbus_get(rtos_msg_t *_msg, size_t timeout)
  29. {
  30. if (queue == NULL)
  31. {
  32. return 1;
  33. }
  34. void* msg;
  35. int ret = tls_os_queue_receive(queue, (void **)&msg, sizeof(rtos_msg_t), timeout);
  36. if (ret == TLS_OS_SUCCESS) {
  37. memcpy(_msg, (rtos_msg_t*)msg, sizeof(rtos_msg_t));
  38. luat_heap_free(msg);
  39. return 0;
  40. }
  41. return -1;
  42. }
  43. uint32_t luat_msgbus_freesize(void)
  44. {
  45. if (queue == NULL)
  46. {
  47. return 1;
  48. }
  49. return 1;
  50. }