Reconfigure ports

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm
Contact:

Reconfigure ports

Post by AtomSoft »

OK i saw an example and want to know would this work?

Basically Port 4D is my Lower Nibble and Port 4C is my Upper Nibble... I want to be able to switch from output to input and back again on the 4bit wide ports.

Code: Select all

out port pU = XS1_PORT_4C;
out port pL = XS1_PORT_4D;

out port * moveable ppU = &pU;
out port * moveable ppL = &pL;

in port:4 * movable p_IN_UPPER;
in port:4 * movable p_IN_LOWER;

//then use this to set to INPUT
p_IN_UPPER = reconfigure_port(move(ppU), in port:4);
p_IN_LOWER = reconfigure_port(move(ppL), in port:4);


//This to set back to output
ppU = reconfigure_port(move(p_IN_UPPER), out port);
ppL = reconfigure_port(move(p_IN_LOWER), out port);


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

After you output to a port, it drives the pins; when you input
from a port, it stops driving. In XC you need to declare the
port as "port" (not "out port" or "in port") or the compiler
won't let you change direction on it.
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm
Contact:

Post by AtomSoft »

My info was from here:

https://www.xmos.com/en/node/17091?page=12

Last section....

So you are saying i should do this:

Code: Select all

port pU = XS1_PORT_4C;
port pL = XS1_PORT_4D;
instead ?
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

If you use buffered ports you should do the reconfiguration
thing. Things are much simpler if you use simple synchronous
ports; can you? I assumed you did but misread.
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm
Contact:

Post by AtomSoft »

Found this info...
6 Bidirectional ports
If a port is programmed in bidirectional mode, it tri-states when an input is made,
and starts to drive when an output is made.
In the case of a timed input to output, a change in tri-state or drive mode is delayed
until the port counter reaches the specified value.
When a conditional input is made, the input pins are tristated the input.
No buffering is available in bidirectional mode.
So if i just call it a port i can use the <: and :> for setting output and input? Like a dummy read/write
User avatar
AtomSoft
XCore Addict
Posts: 135
Joined: Mon Dec 14, 2009 3:02 pm
Contact:

Post by AtomSoft »

Hows this:

Code: Select all

port pU = XS1_PORT_4C;
port pL = XS1_PORT_4D;

void all_pin_input(void)
{
	char temp;
	pL :> temp;
	pU :> temp;
}

void all_pin_output(void)
{
	char temp;
	pL :> temp;
	pL <: temp;
	pU :> temp;
	pU <: temp;
}
User avatar
Ross
XCore Expert
Posts: 962
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Reconfigure port is new - its only really useful for changing buffering mode or the direction of a buffered port. You don't need to use it for changing "direction" on a standard port.
Post Reply