Skip to content

Commit

Permalink
Add additional debug and cleanup code
Browse files Browse the repository at this point in the history
Signed-off-by: Eshe N Pickett <eshe.n.pickett@intel.com>
  • Loading branch information
eshenayo committed Apr 10, 2024
2 parents 751f348 + 1fc53e7 commit 218edc4
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
tags
.vscode
vsync.code-workspace
release/
release/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ apt install -y intel-gpu-tools edid-decode
```

# Preparing two systems for PTP communication:
This program allows two systems to synchronize their vertical sync firing times.

Building steps:
1) Type ```make release``` from the main directory. It compiles everything and creates a
release folder which can then be copied to the target systems.

Building of this program has been successfully tested on both Ubuntu 20 and Fedora 30.

Preparing two systems for PTP communication:
In order to prepare two systems, please follow these steps:
1) There should be a network cable directly connecting the ethernet ports of the two
systems.
Expand Down
43 changes: 35 additions & 8 deletions lib/combo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include <signal.h>
#include <unistd.h>
#include <memory.h>
#include <time.h>
#include "mmio.h"
#include "combo.h"

list<ddi_sel *> *dpll_enabled_list = NULL;

combo_phy_reg combo_table[] = {
{REG(DPLL0_CFGCR0), REG(DPLL0_CFGCR1), 0, 1},
Expand Down Expand Up @@ -230,8 +232,9 @@ void program_combo_phys(double time_diff, timer_t *t)
user_info *ui = new user_info(COMBO, &combo_table[i]);
make_timer((long) steps, ui, t, reset_combo);
#endif
DBG("OLD VALUES\n cfgcr0 \t 0x%X\n cfgcr1 \t 0x%X\n",
combo_table[i].cfgcr0.orig_val, combo_table[i].cfgcr1.orig_val);
DBG("OLD VALUES\n cfgcr0 [0x%X] =\t 0x%X\n cfgcr1 [0x%X] =\t 0x%X\n",
combo_table[i].cfgcr0.addr, combo_table[i].cfgcr0.orig_val,
combo_table[i].cfgcr1.addr, combo_table[i].cfgcr1.orig_val);

/*
* Symbol clock frequency in MHz (base) = DCO Divider * Reference frequency in MHz / (5 * Pdiv * Qdiv * Kdiv)
Expand Down Expand Up @@ -282,22 +285,23 @@ void program_combo_phys(double time_diff, timer_t *t)
combo_table[i].cfgcr0.mod_val |= i_fbdiv_intgr_9_0;
combo_table[i].cfgcr0.mod_val |= (long) new_i_fbdivfrac_14_0 << 10;

DBG("NEW VALUES\n cfgcr0 \t 0x%X\n", combo_table[i].cfgcr0.mod_val);
DBG("NEW VALUES\n cfgcr0 [0x%X] =\t 0x%X\n", combo_table[i].cfgcr0.addr,
combo_table[i].cfgcr0.mod_val);
program_combo_mmio(&combo_table[i], 1);
}
}

/*******************************************************************************
* Description
* check_if_combo_done - This function checks to see if the Combo programming is
* wait_until_combo_done - This function waits until the Combo programming is
* finished. There is a timer for which time the new values will remain in
* effect. After that timer expires, the original values will be restored.
* Parameters
* NONE
* timer_t t - The timer which needs to be deleted
* Return val
* void
******************************************************************************/
void check_if_combo_done()
void wait_until_combo_done(timer_t t)
{
TRACING();
/* Wait to write back the original value */
Expand All @@ -306,6 +310,8 @@ void check_if_combo_done()
usleep(1000);
}
}
timer_delete(t);
cleanup_list();
}

/*******************************************************************************
Expand Down Expand Up @@ -355,8 +361,29 @@ void reset_combo(int sig, siginfo_t *si, void *uc)
DBG("timer done\n");
combo_phy_reg *cr = (combo_phy_reg *) ui->get_reg();
program_combo_mmio(cr, 0);
DBG("DEFAULT VALUES\n cfgcr0 \t 0x%X\n cfgcr1 \t 0x%X\n",
cr->cfgcr0.orig_val, cr->cfgcr1.orig_val);
DBG("DEFAULT VALUES\n cfgcr0 [0x%X] =\t 0x%X\n cfgcr1 [0x%X] =\t 0x%X\n",
cr->cfgcr0.addr, cr->cfgcr0.orig_val, cr->cfgcr1.addr, cr->cfgcr1.orig_val);
cr->done = 1;
delete ui;
}


/*******************************************************************************
* Description
* cleanup_list - This function deallocates all members of the dpll_enabled_list
* Parameters
* NONE
* Return val
* void
******************************************************************************/
void cleanup_list()
{
if(dpll_enabled_list) {
for(list<ddi_sel *>::iterator it = dpll_enabled_list->begin();
it != dpll_enabled_list->end(); it++) {
delete *it;
}
delete dpll_enabled_list;
dpll_enabled_list = NULL;
}
}
3 changes: 2 additions & 1 deletion lib/combo.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ extern combo_phy_reg combo_table[];

int find_enabled_combo_phys();
void program_combo_phys(double time_diff, timer_t *t);
void check_if_combo_done();
void wait_until_combo_done(timer_t t);
void program_combo_mmio(combo_phy_reg *pr, int mod);
void reset_combo(int sig, siginfo_t *si, void *uc);
void cleanup_list();

#endif
5 changes: 2 additions & 3 deletions lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ typedef struct _vbl_info {

typedef int (*find_func)();
typedef void (*program_func)(double time_diff, timer_t *t);
typedef void (*check_func)();
typedef void (*wait_func)(timer_t t);
typedef void (*reset_func)(int sig, siginfo_t *si, void *uc);

typedef struct _phy_funcs {
char name[20];
void *table;
find_func find;
program_func program;
check_func check_if_done;
wait_func wait_until_done;
timer_t timer_id;
} phy_funcs;

Expand All @@ -98,7 +98,6 @@ typedef struct _platform {

extern platform platform_table[];
extern int supported_platform;
extern list<ddi_sel *> *dpll_enabled_list;

int calc_steps_to_sync(double time_diff, double shift);
void timer_handler(int sig, siginfo_t *si, void *uc);
Expand Down
35 changes: 26 additions & 9 deletions lib/dkl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <debug.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include "mmio.h"
#include "dkl.h"

Expand Down Expand Up @@ -117,12 +118,17 @@ void program_dkl_phys(double time_diff, timer_t *t)
user_info *ui = new user_info(DKL, &dkl_table[i]);
make_timer((long) steps, ui, t, reset_dkl);
#endif
DBG("OLD VALUES\n dkl_pll_div0 \t 0x%X\n dkl_visa_serializer \t 0x%X\n "
"dkl_bias \t 0x%X\n dkl_ssc \t 0x%X\n dkl_dco \t 0x%X\n",
DBG("OLD VALUES\n dkl_pll_div0 [0x%X] =\t 0x%X\n dkl_visa_serializer [0x%X] =\t 0x%X\n "
"dkl_bias [0x%X] =\t 0x%X\n dkl_ssc [0x%X] =\t 0x%X\n dkl_dco [0x%X] =\t 0x%X\n",
dkl_table[i].dkl_pll_div0.addr,
dkl_table[i].dkl_pll_div0.orig_val,
dkl_table[i].dkl_visa_serializer.addr,
dkl_table[i].dkl_visa_serializer.orig_val,
dkl_table[i].dkl_bias.addr,
dkl_table[i].dkl_bias.orig_val,
dkl_table[i].dkl_ssc.addr,
dkl_table[i].dkl_ssc.orig_val,
dkl_table[i].dkl_dco.addr,
dkl_table[i].dkl_dco.orig_val);

/*
Expand Down Expand Up @@ -158,35 +164,41 @@ void program_dkl_phys(double time_diff, timer_t *t)
dkl_table[i].dkl_dco.mod_val &= ~BIT(2);
dkl_table[i].dkl_dco.mod_val |= 0x2 << 1;

DBG("NEW VALUES\n dkl_pll_div0 \t 0x%X\n dkl_visa_serializer \t 0x%X\n "
"dkl_bias \t 0x%X\n dkl_ssc \t 0x%X\n dkl_dco \t 0x%X\n",
DBG("NEW VALUES\n dkl_pll_div0 [0x%X] =\t 0x%X\n dkl_visa_serializer [0x%X] =\t 0x%X\n "
"dkl_bias [0x%X] =\t 0x%X\n dkl_ssc [0x%X] =\t 0x%X\n dkl_dco [0x%X] =\t 0x%X\n",
dkl_table[i].dkl_pll_div0.addr,
dkl_table[i].dkl_pll_div0.mod_val,
dkl_table[i].dkl_visa_serializer.addr,
dkl_table[i].dkl_visa_serializer.mod_val,
dkl_table[i].dkl_bias.addr,
dkl_table[i].dkl_bias.mod_val,
dkl_table[i].dkl_ssc.addr,
dkl_table[i].dkl_ssc.mod_val,
dkl_table[i].dkl_dco.addr,
dkl_table[i].dkl_dco.mod_val);
program_dkl_mmio(&dkl_table[i], 1);
}
}

/*******************************************************************************
* Description
* check_if_dkl_done - This function checks to see if the DKL programming is
* wait_until_dkl_done - This function waits until the DKL programming is
* finished. There is a timer for which time the new values will remain in
* effect. After that timer expires, the original values will be restored.
* Parameters
* NONE
* timer_t t - The timer which needs to be deleted
* Return val
* void
******************************************************************************/
void check_if_dkl_done()
void wait_until_dkl_done(timer_t t)
{
TRACING();
for(int i = 0; i < ARRAY_SIZE(dkl_table); i++) {
while(!dkl_table[i].done) {
usleep(1000);
}
}
timer_delete(t);
}

/*******************************************************************************
Expand Down Expand Up @@ -258,12 +270,17 @@ void reset_dkl(int sig, siginfo_t *si, void *uc)
DBG("timer done\n");
dkl_phy_reg *dr = (dkl_phy_reg *) ui->get_reg();
program_dkl_mmio(dr, 0);
DBG("DEFAULT VALUES\n dkl_pll_div0 \t 0x%X\n dkl_visa_serializer \t 0x%X\n "
"dkl_bias \t 0x%X\n dkl_ssc \t 0x%X\n dkl_dco \t 0x%X\n",
DBG("DEFAULT VALUES\n dkl_pll_div0 [0x%X] =\t 0x%X\n dkl_visa_serializer [0x%X] =\t 0x%X\n "
"dkl_bias [0x%X] =\t 0x%X\n dkl_ssc [0x%X] =\t 0x%X\n dkl_dco [0x%X] =\t 0x%X\n",
dr->dkl_pll_div0.addr,
dr->dkl_pll_div0.orig_val,
dr->dkl_visa_serializer.addr,
dr->dkl_visa_serializer.orig_val,
dr->dkl_bias.addr,
dr->dkl_bias.orig_val,
dr->dkl_ssc.addr,
dr->dkl_ssc.orig_val,
dr->dkl_dco.addr,
dr->dkl_dco.orig_val);
dr->done = 1;
delete ui;
Expand Down
2 changes: 1 addition & 1 deletion lib/dkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern dkl_phy_reg dkl_table[];

int find_enabled_dkl_phys();
void program_dkl_phys(double time_diff, timer_t *t);
void check_if_dkl_done();
void wait_until_dkl_done(timer_t t);
void program_dkl_mmio(dkl_phy_reg *pr, int mod);
void reset_dkl(int sig, siginfo_t *si, void *uc);

Expand Down
32 changes: 6 additions & 26 deletions lib/vsyncalter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


phy_funcs phy[] = {
{"DKL", dkl_table, find_enabled_dkl_phys, program_dkl_phys, check_if_dkl_done, 0},
{"COMBO", combo_table, find_enabled_combo_phys, program_combo_phys, check_if_combo_done, 0},
{"DKL", dkl_table, find_enabled_dkl_phys, program_dkl_phys, wait_until_dkl_done, 0},
{"COMBO", combo_table, find_enabled_combo_phys, program_combo_phys, wait_until_combo_done, 0},
};

ddi_sel adl_s_ddi_sel[] = {
Expand All @@ -49,7 +49,6 @@ platform platform_table[] = {

int g_dev_fd = 0;
int supported_platform = 0;
list<ddi_sel *> *dpll_enabled_list = NULL;

/*******************************************************************************
* Description
Expand Down Expand Up @@ -122,24 +121,6 @@ int vsync_lib_init()
return 0;
}

/*******************************************************************************
* Description
* cleanup_list - This function deallocates all members of the dpll_enabled_list
* Parameters
* NONE
* Return val
* void
******************************************************************************/
void cleanup_list()
{
if(dpll_enabled_list) {
for(list<ddi_sel *>::iterator it = dpll_enabled_list->begin(); it != dpll_enabled_list->end(); it++) {
delete *it;
}
delete dpll_enabled_list;
}
}

/*******************************************************************************
* Description
* vsync_lib_uninit - This function uninitializes the library by closing devices
Expand All @@ -152,7 +133,6 @@ void cleanup_list()
******************************************************************************/
void vsync_lib_uninit()
{
cleanup_list();
close_mmio_handle();
UNINIT();
}
Expand All @@ -172,17 +152,17 @@ void vsync_lib_uninit()
******************************************************************************/
void synchronize_phys(int type, double time_diff)
{
/* First, find all the enabled phys */
if(!phy[type].find()) {
DBG("No %s PHYs found\n", phy[type].name);
return;
}

/* Cycle through all the phys */
/* Program the phys that were found with new values */
phy[type].program(time_diff, &phy[type].timer_id);

/* Wait to write back the original values */
phy[type].check_if_done();
timer_delete(phy[type].timer_id);
/* Finally, wait to write back the original values */
phy[type].wait_until_done(phy[type].timer_id);
}

/*******************************************************************************
Expand Down

0 comments on commit 218edc4

Please sign in to comment.