Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnConfigFrame.h
- Revision:
- 56:0bba0ef15697
- Parent:
- 40:1324da35afd4
- Child:
- 59:21128cc24b04
--- a/SnConfigFrame.h Fri Jan 03 13:03:01 2014 +0000 +++ b/SnConfigFrame.h Thu Oct 30 06:42:17 2014 +0000 @@ -15,16 +15,17 @@ static const uint32_t kMaxCommWinPrdLowPwr; // exclusive max low power comm win period (s) static const uint32_t kMinCommWinDurLowPwr; // exclusive min low power comm win duration (s) static const uint32_t kMaxCommWinDurLowPwr; // exclusive max low power comm win duration (s) - static const uint8_t kConfLblLen=64; // length of configuration label char array (63+'\0') - static const uint8_t kIPLen=16; // length of IP string. matches MBED's Socket class (so no ipv6) + static const uint8_t kConfLblLen=64; // length of configuration label char array (63+'\0') (must not change!! used in i/o sizes) + static const uint8_t kIPLen=16; // length of IP string. matches MBED's Socket class (so no ipv6) (must not change!! used in i/o sizes) static const char* const kDefConfFile; // default configuration file static const char* const kDefIPflag; // flag to use IP default + // ATWD 4channel configs static const uint32_t kMaxSizeOfV1 = + (9u*sizeof(uint32_t)) + (6u*sizeof(uint16_t)) - + (10u*sizeof(uint8_t)) + (3u*kNplasV1*sizeof(uint16_t)) - + (kTotDacs*sizeof(uint16_t)) + + (10u*sizeof(uint8_t)) + (3u*kNplasV1*sizeof(uint16_t)) // 3*Nplas because if StreamHiLo is set, will stream 3 values (composite, high side, low side) + + (kTotDacsAtwd4ch*sizeof(uint16_t)) + (kConfLblLen*sizeof(uint8_t)); static const uint32_t kMaxSizeOfV2 = kMaxSizeOfV1 + sizeof(uint32_t) + sizeof(uint8_t); @@ -35,7 +36,17 @@ static const uint32_t kMaxSizeOfV6 = kMaxSizeOfV5 + sizeof(uint16_t); // To/From Low Power static const uint32_t kMaxSizeOfV7 = kMaxSizeOfV6 + (2u*sizeof(uint8_t)); // add ConnTOmins, ListenTOmins static const uint32_t kMaxSizeOfV8 = kMaxSizeOfV7 - sizeof(uint32_t) + sizeof(uint16_t); // FirstEvt -> FirstSeq - static const uint32_t kMaxSizeOf = kMaxSizeOfV8; + + // SST 4channel configs + static const uint32_t kMaxSizeOfV9 = kMaxSizeOfV8 + - (3u*kNplasV1*sizeof(uint16_t)) // no patterns in SST + - (kTotDacsAtwd4ch*sizeof(uint16_t)) + + (kTotDacsSst4ch*sizeof(uint16_t)) // switch to number of SST dacs + - sizeof(uint8_t) // no stream hi/lo pla flag + - sizeof(uint8_t); // no num plas variable + static const uint32_t kMaxSizeOfV10 = kMaxSizeOfV9 + sizeof(int8_t); // add fTempCheckPeriod + + static const uint32_t kMaxSizeOf = kMaxSizeOfV7; // should be the biggest one enum EDatPackBit { kSDcard = BIT(0), @@ -51,6 +62,7 @@ kDelete = BIT(3), // if bit=0 => do not delete sent files kForceSBDdata = BIT(4), // if bit=0 => do not send data over SBD kHnShBefSendDat = BIT(5), // if bit=0 => do not wait for a handshake after GetConfig before calling SendData + kSendRunSeqList = BIT(6), // if bit=1 and kAllFiles bit=0, send all files in the run/seq list (instead of most recent file) kUseBits = static_cast<int16_t>(-BIT(14)) // useful to initialize fCommSendData as a bit word }; @@ -68,7 +80,11 @@ enum ERunMode { kSingleSeqBit = BIT(0), // if 0, infinite sequences kCountPowerBit = BIT(1), // if 0, count events - }; + kDualThreshBit = BIT(2), // if 0, single sided thresholds on SST + kDiffTrigBit = BIT(3), // if 0, send result of each comparator on SST + kLowPwrSBDonly = BIT(4), // if 0, low power afar/sbd power settings same as normal. if 1, afar off and sbd on during low power mode + kRSListOneCW = BIT(5) // if 0, only clear run/seq list after files sent from it + }; // i/o version static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!) @@ -87,16 +103,20 @@ uint16_t fFirstSeq; // starting sequence number uint32_t fEvtsPerSeq; // number of events per file uint8_t fRunMode; // mode of running (see ERunMode) +#if CHIPBOARD==ATWD4CH uint8_t fStreamHiLoPlas; // (1byte bool) if true, add the separated hi/lo thresh PLA patterns to the i/o +#endif // data packing uint8_t fWvLoseLSB; // number of least significant bits to lose when packing waveform data uint8_t fWvLoseMSB; // number of most significant bits to lose when packing waveform data uint16_t fWvBaseline; // global baseline to use when packing data (useful to reduce clipping on the high end) uint8_t fDatPackType; // type of data packing. OR'd bitword: if bit 1, will pack for writing. see EDatPackBit. default: always pack (all 1's) // trigger setup - uint16_t fDAC[kNchans][kNfpgaDacs]; //[card id][dac id] values should be 0-4095 here (not checked tho) + uint16_t fDAC[kNchans][kNchanDacs]; //[card id][dac id] values should be 0-4095 here (not checked tho) +#if CHIPBOARD==ATWD4CH uint8_t fNumPlas; // number of patterns to use. must be <= kNplas. uint16_t fPLA[kNplas]; //[pattern id] (same for each card) +#endif uint8_t fNumCardsMajLog; // number of cards participating in the MajLogic trigger (1 to 4) uint8_t fEnableThermTrig; // (1byte bool) whether or not to allow thermal triggers float fForceTrigPeriod; // number of seconds between force triggers (0=none) @@ -123,6 +143,8 @@ char fMbedGate[kIPLen]; // IP address of this mbed gateway // watchdog uint32_t fWatchDogPeriod; // number of seconds of inactivity for watchdog to issue a reset + // temp + int8_t fTempCheckPeriod; // number of minutes between temperature checks. if negative, uses parasite power. if 0, never check. // in case of low power, store regular settings // these are not sent over i/o or stored in the file @@ -134,6 +156,24 @@ void SetHardDefaults(); static + uint16_t GetTotDacsForIOVers(const uint8_t rv) { + if (rv<9) { + return kTotDacsAtwd4ch; + } else { + return kTotDacsSst4ch; + } + } + + static + uint16_t GetMaxPlasForIOVers(const uint8_t rv) { + if (rv<9) { + return kNplasV1; + } else { + return 0; + } + } + + static uint32_t SizeOf(const uint8_t rv, const bool streamHiLoPlas, const uint8_t nplas, @@ -159,19 +199,29 @@ maxsize = kMaxSizeOfV7; } else if (rv==8) { maxsize = kMaxSizeOfV8; + } else if (rv==9) { + maxsize = kMaxSizeOfV9; + } else if (rv==10) { + maxsize = kMaxSizeOfV10; } const int32_t lbldiff = kConfLblLen - lblLen; uint32_t sz = maxsize - lbldiff; if ((lbldiff!=0) && (rv>=4)) { sz += 1; // the \0 at the end of the string } - static const uint32_t mhlp = 2u*kNplas*sizeof(uint16_t); - const int32_t dp = (nplas-kNplas)*sizeof(uint16_t); - const uint8_t fac = (streamHiLoPlas) ? 3u : 1u; - sz += (fac*dp); - if (streamHiLoPlas==false) { - sz -= mhlp; + +#if CHIPBOARD==ATWD4CH + if (rv<9) { + // streaming hi/lo plas separately? + const uint32_t mhlp = 2u*GetMaxPlasForIOVers(rv)*sizeof(uint16_t); + const int32_t dp = (nplas-GetMaxPlasForIOVers(rv))*sizeof(uint16_t); + const uint8_t fac = (streamHiLoPlas) ? 3u : 1u; + sz += (fac*dp); + if (streamHiLoPlas==false) { + sz -= mhlp; + } } +#endif return sz; } @@ -194,12 +244,17 @@ bool IsCountingPowerReadings() const { return ((fRunMode & kCountPowerBit)!=0); } bool IsSingleSeqRunMode() const { return ((fRunMode & kSingleSeqBit)!=0); } + bool IsDualThresholdMode() const { return ((fRunMode & kDualThreshBit)!=0); } + bool IsDifferentialTrigMode() const { return ((fRunMode & kDiffTrigBit)!=0); } + bool IsSBDonlyLowPwrMode() const { return ((fRunMode & kLowPwrSBDonly)!=0); } + bool IsRunSeqListOneCommWinOnly() const { return ((fRunMode & kRSListOneCW)!=0); } bool IsLowPowerMode() const { return fIsLowPower; } const char* GetLabel() const { return fLabel; } uint32_t GetLabelStrLen() const { return strlen(fLabel); } uint32_t GetRun() const { return fRun; } uint16_t GetFirstSeq() const { return fFirstSeq; } uint32_t GetEvtsPerFile() const { return fEvtsPerSeq; } + inline uint16_t GetEvtThrtlPeriodMs() const { return fEvtThrtlPeriodMs; } float GetForceTrigPeriod() const { return fForceTrigPeriod; } uint16_t GetHeartbeatPeriod() const { return fHeartBeatPeriod; } @@ -207,9 +262,16 @@ uint16_t GetBatVoltFromLowPwr() const { return fBatVoltFromLowPwr; } uint16_t GetVoltCheckPeriod() const { return fVoltCheckPeriod; } uint32_t GetWatchdogPeriod() const { return fWatchDogPeriod; } + uint16_t GetTempCheckPeriod() const { + const uint16_t t = (fTempCheckPeriod<0) ? (-fTempCheckPeriod) : fTempCheckPeriod; + return t*60; + } + bool IsTempUsingParasitePower() const { return (fTempCheckPeriod<0); } uint16_t GetDac(const uint8_t ch, const uint8_t dn) const { return fDAC[ch][dn]; } +#if CHIPBOARD==ATWD4CH uint8_t GetNumPlas() const { return fNumPlas; } uint16_t GetPla(const uint8_t pn) const { return fPLA[pn]; } +#endif uint8_t GetNumCardsMajLog() const { return fNumCardsMajLog; } bool IsThermTrigEnabled() const { return fEnableThermTrig!=0; } bool IsEachAmpOn() const { @@ -242,15 +304,21 @@ { return (fCommSendData<0) && ((fCommSendData & kForceSBDdata)!=0); } bool IsWaitingHndShkBeforeSendData() const { return (fCommSendData<0) && ((fCommSendData & kHnShBefSendDat)!=0); } + bool IsSendingFilesRunSeqList() const + { return (fCommSendData<0) && ((fCommSendData & kSendRunSeqList)!=0); } uint8_t GetPowerMode() const { return fPowerMode; } int GetPowPinSetting(const EPowerModeBit p, const bool isOn) const { +#if CHIPBOARD==ATWD4CH if (p==kCardDatTak || p==kCardComWin || p==kAmpsDatTak || p==kAmpsComWin) { return isOn ? 0 : 1; } else { return isOn ? 1 : 0; } +#else + return isOn ? 1 : 0; +#endif } int GetPowPinSetting(const EPowerModeBit p) const { // return int to correspond to what DigitalOut::operator= expects @@ -309,6 +377,13 @@ printf("Rv=%hhu\r\n",Rv); #endif if (Rv>0) { + + if (IsLowPowerMode()) { + // the low power bit is not streamed, so we need to + // reset it explicitly + ChangeToNormPower(); + } + uint32_t llen=kConfLblLen; b = SnBitUtils::ReadFrom(b, llen); #ifdef DEBUG @@ -347,10 +422,14 @@ printf("eps=%u\r\n",fEvtsPerSeq); printf("rm=%hhu\r\n",fRunMode); #endif - b = SnBitUtils::ReadFrom(b, fStreamHiLoPlas); +#if CHIPBOARD==ATWD4CH + if (Rv<9) { + b = SnBitUtils::ReadFrom(b, fStreamHiLoPlas); #ifdef DEBUG - printf("shilo=%d\r\n",(int)fStreamHiLoPlas); + printf("shilo=%d\r\n",(int)fStreamHiLoPlas); #endif + } +#endif // ATWD4CH b = SnBitUtils::ReadFrom(b, fWvLoseLSB); #ifdef DEBUG printf("lsb=%hhu\r\n",fWvLoseLSB); @@ -368,23 +447,31 @@ printf("dp=%hhu\r\n",fDatPackType); #endif uint16_t* dc = &(fDAC[0][0]); - for (uint16_t i=0; i<kTotDacs; i++, dc++) { + const uint8_t ntotdacs = GetTotDacsForIOVers(Rv); +#ifdef DEBUG + printf("ntotdacs=%hhu\r\n",ntotdacs); +#endif + for (uint16_t i=0; i<ntotdacs; i++, dc++) { b = SnBitUtils::ReadFrom(b, *dc); #ifdef DEBUG printf("dac[%hu]=%hu\r\n",i,*dc); #endif } - b = SnBitUtils::ReadFrom(b, fNumPlas); +#if CHIPBOARD==ATWD4CH + if (Rv<9) { + b = SnBitUtils::ReadFrom(b, fNumPlas); #ifdef DEBUG - printf("npla=%hhu\r\n",fNumPlas); + printf("npla=%hhu\r\n",fNumPlas); #endif - uint16_t* pl = &(fPLA[0]); - for (uint8_t j=0; j<fNumPlas; j++, pl++) { - b = SnBitUtils::ReadFrom(b, *pl); + uint16_t* pl = &(fPLA[0]); + for (uint8_t j=0; j<fNumPlas; j++, pl++) { + b = SnBitUtils::ReadFrom(b, *pl); #ifdef DEBUG - printf("pla[%hhu]=%hu\r\n",j,*pl); + printf("pla[%hhu]=%hu\r\n",j,*pl); #endif + } } +#endif // ATWD4CH b = SnBitUtils::ReadFrom(b, fNumCardsMajLog); #ifdef DEBUG printf("mj=%hhu\r\n",fNumCardsMajLog); @@ -510,20 +597,30 @@ #ifdef DEBUG printf("watch=%u\r\n",fWatchDogPeriod); #endif - if (fStreamHiLoPlas!=0) { - uint16_t hi, lo; - for (uint8_t j=0; j<fNumPlas; j++) { - b = SnBitUtils::ReadFrom(b, hi); + if (Rv>9) { + b = SnBitUtils::ReadFrom(b, fTempCheckPeriod); + } #ifdef DEBUG - printf("hi=%hu\r\n",hi); + printf("temp check period=%hhd\r\n", fTempCheckPeriod); #endif - b = SnBitUtils::ReadFrom(b, lo); +#if CHIPBOARD==ATWD4CH + if (Rv<9) { + if (fStreamHiLoPlas!=0) { + uint16_t hi, lo; + for (uint8_t j=0; j<fNumPlas; j++) { + b = SnBitUtils::ReadFrom(b, hi); #ifdef DEBUG - printf("lo=%hu\r\n",lo); + printf("hi=%hu\r\n",hi); +#endif + b = SnBitUtils::ReadFrom(b, lo); +#ifdef DEBUG + printf("lo=%hu\r\n",lo); #endif // don't save these + } } } +#endif // ATWD4CH } if (fgApplySafetyNets) { @@ -559,20 +656,29 @@ b = SnBitUtils::WriteTo(b, fFirstSeq); b = SnBitUtils::WriteTo(b, fEvtsPerSeq); b = SnBitUtils::WriteTo(b, fRunMode); - b = SnBitUtils::WriteTo(b, fStreamHiLoPlas); +#if CHIPBOARD==ATWD4CH + if (kIOVers<9) { + b = SnBitUtils::WriteTo(b, fStreamHiLoPlas); + } +#endif b = SnBitUtils::WriteTo(b, fWvLoseLSB); b = SnBitUtils::WriteTo(b, fWvLoseMSB); b = SnBitUtils::WriteTo(b, fWvBaseline); b = SnBitUtils::WriteTo(b, fDatPackType); const uint16_t* dc = &(fDAC[0][0]); - for (uint16_t i=0; i<kTotDacs; i++, dc++) { + const uint8_t ntotdacs = GetTotDacsForIOVers(kIOVers); + for (uint16_t i=0; i<ntotdacs; i++, dc++) { b = SnBitUtils::WriteTo(b, *dc); } - b = SnBitUtils::WriteTo(b, fNumPlas); - const uint16_t* pl = &(fPLA[0]); - for (uint8_t j=0; j<fNumPlas; j++, pl++) { - b = SnBitUtils::WriteTo(b, *pl); +#if CHIPBOARD==ATWD4CH + if (kIOVers<9) { + b = SnBitUtils::WriteTo(b, fNumPlas); + const uint16_t* pl = &(fPLA[0]); + for (uint8_t j=0; j<fNumPlas; j++, pl++) { + b = SnBitUtils::WriteTo(b, *pl); + } } +#endif b = SnBitUtils::WriteTo(b, fNumCardsMajLog); b = SnBitUtils::WriteTo(b, fEnableThermTrig); b = SnBitUtils::WriteTo(b, fForceTrigPeriod); @@ -596,15 +702,20 @@ b = SnBitUtils::WriteTo(b, fMbedMask, kIPLen); b = SnBitUtils::WriteTo(b, fMbedGate, kIPLen); b = SnBitUtils::WriteTo(b, fWatchDogPeriod); - if (fStreamHiLoPlas!=0) { - pl = fPLA; - uint16_t hi, lo; - for (uint8_t j=0; j<fNumPlas; j++, pl++) { - GetHiLoPlas(*pl, hi, lo); - b = SnBitUtils::WriteTo(b, hi); - b = SnBitUtils::WriteTo(b, lo); + b = SnBitUtils::WriteTo(b, fTempCheckPeriod); +#if CHIPBOARD==ATWD4CH + if (kIOVers<9) { + if (fStreamHiLoPlas!=0) { + const uint16_t* pl = &(fPLA[0]); + uint16_t hi, lo; + for (uint8_t j=0; j<fNumPlas; j++, pl++) { + GetHiLoPlas(*pl, hi, lo); + b = SnBitUtils::WriteTo(b, hi); + b = SnBitUtils::WriteTo(b, lo); + } } } +#endif } bool ReadFromFile(const char* cfile); @@ -626,7 +737,11 @@ // returns the num of bytes needed to stream this object // = size of member vars + 1 for i/o version + extra PLA strings (maybe) // + length of label string +#if CHIPBOARD==ATWD4CH return SizeOf(rv, fStreamHiLoPlas!=0, fNumPlas, strlen(fLabel)); +#else // SST + return SizeOf(rv, false, 0, strlen(fLabel)); +#endif } static void SetMacAddress();