# HG changeset patch # User paul # Date 2016-01-28 09:29:29 # Node ID 132f1c3627d77b59e5ec69d3128414c800a86b08 # Parent f8034461b4039ee9e682e04233aa7ba12b932a14 snapshot resynchro changed the timecode timer is started at the end of the INIT task diff --git a/.hgsubstate b/.hgsubstate --- a/.hgsubstate +++ b/.hgsubstate @@ -1,2 +1,2 @@ 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters -80d727bb9d808ae67c801c4c6101811d68b94af6 header/lfr_common_headers +4ffa7549495b4d1e5ddbda520569468a5e3b8779 header/lfr_common_headers diff --git a/header/wf_handler.h b/header/wf_handler.h --- a/header/wf_handler.h +++ b/header/wf_handler.h @@ -61,6 +61,8 @@ void compute_acquisition_time(unsigned i unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime ); void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel , unsigned long long acquisitionTimeF0_asLong, ring_node *ring_node_swf_extracted, int *swf_extracted); +double computeCorrection( unsigned char *timePtr ); +void applyCorrection( double correction ); void snapshot_resynchronization( unsigned char *timePtr ); // rtems_id get_pkts_queue_id( void ); diff --git a/src/fsw_init.c b/src/fsw_init.c --- a/src/fsw_init.c +++ b/src/fsw_init.c @@ -268,6 +268,9 @@ rtems_task Init( rtems_task_argument ign set_hk_lfr_sc_potential_flag( true ); + // start the timer used for the detection of missing parameters (started also by the timecode_irq_handler ISR) + status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); + status = rtems_task_delete(RTEMS_SELF); } diff --git a/src/tc_handler.c b/src/tc_handler.c --- a/src/tc_handler.c +++ b/src/tc_handler.c @@ -444,8 +444,16 @@ int check_mode_transition( unsigned char void update_last_valid_transition_date( unsigned int transitionCoarseTime ) { - lastValidEnterModeTime = transitionCoarseTime; - PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); + if (transitionCoarseTime == 0) + { + lastValidEnterModeTime = time_management_regs->coarse_time + 1; + PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", transitionCoarseTime); + } + else + { + lastValidEnterModeTime = transitionCoarseTime; + PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); + } } int check_transition_date( unsigned int transitionCoarseTime ) @@ -1243,6 +1251,7 @@ int suspend_asm_tasks( void ) void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) { + WFP_reset_current_ring_nodes(); reset_waveform_picker_regs(); @@ -1263,6 +1272,8 @@ void launch_waveform_picker( unsigned ch waveform_picker_regs->start_date = transitionCoarseTime; } + update_last_valid_transition_date(waveform_picker_regs->start_date); + } void launch_spectral_matrix( void ) diff --git a/src/wf_handler.c b/src/wf_handler.c --- a/src/wf_handler.c +++ b/src/wf_handler.c @@ -45,9 +45,10 @@ ring_node ring_node_swf2_extracted; typedef enum resynchro_state_t { - IDLE, - MEASURE_K, - MEASURE_K_PLUS_1, + MEASURE_0, + MEASURE_1, + CORRECTION_0, + CORRECTION_1 } resynchro_state; //********************* @@ -868,7 +869,7 @@ void build_snapshot_from_ring( ring_node } } -void snapshot_resynchronization( unsigned char *timePtr ) +double computeCorrection( unsigned char *timePtr ) { unsigned long long int acquisitionTime; unsigned long long int centerTime; @@ -876,63 +877,110 @@ void snapshot_resynchronization( unsigne unsigned long long int nextTick; unsigned long long int deltaPreviousTick; unsigned long long int deltaNextTick; - int deltaTickInF2; double deltaPrevious_ms; double deltaNext_ms; double correctionInF2; - double center_k = 0.; - double cnter_k_plus_1 = 0.; - static resynchro_state state = IDLE; - static unsigned char resynchroEngaged = 0; + + // get acquisition time in fine time ticks + acquisitionTime = get_acquisition_time( timePtr ); - if (resynchroEngaged == 0) - { - resynchroEngaged = 1; - // get acquisition time in fine time ticks - acquisitionTime = get_acquisition_time( timePtr ); + // compute center time + centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; + previousTick = centerTime - (centerTime & 0xffff); + nextTick = previousTick + 65536; - // compute center time - centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; - previousTick = centerTime - (centerTime & 0xffff); - nextTick = previousTick + 65536; + deltaPreviousTick = centerTime - previousTick; + deltaNextTick = nextTick - centerTime; - deltaPreviousTick = centerTime - previousTick; - deltaNextTick = nextTick - centerTime; + deltaPrevious_ms = ((double) deltaPreviousTick) / 65536. * 1000.; + deltaNext_ms = ((double) deltaNextTick) / 65536. * 1000.; - deltaPrevious_ms = ((double) deltaPreviousTick) / 65536. * 1000.; - deltaNext_ms = ((double) deltaNextTick) / 65536. * 1000.; + PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); +// PRINTF2(" delta previous = %llu fine time ticks, delta next = %llu fine time ticks\n", +// deltaPreviousTick, deltaNextTick); - PRINTF2("delta previous = %f ms, delta next = %f ms\n", deltaPrevious_ms, deltaNext_ms); - PRINTF2("delta previous = %llu fine time ticks, delta next = %llu fine time ticks\n", deltaPreviousTick, deltaNextTick); + // which tick is the closest? + if (deltaPreviousTick > deltaNextTick) + { + // the snapshot center is just before the second => increase delta_snapshot + correctionInF2 = + (deltaNext_ms * 256. / 1000. ); + } + else + { + // the snapshot center is just after the second => decrease delta_snapshot + correctionInF2 = - (deltaPrevious_ms * 256. / 1000. ); + } - // which tick is the closest? - if (deltaPreviousTick > deltaNextTick) - { - // the snapshot center is just before the second => increase delta_snapshot - correctionInF2 = + (deltaNext_ms * 256. / 1000. ); - } - else - { - // the snapshot center is just after the second => decrease delta_snapshot - correctionInF2 = - (deltaPrevious_ms * 256. / 1000. ); - } + PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); + + return correctionInF2; +} - if (correctionInF2 >=0 ) - { - deltaTickInF2 = ceil( correctionInF2 ); - } - else - { - deltaTickInF2 = floor( correctionInF2 ); - } - waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + deltaTickInF2; - set_wfp_delta_f0_f0_2(); // this is necessary to reset the value of delta_f0 as delta_snapshot has been changed - PRINTF2("Correction of = %d, delta_snapshot = %d\n\n", deltaTickInF2, waveform_picker_regs->delta_snapshot); +void applyCorrection( double correction ) +{ + int correctionInt; + + if (correction>=0) + { + correctionInt = floor(correction); } else { - PRINTF1("No resynchro, delta_snapshot = %d\n\n", waveform_picker_regs->delta_snapshot); - resynchroEngaged = 0; + correctionInt = ceil(correction); + } + waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; + //set_wfp_delta_f0_f0_2(); +} + +void snapshot_resynchronization( unsigned char *timePtr ) +{ + static double correction = 0.; + static double delay_0 = 0.; + static resynchro_state state = MEASURE_0; + + int correctionInt; + + correctionInt = 0; + + switch (state) + { + + case MEASURE_0: + // ******** + PRINTF("MEASURE_0 ===\n"); + state = CORRECTION_0; + delay_0 = computeCorrection( timePtr ); + correction = delay_0; + PRINTF1("MEASURE_0 === correction = %.2f\n", correction ); + applyCorrection( correction ); + PRINTF1("MEASURE_0 === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); + //**** + break; + + case CORRECTION_0: + //************ + PRINTF("CORRECTION_0 ===\n"); + state = CORRECTION_1; + computeCorrection( timePtr ); + correction = -correction; + PRINTF1("CORRECTION_0 === correction = %.2f\n", correction ); + applyCorrection( correction ); + PRINTF1("CORRECTION_0 === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); + //**** + break; + + case CORRECTION_1: + //************ + PRINTF("CORRECTION_1 ===\n"); + state = MEASURE_0; + computeCorrection( timePtr ); + PRINTF1("CORRECTION_1 === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); + //**** + break; + + default: + break; + } }