[etherlab-users] Knowing when the packet has finished cycle

Shahbaz Yousefi shabbyx at gmail.com
Thu Oct 13 17:12:46 CEST 2011


Hi,

I have been working with etherlab recently and got ethercat working up and
everything is fine.

There is a delay issue however that I'm concerned about. As seen in the
examples, the way you read from the network is like this (imagine you are
interested in reading sensor values):

while (running)
{
  master receive
  domain process

  read data

  domain queue
  master send

  rt wait period
}

in which case you assume that the task period is long enough to be sure that
the packet sent in the bottom of the loop has returned when the loop starts
again and so you can receive the data.

However, I was wondering if it is possible to, instead of taking an upper
bound of the time, simply check to see whether the data has arrived or not.
After some research, I got to this code:

while (running)
{
  domain queue
  master send

  do
  {
    sleep a little

    master receive
    domain process

    ecrt_domain_state(domain, &state);

  } while (state.wc_state != EC_WC_COMPLETE && !timeout)

  read data

  rt wait period
}

This way, after sending the packet, you would read the data as soon as they
arrive.

The problem with this was that, besides the fact that early calls to
master_receive (or domain_process) generated a huge amount of warning about
working counter changing to 0/1 and back to 1/1 again, the kernel started to
at some point keep crashing.

I would like to know, how can I detect when the packet has arrived without
knowing an upper bound about it and wait blindly by that much?

Note: This is most useful for me for this reason:

I may have different threads requesting data from a domain which includes
different sensors. Each type of sensor produces data at a different rate and
I would like to read the data at different rates to. I don't want to (and I
don't think is even possible) to have different threads requesting data from
the same domain (because they may send the packet while the one for the
previous thread hasn't yet arrived). So what I want to is this:

ethercat coordinator:

domain_updating = no

send_request_for_domain
{
  if (domain_updating == no)
  {
    domain_updating = yes
    domain queue
    master send
  }
  // else, do nothing, it is being updated!
}

receive_from_domain()
{
  while (ecrt_domain_data_not_yet_received) // this is the function I need
    wait
  domain_updating = no
  // data available
}

and then, each thread that wants something from the domain would look like
this:

thread:
  send_request_for_domain
  receive_from_domain
  read data

This way, if two threads call send_request_for_domain at the same time, only
one of them would actually do the

domain queue
master send

and both of them use the result.

I would appreciate it if you could shed some light on this matter.
Shahbaz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20111013/5c58e20a/attachment-0003.htm>


More information about the Etherlab-users mailing list