port.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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: port.c,v 1.60 2015/02/01 9:18:05 Armink $
  20. */
  21. /* ----------------------- System includes --------------------------------*/
  22. /* ----------------------- Modbus includes ----------------------------------*/
  23. #include "port.h"
  24. /* ----------------------- Variables ----------------------------------------*/
  25. static struct rt_semaphore lock;
  26. static int is_inited = 0;
  27. /* ----------------------- Start implementation -----------------------------*/
  28. void EnterCriticalSection(void)
  29. {
  30. rt_err_t err;
  31. if(!is_inited)
  32. {
  33. err = rt_sem_init(&lock, "fmb_lock", 1, RT_IPC_FLAG_PRIO);
  34. if(err != RT_EOK)
  35. {
  36. rt_kprintf("Freemodbus Critical init failed!\n");
  37. }
  38. is_inited = 1;
  39. }
  40. rt_sem_take(&lock, RT_WAITING_FOREVER);
  41. }
  42. void ExitCriticalSection(void)
  43. {
  44. rt_sem_release(&lock);
  45. }