Struggling with my first XCode app

New to XMOS and XCore? Get started here.
User avatar
LyleHaze
Experienced Member
Posts: 71
Joined: Wed Apr 11, 2012 6:21 am

Struggling with my first XCode app

Post by LyleHaze »

OK, just getting started, having some luck, but at this point I'm not even reading the correct manuals. The online help is quite helpful, but I'm sure there is more detailed documents somewhere.
I'll describe what I'm trying to accomplish, then show you what I have so far.
I'm quite sure this is complete rookie stuff, please let me know what you see, right or wrong.

I have an L2 attached to the "fast localbus" of my computer.

So far I have the code below, untested.
What I do NOT know how to do yet is to switch the 16 bit AD bus between input and output modes. I have port_drive_on and port_drive_off where they are intended.

I'm not really using any data yet, just getting the code ready.

Any suggestions about better ways to do this are invited.

[edit] I think I found out how.. is it as easy as doing an out to set the
port to output, and later doing an input to tri-state the drivers?

Code: Select all

/* On ALE rising edge latch upper address
on ale falling edge latch bottom address

on WE low with CS low latch data

if OE is low and CS is low output data */

on stdcore [1] : port pin_LPC_AD = XS1_PORT_16A;
on stdcore [1] : port in pin_ALE = XS1_PORT_1A;
on stdcore [1] : port in pin_WE = XS1_PORT_1B;
on stdcore [1] : port in pin_OE = XS1_PORT_1C;
on stdcore [1] : port in pin_CS = XS1_PORT_1D;

void localbus( void )
{
	int add_l, add_h;
	int ale = 0;
	int cs = 1;
	int dummy;
	int val;
	int oe = 1, we = 1;
	int LEDval;
	int indata;

	while (1)
	{
		select
		{
			case pin_ALE when pinsneq (ale) :> ale:
				if(1 == ale) pin_LPC_AD :> add_h;
				else         pin_LPC_AD :> add_l;
				break;
			case pin_OE when pinsneq (oe) :> oe:
				pin_CS :> cs;
				if((0 == oe)&&(0 == cs)) pin_LPC_AD <: indata;
				else				pin_LPC_AD :> dummy;
				break;
			case pin_WE when pinsneq (we) :> we:
				pin_CS :> cs;
				if((0 == we)&&(0 == cs)) pin_LPC_AD :> indata;
				break;
		}		
	return ;
}
Thanks,
LyleHaze


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

LyleHaze wrote:
[edit] I think I found out how.. is it as easy as doing an out to set the
port to output, and later doing an input to tri-state the drivers?

Thanks,
LyleHaze

Yes. You can do a dummy read if necessary to change the mode to input.