From e658d077d9ce97c455e23dd75af9d1ec1517e401 Mon Sep 17 00:00:00 2001 From: Christos Spirotis Date: Thu, 2 Jul 2020 10:35:42 +0100 Subject: [PATCH] DHBKM1024I-8 Removed local fpm6utils.h file. Removed constant value setup used for debugging. --- firmware/dhb_fpga_top/src/dhb_fpga_top.vhd | 8 +- firmware/dhb_fpga_top/src/power_control.vhd | 31 +++- firmware/top/src/test/src/fpm6Utils.h | 192 -------------------- firmware/top/src/test/src/runTest.cpp | 64 ++++--- 4 files changed, 69 insertions(+), 226 deletions(-) delete mode 100644 firmware/top/src/test/src/fpm6Utils.h diff --git a/firmware/dhb_fpga_top/src/dhb_fpga_top.vhd b/firmware/dhb_fpga_top/src/dhb_fpga_top.vhd index f4f488e..76fd2f5 100644 --- a/firmware/dhb_fpga_top/src/dhb_fpga_top.vhd +++ b/firmware/dhb_fpga_top/src/dhb_fpga_top.vhd @@ -261,9 +261,9 @@ architecture struct of dhb_fpga_top is type power_ch_cnt_t is array (0 to 9) of integer range 0 to 255; type power_edg_t is array (0 to 9) of std_logic_vector(2 downto 0); - signal power_on : std_logic := '1'; + signal power_on : std_logic := '0'; signal power_hold : std_logic := '0'; - signal power_ch_en : std_logic_vector(9 downto 0) := "1111111111"; + signal power_ch_en : std_logic_vector(9 downto 0) := (others => '0'); signal power_ch_edg : power_edg_t; signal power_busy : std_logic; signal power_configured : std_logic; @@ -271,7 +271,7 @@ architecture struct of dhb_fpga_top is signal shutdown_int : std_logic := '0'; signal pgood_dly : std_logic_vector(7 downto 0) := X"0A"; signal pgood_cnt : power_ch_cnt_t := ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); - signal pgood_mon : std_logic_vector(9 downto 0) := (others => '0'); + signal pgood_mon : std_logic_vector(9 downto 0); signal pgood_edg : power_edg_t; signal pgood_bad : std_logic_vector(9 downto 0) := (others => '0'); @@ -282,7 +282,7 @@ architecture struct of dhb_fpga_top is type sel_ch_iv_t is array (boolean) of power_ch_iv_t; constant sel_ch_iv : sel_ch_iv_t := (true => ( "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"14", "00" & X"14" ), - false => ( "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff", "10" & X"ff" ) ); + false => ( "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"00", "00" & X"08", "10" & X"89" ) ); signal power_ch_iv : power_ch_iv_t := sel_ch_iv(TEST_MODE); signal heater_temp : std_logic_vector(11 downto 0); diff --git a/firmware/dhb_fpga_top/src/power_control.vhd b/firmware/dhb_fpga_top/src/power_control.vhd index c0b4854..61e95c9 100644 --- a/firmware/dhb_fpga_top/src/power_control.vhd +++ b/firmware/dhb_fpga_top/src/power_control.vhd @@ -118,7 +118,10 @@ architecture struct of power_control is constant active_ch : std_logic_vector(21 downto 0) := "0111001111011100000100"; begin - + + --------------------------------------------------- + -- Master I2C + --------------------------------------------------- simple_i2c_master_inst : simple_i2c_master generic map ( CLOCK_DIVIDER => i2c_freq_div(TEST_MODE) @@ -139,7 +142,10 @@ begin rd_data_out => i2c_rd_data, error => i2c_error ); - + + --------------------------------------------------- + -- Controller state machine + --------------------------------------------------- control_proc : process (clk) begin if rising_edge(clk) then @@ -147,10 +153,12 @@ begin ctrl_st_d <= ctrl_st; i2c_wr <= '0'; + -- Done for timing , register the current channel settling point value if ch_idx < 10 then vctrl <= vctrl_s(ch_idx); end if; - + + -- Grab data returned by the I2C interface if i2c_data_rdy = '1' and byte_idx = 3 then adc_val(11 downto 8) <= i2c_rd_data(3 downto 0); elsif i2c_data_rdy = '1' and byte_idx = 0 then @@ -158,10 +166,12 @@ begin end if; case ctrl_st is - + when inactive => + -- Detect power on if power_on_d = '0' and power_on = '1' then busy <= '1'; + -- Register settings for this operation for i in 0 to no_ch-1 loop vctrl_v(i) <= vctrl_iv(i*10+9 downto i*10); vctrl_s(i) <= vctrl_sp(i*12+11 downto i*12); @@ -173,13 +183,17 @@ begin end if; when set_dac_iv => + -- If not coming from sending a DAC message if ctrl_st_d /= msg_dac_wait then + -- For every enabled channel if enable_ch(ch_idx) = '1' then + -- Send a dac message to set the initial value byte_idx <= 0; cmd_idx <= 8; rtrn_st <= set_dac_iv; ctrl_st <= msg_dac; else + -- Channel disabled so move to next one if ch_idx = no_ch-1 then ch_idx <= 0; ctrl_st <= set_dac_en; @@ -187,6 +201,7 @@ begin ch_idx <= ch_idx + 1; end if; end if; + -- DAC message just sent so move to next channel else if ch_idx = no_ch-1 then ch_idx <= 0; @@ -204,7 +219,7 @@ begin rtrn_st <= set_dac_en; ctrl_st <= msg_dac; elsif ctrl_st_d = msg_dac_wait and ch_idx = 8 then - ctrl_st <= sleep; + ctrl_st <= set_adc_idle; else byte_idx <= 0; cmd_idx <= 1; @@ -212,7 +227,7 @@ begin ctrl_st <= msg_dac; end if; - when set_adc_idle => + when set_adc_idle => if ctrl_st_d /= msg_adc_wait then byte_idx <= 0; cmd_idx <= 0; -- Idle mode @@ -318,10 +333,8 @@ begin end if; when sleep => - configured <= '1'; - ch_idx <= 0; if sl_done = '1' and ctrl_st_d = sleep then - ctrl_st <= set_dac_iv; + ctrl_st <= poll_adc; end if; when read_adc => diff --git a/firmware/top/src/test/src/fpm6Utils.h b/firmware/top/src/test/src/fpm6Utils.h deleted file mode 100644 index 183b62e..0000000 --- a/firmware/top/src/test/src/fpm6Utils.h +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************/ -/* fpm6Utils.h Date: 2020/04/29 */ -/* */ -/* Copyright (c) 2020 GIS. All rights reserved. */ -/* */ -/* Utilities class definition for configuring & running FPM6 */ -/* */ -/**************************************************************/ - -#include -#include - -#ifndef _FPM6UTILS_H_ -#define _FPM6UTILS_H_ - -// Before this file is included, EL-HAL definitions for the core -// and the FPM6 (and its subcomponents) must be included - -class fpm6Utils -{ -public: - - static const uint32_t REG_WR_LATENCY_NS = 60; - static const uint32_t STARTUP_LATENCY_NS = 2000; //18000; - - // Constructor - fpm6Utils() {}; - -protected: - - // ------------------------------------ - // Set up FPM for PD emulation - // - void configFpmForEmulPulses(CCoreAuto* pCore, - double encFreqKHz, - double divRatio, - uint32_t numSubPixPhases, - double clkFreqMHz = 100.0, - uint32_t seq[] = NULL, - uint32_t seqLen = 0) - { - configPdEmulator (pCore, divRatio, encFreqKHz, clkFreqMHz); - fpmConfig (pCore, divRatio, numSubPixPhases, seq, seqLen); - }; - -// ------------------------------------ -// Configure the FPM's pulse generator -// -int fpmConfig(CCoreAuto* pCore, double divRatio, uint32_t numSubPixPhases, uint32_t seq[], uint32_t seqLen) -{ - CPulseGenerator3Auto* pPulseGen[4] = { pCore->pPulseGenerator30, pCore->pPulseGenerator31, pCore->pPulseGenerator32, pCore->pPulseGenerator33 }; - - for (int ch = 0; ch < 4; ch++) - { - - // Program the sequence if a buffer pointer is provided and the length isn't zero. - if (seq != NULL && seqLen != 0) - { - // Load the sequencer with default program - uint32_t seqBaseAddr = (uint32_t)pPulseGen[ch]->GetCsrBaseAddr() + CSR_PULSE_GENERATOR_3_CHANNEL_CONTROLLER_SEQ; - - for(int idx = 0; idx < seqLen; idx++) - { - csrWriteMem(seqBaseAddr + idx*4, seq[idx]); - } - } - - // Disable/Re-enable first the whole pulse_generator - pPulseGen[ch]->pPulseGenControl->SetPulseGenControl(0); - pPulseGen[ch]->pPulseGenControl->SetEnable(1); - pPulseGen[ch]->pPulseGenControl->SetEnableOutput(1); - - // Disable the Channel Controller sequencer - pPulseGen[ch]->pChannelControllerControl->SetChannelControllerControl(0); - - // Set the number of sub-pixel phases - pPulseGen[ch]->pSubpixelPhaseNum->SetSubpixelPhaseNum(numSubPixPhases); - - // Set the integer part of the div-ratio - uint64_t ratio_int = ((divRatio/(double)numSubPixPhases) * (double)(1UL << 24)); - - pPulseGen[ch]->pDividerRatioInt->SetDividerRatioInt((uint32_t)(ratio_int >> 24)); - - // Set the fractional part of the div-ratio - pPulseGen[ch]->pDividerRatioFraction->SetDividerRatioFraction((uint32_t)(ratio_int & ((1UL << 24)-1))); - - // ---- - - // Disable/Enable the fractional divider - pPulseGen[ch]->pFractionalDividerControl->SetFractionalDividerControl(0); - pPulseGen[ch]->pFractionalDividerControl->SetFractionalDividerControl(CSR_PULSE_GENERATOR_3_FRACTIONAL_DIVIDER_CONTROL_ENABLE_MASK | - CSR_PULSE_GENERATOR_3_FRACTIONAL_DIVIDER_CONTROL_UDP_MAX_POS_MASK | - CSR_PULSE_GENERATOR_3_FRACTIONAL_DIVIDER_CONTROL_UDP_MIN_POS_MASK); - - // enable the ch-ctrl sequencer - pPulseGen[ch]->pGenericSequencer15Channel->pCtrl->SetSeqEnable(1); - - - // Issue a start_req to the ch-ctrl sequencer - pPulseGen[ch]->pChannelControllerControl->SetChannelControllerControl(1); - } -}; - // ------------------------------------ - // Issue a product detect - // - inline void issuePd (CEncPdEmul1Auto* pEmul, bool setEnables = false) - { - if (setEnables) - { - // Enable everything - pEmul->pOutEnable->SetOutEnable(0xff); - } - - pEmul->pPdCtrl->SetPdCtrl(CSR_ENC_PD_EMUL_1_PD_CTRL_PD_EN_MASK | CSR_ENC_PD_EMUL_1_PD_CTRL_PD_GEN_MASK); - }; - - // ------------------------------------ - // Configure the product detect emulator - // - void configPdEmulator(CCoreAuto* pCore, double divRatio, double encFreqKHz, double clkFreqMHz = 100.0) - { - pCore->pEncPdEmul1->pEncCtrl->SetSetAbsPos(1); - - // Select source of pulses - pCore->pFpmCtrl6->pSignalselection->SetFirePulseSel(1); - pCore->pFpmCtrl6->pSignalselection->SetEncPdEmulEn(1); - pCore->pFpmCtrl6->pSignalselection->SetSebEpdEn(0); - pCore->pFpmCtrl6->pSignalselection->SetSebEpdLinkoutSel(0); - - // Run the encoder - runEnc(pCore->pEncPdEmul1, (encFreqKHz*divRatio)/1000.0, 1, 1, clkFreqMHz); - - }; - - // ------------------------------------ - // Generate a set of product detects - // spaced at a given period - // - void generatePDs(CCoreAuto* pCore, uint32_t numPDs, uint32_t periodNs) - { - for (int idx = 0; idx < numPDs; idx++) - { - issuePd(pCore->pEncPdEmul1); - - if (idx == 0) - { - nsleepSim(periodNs - REG_WR_LATENCY_NS + STARTUP_LATENCY_NS); - } - else - { - nsleepSim(periodNs - REG_WR_LATENCY_NS); - } - } - }; - -private: - // ------------------------------------ - // convert a frequency into an NCO inc - // - inline uint32_t freq2NCO(double freqMHz, double clkFreqMHz) - { - - // The NCO is 32 bits wide - return (uint32_t)(((freqMHz/4)/clkFreqMHz)*((double)(1 << 16)*(double)(1 << 16))); - } - - // ------------------------------------ - // Configure and run the PD emulator - // - void runEnc(CEncPdEmul1Auto* pEmul, double freqMHz, int enable, int init_phase_en, double clkFreqMHz) - { - // Make sure all the outputs are enabled - pEmul->pOutEnable->SetOutEnable(0xff); - - // Set the NCO frequency - pEmul->pEncNcoInc->SetEncNcoInc(freq2NCO(freqMHz, clkFreqMHz)); - - // Re-initialise the NCO phase (Phase-1 and Phase-2 both to zero) - if(init_phase_en) - { - pEmul->pEncCtrl->SetNcoInit(1); - } - - if(enable) - { - pEmul->pEncCtrl->SetNcoEn(1); - } - }; -}; - - -#endif diff --git a/firmware/top/src/test/src/runTest.cpp b/firmware/top/src/test/src/runTest.cpp index e4129cd..838a1d8 100644 --- a/firmware/top/src/test/src/runTest.cpp +++ b/firmware/top/src/test/src/runTest.cpp @@ -2043,6 +2043,10 @@ int runTest::sub_pixel_firing_test (CCoreAuto* pCore, int node) int error = NOERROR; CPrintCtrlAuto* pPrintCtrl = pCore->pPrintCtrl; CTestAuto* pTestBench = new CTestAuto((uint32_t*)(0)); + CPulseGenerator3Auto* pPulseGenerator0 = pCore->pPulseGenerator30; + CPulseGenerator3Auto* pPulseGenerator1 = pCore->pPulseGenerator31; + CPulseGenerator3Auto* pPulseGenerator2 = pCore->pPulseGenerator32; + CPulseGenerator3Auto* pPulseGenerator3 = pCore->pPulseGenerator33; // Calculate the size of a stripe in DWords uint32_t stripeSize1BppWords = (maxOpWidth*shiftDepth/32); @@ -2135,15 +2139,23 @@ int runTest::sub_pixel_firing_test (CCoreAuto* pCore, int node) pPrintRx[shead]->pLatchClear->SetLatchClear(1); } - // Configure the FPM for numStripes stripes, at a *pixel* rate of 20KHz - // with a division ratio of 4, and four phases - configFpmForEmulPulses (pCore, - 15.0, // Pixel frequency - 32.0, // divider ratio - 32, // Number of subpixel phases - clkFreqMHz, // FPM logic clock frequency - fpmSeq, // Sequence to load - fpmSeqLen); // Length of the sequence + pPulseGenerator0->pPdOffsetDir0->SetPdOffsetDir0(0); + pPulseGenerator1->pPdOffsetDir0->SetPdOffsetDir0(0); + pPulseGenerator2->pPdOffsetDir0->SetPdOffsetDir0(0); + pPulseGenerator3->pPdOffsetDir0->SetPdOffsetDir0(0); + + for (uint32_t pgSel = 0; pgSel < numHeads; pgSel++) { + // Configure the FPM for numStripes stripes, at a *pixel* rate of 20KHz + // with a division ratio of 4, and four phases + configFpmForEmulPulses (pCore, + 15.0, // Pixel frequency + 32.0, // divider ratio + 32, // Number of subpixel phases + clkFreqMHz, // FPM logic clock frequency + fpmSeq, // Sequence to load + fpmSeqLen, // Length of the sequence + pgSel); + } // Generate a product detect to set off the two stripes (as configured in the sequence), and wait a bit generatePDs (pCore, @@ -2426,6 +2438,16 @@ int runTest::link_crc_test(CCoreAuto* pCore, int node) VPrint("Starting crc tests\n"); + // Check link is aligned + uint32_t link_status = 0; + + i2cRead(I2C_ADDR_FPGA, I2C_ADDR_LINK_STATUS, link_status, pTestBench); + + if ((link_status & 0x01) == 0) { + VPrint(" Link is not aligned!\n"); + error |= 1; + } + // Read link A/B errors registers i2cRead(I2C_ADDR_FPGA, I2C_ADDR_CNT_ERR_L3, dataA, pTestBench); i2cRead(I2C_ADDR_FPGA, I2C_ADDR_CNT_ERR_L2, dataB, pTestBench); @@ -2510,23 +2532,23 @@ int runTest::dac_ctrl_test(CCoreAuto* pCore, int node) error |= 1; } -// i2cWrite(I2C_ADDR_PWR_CH0A_SP, 0x10, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH0B_SP, 0x00, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH1A_SP, 0x11, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH1B_SP, 0x00, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH0A_SP, 0x10, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH0B_SP, 0x00, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH1A_SP, 0x11, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH1B_SP, 0x00, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH0A_IV, 0x14, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH0B_IV, 0x00, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH1A_IV, 0x14, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CH1B_IV, 0x00, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH0A_IV, 0x14, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH0B_IV, 0x00, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH1A_IV, 0x14, pTestBench); + i2cWrite(I2C_ADDR_PWR_CH1B_IV, 0x00, pTestBench); VPrint(" Pausing and Power up...\n"); // Enable channels -// i2cWrite(I2C_ADDR_PWR_CHA_EN, 0x03, pTestBench); -// i2cWrite(I2C_ADDR_PWR_CHB_EN, 0x03, pTestBench); + i2cWrite(I2C_ADDR_PWR_CHA_EN, 0x03, pTestBench); + i2cWrite(I2C_ADDR_PWR_CHB_EN, 0x03, pTestBench); // Power up -// i2cWrite(I2C_ADDR_PWR_EN, 0x03, pTestBench); + i2cWrite(I2C_ADDR_PWR_EN, 0x03, pTestBench); uint32_t pwr_state = 0; @@ -2606,7 +2628,7 @@ int runTest::dac_ctrl_test(CCoreAuto* pCore, int node) VPrint(" Polling...\n"); // Remove pause -// i2cWrite(I2C_ADDR_PWR_EN, 0x01, pTestBench); + i2cWrite(I2C_ADDR_PWR_EN, 0x01, pTestBench); usleepSim(2000);