I made a simple program using MQX for FRDM K22F board (Using Kinetis Design Studio), and wanted to have the RGB LED blinking. I wanted to use _time_delay() function to define the LED blinking frequence, but it failed. I found that once I use _time_delay() the code after this instruction is never executed.
Here is my simple program to test _time_delay:
#include <stdio.h>
#include <mqx.h>
#include <bsp.h>
/* Task IDs */
#define INIT_TASK 5
extern void init_task(uint32_t);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{INIT_TASK, init_task, 1500, 9, "init", MQX_AUTO_START_TASK, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};
/*TASK*-----------------------------------------------------
*
* Task Name : init_task
* Comments :
* This task init stuff and then prints "Hello World ".
*
*END*-----------------------------------------------------*/
void init_task (uint32_t initial_data)
{
printf("Hello World\n");
printf("before\n");
_time_delay(0);
printf("after\n");
}
I get both “before” and “after” sent to the hyper terminal, but if I change the time_delay to a non zero value: _time_delay(1); “after” is never printed?
Any idea of what I am doing wrong?
Thanks for your support
已解决! 转到解答。
Hello Jacques,
I tried with the below code using MQX for KDSK 1.1.0 and KDS 2.0. without issues, unfortunately I cannot reproduce this issue.
Could you please try using this code??
/*HEADER**********************************************************************
*
* Copyright 2008 Freescale Semiconductor, Inc.
* Copyright 1989-2008 ARC International
*
* This software is owned or controlled by Freescale Semiconductor.
* Use of this software is governed by the Freescale MQX RTOS License
* distributed with this Material.
* See the MQX_RTOS_LICENSE file distributed for more details.
*
* Brief License Summary:
* This software is provided in source form for you to use free of charge,
* but it is not open source software. You are allowed to use this software
* but you cannot redistribute it or derivative works of it in source form.
* The software may be used only in connection with a product containing
* a Freescale microprocessor, microcontroller, or digital signal processor.
* See license agreement file for full license terms including other
* restrictions.
*****************************************************************************
*
* Comments:
*
* This file contains the source for the hello2 example program.
*
*
*END************************************************************************/
#include <stdio.h>
#include <mqx.h>
#include <bsp.h>
/* Task IDs */
#define HELLO_TASK 5
#define WORLD_TASK 6
extern void hello_task(uint32_t);
extern void world_task(uint32_t);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ WORLD_TASK, world_task, 700, 9, "world", MQX_AUTO_START_TASK, 0, 0 },
{ HELLO_TASK, hello_task, 700, 8, "hello", 0, 0, 0 },
{ 0 }
};
/*TASK*-----------------------------------------------------
*
* Task Name : world_task
* Comments :
* This task creates hello_task and then prints " World ".
*
*END*-----------------------------------------------------*/
void world_task
(
uint32_t initial_data
)
{
_task_id hello_task_id;
hello_task_id = _task_create(0, HELLO_TASK, 0);
if (hello_task_id == MQX_NULL_TASK_ID) {
printf ("\n Could not create hello_task\n");
} else {
printf(" World \n");
}
_task_block();
}
/*TASK*-----------------------------------------------------
*
* Task Name : hello_task
* Comments :
* This task prints " Hello".
*
*END*-----------------------------------------------------*/
void hello_task
(
uint32_t initial_data
)
{
printf("\n Hello\n");
_time_delay(5000);
printf("\n Hello\n");
_time_delay(0);
printf("\n Hello\n");
_task_block();
}
/* EOF */
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------