Problem with lwevents on MQXlite

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with lwevents on MQXlite

450 Views
wojciechlesniew
Contributor I

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?

0 Kudos
1 Reply

326 Views
soledad
NXP Employee
NXP Employee

Hello,

For CodeWarrior 10.6, you can find  and example at the path: C:\Freescale\CW MCU v10.6\MCU\CodeWarrior_Examples\Processor_Expert\MQXLite\Kinetis\FRDM_KL25Z\LWEVENT_KL25Z\Sources

Please check the attached example code


Have a great day,
Sol

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

0 Kudos