UserReadHIDButtons : read port fails Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
bonelli
Member
Posts: 14
Joined: Wed Feb 03, 2021 9:06 pm

UserReadHIDButtons : read port fails

Post by bonelli »

Hello,

I successfully ported the USB audio SW to my custom board. Working with linux and windows with a single stereo output port, 192kHz/24b with a TI DAC.

I'm trying to make the hid function to work. I have some switches connected on tile 0 and declared as follow:

Code: Select all

in port  p_sw1  = on tile[0] : XS1_PORT_4C;  // PREV, SRC, NEXT, ON
in port  p_sw2  = on tile[0] : XS1_PORT_4E;  // PLAY, DST, VOL-, VOL+
in UserReadHIDButtons, the following code does not work:

Code: Select all

    unsigned int sw1, sw2;
    p_sw1 :> sw1;
    p_sw2 :> sw2;
I have random values in sw1 and sw2.

I'm suspecting that UserReadHIDButtons is executed on tile 1, when ports are located on tile 0. Quite strange, because :
- When accessing a port located on tile 1 in this function, the compiler warns
- It didn't warn accessing port on tile 0

=> How can I know the location of a function (tile 0/1) ?

Also, I found in the documentation :
A port is initially OFF with its pins in a high impedance state. Before it is used,
it must be configured to determine the way it interacts with its pins, and set
ON, which also has the effect of starting the port
ok, so how to configure the port ? I'm using an output port without any config, and it works... Basic examples of port usage on the web don't do any config. I found some init functions but only for a more complex usage with clock.

Finally, does someone makes this adaptation of eclipse working ?
- CTRL+H regularly fails
- CTRL+clic almost never works
- right clic + open call hierarchy and other usefull things don't works.
Very bad to debug a spaghetti plate when even the main() is hidden and not visible in the project explorer tab.

Thank you
Regards


View Solution
User avatar
Ross
XCore Expert
Posts: 860
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

What do you have XUD_TILE set to? 0 or 1?

I assume you don't mean fully random numbers in those variables, you should only see the lower 4 bits being set.
bonelli
Member
Posts: 14
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

XUD_TILE = 1.

I'm reading true random 32 bits values, with not only 4 lower bits set. But you are asking for XUD_TILE location, so UserReadHIDButtons may be on tile 1. And I'm reading a port on tile 0 from code on tile 1. This may be the source for my bug, but it's quite strange that the compiler didn't warns about that.

Now I have to learn a lot about the channels/interfaces/... to see how I could transfer data between tiles.
User avatar
fabriceo
Experienced Member
Posts: 94
Joined: Mon Jan 08, 2018 4:14 pm

Post by fabriceo »

Hi Bonelli;
welcome in this journey :)

reading your questions, I d recommend you use xscope and printf inside userreadhid to check whats happen exactly.
FYI, a function is not dedicated to a tile at compilation time. The linker is creating dedicated cpu code for each tile and will potentially put a copy of the function code in that cpu code if it is required. a function can exist in the 2 tile domain but has a single existence in your source code. if you want to trace where the function is executed, you can use this :
printf("core %d:%d ", get_local_tile_id() & 1, get_logical_core_id() )

basic output/input port configuration is made automatically by compiler, you don't need to care about it in XC.
but if you want to be in full control you can use some predefined macros like "set_port_drive"

to report your tile0 port value to the function readhid in tile1, you will need to create a specific I/O task in tile0, declared in main.xc, with a basic interface doing read/write on the local ports. then this interface has to be included in the main.xc and passed as a parameter to buffer() thread, via usb_audio_core(), and then to userreadhid...
you will loose some hairs for sure, but it works (I ve done that for exchanging parameters between a DSP task running on tile 0 and USB host via endpoint0 running on tile 1...)
You could also use another approach, which is to transmit the value of the local I/O port as an additional data word between Audio.xc (DoSampleTransfer) and Decouple.xc(handle_audio_request), but this is another story not for the fainthearted :)

for eclipse, I m using all the shortcut you mentioned and they all work, I m on OSX with 14.4.1 and java 8. Player One Try Again
bonelli
Member
Posts: 14
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

fabriceo wrote: Tue Apr 18, 2023 9:11 am I d recommend you use xscope and printf inside userreadhid to check whats happen exactly.
good idea. printf confirms that UserReadHIDButtons() is located on tile 1.
to report your tile0 port value to the function readhid in tile1, you will need to create a specific I/O task in tile0, declared in main.xc, with a basic interface doing read/write on the local ports. then this interface has to be included in the main.xc and passed as a parameter to buffer() thread, via usb_audio_core(), and then to userreadhid...
you will loose some hairs for sure, but it works
Not a cause for concern, still having a lot :)
bonelli
Member
Posts: 14
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

fabriceo wrote: Tue Apr 18, 2023 9:11 am for eclipse, I m using all the shortcut you mentioned and they all work, I m on OSX with 14.4.1 and java 8. Player One Try Again
Really?
You can "open call hierarchy" for UserReadHIDButtons () to see where it is called?