kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: laumann.thomas@gmail.com (Thomas Bracht Laumann Jespersen)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Implementing tight time constraints for read/write with USB serial (ftdi_sio)
Date: Wed, 5 Sep 2018 11:46:28 +0200	[thread overview]
Message-ID: <CAN=42sz+DNuS6t-PgGXkGipyZG8zZkrW0Nn5=mu7m48XubOhew@mail.gmail.com> (raw)
In-Reply-To: <169096.1536024173@turing-police.cc.vt.edu>

Hi Valdis,

Thanks for your reply!

Failure in our context means that we cannot participate as an alternative master
in the PROFIBUS network.

I'll try to explain briefly what the intended setup is: A PROFIBUS network
consists of exactly one master (a class 1 master, or MC1), and a number of
slaves. All the slaves are silent until queried for information. The MC1 goes
round-robin asking each slave for periodic status updates, to keep tabs on how
things are going. PROFIBUS is _very_ deterministic: only station may be
communicating at a time and the master orchestrates the exchange of information
[0].

Our challenge is that we want to pull run-time data out of this network, and
re-programming MC1 to extract more data is not an option. So failure also means
we cannot monitor the system as well as we want.

Fortunately, PROFIBUS also specifies a class 2 master (MC2) that is intended for
maintenance purposes [1]. The MC2 design allows other stations to dynamically
enter and leave the network. The idea is to use the gap time to act as a master.

To orchestrate this, the masters pass a token around. Specifically, the MC1
periodically tries all possible network addresses to see if any other stations
want to accept the token. If so, then the station must respond with a specific
"accept token" message. Once the MC1 station sees the accept, it passes the
token to the new MC2 and the two masters then pass the token back and forth.

An MC2 station leaves the network by simply failing to return the token three
times.

We have a test setup where I have been able to successfully send the "accept
token" message, but by the time the MC1 station passes the token (and my program
sees it), it has already failed to pass it back.

The problem is that response transmission has to begin within 100 tbits of
response receipt (this is called the slot time). That is, from the time I see a
message I should respond to, I must begin transmitting a response within 100
tbits. In our test setup we run 115 kBaud, so our slot time works out to about
0.868ms. In the production setup, we need to go even faster, at 1.5Mbaud, so the
slot time dips to ~0.066ms.

[0] https://www.felser.ch/profibus-manual/stationen.html
[1] https://www.felser.ch/profibus-manual/prinzip_des_token-passing.html


-- Thomas
On Tue, 4 Sep 2018 at 03:23, <valdis.kletnieks@vt.edu> wrote:
>
> On Mon, 03 Sep 2018 21:12:35 +0200, Thomas Bracht Laumann Jespersen said:
>
> > The challenge is that my application needs to act within 100 tbits, ie in around
> > ~.066ms. That is the window in which I need to begin transmitting a reply. Is
> > there a way to achieve this with the ftdi_sio driver or do I need dedicated
> > hardware for this?
>
> (Hopefully you've already done all of the below - it's mostly for the
> others out there thinking about doing real-time work...)
>
> Step 0 is quantifying what a failure means.  Do you just miss a data point for
> a graph, or does something on the assembly line explode or equally bad, or
> something in between?
>
> Step 1 is firming up exactly what that 0.66ms is.  Does it start at the
> beginning of receiving the packet you care about, or when the last byte has
> arrived?  And are you counting until the first byte of the response leaves, or
> the last byte? Or are you counting until it's actually received at the target?
> (Note that some statistical modeling may be needed, depending how PROFIBUS
> behaves under load - what happens if another station is transmitting a very
> large packet at the time you need to send your packet, etc etc..)
>
> Step 2 is doing some userspace benchmarking of your response code - can the
> target hardware do whatever processing is needed in the time allowed (remember
> to subtract off any hardware-imposed latency like your PROFIBUS or your
> RS485-USB converter).  This can be easy to meet if you have a beefy CPU and
> just need to check the values of 3 bytes, add 2 other bytes together, and send
> the result.  On the other hand, if you're on a low-end ARM and need to do a
> 512x512 FFT - the Realtime Gods may not smile favorably on your endeavor.
>
> If your project is still alive at this point, *now* you start asking stuff like
> realtime scheduling for your kernel thread, how to reduce interrupt
> latency, and so on....
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2018-09-05  9:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 19:12 Implementing tight time constraints for read/write with USB serial (ftdi_sio) Thomas Bracht Laumann Jespersen
2018-09-04  1:22 ` valdis.kletnieks at vt.edu
2018-09-05  9:46   ` Thomas Bracht Laumann Jespersen [this message]
2018-09-04  5:30 ` Greg KH
2018-09-05 10:25   ` Thomas Bracht Laumann Jespersen
2018-09-05 10:48     ` Greg KH
2018-09-05 11:07       ` Thomas Bracht Laumann Jespersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=42sz+DNuS6t-PgGXkGipyZG8zZkrW0Nn5=mu7m48XubOhew@mail.gmail.com' \
    --to=laumann.thomas@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).