Confused on Port and Pin Assignments

New to XMOS and XCore? Get started here.
Post Reply
User avatar
GeorgeIoak
Active Member
Posts: 56
Joined: Wed May 19, 2010 9:42 pm

Confused on Port and Pin Assignments

Post by GeorgeIoak »

I've got myself all confused while trying to study the audio example code (app_usb_aud_xk_216_mc). When I look at the schematic (xCORE-200 Multichannel Audio Platform 2V0 Hardware Manual.pdf) I can see:

X0D26 DSD_MODE
X0D27 DAC_RST_N
...
X0D33 MCLK_FSEL

X0D26:X0D33 are P8B or P4C/P4D

If I look at xk-audio-216-mc.xn I was expecting to see a definition for either of those ports but I don't see them.

So I moved onto the code to see what I could find and in gpio_access.h I find:

Code: Select all

/* General output port bit definitions */
#define P_GPIO_DSD_MODE         (1 << 0) /* DSD mode select 0 = 8i/8o I2S, 1 = 8o DSD*/
#define P_GPIO_DAC_RST_N        (1 << 1)
#define P_GPIO_USB_SEL0         (1 << 2)
#define P_GPIO_USB_SEL1         (1 << 3)
#define P_GPIO_VBUS_EN          (1 << 4)
#define P_GPIO_PLL_SEL          (1 << 5) /* 1 = CS2100, 0 = Phaselink clock source */
#define P_GPIO_ADC_RST_N        (1 << 6)
#define P_GPIO_MCLK_FSEL        (1 << 7) /* Select frequency on Phaselink clock. 0 = 24.576MHz for 48k, 1 = 22.5792MHz for 44.1k.*/
So that looks like the 8-bit port was used but I don't really see that actually defined which confuses me. So I thought I would drill down deeper and take a look at how MCLK_FSEL was used. In audiohw.xc I find:

Code: Select all

#else
    if (mClk == MCLK_441)
    {
        set_gpio(P_GPIO_MCLK_FSEL, 0);
    }
    else
    {
        set_gpio(P_GPIO_MCLK_FSEL, 1); //mClk = MCLK_48
    }
Lastly, if I follow set_gpio I just get myself more confused since I don't see how the port or tile is determined before the actual bit is set.

I'm sure I've just thoroughly confused myself and there's an easy clarification for all of (or at least I hope so). I've gone through some threads and documentation which hasn't helped so I thought someone might be nice enough to get me going down the right path.

Thanks in advance!


User avatar
GeorgeIoak
Active Member
Posts: 56
Joined: Wed May 19, 2010 9:42 pm

Post by GeorgeIoak »

So of course once you post something you find part of what you were missing. I see in audiohw.xc this definition:

Code: Select all

on tile[0] : out port p_gpio = XS1_PORT_8C;
Which ties together the port assignment that I assumed before but missed. I guess I incorrected also thought that your port/pin assignments needed to be in your XN file which I guess is not correct.

I still haven't figured out exactly how set_gpio works but that my lack of understanding of the assembly calls so eother another light bulb will come on for me or somebody will chime in with some help.
User avatar
CousinItt
Respected Member
Posts: 360
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

It looks like the port is assigned globally using p_gpio as you describe.

set_gpio reads the port directly into local variable port_shadow using peek, and then sets or clears one bit before writing the data back to the port. Software locking is used to prevent multiple threads accessing the port simultaneously.
Alinavox
Junior Member
Posts: 6
Joined: Sun Feb 04, 2018 11:58 pm

Post by Alinavox »

Ive been trying to research this topic. I dont really know where to look. ALl i kow is, if you get more people to back you up, you can get more done.


User avatar
Ross
XCore Expert
Posts: 962
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Some asm trickery is used to quickly share that port between cores (thread) in this old codebase. In later code bases we would user interfaces to do the same thing a bit more nicely... we're actually releasing a refreshed USB Audio codebase fairly soon.
bonelli
Member++
Posts: 19
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

Ross wrote: Tue Nov 08, 2022 4:30 pm Some asm trickery is used to quickly share that port between cores (thread) in this old codebase. In later code bases we would user interfaces to do the same thing a bit more nicely... we're actually releasing a refreshed USB Audio codebase fairly soon.
Hello,
Any news about this new codebase? Will santa claus bring it ? :)
User avatar
Ross
XCore Expert
Posts: 962
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

A pre-release is available imminently is my understanding
maxmatteo
Member
Posts: 8
Joined: Wed Dec 30, 2020 8:11 pm
Location: Hamburg

Post by maxmatteo »

Ross wrote: Tue Jan 03, 2023 12:51 pm A pre-release is available imminently is my understanding
Nice, any hints where to find the pre release?
Post Reply