porttimer_m.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
  20. */
  21. /* ----------------------- Platform includes --------------------------------*/
  22. #include "port.h"
  23. /* ----------------------- Modbus includes ----------------------------------*/
  24. #include "mb.h"
  25. #include "mb_m.h"
  26. #include "mbport.h"
  27. #include "mbconfig.h"
  28. #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
  29. /* ----------------------- Variables ----------------------------------------*/
  30. static USHORT usT35TimeOut50us;
  31. /* ----------------------- static functions ---------------------------------*/
  32. /* ----------------------- Start implementation -----------------------------*/
  33. BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
  34. {
  35. /* backup T35 ticks */
  36. usT35TimeOut50us = usTimeOut50us * 500;
  37. //MRT_Init(); // this is called outside
  38. return TRUE;
  39. }
  40. void vMBMasterPortTimersT35Enable()
  41. {
  42. MRT1_Start(usT35TimeOut50us);
  43. }
  44. void vMBMasterPortTimersConvertDelayEnable()
  45. {
  46. unsigned int timer_tick = MB_MASTER_DELAY_MS_CONVERT * 1000;
  47. /* Set current timer mode, don't change it.*/
  48. vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
  49. //rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
  50. //rt_timer_start(&timer);
  51. MRT1_Start(timer_tick);
  52. }
  53. void vMBMasterPortTimersRespondTimeoutEnable()
  54. {
  55. unsigned int timer_tick = MB_MASTER_DELAY_MS_CONVERT * 1000;
  56. /* Set current timer mode, don't change it.*/
  57. vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
  58. MRT1_Start(timer_tick);
  59. }
  60. void vMBMasterPortTimersDisable()
  61. {
  62. MRT1_Stop();
  63. }
  64. void prvvMBMasterTIMERExpiredISR(void)
  65. {
  66. (void) pxMBMasterPortCBTimerExpired();
  67. }
  68. #endif