XC-2 code overload

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

XC-2 code overload

Post by ahenshaw »

I'm confounded by the example code available for the XC-2. Is there a better abstracted TCP/IP example then the app_simple_webserver. I just need some code that will let the XC-2 act as a socket client (open a tcp/ip socket, send some data, close the socket), but the webserver example has a main (which should be at a pretty high level of abstraction) that looks like this:

Code: Select all

int main(void) 
{
  chan mac_rx[1], mac_tx[1], xtcp[1], connect_status;
  par {
    on stdcore[1]: uip_server(mac_rx[0], mac_tx[0], 
                              xtcp, 1, ipconfig, connect_status);
  
    on stdcore[3]: xhttpd(xtcp[0]);

    on stdcore[2]:
    {
      int mac_address[2];
      ethernet_getmac_otp((mac_address, char[]));
      phy_init(clk_smi, clk_mii_ref, 
#ifdef PORT_ETH_RST_N               
               p_mii_resetn,
#else
               null,
#endif
               smi,
               mii);
      ethernet_server(mii, clk_mii_ref, mac_address, 
                      mac_rx, 1, 
                      mac_tx, 1,
                      smi,
                      connect_status);
    }
    
  }
}
Do I really need to worry about mii, smi, and phy to do this kind of programming on the XC-2? I was expecting a module that would encapsulate all of this detail and provide me with some comm channels through which I could perform socket-level operations. It appears that the XTCP module, to some extent, is organized like this, but I can't seem to find any relevant examples.


User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Yeah it is hell to do anything with the example. Thats why i made my own API for it, that simplifys it down to listen connect send and receive. The thing is still very rough but it works.
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

Post by ahenshaw »

I'd certainly like to see your library, if it is shareable.

In the module_xtcp.1v3 subdirectory of the xmos_tcpip_1v3 source code distribution, there is a README which reads as follows:

Code: Select all

XMOS XTCP SOURCE DIRECTORIES
----------------------------

  * xtcp         - TCP/UDP/IP client layer files
  * uip          - The uIP protocol stack
  * uip/xcore    - XMOS architecture specific files for uIP port
  * xtcp_apps    - Applications that use the xtcp interface
  * demo         - A simple demo using uIP and the xtcp client layer
  * xc2_firmware - The XC-2 webserver demo

GETTING STARTED
---------------

The xtcp client layer is documented in the header files. The most
important files to look at to get started are:

         * src/xtcp/xtcp_client.h     - xtcp client api
         * src/uip/xcore/uip_server.h - uip protocol server for xtcp
         * src/demo/*                 - simple demo showing how to use
                                        the component
 
Unfortunately, there are no src/demo or xtc_apps folders, which I believe would be of great help to me. Does anyone have this code?
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

You can find my library under projects on this site. Its here http://www.xcore.com/projects/winsock-a ... net-driver
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

Post by ahenshaw »

I'm getting closer. I think that I'm correctly hiding most of the network code into a networkManager function, so that I can now have a top-level that looks something like this:

Code: Select all

int main(void) {
    chan xtcp[1];
    par {
        on stdcore[1]: testTcp(xtcp[0]);
        on stdcore[2]: networkManager(xtcp, 1);
    }
    return 0;
}
So, now I'm having trouble using the xtcp code (an xtcp client demo would be great). I seem to be able to almost complete a connection to a simple Python server with the following code:

Code: Select all

void testTcp(chanend xtcp) {
    
    xtcp_ipaddr_t host = {192,168,1,100};
    xtcp_connect(xtcp, 8000, host, XTCP_PROTOCOL_TCP);
When I run this, interestingly enough, my server won't show that the connection has been made until the XC-2 times out (apparently). Then, I get this from my Python server:

Code: Select all

waiting for connection
connected to ('192.168.1.149', 1026)
waiting for data
Traceback (most recent call last):
  File "tcptest.py", line 11, in <module>
    data = conn.recv(1024)
socket.error: (10054, 'Connection reset by peer')
So, I imagine that I need to do something to complete the connection initiation, which I'm now completely guessing, has to do with waiting for the connection event. I tried recoding my example as:

Code: Select all

void testTcp(chanend xtcp) {
    xtcp_conn_or_config_t event_type;
    xtcp_config_event_t   event;
    xtcp_ipconfig_t       ipconfig;
    xtcp_connection_t     conn;
    
    xtcp_ipaddr_t host = {192,168,1,100};
    xtcp_connect(xtcp, 8000, host, XTCP_PROTOCOL_TCP);
    
    //xtcp_ask_for_conn_or_config_event(xtcp);   // is this needed?
    printstrln("connection attempted");
    slave {
        xtcp_conn_or_config_event(xtcp, event_type, event, ipconfig, conn);
    }
 
  
But no luck. Is there anybody that can supply a simple tcp client demo using the xtcp lib?

For completeness, here's my test Python code:

Code: Select all

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 8000))
s.listen(1)
print 'waiting for connection'
conn, addr = s.accept()
print 'connected to', addr
print 'waiting for data'
while True:
    data = conn.recv(1024)
    if not data:
        break
    else:
        print data
conn.close()
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

You will need to dig deep in to the tcp code and its documentation to find out. I admit it was not easy. In my sockets code there may still be the IRC try i did. It connected and longed on to a IRC server.
User avatar
russf
XCore Addict
Posts: 146
Joined: Thu Dec 10, 2009 10:17 pm

Post by russf »

@ahenshaw - did you manage to get your example working?
User avatar
russf
XCore Addict
Posts: 146
Joined: Thu Dec 10, 2009 10:17 pm

Post by russf »

I took some code from this page and incorporated in my test project:

http://github.com/topiaruss/xmostcptests

I'm interested to hear more about xtcp projects and progress.

Can we get 10Mbit/s send rate? More?

--r
russf@topia.com
User avatar
nieuwhzn
Member++
Posts: 26
Joined: Sat Dec 12, 2009 6:45 am

Post by nieuwhzn »

Hm, interesting, planets must be aligning somehow, since I was just trying to figure out what the status of the various ethernet applications was. Looks like more people are having problems getting this going. I need it to get data on and off the XMP-64.
In my innocence I expected that I could just find a couple of examples with nice documentation, not the case unfortunately. It's not that I'm too lazy to figure it out myself (well, maybe a bit wary) I simply don't have the time to invent the wheel over and over again. Considering that the XC-2 and XC-3 are very ethernet centric I hoped that XMOS would provide more comprehensible information.
User avatar
xcorific
Member++
Posts: 17
Joined: Fri Aug 12, 2011 2:36 pm

Post by xcorific »

XMOS has finally taught me my lesson. I went and purchased the XC-2, thinking that it would have examples ready to go and I'd be free from having to deal with the low-level details. I've got the XC-2 connected, but now I'm scouring the web, looking for the example code referred to in the tutorial. I need to stop doing this unless I have completely vetted a potential solution to my problem. :)

I found a link in the XMOS Support page (deprecated - http://www.xmos.com/discuss/viewtopic.php?f=7&t=822) and there's code there, but none of the project build yet. I have to figure out why certain files are missing. I then found a link to the "Ethernet software code" referred to by the tutorial (http://letsmakerobots.com/node/10622), but all of the links are broken.

Has there been any recent progress with the development of easy-to-use libraries, or should I prepare myself for a steep learning curve (or just ditch the idea and use a different solution for Ethernet)? I can always use the XMOS processor for some timing-sensitive DIO operations later.