dynamic port configuration

Technical questions regarding the XTC tools and programming with XMOS.
hegt
Member++
Posts: 19
Joined: Wed Sep 17, 2014 1:20 pm

dynamic port configuration

Post by hegt »

Hello I have a program, that I want to run on the same tile on 2 cores. The program is the same only the ports differ.

So I want to start the software in the par{} statement with different port configurations....is there a good way to do that?

I guess it would be something like:

on tile[0]: ctrl_ports_t hal_ctrl1 =
{
XS1_PORT_4F, // slp_tr / rst_n
XS1_PORT_1M, // chip select
XS1_PORT_1I, // nIRQ
XS1_PORT_4E,
};

on tile[0]: ctrl_ports_t hal_ctrl2 =
{
... different config...
};

par
{
on tile[0]: rfmac_server(hal_ctrl1);
on tile[0]: rfmac_server(hal_ctrl2);
}

Is there a good example I can look at?


hegt
Member++
Posts: 19
Joined: Wed Sep 17, 2014 1:20 pm

Post by hegt »

I meant somethin like this:

Code: Select all

//Port Configuration 1
on tile[0]: at86rf233_ctrl_ports_t hal_ctrl1 =
{
  XS1_PORT_4E
};

//Port Configuration 2
on tile[1]: at86rf233_ctrl_ports_t hal_ctrl2 =
{
   XS1_PORT_4A
};


port* unsafe val;

at86rf233_ctrl_ports_t* unsafe local_cnfg;

void ledtask(at86rf233_ctrl_ports_t &port_cnfg){

    at86rf233_ctrl_ports_t* movable local_cnfg_tmp = &port_cnfg;

    unsafe {
        local_cnfg = move(local_cnfg_tmp);
    }

    while(1){
        unsafe{
            local_cnfg->p_led <: 0xFF;
            delay_seconds(1);
            local_cnfg->p_led <: 0x00;
            delay_seconds(1);
        }
    }

}


int main () {

    par {
        on tile[0]:ledtask(hal_ctrl1);
        on tile[1]:ledtask(hal_ctrl2);
        //ledtask();
    }

    return 0;
}
can someone overview it? There should be a better implementation without unsafe regions. My problem is, that I have to access ports out of the select functions. I have a whole class that should be able to access the port...and runs on one core
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

You can do something as shown below:

Code: Select all

/Port Configuration 1
on tile[0]: hal_ctrl1 =
{
  XS1_PORT_4E
};

//Port Configuration 2
on tile[1]: hal_ctrl2 =
{
   XS1_PORT_4A
};


void ledtask(port hal_port){

    while(1){
    select{
       
       case hal_port:> unsigned data: //If you want to read from a port
       break; 
       }
      hal_port<: 0xFF; //Write data to the port
     }
}

int main () {

    par {
        on tile[0]:ledtask(hal_ctrl1);
        on tile[1]:ledtask(hal_ctrl2);
        //ledtask();
    }

    return 0;
}
Is this what you are looking for?
hegt
Member++
Posts: 19
Joined: Wed Sep 17, 2014 1:20 pm

Post by hegt »

sethu_jangala wrote:You can do something as shown below:

Code: Select all

/Port Configuration 1
on tile[0]: hal_ctrl1 =
{
  XS1_PORT_4E
};

//Port Configuration 2
on tile[1]: hal_ctrl2 =
{
   XS1_PORT_4A
};


void ledtask(port hal_port){

    while(1){
    select{
       
       case hal_port:> unsigned data: //If you want to read from a port
       break; 
       }
      hal_port<: 0xFF; //Write data to the port
     }
}

int main () {

    par {
        on tile[0]:ledtask(hal_ctrl1);
        on tile[1]:ledtask(hal_ctrl2);
        //ledtask();
    }

    return 0;
}
Is this what you are looking for?

Thanks, yes I am aware and know that implementation. My problem is that I have a driver that is written in C and that calls functions like Select() that should set a pin high. The whole driver must be ported to xc if I want to do it your way.

Somehow I need to copy the port configuration, so that I can call functions like:

Code: Select all

void xhal_set_rst_low(void){
	p_ctrl_state &= ~HAL_RST_N;	
        hal_ctrl->p_ctrl <: p_ctrl_state; //set pin low

}
and this from C functions.

I have a version running now using unsafe structure and copying the port configuration in the local xc file:

Code: Select all

    at86rf233_ctrl_ports_t* movable local_cnfg_tmp = &ctrl_ports;

    unsafe {
        hal_ctrl = move(local_cnfg_tmp);
    }
Whis should be possible with movable pointers as well, right?
User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

If I understand correctly, you want to pass the port as parameters to C functions. If that is the case, have a look at the solution specified by Ross in the following post:

http://www.xcore.com/forum/viewtopic.php?f=3&t=2562

You can pass XC to C using xccompat.h header file.
hegt
Member++
Posts: 19
Joined: Wed Sep 17, 2014 1:20 pm

Post by hegt »

yes thanks, if the same works with channels and ports....I guess it does ;) thank you!