MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / can_rx_thread

Function can_rx_thread

bsp/hc32/tests/test_can.c:122–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122static void can_rx_thread(void *parameter)
123{
124 struct rt_can_msg rxmsg = {0};
125 rt_size_t size;
126 uint8_t data_len;
127
128 while (1)
129 {
130 rt_memset(&rxmsg, 0, sizeof(struct rt_can_msg));
131 rt_sem_take(&can_rx_sem, RT_WAITING_FOREVER);
132 rt_mutex_take(can_mutex, RT_WAITING_FOREVER);
133 /* hdr 值为 - 1,表示直接从 uselist 链表读取数据 */
134 rxmsg.hdr_index = -1;
135 /* 从 CAN 读取一帧数据 */
136 rt_device_read(can_dev, 0, &rxmsg, sizeof(rxmsg));
137 /* 打印数据 ID 及内容 */
138 rt_kprintf("ID:%x Data:", rxmsg.id);
139 data_len = _get_can_data_bytes_len(rxmsg.len);
140 for (int i = 0; i < data_len; i++)
141 {
142 rt_kprintf("%2x ", rxmsg.data[i]);
143 }
144 rt_kprintf("\n");
145 /* 发送接收到的消息 */
146 size = rt_device_write(can_dev, 0, &rxmsg, sizeof(rxmsg));
147 rt_mutex_release(can_mutex);
148 if (size == 0)
149 {
150 rt_kprintf("can dev write data failed!\n");
151 }
152 }
153}
154
155static void _msh_cmd_set_baud(int argc, char **argv)
156{

Callers

nothing calls this directly

Calls 8

rt_memsetFunction · 0.85
rt_sem_takeFunction · 0.85
rt_mutex_takeFunction · 0.85
rt_device_readFunction · 0.85
rt_kprintfFunction · 0.85
rt_device_writeFunction · 0.85
rt_mutex_releaseFunction · 0.85
_get_can_data_bytes_lenFunction · 0.70

Tested by

no test coverage detected