mcu_hi3321_watch/tjd/task/task_driver_event.c
2025-05-26 20:15:20 +08:00

128 lines
4.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2020. All rights reserved.
*
* Description: task_driver_event.c
*
* Author: saimen
*
* Create: 2024-4-20
*--------------------------------------------------------------------------*/
//lib
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
//os
#include "securec.h"
#include "common_def.h"
#include "debug_print.h"
#include "soc_osal.h"
#include "cmsis_os2.h"
//sdk
//drv
//user
#include "sys_typedef.h"
#include "sys_config.h"
#include "task_driver_event.h"
/**********************************************************************************************************************
* DEFINE
*/
#define ENABLE_STATIC_PRINT_INFO false
#define ENABLE_STATIC_PRINT_WARN true
#define ENABLE_STATIC_PRINT_ERROR true
#if ENABLE_STATIC_PRINT_INFO
#define static_print_debug(...) sys_common_printf(__VA_ARGS__)
#else
#define static_print_debug(...)
#endif
#if ENABLE_STATIC_PRINT_WARN
#define static_print_warn(...) sys_common_printf(__VA_ARGS__)
#else
#define static_print_warn(...)
#endif
#if ENABLE_STATIC_PRINT_ERROR
#define static_print_error(...) sys_common_printf(__VA_ARGS__)
#else
#define static_print_error(...)
#endif
#define QUEUE_DRIVER_EVENT_COUNT 16
/**********************************************************************************************************************
* VARIABLES
*/
static unsigned long g_queue_driver_event;
static unsigned int *g_task_driver_event_handle;
/**********************************************************************************************************************
* PUBLIC FUNCTIONS
*/
unsigned int *tjd_task_driver_event_get_task_handle(void)
{
return g_task_driver_event_handle;
}
unsigned long tjd_task_driver_event_get_queue_id(void)
{
return g_queue_driver_event;
}
void tjd_task_driver_event_entry(void *param)
{
unused(param);
int32_t ret = OSAL_FAILURE;
queue_default_info_t msg_data;
unsigned int msg_size = sizeof(queue_default_info_t);
while (1) {
(void)memset_s(&msg_data, sizeof(msg_data), 0, sizeof(msg_data));
ret = osal_msg_queue_read_copy(g_queue_driver_event, &msg_data, &msg_size, OSAL_MSGQ_WAIT_FOREVER);
if (ret != OSAL_SUCCESS) {
continue;
}
static_print_debug("queue_driver_event_default_info_t: service_node:0x%X-0x%X-%d\r\n", msg_data.param, msg_data.func_event_handler, msg_data.value);
if(msg_data.func_event_handler) {
ret = msg_data.func_event_handler(msg_data.param);
}
osal_kfree(msg_data.payload);
}
}
void tjd_task_driver_event_init(unsigned short stack_depth, unsigned short priority)
{
osal_msg_queue_create("tjd_q_driver_event", QUEUE_DRIVER_EVENT_COUNT, &g_queue_driver_event, 0, sizeof(queue_default_info_t));
#define APP_MAIN_STACK_SIZE 0x800
#define TASK_PRIORITY_APP (osPriority_t)(osPriorityAboveNormal2)//17
osThreadAttr_t task_attr = { "tjd_t_driver_event", 0, NULL, 0, NULL, APP_MAIN_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 };
if(stack_depth>APP_MAIN_STACK_SIZE){
task_attr.stack_size = stack_depth;
}
if(priority>TASK_PRIORITY_APP){
//task_attr.priority = priority;
}
task_attr.stack_mem = memalign(16, task_attr.stack_size);//add
g_task_driver_event_handle = osThreadNew(tjd_task_driver_event_entry, NULL, &task_attr);
static_print_warn("tjd_task_driver_event_init() END: task-0x%X queue-0x%X-%d\r\n", g_task_driver_event_handle, g_queue_driver_event, sizeof(queue_default_info_t));
}
/**********************************************************************************************************************
* TEST FUNCTIONS
*/
static unsigned long s_test_param;
signed int tjd_task_driver_event_test_handle(void *param)
{
unsigned long *p_param = (unsigned long *)param;
static_print_debug("tjd_task_driver_event_test_handle(): param=%d\r\n", *p_param);
s_test_param++;
return 0; //默认返回0也可以自定义。
}
void tjd_task_driver_event_test_send(void)
{
queue_default_info_t msg_data = { tjd_task_driver_event_test_handle, &s_test_param, NULL, NULL };
osal_msg_queue_write_copy(tjd_task_driver_event_get_queue_id(), (void *)&msg_data, sizeof(queue_default_info_t), 0);
}