portevent.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * FreeModbus Libary: RT-Thread Port
  3. * Copyright (C) 2013 Armink <armink.ztl@gmail.com>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * File: $Id: portevent.c,v 1.60 2013/08/13 15:07:05 Armink $
  20. */
  21. /* ----------------------- Modbus includes ----------------------------------*/
  22. #include "mb.h"
  23. #include "mbport.h"
  24. /* ----------------------- Variables ----------------------------------------*/
  25. static struct rt_event xSlaveOsEvent;
  26. /* ----------------------- Start implementation -----------------------------*/
  27. BOOL
  28. xMBPortEventInit( void )
  29. {
  30. rt_event_init(&xSlaveOsEvent,"slave event",RT_IPC_FLAG_PRIO);
  31. return TRUE;
  32. }
  33. BOOL
  34. xMBPortEventPost( eMBEventType eEvent )
  35. {
  36. rt_event_send(&xSlaveOsEvent, eEvent);
  37. return TRUE;
  38. }
  39. BOOL
  40. xMBPortEventGet( eMBEventType * eEvent )
  41. {
  42. rt_uint32_t recvedEvent;
  43. /* waiting forever OS event */
  44. rt_event_recv(&xSlaveOsEvent,
  45. EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | EV_FRAME_SENT,
  46. RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
  47. &recvedEvent);
  48. switch (recvedEvent)
  49. {
  50. case EV_READY:
  51. *eEvent = EV_READY;
  52. break;
  53. case EV_FRAME_RECEIVED:
  54. *eEvent = EV_FRAME_RECEIVED;
  55. break;
  56. case EV_EXECUTE:
  57. *eEvent = EV_EXECUTE;
  58. break;
  59. case EV_FRAME_SENT:
  60. *eEvent = EV_FRAME_SENT;
  61. break;
  62. }
  63. return TRUE;
  64. }