MQX lite suspend tasks

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MQX lite suspend tasks

1,786件の閲覧回数
danielecortella
Contributor V

Hi,

i have a problem with MQX lite. I have an interrupt that occure when i connect the usb cable. When i connect the usb i have to block two task and activate one other, when i disconnect the cable i have to block this task and re-activate the other two. Mi code is this:

if (USB_ID_GetVal(NULL)) {//se usb collegata

  flag_usb=1;

  _task_abort(task_LCD);

  _task_abort(task_CLOCK);

  } else {//altrimenti

  error = _task_abort(task_USB);

  _task_restart(task_LCD, NULL, 0);

  _task_restart(task_CLOCK, NULL, 0);

  }

the problem is that if i call the _task_abort i can't restart this, what is the best function for block the task in a ISR? I have seen that i can't use the _task_block function. I have to remove the two task from the queue of execution. Thanks

0 件の賞賛
返信
6 返答(返信)

1,337件の閲覧回数
danielecortella
Contributor V

Up,

what is the best solution for suspend the active task and enable one other? Thanks

0 件の賞賛
返信

1,337件の閲覧回数
RadekS
NXP Employee
NXP Employee

I suppose that there is fourth task/ISR which will determine which of task will be blocked. Correct?

I suppose that all three tasks will run in some endless loop. Correct?

I would like to recommend synchronization objects like events, semaphores, mutexes and mainly their lightweight versions…

Simplest way:

I would like to recommend create lwevent group (_lwevent_create()) with 0 as flag parameter (autoclearing is disabled), add to every task loops wait for one from events (_lwevent_wait_xxx()).

In fourth task you can simply clear some of events (_lwevent_clear()) and this way block some of tasks.

After that you can simple set some of events (_lwevent_set()) or restart these task.

I hope it helps you.


Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信

1,337件の閲覧回数
danielecortella
Contributor V

Hi,

in fact i'm using the lwevent in the task but the problem is that when i have to reset the other task this didn't work. I call the function:

_task_restart(task_LCD, NULL, 0);

_task_restart(task_CLOCK, NULL, 0);

_task_restart(task_USB, NULL, 0);

in the task_USB but nothing happen. How i can use this function? Or is better use a task queue for control this? Thanks

0 件の賞賛
返信

1,337件の閲覧回数
RadekS
NXP Employee
NXP Employee

What means nothing happen?

How it looks with your tasks priorities?

Are you sure that restarted tasks could run due to priority?

Did you try for example _sched_yield() or time_delay() for switching between tasks?

0 件の賞賛
返信

1,337件の閲覧回数
danielecortella
Contributor V

My task is this :

void Task4_task(uint32_t task_init_data) {

     if (_lwevent_create(&usb_event,0) != MQX_OK) {

        Error_Task_Init();

    }

   if (_lwevent_wait_ticks(&usb_event, 1, TRUE,0) != MQX_OK) {

         _task_block();

    }

   MSD_Init();//inizializzo libreria USB

  while(flag_usb) {//ciclo di gestione USB

  MSD_Task();

  WAIT_Waitus(10);

  //_time_delay_ticks(10);

  }

  _task_restart(task_LCD, NULL, 0);

  _task_restart(task_CLOCK, NULL, 0);

  _task_restart(task_USB, NULL, 0);

}

i wait in the task until the event is set by an interrupt, after i activate the MSD until the usb cable is connected. After it is remove i exit from the while and i want to reset all the task (this task has the highest priority respect the others)

The problem is that when the command  _task_restart(task_LCD, NULL, 0); is execute i have a PE_ISR(Cpu_Interrupt).

Thanks for the support!!

0 件の賞賛
返信

1,337件の閲覧回数
RadekS
NXP Employee
NXP Employee

The main problem is that when you call _task_restart, you don’t know in which state task_LCD is.

You don’t know if it waiting for some message, if it holds some of semaphores, if it is just in middle of communication with external device, status of drivers, ….

So, I would like to not recommend such using of _task_restart. This could work only in simplest tasks which do “nothing”.

My recommendation:

Tasks as task_LCD have to run in loop and inside this loop have to be dedicated point where we test some condition (global variable/lwevent,…). On base of this condition we will stop this task and after situation change it will continue from this point. Other option is that we can clean all resources used in task and destroy this task (or rather simple return from this task – this will effectively destroy this task) after situation change we can simply call _task_create().