By Mcuzone
调试串口波特率:115200-uart2
基于MDKK70-EK_T7硬件平台
在指定的空间中创建任务,但只能自定义一个由ABI自动分配的空间,无法做到随意指定地址。
串口输出:
main_task: Test task will create at 0x1fff0098..0x1fff0868 (2000)
test_task: Local var at 0x1fff0838 and param 0x12345678 (teat任务的buf变量地址和入口参数)
PASSED
程序:
#define MAIN_TASK 10
#define TEST_TASK1 11
#define TEST_TASK1_PARAM 0x12345678
extern void main_task(uint_32);
extern void test_task(uint_32);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ MAIN_TASK, main_task, 4000, 9, "Main", MQX_AUTO_START_TASK, 0, 0 },
{ TEST_TASK1, test_task, 0, 8, "test", 0, 0, 0 },
{ 0 }
};
#define TEST_STACK_SIZE 2000
// Should be ABI(应用程序二进制接口) aligned ... cannot do so portably(无法随意定义)....
double test_task_stack[TEST_STACK_SIZE/sizeof(double)];
volatile uint_32 test_task_val = 0;
/*TASK*-------------------------------------------------------------------
*
* Task Name : test_task
* Comments :
* created task
*
*END*----------------------------------------------------------------------*/
void test_task
(
uint_32 param
)
{/* Body */
char buf[8];
buf[7]=1;
test_task_val = 1;
printf("test_task: Local var at 0x%08x and param 0x%08x\n", buf, param);
}/* Endbody */
/*TASK*-------------------------------------------------------------------
*
* Task Name : main_task
* Comments :
* starts up the task at given memory area.
*
*END*----------------------------------------------------------------------*/
void main_task
(
uint_32 param
)
{/* Body */
_task_id tid;
printf("main_task: Test task will create at 0x%08x..0x%08x\n",
test_task_stack, (uchar_ptr)test_task_stack + TEST_STACK_SIZE);
tid = _task_create_at(0, TEST_TASK1, TEST_TASK1_PARAM, test_task_stack,
TEST_STACK_SIZE);
if (tid == MQX_NULL_TASK_ID) {
printf("task create at failed");
_mqx_fatal_error(MQX_INVALID_TASK_ID);
} /* Endif */
if (test_task_val != 1) {
printf("ERROR: test_task_val != 1\n");
} else {
printf("PASSED\n");
}/* Endif */
_task_block();
} /* Endbody */
/* EOF */
在指定的空间中创建任务,但只能自定义一个由ABI自动分配的空间,无法做到随意指定地址。
串口输出:
main_task: Test task will create at 0x1fff0098..0x1fff0868 (2000)
test_task: Local var at 0x1fff0838 and param 0x12345678 (teat任务的buf变量地址和入口参数)
PASSED
程序:
#define MAIN_TASK 10
#define TEST_TASK1 11
#define TEST_TASK1_PARAM 0x12345678
extern void main_task(uint_32);
extern void test_task(uint_32);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ MAIN_TASK, main_task, 4000, 9, "Main", MQX_AUTO_START_TASK, 0, 0 },
{ TEST_TASK1, test_task, 0, 8, "test", 0, 0, 0 },
{ 0 }
};
#define TEST_STACK_SIZE 2000
// Should be ABI(应用程序二进制接口) aligned ... cannot do so portably(无法随意定义)....
double test_task_stack[TEST_STACK_SIZE/sizeof(double)];
volatile uint_32 test_task_val = 0;
/*TASK*-------------------------------------------------------------------
*
* Task Name : test_task
* Comments :
* created task
*
*END*----------------------------------------------------------------------*/
void test_task
(
uint_32 param
)
{/* Body */
char buf[8];
buf[7]=1;
test_task_val = 1;
printf("test_task: Local var at 0x%08x and param 0x%08x\n", buf, param);
}/* Endbody */
/*TASK*-------------------------------------------------------------------
*
* Task Name : main_task
* Comments :
* starts up the task at given memory area.
*
*END*----------------------------------------------------------------------*/
void main_task
(
uint_32 param
)
{/* Body */
_task_id tid;
printf("main_task: Test task will create at 0x%08x..0x%08x\n",
test_task_stack, (uchar_ptr)test_task_stack + TEST_STACK_SIZE);
tid = _task_create_at(0, TEST_TASK1, TEST_TASK1_PARAM, test_task_stack,
TEST_STACK_SIZE);
if (tid == MQX_NULL_TASK_ID) {
printf("task create at failed");
_mqx_fatal_error(MQX_INVALID_TASK_ID);
} /* Endif */
if (test_task_val != 1) {
printf("ERROR: test_task_val != 1\n");
} else {
printf("PASSED\n");
}/* Endif */
_task_block();
} /* Endbody */
/* EOF */
![](https://i-blog.csdnimg.cn/blog_migrate/72e645b1f3a9bd4087a6322976ddb74f.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/f7008e67d1271b94404b20aad49d7f9a.jpeg)
串口输出:
![](https://i-blog.csdnimg.cn/blog_migrate/cb44f16a01e68c2edf30ee46eaf7322a.jpeg)