//------------------------------------------------------------------------------ // DDR2 test application task -- // (C) Devis Contarato 2009, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_DDR.cpp" // [Author] "Devis Contarato" // [Version] "0.5" // [Modified by] "Devis Contarato" // [Last revision] "16 Mar 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "DAQ application task" // [Key documentation] // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Standard components #include // Application components #include "global.h" #include "cool.h" #include "task_DDR.h" // Define some standard color #define kc_Desk cool::Gui->kc_blue_Dark #define kc_desk_Label cool::Gui->kc_White #define kc_Btn cool::Gui->kc_Blue #define kc_btn_Label cool::Gui->kc_White //______________________________________________________________________________ task_DDR::task_DDR() { // Standard constructor dbg_Print("task_DDR::task_DDR: constructor called", DBG_LVL_ZERO); // Set up the communication comm_Setup(); // Set up the interface gui_Setup(); } //______________________________________________________________________________ task_DDR::~task_DDR() { // Standard destructor dbg_Print("task_DDR::~task_DDR: destructor called", DBG_LVL_ZERO); // Kills the interface gui objects gui_Delete(); } //______________________________________________________________________________ UInt_t task_DDR::run() { // Debug dbg_Print("task_DDR::run: run called", DBG_LVL_MAKE); // Returns all ok return 0; } //______________________________________________________________________________ void task_DDR::static_Evn(const int arg) { // Try the call to a static function dbg_Print("task_DDR::static_Evn: it works!", DBG_LVL_FLOW); } //****************************************************************************** //* * //* GUI initialization and destruction * //* * //****************************************************************************** //______________________________________________________________________________ void task_DDR::gui_Setup() { // Set up all the interface objects dbg_Print("task_DAQ::gui_Setup: defining interface!", DBG_LVL_FLOW); //////////////////////// // GENERAL APPEARANCE // //////////////////////// // Main window size cool::Gui->update_Auto(false); cool::Gui->Resize(640, 480); // Main window color cool::Gui->color_Set(0x888888, 0x000060); ////////////////// // MAIN BUTTONS // ////////////////// btn_set_All= new gui_CoolButton("Set All", 360, 64, gui_Const::btn_Width, gui_Const::btn_Height, kc_btn_Label, 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_DDR::btn_all_Evn); btn_set_ADC= new gui_CoolButton("Set ADC FIFO", 508, 64, gui_Const::btn_Width, gui_Const::btn_Height, kc_btn_Label, 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_DDR::btn_adc_Evn); btn_set_RO= new gui_CoolButton("Set RO FIFO", 656, 64, gui_Const::btn_Width, gui_Const::btn_Height, kc_btn_Label, 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_DDR::btn_ro_Evn); btn_open_Comm= new gui_CoolButton("Open COMM", 64, 64, gui_Const::btn_Width, gui_Const::btn_Height, kc_btn_Label, gui_CoolButton::kc_Green); btn_open_Comm->btn_Mode(gui_CoolButton::km_Button); btn_open_Comm->btn_Status(false); btn_open_Comm->task_Connect(this, &task_DDR::btn_CommOpen_Evn); btn_clear_Comm= new gui_CoolButton("Clear COMM", 64, 120, gui_Const::btn_Width, gui_Const::btn_Height, kc_btn_Label, gui_CoolButton::kc_Red); btn_clear_Comm->btn_Mode(gui_CoolButton::km_Button); btn_clear_Comm->btn_Status(false); btn_clear_Comm->task_Connect(this, &task_DDR::btn_CommClear_Evn); btn_Quit = new gui_CoolButton("Quit", 64, 288, gui_Const::btn_Width, gui_Const::btn_Height, kc_btn_Label, gui_CoolButton::kc_Purple); btn_Quit->btn_Mode(gui_CoolButton::km_Button); btn_Quit->btn_Status(false); btn_Quit->task_Connect(this, &task_DDR::btn_quit_Evn); // Combo box for write and read mode selection cbox_Mode = new gui_Combo(0, 360, 120, 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(1, 508, 120, 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(2, 656, 120, 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(0, 508, 176, 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(0, 656, 176, 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(0, 508, 232, 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); // Refresh the Gui! cool::Gui->Update(true); } //______________________________________________________________________________ void task_DDR::gui_Delete() { // Delete all the interface objects dbg_Print("task_DDR::gui_delete: closing interface objects!", DBG_LVL_FLOW); cool::Gui->delete_All(); } //****************************************************************************** //* * //* GUI Callback target functions * //* * //****************************************************************************** //______________________________________________________________________________ void task_DDR::btn_quit_Evn(const int arg) { // Quit button events handler dbg_Print("task_DDR::btn_quit_Evn: quit called", DBG_LVL_FLOW); // Exits by self-quitting the class cool::Gui->Quit(); } //______________________________________________________________________________ void task_DDR::btn_all_Evn(const int arg) { // Set all button event handler dbg_Print("task_DDR::btn_all_Evn: button has been pressed!", DBG_LVL_FLOW); set_All(); } //______________________________________________________________________________ void task_DDR::btn_adc_Evn(const int arg) { // Set ADC FIFO button event handler dbg_Print("task_DDR::btn_adc_Evn: button has been pressed!", DBG_LVL_FLOW); set_ADC(); } //______________________________________________________________________________ void task_DDR::btn_ro_Evn(const int arg) { // Set RO FIFO button event handler dbg_Print("task_DDR::btn_ro_Evn: button has been pressed!", DBG_LVL_FLOW); set_RO(); } //______________________________________________________________________________ void task_DDR::btn_CommOpen_Evn(const int arg) { // Set Comm button event handler dbg_Print("task_DDR::btn_CommOpen_Evn: button has been pressed!", DBG_LVL_FLOW); cool::Comm->Open(); } //______________________________________________________________________________ void task_DDR::btn_CommClear_Evn(const int arg) { // Set Comm button event handler dbg_Print("task_DDR::btn_CommClear_Evn: button has been pressed!", DBG_LVL_FLOW); cool::Comm->Clear(); } //______________________________________________________________________________ void task_DDR::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(); } //______________________________________________________________________________ void task_DDR::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_DDR::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"); } //****************************************************************************** //* * //* USB Communication setup * //* * //****************************************************************************** //______________________________________________________________________________ void task_DDR::comm_Setup() { // Comm setup dbg_Print("task_DDR::comm_Setup: setting up communication", DBG_LVL_FLOW); // Open USB communication cool::Comm->Open(); if (!cool::Comm->isOpen()) { std::cout << "You need to open the communication before!\n"; return; } }