AnsweredAssumed Answered

Problem with lwevents on MQXlite

Question asked by Wojciech Lesniewicz on Jan 9, 2016
Latest reply on Jan 11, 2016 by soledad

Hi everyone!

I have a problem with MQXlite lightweight events on KL25z. The algorytm looks like this:

 

1) Main task creates two additional tasks, initializes events and mutexes, after all- blocks itself

 

(...)

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

      uart_string("Event create failed\r\n");

      _task_block();

  }else{

      uart_string("Event create OK!\r\n");

  }

  _mutex_init(&my_mutex, NULL);

  _task_block();

  _mqx_exit(0);

 

2) Task1 checks for pressed button and while it's pressed sets event connected to Task2 then unlocks mutex- "if" condition below is in while tasks' loop

 

if(Button)

{

     result = _lwevent_set(&lwevent,K_EVENT);

        

          if(result != MQX_OK)

          {

              uart_string("Event setting failed\r\n");

              _task_block();

          }

          else

          {

               counter++;

              LedR_ClrVal(0);

          }        

             _mutex_unlock(&my_mutex);

}

else

{

     LedR_SetVal(0);

}

 

3) Task2 shall do something and wait for next button press

 

  while(1) {

      counter++;

      result_event = _lwevent_wait_ticks(&lwevent,K_EVENT,TRUE,0);

    

      if(result != MQX_OK){

          sprintf(uart_buf3, "Czekanie na event nie wyszlo, kod bledu 0x%X", result);

          uart_string(uart_buf3);

          _task_block();

      }

    

    _mutex_try_lock(&my_mutex);

     do_sth();

      _lwevent_clear(&lwevent,K_EVENT);

       _mutex_unlock(&my_mutex); 

  

    if(_lwevent_clear(&lwevent,K_EVENT) != MQX_OK){

        uart_string("Event clear failed!\r\n");

        _task_block();

    }

}

 

Such code structure I took from lwevent tutorial written when CW6.3 was availble but I cannot find it now. What am I doing wrong?

Outcomes