1 #pragma once 2 3 #include <algorithm> 4 #include <map> 5 #include <vector> 6 #include "device.hpp" 7 #include "pmbus.hpp" 8 #include "types.hpp" 9 10 namespace witherspoon 11 { 12 namespace power 13 { 14 15 /** 16 * @class UCD90160 17 * 18 * This class implements fault analysis for the UCD90160 19 * power sequencer device. 20 * 21 */ 22 class UCD90160 : public Device 23 { 24 public: 25 26 UCD90160() = delete; 27 ~UCD90160() = default; 28 UCD90160(const UCD90160&) = delete; 29 UCD90160& operator=(const UCD90160&) = delete; 30 UCD90160(UCD90160&&) = default; 31 UCD90160& operator=(UCD90160&&) = default; 32 33 /** 34 * Constructor 35 * 36 * @param[in] instance - the device instance number 37 */ 38 UCD90160(size_t instance); 39 40 /** 41 * Analyzes the device for errors when the device is 42 * known to be in an error state. A log will be created. 43 */ 44 void onFailure() override; 45 46 /** 47 * Checks the device for errors and only creates a log 48 * if one is found. 49 */ 50 void analyze() override; 51 52 /** 53 * Clears faults in the device 54 */ 55 void clearFaults() override; 56 57 private: 58 59 /** 60 * Checks for VOUT faults on the device. 61 * 62 * This device can monitor voltages of its dependent 63 * devices, and VOUT faults are voltage faults 64 * on these devices. 65 * 66 * @return bool - true if an error log was created 67 */ 68 bool checkVOUTFaults(); 69 70 /** 71 * Checks for PGOOD faults on the device. 72 * 73 * This device can monitor the PGOOD signals of its dependent 74 * devices, and this check will look for faults of 75 * those PGOODs. 76 * 77 * @param[in] polling - If this is running while polling for errors, 78 * as opposing to analyzing a fail condition. 79 * 80 * @return bool - true if an error log was created 81 */ 82 bool checkPGOODFaults(bool polling); 83 84 /** 85 * Creates an error log when the device has an error 86 * but it isn't a PGOOD or voltage failure. 87 */ 88 void createPowerFaultLog(); 89 90 /** 91 * Reads the status_word register 92 * 93 * @return uint16_t - the register contents 94 */ 95 uint16_t readStatusWord(); 96 97 /** 98 * Reads the mfr_status register 99 * 100 * @return uint32_t - the register contents 101 */ 102 uint32_t readMFRStatus(); 103 104 /** 105 * Says if we've already logged a Vout fault 106 * 107 * The policy is only 1 of the same error will 108 * be logged for the duration of a class instance. 109 * 110 * @param[in] page - the page to check 111 * 112 * @return bool - if we've already logged a fault against 113 * this page 114 */ 115 inline bool isVoutFaultLogged(uint32_t page) const 116 { 117 return std::find(voutErrors.begin(), 118 voutErrors.end(), 119 page) != voutErrors.end(); 120 } 121 122 /** 123 * Saves that a Vout fault has been logged 124 * 125 * @param[in] page - the page the error was logged against 126 */ 127 inline void setVoutFaultLogged(uint32_t page) 128 { 129 voutErrors.push_back(page); 130 } 131 132 /** 133 * List of pages that Vout errors have 134 * already been logged against 135 */ 136 std::vector<uint32_t> voutErrors; 137 138 /** 139 * The read/write interface to this hardware 140 */ 141 pmbus::PMBus interface; 142 143 /** 144 * Keeps track of device access errors to avoid repeatedly 145 * logging errors for bad hardware 146 */ 147 bool accessError = false; 148 149 /** 150 * Map of device instance to the instance specific data 151 */ 152 static const ucd90160::DeviceMap deviceMap; 153 }; 154 155 } 156 } 157