Port dimensions

Technical discussions around xCORE processors (e.g. xcore-200 & xcore.ai).
Post Reply
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Port dimensions

Post by Folknology »

Is there a function/macro that I can use in order to determine a port's dimension i.e. is a it a 4,8,16 or 32 bit port?


User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Can't think of a direct way, although looking at the resource ID from xs1_g4000b-512.h would yield a rather neat way of getting that info..

Code: Select all

((ID & 0xFF0000) >> 16) 
Compiler doesn't like resource to int conversions so some inline ASM may be in order...

Code: Select all

/* gpio ports */
#define XS1_PORT_32A 0x200000

#define XS1_PORT_16A 0x100000
#define XS1_PORT_16B 0x100100

#define XS1_PORT_8A 0x80000
#define XS1_PORT_8B 0x80100
#define XS1_PORT_8C 0x80200
#define XS1_PORT_8D 0x80300

#define XS1_PORT_4A 0x40000
#define XS1_PORT_4B 0x40100
#define XS1_PORT_4C 0x40200
#define XS1_PORT_4D 0x40300
#define XS1_PORT_4E 0x40400
#define XS1_PORT_4F 0x40500

#define XS1_PORT_1A 0x10200
#define XS1_PORT_1B 0x10000
#define XS1_PORT_1C 0x10100
#define XS1_PORT_1D 0x10300
#define XS1_PORT_1E 0x10600
#define XS1_PORT_1F 0x10400
#define XS1_PORT_1G 0x10500
#define XS1_PORT_1H 0x10700
#define XS1_PORT_1I 0x10a00
#define XS1_PORT_1J 0x10800
#define XS1_PORT_1K 0x10900
#define XS1_PORT_1L 0x10b00
#define XS1_PORT_1M 0x10c00
#define XS1_PORT_1N 0x10d00
#define XS1_PORT_1O 0x10e00
#define XS1_PORT_1P 0x10f00
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Actually you can avoid inline asm by using unsafe pointers..

Code: Select all

#include <xs1.h>
#include <stdio.h>

out port ports[5] = {XS1_PORT_1A, XS1_PORT_4E, XS1_PORT_8C, XS1_PORT_16B, XS1_PORT_32A};

int main(void){

  port * unsafe p_ptr;
  int width;

  for (int i=0; i< 5; i++){
    unsafe{
      p_ptr = (port * unsafe)&ports[i];
      width = (((int)*p_ptr & 0xff0000) >> 16);
    }
    printf("port width of ports[%d] = %d\n", i, width);
  }
  return 0;
}

Code: Select all

port width of ports[0] = 1
port width of ports[1] = 4
port width of ports[2] = 8
port width of ports[3] = 16
port width of ports[4] = 32
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Are the resource Id's consistent in this manner across architectures G4,LX,200 ?
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

That's OK. Yes - projects built with any target includes xs1.h which includes xs1_g4000b-512.h. So you get the same resource IDs even for L and XC200
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Thanks Infinite, I will implement as unsafe pointer is speed/size not particularly important, it's just used in task initialisation.

regards
AL
Post Reply