zpu: Reset PID when setting TCXO DAC from the control socket.

This commit is contained in:
Alexander Chemeris
2017-07-26 23:20:36 +03:00
parent aa35f5cc40
commit dfa6aa0a0c
3 changed files with 23 additions and 10 deletions

View File

@@ -162,10 +162,10 @@ static void handle_udp_ctrl_packet(
ctrl_data_out.data.zpu_action.action = ctrl_data_in->data.zpu_action.action;
switch (ctrl_data_in->data.zpu_action.action) {
case UMTRX_ZPU_REQUEST_GET_VCTCXO_DAC:
ctrl_data_out.data.zpu_action.data = (uint32_t)get_vctcxo_dac();
ctrl_data_out.data.zpu_action.data = (uint32_t)gpsdo_get_dac();
break;
case UMTRX_ZPU_REQUEST_SET_VCTCXO_DAC:
set_vctcxo_dac((uint16_t)ctrl_data_in->data.zpu_action.data);
gpsdo_set_dac((uint16_t)ctrl_data_in->data.zpu_action.data);
break;
}
}

View File

@@ -41,8 +41,8 @@ static int gpsdo_debug = 0;
static uint16_t dac_value; /* Current DAC value */
int
set_vctcxo_dac(uint16_t v)
static int
_set_vctcxo_dac(uint16_t v)
{
if (gpsdo_debug) printf("DAC: %d\n", v);
dac_value = v;
@@ -53,8 +53,8 @@ set_vctcxo_dac(uint16_t v)
);
}
uint16_t
get_vctcxo_dac(void)
static uint16_t
_get_vctcxo_dac(void)
{
return dac_value;
}
@@ -140,7 +140,7 @@ _gpsdo_pid_step(int32_t val)
if (gpsdo_debug) printf("GPSDO: correction = %d (P=%d, I=%d, D=%d)>>%d limit +-%d\n", tot, p_term, i_term, d_term, PID_SCALE_SHIFT, PID_MAX_DEV);
/* Update DAC */
set_vctcxo_dac( PID_MID_VAL + tot );
_set_vctcxo_dac( PID_MID_VAL + tot );
}
@@ -190,7 +190,7 @@ void
gpsdo_init(void)
{
/* Set the DAC to mid value */
set_vctcxo_dac( PID_MID_VAL );
_set_vctcxo_dac( PID_MID_VAL );
/* Register IRQ handler */
pic_register_handler(IRQ_GPSDO, _gpsdo_irq_handler);
@@ -201,3 +201,16 @@ gpsdo_init(void)
/* Start request */
gpsdo_regs->csr = GPSDO_CSR_REQ;
}
void gpsdo_set_dac(uint16_t v)
{
/* Reset PID */
_gpsdo_pid_init();
/* Set the DAC value */
_set_vctcxo_dac(v);
}
uint16_t gpsdo_get_dac(void)
{
return _get_vctcxo_dac();
}

View File

@@ -22,9 +22,9 @@
void gpsdo_init(void);
/* Set value of the VCTCXO DAC */
int set_vctcxo_dac(uint16_t v);
void gpsdo_set_dac(uint16_t v);
/* Get the current VCTCXO DAC value */
uint16_t get_vctcxo_dac(void);
uint16_t gpsdo_get_dac(void);
#endif /* INCLUDED_GPSDO_H */