Technical Manual PD4-E-M (EtherCAT)
9 Programming with NanoJ
9.2.3 Possible error at
od_write()
A possible source of errors is a write access with the
od_write()
function (see System calls in a
NanoJ program) of an object in the object dictionary that was simultaneously created as mapping. The
code listed in the following is incorrect:
map U16 controlWord as output 0x6040:00
#include " wrapper.h"
void user()
{
[...]
Out.controlWord = 1;
[...]
od_write(0x6040, 0x00, 5 );
// der Wert wird durch das Mapping
überschrieben
[...]
}
The line with the
od_write(0x6040, 0x00, 5 );
command has no effect. As described in the
introduction, all mappings are copied to the object dictionary at the end of each millisecond.
This results in the following sequence:
1. The
od_write
function writes the value
5
in object 6040
h
:00
h
.
2. At the end of the 1 ms cycle, the mapping is written that also specifies object 6040
h
:00
h
, however,
with the value
1
.
3. From the perspective of the user, the
od_write
command thus serves no purpose.
9.3 System calls in a NanoJ program
With system calls, it is possible to call up functions integrated in the firmware directly from a user
program. Because direct code execution is only possible in the protected area of the sandbox, this
is implemented via so-called Cortex-Supervisor-Calls (Svc Calls). An interrupt is triggered when
the function is called. The firmware thus has the possibility of temporarily allowing code execution
outside of the sandbox. Developers of user programs do not need to worry about this mechanism – for
them, the system calls can be called up like normal C functions. Only the wrapper.h file needs to be
integrated as usual.
9.3.1 Accessing the object dictionary
void od_write (U32 index, U32 subindex, U32 value)
This function writes the transferred value to the specified location in the object dictionary.
index
Index of the object to be written in the object dictionary
subindex
Subindex of the object to be written in the object dictionary
value
Value to be written
Note
It is highly recommended that the processor time be passed on with
yield()
after calling a
od_write()
. The value is immediately written to the OD. For the firmware to be able to trigger
actions that are dependent on this, however, it must receive computing time. This, in turn, means that
the user program must either be ended or interrupted with
yield()
.
U32 od_read (U32 index, U32 subindex)
This function reads the value at the specified location in the object dictionary and returns it.
Version: 1.0.1 / FIR-v1748
99