portevent.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * File : portevent.c
  3. * This file is part of freemodbus in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-04-04 yi.qiu first version
  13. */
  14. /* ----------------------- Modbus includes ----------------------------------*/
  15. #include <rtthread.h>
  16. #include "mb.h"
  17. #include "mbport.h"
  18. /* ----------------------- Variables ----------------------------------------*/
  19. static struct rt_event event;
  20. /* ----------------------- Start implementation -----------------------------*/
  21. BOOL xMBPortEventInit( void )
  22. {
  23. rt_event_init(&event, "modbus", RT_IPC_FLAG_FIFO);
  24. return TRUE;
  25. }
  26. BOOL xMBPortEventPost( eMBEventType eEvent )
  27. {
  28. /* only care abot EV_FRAME_RECEIVED event */
  29. if(eEvent == EV_FRAME_RECEIVED)
  30. {
  31. rt_event_send(&event, 1<<eEvent);
  32. }
  33. return TRUE;
  34. }
  35. BOOL xMBPortEventGet( eMBEventType * eEvent )
  36. {
  37. rt_uint32_t e;
  38. rt_int32_t time_out = 3000/(1000/RT_TICK_PER_SECOND);
  39. if(rt_event_recv(&event, (1<<EV_FRAME_RECEIVED),
  40. RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
  41. time_out, &e) == RT_EOK)
  42. {
  43. *eEvent = EV_FRAME_RECEIVED;
  44. return TRUE;
  45. }
  46. else
  47. {
  48. rt_kprintf("get event timeout\n");
  49. return FALSE;
  50. }
  51. }