IgH EtherCAT Master  1.6.13
api_usage_notes.md
1 # Notes regaring API Usage {#apiusage}
2 
3 There are some restrictions on the
4 [Application Interface](@ref ApplicationInterface) with respect to the state of
5 the master instance and the calling context, which are explained in the
6 following.
7 
8 ## Rules of Thumb
9 
10 All configuration (`ecrt_slave_config_*()`) has to be done in Linux process
11 context. They can be blocking, so take care when holding locks. After
12 `ecrt_master_activate()` ing the master, your application must not alter the
13 slave configuration. Instead, update process data using ecrt_domain_queue() and
14 ecrt_domain_process() or use the asynchronous interface like
15 ecrt_sdo_request_read(). Don't forget to ecrt_master_receive() and
16 ecrt_master_send(). These functions can be called from non-process context too,
17 like Xenomai/RTAI applications or custom kernel modules.
18 
19 ## Master Phase
20 
21 The first distinction of cases is whether ecrt_master_activate() has been
22 called or not. Before ecrt_master_activate() (or after
23 ecrt_master_deactivate()), the master is in idle phase. Sending and receiving
24 EtherCAT frames will be done by the master itself, the application (e. g. you)
25 can store slave configurations for later use. After ecrt_master_activate(),
26 the master switches into operation mode. The application is now in charge of
27 steering the communication. Process data can be exchanged under real time
28 constraints. Altering the slave configuration is not possible anymore.
29 
30 | Tag | Description |
31 |---------------|---------------------------------------------------------------------------------------|
32 | `master_op` | Master must be in operation phase, so after `ecrt_master_activate()` has been called. |
33 | `master_idle` | Master must be in idle phase, so before `ecrt_master_activate()` has been called. |
34 | `master_any` | Master can be in idle or operation phase. |
35 
36 ## Allowed Context
37 
38 The second distinction of cases is the calling context, which means how the
39 application is run. Most of the functions of the
40 [Application Interface](@ref ApplicationInterface) have to acquire locks or
41 allocate memory, so they are potentially sleeping. They are tagged as
42 `blocking`. Sleeping is not allowed in all contexts, for instance when using
43 Xenomai/RTAI or a kernel timer. Only a very limited set of functions can be
44 called from any context, marked as `rt_safe`. They do not allocate memory and
45 will not block.
46 
47 | Tag | Description |
48 |------------|-----------------------------------------------------------------------------------------------|
49 | `rt_safe` | Realtime context (RT userspace, atomic/softirq context in kernel, Xenomai/RTAI RT task) safe. |
50 | `blocking` | Linux process context only (userspace or kernel), might block. |