Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Wed Jun 05 17:29:31 2019 +0000
Revision:
125:ce4045184366
Parent:
119:b3d7699d0eb0
Added SnRateListner proto-class, publishing this version of the code in order to enable exporting of most recent features.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 1:e392595b4b76 1 #ifndef SN_SnConstants
uci1 1:e392595b4b76 2 #define SN_SnConstants
uci1 1:e392595b4b76 3
uci1 84:80b15993944e 4 // see this file for various switches and options
uci1 84:80b15993944e 5 // used to buid the mbed binary
uci1 84:80b15993944e 6 #include "SnPreCompOptions.h"
uci1 56:0bba0ef15697 7
uci1 1:e392595b4b76 8 #include "SnBitUtils.h"
uci1 37:ff95e7070f26 9 #include "SnCommConstants.h"
uci1 25:57b2627fe756 10
uci1 1:e392595b4b76 11 //
uci1 1:e392595b4b76 12 // constants
uci1 1:e392595b4b76 13 //
uci1 67:ec999336fcd1 14
uci1 67:ec999336fcd1 15 // this should be updated for each and every mbed board (ugh!)
uci1 116:8099b754fbb4 16 static const char kDefaultMacAdress[] = {0x00, 0x02, 0xAA, 0xAA, 0xAA, 0xAA}; // for testing SST
uci1 67:ec999336fcd1 17 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xBB, 0xBB, 0xBB, 0xBB}; // for testing ATWD
uci1 82:f2c8e2048370 18 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF0, 0xAE, 0xE0}; // STN 20 (ATWD MB 1) 0002F7F0AEE0
uci1 83:a0d38ba9d6c2 19 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF0, 0xC3, 0xB6}; // STN 3 (ATWD MB 5) 0002F7F0C3B6
uci1 109:c3fe52b2e46f 20 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF2, 0x1A, 0x8A}; // STN 18 (SST 111) 0002F7F21A8A
uci1 81:6667e2adb926 21 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF0, 0xC6, 0x1A}; // STN 10 (ATWD MB 8) 0002F7F0C61A
uci1 106:4c1c39562b6f 22 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF2, 0x0A, 0x9C}; // STN 14 (SST 104) 0002F7F20A9C
uci1 104:b055a7f39dc0 23 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF2, 0x02, 0xC1}; // STN 17 (SST 109) 0002F7F202C1
uci1 110:d1da040a0cf2 24 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF2, 0x24, 0x44}; // STN 19 (SST 105) 0002F7F22444
uci1 105:bc5d12d38509 25 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF1, 0xF7, 0xA8}; // STN 15 (SST 110) 0002F7F1F7A8
uci1 114:554fa3a956b4 26 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF2, 0x24, 0x4B}; // STN 13 (SST 102) 0002F7F2244B
uci1 115:29f46e4b65d4 27 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF1, 0xF6, 0x34}; // STN 31 (SST 107) 0002F7F1F634
uci1 116:8099b754fbb4 28 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF1, 0xF2, 0x1A}; // STN 32 (SST 112) 0002F7F1F21A (slow)
uci1 107:c8605e985423 29 //static const char kDefaultMacAdress[] = {0x00, 0x02, 0xF7, 0xF1, 0xF2, 0x12}; // STN 30 (SST 113) 0002F7F1F212
uci1 67:ec999336fcd1 30
uci1 40:1324da35afd4 31 // if these change, it is likely that some i/o version (config, event, etc) will need to change
uci1 83:a0d38ba9d6c2 32 static const bool kIridPwrFromAfar = false; // true if Iridium & Afar are on the same relay, false if not
uci1 1:e392595b4b76 33 static const uint32_t kBStime = 946684800u; // 1/1/2000 00:00:00 UTC
uci1 56:0bba0ef15697 34
uci1 56:0bba0ef15697 35 // these constants are used to specify the size of a specific i/o version of a frame, even if e.g. the number of samples changes for later i/o versions
uci1 56:0bba0ef15697 36 // these values should NEVER be changed!!
uci1 56:0bba0ef15697 37 // these values should be used in i/o functions
uci1 56:0bba0ef15697 38 static const uint8_t kNplasV1 = 5u; // to preserve i/o version sizes
uci1 56:0bba0ef15697 39 static const uint16_t kNsampsAtwd = 128u;
uci1 56:0bba0ef15697 40 static const uint16_t kNsampsSst = 256u;
uci1 116:8099b754fbb4 41 static const uint16_t kNsampsSst512 = 512u;
uci1 56:0bba0ef15697 42 static const uint8_t kNchanDacsAtwd = 4u;
uci1 56:0bba0ef15697 43 static const uint8_t kNchanDacsSst = 2u;
uci1 56:0bba0ef15697 44 static const uint8_t kNchansFourAnt = 4u;
uci1 119:b3d7699d0eb0 45 static const uint8_t kNchansEightAnt = 8u;
uci1 119:b3d7699d0eb0 46 static const uint8_t kNchipsSst4ch = 1u;
uci1 119:b3d7699d0eb0 47 static const uint8_t kNchipsSst8ch = 2u;
uci1 56:0bba0ef15697 48 static const uint16_t kTotSampsAtwd4ch = kNchansFourAnt*kNsampsAtwd;
uci1 56:0bba0ef15697 49 static const uint16_t kTotDacsAtwd4ch = kNchansFourAnt*kNchanDacsAtwd;
uci1 56:0bba0ef15697 50 static const uint16_t kTotSampsSst4ch = kNchansFourAnt*kNsampsSst;
uci1 116:8099b754fbb4 51 static const uint16_t kTotSampsSst4ch512= kNchansFourAnt*kNsampsSst512;
uci1 119:b3d7699d0eb0 52 static const uint16_t kTotSampsSst8ch = kNchansEightAnt*kNsampsSst;
uci1 56:0bba0ef15697 53 static const uint16_t kTotDacsSst4ch = kNchansFourAnt*kNchanDacsSst;
uci1 119:b3d7699d0eb0 54 static const uint16_t kTotDacsSst8ch = kNchansEightAnt*kNchanDacsSst;
uci1 119:b3d7699d0eb0 55 static const uint16_t kNstopBytesSst4ch = kNchipsSst4ch * (kNsampsSst / BITS_IN_CHAR); // if the values change, may need to round this numebr
uci1 119:b3d7699d0eb0 56 static const uint16_t kNstopBytesSst4ch512 = kNchipsSst4ch * (kNsampsSst512 / BITS_IN_CHAR); // if the values change, may need to round this numebr
uci1 119:b3d7699d0eb0 57 static const uint16_t kNstopBytesSst8ch = kNchipsSst8ch * (kNsampsSst / BITS_IN_CHAR); // if the values change, may need to round this numebr
uci1 56:0bba0ef15697 58
uci1 56:0bba0ef15697 59 // these are the station config sizes, and may change. they should not be used in i/o functions. i/o versions need updating as these change!
uci1 56:0bba0ef15697 60 #if CHIPBOARD==ATWD4CH
uci1 56:0bba0ef15697 61 static const uint8_t kNchans = kNchansFourAnt;
uci1 56:0bba0ef15697 62 static const uint16_t kNsamps = kNsampsAtwd;
uci1 40:1324da35afd4 63 static const uint8_t kNplas = kNplasV1; // update config i/o version if this changes
uci1 56:0bba0ef15697 64 static const uint8_t kNchanDacs = kNchanDacsAtwd;
uci1 1:e392595b4b76 65 static const uint16_t kNoTrigPla = 0x0000u;
uci1 56:0bba0ef15697 66 static const float kAsfClkPrdUs = 8.535; // us -- change kAdcToMBtimeCut if this is <=2us
uci1 56:0bba0ef15697 67 static const float kAdcToMBtimeCut = (kNsamps*kAsfClkPrdUs)+(kAsfClkPrdUs/2.0);
uci1 114:554fa3a956b4 68 #elif (CHIPBOARD==SST4CH) || (CHIPBOARD==SST4CH_1GHz)
uci1 56:0bba0ef15697 69 static const uint8_t kNchans = kNchansFourAnt;
uci1 56:0bba0ef15697 70 static const uint16_t kNsamps = kNsampsSst;
uci1 56:0bba0ef15697 71 static const uint8_t kNchanDacs = kNchanDacsSst;
uci1 56:0bba0ef15697 72 static const uint16_t kNstopBytes = kNstopBytesSst4ch;
uci1 119:b3d7699d0eb0 73 static const uint8_t kNumLTC2657s = 1;
uci1 119:b3d7699d0eb0 74 static const uint8_t kChansPerLTC2657 = 4;
uci1 119:b3d7699d0eb0 75 static const uint8_t kLTC2657Adrs[] = { 0x73u << 1 }; // slave address that every LTC2657 DAC chip will respond to
uci1 56:0bba0ef15697 76 static const uint8_t kUpdateDacCmd = 0x3u; // LTC2657 DAC chip command bits that write to & update DAC value
uci1 56:0bba0ef15697 77 static const uint8_t kMaxDacSetTries = 3u; // how many times to retry setting a dac in case no ACK is received from the DAC chip
uci1 125:ce4045184366 78 static const uint8_t kMaxRateReadTries = 3u; // how many times to retry reading a single-channel rate from FPGA if no ACK is receiv
uci1 116:8099b754fbb4 79 #elif (CHIPBOARD==SST4CH512) || (CHIPBOARD==SST4CH512_1GHz)
uci1 116:8099b754fbb4 80 static const uint8_t kNchans = kNchansFourAnt;
uci1 116:8099b754fbb4 81 static const uint16_t kNsamps = kNsampsSst512;
uci1 116:8099b754fbb4 82 static const uint8_t kNchanDacs = kNchanDacsSst;
uci1 116:8099b754fbb4 83 static const uint16_t kNstopBytes = kNstopBytesSst4ch512;
uci1 119:b3d7699d0eb0 84 static const uint8_t kNumLTC2657s = 1;
uci1 119:b3d7699d0eb0 85 static const uint8_t kChansPerLTC2657 = 4;
uci1 119:b3d7699d0eb0 86 static const uint8_t kLTC2657Adrs[] = { 0x73u << 1 }; // slave address that every LTC2657 DAC chip will respond to
uci1 119:b3d7699d0eb0 87 static const uint8_t kUpdateDacCmd = 0x3u; // LTC2657 DAC chip command bits that write to & update DAC value
uci1 119:b3d7699d0eb0 88 static const uint8_t kMaxDacSetTries = 3u; // how many times to retry setting a dac in case no ACK is received from the DAC chip
uci1 125:ce4045184366 89 static const uint8_t kMaxRateReadTries = 3u; // how many times to retry reading a single-channel rate from FPGA if no ACK is receiv
uci1 119:b3d7699d0eb0 90 #elif (CHIPBOARD==SST8CH) || (CHIPBOARD==SST8CH_1GHz)
uci1 119:b3d7699d0eb0 91 static const uint8_t kNchans = kNchansEightAnt;
uci1 119:b3d7699d0eb0 92 static const uint16_t kNsamps = kNsampsSst;
uci1 119:b3d7699d0eb0 93 static const uint8_t kNchanDacs = kNchanDacsSst;
uci1 119:b3d7699d0eb0 94 static const uint16_t kNstopBytes = kNstopBytesSst8ch;
uci1 119:b3d7699d0eb0 95 static const uint8_t kNumLTC2657s = 2;
uci1 119:b3d7699d0eb0 96 static const uint8_t kChansPerLTC2657 = 4;
uci1 119:b3d7699d0eb0 97 static const uint8_t kLTC2657Adrs[] = { 0x41u << 1, 0x32u << 1 }; // Adr[0]=1000001 (flt-flt-flt), Adr[2]=0110010 (flt-gnd-flt)
uci1 116:8099b754fbb4 98 static const uint8_t kUpdateDacCmd = 0x3u; // LTC2657 DAC chip command bits that write to & update DAC value
uci1 116:8099b754fbb4 99 static const uint8_t kMaxDacSetTries = 3u; // how many times to retry setting a dac in case no ACK is received from the DAC chip
uci1 125:ce4045184366 100 static const uint8_t kMaxRateReadTries = 3u; // how many times to retry reading a single-channel rate from FPGA if no ACK is receiv
uci1 56:0bba0ef15697 101 #endif
uci1 84:80b15993944e 102 static const uint8_t kNcomms = 2u; // must match the number of comms enabled in SnPreCompOptions
uci1 116:8099b754fbb4 103 static const uint16_t kNvoltsAve = 500u; // must be greater than ~10 (but value is not checked, so <2 will result in a divide by 0)
uci1 16:744ce85aede2 104
uci1 1:e392595b4b76 105 static const uint32_t kAbsMaxTimer = 1800u; // timers use integers counting us and can't go longer than ~ this many secs
uci1 3:24c5f0f50bf1 106
uci1 40:1324da35afd4 107 // NOTE: these times (in sec) must be less than kAbsMaxTimer (this is not checked, however)
uci1 84:80b15993944e 108 static const uint8_t kDefTimeoutMin = 1u; // minutes. used in case (minimum) range needs enforcing
uci1 84:80b15993944e 109 static const uint8_t kDefTimeoutSafe = 3u; // minutes. used in case a clock error is detected or max range needs enforcing
uci1 40:1324da35afd4 110 static const uint32_t kCommWinLongPrdTk = 300u; // seconds. check if it's time for a comm win every X sec. this way comm per can be longer than Timer allows
uci1 40:1324da35afd4 111
uci1 84:80b15993944e 112 // 2015-10-12: increased from 4 to 75. this raises the window before a reboot from ~1 hour to ~1 day, depending on config options
uci1 84:80b15993944e 113 static const uint16_t kMaxConsecCommFails = 75; // (exclusive) number of times a comm win can fail before the mbed resets
uci1 40:1324da35afd4 114
uci1 28:484943132bb0 115 // safety nets
uci1 40:1324da35afd4 116 static const uint16_t kMaxFirstSeq = 25000; // max specifiable seq number -- leave room to grow
uci1 28:484943132bb0 117 static const float kMinForcePer = 0.05; // seconds -- safety net for max force trigger rate
uci1 28:484943132bb0 118 static const uint16_t kMaxThrottlePerMs = 60000; // ms -- max time between thermal triggers
uci1 28:484943132bb0 119 static const uint16_t kMaxBatVoltLowPwr = 25000; // ADCs -- probably futile, but try to prevent it from being in low power mode always
uci1 40:1324da35afd4 120 static const uint32_t kMinCommWinPeriod = 120; // seconds -- min time between communication windows
uci1 28:484943132bb0 121 static const uint32_t kMaxCommWinPeriod = 259200; // seconds -- max time between communication windows
uci1 40:1324da35afd4 122 static const uint32_t kMinCommWinDur = 600; // seconds -- min communication window duration -- must be >= Ncomms*listen/connect timeout
uci1 28:484943132bb0 123 static const uint32_t kMaxWatchDogPer = 3600; // seconds -- max time before watchdog reset on idle
uci1 40:1324da35afd4 124 static const uint32_t kMinWatchDogPer = 300; // seconds -- min time before watchdog reset on idle
uci1 116:8099b754fbb4 125 static const uint8_t kMinSingleFreqSuppRatio = 26; // L1>0.1 is the min cut value (avoid rejecting absolutely all events)
uci1 116:8099b754fbb4 126 static const uint8_t kMaxSingleFreqSuppRatio =255; // L1>1.0 is the max cut value
uci1 116:8099b754fbb4 127 static const uint8_t kDefSingleFreqSuppRatio = 77; // L1=0.3 is the default
uci1 28:484943132bb0 128
uci1 1:e392595b4b76 129 static const uint16_t kTotSamps = kNchans*kNsamps;
uci1 56:0bba0ef15697 130 static const uint16_t kTotDacs = kNchans*kNchanDacs;
uci1 1:e392595b4b76 131
uci1 16:744ce85aede2 132
uci1 84:80b15993944e 133 enum ETrgBit_t {
uci1 116:8099b754fbb4 134 // see SnEventFrame::fTrgBits for number of available bits
uci1 84:80b15993944e 135 kThermal = BIT(0), // thermal trigger
uci1 84:80b15993944e 136 kForced = BIT(1), // forced trigger
uci1 84:80b15993944e 137 kExternal = BIT(2), // reserved for external, but impossible to set with current DAQ
uci1 84:80b15993944e 138 kSingleFreqSupp = BIT(3), // the L1 trigger to cut away events with a large fraction of power in a single frequency
uci1 116:8099b754fbb4 139 // bit 4 not yet used
uci1 116:8099b754fbb4 140 kL1Scaledown = BIT(5), // whether the event is written thanks to the L1 scaledown
uci1 84:80b15993944e 141 kL1TrgApplied = BIT(6), // whether to throw away events based on L1 triggers
uci1 84:80b15993944e 142 kAdcToMBflag = BIT(7) // flag events that took too long to get data from dCards to MB
uci1 84:80b15993944e 143 };
uci1 84:80b15993944e 144
uci1 84:80b15993944e 145 enum EL1TrigStatus {
uci1 84:80b15993944e 146 kL1Fail=0,
uci1 84:80b15993944e 147 kL1Pass=1,
uci1 84:80b15993944e 148 kL1UnableToProcess=2
uci1 84:80b15993944e 149 };
uci1 1:e392595b4b76 150
uci1 0:664899e0b988 151 #endif // SN_SnConstants