xref: /nrf52832-nimble/rt-thread/components/net/freemodbus/port/porttimer.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * FreeModbus Libary: RT-Thread Port
3  * Copyright (C) 2013 Armink <[email protected]>
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 
22 /* ----------------------- Platform includes --------------------------------*/
23 #include "port.h"
24 
25 /* ----------------------- Modbus includes ----------------------------------*/
26 #include "mb.h"
27 #include "mbport.h"
28 
29 /* ----------------------- static functions ---------------------------------*/
30 static struct rt_timer timer;
31 static void prvvTIMERExpiredISR(void);
32 static void timer_timeout_ind(void* parameter);
33 
34 /* ----------------------- Start implementation -----------------------------*/
xMBPortTimersInit(USHORT usTim1Timerout50us)35 BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
36 {
37     rt_timer_init(&timer, "slave timer",
38                    timer_timeout_ind, /* bind timeout callback function */
39                    RT_NULL,
40                    (50 * usTim1Timerout50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
41                    RT_TIMER_FLAG_ONE_SHOT); /* one shot */
42     return TRUE;
43 }
44 
vMBPortTimersEnable()45 void vMBPortTimersEnable()
46 {
47     rt_timer_start(&timer);
48 }
49 
vMBPortTimersDisable()50 void vMBPortTimersDisable()
51 {
52     rt_timer_stop(&timer);
53 }
54 
prvvTIMERExpiredISR(void)55 void prvvTIMERExpiredISR(void)
56 {
57     (void) pxMBPortCBTimerExpired();
58 }
59 
timer_timeout_ind(void * parameter)60 static void timer_timeout_ind(void* parameter)
61 {
62     prvvTIMERExpiredISR();
63 }
64