<?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 Re: Understanding _io_read Errors in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339954#M10947</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Scott,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you show on the configuration about the ADC and the task ,&amp;nbsp; also the error ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you can refer to the adc sample under&amp;nbsp; C:\Freescale\Freescale_MQX_4_1_1\mqx\examples (change 4.1 to 4.0,&amp;nbsp; I use MQX4.1, ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;Alice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 25 Sep 2014 03:08:47 GMT</pubDate>
    <dc:creator>Alice_Yang</dc:creator>
    <dc:date>2014-09-25T03:08:47Z</dc:date>
    <item>
      <title>Understanding _io_read Errors</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339953#M10946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I'm using MQX 4.0 and am using _io_read to read values from one the internal ADC modules on a MK10 mirco.&amp;nbsp; My read logic is similar to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;if ( _io_read(...) ) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do something&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;} else {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write error message to console&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Every so often, the _io_read function returns an error value and I get an error message on the console output.&amp;nbsp; I'm having trouble trying to understand what's causing the error &amp;amp; am hoping for some help.&amp;nbsp; How can I translate the return value of the function to a pass/fail value and learn more about why the read failed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's more info:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I'm reading from multiple ADC inputs, and it's not always the same channel which errors out&lt;/LI&gt;&lt;LI&gt;Only one task reads from the ADCs&lt;/LI&gt;&lt;LI&gt;I have higher-priority tasks running, so it's possible my ADC task could be pre-empted during the _io_read process.&amp;nbsp; If so, how would I know this and how could I prevent it?&lt;/LI&gt;&lt;LI&gt;Is there a way to monitor task stack usage, or tell if a task is being continually pre-empted?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2014 20:34:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339953#M10946</guid>
      <dc:creator>ttocsmi</dc:creator>
      <dc:date>2014-09-23T20:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding _io_read Errors</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339954#M10947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Scott,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you show on the configuration about the ADC and the task ,&amp;nbsp; also the error ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you can refer to the adc sample under&amp;nbsp; C:\Freescale\Freescale_MQX_4_1_1\mqx\examples (change 4.1 to 4.0,&amp;nbsp; I use MQX4.1, ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;Alice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Sep 2014 03:08:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339954#M10947</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2014-09-25T03:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Understanding _io_read Errors</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339955#M10948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply, Alice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure exactly what the "error" is, as I'm having difficulty reading and interpreting the return value of the _io_read function.&amp;nbsp; When the "error" occurs, my code enters the "else" branch and I see the message I have within.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This looks to be the relevant code from the adc_demo.c file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* channel 1 sample ready? */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (read(f_ch1, &amp;amp;data, sizeof(data) ))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("ADC ch 1: %4d ", data.result);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking at the comment line, if a sample cannot be read, it's because it is not "ready".&amp;nbsp; Does this imply that there is not necessarily an error, just that it hasn't been acquired/processed yet?&amp;nbsp; If so, then my interpretation of a "failed" read as an "error" is incorrect.&amp;nbsp; Like I stated previously, this does not happen regularly or consistently on any one channel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to determine the reason why the sample isn't ready?&amp;nbsp; What can I do to ensure that when requested, the sample will be ready?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are the configuration/initialization commands for my ADC:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; #define ADC1 "adc1:"&amp;nbsp;&amp;nbsp; /* adc1&amp;nbsp; must be #1 as the inputs are wired to ADC 1 */&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; // ADC configuration parameters&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; #define ADC_HARDWARE_AVERAGING&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&lt;BR /&gt; #define NO_SAMPLE_IN_ONE_RUN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp; // number of samples in one run sequence (orig 32)&lt;BR /&gt; #define START_OFFSET&amp;nbsp;&amp;nbsp;&amp;nbsp; 4400 // time offset from trigger point in us (orig 100); manually tweaked for improved accuracy&lt;BR /&gt; #define PERIOD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30000&amp;nbsp;&amp;nbsp; // period in us (orig 30000)&lt;BR /&gt; #define SCALE_RANGE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10000 // scale range of result (not used now)&lt;BR /&gt; #define CIRCULAR_BUFFER_SIZE&amp;nbsp; 16&amp;nbsp; // circular buffer size (sample count) (orig 32)&lt;BR /&gt; #define ADC_LONG_SAMPLE&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; // long sample time = 2 usec&lt;BR /&gt; #define ADC_REF_VREF&amp;nbsp;&amp;nbsp;&amp;nbsp; 3300&amp;nbsp;&amp;nbsp;&amp;nbsp; // Vref = 3.3 volts&lt;BR /&gt; #define MY_TRIGGER ADC_PDB_TRIGGER&amp;nbsp;&amp;nbsp;&amp;nbsp; // logical trigger ID that starts this ADC channel&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; // global variables&lt;BR /&gt; MQX_FILE_PTR f0, f1;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; // ADC device initialization structure&lt;BR /&gt; const ADC_INIT_STRUCT adc_init = { ADC_RESOLUTION_DEFAULT, /* resolution */&lt;BR /&gt; };&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; //&lt;BR /&gt; // AI_MUX_DA and AI_MUX_DA read together&lt;BR /&gt; //&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; const ADC_INIT_CHANNEL_STRUCT ai_mux_da_param = { AI_MUX_DA, //&amp;nbsp; physical ADC channel &lt;BR /&gt;&amp;nbsp; ADC_CHANNEL_MEASURE_ONCE | ADC_CHANNEL_START_TRIGGERED, &lt;BR /&gt;&amp;nbsp; NO_SAMPLE_IN_ONE_RUN, &lt;BR /&gt;&amp;nbsp; START_OFFSET, &lt;BR /&gt;&amp;nbsp; PERIOD, &lt;BR /&gt;&amp;nbsp; SCALE_RANGE, &lt;BR /&gt;&amp;nbsp; CIRCULAR_BUFFER_SIZE, &lt;BR /&gt;&amp;nbsp; MY_TRIGGER &lt;BR /&gt; };&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; const ADC_INIT_CHANNEL_STRUCT ai_mux_db_param = { AI_MUX_DB, //&amp;nbsp; physical ADC channel &lt;BR /&gt;&amp;nbsp; ADC_CHANNEL_MEASURE_ONCE | ADC_CHANNEL_START_TRIGGERED, &lt;BR /&gt;&amp;nbsp; NO_SAMPLE_IN_ONE_RUN, &lt;BR /&gt;&amp;nbsp; START_OFFSET+100,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // problems occur if both reads occur simultaneously&lt;BR /&gt;&amp;nbsp; PERIOD, &lt;BR /&gt;&amp;nbsp; SCALE_RANGE, &lt;BR /&gt;&amp;nbsp; CIRCULAR_BUFFER_SIZE, &lt;BR /&gt;&amp;nbsp; MY_TRIGGER &lt;BR /&gt; };&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within the main task loop, I'm opening the ADCs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; _mqx_int error_code = MQX_OK;&lt;BR /&gt; &lt;BR /&gt; f1 = _io_fopen(ADC1, (const char*) &amp;amp;adc_init);&lt;BR /&gt; if (f1 != NULL) {&lt;BR /&gt;&amp;nbsp; // long sample time&lt;BR /&gt;&amp;nbsp; error_code = _io_ioctl(f1, ADC_IOCTL_SET_LONG_SAMPLE, (pointer)ADC_LONG_SAMPLE);&lt;BR /&gt;&amp;nbsp; // hardware averaging&lt;BR /&gt;&amp;nbsp; error_code = _io_ioctl(f1, ADC_IOCTL_SET_HW_AVERAGING, (pointer)ADC_HARDWARE_AVERAGING);&lt;BR /&gt;&amp;nbsp; // reference voltage; not sure how this is used&lt;BR /&gt;&amp;nbsp; error_code = _io_ioctl(f1, ADC_IOCTL_SET_REFERENCE,(pointer)ADC_REF_VREF);&lt;BR /&gt;&amp;nbsp; // acquisition speed (was previously HIGH speed&lt;BR /&gt;&amp;nbsp; error_code = _io_ioctl(f1, ADC_IOCTL_SET_LOW_SPEED, NULL);&lt;BR /&gt; } else {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; _task_block();&lt;BR /&gt; }&lt;BR /&gt; _time_delay(OPEN_DELAY);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then opening the individual channels&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; ch_ai_mux_da = _io_fopen(ADC1 "MUX_DA", (const char*) &amp;amp;ai_mux_da_param);&lt;BR /&gt; if (ch_ai_mux_da != NULL) {&lt;BR /&gt; } else {&lt;BR /&gt;&amp;nbsp; _io_printf("Failed to open MUX_DA\n");&lt;BR /&gt;&amp;nbsp; _task_block();&lt;BR /&gt; }&lt;BR /&gt; ch_ai_mux_db = _io_fopen(ADC1 "MUX_DB", (const char*) &amp;amp;ai_mux_db_param);&lt;BR /&gt; if (ch_ai_mux_db != NULL) {&lt;BR /&gt; } else {&lt;BR /&gt;&amp;nbsp; _io_printf("Failed to open MUX_DB\n");&lt;BR /&gt;&amp;nbsp; _task_block();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then triggering&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; _io_ioctl(f1, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER);&lt;BR /&gt; _time_delay(TRIGGER_TIME_DELAY);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then reading (analogLimitCheck is my limit check routine, the BYPASS... statement is the one which started this discussion)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;BR /&gt; if (_io_read(ch_ai_mux_da, &amp;amp;data, sizeof(data))) {&lt;BR /&gt;&amp;nbsp; analogLimitCheck(...);&lt;BR /&gt; } else {&lt;BR /&gt;&amp;nbsp; _io_printf("BYPASS reading ch_ai_mux_da\n");&lt;BR /&gt; }&lt;BR /&gt; if (_io_read(ch_ai_mux_db, &amp;amp;data, sizeof(data))) {&lt;BR /&gt;&amp;nbsp; analogLimitCheck(...);&lt;BR /&gt; } else {&lt;BR /&gt;&amp;nbsp; _io_printf("BYPASS reading ch_ai_mux_da\n");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then closing the channels&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; _io_fclose(ch_ai_mux_da);&lt;BR /&gt; _io_fclose(ch_ai_mux_db);&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;And closing the ADC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;_io_fclose(f1);&lt;BR /&gt;_time_delay(CLOSE_DELAY);&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;========&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if I'm missing anything. I think I got it all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 13:55:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Understanding-io-read-Errors/m-p/339955#M10948</guid>
      <dc:creator>ttocsmi</dc:creator>
      <dc:date>2014-10-07T13:55:54Z</dc:date>
    </item>
  </channel>
</rss>

