2013-11-06 21:47:49 +08:00
|
|
|
/*
|
2015-02-05 19:27:24 +08:00
|
|
|
* FreeModbus Libary: RT-Thread Port
|
2013-11-06 21:47:49 +08:00
|
|
|
* Copyright (C) 2013 Armink <armink.ztl@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* File: $Id: porttimer_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------------- Platform includes --------------------------------*/
|
|
|
|
#include "port.h"
|
|
|
|
|
|
|
|
/* ----------------------- Modbus includes ----------------------------------*/
|
|
|
|
#include "mb.h"
|
|
|
|
#include "mb_m.h"
|
|
|
|
#include "mbport.h"
|
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
|
2013-11-06 21:47:49 +08:00
|
|
|
/* ----------------------- Variables ----------------------------------------*/
|
|
|
|
static USHORT usT35TimeOut50us;
|
2015-02-05 19:27:24 +08:00
|
|
|
static struct rt_timer timer;
|
|
|
|
static void prvvTIMERExpiredISR(void);
|
|
|
|
static void timer_timeout_ind(void* parameter);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
|
|
|
/* ----------------------- static functions ---------------------------------*/
|
|
|
|
static void prvvTIMERExpiredISR(void);
|
|
|
|
|
|
|
|
/* ----------------------- Start implementation -----------------------------*/
|
|
|
|
BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
|
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
/* backup T35 ticks */
|
|
|
|
usT35TimeOut50us = usTimeOut50us;
|
|
|
|
|
|
|
|
rt_timer_init(&timer, "master timer",
|
|
|
|
timer_timeout_ind, /* bind timeout callback function */
|
|
|
|
RT_NULL,
|
|
|
|
(50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND),
|
|
|
|
RT_TIMER_FLAG_ONE_SHOT); /* one shot */
|
|
|
|
|
|
|
|
return TRUE;
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void vMBMasterPortTimersT35Enable()
|
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_tick_t timer_tick = (50 * usT35TimeOut50us)
|
|
|
|
/ (1000 * 1000 / RT_TICK_PER_SECOND);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
/* Set current timer mode, don't change it.*/
|
|
|
|
vMBMasterSetCurTimerMode(MB_TMODE_T35);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_start(&timer);
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void vMBMasterPortTimersConvertDelayEnable()
|
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_tick_t timer_tick = MB_MASTER_DELAY_MS_CONVERT * RT_TICK_PER_SECOND / 1000;
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
/* Set current timer mode, don't change it.*/
|
|
|
|
vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_start(&timer);
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void vMBMasterPortTimersRespondTimeoutEnable()
|
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_tick_t timer_tick = MB_MASTER_TIMEOUT_MS_RESPOND * RT_TICK_PER_SECOND / 1000;
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
/* Set current timer mode, don't change it.*/
|
|
|
|
vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
2013-11-06 21:47:49 +08:00
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_start(&timer);
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void vMBMasterPortTimersDisable()
|
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
rt_timer_stop(&timer);
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void prvvTIMERExpiredISR(void)
|
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
(void) pxMBMasterPortCBTimerExpired();
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
2015-02-05 19:27:24 +08:00
|
|
|
static void timer_timeout_ind(void* parameter)
|
2013-11-06 21:47:49 +08:00
|
|
|
{
|
2015-02-05 19:27:24 +08:00
|
|
|
prvvTIMERExpiredISR();
|
2013-11-06 21:47:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|