Commit 263b982d authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

softpll: tom's patches

parent 4a319b43
...@@ -56,13 +56,6 @@ void spll_init() ...@@ -56,13 +56,6 @@ void spll_init()
n_chan_out = SPLL_CSR_N_OUT_R(SPLL->CSR); n_chan_out = SPLL_CSR_N_OUT_R(SPLL->CSR);
TRACE_DEV("SPLL_Init: %d ref channels, %d out channels\n", n_chan_ref, n_chan_out); TRACE_DEV("SPLL_Init: %d ref channels, %d out channels\n", n_chan_ref, n_chan_out);
SPLL->DAC_HPLL = 0;
TRACE_DEV("delay on\n");
timer_delay(1000);
//GD timer_delay(100000);
//GD
timer_delay(1000);
TRACE_DEV("delay off\n");
SPLL->CSR= 0 ; SPLL->CSR= 0 ;
SPLL->OCER = 0; SPLL->OCER = 0;
...@@ -70,6 +63,7 @@ void spll_init() ...@@ -70,6 +63,7 @@ void spll_init()
SPLL->RCGER = 0; SPLL->RCGER = 0;
SPLL->DCCR = 0; SPLL->DCCR = 0;
SPLL->DEGLITCH_THR = 1000; SPLL->DEGLITCH_THR = 1000;
SPLL->DAC_MAIN = 32000;
while(! (SPLL->TRR_CSR & SPLL_TRR_CSR_EMPTY)) dummy = SPLL->TRR_R0; while(! (SPLL->TRR_CSR & SPLL_TRR_CSR_EMPTY)) dummy = SPLL->TRR_R0;
dummy = SPLL->PER_HPLL; dummy = SPLL->PER_HPLL;
SPLL->EIC_IER = 1; SPLL->EIC_IER = 1;
...@@ -80,7 +74,8 @@ int spll_check_lock() ...@@ -80,7 +74,8 @@ int spll_check_lock()
return helper.ld.locked ? 1 : 0; return helper.ld.locked ? 1 : 0;
} }
#define CHAN_TCXO 8 #define CHAN_RX 0
#define CHAN_TCXO 1
void spll_test() void spll_test()
{ {
...@@ -88,32 +83,84 @@ void spll_test() ...@@ -88,32 +83,84 @@ void spll_test()
volatile int dummy; volatile int dummy;
TRACE_DEV("running spll_init\n"); TRACE_DEV("running spll_init\n");
spll_init(); // TRACE_DEV("enable irq\n");
helper_init(&helper, 0);
TRACE_DEV("spll_init\n");
helper_start(&helper);
TRACE_DEV("helper start\n");
mpll_init(&mpll, 0, 0); //CHAN_TCXO);
enable_irq();
TRACE_DEV("enable irq\n");
// mpll_init(&mpll, 0, CHAN_TCXO); // mpll_init(&mpll, 0, CHAN_TCXO);
while(!helper.ld.locked) ;//TRACE("%d\n", helper.phase.ld.locked); while(!helper.ld.locked) ;//TRACE("%d\n", helper.phase.ld.locked);
TRACE_DEV("Helper locked, starting main\n"); TRACE_DEV("Helper locked, starting main\n");
mpll_start(&mpll); // mpll_start(&mpll);
} }
/* static int spll_master = 0;
#define CHAN_AUX 7 void softpll_set_mode(int master)
#define CHAN_EXT 6 {
spll_master = master;
}
/* Enables SoftPLL in Slave mode.*/
void softpll_enable()
{
if(spll_master)
mprintf("Softpll: running in MASTER mode\n");
else
mprintf("Softpll: running in SLAVE mode\n");
spll_init();
helper_init(&helper, spll_master? CHAN_TCXO : CHAN_RX); /* Change CHAN_RX to CHAN_TCXO if master mode */
helper_start(&helper);
enable_irq();
while(!helper.ld.locked) timer_delay(1);
TRACE_DEV("Helper locked\n");
if(spll_master) return;
/* comment the lines below if Master mode */
mpll_init(&mpll, CHAN_RX, CHAN_TCXO);
mpll_start(&mpll);
while(!mpll.ld.locked) timer_delay(1);
TRACE_DEV("Softpll locked\n");
}
int softpll_check_lock()
{
static int prev_lck = 0;
int lck = mpll.ld.locked && helper.ld.locked;
if(lck && !prev_lck) {
TRACE_DEV("[softpll]: got lock\n");
}else if (!lck && prev_lck)
TRACE_DEV("[softpll]: lost lock\n");
prev_lck = lck;
return lck;
}
int softpll_get_aux_status()
{
return 0;
}
int softpll_busy(int channel)
{
return mpll.phase_shift_target != mpll.phase_shift_current;
}
int spll_gm_measure_ext_phase() void softpll_set_phase( int ps)
{ {
SPLL->CSR = 0; mpll.phase_shift_target = ((int32_t) ((int64_t)ps * (long long)(1<<HPLL_N) / 8000LL));
SPLL->DCCR = SPLL_DCCR_GATE_DIV_W(25);
SPLL->RCGER = (1<<CHAN_AUX);
SPLL->RCGER = (1<<CHAN_EXT);
} }
*/
void softpll_disable()
{
disable_irq();
}
int softpll_get_setpoint()
{
return mpll.phase_shift_target;
}
...@@ -20,7 +20,7 @@ struct spll_helper_state { ...@@ -20,7 +20,7 @@ struct spll_helper_state {
spll_pi_t pi; spll_pi_t pi;
spll_lock_det_t ld; spll_lock_det_t ld;
}; };
static void helper_init(struct spll_helper_state *s, int ref_channel) static void helper_init(struct spll_helper_state *s, int ref_channel)
{ {
...@@ -72,7 +72,6 @@ static int helper_update(struct spll_helper_state *s, int tag, int source) ...@@ -72,7 +72,6 @@ static int helper_update(struct spll_helper_state *s, int tag, int source)
err = (tag + s->p_adder) - s->p_setpoint; err = (tag + s->p_adder) - s->p_setpoint;
// if(s->tag_d0 - tag > -100000) // if(s->tag_d0 - tag > -100000)
TRACE_DEV("%d\n", s->tag_d0 - tag);
//spll_debug(DBG_ERR | DBG_HELPER, s->tag_d0-tag, 1); //spll_debug(DBG_ERR | DBG_HELPER, s->tag_d0-tag, 1);
if(HELPER_ERROR_CLAMP) if(HELPER_ERROR_CLAMP)
...@@ -96,9 +95,9 @@ static int helper_update(struct spll_helper_state *s, int tag, int source) ...@@ -96,9 +95,9 @@ static int helper_update(struct spll_helper_state *s, int tag, int source)
y = pi_update(&s->pi, err); y = pi_update(&s->pi, err);
SPLL->DAC_HPLL = y; SPLL->DAC_HPLL = y;
//spll_debug(DBG_SAMPLE_ID | DBG_HELPER, s->sample_n++, 0); spll_debug(DBG_SAMPLE_ID | DBG_HELPER, s->sample_n++, 0);
//spll_debug(DBG_Y | DBG_HELPER, y, 0); spll_debug(DBG_Y | DBG_HELPER, y, 0);
//spll_debug(DBG_ERR | DBG_HELPER, err, 1); spll_debug(DBG_ERR | DBG_HELPER, err, 1);
if(ld_update(&s->ld, err)) if(ld_update(&s->ld, err))
return SPLL_LOCKED; return SPLL_LOCKED;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment