AnsweredAssumed Answered

watchdog for roundrobin tasks

Question asked by amleng on Aug 7, 2012
Latest reply on Sep 24, 2014 by Vinod Ganesh

Hi ,

I wrote a sample code (please see the attachment) to use  watchdog timer for two roundrabin tasks. when I have only one task (e.g. only simulated_ISR_task_1) it  works well but when I add the second task  (simulated_ISR_task_2) it stops work. I've check the MQX  plugin tool. it didn't show any error or something wrong! any
suggestion?

 

Regards

 

#include <mqx.h>
#include <bsp.h>
#include <event.h>
#include <watchdog.h>

 

/* Task IDs */
#define MAIN_TASK 5
#define ISR_1_TASK 6
#define ISR_2_TASK 7

/* Function prototypes */
extern void simulated_ISR_task_1(uint_32);
extern void simulated_ISR_task_2(uint_32);
extern void main_task(uint_32);
extern void handle_watchdog_expiry_1(pointer);
extern void handle_watchdog_expiry_2(pointer);

const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ MAIN_TASK, main_task, 2000, 8, "service", MQX_AUTO_START_TASK, 0, 0 },
{ ISR_1_TASK, simulated_ISR_task_1, 2000, 9, "simulated_ISR1", MQX_TIME_SLICE_TASK, 0, 1 },
{ ISR_2_TASK, simulated_ISR_task_2, 2000, 9, "simulated_ISR2", MQX_TIME_SLICE_TASK, 0, 1 },
{ 0 } };

/*TASK*-----------------------------------------------------
*
* Task Name : simulated_ISR_task
* Comments :
* This task opens a connection to the event group. After
* delaying, it sets the event bits.
*END*-----------------------------------------------------*/

void handle_watchdog_expiry_1(pointer td_ptr)
{
pointer event_ptr;
_mqx_uint event_bits;

printf("expire_1\n\r");
fflush(stdout);
}

void handle_watchdog_expiry_2(pointer td_ptr)
{
pointer event_ptr;
_mqx_uint event_bits;

printf("expire_2\n\r");
fflush(stdout);
}

void simulated_ISR_task_1(uint_32 initial_data)
{
pointer event_ptr;
MQX_TICK_STRUCT ticks;
_mqx_uint result;

_time_init_ticks(&ticks, 10);

result = _watchdog_create_component(BSP_TIMER_INTERRUPT_VECTOR,
handle_watchdog_expiry_1);

printf(" restart1 \n");

while (TRUE)
{
result = _watchdog_start_ticks(&ticks);
_time_delay(100);
_watchdog_stop();
}
}

void simulated_ISR_task_2(uint_32 initial_data)
{
pointer event_ptr;
MQX_TICK_STRUCT ticks;
_mqx_uint result;

_time_init_ticks(&ticks, 10);

result = _watchdog_create_component(BSP_TIMER_INTERRUPT_VECTOR,
handle_watchdog_expiry_2);

printf(" restart2 \n");

while (TRUE)
{
result = _watchdog_start_ticks(&ticks);
_time_delay(100);
_watchdog_stop();
}
}

/*TASK*-----------------------------------------------------
*
* Task Name : service_task
* Comments :
* This task creates an event group and the simulated_ISR_task
* task. It opens a connection to the event group and waits.
* After the appropriate event bit has been set, it clears
* the event bit and prints "Tick."
*END*-----------------------------------------------------*/

void main_task(uint_32 initial_data)
{
pointer event_ptr;
_task_id task_id_1, task_id_2;
_mqx_uint event_bits;

/* Create the ISR task */
task_id_1 = _task_create(0, ISR_1_TASK, 0);
if (task_id_1 == MQX_NULL_TASK_ID)
{
printf("Could not create simulated_ISR1_task \n");
_task_block();
}

/* Create the ISR task */
task_id_2 = _task_create(0, ISR_2_TASK, 0);
if (task_id_2 == MQX_NULL_TASK_ID)
{
printf("Could not create simulated_ISR2_task \n");
_task_block();
}

while (TRUE)
{
_time_delay(1000);
}
}

/* EOF */

 

Outcomes