diff --git a/inc/err_num.h b/inc/err_num.h index ac83c8a..0cd0dfb 100644 --- a/inc/err_num.h +++ b/inc/err_num.h @@ -1,12 +1,14 @@ #ifndef __ERR_NUM_H__ #define __ERR_NUM_H__ -#define OSP_OK (0) /* 正常返回 */ -#define OSP_PAR_ILL (1) /* 入参错误 */ -#define OSP_PAR_REP (2) /* 入参重复 */ -#define OSP_QUE_FULL (3) /* 软队列满 */ -#define OSP_QUE_EMPT (4) /* 软队列空 */ -#define OSP_MEM_FULL (5) /* 内存申请失败 */ +#define OSP_OK (0) /* 正常返回 */ +#define OSP_PAR_ILL (1) /* 入参错误 */ +#define OSP_PAR_REP (2) /* 入参重复 */ +#define OSP_QUE_FULL (3) /* 软队列满 */ +#define OSP_QUE_EMPT (4) /* 软队列空 */ +#define OSP_MEM_FULL (5) /* 内存申请失败 */ + +#define OSP_TASK_INIT_ERR (12) /* 任务初始化函数返回失败 */ #endif diff --git a/inc/osp_ape.h b/inc/osp_ape.h index 463c085..d1bb92c 100644 --- a/inc/osp_ape.h +++ b/inc/osp_ape.h @@ -57,7 +57,7 @@ typedef enum OSP_TASK_TYPE /* 函数类型*/ typedef void(*OSP_TASKENTRY_FUNC)(); -typedef void(*OSP_TASKINIT_FUNC)(void); +typedef int(*OSP_TASKINIT_FUNC)(void); /* 任务信息结构体 */ typedef struct OSP_TASK_INFO_EX diff --git a/public/ape_spu/osp/inc/err_num.h b/public/ape_spu/osp/inc/err_num.h index c771719..589b2df 100644 --- a/public/ape_spu/osp/inc/err_num.h +++ b/public/ape_spu/osp/inc/err_num.h @@ -13,6 +13,7 @@ #define OSP_HW_VECT (9) /* 硬件队列获取中断号失败 */ #define OSP_HW_IRQ (10) /* 硬件队列注册中断服务失败 */ #define OSP_HW_EMPTY_ERR (11) /* 硬件队列非空中断使能失败 */ +#define OSP_TASK_INIT_ERR (12) /* 任务初始化函数返回失败 */ #endif diff --git a/public/ape_spu/osp/inc/osp_task.h b/public/ape_spu/osp/inc/osp_task.h index 26cd81a..f0f46c2 100644 --- a/public/ape_spu/osp/inc/osp_task.h +++ b/public/ape_spu/osp/inc/osp_task.h @@ -36,7 +36,7 @@ typedef enum OSP_TASK_TYPE /* 函数类型*/ typedef void(*OSP_TASKENTRY_FUNC)(); -typedef void(*OSP_TASKINIT_FUNC)(void); +typedef int(*OSP_TASKINIT_FUNC)(void); typedef struct osp_task_data{ uint32_t end_flag; /* 0xffff --> end */ @@ -110,7 +110,7 @@ typedef struct tcb_struct int once_value; sem_t *sem; sem_t *event_sem; - void (*init_func)(void); + int (*init_func)(void); void (*loop_fun)(); osp_sw_queue *que_head; // dm space int period; diff --git a/public/ape_spu/osp/src/osp_task.s.c b/public/ape_spu/osp/src/osp_task.s.c index 895c71b..69a6e84 100644 --- a/public/ape_spu/osp/src/osp_task.s.c +++ b/public/ape_spu/osp/src/osp_task.s.c @@ -64,7 +64,7 @@ static void osp_event_task(void *data) { osp_tcb *tcb_val = (osp_tcb*)data; osp_msg_head *ptr = NULL; - (tcb_val->init_func == NULL)? 0:tcb_val->init_func(); + //(tcb_val->init_func == NULL)? 0:tcb_val->init_func(); while(1) { osp_wait_sem(tcb_val->event_sem); @@ -94,7 +94,7 @@ static void osp_mtimer_task(void *data) { osp_tcb *tcb_val = (osp_tcb*)data; //osp_msg_head *ptr = NULLPTR; - (tcb_val->init_func == NULL)? 0:tcb_val->init_func(); + //(tcb_val->init_func == NULL)? 0:tcb_val->init_func(); while(1) { osp_wait_sem(tcb_val->sem); //本文件不要存在os 接口函数 @@ -116,7 +116,7 @@ static void osp_loop_task(void *data) { osp_tcb *tcb_val = (osp_tcb*)data; //osp_msg_head *ptr = NULLPTR; - (tcb_val->init_func == NULL)? 0:tcb_val->init_func(); + //(tcb_val->init_func == NULL)? 0:tcb_val->init_func(); while(1) { osp_delay_cycle(tcb_val->delay_cycle); @@ -141,7 +141,7 @@ static void osp_driver_task(void *data) { osp_tcb *tcb_val = (osp_tcb*)data; osp_msg_head *ptr = NULL; - (tcb_val->init_func == NULL)? 0:tcb_val->init_func(); + //(tcb_val->init_func == NULL)? 0:tcb_val->init_func(); while(1) { osp_delay_cycle(tcb_val->delay_cycle); @@ -171,7 +171,7 @@ static void osp_osp_task(void *data) { osp_tcb *tcb_val = (osp_tcb*)data; osp_msg_head *ptr = NULL; - (tcb_val->init_func == NULL)? 0:tcb_val->init_func(); + //(tcb_val->init_func == NULL)? 0:tcb_val->init_func(); while(1) { osp_delay_cycle(tcb_val->delay_cycle); @@ -480,6 +480,7 @@ malloc_stack_failed: 0x1b: sw_que init failed(event task) 0x1c: timer point is overflow(timer task) 0x1d: os create task failed + 0x1e: task_init return error #21: task id */ int osp_task_create(osp_task_info_ex *t_info_val) @@ -495,6 +496,8 @@ int osp_task_create(osp_task_info_ex *t_info_val) char *stack_top = NULL; void (*ptask_fun)(void *); int ret = -1; + + /* 任务主函数不能为空 */ if(t_info_val->task_entry == NULL) { UCP_PRINT_ERROR("task(%d) entry is none", t_info_val->task_id); @@ -504,6 +507,21 @@ int osp_task_create(osp_task_info_ex *t_info_val) #endif return -OSP_PAR_ILL; } + + /* 若任务有初始化函数,先执行初始化函数 */ + if (t_info_val->task_init != NULL) + { + if (-1 == t_info_val->task_init()) + //if (-1 == ret) + { +#ifdef OSP_DEBUG_TEST + debug_write(OSP_DEBUG_POT(g_ape_id, 20), 0x1e); + debug_write(OSP_DEBUG_POT(g_ape_id, 21), t_info_val->task_id); +#endif + return -OSP_TASK_INIT_ERR; + } + } + if(t_info_val->task_id > TASK_ID_MAX) { UCP_PRINT_ERROR("task(%d) id is error", t_info_val->task_id);