luat_irq.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "luat_base.h"
  2. #include "luat_irq.h"
  3. #include "luat_msgbus.h"
  4. #include "luat_gpio.h"
  5. #include "luat_uart.h"
  6. #include "luat_malloc.h"
  7. int luat_irq_fire(int tp, int arg, void* args);
  8. int luat_irq_gpio_cb(int pin, void* args) {
  9. rtos_msg_t msg = {0};
  10. msg.handler = l_gpio_handler;
  11. msg.ptr = NULL;
  12. msg.arg1 = pin;
  13. msg.arg2 = luat_gpio_get(pin);
  14. return luat_msgbus_put(&msg, 0);
  15. }
  16. int luat_irq_uart_cb(int id, void* args) {
  17. int len = (int)(args);
  18. rtos_msg_t msg = {0};
  19. msg.handler = l_uart_handler;
  20. msg.ptr = NULL;
  21. msg.arg1 = id;
  22. msg.arg2 = len;
  23. return luat_msgbus_put(&msg, 0);
  24. }
  25. int luat_irq_spi_cb(int id);
  26. static int luat_irq_topic_cb_handler(lua_State *L, void* ptr) {
  27. rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
  28. lua_getglobal(L, "sys_pub");
  29. if (lua_isfunction(L, -1)) {
  30. lua_pushstring(L, msg->ptr);
  31. lua_pushinteger(L, msg->arg1);
  32. lua_pushboolean(L, !msg->arg2);
  33. lua_pushinteger(L, msg->arg2);
  34. lua_call(L, 4, 0);
  35. }
  36. luat_heap_free(msg->ptr);
  37. return 0;
  38. }
  39. //pdata 为 result << 16 | device_id, result 为0 则表示成功,其他失败
  40. //param 为回调topic
  41. int32_t luat_irq_hardware_cb_handler(void *pdata, void *param)
  42. {
  43. rtos_msg_t msg;
  44. msg.handler = luat_irq_topic_cb_handler;
  45. msg.ptr = param;
  46. msg.arg1 = (uint32_t)pdata & 0x0000ffff;
  47. msg.arg2 = ((uint32_t)pdata >> 16);
  48. luat_msgbus_put(&msg, 0);
  49. return 0;
  50. }