//------------------------------------------------------------------------------ // Application task example -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_Demo.cpp" // [Author] "Piero Giubilato" // [Version] "1.5" // [Modified by] "Piero Giubilato" // [Last revision] "02 Jul 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Application task example" // [Key documentation] // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Standard components #include #include #include #include // Root Components #include "TSystem.h" #include #include // Application components #include "global.h" #include "cool.h" #include "task_Demo.h" #define FLASH_BLOCK_SIZE (128 * 1024) #define FLASH_BLOCKS 128 #define FLASH_BUFFER_BYTES 32 #define WRITE_COMMAND 0X8000 #define READ_COMMAND 0XC000 #define DEF_SLOT_OFFSET 0X000 using namespace std; //______________________________________________________________________________ task_Demo::task_Demo() { // Standard constructor dbg_Print("task_Demo::task_Demo:()", DBG_LVL_ZERO); // Clears handles burst_Raw = 0; frame_Pedestal = 0; frame_Image = 0; frame_Sum = 0; frame_Display = 0; frame_Noise = 0; // Acq setting old_frm_Cnt = -1; old_Det = -1; old_Col = -1; old_Row = -1; // Set up the interface gui_Setup(); // Set up the detectors detector_Setup(); // Set up the data container(s) data_Setup(detector_List[0], 1); } //______________________________________________________________________________ task_Demo::~task_Demo() { // Standard destructor dbg_Print("task_Demo::~task_Demo:()", DBG_LVL_ZERO); // Kill everything delete_All(); } //______________________________________________________________________________ UInt_t task_Demo::run() { // Debug dbg_Print("task_Demo::run: run called", DBG_LVL_MAKE); // Returns all ok return 0; } //______________________________________________________________________________ void task_Demo::delete_All() { // Delete the data dbg_Print("task_Demo::delete_All:()", DBG_LVL_FLOW); // Deletes all GUI objects cool::Gui->delete_All(); // Delete data structures if (burst_Raw) delete burst_Raw; if (frame_Noise) delete frame_Noise; if (frame_Image) delete frame_Image; if (frame_Sum) delete frame_Sum; if (frame_Display) delete frame_Display; if (frame_Pedestal)delete frame_Pedestal; // Delete detectors for (UInt_t i = 0; i < detector_List.size(); i++) { if (detector_List[i]) delete detector_List[i]; } } //______________________________________________________________________________ void task_Demo::static_Evn(const int arg) { // Try the call to a static function (here just to give an example) dbg_Print("task_Demo::static_Evn: it works!", DBG_LVL_FLOW); } //****************************************************************************** //* * //* GUI initialization and destruction * //* * //****************************************************************************** //______________________________________________________________________________ void task_Demo::gui_Setup() { // Set up all the interface objects dbg_Print("task_Demo::gui_Setup: defining interface!", DBG_LVL_FLOW); // General appearance // ------------------ // Main window color cool::Gui->update_Auto(false); cool::Gui->color_Set(0x88AA88, cool::Gui->kc_Black); // Buttons // ------- // Button Quit // Acquisition // ----------- // The main Panel & label lbl_Desk.push_back(new gui_Label("Acquisition", 1260, 10)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1260, 40, 360, 240, cool::Gui->kc_Cyan, true)); pnl_Desk.back()->LowerWindow(); // ACQ timing [0] cmb_Acq.push_back(new gui_Combo(pnl_Desk.back(), 20, 150, 35, 100, 24)); cmb_Acq.back()->fontName("Calibri"); cmb_Acq.back()->label_Set("Timing", 0); cmb_Acq.back()->cbox_Entry("Single Shot", 0); cmb_Acq.back()->cbox_Entry("Continuous", 1); cmb_Acq.back()->cbox_Entry("Countdown", 2); cmb_Acq.back()->cbox_Val(0); // Data path [1] cmb_Acq.push_back(new gui_Combo(pnl_Desk.back(), 40, 270, 35, 100, 24)); cmb_Acq.back()->fontName("Calibri"); cmb_Acq.back()->label_Set("Data source", 0); cmb_Acq.back()->cbox_Entry("ADCs", 0); cmb_Acq.back()->cbox_Entry("Dummy data", 1); cmb_Acq.back()->cbox_Entry("Gretina", 4); cmb_Acq.back()->cbox_Val(0); // Reset mode [2] cmb_Acq.push_back(new gui_Combo(pnl_Desk.back(), 40, 270, 80, 100, 24)); cmb_Acq.back()->fontName("Calibri"); cmb_Acq.back()->label_Set("Trigger mode", 0); cmb_Acq.back()->cbox_Entry("Chip synch", 0); cmb_Acq.back()->cbox_Entry("Trig synch", 1); cmb_Acq.back()->cbox_Val(0); // What to see mode [3] cmb_Acq.push_back(new gui_Combo(pnl_Desk.back(), 40, 270, 125, 100, 24)); cmb_Acq.back()->fontName("Calibri"); cmb_Acq.back()->label_Set("Show what", 0); cmb_Acq.back()->cbox_Entry("Raw data", 0); cmb_Acq.back()->cbox_Entry("Diff data", 1); cmb_Acq.back()->cbox_Val(0); // Connect the combos for (UInt_t i = 0; i < cmb_Acq.size(); i++) cmb_Acq[i]->task_Connect(this, &task_Demo::cmb_acq_Evn); // Frames per burst [0] num_Acq.push_back(new gui_Numeric(pnl_Desk.back(), 1, 150, 80, 100, 24)); num_Acq.back()->fontName("Calibri"); num_Acq.back()->label_Set("Frames per Burst", 0); num_Acq.back()->num_Min(1); num_Acq.back()->num_Max(1024); num_Acq.back()->num_Limits(true); // Countdown [1] num_Acq.push_back(new gui_Numeric(pnl_Desk.back(), 1, 150, 125, 100, 24)); num_Acq.back()->fontName("Calibri"); num_Acq.back()->label_Set("Countdown", 0); num_Acq.back()->num_Min(0); num_Acq.back()->num_Max(1000000); num_Acq.back()->num_Limits(true); // Integration [2] num_Acq.push_back(new gui_Numeric(pnl_Desk.back(), 1, 270, 170, 100, 24)); num_Acq.back()->fontName("Calibri"); num_Acq.back()->label_Set("Integration(s)", 0); num_Acq.back()->num_Min(1); num_Acq.back()->num_Max(128); num_Acq.back()->num_Limits(true); // Pedestal count [3] num_Acq.push_back(new gui_Numeric(pnl_Desk.back(), 5, 150, 170, 100, 24)); num_Acq.back()->fontName("Calibri"); num_Acq.back()->label_Set("Ped count", 0); num_Acq.back()->num_Min(1); num_Acq.back()->num_Max(128); num_Acq.back()->num_Limits(true); // File count [4] num_Acq.push_back(new gui_Numeric(pnl_Desk.back(), 0, 240, 225, 50, 24)); num_Acq.back()->fontName("Calibri"); num_Acq.back()->label_Set("Idx", 0); // Text file txt_Acq.push_back(new gui_Text(pnl_Desk.back(), "Test", 20, 225, 230, 24)); txt_Acq.back()->fontName("Calibri"); txt_Acq.back()->label_Set("Stream file root", 0); // Buttons btn_Acq.push_back(new gui_CoolButton(pnl_Desk.back(), "Acquire", 20, 30, 110, 36, cool::Gui->kc_White, cool::Gui->kc_Green)); btn_Acq.back()->btn_Mode(gui_CoolButton::km_Latch); btn_Acq.push_back(new gui_CoolButton(pnl_Desk.back(), "Pedestals", 20, 75, 90, 36, cool::Gui->kc_White, cool::Gui->kc_Green)); btn_Acq.back()->btn_Mode(gui_CoolButton::km_Latch); btn_Acq.push_back(new gui_CoolButton(pnl_Desk.back(), "Quit", 20, 165, 110, 36, cool::Gui->kc_White, cool::Gui->kc_Red)); btn_Acq.push_back(new gui_CoolButton(pnl_Desk.back(), "Write", 20, 120, 110, 36, cool::Gui->kc_White, cool::Gui->kc_Blue)); btn_Acq.push_back(new gui_CoolButton(pnl_Desk.back(), "Set", 300, 223, 36, 28, cool::Gui->kc_White, cool::Gui->kc_Blue)); btn_Acq.push_back(new gui_CoolButton(pnl_Desk.back(), "On", 340, 223, 36, 28, cool::Gui->kc_White, cool::Gui->kc_Blue)); btn_Acq.back()->btn_Mode(gui_CoolButton::km_Latch); // Connect the buttons for (UInt_t i = 0; i < btn_Acq.size(); i++) btn_Acq[i]->task_Connect(this, &task_Demo::btn_acq_Evn); // Leds led_Acq.push_back(new gui_Led(pnl_Desk.back(), 110, 81, 24, 24)); // Detector // -------- // Detector panel & label lbl_Desk.push_back(new gui_Label("Detector", 1260, 300)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial Black"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1260, 330, 240, 145, cool::Gui->kc_gray_Dark, true)); pnl_Desk.back()->LowerWindow(); // Detector type [0] cmb_Det.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 35, 110, 24)); cmb_Det.back()->fontName("Calibri"); cmb_Det.back()->label_Set("Detector", 0); cmb_Det.back()->cbox_Entry("Dummy 1Ch" , 0); cmb_Det.back()->cbox_Entry("Dummy 4Ch" , 1); cmb_Det.back()->cbox_Entry("LDRD2 Px + Ref" , 2); cmb_Det.back()->cbox_Entry("TEAM 1Ch" , 3); cmb_Det.back()->cbox_Entry("TEAM 4Ch" , 4); cmb_Det.back()->cbox_Val(0); // Detector clock divider [1] cmb_Det.push_back(new gui_Combo(pnl_Desk.back(), 0, 140, 35, 110, 24)); cmb_Det.back()->fontName("Calibri"); cmb_Det.back()->label_Set("Clock speed", 0); cmb_Det.back()->cbox_Entry("50 Mhz", 0); cmb_Det.back()->cbox_Entry("25 MHz", 1); cmb_Det.back()->cbox_Entry("12.5 MHz", 2); cmb_Det.back()->cbox_Entry("6.25 Mhz", 3); cmb_Det.back()->cbox_Entry("3.12 MHz", 4); cmb_Det.back()->cbox_Entry("1.56 MHz", 5); cmb_Det.back()->cbox_Entry("781 KHz", 6); cmb_Det.back()->cbox_Entry("390 Khz", 7); cmb_Det.back()->cbox_Entry("195 KHz", 8); cmb_Det.back()->cbox_Val(1); // Dummy detector cols [2] cmb_Det.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 80, 110, 24)); cmb_Det.back()->fontName("Calibri"); cmb_Det.back()->label_Set("Dummy cols", 0); cmb_Det.back()->cbox_Entry("2", 2); cmb_Det.back()->cbox_Entry("4", 4); cmb_Det.back()->cbox_Entry("8", 8); cmb_Det.back()->cbox_Entry("16", 16); cmb_Det.back()->cbox_Entry("32", 32); cmb_Det.back()->cbox_Entry("64", 64); cmb_Det.back()->cbox_Entry("128", 128); cmb_Det.back()->cbox_Entry("256", 256); cmb_Det.back()->cbox_Entry("512", 512); cmb_Det.back()->cbox_Entry("1024", 1024); cmb_Det.back()->cbox_Entry("2048", 2048); cmb_Det.back()->cbox_Entry("4096", 4096); cmb_Det.back()->cbox_Entry("16384", 16384); cmb_Det.back()->cbox_Val(16); // Dummy detector rows [3] cmb_Det.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 125, 110, 24)); cmb_Det.back()->fontName("Calibri"); cmb_Det.back()->label_Set("Dummy rows", 0); cmb_Det.back()->cbox_Entry("2", 2); cmb_Det.back()->cbox_Entry("4", 4); cmb_Det.back()->cbox_Entry("8", 8); cmb_Det.back()->cbox_Entry("16", 16); cmb_Det.back()->cbox_Entry("32", 32); cmb_Det.back()->cbox_Entry("64", 64); cmb_Det.back()->cbox_Entry("128", 128); cmb_Det.back()->cbox_Entry("256", 256); cmb_Det.back()->cbox_Entry("512", 512); cmb_Det.back()->cbox_Entry("1024", 1024); cmb_Det.back()->cbox_Entry("2048", 2048); cmb_Det.back()->cbox_Entry("4096", 4096); cmb_Det.back()->cbox_Val(16); // Channels chk_Adc.clear(); TString chk_Adc_name; chk_Adc.push_back(new gui_Check(pnl_Desk.back(), "Ch 1", 140, 70, 50, 20)); chk_Adc.back()->foreColor(cool::Gui->kc_White); chk_Adc.push_back(new gui_Check(pnl_Desk.back(), "Ch 2", 140, 90, 50, 20)); chk_Adc.back()->foreColor(cool::Gui->kc_White); chk_Adc.push_back(new gui_Check(pnl_Desk.back(), "Ch 3", 200, 70, 50, 20)); chk_Adc.back()->foreColor(cool::Gui->kc_White); chk_Adc.push_back(new gui_Check(pnl_Desk.back(), "Ch 4", 200, 90, 50, 20)); chk_Adc.back()->foreColor(cool::Gui->kc_White); // Gretina button btn_Det.push_back(new gui_CoolButton(pnl_Desk.back(), "Set TEAM", 140, 120, 110, 36, cool::Gui->kc_White, cool::Gui->kc_Orange)); // Connect the buttons for (UInt_t i = 0; i < btn_Det.size(); i++) btn_Det[i]->task_Connect(this, &task_Demo::btn_det_Evn); // Connect the combos for (UInt_t i = 0; i < cmb_Det.size(); i++) cmb_Det[i]->task_Connect(this, &task_Demo::cmb_det_Evn); // Communication // ------------- // Comm panel & label lbl_Desk.push_back(new gui_Label("Communication", 1530, 300)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial Black"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1530, 330, 90, 230, cool::Gui->kc_gray_Dark)); pnl_Desk.back()->label_Set("Communication", 0); pnl_Desk.back()->LowerWindow(); // Comm buttons btn_Comm.push_back(new gui_CoolButton(pnl_Desk.back(), "Open", 20, 20, 78, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_Comm.push_back(new gui_CoolButton(pnl_Desk.back(), "Reset", 20, 65, 78, 36, cool::Gui->kc_Red, cool::Gui->kc_Gray)); btn_Comm.push_back(new gui_CoolButton(pnl_Desk.back(), "Close", 20, 110, 78, 36, cool::Gui->kc_Black, cool::Gui->kc_Gray)); btn_Comm.push_back(new gui_CoolButton(pnl_Desk.back(), "Purge", 20, 155, 78, 36, cool::Gui->kc_Black, cool::Gui->kc_Gray)); btn_Comm.push_back(new gui_CoolButton(pnl_Desk.back(), "Clear", 20, 200, 78, 36, cool::Gui->kc_Black, cool::Gui->kc_Gray)); for (UInt_t i = 0; i < btn_Comm.size(); i++) btn_Comm[i]->task_Connect(this, &task_Demo::btn_comm_Evn); // Registers // --------- // Register panel & label lbl_Desk.push_back(new gui_Label("Register IO", 1260, 500)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1260, 530, 200, 550, cool::Gui->kc_Orange)); pnl_Desk.back()->LowerWindow(); // Register numerics //for (UInt_t c = 0; c < 3; c++) { for (UInt_t i = 0; i < 16; i++) { num_Reg.push_back(new gui_Numeric(pnl_Desk.back(), 0, 35, 125 + i * 26, 60, 24)); num_Reg.back()->fontName("Calibri"); num_Reg.back()->num_Hex(true); num_Reg.back()->label_Set("0x", gui_Const::align_Middle + gui_Const::align_Left, cool::Gui->kc_White); //num_Grt.back()->label_Set("Frames per Burst", 0); } //} // Register buttons btn_Reg.push_back(new gui_CoolButton(pnl_Desk.back(), "Write", 20, 25, 80, 36, cool::Gui->kc_White, cool::Gui->kc_Orange)); btn_Reg.back()->task_Connect(this, &task_Demo::btn_reg_Evn); btn_Reg.push_back(new gui_CoolButton(pnl_Desk.back(), "Read", 20, 70, 80, 36, cool::Gui->kc_White, cool::Gui->kc_Green)); btn_Reg.back()->task_Connect(this, &task_Demo::btn_reg_Evn); // TEAM buttons btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "DatNCfg ON", 110, 25, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "DatNCfg OFF", 110, 70, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "UpdateDAC", 110, 115, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "Reconfig FPGA", 110, 160, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "Clock 25MHz", 110, 205, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "Clock 6.25MHz", 110, 250, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "Erase Firm", 110, 295, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "Downld Firm", 110, 340, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); btn_TEAM.push_back(new gui_CoolButton(pnl_Desk.back(), "Verif Firm", 110, 385, 100, 36, cool::Gui->kc_White, cool::Gui->kc_Gray)); for (UInt_t i = 0; i < btn_TEAM.size(); i++) btn_TEAM[i]->task_Connect(this, &task_Demo::btn_TEAM_Evn); btn_TEAM[(btn_TEAM.size()-3)]->task_Connect(this, &task_Demo::team_EraseFirmware); btn_TEAM[(btn_TEAM.size()-2)]->task_Connect(this, &task_Demo::team_DownloadFirmware); btn_TEAM[(btn_TEAM.size()-1)]->task_Connect(this, &task_Demo::team_VerifyFirmware); //btn_Reg.push_back(new gui_CoolButton(pnl_Desk.back(), "Write", 110, 25, 80, 36, cool::Gui->kc_White, cool::Gui->kc_Orange)); //btn_Reg.back()->task_Connect(this, &task_Demo::btn_reg_Evn); //btn_Reg.push_back(new gui_CoolButton(pnl_Desk.back(), "Read", 110, 70, 80, 36, cool::Gui->kc_White, cool::Gui->kc_Green)); //btn_Reg.back()->task_Connect(this, &task_Demo::btn_reg_Evn); //btn_Reg.push_back(new gui_CoolButton(pnl_Desk.back(), "Write", 200, 25, 80, 36, cool::Gui->kc_White, cool::Gui->kc_Orange)); //btn_Reg.back()->task_Connect(this, &task_Demo::btn_reg_Evn); //btn_Reg.push_back(new gui_CoolButton(pnl_Desk.back(), "Read", 200, 70, 80, 36, cool::Gui->kc_White, cool::Gui->kc_Green)); //btn_Reg.back()->task_Connect(this, &task_Demo::btn_reg_Evn); // TEAM/Gretina /* // Comm panel & label lbl_Desk.push_back(new gui_Label("TEAM Detector", 990, 10)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial Black"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(990, 40, 140, 210, cool::Gui->kc_gray_Dark)); //pnl_Desk.back()->label_Set("TEAM", 0); pnl_Desk.back()->LowerWindow(); // Clock Combo [0] cmb_TEAM.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 35, 120, 24)); cmb_TEAM.back()->fontName("Calibri"); cmb_TEAM.back()->label_Set("Clocks", 0); cmb_TEAM.back()->cbox_Entry("Internal", 0); cmb_TEAM.back()->cbox_Entry("External", 1); cmb_TEAM.back()->cbox_Val(0); // Data Combo [1] cmb_TEAM.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 80, 120, 24)); cmb_TEAM.back()->fontName("Calibri"); cmb_TEAM.back()->label_Set("Data mode", 0); cmb_TEAM.back()->cbox_Entry("Real data", 0); cmb_TEAM.back()->cbox_Entry("GRT fake data", 1); cmb_TEAM.back()->cbox_Entry("V5 fake data", 2); cmb_TEAM.back()->cbox_Val(0); // Sector size columns Combo [2] cmb_TEAM.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 125, 50, 24)); cmb_TEAM.back()->fontName("Calibri"); cmb_TEAM.back()->label_Set("Cols", 0); cmb_TEAM.back()->cbox_Entry("8", 8); cmb_TEAM.back()->cbox_Entry("16", 16); cmb_TEAM.back()->cbox_Entry("32", 32); cmb_TEAM.back()->cbox_Entry("64", 64); cmb_TEAM.back()->cbox_Val(16); // Sector size rows Combo [3] cmb_TEAM.push_back(new gui_Combo(pnl_Desk.back(), 0, 80, 125, 60, 24)); cmb_TEAM.back()->fontName("Calibri"); cmb_TEAM.back()->label_Set("Rows", 0); cmb_TEAM.back()->cbox_Entry("32", 32); cmb_TEAM.back()->cbox_Entry("64", 64); cmb_TEAM.back()->cbox_Entry("128", 128); cmb_TEAM.back()->cbox_Entry("256", 256); cmb_TEAM.back()->cbox_Entry("512", 512); cmb_TEAM.back()->cbox_Entry("1024", 1024); cmb_TEAM.back()->cbox_Val(128); // Image size on V4 [4] cmb_TEAM.push_back(new gui_Combo(pnl_Desk.back(), 0, 20, 170, 120, 24)); cmb_TEAM.back()->fontName("Calibri"); cmb_TEAM.back()->label_Set("Rows", 0); cmb_TEAM.back()->cbox_Entry("32", 32); cmb_TEAM.back()->cbox_Entry("64", 64); cmb_TEAM.back()->cbox_Entry("128", 128); cmb_TEAM.back()->cbox_Entry("256", 256); cmb_TEAM.back()->cbox_Entry("512", 512); cmb_TEAM.back()->cbox_Entry("1024", 1024); cmb_TEAM.back()->cbox_Val(128); */ // DAC // --- // Comm panel & label lbl_Desk.push_back(new gui_Label("TEAM DACs", 1490, 590)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial Black"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1490, 620, 200, 460, cool::Gui->kc_Blue)); pnl_Desk.back()->LowerWindow(); // DAC Buttons & Numerics TString name, label1, label2, unit1, unit2; Double_t max1, max2; Double_t initvalue1, initvalue2; ifstream in("DAC.txt", ifstream::in); // in.close(); for (UInt_t i = 0; i < 7; i++) { name.Form("DAC %i - %i", i * 2 + 1, i * 2 + 2); btn_DAC.push_back(new gui_CoolButton(pnl_Desk.back(), ">", 185, 20 + i * 64, 25, 56, cool::Gui->kc_White, cool::Gui->kc_Blue)); // Label & setting switch (i) { // DAC 1 & 2 case 0: label1.Form("CMOS pos rail"); unit1.Form("V"); max1 = 5; initvalue1 = 3.300; label2.Form("Bias Pin Bias"); unit2.Form("mA"); max2 = 1; initvalue2 = 0.100; break; // DAC 3 & 4 case 1: label1.Form("Vdd reset"); unit1.Form("V"); max1 = 5; initvalue1 = 2.300; label2.Form("GRD"); unit2.Form("V"); max2 = 5; initvalue2 = 0.000; break; // DAC 5 & 6 case 2: label1.Form("V Sub"); unit1.Form("V"); max1 = 5; initvalue1 = .000; label2.Form("Analog Rai;"); unit2.Form("V"); max2 = 5; initvalue2 = 3.300; break; // DAC 7 & 8 case 3: label1.Form("Temp Resistor"); initvalue1 = 0.100; unit1.Form("mA"); max1 = 1; label2.Form("DAQ Reference"); unit2.Form("V"); max2 = 5; initvalue2 = 1.600; break; // DAC 9 & 10 case 4: label1.Form("Bs N3SRE"); unit1.Form("mA"); max1 = 1; initvalue1 = 0.300; label2.Form("Bs N3Buf"); unit2.Form("mA"); max2 = 1; initvalue2 = 0.300; break; // DAC 11 & 12 case 5: label1.Form("Bs N3PreDrive"); unit1.Form("mA"); max1 = 1;initvalue1 = 0.100; label2.Form("Bias P"); unit2.Form("mA"); max2 = 1; initvalue2 = .500; break; // DAC 13 & 14 case 6: label1.Form("Bias N"); unit1.Form("mA"); max1 = 1; initvalue1 = 0.020; label2.Form("Null"); unit2.Form("mA"); max2 = 1; initvalue2 = 0.000; break; } lbl_Desk.push_back(new gui_Label(pnl_Desk.back(), label1.Data(), 20, 24 + (i * 2) * 32)); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.push_back(new gui_Label(pnl_Desk.back(), label2.Data(), 20, 24 + (i * 2 + 1) * 32)); lbl_Desk.back()->foreColor(cool::Gui->kc_White); // Numeric num_DAC.push_back(new gui_Numeric(pnl_Desk.back(), 0, 120, 20 + (i * 2) * 32, 60, 24)); num_DAC.back()->fontName("Calibri"); //num_DAC.back()->num_Hex(true); num_DAC.back()->num_Limits(true) ; num_DAC.back()->Root()->SetNumStyle(TGNumberEntry::kNESRealThree); num_DAC.back()->num_Max(max1); num_DAC.back()->num_Min(0); num_DAC.back()->label_Set(unit1.Data(), gui_Const::align_Middle + gui_Const::align_Left, cool::Gui->kc_White); num_DAC.back()->num_Val(initvalue1); num_DAC.push_back(new gui_Numeric(pnl_Desk.back(), 0, 120, 20 + (i * 2 + 1) * 32, 60, 24)); num_DAC.back()->fontName("Calibri"); //num_DAC.back()->num_Hex(true); num_DAC.back()->num_Limits(true) ; num_DAC.back()->Root()->SetNumStyle(TGNumberEntry::kNESRealThree); num_DAC.back()->num_Max(max2); num_DAC.back()->num_Min(0); num_DAC.back()->label_Set(unit2.Data(), gui_Const::align_Middle + gui_Const::align_Left, cool::Gui->kc_White); num_DAC.back()->num_Val(initvalue2); } for (UInt_t i = 0; i < btn_DAC.size(); i++) btn_DAC[i]->task_Connect(this, &task_Demo::btn_DAC_Evn); // DDR // --- // Comm panel & label lbl_Desk.push_back(new gui_Label("DDR controller", 1660, 10)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial Black"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1660, 40, 140, 490, cool::Gui->kc_Purple)); pnl_Desk.back()->LowerWindow(); // Combo box for write and read mode selection cbox_Mode = new gui_Combo(pnl_Desk.back(), 0, 20, 40, gui_Const::wdgt_Width, gui_Const::wdgt_Height); cbox_Mode->label_Set("Write and read mode", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); // Write entries in the combo box TString entry_Mode; entry_Mode.Form("Real data"); cbox_Mode->cbox_Entry(entry_Mode.Data(), 0); entry_Mode.Form("Write calibration"); cbox_Mode->cbox_Entry(entry_Mode.Data(), 1); entry_Mode.Form("Read calibration"); cbox_Mode->cbox_Entry(entry_Mode.Data(), 2); // select real data by default cbox_Mode->Root()->Select(0); // Combo box for ADC_FIFO input selection cbox_ADC_Input = new gui_Combo(pnl_Desk.back(), 1, 20, 90, gui_Const::wdgt_Width, gui_Const::wdgt_Height); cbox_ADC_Input->label_Set("ADC FIFO input", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); // Write entries in the combo box TString entry_ADC_Input; entry_ADC_Input.Form("ADC data"); cbox_ADC_Input->cbox_Entry(entry_ADC_Input.Data(), 0); entry_ADC_Input.Form("32 bit counter"); cbox_ADC_Input->cbox_Entry(entry_ADC_Input.Data(), 1); entry_ADC_Input.Form("Test data"); cbox_ADC_Input->cbox_Entry(entry_ADC_Input.Data(), 2); entry_ADC_Input.Form("0s and 1s"); cbox_ADC_Input->cbox_Entry(entry_ADC_Input.Data(), 3); entry_ADC_Input.Form("Program pattern"); cbox_ADC_Input->cbox_Entry(entry_ADC_Input.Data(), 4); // select ADC data by default cbox_ADC_Input->Root()->Select(0); // Combo box for RO_FIFO input selection cbox_RO_Input = new gui_Combo(pnl_Desk.back(), 2, 20, 140, gui_Const::wdgt_Width, gui_Const::wdgt_Height); cbox_RO_Input->label_Set("RO FIFO input", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); // Write entries in the combo box TString entry_RO_Input; entry_RO_Input.Form("DDR2 data"); cbox_RO_Input->cbox_Entry(entry_RO_Input.Data(), 0); entry_RO_Input.Form("32 bit counter"); cbox_RO_Input->cbox_Entry(entry_RO_Input.Data(), 1); // select DDR2 data by default cbox_RO_Input->Root()->Select(0); // ADC_FIFO readout clock phase shifting selection num_ADC_Phase = new gui_Numeric(pnl_Desk.back(), 0, 20, 190, gui_Const::wdgt_Width, gui_Const::wdgt_Height, 0, 128); num_ADC_Phase->label_Set("ADC FIFO clock phase", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); // RO_FIFO write clock phase shifting selection num_RO_Phase = new gui_Numeric(pnl_Desk.back(), 0, 20, 240, gui_Const::wdgt_Width, gui_Const::wdgt_Height, 0, 128); num_RO_Phase->label_Set("RO FIFO clock phase", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); // Programmable pattern for ADC_FIFO input num_prog_Data = new gui_Numeric(pnl_Desk.back(), 0, 20, 290, gui_Const::wdgt_Width, gui_Const::wdgt_Height, 0, 128); num_prog_Data->label_Set("Input data", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); // Row and CG number num_Row = new gui_Numeric(pnl_Desk.back(), 1, 20, 340, 60, gui_Const::wdgt_Height, 0, 128); num_Row->label_Set("Rows", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); num_Row->num_Max(8192); num_Row->num_Min(0); num_CG = new gui_Numeric(pnl_Desk.back(), 1, 90, 340, 60, gui_Const::wdgt_Height, 0, 128); num_CG->label_Set("GCs", gui_Const::align_Left | gui_Const::align_Top, 0xFFFFFF, 0x000060); num_CG->num_Max(64); num_CG->num_Min(0); // Buttons btn_set_ADC= new gui_CoolButton(pnl_Desk.back(),"Set ADC FIFO", 20, 380, gui_Const::btn_Width, gui_Const::btn_Height, gui_CoolButton::kc_White, gui_CoolButton::kc_Cyan); btn_set_ADC->btn_Mode(gui_CoolButton::km_Button); btn_set_ADC->btn_Status(false); btn_set_ADC->task_Connect(this, &task_Demo::btn_adc_Evn); btn_set_RO= new gui_CoolButton(pnl_Desk.back(), "Set RO FIFO", 20, 420, gui_Const::btn_Width, gui_Const::btn_Height, gui_CoolButton::kc_White, gui_CoolButton::kc_Cyan); btn_set_RO->btn_Mode(gui_CoolButton::km_Button); btn_set_RO->btn_Status(false); btn_set_RO->task_Connect(this, &task_Demo::btn_ro_Evn); btn_set_All= new gui_CoolButton(pnl_Desk.back(), "Set All", 20, 460, gui_Const::btn_Width, gui_Const::btn_Height, gui_CoolButton::kc_White, gui_CoolButton::kc_Cyan); btn_set_All->btn_Mode(gui_CoolButton::km_Button); btn_set_All->btn_Status(false); btn_set_All->task_Connect(this, &task_Demo::btn_all_Evn); // Temperature Measurements // --- // Comm panel & label lbl_Desk.push_back(new gui_Label("TEAM Temp", 1490+230, 590)); lbl_Desk.back()->Transparent(true); lbl_Desk.back()->fontName("Arial Black"); lbl_Desk.back()->fontSize(14); lbl_Desk.back()->foreColor(cool::Gui->kc_White); lbl_Desk.back()->fontBold(true); pnl_Desk.push_back(new gui_Panel(1490+230, 620, 500, 110, cool::Gui->kc_Blue)); pnl_Desk.back()->LowerWindow(); // DAC Buttons & Numerics TString labelVT, unitVT; Double_t maxVT; in.close(); name.Form("Temp %i - %i", 1, 2); btn_Temp.push_back(new gui_CoolButton(pnl_Desk.back(), ">", 185 - 30, 20, 25, 56+29, cool::Gui->kc_White, cool::Gui->kc_Blue)); labelVT.Form("Temp"); lbl_Desk.push_back(new gui_Label(pnl_Desk.back(), labelVT.Data(), 20, 24)); lbl_Desk.back()->foreColor(cool::Gui->kc_White); // Numeric num_Temp.push_back(new gui_Numeric(pnl_Desk.back(), 0, 120 - 30, 20, 60, 24)); num_Temp.back()->fontName("Calibri"); unitVT.Form("V"); maxVT = 5; //num_DAC.back()->num_Hex(true); num_Temp.back()->num_Limits(true) ; num_Temp.back()->Root()->SetNumStyle(TGNumberEntry::kNESRealThree); num_Temp.back()->num_Max(maxVT); num_Temp.back()->num_Min(0); num_Temp.back()->label_Set(unitVT.Data(), gui_Const::align_Middle + gui_Const::align_Left, cool::Gui->kc_White); num_Temp.back()->num_Val(0); // Numeric num_Temp.push_back(new gui_Numeric(pnl_Desk.back(), 0, 120 - 30, 20 + 32, 60, 24)); num_Temp.back()->fontName("Calibri"); unitVT.Form("C"); maxVT = 5; //num_DAC.back()->num_Hex(true); num_Temp.back()->num_Limits(true) ; num_Temp.back()->Root()->SetNumStyle(TGNumberEntry::kNESRealOne); num_Temp.back()->num_Max(maxVT); num_Temp.back()->num_Min(0); num_Temp.back()->label_Set(unitVT.Data(), gui_Const::align_Middle + gui_Const::align_Left, cool::Gui->kc_White); num_Temp.back()->num_Val(0); // Numeric num_Temp.push_back(new gui_Numeric(pnl_Desk.back(), 0, 120 - 30, 20 + 32*2, 60, 24)); num_Temp.back()->fontName("Calibri"); unitVT.Form("B"); maxVT = 5; //num_DAC.back()->num_Hex(true); num_Temp.back()->num_Limits(true) ; num_Temp.back()->Root()->SetNumStyle(TGNumberEntry::kNESInteger); num_Temp.back()->num_Max(maxVT); num_Temp.back()->num_Min(0); num_Temp.back()->label_Set(unitVT.Data(), gui_Const::align_Middle + gui_Const::align_Left, cool::Gui->kc_White); num_Temp.back()->num_Val(0); btn_Temp[0]->task_Connect(this, &task_Demo::btn_Temp_Evn); // Maps // ---- // Palette UInt_t col[6] = {0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF}; // Signal map_Signal = new gui_Map(80, 10, 1024 + 18, 1024 + 18, cool::Gui->kc_White); map_Signal->range_Color(col, 6); // Plots // ----- plt_Slice = new gui_Plot(80, 1120, 1024 + 18, 256, cool::Gui->kc_White); plt_Slice->palette_Color(col, 1); num_Slice = new gui_Numeric(0,80,1420,60,20); num_Slice->label_Set("Line #", 0, cool::Gui->kc_White); num_Slice->task_Connect(this, &task_Demo::num_slice_Evn); // Refresh cool::Gui->size_Set(1900, 1500); cool::Gui->Update(); } //****************************************************************************** //* * //* GUI Callback target functions * //* * //****************************************************************************** //______________________________________________________________________________ void task_Demo::btn_acq_Evn(const int arg) { // Play button events handler dbg_Print("task_Demo::btn_run_Evn: run called", DBG_LVL_FLOW); // Run/Stop if (arg == btn_Acq[0]->obj_Id()) { // Start acquisition if (btn_Acq[0]->btn_Status()) { btn_Acq[0]->Text("Stop"); btn_Acq[0]->backColor(gui_CoolButton::kc_Red); // Acquire data_Preset(); switch (cmb_Acq[3]->cbox_Val()) { case 0: data_Acquire(ka_Std); break; case 1: data_Acquire(ka_PedSub); break; } // Stop acquisition } else { btn_Acq[0]->Text("Start"); btn_Acq[0]->backColor(gui_CoolButton::kc_Green); } return; } // Pedestal Run if (arg == btn_Acq[1]->obj_Id()) { // Start pedestals if (btn_Acq[1]->btn_Status()) { btn_Acq[1]->Text("Stop"); btn_Acq[1]->backColor(gui_CoolButton::kc_Red); // Acquire data_Pedestal(); // Stop pedestals } else { btn_Acq[1]->Text("Pedestal"); btn_Acq[1]->backColor(gui_CoolButton::kc_Green); } } // Write if (arg == btn_Acq[3]->obj_Id()) data_Write(); // Set root stream file if (arg == btn_Acq[4]->obj_Id()) { data_Write(0, 0, true); txt_Acq[0]->Root()->SetText(stream_fileRoot.Data()); } // Quit if (arg == btn_Acq[2]->obj_Id()) cool::Gui->Quit(); } //______________________________________________________________________________ void task_Demo::btn_comm_Evn(const int arg) { // Do some comm operation if (arg == btn_Comm[0]->obj_Id()) fpga_Setup(burst_Raw); if (arg == btn_Comm[1]->obj_Id()) cool::Comm->Reset(); if (arg == btn_Comm[2]->obj_Id()) cool::Comm->Close(); if (arg == btn_Comm[3]->obj_Id()) cool::Comm->Purge(); if (arg == btn_Comm[4]->obj_Id()) cool::Comm->Clear(); } //______________________________________________________________________________ void task_Demo::btn_TEAM_Evn(const int arg) { // Pointer buffer UShort_t pt_Buffer[12][16] = { {5, 0, 0, 0x8802, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #0 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #1 {5, 0, 0, 0x8802, 0, 0, 0x8402, 0x22, 0xa002, 0x8402, 0x22, 0x8002, 0x8802, 0, 0x45, 0}, // Button #2 {5, 0, 0, 0x83c3, 0, 1, 0x83c3, 0, 0, 0x87c3, 0, 1, 0x87c3, 0, 0, 0}, // Button #3 {5, 0, 0, 0x8802, 0, 0, 0x800D, 0, 0x13, 0x840d, 0, 0x3, 0x8802, 0, 0x45, 0}, // Button #4 {5, 0, 0, 0x8802, 0, 0, 0x800D, 0xb00, 0x13, 0x840d, 0xb00, 0x3, 0x8802, 0, 0x45, 0}, // Button #5 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #6 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #7 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #8 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #9 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Button #10 {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // Button #11 }; // Write for (UInt_t i = 0; i < btn_TEAM.size(); i++) { if (arg == btn_TEAM[i]->obj_Id()) reg_Write(pt_Buffer[i]); } } //______________________________________________________________________________ void task_Demo::btn_DAC_Evn(const int arg) { // The set sequence, without the values // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 UShort_t buffer[16] = {5, 0, 0, 0x8802, 0, 0, 0, 0, 0, 0, 0, 0, 0x8802, 0, 0x45, 0}; UShort_t update[16] = {5, 0, 0, 0x8802, 0, 0, 0x8402, 0x12, 0xa002, 0x8402, 0x12, 0x8002, 0x8802, 0, 0x45, 0}; // Grab which register UInt_t reg_Idx = 0; for (reg_Idx = 0; reg_Idx < btn_DAC.size(); reg_Idx++) if (arg == btn_DAC[reg_Idx]->obj_Id()) break; // 1 -> CMOS positive rail (Vol) // 2 -> Bias Pin Bias (Current) // 3 -> Vdd Reset (Volt) // 4 -> GRD (Current) // 5 -> Vsub (Volt) // 6 -> Analog Rail (Volt) // 7 -> Temperature Resistor currenr (Curr) // 8 -> DAQ Ref (Volt) // 9 -> Bias N3SRE (Curr) // 10 -> Bias N3BUF (Curr) // 11 -> Bias N3PreDrive (Curr) // 12 -> Bias P (Curr) // 13 -> Bias N In (Curr) // Set register address and conversion factors UShort_t reg_Add = 0; Double_t mult1, mult2; switch (reg_Idx) { // DAC 1 & 2 case 0: reg_Add = 0x05; mult1 = 819; mult2 = 4095; break; // DAC 3 & 4 case 1: reg_Add = 0x06; mult1 = 819; mult2 = 4095; break; // DAC 5 & 6 case 2: reg_Add = 0x07; mult1 = 450; mult2 = 819; break; // DAC 7 & 8 case 3: reg_Add = 0x08; mult1 = 4095; mult2 = 410; break; // DAC 9 & 10 case 4: reg_Add = 0x09; mult1 = 4095; mult2 = 4095; break; // DAC 11 & 12 case 5: reg_Add = 0x10; mult1 = 4095; mult2 = 4095; break; // DAC 13 case 6: reg_Add = 0x11; mult1 = 4095; mult2 = 0; break; } // Set the values, first 4 MSb by default to one UShort_t val_Left = (UShort_t)(mult1 * num_DAC[reg_Idx * 2]->num_Val()); UShort_t val_Right = (UShort_t)(mult2 * num_DAC[reg_Idx * 2 + 1]->num_Val()); // Debug std::cout << "\nSetting REG #" << reg_Add << " [" << std::hex << val_Left << ", " << std::hex << val_Right << "]\n"; // Put values buffer[6] = 0x8400 + reg_Add; buffer[7] = 0x1000 + val_Right; buffer[8] = 0x1000 + val_Left; // Writes to the DAC reg_Write(buffer); // Send the update command reg_Write(update); } //______________________________________________________________________________ void task_Demo::btn_Temp_Evn(const int arg) { // Reading from the registers dbg_Print("task_Demo::reg_Read:(const UShort*)", DBG_LVL_FLOW); // Info std::cout << "Reading Temperature!\n"; // const double TEMP_BIT_PER_V = 204.7; const double R_ROOM_TEMP = 10900.0; const double ROOM_TEMP = 22.1; const double TEMP_CO = (23.5 - ROOM_TEMP ) / ( 11430.0 - R_ROOM_TEMP); double TempV; // Set up buffers UShort_t wr_buff[16] = {5, 0, 0, 0xc40f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; UShort_t rd_buff[256]; Int_t wr_buff_Len = 16; Int_t rd_buff_Len = 256; // Clean input buffer for (UInt_t i = 0; i < rd_buff_Len; i++) rd_buff[i] = 0; // Fill the write buffer with the numeric values std::cout << "Sending: "; for (UInt_t i = 0; i < wr_buff_Len; i++) { //if (pt_Buffer) wr_buff[i] = pt_Buffer[i]; //else wr_buff[i] = (UShort_t)(num_Reg[i]->num_Val()); std::cout << wr_buff[i] << " "; } std::cout << "\n"; // Send the write command to the module cool::Comm->raw_Write(wr_buff, &wr_buff_Len); // Read back the data from the USB //cool::Comm->raw_Read(rd_buff, &rd_buff_Len); for (UInt_t k = 0; k < 5; k++) { cool::Comm->raw_Read(rd_buff, &rd_buff_Len); std::cout << "Reading Try: " << k << "\n"; for (UInt_t i = 0; i < rd_buff_Len; i++) { std::cout << "Reading word: 0x " << std::hex << rd_buff[i] << "\n"; if ( rd_buff[i] > 2) { TempV = (double)( rd_buff[i] / TEMP_BIT_PER_V); num_Temp[0]->num_Val( TempV ); num_Temp[1]->num_Val( ROOM_TEMP + TEMP_CO * (TempV / num_DAC[6]->num_Val() * 1000.0 - R_ROOM_TEMP) ); num_Temp[2]->num_Val(rd_buff[i]); k += 10; break; } } } } //__ //______________________________________________________________________________ void task_Demo::cmb_acq_Evn(const int arg) { // Nothing to do at the moment } //______________________________________________________________________________ void task_Demo::cmb_det_Evn(const int arg) { // Performs some options // Gretina detector constrains //if (arg == cmb_Det[0]->obj_Id()) { if (cmb_Det[0]->cbox_Val() == 2) { //cmb_Det[1]->cbox_Val((Int_t)sqrt((Double_t)(cmb_Det[4]->cbox_Val() * cmb_Det[5]->cbox_Val() / 4))); // Expected size //cmb_Det[2]->cbox_Val(0); // 50 MHz //cmb_Acq[1]->cbox_Val(4); // Gretina data path } } //______________________________________________________________________________ void task_Demo::btn_det_Evn(const int arg) { // Gretina default setup if (arg == btn_Det[0]->obj_Id()) team_Setup(); } //______________________________________________________________________________ void task_Demo::num_slice_Evn(const int arg) { UInt_t row_Idx = (UInt_t)num_Slice->num_Val(); if (row_Idx <0) row_Idx = 0; if (row_Idx >= frame_Image->layer(0)->dp_row_Count()) row_Idx = frame_Image->layer(0)->dp_row_Count() - 1; UInt_t col_Count = frame_Image->layer(0)->dp_col_Count(); Int_t* line_Start = frame_Image->layer(0)->dp_Front() + col_Count * row_Idx; plt_Slice->data_Set(line_Start, col_Count, 1); plt_Slice->data_Refresh(); } //______________________________________________________________________________ void task_Demo::btn_reg_Evn(const int arg) { // Writes what in the numeric controls if (arg == btn_Reg[0]->obj_Id()) reg_Write(0); if (arg == btn_Reg[1]->obj_Id()) reg_Read(0); } //****************************************************************************** //* * //* Data & Detector initialization and destruction * //* * //****************************************************************************** //______________________________________________________________________________ void task_Demo::reg_Write(const UShort_t* pt_Buffer) { // Writing to the registers dbg_Print("task_Demo::reg_Write:(const UShort*)", DBG_LVL_FLOW); // Info std::cout << "Writing to Gretina!\n"; // Set up a pivot buffer UShort_t buff[16]; Int_t buff_Len = 16; // Fill the buffer with the numeric values for (UInt_t i = 0; i < buff_Len; i++) { if (pt_Buffer) buff[i] = pt_Buffer[i]; else buff[i] = (UShort_t)(num_Reg[i]->num_Val()); std::cout << buff[i] << " "; } std::cout << "\n"; // Write cool::Comm->raw_Write(buff, &buff_Len); } //______________________________________________________________________________ void task_Demo::reg_Read(const UShort_t* pt_Buffer) { // Reading from the registers dbg_Print("task_Demo::reg_Read:(const UShort*)", DBG_LVL_FLOW); // Info std::cout << "Reading from Gretina!\n"; // Set up buffers UShort_t wr_buff[16]; UShort_t rd_buff[256]; Int_t wr_buff_Len = 16; Int_t rd_buff_Len = 256; // Clean input buffer for (UInt_t i = 0; i < rd_buff_Len; i++) rd_buff[i] = 0; // Fill the write buffer with the numeric values std::cout << "Sending: "; for (UInt_t i = 0; i < wr_buff_Len; i++) { if (pt_Buffer) wr_buff[i] = pt_Buffer[i]; else wr_buff[i] = (UShort_t)(num_Reg[i]->num_Val()); std::cout << wr_buff[i] << " "; } std::cout << "\n"; // Send the write command to the module cool::Comm->raw_Write(wr_buff, &wr_buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found std::cout << "Reading: \n"; if (rd_buff_Len > 0) { for (UInt_t i = 0; i < rd_buff_Len; i++) { std::cout << "Word #" << i << ": 0x " << std::hex << rd_buff[i] << "\n"; } //std::cout << "\n"; } else { std::cout << "No answer!\n"; } } //______________________________________________________________________________ void task_Demo::detector_Setup(UInt_t col_Count, UInt_t row_Count) { // Set up the data dbg_Print("task_Demo::data_Setup: defining data objects", DBG_LVL_FLOW); cool::Out->Print("Defining detector\n", WHITE); // Creates new detectors for (UInt_t i = 0; i < detector_List.size(); i++) delete detector_List[i]; detector_List.clear(); // TEST 1Ch // -------- detector_List.push_back(new geom_Frame()); geom_Frame* test1 = detector_List.back(); // This is a test chip! // Hardware ID test1->HrdID(1); // FPGA-encoded hardware ID // 1 Chip test1->chip(0)->Name("Chip 0"); test1->chip(0)->col_Count(col_Count); test1->chip(0)->row_Count(row_Count); // 1 Layer test1->layer(0)->Name("Layer 0"); test1->layer(0)->dp_col_Count(col_Count); test1->layer(0)->dp_row_Count(row_Count); // 1 Channel test1->channel(0)->Name("Channel 0"); test1->channel(0)->chip_Idx(0); test1->channel(0)->layer_Idx(0); // Dummy linear geometry test1->chip(0)->dp_all_Range(0, 1); // TEST 4Ch // -------- detector_List.push_back(new geom_Frame()); geom_Frame* test4 = detector_List.back(); // This is a test chip! // Hardware ID test4->HrdID(1); // FPGA-encoded hardware ID // 4 Chip test4->chip(0)->Name("Chip 0"); test4->chip(0)->col_Count(col_Count / 4); test4->chip(0)->row_Count(row_Count); for (UInt_t i = 1; i < 4; i++) { test4->chip_Add(); test4->chip(i)->col_Count(col_Count / 4); test4->chip(i)->row_Count(row_Count); } // 1 Layer test4->layer(0)->Name("Layer 0"); test4->layer(0)->dp_col_Count(col_Count); test4->layer(0)->dp_row_Count(row_Count); // 4 Channel test4->channel(0)->Name("Channel 0"); test4->channel(0)->chip_Idx(0); test4->channel(0)->layer_Idx(0); for (UInt_t i = 1; i < 4; i++) test4->channel_Add(i, 0); // Dummy linear geometry for (UInt_t i = 0; i < 4; i++) test4->chip(i)->dp_all_Range(i * col_Count * row_Count / 4, 1); // TEAM style geometry UInt_t row_Count = test4->chip(0)->row_Count(); UInt_t col_Count = test4->chip(0)->col_Count(); UInt_t width = col_Count * 4; UInt_t half_Width = col_Count * 2; for (UInt_t y = 0; y < row_Count; y++) { for (UInt_t x = 0; x < col_Count; x++) { test4->chip(0)->dp_Value(x, y)= y * width + x * 2; test4->chip(1)->dp_Value(x, y)= y * width + x * 2 + 1; test4->chip(2)->dp_Value(x, y)= y * width + x * 2 + half_Width; test4->chip(3)->dp_Value(x, y)= y * width + x * 2 + half_Width + 1; } } // LDRD2 // ----- detector_List.push_back(new geom_Frame()); geom_Frame* ldrd2 = detector_List.back(); // Defines the hardware chips // Hardwrae ID ldrd2->HrdID(2); // FPGA-encoded hardware ID // LEFT LDRD2 sector ldrd2->chip(0)->Name("Left"); // LEFT side of LDRD2 ldrd2->chip(0)->col_Count(48); // 48 columns ldrd2->chip(0)->row_Count(96); // 96 rows ldrd2->chip(0)->col_Pitch(20); // Pixel column pitch ldrd2->chip(0)->row_Pitch(20); // Pixel row pitch // RIGHT LDRD2 sector ldrd2->chip_Add(); ldrd2->chip(1)->Name("Right"); // RIGHT side of LDRD2 ldrd2->chip(1)->col_Count(48); // 48 columns ldrd2->chip(1)->row_Count(96); // 96 rows ldrd2->chip(1)->col_Pitch(20); // Pixel column pitch ldrd2->chip(1)->row_Pitch(20); // Pixel row pitch // Defines the logic layers // First logical layer (SIGNAL) ldrd2->layer(0)->Name("Signal"); // The signal (abstracted) layer ldrd2->layer(0)->dp_col_Count(96); // Logical column count ldrd2->layer(0)->dp_row_Count(96); // Logical row count // Second logical layer (REFERENCE) ldrd2->layer_Add(); ldrd2->layer(1)->Name("Reference"); // The reference (abstracted) layer ldrd2->layer(1)->dp_col_Count(96); // 96 columns ldrd2->layer(1)->dp_row_Count(96); // 96 rows // Defines the chip/channel/layer connections // 1st output, left sector signal ldrd2->channel(0)->Name("Left signal"); // Chip/Layer connection ldrd2->channel(0)->chip_Idx(0); // Data are shaped as decribed by chip #0 ldrd2->channel(0)->layer_Idx(0); // Data are directed to layer #0 // 2nd output, left sector reference ldrd2->channel_Add(0, 1); // Chip #0 to layer #1 ldrd2->channel(1)->Name("Left reference"); // 3rd output, right sector signal ldrd2->channel_Add(1, 0); // Chip #1 to layer #0 ldrd2->channel(2)->Name("Right signal"); // 4th output, right sector reference ldrd2->channel_Add(1, 1); // Chip #1 to layer #1 ldrd2->channel(3)->Name("Right reference"); // Sets the chip geometry // Here we set the chip mapping respect to layer mapping. Basically, the // number of pixels contained into one chip is considered as a linear vector, // where for each pixel is stored the location where to place it into the // logical target layer defined by the channel association. // Chip #0 is on the left side of the logical frame, chip #1 (Right) // on the right side but mirrored, i.e. the first data to exit is the\ // last in the row. geom_Chip* chip_Left = ldrd2->chip(0); geom_Chip* chip_Right = ldrd2->chip(1); UInt_t l_Col = 0, r_Col = 0, lr_Row = 0; for (UInt_t i = 0; i < chip_Left->dp_Count(); i++) { // Left l_Col = i % 48; r_Col = 95 - i % 48; lr_Row = (UInt_t)(i / 48); // Put the address in linear style chip_Left->dp_Value(i) = l_Col + lr_Row * 96; chip_Right->dp_Value(i) = r_Col + lr_Row * 96; } // Gretina digitizer / 1 Ch // ------------------------ detector_List.push_back(new geom_Frame()); geom_Frame* team1 = detector_List.back(); // Hardware ID team1->HrdID(128); // FPGA-encoded hardware ID // 16 Chip team1->chip(0)->col_Count(col_Count); team1->chip(0)->row_Count(row_Count); // 1 Layer team1->layer(0)->Name("TEAM chip"); team1->layer(0)->dp_col_Count(col_Count); team1->layer(0)->dp_row_Count(row_Count); // 1 Channel team1->channel(0)->chip_Idx(0); team1->channel(0)->layer_Idx(0); // Linear geometry for every sector for (UInt_t i = 0; i < team1->channel_Count() ; i++) team1->chip(i)->dp_all_Range(i * col_Count * row_Count, 1); // Gretina digitizer / 4 Ch - Full frame // ------------------------------------- detector_List.push_back(new geom_Frame()); geom_Frame* team4 = detector_List.back(); // Hardware ID team4->HrdID(128); // FPGA-encoded hardware ID // 4 Chips: as we are reading 4 channels, the 16 real sectors are rearranged into // 4 macro sectors, each one of 1/4 of the total number of pixels team4->chip(0)->col_Count(col_Count / 4); team4->chip(0)->row_Count(row_Count); for (UInt_t i = 1; i < 4; i++) { team4->chip_Add(); team4->chip(i)->col_Count(col_Count / 4); team4->chip(i)->row_Count(row_Count); } // 1 Layer team4->layer(0)->Name("TEAM chip"); team4->layer(0)->dp_col_Count(col_Count); team4->layer(0)->dp_row_Count(row_Count); // 4 Channels team4->channel(0)->chip_Idx(0); team4->channel(0)->layer_Idx(0); for (UInt_t i = 1; i < 4; i++) team4->channel_Add(i, 0); // The data sequence from the digitizer is: // Chn: 0 1 2 3 0 1 2 3 ... 0 1 2 3 0 1 2 3 ... 0 1 2 3 0 1 2 3 0 1 2 3 ... 0 1 2 3 // Sec: 0 0 8 8 0 0 8 8 ... 0 0 8 8 0 0 8 8 ... 0 0 8 8 1 1 9 9 1 1 9 9 ... 1 1 9 9 // Row: 0 0 0 0 0 0 0 0 ... 0 0 0 0 1 1 1 1 ... k k k k 0 0 0 0 0 0 0 0 k k k k // Col: 0 1 0 1 2 3 2 3 ... 626362630 1 0 1 ... 626362630 1 0 1 2 3 2 3 ... 62636263 // Trhough all the expected data point per channel row_Count = team4->chip(0)->row_Count(); col_Count = team4->chip(0)->col_Count(); width = col_Count * 4; half_Width = col_Count * 2; for (UInt_t y = 0; y < row_Count; y++) { for (UInt_t x = 0; x < col_Count; x++) { // Column left-right swapped version // Digitizer 0 team4->chip(0)->dp_Value(x, y) = y * width + ((x*2)/64+1)*64 - (x*2)%64 - 1; team4->chip(1)->dp_Value(x, y) = y * width + ((x*2+1)/64+1)*64 - (x*2+1)%64 -1; // Digitizer 1 team4->chip(2)->dp_Value(x, y) = y * width + half_Width + ((x*2) /64+1)*64 - (x*2)%64 - 1; team4->chip(3)->dp_Value(x, y) = y * width + half_Width + ((x*2+1)/64+1)*64 - (x*2+1)%64 -1; // Correct version //team4->chip(0)->dp_Value(x, y)= y * width + x * 2; //team4->chip(1)->dp_Value(x, y)= y * width + x * 2 + 1; //team4->chip(2)->dp_Value(x, y)= y * width + x * 2 + half_Width; //team4->chip(3)->dp_Value(x, y)= y * width + x * 2 + half_Width + 1; // Debug version, Left and right swapped to account for a similar swap // into the data_Mux moddule on the firmware //team4->chip(0)->dp_Value(x, y)= y * width + x * 2 + 1; //team4->chip(1)->dp_Value(x, y)= y * width + x * 2; //team4->chip(2)->dp_Value(x, y)= y * width + x * 2 + half_Width + 1; //team4->chip(3)->dp_Value(x, y)= y * width + x * 2 + half_Width; } } } //****************************************************************************** //* * //* Data acquisition functions * //* * //****************************************************************************** //______________________________________________________________________________ void task_Demo::data_Preset() { // Preset the data dbg_Print("task_Demo::data_Preset: setting DAQ", DBG_LVL_FLOW); // Info cool::Out->Print("\nData preset\n", LWHITE); // Updates the detector with the selected number of col/row in case of need if ((old_Det != cmb_Det[0]->cbox_Val()) || (old_Col != cmb_Det[2]->cbox_Val()) || (old_Row != cmb_Det[3]->cbox_Val()) || old_frm_Cnt != num_Acq[0]->num_Val()) { // Set off the led led_Acq[0]->Status(gui_Led::ks_Off); detector_Setup(cmb_Det[2]->cbox_Val(), cmb_Det[3]->cbox_Val()); data_Setup(detector_List[cmb_Det[0]->cbox_Val()], (UInt_t)num_Acq[0]->num_Val()); } old_Det = cmb_Det[0]->cbox_Val(); old_Col = cmb_Det[2]->cbox_Val(); old_Row = cmb_Det[3]->cbox_Val(); old_frm_Cnt = (UInt_t)num_Acq[0]->num_Val(); // Set FPGA fpga_Setup(burst_Raw); } //______________________________________________________________________________ void task_Demo::data_Setup(geom_Frame* detector, UInt_t fr_Count) { // Setup data structures dbg_Print("task_Demo::data_Preset: assigning memory space", DBG_LVL_FLOW); cool::Out->Print("Sizing data objects\n", WHITE); // Delete if (burst_Raw) delete burst_Raw; if (frame_Noise) delete frame_Noise; if (frame_Image) delete frame_Image; if (frame_Sum) delete frame_Sum; if (frame_Display) delete frame_Display; if (frame_Pedestal)delete frame_Pedestal; // New burst_Raw = new data_Burst(detector, fr_Count); frame_Pedestal = new data_Frame(detector); frame_Image = new data_Frame(detector); frame_Sum = new data_Frame(detector); frame_Display = new data_Frame(detector); frame_Noise = new data_Frame(detector); // Prefit map and plot map_Signal->data_Set(frame_Image->layer(0)); map_Signal->data_Refresh(0, 0, frame_Image->layer(0)->dp_col_Count(), frame_Image->layer(0)->dp_row_Count()); plt_Slice->data_Set(frame_Image->layer(0)->dp_Front(), frame_Image->layer(0)->dp_col_Count(), 1); plt_Slice->data_Refresh(0, 0, frame_Image->layer(0)->dp_col_Count(), 100); } //______________________________________________________________________________ void task_Demo::fpga_Setup(data_Burst* burst) { // Comm setup dbg_Print("task_Demo::comm_Setup: setting up communication", DBG_LVL_FLOW); // Info cool::Out->Print("FPGA setup\n", LWHITE); // Step if (!cool::Comm->isOpen()) cool::Comm->Open(); // Check comm status if (!cool::Comm->isOpen()) { cool::Out->Print("You need to open communication to set FPGA!\n", LYELLOW); return; } // Set the ADCs and the clock cool::Reg->adc_clk_Chn(0); // Reference ADC clock cool::Reg->adc_clk_Div(cmb_Det[1]->cbox_Val()); // Clock divider cool::Reg->adc_Avgs(0); // No averages // Set the data trigger cool::Reg->data_trg_Mode(0); // External triggering // Set the dummy driver UInt_t dmy_Size = (UInt_t)sqrt((Double_t)burst->frame_Fit()->chip(0)->dp_Count()); cool::Reg->acq_dmy_Size(dmy_Size); // Set the acquisition mode cool::Reg->acq_Mode(cmb_Acq[2]->cbox_Val()); // Acq(trigger) mode // Set the acquisition driver cool::Reg->acq_drv_Delay(0); // No driving delay cool::Reg->acq_drv_Sel(burst->frame_Fit()->HrdID()); // Set the driver // Set data pipeline cool::Reg->acq_data_Mode(cmb_Acq[1]->cbox_Val()); // Data source; // Set channels UInt_t chn_Count = burst->frame_Fit()->channel_Count(); UInt_t chk_Count = 0; UInt_t chn_Mask = 0; for (UInt_t i = 0; i < 4; i++) { if (chk_Adc[i]->chk_Status()) { chn_Mask += (UInt_t)(pow((double)2, (int)i)); chk_Count++; } } // Check for improprer channelsettings if (chk_Count != chn_Count) { chn_Mask = (UInt_t)(pow((double)2, (int)burst->frame_Fit()->channel_Count()) - 1); } // Shows the actually selected channels for (UInt_t i = 0; i < 4; i++) chk_Adc[i]->chk_Status(1 & chn_Mask >> i); // Sets the channel on the FPGA cool::Reg->acq_chn_Enable(chn_Mask); // Set data count for the packet builder cool::Reg->acq_frm_Count(burst->frame_Count()); // Frame data count cool::Reg->acq_dp_Count(burst->frame_Fit()->chip(0)->dp_Count()); // Total data count (per channel!) // Set data triggering mode cool::Reg->acq_trg_Mode(0); // Internal trigger cool::Reg->acq_trg_Period(1000); // 10 Hz trigger period } //______________________________________________________________________________ void task_Demo::team_Setup() { // Preset the data dbg_Print("task_Demo::team_Set: setting DAQ", DBG_LVL_FLOW); // Set up a pivot buffer Int_t buff_Count = 29; Int_t buff_Len = 16; UShort_t wr_Buff[29][16] = { // Sets DataNConfig to config mode {5, 0, 0, 0x8802, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets clock {5, 0, 0, 0x87c2, 0x0000, 0x0002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x87c2, 0x0000, 0x0003, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //reset second digitizer {5, 0, 0, 0x87c3, 0x0000, 0x0010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x87c3, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //Sync APS clock {5, 0, 0, 0x8802, 0x0000, 0x00C5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8802, 0x0000, 0x0045, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8802, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets register DAC values {5, 0, 0, 0x8405, 0x11E4, 0x1AB8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8406, 0x0000, 0x177C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8407, 0x1AB8, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8408, 0x1290, 0x1199, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets digitizer to send clocks to the sensor and update the DAC values. {5, 0, 0, 0x8002, 0x000A, 0x8001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8402, 0x0022, 0x8002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8402, 0x0022, 0xA002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8402, 0x0022, 0x8002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Selects real data from digitizers {5, 0, 0, 0x8004, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x8404, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets image size (64 columns per output and 1024 rows, the full sector) {5, 0, 0, 0x800c, 0x0140, 0x0400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x840c, 0x0140, 0x0400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets APS clock speed {5, 0, 0, 0x800d, 0x0000, 0x0018, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x800d, 0x0000, 0x0013, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x800d, 0x0000, 0x0018, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x800d, 0x0000, 0x0013, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x840d, 0x0000, 0x0003, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets delays from qwrap and C0 {5, 0, 0, 0x800e, 0x0000, 0x0340, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5, 0, 0, 0x840e, 0x0000, 0x0340, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets image size on V4 (here it is 1024 * 1024) {5, 0, 0, 0x8803, 0x0400, 0x0400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Sets DataNConfig {5, 0, 0, 0x8802, 0x0000, 0x0045, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; // Sets the other control cmb_Acq[1]->cbox_Val(4); // Data Mode cmb_Det[0]->cbox_Val(4); // Gretina 4 ch cmb_Det[1]->cbox_Val(4); // 3 MHz clock cmb_Det[2]->cbox_Val(4096); // Cols cmb_Det[3]->cbox_Val(1024); // Rows // Sends the buffer for (UInt_t i = 0; i < buff_Count; i++) cool::Comm->raw_Write(wr_Buff[i], &buff_Len); // Check readback //cool::Out->Print("Check readback\n", WHITE); //UShort_t rd_Buff[16]; //for (UInt_t i = 0; i < buff_Count; i++) { // wr_Buff[i][3] = wr_Buff[i][3] + 0x4000; // cool::Comm->raw_Write(wr_Buff[i], &buff_Len); // cool::Comm->raw_Read(rd_Buff, &buff_Len); // std::cout << std::hex << wr_Buff[i][3] << ": "; // for (UInt_t i = 0; i < buff_Len; i++) std::cout << rd_Buff[i] << ", "; // std::cout << "\n"; //} // TEAM mode set! cool::Out->Print("TEAM mode set\n", LWHITE); } //______________________________________________________________________________ void task_Demo::data_Pedestal() { // Acquire the pedestals dbg_Print("task_Demo::data_Pedestal: acquiring pedestals", DBG_LVL_FLOW); // Info cool::Out->Print("\nTaking pedestals... ", LWHITE); // Clear the led! led_Acq[0]->Status(gui_Led::ks_Off); // Run n times and add UInt_t runs =(UInt_t) num_Acq[3]->num_Val(); // Blank the data *frame_Pedestal = 0; bool broken = false; // Sum for (UInt_t i = 0; i < runs; i++) { // Check the button if (!btn_Acq[1]->btn_Status()) {broken = true; break;} // Retrieves the data data_Acquire(ka_Ped); // Sum up *(frame_Pedestal) += *(frame_Image); } // Ok if (!broken) { // Averages and noise frame_Pedestal->dp_all_Div(runs); // Show map_Signal->data_Set(frame_Pedestal->layer(0)); map_Signal->range_Auto(true); // Info cool::Out->Print("done\n", LGREEN); led_Acq[0]->Status(gui_Led::ks_On); } else { // Info cool::Out->Print("interrupted\n", LYELLOW); led_Acq[0]->Status(gui_Led::ks_Off); } // Reset button btn_Acq[1]->btn_Status(false); } //______________________________________________________________________________ void task_Demo::data_Write(TString* fileName, UInt_t fileMode, bool setMode) { // Write current data dbg_Print("task_Demo::data_Write: saving data to file", DBG_LVL_FLOW); // Ask for file name and type in case bool selfName = false; if (!fileName) { // Create a tenmporary object fileName = new TString; selfName = true; // Set file types TGFileInfo fi; const char *ft[] = {"ASCII", "*.asc", "Binary 2 bytes", "*.bin", "Binary 4 bytes", "*.bin", 0, 0}; fi.fFileTypes = ft; // Show file dialog new TGFileDialog(gClient->GetRoot(), gClient->GetDefaultRoot(), kFDSave, &fi); if (!fi.fFilename) return; fileName->Form(fi.fFilename); // Add the file type identifier switch (fi.fFileTypeIdx) { case 0: fileMode = 0; break; // ASCII case 2: fileMode = 1; break; // Binary 4 bytes case 4: fileMode = 2; break; // Binary 2 bytes } } // In set mode, just set the global file name and data mode if (setMode) { stream_fileRoot.Form(fileName->Data()); stream_fileMode = fileMode; std::cout << fileName->Data(); cool::Out->Print("Stream file is:", WHITE); cool::Out->Print((char*)fileName->Data(), LWHITE, true); cool::Out->Print("Stream file mode:", WHITE); cool::Out->Print(fileMode, LWHITE, true); return; } // Assign currend displayed data pointer Int_t* px_Front = 0; char* ch_Front = 0; UInt_t px_Count = 0; if (num_Acq[2]->num_Val() == 1) { px_Front = frame_Image->layer(0)->dp_Front(); ch_Front = (char*)frame_Image->layer(0)->dp_Front(); px_Count = frame_Image->layer(0)->dp_Count(); } else { px_Front = frame_Display->layer(0)->dp_Front(); ch_Front = (char*)frame_Display->layer(0)->dp_Front(); px_Count = frame_Display->layer(0)->dp_Count(); } // Write ofstream* outFile = new ofstream(fileName->Data(), std::ios::out|std::ios::binary); // ASCII if (fileMode == 0) for (UInt_t i = 0; i < px_Count; i++) { if ((i+1) % 1024) *outFile << px_Front[i] << " "; else *outFile << px_Front[i] << "\n"; } // Binary 2 bytes if (fileMode == 1) { UInt_t pivot; const char* ref = (const char*)(&pivot); for (UInt_t i = 0; i < px_Count; i++) { pivot = (Short_t)px_Front[i]; outFile->write(ref, 2); } } // Binary 4 bytes if (fileMode == 2) outFile->write(reinterpret_cast(px_Front), 4 * px_Count); // Close outFile->close(); // Info cool::Out->Print("File "); cool::Out->Print((char*)(fileName->Data()), LWHITE); cool::Out->Print(" written!\n"); // Delete fileNAme if it is self-ownes if (selfName) delete fileName; } //______________________________________________________________________________ void task_Demo::data_Acquire(UInt_t acq_Mode) { // Acquire the data dbg_Print("task_Demo::data_Acquire: retriving data from DAQ", DBG_LVL_FLOW); // acq_Mode values: ka_Std = standard // ka_Ped = pedestal // ka_Grt = Gretina/TEAM // Fits and Setups maps //map_Signal->data_Set(frame_Image->layer(0)); //map_Signal->range_Auto(true); //plt_Slice->range_Auto(true); // Acq type if (acq_Mode != ka_Ped) cool::Out->Print("ACQ started!\n", LWHITE); // DDR Memory // ---------- /* // Less than 1024 points, they will stay in a row UInt_t dp_Count = burst_Raw->frame_Fit()->chip(0)->dp_Count(); dp_Count = burst_Raw->dp_Count(); std::cout << "burst_Raw->dp_Count = " << dp_Count << "\n"; UInt_t ddr_cg_Count = 63; UInt_t ddr_row_Count = 1; //(UInt_t)floor((double)dp_Count / 4096); // Debug info std::cout << "DDR row_Count = " << ddr_row_Count << "\n"; std::cout << "DDR cg_Count = " << ddr_cg_Count << "\n"; std::cout << "DDR set capacity = " << 4 * (ddr_row_Count + 1) * (ddr_cg_Count + 1) * 16 << " word/px\n"; cool::Reg->ddr_Cmd(0x08); // Set DDR number of row cool::Reg->ddr_Data(ddr_row_Count); // Data for the the DDR cool::Reg->ddr_Cmd(0x09); // Set DDR number of bursts per row (each burst 256 bit) cool::Reg->ddr_Data(ddr_cg_Count); // Data for the the DDR */ // This is for the Gretina control (5 is the Gretina ID in the USB chain), // It sends the start bit to the gretina controller UShort_t wr_Buff[16] = {5, 0, 0, 0x8801, 0x000, 0x0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Int_t wr_Len = 16; // Acquisition mode UInt_t burst_Count; UInt_t burst_Inc; // Acquisition if (acq_Mode != ka_Ped) { if (cmb_Acq[0]->cbox_Val() == 0) { burst_Count = 1; burst_Inc = 1; } else if (cmb_Acq[0]->cbox_Val() == 1) { burst_Count = 1; burst_Inc = 0; } else { burst_Count = (UInt_t)num_Acq[1]->num_Val(); burst_Inc = 1; } // Pedestals } else { burst_Count = 1; burst_Inc = 1; } // Integration UInt_t sum_Count = (UInt_t)(num_Acq[2]->num_Val()); UInt_t sum_Index = 0; *frame_Sum = 0; *frame_Display = 0; // Timing references clock_t start = clock(); clock_t stop = clock(); Double_t elapsed; // Debug std::cout << "burst_Raw->dp_Count(): " << burst_Raw->dp_Count() << "\n"; // Main acquisition loop for (UInt_t i = 0 ; i < burst_Count; i+= burst_Inc) { // Check the button status if (!btn_Acq[0]->btn_Status() && acq_Mode != ka_Ped) break; // Home //if (cool::Comm->isOpen()) { // *************************************************************** // Launch the read thread, the 'false' indicating a do not wait mode // if (acq_Mode != ka_Ped) std::cout << "Starting the burst read...\n"; cool::Comm->burst_Read(burst_Raw, false, 2000); // If Gretina is the target, trigger the gretina sync bit! if (cmb_Det[0]->cbox_Val() >= 3) { std::cout << "Sending gretina start bit...\n"; cool::Comm->raw_Write(wr_Buff, &wr_Len); // Wait for the read thread to be correctly launched } else Sleep(50); // Wait until the read request has been completed completed. Here // we are just waiting, but one could/should use this time to // perform data processing or others tasks. Important: you can // access the communication ONLY when the status comes back to // 'kbr_Free'! while (cool::Comm->burst_read_Status() != cool::Comm->kbr_Free) { // Use this to process the GUI events pipeline std::cout << "*"; gSystem->ProcessEvents(); // Frees (milliseconds) CPU time. Values between (10 - 50) are // usually ok to give good user feedback. Sleep(50); } // Example: check the end status of the burst read. Note that this flag // value is also returned by 'burst_Read()' itself when used with the // 'wait' parameter set to 'true' switch (cool::Comm->burst_read_Exited()) { case cool::Comm->kbr_Free: break; // Everything fine! case cool::Comm->kbr_Missed: break; // Error handled at comm_Master level case cool::Comm->kbr_Timeout: break; // Error handled at comm_Master level case cool::Comm->kbr_Error: break; // Error handled at comm_Master level } //} else { // ****************************** // std::cout << "Fake soft mode\n"; // ***************************** //burst_Raw->dp_all_Populate(10,1,1); // ******************************* //burst_Raw->dp_all_Clusterize(1,10); // ******************************* //} // ***************************** // Shows if (cool::Comm->burst_read_Exited() == cool::Comm->kbr_Free) { // Fake clusters //burst_Raw->frame(0)->layer(0)->dp_all_Populate(1, 20, 3); //std::cout << "Clustering:\n"; //data_Stack* stack; //stack = burst_Raw->frame(0)->layer(0)->dp_all_Clusterize(0, 10); //stack->Dump(); //stack->List(); //delete stack; // Checks for broken frame //if (burst_Raw->frame(0)->layer(0)->dp_Value(0) == 0) { // cool::Out->Print("Bad frame\n", LYELLOW); //} else { // Move the UShort raw data to a more comfortable space *frame_Image = *(burst_Raw->frame(0)); // Pedestal subtraction in case if (acq_Mode == ka_PedSub) *frame_Image -= *frame_Pedestal; // Integration mode in case if (sum_Count > 1) { if (sum_Index < sum_Count) { *frame_Sum += *frame_Image; sum_Index++; } else { *frame_Display = *frame_Sum / sum_Count; *frame_Sum = *frame_Image; sum_Index = 1; // Refresh the map map_Signal->data_Set(frame_Display->layer(0)); map_Signal->data_Refresh(); } } else { // Refresh the map map_Signal->data_Set(frame_Image->layer(0)); map_Signal->data_Refresh(); } // Take the slice UInt_t row_Idx = (UInt_t)num_Slice->num_Val(); if (row_Idx < 0) row_Idx = 0; if (row_Idx >= frame_Image->layer(0)->dp_row_Count()) row_Idx = frame_Image->layer(0)->dp_row_Count() - 1; UInt_t col_Count = frame_Image->layer(0)->dp_col_Count(); Int_t* line_Start = frame_Image->layer(0)->dp_Front() + col_Count * row_Idx; //std::cout << "row_Idx: " << row_Idx << "\n"; //std::cout << "line_Start: " << line_Start << "\n"; //std::cout << "col_Count: " << col_Count << "\n"; plt_Slice->data_Set(line_Start, col_Count, 1); plt_Slice->data_Refresh(); // Time counter elapsed = (double)(clock() - stop) / CLOCKS_PER_SEC; stop = clock(); if (acq_Mode != ka_Ped) std::cout << "Frame #" << i << " (" << elapsed << ") Exit status: " << cool::Comm->burst_read_Exited() << "\n"; // Save in case if (btn_Acq[5]->btn_Status()) { // Get root and counter stream_fileCount = (UInt_t)(num_Acq[4]->num_Val()); // Write TString fName(stream_fileRoot.Data()); TString fCount; fCount.Form("%i", stream_fileCount); fName.Append("_"); fName.Append(fCount.Data()); data_Write(&fName, stream_fileMode, false); // Increase counter stream_fileCount++; num_Acq[4]->num_Val(stream_fileCount); } //} } // Anyway, allow the g-system to refresh, and to the user to interact gSystem->ProcessEvents(); Sleep(10); } // End of burst_Count LOOP // Some standard acq procedures elapsed = (double)(stop - start) / CLOCKS_PER_SEC; if (acq_Mode != ka_Ped) { std::cout << "\n"; cool::Out->Print(burst_Count); cool::Out->Print(" burst(s): "); cool::Out->Print(elapsed, LWHITE); cool::Out->Print("s; Frame/s = "); cool::Out->Print((burst_Count / elapsed)); cool::Out->Print("; Speed = "); cool::Out->Print((burst_Count * burst_Raw->dp_Count() * 2) / (elapsed * 1024 * 1024)); cool::Out->Print(" MB/s\n"); // Reset the button btn_Acq[0]->btn_Status(false); // Shows data commitment std::cout << "\nTotal allocated data: " << data_Object::stc_data_Size() / 1024 << " kBytes\n"; std::cout << "raw_Burst data:" << burst_Raw->dp_Size() / 1024 << " kBytes\n"; } } // ************************ // D D R // ************************ //______________________________________________________________________________ void task_Demo::btn_all_Evn(const int arg) { // Set all button event handler dbg_Print("task_Demo::btn_all_Evn: button has been pressed!", DBG_LVL_FLOW); set_All(); } //______________________________________________________________________________ void task_Demo::btn_adc_Evn(const int arg) { // Set ADC FIFO button event handler dbg_Print("task_Demo::btn_adc_Evn: button has been pressed!", DBG_LVL_FLOW); set_ADC(); } //______________________________________________________________________________ void task_Demo::btn_ro_Evn(const int arg) { // Set RO FIFO button event handler dbg_Print("task_Demo::btn_ro_Evn: button has been pressed!", DBG_LVL_FLOW); set_RO(); } //______________________________________________________________________________ void task_Demo::set_All() { // Send the command cool::Reg->ddr_Cmd(1); // Read-back the command // Set the mode unsigned int mode; mode = cool::Reg->ddr_Data( cbox_Mode->cbox_Val() ); if( mode == 0 ){ cool::Out->Print("\nReal data mode\n", LGREEN); }else if( mode == 1 ){ cool::Out->Print("\nWrite calibration mode\n", LGREEN); }else if( mode == 2 ){ cool::Out->Print("\nRead calibration mode\n", LGREEN); } // Set ADC_FIFO settings set_ADC(); // Set RO_FIFO settings set_RO(); // Set memory size // Memory size: 4 pages, 8196 rows each page, 64 cg each row // where 1 cg = 32 * 8 bits = 32 byte = 16 word // considering 4 mandatory pages, and a minimum write/read lenght // of 1 row, the minimum amount of data is 64 * 32 * 4 = 8192 bytes, // or 4096 words UInt_t dp_Count = burst_Raw->frame_Fit()->chip(0)->dp_Count(); dp_Count = burst_Raw->dp_Count(); std::cout << "burst_Raw->dp_Count = " << dp_Count << "\n"; UInt_t ddr_cg_Count = (UInt_t)num_CG->num_Val(); UInt_t ddr_row_Count = (UInt_t)num_Row->num_Val();; // Debug info std::cout << "DDR row_Count = " << ddr_row_Count << "\n"; std::cout << "DDR cg_Count = " << ddr_cg_Count << "\n"; std::cout << "DDR set capacity = " << 4 * (ddr_row_Count) * (ddr_cg_Count) * 16 << " word/px\n"; cool::Reg->ddr_Cmd(0x08); // Set DDR number of row cool::Reg->ddr_Data(ddr_row_Count); // Data for the the DDR cool::Reg->ddr_Cmd(0x09); // Set DDR number of bursts per row (each burst 256 bit) cool::Reg->ddr_Data(ddr_cg_Count); // Data for the the DDR } //______________________________________________________________________________ void task_Demo::set_ADC() { // SET ADC_FIFO SETTINGS // First set the programmable input pattern cool::Reg->ddr_Cmd(3); unsigned int prog_data; prog_data = cool::Reg->ddr_Data( (unsigned int)num_prog_Data->num_Val() ); // Set the ADC FIFO input cool::Reg->ddr_Cmd(2); unsigned int adc_in; adc_in = cool::Reg->ddr_Data( cbox_ADC_Input->cbox_Val() ); // Set the ADC_FIFO readout clock phase cool::Reg->ddr_Cmd(6); // first command unsigned int adc_phase; adc_phase = cool::Reg->ddr_Data( (unsigned int)num_ADC_Phase->num_Val() | (2<<8) ); cool::Reg->ddr_Cmd(7); // second command //std::cout << ((unsigned int)num_ADC_Phase->num_Val() | (2<<8)) << std::endl; cool::Out->Print("\nADC_FIFO settings:\n",LGREEN); cool::Out->Print("Input: ", LGREEN); if( adc_in == 0){ cool::Out->Print("real ADC data\n", LWHITE); }else if( adc_in == 1 ){ cool::Out->Print("32 bit counter data\n", LWHITE); }else if( adc_in == 2 ){ cool::Out->Print("test data\n", LWHITE); }else if( adc_in == 3 ){ cool::Out->Print("alternate 0s and 1s\n", LWHITE); }else if( adc_in == 4 ){ cool::Out->Print("Program pattern: ", LWHITE); cool::Out->Print(prog_data, LWHITE); cool::Out->Print("\n"); } cool::Out->Print("Phase: ", LGREEN); cool::Out->Print(adc_phase & 255, LWHITE); cool::Out->Print("\n"); } //______________________________________________________________________________ void task_Demo::set_RO() { // SET RO_FIFO SETTINGS // Set the RO_FIFO input cool::Reg->ddr_Cmd(4); unsigned int ro_in; ro_in = cool::Reg->ddr_Data( cbox_RO_Input->cbox_Val() ); // Set the ADC_FIFO readout clock phase cool::Reg->ddr_Cmd(6); // first command unsigned int ro_phase; ro_phase = cool::Reg->ddr_Data( (unsigned int)num_RO_Phase->num_Val() | (3<<8) ); cool::Reg->ddr_Cmd(7); // second command //std::cout << ((unsigned int)num_RO_Phase->num_Val() | (3<<8)) << std::endl; cool::Out->Print("\nRO_FIFO settings:\n",LGREEN); cool::Out->Print("Input: ", LGREEN); if( ro_in == 0){ cool::Out->Print("data from DDR2\n", LWHITE); }else if( ro_in == 1 ){ cool::Out->Print("32 bit counter data\n", LWHITE); } cool::Out->Print("Phase: ", LGREEN); cool::Out->Print(ro_phase & 255, LWHITE); cool::Out->Print("\n"); } void task_Demo::team_EraseFirmware(const int arg) { int val=0; Int_t buff_Len = 16; UShort_t wr_Buff[16] = {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; UShort_t slot_offset = DEF_SLOT_OFFSET; int end, addr, stat; UShort_t rd_buff[256]; Int_t rd_buff_Len = 256; cout << hex; // Set Config overwrite == 1 wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x120; cool::Comm->raw_Write(wr_Buff, &buff_Len); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x100; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Set VPEN signal == 1 wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C2; wr_Buff[4] = 0x0; wr_Buff[5] = 0x511; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Erase [first quarter of] flash end = (FLASH_BLOCKS / 4) * FLASH_BLOCK_SIZE; cout << " - Erasing 128 Flash Blocks\n"; //Set mem to erase block wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = 0; wr_Buff[5] = 0; cool::Comm->raw_Write(wr_Buff, &buff_Len); for (addr = 0; addr < end; addr += (FLASH_BLOCK_SIZE/2)) { wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = (short int)(addr>>16); wr_Buff[5] =(short int)(addr); cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0x20); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x20; cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x80+slot_offset, addr); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0xD0; cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0xD0); //READ status wr_Buff[3] = READ_COMMAND+slot_offset+0x3c1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x00; cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); cout << addr << " \n"; cool::Comm->raw_Read(rd_buff, &rd_buff_Len); stat = rd_buff[rd_buff_Len-1]; cout << rd_buff_Len << " | " << rd_buff[rd_buff_Len] << " | " << rd_buff[rd_buff_Len-1] <<" ||" << stat <<" \n"; wr_Buff[3] = 0;wr_Buff[4] = 0;wr_Buff[5] = 0;wr_Buff[6] = 0;wr_Buff[7] = 0;wr_Buff[9] = 0;wr_Buff[9] = 0; wr_Buff[10] = 0;wr_Buff[11] = 0;wr_Buff[12] = 0;wr_Buff[13] = 0;wr_Buff[14] = 0;wr_Buff[15] = 0; while (stat & 0x80) { //get status to wait until mem is not busy anymore //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); wr_Buff[3] = READ_COMMAND+slot_offset+0x3C1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); wr_Buff[3] = READ_COMMAND+slot_offset+0x3C1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found //std::cout << "Reading: \n"; stat = rd_buff[rd_buff_Len-1]; //cout << "in" << rd_buff_Len << " | " << rd_buff[rd_buff_Len] << " | " << rd_buff[rd_buff_Len-1] << "||" << stat << " \n"; } } //DisplayError(panel, "Blocks Erased", addr/FLASH_BLOCK_SIZE); cout << "Blocks Erased " << addr/FLASH_BLOCK_SIZE << " Done \n"; //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x80+slot_offset, 0x0); // Set Flash Address to 0x0h wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0xFF); // Set Flash to Read Array Mode wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0xFF; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Set Config overwrite == 1 //wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x00; //cool::Comm->raw_Write(wr_Buff, &buff_Len); // Set VPEN signal == 1 //wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C2; wr_Buff[4] = 0x0; wr_Buff[5] = 0x501; //cool::Comm->raw_Write(wr_Buff, &buff_Len); } void task_Demo::team_DownloadFirmware(const int arg) { int length; char * filebuf; int val=0; ifstream is; Int_t buff_Len = 16; UShort_t wr_Buff[16] = {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; UShort_t slot_offset; int end, addr, stat, count, i; int *outptr; short int *addrptr; UShort_t rd_buff[256]; Int_t rd_buff_Len = 256; std::cout << "\nRead file\n"; //open bin file //in the future this should call a menu to select the file is.open ("c:\\develop_files\\vhdl\\chip_pad_012c.bin", ios::binary ); // get length of file: is.seekg (0, ios::end); length = is.tellg(); is.seekg (0, ios::beg); // allocate memory: filebuf = new char [length]; // read data as a block: is.read (filebuf,length); cout << length << endl; outptr = (int *)filebuf; addr = 0x000; cout << hex ; cout << " addr " << (short int)addr << " | " << (short int)(addr>>16); addrptr = (short int *)filebuf; is.close(); std::cout << "Start Download of firmware to dititizer one!\n"; // set off set for the first digitizers slot_offset = DEF_SLOT_OFFSET; // Set Config overwrite == 1 wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x120; cool::Comm->raw_Write(wr_Buff, &buff_Len); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x100; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Set VPEN signal == 1 wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C2; wr_Buff[4] = 0x0; wr_Buff[5] = 0x111; cool::Comm->raw_Write(wr_Buff, &buff_Len); end = (FLASH_BLOCKS / 4) * FLASH_BLOCK_SIZE; //*********************************************************************************************** //*********************************************************************************************** // starts writing //*********************************************************************************************** //*********************************************************************************************** count = 0; //DisplayStatus(panel, " - Programming Main FPGA Flash",2); cout << " - Programming Main FPGA Flash\n"; wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = (short int)(addr>>16); wr_Buff[5] =(short int)(addr); cool::Comm->raw_Write(wr_Buff, &buff_Len); // intialize pointer addrptr = (short int *)filebuf; // end 1659904 for (addr = 0x0; addr < 0x200000; ) { //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x80+slot_offset, addr); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = (short int)(addr>>16); wr_Buff[5] =(short int)(addr); //cool::Comm->raw_Write(wr_Buff, &buff_Len); //cout << (short int)(addr>>16) << " | " << (short int)(addr) << " | "; //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0xE8); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0xE8; cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0xF); // Block Word Count wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0xf; cool::Comm->raw_Write(wr_Buff, &buff_Len); for (i = 0, outptr = (int *)filebuf; i < 0x2; i++, outptr++, addr+=8, addrptr+=4) { //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x84+slot_offset, *outptr); if (addr < 1658992-8) { wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[4] = (short int)*(addrptr+1); wr_Buff[5] = (short int)*addrptr; wr_Buff[6] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[7] = (short int)*(addrptr+1); wr_Buff[8] = (short int)*(addrptr+0); wr_Buff[9] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[11] = (short int)*(addrptr+3); wr_Buff[11] = (short int)*(addrptr+2); wr_Buff[12] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[13] = (short int)*(addrptr+3); wr_Buff[14] = (short int)*(addrptr+2); } else { wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[4] = 0; wr_Buff[5] = 0; wr_Buff[6] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[7] = 0; wr_Buff[8] = 0; wr_Buff[9] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[11] = 0; wr_Buff[11] = 0; wr_Buff[12] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[13] = 0; wr_Buff[14] = 0; } //wr_Buff[6] = WRITE_COMMAND+slot_offset+0x3e1; wr_Buff[7] = (short int)*(addrptr+1); wr_Buff[8] = (short int)*addrptr; cool::Comm->raw_Write(wr_Buff, &buff_Len); //cout << addr << " of " << end << " | " << (short int)*(addrptr+1) << " | " << (short int)*addrptr << "\n"; //cout << addr << " of " << end << " | " << (short int)*(addrptr+1) << " | " << (short int)*(addrptr+0) << "\n"; //cout << addr << " of " << end << " | " << (short int)*(addrptr+3) << " | " << (short int)*(addrptr+2) << "\n"; //cout << addr << " of " << end << " | " << (short int)*(addrptr+3) << " | " << (short int)*(addrptr+2) << "\n"; } wr_Buff[6] = 0; wr_Buff[7] = 0; wr_Buff[8] = 0; wr_Buff[9] = 0; wr_Buff[10] = 0; wr_Buff[11] = 0; wr_Buff[12] = 0; wr_Buff[13] = 0; wr_Buff[14] = 0; //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); wr_Buff[3] = READ_COMMAND+slot_offset+0x3C1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found //std::cout << "Reading: \n"; stat = rd_buff[rd_buff_Len-1]; //cout << rd_buff_Len << " | " << rd_buff[rd_buff_Len] << " | " << rd_buff[rd_buff_Len-1] << "||" << stat << " /n"; while (stat & 0x80) { //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); wr_Buff[3] = READ_COMMAND+slot_offset+0x3C1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found //std::cout << "Reading: \n"; stat = rd_buff[rd_buff_Len-1]; // cout << "in3" << rd_buff_Len << " | " << rd_buff[rd_buff_Len] << " | " << rd_buff[rd_buff_Len-1] << "||" << stat << " \n"; } //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0xD0); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0xD0; cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); wr_Buff[3] = READ_COMMAND+slot_offset+0x3C1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found //std::cout << "Reading: \n"; stat = rd_buff[rd_buff_Len-1]; //cout << rd_buff_Len << " | " << rd_buff[rd_buff_Len] << " | " << rd_buff[rd_buff_Len-1] << "||" << stat << " /n"; while (stat & 0x80) { //A32_Status = viIn32 (vme_slot, VI_A32_SPACE, 0x4+slot_offset, &stat); wr_Buff[3] = READ_COMMAND+slot_offset+0x3C1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found //std::cout << "Reading: \n"; stat = rd_buff[rd_buff_Len-1]; // cout << "in3" << rd_buff_Len << " | " << rd_buff[rd_buff_Len] << " | " << rd_buff[rd_buff_Len-1] << "||" << stat << " \n"; } } //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x80+slot_offset, 0x0); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; // cool::Comm->raw_Write(wr_Buff, &buff_Len); //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x8C+slot_offset, 0xFF); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E3; wr_Buff[4] = 0x0; wr_Buff[5] = 0xFF; cool::Comm->raw_Write(wr_Buff, &buff_Len); cout << "Write Flash File end/n"; // Set VPEN signal == 0 //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x10+slot_offset, 0x0); // wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C2; wr_Buff[4] = 0x0; wr_Buff[5] = 0x1; // cool::Comm->raw_Write(wr_Buff, &buff_Len); // Set config overwrite == 0 //A32_Status = viOut32 (vme_slot, VI_A32_SPACE, 0x10+slot_offset, 0x0); // wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; // cool::Comm->raw_Write(wr_Buff, &buff_Len); std::cout << "Start Download of firmware to dititizer two!\n"; std::cout << "End download!\n"; delete[] filebuf; } void task_Demo::team_VerifyFirmware(const int arg) { int length; char * filebuf; int val=0; ifstream is; Int_t buff_Len = 16; UShort_t wr_Buff[16] = {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; UShort_t slot_offset; int end, addr, count; int *outptr; short int *addrptr; UShort_t rd_buff[256]; Int_t rd_buff_Len = 256; int bsuccess = 1; std::cout << "\nRead file\n"; //open bin file //in the future this should call a menu to select the file is.open ("c:\\develop_files\\vhdl\\chip_pad_012c.bin", ios::binary ); // get length of file: is.seekg (0, ios::end); length = is.tellg(); is.seekg (0, ios::beg); // allocate memory: filebuf = new char [length]; // read data as a block: is.read (filebuf,length); cout << length << endl; outptr = (int *)filebuf; addr = 0x000; cout << hex ; cout << " addr " << (short int)addr << " | " << (short int)(addr>>16) << " /n"; addrptr = (short int *)filebuf; is.close(); std::cout << "Start firmware verfication!\n"; // set off set for the first digitizers slot_offset = DEF_SLOT_OFFSET; // Set Config overwrite == 1 wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x140; cool::Comm->raw_Write(wr_Buff, &buff_Len); end = (FLASH_BLOCKS / 4) * FLASH_BLOCK_SIZE; //*********************************************************************************************** //*********************************************************************************************** // starts writing //*********************************************************************************************** //*********************************************************************************************** // Set Config overwrite == 1 wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x120; cool::Comm->raw_Write(wr_Buff, &buff_Len); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3C3; wr_Buff[4] = 0x0; wr_Buff[5] = 0x140; cool::Comm->raw_Write(wr_Buff, &buff_Len); count = 0; //DisplayStatus(panel, " - Programming Main FPGA Flash",2); wr_Buff[3] = WRITE_COMMAND+slot_offset+0x3E0; wr_Buff[4] = (short int)(addr>>16); wr_Buff[5] =(short int)(addr); cool::Comm->raw_Write(wr_Buff, &buff_Len); // intialize pointer addrptr = (short int *)filebuf; // end for (addr = 0x0; addr < length; addr+=4, addrptr+=2) { wr_Buff[3] = READ_COMMAND+slot_offset+0x3E1; wr_Buff[4] = 0x0; wr_Buff[5] = 0x0; cool::Comm->raw_Write(wr_Buff, &buff_Len); // Read back the data from the USB cool::Comm->raw_Read(rd_buff, &rd_buff_Len); // Show what found //std::cout << "Reading: \n"; if (((short int)rd_buff[rd_buff_Len-1] != (short int)*(addrptr)) | ((short int)rd_buff[rd_buff_Len-2] !=(short int)*(addrptr+1))) { bsuccess = 0; std::cout << "Verify faield at " << addr << " \n"; cout << addr << " of " << length << " | " << (short int)*(addrptr+1) << " | " << (short int)*addrptr << "\n"; cout << addr << " of " << length << " | " << (short int)rd_buff[rd_buff_Len-1] << " | " << (short int)rd_buff[rd_buff_Len-2] << "\n"; addr = length; } } if (bsuccess == 1) std::cout << "Verify finished succesfully!\n"; delete[] filebuf; }