From 355c439e6af0b89952e22501480d6e034a2e0fd8 Mon Sep 17 00:00:00 2001
From: Module Testing <uplegger@FNAL.GOV>
Date: Wed, 29 Nov 2023 13:14:42 -0600
Subject: [PATCH] Read SSA2.1 fuse ID

---
 HWInterface/SSA2Interface.cc | 17 +++++++++++++++++
 HWInterface/SSA2Interface.h  |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/HWInterface/SSA2Interface.cc b/HWInterface/SSA2Interface.cc
index 88d42d47d..886e71898 100644
--- a/HWInterface/SSA2Interface.cc
+++ b/HWInterface/SSA2Interface.cc
@@ -131,9 +131,26 @@ bool SSA2Interface::ConfigureChip(Chip* pSSA2, bool pVerify, uint32_t pBlockSize
     }
 
     pSSA2->setRegisterTracking(1);
+    this->ReadFuseID(pSSA2);
     return cSuccess;
 }
 
+void SSA2Interface::ReadFuseID(Chip* pSSA2)
+{
+    this->WriteChipReg(pSSA2, "Fuse_Mode", 0x0);
+    std::this_thread::sleep_for(std::chrono::microseconds(10));
+    this->WriteChipReg(pSSA2, "Fuse_Mode", 0xF);
+    std::this_thread::sleep_for(std::chrono::microseconds(10));
+    this->WriteChipReg(pSSA2, "Fuse_Mode", 0x0);
+
+    uint32_t val = (this->ReadChipReg(pSSA2, "Fuse_Value_b3") << 24) | (this->ReadChipReg(pSSA2, "Fuse_Value_b2") << 16) | (this->ReadChipReg(pSSA2, "Fuse_Value_b1") << 8) |
+                   (this->ReadChipReg(pSSA2, "Fuse_Value_b0") << 0);
+    pSSA2->pChipFuseID.SetId(val);
+
+    LOG(INFO) << GREEN << "FuseID from SSA2#" << +pSSA2->getId() << " Pos " << +pSSA2->pChipFuseID.Pos() << " Wafer " << +pSSA2->pChipFuseID.Wafer() << " Lot " << +pSSA2->pChipFuseID.Lot()
+              << " Status " << +pSSA2->pChipFuseID.Status() << " Process " << +pSSA2->pChipFuseID.Process() << " ADCRef " << +pSSA2->pChipFuseID.ADCRef() << RESET;
+}
+
 uint16_t SSA2Interface::ReadADC(Ph2_HwDescription::ReadoutChip* pChip, std::string pRegName)
 {
     auto theRegister = SSA2_ADC_CONTROL_TABLE.find(pRegName);
diff --git a/HWInterface/SSA2Interface.h b/HWInterface/SSA2Interface.h
index 2019b68f7..593f73a4e 100644
--- a/HWInterface/SSA2Interface.h
+++ b/HWInterface/SSA2Interface.h
@@ -47,7 +47,7 @@ class SSA2Interface : public ReadoutChipInterface
     uint16_t ReadChipReg(Ph2_HwDescription::Chip* pSSA2, const std::string& pRegNode) override;
     uint16_t ReadADC(Ph2_HwDescription::ReadoutChip* pChip, uint8_t pInput);
     uint16_t ReadADC(Ph2_HwDescription::ReadoutChip* pChip, std::string pRegName);
-
+    void     ReadFuseID(Ph2_HwDescription::Chip* pSSA2);
     float    CalculateADCLSB(Ph2_HwDescription::Chip* pSSA2, float vrefExp = SSA2_VREF_EXPECTED);
     uint16_t MeasureGND(Ph2_HwDescription::Chip* pSSA2);
 
-- 
GitLab