1515#define THREAD_TIMESLICE 40
1616#define UART_NAME "uart5"
1717
18- /* 消息队列控制块 */
1918static struct rt_messagequeue mesh_mq ;
2019static rt_thread_t mesh_command_tx_thread = RT_NULL ;
2120static rt_thread_t mesh_command_rx_thread = RT_NULL ;
2221static rt_uint8_t thread_priority = 20 ;
23- static rt_device_t serial ; /* 串口设备句柄 */
24- static struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT ; /* 初始化配置参数 */
22+ static rt_device_t serial ;
23+ static struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT ;
2524static struct rt_semaphore rx_sem ;
2625
27- /* 消息队列中用到的放置消息的内存池 */
2826static rt_uint8_t msg_pool [2048 ];
2927
3028void mesh_send_command (command_opcode_t opc , uint16_t addr , uint8_t * data )
@@ -45,10 +43,8 @@ void mesh_send_command(command_opcode_t opc, uint16_t addr, uint8_t *data)
4543 LOG_HEX ("Uart send data" , 11 , command , sizeof (command ));
4644}
4745
48- /* 接收数据回调函数 */
4946static rt_err_t uart_input (rt_device_t dev , rt_size_t size )
5047{
51- /* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
5248 rt_sem_release (& rx_sem );
5349
5450 return RT_EOK ;
@@ -59,17 +55,14 @@ static void mesh_command_tx_thread_entry(void *params)
5955 serial = rt_device_find (UART_NAME );
6056 if (serial != RT_NULL )
6157 {
62- /* 修改串口配置参数 */
6358 config .baud_rate = BAUD_RATE_115200 ;
6459 config .data_bits = DATA_BITS_8 ;
6560 config .stop_bits = STOP_BITS_1 ;
6661 config .bufsz = 128 ;
6762 config .parity = PARITY_NONE ;
6863
69- /* 控制串口设备。通过控制接口传入命令控制字,与控制参数 */
7064 rt_device_control (serial , RT_DEVICE_CTRL_CONFIG , & config );
7165
72- /* 打开串口设备。以中断接收及轮询发送模式打开串口设备 */
7366 rt_device_open (serial , RT_DEVICE_FLAG_INT_RX );
7467
7568 rt_device_set_rx_indicate (serial , uart_input );
@@ -79,7 +72,6 @@ static void mesh_command_tx_thread_entry(void *params)
7972
8073 char command [11 ];
8174
82- /* 从消息队列中接收消息 */
8375 if (rt_mq_recv (& mesh_mq , command , sizeof (command ), RT_WAITING_FOREVER ) == RT_EOK )
8476 {
8577 rt_size_t res = rt_device_write (serial , 0 , command , sizeof (command ));
@@ -136,7 +128,6 @@ static void mesh_command_rx_thread_entry(void *parameter)
136128 uint8_t ch ;
137129 while (rt_device_read (serial , -1 , & ch , 1 ) != 1 )
138130 {
139- /* 阻塞等待接收信号量,等到信号量后再次读取数据 */
140131 rt_sem_take (& rx_sem , RT_WAITING_FOREVER );
141132 }
142133
0 commit comments