Commit 82a509e0 authored by Wenxi XU's avatar Wenxi XU
Browse files

修改sample

parent 74dda82a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -2,5 +2,4 @@

};
&usart6 {
	current-speed = <115200>;
};
 No newline at end of file
+5 −2
Original line number Diff line number Diff line
@@ -4,10 +4,13 @@ CONFIG_USB_DEVICE_STACK=n
# 匹配自定义类驱动中的日志模块名

CONFIG_DUAL_PROPOSE_PROTOCOL=y
# CONFIG_USB_BULK_INTERFACE=y
CONFIG_USB_BULK_INTERFACE=y
CONFIG_UART_INTERFACE=y

CONFIG_MAIN_THREAD_PRIORITY=10

CONFIG_PLOTTER=n
CONFIG_NET_BUF=y

CONFIG_UDC_DRIVER_LOG_LEVEL_INF=y
CONFIG_USBD_LOG_LEVEL_DBG=y
 No newline at end of file
+35 −19
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/net_buf.h>
// #include <ares/interface/usb/usb_bulk.h>
#include <ares/interface/usb/usb_bulk.h>
#include <ares/interface/uart/uart.h>
#include <ares/protocol/dual/dual_protocol.h>
#include <ares/ares_comm.h>
@@ -15,15 +15,27 @@ LOG_MODULE_REGISTER(main_app, LOG_LEVEL_INF);
static const struct device *uart_dev = DEVICE_DT_GET(UART_DEV);

DUAL_PROPOSE_PROTOCOL_DEFINE(dual_protocol);
// ARES_BULK_INTERFACE_DEFINE(usb_bulk_interface);
ARES_UART_INTERFACE_DEFINE(usb_bulk_interface);
DUAL_PROPOSE_PROTOCOL_DEFINE(uart_protocol);
ARES_BULK_INTERFACE_DEFINE(usb_bulk_interface);
ARES_UART_INTERFACE_DEFINE(uart_interface);

int cnt = 0;
void func_cb(uint32_t param1, uint32_t param2, uint32_t param3)
int func_cb(uint32_t param1, uint32_t param2, uint32_t param3)
{
	cnt++;
	// LOG_INF("func_cb");
	// LOG_INF("params: %2x,%2x,%2x", param1, param2, param3);
	LOG_INF("func_cb");
	LOG_INF("params: %2x,%2x,%2x", param1, param2, param3);
	return cnt;
}

void sync_cb(uint32_t status)
{
	LOG_INF("sync_cb: %d", status);
}

void func_ret_cb(uint16_t id, uint16_t req_id, uint32_t ret)
{
	LOG_INF("func_ret_cb: ID %x, req_id %x, ret %x", id, req_id, ret);
}

uint8_t test[59] = {0};
@@ -31,11 +43,13 @@ int main(void)
{
	// Initialize the USB stack and our async pipeline.
	// Pass the function that will handle the data.
	// int err = ares_usbd_init(&usb_bulk_interface);
	ares_uart_init_dev(&usb_bulk_interface, uart_dev);
	// ares_uart_init_dev(&uart_interface, uart_dev);
	int err = ares_bind_interface(&usb_bulk_interface, &dual_protocol);
	dual_func_add(&dual_protocol, 0x1, func_cb);
	sync_table_t *pack = dual_sync_add(&dual_protocol, 0x1, test, sizeof(test), func_cb);
	// err = ares_bind_interface(&uart_interface, &uart_protocol);
	dual_ret_cb_set(&dual_protocol, (dual_func_ret_cb_t)func_ret_cb);
	dual_func_add(&dual_protocol, 0x1, (dual_trans_func_t)func_cb);
	sync_table_t *pack =
		dual_sync_add(&dual_protocol, 0x1, test, sizeof(test), (dual_trans_cb_t)sync_cb);
	if (err) {
		LOG_ERR("Failed to initialize ARES USB device (%d)", err);
		return 0;
@@ -45,17 +59,19 @@ int main(void)

	// The main thread is now free to do other things.
	// All USB data processing happens in the background.
	uint32_t prev_cnt = 0;
	uint32_t prev_time = k_uptime_get_32();
	// uint32_t prev_cnt = 0;
	// uint32_t prev_time = k_uptime_get_32();
	int cnt = 0;
	while (1) {
		k_sleep(K_SECONDS(1));
		k_sleep(K_MSEC(100));
		// dual_sync_flush(&dual_protocol, pack);
		if (prev_time + 1000 < k_uptime_get_32()) {
			// 	// thread_analyzer_print(NULL);
			LOG_INF("cnt: %d, delta: %d", cnt, cnt - prev_cnt);
			prev_time = k_uptime_get_32();
		}
		prev_cnt = cnt;
		dual_func_call(&dual_protocol, 0x1, 0x1, 0x2, cnt);
		// if (prev_time + 1000 < k_uptime_get_32()) {
		// 	// 	// thread_analyzer_print(NULL);
		// 	LOG_INF("cnt: %d, delta: %d", cnt, cnt - prev_cnt);
		// 	prev_time = k_uptime_get_32();
		// }
		// prev_cnt = cnt;

		// You can also call ares_usbd_write() from here to send data proactively.
	}