diff --git a/scripts/gen_fault_headers.py b/scripts/gen_fault_headers.py index c697b19e4241511b4dad2ec9479f8ef275403835..0a5badbdaac96f3de9d501d912fbe39c1f3f4ef2 100755 --- a/scripts/gen_fault_headers.py +++ b/scripts/gen_fault_headers.py @@ -58,6 +58,7 @@ def genEnum(name, s, inc): a += " " + i + " = " + str(s[i]) + ",\n" cnt += 1 a += "};\n" + a += "const std::size_t %s_SIZE = %d;\n" %(name, cnt) return a def genHeaderFile(fileName,csvFile): @@ -99,17 +100,14 @@ def genHeaderFile(fileName,csvFile): #ifndef SKYWARD_FAULT_CTRL_LIST_H #define SKYWARD_FAULT_CTRL_LIST_H -namespace FaultCounter -{ - ''') % (csvFile, fileHash(csvFile), datetime.datetime.now()) - content += genEnum("FaultCategory", categories, False) - content += "\n" content += genEnum("Fault", enums, True) + content += "\nnamespace FaultCounterData\n{\n\n" + content += genEnum("FaultCategory", categories, False) content += ''' // Usage: categoryID = FaultCounter::FaultToCategory[faultID]; -static const uint32_t FaultToCategory[] = +const uint32_t FaultToCategory[] = { ''' colCnt = 0 @@ -122,7 +120,7 @@ static const uint32_t FaultToCategory[] = content += ''' }; /* CategoryMapping */ -} /* FaultCounter */ +} /* FaultCounterData */ #endif /* SKYWARD_FAULT_CTRL_LIST_H */ diff --git a/src/shared/diagnostic/FaultCounter.h b/src/shared/diagnostic/FaultCounter.h new file mode 100644 index 0000000000000000000000000000000000000000..ea6fabad995b230e14392485b59726b9d83e4bb4 --- /dev/null +++ b/src/shared/diagnostic/FaultCounter.h @@ -0,0 +1,84 @@ +/* Copyright (c) 2015-2017 Skyward Experimental Rocketry + * Authors: Alain Carlucci + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef SKYWARD_FAULT_CTRL_H +#define SKYWARD_FAULT_CTRL_H + +#include <Common.h> +#include <Singleton.h> +#include "FaultCounterData.h" + +class FaultCounterMgr : public Singleton<FaultCounterMgr> +{ + friend class Singleton<FaultCounterMgr>; +public: + ~FaultCounterMgr() + { + + } + + void Increment(const Fault id) + { + using FaultCounterData::FaultToCategory; + + miosix::FastInterruptDisableLock dLock; + const uint32_t numId = static_cast<uint32_t>(id); + const uint32_t catId = FaultToCategory[numId]; + mCounters[numId]++; + mCategories[catId]++; + + mFaultTriggered[numId] = 1; + mCategoryTriggered[catId] = 1; + } + + inline std::pair<const uint8_t *, size_t> GetFaultCounters() const + { + return std::make_pair(mCounters, Fault_SIZE); + } + + inline std::pair<const uint8_t *, size_t> GetCategoryCounters() const + { + using FaultCounterData::FaultCategory_SIZE; + return std::make_pair(mCategories, FaultCategory_SIZE); + } + +private: + uint8_t mCounters[Fault_SIZE]; + uint8_t mCategories[FaultCounterData::FaultCategory_SIZE]; + + std::vector<bool> mFaultTriggered; + std::vector<bool> mCategoryTriggered; + + FaultCounterMgr() + { + memset(mCounters, 0, sizeof(mCounters)); + memset(mCategories, 0, sizeof(mCategories)); + + // TODO: static bitmap? + mFaultTriggered.resize(Fault_SIZE); + mCategoryTriggered.resize(FaultCounterData::FaultCategory_SIZE); + } +}; + +#define sFaultCounterMgr FaultCounterMgr::getInstance() + +#endif /* ifndef SKYWARD_FAULT_CTRL_H */ diff --git a/src/shared/diagnostic/FaultCounterData.h b/src/shared/diagnostic/FaultCounterData.h index 73d0f02590ca6000b86d80402e4e9ee25f3b04ab..2310e6300de7280f5b0c3287c779832d7d7cdbf4 100644 --- a/src/shared/diagnostic/FaultCounterData.h +++ b/src/shared/diagnostic/FaultCounterData.h @@ -28,34 +28,36 @@ // CSV File: data/fault_list.csv // SHA1 of CSV File: e9a518af53ac91c2e57142fda140689918338c66 -// Autogen date: 2017-09-16 19:03:30.061175 +// Autogen date: 2017-09-16 21:53:44.208079 #include <cstdint> #ifndef SKYWARD_FAULT_CTRL_LIST_H #define SKYWARD_FAULT_CTRL_LIST_H -namespace FaultCounter +enum class Fault { + F_ANAKIN_TEST_FAULT = 0, +}; +const std::size_t Fault_SIZE = 1; -enum class FaultCategory +namespace FaultCounterData { - ANAKIN = 0, -}; -enum class Fault +enum class FaultCategory { - F_ANAKIN_TEST_FAULT = 0, + ANAKIN = 0, }; +const std::size_t FaultCategory_SIZE = 1; // Usage: categoryID = FaultCounter::FaultToCategory[faultID]; -static const uint32_t FaultToCategory[] = +const uint32_t FaultToCategory[] = { 0, }; /* CategoryMapping */ -} /* FaultCounter */ +} /* FaultCounterData */ #endif /* SKYWARD_FAULT_CTRL_LIST_H */