[modbus]changed tabs to spaces.
This commit is contained in:
parent
dec67c3a29
commit
b3290f6eed
|
@ -16,7 +16,7 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* File: $Id: portevent.c,v 1.60 2015/02/01 9:18:05 Armink $
|
* File: $Id: port.c,v 1.60 2015/02/01 9:18:05 Armink $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ----------------------- System includes --------------------------------*/
|
/* ----------------------- System includes --------------------------------*/
|
||||||
|
@ -28,11 +28,11 @@ static rt_base_t level;
|
||||||
/* ----------------------- Start implementation -----------------------------*/
|
/* ----------------------- Start implementation -----------------------------*/
|
||||||
void EnterCriticalSection(void)
|
void EnterCriticalSection(void)
|
||||||
{
|
{
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExitCriticalSection(void)
|
void ExitCriticalSection(void)
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,11 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#define INLINE
|
#define INLINE
|
||||||
#define PR_BEGIN_EXTERN_C extern "C" {
|
#define PR_BEGIN_EXTERN_C extern "C" {
|
||||||
#define PR_END_EXTERN_C }
|
#define PR_END_EXTERN_C }
|
||||||
|
|
||||||
#define ENTER_CRITICAL_SECTION() EnterCriticalSection()
|
#define ENTER_CRITICAL_SECTION() EnterCriticalSection()
|
||||||
#define EXIT_CRITICAL_SECTION() ExitCriticalSection()
|
#define EXIT_CRITICAL_SECTION() ExitCriticalSection()
|
||||||
|
|
||||||
typedef uint8_t BOOL;
|
typedef uint8_t BOOL;
|
||||||
|
|
|
@ -133,7 +133,7 @@ void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* switch 485 to transmit mode */
|
/* switch 485 to transmit mode */
|
||||||
rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
|
rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
|
||||||
/* disable RX interrupt */
|
/* disable RX interrupt */
|
||||||
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
|
||||||
* set 485 mode receive and transmit control IO
|
* set 485 mode receive and transmit control IO
|
||||||
* @note MODBUS_MASTER_RT_CONTROL_PIN_INDEX need be defined by user
|
* @note MODBUS_MASTER_RT_CONTROL_PIN_INDEX need be defined by user
|
||||||
*/
|
*/
|
||||||
rt_pin_mode(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
|
rt_pin_mode(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
|
||||||
|
|
||||||
/* set serial name */
|
/* set serial name */
|
||||||
if (ucPORT == 1) {
|
if (ucPORT == 1) {
|
||||||
|
@ -129,12 +129,12 @@ void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
|
||||||
/* enable RX interrupt */
|
/* enable RX interrupt */
|
||||||
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||||
/* switch 485 to receive mode */
|
/* switch 485 to receive mode */
|
||||||
rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_LOW);
|
rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_LOW);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* switch 485 to transmit mode */
|
/* switch 485 to transmit mode */
|
||||||
rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_HIGH);
|
rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_HIGH);
|
||||||
/* disable RX interrupt */
|
/* disable RX interrupt */
|
||||||
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||||
}
|
}
|
||||||
|
@ -154,13 +154,13 @@ void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
|
||||||
|
|
||||||
void vMBMasterPortClose(void)
|
void vMBMasterPortClose(void)
|
||||||
{
|
{
|
||||||
serial->parent.close(&(serial->parent));
|
serial->parent.close(&(serial->parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL xMBMasterPortSerialPutByte(CHAR ucByte)
|
BOOL xMBMasterPortSerialPutByte(CHAR ucByte)
|
||||||
{
|
{
|
||||||
serial->parent.write(&(serial->parent), 0, &ucByte, 1);
|
serial->parent.write(&(serial->parent), 0, &ucByte, 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL xMBMasterPortSerialGetByte(CHAR * pucByte)
|
BOOL xMBMasterPortSerialGetByte(CHAR * pucByte)
|
||||||
|
|
|
@ -54,44 +54,44 @@ BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
|
||||||
|
|
||||||
void vMBMasterPortTimersT35Enable()
|
void vMBMasterPortTimersT35Enable()
|
||||||
{
|
{
|
||||||
rt_tick_t timer_tick = (50 * usT35TimeOut50us)
|
rt_tick_t timer_tick = (50 * usT35TimeOut50us)
|
||||||
/ (1000 * 1000 / RT_TICK_PER_SECOND);
|
/ (1000 * 1000 / RT_TICK_PER_SECOND);
|
||||||
|
|
||||||
/* Set current timer mode, don't change it.*/
|
/* Set current timer mode, don't change it.*/
|
||||||
vMBMasterSetCurTimerMode(MB_TMODE_T35);
|
vMBMasterSetCurTimerMode(MB_TMODE_T35);
|
||||||
|
|
||||||
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
||||||
|
|
||||||
rt_timer_start(&timer);
|
rt_timer_start(&timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vMBMasterPortTimersConvertDelayEnable()
|
void vMBMasterPortTimersConvertDelayEnable()
|
||||||
{
|
{
|
||||||
rt_tick_t timer_tick = MB_MASTER_DELAY_MS_CONVERT * RT_TICK_PER_SECOND / 1000;
|
rt_tick_t timer_tick = MB_MASTER_DELAY_MS_CONVERT * RT_TICK_PER_SECOND / 1000;
|
||||||
|
|
||||||
/* Set current timer mode, don't change it.*/
|
/* Set current timer mode, don't change it.*/
|
||||||
vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
|
vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
|
||||||
|
|
||||||
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
||||||
|
|
||||||
rt_timer_start(&timer);
|
rt_timer_start(&timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vMBMasterPortTimersRespondTimeoutEnable()
|
void vMBMasterPortTimersRespondTimeoutEnable()
|
||||||
{
|
{
|
||||||
rt_tick_t timer_tick = MB_MASTER_TIMEOUT_MS_RESPOND * RT_TICK_PER_SECOND / 1000;
|
rt_tick_t timer_tick = MB_MASTER_TIMEOUT_MS_RESPOND * RT_TICK_PER_SECOND / 1000;
|
||||||
|
|
||||||
/* Set current timer mode, don't change it.*/
|
/* Set current timer mode, don't change it.*/
|
||||||
vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
|
vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
|
||||||
|
|
||||||
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
|
||||||
|
|
||||||
rt_timer_start(&timer);
|
rt_timer_start(&timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vMBMasterPortTimersDisable()
|
void vMBMasterPortTimersDisable()
|
||||||
{
|
{
|
||||||
rt_timer_stop(&timer);
|
rt_timer_stop(&timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void prvvTIMERExpiredISR(void)
|
void prvvTIMERExpiredISR(void)
|
||||||
|
|
|
@ -260,8 +260,8 @@ eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT us
|
||||||
if ((usAddress >= DISCRETE_INPUT_START)
|
if ((usAddress >= DISCRETE_INPUT_START)
|
||||||
&& (usAddress + usNDiscrete <= DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))
|
&& (usAddress + usNDiscrete <= DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))
|
||||||
{
|
{
|
||||||
iRegIndex = (USHORT) (usAddress - usDiscreteInputStart) / 8; //每个寄存器存8个
|
iRegIndex = (USHORT) (usAddress - usDiscreteInputStart) / 8;
|
||||||
iRegBitIndex = (USHORT) (usAddress - usDiscreteInputStart) % 8; //相对于寄存器内部的位地址
|
iRegBitIndex = (USHORT) (usAddress - usDiscreteInputStart) % 8;
|
||||||
|
|
||||||
while (iNReg > 0)
|
while (iNReg > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue