transaction xtcp_event used in select

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

transaction xtcp_event used in select

Post by aclassifier »

I am trying to understand the

Code: Select all

/** \brief Receive the next connect event.
 *
 *  \note This can be used in a select statement.
 *
 *  Upon receiving the event, the xtcp_connection_t structure conn
 *  is instantiated with information of the event and the connection
 *  it is on.
 *
 * \param c_xtcp      chanend connected to the wifi server
 * \param conn        the connection relating to the current event
 */
transaction xtcp_event(chanend c_xtcp, xtcp_connection_t &conn);
in module_wifi_tiwisl, file xtcp_cient.xp. The full code goes like this:

Code: Select all

// This can be used in a select statement.
#pragma unsafe arrays
transaction xtcp_event(chanend c_xtcp, xtcp_connection_t &conn)
{
  for(int i = 0; i < sizeof(conn) >> 2; i++)
  {
    c_xtcp :> (conn,unsigned int[])[i];
  }
}
Here is the select statement it's being used, in app_tiwisl_simple_webserver file xhttpd.xc. (I have added a LED server).

Code: Select all

while(1)
{
  select
  {
    case xtcp_event(c_wifi, conn): 
    {
      wifi_led_cmd = httpd_handle_event(c_wifi, conn); // Teig
      event_cnt++;
      i_wifi_led_server.command (wifi_led_cmd);
      break;
    } // case xtcp_event(c_wifi, conn):
  } // select
} // while(1)
The above code is also shown in xtcp.pdf in lib_xtcp and in webserver.pdf in lib_webserver with the following text:
To use the webserver you must have an instance of an XTCP server running on your system. You can then write a function that implements a task that handles tcp events. This may do other functions/handle other tcp traffic as well as implementing the webserver. Here is a rough template of how the code should look:
(As mentioned the code I use (app_tiwisl_simple_webserver ) does not use lib_xtcp (for XTCP) but module_wifi_tiwisl (for wifi_tiwisl_server) that takes care of the Wi-Fi TiWi-SL)

Below is some pseudocode, perhaps to see c_wifi /c_xtcp in scope:

Code: Select all

while(1)
{
  select
  {
    case xtcp_event(c_wifi,conn):
      { // "transcation":
        for(int i = 0; i < sizeof(conn) >> 2; i++)
        {
          c_wifi :> (conn,unsigned int[])[i];
        }
      {
      wifi_led_cmd = httpd_handle_event(c_wifi, conn); // Teig
      event_cnt++;
      i_wifi_led_server.command (wifi_led_cmd);
      break;
    } // case xtcp_event(c_wifi, conn):
  } // select
} // while(1)
(For those of you who read my first attempt, this text has been edited after that pessimistic try:)

My problem is, even after having read the XC specs and books I am not certain if I understand this. I'll try to explain what I think I understand.

I observe that there is one event arriving on c_wifi and it's also used to send data back again. On the client side.

xtcp_event certainly is a synchronization point. c_wifi is used by the sender in module_wifi_tiwisl to fill up the conn struct/array asynchronously across a core and then the synchronization is handled by the enclosing transaction statement? I guess this syntax does this array filling: c_wifi :> (conn,unsigned int[]); And this is unsafe by the compiler rules, but not as it is coded?)

I assume that defining xtcp_event in another module than the user/client/has-select is a way to make general task-based library modules clean?

I have started a task diagram (attached). I do this because I plan to port the WiFi101 SW for the ATWINC1500 module into XC code [1]. To do that I need to understand the XMOS solution with the WiFi sliceCARD (that I obsolete). Much about this in my blog notes.

[1] http://www.teigfam.net/oyvind/home/tech ... rary-port/ (Disclaimer: no money, no gifts, no ads, just a private hobby)
Attachments
143 fig 14 task data flow diagram_.jpg
Task msc etc. (a raw start)
(1.31 MiB) Not downloaded yet
143 fig 14 task data flow diagram_.jpg
Task msc etc. (a raw start)
(1.31 MiB) Not downloaded yet


--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
Post Reply