Is it possible to create two different timers and their priorities are different?
For example.
timer 1: the period is 5ms and the priority is 2.
timer 2: the period is 5ms and the priority is 5.
Hello Robin,
Do you want to use hardware timers in MQX?
or do you want to use only a time delay???
Regards
Sol
Hello soledad,
I want to create two tasks.The two tasks work in period and their priotrities are different.
tasks1:the period is 5ms and the priority is 2.
tasks2:the period is 10ms and the priority is 5.
Is it possible to realize it by using the timer in the MQX?
If not,can you tell me how to realize it?
Best regards.
Robin.
Hello Robin,
Please check the below example code and let me know if this helps!!
For this example I have 2 tasks ( MAIN_TASK and TASK_2 ) these task have different priority (MAIN_TASK priority 9 and TASK_2 priority 12)
both tasks have a while (1) but both tasks have a time_delay, this time_delay blocks the calling task.
#define MAIN_TASK 1
#define TASK_2 2
extern void Main_task(uint32_t);
extern void task_2(uint32_t);
TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task number, Entry point, Stack, Pri, String, Auto? */
{MAIN_TASK, Main_task, 1500, 9, "main", MQX_AUTO_START_TASK},
{TASK_2, task_2, 1500, 12, "main", MQX_AUTO_START_TASK},
{0, 0, 0, 0, 0, 0, }
};
/*TASK*-----------------------------------------------------
*
* Task Name : Main_task
* Comments :
* This task prints " Hello World "
*
*END*-----------------------------------------------------*/
void Main_task(uint32_t initial_data)
{
printf("\n Hello World \n");
LWGPIO_STRUCT led1;
lwgpio_init(&led1, BSP_LED1, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE );
lwgpio_set_functionality(&led1, BSP_LED1_MUX_GPIO );
while (1)
{
_time_delay(10);
lwgpio_toggle_value(&led1);
}
printf("\n Hello World \n");
_mqx_exit(0);
}
void task_2(uint32_t initial_data)
{
printf("\n Hello World \n");
LWGPIO_STRUCT led2;
lwgpio_init(&led2, BSP_LED2, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE );
lwgpio_set_functionality(&led2, BSP_LED2_MUX_GPIO );
while (1)
{
_time_delay(5);
lwgpio_toggle_value(&led2);
}
printf("\n Hello World \n");
_mqx_exit(0);
}
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you for your help.
I still have the other two questions.
_mqx_int hwtimer_init
(
HWTIMER_PTR hwtimer,
const HWTIMER_DEVIF_STRUCT_PTR devif,
uint32_t id,
uint32_t int_priority
)
Hello Robin,
Sorry for my long delay. Please see below my answers:
1.How many hardware timers can I use in the MQX? My hardware is MK64F12.
In the BSP you can find the file:twrk64f120m
This file contains the definitions for 2 hardware timers (PIT and LPT) please check the code below.
/* HWTIMER definitions for user applications */
#define BSP_HWTIMER1_DEV pit_devif
#define BSP_HWTIMER1_SOURCE_CLK (CM_CLOCK_SOURCE_BUS)
#define BSP_HWTIMER1_ID (0)
#define BSP_HWTIMER2_DEV lpt_devif
#define BSP_HWTIMER2_SOURCE_CLK (CM_CLOCK_SOURCE_LPO)
#define BSP_HWTIMER2_ID (0)
2.What is the parameter “id” is used to do in the
function “hwtimer_init()”?
id-Numerical identifier of the timer within one timer module. The meaning of the numerical identifier varies depending on the low layer driver used. Typically, it identifies a particular timer channel to initialize.
Is it possible to set different priorities for one hardware timer device?
Yes, you can set the priority in the function “hwtimer_init()” the parameter is "uint32_t int_priority"
I developed an example for you using the lpt, the example toggle a led for every lpt interrupt (1sec)
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------