适配系统适配层的更新

This commit is contained in:
2026-04-23 14:48:24 +08:00
parent d9873206cc
commit fd4b7ebf9d
10 changed files with 159 additions and 52 deletions

View File

@@ -14,17 +14,17 @@ static has_ptcl_handler *g_handler = NULL;
static void has_receive_from_mcu(const has_tlv_t *box)
{
printf("receive event:%d\n", box->event);
return 0;
return;
}
static void has_receive_from_mcu_1(const has_tlv_t *box)
{
printf("receive event:%d\n", box->event);
return 0;
return;
}
static void has_receive_from_mcu_2(const has_tlv_t *box)
{
printf("receive event:%d\n", box->event);
return 0;
return;
}
int acm_hal_send(uint8_t *buff, uint32_t len)
@@ -47,10 +47,11 @@ void send_fail_callback(has_tlv_t *p_tlv)
printf("event %x send fail\n", p_tlv->event);
}
void *protocol_task(void *param)
static void protocol_task(void *param)
{
int actuall_len;
(void)param;
while (1)
{
/* reads */
@@ -61,7 +62,6 @@ void *protocol_task(void *param)
}
has_sleep_ms(PROCESS_MSG_PERIOD);
}
return NULL;
}
static void msg_handle_cb(unsigned char module_id, const unsigned char *buf, unsigned int len)
@@ -72,9 +72,11 @@ static void msg_handle_cb(unsigned char module_id, const unsigned char *buf, uns
}
void *send_test_task(void *param)
static void send_test_task(void *param)
{
unsigned char data = 3;
(void)param;
while (1)
{
/* write */
@@ -87,6 +89,22 @@ void *send_test_task(void *param)
int example_protocol_init(void)
{
has_protocol_attr attr;
has_task_attr_t protocol_task_attr = {
.name = "acm_read",
.entry = protocol_task,
.arg = NULL,
.stack_size_bytes = 1024U,
.priority = HAS_TASK_PRIORITY_NORMAL,
.linux_attr = { .sched_policy = -1 },
};
has_task_attr_t send_task_attr = {
.name = "acm_send",
.entry = send_test_task,
.arg = NULL,
.stack_size_bytes = 1024U,
.priority = HAS_TASK_PRIORITY_NORMAL,
.linux_attr = { .sched_policy = -1 },
};
kbox_event uart_list[] =
{
{TEST_EVENT, has_receive_from_mcu},
@@ -102,21 +120,35 @@ int example_protocol_init(void)
attr.success_cb = send_success_callback;
attr.fail_cb = send_fail_callback;
if (read_buffer == NULL) {
read_buffer = has_malloc(REC_BUFFER_LEN_MAX);
if (read_buffer == NULL) {
printf("alloc ACM read buffer failed\n");
return -1;
}
}
g_handler = has_protocol_create(&attr);
if (g_handler == NULL)
{
printf("create ACM handler err!\n");
return NULL;
has_free(read_buffer);
read_buffer = NULL;
return -1;
}
printf("module:ACM\n");
/* 创建线程 */
if (has_task_create("read_test", TASK_PRIORITY_NORMAL, 1024, protocol_task, NULL, &protocol_tid) != 0) {
printf("module:WIFI create task failed\n");
if (has_task_create(&protocol_task_attr, &protocol_tid) != 0) {
printf("module:ACM create read task failed\n");
has_protocol_destroy(g_handler);
g_handler = NULL;
has_free(read_buffer);
read_buffer = NULL;
return -1;
}
if (has_task_create("send_test", TASK_PRIORITY_NORMAL, 1024, send_test_task, NULL, &send_test_tid) != 0) {
printf("module:WIFI create task failed\n");
return -1;
if (has_task_create(&send_task_attr, &send_test_tid) != 0) {
printf("module:ACM create send task failed\n");
// return -1;
}
return 0;
}

View File

@@ -8,7 +8,7 @@ static void timer_cb(void *arg)
}
static OS_THREAD_ID gui_tid;
void *gui_task(void *param)
static void gui_task(void *param)
{
(void)param;
uint8_t data[2];
@@ -18,17 +18,25 @@ void *gui_task(void *param)
while (1)
{
has_msg_publish(GUI, data, sizeof(data));
sleep(10);
has_sleep_ms(10000);
}
return NULL;
}
int example_gui_init(void)
{
has_task_attr_t task_attr = {
.name = "gui",
.entry = gui_task,
.arg = NULL,
.stack_size_bytes = 1024U,
.priority = HAS_TASK_PRIORITY_NORMAL,
.linux_attr = { .sched_policy = -1 },
};
printf("module:GUI\n");
/* 创建线程 */
if (has_task_create("wifi", TASK_PRIORITY_NORMAL, 1024, gui_task, NULL, &gui_tid) != 0) {
printf("module:WIFI create task failed\n");
if (has_task_create(&task_attr, &gui_tid) != 0) {
printf("module:GUI create task failed\n");
return -1;
}
return 0;

View File

@@ -39,7 +39,7 @@ int main()
}
while (1) {
sleep(1);
has_sleep_ms(1000);
}
return 0;
}

View File

@@ -7,8 +7,9 @@ void msg_handle_cb(unsigned char module_id, const unsigned char *buf, unsigned i
}
static OS_THREAD_ID wifi_tid;
void *wifi_task(void *param)
static void wifi_task(void *param)
{
(void)param;
uint8_t buffer[10] = {1, 2, 8};
uint8_t data[2];
data[0] = 0x5c;
@@ -25,16 +26,24 @@ void *wifi_task(void *param)
has_msg_handle(WIFI, msg_handle_cb, 1000);
has_msg_publish(WIFI, data, sizeof(data));
}
return NULL;
}
int example_wifi_init(void)
{
has_task_attr_t task_attr = {
.name = "wifi",
.entry = wifi_task,
.arg = NULL,
.stack_size_bytes = 1024U,
.priority = HAS_TASK_PRIORITY_NORMAL,
.linux_attr = { .sched_policy = -1 },
};
printf("module:WIFI\n");
// has_msg_printf_subscribe(WIFI);
/* 创建线程 */
if (has_task_create("wifi", TASK_PRIORITY_NORMAL, 1024, wifi_task, NULL, &wifi_tid) != 0) {
if (has_task_create(&task_attr, &wifi_tid) != 0) {
printf("module:WIFI create task failed\n");
return -1;
}