[components][freemodbus] update function : xMBPortSerialInit(...) and xMBMasterPortSerialInit(...) | 更新 xMBPortSerialInit() 与 xMBMasterPortSerialInit() 函数

This commit is contained in:
tangweikang 2019-05-15 12:03:03 +08:00
parent 0dae909f66
commit 3dd64da78b
2 changed files with 49 additions and 31 deletions

View File

@ -52,6 +52,7 @@ static void serial_soft_trans_irq(void* parameter);
BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
eMBParity eParity)
{
rt_device_t dev = RT_NULL;
/**
* set 485 mode receive and transmit control IO
* @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user
@ -60,22 +61,28 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
#endif
/* set serial name */
if (ucPORT == 1) {
#if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
extern struct rt_serial_device serial1;
serial = &serial1;
#endif
} else if (ucPORT == 2) {
#if defined(RT_USING_UART2)
extern struct rt_serial_device serial2;
serial = &serial2;
#endif
} else if (ucPORT == 3) {
#if defined(RT_USING_UART3)
extern struct rt_serial_device serial3;
serial = &serial3;
#endif
if (ucPORT == 1)
{
dev = rt_device_find("uart1");
}
else if (ucPORT == 2)
{
dev = rt_device_find("uart2");
}
else if (ucPORT == 3)
{
dev = rt_device_find("uart3");
}
if(dev == RT_NULL)
{
return FALSE;
}
else
{
serial = (struct rt_serial_device*)dev;
}
/* set serial configure parameter */
serial->config.baud_rate = ulBaudRate;
serial->config.stop_bits = STOP_BITS_1;

View File

@ -53,6 +53,7 @@ static void serial_soft_trans_irq(void* parameter);
BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
eMBParity eParity)
{
rt_device_t dev = RT_NULL;
/**
* set 485 mode receive and transmit control IO
* @note MODBUS_MASTER_RT_CONTROL_PIN_INDEX need be defined by user
@ -60,23 +61,27 @@ BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
#if defined(RT_MODBUS_MASTER_USE_CONTROL_PIN)
rt_pin_mode(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
#endif
/* set serial name */
if (ucPORT == 1) {
#if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
extern struct rt_serial_device serial1;
serial = &serial1;
#endif
} else if (ucPORT == 2) {
#if defined(RT_USING_UART2)
extern struct rt_serial_device serial2;
serial = &serial2;
#endif
} else if (ucPORT == 3) {
#if defined(RT_USING_UART3)
extern struct rt_serial_device serial3;
serial = &serial3;
#endif
if (ucPORT == 1)
{
dev = rt_device_find("uart1");
}
else if (ucPORT == 2)
{
dev = rt_device_find("uart2");
}
else if (ucPORT == 3)
{
dev = rt_device_find("uart3");
}
if(dev == RT_NULL)
{
return FALSE;
}
else
{
serial = (struct rt_serial_device*)dev;
}
/* set serial configure parameter */
serial->config.baud_rate = ulBaudRate;
@ -211,6 +216,12 @@ static void serial_soft_trans_irq(void* parameter) {
RT_WAITING_FOREVER, &recved_event);
/* execute modbus callback */
prvvUARTTxReadyISR();
/* waiting for serial transmit start */
// if (rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,RT_WAITING_FOREVER, &recved_event) == RT_EOK )
// {
// /* execute modbus callback */
// prvvUARTTxReadyISR();
// }
}
}