XK-1A, pin by pin?

New to XMOS and XCore? Get started here.
New User
Posts: 3
Joined: Mon Mar 19, 2012 7:27 am

XK-1A, pin by pin?

Postby tevious » Tue Mar 20, 2012 1:27 am


I'm working on the XK-1A dev board and I'm trying to make a first software layer.
Actually, I know how to set the ports, what's the configuration etc...

What I'd like to do is simple, a easy library to set pinmode, to set pin output and to read pin input.

An example could be:

pinMode(8,1) // set pin XD8 as an output pin
pinMode(7,0) // set pin XD7 as an input pin

then using my library to read and set pin, using what I've just written:

pin(8,0); // make lower state to pin XD8
pin(8,1); // make higher state to pin XD8

int myvar=read(7); // set the content of mywar as the state of pin XD7

I know that Arduino use such a system and in the past my teacher made a similar library for microprocessor Siemens.

Can somebody say me if such a library already exist?

For the moment, I'm stuck on several problems:
Firstly, there are only some ports which are 1 bit port... If I want to make a pin by pin setting, how could I set the pins when the port is more than a 1 bit port? (typically, I can set pins XD2 to XD9 by writting: out port mypins=XS1_PORT_8A, but could I set some of these pins as an input in this case?)

Then, I don't know a priori what will be the setting, so could I make 2 declarations and keep what my users will keep:


int type_port8A=0; // 0 if port is an input, 1 if it's an output
out port port8A_out=XS1_PORT_8A;
in port port8A_out=XS1_PORT_8A;
And then I will based what port I use relying on the content of my int?

Finally, could I read the port like that or not? (it's seems to be easy, but I don't know if it's legal)
=> in port myport=XS1_PORT_8A;
int myval=0;
myval= myport & 0b00000001; // to read the pin XD2

Thanks a lot!
User avatar
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Postby paul » Tue Mar 20, 2012 11:35 am

I would recommend you consult the XC Programming Guide. This will explain how to use the ports and write software for them.

What you want to do doesn't quite fit with how the XMOS architecture does things with it's pins - I recommend you take a look through the documentation before embarking on producing a library like you are suggesting to ensure you understand how XMOS ports work :D

On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
New User
Posts: 3
Joined: Mon Mar 19, 2012 7:27 am

Postby tevious » Tue Mar 20, 2012 2:30 pm


Thanks for your reply! I will read this document seriously before starting something!

Who is online

Users browsing this forum: No registered users and 2 guests