欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

创建task

程序员文章站 2022-03-28 16:28:55
1.定义堆栈存储task的地方static StackType_t aos_loop_proc_stack[1024];2.定义堆栈taskstatic StaticTask_t aos_loop_proc_task;typedef struct xSTATIC_TCB{void*pxDummy1;#if ( portUSING_MPU_WRAPPERS == 1 )xMPU_SETTINGSxDummy2;#endifStaticListItem_tx...
  1. 定义堆栈

存储task的地方

static StackType_t aos_loop_proc_stack[1024];
  1. 定义task
static StaticTask_t aos_loop_proc_task;

下面是FreeRTOS里对task的定义

typedef struct xSTATIC_TCB
{
	void				*pxDummy1;
	#if ( portUSING_MPU_WRAPPERS == 1 )
		xMPU_SETTINGS	xDummy2;
	#endif
	StaticListItem_t	xDummy3[ 2 ];
	UBaseType_t			uxDummy5;
	void				*pxDummy6;
	uint8_t				ucDummy7[ configMAX_TASK_NAME_LEN ];
	#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
		void			*pxDummy8;
	#endif
	#if ( portCRITICAL_NESTING_IN_TCB == 1 )
		UBaseType_t		uxDummy9;
	#endif
	#if ( configUSE_TRACE_FACILITY == 1 )
		UBaseType_t		uxDummy10[ 2 ];
	#endif
	#if ( configUSE_MUTEXES == 1 )
		UBaseType_t		uxDummy12[ 2 ];
	#endif
	#if ( configUSE_APPLICATION_TASK_TAG == 1 )
		void			*pxDummy14;
	#endif
	#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
		void			*pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
	#endif
	#if ( configGENERATE_RUN_TIME_STATS == 1 )
		uint32_t		ulDummy16;
	#endif
	#if ( configUSE_NEWLIB_REENTRANT == 1 )
		struct	_reent	xDummy17;
	#endif
	#if ( configUSE_TASK_NOTIFICATIONS == 1 )
		uint32_t 		ulDummy18;
		uint8_t 		ucDummy19;
	#endif
	#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )
		uint8_t			uxDummy20;
	#endif

	#if( INCLUDE_xTaskAbortDelay == 1 )
		uint8_t ucDummy21;
	#endif
	#if ( configUSE_POSIX_ERRNO == 1 )
		int				iDummy22;
	#endif
} StaticTask_t;
  1. 初始化系统以及系统线程
system_init();
system_thread_init();
  1. 创建线程
TaskHandle_t xTaskCreateStatic(	
	TaskFunction_t pxTaskCode,          //任务函数
	const char * const pcName,		//PC名称/*lint !e971 Unqualified char types are allowed for strings and single characters only. */
									const uint32_t ulStackDepth, //堆栈深度,即堆栈大小
									void * const pvParameters,// 参数
									UBaseType_t uxPriority,//优先级
									StackType_t * const puxStackBuffer, //堆buffer地址
									StaticTask_t * const pxTaskBuffer )//task buffer地址

涉及的数据类型

>TaskFunction_t     void (*TaskFunction_t)( void * )  即任意函数
> uint32_t          long unsigned int
> UBaseType_t       long unsigned int
> StackType_t       long unsigned int
> StaticTask_t      typedef struct xSTATIC_TCB

实例

xTaskCreateStatic(aos_loop_proc, (char*)"event_loop", 1024, NULL, 15, aos_loop_proc_stack, &aos_loop_proc_task);

启动系统调度器

vTaskStartScheduler();

本文地址:https://blog.csdn.net/weixin_44095069/article/details/108580788

相关标签: SDK