FIJI.pm 3.42 KB
Newer Older
1
## @file
2

3
## @class FIJI
4
5
6
7
#
# Various constants used in the FIJI packages.
package FIJI;

8
9
10
use strict;
use warnings;

11
12
13
# Architecture from http://www.perlmonks.org/?node_id=1072731

# Fields:
14
15
16
#    - ini_name = key name in FIJI Settings file
#    - unit = (optional) physical unit
#    - type = (optional) enables type-specific conversions and tests:
Stefan Tauner's avatar
Stefan Tauner committed
17
18
#             natural: values must be oct, hex, binary strings looking like a real number.
#             hexadecimal: values must be hexadecimal numbers.
19
#             boolean: will be convert to a truth value by Perl semantics
Stefan Tauner's avatar
Stefan Tauner committed
20
21
22
23
#    - values = (optional) an array reference listing all valid values (emulates an enum)
#    - phases_opt = (optional) list of phases (subset of "setup", "instrument", "download")
#                  where no value must be present in input (e.g. ID is only necessary while downloading).
#    - default = (optional) default value if not given in file and not determinable otherwise
24
my %designmap;
25
BEGIN {
26
27
28
  %designmap = (
    ID => {
      ini_name => "ID",
Stefan Tauner's avatar
Stefan Tauner committed
29
30
      type => 'hexadecimal',
      phases_opt => [qw(setup instrument)], # generated in instrumentation
31
32
33
    },
    FIU_NUM => {
      ini_name => "FIU_NUM",
Stefan Tauner's avatar
Stefan Tauner committed
34
35
      type => 'natural',
      phases_opt => [qw(setup instrument download)], # auto-generated if need be
36
37
38
39
    },
    BAUDRATE => {
      ini_name => "BAUDRATE",
      default => 115200,
Stefan Tauner's avatar
Stefan Tauner committed
40
      type => 'natural',
41
42
43
44
45
      unit => 'bps',
    },
    FREQUENCY => {
      ini_name => "FREQUENCY",
      default => 50e8,
Stefan Tauner's avatar
Stefan Tauner committed
46
      type => 'natural',
47
48
49
50
51
      unit => 'Hz',
    },
    FIU_CFG_BITS => {
      ini_name => "FIU_CFG_BITS",
      default => 3,
Stefan Tauner's avatar
Stefan Tauner committed
52
53
      type => 'natural',
      phases_opt => [qw(setup instrument download)], # currently not user-configurable at all
54
55
56
57
    },
    TIMER_WIDTH => {
      ini_name => "TIMER_WIDTH",
      default => 32,
Stefan Tauner's avatar
Stefan Tauner committed
58
      type => 'natural',
59
      unit => 'bits',
Stefan Tauner's avatar
Stefan Tauner committed
60
61
62
63
      values => sub {
        my $val = shift;
        return $val % 8 == 0 && $val > 0 && $val <= 64;
      }
64
65
    },
  );
66
67
}

68
69
70
71
72
use constant \%designmap;
use constant DESIGNMAP => \%designmap;

my %fiumap;
BEGIN {
73
74
75
  %fiumap = (
    FIU_NET_NAME => {
      ini_name => "NET_NAME",
Stefan Tauner's avatar
Stefan Tauner committed
76
      phases_opt => [qw(setup)], # defaults to undef
77
78
79
80
81
    },
    FIU_MODEL => {
      ini_name => "FAULT_MODEL",
      default => "RUNTIME",
      values => [qw(RUNTIME PASS_THRU STUCK_AT_0 STUCK_AT_1 STUCK_OPEN DELAY SEU)],
Stefan Tauner's avatar
Stefan Tauner committed
82
      phases_opt => [qw(setup)],
83
84
85
86
87
    },
    FIU_LFSR_EN => {
      ini_name => "ENABLED_BY_LFSR",
      default => 0,
      type => 'boolean',
Stefan Tauner's avatar
Stefan Tauner committed
88
      phases_opt => [qw(setup)],
89
90
91
92
    },
    FIU_LFSR_MASK => {
      ini_name => "LFSR_MASK",
      default => 0,
Stefan Tauner's avatar
Stefan Tauner committed
93
94
      type => 'hexadecimal',
      phases_opt => [qw(setup)],
95
96
97
98
    },
    FIU_LFSR_STUCK_OPEN_BIT => {
      ini_name => "LFSR_BIT_FOR_STUCK_OPEN",
      default => 0,
Stefan Tauner's avatar
Stefan Tauner committed
99
100
      type => 'natural',
      phases_opt => [qw(setup)],
101
102
    },
  );
103
104
105
106
}

use constant \%fiumap;
use constant FIUMAP => \%fiumap;
107

108
109
110
111
112
113
114
115
116
117
118
sub ini2constkey {
  my ($ini_name, $map_ref) = @_;
  $map_ref = DESIGNMAP if !defined($map_ref);
  foreach my $k (keys $map_ref) {
    if ($ini_name eq $map_ref->{$k}->{'ini_name'}) {
      return $k;
    }
  }
  return undef;
}

119
120
121
use base 'Exporter';

# our @EXPORT      = ();
122
123
our @EXPORT      = (keys(%designmap), keys(%fiumap));
our @EXPORT_OK   = (keys(%designmap), 'DESIGNMAP', keys(%fiumap), 'FIUMAP');
124
125
126
127
128
129
130
our %EXPORT_TAGS = (
   all     => \@EXPORT_OK,
   default => \@EXPORT,
   # log     => [ grep /^LOG_/, @EXPORT_OK ], # all constants beginning with "LOG_"
);

1;