在线时间36 小时
UID423505
注册时间2013-3-27
NXP金币0
该用户从未签到
高级会员

- 积分
- 651
- 最后登录
- 2020-9-4
|
如下例程,我创建了hello_task为MQX_TIME_SLICE_TASK,时间片为10
hello_task任务中count是不是每隔10ms就自动加1呀???
如果我理解的对的话,那例程怎么不执行呀????
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ SERVER_TASK, server_task, 1000, 8, "server", MQX_AUTO_START_TASK, 0, 0 },
{ CLIENT_TASK, client_task, 1000, 8, "client", 0, 0, 0 },
{ HELLO_TASK, hello_task, 1000, 8, "client", MQX_TIME_SLICE_TASK, 0, 10 },
{ 0 }
};
uint_32 count = 0;
void hello_task
(
uint_32 param
)
{
count++;
if(count>10){
count = 0;
_task_block();
}
}
void server_task
(
uint_32 param
)
{
SERVER_MESSAGE_PTR msg_ptr;
_mqx_uint i;
_queue_id server_qid;
boolean result;
_task_id task_id;
uint_32 time;
_mqx_uint highest_priority;
/* open a message queue */
server_qid = _msgq_open(SERVER_QUEUE, 0);
if (server_qid == 0) {
printf("\nCould not open the server message queue\n");
_task_block();
}
/* create a message pool */
message_pool = _msgpool_create(sizeof(SERVER_MESSAGE),
NUM_CLIENTS, 0, 0);
if (message_pool == MSGPOOL_NULL_POOL_ID) {
printf("\nCount not create a message pool\n");
_task_block();
}
/* create the client tasks */
for (i = 0; i < NUM_CLIENTS; i++) {
task_id = _task_create(0, CLIENT_TASK, (uint_32)i);
if (task_id == 0) {
printf("\nCould not create a client task\n");
_task_block();
}
}
task_id = _task_create(0, HELLO_TASK, 0);
if (task_id == 0) {
printf("\nCould not create a client task\n");
_task_block();
}
while (TRUE) {
msg_ptr = _msgq_receive(server_qid, 0);
if (msg_ptr == NULL) {
printf("\nCould not receive a message\n");
_task_block();
}
printf(" %c \n", msg_ptr->DATA[0]);
/* return the message */
msg_ptr->HEADER.TARGET_QID = msg_ptr->HEADER.SOURCE_QID;
msg_ptr->HEADER.SOURCE_QID = server_qid;
result = _msgq_send(msg_ptr);
if (result != TRUE) {
printf("\nCould not send a message\n");
_task_block();
}
}
}
void client_task
(
uint_32 index
)
{
SERVER_MESSAGE_PTR msg_ptr;
_queue_id client_qid;
boolean result;
client_qid = _msgq_open((_queue_number)(CLIENT_QUEUE_BASE +
index), 0);
if (client_qid == 0) {
printf("\nCould not open a client message queue\n");
_task_block();
}
while (TRUE) {
/*allocate a message*/
msg_ptr = (SERVER_MESSAGE_PTR)_msg_alloc(message_pool);
if (msg_ptr == NULL) {
printf("\nCould not allocate a message\n");
_task_block();
}
msg_ptr->HEADER.SOURCE_QID = client_qid;
msg_ptr->HEADER.TARGET_QID = _msgq_get_id(0, SERVER_QUEUE);
msg_ptr->HEADER.SIZE = sizeof(MESSAGE_HEADER_STRUCT) +
strlen((char_ptr)msg_ptr->DATA) + 1;
msg_ptr->DATA[0] = ('A'+ index);
printf("Client Task %ld\n", index);
result = _msgq_send(msg_ptr);
if (result != TRUE) {
printf("\nCould not send a message\n");
_task_block();
}
/* wait for a return message */
msg_ptr = _msgq_receive(client_qid, 0);
if (msg_ptr == NULL) {
printf("\nCould not receive a message\n");
_task_block();
}
/* free the message */
_msg_free(msg_ptr);
}
}
|
|