##// END OF EJS Templates

Compare Commits r331:a05d13cb0957...r337:e784d0191567

Target:

Source:

Compare was calculated based on this common ancestor commit: 5af3ab05fe7b
Time Author Commit Description
7 commits hidden, click expand to show them.
@@ -1,2 +1,2
1 1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 7c46de6059673d3239fcc7103e16510727f35923 header/lfr_common_headers
2 a34c50cabb1bc5e778bfc8374242e4683e4defc2 header/lfr_common_headers
@@ -1,111 +1,115
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <leon.h>
6 6
7 7 #include "tc_load_dump_parameters.h"
8 8 #include "tc_acceptance.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "wf_handler.h"
11 11 #include "fsw_processing.h"
12 12
13 13 #include "lfr_cpu_usage_report.h"
14 14
15 15 #define MAX_DELTA_COARSE_TIME 3
16 16 #define NB_SCIENCE_TASKS 10
17 17 #define NB_ASM_TASKS 6
18 18 #define STATUS_0 0
19 19 #define STATUS_1 1
20 20 #define STATUS_2 2
21 21 #define STATUS_3 3
22 22 #define STATUS_4 4
23 23 #define STATUS_5 5
24 24 #define STATUS_6 6
25 25 #define STATUS_7 7
26 26 #define STATUS_8 8
27 27 #define STATUS_9 9
28 28
29 #define CAL_F0 625
30 #define CAL_F1 10000
29 #define CAL_F0 625.
30 #define CAL_F1 10000.
31 #define CAL_W0 (2. * pi * CAL_F0)
32 #define CAL_W1 (2. * pi * CAL_F1)
33 #define CAL_A0 1.
34 #define CAL_A1 2.
31 35 #define CAL_FS 160256.410
32 36 #define CAL_SCALE_FACTOR (0.250 / 0.000654) // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV
33 37 #define CAL_NB_PTS 256
34 38 #define CAL_DATA_MASK 0xfff
35 39 #define CAL_F_DIVISOR 38 // 25 MHz => 160 256 (39 - 1)
36 40 // INTERLEAVED MODE
37 41 #define CAL_FS_INTER 240384.615
38 42 #define CAL_NB_PTS_INTER 384
39 43 #define CAL_DATA_MASK_INTER 0x3f
40 44 #define CAL_DATA_SHIFT_INTER 12
41 45 #define BYTES_FOR_2_SAMPLES 3 // one need 3 bytes = 24 bits to store 3 samples of 12 bits in interleaved mode
42 46 #define STEPS_FOR_STORAGE_INTER 128
43 47 #define CAL_F_DIVISOR_INTER 26 // 25 MHz => 240 384
44 48
45 49 extern unsigned int lastValidEnterModeTime;
46 50 extern unsigned char oneTcLfrUpdateTimeReceived;
47 51
48 52 //****
49 53 // ISR
50 54 rtems_isr commutation_isr1( rtems_vector_number vector );
51 55 rtems_isr commutation_isr2( rtems_vector_number vector );
52 56
53 57 //***********
54 58 // RTEMS TASK
55 59 rtems_task actn_task( rtems_task_argument unused );
56 60
57 61 //***********
58 62 // TC ACTIONS
59 63 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
60 64 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
61 65 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
62 66 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
63 67 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
64 68 int action_update_time( ccsdsTelecommandPacket_t *TC);
65 69
66 70 // mode transition
67 71 int check_mode_value( unsigned char requestedMode );
68 72 int check_mode_transition( unsigned char requestedMode );
69 73 void update_last_valid_transition_date( unsigned int transitionCoarseTime );
70 74 int check_transition_date( unsigned int transitionCoarseTime );
71 75 int stop_spectral_matrices( void );
72 76 int stop_current_mode( void );
73 77 int enter_mode_standby(void );
74 78 int enter_mode_normal( unsigned int transitionCoarseTime );
75 79 int enter_mode_burst( unsigned int transitionCoarseTime );
76 80 int enter_mode_sbm1( unsigned int transitionCoarseTime );
77 81 int enter_mode_sbm2( unsigned int transitionCoarseTime );
78 82 int restart_science_tasks( unsigned char lfrRequestedMode );
79 83 int restart_asm_tasks(unsigned char lfrRequestedMode );
80 84 int suspend_science_tasks(void);
81 85 int suspend_asm_tasks( void );
82 86 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
83 87 void launch_spectral_matrix( void );
84 88 void set_sm_irq_onNewMatrix( unsigned char value );
85 89 void set_sm_irq_onError( unsigned char value );
86 90
87 91 // other functions
88 92 void updateLFRCurrentMode(unsigned char requestedMode);
89 93 void set_lfr_soft_reset( unsigned char value );
90 94 void reset_lfr( void );
91 95 // CALIBRATION
92 96 void setCalibrationPrescaler( unsigned int prescaler );
93 97 void setCalibrationDivisor( unsigned int divisionFactor );
94 98 void setCalibrationData( void );
95 99 void setCalibrationReload( bool state);
96 100 void setCalibrationEnable( bool state );
97 101 void setCalibrationInterleaved( bool state );
98 102 void setCalibration( bool state );
99 103 void configureCalibration( bool interleaved );
100 104 //
101 105 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
102 106 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
103 107 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
104 108
105 109 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
106 110 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
107 111
108 112 #endif // TC_HANDLER_H_INCLUDED
109 113
110 114
111 115
@@ -1,101 +1,103
1 1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 2 #define TC_LOAD_DUMP_PARAMETERS_H
3 3
4 4 #include <rtems.h>
5 5 #include <stdio.h>
6 6
7 7 #include "fsw_params.h"
8 8 #include "wf_handler.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "fsw_misc.h"
11 11 #include "basic_parameters_params.h"
12 12 #include "avf0_prc0.h"
13 13
14 14 #define FLOAT_EQUAL_ZERO 0.001
15 15 #define NB_BINS_TO_REMOVE 3
16 16 #define FI_INTERVAL_COEFF 0.285
17 17 #define BIN_MIN 0
18 18 #define BIN_MAX 127
19 19 #define DELTAF_F0 96.
20 20 #define DELTAF_F1 16.
21 21 #define DELTAF_F2 1.
22 22
23 23 #define BIT_RW1_F1 0x80
24 24 #define BIT_RW1_F2 0x40
25 25 #define BIT_RW2_F1 0x20
26 26 #define BIT_RW2_F2 0x10
27 27 #define BIT_RW3_F1 0x08
28 28 #define BIT_RW3_F2 0x04
29 29 #define BIT_RW4_F1 0x02
30 30 #define BIT_RW4_F2 0x01
31 31
32 32 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
33 33
34 34 extern unsigned short sequenceCounterParameterDump;
35 35 extern unsigned short sequenceCounters_TM_DUMP[];
36 36 extern float k_coeff_intercalib_f0_norm[ ];
37 37 extern float k_coeff_intercalib_f0_sbm[ ];
38 38 extern float k_coeff_intercalib_f1_norm[ ];
39 39 extern float k_coeff_intercalib_f1_sbm[ ];
40 40 extern float k_coeff_intercalib_f2[ ];
41 41 extern fbins_masks_t fbins_masks;
42 42
43 43 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
44 44 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
45 45 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
46 46 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
47 47 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
48 48 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
49 49 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
50 50 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
51 51 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
52 52 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
53 53
54 54 // NORMAL
55 55 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
56 56 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
57 57 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
58 58 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
59 59 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
60 60 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
61 61 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
62 62
63 63 // BURST
64 64 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
65 65 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
66 66
67 67 // SBM1
68 68 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
69 69 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
70 70
71 71 // SBM2
72 72 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
73 73 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
74 74
75 75 // TC_LFR_UPDATE_INFO
76 76 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
77 77 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
78 78 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
79 79 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
80 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag );
80 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag, float sy_lfr_rw_k );
81 81 void build_sy_lfr_rw_mask( unsigned int channel );
82 82 void build_sy_lfr_rw_masks();
83 83 void merge_fbins_masks( void );
84 84
85 85 // FBINS_MASK
86 86 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
87 87
88 88 // TC_LFR_LOAD_PARS_FILTER_PAR
89 89 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
90 90
91 91 // KCOEFFICIENTS
92 92 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
93 93 void copyFloatByChar( unsigned char *destination, unsigned char *source );
94 void copyInt32ByChar( unsigned char *destination, unsigned char *source );
95 void copyInt16ByChar( unsigned char *destination, unsigned char *source );
94 96 void floatToChar( float value, unsigned char* ptr);
95 97
96 98 void init_parameter_dump( void );
97 99 void init_kcoefficients_dump( void );
98 100 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
99 101 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
100 102
101 103 #endif // TC_LOAD_DUMP_PARAMETERS_H
@@ -1,107 +1,107
1 1 cmake_minimum_required (VERSION 2.6)
2 2 project (fsw)
3 3
4 4 include(sparc-rtems)
5 5 include(cppcheck)
6 6
7 7 include_directories("../header"
8 8 "../header/lfr_common_headers"
9 9 "../header/processing"
10 10 "../LFR_basic-parameters"
11 11 "../src")
12 12
13 13 set(SOURCES wf_handler.c
14 14 tc_handler.c
15 15 fsw_misc.c
16 16 fsw_init.c
17 17 fsw_globals.c
18 18 fsw_spacewire.c
19 19 tc_load_dump_parameters.c
20 20 tm_lfr_tc_exe.c
21 21 tc_acceptance.c
22 22 processing/fsw_processing.c
23 23 processing/avf0_prc0.c
24 24 processing/avf1_prc1.c
25 25 processing/avf2_prc2.c
26 26 lfr_cpu_usage_report.c
27 27 ${LFR_BP_SRC}
28 28 ../header/wf_handler.h
29 29 ../header/tc_handler.h
30 30 ../header/grlib_regs.h
31 31 ../header/fsw_misc.h
32 32 ../header/fsw_init.h
33 33 ../header/fsw_spacewire.h
34 34 ../header/tc_load_dump_parameters.h
35 35 ../header/tm_lfr_tc_exe.h
36 36 ../header/tc_acceptance.h
37 37 ../header/processing/fsw_processing.h
38 38 ../header/processing/avf0_prc0.h
39 39 ../header/processing/avf1_prc1.h
40 40 ../header/processing/avf2_prc2.h
41 41 ../header/fsw_params_wf_handler.h
42 42 ../header/lfr_cpu_usage_report.h
43 43 ../header/lfr_common_headers/ccsds_types.h
44 44 ../header/lfr_common_headers/fsw_params.h
45 45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
46 46 ../header/lfr_common_headers/fsw_params_processing.h
47 47 ../header/lfr_common_headers/tm_byte_positions.h
48 48 ../LFR_basic-parameters/basic_parameters.h
49 49 ../LFR_basic-parameters/basic_parameters_params.h
50 50 ../header/GscMemoryLPP.hpp
51 51 )
52 52
53 53
54 54 option(FSW_verbose "Enable verbose LFR" OFF)
55 55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
56 56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
57 57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
58 58 option(FSW_stack_report "Enable LFR stack report" OFF)
59 59 option(FSW_vhdl_dev "?" OFF)
60 60 option(FSW_lpp_dpu_destid "Set to debug at LPP" ON)
61 61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
62 62 option(FSW_debug_tch "?" OFF)
63 63
64 64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
65 65 set(SW_VERSION_N2 "1" CACHE STRING "Choose N2 FSW Version." FORCE)
66 66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
67 set(SW_VERSION_N4 "5" CACHE STRING "Choose N4 FSW Version." FORCE)
67 set(SW_VERSION_N4 "7" CACHE STRING "Choose N4 FSW Version." FORCE)
68 68
69 69 if(FSW_verbose)
70 70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 71 endif()
72 72 if(FSW_boot_messages)
73 73 add_definitions(-DBOOT_MESSAGES)
74 74 endif()
75 75 if(FSW_debug_messages)
76 76 add_definitions(-DDEBUG_MESSAGES)
77 77 endif()
78 78 if(FSW_cpu_usage_report)
79 79 add_definitions(-DPRINT_TASK_STATISTICS)
80 80 endif()
81 81 if(FSW_stack_report)
82 82 add_definitions(-DPRINT_STACK_REPORT)
83 83 endif()
84 84 if(FSW_vhdl_dev)
85 85 add_definitions(-DVHDL_DEV)
86 86 endif()
87 87 if(FSW_lpp_dpu_destid)
88 88 add_definitions(-DLPP_DPU_DESTID)
89 89 endif()
90 90 if(FSW_debug_watchdog)
91 91 add_definitions(-DDEBUG_WATCHDOG)
92 92 endif()
93 93 if(FSW_debug_tch)
94 94 add_definitions(-DDEBUG_TCH)
95 95 endif()
96 96
97 97 add_definitions(-DMSB_FIRST_TCH)
98 98
99 99 add_definitions(-DSWVERSION=-1-0)
100 100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
101 101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
102 102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
103 103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
104 104
105 105 add_executable(fsw ${SOURCES})
106 106 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
107 107
@@ -1,988 +1,988
1 1 /** General usage functions and RTEMS tasks.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 */
7 7
8 8 #include "fsw_misc.h"
9 9
10 10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 12 {
13 13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 14 *
15 15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 18 * @param interrupt_level is the interrupt level that the timer drives.
19 19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 20 *
21 21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 22 *
23 23 */
24 24
25 25 rtems_status_code status;
26 26 rtems_isr_entry old_isr_handler;
27 27
28 28 old_isr_handler = NULL;
29 29
30 30 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
31 31
32 32 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
33 33 if (status!=RTEMS_SUCCESSFUL)
34 34 {
35 35 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
36 36 }
37 37
38 38 timer_set_clock_divider( timer, clock_divider);
39 39 }
40 40
41 41 void timer_start(unsigned char timer)
42 42 {
43 43 /** This function starts a GPTIMER timer.
44 44 *
45 45 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
46 46 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
47 47 *
48 48 */
49 49
50 50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
51 51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
52 52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
53 53 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
54 54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
55 55 }
56 56
57 57 void timer_stop(unsigned char timer)
58 58 {
59 59 /** This function stops a GPTIMER timer.
60 60 *
61 61 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
62 62 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
63 63 *
64 64 */
65 65
66 66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
67 67 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
68 68 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
69 69 }
70 70
71 71 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
72 72 {
73 73 /** This function sets the clock divider of a GPTIMER timer.
74 74 *
75 75 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
76 76 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
77 77 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
78 78 *
79 79 */
80 80
81 81 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
82 82 }
83 83
84 84 // WATCHDOG
85 85
86 86 rtems_isr watchdog_isr( rtems_vector_number vector )
87 87 {
88 88 rtems_status_code status_code;
89 89
90 90 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
91 91
92 92 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
93 93
94 94 exit(0);
95 95 }
96 96
97 97 void watchdog_configure(void)
98 98 {
99 99 /** This function configure the watchdog.
100 100 *
101 101 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
102 102 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
103 103 *
104 104 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
105 105 *
106 106 */
107 107
108 108 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
109 109
110 110 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
111 111
112 112 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
113 113 }
114 114
115 115 void watchdog_stop(void)
116 116 {
117 117 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
118 118 timer_stop( TIMER_WATCHDOG );
119 119 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
120 120 }
121 121
122 122 void watchdog_reload(void)
123 123 {
124 124 /** This function reloads the watchdog timer counter with the timer reload value.
125 125 *
126 126 * @param void
127 127 *
128 128 * @return void
129 129 *
130 130 */
131 131
132 132 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
133 133 }
134 134
135 135 void watchdog_start(void)
136 136 {
137 137 /** This function starts the watchdog timer.
138 138 *
139 139 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
140 140 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
141 141 *
142 142 */
143 143
144 144 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
145 145
146 146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
147 147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
148 148 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
149 149 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
150 150
151 151 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
152 152
153 153 }
154 154
155 155 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
156 156 {
157 157 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
158 158
159 159 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
160 160
161 161 return 0;
162 162 }
163 163
164 164 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
165 165 {
166 166 /** This function sets the scaler reload register of the apbuart module
167 167 *
168 168 * @param regs is the address of the apbuart registers in memory
169 169 * @param value is the value that will be stored in the scaler register
170 170 *
171 171 * The value shall be set by the software to get data on the serial interface.
172 172 *
173 173 */
174 174
175 175 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
176 176
177 177 apbuart_regs->scaler = value;
178 178
179 179 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
180 180 }
181 181
182 182 //************
183 183 // RTEMS TASKS
184 184
185 185 rtems_task load_task(rtems_task_argument argument)
186 186 {
187 187 BOOT_PRINTF("in LOAD *** \n")
188 188
189 189 rtems_status_code status;
190 190 unsigned int i;
191 191 unsigned int j;
192 192 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
193 193 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
194 194
195 195 watchdog_period_id = RTEMS_ID_NONE;
196 196
197 197 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
198 198
199 199 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
200 200 if( status != RTEMS_SUCCESSFUL ) {
201 201 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
202 202 }
203 203
204 204 i = 0;
205 205 j = 0;
206 206
207 207 watchdog_configure();
208 208
209 209 watchdog_start();
210 210
211 211 set_sy_lfr_watchdog_enabled( true );
212 212
213 213 while(1){
214 214 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
215 215 watchdog_reload();
216 216 i = i + 1;
217 217 if ( i == WATCHDOG_LOOP_PRINTF )
218 218 {
219 219 i = 0;
220 220 j = j + 1;
221 221 PRINTF1("%d\n", j)
222 222 }
223 223 #ifdef DEBUG_WATCHDOG
224 224 if (j == WATCHDOG_LOOP_DEBUG )
225 225 {
226 226 status = rtems_task_delete(RTEMS_SELF);
227 227 }
228 228 #endif
229 229 }
230 230 }
231 231
232 232 rtems_task hous_task(rtems_task_argument argument)
233 233 {
234 234 rtems_status_code status;
235 235 rtems_status_code spare_status;
236 236 rtems_id queue_id;
237 237 rtems_rate_monotonic_period_status period_status;
238 238 bool isSynchronized;
239 239
240 240 queue_id = RTEMS_ID_NONE;
241 241 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
242 242 isSynchronized = false;
243 243
244 244 status = get_message_queue_id_send( &queue_id );
245 245 if (status != RTEMS_SUCCESSFUL)
246 246 {
247 247 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
248 248 }
249 249
250 250 BOOT_PRINTF("in HOUS ***\n");
251 251
252 252 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
253 253 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
254 254 if( status != RTEMS_SUCCESSFUL ) {
255 255 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
256 256 }
257 257 }
258 258
259 259 status = rtems_rate_monotonic_cancel(HK_id);
260 260 if( status != RTEMS_SUCCESSFUL ) {
261 261 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
262 262 }
263 263 else {
264 264 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
265 265 }
266 266
267 267 // startup phase
268 268 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
269 269 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
270 270 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
271 271 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
272 272 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
273 273 {
274 274 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
275 275 {
276 276 isSynchronized = true;
277 277 }
278 278 else
279 279 {
280 280 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
281 281
282 282 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
283 283 }
284 284 }
285 285 status = rtems_rate_monotonic_cancel(HK_id);
286 286 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
287 287
288 288 set_hk_lfr_reset_cause( POWER_ON );
289 289
290 290 while(1){ // launch the rate monotonic task
291 291 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
292 292 if ( status != RTEMS_SUCCESSFUL ) {
293 293 PRINTF1( "in HOUS *** ERR period: %d\n", status);
294 294 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
295 295 }
296 296 else {
297 297 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
298 298 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
299 299 increment_seq_counter( &sequenceCounterHK );
300 300
301 301 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
302 302 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
303 303 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
304 304 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
305 305 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
306 306 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
307 307
308 308 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
309 309
310 310 spacewire_read_statistics();
311 311
312 312 update_hk_with_grspw_stats();
313 313
314 314 set_hk_lfr_time_not_synchro();
315 315
316 316 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
317 317 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
318 318 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
319 319 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
320 320 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
321 321
322 322 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
323 323 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
324 324 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
325 325 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
326 326 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
327 327
328 328 hk_lfr_le_me_he_update();
329 329
330 330 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
331 331
332 332 // SEND PACKET
333 333 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
334 334 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
335 335 if (status != RTEMS_SUCCESSFUL) {
336 336 PRINTF1("in HOUS *** ERR send: %d\n", status)
337 337 }
338 338 }
339 339 }
340 340
341 341 PRINTF("in HOUS *** deleting task\n")
342 342
343 343 status = rtems_task_delete( RTEMS_SELF ); // should not return
344 344
345 345 return;
346 346 }
347 347
348 348 rtems_task avgv_task(rtems_task_argument argument)
349 349 {
350 350 #define MOVING_AVERAGE 16
351 351 rtems_status_code status;
352 352 static unsigned int v[MOVING_AVERAGE] = {0};
353 353 static unsigned int e1[MOVING_AVERAGE] = {0};
354 354 static unsigned int e2[MOVING_AVERAGE] = {0};
355 355 float average_v;
356 356 float average_e1;
357 357 float average_e2;
358 358 unsigned char k;
359 359 unsigned char indexOfOldValue;
360 360
361 361 BOOT_PRINTF("in AVGV ***\n");
362 362
363 363 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
364 364 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
365 365 if( status != RTEMS_SUCCESSFUL ) {
366 366 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
367 367 }
368 368 }
369 369
370 370 status = rtems_rate_monotonic_cancel(AVGV_id);
371 371 if( status != RTEMS_SUCCESSFUL ) {
372 372 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
373 373 }
374 374 else {
375 375 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
376 376 }
377 377
378 378 // initialize values
379 379 indexOfOldValue = MOVING_AVERAGE - 1;
380 380 average_v = 0.;
381 381 average_e1 = 0.;
382 382 average_e2 = 0.;
383 383
384 384 k = 0;
385 385
386 386 while(1){ // launch the rate monotonic task
387 387 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
388 388 if ( status != RTEMS_SUCCESSFUL ) {
389 389 PRINTF1( "in AVGV *** ERR period: %d\n", status);
390 390 }
391 391 else {
392 392 // store new value in buffer
393 393 v[k] = waveform_picker_regs->v;
394 394 e1[k] = waveform_picker_regs->e1;
395 395 e2[k] = waveform_picker_regs->e2;
396 396 if (k == (MOVING_AVERAGE - 1))
397 397 {
398 398 indexOfOldValue = 0;
399 399 }
400 400 else
401 401 {
402 402 indexOfOldValue = k + 1;
403 403 }
404 404 average_v = average_v + v[k] - v[indexOfOldValue];
405 405 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
406 406 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
407 407 }
408 408 if (k == (MOVING_AVERAGE-1))
409 409 {
410 410 k = 0;
411 printf("tick\n");
411 PRINTF("tick\n");
412 412 }
413 413 else
414 414 {
415 415 k++;
416 416 }
417 417 }
418 418
419 419 PRINTF("in AVGV *** deleting task\n")
420 420
421 421 status = rtems_task_delete( RTEMS_SELF ); // should not return
422 422
423 423 return;
424 424 }
425 425
426 426 rtems_task dumb_task( rtems_task_argument unused )
427 427 {
428 428 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
429 429 *
430 430 * @param unused is the starting argument of the RTEMS task
431 431 *
432 432 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
433 433 *
434 434 */
435 435
436 436 unsigned int i;
437 437 unsigned int intEventOut;
438 438 unsigned int coarse_time = 0;
439 439 unsigned int fine_time = 0;
440 440 rtems_event_set event_out;
441 441
442 442 event_out = EVENT_SETS_NONE_PENDING;
443 443
444 444 BOOT_PRINTF("in DUMB *** \n")
445 445
446 446 while(1){
447 447 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
448 448 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
449 449 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
450 450 | RTEMS_EVENT_14,
451 451 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
452 452 intEventOut = (unsigned int) event_out;
453 453 for ( i=0; i<NB_RTEMS_EVENTS; i++)
454 454 {
455 455 if ( ((intEventOut >> i) & 1) != 0)
456 456 {
457 457 coarse_time = time_management_regs->coarse_time;
458 458 fine_time = time_management_regs->fine_time;
459 459 if (i==EVENT_12)
460 460 {
461 461 PRINTF1("%s\n", DUMB_MESSAGE_12)
462 462 }
463 463 if (i==EVENT_13)
464 464 {
465 465 PRINTF1("%s\n", DUMB_MESSAGE_13)
466 466 }
467 467 if (i==EVENT_14)
468 468 {
469 469 PRINTF1("%s\n", DUMB_MESSAGE_1)
470 470 }
471 471 }
472 472 }
473 473 }
474 474 }
475 475
476 476 //*****************************
477 477 // init housekeeping parameters
478 478
479 479 void init_housekeeping_parameters( void )
480 480 {
481 481 /** This function initialize the housekeeping_packet global variable with default values.
482 482 *
483 483 */
484 484
485 485 unsigned int i = 0;
486 486 unsigned char *parameters;
487 487 unsigned char sizeOfHK;
488 488
489 489 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
490 490
491 491 parameters = (unsigned char*) &housekeeping_packet;
492 492
493 493 for(i = 0; i< sizeOfHK; i++)
494 494 {
495 495 parameters[i] = INIT_CHAR;
496 496 }
497 497
498 498 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
499 499 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
500 500 housekeeping_packet.reserved = DEFAULT_RESERVED;
501 501 housekeeping_packet.userApplication = CCSDS_USER_APP;
502 502 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
503 503 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
504 504 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
505 505 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
506 506 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
507 507 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
508 508 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
509 509 housekeeping_packet.serviceType = TM_TYPE_HK;
510 510 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
511 511 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
512 512 housekeeping_packet.sid = SID_HK;
513 513
514 514 // init status word
515 515 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
516 516 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
517 517 // init software version
518 518 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
519 519 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
520 520 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
521 521 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
522 522 // init fpga version
523 523 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
524 524 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
525 525 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
526 526 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
527 527
528 528 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
529 529 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
530 530 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
531 531 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
532 532 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
533 533 }
534 534
535 535 void increment_seq_counter( unsigned short *packetSequenceControl )
536 536 {
537 537 /** This function increment the sequence counter passes in argument.
538 538 *
539 539 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
540 540 *
541 541 */
542 542
543 543 unsigned short segmentation_grouping_flag;
544 544 unsigned short sequence_cnt;
545 545
546 546 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
547 547 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
548 548
549 549 if ( sequence_cnt < SEQ_CNT_MAX)
550 550 {
551 551 sequence_cnt = sequence_cnt + 1;
552 552 }
553 553 else
554 554 {
555 555 sequence_cnt = 0;
556 556 }
557 557
558 558 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
559 559 }
560 560
561 561 void getTime( unsigned char *time)
562 562 {
563 563 /** This function write the current local time in the time buffer passed in argument.
564 564 *
565 565 */
566 566
567 567 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
568 568 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
569 569 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
570 570 time[3] = (unsigned char) (time_management_regs->coarse_time);
571 571 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
572 572 time[5] = (unsigned char) (time_management_regs->fine_time);
573 573 }
574 574
575 575 unsigned long long int getTimeAsUnsignedLongLongInt( )
576 576 {
577 577 /** This function write the current local time in the time buffer passed in argument.
578 578 *
579 579 */
580 580 unsigned long long int time;
581 581
582 582 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
583 583 + time_management_regs->fine_time;
584 584
585 585 return time;
586 586 }
587 587
588 588 void send_dumb_hk( void )
589 589 {
590 590 Packet_TM_LFR_HK_t dummy_hk_packet;
591 591 unsigned char *parameters;
592 592 unsigned int i;
593 593 rtems_id queue_id;
594 594
595 595 queue_id = RTEMS_ID_NONE;
596 596
597 597 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
598 598 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
599 599 dummy_hk_packet.reserved = DEFAULT_RESERVED;
600 600 dummy_hk_packet.userApplication = CCSDS_USER_APP;
601 601 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
602 602 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
603 603 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
604 604 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
605 605 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
606 606 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
607 607 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
608 608 dummy_hk_packet.serviceType = TM_TYPE_HK;
609 609 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
610 610 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
611 611 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
612 612 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
613 613 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
614 614 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
615 615 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
616 616 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
617 617 dummy_hk_packet.sid = SID_HK;
618 618
619 619 // init status word
620 620 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
621 621 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
622 622 // init software version
623 623 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
624 624 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
625 625 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
626 626 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
627 627 // init fpga version
628 628 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
629 629 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
630 630 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
631 631 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
632 632
633 633 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
634 634
635 635 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
636 636 {
637 637 parameters[i] = INT8_ALL_F;
638 638 }
639 639
640 640 get_message_queue_id_send( &queue_id );
641 641
642 642 rtems_message_queue_send( queue_id, &dummy_hk_packet,
643 643 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
644 644 }
645 645
646 646 void get_temperatures( unsigned char *temperatures )
647 647 {
648 648 unsigned char* temp_scm_ptr;
649 649 unsigned char* temp_pcb_ptr;
650 650 unsigned char* temp_fpga_ptr;
651 651
652 652 // SEL1 SEL0
653 653 // 0 0 => PCB
654 654 // 0 1 => FPGA
655 655 // 1 0 => SCM
656 656
657 657 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
658 658 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
659 659 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
660 660
661 661 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
662 662 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
663 663 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
664 664 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
665 665 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
666 666 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
667 667 }
668 668
669 669 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
670 670 {
671 671 unsigned char* v_ptr;
672 672 unsigned char* e1_ptr;
673 673 unsigned char* e2_ptr;
674 674
675 675 v_ptr = (unsigned char *) &waveform_picker_regs->v;
676 676 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
677 677 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
678 678
679 679 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
680 680 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
681 681 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
682 682 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
683 683 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
684 684 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
685 685 }
686 686
687 687 void get_cpu_load( unsigned char *resource_statistics )
688 688 {
689 689 unsigned char cpu_load;
690 690
691 691 cpu_load = lfr_rtems_cpu_usage_report();
692 692
693 693 // HK_LFR_CPU_LOAD
694 694 resource_statistics[0] = cpu_load;
695 695
696 696 // HK_LFR_CPU_LOAD_MAX
697 697 if (cpu_load > resource_statistics[1])
698 698 {
699 699 resource_statistics[1] = cpu_load;
700 700 }
701 701
702 702 // CPU_LOAD_AVE
703 703 resource_statistics[BYTE_2] = 0;
704 704
705 705 #ifndef PRINT_TASK_STATISTICS
706 706 rtems_cpu_usage_reset();
707 707 #endif
708 708
709 709 }
710 710
711 711 void set_hk_lfr_sc_potential_flag( bool state )
712 712 {
713 713 if (state == true)
714 714 {
715 715 housekeeping_packet.lfr_status_word[1] =
716 716 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
717 717 }
718 718 else
719 719 {
720 720 housekeeping_packet.lfr_status_word[1] =
721 721 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
722 722 }
723 723 }
724 724
725 725 void set_sy_lfr_pas_filter_enabled( bool state )
726 726 {
727 727 if (state == true)
728 728 {
729 729 housekeeping_packet.lfr_status_word[1] =
730 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
730 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
731 731 }
732 732 else
733 733 {
734 734 housekeeping_packet.lfr_status_word[1] =
735 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
735 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
736 736 }
737 737 }
738 738
739 739 void set_sy_lfr_watchdog_enabled( bool state )
740 740 {
741 741 if (state == true)
742 742 {
743 743 housekeeping_packet.lfr_status_word[1] =
744 744 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
745 745 }
746 746 else
747 747 {
748 748 housekeeping_packet.lfr_status_word[1] =
749 749 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
750 750 }
751 751 }
752 752
753 753 void set_hk_lfr_calib_enable( bool state )
754 754 {
755 755 if (state == true)
756 756 {
757 757 housekeeping_packet.lfr_status_word[1] =
758 758 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
759 759 }
760 760 else
761 761 {
762 762 housekeeping_packet.lfr_status_word[1] =
763 763 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
764 764 }
765 765 }
766 766
767 767 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
768 768 {
769 769 housekeeping_packet.lfr_status_word[1] =
770 770 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
771 771
772 772 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
773 773 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
774 774
775 775 }
776 776
777 777 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
778 778 {
779 779 int delta;
780 780
781 781 delta = 0;
782 782
783 783 if (newValue >= oldValue)
784 784 {
785 785 delta = newValue - oldValue;
786 786 }
787 787 else
788 788 {
789 delta = (255 - oldValue) + newValue;
789 delta = (CONST_256 - oldValue) + newValue;
790 790 }
791 791
792 792 *counter = *counter + delta;
793 793 }
794 794
795 795 void hk_lfr_le_update( void )
796 796 {
797 797 static hk_lfr_le_t old_hk_lfr_le = {0};
798 798 hk_lfr_le_t new_hk_lfr_le;
799 799 unsigned int counter;
800 800
801 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
801 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
802 802
803 803 // DPU
804 804 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
805 805 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
806 806 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
807 807 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
808 808 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
809 809 // TIMECODE
810 810 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
811 811 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
812 812 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
813 813 // TIME
814 814 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
815 815 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
816 816 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
817 817 //AHB
818 818 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
819 819 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
820 820 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
821 821
822 822 // update the le counter
823 823 // DPU
824 824 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
825 825 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
826 826 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
827 827 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
828 828 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
829 829 // TIMECODE
830 830 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
831 831 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
832 832 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
833 833 // TIME
834 834 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
835 835 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
836 836 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
837 837 // AHB
838 838 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
839 839
840 840 // DPU
841 841 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
842 842 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
843 843 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
844 844 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
845 845 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
846 846 // TIMECODE
847 847 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
848 848 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
849 849 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
850 850 // TIME
851 851 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
852 852 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
853 853 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
854 854 //AHB
855 855 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
856 856 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
857 857 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
858 858
859 859 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
860 860 // LE
861 861 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
862 862 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
863 863 }
864 864
865 865 void hk_lfr_me_update( void )
866 866 {
867 867 static hk_lfr_me_t old_hk_lfr_me = {0};
868 868 hk_lfr_me_t new_hk_lfr_me;
869 869 unsigned int counter;
870 870
871 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
871 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
872 872
873 873 // get the current values
874 874 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
875 875 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
876 876 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
877 877 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
878 878
879 879 // update the me counter
880 880 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
881 881 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
882 882 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
883 883 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
884 884
885 885 // store the counters for the next time
886 886 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
887 887 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
888 888 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
889 889 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
890 890
891 891 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
892 892 // ME
893 893 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
894 894 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
895 895 }
896 896
897 897 void hk_lfr_le_me_he_update()
898 898 {
899 899
900 900 unsigned int hk_lfr_he_cnt;
901 901
902 902 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
903 903
904 904 //update the low severity error counter
905 905 hk_lfr_le_update( );
906 906
907 907 //update the medium severity error counter
908 908 hk_lfr_me_update();
909 909
910 910 //update the high severity error counter
911 911 hk_lfr_he_cnt = 0;
912 912
913 913 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
914 914 // HE
915 915 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
916 916 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
917 917
918 918 }
919 919
920 920 void set_hk_lfr_time_not_synchro()
921 921 {
922 922 static unsigned char synchroLost = 1;
923 923 int synchronizationBit;
924 924
925 925 // get the synchronization bit
926 926 synchronizationBit =
927 927 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
928 928
929 929 switch (synchronizationBit)
930 930 {
931 931 case 0:
932 932 if (synchroLost == 1)
933 933 {
934 934 synchroLost = 0;
935 935 }
936 936 break;
937 937 case 1:
938 938 if (synchroLost == 0 )
939 939 {
940 940 synchroLost = 1;
941 941 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
942 942 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
943 943 }
944 944 break;
945 945 default:
946 946 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
947 947 break;
948 948 }
949 949
950 950 }
951 951
952 952 void set_hk_lfr_ahb_correctable() // CRITICITY L
953 953 {
954 954 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
955 955 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
956 956 * detected errors in the cache, in the integer unit and in the floating point unit.
957 957 *
958 958 * @param void
959 959 *
960 960 * @return void
961 961 *
962 962 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
963 963 *
964 964 */
965 965
966 966 unsigned int ahb_correctable;
967 967 unsigned int instructionErrorCounter;
968 968 unsigned int dataErrorCounter;
969 969 unsigned int fprfErrorCounter;
970 970 unsigned int iurfErrorCounter;
971 971
972 972 instructionErrorCounter = 0;
973 973 dataErrorCounter = 0;
974 974 fprfErrorCounter = 0;
975 975 iurfErrorCounter = 0;
976 976
977 977 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
978 978 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
979 979
980 980 ahb_correctable = instructionErrorCounter
981 981 + dataErrorCounter
982 982 + fprfErrorCounter
983 983 + iurfErrorCounter
984 984 + housekeeping_packet.hk_lfr_ahb_correctable;
985 985
986 986 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
987 987
988 988 }
@@ -1,1633 +1,1633
1 1 /** Functions related to the SpaceWire interface.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle SpaceWire transmissions:
7 7 * - configuration of the SpaceWire link
8 8 * - SpaceWire related interruption requests processing
9 9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 10 * - reception of TeleCommands by a dedicated RTEMS task
11 11 *
12 12 */
13 13
14 14 #include "fsw_spacewire.h"
15 15
16 16 rtems_name semq_name = 0;
17 17 rtems_id semq_id = RTEMS_ID_NONE;
18 18
19 19 //*****************
20 20 // waveform headers
21 21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
22 22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
23 23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
24 24
25 25 unsigned char previousTimecodeCtr = 0;
26 26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27 27
28 28 //***********
29 29 // RTEMS TASK
30 30 rtems_task spiq_task(rtems_task_argument unused)
31 31 {
32 32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 33 *
34 34 * @param unused is the starting argument of the RTEMS task
35 35 *
36 36 */
37 37
38 38 rtems_event_set event_out;
39 39 rtems_status_code status;
40 40 int linkStatus;
41 41
42 42 event_out = EVENT_SETS_NONE_PENDING;
43 43 linkStatus = 0;
44 44
45 45 BOOT_PRINTF("in SPIQ *** \n")
46 46
47 47 while(true){
48 48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
49 49 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
50 50
51 51 // [0] SUSPEND RECV AND SEND TASKS
52 52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
53 53 if ( status != RTEMS_SUCCESSFUL ) {
54 54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
55 55 }
56 56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
57 57 if ( status != RTEMS_SUCCESSFUL ) {
58 58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
59 59 }
60 60
61 61 // [1] CHECK THE LINK
62 62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
63 63 if ( linkStatus != SPW_LINK_OK) {
64 64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
65 65 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
66 66 }
67 67
68 68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
69 69 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
70 70 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
71 71 {
72 72 spacewire_read_statistics();
73 73 status = spacewire_several_connect_attemps( );
74 74 }
75 75 else // [2.b] in run state, start the link
76 76 {
77 77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
78 78 if ( status != RTEMS_SUCCESSFUL)
79 79 {
80 80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
81 81 }
82 82 }
83 83
84 84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
85 85 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
86 86 {
87 87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
88 88 if ( status != RTEMS_SUCCESSFUL ) {
89 89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
90 90 }
91 91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
92 92 if ( status != RTEMS_SUCCESSFUL ) {
93 93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
94 94 }
95 95 }
96 96 else // [3.b] the link is not in run state, go in STANDBY mode
97 97 {
98 98 status = enter_mode_standby();
99 99 if ( status != RTEMS_SUCCESSFUL )
100 100 {
101 101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
102 102 }
103 103 {
104 104 updateLFRCurrentMode( LFR_MODE_STANDBY );
105 105 }
106 106 // wake the LINK task up to wait for the link recovery
107 107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
108 108 status = rtems_task_suspend( RTEMS_SELF );
109 109 }
110 110 }
111 111 }
112 112
113 113 rtems_task recv_task( rtems_task_argument unused )
114 114 {
115 115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
116 116 *
117 117 * @param unused is the starting argument of the RTEMS task
118 118 *
119 119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
120 120 * 1. It reads the incoming data.
121 121 * 2. Launches the acceptance procedure.
122 122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
123 123 *
124 124 */
125 125
126 126 int len;
127 ccsdsTelecommandPacket_t currentTC;
127 ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC;
128 128 unsigned char computed_CRC[ BYTES_PER_CRC ];
129 129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
130 130 unsigned char destinationID;
131 131 unsigned int estimatedPacketLength;
132 132 unsigned int parserCode;
133 133 rtems_status_code status;
134 134 rtems_id queue_recv_id;
135 135 rtems_id queue_send_id;
136 136
137 137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
138 138 destinationID = 0;
139 139 queue_recv_id = RTEMS_ID_NONE;
140 140 queue_send_id = RTEMS_ID_NONE;
141 141
142 142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
143 143
144 144 status = get_message_queue_id_recv( &queue_recv_id );
145 145 if (status != RTEMS_SUCCESSFUL)
146 146 {
147 147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
148 148 }
149 149
150 150 status = get_message_queue_id_send( &queue_send_id );
151 151 if (status != RTEMS_SUCCESSFUL)
152 152 {
153 153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
154 154 }
155 155
156 156 BOOT_PRINTF("in RECV *** \n")
157 157
158 158 while(1)
159 159 {
160 160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
161 161 if (len == -1){ // error during the read call
162 162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
163 163 }
164 164 else {
165 165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
166 166 PRINTF("in RECV *** packet lenght too short\n")
167 167 }
168 168 else {
169 169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
170 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
170 PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
171 171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
172 172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
173 173 // CHECK THE TC
174 174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
175 175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
176 176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
177 177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
178 178 || (parserCode == WRONG_SRC_ID) )
179 179 { // send TM_LFR_TC_EXE_CORRUPTED
180 180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
181 181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
182 182 &&
183 183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
184 184 )
185 185 {
186 186 if ( parserCode == WRONG_SRC_ID )
187 187 {
188 188 destinationID = SID_TC_GROUND;
189 189 }
190 190 else
191 191 {
192 192 destinationID = currentTC.sourceID;
193 193 }
194 194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
195 195 computed_CRC, currentTC_LEN_RCV,
196 196 destinationID );
197 197 }
198 198 }
199 199 else
200 200 { // send valid TC to the action launcher
201 201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
202 202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
203 203 }
204 204 }
205 205 }
206 206
207 207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
208 208
209 209 }
210 210 }
211 211
212 212 rtems_task send_task( rtems_task_argument argument)
213 213 {
214 214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
215 215 *
216 216 * @param unused is the starting argument of the RTEMS task
217 217 *
218 218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
219 219 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
220 220 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
221 221 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
222 222 * data it contains.
223 223 *
224 224 */
225 225
226 226 rtems_status_code status; // RTEMS status code
227 227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
228 228 ring_node *incomingRingNodePtr;
229 229 int ring_node_address;
230 230 char *charPtr;
231 231 spw_ioctl_pkt_send *spw_ioctl_send;
232 232 size_t size; // size of the incoming TC packet
233 233 rtems_id queue_send_id;
234 234 unsigned int sid;
235 235 unsigned char sidAsUnsignedChar;
236 236 unsigned char type;
237 237
238 238 incomingRingNodePtr = NULL;
239 239 ring_node_address = 0;
240 240 charPtr = (char *) &ring_node_address;
241 241 size = 0;
242 242 queue_send_id = RTEMS_ID_NONE;
243 243 sid = 0;
244 244 sidAsUnsignedChar = 0;
245 245
246 246 init_header_cwf( &headerCWF );
247 247 init_header_swf( &headerSWF );
248 248 init_header_asm( &headerASM );
249 249
250 250 status = get_message_queue_id_send( &queue_send_id );
251 251 if (status != RTEMS_SUCCESSFUL)
252 252 {
253 253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
254 254 }
255 255
256 256 BOOT_PRINTF("in SEND *** \n")
257 257
258 258 while(1)
259 259 {
260 260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
261 261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
262 262
263 263 if (status!=RTEMS_SUCCESSFUL)
264 264 {
265 265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
266 266 }
267 267 else
268 268 {
269 269 if ( size == sizeof(ring_node*) )
270 270 {
271 271 charPtr[0] = incomingData[0];
272 272 charPtr[1] = incomingData[1];
273 273 charPtr[BYTE_2] = incomingData[BYTE_2];
274 274 charPtr[BYTE_3] = incomingData[BYTE_3];
275 275 incomingRingNodePtr = (ring_node*) ring_node_address;
276 276 sid = incomingRingNodePtr->sid;
277 277 if ( (sid==SID_NORM_CWF_LONG_F3)
278 278 || (sid==SID_BURST_CWF_F2 )
279 279 || (sid==SID_SBM1_CWF_F1 )
280 280 || (sid==SID_SBM2_CWF_F2 ))
281 281 {
282 282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
283 283 }
284 284 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
285 285 {
286 286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
287 287 }
288 288 else if ( (sid==SID_NORM_CWF_F3) )
289 289 {
290 290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
291 291 }
292 292 else if (sid==SID_NORM_ASM_F0)
293 293 {
294 294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
295 295 }
296 296 else if (sid==SID_NORM_ASM_F1)
297 297 {
298 298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
299 299 }
300 300 else if (sid==SID_NORM_ASM_F2)
301 301 {
302 302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
303 303 }
304 304 else if ( sid==TM_CODE_K_DUMP )
305 305 {
306 306 spw_send_k_dump( incomingRingNodePtr );
307 307 }
308 308 else
309 309 {
310 310 PRINTF1("unexpected sid = %d\n", sid);
311 311 }
312 312 }
313 313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
314 314 {
315 315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
316 316 sid = sidAsUnsignedChar;
317 317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
318 318 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
319 319 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
320 320 {
321 321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
322 322 }
323 323
324 324 status = write( fdSPW, incomingData, size );
325 325 if (status == -1){
326 326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
327 327 }
328 328 }
329 329 else // the incoming message is a spw_ioctl_pkt_send structure
330 330 {
331 331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
332 332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
333 333 if (status == -1){
334 334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
335 335 }
336 336 }
337 337 }
338 338
339 339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
340 340
341 341 }
342 342 }
343 343
344 344 rtems_task link_task( rtems_task_argument argument )
345 345 {
346 346 rtems_event_set event_out;
347 347 rtems_status_code status;
348 348 int linkStatus;
349 349
350 350 event_out = EVENT_SETS_NONE_PENDING;
351 351 linkStatus = 0;
352 352
353 353 BOOT_PRINTF("in LINK ***\n")
354 354
355 355 while(1)
356 356 {
357 357 // wait for an RTEMS_EVENT
358 358 rtems_event_receive( RTEMS_EVENT_0,
359 359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
360 360 PRINTF("in LINK *** wait for the link\n")
361 361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
362 362 while( linkStatus != SPW_LINK_OK) // wait for the link
363 363 {
364 364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
365 365 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
366 366 watchdog_reload();
367 367 }
368 368
369 369 spacewire_read_statistics();
370 370 status = spacewire_stop_and_start_link( fdSPW );
371 371
372 372 if (status != RTEMS_SUCCESSFUL)
373 373 {
374 374 PRINTF1("in LINK *** ERR link not started %d\n", status)
375 375 }
376 376 else
377 377 {
378 378 PRINTF("in LINK *** OK link started\n")
379 379 }
380 380
381 381 // restart the SPIQ task
382 382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
383 383 if ( status != RTEMS_SUCCESSFUL ) {
384 384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
385 385 }
386 386
387 387 // restart RECV and SEND
388 388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
389 389 if ( status != RTEMS_SUCCESSFUL ) {
390 390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
391 391 }
392 392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
393 393 if ( status != RTEMS_SUCCESSFUL ) {
394 394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
395 395 }
396 396 }
397 397 }
398 398
399 399 //****************
400 400 // OTHER FUNCTIONS
401 401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
402 402 {
403 403 /** This function opens the SpaceWire link.
404 404 *
405 405 * @return a valid file descriptor in case of success, -1 in case of a failure
406 406 *
407 407 */
408 408 rtems_status_code status;
409 409
410 410 status = RTEMS_SUCCESSFUL;
411 411
412 412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
413 413 if ( fdSPW < 0 ) {
414 414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
415 415 }
416 416 else
417 417 {
418 418 status = RTEMS_SUCCESSFUL;
419 419 }
420 420
421 421 return status;
422 422 }
423 423
424 424 int spacewire_start_link( int fd )
425 425 {
426 426 rtems_status_code status;
427 427
428 428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
429 429 // -1 default hardcoded driver timeout
430 430
431 431 return status;
432 432 }
433 433
434 434 int spacewire_stop_and_start_link( int fd )
435 435 {
436 436 rtems_status_code status;
437 437
438 438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
439 439 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
440 440 // -1 default hardcoded driver timeout
441 441
442 442 return status;
443 443 }
444 444
445 445 int spacewire_configure_link( int fd )
446 446 {
447 447 /** This function configures the SpaceWire link.
448 448 *
449 449 * @return GR-RTEMS-DRIVER directive status codes:
450 450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
451 451 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
452 452 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
453 453 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
454 454 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
455 455 * - 5 EIO - Error when writing to grswp hardware registers.
456 456 * - 2 ENOENT - No such file or directory
457 457 */
458 458
459 459 rtems_status_code status;
460 460
461 461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
462 462 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
463 463 spw_ioctl_packetsize packetsize;
464 464
465 465 packetsize.rxsize = SPW_RXSIZE;
466 466 packetsize.txdsize = SPW_TXDSIZE;
467 467 packetsize.txhsize = SPW_TXHSIZE;
468 468
469 469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
470 470 if (status!=RTEMS_SUCCESSFUL) {
471 471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
472 472 }
473 473 //
474 474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
475 475 if (status!=RTEMS_SUCCESSFUL) {
476 476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
477 477 }
478 478 //
479 479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
480 480 if (status!=RTEMS_SUCCESSFUL) {
481 481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
482 482 }
483 483 //
484 484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
485 485 if (status!=RTEMS_SUCCESSFUL) {
486 486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
487 487 }
488 488 //
489 489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
490 490 if (status!=RTEMS_SUCCESSFUL) {
491 491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
492 492 }
493 493 //
494 494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
495 495 if (status!=RTEMS_SUCCESSFUL) {
496 496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
497 497 }
498 498 //
499 499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
500 500 if (status!=RTEMS_SUCCESSFUL) {
501 501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
502 502 }
503 503 //
504 504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
505 505 if (status!=RTEMS_SUCCESSFUL) {
506 506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
507 507 }
508 508
509 509 return status;
510 510 }
511 511
512 512 int spacewire_several_connect_attemps( void )
513 513 {
514 514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
515 515 *
516 516 * @return RTEMS directive status code:
517 517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
518 518 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
519 519 *
520 520 */
521 521
522 522 rtems_status_code status_spw;
523 523 rtems_status_code status;
524 524 int i;
525 525
526 526 status_spw = RTEMS_SUCCESSFUL;
527 527
528 528 i = 0;
529 529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
530 530 {
531 531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
532 532
533 533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
534 534
535 535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
536 536
537 537 status_spw = spacewire_stop_and_start_link( fdSPW );
538 538
539 539 if ( status_spw != RTEMS_SUCCESSFUL )
540 540 {
541 541 i = i + 1;
542 542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
543 543 }
544 544 else
545 545 {
546 546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
547 547 }
548 548 }
549 549
550 550 return status_spw;
551 551 }
552 552
553 553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
554 554 {
555 555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
556 556 *
557 557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
558 558 * @param regAddr is the address of the GRSPW control register.
559 559 *
560 560 * NP is the bit 20 of the GRSPW control register.
561 561 *
562 562 */
563 563
564 564 unsigned int *spwptr = (unsigned int*) regAddr;
565 565
566 566 if (val == 1) {
567 567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
568 568 }
569 569 if (val== 0) {
570 570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
571 571 }
572 572 }
573 573
574 574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
575 575 {
576 576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
577 577 *
578 578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
579 579 * @param regAddr is the address of the GRSPW control register.
580 580 *
581 581 * RE is the bit 16 of the GRSPW control register.
582 582 *
583 583 */
584 584
585 585 unsigned int *spwptr = (unsigned int*) regAddr;
586 586
587 587 if (val == 1)
588 588 {
589 589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
590 590 }
591 591 if (val== 0)
592 592 {
593 593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
594 594 }
595 595 }
596 596
597 597 void spacewire_read_statistics( void )
598 598 {
599 599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
600 600 *
601 601 * @param void
602 602 *
603 603 * @return void
604 604 *
605 605 * Once they are read, the counters are stored in a global variable used during the building of the
606 606 * HK packets.
607 607 *
608 608 */
609 609
610 610 rtems_status_code status;
611 611 spw_stats current;
612 612
613 613 memset(&current, 0, sizeof(spw_stats));
614 614
615 615 spacewire_get_last_error();
616 616
617 617 // read the current statistics
618 618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
619 619
620 620 // clear the counters
621 621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
622 622
623 623 // typedef struct {
624 624 // unsigned int tx_link_err; // NOT IN HK
625 625 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
626 626 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
627 627 // unsigned int rx_eep_err;
628 628 // unsigned int rx_truncated;
629 629 // unsigned int parity_err;
630 630 // unsigned int escape_err;
631 631 // unsigned int credit_err;
632 632 // unsigned int write_sync_err;
633 633 // unsigned int disconnect_err;
634 634 // unsigned int early_ep;
635 635 // unsigned int invalid_address;
636 636 // unsigned int packets_sent;
637 637 // unsigned int packets_received;
638 638 // } spw_stats;
639 639
640 640 // rx_eep_err
641 641 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
642 642 // rx_truncated
643 643 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
644 644 // parity_err
645 645 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
646 646 // escape_err
647 647 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
648 648 // credit_err
649 649 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
650 650 // write_sync_err
651 651 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
652 652 // disconnect_err
653 653 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
654 654 // early_ep
655 655 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
656 656 // invalid_address
657 657 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
658 658 // packets_sent
659 659 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
660 660 // packets_received
661 661 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
662 662
663 663 }
664 664
665 665 void spacewire_get_last_error( void )
666 666 {
667 667 static spw_stats previous = {0};
668 668 spw_stats current;
669 669 rtems_status_code status;
670 670
671 671 unsigned int hk_lfr_last_er_rid;
672 672 unsigned char hk_lfr_last_er_code;
673 673 int coarseTime;
674 674 int fineTime;
675 675 unsigned char update_hk_lfr_last_er;
676 676
677 677 memset(&current, 0, sizeof(spw_stats));
678 678 hk_lfr_last_er_rid = INIT_CHAR;
679 679 hk_lfr_last_er_code = INIT_CHAR;
680 680 update_hk_lfr_last_er = INIT_CHAR;
681 681
682 682 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
683 683
684 684 // get current time
685 685 coarseTime = time_management_regs->coarse_time;
686 686 fineTime = time_management_regs->fine_time;
687 687
688 688 // typedef struct {
689 689 // unsigned int tx_link_err; // NOT IN HK
690 690 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
691 691 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
692 692 // unsigned int rx_eep_err;
693 693 // unsigned int rx_truncated;
694 694 // unsigned int parity_err;
695 695 // unsigned int escape_err;
696 696 // unsigned int credit_err;
697 697 // unsigned int write_sync_err;
698 698 // unsigned int disconnect_err;
699 699 // unsigned int early_ep;
700 700 // unsigned int invalid_address;
701 701 // unsigned int packets_sent;
702 702 // unsigned int packets_received;
703 703 // } spw_stats;
704 704
705 705 // tx_link_err *** no code associated to this field
706 706 // rx_rmap_header_crc_err *** LE *** in HK
707 707 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
708 708 {
709 709 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
710 710 hk_lfr_last_er_code = CODE_HEADER_CRC;
711 711 update_hk_lfr_last_er = 1;
712 712 }
713 713 // rx_rmap_data_crc_err *** LE *** NOT IN HK
714 714 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
715 715 {
716 716 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
717 717 hk_lfr_last_er_code = CODE_DATA_CRC;
718 718 update_hk_lfr_last_er = 1;
719 719 }
720 720 // rx_eep_err
721 721 if (previous.rx_eep_err != current.rx_eep_err)
722 722 {
723 723 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
724 724 hk_lfr_last_er_code = CODE_EEP;
725 725 update_hk_lfr_last_er = 1;
726 726 }
727 727 // rx_truncated
728 728 if (previous.rx_truncated != current.rx_truncated)
729 729 {
730 730 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
731 731 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
732 732 update_hk_lfr_last_er = 1;
733 733 }
734 734 // parity_err
735 735 if (previous.parity_err != current.parity_err)
736 736 {
737 737 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
738 738 hk_lfr_last_er_code = CODE_PARITY;
739 739 update_hk_lfr_last_er = 1;
740 740 }
741 741 // escape_err
742 742 if (previous.parity_err != current.parity_err)
743 743 {
744 744 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
745 745 hk_lfr_last_er_code = CODE_ESCAPE;
746 746 update_hk_lfr_last_er = 1;
747 747 }
748 748 // credit_err
749 749 if (previous.credit_err != current.credit_err)
750 750 {
751 751 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
752 752 hk_lfr_last_er_code = CODE_CREDIT;
753 753 update_hk_lfr_last_er = 1;
754 754 }
755 755 // write_sync_err
756 756 if (previous.write_sync_err != current.write_sync_err)
757 757 {
758 758 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
759 759 hk_lfr_last_er_code = CODE_WRITE_SYNC;
760 760 update_hk_lfr_last_er = 1;
761 761 }
762 762 // disconnect_err
763 763 if (previous.disconnect_err != current.disconnect_err)
764 764 {
765 765 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
766 766 hk_lfr_last_er_code = CODE_DISCONNECT;
767 767 update_hk_lfr_last_er = 1;
768 768 }
769 769 // early_ep
770 770 if (previous.early_ep != current.early_ep)
771 771 {
772 772 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
773 773 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
774 774 update_hk_lfr_last_er = 1;
775 775 }
776 776 // invalid_address
777 777 if (previous.invalid_address != current.invalid_address)
778 778 {
779 779 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
780 780 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
781 781 update_hk_lfr_last_er = 1;
782 782 }
783 783
784 784 // if a field has changed, update the hk_last_er fields
785 785 if (update_hk_lfr_last_er == 1)
786 786 {
787 787 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
788 788 }
789 789
790 790 previous = current;
791 791 }
792 792
793 793 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
794 794 {
795 795 unsigned char *coarseTimePtr;
796 796 unsigned char *fineTimePtr;
797 797
798 798 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
799 799 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
800 800
801 801 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
802 802 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
803 803 housekeeping_packet.hk_lfr_last_er_code = code;
804 804 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
805 805 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
806 806 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
807 807 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
808 808 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
809 809 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
810 810 }
811 811
812 812 void update_hk_with_grspw_stats( void )
813 813 {
814 814 //****************************
815 815 // DPU_SPACEWIRE_IF_STATISTICS
816 816 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
817 817 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
818 818 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
819 819 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
820 820
821 821 //******************************************
822 822 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
823 823 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
824 824 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
825 825 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
826 826 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
827 827 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
828 828
829 829 //*********************************************
830 830 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
831 831 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
832 832 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
833 833 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
834 834 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
835 835 }
836 836
837 837 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
838 838 {
839 839 unsigned int *statusRegisterPtr;
840 840 unsigned char linkState;
841 841
842 842 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
843 843 linkState =
844 844 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
845 845
846 846 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
847 847
848 848 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
849 849 }
850 850
851 851 void increase_unsigned_char_counter( unsigned char *counter )
852 852 {
853 853 // update the number of valid timecodes that have been received
854 854 if (*counter == UINT8_MAX)
855 855 {
856 856 *counter = 0;
857 857 }
858 858 else
859 859 {
860 860 *counter = *counter + 1;
861 861 }
862 862 }
863 863
864 864 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
865 865 {
866 866 /** This function checks the coherency between the incoming timecode and the last valid timecode.
867 867 *
868 868 * @param currentTimecodeCtr is the incoming timecode
869 869 *
870 870 * @return returned codes::
871 871 * - LFR_DEFAULT
872 872 * - LFR_SUCCESSFUL
873 873 *
874 874 */
875 875
876 876 static unsigned char firstTickout = 1;
877 877 unsigned char ret;
878 878
879 879 ret = LFR_DEFAULT;
880 880
881 881 if (firstTickout == 0)
882 882 {
883 883 if (currentTimecodeCtr == 0)
884 884 {
885 885 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
886 886 {
887 887 ret = LFR_SUCCESSFUL;
888 888 }
889 889 else
890 890 {
891 891 ret = LFR_DEFAULT;
892 892 }
893 893 }
894 894 else
895 895 {
896 896 if (currentTimecodeCtr == (previousTimecodeCtr +1))
897 897 {
898 898 ret = LFR_SUCCESSFUL;
899 899 }
900 900 else
901 901 {
902 902 ret = LFR_DEFAULT;
903 903 }
904 904 }
905 905 }
906 906 else
907 907 {
908 908 firstTickout = 0;
909 909 ret = LFR_SUCCESSFUL;
910 910 }
911 911
912 912 return ret;
913 913 }
914 914
915 915 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
916 916 {
917 917 unsigned int ret;
918 918
919 919 ret = LFR_DEFAULT;
920 920
921 921 if (timecode == internalTime)
922 922 {
923 923 ret = LFR_SUCCESSFUL;
924 924 }
925 925 else
926 926 {
927 927 ret = LFR_DEFAULT;
928 928 }
929 929
930 930 return ret;
931 931 }
932 932
933 933 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
934 934 {
935 935 // a tickout has been emitted, perform actions on the incoming timecode
936 936
937 937 unsigned char incomingTimecode;
938 938 unsigned char updateTime;
939 939 unsigned char internalTime;
940 940 rtems_status_code status;
941 941
942 942 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
943 943 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
944 944 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
945 945
946 946 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
947 947
948 948 // update the number of tickout that have been generated
949 949 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
950 950
951 951 //**************************
952 952 // HK_LFR_TIMECODE_ERRONEOUS
953 953 // MISSING and INVALID are handled by the timecode_timer_routine service routine
954 954 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
955 955 {
956 956 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
957 957 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
958 958 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
959 959 }
960 960
961 961 //************************
962 962 // HK_LFR_TIME_TIMECODE_IT
963 963 // check the coherency between the SpaceWire timecode and the Internal Time
964 964 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
965 965 {
966 966 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
967 967 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
968 968 }
969 969
970 970 //********************
971 971 // HK_LFR_TIMECODE_CTR
972 972 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
973 973 if (oneTcLfrUpdateTimeReceived == 1)
974 974 {
975 975 if ( incomingTimecode != updateTime )
976 976 {
977 977 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
978 978 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
979 979 }
980 980 }
981 981
982 982 // launch the timecode timer to detect missing or invalid timecodes
983 983 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
984 984 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
985 985 if (status != RTEMS_SUCCESSFUL)
986 986 {
987 987 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
988 988 }
989 989 }
990 990
991 991 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
992 992 {
993 993 static unsigned char initStep = 1;
994 994
995 995 unsigned char currentTimecodeCtr;
996 996
997 997 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
998 998
999 999 if (initStep == 1)
1000 1000 {
1001 1001 if (currentTimecodeCtr == previousTimecodeCtr)
1002 1002 {
1003 1003 //************************
1004 1004 // HK_LFR_TIMECODE_MISSING
1005 1005 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
1006 1006 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1007 1007 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1008 1008 }
1009 1009 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
1010 1010 {
1011 1011 // the timecode value has changed and the value is valid, this is unexpected because
1012 1012 // the timer should not have fired, the timecode_irq_handler should have been raised
1013 1013 }
1014 1014 else
1015 1015 {
1016 1016 //************************
1017 1017 // HK_LFR_TIMECODE_INVALID
1018 1018 // the timecode value has changed and the value is not valid, no tickout has been generated
1019 1019 // this is why the timer has fired
1020 1020 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1021 1021 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1022 1022 }
1023 1023 }
1024 1024 else
1025 1025 {
1026 1026 initStep = 1;
1027 1027 //************************
1028 1028 // HK_LFR_TIMECODE_MISSING
1029 1029 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1030 1030 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1031 1031 }
1032 1032
1033 1033 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1034 1034 }
1035 1035
1036 1036 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1037 1037 {
1038 1038 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1039 1039 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1040 1040 header->reserved = DEFAULT_RESERVED;
1041 1041 header->userApplication = CCSDS_USER_APP;
1042 1042 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1043 1043 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1044 1044 header->packetLength[0] = INIT_CHAR;
1045 1045 header->packetLength[1] = INIT_CHAR;
1046 1046 // DATA FIELD HEADER
1047 1047 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1048 1048 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1049 1049 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1050 1050 header->destinationID = TM_DESTINATION_ID_GROUND;
1051 1051 header->time[BYTE_0] = INIT_CHAR;
1052 1052 header->time[BYTE_1] = INIT_CHAR;
1053 1053 header->time[BYTE_2] = INIT_CHAR;
1054 1054 header->time[BYTE_3] = INIT_CHAR;
1055 1055 header->time[BYTE_4] = INIT_CHAR;
1056 1056 header->time[BYTE_5] = INIT_CHAR;
1057 1057 // AUXILIARY DATA HEADER
1058 1058 header->sid = INIT_CHAR;
1059 1059 header->pa_bia_status_info = DEFAULT_HKBIA;
1060 1060 header->blkNr[0] = INIT_CHAR;
1061 1061 header->blkNr[1] = INIT_CHAR;
1062 1062 }
1063 1063
1064 1064 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1065 1065 {
1066 1066 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1067 1067 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1068 1068 header->reserved = DEFAULT_RESERVED;
1069 1069 header->userApplication = CCSDS_USER_APP;
1070 1070 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1071 1071 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1072 1072 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1073 1073 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1074 1074 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1075 1075 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1076 1076 // DATA FIELD HEADER
1077 1077 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1078 1078 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1079 1079 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1080 1080 header->destinationID = TM_DESTINATION_ID_GROUND;
1081 1081 header->time[BYTE_0] = INIT_CHAR;
1082 1082 header->time[BYTE_1] = INIT_CHAR;
1083 1083 header->time[BYTE_2] = INIT_CHAR;
1084 1084 header->time[BYTE_3] = INIT_CHAR;
1085 1085 header->time[BYTE_4] = INIT_CHAR;
1086 1086 header->time[BYTE_5] = INIT_CHAR;
1087 1087 // AUXILIARY DATA HEADER
1088 1088 header->sid = INIT_CHAR;
1089 1089 header->pa_bia_status_info = DEFAULT_HKBIA;
1090 1090 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1091 1091 header->pktNr = INIT_CHAR;
1092 1092 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1093 1093 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1094 1094 }
1095 1095
1096 1096 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1097 1097 {
1098 1098 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1099 1099 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1100 1100 header->reserved = DEFAULT_RESERVED;
1101 1101 header->userApplication = CCSDS_USER_APP;
1102 1102 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1103 1103 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1104 1104 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1105 1105 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1106 1106 header->packetLength[0] = INIT_CHAR;
1107 1107 header->packetLength[1] = INIT_CHAR;
1108 1108 // DATA FIELD HEADER
1109 1109 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1110 1110 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1111 1111 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1112 1112 header->destinationID = TM_DESTINATION_ID_GROUND;
1113 1113 header->time[BYTE_0] = INIT_CHAR;
1114 1114 header->time[BYTE_1] = INIT_CHAR;
1115 1115 header->time[BYTE_2] = INIT_CHAR;
1116 1116 header->time[BYTE_3] = INIT_CHAR;
1117 1117 header->time[BYTE_4] = INIT_CHAR;
1118 1118 header->time[BYTE_5] = INIT_CHAR;
1119 1119 // AUXILIARY DATA HEADER
1120 1120 header->sid = INIT_CHAR;
1121 1121 header->pa_bia_status_info = INIT_CHAR;
1122 1122 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1123 1123 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1124 1124 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1125 1125 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1126 1126 }
1127 1127
1128 1128 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1129 1129 Header_TM_LFR_SCIENCE_CWF_t *header )
1130 1130 {
1131 1131 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1132 1132 *
1133 1133 * @param waveform points to the buffer containing the data that will be send.
1134 1134 * @param sid is the source identifier of the data that will be sent.
1135 1135 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1136 1136 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1137 1137 * contain information to setup the transmission of the data packets.
1138 1138 *
1139 1139 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1140 1140 *
1141 1141 */
1142 1142
1143 1143 unsigned int i;
1144 1144 int ret;
1145 1145 unsigned int coarseTime;
1146 1146 unsigned int fineTime;
1147 1147 rtems_status_code status;
1148 1148 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1149 1149 int *dataPtr;
1150 1150 unsigned char sid;
1151 1151
1152 1152 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1153 1153 spw_ioctl_send_CWF.options = 0;
1154 1154
1155 1155 ret = LFR_DEFAULT;
1156 1156 sid = (unsigned char) ring_node_to_send->sid;
1157 1157
1158 1158 coarseTime = ring_node_to_send->coarseTime;
1159 1159 fineTime = ring_node_to_send->fineTime;
1160 1160 dataPtr = (int*) ring_node_to_send->buffer_address;
1161 1161
1162 1162 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1163 1163 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1164 1164 header->pa_bia_status_info = pa_bia_status_info;
1165 1165 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1166 1166 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1167 1167 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1168 1168
1169 1169 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1170 1170 {
1171 1171 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1172 1172 spw_ioctl_send_CWF.hdr = (char*) header;
1173 1173 // BUILD THE DATA
1174 1174 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1175 1175
1176 1176 // SET PACKET SEQUENCE CONTROL
1177 1177 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1178 1178
1179 1179 // SET SID
1180 1180 header->sid = sid;
1181 1181
1182 1182 // SET PACKET TIME
1183 1183 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1184 1184 //
1185 1185 header->time[0] = header->acquisitionTime[0];
1186 1186 header->time[1] = header->acquisitionTime[1];
1187 1187 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1188 1188 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1189 1189 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1190 1190 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1191 1191
1192 1192 // SET PACKET ID
1193 1193 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1194 1194 {
1195 1195 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1196 1196 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1197 1197 }
1198 1198 else
1199 1199 {
1200 1200 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1201 1201 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1202 1202 }
1203 1203
1204 1204 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1205 1205 if (status != RTEMS_SUCCESSFUL) {
1206 1206 ret = LFR_DEFAULT;
1207 1207 }
1208 1208 }
1209 1209
1210 1210 return ret;
1211 1211 }
1212 1212
1213 1213 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1214 1214 Header_TM_LFR_SCIENCE_SWF_t *header )
1215 1215 {
1216 1216 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1217 1217 *
1218 1218 * @param waveform points to the buffer containing the data that will be send.
1219 1219 * @param sid is the source identifier of the data that will be sent.
1220 1220 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1221 1221 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1222 1222 * contain information to setup the transmission of the data packets.
1223 1223 *
1224 1224 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1225 1225 *
1226 1226 */
1227 1227
1228 1228 unsigned int i;
1229 1229 int ret;
1230 1230 unsigned int coarseTime;
1231 1231 unsigned int fineTime;
1232 1232 rtems_status_code status;
1233 1233 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1234 1234 int *dataPtr;
1235 1235 unsigned char sid;
1236 1236
1237 1237 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1238 1238 spw_ioctl_send_SWF.options = 0;
1239 1239
1240 1240 ret = LFR_DEFAULT;
1241 1241
1242 1242 coarseTime = ring_node_to_send->coarseTime;
1243 1243 fineTime = ring_node_to_send->fineTime;
1244 1244 dataPtr = (int*) ring_node_to_send->buffer_address;
1245 1245 sid = ring_node_to_send->sid;
1246 1246
1247 1247 header->pa_bia_status_info = pa_bia_status_info;
1248 1248 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1249 1249
1250 1250 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1251 1251 {
1252 1252 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1253 1253 spw_ioctl_send_SWF.hdr = (char*) header;
1254 1254
1255 1255 // SET PACKET SEQUENCE CONTROL
1256 1256 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1257 1257
1258 1258 // SET PACKET LENGTH AND BLKNR
1259 1259 if (i == (PKTCNT_SWF-1))
1260 1260 {
1261 1261 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1262 1262 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1263 1263 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1264 1264 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1265 1265 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1266 1266 }
1267 1267 else
1268 1268 {
1269 1269 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1270 1270 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1271 1271 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1272 1272 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1273 1273 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1274 1274 }
1275 1275
1276 1276 // SET PACKET TIME
1277 1277 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1278 1278 //
1279 1279 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1280 1280 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1281 1281 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1282 1282 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1283 1283 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1284 1284 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1285 1285
1286 1286 // SET SID
1287 1287 header->sid = sid;
1288 1288
1289 1289 // SET PKTNR
1290 1290 header->pktNr = i+1; // PKT_NR
1291 1291
1292 1292 // SEND PACKET
1293 1293 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1294 1294 if (status != RTEMS_SUCCESSFUL) {
1295 1295 ret = LFR_DEFAULT;
1296 1296 }
1297 1297 }
1298 1298
1299 1299 return ret;
1300 1300 }
1301 1301
1302 1302 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1303 1303 Header_TM_LFR_SCIENCE_CWF_t *header )
1304 1304 {
1305 1305 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1306 1306 *
1307 1307 * @param waveform points to the buffer containing the data that will be send.
1308 1308 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1309 1309 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1310 1310 * contain information to setup the transmission of the data packets.
1311 1311 *
1312 1312 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1313 1313 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1314 1314 *
1315 1315 */
1316 1316
1317 1317 unsigned int i;
1318 1318 int ret;
1319 1319 unsigned int coarseTime;
1320 1320 unsigned int fineTime;
1321 1321 rtems_status_code status;
1322 1322 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1323 1323 char *dataPtr;
1324 1324 unsigned char sid;
1325 1325
1326 1326 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1327 1327 spw_ioctl_send_CWF.options = 0;
1328 1328
1329 1329 ret = LFR_DEFAULT;
1330 1330 sid = ring_node_to_send->sid;
1331 1331
1332 1332 coarseTime = ring_node_to_send->coarseTime;
1333 1333 fineTime = ring_node_to_send->fineTime;
1334 1334 dataPtr = (char*) ring_node_to_send->buffer_address;
1335 1335
1336 1336 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1337 1337 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1338 1338 header->pa_bia_status_info = pa_bia_status_info;
1339 1339 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1340 1340 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1341 1341 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1342 1342
1343 1343 //*********************
1344 1344 // SEND CWF3_light DATA
1345 1345 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1346 1346 {
1347 1347 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1348 1348 spw_ioctl_send_CWF.hdr = (char*) header;
1349 1349 // BUILD THE DATA
1350 1350 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1351 1351
1352 1352 // SET PACKET SEQUENCE COUNTER
1353 1353 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1354 1354
1355 1355 // SET SID
1356 1356 header->sid = sid;
1357 1357
1358 1358 // SET PACKET TIME
1359 1359 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1360 1360 //
1361 1361 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1362 1362 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1363 1363 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1364 1364 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1365 1365 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1366 1366 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1367 1367
1368 1368 // SET PACKET ID
1369 1369 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1370 1370 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1371 1371
1372 1372 // SEND PACKET
1373 1373 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1374 1374 if (status != RTEMS_SUCCESSFUL) {
1375 1375 ret = LFR_DEFAULT;
1376 1376 }
1377 1377 }
1378 1378
1379 1379 return ret;
1380 1380 }
1381 1381
1382 1382 void spw_send_asm_f0( ring_node *ring_node_to_send,
1383 1383 Header_TM_LFR_SCIENCE_ASM_t *header )
1384 1384 {
1385 1385 unsigned int i;
1386 1386 unsigned int length = 0;
1387 1387 rtems_status_code status;
1388 1388 unsigned int sid;
1389 1389 float *spectral_matrix;
1390 1390 int coarseTime;
1391 1391 int fineTime;
1392 1392 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1393 1393
1394 1394 sid = ring_node_to_send->sid;
1395 1395 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1396 1396 coarseTime = ring_node_to_send->coarseTime;
1397 1397 fineTime = ring_node_to_send->fineTime;
1398 1398
1399 1399 header->pa_bia_status_info = pa_bia_status_info;
1400 1400 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1401 1401
1402 1402 for (i=0; i<PKTCNT_ASM; i++)
1403 1403 {
1404 1404 if ((i==0) || (i==1))
1405 1405 {
1406 1406 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1407 1407 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1408 1408 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1409 1409 ];
1410 1410 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1411 1411 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1412 1412 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1413 1413 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1414 1414 }
1415 1415 else
1416 1416 {
1417 1417 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1418 1418 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1419 1419 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1420 1420 ];
1421 1421 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1422 1422 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1423 1423 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1424 1424 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1425 1425 }
1426 1426
1427 1427 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1428 1428 spw_ioctl_send_ASM.hdr = (char *) header;
1429 1429 spw_ioctl_send_ASM.options = 0;
1430 1430
1431 1431 // (2) BUILD THE HEADER
1432 1432 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1433 1433 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1434 1434 header->packetLength[1] = (unsigned char) (length);
1435 1435 header->sid = (unsigned char) sid; // SID
1436 1436 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1437 1437 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1438 1438
1439 1439 // (3) SET PACKET TIME
1440 1440 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1441 1441 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1442 1442 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1443 1443 header->time[BYTE_3] = (unsigned char) (coarseTime);
1444 1444 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1445 1445 header->time[BYTE_5] = (unsigned char) (fineTime);
1446 1446 //
1447 1447 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1448 1448 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1449 1449 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1450 1450 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1451 1451 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1452 1452 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1453 1453
1454 1454 // (4) SEND PACKET
1455 1455 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1456 1456 if (status != RTEMS_SUCCESSFUL) {
1457 1457 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1458 1458 }
1459 1459 }
1460 1460 }
1461 1461
1462 1462 void spw_send_asm_f1( ring_node *ring_node_to_send,
1463 1463 Header_TM_LFR_SCIENCE_ASM_t *header )
1464 1464 {
1465 1465 unsigned int i;
1466 1466 unsigned int length = 0;
1467 1467 rtems_status_code status;
1468 1468 unsigned int sid;
1469 1469 float *spectral_matrix;
1470 1470 int coarseTime;
1471 1471 int fineTime;
1472 1472 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1473 1473
1474 1474 sid = ring_node_to_send->sid;
1475 1475 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1476 1476 coarseTime = ring_node_to_send->coarseTime;
1477 1477 fineTime = ring_node_to_send->fineTime;
1478 1478
1479 1479 header->pa_bia_status_info = pa_bia_status_info;
1480 1480 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1481 1481
1482 1482 for (i=0; i<PKTCNT_ASM; i++)
1483 1483 {
1484 1484 if ((i==0) || (i==1))
1485 1485 {
1486 1486 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1487 1487 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1488 1488 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1489 1489 ];
1490 1490 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1491 1491 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1492 1492 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1493 1493 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1494 1494 }
1495 1495 else
1496 1496 {
1497 1497 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1498 1498 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1499 1499 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1500 1500 ];
1501 1501 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1502 1502 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1503 1503 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1504 1504 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1505 1505 }
1506 1506
1507 1507 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1508 1508 spw_ioctl_send_ASM.hdr = (char *) header;
1509 1509 spw_ioctl_send_ASM.options = 0;
1510 1510
1511 1511 // (2) BUILD THE HEADER
1512 1512 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1513 1513 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1514 1514 header->packetLength[1] = (unsigned char) (length);
1515 1515 header->sid = (unsigned char) sid; // SID
1516 1516 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1517 1517 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1518 1518
1519 1519 // (3) SET PACKET TIME
1520 1520 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1521 1521 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1522 1522 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1523 1523 header->time[BYTE_3] = (unsigned char) (coarseTime);
1524 1524 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1525 1525 header->time[BYTE_5] = (unsigned char) (fineTime);
1526 1526 //
1527 1527 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1528 1528 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1529 1529 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1530 1530 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1531 1531 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1532 1532 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1533 1533
1534 1534 // (4) SEND PACKET
1535 1535 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1536 1536 if (status != RTEMS_SUCCESSFUL) {
1537 1537 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1538 1538 }
1539 1539 }
1540 1540 }
1541 1541
1542 1542 void spw_send_asm_f2( ring_node *ring_node_to_send,
1543 1543 Header_TM_LFR_SCIENCE_ASM_t *header )
1544 1544 {
1545 1545 unsigned int i;
1546 1546 unsigned int length = 0;
1547 1547 rtems_status_code status;
1548 1548 unsigned int sid;
1549 1549 float *spectral_matrix;
1550 1550 int coarseTime;
1551 1551 int fineTime;
1552 1552 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1553 1553
1554 1554 sid = ring_node_to_send->sid;
1555 1555 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1556 1556 coarseTime = ring_node_to_send->coarseTime;
1557 1557 fineTime = ring_node_to_send->fineTime;
1558 1558
1559 1559 header->pa_bia_status_info = pa_bia_status_info;
1560 1560 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1561 1561
1562 1562 for (i=0; i<PKTCNT_ASM; i++)
1563 1563 {
1564 1564
1565 1565 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1566 1566 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1567 1567 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1568 1568 ];
1569 1569 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1570 1570 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1571 1571 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1572 1572 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1573 1573
1574 1574 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1575 1575 spw_ioctl_send_ASM.hdr = (char *) header;
1576 1576 spw_ioctl_send_ASM.options = 0;
1577 1577
1578 1578 // (2) BUILD THE HEADER
1579 1579 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1580 1580 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1581 1581 header->packetLength[1] = (unsigned char) (length);
1582 1582 header->sid = (unsigned char) sid; // SID
1583 1583 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1584 1584 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1585 1585
1586 1586 // (3) SET PACKET TIME
1587 1587 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1588 1588 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1589 1589 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1590 1590 header->time[BYTE_3] = (unsigned char) (coarseTime);
1591 1591 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1592 1592 header->time[BYTE_5] = (unsigned char) (fineTime);
1593 1593 //
1594 1594 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1595 1595 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1596 1596 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1597 1597 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1598 1598 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1599 1599 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1600 1600
1601 1601 // (4) SEND PACKET
1602 1602 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1603 1603 if (status != RTEMS_SUCCESSFUL) {
1604 1604 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1605 1605 }
1606 1606 }
1607 1607 }
1608 1608
1609 1609 void spw_send_k_dump( ring_node *ring_node_to_send )
1610 1610 {
1611 1611 rtems_status_code status;
1612 1612 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1613 1613 unsigned int packetLength;
1614 1614 unsigned int size;
1615 1615
1616 1616 PRINTF("spw_send_k_dump\n")
1617 1617
1618 1618 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1619 1619
1620 1620 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1621 1621
1622 1622 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1623 1623
1624 1624 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1625 1625
1626 1626 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1627 1627
1628 1628 if (status == -1){
1629 1629 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1630 1630 }
1631 1631
1632 1632 ring_node_to_send->status = INIT_CHAR;
1633 1633 }
@@ -1,423 +1,423
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf0_prc0.h"
11 11
12 12 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
13 13
14 14 //***
15 15 // F0
16 16 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
17 17 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
18 18
19 19 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
20 20 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
21 21
22 22 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 23 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 24 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
25 25
26 26 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
27 27 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
28 28
29 29 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
30 30 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
31 31
32 32 //************
33 33 // RTEMS TASKS
34 34
35 35 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
36 36 {
37 37 int i;
38 38
39 39 rtems_event_set event_out;
40 40 rtems_status_code status;
41 41 rtems_id queue_id_prc0;
42 42 asm_msg msgForPRC;
43 43 ring_node *nodeForAveraging;
44 44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 45 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
46 46 ring_node_asm *current_ring_node_asm_norm_f0;
47 47
48 48 unsigned int nb_norm_bp1;
49 49 unsigned int nb_norm_bp2;
50 50 unsigned int nb_norm_asm;
51 51 unsigned int nb_sbm_bp1;
52 52 unsigned int nb_sbm_bp2;
53 53
54 54 nb_norm_bp1 = 0;
55 55 nb_norm_bp2 = 0;
56 56 nb_norm_asm = 0;
57 57 nb_sbm_bp1 = 0;
58 58 nb_sbm_bp2 = 0;
59 59 event_out = EVENT_SETS_NONE_PENDING;
60 60 queue_id_prc0 = RTEMS_ID_NONE;
61 61
62 62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67 67
68 68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
69 69
70 70 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 71 if (status != RTEMS_SUCCESSFUL)
72 72 {
73 73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 74 }
75 75
76 76 while(1){
77 77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78 78
79 79 //****************************************
80 80 // initialize the mesage for the MATR task
81 81 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
84 84 //
85 85 //****************************************
86 86
87 87 nodeForAveraging = getRingNodeForAveraging( 0 );
88 88
89 89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 91 {
92 92 nodeForAveraging = nodeForAveraging->previous;
93 93 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
94 94 }
95 95
96 96 // compute the average and store it in the averaged_sm_f1 buffer
97 97 SM_average( current_ring_node_asm_norm_f0->matrix,
98 98 current_ring_node_asm_burst_sbm_f0->matrix,
99 99 ring_node_tab,
100 100 nb_norm_bp1, nb_sbm_bp1,
101 101 &msgForPRC, 0 ); // 0 => frequency channel 0
102 102
103 103 // update nb_average
104 104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109 109
110 110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 111 {
112 112 nb_sbm_bp1 = 0;
113 113 // set another ring for the ASM storage
114 114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 115 if ( lfrCurrentMode == LFR_MODE_BURST )
116 116 {
117 117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 118 }
119 119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 120 {
121 121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 122 }
123 123 }
124 124
125 125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 126 {
127 127 nb_sbm_bp2 = 0;
128 128 if ( lfrCurrentMode == LFR_MODE_BURST )
129 129 {
130 130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 131 }
132 132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 133 {
134 134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 135 }
136 136 }
137 137
138 138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 139 {
140 140 nb_norm_bp1 = 0;
141 141 // set another ring for the ASM storage
142 142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 145 {
146 146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 147 }
148 148 }
149 149
150 150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 151 {
152 152 nb_norm_bp2 = 0;
153 153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 155 {
156 156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 157 }
158 158 }
159 159
160 160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 161 {
162 162 nb_norm_asm = 0;
163 163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 165 {
166 166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 167 }
168 168 }
169 169
170 170 //*************************
171 171 // send the message to PRC
172 172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 173 {
174 174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 175 }
176 176
177 177 if (status != RTEMS_SUCCESSFUL) {
178 178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 179 }
180 180 }
181 181 }
182 182
183 183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 184 {
185 185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 186 size_t size; // size of the incoming TC packet
187 187 asm_msg *incomingMsg;
188 188 //
189 189 unsigned char sid;
190 190 rtems_status_code status;
191 191 rtems_id queue_id;
192 192 rtems_id queue_id_q_p0;
193 bp_packet_with_spare packet_norm_bp1;
194 bp_packet packet_norm_bp2;
195 bp_packet packet_sbm_bp1;
196 bp_packet packet_sbm_bp2;
193 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
194 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
195 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
197 197 ring_node *current_ring_node_to_send_asm_f0;
198 198 float nbSMInASMNORM;
199 199 float nbSMInASMSBM;
200 200
201 201 size = 0;
202 202 queue_id = RTEMS_ID_NONE;
203 203 queue_id_q_p0 = RTEMS_ID_NONE;
204 204 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
205 205 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
206 206 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
207 207 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
208 208
209 209 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
210 210 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
211 211 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
212 212
213 213 //*************
214 214 // NORM headers
215 215 BP_init_header_with_spare( &packet_norm_bp1,
216 216 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
217 217 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
218 218 BP_init_header( &packet_norm_bp2,
219 219 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
220 220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
221 221
222 222 //****************************
223 223 // BURST SBM1 and SBM2 headers
224 224 if ( lfrRequestedMode == LFR_MODE_BURST )
225 225 {
226 226 BP_init_header( &packet_sbm_bp1,
227 227 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
228 228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 229 BP_init_header( &packet_sbm_bp2,
230 230 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
231 231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 232 }
233 233 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
234 234 {
235 235 BP_init_header( &packet_sbm_bp1,
236 236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
237 237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 238 BP_init_header( &packet_sbm_bp2,
239 239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
240 240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 241 }
242 242 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
243 243 {
244 244 BP_init_header( &packet_sbm_bp1,
245 245 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
246 246 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
247 247 BP_init_header( &packet_sbm_bp2,
248 248 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
249 249 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
250 250 }
251 251 else
252 252 {
253 253 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
254 254 }
255 255
256 256 status = get_message_queue_id_send( &queue_id );
257 257 if (status != RTEMS_SUCCESSFUL)
258 258 {
259 259 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
260 260 }
261 261 status = get_message_queue_id_prc0( &queue_id_q_p0);
262 262 if (status != RTEMS_SUCCESSFUL)
263 263 {
264 264 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
265 265 }
266 266
267 267 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
268 268
269 269 while(1){
270 270 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
271 271 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
272 272
273 273 incomingMsg = (asm_msg*) incomingData;
274 274
275 275 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
276 276 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
277 277
278 278 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
279 279 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
280 280
281 281 //****************
282 282 //****************
283 283 // BURST SBM1 SBM2
284 284 //****************
285 285 //****************
286 286 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
287 287 {
288 288 sid = getSID( incomingMsg->event );
289 289 // 1) compress the matrix for Basic Parameters calculation
290 290 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
291 291 nbSMInASMSBM,
292 292 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
293 293 ASM_F0_INDICE_START, CHANNELF0);
294 294 // 2) compute the BP1 set
295 295 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
296 296 // 3) send the BP1 set
297 297 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 298 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 299 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
300 300 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 301 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
302 302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
303 303 sid);
304 304 // 4) compute the BP2 set if needed
305 305 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
306 306 {
307 307 // 1) compute the BP2 set
308 308 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
309 309 // 2) send the BP2 set
310 310 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
311 311 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
312 312 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
313 313 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 314 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
315 315 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
316 316 sid);
317 317 }
318 318 }
319 319
320 320 //*****
321 321 //*****
322 322 // NORM
323 323 //*****
324 324 //*****
325 325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
326 326 {
327 327 // 1) compress the matrix for Basic Parameters calculation
328 328 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
329 329 nbSMInASMNORM,
330 330 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
331 331 ASM_F0_INDICE_START, CHANNELF0 );
332 332 // 2) compute the BP1 set
333 333 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
334 334 // 3) send the BP1 set
335 335 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 336 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
337 337 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
338 338 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
339 339 BP_send( (char *) &packet_norm_bp1, queue_id,
340 340 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
341 341 SID_NORM_BP1_F0 );
342 342 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
343 343 {
344 344 // 1) compute the BP2 set using the same ASM as the one used for BP1
345 345 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
346 346 // 2) send the BP2 set
347 347 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
348 348 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
349 349 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
350 350 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
351 351 BP_send( (char *) &packet_norm_bp2, queue_id,
352 352 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
353 353 SID_NORM_BP2_F0);
354 354 }
355 355 }
356 356
357 357 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
358 358 {
359 359 // 1) reorganize the ASM and divide
360 360 ASM_reorganize_and_divide( asm_f0_patched_norm,
361 361 (float*) current_ring_node_to_send_asm_f0->buffer_address,
362 362 nbSMInASMNORM );
363 363 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
364 364 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
365 365 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
366 366
367 367 // 3) send the spectral matrix packets
368 368 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
369 369
370 370 // change asm ring node
371 371 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
372 372 }
373 373
374 374 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
375 375
376 376 }
377 377 }
378 378
379 379 //**********
380 380 // FUNCTIONS
381 381
382 382 void reset_nb_sm_f0( unsigned char lfrMode )
383 383 {
384 384 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
385 385 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
386 386 nb_sm_before_f0.norm_asm =
387 387 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
388 388 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
389 389 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
390 390 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
391 391 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
392 392 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
393 393 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
394 394
395 395 if (lfrMode == LFR_MODE_SBM1)
396 396 {
397 397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
398 398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
399 399 }
400 400 else if (lfrMode == LFR_MODE_SBM2)
401 401 {
402 402 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
403 403 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
404 404 }
405 405 else if (lfrMode == LFR_MODE_BURST)
406 406 {
407 407 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
408 408 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
409 409 }
410 410 else
411 411 {
412 412 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
413 413 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
414 414 }
415 415 }
416 416
417 417 void init_k_coefficients_prc0( void )
418 418 {
419 419 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
420 420
421 421 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
422 422 }
423 423
@@ -1,407 +1,407
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf1_prc1.h"
11 11
12 12 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
13 13
14 14 //***
15 15 // F1
16 16 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
17 17 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
18 18
19 19 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
20 20 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
21 21
22 22 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 23 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 24 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
25 25
26 26 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
27 27 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
28 28
29 29 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
30 30 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
31 31
32 32 //************
33 33 // RTEMS TASKS
34 34
35 35 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
36 36 {
37 37 int i;
38 38
39 39 rtems_event_set event_out;
40 40 rtems_status_code status;
41 41 rtems_id queue_id_prc1;
42 42 asm_msg msgForPRC;
43 43 ring_node *nodeForAveraging;
44 44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 45 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
46 46 ring_node_asm *current_ring_node_asm_norm_f1;
47 47
48 48 unsigned int nb_norm_bp1;
49 49 unsigned int nb_norm_bp2;
50 50 unsigned int nb_norm_asm;
51 51 unsigned int nb_sbm_bp1;
52 52 unsigned int nb_sbm_bp2;
53 53
54 54 event_out = EVENT_SETS_NONE_PENDING;
55 55 queue_id_prc1 = RTEMS_ID_NONE;
56 56
57 57 nb_norm_bp1 = 0;
58 58 nb_norm_bp2 = 0;
59 59 nb_norm_asm = 0;
60 60 nb_sbm_bp1 = 0;
61 61 nb_sbm_bp2 = 0;
62 62
63 63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68 68
69 69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70 70
71 71 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 72 if (status != RTEMS_SUCCESSFUL)
73 73 {
74 74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 75 }
76 76
77 77 while(1){
78 78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79 79
80 80 //****************************************
81 81 // initialize the mesage for the MATR task
82 82 msgForPRC.norm = current_ring_node_asm_norm_f1;
83 83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 84 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
85 85 //
86 86 //****************************************
87 87
88 88 nodeForAveraging = getRingNodeForAveraging( 1 );
89 89
90 90 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
91 91 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
92 92 {
93 93 nodeForAveraging = nodeForAveraging->previous;
94 94 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
95 95 }
96 96
97 97 // compute the average and store it in the averaged_sm_f1 buffer
98 98 SM_average( current_ring_node_asm_norm_f1->matrix,
99 99 current_ring_node_asm_burst_sbm_f1->matrix,
100 100 ring_node_tab,
101 101 nb_norm_bp1, nb_sbm_bp1,
102 102 &msgForPRC, 1 ); // 1 => frequency channel 1
103 103
104 104 // update nb_average
105 105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
106 106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
107 107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
108 108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
109 109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
110 110
111 111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 112 {
113 113 nb_sbm_bp1 = 0;
114 114 // set another ring for the ASM storage
115 115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 116 if ( lfrCurrentMode == LFR_MODE_BURST )
117 117 {
118 118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
119 119 }
120 120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 121 {
122 122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
123 123 }
124 124 }
125 125
126 126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 127 {
128 128 nb_sbm_bp2 = 0;
129 129 if ( lfrCurrentMode == LFR_MODE_BURST )
130 130 {
131 131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
132 132 }
133 133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 134 {
135 135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
136 136 }
137 137 }
138 138
139 139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 140 {
141 141 nb_norm_bp1 = 0;
142 142 // set another ring for the ASM storage
143 143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 146 {
147 147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
148 148 }
149 149 }
150 150
151 151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 152 {
153 153 nb_norm_bp2 = 0;
154 154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 156 {
157 157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
158 158 }
159 159 }
160 160
161 161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 162 {
163 163 nb_norm_asm = 0;
164 164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 166 {
167 167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
168 168 }
169 169 }
170 170
171 171 //*************************
172 172 // send the message to PRC
173 173 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
174 174 {
175 175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
176 176 }
177 177
178 178 if (status != RTEMS_SUCCESSFUL) {
179 179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 180 }
181 181 }
182 182 }
183 183
184 184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 185 {
186 186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 187 size_t size; // size of the incoming TC packet
188 188 asm_msg *incomingMsg;
189 189 //
190 190 unsigned char sid;
191 191 rtems_status_code status;
192 192 rtems_id queue_id_send;
193 193 rtems_id queue_id_q_p1;
194 bp_packet_with_spare packet_norm_bp1;
195 bp_packet packet_norm_bp2;
196 bp_packet packet_sbm_bp1;
197 bp_packet packet_sbm_bp2;
194 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
195 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
197 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
198 198 ring_node *current_ring_node_to_send_asm_f1;
199 199 float nbSMInASMNORM;
200 200 float nbSMInASMSBM;
201 201
202 202 size = 0;
203 203 queue_id_send = RTEMS_ID_NONE;
204 204 queue_id_q_p1 = RTEMS_ID_NONE;
205 205 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
206 206 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
207 207 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
208 208 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
209 209
210 210 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
211 211 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
212 212 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
213 213
214 214 //*************
215 215 // NORM headers
216 216 BP_init_header_with_spare( &packet_norm_bp1,
217 217 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
218 218 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
219 219 BP_init_header( &packet_norm_bp2,
220 220 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
221 221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
222 222
223 223 //***********************
224 224 // BURST and SBM2 headers
225 225 if ( lfrRequestedMode == LFR_MODE_BURST )
226 226 {
227 227 BP_init_header( &packet_sbm_bp1,
228 228 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
229 229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
230 230 BP_init_header( &packet_sbm_bp2,
231 231 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
232 232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
233 233 }
234 234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
235 235 {
236 236 BP_init_header( &packet_sbm_bp1,
237 237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
238 238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
239 239 BP_init_header( &packet_sbm_bp2,
240 240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
241 241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
242 242 }
243 243 else
244 244 {
245 245 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
246 246 }
247 247
248 248 status = get_message_queue_id_send( &queue_id_send );
249 249 if (status != RTEMS_SUCCESSFUL)
250 250 {
251 251 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
252 252 }
253 253 status = get_message_queue_id_prc1( &queue_id_q_p1);
254 254 if (status != RTEMS_SUCCESSFUL)
255 255 {
256 256 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
257 257 }
258 258
259 259 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
260 260
261 261 while(1){
262 262 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
263 263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
264 264
265 265 incomingMsg = (asm_msg*) incomingData;
266 266
267 267 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
268 268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
269 269
270 270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272 272
273 273 //***********
274 274 //***********
275 275 // BURST SBM2
276 276 //***********
277 277 //***********
278 278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
279 279 {
280 280 sid = getSID( incomingMsg->event );
281 281 // 1) compress the matrix for Basic Parameters calculation
282 282 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
283 283 nbSMInASMSBM,
284 284 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
285 285 ASM_F1_INDICE_START, CHANNELF1);
286 286 // 2) compute the BP1 set
287 287 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
288 288 // 3) send the BP1 set
289 289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
292 292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
293 293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
294 294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
295 295 sid );
296 296 // 4) compute the BP2 set if needed
297 297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
298 298 {
299 299 // 1) compute the BP2 set
300 300 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
301 301 // 2) send the BP2 set
302 302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
304 304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
305 305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
306 306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
307 307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
308 308 sid );
309 309 }
310 310 }
311 311
312 312 //*****
313 313 //*****
314 314 // NORM
315 315 //*****
316 316 //*****
317 317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
318 318 {
319 319 // 1) compress the matrix for Basic Parameters calculation
320 320 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
321 321 nbSMInASMNORM,
322 322 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
323 323 ASM_F1_INDICE_START, CHANNELF1 );
324 324 // 2) compute the BP1 set
325 325 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
326 326 // 3) send the BP1 set
327 327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
330 330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
331 331 BP_send( (char *) &packet_norm_bp1, queue_id_send,
332 332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
333 333 SID_NORM_BP1_F1 );
334 334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
335 335 {
336 336 // 1) compute the BP2 set
337 337 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
338 338 // 2) send the BP2 set
339 339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
341 341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
342 342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
343 343 BP_send( (char *) &packet_norm_bp2, queue_id_send,
344 344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
345 345 SID_NORM_BP2_F1 );
346 346 }
347 347 }
348 348
349 349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
350 350 {
351 351 // 1) reorganize the ASM and divide
352 352 ASM_reorganize_and_divide( asm_f1_patched_norm,
353 353 (float*) current_ring_node_to_send_asm_f1->buffer_address,
354 354 nbSMInASMNORM );
355 355 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
356 356 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
357 357 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
358 358
359 359 // 3) send the spectral matrix packets
360 360 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
361 361
362 362 // change asm ring node
363 363 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
364 364 }
365 365
366 366 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
367 367
368 368 }
369 369 }
370 370
371 371 //**********
372 372 // FUNCTIONS
373 373
374 374 void reset_nb_sm_f1( unsigned char lfrMode )
375 375 {
376 376 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
377 377 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
378 378 nb_sm_before_f1.norm_asm =
379 379 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
380 380 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
381 381 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
382 382 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
383 383 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
384 384
385 385 if (lfrMode == LFR_MODE_SBM2)
386 386 {
387 387 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
388 388 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
389 389 }
390 390 else if (lfrMode == LFR_MODE_BURST)
391 391 {
392 392 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
393 393 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
394 394 }
395 395 else
396 396 {
397 397 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
398 398 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
399 399 }
400 400 }
401 401
402 402 void init_k_coefficients_prc1( void )
403 403 {
404 404 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
405 405
406 406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
407 407 }
@@ -1,332 +1,332
1 1 /** Functions related to data processing.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 7 *
8 8 */
9 9
10 10 #include "avf2_prc2.h"
11 11
12 12 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
13 13
14 14 //***
15 15 // F2
16 16 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
17 17
18 18 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
19 19 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
20 20
21 21 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
22 22 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
23 23
24 24 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
25 25
26 26 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
27 27
28 28 //************
29 29 // RTEMS TASKS
30 30
31 31 //***
32 32 // F2
33 33 rtems_task avf2_task( rtems_task_argument argument )
34 34 {
35 35 rtems_event_set event_out;
36 36 rtems_status_code status;
37 37 rtems_id queue_id_prc2;
38 38 asm_msg msgForPRC;
39 39 ring_node *nodeForAveraging;
40 40 ring_node_asm *current_ring_node_asm_norm_f2;
41 41
42 42 unsigned int nb_norm_bp1;
43 43 unsigned int nb_norm_bp2;
44 44 unsigned int nb_norm_asm;
45 45
46 46 event_out = EVENT_SETS_NONE_PENDING;
47 47 queue_id_prc2 = RTEMS_ID_NONE;
48 48 nb_norm_bp1 = 0;
49 49 nb_norm_bp2 = 0;
50 50 nb_norm_asm = 0;
51 51
52 52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
53 53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
54 54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
55 55
56 56 BOOT_PRINTF("in AVF2 ***\n")
57 57
58 58 status = get_message_queue_id_prc2( &queue_id_prc2 );
59 59 if (status != RTEMS_SUCCESSFUL)
60 60 {
61 61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
62 62 }
63 63
64 64 while(1){
65 65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66 66
67 67 //****************************************
68 68 // initialize the mesage for the MATR task
69 69 msgForPRC.norm = current_ring_node_asm_norm_f2;
70 70 msgForPRC.burst_sbm = NULL;
71 71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
72 72 //
73 73 //****************************************
74 74
75 75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
76 76
77 77 // compute the average and store it in the averaged_sm_f2 buffer
78 78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
79 79 nodeForAveraging,
80 80 nb_norm_bp1,
81 81 &msgForPRC );
82 82
83 83 // update nb_average
84 84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
85 85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
86 86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
87 87
88 88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
89 89 {
90 90 nb_norm_bp1 = 0;
91 91 // set another ring for the ASM storage
92 92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
93 93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
94 94 || (lfrCurrentMode == LFR_MODE_SBM2) )
95 95 {
96 96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
97 97 }
98 98 }
99 99
100 100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
101 101 {
102 102 nb_norm_bp2 = 0;
103 103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
104 104 || (lfrCurrentMode == LFR_MODE_SBM2) )
105 105 {
106 106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
107 107 }
108 108 }
109 109
110 110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
111 111 {
112 112 nb_norm_asm = 0;
113 113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
114 114 || (lfrCurrentMode == LFR_MODE_SBM2) )
115 115 {
116 116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
117 117 }
118 118 }
119 119
120 120 //*************************
121 121 // send the message to PRC2
122 122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
123 123 {
124 124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
125 125 }
126 126
127 127 if (status != RTEMS_SUCCESSFUL) {
128 128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
129 129 }
130 130 }
131 131 }
132 132
133 133 rtems_task prc2_task( rtems_task_argument argument )
134 134 {
135 135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
136 136 size_t size; // size of the incoming TC packet
137 137 asm_msg *incomingMsg;
138 138 //
139 139 rtems_status_code status;
140 140 rtems_id queue_id_send;
141 141 rtems_id queue_id_q_p2;
142 bp_packet packet_norm_bp1;
143 bp_packet packet_norm_bp2;
142 bp_packet __attribute__((aligned(4))) packet_norm_bp1;
143 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
144 144 ring_node *current_ring_node_to_send_asm_f2;
145 145 float nbSMInASMNORM;
146 146
147 147 unsigned long long int localTime;
148 148
149 149 size = 0;
150 150 queue_id_send = RTEMS_ID_NONE;
151 151 queue_id_q_p2 = RTEMS_ID_NONE;
152 152 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
153 153 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
154 154
155 155 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
156 156 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
157 157 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
158 158
159 159 //*************
160 160 // NORM headers
161 161 BP_init_header( &packet_norm_bp1,
162 162 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
163 163 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
164 164 BP_init_header( &packet_norm_bp2,
165 165 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
166 166 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
167 167
168 168 status = get_message_queue_id_send( &queue_id_send );
169 169 if (status != RTEMS_SUCCESSFUL)
170 170 {
171 171 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
172 172 }
173 173 status = get_message_queue_id_prc2( &queue_id_q_p2);
174 174 if (status != RTEMS_SUCCESSFUL)
175 175 {
176 176 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
177 177 }
178 178
179 179 BOOT_PRINTF("in PRC2 ***\n")
180 180
181 181 while(1){
182 182 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
183 183 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
184 184
185 185 incomingMsg = (asm_msg*) incomingData;
186 186
187 187 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
188 188
189 189 localTime = getTimeAsUnsignedLongLongInt( );
190 190
191 191 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
192 192
193 193 //*****
194 194 //*****
195 195 // NORM
196 196 //*****
197 197 //*****
198 198 // 1) compress the matrix for Basic Parameters calculation
199 199 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
200 200 nbSMInASMNORM,
201 201 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
202 202 ASM_F2_INDICE_START, CHANNELF2 );
203 203 // BP1_F2
204 204 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
205 205 {
206 206 // 1) compute the BP1 set
207 207 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
208 208 // 2) send the BP1 set
209 209 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 210 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
211 211 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
212 212 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
213 213 BP_send( (char *) &packet_norm_bp1, queue_id_send,
214 214 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
215 215 SID_NORM_BP1_F2 );
216 216 }
217 217 // BP2_F2
218 218 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
219 219 {
220 220 // 1) compute the BP2 set
221 221 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
222 222 // 2) send the BP2 set
223 223 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
224 224 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
225 225 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
226 226 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
227 227 BP_send( (char *) &packet_norm_bp2, queue_id_send,
228 228 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
229 229 SID_NORM_BP2_F2 );
230 230 }
231 231
232 232 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
233 233 {
234 234 // 1) reorganize the ASM and divide
235 235 ASM_reorganize_and_divide( asm_f2_patched_norm,
236 236 (float*) current_ring_node_to_send_asm_f2->buffer_address,
237 237 nb_sm_before_f2.norm_bp1 );
238 238 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
239 239 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
240 240 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
241 241
242 242 // 3) send the spectral matrix packets
243 243 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
244 244
245 245 // change asm ring node
246 246 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
247 247 }
248 248
249 249 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
250 250
251 251 }
252 252 }
253 253
254 254 //**********
255 255 // FUNCTIONS
256 256
257 257 void reset_nb_sm_f2( void )
258 258 {
259 259 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
260 260 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
261 261 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
262 262 }
263 263
264 264 void SM_average_f2( float *averaged_spec_mat_f2,
265 265 ring_node *ring_node,
266 266 unsigned int nbAverageNormF2,
267 267 asm_msg *msgForMATR )
268 268 {
269 269 float sum;
270 270 unsigned int i;
271 271 unsigned char keepMatrix;
272 272
273 273 // test acquisitionTime validity
274 274 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
275 275
276 276 for(i=0; i<TOTAL_SIZE_SM; i++)
277 277 {
278 278 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
279 279 if ( (nbAverageNormF2 == 0) ) // average initialization
280 280 {
281 281 if (keepMatrix == 1) // keep the matrix and add it to the average
282 282 {
283 283 averaged_spec_mat_f2[ i ] = sum;
284 284 }
285 285 else // drop the matrix and initialize the average
286 286 {
287 287 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
288 288 }
289 289 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
290 290 msgForMATR->fineTimeNORM = ring_node->fineTime;
291 291 }
292 292 else
293 293 {
294 294 if (keepMatrix == 1) // keep the matrix and add it to the average
295 295 {
296 296 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
297 297 }
298 298 else
299 299 {
300 300 // nothing to do, the matrix is not valid
301 301 }
302 302 }
303 303 }
304 304
305 305 if (keepMatrix == 1)
306 306 {
307 307 if ( (nbAverageNormF2 == 0) )
308 308 {
309 309 msgForMATR->numberOfSMInASMNORM = 1;
310 310 }
311 311 else
312 312 {
313 313 msgForMATR->numberOfSMInASMNORM++;
314 314 }
315 315 }
316 316 else
317 317 {
318 318 if ( (nbAverageNormF2 == 0) )
319 319 {
320 320 msgForMATR->numberOfSMInASMNORM = 0;
321 321 }
322 322 else
323 323 {
324 324 // nothing to do
325 325 }
326 326 }
327 327 }
328 328
329 329 void init_k_coefficients_prc2( void )
330 330 {
331 331 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
332 332 }
@@ -1,1663 +1,1660
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 14 #include "math.h"
15 15
16 16 //***********
17 17 // RTEMS TASK
18 18
19 19 rtems_task actn_task( rtems_task_argument unused )
20 20 {
21 21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 22 *
23 23 * @param unused is the starting argument of the RTEMS task
24 24 *
25 25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 26 * on the incoming TeleCommand.
27 27 *
28 28 */
29 29
30 30 int result;
31 31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
33 33 size_t size; // size of the incoming TC packet
34 34 unsigned char subtype; // subtype of the current TC packet
35 35 unsigned char time[BYTES_PER_TIME];
36 36 rtems_id queue_rcv_id;
37 37 rtems_id queue_snd_id;
38 38
39 39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 40 size = 0;
41 41 queue_rcv_id = RTEMS_ID_NONE;
42 42 queue_snd_id = RTEMS_ID_NONE;
43 43
44 44 status = get_message_queue_id_recv( &queue_rcv_id );
45 45 if (status != RTEMS_SUCCESSFUL)
46 46 {
47 47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
48 48 }
49 49
50 50 status = get_message_queue_id_send( &queue_snd_id );
51 51 if (status != RTEMS_SUCCESSFUL)
52 52 {
53 53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
54 54 }
55 55
56 56 result = LFR_SUCCESSFUL;
57 57 subtype = 0; // subtype of the current TC packet
58 58
59 59 BOOT_PRINTF("in ACTN *** \n");
60 60
61 61 while(1)
62 62 {
63 63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
64 64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
65 65 getTime( time ); // set time to the current time
66 66 if (status!=RTEMS_SUCCESSFUL)
67 67 {
68 68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
69 69 }
70 70 else
71 71 {
72 72 subtype = TC.serviceSubType;
73 73 switch(subtype)
74 74 {
75 75 case TC_SUBTYPE_RESET:
76 76 result = action_reset( &TC, queue_snd_id, time );
77 77 close_action( &TC, result, queue_snd_id );
78 78 break;
79 79 case TC_SUBTYPE_LOAD_COMM:
80 80 result = action_load_common_par( &TC );
81 81 close_action( &TC, result, queue_snd_id );
82 82 break;
83 83 case TC_SUBTYPE_LOAD_NORM:
84 84 result = action_load_normal_par( &TC, queue_snd_id, time );
85 85 close_action( &TC, result, queue_snd_id );
86 86 break;
87 87 case TC_SUBTYPE_LOAD_BURST:
88 88 result = action_load_burst_par( &TC, queue_snd_id, time );
89 89 close_action( &TC, result, queue_snd_id );
90 90 break;
91 91 case TC_SUBTYPE_LOAD_SBM1:
92 92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
93 93 close_action( &TC, result, queue_snd_id );
94 94 break;
95 95 case TC_SUBTYPE_LOAD_SBM2:
96 96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
97 97 close_action( &TC, result, queue_snd_id );
98 98 break;
99 99 case TC_SUBTYPE_DUMP:
100 100 result = action_dump_par( &TC, queue_snd_id );
101 101 close_action( &TC, result, queue_snd_id );
102 102 break;
103 103 case TC_SUBTYPE_ENTER:
104 104 result = action_enter_mode( &TC, queue_snd_id );
105 105 close_action( &TC, result, queue_snd_id );
106 106 break;
107 107 case TC_SUBTYPE_UPDT_INFO:
108 108 result = action_update_info( &TC, queue_snd_id );
109 109 close_action( &TC, result, queue_snd_id );
110 110 break;
111 111 case TC_SUBTYPE_EN_CAL:
112 112 result = action_enable_calibration( &TC, queue_snd_id, time );
113 113 close_action( &TC, result, queue_snd_id );
114 114 break;
115 115 case TC_SUBTYPE_DIS_CAL:
116 116 result = action_disable_calibration( &TC, queue_snd_id, time );
117 117 close_action( &TC, result, queue_snd_id );
118 118 break;
119 119 case TC_SUBTYPE_LOAD_K:
120 120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
121 121 close_action( &TC, result, queue_snd_id );
122 122 break;
123 123 case TC_SUBTYPE_DUMP_K:
124 124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
125 125 close_action( &TC, result, queue_snd_id );
126 126 break;
127 127 case TC_SUBTYPE_LOAD_FBINS:
128 128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
129 129 close_action( &TC, result, queue_snd_id );
130 130 break;
131 131 case TC_SUBTYPE_LOAD_FILTER_PAR:
132 132 result = action_load_filter_par( &TC, queue_snd_id, time );
133 133 close_action( &TC, result, queue_snd_id );
134 134 break;
135 135 case TC_SUBTYPE_UPDT_TIME:
136 136 result = action_update_time( &TC );
137 137 close_action( &TC, result, queue_snd_id );
138 138 break;
139 139 default:
140 140 break;
141 141 }
142 142 }
143 143 }
144 144 }
145 145
146 146 //***********
147 147 // TC ACTIONS
148 148
149 149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
150 150 {
151 151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
152 152 *
153 153 * @param TC points to the TeleCommand packet that is being processed
154 154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
155 155 *
156 156 */
157 157
158 158 PRINTF("this is the end!!!\n");
159 159 exit(0);
160 160
161 161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
162 162
163 163 return LFR_DEFAULT;
164 164 }
165 165
166 166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
167 167 {
168 168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
169 169 *
170 170 * @param TC points to the TeleCommand packet that is being processed
171 171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
172 172 *
173 173 */
174 174
175 175 rtems_status_code status;
176 176 unsigned char requestedMode;
177 unsigned int *transitionCoarseTime_ptr;
178 177 unsigned int transitionCoarseTime;
179 178 unsigned char * bytePosPtr;
180 179
181 180 bytePosPtr = (unsigned char *) &TC->packetID;
182
183 181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
184 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
185 transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK;
186
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
187 184 status = check_mode_value( requestedMode );
188 185
189 186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
190 187 {
191 188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
192 189 }
193 190
194 191 else // the mode value is valid, check the transition
195 192 {
196 193 status = check_mode_transition(requestedMode);
197 194 if (status != LFR_SUCCESSFUL)
198 195 {
199 196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
200 197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
201 198 }
202 199 }
203 200
204 201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
205 202 {
206 203 status = check_transition_date( transitionCoarseTime );
207 204 if (status != LFR_SUCCESSFUL)
208 205 {
209 206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
210 207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
211 208 }
212 209 }
213 210
214 211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
215 212 {
216 213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
217 214
218 215 switch(requestedMode)
219 216 {
220 217 case LFR_MODE_STANDBY:
221 218 status = enter_mode_standby();
222 219 break;
223 220 case LFR_MODE_NORMAL:
224 221 status = enter_mode_normal( transitionCoarseTime );
225 222 break;
226 223 case LFR_MODE_BURST:
227 224 status = enter_mode_burst( transitionCoarseTime );
228 225 break;
229 226 case LFR_MODE_SBM1:
230 227 status = enter_mode_sbm1( transitionCoarseTime );
231 228 break;
232 229 case LFR_MODE_SBM2:
233 230 status = enter_mode_sbm2( transitionCoarseTime );
234 231 break;
235 232 default:
236 233 break;
237 234 }
238 235
239 236 if (status != RTEMS_SUCCESSFUL)
240 237 {
241 238 status = LFR_EXE_ERROR;
242 239 }
243 240 }
244 241
245 242 return status;
246 243 }
247 244
248 245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
249 246 {
250 247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
251 248 *
252 249 * @param TC points to the TeleCommand packet that is being processed
253 250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
254 251 *
255 252 * @return LFR directive status code:
256 253 * - LFR_DEFAULT
257 254 * - LFR_SUCCESSFUL
258 255 *
259 256 */
260 257
261 258 unsigned int val;
262 259 int result;
263 260 unsigned int status;
264 261 unsigned char mode;
265 262 unsigned char * bytePosPtr;
266 263
267 264 bytePosPtr = (unsigned char *) &TC->packetID;
268 265
269 266 // check LFR mode
270 267 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
271 268 status = check_update_info_hk_lfr_mode( mode );
272 269 if (status == LFR_SUCCESSFUL) // check TDS mode
273 270 {
274 271 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
275 272 status = check_update_info_hk_tds_mode( mode );
276 273 }
277 274 if (status == LFR_SUCCESSFUL) // check THR mode
278 275 {
279 276 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
280 277 status = check_update_info_hk_thr_mode( mode );
281 278 }
282 279 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
283 280 {
284 281 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
285 282 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
286 283 val++;
287 284 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
288 285 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
289 286 }
290 287
291 288 // pa_bia_status_info
292 289 // => pa_bia_mode_mux_set 3 bits
293 290 // => pa_bia_mode_hv_enabled 1 bit
294 291 // => pa_bia_mode_bias1_enabled 1 bit
295 292 // => pa_bia_mode_bias2_enabled 1 bit
296 293 // => pa_bia_mode_bias3_enabled 1 bit
297 294 // => pa_bia_on_off (cp_dpu_bias_on_off)
298 295 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
299 296 pa_bia_status_info = pa_bia_status_info
300 297 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
301 298
302 299 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
303 300
304 301 cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
305 302 getReactionWheelsFrequencies( TC );
306 303 build_sy_lfr_rw_masks();
307 304
308 305 // once the masks are built, they have to be merged with the fbins_mask
309 306 merge_fbins_masks();
310 307
311 308 result = status;
312 309
313 310 return result;
314 311 }
315 312
316 313 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
317 314 {
318 315 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
319 316 *
320 317 * @param TC points to the TeleCommand packet that is being processed
321 318 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
322 319 *
323 320 */
324 321
325 322 int result;
326 323
327 324 result = LFR_DEFAULT;
328 325
329 326 setCalibration( true );
330 327
331 328 result = LFR_SUCCESSFUL;
332 329
333 330 return result;
334 331 }
335 332
336 333 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
337 334 {
338 335 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
339 336 *
340 337 * @param TC points to the TeleCommand packet that is being processed
341 338 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
342 339 *
343 340 */
344 341
345 342 int result;
346 343
347 344 result = LFR_DEFAULT;
348 345
349 346 setCalibration( false );
350 347
351 348 result = LFR_SUCCESSFUL;
352 349
353 350 return result;
354 351 }
355 352
356 353 int action_update_time(ccsdsTelecommandPacket_t *TC)
357 354 {
358 355 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
359 356 *
360 357 * @param TC points to the TeleCommand packet that is being processed
361 358 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
362 359 *
363 360 * @return LFR_SUCCESSFUL
364 361 *
365 362 */
366 363
367 364 unsigned int val;
368 365
369 366 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
370 367 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
371 368 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
372 369 + TC->dataAndCRC[BYTE_3];
373 370
374 371 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
375 372 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
376 373 val++;
377 374 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
378 375 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
379 376
380 377 oneTcLfrUpdateTimeReceived = 1;
381 378
382 379 return LFR_SUCCESSFUL;
383 380 }
384 381
385 382 //*******************
386 383 // ENTERING THE MODES
387 384 int check_mode_value( unsigned char requestedMode )
388 385 {
389 386 int status;
390 387
391 388 status = LFR_DEFAULT;
392 389
393 390 if ( (requestedMode != LFR_MODE_STANDBY)
394 391 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
395 392 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
396 393 {
397 394 status = LFR_DEFAULT;
398 395 }
399 396 else
400 397 {
401 398 status = LFR_SUCCESSFUL;
402 399 }
403 400
404 401 return status;
405 402 }
406 403
407 404 int check_mode_transition( unsigned char requestedMode )
408 405 {
409 406 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
410 407 *
411 408 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
412 409 *
413 410 * @return LFR directive status codes:
414 411 * - LFR_SUCCESSFUL - the transition is authorized
415 412 * - LFR_DEFAULT - the transition is not authorized
416 413 *
417 414 */
418 415
419 416 int status;
420 417
421 418 switch (requestedMode)
422 419 {
423 420 case LFR_MODE_STANDBY:
424 421 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
425 422 status = LFR_DEFAULT;
426 423 }
427 424 else
428 425 {
429 426 status = LFR_SUCCESSFUL;
430 427 }
431 428 break;
432 429 case LFR_MODE_NORMAL:
433 430 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
434 431 status = LFR_DEFAULT;
435 432 }
436 433 else {
437 434 status = LFR_SUCCESSFUL;
438 435 }
439 436 break;
440 437 case LFR_MODE_BURST:
441 438 if ( lfrCurrentMode == LFR_MODE_BURST ) {
442 439 status = LFR_DEFAULT;
443 440 }
444 441 else {
445 442 status = LFR_SUCCESSFUL;
446 443 }
447 444 break;
448 445 case LFR_MODE_SBM1:
449 446 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
450 447 status = LFR_DEFAULT;
451 448 }
452 449 else {
453 450 status = LFR_SUCCESSFUL;
454 451 }
455 452 break;
456 453 case LFR_MODE_SBM2:
457 454 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
458 455 status = LFR_DEFAULT;
459 456 }
460 457 else {
461 458 status = LFR_SUCCESSFUL;
462 459 }
463 460 break;
464 461 default:
465 462 status = LFR_DEFAULT;
466 463 break;
467 464 }
468 465
469 466 return status;
470 467 }
471 468
472 469 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
473 470 {
474 471 if (transitionCoarseTime == 0)
475 472 {
476 473 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
477 474 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
478 475 }
479 476 else
480 477 {
481 478 lastValidEnterModeTime = transitionCoarseTime;
482 479 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
483 480 }
484 481 }
485 482
486 483 int check_transition_date( unsigned int transitionCoarseTime )
487 484 {
488 485 int status;
489 486 unsigned int localCoarseTime;
490 487 unsigned int deltaCoarseTime;
491 488
492 489 status = LFR_SUCCESSFUL;
493 490
494 491 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
495 492 {
496 493 status = LFR_SUCCESSFUL;
497 494 }
498 495 else
499 496 {
500 497 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
501 498
502 499 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
503 500
504 501 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
505 502 {
506 503 status = LFR_DEFAULT;
507 504 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
508 505 }
509 506
510 507 if (status == LFR_SUCCESSFUL)
511 508 {
512 509 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
513 510 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
514 511 {
515 512 status = LFR_DEFAULT;
516 513 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
517 514 }
518 515 }
519 516 }
520 517
521 518 return status;
522 519 }
523 520
524 521 int restart_asm_activities( unsigned char lfrRequestedMode )
525 522 {
526 523 rtems_status_code status;
527 524
528 525 status = stop_spectral_matrices();
529 526
530 527 thisIsAnASMRestart = 1;
531 528
532 529 status = restart_asm_tasks( lfrRequestedMode );
533 530
534 531 launch_spectral_matrix();
535 532
536 533 return status;
537 534 }
538 535
539 536 int stop_spectral_matrices( void )
540 537 {
541 538 /** This function stops and restarts the current mode average spectral matrices activities.
542 539 *
543 540 * @return RTEMS directive status codes:
544 541 * - RTEMS_SUCCESSFUL - task restarted successfully
545 542 * - RTEMS_INVALID_ID - task id invalid
546 543 * - RTEMS_ALREADY_SUSPENDED - task already suspended
547 544 *
548 545 */
549 546
550 547 rtems_status_code status;
551 548
552 549 status = RTEMS_SUCCESSFUL;
553 550
554 551 // (1) mask interruptions
555 552 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
556 553
557 554 // (2) reset spectral matrices registers
558 555 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
559 556 reset_sm_status();
560 557
561 558 // (3) clear interruptions
562 559 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
563 560
564 561 // suspend several tasks
565 562 if (lfrCurrentMode != LFR_MODE_STANDBY) {
566 563 status = suspend_asm_tasks();
567 564 }
568 565
569 566 if (status != RTEMS_SUCCESSFUL)
570 567 {
571 568 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
572 569 }
573 570
574 571 return status;
575 572 }
576 573
577 574 int stop_current_mode( void )
578 575 {
579 576 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
580 577 *
581 578 * @return RTEMS directive status codes:
582 579 * - RTEMS_SUCCESSFUL - task restarted successfully
583 580 * - RTEMS_INVALID_ID - task id invalid
584 581 * - RTEMS_ALREADY_SUSPENDED - task already suspended
585 582 *
586 583 */
587 584
588 585 rtems_status_code status;
589 586
590 587 status = RTEMS_SUCCESSFUL;
591 588
592 589 // (1) mask interruptions
593 590 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
594 591 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
595 592
596 593 // (2) reset waveform picker registers
597 594 reset_wfp_burst_enable(); // reset burst and enable bits
598 595 reset_wfp_status(); // reset all the status bits
599 596
600 597 // (3) reset spectral matrices registers
601 598 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
602 599 reset_sm_status();
603 600
604 601 // reset lfr VHDL module
605 602 reset_lfr();
606 603
607 604 reset_extractSWF(); // reset the extractSWF flag to false
608 605
609 606 // (4) clear interruptions
610 607 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
611 608 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
612 609
613 610 // suspend several tasks
614 611 if (lfrCurrentMode != LFR_MODE_STANDBY) {
615 612 status = suspend_science_tasks();
616 613 }
617 614
618 615 if (status != RTEMS_SUCCESSFUL)
619 616 {
620 617 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
621 618 }
622 619
623 620 return status;
624 621 }
625 622
626 623 int enter_mode_standby( void )
627 624 {
628 625 /** This function is used to put LFR in the STANDBY mode.
629 626 *
630 627 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
631 628 *
632 629 * @return RTEMS directive status codes:
633 630 * - RTEMS_SUCCESSFUL - task restarted successfully
634 631 * - RTEMS_INVALID_ID - task id invalid
635 632 * - RTEMS_INCORRECT_STATE - task never started
636 633 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
637 634 *
638 635 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
639 636 * is immediate.
640 637 *
641 638 */
642 639
643 640 int status;
644 641
645 642 status = stop_current_mode(); // STOP THE CURRENT MODE
646 643
647 644 #ifdef PRINT_TASK_STATISTICS
648 645 rtems_cpu_usage_report();
649 646 #endif
650 647
651 648 #ifdef PRINT_STACK_REPORT
652 649 PRINTF("stack report selected\n")
653 650 rtems_stack_checker_report_usage();
654 651 #endif
655 652
656 653 return status;
657 654 }
658 655
659 656 int enter_mode_normal( unsigned int transitionCoarseTime )
660 657 {
661 658 /** This function is used to start the NORMAL mode.
662 659 *
663 660 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
664 661 *
665 662 * @return RTEMS directive status codes:
666 663 * - RTEMS_SUCCESSFUL - task restarted successfully
667 664 * - RTEMS_INVALID_ID - task id invalid
668 665 * - RTEMS_INCORRECT_STATE - task never started
669 666 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
670 667 *
671 668 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
672 669 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
673 670 *
674 671 */
675 672
676 673 int status;
677 674
678 675 #ifdef PRINT_TASK_STATISTICS
679 676 rtems_cpu_usage_reset();
680 677 #endif
681 678
682 679 status = RTEMS_UNSATISFIED;
683 680
684 681 switch( lfrCurrentMode )
685 682 {
686 683 case LFR_MODE_STANDBY:
687 684 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
688 685 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
689 686 {
690 687 launch_spectral_matrix( );
691 688 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
692 689 }
693 690 break;
694 691 case LFR_MODE_BURST:
695 692 status = stop_current_mode(); // stop the current mode
696 693 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
697 694 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
698 695 {
699 696 launch_spectral_matrix( );
700 697 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
701 698 }
702 699 break;
703 700 case LFR_MODE_SBM1:
704 701 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
705 702 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
706 703 update_last_valid_transition_date( transitionCoarseTime );
707 704 break;
708 705 case LFR_MODE_SBM2:
709 706 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
710 707 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
711 708 update_last_valid_transition_date( transitionCoarseTime );
712 709 break;
713 710 default:
714 711 break;
715 712 }
716 713
717 714 if (status != RTEMS_SUCCESSFUL)
718 715 {
719 716 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
720 717 status = RTEMS_UNSATISFIED;
721 718 }
722 719
723 720 return status;
724 721 }
725 722
726 723 int enter_mode_burst( unsigned int transitionCoarseTime )
727 724 {
728 725 /** This function is used to start the BURST mode.
729 726 *
730 727 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
731 728 *
732 729 * @return RTEMS directive status codes:
733 730 * - RTEMS_SUCCESSFUL - task restarted successfully
734 731 * - RTEMS_INVALID_ID - task id invalid
735 732 * - RTEMS_INCORRECT_STATE - task never started
736 733 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
737 734 *
738 735 * The way the BURST mode is started does not depend on the LFR current mode.
739 736 *
740 737 */
741 738
742 739
743 740 int status;
744 741
745 742 #ifdef PRINT_TASK_STATISTICS
746 743 rtems_cpu_usage_reset();
747 744 #endif
748 745
749 746 status = stop_current_mode(); // stop the current mode
750 747 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
751 748 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
752 749 {
753 750 launch_spectral_matrix( );
754 751 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
755 752 }
756 753
757 754 if (status != RTEMS_SUCCESSFUL)
758 755 {
759 756 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
760 757 status = RTEMS_UNSATISFIED;
761 758 }
762 759
763 760 return status;
764 761 }
765 762
766 763 int enter_mode_sbm1( unsigned int transitionCoarseTime )
767 764 {
768 765 /** This function is used to start the SBM1 mode.
769 766 *
770 767 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
771 768 *
772 769 * @return RTEMS directive status codes:
773 770 * - RTEMS_SUCCESSFUL - task restarted successfully
774 771 * - RTEMS_INVALID_ID - task id invalid
775 772 * - RTEMS_INCORRECT_STATE - task never started
776 773 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
777 774 *
778 775 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
779 776 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
780 777 * cases, the acquisition is completely restarted.
781 778 *
782 779 */
783 780
784 781 int status;
785 782
786 783 #ifdef PRINT_TASK_STATISTICS
787 784 rtems_cpu_usage_reset();
788 785 #endif
789 786
790 787 status = RTEMS_UNSATISFIED;
791 788
792 789 switch( lfrCurrentMode )
793 790 {
794 791 case LFR_MODE_STANDBY:
795 792 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
796 793 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
797 794 {
798 795 launch_spectral_matrix( );
799 796 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
800 797 }
801 798 break;
802 799 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
803 800 status = restart_asm_activities( LFR_MODE_SBM1 );
804 801 status = LFR_SUCCESSFUL;
805 802 update_last_valid_transition_date( transitionCoarseTime );
806 803 break;
807 804 case LFR_MODE_BURST:
808 805 status = stop_current_mode(); // stop the current mode
809 806 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
810 807 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
811 808 {
812 809 launch_spectral_matrix( );
813 810 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
814 811 }
815 812 break;
816 813 case LFR_MODE_SBM2:
817 814 status = restart_asm_activities( LFR_MODE_SBM1 );
818 815 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
819 816 update_last_valid_transition_date( transitionCoarseTime );
820 817 break;
821 818 default:
822 819 break;
823 820 }
824 821
825 822 if (status != RTEMS_SUCCESSFUL)
826 823 {
827 824 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
828 825 status = RTEMS_UNSATISFIED;
829 826 }
830 827
831 828 return status;
832 829 }
833 830
834 831 int enter_mode_sbm2( unsigned int transitionCoarseTime )
835 832 {
836 833 /** This function is used to start the SBM2 mode.
837 834 *
838 835 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
839 836 *
840 837 * @return RTEMS directive status codes:
841 838 * - RTEMS_SUCCESSFUL - task restarted successfully
842 839 * - RTEMS_INVALID_ID - task id invalid
843 840 * - RTEMS_INCORRECT_STATE - task never started
844 841 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
845 842 *
846 843 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
847 844 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
848 845 * cases, the acquisition is completely restarted.
849 846 *
850 847 */
851 848
852 849 int status;
853 850
854 851 #ifdef PRINT_TASK_STATISTICS
855 852 rtems_cpu_usage_reset();
856 853 #endif
857 854
858 855 status = RTEMS_UNSATISFIED;
859 856
860 857 switch( lfrCurrentMode )
861 858 {
862 859 case LFR_MODE_STANDBY:
863 860 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
864 861 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
865 862 {
866 863 launch_spectral_matrix( );
867 864 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
868 865 }
869 866 break;
870 867 case LFR_MODE_NORMAL:
871 868 status = restart_asm_activities( LFR_MODE_SBM2 );
872 869 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
873 870 update_last_valid_transition_date( transitionCoarseTime );
874 871 break;
875 872 case LFR_MODE_BURST:
876 873 status = stop_current_mode(); // stop the current mode
877 874 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
878 875 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
879 876 {
880 877 launch_spectral_matrix( );
881 878 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
882 879 }
883 880 break;
884 881 case LFR_MODE_SBM1:
885 882 status = restart_asm_activities( LFR_MODE_SBM2 );
886 883 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
887 884 update_last_valid_transition_date( transitionCoarseTime );
888 885 break;
889 886 default:
890 887 break;
891 888 }
892 889
893 890 if (status != RTEMS_SUCCESSFUL)
894 891 {
895 892 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
896 893 status = RTEMS_UNSATISFIED;
897 894 }
898 895
899 896 return status;
900 897 }
901 898
902 899 int restart_science_tasks( unsigned char lfrRequestedMode )
903 900 {
904 901 /** This function is used to restart all science tasks.
905 902 *
906 903 * @return RTEMS directive status codes:
907 904 * - RTEMS_SUCCESSFUL - task restarted successfully
908 905 * - RTEMS_INVALID_ID - task id invalid
909 906 * - RTEMS_INCORRECT_STATE - task never started
910 907 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
911 908 *
912 909 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
913 910 *
914 911 */
915 912
916 913 rtems_status_code status[NB_SCIENCE_TASKS];
917 914 rtems_status_code ret;
918 915
919 916 ret = RTEMS_SUCCESSFUL;
920 917
921 918 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
922 919 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
923 920 {
924 921 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
925 922 }
926 923
927 924 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
928 925 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
929 926 {
930 927 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
931 928 }
932 929
933 930 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
934 931 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
935 932 {
936 933 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
937 934 }
938 935
939 936 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
940 937 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
941 938 {
942 939 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
943 940 }
944 941
945 942 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
946 943 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
947 944 {
948 945 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
949 946 }
950 947
951 948 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
952 949 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
953 950 {
954 951 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
955 952 }
956 953
957 954 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
958 955 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
959 956 {
960 957 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
961 958 }
962 959
963 960 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
964 961 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
965 962 {
966 963 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
967 964 }
968 965
969 966 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
970 967 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
971 968 {
972 969 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
973 970 }
974 971
975 972 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
976 973 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
977 974 {
978 975 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
979 976 }
980 977
981 978 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
982 979 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
983 980 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
984 981 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
985 982 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
986 983 {
987 984 ret = RTEMS_UNSATISFIED;
988 985 }
989 986
990 987 return ret;
991 988 }
992 989
993 990 int restart_asm_tasks( unsigned char lfrRequestedMode )
994 991 {
995 992 /** This function is used to restart average spectral matrices tasks.
996 993 *
997 994 * @return RTEMS directive status codes:
998 995 * - RTEMS_SUCCESSFUL - task restarted successfully
999 996 * - RTEMS_INVALID_ID - task id invalid
1000 997 * - RTEMS_INCORRECT_STATE - task never started
1001 998 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1002 999 *
1003 1000 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1004 1001 *
1005 1002 */
1006 1003
1007 1004 rtems_status_code status[NB_ASM_TASKS];
1008 1005 rtems_status_code ret;
1009 1006
1010 1007 ret = RTEMS_SUCCESSFUL;
1011 1008
1012 1009 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1013 1010 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1014 1011 {
1015 1012 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1016 1013 }
1017 1014
1018 1015 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1019 1016 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1020 1017 {
1021 1018 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1022 1019 }
1023 1020
1024 1021 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1025 1022 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1026 1023 {
1027 1024 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1028 1025 }
1029 1026
1030 1027 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1031 1028 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1032 1029 {
1033 1030 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1034 1031 }
1035 1032
1036 1033 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1037 1034 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1038 1035 {
1039 1036 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1040 1037 }
1041 1038
1042 1039 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1043 1040 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1044 1041 {
1045 1042 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1046 1043 }
1047 1044
1048 1045 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1049 1046 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1050 1047 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1051 1048 {
1052 1049 ret = RTEMS_UNSATISFIED;
1053 1050 }
1054 1051
1055 1052 return ret;
1056 1053 }
1057 1054
1058 1055 int suspend_science_tasks( void )
1059 1056 {
1060 1057 /** This function suspends the science tasks.
1061 1058 *
1062 1059 * @return RTEMS directive status codes:
1063 1060 * - RTEMS_SUCCESSFUL - task restarted successfully
1064 1061 * - RTEMS_INVALID_ID - task id invalid
1065 1062 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1066 1063 *
1067 1064 */
1068 1065
1069 1066 rtems_status_code status;
1070 1067
1071 1068 PRINTF("in suspend_science_tasks\n")
1072 1069
1073 1070 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1074 1071 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1075 1072 {
1076 1073 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1077 1074 }
1078 1075 else
1079 1076 {
1080 1077 status = RTEMS_SUCCESSFUL;
1081 1078 }
1082 1079 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1083 1080 {
1084 1081 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1085 1082 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1086 1083 {
1087 1084 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1088 1085 }
1089 1086 else
1090 1087 {
1091 1088 status = RTEMS_SUCCESSFUL;
1092 1089 }
1093 1090 }
1094 1091 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1095 1092 {
1096 1093 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1097 1094 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1098 1095 {
1099 1096 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1100 1097 }
1101 1098 else
1102 1099 {
1103 1100 status = RTEMS_SUCCESSFUL;
1104 1101 }
1105 1102 }
1106 1103 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1107 1104 {
1108 1105 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1109 1106 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1110 1107 {
1111 1108 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1112 1109 }
1113 1110 else
1114 1111 {
1115 1112 status = RTEMS_SUCCESSFUL;
1116 1113 }
1117 1114 }
1118 1115 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1119 1116 {
1120 1117 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1121 1118 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1122 1119 {
1123 1120 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1124 1121 }
1125 1122 else
1126 1123 {
1127 1124 status = RTEMS_SUCCESSFUL;
1128 1125 }
1129 1126 }
1130 1127 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1131 1128 {
1132 1129 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1133 1130 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1134 1131 {
1135 1132 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1136 1133 }
1137 1134 else
1138 1135 {
1139 1136 status = RTEMS_SUCCESSFUL;
1140 1137 }
1141 1138 }
1142 1139 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1143 1140 {
1144 1141 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1145 1142 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1146 1143 {
1147 1144 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1148 1145 }
1149 1146 else
1150 1147 {
1151 1148 status = RTEMS_SUCCESSFUL;
1152 1149 }
1153 1150 }
1154 1151 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1155 1152 {
1156 1153 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1157 1154 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1158 1155 {
1159 1156 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1160 1157 }
1161 1158 else
1162 1159 {
1163 1160 status = RTEMS_SUCCESSFUL;
1164 1161 }
1165 1162 }
1166 1163 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1167 1164 {
1168 1165 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1169 1166 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1170 1167 {
1171 1168 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1172 1169 }
1173 1170 else
1174 1171 {
1175 1172 status = RTEMS_SUCCESSFUL;
1176 1173 }
1177 1174 }
1178 1175 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1179 1176 {
1180 1177 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1181 1178 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1182 1179 {
1183 1180 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1184 1181 }
1185 1182 else
1186 1183 {
1187 1184 status = RTEMS_SUCCESSFUL;
1188 1185 }
1189 1186 }
1190 1187
1191 1188 return status;
1192 1189 }
1193 1190
1194 1191 int suspend_asm_tasks( void )
1195 1192 {
1196 1193 /** This function suspends the science tasks.
1197 1194 *
1198 1195 * @return RTEMS directive status codes:
1199 1196 * - RTEMS_SUCCESSFUL - task restarted successfully
1200 1197 * - RTEMS_INVALID_ID - task id invalid
1201 1198 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1202 1199 *
1203 1200 */
1204 1201
1205 1202 rtems_status_code status;
1206 1203
1207 1204 PRINTF("in suspend_science_tasks\n")
1208 1205
1209 1206 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1210 1207 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1211 1208 {
1212 1209 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1213 1210 }
1214 1211 else
1215 1212 {
1216 1213 status = RTEMS_SUCCESSFUL;
1217 1214 }
1218 1215
1219 1216 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1220 1217 {
1221 1218 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1222 1219 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1223 1220 {
1224 1221 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1225 1222 }
1226 1223 else
1227 1224 {
1228 1225 status = RTEMS_SUCCESSFUL;
1229 1226 }
1230 1227 }
1231 1228
1232 1229 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1233 1230 {
1234 1231 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1235 1232 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1236 1233 {
1237 1234 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1238 1235 }
1239 1236 else
1240 1237 {
1241 1238 status = RTEMS_SUCCESSFUL;
1242 1239 }
1243 1240 }
1244 1241
1245 1242 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1246 1243 {
1247 1244 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1248 1245 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1249 1246 {
1250 1247 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1251 1248 }
1252 1249 else
1253 1250 {
1254 1251 status = RTEMS_SUCCESSFUL;
1255 1252 }
1256 1253 }
1257 1254
1258 1255 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1259 1256 {
1260 1257 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1261 1258 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1262 1259 {
1263 1260 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1264 1261 }
1265 1262 else
1266 1263 {
1267 1264 status = RTEMS_SUCCESSFUL;
1268 1265 }
1269 1266 }
1270 1267
1271 1268 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1272 1269 {
1273 1270 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1274 1271 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1275 1272 {
1276 1273 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1277 1274 }
1278 1275 else
1279 1276 {
1280 1277 status = RTEMS_SUCCESSFUL;
1281 1278 }
1282 1279 }
1283 1280
1284 1281 return status;
1285 1282 }
1286 1283
1287 1284 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1288 1285 {
1289 1286
1290 1287 WFP_reset_current_ring_nodes();
1291 1288
1292 1289 reset_waveform_picker_regs();
1293 1290
1294 1291 set_wfp_burst_enable_register( mode );
1295 1292
1296 1293 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1297 1294 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1298 1295
1299 1296 if (transitionCoarseTime == 0)
1300 1297 {
1301 1298 // instant transition means transition on the next valid date
1302 1299 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1303 1300 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1304 1301 }
1305 1302 else
1306 1303 {
1307 1304 waveform_picker_regs->start_date = transitionCoarseTime;
1308 1305 }
1309 1306
1310 1307 update_last_valid_transition_date(waveform_picker_regs->start_date);
1311 1308
1312 1309 }
1313 1310
1314 1311 void launch_spectral_matrix( void )
1315 1312 {
1316 1313 SM_reset_current_ring_nodes();
1317 1314
1318 1315 reset_spectral_matrix_regs();
1319 1316
1320 1317 reset_nb_sm();
1321 1318
1322 1319 set_sm_irq_onNewMatrix( 1 );
1323 1320
1324 1321 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1325 1322 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1326 1323
1327 1324 }
1328 1325
1329 1326 void set_sm_irq_onNewMatrix( unsigned char value )
1330 1327 {
1331 1328 if (value == 1)
1332 1329 {
1333 1330 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1334 1331 }
1335 1332 else
1336 1333 {
1337 1334 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1338 1335 }
1339 1336 }
1340 1337
1341 1338 void set_sm_irq_onError( unsigned char value )
1342 1339 {
1343 1340 if (value == 1)
1344 1341 {
1345 1342 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1346 1343 }
1347 1344 else
1348 1345 {
1349 1346 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1350 1347 }
1351 1348 }
1352 1349
1353 1350 //*****************************
1354 1351 // CONFIGURE CALIBRATION SIGNAL
1355 1352 void setCalibrationPrescaler( unsigned int prescaler )
1356 1353 {
1357 1354 // prescaling of the master clock (25 MHz)
1358 1355 // master clock is divided by 2^prescaler
1359 1356 time_management_regs->calPrescaler = prescaler;
1360 1357 }
1361 1358
1362 1359 void setCalibrationDivisor( unsigned int divisionFactor )
1363 1360 {
1364 1361 // division of the prescaled clock by the division factor
1365 1362 time_management_regs->calDivisor = divisionFactor;
1366 1363 }
1367 1364
1368 1365 void setCalibrationData( void )
1369 1366 {
1370 1367 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1371 1368 *
1372 1369 * @param void
1373 1370 *
1374 1371 * @return void
1375 1372 *
1376 1373 */
1377 1374
1378 1375 unsigned int k;
1379 1376 unsigned short data;
1380 1377 float val;
1381 1378 float Ts;
1382 1379
1383 1380 time_management_regs->calDataPtr = INIT_CHAR;
1384 1381
1385 1382 Ts = 1 / CAL_FS;
1386 1383
1387 1384 // build the signal for the SCM calibration
1388 1385 for (k = 0; k < CAL_NB_PTS; k++)
1389 1386 {
1390 val = sin( 2 * pi * CAL_F0 * k * Ts )
1391 + sin( 2 * pi * CAL_F1 * k * Ts );
1387 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1388 + CAL_A1 * sin( CAL_W1 * k * Ts );
1392 1389 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1393 1390 time_management_regs->calData = data & CAL_DATA_MASK;
1394 1391 }
1395 1392 }
1396 1393
1397 1394 void setCalibrationDataInterleaved( void )
1398 1395 {
1399 1396 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1400 1397 *
1401 1398 * @param void
1402 1399 *
1403 1400 * @return void
1404 1401 *
1405 1402 * In interleaved mode, one can store more values than in normal mode.
1406 1403 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1407 1404 * T store 3 values, one need two write operations.
1408 1405 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1409 1406 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1410 1407 *
1411 1408 */
1412 1409
1413 1410 unsigned int k;
1414 1411 float val;
1415 1412 float Ts;
1416 1413 unsigned short data[CAL_NB_PTS_INTER];
1417 1414 unsigned char *dataPtr;
1418 1415
1419 1416 Ts = 1 / CAL_FS_INTER;
1420 1417
1421 1418 time_management_regs->calDataPtr = INIT_CHAR;
1422 1419
1423 1420 // build the signal for the SCM calibration
1424 1421 for (k=0; k<CAL_NB_PTS_INTER; k++)
1425 1422 {
1426 1423 val = sin( 2 * pi * CAL_F0 * k * Ts )
1427 1424 + sin( 2 * pi * CAL_F1 * k * Ts );
1428 1425 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1429 1426 }
1430 1427
1431 1428 // write the signal in interleaved mode
1432 1429 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1433 1430 {
1434 1431 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1435 1432 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1436 1433 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1437 1434 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1438 1435 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1439 1436 }
1440 1437 }
1441 1438
1442 1439 void setCalibrationReload( bool state)
1443 1440 {
1444 1441 if (state == true)
1445 1442 {
1446 1443 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1447 1444 }
1448 1445 else
1449 1446 {
1450 1447 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1451 1448 }
1452 1449 }
1453 1450
1454 1451 void setCalibrationEnable( bool state )
1455 1452 {
1456 1453 // this bit drives the multiplexer
1457 1454 if (state == true)
1458 1455 {
1459 1456 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1460 1457 }
1461 1458 else
1462 1459 {
1463 1460 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1464 1461 }
1465 1462 }
1466 1463
1467 1464 void setCalibrationInterleaved( bool state )
1468 1465 {
1469 1466 // this bit drives the multiplexer
1470 1467 if (state == true)
1471 1468 {
1472 1469 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1473 1470 }
1474 1471 else
1475 1472 {
1476 1473 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1477 1474 }
1478 1475 }
1479 1476
1480 1477 void setCalibration( bool state )
1481 1478 {
1482 1479 if (state == true)
1483 1480 {
1484 1481 setCalibrationEnable( true );
1485 1482 setCalibrationReload( false );
1486 1483 set_hk_lfr_calib_enable( true );
1487 1484 }
1488 1485 else
1489 1486 {
1490 1487 setCalibrationEnable( false );
1491 1488 setCalibrationReload( true );
1492 1489 set_hk_lfr_calib_enable( false );
1493 1490 }
1494 1491 }
1495 1492
1496 1493 void configureCalibration( bool interleaved )
1497 1494 {
1498 1495 setCalibration( false );
1499 1496 if ( interleaved == true )
1500 1497 {
1501 1498 setCalibrationInterleaved( true );
1502 1499 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1503 1500 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1504 1501 setCalibrationDataInterleaved();
1505 1502 }
1506 1503 else
1507 1504 {
1508 1505 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1509 1506 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1510 1507 setCalibrationData();
1511 1508 }
1512 1509 }
1513 1510
1514 1511 //****************
1515 1512 // CLOSING ACTIONS
1516 1513 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1517 1514 {
1518 1515 /** This function is used to update the HK packets statistics after a successful TC execution.
1519 1516 *
1520 1517 * @param TC points to the TC being processed
1521 1518 * @param time is the time used to date the TC execution
1522 1519 *
1523 1520 */
1524 1521
1525 1522 unsigned int val;
1526 1523
1527 1524 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1528 1525 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1529 1526 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1530 1527 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1531 1528 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1532 1529 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1533 1530 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1534 1531 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1535 1532 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1536 1533 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1537 1534 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1538 1535 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1539 1536
1540 1537 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1541 1538 val++;
1542 1539 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1543 1540 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1544 1541 }
1545 1542
1546 1543 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1547 1544 {
1548 1545 /** This function is used to update the HK packets statistics after a TC rejection.
1549 1546 *
1550 1547 * @param TC points to the TC being processed
1551 1548 * @param time is the time used to date the TC rejection
1552 1549 *
1553 1550 */
1554 1551
1555 1552 unsigned int val;
1556 1553
1557 1554 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1558 1555 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1559 1556 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1560 1557 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1561 1558 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1562 1559 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1563 1560 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1564 1561 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1565 1562 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1566 1563 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1567 1564 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1568 1565 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1569 1566
1570 1567 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1571 1568 val++;
1572 1569 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1573 1570 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1574 1571 }
1575 1572
1576 1573 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1577 1574 {
1578 1575 /** This function is the last step of the TC execution workflow.
1579 1576 *
1580 1577 * @param TC points to the TC being processed
1581 1578 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1582 1579 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1583 1580 * @param time is the time used to date the TC execution
1584 1581 *
1585 1582 */
1586 1583
1587 1584 unsigned char requestedMode;
1588 1585
1589 1586 if (result == LFR_SUCCESSFUL)
1590 1587 {
1591 1588 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1592 1589 &
1593 1590 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1594 1591 )
1595 1592 {
1596 1593 send_tm_lfr_tc_exe_success( TC, queue_id );
1597 1594 }
1598 1595 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1599 1596 {
1600 1597 //**********************************
1601 1598 // UPDATE THE LFRMODE LOCAL VARIABLE
1602 1599 requestedMode = TC->dataAndCRC[1];
1603 1600 updateLFRCurrentMode( requestedMode );
1604 1601 }
1605 1602 }
1606 1603 else if (result == LFR_EXE_ERROR)
1607 1604 {
1608 1605 send_tm_lfr_tc_exe_error( TC, queue_id );
1609 1606 }
1610 1607 }
1611 1608
1612 1609 //***************************
1613 1610 // Interrupt Service Routines
1614 1611 rtems_isr commutation_isr1( rtems_vector_number vector )
1615 1612 {
1616 1613 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1617 1614 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1618 1615 }
1619 1616 }
1620 1617
1621 1618 rtems_isr commutation_isr2( rtems_vector_number vector )
1622 1619 {
1623 1620 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1624 1621 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1625 1622 }
1626 1623 }
1627 1624
1628 1625 //****************
1629 1626 // OTHER FUNCTIONS
1630 1627 void updateLFRCurrentMode( unsigned char requestedMode )
1631 1628 {
1632 1629 /** This function updates the value of the global variable lfrCurrentMode.
1633 1630 *
1634 1631 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1635 1632 *
1636 1633 */
1637 1634
1638 1635 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1639 1636 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1640 1637 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1641 1638 lfrCurrentMode = requestedMode;
1642 1639 }
1643 1640
1644 1641 void set_lfr_soft_reset( unsigned char value )
1645 1642 {
1646 1643 if (value == 1)
1647 1644 {
1648 1645 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1649 1646 }
1650 1647 else
1651 1648 {
1652 1649 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1653 1650 }
1654 1651 }
1655 1652
1656 1653 void reset_lfr( void )
1657 1654 {
1658 1655 set_lfr_soft_reset( 1 );
1659 1656
1660 1657 set_lfr_soft_reset( 0 );
1661 1658
1662 1659 set_hk_lfr_sc_potential_flag( true );
1663 1660 }
@@ -1,1657 +1,1693
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
18 18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
19 19 ring_node kcoefficient_node_1 = {0};
20 20 ring_node kcoefficient_node_2 = {0};
21 21
22 22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 23 {
24 24 /** This function updates the LFR registers with the incoming common parameters.
25 25 *
26 26 * @param TC points to the TeleCommand packet that is being processed
27 27 *
28 28 *
29 29 */
30 30
31 31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 33 set_wfp_data_shaping( );
34 34 return LFR_SUCCESSFUL;
35 35 }
36 36
37 37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 38 {
39 39 /** This function updates the LFR registers with the incoming normal parameters.
40 40 *
41 41 * @param TC points to the TeleCommand packet that is being processed
42 42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 43 *
44 44 */
45 45
46 46 int result;
47 47 int flag;
48 48 rtems_status_code status;
49 49
50 50 flag = LFR_SUCCESSFUL;
51 51
52 52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 55 flag = LFR_DEFAULT;
56 56 }
57 57
58 58 // CHECK THE PARAMETERS SET CONSISTENCY
59 59 if (flag == LFR_SUCCESSFUL)
60 60 {
61 61 flag = check_normal_par_consistency( TC, queue_id );
62 62 }
63 63
64 64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 65 if (flag == LFR_SUCCESSFUL)
66 66 {
67 67 result = set_sy_lfr_n_swf_l( TC );
68 68 result = set_sy_lfr_n_swf_p( TC );
69 69 result = set_sy_lfr_n_bp_p0( TC );
70 70 result = set_sy_lfr_n_bp_p1( TC );
71 71 result = set_sy_lfr_n_asm_p( TC );
72 72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 73 }
74 74
75 75 return flag;
76 76 }
77 77
78 78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 79 {
80 80 /** This function updates the LFR registers with the incoming burst parameters.
81 81 *
82 82 * @param TC points to the TeleCommand packet that is being processed
83 83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 84 *
85 85 */
86 86
87 87 int flag;
88 88 rtems_status_code status;
89 89 unsigned char sy_lfr_b_bp_p0;
90 90 unsigned char sy_lfr_b_bp_p1;
91 91 float aux;
92 92
93 93 flag = LFR_SUCCESSFUL;
94 94
95 95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 97 flag = LFR_DEFAULT;
98 98 }
99 99
100 100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102 102
103 103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 104 if (flag == LFR_SUCCESSFUL)
105 105 {
106 106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 107 {
108 108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 109 flag = WRONG_APP_DATA;
110 110 }
111 111 }
112 112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 113 if (flag == LFR_SUCCESSFUL)
114 114 {
115 115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 116 {
117 117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 118 flag = WRONG_APP_DATA;
119 119 }
120 120 }
121 121 //****************************************************************
122 122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 123 if (flag == LFR_SUCCESSFUL)
124 124 {
125 125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 128 if (aux > FLOAT_EQUAL_ZERO)
129 129 {
130 130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 131 flag = LFR_DEFAULT;
132 132 }
133 133 }
134 134
135 135 // SET THE PARAMETERS
136 136 if (flag == LFR_SUCCESSFUL)
137 137 {
138 138 flag = set_sy_lfr_b_bp_p0( TC );
139 139 flag = set_sy_lfr_b_bp_p1( TC );
140 140 }
141 141
142 142 return flag;
143 143 }
144 144
145 145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 146 {
147 147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 148 *
149 149 * @param TC points to the TeleCommand packet that is being processed
150 150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 151 *
152 152 */
153 153
154 154 int flag;
155 155 rtems_status_code status;
156 156 unsigned char sy_lfr_s1_bp_p0;
157 157 unsigned char sy_lfr_s1_bp_p1;
158 158 float aux;
159 159
160 160 flag = LFR_SUCCESSFUL;
161 161
162 162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 164 flag = LFR_DEFAULT;
165 165 }
166 166
167 167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169 169
170 170 // sy_lfr_s1_bp_p0
171 171 if (flag == LFR_SUCCESSFUL)
172 172 {
173 173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 174 {
175 175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 176 flag = WRONG_APP_DATA;
177 177 }
178 178 }
179 179 // sy_lfr_s1_bp_p1
180 180 if (flag == LFR_SUCCESSFUL)
181 181 {
182 182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 183 {
184 184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 185 flag = WRONG_APP_DATA;
186 186 }
187 187 }
188 188 //******************************************************************
189 189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 190 if (flag == LFR_SUCCESSFUL)
191 191 {
192 192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 194 if (aux > FLOAT_EQUAL_ZERO)
195 195 {
196 196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 197 flag = LFR_DEFAULT;
198 198 }
199 199 }
200 200
201 201 // SET THE PARAMETERS
202 202 if (flag == LFR_SUCCESSFUL)
203 203 {
204 204 flag = set_sy_lfr_s1_bp_p0( TC );
205 205 flag = set_sy_lfr_s1_bp_p1( TC );
206 206 }
207 207
208 208 return flag;
209 209 }
210 210
211 211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 212 {
213 213 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 214 *
215 215 * @param TC points to the TeleCommand packet that is being processed
216 216 * @param queue_id is the id of the queue which handles TM related to this execution step
217 217 *
218 218 */
219 219
220 220 int flag;
221 221 rtems_status_code status;
222 222 unsigned char sy_lfr_s2_bp_p0;
223 223 unsigned char sy_lfr_s2_bp_p1;
224 224 float aux;
225 225
226 226 flag = LFR_SUCCESSFUL;
227 227
228 228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 230 flag = LFR_DEFAULT;
231 231 }
232 232
233 233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235 235
236 236 // sy_lfr_s2_bp_p0
237 237 if (flag == LFR_SUCCESSFUL)
238 238 {
239 239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 240 {
241 241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 242 flag = WRONG_APP_DATA;
243 243 }
244 244 }
245 245 // sy_lfr_s2_bp_p1
246 246 if (flag == LFR_SUCCESSFUL)
247 247 {
248 248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 249 {
250 250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 251 flag = WRONG_APP_DATA;
252 252 }
253 253 }
254 254 //******************************************************************
255 255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 256 if (flag == LFR_SUCCESSFUL)
257 257 {
258 258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 261 if (aux > FLOAT_EQUAL_ZERO)
262 262 {
263 263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 264 flag = LFR_DEFAULT;
265 265 }
266 266 }
267 267
268 268 // SET THE PARAMETERS
269 269 if (flag == LFR_SUCCESSFUL)
270 270 {
271 271 flag = set_sy_lfr_s2_bp_p0( TC );
272 272 flag = set_sy_lfr_s2_bp_p1( TC );
273 273 }
274 274
275 275 return flag;
276 276 }
277 277
278 278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 279 {
280 280 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 281 *
282 282 * @param TC points to the TeleCommand packet that is being processed
283 283 * @param queue_id is the id of the queue which handles TM related to this execution step
284 284 *
285 285 */
286 286
287 287 int flag;
288 288
289 289 flag = LFR_DEFAULT;
290 290
291 291 flag = set_sy_lfr_kcoeff( TC, queue_id );
292 292
293 293 return flag;
294 294 }
295 295
296 296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 297 {
298 298 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 299 *
300 300 * @param TC points to the TeleCommand packet that is being processed
301 301 * @param queue_id is the id of the queue which handles TM related to this execution step
302 302 *
303 303 */
304 304
305 305 int flag;
306 306
307 307 flag = LFR_DEFAULT;
308 308
309 309 flag = set_sy_lfr_fbins( TC );
310 310
311 311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 312 merge_fbins_masks();
313 313
314 314 return flag;
315 315 }
316 316
317 317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 318 {
319 319 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 320 *
321 321 * @param TC points to the TeleCommand packet that is being processed
322 322 * @param queue_id is the id of the queue which handles TM related to this execution step
323 323 *
324 324 */
325 325
326 326 int flag;
327 327
328 328 flag = LFR_DEFAULT;
329 329
330 330 flag = check_sy_lfr_filter_parameters( TC, queue_id );
331 331
332 332 if (flag == LFR_SUCCESSFUL)
333 333 {
334 334 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
335 335 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
336 336 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
337 337 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
338 338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
339 339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
340 340 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
341 341 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
342 342 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
343 343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
344 344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
345 345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
346 346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
347 347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
348 348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
349 349
350 350 //****************************
351 351 // store PAS filter parameters
352 352 // sy_lfr_pas_filter_enabled
353 353 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
354 354 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
355 355 // sy_lfr_pas_filter_modulus
356 356 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
357 357 // sy_lfr_pas_filter_tbad
358 358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
359 359 parameter_dump_packet.sy_lfr_pas_filter_tbad );
360 360 // sy_lfr_pas_filter_offset
361 361 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
362 362 // sy_lfr_pas_filter_shift
363 363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
364 364 parameter_dump_packet.sy_lfr_pas_filter_shift );
365 365
366 366 //****************************************************
367 367 // store the parameter sy_lfr_sc_rw_delta_f as a float
368 368 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
369 369 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
370 370 }
371 371
372 372 return flag;
373 373 }
374 374
375 375 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
376 376 {
377 377 /** This function updates the LFR registers with the incoming sbm2 parameters.
378 378 *
379 379 * @param TC points to the TeleCommand packet that is being processed
380 380 * @param queue_id is the id of the queue which handles TM related to this execution step
381 381 *
382 382 */
383 383
384 384 unsigned int address;
385 385 rtems_status_code status;
386 386 unsigned int freq;
387 387 unsigned int bin;
388 388 unsigned int coeff;
389 389 unsigned char *kCoeffPtr;
390 390 unsigned char *kCoeffDumpPtr;
391 391
392 392 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
393 393 // F0 => 11 bins
394 394 // F1 => 13 bins
395 395 // F2 => 12 bins
396 396 // 36 bins to dump in two packets (30 bins max per packet)
397 397
398 398 //*********
399 399 // PACKET 1
400 400 // 11 F0 bins, 13 F1 bins and 6 F2 bins
401 401 kcoefficients_dump_1.destinationID = TC->sourceID;
402 402 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
403 403 for( freq = 0;
404 404 freq < NB_BINS_COMPRESSED_SM_F0;
405 405 freq++ )
406 406 {
407 407 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
408 408 bin = freq;
409 409 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
410 410 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
411 411 {
412 412 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
413 413 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
414 414 ]; // 2 for the kcoeff_frequency
415 415 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
416 416 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
417 417 }
418 418 }
419 419 for( freq = NB_BINS_COMPRESSED_SM_F0;
420 420 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
421 421 freq++ )
422 422 {
423 423 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
424 424 bin = freq - NB_BINS_COMPRESSED_SM_F0;
425 425 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
426 426 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
427 427 {
428 428 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
429 429 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
430 430 ]; // 2 for the kcoeff_frequency
431 431 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
432 432 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
433 433 }
434 434 }
435 435 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
436 436 freq < KCOEFF_BLK_NR_PKT1 ;
437 437 freq++ )
438 438 {
439 439 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
440 440 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
441 441 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
442 442 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
443 443 {
444 444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
445 445 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
446 446 ]; // 2 for the kcoeff_frequency
447 447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
448 448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
449 449 }
450 450 }
451 451 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
452 452 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
453 453 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
454 454 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
455 455 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
456 456 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
457 457 // SEND DATA
458 458 kcoefficient_node_1.status = 1;
459 459 address = (unsigned int) &kcoefficient_node_1;
460 460 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
461 461 if (status != RTEMS_SUCCESSFUL) {
462 462 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
463 463 }
464 464
465 465 //********
466 466 // PACKET 2
467 467 // 6 F2 bins
468 468 kcoefficients_dump_2.destinationID = TC->sourceID;
469 469 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
470 470 for( freq = 0;
471 471 freq < KCOEFF_BLK_NR_PKT2;
472 472 freq++ )
473 473 {
474 474 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
475 475 bin = freq + KCOEFF_BLK_NR_PKT2;
476 476 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
477 477 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
478 478 {
479 479 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
480 480 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
481 481 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
482 482 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
483 483 }
484 484 }
485 485 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
486 486 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
487 487 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
488 488 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
489 489 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
490 490 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
491 491 // SEND DATA
492 492 kcoefficient_node_2.status = 1;
493 493 address = (unsigned int) &kcoefficient_node_2;
494 494 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
495 495 if (status != RTEMS_SUCCESSFUL) {
496 496 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
497 497 }
498 498
499 499 return status;
500 500 }
501 501
502 502 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
503 503 {
504 504 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
505 505 *
506 506 * @param queue_id is the id of the queue which handles TM related to this execution step.
507 507 *
508 508 * @return RTEMS directive status codes:
509 509 * - RTEMS_SUCCESSFUL - message sent successfully
510 510 * - RTEMS_INVALID_ID - invalid queue id
511 511 * - RTEMS_INVALID_SIZE - invalid message size
512 512 * - RTEMS_INVALID_ADDRESS - buffer is NULL
513 513 * - RTEMS_UNSATISFIED - out of message buffers
514 514 * - RTEMS_TOO_MANY - queue s limit has been reached
515 515 *
516 516 */
517 517
518 518 int status;
519 519
520 520 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
521 521 parameter_dump_packet.destinationID = TC->sourceID;
522 522
523 523 // UPDATE TIME
524 524 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
525 525 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
526 526 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
527 527 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
528 528 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
529 529 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
530 530 // SEND DATA
531 531 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
532 532 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
533 533 if (status != RTEMS_SUCCESSFUL) {
534 534 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
535 535 }
536 536
537 537 return status;
538 538 }
539 539
540 540 //***********************
541 541 // NORMAL MODE PARAMETERS
542 542
543 543 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
544 544 {
545 545 unsigned char msb;
546 546 unsigned char lsb;
547 547 int flag;
548 548 float aux;
549 549 rtems_status_code status;
550 550
551 551 unsigned int sy_lfr_n_swf_l;
552 552 unsigned int sy_lfr_n_swf_p;
553 553 unsigned int sy_lfr_n_asm_p;
554 554 unsigned char sy_lfr_n_bp_p0;
555 555 unsigned char sy_lfr_n_bp_p1;
556 556 unsigned char sy_lfr_n_cwf_long_f3;
557 557
558 558 flag = LFR_SUCCESSFUL;
559 559
560 560 //***************
561 561 // get parameters
562 562 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
563 563 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
564 564 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
565 565
566 566 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
567 567 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
568 568 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
569 569
570 570 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
571 571 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
572 572 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
573 573
574 574 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
575 575
576 576 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
577 577
578 578 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
579 579
580 580 //******************
581 581 // check consistency
582 582 // sy_lfr_n_swf_l
583 583 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
584 584 {
585 585 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
586 586 flag = WRONG_APP_DATA;
587 587 }
588 588 // sy_lfr_n_swf_p
589 589 if (flag == LFR_SUCCESSFUL)
590 590 {
591 591 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
592 592 {
593 593 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
594 594 flag = WRONG_APP_DATA;
595 595 }
596 596 }
597 597 // sy_lfr_n_bp_p0
598 598 if (flag == LFR_SUCCESSFUL)
599 599 {
600 600 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
601 601 {
602 602 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
603 603 flag = WRONG_APP_DATA;
604 604 }
605 605 }
606 606 // sy_lfr_n_asm_p
607 607 if (flag == LFR_SUCCESSFUL)
608 608 {
609 609 if (sy_lfr_n_asm_p == 0)
610 610 {
611 611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
612 612 flag = WRONG_APP_DATA;
613 613 }
614 614 }
615 615 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
616 616 if (flag == LFR_SUCCESSFUL)
617 617 {
618 618 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
619 619 if (aux > FLOAT_EQUAL_ZERO)
620 620 {
621 621 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
622 622 flag = WRONG_APP_DATA;
623 623 }
624 624 }
625 625 // sy_lfr_n_bp_p1
626 626 if (flag == LFR_SUCCESSFUL)
627 627 {
628 628 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
629 629 {
630 630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
631 631 flag = WRONG_APP_DATA;
632 632 }
633 633 }
634 634 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
635 635 if (flag == LFR_SUCCESSFUL)
636 636 {
637 637 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
638 638 if (aux > FLOAT_EQUAL_ZERO)
639 639 {
640 640 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
641 641 flag = LFR_DEFAULT;
642 642 }
643 643 }
644 644 // sy_lfr_n_cwf_long_f3
645 645
646 646 return flag;
647 647 }
648 648
649 649 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
650 650 {
651 651 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
652 652 *
653 653 * @param TC points to the TeleCommand packet that is being processed
654 654 * @param queue_id is the id of the queue which handles TM related to this execution step
655 655 *
656 656 */
657 657
658 658 int result;
659 659
660 660 result = LFR_SUCCESSFUL;
661 661
662 662 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
663 663 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
664 664
665 665 return result;
666 666 }
667 667
668 668 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
669 669 {
670 670 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
671 671 *
672 672 * @param TC points to the TeleCommand packet that is being processed
673 673 * @param queue_id is the id of the queue which handles TM related to this execution step
674 674 *
675 675 */
676 676
677 677 int result;
678 678
679 679 result = LFR_SUCCESSFUL;
680 680
681 681 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
682 682 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
683 683
684 684 return result;
685 685 }
686 686
687 687 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
688 688 {
689 689 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
690 690 *
691 691 * @param TC points to the TeleCommand packet that is being processed
692 692 * @param queue_id is the id of the queue which handles TM related to this execution step
693 693 *
694 694 */
695 695
696 696 int result;
697 697
698 698 result = LFR_SUCCESSFUL;
699 699
700 700 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
701 701 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
702 702
703 703 return result;
704 704 }
705 705
706 706 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
707 707 {
708 708 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
709 709 *
710 710 * @param TC points to the TeleCommand packet that is being processed
711 711 * @param queue_id is the id of the queue which handles TM related to this execution step
712 712 *
713 713 */
714 714
715 715 int status;
716 716
717 717 status = LFR_SUCCESSFUL;
718 718
719 719 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
720 720
721 721 return status;
722 722 }
723 723
724 724 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
725 725 {
726 726 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
727 727 *
728 728 * @param TC points to the TeleCommand packet that is being processed
729 729 * @param queue_id is the id of the queue which handles TM related to this execution step
730 730 *
731 731 */
732 732
733 733 int status;
734 734
735 735 status = LFR_SUCCESSFUL;
736 736
737 737 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
738 738
739 739 return status;
740 740 }
741 741
742 742 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
743 743 {
744 744 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
745 745 *
746 746 * @param TC points to the TeleCommand packet that is being processed
747 747 * @param queue_id is the id of the queue which handles TM related to this execution step
748 748 *
749 749 */
750 750
751 751 int status;
752 752
753 753 status = LFR_SUCCESSFUL;
754 754
755 755 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
756 756
757 757 return status;
758 758 }
759 759
760 760 //**********************
761 761 // BURST MODE PARAMETERS
762 762 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
763 763 {
764 764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
765 765 *
766 766 * @param TC points to the TeleCommand packet that is being processed
767 767 * @param queue_id is the id of the queue which handles TM related to this execution step
768 768 *
769 769 */
770 770
771 771 int status;
772 772
773 773 status = LFR_SUCCESSFUL;
774 774
775 775 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
776 776
777 777 return status;
778 778 }
779 779
780 780 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
781 781 {
782 782 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
783 783 *
784 784 * @param TC points to the TeleCommand packet that is being processed
785 785 * @param queue_id is the id of the queue which handles TM related to this execution step
786 786 *
787 787 */
788 788
789 789 int status;
790 790
791 791 status = LFR_SUCCESSFUL;
792 792
793 793 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
794 794
795 795 return status;
796 796 }
797 797
798 798 //*********************
799 799 // SBM1 MODE PARAMETERS
800 800 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
801 801 {
802 802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
803 803 *
804 804 * @param TC points to the TeleCommand packet that is being processed
805 805 * @param queue_id is the id of the queue which handles TM related to this execution step
806 806 *
807 807 */
808 808
809 809 int status;
810 810
811 811 status = LFR_SUCCESSFUL;
812 812
813 813 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
814 814
815 815 return status;
816 816 }
817 817
818 818 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
819 819 {
820 820 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
821 821 *
822 822 * @param TC points to the TeleCommand packet that is being processed
823 823 * @param queue_id is the id of the queue which handles TM related to this execution step
824 824 *
825 825 */
826 826
827 827 int status;
828 828
829 829 status = LFR_SUCCESSFUL;
830 830
831 831 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
832 832
833 833 return status;
834 834 }
835 835
836 836 //*********************
837 837 // SBM2 MODE PARAMETERS
838 838 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
839 839 {
840 840 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
841 841 *
842 842 * @param TC points to the TeleCommand packet that is being processed
843 843 * @param queue_id is the id of the queue which handles TM related to this execution step
844 844 *
845 845 */
846 846
847 847 int status;
848 848
849 849 status = LFR_SUCCESSFUL;
850 850
851 851 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
852 852
853 853 return status;
854 854 }
855 855
856 856 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
857 857 {
858 858 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
859 859 *
860 860 * @param TC points to the TeleCommand packet that is being processed
861 861 * @param queue_id is the id of the queue which handles TM related to this execution step
862 862 *
863 863 */
864 864
865 865 int status;
866 866
867 867 status = LFR_SUCCESSFUL;
868 868
869 869 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
870 870
871 871 return status;
872 872 }
873 873
874 874 //*******************
875 875 // TC_LFR_UPDATE_INFO
876 876 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
877 877 {
878 878 unsigned int status;
879 879
880 880 status = LFR_DEFAULT;
881 881
882 882 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
883 883 || (mode == LFR_MODE_BURST)
884 884 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
885 885 {
886 886 status = LFR_SUCCESSFUL;
887 887 }
888 888 else
889 889 {
890 890 status = LFR_DEFAULT;
891 891 }
892 892
893 893 return status;
894 894 }
895 895
896 896 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
897 897 {
898 898 unsigned int status;
899 899
900 900 status = LFR_DEFAULT;
901 901
902 902 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
903 903 || (mode == TDS_MODE_BURST)
904 904 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
905 905 || (mode == TDS_MODE_LFM))
906 906 {
907 907 status = LFR_SUCCESSFUL;
908 908 }
909 909 else
910 910 {
911 911 status = LFR_DEFAULT;
912 912 }
913 913
914 914 return status;
915 915 }
916 916
917 917 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
918 918 {
919 919 unsigned int status;
920 920
921 921 status = LFR_DEFAULT;
922 922
923 923 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
924 924 || (mode == THR_MODE_BURST))
925 925 {
926 926 status = LFR_SUCCESSFUL;
927 927 }
928 928 else
929 929 {
930 930 status = LFR_DEFAULT;
931 931 }
932 932
933 933 return status;
934 934 }
935 935
936 936 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
937 937 {
938 938 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
939 939 *
940 940 * @param TC points to the TeleCommand packet that is being processed
941 941 *
942 942 */
943 943
944 944 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
945 945
946 946 bytePosPtr = (unsigned char *) &TC->packetID;
947 947
948 948 // cp_rpw_sc_rw1_f1
949 949 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
950 950 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
951 951
952 952 // cp_rpw_sc_rw1_f2
953 953 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
954 954 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
955 955
956 956 // cp_rpw_sc_rw2_f1
957 957 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
958 958 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
959 959
960 960 // cp_rpw_sc_rw2_f2
961 961 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
962 962 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
963 963
964 964 // cp_rpw_sc_rw3_f1
965 965 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
966 966 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
967 967
968 968 // cp_rpw_sc_rw3_f2
969 969 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
970 970 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
971 971
972 972 // cp_rpw_sc_rw4_f1
973 973 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
974 974 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
975 975
976 976 // cp_rpw_sc_rw4_f2
977 977 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
978 978 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
979 979 }
980 980
981 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
981 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag, float sy_lfr_rw_k )
982 982 {
983 983 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
984 984 *
985 985 * @param fbins_mask
986 986 * @param rw_f is the reaction wheel frequency to filter
987 987 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
988 988 * @param flag [true] filtering enabled [false] filtering disabled
989 989 *
990 990 * @return void
991 991 *
992 992 */
993 993
994 994 float f_RW_min;
995 995 float f_RW_MAX;
996 996 float fi_min;
997 997 float fi_MAX;
998 998 float fi;
999 999 float deltaBelow;
1000 1000 float deltaAbove;
1001 float freqToFilterOut;
1001 1002 int binBelow;
1002 1003 int binAbove;
1003 1004 int closestBin;
1004 1005 unsigned int whichByte;
1005 1006 int selectedByte;
1006 1007 int bin;
1007 1008 int binToRemove[NB_BINS_TO_REMOVE];
1008 1009 int k;
1010 bool filteringSet;
1009 1011
1010 1012 closestBin = 0;
1011 1013 whichByte = 0;
1012 1014 bin = 0;
1015 filteringSet = false;
1013 1016
1014 1017 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1015 1018 {
1016 1019 binToRemove[k] = -1;
1017 1020 }
1018 1021
1019 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1020 f_RW_min = rw_f - (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1021 f_RW_MAX = rw_f + (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1022 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1023 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1024 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1022 1025
1023 // compute the index of the frequency bin immediately below rw_f
1024 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1025 deltaBelow = rw_f - binBelow * deltaFreq;
1026 freqToFilterOut = f_RW_min;
1027 while ( filteringSet == false )
1028 {
1029 // compute the index of the frequency bin immediately below rw_f
1030 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1031 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1026 1032
1027 // compute the index of the frequency bin immediately above rw_f
1028 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1029 deltaAbove = binAbove * deltaFreq - rw_f;
1033 // compute the index of the frequency bin immediately above rw_f
1034 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1035 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1030 1036
1031 // search the closest bin
1032 if (deltaAbove > deltaBelow)
1033 {
1034 closestBin = binBelow;
1035 }
1036 else
1037 {
1038 closestBin = binAbove;
1039 }
1037 // search the closest bin
1038 if (deltaAbove > deltaBelow)
1039 {
1040 closestBin = binBelow;
1041 }
1042 else
1043 {
1044 closestBin = binAbove;
1045 }
1040 1046
1041 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1042 fi = closestBin * deltaFreq;
1043 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1044 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1047 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1048 fi = closestBin * deltaFreq;
1049 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1050 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1051
1052 //**************************************************************************************
1053 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1054 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1055 //**************************************************************************************
1045 1056
1046 //**************************************************************************************
1047 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1048 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1049 //**************************************************************************************
1057 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1058 // => remove f_(i), f_(i-1) and f_(i+1)
1059 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1060 {
1061 binToRemove[0] = (closestBin - 1) - 1;
1062 binToRemove[1] = (closestBin) - 1;
1063 binToRemove[2] = (closestBin + 1) - 1;
1064 }
1065 // 2. ELSE
1066 // => remove the two f_(i) which are around f_RW
1067 else
1068 {
1069 binToRemove[0] = (binBelow) - 1;
1070 binToRemove[1] = (binAbove) - 1;
1071 binToRemove[2] = (-1);
1072 }
1050 1073
1051 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1052 // => remove f_(i), f_(i-1) and f_(i+1)
1053 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1054 {
1055 binToRemove[0] = (closestBin - 1) - 1;
1056 binToRemove[1] = (closestBin) - 1;
1057 binToRemove[2] = (closestBin + 1) - 1;
1058 }
1059 // 2. ELSE
1060 // => remove the two f_(i) which are around f_RW
1061 else
1062 {
1063 binToRemove[0] = (binBelow) - 1;
1064 binToRemove[1] = (binAbove) - 1;
1065 binToRemove[2] = (-1);
1066 }
1074 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1075 {
1076 bin = binToRemove[k];
1077 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1078 {
1079 if (flag == 1)
1080 {
1081 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1082 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1083 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1084 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1085 }
1086 }
1087 }
1067 1088
1068 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1069 {
1070 bin = binToRemove[k];
1071 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1089 // update freqToFilterOut
1090 if ( freqToFilterOut == f_RW_MAX )
1091 {
1092 filteringSet = true; // end of the loop
1093 }
1094 else
1072 1095 {
1073 if (flag == 1)
1074 {
1075 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1076 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1077 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1078 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1079 }
1096 freqToFilterOut = freqToFilterOut + deltaFreq;
1097 }
1098
1099 if ( freqToFilterOut > f_RW_MAX)
1100 {
1101 freqToFilterOut = f_RW_MAX;
1080 1102 }
1081 1103 }
1082 1104 }
1083 1105
1084 1106 void build_sy_lfr_rw_mask( unsigned int channel )
1085 1107 {
1086 1108 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1087 1109 unsigned char *maskPtr;
1088 1110 double deltaF;
1089 1111 unsigned k;
1090 1112
1091 1113 k = 0;
1092 1114
1093 1115 maskPtr = NULL;
1094 1116 deltaF = DELTAF_F2;
1095 1117
1096 1118 switch (channel)
1097 1119 {
1098 1120 case CHANNELF0:
1099 1121 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1100 1122 deltaF = DELTAF_F0;
1101 1123 break;
1102 1124 case CHANNELF1:
1103 1125 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1104 1126 deltaF = DELTAF_F1;
1105 1127 break;
1106 1128 case CHANNELF2:
1107 1129 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1108 1130 deltaF = DELTAF_F2;
1109 1131 break;
1110 1132 default:
1111 1133 break;
1112 1134 }
1113 1135
1114 1136 for (k = 0; k < BYTES_PER_MASK; k++)
1115 1137 {
1116 1138 local_rw_fbins_mask[k] = INT8_ALL_F;
1117 1139 }
1118 1140
1119 1141 // RW1 F1
1120 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS ); // [1000 0000]
1142 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS, 1. ); // [1000 0000]
1121 1143
1122 1144 // RW1 F2
1123 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS ); // [0100 0000]
1145 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS, 1. ); // [0100 0000]
1124 1146
1125 1147 // RW2 F1
1126 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS ); // [0010 0000]
1148 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS, 1. ); // [0010 0000]
1127 1149
1128 1150 // RW2 F2
1129 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS ); // [0001 0000]
1151 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS, 1. ); // [0001 0000]
1130 1152
1131 1153 // RW3 F1
1132 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS ); // [0000 1000]
1154 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS, 1. ); // [0000 1000]
1133 1155
1134 1156 // RW3 F2
1135 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS ); // [0000 0100]
1157 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS, 1. ); // [0000 0100]
1136 1158
1137 1159 // RW4 F1
1138 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 ); // [0000 0010]
1160 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 , 1. ); // [0000 0010]
1139 1161
1140 1162 // RW4 F2
1141 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) ); // [0000 0001]
1163 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) , 1.); // [0000 0001]
1142 1164
1143 1165 // update the value of the fbins related to reaction wheels frequency filtering
1144 1166 if (maskPtr != NULL)
1145 1167 {
1146 1168 for (k = 0; k < BYTES_PER_MASK; k++)
1147 1169 {
1148 1170 maskPtr[k] = local_rw_fbins_mask[k];
1149 1171 }
1150 1172 }
1151 1173 }
1152 1174
1153 1175 void build_sy_lfr_rw_masks( void )
1154 1176 {
1155 1177 build_sy_lfr_rw_mask( CHANNELF0 );
1156 1178 build_sy_lfr_rw_mask( CHANNELF1 );
1157 1179 build_sy_lfr_rw_mask( CHANNELF2 );
1158 1180 }
1159 1181
1160 1182 void merge_fbins_masks( void )
1161 1183 {
1162 1184 unsigned char k;
1163 1185
1164 1186 unsigned char *fbins_f0;
1165 1187 unsigned char *fbins_f1;
1166 1188 unsigned char *fbins_f2;
1167 1189 unsigned char *rw_mask_f0;
1168 1190 unsigned char *rw_mask_f1;
1169 1191 unsigned char *rw_mask_f2;
1170 1192
1171 1193 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1172 1194 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1173 1195 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1174 1196 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1175 1197 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1176 1198 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1177 1199
1178 1200 for( k=0; k < BYTES_PER_MASK; k++ )
1179 1201 {
1180 1202 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1181 1203 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1182 1204 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1183 1205 }
1184 1206 }
1185 1207
1186 1208 //***********
1187 1209 // FBINS MASK
1188 1210
1189 1211 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1190 1212 {
1191 1213 int status;
1192 1214 unsigned int k;
1193 1215 unsigned char *fbins_mask_dump;
1194 1216 unsigned char *fbins_mask_TC;
1195 1217
1196 1218 status = LFR_SUCCESSFUL;
1197 1219
1198 1220 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1199 1221 fbins_mask_TC = TC->dataAndCRC;
1200 1222
1201 1223 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1202 1224 {
1203 1225 fbins_mask_dump[k] = fbins_mask_TC[k];
1204 1226 }
1205 1227
1206 1228 return status;
1207 1229 }
1208 1230
1209 1231 //***************************
1210 1232 // TC_LFR_LOAD_PAS_FILTER_PAR
1211 1233
1212 1234 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1213 1235 {
1214 1236 int flag;
1215 1237 rtems_status_code status;
1216 1238
1217 1239 unsigned char sy_lfr_pas_filter_enabled;
1218 1240 unsigned char sy_lfr_pas_filter_modulus;
1219 1241 float sy_lfr_pas_filter_tbad;
1220 1242 unsigned char sy_lfr_pas_filter_offset;
1221 1243 float sy_lfr_pas_filter_shift;
1222 1244 float sy_lfr_sc_rw_delta_f;
1223 1245 char *parPtr;
1224 1246
1225 1247 flag = LFR_SUCCESSFUL;
1226 1248 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1227 1249 sy_lfr_pas_filter_shift = INIT_FLOAT;
1228 1250 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1229 1251 parPtr = NULL;
1230 1252
1231 1253 //***************
1232 1254 // get parameters
1233 1255 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1234 1256 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1235 1257 copyFloatByChar(
1236 1258 (unsigned char*) &sy_lfr_pas_filter_tbad,
1237 1259 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1238 1260 );
1239 1261 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1240 1262 copyFloatByChar(
1241 1263 (unsigned char*) &sy_lfr_pas_filter_shift,
1242 1264 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1243 1265 );
1244 1266 copyFloatByChar(
1245 1267 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1246 1268 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1247 1269 );
1248 1270
1249 1271 //******************
1250 1272 // CHECK CONSISTENCY
1251 1273
1252 1274 //**************************
1253 1275 // sy_lfr_pas_filter_enabled
1254 1276 // nothing to check, value is 0 or 1
1255 1277
1256 1278 //**************************
1257 1279 // sy_lfr_pas_filter_modulus
1258 1280 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1259 1281 {
1260 1282 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1261 1283 flag = WRONG_APP_DATA;
1262 1284 }
1263 1285
1264 1286 //***********************
1265 1287 // sy_lfr_pas_filter_tbad
1266 1288 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1267 1289 {
1268 1290 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1269 1291 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1270 1292 flag = WRONG_APP_DATA;
1271 1293 }
1272 1294
1273 1295 //*************************
1274 1296 // sy_lfr_pas_filter_offset
1275 1297 if (flag == LFR_SUCCESSFUL)
1276 1298 {
1277 1299 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1278 1300 {
1279 1301 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1280 1302 flag = WRONG_APP_DATA;
1281 1303 }
1282 1304 }
1283 1305
1284 1306 //************************
1285 1307 // sy_lfr_pas_filter_shift
1286 1308 if (flag == LFR_SUCCESSFUL)
1287 1309 {
1288 1310 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1289 1311 {
1290 1312 parPtr = (char*) &sy_lfr_pas_filter_shift;
1291 1313 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1292 1314 flag = WRONG_APP_DATA;
1293 1315 }
1294 1316 }
1295 1317
1296 1318 //*************************************
1297 1319 // check global coherency of the values
1298 1320 if (flag == LFR_SUCCESSFUL)
1299 1321 {
1300 1322 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1301 1323 {
1302 1324 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1303 1325 flag = WRONG_APP_DATA;
1304 1326 }
1305 1327 }
1306 1328
1307 1329 //*********************
1308 1330 // sy_lfr_sc_rw_delta_f
1309 1331 // nothing to check, no default value in the ICD
1310 1332
1311 1333 return flag;
1312 1334 }
1313 1335
1314 1336 //**************
1315 1337 // KCOEFFICIENTS
1316 1338 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1317 1339 {
1318 1340 unsigned int kcoeff;
1319 1341 unsigned short sy_lfr_kcoeff_frequency;
1320 1342 unsigned short bin;
1321 unsigned short *freqPtr;
1322 1343 float *kcoeffPtr_norm;
1323 1344 float *kcoeffPtr_sbm;
1324 1345 int status;
1325 1346 unsigned char *kcoeffLoadPtr;
1326 1347 unsigned char *kcoeffNormPtr;
1327 1348 unsigned char *kcoeffSbmPtr_a;
1328 1349 unsigned char *kcoeffSbmPtr_b;
1329 1350
1330 status = LFR_SUCCESSFUL;
1331
1351 sy_lfr_kcoeff_frequency = 0;
1352 bin = 0;
1332 1353 kcoeffPtr_norm = NULL;
1333 1354 kcoeffPtr_sbm = NULL;
1334 bin = 0;
1355 status = LFR_SUCCESSFUL;
1335 1356
1336 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1337 sy_lfr_kcoeff_frequency = *freqPtr;
1357 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1358 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1338 1359
1339 1360 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1340 1361 {
1341 1362 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1342 1363 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1343 1364 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1344 1365 status = LFR_DEFAULT;
1345 1366 }
1346 1367 else
1347 1368 {
1348 1369 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1349 1370 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1350 1371 {
1351 1372 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1352 1373 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1353 1374 bin = sy_lfr_kcoeff_frequency;
1354 1375 }
1355 1376 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1356 1377 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1357 1378 {
1358 1379 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1359 1380 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1360 1381 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1361 1382 }
1362 1383 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1363 1384 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1364 1385 {
1365 1386 kcoeffPtr_norm = k_coeff_intercalib_f2;
1366 1387 kcoeffPtr_sbm = NULL;
1367 1388 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1368 1389 }
1369 1390 }
1370 1391
1371 1392 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1372 1393 {
1373 1394 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1374 1395 {
1375 1396 // destination
1376 1397 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1377 1398 // source
1378 1399 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1379 1400 // copy source to destination
1380 1401 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1381 1402 }
1382 1403 }
1383 1404
1384 1405 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1385 1406 {
1386 1407 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1387 1408 {
1388 1409 // destination
1389 1410 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1390 1411 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1391 1412 // source
1392 1413 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1393 1414 // copy source to destination
1394 1415 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1395 1416 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1396 1417 }
1397 1418 }
1398 1419
1399 // print_k_coeff();
1420 //print_k_coeff();
1400 1421
1401 1422 return status;
1402 1423 }
1403 1424
1404 1425 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1405 1426 {
1406 1427 destination[BYTE_0] = source[BYTE_0];
1407 1428 destination[BYTE_1] = source[BYTE_1];
1408 1429 destination[BYTE_2] = source[BYTE_2];
1409 1430 destination[BYTE_3] = source[BYTE_3];
1410 1431 }
1411 1432
1433 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1434 {
1435 destination[BYTE_0] = source[BYTE_0];
1436 destination[BYTE_1] = source[BYTE_1];
1437 destination[BYTE_2] = source[BYTE_2];
1438 destination[BYTE_3] = source[BYTE_3];
1439 }
1440
1441 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1442 {
1443 destination[BYTE_0] = source[BYTE_0];
1444 destination[BYTE_1] = source[BYTE_1];
1445 }
1446
1412 1447 void floatToChar( float value, unsigned char* ptr)
1413 1448 {
1414 1449 unsigned char* valuePtr;
1415 1450
1416 1451 valuePtr = (unsigned char*) &value;
1452
1417 1453 ptr[BYTE_0] = valuePtr[BYTE_0];
1418 1454 ptr[BYTE_1] = valuePtr[BYTE_1];
1419 1455 ptr[BYTE_2] = valuePtr[BYTE_2];
1420 1456 ptr[BYTE_3] = valuePtr[BYTE_3];
1421 1457 }
1422 1458
1423 1459 //**********
1424 1460 // init dump
1425 1461
1426 1462 void init_parameter_dump( void )
1427 1463 {
1428 1464 /** This function initialize the parameter_dump_packet global variable with default values.
1429 1465 *
1430 1466 */
1431 1467
1432 1468 unsigned int k;
1433 1469
1434 1470 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1435 1471 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1436 1472 parameter_dump_packet.reserved = CCSDS_RESERVED;
1437 1473 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1438 1474 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1439 1475 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1440 1476 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1441 1477 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1442 1478 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1443 1479 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1444 1480 // DATA FIELD HEADER
1445 1481 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1446 1482 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1447 1483 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1448 1484 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1449 1485 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1450 1486 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1451 1487 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1452 1488 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1453 1489 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1454 1490 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1455 1491 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1456 1492
1457 1493 //******************
1458 1494 // COMMON PARAMETERS
1459 1495 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1460 1496 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1461 1497
1462 1498 //******************
1463 1499 // NORMAL PARAMETERS
1464 1500 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1465 1501 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1466 1502 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1467 1503 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1468 1504 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1469 1505 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1470 1506 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1471 1507 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1472 1508 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1473 1509
1474 1510 //*****************
1475 1511 // BURST PARAMETERS
1476 1512 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1477 1513 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1478 1514
1479 1515 //****************
1480 1516 // SBM1 PARAMETERS
1481 1517 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1482 1518 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1483 1519
1484 1520 //****************
1485 1521 // SBM2 PARAMETERS
1486 1522 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1487 1523 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1488 1524
1489 1525 //************
1490 1526 // FBINS MASKS
1491 1527 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1492 1528 {
1493 1529 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1494 1530 }
1495 1531
1496 1532 // PAS FILTER PARAMETERS
1497 1533 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1498 1534 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1499 1535 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1500 1536 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1501 1537 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1502 1538 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1503 1539 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1504 1540
1505 1541 // LFR_RW_MASK
1506 1542 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1507 1543 {
1508 1544 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1509 1545 }
1510 1546
1511 1547 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1512 1548 merge_fbins_masks();
1513 1549 }
1514 1550
1515 1551 void init_kcoefficients_dump( void )
1516 1552 {
1517 1553 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1518 1554 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1519 1555
1520 1556 kcoefficient_node_1.previous = NULL;
1521 1557 kcoefficient_node_1.next = NULL;
1522 1558 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1523 1559 kcoefficient_node_1.coarseTime = INIT_CHAR;
1524 1560 kcoefficient_node_1.fineTime = INIT_CHAR;
1525 1561 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1526 1562 kcoefficient_node_1.status = INIT_CHAR;
1527 1563
1528 1564 kcoefficient_node_2.previous = NULL;
1529 1565 kcoefficient_node_2.next = NULL;
1530 1566 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1531 1567 kcoefficient_node_2.coarseTime = INIT_CHAR;
1532 1568 kcoefficient_node_2.fineTime = INIT_CHAR;
1533 1569 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1534 1570 kcoefficient_node_2.status = INIT_CHAR;
1535 1571 }
1536 1572
1537 1573 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1538 1574 {
1539 1575 unsigned int k;
1540 1576 unsigned int packetLength;
1541 1577
1542 1578 packetLength =
1543 1579 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1544 1580
1545 1581 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1546 1582 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1547 1583 kcoefficients_dump->reserved = CCSDS_RESERVED;
1548 1584 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1549 1585 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1550 1586 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1551 1587 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1552 1588 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1553 1589 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1554 1590 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1555 1591 // DATA FIELD HEADER
1556 1592 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1557 1593 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1558 1594 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1559 1595 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1560 1596 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1561 1597 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1562 1598 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1563 1599 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1564 1600 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1565 1601 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1566 1602 kcoefficients_dump->sid = SID_K_DUMP;
1567 1603
1568 1604 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1569 1605 kcoefficients_dump->pkt_nr = PKTNR_1;
1570 1606 kcoefficients_dump->blk_nr = blk_nr;
1571 1607
1572 1608 //******************
1573 1609 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1574 1610 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1575 1611 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1576 1612 {
1577 1613 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1578 1614 }
1579 1615 }
1580 1616
1581 1617 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1582 1618 {
1583 1619 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1584 1620 *
1585 1621 * @param packet_sequence_control points to the packet sequence control which will be incremented
1586 1622 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1587 1623 *
1588 1624 * If the destination ID is not known, a dedicated counter is incremented.
1589 1625 *
1590 1626 */
1591 1627
1592 1628 unsigned short sequence_cnt;
1593 1629 unsigned short segmentation_grouping_flag;
1594 1630 unsigned short new_packet_sequence_control;
1595 1631 unsigned char i;
1596 1632
1597 1633 switch (destination_id)
1598 1634 {
1599 1635 case SID_TC_GROUND:
1600 1636 i = GROUND;
1601 1637 break;
1602 1638 case SID_TC_MISSION_TIMELINE:
1603 1639 i = MISSION_TIMELINE;
1604 1640 break;
1605 1641 case SID_TC_TC_SEQUENCES:
1606 1642 i = TC_SEQUENCES;
1607 1643 break;
1608 1644 case SID_TC_RECOVERY_ACTION_CMD:
1609 1645 i = RECOVERY_ACTION_CMD;
1610 1646 break;
1611 1647 case SID_TC_BACKUP_MISSION_TIMELINE:
1612 1648 i = BACKUP_MISSION_TIMELINE;
1613 1649 break;
1614 1650 case SID_TC_DIRECT_CMD:
1615 1651 i = DIRECT_CMD;
1616 1652 break;
1617 1653 case SID_TC_SPARE_GRD_SRC1:
1618 1654 i = SPARE_GRD_SRC1;
1619 1655 break;
1620 1656 case SID_TC_SPARE_GRD_SRC2:
1621 1657 i = SPARE_GRD_SRC2;
1622 1658 break;
1623 1659 case SID_TC_OBCP:
1624 1660 i = OBCP;
1625 1661 break;
1626 1662 case SID_TC_SYSTEM_CONTROL:
1627 1663 i = SYSTEM_CONTROL;
1628 1664 break;
1629 1665 case SID_TC_AOCS:
1630 1666 i = AOCS;
1631 1667 break;
1632 1668 case SID_TC_RPW_INTERNAL:
1633 1669 i = RPW_INTERNAL;
1634 1670 break;
1635 1671 default:
1636 1672 i = GROUND;
1637 1673 break;
1638 1674 }
1639 1675
1640 1676 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1641 1677 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1642 1678
1643 1679 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1644 1680
1645 1681 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1646 1682 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1647 1683
1648 1684 // increment the sequence counter
1649 1685 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1650 1686 {
1651 1687 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1652 1688 }
1653 1689 else
1654 1690 {
1655 1691 sequenceCounters_TM_DUMP[ i ] = 0;
1656 1692 }
1657 1693 }