From 004ebe0bc4d339db7af32de7e3e43eac2cde5eca Mon Sep 17 00:00:00 2001 From: David Date: Sun, 15 Nov 2026 19:07:07 +0000 Subject: [PATCH] RunTest files added to the repository --- firmware/top/src/test/src/RunTest.cpp | 349 ++++++++++++++++++++++++++ firmware/top/src/test/src/RunTest.h | 63 +++++ 2 files changed, 412 insertions(+) create mode 100644 firmware/top/src/test/src/RunTest.cpp create mode 100644 firmware/top/src/test/src/RunTest.h diff --git a/firmware/top/src/test/src/RunTest.cpp b/firmware/top/src/test/src/RunTest.cpp new file mode 100644 index 0000000..a4e6fcc --- /dev/null +++ b/firmware/top/src/test/src/RunTest.cpp @@ -0,0 +1,349 @@ +/**************************************************************/ +/* runTest.cpp Date: 2026/11/11 */ +/* */ +/* Copyright (c) 2026 MZtech. All rights reserved. */ +/* */ +/**************************************************************/ + +#include + +#include "tb.h" +//#include "runTest.h" +#include "utils.h" + +extern "C" { +#include "VUser.h" +} + + // Entry method for running the tests + int start (uint32_t* coreBaseAddr, zgConfig_t &zgCfg, int node); + + // -------------------------------------------------- +// Test code +// -------------------------------------------------- + +int runTest::start(uint32_t* coreBaseAddr, zgConfig_t &zgCfg, int node) +{ + int error = 0; + + // ------------------------------------ + // Create a core object for reg access + CCoreAuto* pCore = new CCoreAuto(coreBaseAddr); + CTestAuto* pTestBench = new CTestAuto((uint32_t*)(0)); + + // Get the serialiser access object from the core + CPrintCtrlAuto* pPrintCtrl = pCore->pPrintCtrl; + + // ------------------------------------ + // Get the test bench configurations + maxOpWidth = pTestBench->pConfig->GetMaxOpWidth(); + shiftDepth = pTestBench->pConfig->GetShiftDepth(); + enSerdes = pTestBench->pConfig->GetEnSerdes() ? true : false; + noZeroGap = pTestBench->pConfig->GetNoZeroGap() ? true : false; + numHeads = 1;// for now dcs pTestBench->pConfig->GetNumHeads(); + clkFreqMHz = pTestBench->pConfigClkFreq->GetConfigClkFreq(); + + allocArrays(); + + // Fill in the zero-gap configuration values + zgCfg.maxOpWidth = maxOpWidth; + zgCfg.shiftDepth = shiftDepth; + zgCfg.numHeads = numHeads; + zgCfg.clkFreqMHz = clkFreqMHz; + + uint32_t clkTicksPerMicroSec = clkFreqMHz; + + // Set a test timeout value (units are system clock ticks) + pTestBench->pTimeout->SetTimeout(50000 * clkTicksPerMicroSec); // 50ms + + // ------------------------------------ + // Run a sanity check to check we're + // able to access blocks and memory + // before diving into main tests + if (sanityTest(pCore, node) != 0) + { + VPrint("Error: Sanity test failure.\n"); + return TEST_ERROR; + } + + VPrint("\nNODE%d: Starting main tests...(Takes 20 mins)!\n", node); + + VPrint("NODE%d: Configuration: clkFreqMHz=%d enable.e 0x%08x\n\n", + node, clkFreqMHz, enable.e); + + // ------------------------------------ + // Run the main tests + + // Do this test first. Others muck up the TB PIO + + if (enable.e & avalonBus) + error |= avalon_bus_test (pCore, node); + pTestBench->pScratch->SetScratch(6); + + if (enable.e & peiUart) + error |= pei_uart_test (pCore, node); + pTestBench->pScratch->SetScratch(7); + + + if ((enable.e & all) != all) + { + pTestBench->pControl->SetPartialTest(1); + } + else + { + pTestBench->pControl->SetPartialTest(0); + } + + // Return status to calling function + return error ? TEST_ERROR : + enable.e != all ? NOFAILURES : + NOERROR; +} +// -------------------------------------------------- +// Avalon bus tests +// -------------------------------------------------- +int runTest::avalon_bus_test (CCoreAuto* pCore, int node) +{ + int error = NOERROR; + uint32_t status; + + CTestAuto* pTestBench = new CTestAuto((uint32_t*)(0)); + CFpmCtrl6Auto* pFpmCtrl = pCore->pFpmCtrl6; + CPulseGenerator3Auto* pPulseGenerator0 = pCore->pPulseGenerator30; + CPulseGenerator3Auto* pPulseGenerator1 = pCore->pPulseGenerator31; + CPulseGenerator3Auto* pPulseGenerator2 = pCore->pPulseGenerator32; + CPulseGenerator3Auto* pPulseGenerator3 = pCore->pPulseGenerator33; + + VPrint("Starting Avalon bus tests\n"); + + bool foundError = false; + + // Loop Write / Read CSR registers + for (int i = 0; i < 16; i++) { + pFpmCtrl->pFineTimeInit->SetFineTimeInit(0x0a551234 + i); + pPulseGenerator0->pPdOffsetDir0->SetPdOffsetDir0(0xabcdef01 + i); + pPulseGenerator0->pPdOffsetDir1->SetPdOffsetDir1(0x12345678 + i); + pPulseGenerator1->pPdOffsetDir0->SetPdOffsetDir0(0x1abcdef0 + i); + pPulseGenerator1->pPdOffsetDir1->SetPdOffsetDir1(0x81234567 + i); + pFpmCtrl->pCoarseTimeInit->SetCoarseTimeInit(0xaa55aa55 + i); + pPulseGenerator2->pPdOffsetDir0->SetPdOffsetDir0(0x01abcdef + i); + pPulseGenerator2->pPdOffsetDir1->SetPdOffsetDir1(0x78123456 + i); + pPulseGenerator3->pPdOffsetDir0->SetPdOffsetDir0(0xf01abcde + i); + pPulseGenerator3->pPdOffsetDir1->SetPdOffsetDir1(0x67812345 + i); + + uint32_t ret; + + if ((ret = pFpmCtrl->pFineTimeInit->GetFineTimeInit()) != (0x0a551234 + i)) + { + if (!foundError) + VPrint("**ERROR 601 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0xaa551234 + i); + foundError = true; + error |= 1; + } + + if ((ret = pPulseGenerator0->pPdOffsetDir0->GetPdOffsetDir0()) != (0xabcdef01 + i)) + { + if (!foundError) + VPrint("**ERROR 602 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0xabcdef01 + i); + foundError = true; + error |= 1; + } + +#ifdef PDOFFSETDIR1_PRESET + if ((ret = pPulseGenerator0->pPdOffsetDir1->GetPdOffsetDir1()) != (0x12345678 + i)) + { + if (!foundError) + VPrint("**ERROR 603 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0x12345678 + i); + foundError = true; + error |= 1; + } +#endif + + if ((ret = pPulseGenerator1->pPdOffsetDir0->GetPdOffsetDir0()) != (0x1abcdef0 + i)) + { + if (!foundError) + VPrint("**ERROR 604 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0x1abcdef0 + i); + foundError = true; + error |= 1; + } + +#ifdef PDOFFSETDIR1_PRESET + if ((ret = pPulseGenerator1->pPdOffsetDir1->GetPdOffsetDir1()) != (0x81234567 + i)) + { + if (!foundError) + VPrint("**ERROR 605 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0x81234567 + i); + foundError = true; + error |= 1; + } +#endif + if ((ret = pFpmCtrl->pCoarseTimeInit->GetCoarseTimeInit()) != (0xaa55aa55 + i)) + { + if (!foundError) + VPrint("**ERROR 606 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0xaa55aa55 + i); + foundError = true; + error |= 1; + } + + if ((ret = pPulseGenerator2->pPdOffsetDir0->GetPdOffsetDir0()) != (0x01abcdef + i)) + { + if (!foundError) + VPrint("**ERROR 607 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0x01abcdef + i); + foundError = true; + error |= 1; + } + +#ifdef PDOFFSETDIR1_PRESET + if ((ret = pPulseGenerator2->pPdOffsetDir1->GetPdOffsetDir1()) != (0x78123456 + i)) + { + if (!foundError) + VPrint("**ERROR 608 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0x78123456 + i); + foundError = true; + error |= 1; + } +#endif + + if ((ret = pPulseGenerator3->pPdOffsetDir0->GetPdOffsetDir0()) != (0xf01abcde + i)) + { + if (!foundError) + VPrint("**ERROR 609 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0xf01abcde + i); + foundError = true; + error |= 1; + } + +#ifdef PDOFFSETDIR1_PRESET + if ((ret = pPulseGenerator3->pPdOffsetDir1->GetPdOffsetDir1()) != (0x67812345 + i)) + { + if (!foundError) + VPrint("**ERROR 610 : Avalon bus data failure loop %d (got = 0x%08x exp = 0x%08x).\n", i, ret, 0x67812345 + i); + foundError = true; + error |= 1; + } +#endif + } + + return error; +} + // -------------------------------------------------- +// PEI UART test +// -------------------------------------------------- +int runTest::pei_uart_test (CCoreAuto* pCore, int node) +{ + uint32_t error = 0; + uint32_t Datastm8 =0; + + + VPrint("Starting PEI Uart Test \n"); + CTestAuto* pTestBench = new CTestAuto((uint32_t*)(0)); + // set the mode to rolling + //change the write mode to 2 byte + usleepSim(8); + + VPrint("Testing stm8 write\n"); + //change i2c write mode to 2 bytes + uartStream("w0e00000002\0",pTestBench); + // Change rolling mode + uartStream("w0d00000200\0",pTestBench); + //change i2c write mode to 1 bytes + uartStream("w0e00000001\0",pTestBench); + // read register C4 + uartStream("w0D000000C4\0",pTestBench); + uartStream("w0D000000C6\0",pTestBench); + //uartStream("r0D\0", pTestBench); + //usleepSim(2000); + + /*uartStream("r10\0", pTestBench); // Read Eprom Addr, check 5678 + + uint32_t rxedData = uartGetData(4, pTestBench); // receive 4 characters + + if (rxedData != 0x5678) + { + VPrint("Error: PEI serial port not working. Expected 0x5678. Got 0x%08x\n", rxedData); + error |= 1; + } + + usleepSim(8); */ + uartStream("r00\0", pTestBench); // Read PEI ID + + uint32_t peiID = uartGetData(8, pTestBench); // receive 8 characters + + usleepSim(8); + uartStream("r01\0", pTestBench); // Read PEI Ver + + uint32_t peiVersion = uartGetData(4, pTestBench); // receive 4 characters + + VPrint("PEI is %08x Version %d\n", peiID, peiVersion); + uartStream("r0D\0", pTestBench); + Datastm8 = uartGetData(4, pTestBench); // receive 4 characters + VPrint("Register value is:%d\n", Datastm8); + if (peiID != 0x000D3000) + error |= 1; + + return error; +} + +void runTest::uartStream(char* pStream, CTestAuto* pTestBench) +{ + int32_t txReady = 0; + + pTestBench->pScratch->SetScratch(7); + + do { + + txReady = pTestBench->pUartPeiStatus->GetAckW(); + if(txReady = 1){ + pTestBench->pUartPeiDataOut->SetUartPeiDataOut(*pStream++); + usleepSim(3); + pTestBench->pScratch->SetScratch(txReady); + } + else + usleepSim(1); + + pTestBench->pScratch->SetScratch(5); + + } while ( *pStream != '\0'); + + pTestBench->pScratch->SetScratch(11); + +} + +uint32_t runTest::uartGetData(uint32_t numChars, CTestAuto* pTestBench) +{ + uint32_t result = 0; + uint32_t charsRxed = 0; + pTestBench->pUartPeiStatus->SetAckR(1); // clear anything hanging around + + pTestBench->pScratch->SetScratch(99); + + do { + + uint32_t rxReady = pTestBench->pUartPeiStatus->GetReadAvailable(); + + maxOpWidth = pTestBench->pConfig->GetMaxOpWidth(); + + if (pTestBench->pUartPeiStatus->GetReadAvailable()) { + pTestBench->pUartPeiStatus->SetAckR(1); + + result <<= 4; + uint32_t asciiVal = (0xFF & pTestBench->pUartPeiDataIn->GetUartPeiDataIn()); + if (asciiVal >= 'a') + result |= asciiVal - 'a' + 0xA; + else if (asciiVal >= 'A') + result |= asciiVal - 'A' + 0xA; + else + result |= asciiVal - '0'; + + charsRxed++; + } + else + usleepSim(1); + + pTestBench->pScratch->SetScratch(rxReady); + pTestBench->pScratch->SetScratch(100); + + } while (charsRxed < numChars); + + pTestBench->pScratch->SetScratch(101); + + return result; + +} diff --git a/firmware/top/src/test/src/RunTest.h b/firmware/top/src/test/src/RunTest.h new file mode 100644 index 0000000..efe1626 --- /dev/null +++ b/firmware/top/src/test/src/RunTest.h @@ -0,0 +1,63 @@ +/**************************************************************/ +/* runTest.cpp Date: 2026/11/11 */ +/* */ +/* Copyright (c) 2026 MZtech. All rights reserved. */ +/* */ +/**************************************************************/ + +#ifndef _READTEST_H_ +#define _READTEST_H_ + +#ifdef HDL_SIM +#include "VUserMain0.h" + +// Memory model API has C linkage functions +extern "C" { +#include "mem_model.h" +#include "VUser.h" +} + +#else +#error No co-simulation support as yet +#endif + +//#include "runTestLocal.h" +//#include "swimUtils.h" +//#include "zeroGapTests.h" + +// -------------------------------------------------- +// Class for main test methods and control. +// -------------------------------------------------- +class runTest : public swimUtils, zeroGapTests +{ + public: + + // List of tests with bit map definitions + enum testEnable_e { + + + peiUart = 0x00000001 + + }; +} + + // Entry method for running the tests + int start (uint32_t* coreBaseAddr, zgConfig_t &zgCfg, int node); + +private: + + // Quick sanity check to verify basic comms ability. + int sanityTest (CCoreAuto* pCore, int node); + + // Project specific test methods + int pei_uart_test (CCoreAuto* pCore, int node); + + //Uart Test method + + void uartStream(char* pStream, CTestAuto* pTestBench); + uint32_t uartGetData(uint32_t numChars, CTestAuto* pTestBench); + + +}; + +#endif \ No newline at end of file