hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
                     Real-Time Media Access Control (RTmac)
                     ======================================
 
RTmac is a module designed to be used with RTnet. It provides a media access
control (MAC) infrastructure for RTnet. The actual access control mechanism is
implemented by so-called discipline modules. The current version comes with a
time division multiple access (TDMA) discipline. Because of the RTmac's modular
design, you can also easily attach your own MAC discipline optimised for the
specific application.
 
 
RTmac Layer
===========
 
Without RTmac:
 
           +---------------+
           |RT applications|
           +-------v-------+
                   |
          +--------v---------+
          |  RT UDP/IP stack |
          +------------------+
          |RT ethernet driver|
          +--------v---------+
                   |
              +----v---+
              |   NIC  |
              +--------+
 
With RTmac inserted:
 
           +---------------+    +-------------------+
           |RT applications|    |   Linux network   |
           +-------v-------+    |stack (TCP/IP etc.)|
                   |            +---------v---------+
          +--------v---------+            |
          |  RT UDP/IP stack |         +--v--+
          +------------------+         |VNIC |
          |      RTmac       |         +--v--+
          |      Layer       |            |
          | .--------------. <------------+
          | |MAC algorithm | |
          | `--------------ยด |
          +------------------+
          |RT ethernet driver|
          +--------v---------+
                   |
              +----v---+
              |   NIC  |
              +--------+
 
RTmac, if loaded, has the exclusive control over transmission of the network
driver. Every outgoing packet is passed to RTmac which forwards it to the MAC
discipline. It will decide then when the packets can be sent to the hardware
driver.
 
 
 
TDMA - Time Division Multiple Access
====================================
 
The TDMA media access control discipline is based on a master/slave hierarchy.
A network master periodically publishes so-called Synchronisation frames,
forming elementary cycles. Network participants, including the master, have
exclusively assigned access windows (time slots) within these cycles, defined
relatively to the Synchronisation frames. In order to catch potential breakdowns
of the central master, additional backup masters can be set up which will take
over sending Synchronistation frames in case of the the primary master failing
to do so.
 
A time slot can be used to transmit a single packet of up to a specified maximum
size. This discipline revision supports flexible assignment of time slots to
real-time network participants. It is possible to use multiple slots per cycle.
Furthermore, a slot can be shared between participants by occupying it only
every Nth cycle. Besides at least one payload slot per participant, slots have
to be reserved for the Synchronisation frame and, optionally, for one or more
backup Synchronisation frames. The concrete timing strongly depends on the
capability of all network participants. Therefore, timing requirements like
worst case jitters or minimum slot gaps are not statically specified, they can
be defined individually for every project.
 
In contrast to earlier TDMA discipline revisions, the slave configuration is
no longer distributed by the TDMA master. This means that the slaves have to
be aware of their slot setup before sending any data to a TDMA-managed
network. Therefore, the required settings either have to be stored on the
slaves or, if a centralised management is desired, the RTnet configuration
service RTcfg has to be used (see related documentation for further details).
 
 
Slot Identification and Selection
---------------------------------
 
Time slots carry an internal ID number, unique per participant. These numbers
are used when determining the slot in which an outgoing packet shall be
transmitted. The TDMA discipline contains no automatic scheduling mechanism.
Instead, the sender, i.e. an user or a service, either explicitly provides a
desired slot ID or a default slot is used.
 
  Slot ID | Description
 ---------+-----------------------------------------------------------------
     0    | default slot for RT; also default NRT slot if slot 1 is missing
     1    | non-RT slot; if missing, slot 0 is used
     2    | user slots, used for explicitly scheduled packets
     :    |
 
 
Configuration Files
-------------------
 
To ease the setup of TDMA-based networks, the rtnet start script is provided
with the RTnet distribution. It is controlled by a configuration file which is
typically named rtnet.conf and stored in /etc. By setting the TDMA_MODE in this
file, the role of the station is set to either "master" or "slave".
 
Beyond this common parameter, the start script supports two configuration modes
for TDMA. In the simple mode, only the IPs of all slaves have to listed in
TDMA_SLAVES, the cycle period has to be provided in TDMA_CYCLE, and the slot
offset difference must be specified in TDMA_OFFSET. Every station is then
assigned a single time slot with the ID 0, starting with offset 0 for the
master node, i.e. the master's payload frame will directly follow the
Synchronisation frame. Further offsets are calculated by incrementing the
previous value by TDMA_OFFSET for each further station.
 
In contrast, the extended mode allows a detailed configuration of every node.
To enable this mode, a TDMA configuration file (typically /etc/tdma.conf) is
required. The path of this file has to be provided to rtnet.conf in the
variable TDMA_CONFIG, while TDMA_SLAVES, TDMA_CYCLE, and TDMA_OFFSET have to
be disabled, e.g. by commenting out. Beside TDMA-related paramters, also
individual stage-2 files can be set for every slave node, overwriting the
common STAGE_2_SRC variable in rtnet.conf (see RTcfg documentation for details
about the configuration concept). The format of the TDMA configuration file is
defined as follows:
 
# Note: every station needs at least one time slot
master:
[ip 1.2.3.4]
cycle <cycle_in_us>
slot <id> <offset_in_us> [<phasing>/<period> [<size>]]
[slot ...]
 
# Slave with known MAC address, IP is assigned by the RTcfg server
slave:
ip 1.2.3.4
mac AA:BB:CC:DD:EE:FF
[stage2 <file>]
slot ...
 
# Slave with unknown MAC address, it is aware of its IP when starting
slave:
ip 1.2.3.4
[stage2 <file>]
slot ...
 
# Slave with known MAC address without IP support
slave:
mac AA:BB:CC:DD:EE:FF
[stage2 <file>]
slot ...
 
# Note:
# - multiple backup masters can be set up, always the one with the smallest
#   backup-slot value will take over in case of a failure
# - the cycle period is already defined with the primary master
backup-master:
ip 1.2.3.4 (or IP+MAC or only MAC, see slave scenarios)
backup-slot <offset_in_us>
[stage2 <file>]
slot ...
 
 
Configuration Example
---------------------
 
An exemplary configuration consisting of two masters, one serving as backup,
and three slaves is shown below. The slot period is expressed in the form
<phasing>/<period>. For instance, 1/3 means that this slot will be used in
every first of three cycles, while 3/3 means in every third of three.
 
  +------+  +----------+  +---------+  +---------+  +----------+
  |      |  | Master 2 |  | Slave A |  | Slave B |  | Master 1 |
  | Sync |  |  Backup  |  | Slot 0  |  | Slot 0  |  |  Slot 0  |
  |      |  |   Sync   |  | RT/NRT  |  |   RT    |  |  RT/NRT  |
  | 1/1  |  |   1/1    |  |   1/1   |  |   1/1   |  |   1/1    |
--+------+--+----------+--+---------+--+---------+--+----------+--...
 
                                     +----------+
                                     | Slave C  |
                                     |  Slot 3  |
                                     |    RT    |
                                     |   3/3    |
     +---------+                     +----------+
     | Slave C |                     | Master 2 |
     | Slot 0  |                     |  Slot 0  |
     | RT/NRT  |                     |  RT/NRT  |
     |   2/2   |                     |   2/3    |
     +---------+        +---------+  +----------+             +------+
     | Slave B |        | Slave C |  |  Slave A |             |      |
     | Slot 1  |        | Slot 2  |  |  Slot 2  |             | Sync |
     |   NRT   |        |   NRT   |  |    RT    |             |      |
     |   1/2   |        |   1/4   |  |   1/3    |             | 1/1  |
...--+---------+--------+---------+--+----------+-------------+------+-->
 
A tdma.conf file describing this scenario is shown below (all time values are
examplary, only expressing relative relations):
 
# Master 1
master:
ip 10.0.0.1
cycle 5000
slot 0 800
 
# Master 2
backup-master:
ip 10.0.0.2
backup-offset 200
slot 0 1500 2/3
 
# Slave A
slave:
ip 10.0.0.3
slot 0 400
slot 2 1500 1/3
 
# Slave B
ip 10.0.0.2
slot 0 600
slot 1 1000 1/2
 
# Slave C
ip 10.0.0.2
slot 0 1000 2/2
slot 2 1300 1/4
slot 3 1500 3/3
 
 
Management Interface
--------------------
 
The TDMA discipline is managed by the command line tool tdmacfg. In the
following, the usage of this tool is described. For typical setups, the rtnet
start script manages the execution of tdmacfg.
 
tdmacfg <dev> master <cycle_period> [-b <backup_offset>]
        [-c calibration_rounds] [-i max_slot_id] [-m max_calibration_requests]
 
Starts a TDMA master on the specified device <dev>. The cycle period length is
given in microseconds using the <cycle_period> parameter. If <backup_offset>
is provided, the master becomes a backup system. In case the main master
fails, the backup master with the smallest <backup_offset> will start sending
Synchronisation frames with the specified offset in microseconds relative to
the scheduled cycle start. <calibration_rounds> specifies the number of clock
calibration requests the master will send to any other potentially already
active master during startup. By default, 100 rounds are performed. The
calibration will be performed when the first slot is added. By default, a
master can handle up to 64 calibration requests at the same time. This value
can be adapted by specifying the <max_calibration_requests> parameter. The
largest used slot ID is tunable by providing <max_slot_id> or will be limited
to 7 if this parameter is omitted.
 
tdmacfg <dev> slave [-c calibration_rounds] [-i max_slot_id]
 
Starts a TDMA slave on the specified device <dev>. <calibration_rounds>
specifies the number of clock calibration requests the slave sends to the
active master during startup. By default, 100 rounds are performed. The
calibration will be performed when the first slot is added. The largest used
slot ID is tunable by providing <max_slot_id> or will be limited to 7 if this
parameter is omitted.
 
tdmacfg <dev> slot <id> [<offset> [-p <phasing>/<period>] [-s <size>]
        [-j joint_slot] [-l calibration_log_file] [-t calibration_timeout]]
 
Adds, reconfigures, or removes a time slot for outgoing data on a started TDMA
master or slave. <id> is used to distinguish between multiple slots. See above
slot ID table for predefined values. If <offset> is given, the time slot is
added or modified to send data with the specified offset in microseconds
relative to the scheduled cycle start, if omitted, the slot is removed from
the station's configuration.
 
By default, a slot will be used in every cycle. When providing <phasing> and
<period>, the slot will only be occupied in every <phasing>-th of <period>
cycles. By assigning e.g. 1/2 to one and 2/2 to another slot, the usage of the
physical time slot will alternate between both slot owners. The <size>
parameter limits the maximum payload size in bytes which can be transmitted
within this slot. If no <size> parameter is provided, the maximum size the
hardware supports is applied. To share the same output queue among several
slots, secondary slots can be attached to a primary <joint_slot>. The slot
sizes must match for this purpose.
 
The addition of the station's first slot will trigger the clock calibration
process. To store the results of each calibration handshake, a
<calibration_log_file> can be provided. By default, this command will not
terminate until the calibration is completed. The <calibration_timeout>
parameter can be used to specify an upper time limit.
 
NOTE: Reconfiguring an existing slot during runtime can cause packet drops on
the involved output channel. You should stop all applications using this slot
before reconfiguring it.
 
tdmacfg <dev> detach
 
Detaches a master or slave from the given devices <dev>. Past this command,
the write access to the device is uncoordinated again and may interfere with
remaining real-time network participants.
 
 
 
NoMAC - Void Media Access Control
=================================
 
Formost as a skeleton for new MAC implementations, the NoMAC discipline module
is provided. It simply forwards every outgoing packet to the driver as soon as
the stack passes it over. NoMAC is configured using the command line tool
nomaccfg. To attach NoMAC to a real-time network adapter, call
 
nomaccfg <dev> attach
 
To detach it again, use
 
nomaccfg <dev> detach
 
 
 
VNIC configuration
==================
 
As soon as an RTmac discipline is loaded and appropriately configured for a
real-time network adapter, a virtual network interface controller (VNIC) is
provided to standard Linux. It is named "vnic<n>", where <n> is the number of
the associated rteth device (e.g. rteth1 --> vnic1). You just have to configure
the VNIC as a normal network device using ifconfig. You are even free to assign
a different IP than the real-time interface uses.
 
 
 
References
==========
 
 - Real-Time Media Access Control Framework (RTmac), revision 2.0
 - TDMA Media Access Control Discipline, revision 2.1a
 - RTnet Configuration Service (RTcfg), revision 1.7