<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Best way to pass simple data into a task in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Best-way-to-pass-simple-data-into-a-task/m-p/458146#M15407</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a question about the best way to pass data into a task. I understand there is a message system for tasks, but I think the message system may be a bit overkill for what I'm trying to do. I have a board with multiple temperature sensors and I select which temperature sensor to read data from through a parameter I pass to 'temperatureRead' (see highlighted in red below). For example, to read temperature data from device 0, I call 'temperatureRead( 0 )'. To read temperature data from device 1, I call 'temperatureRead( 1 )'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is whether or not my use of a global variable to specify the device (device 0, 1, 2, 3, 4, etc.) is the best way to accomplish what I am trying to accomplish. I like to avoid using global variables, but I also want a solution that is relatively simple.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void Temperature_task( uint32_t initial_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; void *event_ptr; // Events are used to block tasks when not needed&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_event_open("event.global", &amp;amp;event_ptr) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; //TODO error message&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(TRUE)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Go onto standby until a temp event is triggered&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_event_wait_all_ticks(event_ptr, TEMP_EVENT_MASK, 0) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("\nEvent Wait failed");&lt;/P&gt;&lt;P&gt;&amp;nbsp; _task_block();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Lock the MUTEX to prevent too much communication across the I2C bus&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_mutex_lock(&amp;amp;i2c_mutex) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("Mutex lock failed.\n");&lt;/P&gt;&lt;P&gt;&amp;nbsp; _task_block();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;temperatureRead( globalVariable );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _mutex_unlock(&amp;amp;i2c_mutex); // Unlock the I2C MUTEX so that other tasks can use the I2C bus&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Clear the event&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_event_clear(event_ptr, TEMP_EVENT_MASK) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; //TODO error message&lt;/P&gt;&lt;P&gt;&amp;nbsp; } // end if( _event ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; } // end while(TRUE)&lt;/P&gt;&lt;P&gt;} // end Temperature_task&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Mitty&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Aug 2015 21:15:58 GMT</pubDate>
    <dc:creator>mittymcdoogle</dc:creator>
    <dc:date>2015-08-21T21:15:58Z</dc:date>
    <item>
      <title>Best way to pass simple data into a task</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Best-way-to-pass-simple-data-into-a-task/m-p/458146#M15407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a question about the best way to pass data into a task. I understand there is a message system for tasks, but I think the message system may be a bit overkill for what I'm trying to do. I have a board with multiple temperature sensors and I select which temperature sensor to read data from through a parameter I pass to 'temperatureRead' (see highlighted in red below). For example, to read temperature data from device 0, I call 'temperatureRead( 0 )'. To read temperature data from device 1, I call 'temperatureRead( 1 )'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is whether or not my use of a global variable to specify the device (device 0, 1, 2, 3, 4, etc.) is the best way to accomplish what I am trying to accomplish. I like to avoid using global variables, but I also want a solution that is relatively simple.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void Temperature_task( uint32_t initial_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; void *event_ptr; // Events are used to block tasks when not needed&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_event_open("event.global", &amp;amp;event_ptr) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; //TODO error message&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(TRUE)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Go onto standby until a temp event is triggered&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_event_wait_all_ticks(event_ptr, TEMP_EVENT_MASK, 0) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("\nEvent Wait failed");&lt;/P&gt;&lt;P&gt;&amp;nbsp; _task_block();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Lock the MUTEX to prevent too much communication across the I2C bus&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_mutex_lock(&amp;amp;i2c_mutex) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf("Mutex lock failed.\n");&lt;/P&gt;&lt;P&gt;&amp;nbsp; _task_block();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;temperatureRead( globalVariable );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _mutex_unlock(&amp;amp;i2c_mutex); // Unlock the I2C MUTEX so that other tasks can use the I2C bus&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Clear the event&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (_event_clear(event_ptr, TEMP_EVENT_MASK) != MQX_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; //TODO error message&lt;/P&gt;&lt;P&gt;&amp;nbsp; } // end if( _event ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; } // end while(TRUE)&lt;/P&gt;&lt;P&gt;} // end Temperature_task&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Mitty&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Aug 2015 21:15:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Best-way-to-pass-simple-data-into-a-task/m-p/458146#M15407</guid>
      <dc:creator>mittymcdoogle</dc:creator>
      <dc:date>2015-08-21T21:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to pass simple data into a task</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Best-way-to-pass-simple-data-into-a-task/m-p/458147#M15408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mitty,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the Mutex example shows how to pass parameters form a task to another. Please refer to the attached file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have any question please let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Carlos&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:19:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Best-way-to-pass-simple-data-into-a-task/m-p/458147#M15408</guid>
      <dc:creator>Carlos_Musich</dc:creator>
      <dc:date>2015-08-27T18:19:12Z</dc:date>
    </item>
  </channel>
</rss>

