Multiple returns from read-type call to task Topic is solved

If you have a simple question and just want an answer.
User avatar
aclassifier
XCore Expert
Posts: 512
Joined: Wed Apr 25, 2012 8:52 pm

Multiple returns from read-type call to task

Post by aclassifier »

I have found no syntax that the compiler likes to get mulitple return from the read statement in a task.

Code: Select all

typedef interface lib_startkit_adc {
    [[guarded]] void trigger (void);
    [[clears_notification]] {unsigned int, unsigned int} read (unsigned short adc_val[4]);
    [[notification]] slave void complete (void);
} lib_startkit_adc_client_if;
Here's a very stripped down version of what I think about:

Code: Select all

typedef struct tag_startkit_adc_user_vals {
    // ...
    unsigned int adc_cnt;
    unsigned int no_adc_cnt;
} t_startkit_adc_user_vals;

[[combinable]]
void lib_startKIT_adc_client (
    // ..
    server lib_startkit_adc_client_if i_startkit_adc_up)
{
    t_startkit_adc_user_vals adc_vals;
    while(1){
        select{
            // Other cases
            case i_startkit_adc_up.read (unsigned short return_adc_vals[4]) ->
            {int adc_cnt, int no_adc_cnt}: {
                // Fill return vals
                {adc_cnt = adc_vals.adc_cnt; no_adc_cnt = adc_vals.no_adc_cnt}; // ???
            } break;
         } // select
    } // while
}
Multiple returns seem to be bounded with a true "return" statement. That is not the way to return values from a read like this, as I assume that would stop the task? I have tried several syntax suggestions above, but none of which compiles. And found no reference to this(?) From the XMOS Programming Guide "5.1.4 Multiple returns", showing the syntax:

Code: Select all

{int, int} swap(int a, int b) {
    return {b, a}; 
}
int x = 5, y = 7; 
{x, y} = swap(x, y);
Return of values in this case is not the same as return of the task with value. The term "return" has several meanings in XC(?)

Right now I don't think this is possible. But then I haven't seen that excluded in the XMOS Programming Guide, either. But also, I can't see why it should not be possible?
View Solution
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1164
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

HI,
I think the issue is that you are trying to assign both return values in the same statement using a similar structure to the return syntax.

I can see the logic in that, but it's not the way the compiler expects things. The key thing is that the return values are declared and exist within the scope of the select case. At the end of this case, the values within the variables are returned implicitly.

So your syntax should be:

Code: Select all

// Fill return vals
adc_cnt = adc_vals.adc_cnt;
no_adc_cnt = adc_vals.no_adc_cnt;
break;
or if you prefer...

Code: Select all

// Fill return vals
{adc_cnt = adc_vals.adc_cnt; no_adc_cnt = adc_vals.no_adc_cnt;}
break;
User avatar
aclassifier
XCore Expert
Posts: 512
Joined: Wed Apr 25, 2012 8:52 pm

Post by aclassifier »

Thanks a lot!

I was so close, but filling of the return values was obviously just two statements, not any set-type syntax as I fiddled with. So when the semicolon came on the correct side of the end curly bracket it compiled fine.

However, the syntax is shown as erroneous even if it compiles:

Code: Select all

#define NUM_STARTKIT_ADC_INPUTS 4
typedef interface lib_startkit_adc {
    [[guarded]] void trigger (void);
    [[clears_notification]] {unsigned int, unsigned int} read (unsigned short adc_val[NUM_STARTKIT_ADC_INPUTS]);
} lib_startkit_adc_client_if;
See attached screen clip. It doesn't seem to like the {unsigned int, unsigned int}(?)
You do not have the required permissions to view the files attached to this post.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

This looks like a separate issue that I am just looking into....
robert
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi aclassifier,

I believe this is a compiler bug that is emitting incorrect assembler directives.

A quick way to fix this now, is to simply remove the offending lines from the assembly files, and continue the build from there.
To do this, change your 'Makefile' to have "-save-temps -v" in the 'XCC_FLAGS' (this will make the console output verbose and the intermediate .s files will be kept).
If you can then upload the verbose console output and a zip of the '.build' directory, I will reply with a suitable command to run.

robert
User avatar
aclassifier
XCore Expert
Posts: 512
Joined: Wed Apr 25, 2012 8:52 pm

Post by aclassifier »

Robert

The verbose build log is attached. The project zip was too large. Find it here: http://www.teigfam.net/oyvind/div/. I will remove it when you have dowloaded it. Please tell.

I now have both "Internal compiler error #8810" and this point reported, so I certainly hope for a new compiler. I'd be glad to beta-test.
You do not have the required permissions to view the files attached to this post.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

I've downloaded the files but I am getting errors:

Creating dependencies for Aquarium.xc
../src/Aquarium.xc:27: error: Can't open include file "lib_startkit_adc_client.h"
#include "lib_startkit_adc_client.h"
User avatar
aclassifier
XCore Expert
Posts: 512
Joined: Wed Apr 25, 2012 8:52 pm

Post by aclassifier »

robertxmos wrote:I've downloaded the files but I am getting errors:

Creating dependencies for Aquarium.xc
../src/Aquarium.xc:27: error: Can't open include file "lib_startkit_adc_client.h"
#include "lib_startkit_adc_client.h"
I did have a "lib" for it, but moved the two files into Aquarium. They are in the zip you received. One of the screen clips I sent (with the syntax error of the interface) showed the lib_startkit_adc_client.h. Don't know why it complained for you.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

I have not been able to confirm, but this looks like a known bug that has been fixed in the next release - available shortly.

I expect the work around will be to create a file 'src/globl_bug_fix.S' with the contents:
  • .set lib_startKIT_adc_client.select.y.enable.cases,0
    .globl lib_startKIT_adc_client.select.y.enable.cases
User avatar
aclassifier
XCore Expert
Posts: 512
Joined: Wed Apr 25, 2012 8:52 pm

Post by aclassifier »

robertxmos wrote:I have not been able to confirm, but this looks like a known bug that has been fixed in the next release - available shortly.

I expect the work around will be to create a file 'src/globl_bug_fix.S' with the contents:
  • .set lib_startKIT_adc_client.select.y.enable.cases,0
    .globl lib_startKIT_adc_client.select.y.enable.cases
Great, at the moment I can't run my filter task. And don't know how to program around.

By the way, what is a nn.S file? Some kind of script or patch or linker command file? Here the problem seems to be that the field has not been exported. How do I know that the first bullet has value 0 and not 3.14?