diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -2,6 +2,7 @@ syntax: glob *.pdf *~ *.o +*.gcno *.zip tests/*.err doc diff --git a/FSW-qt/Makefile b/FSW-qt/Makefile --- a/FSW-qt/Makefile +++ b/FSW-qt/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: bin/fsw -# Generated by qmake (2.01a) (Qt 4.8.6) on: Thu Sep 25 11:05:34 2014 +# Generated by qmake (2.01a) (Qt 4.8.6) on: Tue Oct 7 15:14:40 2014 # Project: fsw-qt.pro # Template: app # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro diff --git a/FSW-qt/fsw-qt.pro b/FSW-qt/fsw-qt.pro --- a/FSW-qt/fsw-qt.pro +++ b/FSW-qt/fsw-qt.pro @@ -14,9 +14,17 @@ DEFINES += SW_VERSION_N2=0 # minor DEFINES += SW_VERSION_N3=1 # patch DEFINES += SW_VERSION_N4=1 # internal +# +#QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage +#QMAKE_LFLAGS_RELEASE += +#LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc +# + +# contains( CONFIG, lpp_dpu_destid ) { DEFINES += LPP_DPU_DESTID } +# contains( CONFIG, debug_tch ) { DEFINES += DEBUG_TCH diff --git a/FSW-qt/fsw-qt.pro.user b/FSW-qt/fsw-qt.pro.user --- a/FSW-qt/fsw-qt.pro.user +++ b/FSW-qt/fsw-qt.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/header/fsw_params.h b/header/fsw_params.h --- a/header/fsw_params.h +++ b/header/fsw_params.h @@ -27,11 +27,11 @@ typedef struct ring_node #define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688 #define TIME_OFFSET 2 #define TIME_OFFSET_IN_BYTES 8 -#define WAVEFORM_EXTENDED_HEADER_OFFSET 22 +//#define WAVEFORM_EXTENDED_HEADER_OFFSET 22 #define NB_BYTES_SWF_BLK (2 * 6) #define NB_WORDS_SWF_BLK 3 #define NB_BYTES_CWF3_LIGHT_BLK 6 -#define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8 +//#define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8 #define NB_RING_NODES_F0 3 // AT LEAST 3 #define NB_RING_NODES_F1 5 // AT LEAST 3 #define NB_RING_NODES_F2 5 // AT LEAST 3 @@ -127,7 +127,8 @@ typedef struct ring_node #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff #define APBUART_CTRL_REG_MASK_TE 0x00000002 -#define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50) +// scaler value = system_clock_frequency / ( baud_rate * 8 ) - 1 +#define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 //********** // IRQ LINES diff --git a/header/wf_handler.h b/header/wf_handler.h --- a/header/wf_handler.h +++ b/header/wf_handler.h @@ -67,7 +67,7 @@ int send_waveform_CWF3_light( volatile i void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime, 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 ); -void build_acquisition_time( unsigned long long int * acquisitionTimeAslong, ring_node *current_ring_node ); +void snapshot_resynchronization( unsigned char *timePtr ); // rtems_id get_pkts_queue_id( void ); diff --git a/src/tc_handler.c b/src/tc_handler.c --- a/src/tc_handler.c +++ b/src/tc_handler.c @@ -145,6 +145,8 @@ int action_reset(ccsdsTelecommandPacket_ * */ + printf("this is the end!!!\n"); + exit(0); send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); return LFR_DEFAULT; } diff --git a/src/wf_handler.c b/src/wf_handler.c --- a/src/wf_handler.c +++ b/src/wf_handler.c @@ -210,6 +210,9 @@ rtems_task wfrm_task(rtems_task_argument rtems_event_set event_out; rtems_id queue_id; rtems_status_code status; + bool resynchronisationEngaged; + + resynchronisationEngaged = false; init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 ); init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 ); @@ -228,6 +231,19 @@ rtems_task wfrm_task(rtems_task_argument rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM, RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + if(resynchronisationEngaged == false) + { // engage resynchronisation + snapshot_resynchronization( (unsigned char *) ring_node_to_send_swf_f0->buffer_address); + resynchronisationEngaged = true; + } + else + { // reset delta_snapshot to the nominal value + PRINTF("no resynchronisation, reset delta_snapshot to the nominal value\n") + set_wfp_delta_snapshot(); + resynchronisationEngaged = false; + } + // + if (event_out == RTEMS_EVENT_MODE_NORMAL) { DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n") @@ -954,7 +970,7 @@ void build_snapshot_from_ring( ring_node sampleOffset_asLong = 0x00; // (1) get the f0 acquisition time - build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 ); + acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) current_ring_node_f0->buffer_address ); // (2) compute the central reference time centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; @@ -986,7 +1002,7 @@ void build_snapshot_from_ring( ring_node for (i=0; ibuffer_address ); if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) { PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong) @@ -1037,19 +1053,47 @@ void build_snapshot_from_ring( ring_node } } -void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node ) +void snapshot_resynchronization( unsigned char *timePtr ) { - unsigned char *acquisitionTimeCharPtr; + unsigned long long int acquisitionTime; + unsigned long long int centerTime; + unsigned long long int previousTick; + unsigned long long int nextTick; + unsigned long long int deltaPreviousTick; + unsigned long long int deltaNextTick; + unsigned int deltaTickInF2; + double deltaPrevious; + double deltaNext; - acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address; + acquisitionTime = get_acquisition_time( timePtr ); + + // compute center time + centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; + previousTick = centerTime - (centerTime & 0xffff); + nextTick = previousTick + 65536; - *acquisitionTimeAslong = 0x00; - *acquisitionTimeAslong = ( (unsigned long long int) (acquisitionTimeCharPtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit - + ( (unsigned long long int) acquisitionTimeCharPtr[1] << 32 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[2] << 24 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[3] << 16 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[6] << 8 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[7] ); + deltaPreviousTick = centerTime - previousTick; + deltaNextTick = nextTick - centerTime; + + deltaPrevious = ((double) deltaPreviousTick) / 65536. * 1000.; + deltaNext = ((double) deltaNextTick) / 65536. * 1000.; + + printf("delta previous = %f ms, delta next = %f ms\n", deltaPrevious, deltaNext); + printf("delta previous = %llu, delta next = %llu\n", deltaPreviousTick, deltaNextTick); + + // which tick is the closest + if (deltaPreviousTick > deltaNextTick) + { + deltaTickInF2 = floor( (deltaNext * 256. / 1000.) ); // the division by 2 is important here + waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + deltaTickInF2; + printf("correction of = + %u\n", deltaTickInF2); + } + else + { + deltaTickInF2 = floor( (deltaPrevious * 256. / 1000.) ); // the division by 2 is important here + waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot - deltaTickInF2; + printf("correction of = - %u\n", deltaTickInF2); + } } //**************