Changes for page EPICS

Last modified by Sebastian Marsching on 2023/02/27 22:56

From version 1.1
edited by Sebastian Marsching
on 2022/04/03 13:57
Change comment: There is no comment for this version
To version 2.1
edited by Sebastian Marsching
on 2023/02/27 22:56
Change comment: There is no comment for this version

Summary

Details

Page properties
Tags
... ... @@ -1,0 +1,1 @@
1 +Network
Content
... ... @@ -1,5 +1,43 @@
1 1  {{toc/}}
2 2  
3 +# EPICS Base
4 +
5 +## Extracting the upper 32 bits from a 64-bit integer
6 +
7 +Sometimes, it is necessary to extract individual bits from a 64-bit integer (e.g. one that is read from a hardware register through the `int64in` record). This is possible through some calc record magic.
8 +
9 +Please note that this depends on some internal casting behavior, so it might not work on all platforms. It has been tested to work successfully with EPICS Base 7.0.6 running x86_64 Linux, but it seems like it does not work with the same version of EPICS running on ARM Linux.
10 +
11 + record(int64in, "$(P)$(R)MyRegister") {
12 + field(FLNK, "$(P)$(R)MyRegister:Low")
13 + }
14 +
15 + record(mbbiDirect, "$(P)$(R)MyRegister:Low") {
16 + field(DTYP, "stream")
17 + field(INP, "$(P)$(R)MyRegister MSI")
18 + field(FLNK, "$(P)$(R)MyRegister:CalcHigh")
19 + }
20 +
21 + # This looks a bit strange, but it is a reliable way of extracting the upper
22 + # 32 bits of the 64 bit register. This works, because the value is implicitly
23 + # converted to a double, which preserves the upper 52 bits of the original
24 + # value. From this value, we have to substract the unsigned value of the lower
25 + # 32 bits (if we didn’t do this, we would get an off-by-one error under certain
26 + # circumstances due to rounding), and then we can right-shift by 32 bits (which
27 + # we have to do through division for a floating point number). Finally, we cut
28 + # off any fractional parts that might be left due to rounding.
29 + record(calc, "$(P)$(R)MyRegister:CalcHigh") {
30 + field(CALC, "FLOOR((A-(B+((B<0)?(2^32):0)))/(2^32))")
31 + field(INPA, "$(P)$(R)MyRegister MSI")
32 + field(INPB, "$(P)$(R)MyRegister:Low MSI")
33 + field(FLNK, "$(P)$(R)MyRegister:High")
34 + }
35 +
36 + record(mbbiDirect, "$(P)$(R)MyRegister:High") {
37 + field(DTYP, "stream")
38 + field(INP, "$(P)$(R)MyRegister:CalcHigh MSI")
39 + }
40 +
3 3  # EDM
4 4  
5 5  In addition to the dependencies for MEDM I had to install the following packages:
... ... @@ -66,6 +66,4 @@
66 66  #define ASYN_TRACEIO_ASCII 0x0001
67 67  #define ASYN_TRACEIO_ESCAPE 0x0002
68 68  #define ASYN_TRACEIO_HEX 0x0004
69 -
70 -
71 71  ```