Accessing port in interface extension function

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
ahenshaw
Experienced Member
Posts: 95
Joined: Mon Mar 22, 2010 8:55 pm

Accessing port in interface extension function

Postby ahenshaw » Wed Jan 23, 2019 7:03 pm

I am trying to extend the spi_master_if interface. My particular interface needs an additional data/command hardware port (dc_port), so I've added a sendCommand interface. Unfortunately, I can't seem to make the dc_port available to the interface extension.

I'm sure that I had this working in the past with a movable pointer, but the compiler is warning:
Taking the address of a resource handle, not the actual resource. Passing by (unsafe) value may be a better option [-Wunusual-code] and an exception is thrown at run-time.

Here's how I try to capture the port in the interface:

Code: Select all

extends client interface spi_master_if  : {
    void init(client spi_master_if self, DisplayContext & dc,
            out port * movable dc_port_ptr,
            out port reset) {
        dc.dc_port = move(dc_port_ptr);
    }

    // sendCommand uses the dc_port like so
    void sendCommand(client spi_master_if self,
                     DisplayContext & dc,
                     uint8_t command)
    {
        *dc.dc_port <: 0;
        self.transfer8(command);
        *dc.dc_port <: 1;
    }
}
and here is how I try to pass the port:

Code: Select all

void demo(client spi_master_if epd) {
    out port * movable dcport_ptr = &dcport;
    epd.init(dc, move(dcport_ptr), reset);

}
errsuberlin
Newbie
Posts: 1
Joined: Mon Jun 30, 2014 10:22 pm

Postby errsuberlin » Sun Apr 28, 2019 10:17 pm

Maybe a bit late for a reply, but it's good to know I'm not the only one (repeatedly stumbling over this issue).

Maybe XMOS could remove the warning, especially because they are proposing to do exactly this in application note AN10060:

https://www.xmos.com/developer/publishe ... n=1.0.0rc4

As a workaround for the warnings, I supress them locally, because all kinds of -Wno-unusual-code or more specialized pragmas don't seem to work:

Code: Select all

  
out port p = ...
  #pragma warning disable
  out port * movable pp = &p;
  #pragma warning enable
For the crash, I guess you should consider restoring dcport_ptr before leaving demo(), something like

Code: Select all

void demo(client spi_master_if epd) {
    out port * movable dcport_ptr = &dcport;
    epd.init(dc, move(dcport_ptr), reset);
    // call sendCommand etc.
    dcport_ptr = move(dc.dc_port);
}
At least in my case this seems to work.

Yours,
Errsu

Who is online

Users browsing this forum: No registered users and 0 guests