函数1,
void uart_net_send(struct tls_uart *uart, u32 head, u32 tail, int count)
{struct tls_uart_circ_buf *recv = &uart->uart_port->recv;
char *uart_net_send_data = NULL;
uart_net_send_data = malloc(UART_NET_SEND_DATA_SIZE);
memset( uart_net_send_data , 0, UART_NET_SEND_DATA_SIZE);
if (count >= UART_NET_SEND_DATA_SIZE)
{
buflen = UART_NET_SEND_DATA_SIZE;
count = count - UART_NET_SEND_DATA_SIZE;
}
MEMCPY(uart_net_send_data, recv->buf + tail, buflen);
}
函数2,
void uart_net_send(struct tls_uart *uart, u32 head, u32 tail, int count)
{struct tls_uart_circ_buf *recv = &uart->uart_port->recv;
char uart_net_send_data[UART_NET_SEND_DATA_SIZE] = {0};
if (count >= UART_NET_SEND_DATA_SIZE)
{
buflen = UART_NET_SEND_DATA_SIZE;
count = count - UART_NET_SEND_DATA_SIZE;
}
MEMCPY(uart_net_send_data, recv->buf + tail, buflen);
}
函数3,
void uart_net_send(struct tls_uart *uart, u32 head, u32 tail, int count)
{struct tls_uart_circ_buf *recv = &uart->uart_port->recv;
char uart_net_send_data[UART_NET_SEND_DATA_SIZE];
if (count >= UART_NET_SEND_DATA_SIZE)
{
buflen = UART_NET_SEND_DATA_SIZE;
count = count - UART_NET_SEND_DATA_SIZE;
}
MEMCPY(uart_net_send_data, recv->buf + tail, buflen);
}
函数uart_net_send()是一个需要快速运行完毕的函数,它的执行时间越短,设备的转发数据的速度就越快,执行效率就越高。
经实验,在以上三个函数实现中,函数3最慢,函数1最快。