Skip to content

Commit

Permalink
1、【优化】RTT串口框架中断读取及设置接口。
Browse files Browse the repository at this point in the history
Signed-off-by: armink <[email protected]>
  • Loading branch information
armink committed Nov 13, 2014
1 parent 8a913c8 commit 334f97f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
45 changes: 21 additions & 24 deletions BSP/src/usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
/* USART1 */
#define UART1_GPIO_TX GPIO_Pin_9
#define UART1_GPIO_RX GPIO_Pin_10
#define UART1_GPIO GPIOA
#define UART1_GPIO GPIOA
/* USART1_REMAP */
#define UART1_GPIO_REMAP_TX GPIO_Pin_6
#define UART1_GPIO_REMAP_RX GPIO_Pin_7
#define UART1_GPIO_REMAP GPIOB
#define UART1_GPIO_REMAP_TX GPIO_Pin_6
#define UART1_GPIO_REMAP_RX GPIO_Pin_7
#define UART1_GPIO_REMAP GPIOB

/* USART2 */
#define UART2_GPIO_TX GPIO_Pin_2
#define UART2_GPIO_RX GPIO_Pin_3
#define UART2_GPIO GPIOA
#define UART2_GPIO GPIOA

/* USART3_REMAP[1:0] = 00 */
#define UART3_GPIO_TX GPIO_Pin_10
#define UART3_GPIO_RX GPIO_Pin_11
#define UART3_GPIO GPIOB
#define UART3_GPIO GPIOB

/* STM32 uart driver */
struct stm32_uart
Expand Down Expand Up @@ -95,7 +95,7 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct stm32_uart* uart;
rt_uint32_t *irq_type = (rt_uint32_t *)(arg);
rt_uint32_t irq_type = (rt_uint32_t)(arg);

RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
Expand All @@ -105,12 +105,12 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
/* disable interrupt */
case RT_DEVICE_CTRL_CLR_INT:

if ((*irq_type) == RT_DEVICE_FLAG_INT_RX)
if (irq_type == RT_DEVICE_FLAG_INT_RX)
{
/* disable rx irq */
USART_ITConfig(uart->uart_device, USART_IT_RXNE, DISABLE);
}
else if ((*irq_type) == RT_DEVICE_FLAG_INT_TX)
else if (irq_type == RT_DEVICE_FLAG_INT_TX)
{
/* disable tx irq */
USART_ITConfig(uart->uart_device, uart->tx_irq_type, DISABLE);
Expand All @@ -123,12 +123,12 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
break;
/* enable interrupt */
case RT_DEVICE_CTRL_SET_INT:
if ((*irq_type) == RT_DEVICE_FLAG_INT_RX)
if (irq_type == RT_DEVICE_FLAG_INT_RX)
{
/* enable rx irq */
USART_ITConfig(uart->uart_device, USART_IT_RXNE, ENABLE);
}
else if ((*irq_type) == RT_DEVICE_FLAG_INT_TX)
else if (irq_type == RT_DEVICE_FLAG_INT_TX)
{
/* enable tx irq */
USART_ITConfig(uart->uart_device, uart->tx_irq_type, ENABLE);
Expand All @@ -141,37 +141,34 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
break;
/* get interrupt flag */
case RT_DEVICE_CTRL_GET_INT:
if ((*irq_type) == RT_DEVICE_FLAG_INT_RX)
if (irq_type == RT_DEVICE_FLAG_INT_RX)
{
/* return rx irq flag */
(*irq_type) = USART_GetITStatus(uart->uart_device, USART_IT_RXNE);
return USART_GetITStatus(uart->uart_device, USART_IT_RXNE);
}
else if ((*irq_type) == RT_DEVICE_FLAG_INT_TX)
else if (irq_type == RT_DEVICE_FLAG_INT_TX)
{
/* return tx irq flag */
(*irq_type) = USART_GetITStatus(uart->uart_device, uart->tx_irq_type);
return USART_GetITStatus(uart->uart_device, uart->tx_irq_type);
}
break;
/* get USART flag */
case RT_DEVICE_CTRL_GET_FLAG:
if ((*irq_type) == RT_DEVICE_FLAG_INT_RX)
if (irq_type == RT_DEVICE_FLAG_INT_RX)
{
/* return rx irq flag */
(*irq_type) = USART_GetFlagStatus(uart->uart_device,
USART_FLAG_RXNE);
return USART_GetFlagStatus(uart->uart_device, USART_FLAG_RXNE);
}
else if ((*irq_type) == RT_DEVICE_FLAG_INT_TX)
else if (irq_type == RT_DEVICE_FLAG_INT_TX)
{
/* return tx flag */
if (uart->tx_irq_type == USART_IT_TC)
{
(*irq_type) = USART_GetFlagStatus(uart->uart_device,
USART_FLAG_TC);
return USART_GetFlagStatus(uart->uart_device, USART_FLAG_TC);
}
else if (uart->tx_irq_type == USART_IT_TXE)
{
(*irq_type) = USART_GetFlagStatus(uart->uart_device,
USART_FLAG_TXE);
return USART_GetFlagStatus(uart->uart_device, USART_FLAG_TXE);
}
}
break;
Expand Down Expand Up @@ -445,7 +442,7 @@ void rt_hw_usart_init(void)

#if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
uart = &uart1;
config.baud_rate = BAUD_RATE_9600;
config.baud_rate = BAUD_RATE_115200;

serial1.ops = &stm32_uart_ops;
serial1.config = config;
Expand Down
13 changes: 3 additions & 10 deletions FreeModbus/port/rtt/portserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,18 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
{
rt_uint32_t recved_event;
uint32_t irq_type;
if (xRxEnable)
{
/* waiting for last transmit complete */
while (1)
{
irq_type = RT_DEVICE_FLAG_INT_TX;
serial->ops->control(serial, RT_DEVICE_CTRL_GET_FLAG, &irq_type);
if (irq_type)
if (serial->ops->control(serial, RT_DEVICE_CTRL_GET_FLAG, (void *)RT_DEVICE_FLAG_INT_TX))
{
break;
}
}
/* enable RX interrupt */
irq_type = RT_DEVICE_FLAG_INT_RX;
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, &irq_type);
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
/* switch 485 to receive mode */
SLAVE_RS485_RECEIVE_MODE;
}
Expand All @@ -155,22 +151,19 @@ void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
/* switch 485 to transmit mode */
SLAVE_RS485_TRANS_MODE;
/* disable RX interrupt */
irq_type = RT_DEVICE_FLAG_INT_RX;
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, &irq_type);
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
}
if (xTxEnable)
{
/* start serial transmit */
rt_event_send(&event_serial, EVENT_SERIAL_TRANS_START);
irq_type = RT_DEVICE_FLAG_INT_TX;
}
else
{
/* stop serial transmit */
rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START,
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0,
&recved_event);
irq_type = RT_DEVICE_FLAG_INT_TX;
}
}

Expand Down

0 comments on commit 334f97f

Please sign in to comment.