porttimer.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: porttimer.c,v 1.60 2013/08/13 15:07:05 Armink $
  20. */
  21. /* ----------------------- Platform includes --------------------------------*/
  22. #include "port.h"
  23. /* ----------------------- Modbus includes ----------------------------------*/
  24. #include "mb.h"
  25. #include "mbport.h"
  26. /* ----------------------- static functions ---------------------------------*/
  27. static struct rt_timer timer;
  28. static void prvvTIMERExpiredISR(void);
  29. static void timer_timeout_ind(void* parameter);
  30. /* ----------------------- Start implementation -----------------------------*/
  31. BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
  32. {
  33. rt_timer_init(&timer, "slave timer",
  34. timer_timeout_ind, /* bind timeout callback function */
  35. RT_NULL,
  36. (50 * usTim1Timerout50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
  37. RT_TIMER_FLAG_ONE_SHOT); /* one shot */
  38. return TRUE;
  39. }
  40. void vMBPortTimersEnable()
  41. {
  42. rt_timer_start(&timer);
  43. }
  44. void vMBPortTimersDisable()
  45. {
  46. rt_timer_stop(&timer);
  47. }
  48. void prvvTIMERExpiredISR(void)
  49. {
  50. (void) pxMBPortCBTimerExpired();
  51. }
  52. static void timer_timeout_ind(void* parameter)
  53. {
  54. prvvTIMERExpiredISR();
  55. }