@@ -1,2 +1,2 | |||
|
1 | 1 | 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters |
|
2 | 94f0f2fccbcb8030d9437ffbb69ee0eefaaea188 header/lfr_common_headers | |
|
2 | 5cf0bac6095ff491d937622f8253c6f05095cb39 header/lfr_common_headers |
@@ -1,125 +1,133 | |||
|
1 | 1 | TEMPLATE = app |
|
2 | CONFIG += console | |
|
3 | CONFIG -= app_bundle | |
|
4 | CONFIG -= qt | |
|
5 | ||
|
6 | include(sparc.pri) | |
|
7 | ||
|
8 | INCLUDEPATH += ./ | |
|
9 | ||
|
10 | OBJECTS_DIR=obj | |
|
11 | DESTDIR=bin | |
|
12 | ||
|
2 | 13 | # CONFIG += console v8 sim |
|
3 | 14 | # CONFIG options = |
|
4 | 15 | # verbose |
|
5 | 16 | # boot_messages |
|
6 | 17 | # debug_messages |
|
7 | 18 | # cpu_usage_report |
|
8 | 19 | # stack_report |
|
9 | 20 | # vhdl_dev |
|
10 | 21 | # debug_tch |
|
11 | 22 | # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\ |
|
12 | 23 | # debug_watchdog |
|
13 | 24 | CONFIG += console verbose lpp_dpu_destid cpu_usage_report |
|
14 | CONFIG -= qt | |
|
15 | ||
|
16 | include(./sparc.pri) | |
|
17 | 25 | |
|
18 | 26 | INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include |
|
19 | 27 | |
|
20 | 28 | # flight software version |
|
21 | 29 | SWVERSION=-1-0 |
|
22 | 30 | DEFINES += SW_VERSION_N1=3 # major |
|
23 | 31 | DEFINES += SW_VERSION_N2=1 # minor |
|
24 | 32 | DEFINES += SW_VERSION_N3=0 # patch |
|
25 | 33 | DEFINES += SW_VERSION_N4=4 # internal |
|
26 | 34 | |
|
27 | 35 | # <GCOV> |
|
28 | 36 | #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage |
|
29 | 37 | #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc |
|
30 | 38 | # </GCOV> |
|
31 | 39 | |
|
32 | 40 | # <CHANGE BEFORE FLIGHT> |
|
33 | 41 | contains( CONFIG, lpp_dpu_destid ) { |
|
34 | 42 | DEFINES += LPP_DPU_DESTID |
|
35 | 43 | } |
|
36 | 44 | # </CHANGE BEFORE FLIGHT> |
|
37 | 45 | |
|
38 | 46 | contains( CONFIG, debug_tch ) { |
|
39 | 47 | DEFINES += DEBUG_TCH |
|
40 | 48 | } |
|
41 | 49 | DEFINES += MSB_FIRST_TCH |
|
42 | 50 | |
|
43 | 51 | contains( CONFIG, vhdl_dev ) { |
|
44 | 52 | DEFINES += VHDL_DEV |
|
45 | 53 | } |
|
46 | 54 | |
|
47 | 55 | contains( CONFIG, verbose ) { |
|
48 | 56 | DEFINES += PRINT_MESSAGES_ON_CONSOLE |
|
49 | 57 | } |
|
50 | 58 | |
|
51 | 59 | contains( CONFIG, debug_messages ) { |
|
52 | 60 | DEFINES += DEBUG_MESSAGES |
|
53 | 61 | } |
|
54 | 62 | |
|
55 | 63 | contains( CONFIG, cpu_usage_report ) { |
|
56 | 64 | DEFINES += PRINT_TASK_STATISTICS |
|
57 | 65 | } |
|
58 | 66 | |
|
59 | 67 | contains( CONFIG, stack_report ) { |
|
60 | 68 | DEFINES += PRINT_STACK_REPORT |
|
61 | 69 | } |
|
62 | 70 | |
|
63 | 71 | contains( CONFIG, boot_messages ) { |
|
64 | 72 | DEFINES += BOOT_MESSAGES |
|
65 | 73 | } |
|
66 | 74 | |
|
67 | 75 | contains( CONFIG, debug_watchdog ) { |
|
68 | 76 | DEFINES += DEBUG_WATCHDOG |
|
69 | 77 | } |
|
70 | 78 | |
|
71 | 79 | #doxygen.target = doxygen |
|
72 | 80 | #doxygen.commands = doxygen ../doc/Doxyfile |
|
73 | 81 | #QMAKE_EXTRA_TARGETS += doxygen |
|
74 | 82 | |
|
75 | 83 | TARGET = fsw |
|
76 | 84 | |
|
77 | 85 | INCLUDEPATH += \ |
|
78 | 86 | $${PWD}/../src \ |
|
79 | 87 | $${PWD}/../header \ |
|
80 | 88 | $${PWD}/../header/lfr_common_headers \ |
|
81 | 89 | $${PWD}/../header/processing \ |
|
82 | 90 | $${PWD}/../LFR_basic-parameters |
|
83 | 91 | |
|
84 | 92 | SOURCES += \ |
|
85 | 93 | ../src/wf_handler.c \ |
|
86 | 94 | ../src/tc_handler.c \ |
|
87 | 95 | ../src/fsw_misc.c \ |
|
88 | 96 | ../src/fsw_init.c \ |
|
89 | 97 | ../src/fsw_globals.c \ |
|
90 | 98 | ../src/fsw_spacewire.c \ |
|
91 | 99 | ../src/tc_load_dump_parameters.c \ |
|
92 | 100 | ../src/tm_lfr_tc_exe.c \ |
|
93 | 101 | ../src/tc_acceptance.c \ |
|
94 | 102 | ../src/processing/fsw_processing.c \ |
|
95 | 103 | ../src/processing/avf0_prc0.c \ |
|
96 | 104 | ../src/processing/avf1_prc1.c \ |
|
97 | 105 | ../src/processing/avf2_prc2.c \ |
|
98 | 106 | ../src/lfr_cpu_usage_report.c \ |
|
99 | 107 | ../LFR_basic-parameters/basic_parameters.c |
|
100 | 108 | |
|
101 | 109 | HEADERS += \ |
|
102 | 110 | ../header/wf_handler.h \ |
|
103 | 111 | ../header/tc_handler.h \ |
|
104 | 112 | ../header/grlib_regs.h \ |
|
105 | 113 | ../header/fsw_misc.h \ |
|
106 | 114 | ../header/fsw_init.h \ |
|
107 | 115 | ../header/fsw_spacewire.h \ |
|
108 | 116 | ../header/tc_load_dump_parameters.h \ |
|
109 | 117 | ../header/tm_lfr_tc_exe.h \ |
|
110 | 118 | ../header/tc_acceptance.h \ |
|
111 | 119 | ../header/processing/fsw_processing.h \ |
|
112 | 120 | ../header/processing/avf0_prc0.h \ |
|
113 | 121 | ../header/processing/avf1_prc1.h \ |
|
114 | 122 | ../header/processing/avf2_prc2.h \ |
|
115 | 123 | ../header/fsw_params_wf_handler.h \ |
|
116 | 124 | ../header/lfr_cpu_usage_report.h \ |
|
117 | 125 | ../header/lfr_common_headers/ccsds_types.h \ |
|
118 | 126 | ../header/lfr_common_headers/fsw_params.h \ |
|
119 | 127 | ../header/lfr_common_headers/fsw_params_nb_bytes.h \ |
|
120 | 128 | ../header/lfr_common_headers/fsw_params_processing.h \ |
|
121 | 129 | ../header/lfr_common_headers/tm_byte_positions.h \ |
|
122 | 130 | ../LFR_basic-parameters/basic_parameters.h \ |
|
123 | 131 | ../LFR_basic-parameters/basic_parameters_params.h \ |
|
124 | 132 | ../header/GscMemoryLPP.hpp |
|
125 | 133 |
@@ -1,99 +1,69 | |||
|
1 | CONFIG += console | |
|
2 | CONFIG -= qt | |
|
1 | ||
|
3 | 2 | QMAKE_CC=sparc-rtems-gcc |
|
4 | 3 | message(C compiler forced to: $$QMAKE_CC) |
|
5 | 4 | QMAKE_CXX=sparc-rtems-g++ |
|
6 | 5 | message(C++ compiler forced to: $$QMAKE_CXX) |
|
7 | 6 | QMAKE_AR=sparc-rtems-ar rcs |
|
8 | 7 | message(Archiver forced to: $$QMAKE_AR) |
|
9 | 8 | QMAKE_LINK=sparc-rtems-g++ |
|
10 | 9 | message(Linker forced to: $$QMAKE_LINK) |
|
11 | 10 | QMAKE_LINK_SHLIB=sparc-rtems-g++ |
|
12 | 11 | QMAKE_OBJCOPY= sparc-rtems-objcopy |
|
13 | 12 | QMAKE_STRIP=sparc-rtems-strip |
|
14 | 13 | QMAKE_GDB=sparc-rtems-gdb |
|
15 | 14 | |
|
16 | #INCLUDEPATH += /opt/rtems-4.10 | |
|
17 | INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include | |
|
18 | ||
|
15 | QMAKE_CFLAGS_APP="" | |
|
16 | QMAKE_CXXFLAGS_APP="" | |
|
17 | QMAKE_CFLAGS= | |
|
19 | 18 | QMAKE_CFLAGS_DEBUG= -g |
|
20 | 19 | QMAKE_CFLAGS_RELEASE="" |
|
21 | 20 | QMAKE_CXXFLAGS_DEBUG= -g |
|
22 | 21 | QMAKE_CXXFLAGS_RELEASE="" |
|
23 |
QMAKE_LFLAGS_RELEASE= |
|
|
22 | QMAKE_LFLAGS_RELEASE= | |
|
24 | 23 | QMAKE_LFLAGS_DEBUG= -g |
|
25 | 24 | QMAKE_CXXFLAGS_DEPS = |
|
26 | 25 | QMAKE_CXXFLAGS_WARN_ON = -Wall |
|
27 | 26 | QMAKE_CXXFLAGS_WARN_OFF = -w |
|
28 | 27 | QMAKE_CXXFLAGS_RELEASE = |
|
29 | 28 | QMAKE_CXXFLAGS_DEBUG = |
|
30 | 29 | QMAKE_CXXFLAGS_YACC = |
|
31 | 30 | QMAKE_CXXFLAGS_THREAD = |
|
32 | 31 | QMAKE_CXXFLAGS_RTTI_ON = |
|
33 | 32 | QMAKE_CXXFLAGS_RTTI_OFF = |
|
34 | 33 | QMAKE_CXXFLAGS_EXCEPTIONS_ON = |
|
35 | 34 | QMAKE_CXXFLAGS_EXCEPTIONS_OFF = |
|
36 | 35 | QMAKE_CFLAGS_WARN_ON = -Wall |
|
37 | 36 | QMAKE_CFLAGS_WARN_OFF = -w |
|
38 | 37 | QMAKE_CFLAGS_RELEASE = |
|
39 | 38 | QMAKE_CFLAGS_YACC = |
|
40 | 39 | QMAKE_LFLAGS_EXCEPTIONS_ON = |
|
41 | 40 | QMAKE_LFLAGS_EXCEPTIONS_OFF = |
|
42 | QMAKE_LFLAGS_RELEASE = -Xlinker -Map=output.map | |
|
43 | 41 | QMAKE_LFLAGS_CONSOLE = |
|
44 | 42 | QMAKE_LFLAGS_WINDOWS = |
|
45 | 43 | QMAKE_LFLAGS_DLL = |
|
46 | 44 | QMAKE_INCDIR_QT = |
|
47 | 45 | QMAKE_INCDIR = |
|
48 | 46 | QMAKE_CFLAGS_SHLIB = |
|
49 | 47 | QMAKE_CFLAGS_STATIC_LIB = |
|
50 | 48 | QMAKE_CXXFLAGS_SHLIB = |
|
51 | 49 | QMAKE_CXXFLAGS_STATIC_LIB = |
|
52 | 50 | QMAKE_LIBS="" |
|
53 | 51 | INCLUDEPATH="" |
|
54 | 52 | DEFINES="" |
|
55 | 53 | |
|
56 | contains( TEMPLATE, app ) { | |
|
57 | OBJECTS_DIR=obj | |
|
58 | DESTDIR=bin | |
|
59 | } | |
|
60 | ||
|
61 | #QMAKE_CFLAGS_RELEASE += -O0 | |
|
62 | #QMAKE_CFLAGS_DEBUG += -O0 | |
|
63 | #QMAKE_CXXFLAGS_RELEASE += -O0 | |
|
64 | #QMAKE_CXXFLAGS_DEBUG += -O0 | |
|
65 | 54 | |
|
66 | 55 | QMAKE_CFLAGS_RELEASE += -O3 |
|
67 | 56 | QMAKE_CFLAGS_DEBUG += -O3 |
|
68 | 57 | QMAKE_CXXFLAGS_RELEASE += -O3 |
|
69 | 58 | QMAKE_CXXFLAGS_DEBUG += -O3 |
|
70 | 59 | |
|
60 | #QMAKE_CFLAGS_RELEASE += -O0 | |
|
61 | #QMAKE_CFLAGS_DEBUG += -O0 | |
|
62 | #QMAKE_CXXFLAGS_RELEASE += -O0 | |
|
63 | #QMAKE_CXXFLAGS_DEBUG += -O0 | |
|
64 | ||
|
65 | ||
|
71 | 66 |
#QMAKE_CFLAGS_RELEASE |
|
72 | 67 |
#QMAKE_CFLAGS_DEBUG |
|
73 | 68 |
#QMAKE_CXXFLAGS_RELEASE |
|
74 | 69 |
#QMAKE_CXXFLAGS_DEBUG |
|
75 | ||
|
76 | contains( TEMPLATE, app ) { | |
|
77 | grmon.target = grmon | |
|
78 | grmon.commands = cd $$DESTDIR && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u | |
|
79 | QMAKE_EXTRA_TARGETS += grmon | |
|
80 | } | |
|
81 | ||
|
82 | ||
|
83 | ||
|
84 | ||
|
85 | ||
|
86 | ||
|
87 | ||
|
88 | ||
|
89 | ||
|
90 | ||
|
91 | ||
|
92 | ||
|
93 | ||
|
94 | ||
|
95 | ||
|
96 | ||
|
97 | ||
|
98 | ||
|
99 |
@@ -1,64 +1,59 | |||
|
1 | 1 | #ifndef FSW_INIT_H_INCLUDED |
|
2 | 2 | #define FSW_INIT_H_INCLUDED |
|
3 | 3 | |
|
4 | 4 | #include <rtems.h> |
|
5 | 5 | #include <leon.h> |
|
6 | 6 | |
|
7 | 7 | #include "fsw_params.h" |
|
8 | 8 | #include "fsw_misc.h" |
|
9 | 9 | #include "fsw_processing.h" |
|
10 | 10 | |
|
11 | 11 | #include "tc_handler.h" |
|
12 | 12 | #include "wf_handler.h" |
|
13 | 13 | #include "fsw_spacewire.h" |
|
14 | 14 | |
|
15 | 15 | #include "avf0_prc0.h" |
|
16 | 16 | #include "avf1_prc1.h" |
|
17 | 17 | #include "avf2_prc2.h" |
|
18 | 18 | |
|
19 | 19 | extern rtems_name Task_name[]; /* array of task names */ |
|
20 | 20 | extern rtems_id Task_id[]; /* array of task ids */ |
|
21 | 21 | extern rtems_name timecode_timer_name; |
|
22 | 22 | extern rtems_id timecode_timer_id; |
|
23 | 23 | extern unsigned char pa_bia_status_info; |
|
24 | extern unsigned char cp_rpw_sc_rw_f_flags; | |
|
25 |
extern |
|
|
26 | extern float cp_rpw_sc_rw1_f2; | |
|
27 | extern float cp_rpw_sc_rw2_f1; | |
|
28 | extern float cp_rpw_sc_rw2_f2; | |
|
29 | extern float cp_rpw_sc_rw3_f1; | |
|
30 | extern float cp_rpw_sc_rw3_f2; | |
|
31 | extern float cp_rpw_sc_rw4_f1; | |
|
32 | extern float cp_rpw_sc_rw4_f2; | |
|
24 | extern unsigned char cp_rpw_sc_rw1_rw2_f_flags; | |
|
25 | extern unsigned char cp_rpw_sc_rw3_rw4_f_flags; | |
|
26 | ||
|
33 | 27 | extern filterPar_t filterPar; |
|
28 | extern rw_f_t rw_f; | |
|
34 | 29 | |
|
35 | 30 | // RTEMS TASKS |
|
36 | 31 | rtems_task Init( rtems_task_argument argument); |
|
37 | 32 | |
|
38 | 33 | // OTHER functions |
|
39 | 34 | void create_names( void ); |
|
40 | 35 | int create_all_tasks( void ); |
|
41 | 36 | int start_all_tasks( void ); |
|
42 | 37 | // |
|
43 | 38 | rtems_status_code create_message_queues( void ); |
|
44 | 39 | rtems_status_code create_timecode_timer( void ); |
|
45 | 40 | rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); |
|
46 | 41 | rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); |
|
47 | 42 | rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id ); |
|
48 | 43 | rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ); |
|
49 | 44 | rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ); |
|
50 | 45 | void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max ); |
|
51 | 46 | void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize ); |
|
52 | 47 | // |
|
53 | 48 | int start_recv_send_tasks( void ); |
|
54 | 49 | // |
|
55 | 50 | void init_local_mode_parameters( void ); |
|
56 | 51 | void reset_local_time( void ); |
|
57 | 52 | |
|
58 | 53 | extern void rtems_cpu_usage_report( void ); |
|
59 | 54 | extern void rtems_cpu_usage_reset( void ); |
|
60 | 55 | extern void rtems_stack_checker_report_usage( void ); |
|
61 | 56 | |
|
62 | 57 | extern int sched_yield( void ); |
|
63 | 58 | |
|
64 | 59 | #endif // FSW_INIT_H_INCLUDED |
@@ -1,83 +1,85 | |||
|
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 | |
|
16 | 16 | extern unsigned short sequenceCounterParameterDump; |
|
17 | 17 | extern unsigned short sequenceCounters_TM_DUMP[]; |
|
18 | 18 | extern float k_coeff_intercalib_f0_norm[ ]; |
|
19 | 19 | extern float k_coeff_intercalib_f0_sbm[ ]; |
|
20 | 20 | extern float k_coeff_intercalib_f1_norm[ ]; |
|
21 | 21 | extern float k_coeff_intercalib_f1_sbm[ ]; |
|
22 | 22 | extern float k_coeff_intercalib_f2[ ]; |
|
23 | 23 | extern fbins_masks_t fbins_masks; |
|
24 | 24 | |
|
25 | 25 | int action_load_common_par( ccsdsTelecommandPacket_t *TC ); |
|
26 | 26 | int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
27 | 27 | int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
28 | 28 | int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
29 | 29 | int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); |
|
30 | 30 | int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
31 | 31 | int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
32 | 32 | int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
33 | 33 | int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); |
|
34 | 34 | int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
35 | 35 | |
|
36 | 36 | // NORMAL |
|
37 | 37 | int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
38 | 38 | int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ); |
|
39 | 39 | int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC ); |
|
40 | 40 | int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ); |
|
41 | 41 | int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
42 | 42 | int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
43 | 43 | int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC ); |
|
44 | 44 | |
|
45 | 45 | // BURST |
|
46 | 46 | int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
47 | 47 | int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
48 | 48 | |
|
49 | 49 | // SBM1 |
|
50 | 50 | int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
51 | 51 | int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
52 | 52 | |
|
53 | 53 | // SBM2 |
|
54 | 54 | int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC ); |
|
55 | 55 | int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ); |
|
56 | 56 | |
|
57 | 57 | // TC_LFR_UPDATE_INFO |
|
58 | 58 | unsigned int check_update_info_hk_lfr_mode( unsigned char mode ); |
|
59 | 59 | unsigned int check_update_info_hk_tds_mode( unsigned char mode ); |
|
60 | 60 | unsigned int check_update_info_hk_thr_mode( unsigned char mode ); |
|
61 | void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value ); | |
|
62 | void set_hk_lfr_sc_rw_f_flags( void ); | |
|
61 | 63 | void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC ); |
|
62 | 64 | void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag ); |
|
63 | 65 | void build_sy_lfr_rw_mask( unsigned int channel ); |
|
64 | 66 | void build_sy_lfr_rw_masks(); |
|
65 | 67 | void merge_fbins_masks( void ); |
|
66 | 68 | |
|
67 | 69 | // FBINS_MASK |
|
68 | 70 | int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC ); |
|
69 | 71 | |
|
70 | 72 | // TC_LFR_LOAD_PARS_FILTER_PAR |
|
71 | 73 | int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
72 | 74 | |
|
73 | 75 | // KCOEFFICIENTS |
|
74 | 76 | int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id); |
|
75 | 77 | void copyFloatByChar( unsigned char *destination, unsigned char *source ); |
|
76 | 78 | void floatToChar( float value, unsigned char* ptr); |
|
77 | 79 | |
|
78 | 80 | void init_parameter_dump( void ); |
|
79 | 81 | void init_kcoefficients_dump( void ); |
|
80 | 82 | void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr ); |
|
81 | 83 | void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id ); |
|
82 | 84 | |
|
83 | 85 | #endif // TC_LOAD_DUMP_PARAMETERS_H |
@@ -1,14 +1,14 | |||
|
1 | 1 | # LOAD FSW USING LINK 1 |
|
2 | 2 | SpwPlugin0.StarDundeeSelectLinkNumber( 1 ) |
|
3 | 3 | |
|
4 |
dsu3plugin0.openFile("/ |
|
|
4 | dsu3plugin0.openFile("/home/pleroy/DEV/DEV_PLE/FSW-qt/bin/fsw") | |
|
5 | 5 | #dsu3plugin0.openFile("/opt/LFR/LFR-FSW/2.0.2.3/fsw") |
|
6 | 6 | dsu3plugin0.loadFile() |
|
7 | 7 | |
|
8 | 8 | dsu3plugin0.run() |
|
9 | 9 | |
|
10 | 10 | # START SENDING TIMECODES AT 1 Hz |
|
11 | 11 | #SpwPlugin0.StarDundeeStartTimecodes( 1 ) |
|
12 | 12 | |
|
13 | 13 | # it is possible to change the time code frequency |
|
14 | 14 | #RMAPPlugin0.changeTimecodeFrequency(2) |
@@ -1,98 +1,92 | |||
|
1 | 1 | /** Global variables of the LFR flight software. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * Among global variables, there are: |
|
7 | 7 | * - RTEMS names and id. |
|
8 | 8 | * - APB configuration registers. |
|
9 | 9 | * - waveforms global buffers, used by the waveform picker hardware module to store data. |
|
10 | 10 | * - spectral matrices buffesr, used by the hardware module to store data. |
|
11 | 11 | * - variable related to LFR modes parameters. |
|
12 | 12 | * - the global HK packet buffer. |
|
13 | 13 | * - the global dump parameter buffer. |
|
14 | 14 | * |
|
15 | 15 | */ |
|
16 | 16 | |
|
17 | 17 | #include <rtems.h> |
|
18 | 18 | #include <grspw.h> |
|
19 | 19 | |
|
20 | 20 | #include "ccsds_types.h" |
|
21 | 21 | #include "grlib_regs.h" |
|
22 | 22 | #include "fsw_params.h" |
|
23 | 23 | #include "fsw_params_wf_handler.h" |
|
24 | 24 | |
|
25 | 25 | // RTEMS GLOBAL VARIABLES |
|
26 | 26 | rtems_name misc_name[5]; |
|
27 | 27 | rtems_name Task_name[20]; /* array of task names */ |
|
28 | 28 | rtems_id Task_id[20]; /* array of task ids */ |
|
29 | 29 | rtems_name timecode_timer_name; |
|
30 | 30 | rtems_id timecode_timer_id; |
|
31 | 31 | int fdSPW = 0; |
|
32 | 32 | int fdUART = 0; |
|
33 | 33 | unsigned char lfrCurrentMode; |
|
34 | 34 | unsigned char pa_bia_status_info; |
|
35 | 35 | unsigned char thisIsAnASMRestart = 0; |
|
36 | 36 | unsigned char oneTcLfrUpdateTimeReceived = 0; |
|
37 | 37 | |
|
38 | 38 | // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584 |
|
39 | 39 | // 97 * 256 = 24832 => delta = 248 bytes = 62 words |
|
40 | 40 | // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264 |
|
41 | 41 | // 127 * 256 = 32512 => delta = 248 bytes = 62 words |
|
42 | 42 | // F0 F1 F2 F3 |
|
43 | 43 | volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
44 | 44 | volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
45 | 45 | volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
46 | 46 | volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
47 | 47 | |
|
48 | 48 | //*********************************** |
|
49 | 49 | // SPECTRAL MATRICES GLOBAL VARIABLES |
|
50 | 50 | |
|
51 | 51 | // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00 |
|
52 | 52 | volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); |
|
53 | 53 | volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); |
|
54 | 54 | volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); |
|
55 | 55 | |
|
56 | 56 | // APB CONFIGURATION REGISTERS |
|
57 | 57 | time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT; |
|
58 | 58 | gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; |
|
59 | 59 | waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER; |
|
60 | 60 | spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX; |
|
61 | 61 | |
|
62 | 62 | // MODE PARAMETERS |
|
63 | 63 | Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; |
|
64 | 64 | struct param_local_str param_local; |
|
65 | 65 | unsigned int lastValidEnterModeTime; |
|
66 | 66 | |
|
67 | 67 | // HK PACKETS |
|
68 | 68 | Packet_TM_LFR_HK_t housekeeping_packet; |
|
69 | unsigned char cp_rpw_sc_rw_f_flags; | |
|
69 | unsigned char cp_rpw_sc_rw1_rw2_f_flags; | |
|
70 | unsigned char cp_rpw_sc_rw3_rw4_f_flags; | |
|
70 | 71 | // message queues occupancy |
|
71 | 72 | unsigned char hk_lfr_q_sd_fifo_size_max; |
|
72 | 73 | unsigned char hk_lfr_q_rv_fifo_size_max; |
|
73 | 74 | unsigned char hk_lfr_q_p0_fifo_size_max; |
|
74 | 75 | unsigned char hk_lfr_q_p1_fifo_size_max; |
|
75 | 76 | unsigned char hk_lfr_q_p2_fifo_size_max; |
|
76 | 77 | // sequence counters are incremented by APID (PID + CAT) and destination ID |
|
77 | 78 | unsigned short sequenceCounters_SCIENCE_NORMAL_BURST; |
|
78 | 79 | unsigned short sequenceCounters_SCIENCE_SBM1_SBM2; |
|
79 | 80 | unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID]; |
|
80 | 81 | unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID]; |
|
81 | 82 | unsigned short sequenceCounterHK; |
|
82 | 83 | spw_stats grspw_stats; |
|
83 | 84 | |
|
84 | 85 | // TC_LFR_UPDATE_INFO |
|
85 | float cp_rpw_sc_rw1_f1; | |
|
86 | float cp_rpw_sc_rw1_f2; | |
|
87 | float cp_rpw_sc_rw2_f1; | |
|
88 | float cp_rpw_sc_rw2_f2; | |
|
89 | float cp_rpw_sc_rw3_f1; | |
|
90 | float cp_rpw_sc_rw3_f2; | |
|
91 | float cp_rpw_sc_rw4_f1; | |
|
92 | float cp_rpw_sc_rw4_f2; | |
|
86 | rw_f_t rw_f; | |
|
93 | 87 | |
|
94 | 88 | // TC_LFR_LOAD_FILTER_PAR |
|
95 | 89 | filterPar_t filterPar; |
|
96 | 90 | |
|
97 | 91 | fbins_masks_t fbins_masks; |
|
98 | 92 | unsigned int acquisitionDurations[3] = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2}; |
@@ -1,955 +1,968 | |||
|
1 | 1 | /** This is the RTEMS initialization module. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * This module contains two very different information: |
|
7 | 7 | * - specific instructions to configure the compilation of the RTEMS executive |
|
8 | 8 | * - functions related to the fligth softwre initialization, especially the INIT RTEMS task |
|
9 | 9 | * |
|
10 | 10 | */ |
|
11 | 11 | |
|
12 | 12 | //************************* |
|
13 | 13 | // GPL reminder to be added |
|
14 | 14 | //************************* |
|
15 | 15 | |
|
16 | 16 | #include <rtems.h> |
|
17 | 17 | |
|
18 | 18 | /* configuration information */ |
|
19 | 19 | |
|
20 | 20 | #define CONFIGURE_INIT |
|
21 | 21 | |
|
22 | 22 | #include <bsp.h> /* for device driver prototypes */ |
|
23 | 23 | |
|
24 | 24 | /* configuration information */ |
|
25 | 25 | |
|
26 | 26 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
|
27 | 27 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
|
28 | 28 | |
|
29 | 29 | #define CONFIGURE_MAXIMUM_TASKS 21 // number of tasks concurrently active including INIT |
|
30 | 30 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
|
31 | 31 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) |
|
32 | 32 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 |
|
33 | 33 | #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 |
|
34 | 34 | #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) |
|
35 | 35 | #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) |
|
36 | 36 | #define CONFIGURE_MAXIMUM_DRIVERS 16 |
|
37 | 37 | #define CONFIGURE_MAXIMUM_PERIODS 5 // [hous] [load] [avgv] |
|
38 | 38 | #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link] |
|
39 | 39 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5 |
|
40 | 40 | #ifdef PRINT_STACK_REPORT |
|
41 | 41 | #define CONFIGURE_STACK_CHECKER_ENABLED |
|
42 | 42 | #endif |
|
43 | 43 | |
|
44 | 44 | #include <rtems/confdefs.h> |
|
45 | 45 | |
|
46 | 46 | /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ |
|
47 | 47 | #ifdef RTEMS_DRVMGR_STARTUP |
|
48 | 48 | #ifdef LEON3 |
|
49 | 49 | /* Add Timer and UART Driver */ |
|
50 | 50 | |
|
51 | 51 | #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
|
52 | 52 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER |
|
53 | 53 | #endif |
|
54 | 54 | |
|
55 | 55 | #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
|
56 | 56 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART |
|
57 | 57 | #endif |
|
58 | 58 | |
|
59 | 59 | #endif |
|
60 | 60 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ |
|
61 | 61 | |
|
62 | 62 | #include <drvmgr/drvmgr_confdefs.h> |
|
63 | 63 | #endif |
|
64 | 64 | |
|
65 | 65 | #include "fsw_init.h" |
|
66 | 66 | #include "fsw_config.c" |
|
67 | 67 | #include "GscMemoryLPP.hpp" |
|
68 | 68 | |
|
69 | 69 | void initCache() |
|
70 | 70 | { |
|
71 | 71 | // ASI 2 contains a few control registers that have not been assigned as ancillary state registers. |
|
72 | 72 | // These should only be read and written using 32-bit LDA/STA instructions. |
|
73 | 73 | // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2. |
|
74 | 74 | // The table below shows the register addresses: |
|
75 | 75 | // 0x00 Cache control register |
|
76 | 76 | // 0x04 Reserved |
|
77 | 77 | // 0x08 Instruction cache configuration register |
|
78 | 78 | // 0x0C Data cache configuration register |
|
79 | 79 | |
|
80 | 80 | // Cache Control Register Leon3 / Leon3FT |
|
81 | 81 | // 31..30 29 28 27..24 23 22 21 20..19 18 17 16 |
|
82 | 82 | // RFT PS TB DS FD FI FT ST IB |
|
83 | 83 | // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0 |
|
84 | 84 | // IP DP ITE IDE DTE DDE DF IF DCS ICS |
|
85 | 85 | |
|
86 | 86 | unsigned int cacheControlRegister; |
|
87 | 87 | |
|
88 | 88 | CCR_resetCacheControlRegister(); |
|
89 | 89 | ASR16_resetRegisterProtectionControlRegister(); |
|
90 | 90 | |
|
91 | 91 | cacheControlRegister = CCR_getValue(); |
|
92 | 92 | PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister); |
|
93 | 93 | PRINTF1("(0) ASR16 = %x\n", *asr16Ptr); |
|
94 | 94 | |
|
95 | 95 | CCR_enableInstructionCache(); // ICS bits |
|
96 | 96 | CCR_enableDataCache(); // DCS bits |
|
97 | 97 | CCR_enableInstructionBurstFetch(); // IB bit |
|
98 | 98 | |
|
99 | 99 | faultTolerantScheme(); |
|
100 | 100 | |
|
101 | 101 | cacheControlRegister = CCR_getValue(); |
|
102 | 102 | PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister); |
|
103 | 103 | PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr); |
|
104 | 104 | |
|
105 | 105 | PRINTF("\n"); |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | rtems_task Init( rtems_task_argument ignored ) |
|
109 | 109 | { |
|
110 | 110 | /** This is the RTEMS INIT taks, it is the first task launched by the system. |
|
111 | 111 | * |
|
112 | 112 | * @param unused is the starting argument of the RTEMS task |
|
113 | 113 | * |
|
114 | 114 | * The INIT task create and run all other RTEMS tasks. |
|
115 | 115 | * |
|
116 | 116 | */ |
|
117 | 117 | |
|
118 | 118 | //*********** |
|
119 | 119 | // INIT CACHE |
|
120 | 120 | |
|
121 | 121 | unsigned char *vhdlVersion; |
|
122 | 122 | |
|
123 | 123 | reset_lfr(); |
|
124 | 124 | |
|
125 | 125 | reset_local_time(); |
|
126 | 126 | |
|
127 | 127 | rtems_cpu_usage_reset(); |
|
128 | 128 | |
|
129 | 129 | rtems_status_code status; |
|
130 | 130 | rtems_status_code status_spw; |
|
131 | 131 | rtems_isr_entry old_isr_handler; |
|
132 | 132 | |
|
133 | 133 | // UART settings |
|
134 | 134 | enable_apbuart_transmitter(); |
|
135 | 135 | set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); |
|
136 | 136 | |
|
137 | 137 | DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") |
|
138 | 138 | |
|
139 | 139 | |
|
140 | 140 | PRINTF("\n\n\n\n\n") |
|
141 | 141 | |
|
142 | 142 | initCache(); |
|
143 | 143 | |
|
144 | 144 | PRINTF("*************************\n") |
|
145 | 145 | PRINTF("** LFR Flight Software **\n") |
|
146 | 146 | PRINTF1("** %d-", SW_VERSION_N1) |
|
147 | 147 | PRINTF1("%d-" , SW_VERSION_N2) |
|
148 | 148 | PRINTF1("%d-" , SW_VERSION_N3) |
|
149 | 149 | PRINTF1("%d **\n", SW_VERSION_N4) |
|
150 | 150 | |
|
151 | 151 | vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
152 | 152 | PRINTF("** VHDL **\n") |
|
153 | 153 | PRINTF1("** %d.", vhdlVersion[1]) |
|
154 | 154 | PRINTF1("%d." , vhdlVersion[2]) |
|
155 | 155 | PRINTF1("%d **\n", vhdlVersion[3]) |
|
156 | 156 | PRINTF("*************************\n") |
|
157 | 157 | PRINTF("\n\n") |
|
158 | 158 | |
|
159 | 159 | init_parameter_dump(); |
|
160 | 160 | init_kcoefficients_dump(); |
|
161 | 161 | init_local_mode_parameters(); |
|
162 | 162 | init_housekeeping_parameters(); |
|
163 | 163 | init_k_coefficients_prc0(); |
|
164 | 164 | init_k_coefficients_prc1(); |
|
165 | 165 | init_k_coefficients_prc2(); |
|
166 | 166 | pa_bia_status_info = 0x00; |
|
167 | cp_rpw_sc_rw_f_flags = 0x00; | |
|
168 | cp_rpw_sc_rw1_f1 = 0.0; | |
|
169 |
cp_rpw_sc_rw1_f |
|
|
170 |
cp_rpw_sc_rw |
|
|
171 |
cp_rpw_sc_rw |
|
|
172 |
cp_rpw_sc_rw |
|
|
173 |
cp_rpw_sc_rw |
|
|
174 |
cp_rpw_sc_rw |
|
|
175 |
cp_rpw_sc_rw |
|
|
167 | ||
|
168 | // initialize all reaction wheels frequencies to NaN | |
|
169 | rw_f.cp_rpw_sc_rw1_f1 = NAN; | |
|
170 | rw_f.cp_rpw_sc_rw1_f2 = NAN; | |
|
171 | rw_f.cp_rpw_sc_rw1_f3 = NAN; | |
|
172 | rw_f.cp_rpw_sc_rw1_f4 = NAN; | |
|
173 | rw_f.cp_rpw_sc_rw2_f1 = NAN; | |
|
174 | rw_f.cp_rpw_sc_rw2_f2 = NAN; | |
|
175 | rw_f.cp_rpw_sc_rw2_f3 = NAN; | |
|
176 | rw_f.cp_rpw_sc_rw2_f4 = NAN; | |
|
177 | rw_f.cp_rpw_sc_rw3_f1 = NAN; | |
|
178 | rw_f.cp_rpw_sc_rw3_f2 = NAN; | |
|
179 | rw_f.cp_rpw_sc_rw3_f3 = NAN; | |
|
180 | rw_f.cp_rpw_sc_rw3_f4 = NAN; | |
|
181 | rw_f.cp_rpw_sc_rw4_f1 = NAN; | |
|
182 | rw_f.cp_rpw_sc_rw4_f2 = NAN; | |
|
183 | rw_f.cp_rpw_sc_rw4_f3 = NAN; | |
|
184 | rw_f.cp_rpw_sc_rw4_f4 = NAN; | |
|
185 | ||
|
186 | cp_rpw_sc_rw1_rw2_f_flags = 0x00; | |
|
187 | cp_rpw_sc_rw3_rw4_f_flags = 0x00; | |
|
188 | ||
|
176 | 189 | // initialize filtering parameters |
|
177 | 190 | filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED; |
|
178 | 191 | filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS; |
|
179 | 192 | filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD; |
|
180 | 193 | filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET; |
|
181 | 194 | filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT; |
|
182 | 195 | filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F; |
|
183 | 196 | update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE ); |
|
184 | 197 | |
|
185 | 198 | // waveform picker initialization |
|
186 | 199 | WFP_init_rings(); |
|
187 | 200 | LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings |
|
188 | 201 | WFP_reset_current_ring_nodes(); |
|
189 | 202 | reset_waveform_picker_regs(); |
|
190 | 203 | |
|
191 | 204 | // spectral matrices initialization |
|
192 | 205 | SM_init_rings(); // initialize spectral matrices rings |
|
193 | 206 | SM_reset_current_ring_nodes(); |
|
194 | 207 | reset_spectral_matrix_regs(); |
|
195 | 208 | |
|
196 | 209 | // configure calibration |
|
197 | 210 | configureCalibration( false ); // true means interleaved mode, false is for normal mode |
|
198 | 211 | |
|
199 | 212 | updateLFRCurrentMode( LFR_MODE_STANDBY ); |
|
200 | 213 | |
|
201 | 214 | BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode) |
|
202 | 215 | |
|
203 | 216 | create_names(); // create all names |
|
204 | 217 | |
|
205 | 218 | status = create_timecode_timer(); // create the timer used by timecode_irq_handler |
|
206 | 219 | if (status != RTEMS_SUCCESSFUL) |
|
207 | 220 | { |
|
208 | 221 | PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status) |
|
209 | 222 | } |
|
210 | 223 | |
|
211 | 224 | status = create_message_queues(); // create message queues |
|
212 | 225 | if (status != RTEMS_SUCCESSFUL) |
|
213 | 226 | { |
|
214 | 227 | PRINTF1("in INIT *** ERR in create_message_queues, code %d", status) |
|
215 | 228 | } |
|
216 | 229 | |
|
217 | 230 | status = create_all_tasks(); // create all tasks |
|
218 | 231 | if (status != RTEMS_SUCCESSFUL) |
|
219 | 232 | { |
|
220 | 233 | PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status) |
|
221 | 234 | } |
|
222 | 235 | |
|
223 | 236 | // ************************** |
|
224 | 237 | // <SPACEWIRE INITIALIZATION> |
|
225 | 238 | status_spw = spacewire_open_link(); // (1) open the link |
|
226 | 239 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
227 | 240 | { |
|
228 | 241 | PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw ) |
|
229 | 242 | } |
|
230 | 243 | |
|
231 | 244 | if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link |
|
232 | 245 | { |
|
233 | 246 | status_spw = spacewire_configure_link( fdSPW ); |
|
234 | 247 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
235 | 248 | { |
|
236 | 249 | PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw ) |
|
237 | 250 | } |
|
238 | 251 | } |
|
239 | 252 | |
|
240 | 253 | if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link |
|
241 | 254 | { |
|
242 | 255 | status_spw = spacewire_start_link( fdSPW ); |
|
243 | 256 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
244 | 257 | { |
|
245 | 258 | PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw ) |
|
246 | 259 | } |
|
247 | 260 | } |
|
248 | 261 | // </SPACEWIRE INITIALIZATION> |
|
249 | 262 | // *************************** |
|
250 | 263 | |
|
251 | 264 | status = start_all_tasks(); // start all tasks |
|
252 | 265 | if (status != RTEMS_SUCCESSFUL) |
|
253 | 266 | { |
|
254 | 267 | PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status) |
|
255 | 268 | } |
|
256 | 269 | |
|
257 | 270 | // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization |
|
258 | 271 | status = start_recv_send_tasks(); |
|
259 | 272 | if ( status != RTEMS_SUCCESSFUL ) |
|
260 | 273 | { |
|
261 | 274 | PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status ) |
|
262 | 275 | } |
|
263 | 276 | |
|
264 | 277 | // suspend science tasks, they will be restarted later depending on the mode |
|
265 | 278 | status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY) |
|
266 | 279 | if (status != RTEMS_SUCCESSFUL) |
|
267 | 280 | { |
|
268 | 281 | PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
269 | 282 | } |
|
270 | 283 | |
|
271 | 284 | // configure IRQ handling for the waveform picker unit |
|
272 | 285 | status = rtems_interrupt_catch( waveforms_isr, |
|
273 | 286 | IRQ_SPARC_WAVEFORM_PICKER, |
|
274 | 287 | &old_isr_handler) ; |
|
275 | 288 | // configure IRQ handling for the spectral matrices unit |
|
276 | 289 | status = rtems_interrupt_catch( spectral_matrices_isr, |
|
277 | 290 | IRQ_SPARC_SPECTRAL_MATRIX, |
|
278 | 291 | &old_isr_handler) ; |
|
279 | 292 | |
|
280 | 293 | // if the spacewire link is not up then send an event to the SPIQ task for link recovery |
|
281 | 294 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
282 | 295 | { |
|
283 | 296 | status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ); |
|
284 | 297 | if ( status != RTEMS_SUCCESSFUL ) { |
|
285 | 298 | PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status ) |
|
286 | 299 | } |
|
287 | 300 | } |
|
288 | 301 | |
|
289 | 302 | BOOT_PRINTF("delete INIT\n") |
|
290 | 303 | |
|
291 | 304 | set_hk_lfr_sc_potential_flag( true ); |
|
292 | 305 | |
|
293 | 306 | // start the timer to detect a missing spacewire timecode |
|
294 | 307 | // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout |
|
295 | 308 | // if a tickout is generated, the timer is restarted |
|
296 | 309 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL ); |
|
297 | 310 | |
|
298 | 311 | grspw_timecode_callback = &timecode_irq_handler; |
|
299 | 312 | |
|
300 | 313 | status = rtems_task_delete(RTEMS_SELF); |
|
301 | 314 | |
|
302 | 315 | } |
|
303 | 316 | |
|
304 | 317 | void init_local_mode_parameters( void ) |
|
305 | 318 | { |
|
306 | 319 | /** This function initialize the param_local global variable with default values. |
|
307 | 320 | * |
|
308 | 321 | */ |
|
309 | 322 | |
|
310 | 323 | unsigned int i; |
|
311 | 324 | |
|
312 | 325 | // LOCAL PARAMETERS |
|
313 | 326 | |
|
314 | 327 | BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) |
|
315 | 328 | BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) |
|
316 | 329 | BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX) |
|
317 | 330 | |
|
318 | 331 | // init sequence counters |
|
319 | 332 | |
|
320 | 333 | for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++) |
|
321 | 334 | { |
|
322 | 335 | sequenceCounters_TC_EXE[i] = 0x00; |
|
323 | 336 | sequenceCounters_TM_DUMP[i] = 0x00; |
|
324 | 337 | } |
|
325 | 338 | sequenceCounters_SCIENCE_NORMAL_BURST = 0x00; |
|
326 | 339 | sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00; |
|
327 | 340 | sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8; |
|
328 | 341 | } |
|
329 | 342 | |
|
330 | 343 | void reset_local_time( void ) |
|
331 | 344 | { |
|
332 | 345 | time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000 |
|
333 | 346 | } |
|
334 | 347 | |
|
335 | 348 | void create_names( void ) // create all names for tasks and queues |
|
336 | 349 | { |
|
337 | 350 | /** This function creates all RTEMS names used in the software for tasks and queues. |
|
338 | 351 | * |
|
339 | 352 | * @return RTEMS directive status codes: |
|
340 | 353 | * - RTEMS_SUCCESSFUL - successful completion |
|
341 | 354 | * |
|
342 | 355 | */ |
|
343 | 356 | |
|
344 | 357 | // task names |
|
345 | 358 | Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' ); |
|
346 | 359 | Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' ); |
|
347 | 360 | Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' ); |
|
348 | 361 | Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' ); |
|
349 | 362 | Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' ); |
|
350 | 363 | Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' ); |
|
351 | 364 | Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' ); |
|
352 | 365 | Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' ); |
|
353 | 366 | Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' ); |
|
354 | 367 | Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' ); |
|
355 | 368 | Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' ); |
|
356 | 369 | Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' ); |
|
357 | 370 | Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' ); |
|
358 | 371 | Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' ); |
|
359 | 372 | Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' ); |
|
360 | 373 | Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' ); |
|
361 | 374 | Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' ); |
|
362 | 375 | Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' ); |
|
363 | 376 | Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' ); |
|
364 | 377 | Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' ); |
|
365 | 378 | |
|
366 | 379 | // rate monotonic period names |
|
367 | 380 | name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' ); |
|
368 | 381 | name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' ); |
|
369 | 382 | |
|
370 | 383 | misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' ); |
|
371 | 384 | misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' ); |
|
372 | 385 | misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' ); |
|
373 | 386 | misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' ); |
|
374 | 387 | misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' ); |
|
375 | 388 | |
|
376 | 389 | timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' ); |
|
377 | 390 | } |
|
378 | 391 | |
|
379 | 392 | int create_all_tasks( void ) // create all tasks which run in the software |
|
380 | 393 | { |
|
381 | 394 | /** This function creates all RTEMS tasks used in the software. |
|
382 | 395 | * |
|
383 | 396 | * @return RTEMS directive status codes: |
|
384 | 397 | * - RTEMS_SUCCESSFUL - task created successfully |
|
385 | 398 | * - RTEMS_INVALID_ADDRESS - id is NULL |
|
386 | 399 | * - RTEMS_INVALID_NAME - invalid task name |
|
387 | 400 | * - RTEMS_INVALID_PRIORITY - invalid task priority |
|
388 | 401 | * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured |
|
389 | 402 | * - RTEMS_TOO_MANY - too many tasks created |
|
390 | 403 | * - RTEMS_UNSATISFIED - not enough memory for stack/FP context |
|
391 | 404 | * - RTEMS_TOO_MANY - too many global objects |
|
392 | 405 | * |
|
393 | 406 | */ |
|
394 | 407 | |
|
395 | 408 | rtems_status_code status; |
|
396 | 409 | |
|
397 | 410 | //********** |
|
398 | 411 | // SPACEWIRE |
|
399 | 412 | // RECV |
|
400 | 413 | status = rtems_task_create( |
|
401 | 414 | Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE, |
|
402 | 415 | RTEMS_DEFAULT_MODES, |
|
403 | 416 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV] |
|
404 | 417 | ); |
|
405 | 418 | if (status == RTEMS_SUCCESSFUL) // SEND |
|
406 | 419 | { |
|
407 | 420 | status = rtems_task_create( |
|
408 | 421 | Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
409 | 422 | RTEMS_DEFAULT_MODES, |
|
410 | 423 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND] |
|
411 | 424 | ); |
|
412 | 425 | } |
|
413 | 426 | if (status == RTEMS_SUCCESSFUL) // LINK |
|
414 | 427 | { |
|
415 | 428 | status = rtems_task_create( |
|
416 | 429 | Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE, |
|
417 | 430 | RTEMS_DEFAULT_MODES, |
|
418 | 431 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK] |
|
419 | 432 | ); |
|
420 | 433 | } |
|
421 | 434 | if (status == RTEMS_SUCCESSFUL) // ACTN |
|
422 | 435 | { |
|
423 | 436 | status = rtems_task_create( |
|
424 | 437 | Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE, |
|
425 | 438 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
426 | 439 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN] |
|
427 | 440 | ); |
|
428 | 441 | } |
|
429 | 442 | if (status == RTEMS_SUCCESSFUL) // SPIQ |
|
430 | 443 | { |
|
431 | 444 | status = rtems_task_create( |
|
432 | 445 | Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE, |
|
433 | 446 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
434 | 447 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ] |
|
435 | 448 | ); |
|
436 | 449 | } |
|
437 | 450 | |
|
438 | 451 | //****************** |
|
439 | 452 | // SPECTRAL MATRICES |
|
440 | 453 | if (status == RTEMS_SUCCESSFUL) // AVF0 |
|
441 | 454 | { |
|
442 | 455 | status = rtems_task_create( |
|
443 | 456 | Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE, |
|
444 | 457 | RTEMS_DEFAULT_MODES, |
|
445 | 458 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0] |
|
446 | 459 | ); |
|
447 | 460 | } |
|
448 | 461 | if (status == RTEMS_SUCCESSFUL) // PRC0 |
|
449 | 462 | { |
|
450 | 463 | status = rtems_task_create( |
|
451 | 464 | Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
452 | 465 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
453 | 466 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0] |
|
454 | 467 | ); |
|
455 | 468 | } |
|
456 | 469 | if (status == RTEMS_SUCCESSFUL) // AVF1 |
|
457 | 470 | { |
|
458 | 471 | status = rtems_task_create( |
|
459 | 472 | Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE, |
|
460 | 473 | RTEMS_DEFAULT_MODES, |
|
461 | 474 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1] |
|
462 | 475 | ); |
|
463 | 476 | } |
|
464 | 477 | if (status == RTEMS_SUCCESSFUL) // PRC1 |
|
465 | 478 | { |
|
466 | 479 | status = rtems_task_create( |
|
467 | 480 | Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
468 | 481 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
469 | 482 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1] |
|
470 | 483 | ); |
|
471 | 484 | } |
|
472 | 485 | if (status == RTEMS_SUCCESSFUL) // AVF2 |
|
473 | 486 | { |
|
474 | 487 | status = rtems_task_create( |
|
475 | 488 | Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE, |
|
476 | 489 | RTEMS_DEFAULT_MODES, |
|
477 | 490 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2] |
|
478 | 491 | ); |
|
479 | 492 | } |
|
480 | 493 | if (status == RTEMS_SUCCESSFUL) // PRC2 |
|
481 | 494 | { |
|
482 | 495 | status = rtems_task_create( |
|
483 | 496 | Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
484 | 497 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
485 | 498 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2] |
|
486 | 499 | ); |
|
487 | 500 | } |
|
488 | 501 | |
|
489 | 502 | //**************** |
|
490 | 503 | // WAVEFORM PICKER |
|
491 | 504 | if (status == RTEMS_SUCCESSFUL) // WFRM |
|
492 | 505 | { |
|
493 | 506 | status = rtems_task_create( |
|
494 | 507 | Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE, |
|
495 | 508 | RTEMS_DEFAULT_MODES, |
|
496 | 509 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM] |
|
497 | 510 | ); |
|
498 | 511 | } |
|
499 | 512 | if (status == RTEMS_SUCCESSFUL) // CWF3 |
|
500 | 513 | { |
|
501 | 514 | status = rtems_task_create( |
|
502 | 515 | Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE, |
|
503 | 516 | RTEMS_DEFAULT_MODES, |
|
504 | 517 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3] |
|
505 | 518 | ); |
|
506 | 519 | } |
|
507 | 520 | if (status == RTEMS_SUCCESSFUL) // CWF2 |
|
508 | 521 | { |
|
509 | 522 | status = rtems_task_create( |
|
510 | 523 | Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE, |
|
511 | 524 | RTEMS_DEFAULT_MODES, |
|
512 | 525 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2] |
|
513 | 526 | ); |
|
514 | 527 | } |
|
515 | 528 | if (status == RTEMS_SUCCESSFUL) // CWF1 |
|
516 | 529 | { |
|
517 | 530 | status = rtems_task_create( |
|
518 | 531 | Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE, |
|
519 | 532 | RTEMS_DEFAULT_MODES, |
|
520 | 533 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1] |
|
521 | 534 | ); |
|
522 | 535 | } |
|
523 | 536 | if (status == RTEMS_SUCCESSFUL) // SWBD |
|
524 | 537 | { |
|
525 | 538 | status = rtems_task_create( |
|
526 | 539 | Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE, |
|
527 | 540 | RTEMS_DEFAULT_MODES, |
|
528 | 541 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD] |
|
529 | 542 | ); |
|
530 | 543 | } |
|
531 | 544 | |
|
532 | 545 | //***** |
|
533 | 546 | // MISC |
|
534 | 547 | if (status == RTEMS_SUCCESSFUL) // LOAD |
|
535 | 548 | { |
|
536 | 549 | status = rtems_task_create( |
|
537 | 550 | Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE, |
|
538 | 551 | RTEMS_DEFAULT_MODES, |
|
539 | 552 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD] |
|
540 | 553 | ); |
|
541 | 554 | } |
|
542 | 555 | if (status == RTEMS_SUCCESSFUL) // DUMB |
|
543 | 556 | { |
|
544 | 557 | status = rtems_task_create( |
|
545 | 558 | Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE, |
|
546 | 559 | RTEMS_DEFAULT_MODES, |
|
547 | 560 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB] |
|
548 | 561 | ); |
|
549 | 562 | } |
|
550 | 563 | if (status == RTEMS_SUCCESSFUL) // HOUS |
|
551 | 564 | { |
|
552 | 565 | status = rtems_task_create( |
|
553 | 566 | Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE, |
|
554 | 567 | RTEMS_DEFAULT_MODES, |
|
555 | 568 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS] |
|
556 | 569 | ); |
|
557 | 570 | } |
|
558 | 571 | if (status == RTEMS_SUCCESSFUL) // AVGV |
|
559 | 572 | { |
|
560 | 573 | status = rtems_task_create( |
|
561 | 574 | Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE, |
|
562 | 575 | RTEMS_DEFAULT_MODES, |
|
563 | 576 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV] |
|
564 | 577 | ); |
|
565 | 578 | } |
|
566 | 579 | |
|
567 | 580 | return status; |
|
568 | 581 | } |
|
569 | 582 | |
|
570 | 583 | int start_recv_send_tasks( void ) |
|
571 | 584 | { |
|
572 | 585 | rtems_status_code status; |
|
573 | 586 | |
|
574 | 587 | status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 ); |
|
575 | 588 | if (status!=RTEMS_SUCCESSFUL) { |
|
576 | 589 | BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n") |
|
577 | 590 | } |
|
578 | 591 | |
|
579 | 592 | if (status == RTEMS_SUCCESSFUL) // SEND |
|
580 | 593 | { |
|
581 | 594 | status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 ); |
|
582 | 595 | if (status!=RTEMS_SUCCESSFUL) { |
|
583 | 596 | BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n") |
|
584 | 597 | } |
|
585 | 598 | } |
|
586 | 599 | |
|
587 | 600 | return status; |
|
588 | 601 | } |
|
589 | 602 | |
|
590 | 603 | int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS |
|
591 | 604 | { |
|
592 | 605 | /** This function starts all RTEMS tasks used in the software. |
|
593 | 606 | * |
|
594 | 607 | * @return RTEMS directive status codes: |
|
595 | 608 | * - RTEMS_SUCCESSFUL - ask started successfully |
|
596 | 609 | * - RTEMS_INVALID_ADDRESS - invalid task entry point |
|
597 | 610 | * - RTEMS_INVALID_ID - invalid task id |
|
598 | 611 | * - RTEMS_INCORRECT_STATE - task not in the dormant state |
|
599 | 612 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task |
|
600 | 613 | * |
|
601 | 614 | */ |
|
602 | 615 | // starts all the tasks fot eh flight software |
|
603 | 616 | |
|
604 | 617 | rtems_status_code status; |
|
605 | 618 | |
|
606 | 619 | //********** |
|
607 | 620 | // SPACEWIRE |
|
608 | 621 | status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 ); |
|
609 | 622 | if (status!=RTEMS_SUCCESSFUL) { |
|
610 | 623 | BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n") |
|
611 | 624 | } |
|
612 | 625 | |
|
613 | 626 | if (status == RTEMS_SUCCESSFUL) // LINK |
|
614 | 627 | { |
|
615 | 628 | status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 ); |
|
616 | 629 | if (status!=RTEMS_SUCCESSFUL) { |
|
617 | 630 | BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n") |
|
618 | 631 | } |
|
619 | 632 | } |
|
620 | 633 | |
|
621 | 634 | if (status == RTEMS_SUCCESSFUL) // ACTN |
|
622 | 635 | { |
|
623 | 636 | status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 ); |
|
624 | 637 | if (status!=RTEMS_SUCCESSFUL) { |
|
625 | 638 | BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n") |
|
626 | 639 | } |
|
627 | 640 | } |
|
628 | 641 | |
|
629 | 642 | //****************** |
|
630 | 643 | // SPECTRAL MATRICES |
|
631 | 644 | if (status == RTEMS_SUCCESSFUL) // AVF0 |
|
632 | 645 | { |
|
633 | 646 | status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY ); |
|
634 | 647 | if (status!=RTEMS_SUCCESSFUL) { |
|
635 | 648 | BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n") |
|
636 | 649 | } |
|
637 | 650 | } |
|
638 | 651 | if (status == RTEMS_SUCCESSFUL) // PRC0 |
|
639 | 652 | { |
|
640 | 653 | status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY ); |
|
641 | 654 | if (status!=RTEMS_SUCCESSFUL) { |
|
642 | 655 | BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n") |
|
643 | 656 | } |
|
644 | 657 | } |
|
645 | 658 | if (status == RTEMS_SUCCESSFUL) // AVF1 |
|
646 | 659 | { |
|
647 | 660 | status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY ); |
|
648 | 661 | if (status!=RTEMS_SUCCESSFUL) { |
|
649 | 662 | BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n") |
|
650 | 663 | } |
|
651 | 664 | } |
|
652 | 665 | if (status == RTEMS_SUCCESSFUL) // PRC1 |
|
653 | 666 | { |
|
654 | 667 | status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY ); |
|
655 | 668 | if (status!=RTEMS_SUCCESSFUL) { |
|
656 | 669 | BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n") |
|
657 | 670 | } |
|
658 | 671 | } |
|
659 | 672 | if (status == RTEMS_SUCCESSFUL) // AVF2 |
|
660 | 673 | { |
|
661 | 674 | status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 ); |
|
662 | 675 | if (status!=RTEMS_SUCCESSFUL) { |
|
663 | 676 | BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n") |
|
664 | 677 | } |
|
665 | 678 | } |
|
666 | 679 | if (status == RTEMS_SUCCESSFUL) // PRC2 |
|
667 | 680 | { |
|
668 | 681 | status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 ); |
|
669 | 682 | if (status!=RTEMS_SUCCESSFUL) { |
|
670 | 683 | BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n") |
|
671 | 684 | } |
|
672 | 685 | } |
|
673 | 686 | |
|
674 | 687 | //**************** |
|
675 | 688 | // WAVEFORM PICKER |
|
676 | 689 | if (status == RTEMS_SUCCESSFUL) // WFRM |
|
677 | 690 | { |
|
678 | 691 | status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 ); |
|
679 | 692 | if (status!=RTEMS_SUCCESSFUL) { |
|
680 | 693 | BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n") |
|
681 | 694 | } |
|
682 | 695 | } |
|
683 | 696 | if (status == RTEMS_SUCCESSFUL) // CWF3 |
|
684 | 697 | { |
|
685 | 698 | status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 ); |
|
686 | 699 | if (status!=RTEMS_SUCCESSFUL) { |
|
687 | 700 | BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n") |
|
688 | 701 | } |
|
689 | 702 | } |
|
690 | 703 | if (status == RTEMS_SUCCESSFUL) // CWF2 |
|
691 | 704 | { |
|
692 | 705 | status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 ); |
|
693 | 706 | if (status!=RTEMS_SUCCESSFUL) { |
|
694 | 707 | BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n") |
|
695 | 708 | } |
|
696 | 709 | } |
|
697 | 710 | if (status == RTEMS_SUCCESSFUL) // CWF1 |
|
698 | 711 | { |
|
699 | 712 | status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 ); |
|
700 | 713 | if (status!=RTEMS_SUCCESSFUL) { |
|
701 | 714 | BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n") |
|
702 | 715 | } |
|
703 | 716 | } |
|
704 | 717 | if (status == RTEMS_SUCCESSFUL) // SWBD |
|
705 | 718 | { |
|
706 | 719 | status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 ); |
|
707 | 720 | if (status!=RTEMS_SUCCESSFUL) { |
|
708 | 721 | BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n") |
|
709 | 722 | } |
|
710 | 723 | } |
|
711 | 724 | |
|
712 | 725 | //***** |
|
713 | 726 | // MISC |
|
714 | 727 | if (status == RTEMS_SUCCESSFUL) // HOUS |
|
715 | 728 | { |
|
716 | 729 | status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 ); |
|
717 | 730 | if (status!=RTEMS_SUCCESSFUL) { |
|
718 | 731 | BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n") |
|
719 | 732 | } |
|
720 | 733 | } |
|
721 | 734 | if (status == RTEMS_SUCCESSFUL) // AVGV |
|
722 | 735 | { |
|
723 | 736 | status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 ); |
|
724 | 737 | if (status!=RTEMS_SUCCESSFUL) { |
|
725 | 738 | BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n") |
|
726 | 739 | } |
|
727 | 740 | } |
|
728 | 741 | if (status == RTEMS_SUCCESSFUL) // DUMB |
|
729 | 742 | { |
|
730 | 743 | status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 ); |
|
731 | 744 | if (status!=RTEMS_SUCCESSFUL) { |
|
732 | 745 | BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") |
|
733 | 746 | } |
|
734 | 747 | } |
|
735 | 748 | if (status == RTEMS_SUCCESSFUL) // LOAD |
|
736 | 749 | { |
|
737 | 750 | status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 ); |
|
738 | 751 | if (status!=RTEMS_SUCCESSFUL) { |
|
739 | 752 | BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n") |
|
740 | 753 | } |
|
741 | 754 | } |
|
742 | 755 | |
|
743 | 756 | return status; |
|
744 | 757 | } |
|
745 | 758 | |
|
746 | 759 | rtems_status_code create_message_queues( void ) // create the two message queues used in the software |
|
747 | 760 | { |
|
748 | 761 | rtems_status_code status_recv; |
|
749 | 762 | rtems_status_code status_send; |
|
750 | 763 | rtems_status_code status_q_p0; |
|
751 | 764 | rtems_status_code status_q_p1; |
|
752 | 765 | rtems_status_code status_q_p2; |
|
753 | 766 | rtems_status_code ret; |
|
754 | 767 | rtems_id queue_id; |
|
755 | 768 | |
|
756 | 769 | //**************************************** |
|
757 | 770 | // create the queue for handling valid TCs |
|
758 | 771 | status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV], |
|
759 | 772 | MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE, |
|
760 | 773 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
761 | 774 | if ( status_recv != RTEMS_SUCCESSFUL ) { |
|
762 | 775 | PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv) |
|
763 | 776 | } |
|
764 | 777 | |
|
765 | 778 | //************************************************ |
|
766 | 779 | // create the queue for handling TM packet sending |
|
767 | 780 | status_send = rtems_message_queue_create( misc_name[QUEUE_SEND], |
|
768 | 781 | MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND, |
|
769 | 782 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
770 | 783 | if ( status_send != RTEMS_SUCCESSFUL ) { |
|
771 | 784 | PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send) |
|
772 | 785 | } |
|
773 | 786 | |
|
774 | 787 | //***************************************************************************** |
|
775 | 788 | // create the queue for handling averaged spectral matrices for processing @ f0 |
|
776 | 789 | status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0], |
|
777 | 790 | MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0, |
|
778 | 791 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
779 | 792 | if ( status_q_p0 != RTEMS_SUCCESSFUL ) { |
|
780 | 793 | PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0) |
|
781 | 794 | } |
|
782 | 795 | |
|
783 | 796 | //***************************************************************************** |
|
784 | 797 | // create the queue for handling averaged spectral matrices for processing @ f1 |
|
785 | 798 | status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1], |
|
786 | 799 | MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1, |
|
787 | 800 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
788 | 801 | if ( status_q_p1 != RTEMS_SUCCESSFUL ) { |
|
789 | 802 | PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1) |
|
790 | 803 | } |
|
791 | 804 | |
|
792 | 805 | //***************************************************************************** |
|
793 | 806 | // create the queue for handling averaged spectral matrices for processing @ f2 |
|
794 | 807 | status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2], |
|
795 | 808 | MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2, |
|
796 | 809 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
797 | 810 | if ( status_q_p2 != RTEMS_SUCCESSFUL ) { |
|
798 | 811 | PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2) |
|
799 | 812 | } |
|
800 | 813 | |
|
801 | 814 | if ( status_recv != RTEMS_SUCCESSFUL ) |
|
802 | 815 | { |
|
803 | 816 | ret = status_recv; |
|
804 | 817 | } |
|
805 | 818 | else if( status_send != RTEMS_SUCCESSFUL ) |
|
806 | 819 | { |
|
807 | 820 | ret = status_send; |
|
808 | 821 | } |
|
809 | 822 | else if( status_q_p0 != RTEMS_SUCCESSFUL ) |
|
810 | 823 | { |
|
811 | 824 | ret = status_q_p0; |
|
812 | 825 | } |
|
813 | 826 | else if( status_q_p1 != RTEMS_SUCCESSFUL ) |
|
814 | 827 | { |
|
815 | 828 | ret = status_q_p1; |
|
816 | 829 | } |
|
817 | 830 | else |
|
818 | 831 | { |
|
819 | 832 | ret = status_q_p2; |
|
820 | 833 | } |
|
821 | 834 | |
|
822 | 835 | return ret; |
|
823 | 836 | } |
|
824 | 837 | |
|
825 | 838 | rtems_status_code create_timecode_timer( void ) |
|
826 | 839 | { |
|
827 | 840 | rtems_status_code status; |
|
828 | 841 | |
|
829 | 842 | status = rtems_timer_create( timecode_timer_name, &timecode_timer_id ); |
|
830 | 843 | |
|
831 | 844 | if ( status != RTEMS_SUCCESSFUL ) |
|
832 | 845 | { |
|
833 | 846 | PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status) |
|
834 | 847 | } |
|
835 | 848 | else |
|
836 | 849 | { |
|
837 | 850 | PRINTF("in create_timer_timecode *** OK creating SPTC timer\n") |
|
838 | 851 | } |
|
839 | 852 | |
|
840 | 853 | return status; |
|
841 | 854 | } |
|
842 | 855 | |
|
843 | 856 | rtems_status_code get_message_queue_id_send( rtems_id *queue_id ) |
|
844 | 857 | { |
|
845 | 858 | rtems_status_code status; |
|
846 | 859 | rtems_name queue_name; |
|
847 | 860 | |
|
848 | 861 | queue_name = rtems_build_name( 'Q', '_', 'S', 'D' ); |
|
849 | 862 | |
|
850 | 863 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
851 | 864 | |
|
852 | 865 | return status; |
|
853 | 866 | } |
|
854 | 867 | |
|
855 | 868 | rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ) |
|
856 | 869 | { |
|
857 | 870 | rtems_status_code status; |
|
858 | 871 | rtems_name queue_name; |
|
859 | 872 | |
|
860 | 873 | queue_name = rtems_build_name( 'Q', '_', 'R', 'V' ); |
|
861 | 874 | |
|
862 | 875 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
863 | 876 | |
|
864 | 877 | return status; |
|
865 | 878 | } |
|
866 | 879 | |
|
867 | 880 | rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id ) |
|
868 | 881 | { |
|
869 | 882 | rtems_status_code status; |
|
870 | 883 | rtems_name queue_name; |
|
871 | 884 | |
|
872 | 885 | queue_name = rtems_build_name( 'Q', '_', 'P', '0' ); |
|
873 | 886 | |
|
874 | 887 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
875 | 888 | |
|
876 | 889 | return status; |
|
877 | 890 | } |
|
878 | 891 | |
|
879 | 892 | rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ) |
|
880 | 893 | { |
|
881 | 894 | rtems_status_code status; |
|
882 | 895 | rtems_name queue_name; |
|
883 | 896 | |
|
884 | 897 | queue_name = rtems_build_name( 'Q', '_', 'P', '1' ); |
|
885 | 898 | |
|
886 | 899 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
887 | 900 | |
|
888 | 901 | return status; |
|
889 | 902 | } |
|
890 | 903 | |
|
891 | 904 | rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ) |
|
892 | 905 | { |
|
893 | 906 | rtems_status_code status; |
|
894 | 907 | rtems_name queue_name; |
|
895 | 908 | |
|
896 | 909 | queue_name = rtems_build_name( 'Q', '_', 'P', '2' ); |
|
897 | 910 | |
|
898 | 911 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
899 | 912 | |
|
900 | 913 | return status; |
|
901 | 914 | } |
|
902 | 915 | |
|
903 | 916 | void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max ) |
|
904 | 917 | { |
|
905 | 918 | u_int32_t count; |
|
906 | 919 | rtems_status_code status; |
|
907 | 920 | |
|
908 | 921 | status = rtems_message_queue_get_number_pending( queue_id, &count ); |
|
909 | 922 | |
|
910 | 923 | count = count + 1; |
|
911 | 924 | |
|
912 | 925 | if (status != RTEMS_SUCCESSFUL) |
|
913 | 926 | { |
|
914 | 927 | PRINTF1("in update_queue_max_count *** ERR = %d\n", status) |
|
915 | 928 | } |
|
916 | 929 | else |
|
917 | 930 | { |
|
918 | 931 | if (count > *fifo_size_max) |
|
919 | 932 | { |
|
920 | 933 | *fifo_size_max = count; |
|
921 | 934 | } |
|
922 | 935 | } |
|
923 | 936 | } |
|
924 | 937 | |
|
925 | 938 | void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize ) |
|
926 | 939 | { |
|
927 | 940 | unsigned char i; |
|
928 | 941 | |
|
929 | 942 | //*************** |
|
930 | 943 | // BUFFER ADDRESS |
|
931 | 944 | for(i=0; i<nbNodes; i++) |
|
932 | 945 | { |
|
933 | 946 | ring[i].coarseTime = 0xffffffff; |
|
934 | 947 | ring[i].fineTime = 0xffffffff; |
|
935 | 948 | ring[i].sid = 0x00; |
|
936 | 949 | ring[i].status = 0x00; |
|
937 | 950 | ring[i].buffer_address = (int) &buffer[ i * bufferSize ]; |
|
938 | 951 | } |
|
939 | 952 | |
|
940 | 953 | //***** |
|
941 | 954 | // NEXT |
|
942 | 955 | ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ]; |
|
943 | 956 | for(i=0; i<nbNodes-1; i++) |
|
944 | 957 | { |
|
945 | 958 | ring[i].next = (ring_node*) &ring[ i + 1 ]; |
|
946 | 959 | } |
|
947 | 960 | |
|
948 | 961 | //********* |
|
949 | 962 | // PREVIOUS |
|
950 | 963 | ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ]; |
|
951 | 964 | for(i=1; i<nbNodes; i++) |
|
952 | 965 | { |
|
953 | 966 | ring[i].previous = (ring_node*) &ring[ i - 1 ]; |
|
954 | 967 | } |
|
955 | 968 | } |
@@ -1,898 +1,913 | |||
|
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 | int16_t hk_lfr_sc_v_f3_as_int16; | |
|
11 | int16_t hk_lfr_sc_e1_f3_as_int16; | |
|
12 | int16_t hk_lfr_sc_e2_f3_as_int16; | |
|
13 | ||
|
10 | 14 | void timer_configure(unsigned char timer, unsigned int clock_divider, |
|
11 | 15 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
12 | 16 | { |
|
13 | 17 | /** This function configures a GPTIMER timer instantiated in the VHDL design. |
|
14 | 18 | * |
|
15 | 19 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
16 | 20 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
17 | 21 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
18 | 22 | * @param interrupt_level is the interrupt level that the timer drives. |
|
19 | 23 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. |
|
20 | 24 | * |
|
21 | 25 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 |
|
22 | 26 | * |
|
23 | 27 | */ |
|
24 | 28 | |
|
25 | 29 | rtems_status_code status; |
|
26 | 30 | rtems_isr_entry old_isr_handler; |
|
27 | 31 | |
|
28 | 32 | gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register |
|
29 | 33 | |
|
30 | 34 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
31 | 35 | if (status!=RTEMS_SUCCESSFUL) |
|
32 | 36 | { |
|
33 | 37 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") |
|
34 | 38 | } |
|
35 | 39 | |
|
36 | 40 | timer_set_clock_divider( timer, clock_divider); |
|
37 | 41 | } |
|
38 | 42 | |
|
39 | 43 | void timer_start(unsigned char timer) |
|
40 | 44 | { |
|
41 | 45 | /** This function starts a GPTIMER timer. |
|
42 | 46 | * |
|
43 | 47 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
44 | 48 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
45 | 49 | * |
|
46 | 50 | */ |
|
47 | 51 | |
|
48 | 52 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
49 | 53 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register |
|
50 | 54 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer |
|
51 | 55 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart |
|
52 | 56 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable |
|
53 | 57 | } |
|
54 | 58 | |
|
55 | 59 | void timer_stop(unsigned char timer) |
|
56 | 60 | { |
|
57 | 61 | /** This function stops a GPTIMER timer. |
|
58 | 62 | * |
|
59 | 63 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
60 | 64 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
61 | 65 | * |
|
62 | 66 | */ |
|
63 | 67 | |
|
64 | 68 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer |
|
65 | 69 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable |
|
66 | 70 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
67 | 71 | } |
|
68 | 72 | |
|
69 | 73 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider) |
|
70 | 74 | { |
|
71 | 75 | /** This function sets the clock divider of a GPTIMER timer. |
|
72 | 76 | * |
|
73 | 77 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
74 | 78 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
75 | 79 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
76 | 80 | * |
|
77 | 81 | */ |
|
78 | 82 | |
|
79 | 83 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
80 | 84 | } |
|
81 | 85 | |
|
82 | 86 | // WATCHDOG |
|
83 | 87 | |
|
84 | 88 | rtems_isr watchdog_isr( rtems_vector_number vector ) |
|
85 | 89 | { |
|
86 | 90 | rtems_status_code status_code; |
|
87 | 91 | |
|
88 | 92 | status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 ); |
|
89 | 93 | |
|
90 | 94 | PRINTF("watchdog_isr *** this is the end, exit(0)\n"); |
|
91 | 95 | |
|
92 | 96 | exit(0); |
|
93 | 97 | } |
|
94 | 98 | |
|
95 | 99 | void watchdog_configure(void) |
|
96 | 100 | { |
|
97 | 101 | /** This function configure the watchdog. |
|
98 | 102 | * |
|
99 | 103 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
100 | 104 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
101 | 105 | * |
|
102 | 106 | * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB. |
|
103 | 107 | * |
|
104 | 108 | */ |
|
105 | 109 | |
|
106 | 110 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration |
|
107 | 111 | |
|
108 | 112 | timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr ); |
|
109 | 113 | |
|
110 | 114 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
111 | 115 | } |
|
112 | 116 | |
|
113 | 117 | void watchdog_stop(void) |
|
114 | 118 | { |
|
115 | 119 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line |
|
116 | 120 | timer_stop( TIMER_WATCHDOG ); |
|
117 | 121 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
118 | 122 | } |
|
119 | 123 | |
|
120 | 124 | void watchdog_reload(void) |
|
121 | 125 | { |
|
122 | 126 | /** This function reloads the watchdog timer counter with the timer reload value. |
|
123 | 127 | * |
|
124 | 128 | * @param void |
|
125 | 129 | * |
|
126 | 130 | * @return void |
|
127 | 131 | * |
|
128 | 132 | */ |
|
129 | 133 | |
|
130 | 134 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register |
|
131 | 135 | } |
|
132 | 136 | |
|
133 | 137 | void watchdog_start(void) |
|
134 | 138 | { |
|
135 | 139 | /** This function starts the watchdog timer. |
|
136 | 140 | * |
|
137 | 141 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
138 | 142 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
139 | 143 | * |
|
140 | 144 | */ |
|
141 | 145 | |
|
142 | 146 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
143 | 147 | |
|
144 | 148 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000010; // clear pending IRQ if any |
|
145 | 149 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register |
|
146 | 150 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000001; // EN enable the timer |
|
147 | 151 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000008; // IE interrupt enable |
|
148 | 152 | |
|
149 | 153 | LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
150 | 154 | |
|
151 | 155 | } |
|
152 | 156 | |
|
153 | 157 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register |
|
154 | 158 | { |
|
155 | 159 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
156 | 160 | |
|
157 | 161 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; |
|
158 | 162 | |
|
159 | 163 | return 0; |
|
160 | 164 | } |
|
161 | 165 | |
|
162 | 166 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) |
|
163 | 167 | { |
|
164 | 168 | /** This function sets the scaler reload register of the apbuart module |
|
165 | 169 | * |
|
166 | 170 | * @param regs is the address of the apbuart registers in memory |
|
167 | 171 | * @param value is the value that will be stored in the scaler register |
|
168 | 172 | * |
|
169 | 173 | * The value shall be set by the software to get data on the serial interface. |
|
170 | 174 | * |
|
171 | 175 | */ |
|
172 | 176 | |
|
173 | 177 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; |
|
174 | 178 | |
|
175 | 179 | apbuart_regs->scaler = value; |
|
176 | 180 | |
|
177 | 181 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) |
|
178 | 182 | } |
|
179 | 183 | |
|
180 | 184 | //************ |
|
181 | 185 | // RTEMS TASKS |
|
182 | 186 | |
|
183 | 187 | rtems_task load_task(rtems_task_argument argument) |
|
184 | 188 | { |
|
185 | 189 | BOOT_PRINTF("in LOAD *** \n") |
|
186 | 190 | |
|
187 | 191 | rtems_status_code status; |
|
188 | 192 | unsigned int i; |
|
189 | 193 | unsigned int j; |
|
190 | 194 | rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic |
|
191 | 195 | rtems_id watchdog_period_id; // id of the watchdog rate monotonic period |
|
192 | 196 | |
|
193 | 197 | name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' ); |
|
194 | 198 | |
|
195 | 199 | status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id ); |
|
196 | 200 | if( status != RTEMS_SUCCESSFUL ) { |
|
197 | 201 | PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
198 | 202 | } |
|
199 | 203 | |
|
200 | 204 | i = 0; |
|
201 | 205 | j = 0; |
|
202 | 206 | |
|
203 | 207 | watchdog_configure(); |
|
204 | 208 | |
|
205 | 209 | watchdog_start(); |
|
206 | 210 | |
|
207 | 211 | set_sy_lfr_watchdog_enabled( true ); |
|
208 | 212 | |
|
209 | 213 | while(1){ |
|
210 | 214 | status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD ); |
|
211 | 215 | watchdog_reload(); |
|
212 | 216 | i = i + 1; |
|
213 | 217 | if ( i == 10 ) |
|
214 | 218 | { |
|
215 | 219 | i = 0; |
|
216 | 220 | j = j + 1; |
|
217 | 221 | PRINTF1("%d\n", j) |
|
218 | 222 | } |
|
219 | 223 | #ifdef DEBUG_WATCHDOG |
|
220 | 224 | if (j == 3 ) |
|
221 | 225 | { |
|
222 | 226 | status = rtems_task_delete(RTEMS_SELF); |
|
223 | 227 | } |
|
224 | 228 | #endif |
|
225 | 229 | } |
|
226 | 230 | } |
|
227 | 231 | |
|
228 | 232 | rtems_task hous_task(rtems_task_argument argument) |
|
229 | 233 | { |
|
230 | 234 | rtems_status_code status; |
|
231 | 235 | rtems_status_code spare_status; |
|
232 | 236 | rtems_id queue_id; |
|
233 | 237 | rtems_rate_monotonic_period_status period_status; |
|
234 | 238 | |
|
235 | 239 | status = get_message_queue_id_send( &queue_id ); |
|
236 | 240 | if (status != RTEMS_SUCCESSFUL) |
|
237 | 241 | { |
|
238 | 242 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
239 | 243 | } |
|
240 | 244 | |
|
241 | 245 | BOOT_PRINTF("in HOUS ***\n"); |
|
242 | 246 | |
|
243 | 247 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
244 | 248 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); |
|
245 | 249 | if( status != RTEMS_SUCCESSFUL ) { |
|
246 | 250 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
247 | 251 | } |
|
248 | 252 | } |
|
249 | 253 | |
|
250 | 254 | status = rtems_rate_monotonic_cancel(HK_id); |
|
251 | 255 | if( status != RTEMS_SUCCESSFUL ) { |
|
252 | 256 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ); |
|
253 | 257 | } |
|
254 | 258 | else { |
|
255 | 259 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n"); |
|
256 | 260 | } |
|
257 | 261 | |
|
258 | 262 | // startup phase |
|
259 | 263 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); |
|
260 | 264 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
261 | 265 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
262 | 266 | while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway |
|
263 | 267 | { |
|
264 | 268 | if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization |
|
265 | 269 | { |
|
266 | 270 | break; // break if LFR is synchronized |
|
267 | 271 | } |
|
268 | 272 | else |
|
269 | 273 | { |
|
270 | 274 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
271 | 275 | // sched_yield(); |
|
272 | 276 | status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms |
|
273 | 277 | } |
|
274 | 278 | } |
|
275 | 279 | status = rtems_rate_monotonic_cancel(HK_id); |
|
276 | 280 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
277 | 281 | |
|
278 | 282 | set_hk_lfr_reset_cause( POWER_ON ); |
|
279 | 283 | |
|
280 | 284 | while(1){ // launch the rate monotonic task |
|
281 | 285 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); |
|
282 | 286 | if ( status != RTEMS_SUCCESSFUL ) { |
|
283 | 287 | PRINTF1( "in HOUS *** ERR period: %d\n", status); |
|
284 | 288 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); |
|
285 | 289 | } |
|
286 | 290 | else { |
|
287 | 291 | housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8); |
|
288 | 292 | housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK ); |
|
289 | 293 | increment_seq_counter( &sequenceCounterHK ); |
|
290 | 294 | |
|
291 | 295 | housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
292 | 296 | housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
293 | 297 | housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
294 | 298 | housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
295 | 299 | housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
296 | 300 | housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
297 | 301 | |
|
298 | 302 | spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] ); |
|
299 | 303 | |
|
300 | 304 | spacewire_read_statistics(); |
|
301 | 305 | |
|
302 | 306 | update_hk_with_grspw_stats(); |
|
303 | 307 | |
|
304 | 308 | set_hk_lfr_time_not_synchro(); |
|
305 | 309 | |
|
306 | 310 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; |
|
307 | 311 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; |
|
308 | 312 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; |
|
309 | 313 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; |
|
310 | 314 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; |
|
311 | 315 | |
|
312 | 316 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; |
|
313 | 317 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
314 | 318 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); |
|
315 | 319 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); |
|
316 | 320 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); |
|
317 | 321 | |
|
318 | 322 | hk_lfr_le_me_he_update(); |
|
319 | 323 | |
|
320 | housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags; | |
|
324 | housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = cp_rpw_sc_rw1_rw2_f_flags; | |
|
325 | housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = cp_rpw_sc_rw3_rw4_f_flags; | |
|
321 | 326 | |
|
322 | 327 | // SEND PACKET |
|
323 | 328 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
324 | 329 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
325 | 330 | if (status != RTEMS_SUCCESSFUL) { |
|
326 | 331 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
327 | 332 | } |
|
328 | 333 | } |
|
329 | 334 | } |
|
330 | 335 | |
|
331 | 336 | PRINTF("in HOUS *** deleting task\n") |
|
332 | 337 | |
|
333 | 338 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
334 | 339 | |
|
335 | 340 | return; |
|
336 | 341 | } |
|
337 | 342 | |
|
338 | 343 | rtems_task avgv_task(rtems_task_argument argument) |
|
339 | 344 | { |
|
340 | 345 | #define MOVING_AVERAGE 16 |
|
341 | 346 | rtems_status_code status; |
|
342 | 347 | unsigned int v[MOVING_AVERAGE]; |
|
343 | 348 | unsigned int e1[MOVING_AVERAGE]; |
|
344 | 349 | unsigned int e2[MOVING_AVERAGE]; |
|
345 | 350 | float average_v; |
|
346 | 351 | float average_e1; |
|
347 | 352 | float average_e2; |
|
353 | float newValue_v; | |
|
354 | float newValue_e1; | |
|
355 | float newValue_e2; | |
|
348 | 356 | unsigned char k; |
|
349 | 357 | unsigned char indexOfOldValue; |
|
350 | 358 | |
|
351 | 359 | BOOT_PRINTF("in AVGV ***\n"); |
|
352 | 360 | |
|
353 | 361 | if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
354 | 362 | status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id ); |
|
355 | 363 | if( status != RTEMS_SUCCESSFUL ) { |
|
356 | 364 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
357 | 365 | } |
|
358 | 366 | } |
|
359 | 367 | |
|
360 | 368 | status = rtems_rate_monotonic_cancel(AVGV_id); |
|
361 | 369 | if( status != RTEMS_SUCCESSFUL ) { |
|
362 | 370 | PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status ); |
|
363 | 371 | } |
|
364 | 372 | else { |
|
365 | 373 | DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n"); |
|
366 | 374 | } |
|
367 | 375 | |
|
368 | 376 | // initialize values |
|
369 | 377 | k = 0; |
|
370 | 378 | indexOfOldValue = MOVING_AVERAGE - 1; |
|
371 | 379 | for (k = 0; k < MOVING_AVERAGE; k++) |
|
372 | 380 | { |
|
373 | 381 | v[k] = 0; |
|
374 | 382 | e1[k] = 0; |
|
375 | 383 | e2[k] = 0; |
|
376 | 384 | average_v = 0.; |
|
377 | 385 | average_e1 = 0.; |
|
378 | 386 | average_e2 = 0.; |
|
387 | newValue_v = 0.; | |
|
388 | newValue_e1 = 0.; | |
|
389 | newValue_e2 = 0.; | |
|
379 | 390 | } |
|
380 | 391 | |
|
381 | 392 | k = 0; |
|
382 | 393 | |
|
383 | 394 | while(1){ // launch the rate monotonic task |
|
384 | 395 | status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD ); |
|
385 | 396 | if ( status != RTEMS_SUCCESSFUL ) { |
|
386 | 397 | PRINTF1( "in AVGV *** ERR period: %d\n", status); |
|
387 | 398 | } |
|
388 | 399 | else { |
|
389 |
// |
|
|
390 |
v |
|
|
391 |
e1 |
|
|
392 |
e2 |
|
|
393 | if (k == (MOVING_AVERAGE - 1)) | |
|
394 | { | |
|
395 | indexOfOldValue = 0; | |
|
396 | } | |
|
397 | else | |
|
398 | { | |
|
399 | indexOfOldValue = k + 1; | |
|
400 | } | |
|
401 | average_v = average_v + v[k] - v[indexOfOldValue]; | |
|
402 | average_e1 = average_e1 + e1[k] - e1[indexOfOldValue]; | |
|
403 | average_e2 = average_e2 + e2[k] - e2[indexOfOldValue]; | |
|
400 | // get new values | |
|
401 | newValue_v = waveform_picker_regs->v; | |
|
402 | newValue_e1 = waveform_picker_regs->e1; | |
|
403 | newValue_e2 = waveform_picker_regs->e2; | |
|
404 | ||
|
405 | // compute the moving average | |
|
406 | average_v = average_v + newValue_v - v[k]; | |
|
407 | average_e1 = average_e1 + newValue_e1 - e1[k]; | |
|
408 | average_e2 = average_e2 + newValue_e2 - e2[k]; | |
|
409 | ||
|
410 | // store new values in buffers | |
|
411 | v[k] = newValue_v; | |
|
412 | e1[k] = newValue_e1; | |
|
413 | e2[k] = newValue_e2; | |
|
404 | 414 | } |
|
405 | 415 | if (k == (MOVING_AVERAGE-1)) |
|
406 | 416 | { |
|
407 | 417 | k = 0; |
|
408 | 418 | printf("tick\n"); |
|
409 | 419 | } |
|
410 | 420 | else |
|
411 | 421 | { |
|
412 | 422 | k++; |
|
413 | 423 | } |
|
414 | 424 | } |
|
415 | 425 | |
|
416 | PRINTF("in AVGV *** deleting task\n") | |
|
426 | //update int16 values | |
|
427 | hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / ((float) MOVING_AVERAGE) ); | |
|
428 | hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / ((float) MOVING_AVERAGE) ); | |
|
429 | hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / ((float) MOVING_AVERAGE) ); | |
|
430 | ||
|
431 | PRINTF("in AVGV *** deleting task\n"); | |
|
417 | 432 | |
|
418 | 433 |
|
|
419 | 434 | |
|
420 | 435 | return; |
|
421 | 436 | } |
|
422 | 437 | |
|
423 | 438 | rtems_task dumb_task( rtems_task_argument unused ) |
|
424 | 439 | { |
|
425 | 440 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
426 | 441 | * |
|
427 | 442 | * @param unused is the starting argument of the RTEMS task |
|
428 | 443 | * |
|
429 | 444 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
430 | 445 | * |
|
431 | 446 | */ |
|
432 | 447 | |
|
433 | 448 | unsigned int i; |
|
434 | 449 | unsigned int intEventOut; |
|
435 | 450 | unsigned int coarse_time = 0; |
|
436 | 451 | unsigned int fine_time = 0; |
|
437 | 452 | rtems_event_set event_out; |
|
438 | 453 | |
|
439 | 454 | char *DumbMessages[15] = {"in DUMB *** default", // RTEMS_EVENT_0 |
|
440 | 455 | "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 |
|
441 | 456 | "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 |
|
442 | 457 | "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 |
|
443 | 458 | "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 |
|
444 | 459 | "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 |
|
445 | 460 | "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6 |
|
446 | 461 | "ready for dump", // RTEMS_EVENT_7 |
|
447 | 462 | "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 |
|
448 | 463 | "tick", // RTEMS_EVENT_9 |
|
449 | 464 | "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 |
|
450 | 465 | "VHDL ERR *** unexpected ready matrix values", // RTEMS_EVENT_11 |
|
451 | 466 | "WATCHDOG timer", // RTEMS_EVENT_12 |
|
452 | 467 | "TIMECODE timer", // RTEMS_EVENT_13 |
|
453 | 468 | "TIMECODE ISR" // RTEMS_EVENT_14 |
|
454 | 469 | }; |
|
455 | 470 | |
|
456 | 471 | BOOT_PRINTF("in DUMB *** \n") |
|
457 | 472 | |
|
458 | 473 | while(1){ |
|
459 | 474 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
460 | 475 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
461 | 476 | | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13 |
|
462 | 477 | | RTEMS_EVENT_14, |
|
463 | 478 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
464 | 479 | intEventOut = (unsigned int) event_out; |
|
465 | 480 | for ( i=0; i<32; i++) |
|
466 | 481 | { |
|
467 | 482 | if ( ((intEventOut >> i) & 0x0001) != 0) |
|
468 | 483 | { |
|
469 | 484 | coarse_time = time_management_regs->coarse_time; |
|
470 | 485 | fine_time = time_management_regs->fine_time; |
|
471 | 486 | if (i==12) |
|
472 | 487 | { |
|
473 | 488 | PRINTF1("%s\n", DumbMessages[12]) |
|
474 | 489 | } |
|
475 | 490 | if (i==13) |
|
476 | 491 | { |
|
477 | 492 | PRINTF1("%s\n", DumbMessages[13]) |
|
478 | 493 | } |
|
479 | 494 | if (i==14) |
|
480 | 495 | { |
|
481 | 496 | PRINTF1("%s\n", DumbMessages[1]) |
|
482 | 497 | } |
|
483 | 498 | } |
|
484 | 499 | } |
|
485 | 500 | } |
|
486 | 501 | } |
|
487 | 502 | |
|
488 | 503 | //***************************** |
|
489 | 504 | // init housekeeping parameters |
|
490 | 505 | |
|
491 | 506 | void init_housekeeping_parameters( void ) |
|
492 | 507 | { |
|
493 | 508 | /** This function initialize the housekeeping_packet global variable with default values. |
|
494 | 509 | * |
|
495 | 510 | */ |
|
496 | 511 | |
|
497 | 512 | unsigned int i = 0; |
|
498 | 513 | unsigned char *parameters; |
|
499 | 514 | unsigned char sizeOfHK; |
|
500 | 515 | |
|
501 | 516 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
502 | 517 | |
|
503 | 518 | parameters = (unsigned char*) &housekeeping_packet; |
|
504 | 519 | |
|
505 | 520 | for(i = 0; i< sizeOfHK; i++) |
|
506 | 521 | { |
|
507 | 522 | parameters[i] = 0x00; |
|
508 | 523 | } |
|
509 | 524 | |
|
510 | 525 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
511 | 526 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
512 | 527 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
513 | 528 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
514 | 529 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
515 | 530 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
516 | 531 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
517 | 532 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
518 | 533 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
519 | 534 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
520 | 535 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
521 | 536 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
522 | 537 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
523 | 538 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
524 | 539 | housekeeping_packet.sid = SID_HK; |
|
525 | 540 | |
|
526 | 541 | // init status word |
|
527 | 542 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
528 | 543 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
529 | 544 | // init software version |
|
530 | 545 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
531 | 546 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
532 | 547 | housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
533 | 548 | housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
534 | 549 | // init fpga version |
|
535 | 550 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
536 | 551 | housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
537 | 552 | housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
538 | 553 | housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
539 | 554 | |
|
540 | 555 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
541 | 556 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
542 | 557 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
543 | 558 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
544 | 559 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
545 | 560 | } |
|
546 | 561 | |
|
547 | 562 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
548 | 563 | { |
|
549 | 564 | /** This function increment the sequence counter passes in argument. |
|
550 | 565 | * |
|
551 | 566 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
552 | 567 | * |
|
553 | 568 | */ |
|
554 | 569 | |
|
555 | 570 | unsigned short segmentation_grouping_flag; |
|
556 | 571 | unsigned short sequence_cnt; |
|
557 | 572 | |
|
558 | 573 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 |
|
559 | 574 | sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] |
|
560 | 575 | |
|
561 | 576 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
562 | 577 | { |
|
563 | 578 | sequence_cnt = sequence_cnt + 1; |
|
564 | 579 | } |
|
565 | 580 | else |
|
566 | 581 | { |
|
567 | 582 | sequence_cnt = 0; |
|
568 | 583 | } |
|
569 | 584 | |
|
570 | 585 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
571 | 586 | } |
|
572 | 587 | |
|
573 | 588 | void getTime( unsigned char *time) |
|
574 | 589 | { |
|
575 | 590 | /** This function write the current local time in the time buffer passed in argument. |
|
576 | 591 | * |
|
577 | 592 | */ |
|
578 | 593 | |
|
579 | 594 | time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
580 | 595 | time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
581 | 596 | time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
582 | 597 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
583 | 598 | time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
584 | 599 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
585 | 600 | } |
|
586 | 601 | |
|
587 | 602 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
588 | 603 | { |
|
589 | 604 | /** This function write the current local time in the time buffer passed in argument. |
|
590 | 605 | * |
|
591 | 606 | */ |
|
592 | 607 | unsigned long long int time; |
|
593 | 608 | |
|
594 | 609 | time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) |
|
595 | 610 | + time_management_regs->fine_time; |
|
596 | 611 | |
|
597 | 612 | return time; |
|
598 | 613 | } |
|
599 | 614 | |
|
600 | 615 | void send_dumb_hk( void ) |
|
601 | 616 | { |
|
602 | 617 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
603 | 618 | unsigned char *parameters; |
|
604 | 619 | unsigned int i; |
|
605 | 620 | rtems_id queue_id; |
|
606 | 621 | |
|
607 | 622 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
608 | 623 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
609 | 624 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
610 | 625 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
611 | 626 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
612 | 627 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
613 | 628 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
614 | 629 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
615 | 630 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
616 | 631 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
617 | 632 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
618 | 633 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
619 | 634 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
620 | 635 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
621 | 636 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
622 | 637 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
623 | 638 | dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
624 | 639 | dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
625 | 640 | dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
626 | 641 | dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
627 | 642 | dummy_hk_packet.sid = SID_HK; |
|
628 | 643 | |
|
629 | 644 | // init status word |
|
630 | 645 | dummy_hk_packet.lfr_status_word[0] = 0xff; |
|
631 | 646 | dummy_hk_packet.lfr_status_word[1] = 0xff; |
|
632 | 647 | // init software version |
|
633 | 648 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
634 | 649 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
635 | 650 | dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
636 | 651 | dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
637 | 652 | // init fpga version |
|
638 | 653 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0); |
|
639 | 654 | dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
640 | 655 | dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
641 | 656 | dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
642 | 657 | |
|
643 | 658 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
644 | 659 | |
|
645 | 660 | for (i=0; i<100; i++) |
|
646 | 661 | { |
|
647 | 662 | parameters[i] = 0xff; |
|
648 | 663 | } |
|
649 | 664 | |
|
650 | 665 | get_message_queue_id_send( &queue_id ); |
|
651 | 666 | |
|
652 | 667 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
653 | 668 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
654 | 669 | } |
|
655 | 670 | |
|
656 | 671 | void get_temperatures( unsigned char *temperatures ) |
|
657 | 672 | { |
|
658 | 673 | unsigned char* temp_scm_ptr; |
|
659 | 674 | unsigned char* temp_pcb_ptr; |
|
660 | 675 | unsigned char* temp_fpga_ptr; |
|
661 | 676 | |
|
662 | 677 | // SEL1 SEL0 |
|
663 | 678 | // 0 0 => PCB |
|
664 | 679 | // 0 1 => FPGA |
|
665 | 680 | // 1 0 => SCM |
|
666 | 681 | |
|
667 | 682 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
668 | 683 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
669 | 684 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
670 | 685 | |
|
671 | 686 | temperatures[0] = temp_scm_ptr[2]; |
|
672 | 687 | temperatures[1] = temp_scm_ptr[3]; |
|
673 | 688 | temperatures[2] = temp_pcb_ptr[2]; |
|
674 | 689 | temperatures[3] = temp_pcb_ptr[3]; |
|
675 | 690 | temperatures[4] = temp_fpga_ptr[2]; |
|
676 | 691 | temperatures[5] = temp_fpga_ptr[3]; |
|
677 | 692 | } |
|
678 | 693 | |
|
679 | 694 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
680 | 695 | { |
|
681 | 696 | unsigned char* v_ptr; |
|
682 | 697 | unsigned char* e1_ptr; |
|
683 | 698 | unsigned char* e2_ptr; |
|
684 | 699 | |
|
685 |
v_ptr = (unsigned char *) & |
|
|
686 |
e1_ptr = (unsigned char *) & |
|
|
687 |
e2_ptr = (unsigned char *) & |
|
|
700 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; | |
|
701 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; | |
|
702 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; | |
|
688 | 703 | |
|
689 |
spacecraft_potential[0] = v_ptr[ |
|
|
690 |
spacecraft_potential[1] = v_ptr[ |
|
|
691 |
spacecraft_potential[2] = e1_ptr[ |
|
|
692 |
spacecraft_potential[3] = e1_ptr[ |
|
|
693 |
spacecraft_potential[4] = e2_ptr[ |
|
|
694 |
spacecraft_potential[5] = e2_ptr[ |
|
|
704 | spacecraft_potential[0] = v_ptr[0]; | |
|
705 | spacecraft_potential[1] = v_ptr[1]; | |
|
706 | spacecraft_potential[2] = e1_ptr[0]; | |
|
707 | spacecraft_potential[3] = e1_ptr[1]; | |
|
708 | spacecraft_potential[4] = e2_ptr[0]; | |
|
709 | spacecraft_potential[5] = e2_ptr[1]; | |
|
695 | 710 | } |
|
696 | 711 | |
|
697 | 712 | void get_cpu_load( unsigned char *resource_statistics ) |
|
698 | 713 | { |
|
699 | 714 | unsigned char cpu_load; |
|
700 | 715 | |
|
701 | 716 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
702 | 717 | |
|
703 | 718 | // HK_LFR_CPU_LOAD |
|
704 | 719 | resource_statistics[0] = cpu_load; |
|
705 | 720 | |
|
706 | 721 | // HK_LFR_CPU_LOAD_MAX |
|
707 | 722 | if (cpu_load > resource_statistics[1]) |
|
708 | 723 | { |
|
709 | 724 | resource_statistics[1] = cpu_load; |
|
710 | 725 | } |
|
711 | 726 | |
|
712 | 727 | // CPU_LOAD_AVE |
|
713 | 728 | resource_statistics[2] = 0; |
|
714 | 729 | |
|
715 | 730 | #ifndef PRINT_TASK_STATISTICS |
|
716 | 731 | rtems_cpu_usage_reset(); |
|
717 | 732 | #endif |
|
718 | 733 | |
|
719 | 734 | } |
|
720 | 735 | |
|
721 | 736 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
722 | 737 | { |
|
723 | 738 | if (state == true) |
|
724 | 739 | { |
|
725 | 740 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000] |
|
726 | 741 | } |
|
727 | 742 | else |
|
728 | 743 | { |
|
729 | 744 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111] |
|
730 | 745 | } |
|
731 | 746 | } |
|
732 | 747 | |
|
733 | 748 | void set_sy_lfr_pas_filter_enabled( bool state ) |
|
734 | 749 | { |
|
735 | 750 | if (state == true) |
|
736 | 751 | { |
|
737 | 752 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000] |
|
738 | 753 | } |
|
739 | 754 | else |
|
740 | 755 | { |
|
741 | 756 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xdf; // [1101 1111] |
|
742 | 757 | } |
|
743 | 758 | } |
|
744 | 759 | |
|
745 | 760 | void set_sy_lfr_watchdog_enabled( bool state ) |
|
746 | 761 | { |
|
747 | 762 | if (state == true) |
|
748 | 763 | { |
|
749 | 764 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x10; // [0001 0000] |
|
750 | 765 | } |
|
751 | 766 | else |
|
752 | 767 | { |
|
753 | 768 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xef; // [1110 1111] |
|
754 | 769 | } |
|
755 | 770 | } |
|
756 | 771 | |
|
757 | 772 | void set_hk_lfr_calib_enable( bool state ) |
|
758 | 773 | { |
|
759 | 774 | if (state == true) |
|
760 | 775 | { |
|
761 | 776 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000] |
|
762 | 777 | } |
|
763 | 778 | else |
|
764 | 779 | { |
|
765 | 780 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111] |
|
766 | 781 | } |
|
767 | 782 | } |
|
768 | 783 | |
|
769 | 784 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) |
|
770 | 785 | { |
|
771 | 786 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf8; // [1111 1000] |
|
772 | 787 | |
|
773 | 788 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] |
|
774 | 789 | | (lfr_reset_cause & 0x07 ); // [0000 0111] |
|
775 | 790 | |
|
776 | 791 | } |
|
777 | 792 | |
|
778 | 793 | void hk_lfr_le_me_he_update() |
|
779 | 794 | { |
|
780 | 795 | unsigned int hk_lfr_le_cnt; |
|
781 | 796 | unsigned int hk_lfr_me_cnt; |
|
782 | 797 | unsigned int hk_lfr_he_cnt; |
|
783 | 798 | unsigned int current_hk_lfr_le_cnt; |
|
784 | 799 | unsigned int current_hk_lfr_me_cnt; |
|
785 | 800 | unsigned int current_hk_lfr_he_cnt; |
|
786 | 801 | |
|
787 | 802 | hk_lfr_le_cnt = 0; |
|
788 | 803 | hk_lfr_me_cnt = 0; |
|
789 | 804 | hk_lfr_he_cnt = 0; |
|
790 | 805 | current_hk_lfr_le_cnt = ((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256 + housekeeping_packet.hk_lfr_le_cnt[1]; |
|
791 | 806 | current_hk_lfr_me_cnt = ((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256 + housekeeping_packet.hk_lfr_me_cnt[1]; |
|
792 | 807 | current_hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1]; |
|
793 | 808 | |
|
794 | 809 | //update the low severity error counter |
|
795 | 810 | hk_lfr_le_cnt = |
|
796 | 811 | current_hk_lfr_le_cnt |
|
797 | 812 | + housekeeping_packet.hk_lfr_dpu_spw_parity |
|
798 | 813 | + housekeeping_packet.hk_lfr_dpu_spw_disconnect |
|
799 | 814 | + housekeeping_packet.hk_lfr_dpu_spw_escape |
|
800 | 815 | + housekeeping_packet.hk_lfr_dpu_spw_credit |
|
801 | 816 | + housekeeping_packet.hk_lfr_dpu_spw_write_sync |
|
802 | 817 | + housekeeping_packet.hk_lfr_timecode_erroneous |
|
803 | 818 | + housekeeping_packet.hk_lfr_timecode_missing |
|
804 | 819 | + housekeeping_packet.hk_lfr_timecode_invalid |
|
805 | 820 | + housekeeping_packet.hk_lfr_time_timecode_it |
|
806 | 821 | + housekeeping_packet.hk_lfr_time_not_synchro |
|
807 | 822 | + housekeeping_packet.hk_lfr_time_timecode_ctr |
|
808 | 823 | + housekeeping_packet.hk_lfr_ahb_correctable; |
|
809 | 824 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
810 | 825 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
811 | 826 | |
|
812 | 827 | //update the medium severity error counter |
|
813 | 828 | hk_lfr_me_cnt = |
|
814 | 829 | current_hk_lfr_me_cnt |
|
815 | 830 | + housekeeping_packet.hk_lfr_dpu_spw_early_eop |
|
816 | 831 | + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr |
|
817 | 832 | + housekeeping_packet.hk_lfr_dpu_spw_eep |
|
818 | 833 | + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; |
|
819 | 834 | |
|
820 | 835 | //update the high severity error counter |
|
821 | 836 | hk_lfr_he_cnt = 0; |
|
822 | 837 | |
|
823 | 838 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
824 | 839 | // LE |
|
825 | 840 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((hk_lfr_le_cnt & 0xff00) >> 8); |
|
826 | 841 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (hk_lfr_le_cnt & 0x00ff); |
|
827 | 842 | // ME |
|
828 | 843 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((hk_lfr_me_cnt & 0xff00) >> 8); |
|
829 | 844 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (hk_lfr_me_cnt & 0x00ff); |
|
830 | 845 | // HE |
|
831 | 846 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & 0xff00) >> 8); |
|
832 | 847 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & 0x00ff); |
|
833 | 848 | |
|
834 | 849 | } |
|
835 | 850 | |
|
836 | 851 | void set_hk_lfr_time_not_synchro() |
|
837 | 852 | { |
|
838 | 853 | static unsigned char synchroLost = 1; |
|
839 | 854 | int synchronizationBit; |
|
840 | 855 | |
|
841 | 856 | // get the synchronization bit |
|
842 | 857 | synchronizationBit = (time_management_regs->coarse_time & 0x80000000) >> 31; // 1000 0000 0000 0000 |
|
843 | 858 | |
|
844 | 859 | switch (synchronizationBit) |
|
845 | 860 | { |
|
846 | 861 | case 0: |
|
847 | 862 | if (synchroLost == 1) |
|
848 | 863 | { |
|
849 | 864 | synchroLost = 0; |
|
850 | 865 | } |
|
851 | 866 | break; |
|
852 | 867 | case 1: |
|
853 | 868 | if (synchroLost == 0 ) |
|
854 | 869 | { |
|
855 | 870 | synchroLost = 1; |
|
856 | 871 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); |
|
857 | 872 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); |
|
858 | 873 | } |
|
859 | 874 | break; |
|
860 | 875 | default: |
|
861 | 876 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); |
|
862 | 877 | break; |
|
863 | 878 | } |
|
864 | 879 | |
|
865 | 880 | } |
|
866 | 881 | |
|
867 | 882 | void set_hk_lfr_ahb_correctable() // CRITICITY L |
|
868 | 883 | { |
|
869 | 884 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided |
|
870 | 885 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the |
|
871 | 886 | * detected errors in the cache, in the integer unit and in the floating point unit. |
|
872 | 887 | * |
|
873 | 888 | * @param void |
|
874 | 889 | * |
|
875 | 890 | * @return void |
|
876 | 891 | * |
|
877 | 892 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. |
|
878 | 893 | * |
|
879 | 894 | */ |
|
880 | 895 | |
|
881 | 896 | unsigned int ahb_correctable; |
|
882 | 897 | unsigned int instructionErrorCounter; |
|
883 | 898 | unsigned int dataErrorCounter; |
|
884 | 899 | unsigned int fprfErrorCounter; |
|
885 | 900 | unsigned int iurfErrorCounter; |
|
886 | 901 | |
|
887 | 902 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); |
|
888 | 903 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); |
|
889 | 904 | |
|
890 | 905 | ahb_correctable = instructionErrorCounter |
|
891 | 906 | + dataErrorCounter |
|
892 | 907 | + fprfErrorCounter |
|
893 | 908 | + iurfErrorCounter |
|
894 | 909 | + housekeeping_packet.hk_lfr_ahb_correctable; |
|
895 | 910 | |
|
896 | 911 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & 0xff); // [1111 1111] |
|
897 | 912 | |
|
898 | 913 | } |
@@ -1,1641 +1,1642 | |||
|
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 | 32 | ccsdsTelecommandPacket_t 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[6]; |
|
36 | 36 | rtems_id queue_rcv_id; |
|
37 | 37 | rtems_id queue_snd_id; |
|
38 | 38 | |
|
39 | 39 | status = get_message_queue_id_recv( &queue_rcv_id ); |
|
40 | 40 | if (status != RTEMS_SUCCESSFUL) |
|
41 | 41 | { |
|
42 | 42 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | status = get_message_queue_id_send( &queue_snd_id ); |
|
46 | 46 | if (status != RTEMS_SUCCESSFUL) |
|
47 | 47 | { |
|
48 | 48 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | result = LFR_SUCCESSFUL; |
|
52 | 52 | subtype = 0; // subtype of the current TC packet |
|
53 | 53 | |
|
54 | 54 | BOOT_PRINTF("in ACTN *** \n"); |
|
55 | 55 | |
|
56 | 56 | while(1) |
|
57 | 57 | { |
|
58 | 58 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
59 | 59 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
60 | 60 | getTime( time ); // set time to the current time |
|
61 | 61 | if (status!=RTEMS_SUCCESSFUL) |
|
62 | 62 | { |
|
63 | 63 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
64 | 64 | } |
|
65 | 65 | else |
|
66 | 66 | { |
|
67 | 67 | subtype = TC.serviceSubType; |
|
68 | 68 | switch(subtype) |
|
69 | 69 | { |
|
70 | 70 | case TC_SUBTYPE_RESET: |
|
71 | 71 | result = action_reset( &TC, queue_snd_id, time ); |
|
72 | 72 | close_action( &TC, result, queue_snd_id ); |
|
73 | 73 | break; |
|
74 | 74 | case TC_SUBTYPE_LOAD_COMM: |
|
75 | 75 | result = action_load_common_par( &TC ); |
|
76 | 76 | close_action( &TC, result, queue_snd_id ); |
|
77 | 77 | break; |
|
78 | 78 | case TC_SUBTYPE_LOAD_NORM: |
|
79 | 79 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
80 | 80 | close_action( &TC, result, queue_snd_id ); |
|
81 | 81 | break; |
|
82 | 82 | case TC_SUBTYPE_LOAD_BURST: |
|
83 | 83 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
84 | 84 | close_action( &TC, result, queue_snd_id ); |
|
85 | 85 | break; |
|
86 | 86 | case TC_SUBTYPE_LOAD_SBM1: |
|
87 | 87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
88 | 88 | close_action( &TC, result, queue_snd_id ); |
|
89 | 89 | break; |
|
90 | 90 | case TC_SUBTYPE_LOAD_SBM2: |
|
91 | 91 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
92 | 92 | close_action( &TC, result, queue_snd_id ); |
|
93 | 93 | break; |
|
94 | 94 | case TC_SUBTYPE_DUMP: |
|
95 | 95 | result = action_dump_par( &TC, queue_snd_id ); |
|
96 | 96 | close_action( &TC, result, queue_snd_id ); |
|
97 | 97 | break; |
|
98 | 98 | case TC_SUBTYPE_ENTER: |
|
99 | 99 | result = action_enter_mode( &TC, queue_snd_id ); |
|
100 | 100 | close_action( &TC, result, queue_snd_id ); |
|
101 | 101 | break; |
|
102 | 102 | case TC_SUBTYPE_UPDT_INFO: |
|
103 | 103 | result = action_update_info( &TC, queue_snd_id ); |
|
104 | 104 | close_action( &TC, result, queue_snd_id ); |
|
105 | 105 | break; |
|
106 | 106 | case TC_SUBTYPE_EN_CAL: |
|
107 | 107 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
108 | 108 | close_action( &TC, result, queue_snd_id ); |
|
109 | 109 | break; |
|
110 | 110 | case TC_SUBTYPE_DIS_CAL: |
|
111 | 111 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
112 | 112 | close_action( &TC, result, queue_snd_id ); |
|
113 | 113 | break; |
|
114 | 114 | case TC_SUBTYPE_LOAD_K: |
|
115 | 115 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); |
|
116 | 116 | close_action( &TC, result, queue_snd_id ); |
|
117 | 117 | break; |
|
118 | 118 | case TC_SUBTYPE_DUMP_K: |
|
119 | 119 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); |
|
120 | 120 | close_action( &TC, result, queue_snd_id ); |
|
121 | 121 | break; |
|
122 | 122 | case TC_SUBTYPE_LOAD_FBINS: |
|
123 | 123 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); |
|
124 | 124 | close_action( &TC, result, queue_snd_id ); |
|
125 | 125 | break; |
|
126 | 126 | case TC_SUBTYPE_LOAD_FILTER_PAR: |
|
127 | 127 | result = action_load_filter_par( &TC, queue_snd_id, time ); |
|
128 | 128 | close_action( &TC, result, queue_snd_id ); |
|
129 | 129 | break; |
|
130 | 130 | case TC_SUBTYPE_UPDT_TIME: |
|
131 | 131 | result = action_update_time( &TC ); |
|
132 | 132 | close_action( &TC, result, queue_snd_id ); |
|
133 | 133 | break; |
|
134 | 134 | default: |
|
135 | 135 | break; |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | } |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | //*********** |
|
142 | 142 | // TC ACTIONS |
|
143 | 143 | |
|
144 | 144 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
145 | 145 | { |
|
146 | 146 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
147 | 147 | * |
|
148 | 148 | * @param TC points to the TeleCommand packet that is being processed |
|
149 | 149 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
150 | 150 | * |
|
151 | 151 | */ |
|
152 | 152 | |
|
153 | 153 | PRINTF("this is the end!!!\n"); |
|
154 | 154 | exit(0); |
|
155 | 155 | |
|
156 | 156 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
157 | 157 | |
|
158 | 158 | return LFR_DEFAULT; |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
162 | 162 | { |
|
163 | 163 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
164 | 164 | * |
|
165 | 165 | * @param TC points to the TeleCommand packet that is being processed |
|
166 | 166 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
167 | 167 | * |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | rtems_status_code status; |
|
171 | 171 | unsigned char requestedMode; |
|
172 | 172 | unsigned int *transitionCoarseTime_ptr; |
|
173 | 173 | unsigned int transitionCoarseTime; |
|
174 | 174 | unsigned char * bytePosPtr; |
|
175 | 175 | |
|
176 | 176 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
177 | 177 | |
|
178 | 178 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; |
|
179 | 179 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); |
|
180 | 180 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; |
|
181 | 181 | |
|
182 | 182 | status = check_mode_value( requestedMode ); |
|
183 | 183 | |
|
184 | 184 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent |
|
185 | 185 | { |
|
186 | 186 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | else // the mode value is valid, check the transition |
|
190 | 190 | { |
|
191 | 191 | status = check_mode_transition(requestedMode); |
|
192 | 192 | if (status != LFR_SUCCESSFUL) |
|
193 | 193 | { |
|
194 | 194 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") |
|
195 | 195 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
196 | 196 | } |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date |
|
200 | 200 | { |
|
201 | 201 | status = check_transition_date( transitionCoarseTime ); |
|
202 | 202 | if (status != LFR_SUCCESSFUL) |
|
203 | 203 | { |
|
204 | 204 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n"); |
|
205 | 205 | send_tm_lfr_tc_exe_not_executable(TC, queue_id ); |
|
206 | 206 | } |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode |
|
210 | 210 | { |
|
211 | 211 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); |
|
212 | 212 | |
|
213 | 213 | switch(requestedMode) |
|
214 | 214 | { |
|
215 | 215 | case LFR_MODE_STANDBY: |
|
216 | 216 | status = enter_mode_standby(); |
|
217 | 217 | break; |
|
218 | 218 | case LFR_MODE_NORMAL: |
|
219 | 219 | status = enter_mode_normal( transitionCoarseTime ); |
|
220 | 220 | break; |
|
221 | 221 | case LFR_MODE_BURST: |
|
222 | 222 | status = enter_mode_burst( transitionCoarseTime ); |
|
223 | 223 | break; |
|
224 | 224 | case LFR_MODE_SBM1: |
|
225 | 225 | status = enter_mode_sbm1( transitionCoarseTime ); |
|
226 | 226 | break; |
|
227 | 227 | case LFR_MODE_SBM2: |
|
228 | 228 | status = enter_mode_sbm2( transitionCoarseTime ); |
|
229 | 229 | break; |
|
230 | 230 | default: |
|
231 | 231 | break; |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | if (status != RTEMS_SUCCESSFUL) |
|
235 | 235 | { |
|
236 | 236 | status = LFR_EXE_ERROR; |
|
237 | 237 | } |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | return status; |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
244 | 244 | { |
|
245 | 245 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
246 | 246 | * |
|
247 | 247 | * @param TC points to the TeleCommand packet that is being processed |
|
248 | 248 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
249 | 249 | * |
|
250 | 250 | * @return LFR directive status code: |
|
251 | 251 | * - LFR_DEFAULT |
|
252 | 252 | * - LFR_SUCCESSFUL |
|
253 | 253 | * |
|
254 | 254 | */ |
|
255 | 255 | |
|
256 | 256 | unsigned int val; |
|
257 | 257 | int result; |
|
258 | 258 | unsigned int status; |
|
259 | 259 | unsigned char mode; |
|
260 | 260 | unsigned char * bytePosPtr; |
|
261 | 261 | |
|
262 | 262 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
263 | 263 | |
|
264 | 264 | // check LFR mode |
|
265 | 265 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; |
|
266 | 266 | status = check_update_info_hk_lfr_mode( mode ); |
|
267 | 267 | if (status == LFR_SUCCESSFUL) // check TDS mode |
|
268 | 268 | { |
|
269 | 269 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; |
|
270 | 270 | status = check_update_info_hk_tds_mode( mode ); |
|
271 | 271 | } |
|
272 | 272 | if (status == LFR_SUCCESSFUL) // check THR mode |
|
273 | 273 | { |
|
274 | 274 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); |
|
275 | 275 | status = check_update_info_hk_thr_mode( mode ); |
|
276 | 276 | } |
|
277 | 277 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful |
|
278 | 278 | { |
|
279 | 279 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 |
|
280 | 280 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
281 | 281 | val++; |
|
282 | 282 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); |
|
283 | 283 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | // pa_bia_status_info |
|
287 | 287 | // => pa_bia_mode_mux_set 3 bits |
|
288 | 288 | // => pa_bia_mode_hv_enabled 1 bit |
|
289 | 289 | // => pa_bia_mode_bias1_enabled 1 bit |
|
290 | 290 | // => pa_bia_mode_bias2_enabled 1 bit |
|
291 | 291 | // => pa_bia_mode_bias3_enabled 1 bit |
|
292 | 292 | // => pa_bia_on_off (cp_dpu_bias_on_off) |
|
293 | 293 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110] |
|
294 | 294 | pa_bia_status_info = pa_bia_status_info |
|
295 | 295 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1); |
|
296 | 296 | |
|
297 | 297 | // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets) |
|
298 | cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ]; | |
|
298 | //cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ]; | |
|
299 | 299 | getReactionWheelsFrequencies( TC ); |
|
300 | set_hk_lfr_sc_rw_f_flags(); | |
|
300 | 301 | build_sy_lfr_rw_masks(); |
|
301 | 302 | |
|
302 | 303 | result = status; |
|
303 | 304 | |
|
304 | 305 | return result; |
|
305 | 306 | } |
|
306 | 307 | |
|
307 | 308 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
308 | 309 | { |
|
309 | 310 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
310 | 311 | * |
|
311 | 312 | * @param TC points to the TeleCommand packet that is being processed |
|
312 | 313 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
313 | 314 | * |
|
314 | 315 | */ |
|
315 | 316 | |
|
316 | 317 | int result; |
|
317 | 318 | |
|
318 | 319 | result = LFR_DEFAULT; |
|
319 | 320 | |
|
320 | 321 | setCalibration( true ); |
|
321 | 322 | |
|
322 | 323 | result = LFR_SUCCESSFUL; |
|
323 | 324 | |
|
324 | 325 | return result; |
|
325 | 326 | } |
|
326 | 327 | |
|
327 | 328 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
328 | 329 | { |
|
329 | 330 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
330 | 331 | * |
|
331 | 332 | * @param TC points to the TeleCommand packet that is being processed |
|
332 | 333 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
333 | 334 | * |
|
334 | 335 | */ |
|
335 | 336 | |
|
336 | 337 | int result; |
|
337 | 338 | |
|
338 | 339 | result = LFR_DEFAULT; |
|
339 | 340 | |
|
340 | 341 | setCalibration( false ); |
|
341 | 342 | |
|
342 | 343 | result = LFR_SUCCESSFUL; |
|
343 | 344 | |
|
344 | 345 | return result; |
|
345 | 346 | } |
|
346 | 347 | |
|
347 | 348 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
348 | 349 | { |
|
349 | 350 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
350 | 351 | * |
|
351 | 352 | * @param TC points to the TeleCommand packet that is being processed |
|
352 | 353 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
353 | 354 | * |
|
354 | 355 | * @return LFR_SUCCESSFUL |
|
355 | 356 | * |
|
356 | 357 | */ |
|
357 | 358 | |
|
358 | 359 | unsigned int val; |
|
359 | 360 | |
|
360 | 361 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) |
|
361 | 362 | + (TC->dataAndCRC[1] << 16) |
|
362 | 363 | + (TC->dataAndCRC[2] << 8) |
|
363 | 364 | + TC->dataAndCRC[3]; |
|
364 | 365 | |
|
365 | 366 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 |
|
366 | 367 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
367 | 368 | val++; |
|
368 | 369 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); |
|
369 | 370 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
370 | 371 | |
|
371 | 372 | oneTcLfrUpdateTimeReceived = 1; |
|
372 | 373 | |
|
373 | 374 | return LFR_SUCCESSFUL; |
|
374 | 375 | } |
|
375 | 376 | |
|
376 | 377 | //******************* |
|
377 | 378 | // ENTERING THE MODES |
|
378 | 379 | int check_mode_value( unsigned char requestedMode ) |
|
379 | 380 | { |
|
380 | 381 | int status; |
|
381 | 382 | |
|
382 | 383 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
383 | 384 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
384 | 385 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
385 | 386 | { |
|
386 | 387 | status = LFR_DEFAULT; |
|
387 | 388 | } |
|
388 | 389 | else |
|
389 | 390 | { |
|
390 | 391 | status = LFR_SUCCESSFUL; |
|
391 | 392 | } |
|
392 | 393 | |
|
393 | 394 | return status; |
|
394 | 395 | } |
|
395 | 396 | |
|
396 | 397 | int check_mode_transition( unsigned char requestedMode ) |
|
397 | 398 | { |
|
398 | 399 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. |
|
399 | 400 | * |
|
400 | 401 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE |
|
401 | 402 | * |
|
402 | 403 | * @return LFR directive status codes: |
|
403 | 404 | * - LFR_SUCCESSFUL - the transition is authorized |
|
404 | 405 | * - LFR_DEFAULT - the transition is not authorized |
|
405 | 406 | * |
|
406 | 407 | */ |
|
407 | 408 | |
|
408 | 409 | int status; |
|
409 | 410 | |
|
410 | 411 | switch (requestedMode) |
|
411 | 412 | { |
|
412 | 413 | case LFR_MODE_STANDBY: |
|
413 | 414 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
414 | 415 | status = LFR_DEFAULT; |
|
415 | 416 | } |
|
416 | 417 | else |
|
417 | 418 | { |
|
418 | 419 | status = LFR_SUCCESSFUL; |
|
419 | 420 | } |
|
420 | 421 | break; |
|
421 | 422 | case LFR_MODE_NORMAL: |
|
422 | 423 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
423 | 424 | status = LFR_DEFAULT; |
|
424 | 425 | } |
|
425 | 426 | else { |
|
426 | 427 | status = LFR_SUCCESSFUL; |
|
427 | 428 | } |
|
428 | 429 | break; |
|
429 | 430 | case LFR_MODE_BURST: |
|
430 | 431 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
431 | 432 | status = LFR_DEFAULT; |
|
432 | 433 | } |
|
433 | 434 | else { |
|
434 | 435 | status = LFR_SUCCESSFUL; |
|
435 | 436 | } |
|
436 | 437 | break; |
|
437 | 438 | case LFR_MODE_SBM1: |
|
438 | 439 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
439 | 440 | status = LFR_DEFAULT; |
|
440 | 441 | } |
|
441 | 442 | else { |
|
442 | 443 | status = LFR_SUCCESSFUL; |
|
443 | 444 | } |
|
444 | 445 | break; |
|
445 | 446 | case LFR_MODE_SBM2: |
|
446 | 447 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
447 | 448 | status = LFR_DEFAULT; |
|
448 | 449 | } |
|
449 | 450 | else { |
|
450 | 451 | status = LFR_SUCCESSFUL; |
|
451 | 452 | } |
|
452 | 453 | break; |
|
453 | 454 | default: |
|
454 | 455 | status = LFR_DEFAULT; |
|
455 | 456 | break; |
|
456 | 457 | } |
|
457 | 458 | |
|
458 | 459 | return status; |
|
459 | 460 | } |
|
460 | 461 | |
|
461 | 462 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) |
|
462 | 463 | { |
|
463 | 464 | if (transitionCoarseTime == 0) |
|
464 | 465 | { |
|
465 | 466 | lastValidEnterModeTime = time_management_regs->coarse_time + 1; |
|
466 | 467 | PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime); |
|
467 | 468 | } |
|
468 | 469 | else |
|
469 | 470 | { |
|
470 | 471 | lastValidEnterModeTime = transitionCoarseTime; |
|
471 | 472 | PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); |
|
472 | 473 | } |
|
473 | 474 | } |
|
474 | 475 | |
|
475 | 476 | int check_transition_date( unsigned int transitionCoarseTime ) |
|
476 | 477 | { |
|
477 | 478 | int status; |
|
478 | 479 | unsigned int localCoarseTime; |
|
479 | 480 | unsigned int deltaCoarseTime; |
|
480 | 481 | |
|
481 | 482 | status = LFR_SUCCESSFUL; |
|
482 | 483 | |
|
483 | 484 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition |
|
484 | 485 | { |
|
485 | 486 | status = LFR_SUCCESSFUL; |
|
486 | 487 | } |
|
487 | 488 | else |
|
488 | 489 | { |
|
489 | 490 | localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; |
|
490 | 491 | |
|
491 | 492 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime); |
|
492 | 493 | |
|
493 | 494 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 |
|
494 | 495 | { |
|
495 | 496 | status = LFR_DEFAULT; |
|
496 | 497 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n"); |
|
497 | 498 | } |
|
498 | 499 | |
|
499 | 500 | if (status == LFR_SUCCESSFUL) |
|
500 | 501 | { |
|
501 | 502 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; |
|
502 | 503 | if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 |
|
503 | 504 | { |
|
504 | 505 | status = LFR_DEFAULT; |
|
505 | 506 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) |
|
506 | 507 | } |
|
507 | 508 | } |
|
508 | 509 | } |
|
509 | 510 | |
|
510 | 511 | return status; |
|
511 | 512 | } |
|
512 | 513 | |
|
513 | 514 | int restart_asm_activities( unsigned char lfrRequestedMode ) |
|
514 | 515 | { |
|
515 | 516 | rtems_status_code status; |
|
516 | 517 | |
|
517 | 518 | status = stop_spectral_matrices(); |
|
518 | 519 | |
|
519 | 520 | thisIsAnASMRestart = 1; |
|
520 | 521 | |
|
521 | 522 | status = restart_asm_tasks( lfrRequestedMode ); |
|
522 | 523 | |
|
523 | 524 | launch_spectral_matrix(); |
|
524 | 525 | |
|
525 | 526 | return status; |
|
526 | 527 | } |
|
527 | 528 | |
|
528 | 529 | int stop_spectral_matrices( void ) |
|
529 | 530 | { |
|
530 | 531 | /** This function stops and restarts the current mode average spectral matrices activities. |
|
531 | 532 | * |
|
532 | 533 | * @return RTEMS directive status codes: |
|
533 | 534 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
534 | 535 | * - RTEMS_INVALID_ID - task id invalid |
|
535 | 536 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
536 | 537 | * |
|
537 | 538 | */ |
|
538 | 539 | |
|
539 | 540 | rtems_status_code status; |
|
540 | 541 | |
|
541 | 542 | status = RTEMS_SUCCESSFUL; |
|
542 | 543 | |
|
543 | 544 | // (1) mask interruptions |
|
544 | 545 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt |
|
545 | 546 | |
|
546 | 547 | // (2) reset spectral matrices registers |
|
547 | 548 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
548 | 549 | reset_sm_status(); |
|
549 | 550 | |
|
550 | 551 | // (3) clear interruptions |
|
551 | 552 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
552 | 553 | |
|
553 | 554 | // suspend several tasks |
|
554 | 555 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
555 | 556 | status = suspend_asm_tasks(); |
|
556 | 557 | } |
|
557 | 558 | |
|
558 | 559 | if (status != RTEMS_SUCCESSFUL) |
|
559 | 560 | { |
|
560 | 561 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
561 | 562 | } |
|
562 | 563 | |
|
563 | 564 | return status; |
|
564 | 565 | } |
|
565 | 566 | |
|
566 | 567 | int stop_current_mode( void ) |
|
567 | 568 | { |
|
568 | 569 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
569 | 570 | * |
|
570 | 571 | * @return RTEMS directive status codes: |
|
571 | 572 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
572 | 573 | * - RTEMS_INVALID_ID - task id invalid |
|
573 | 574 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
574 | 575 | * |
|
575 | 576 | */ |
|
576 | 577 | |
|
577 | 578 | rtems_status_code status; |
|
578 | 579 | |
|
579 | 580 | status = RTEMS_SUCCESSFUL; |
|
580 | 581 | |
|
581 | 582 | // (1) mask interruptions |
|
582 | 583 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
583 | 584 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
584 | 585 | |
|
585 | 586 | // (2) reset waveform picker registers |
|
586 | 587 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
587 | 588 | reset_wfp_status(); // reset all the status bits |
|
588 | 589 | |
|
589 | 590 | // (3) reset spectral matrices registers |
|
590 | 591 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
591 | 592 | reset_sm_status(); |
|
592 | 593 | |
|
593 | 594 | // reset lfr VHDL module |
|
594 | 595 | reset_lfr(); |
|
595 | 596 | |
|
596 | 597 | reset_extractSWF(); // reset the extractSWF flag to false |
|
597 | 598 | |
|
598 | 599 | // (4) clear interruptions |
|
599 | 600 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
600 | 601 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
601 | 602 | |
|
602 | 603 | // suspend several tasks |
|
603 | 604 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
604 | 605 | status = suspend_science_tasks(); |
|
605 | 606 | } |
|
606 | 607 | |
|
607 | 608 | if (status != RTEMS_SUCCESSFUL) |
|
608 | 609 | { |
|
609 | 610 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
610 | 611 | } |
|
611 | 612 | |
|
612 | 613 | return status; |
|
613 | 614 | } |
|
614 | 615 | |
|
615 | 616 | int enter_mode_standby( void ) |
|
616 | 617 | { |
|
617 | 618 | /** This function is used to put LFR in the STANDBY mode. |
|
618 | 619 | * |
|
619 | 620 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
620 | 621 | * |
|
621 | 622 | * @return RTEMS directive status codes: |
|
622 | 623 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
623 | 624 | * - RTEMS_INVALID_ID - task id invalid |
|
624 | 625 | * - RTEMS_INCORRECT_STATE - task never started |
|
625 | 626 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
626 | 627 | * |
|
627 | 628 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE |
|
628 | 629 | * is immediate. |
|
629 | 630 | * |
|
630 | 631 | */ |
|
631 | 632 | |
|
632 | 633 | int status; |
|
633 | 634 | |
|
634 | 635 | status = stop_current_mode(); // STOP THE CURRENT MODE |
|
635 | 636 | |
|
636 | 637 | #ifdef PRINT_TASK_STATISTICS |
|
637 | 638 | rtems_cpu_usage_report(); |
|
638 | 639 | #endif |
|
639 | 640 | |
|
640 | 641 | #ifdef PRINT_STACK_REPORT |
|
641 | 642 | PRINTF("stack report selected\n") |
|
642 | 643 | rtems_stack_checker_report_usage(); |
|
643 | 644 | #endif |
|
644 | 645 | |
|
645 | 646 | return status; |
|
646 | 647 | } |
|
647 | 648 | |
|
648 | 649 | int enter_mode_normal( unsigned int transitionCoarseTime ) |
|
649 | 650 | { |
|
650 | 651 | /** This function is used to start the NORMAL mode. |
|
651 | 652 | * |
|
652 | 653 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
653 | 654 | * |
|
654 | 655 | * @return RTEMS directive status codes: |
|
655 | 656 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
656 | 657 | * - RTEMS_INVALID_ID - task id invalid |
|
657 | 658 | * - RTEMS_INCORRECT_STATE - task never started |
|
658 | 659 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
659 | 660 | * |
|
660 | 661 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, |
|
661 | 662 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. |
|
662 | 663 | * |
|
663 | 664 | */ |
|
664 | 665 | |
|
665 | 666 | int status; |
|
666 | 667 | |
|
667 | 668 | #ifdef PRINT_TASK_STATISTICS |
|
668 | 669 | rtems_cpu_usage_reset(); |
|
669 | 670 | #endif |
|
670 | 671 | |
|
671 | 672 | status = RTEMS_UNSATISFIED; |
|
672 | 673 | |
|
673 | 674 | switch( lfrCurrentMode ) |
|
674 | 675 | { |
|
675 | 676 | case LFR_MODE_STANDBY: |
|
676 | 677 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks |
|
677 | 678 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
678 | 679 | { |
|
679 | 680 | launch_spectral_matrix( ); |
|
680 | 681 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
681 | 682 | } |
|
682 | 683 | break; |
|
683 | 684 | case LFR_MODE_BURST: |
|
684 | 685 | status = stop_current_mode(); // stop the current mode |
|
685 | 686 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks |
|
686 | 687 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
687 | 688 | { |
|
688 | 689 | launch_spectral_matrix( ); |
|
689 | 690 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
690 | 691 | } |
|
691 | 692 | break; |
|
692 | 693 | case LFR_MODE_SBM1: |
|
693 | 694 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters |
|
694 | 695 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
695 | 696 | update_last_valid_transition_date( transitionCoarseTime ); |
|
696 | 697 | break; |
|
697 | 698 | case LFR_MODE_SBM2: |
|
698 | 699 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters |
|
699 | 700 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
700 | 701 | update_last_valid_transition_date( transitionCoarseTime ); |
|
701 | 702 | break; |
|
702 | 703 | default: |
|
703 | 704 | break; |
|
704 | 705 | } |
|
705 | 706 | |
|
706 | 707 | if (status != RTEMS_SUCCESSFUL) |
|
707 | 708 | { |
|
708 | 709 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) |
|
709 | 710 | status = RTEMS_UNSATISFIED; |
|
710 | 711 | } |
|
711 | 712 | |
|
712 | 713 | return status; |
|
713 | 714 | } |
|
714 | 715 | |
|
715 | 716 | int enter_mode_burst( unsigned int transitionCoarseTime ) |
|
716 | 717 | { |
|
717 | 718 | /** This function is used to start the BURST mode. |
|
718 | 719 | * |
|
719 | 720 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
720 | 721 | * |
|
721 | 722 | * @return RTEMS directive status codes: |
|
722 | 723 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
723 | 724 | * - RTEMS_INVALID_ID - task id invalid |
|
724 | 725 | * - RTEMS_INCORRECT_STATE - task never started |
|
725 | 726 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
726 | 727 | * |
|
727 | 728 | * The way the BURST mode is started does not depend on the LFR current mode. |
|
728 | 729 | * |
|
729 | 730 | */ |
|
730 | 731 | |
|
731 | 732 | |
|
732 | 733 | int status; |
|
733 | 734 | |
|
734 | 735 | #ifdef PRINT_TASK_STATISTICS |
|
735 | 736 | rtems_cpu_usage_reset(); |
|
736 | 737 | #endif |
|
737 | 738 | |
|
738 | 739 | status = stop_current_mode(); // stop the current mode |
|
739 | 740 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks |
|
740 | 741 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
741 | 742 | { |
|
742 | 743 | launch_spectral_matrix( ); |
|
743 | 744 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); |
|
744 | 745 | } |
|
745 | 746 | |
|
746 | 747 | if (status != RTEMS_SUCCESSFUL) |
|
747 | 748 | { |
|
748 | 749 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) |
|
749 | 750 | status = RTEMS_UNSATISFIED; |
|
750 | 751 | } |
|
751 | 752 | |
|
752 | 753 | return status; |
|
753 | 754 | } |
|
754 | 755 | |
|
755 | 756 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) |
|
756 | 757 | { |
|
757 | 758 | /** This function is used to start the SBM1 mode. |
|
758 | 759 | * |
|
759 | 760 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
760 | 761 | * |
|
761 | 762 | * @return RTEMS directive status codes: |
|
762 | 763 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
763 | 764 | * - RTEMS_INVALID_ID - task id invalid |
|
764 | 765 | * - RTEMS_INCORRECT_STATE - task never started |
|
765 | 766 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
766 | 767 | * |
|
767 | 768 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, |
|
768 | 769 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
769 | 770 | * cases, the acquisition is completely restarted. |
|
770 | 771 | * |
|
771 | 772 | */ |
|
772 | 773 | |
|
773 | 774 | int status; |
|
774 | 775 | |
|
775 | 776 | #ifdef PRINT_TASK_STATISTICS |
|
776 | 777 | rtems_cpu_usage_reset(); |
|
777 | 778 | #endif |
|
778 | 779 | |
|
779 | 780 | status = RTEMS_UNSATISFIED; |
|
780 | 781 | |
|
781 | 782 | switch( lfrCurrentMode ) |
|
782 | 783 | { |
|
783 | 784 | case LFR_MODE_STANDBY: |
|
784 | 785 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks |
|
785 | 786 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
786 | 787 | { |
|
787 | 788 | launch_spectral_matrix( ); |
|
788 | 789 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
789 | 790 | } |
|
790 | 791 | break; |
|
791 | 792 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action |
|
792 | 793 | status = restart_asm_activities( LFR_MODE_SBM1 ); |
|
793 | 794 | status = LFR_SUCCESSFUL; |
|
794 | 795 | update_last_valid_transition_date( transitionCoarseTime ); |
|
795 | 796 | break; |
|
796 | 797 | case LFR_MODE_BURST: |
|
797 | 798 | status = stop_current_mode(); // stop the current mode |
|
798 | 799 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks |
|
799 | 800 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
800 | 801 | { |
|
801 | 802 | launch_spectral_matrix( ); |
|
802 | 803 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
803 | 804 | } |
|
804 | 805 | break; |
|
805 | 806 | case LFR_MODE_SBM2: |
|
806 | 807 | status = restart_asm_activities( LFR_MODE_SBM1 ); |
|
807 | 808 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
808 | 809 | update_last_valid_transition_date( transitionCoarseTime ); |
|
809 | 810 | break; |
|
810 | 811 | default: |
|
811 | 812 | break; |
|
812 | 813 | } |
|
813 | 814 | |
|
814 | 815 | if (status != RTEMS_SUCCESSFUL) |
|
815 | 816 | { |
|
816 | 817 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status); |
|
817 | 818 | status = RTEMS_UNSATISFIED; |
|
818 | 819 | } |
|
819 | 820 | |
|
820 | 821 | return status; |
|
821 | 822 | } |
|
822 | 823 | |
|
823 | 824 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) |
|
824 | 825 | { |
|
825 | 826 | /** This function is used to start the SBM2 mode. |
|
826 | 827 | * |
|
827 | 828 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
828 | 829 | * |
|
829 | 830 | * @return RTEMS directive status codes: |
|
830 | 831 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
831 | 832 | * - RTEMS_INVALID_ID - task id invalid |
|
832 | 833 | * - RTEMS_INCORRECT_STATE - task never started |
|
833 | 834 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
834 | 835 | * |
|
835 | 836 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, |
|
836 | 837 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
837 | 838 | * cases, the acquisition is completely restarted. |
|
838 | 839 | * |
|
839 | 840 | */ |
|
840 | 841 | |
|
841 | 842 | int status; |
|
842 | 843 | |
|
843 | 844 | #ifdef PRINT_TASK_STATISTICS |
|
844 | 845 | rtems_cpu_usage_reset(); |
|
845 | 846 | #endif |
|
846 | 847 | |
|
847 | 848 | status = RTEMS_UNSATISFIED; |
|
848 | 849 | |
|
849 | 850 | switch( lfrCurrentMode ) |
|
850 | 851 | { |
|
851 | 852 | case LFR_MODE_STANDBY: |
|
852 | 853 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks |
|
853 | 854 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
854 | 855 | { |
|
855 | 856 | launch_spectral_matrix( ); |
|
856 | 857 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
857 | 858 | } |
|
858 | 859 | break; |
|
859 | 860 | case LFR_MODE_NORMAL: |
|
860 | 861 | status = restart_asm_activities( LFR_MODE_SBM2 ); |
|
861 | 862 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
862 | 863 | update_last_valid_transition_date( transitionCoarseTime ); |
|
863 | 864 | break; |
|
864 | 865 | case LFR_MODE_BURST: |
|
865 | 866 | status = stop_current_mode(); // stop the current mode |
|
866 | 867 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks |
|
867 | 868 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
868 | 869 | { |
|
869 | 870 | launch_spectral_matrix( ); |
|
870 | 871 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
871 | 872 | } |
|
872 | 873 | break; |
|
873 | 874 | case LFR_MODE_SBM1: |
|
874 | 875 | status = restart_asm_activities( LFR_MODE_SBM2 ); |
|
875 | 876 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
876 | 877 | update_last_valid_transition_date( transitionCoarseTime ); |
|
877 | 878 | break; |
|
878 | 879 | default: |
|
879 | 880 | break; |
|
880 | 881 | } |
|
881 | 882 | |
|
882 | 883 | if (status != RTEMS_SUCCESSFUL) |
|
883 | 884 | { |
|
884 | 885 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) |
|
885 | 886 | status = RTEMS_UNSATISFIED; |
|
886 | 887 | } |
|
887 | 888 | |
|
888 | 889 | return status; |
|
889 | 890 | } |
|
890 | 891 | |
|
891 | 892 | int restart_science_tasks( unsigned char lfrRequestedMode ) |
|
892 | 893 | { |
|
893 | 894 | /** This function is used to restart all science tasks. |
|
894 | 895 | * |
|
895 | 896 | * @return RTEMS directive status codes: |
|
896 | 897 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
897 | 898 | * - RTEMS_INVALID_ID - task id invalid |
|
898 | 899 | * - RTEMS_INCORRECT_STATE - task never started |
|
899 | 900 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
900 | 901 | * |
|
901 | 902 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 |
|
902 | 903 | * |
|
903 | 904 | */ |
|
904 | 905 | |
|
905 | 906 | rtems_status_code status[10]; |
|
906 | 907 | rtems_status_code ret; |
|
907 | 908 | |
|
908 | 909 | ret = RTEMS_SUCCESSFUL; |
|
909 | 910 | |
|
910 | 911 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
911 | 912 | if (status[0] != RTEMS_SUCCESSFUL) |
|
912 | 913 | { |
|
913 | 914 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
914 | 915 | } |
|
915 | 916 | |
|
916 | 917 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
917 | 918 | if (status[1] != RTEMS_SUCCESSFUL) |
|
918 | 919 | { |
|
919 | 920 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
920 | 921 | } |
|
921 | 922 | |
|
922 | 923 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
923 | 924 | if (status[2] != RTEMS_SUCCESSFUL) |
|
924 | 925 | { |
|
925 | 926 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) |
|
926 | 927 | } |
|
927 | 928 | |
|
928 | 929 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
929 | 930 | if (status[3] != RTEMS_SUCCESSFUL) |
|
930 | 931 | { |
|
931 | 932 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) |
|
932 | 933 | } |
|
933 | 934 | |
|
934 | 935 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
935 | 936 | if (status[4] != RTEMS_SUCCESSFUL) |
|
936 | 937 | { |
|
937 | 938 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) |
|
938 | 939 | } |
|
939 | 940 | |
|
940 | 941 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
941 | 942 | if (status[5] != RTEMS_SUCCESSFUL) |
|
942 | 943 | { |
|
943 | 944 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) |
|
944 | 945 | } |
|
945 | 946 | |
|
946 | 947 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
947 | 948 | if (status[6] != RTEMS_SUCCESSFUL) |
|
948 | 949 | { |
|
949 | 950 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) |
|
950 | 951 | } |
|
951 | 952 | |
|
952 | 953 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
953 | 954 | if (status[7] != RTEMS_SUCCESSFUL) |
|
954 | 955 | { |
|
955 | 956 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) |
|
956 | 957 | } |
|
957 | 958 | |
|
958 | 959 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
959 | 960 | if (status[8] != RTEMS_SUCCESSFUL) |
|
960 | 961 | { |
|
961 | 962 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) |
|
962 | 963 | } |
|
963 | 964 | |
|
964 | 965 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
965 | 966 | if (status[9] != RTEMS_SUCCESSFUL) |
|
966 | 967 | { |
|
967 | 968 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) |
|
968 | 969 | } |
|
969 | 970 | |
|
970 | 971 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
971 | 972 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
972 | 973 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || |
|
973 | 974 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || |
|
974 | 975 | (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) |
|
975 | 976 | { |
|
976 | 977 | ret = RTEMS_UNSATISFIED; |
|
977 | 978 | } |
|
978 | 979 | |
|
979 | 980 | return ret; |
|
980 | 981 | } |
|
981 | 982 | |
|
982 | 983 | int restart_asm_tasks( unsigned char lfrRequestedMode ) |
|
983 | 984 | { |
|
984 | 985 | /** This function is used to restart average spectral matrices tasks. |
|
985 | 986 | * |
|
986 | 987 | * @return RTEMS directive status codes: |
|
987 | 988 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
988 | 989 | * - RTEMS_INVALID_ID - task id invalid |
|
989 | 990 | * - RTEMS_INCORRECT_STATE - task never started |
|
990 | 991 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
991 | 992 | * |
|
992 | 993 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 |
|
993 | 994 | * |
|
994 | 995 | */ |
|
995 | 996 | |
|
996 | 997 | rtems_status_code status[6]; |
|
997 | 998 | rtems_status_code ret; |
|
998 | 999 | |
|
999 | 1000 | ret = RTEMS_SUCCESSFUL; |
|
1000 | 1001 | |
|
1001 | 1002 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
1002 | 1003 | if (status[0] != RTEMS_SUCCESSFUL) |
|
1003 | 1004 | { |
|
1004 | 1005 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
1005 | 1006 | } |
|
1006 | 1007 | |
|
1007 | 1008 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
1008 | 1009 | if (status[1] != RTEMS_SUCCESSFUL) |
|
1009 | 1010 | { |
|
1010 | 1011 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
1011 | 1012 | } |
|
1012 | 1013 | |
|
1013 | 1014 | status[2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
1014 | 1015 | if (status[2] != RTEMS_SUCCESSFUL) |
|
1015 | 1016 | { |
|
1016 | 1017 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[2]) |
|
1017 | 1018 | } |
|
1018 | 1019 | |
|
1019 | 1020 | status[3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
1020 | 1021 | if (status[3] != RTEMS_SUCCESSFUL) |
|
1021 | 1022 | { |
|
1022 | 1023 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[3]) |
|
1023 | 1024 | } |
|
1024 | 1025 | |
|
1025 | 1026 | status[4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
1026 | 1027 | if (status[4] != RTEMS_SUCCESSFUL) |
|
1027 | 1028 | { |
|
1028 | 1029 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[4]) |
|
1029 | 1030 | } |
|
1030 | 1031 | |
|
1031 | 1032 | status[5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
1032 | 1033 | if (status[5] != RTEMS_SUCCESSFUL) |
|
1033 | 1034 | { |
|
1034 | 1035 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[5]) |
|
1035 | 1036 | } |
|
1036 | 1037 | |
|
1037 | 1038 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
1038 | 1039 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
1039 | 1040 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ) |
|
1040 | 1041 | { |
|
1041 | 1042 | ret = RTEMS_UNSATISFIED; |
|
1042 | 1043 | } |
|
1043 | 1044 | |
|
1044 | 1045 | return ret; |
|
1045 | 1046 | } |
|
1046 | 1047 | |
|
1047 | 1048 | int suspend_science_tasks( void ) |
|
1048 | 1049 | { |
|
1049 | 1050 | /** This function suspends the science tasks. |
|
1050 | 1051 | * |
|
1051 | 1052 | * @return RTEMS directive status codes: |
|
1052 | 1053 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1053 | 1054 | * - RTEMS_INVALID_ID - task id invalid |
|
1054 | 1055 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1055 | 1056 | * |
|
1056 | 1057 | */ |
|
1057 | 1058 | |
|
1058 | 1059 | rtems_status_code status; |
|
1059 | 1060 | |
|
1060 | 1061 | PRINTF("in suspend_science_tasks\n") |
|
1061 | 1062 | |
|
1062 | 1063 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1063 | 1064 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1064 | 1065 | { |
|
1065 | 1066 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1066 | 1067 | } |
|
1067 | 1068 | else |
|
1068 | 1069 | { |
|
1069 | 1070 | status = RTEMS_SUCCESSFUL; |
|
1070 | 1071 | } |
|
1071 | 1072 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1072 | 1073 | { |
|
1073 | 1074 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1074 | 1075 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1075 | 1076 | { |
|
1076 | 1077 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1077 | 1078 | } |
|
1078 | 1079 | else |
|
1079 | 1080 | { |
|
1080 | 1081 | status = RTEMS_SUCCESSFUL; |
|
1081 | 1082 | } |
|
1082 | 1083 | } |
|
1083 | 1084 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1084 | 1085 | { |
|
1085 | 1086 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1086 | 1087 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1087 | 1088 | { |
|
1088 | 1089 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1089 | 1090 | } |
|
1090 | 1091 | else |
|
1091 | 1092 | { |
|
1092 | 1093 | status = RTEMS_SUCCESSFUL; |
|
1093 | 1094 | } |
|
1094 | 1095 | } |
|
1095 | 1096 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1096 | 1097 | { |
|
1097 | 1098 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1098 | 1099 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1099 | 1100 | { |
|
1100 | 1101 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1101 | 1102 | } |
|
1102 | 1103 | else |
|
1103 | 1104 | { |
|
1104 | 1105 | status = RTEMS_SUCCESSFUL; |
|
1105 | 1106 | } |
|
1106 | 1107 | } |
|
1107 | 1108 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1108 | 1109 | { |
|
1109 | 1110 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1110 | 1111 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1111 | 1112 | { |
|
1112 | 1113 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1113 | 1114 | } |
|
1114 | 1115 | else |
|
1115 | 1116 | { |
|
1116 | 1117 | status = RTEMS_SUCCESSFUL; |
|
1117 | 1118 | } |
|
1118 | 1119 | } |
|
1119 | 1120 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1120 | 1121 | { |
|
1121 | 1122 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1122 | 1123 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1123 | 1124 | { |
|
1124 | 1125 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1125 | 1126 | } |
|
1126 | 1127 | else |
|
1127 | 1128 | { |
|
1128 | 1129 | status = RTEMS_SUCCESSFUL; |
|
1129 | 1130 | } |
|
1130 | 1131 | } |
|
1131 | 1132 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
1132 | 1133 | { |
|
1133 | 1134 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
1134 | 1135 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1135 | 1136 | { |
|
1136 | 1137 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
1137 | 1138 | } |
|
1138 | 1139 | else |
|
1139 | 1140 | { |
|
1140 | 1141 | status = RTEMS_SUCCESSFUL; |
|
1141 | 1142 | } |
|
1142 | 1143 | } |
|
1143 | 1144 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
1144 | 1145 | { |
|
1145 | 1146 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
1146 | 1147 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1147 | 1148 | { |
|
1148 | 1149 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
1149 | 1150 | } |
|
1150 | 1151 | else |
|
1151 | 1152 | { |
|
1152 | 1153 | status = RTEMS_SUCCESSFUL; |
|
1153 | 1154 | } |
|
1154 | 1155 | } |
|
1155 | 1156 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
1156 | 1157 | { |
|
1157 | 1158 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
1158 | 1159 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1159 | 1160 | { |
|
1160 | 1161 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
1161 | 1162 | } |
|
1162 | 1163 | else |
|
1163 | 1164 | { |
|
1164 | 1165 | status = RTEMS_SUCCESSFUL; |
|
1165 | 1166 | } |
|
1166 | 1167 | } |
|
1167 | 1168 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
1168 | 1169 | { |
|
1169 | 1170 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
1170 | 1171 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1171 | 1172 | { |
|
1172 | 1173 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
1173 | 1174 | } |
|
1174 | 1175 | else |
|
1175 | 1176 | { |
|
1176 | 1177 | status = RTEMS_SUCCESSFUL; |
|
1177 | 1178 | } |
|
1178 | 1179 | } |
|
1179 | 1180 | |
|
1180 | 1181 | return status; |
|
1181 | 1182 | } |
|
1182 | 1183 | |
|
1183 | 1184 | int suspend_asm_tasks( void ) |
|
1184 | 1185 | { |
|
1185 | 1186 | /** This function suspends the science tasks. |
|
1186 | 1187 | * |
|
1187 | 1188 | * @return RTEMS directive status codes: |
|
1188 | 1189 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1189 | 1190 | * - RTEMS_INVALID_ID - task id invalid |
|
1190 | 1191 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1191 | 1192 | * |
|
1192 | 1193 | */ |
|
1193 | 1194 | |
|
1194 | 1195 | rtems_status_code status; |
|
1195 | 1196 | |
|
1196 | 1197 | PRINTF("in suspend_science_tasks\n") |
|
1197 | 1198 | |
|
1198 | 1199 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1199 | 1200 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1200 | 1201 | { |
|
1201 | 1202 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1202 | 1203 | } |
|
1203 | 1204 | else |
|
1204 | 1205 | { |
|
1205 | 1206 | status = RTEMS_SUCCESSFUL; |
|
1206 | 1207 | } |
|
1207 | 1208 | |
|
1208 | 1209 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1209 | 1210 | { |
|
1210 | 1211 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1211 | 1212 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1212 | 1213 | { |
|
1213 | 1214 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1214 | 1215 | } |
|
1215 | 1216 | else |
|
1216 | 1217 | { |
|
1217 | 1218 | status = RTEMS_SUCCESSFUL; |
|
1218 | 1219 | } |
|
1219 | 1220 | } |
|
1220 | 1221 | |
|
1221 | 1222 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1222 | 1223 | { |
|
1223 | 1224 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1224 | 1225 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1225 | 1226 | { |
|
1226 | 1227 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1227 | 1228 | } |
|
1228 | 1229 | else |
|
1229 | 1230 | { |
|
1230 | 1231 | status = RTEMS_SUCCESSFUL; |
|
1231 | 1232 | } |
|
1232 | 1233 | } |
|
1233 | 1234 | |
|
1234 | 1235 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1235 | 1236 | { |
|
1236 | 1237 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1237 | 1238 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1238 | 1239 | { |
|
1239 | 1240 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1240 | 1241 | } |
|
1241 | 1242 | else |
|
1242 | 1243 | { |
|
1243 | 1244 | status = RTEMS_SUCCESSFUL; |
|
1244 | 1245 | } |
|
1245 | 1246 | } |
|
1246 | 1247 | |
|
1247 | 1248 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1248 | 1249 | { |
|
1249 | 1250 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1250 | 1251 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1251 | 1252 | { |
|
1252 | 1253 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1253 | 1254 | } |
|
1254 | 1255 | else |
|
1255 | 1256 | { |
|
1256 | 1257 | status = RTEMS_SUCCESSFUL; |
|
1257 | 1258 | } |
|
1258 | 1259 | } |
|
1259 | 1260 | |
|
1260 | 1261 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1261 | 1262 | { |
|
1262 | 1263 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1263 | 1264 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1264 | 1265 | { |
|
1265 | 1266 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1266 | 1267 | } |
|
1267 | 1268 | else |
|
1268 | 1269 | { |
|
1269 | 1270 | status = RTEMS_SUCCESSFUL; |
|
1270 | 1271 | } |
|
1271 | 1272 | } |
|
1272 | 1273 | |
|
1273 | 1274 | return status; |
|
1274 | 1275 | } |
|
1275 | 1276 | |
|
1276 | 1277 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) |
|
1277 | 1278 | { |
|
1278 | 1279 | |
|
1279 | 1280 | WFP_reset_current_ring_nodes(); |
|
1280 | 1281 | |
|
1281 | 1282 | reset_waveform_picker_regs(); |
|
1282 | 1283 | |
|
1283 | 1284 | set_wfp_burst_enable_register( mode ); |
|
1284 | 1285 | |
|
1285 | 1286 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1286 | 1287 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1287 | 1288 | |
|
1288 | 1289 | if (transitionCoarseTime == 0) |
|
1289 | 1290 | { |
|
1290 | 1291 | // instant transition means transition on the next valid date |
|
1291 | 1292 | // this is mandatory to have a good snapshot period and a good correction of the snapshot period |
|
1292 | 1293 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; |
|
1293 | 1294 | } |
|
1294 | 1295 | else |
|
1295 | 1296 | { |
|
1296 | 1297 | waveform_picker_regs->start_date = transitionCoarseTime; |
|
1297 | 1298 | } |
|
1298 | 1299 | |
|
1299 | 1300 | update_last_valid_transition_date(waveform_picker_regs->start_date); |
|
1300 | 1301 | |
|
1301 | 1302 | } |
|
1302 | 1303 | |
|
1303 | 1304 | void launch_spectral_matrix( void ) |
|
1304 | 1305 | { |
|
1305 | 1306 | SM_reset_current_ring_nodes(); |
|
1306 | 1307 | |
|
1307 | 1308 | reset_spectral_matrix_regs(); |
|
1308 | 1309 | |
|
1309 | 1310 | reset_nb_sm(); |
|
1310 | 1311 | |
|
1311 | 1312 | set_sm_irq_onNewMatrix( 1 ); |
|
1312 | 1313 | |
|
1313 | 1314 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1314 | 1315 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1315 | 1316 | |
|
1316 | 1317 | } |
|
1317 | 1318 | |
|
1318 | 1319 | void set_sm_irq_onNewMatrix( unsigned char value ) |
|
1319 | 1320 | { |
|
1320 | 1321 | if (value == 1) |
|
1321 | 1322 | { |
|
1322 | 1323 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; |
|
1323 | 1324 | } |
|
1324 | 1325 | else |
|
1325 | 1326 | { |
|
1326 | 1327 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 |
|
1327 | 1328 | } |
|
1328 | 1329 | } |
|
1329 | 1330 | |
|
1330 | 1331 | void set_sm_irq_onError( unsigned char value ) |
|
1331 | 1332 | { |
|
1332 | 1333 | if (value == 1) |
|
1333 | 1334 | { |
|
1334 | 1335 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; |
|
1335 | 1336 | } |
|
1336 | 1337 | else |
|
1337 | 1338 | { |
|
1338 | 1339 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 |
|
1339 | 1340 | } |
|
1340 | 1341 | } |
|
1341 | 1342 | |
|
1342 | 1343 | //***************************** |
|
1343 | 1344 | // CONFIGURE CALIBRATION SIGNAL |
|
1344 | 1345 | void setCalibrationPrescaler( unsigned int prescaler ) |
|
1345 | 1346 | { |
|
1346 | 1347 | // prescaling of the master clock (25 MHz) |
|
1347 | 1348 | // master clock is divided by 2^prescaler |
|
1348 | 1349 | time_management_regs->calPrescaler = prescaler; |
|
1349 | 1350 | } |
|
1350 | 1351 | |
|
1351 | 1352 | void setCalibrationDivisor( unsigned int divisionFactor ) |
|
1352 | 1353 | { |
|
1353 | 1354 | // division of the prescaled clock by the division factor |
|
1354 | 1355 | time_management_regs->calDivisor = divisionFactor; |
|
1355 | 1356 | } |
|
1356 | 1357 | |
|
1357 | 1358 | void setCalibrationData( void ){ |
|
1358 | 1359 | unsigned int k; |
|
1359 | 1360 | unsigned short data; |
|
1360 | 1361 | float val; |
|
1361 | 1362 | float f0; |
|
1362 | 1363 | float f1; |
|
1363 | 1364 | float fs; |
|
1364 | 1365 | float Ts; |
|
1365 | 1366 | float scaleFactor; |
|
1366 | 1367 | |
|
1367 | 1368 | f0 = 625; |
|
1368 | 1369 | f1 = 10000; |
|
1369 | 1370 | fs = 160256.410; |
|
1370 | 1371 | Ts = 1. / fs; |
|
1371 | 1372 | scaleFactor = 0.250 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV |
|
1372 | 1373 | |
|
1373 | 1374 | time_management_regs->calDataPtr = 0x00; |
|
1374 | 1375 | |
|
1375 | 1376 | // build the signal for the SCM calibration |
|
1376 | 1377 | for (k=0; k<256; k++) |
|
1377 | 1378 | { |
|
1378 | 1379 | val = sin( 2 * pi * f0 * k * Ts ) |
|
1379 | 1380 | + sin( 2 * pi * f1 * k * Ts ); |
|
1380 | 1381 | data = (unsigned short) ((val * scaleFactor) + 2048); |
|
1381 | 1382 | time_management_regs->calData = data & 0xfff; |
|
1382 | 1383 | } |
|
1383 | 1384 | } |
|
1384 | 1385 | |
|
1385 | 1386 | void setCalibrationDataInterleaved( void ){ |
|
1386 | 1387 | unsigned int k; |
|
1387 | 1388 | float val; |
|
1388 | 1389 | float f0; |
|
1389 | 1390 | float f1; |
|
1390 | 1391 | float fs; |
|
1391 | 1392 | float Ts; |
|
1392 | 1393 | unsigned short data[384]; |
|
1393 | 1394 | unsigned char *dataPtr; |
|
1394 | 1395 | |
|
1395 | 1396 | f0 = 625; |
|
1396 | 1397 | f1 = 10000; |
|
1397 | 1398 | fs = 240384.615; |
|
1398 | 1399 | Ts = 1. / fs; |
|
1399 | 1400 | |
|
1400 | 1401 | time_management_regs->calDataPtr = 0x00; |
|
1401 | 1402 | |
|
1402 | 1403 | // build the signal for the SCM calibration |
|
1403 | 1404 | for (k=0; k<384; k++) |
|
1404 | 1405 | { |
|
1405 | 1406 | val = sin( 2 * pi * f0 * k * Ts ) |
|
1406 | 1407 | + sin( 2 * pi * f1 * k * Ts ); |
|
1407 | 1408 | data[k] = (unsigned short) (val * 512 + 2048); |
|
1408 | 1409 | } |
|
1409 | 1410 | |
|
1410 | 1411 | // write the signal in interleaved mode |
|
1411 | 1412 | for (k=0; k<128; k++) |
|
1412 | 1413 | { |
|
1413 | 1414 | dataPtr = (unsigned char*) &data[k*3 + 2]; |
|
1414 | 1415 | time_management_regs->calData = (data[k*3] & 0xfff) |
|
1415 | 1416 | + ( (dataPtr[0] & 0x3f) << 12); |
|
1416 | 1417 | time_management_regs->calData = (data[k*3 + 1] & 0xfff) |
|
1417 | 1418 | + ( (dataPtr[1] & 0x3f) << 12); |
|
1418 | 1419 | } |
|
1419 | 1420 | } |
|
1420 | 1421 | |
|
1421 | 1422 | void setCalibrationReload( bool state) |
|
1422 | 1423 | { |
|
1423 | 1424 | if (state == true) |
|
1424 | 1425 | { |
|
1425 | 1426 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] |
|
1426 | 1427 | } |
|
1427 | 1428 | else |
|
1428 | 1429 | { |
|
1429 | 1430 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] |
|
1430 | 1431 | } |
|
1431 | 1432 | } |
|
1432 | 1433 | |
|
1433 | 1434 | void setCalibrationEnable( bool state ) |
|
1434 | 1435 | { |
|
1435 | 1436 | // this bit drives the multiplexer |
|
1436 | 1437 | if (state == true) |
|
1437 | 1438 | { |
|
1438 | 1439 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] |
|
1439 | 1440 | } |
|
1440 | 1441 | else |
|
1441 | 1442 | { |
|
1442 | 1443 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] |
|
1443 | 1444 | } |
|
1444 | 1445 | } |
|
1445 | 1446 | |
|
1446 | 1447 | void setCalibrationInterleaved( bool state ) |
|
1447 | 1448 | { |
|
1448 | 1449 | // this bit drives the multiplexer |
|
1449 | 1450 | if (state == true) |
|
1450 | 1451 | { |
|
1451 | 1452 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] |
|
1452 | 1453 | } |
|
1453 | 1454 | else |
|
1454 | 1455 | { |
|
1455 | 1456 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] |
|
1456 | 1457 | } |
|
1457 | 1458 | } |
|
1458 | 1459 | |
|
1459 | 1460 | void setCalibration( bool state ) |
|
1460 | 1461 | { |
|
1461 | 1462 | if (state == true) |
|
1462 | 1463 | { |
|
1463 | 1464 | setCalibrationEnable( true ); |
|
1464 | 1465 | setCalibrationReload( false ); |
|
1465 | 1466 | set_hk_lfr_calib_enable( true ); |
|
1466 | 1467 | } |
|
1467 | 1468 | else |
|
1468 | 1469 | { |
|
1469 | 1470 | setCalibrationEnable( false ); |
|
1470 | 1471 | setCalibrationReload( true ); |
|
1471 | 1472 | set_hk_lfr_calib_enable( false ); |
|
1472 | 1473 | } |
|
1473 | 1474 | } |
|
1474 | 1475 | |
|
1475 | 1476 | void configureCalibration( bool interleaved ) |
|
1476 | 1477 | { |
|
1477 | 1478 | setCalibration( false ); |
|
1478 | 1479 | if ( interleaved == true ) |
|
1479 | 1480 | { |
|
1480 | 1481 | setCalibrationInterleaved( true ); |
|
1481 | 1482 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1482 | 1483 | setCalibrationDivisor( 26 ); // => 240 384 |
|
1483 | 1484 | setCalibrationDataInterleaved(); |
|
1484 | 1485 | } |
|
1485 | 1486 | else |
|
1486 | 1487 | { |
|
1487 | 1488 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1488 | 1489 | setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) |
|
1489 | 1490 | setCalibrationData(); |
|
1490 | 1491 | } |
|
1491 | 1492 | } |
|
1492 | 1493 | |
|
1493 | 1494 | //**************** |
|
1494 | 1495 | // CLOSING ACTIONS |
|
1495 | 1496 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1496 | 1497 | { |
|
1497 | 1498 | /** This function is used to update the HK packets statistics after a successful TC execution. |
|
1498 | 1499 | * |
|
1499 | 1500 | * @param TC points to the TC being processed |
|
1500 | 1501 | * @param time is the time used to date the TC execution |
|
1501 | 1502 | * |
|
1502 | 1503 | */ |
|
1503 | 1504 | |
|
1504 | 1505 | unsigned int val; |
|
1505 | 1506 | |
|
1506 | 1507 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
1507 | 1508 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
1508 | 1509 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; |
|
1509 | 1510 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
1510 | 1511 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; |
|
1511 | 1512 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
1512 | 1513 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; |
|
1513 | 1514 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; |
|
1514 | 1515 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; |
|
1515 | 1516 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; |
|
1516 | 1517 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; |
|
1517 | 1518 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; |
|
1518 | 1519 | |
|
1519 | 1520 | val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; |
|
1520 | 1521 | val++; |
|
1521 | 1522 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1522 | 1523 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); |
|
1523 | 1524 | } |
|
1524 | 1525 | |
|
1525 | 1526 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1526 | 1527 | { |
|
1527 | 1528 | /** This function is used to update the HK packets statistics after a TC rejection. |
|
1528 | 1529 | * |
|
1529 | 1530 | * @param TC points to the TC being processed |
|
1530 | 1531 | * @param time is the time used to date the TC rejection |
|
1531 | 1532 | * |
|
1532 | 1533 | */ |
|
1533 | 1534 | |
|
1534 | 1535 | unsigned int val; |
|
1535 | 1536 | |
|
1536 | 1537 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
1537 | 1538 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
1538 | 1539 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; |
|
1539 | 1540 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
1540 | 1541 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; |
|
1541 | 1542 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
1542 | 1543 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; |
|
1543 | 1544 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; |
|
1544 | 1545 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; |
|
1545 | 1546 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; |
|
1546 | 1547 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; |
|
1547 | 1548 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; |
|
1548 | 1549 | |
|
1549 | 1550 | val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; |
|
1550 | 1551 | val++; |
|
1551 | 1552 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1552 | 1553 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); |
|
1553 | 1554 | } |
|
1554 | 1555 | |
|
1555 | 1556 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) |
|
1556 | 1557 | { |
|
1557 | 1558 | /** This function is the last step of the TC execution workflow. |
|
1558 | 1559 | * |
|
1559 | 1560 | * @param TC points to the TC being processed |
|
1560 | 1561 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) |
|
1561 | 1562 | * @param queue_id is the id of the RTEMS message queue used to send TM packets |
|
1562 | 1563 | * @param time is the time used to date the TC execution |
|
1563 | 1564 | * |
|
1564 | 1565 | */ |
|
1565 | 1566 | |
|
1566 | 1567 | unsigned char requestedMode; |
|
1567 | 1568 | |
|
1568 | 1569 | if (result == LFR_SUCCESSFUL) |
|
1569 | 1570 | { |
|
1570 | 1571 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
1571 | 1572 | & |
|
1572 | 1573 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
1573 | 1574 | ) |
|
1574 | 1575 | { |
|
1575 | 1576 | send_tm_lfr_tc_exe_success( TC, queue_id ); |
|
1576 | 1577 | } |
|
1577 | 1578 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) |
|
1578 | 1579 | { |
|
1579 | 1580 | //********************************** |
|
1580 | 1581 | // UPDATE THE LFRMODE LOCAL VARIABLE |
|
1581 | 1582 | requestedMode = TC->dataAndCRC[1]; |
|
1582 | 1583 | updateLFRCurrentMode( requestedMode ); |
|
1583 | 1584 | } |
|
1584 | 1585 | } |
|
1585 | 1586 | else if (result == LFR_EXE_ERROR) |
|
1586 | 1587 | { |
|
1587 | 1588 | send_tm_lfr_tc_exe_error( TC, queue_id ); |
|
1588 | 1589 | } |
|
1589 | 1590 | } |
|
1590 | 1591 | |
|
1591 | 1592 | //*************************** |
|
1592 | 1593 | // Interrupt Service Routines |
|
1593 | 1594 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
1594 | 1595 | { |
|
1595 | 1596 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1596 | 1597 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") |
|
1597 | 1598 | } |
|
1598 | 1599 | } |
|
1599 | 1600 | |
|
1600 | 1601 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
1601 | 1602 | { |
|
1602 | 1603 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1603 | 1604 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") |
|
1604 | 1605 | } |
|
1605 | 1606 | } |
|
1606 | 1607 | |
|
1607 | 1608 | //**************** |
|
1608 | 1609 | // OTHER FUNCTIONS |
|
1609 | 1610 | void updateLFRCurrentMode( unsigned char requestedMode ) |
|
1610 | 1611 | { |
|
1611 | 1612 | /** This function updates the value of the global variable lfrCurrentMode. |
|
1612 | 1613 | * |
|
1613 | 1614 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
1614 | 1615 | * |
|
1615 | 1616 | */ |
|
1616 | 1617 | |
|
1617 | 1618 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
1618 | 1619 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); |
|
1619 | 1620 | lfrCurrentMode = requestedMode; |
|
1620 | 1621 | } |
|
1621 | 1622 | |
|
1622 | 1623 | void set_lfr_soft_reset( unsigned char value ) |
|
1623 | 1624 | { |
|
1624 | 1625 | if (value == 1) |
|
1625 | 1626 | { |
|
1626 | 1627 | time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] |
|
1627 | 1628 | } |
|
1628 | 1629 | else |
|
1629 | 1630 | { |
|
1630 | 1631 | time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] |
|
1631 | 1632 | } |
|
1632 | 1633 | } |
|
1633 | 1634 | |
|
1634 | 1635 | void reset_lfr( void ) |
|
1635 | 1636 | { |
|
1636 | 1637 | set_lfr_soft_reset( 1 ); |
|
1637 | 1638 | |
|
1638 | 1639 | set_lfr_soft_reset( 0 ); |
|
1639 | 1640 | |
|
1640 | 1641 | set_hk_lfr_sc_potential_flag( true ); |
|
1641 | 1642 | } |
@@ -1,1628 +1,1753 | |||
|
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; |
|
18 | 18 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2; |
|
19 | 19 | ring_node kcoefficient_node_1; |
|
20 | 20 | ring_node kcoefficient_node_2; |
|
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+10, 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+10, 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+10, 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+10, 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+10, 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*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25)); |
|
193 | 193 | if (aux > FLOAT_EQUAL_ZERO) |
|
194 | 194 | { |
|
195 | 195 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 ); |
|
196 | 196 | flag = LFR_DEFAULT; |
|
197 | 197 | } |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | // SET THE PARAMETERS |
|
201 | 201 | if (flag == LFR_SUCCESSFUL) |
|
202 | 202 | { |
|
203 | 203 | flag = set_sy_lfr_s1_bp_p0( TC ); |
|
204 | 204 | flag = set_sy_lfr_s1_bp_p1( TC ); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | return flag; |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
211 | 211 | { |
|
212 | 212 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
213 | 213 | * |
|
214 | 214 | * @param TC points to the TeleCommand packet that is being processed |
|
215 | 215 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
216 | 216 | * |
|
217 | 217 | */ |
|
218 | 218 | |
|
219 | 219 | int flag; |
|
220 | 220 | rtems_status_code status; |
|
221 | 221 | unsigned char sy_lfr_s2_bp_p0; |
|
222 | 222 | unsigned char sy_lfr_s2_bp_p1; |
|
223 | 223 | float aux; |
|
224 | 224 | |
|
225 | 225 | flag = LFR_SUCCESSFUL; |
|
226 | 226 | |
|
227 | 227 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
228 | 228 | status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
229 | 229 | flag = LFR_DEFAULT; |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; |
|
233 | 233 | sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; |
|
234 | 234 | |
|
235 | 235 | // sy_lfr_s2_bp_p0 |
|
236 | 236 | if (flag == LFR_SUCCESSFUL) |
|
237 | 237 | { |
|
238 | 238 | if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 ) |
|
239 | 239 | { |
|
240 | 240 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 ); |
|
241 | 241 | flag = WRONG_APP_DATA; |
|
242 | 242 | } |
|
243 | 243 | } |
|
244 | 244 | // sy_lfr_s2_bp_p1 |
|
245 | 245 | if (flag == LFR_SUCCESSFUL) |
|
246 | 246 | { |
|
247 | 247 | if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 ) |
|
248 | 248 | { |
|
249 | 249 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 ); |
|
250 | 250 | flag = WRONG_APP_DATA; |
|
251 | 251 | } |
|
252 | 252 | } |
|
253 | 253 | //****************************************************************** |
|
254 | 254 | // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1 |
|
255 | 255 | if (flag == LFR_SUCCESSFUL) |
|
256 | 256 | { |
|
257 | 257 | sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; |
|
258 | 258 | sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; |
|
259 | 259 | aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0); |
|
260 | 260 | if (aux > FLOAT_EQUAL_ZERO) |
|
261 | 261 | { |
|
262 | 262 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 ); |
|
263 | 263 | flag = LFR_DEFAULT; |
|
264 | 264 | } |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | // SET THE PARAMETERS |
|
268 | 268 | if (flag == LFR_SUCCESSFUL) |
|
269 | 269 | { |
|
270 | 270 | flag = set_sy_lfr_s2_bp_p0( TC ); |
|
271 | 271 | flag = set_sy_lfr_s2_bp_p1( TC ); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | return flag; |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
278 | 278 | { |
|
279 | 279 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
280 | 280 | * |
|
281 | 281 | * @param TC points to the TeleCommand packet that is being processed |
|
282 | 282 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
283 | 283 | * |
|
284 | 284 | */ |
|
285 | 285 | |
|
286 | 286 | int flag; |
|
287 | 287 | |
|
288 | 288 | flag = LFR_DEFAULT; |
|
289 | 289 | |
|
290 | 290 | flag = set_sy_lfr_kcoeff( TC, queue_id ); |
|
291 | 291 | |
|
292 | 292 | return flag; |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
296 | 296 | { |
|
297 | 297 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
298 | 298 | * |
|
299 | 299 | * @param TC points to the TeleCommand packet that is being processed |
|
300 | 300 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
301 | 301 | * |
|
302 | 302 | */ |
|
303 | 303 | |
|
304 | 304 | int flag; |
|
305 | 305 | |
|
306 | 306 | flag = LFR_DEFAULT; |
|
307 | 307 | |
|
308 | 308 | flag = set_sy_lfr_fbins( TC ); |
|
309 | 309 | |
|
310 | 310 | return flag; |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
314 | 314 | { |
|
315 | 315 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
316 | 316 | * |
|
317 | 317 | * @param TC points to the TeleCommand packet that is being processed |
|
318 | 318 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
319 | 319 | * |
|
320 | 320 | */ |
|
321 | 321 | |
|
322 | 322 | int flag; |
|
323 | unsigned char k; | |
|
323 | 324 | |
|
324 | 325 | flag = LFR_DEFAULT; |
|
326 | k = 0; | |
|
325 | 327 | |
|
326 | 328 | flag = check_sy_lfr_filter_parameters( TC, queue_id ); |
|
327 | 329 | |
|
328 | 330 | if (flag == LFR_SUCCESSFUL) |
|
329 | 331 | { |
|
330 | 332 | parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ]; |
|
331 | 333 | parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ]; |
|
332 | 334 | parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ]; |
|
333 | 335 | parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ]; |
|
334 | 336 | parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ]; |
|
335 | 337 | parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ]; |
|
336 | 338 | parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ]; |
|
337 | 339 | parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ]; |
|
338 | 340 | parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ]; |
|
339 | 341 | parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ]; |
|
340 | 342 | parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ]; |
|
341 | 343 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ]; |
|
342 | 344 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ]; |
|
343 | 345 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ]; |
|
344 | 346 | parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ]; |
|
345 | 347 | |
|
346 | 348 | //**************************** |
|
347 | 349 | // store PAS filter parameters |
|
348 | 350 | // sy_lfr_pas_filter_enabled |
|
349 | 351 | filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled; |
|
350 | 352 | set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 ); |
|
351 | 353 | // sy_lfr_pas_filter_modulus |
|
352 | 354 | filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus; |
|
353 | 355 | // sy_lfr_pas_filter_tbad |
|
354 | 356 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad, |
|
355 | 357 | parameter_dump_packet.sy_lfr_pas_filter_tbad ); |
|
356 | 358 | // sy_lfr_pas_filter_offset |
|
357 | 359 | filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset; |
|
358 | 360 | // sy_lfr_pas_filter_shift |
|
359 | 361 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift, |
|
360 | 362 | parameter_dump_packet.sy_lfr_pas_filter_shift ); |
|
361 | 363 | |
|
362 | 364 | //**************************************************** |
|
363 | 365 | // store the parameter sy_lfr_sc_rw_delta_f as a float |
|
364 | 366 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f, |
|
365 | 367 | parameter_dump_packet.sy_lfr_sc_rw_delta_f ); |
|
368 | ||
|
369 | // copy rw.._k.. from the incoming TC to the local parameter_dump_packet | |
|
370 | for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++) | |
|
371 | { | |
|
372 | parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ]; | |
|
373 | } | |
|
374 | ||
|
375 | //*********************************************** | |
|
376 | // store the parameter sy_lfr_rw.._k.. as a float | |
|
377 | // rw1_k | |
|
378 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 ); | |
|
379 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 ); | |
|
380 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 ); | |
|
381 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 ); | |
|
382 | // rw2_k | |
|
383 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 ); | |
|
384 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 ); | |
|
385 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 ); | |
|
386 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 ); | |
|
387 | // rw3_k | |
|
388 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 ); | |
|
389 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 ); | |
|
390 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 ); | |
|
391 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 ); | |
|
392 | // rw4_k | |
|
393 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 ); | |
|
394 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 ); | |
|
395 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 ); | |
|
396 | copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 ); | |
|
397 | ||
|
366 | 398 | } |
|
367 | 399 | |
|
368 | 400 | return flag; |
|
369 | 401 | } |
|
370 | 402 | |
|
371 | 403 | int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
372 | 404 | { |
|
373 | 405 | /** This function updates the LFR registers with the incoming sbm2 parameters. |
|
374 | 406 | * |
|
375 | 407 | * @param TC points to the TeleCommand packet that is being processed |
|
376 | 408 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
377 | 409 | * |
|
378 | 410 | */ |
|
379 | 411 | |
|
380 | 412 | unsigned int address; |
|
381 | 413 | rtems_status_code status; |
|
382 | 414 | unsigned int freq; |
|
383 | 415 | unsigned int bin; |
|
384 | 416 | unsigned int coeff; |
|
385 | 417 | unsigned char *kCoeffPtr; |
|
386 | 418 | unsigned char *kCoeffDumpPtr; |
|
387 | 419 | |
|
388 | 420 | // for each sy_lfr_kcoeff_frequency there is 32 kcoeff |
|
389 | 421 | // F0 => 11 bins |
|
390 | 422 | // F1 => 13 bins |
|
391 | 423 | // F2 => 12 bins |
|
392 | 424 | // 36 bins to dump in two packets (30 bins max per packet) |
|
393 | 425 | |
|
394 | 426 | //********* |
|
395 | 427 | // PACKET 1 |
|
396 | 428 | // 11 F0 bins, 13 F1 bins and 6 F2 bins |
|
397 | 429 | kcoefficients_dump_1.destinationID = TC->sourceID; |
|
398 | 430 | increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID ); |
|
399 | 431 | for( freq=0; |
|
400 | 432 | freq<NB_BINS_COMPRESSED_SM_F0; |
|
401 | 433 | freq++ ) |
|
402 | 434 | { |
|
403 | 435 | kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq; |
|
404 | 436 | bin = freq; |
|
405 | 437 | // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm); |
|
406 | 438 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
407 | 439 | { |
|
408 | 440 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency |
|
409 | 441 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
410 | 442 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
411 | 443 | } |
|
412 | 444 | } |
|
413 | 445 | for( freq=NB_BINS_COMPRESSED_SM_F0; |
|
414 | 446 | freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1); |
|
415 | 447 | freq++ ) |
|
416 | 448 | { |
|
417 | 449 | kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq; |
|
418 | 450 | bin = freq - NB_BINS_COMPRESSED_SM_F0; |
|
419 | 451 | // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm); |
|
420 | 452 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
421 | 453 | { |
|
422 | 454 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency |
|
423 | 455 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
424 | 456 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
425 | 457 | } |
|
426 | 458 | } |
|
427 | 459 | for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1); |
|
428 | 460 | freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6); |
|
429 | 461 | freq++ ) |
|
430 | 462 | { |
|
431 | 463 | kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq; |
|
432 | 464 | bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1); |
|
433 | 465 | // printKCoefficients( freq, bin, k_coeff_intercalib_f2); |
|
434 | 466 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
435 | 467 | { |
|
436 | 468 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency |
|
437 | 469 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
438 | 470 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
439 | 471 | } |
|
440 | 472 | } |
|
441 | 473 | kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
442 | 474 | kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
443 | 475 | kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
444 | 476 | kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
445 | 477 | kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
446 | 478 | kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
447 | 479 | // SEND DATA |
|
448 | 480 | kcoefficient_node_1.status = 1; |
|
449 | 481 | address = (unsigned int) &kcoefficient_node_1; |
|
450 | 482 | status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) ); |
|
451 | 483 | if (status != RTEMS_SUCCESSFUL) { |
|
452 | 484 | PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status) |
|
453 | 485 | } |
|
454 | 486 | |
|
455 | 487 | //******** |
|
456 | 488 | // PACKET 2 |
|
457 | 489 | // 6 F2 bins |
|
458 | 490 | kcoefficients_dump_2.destinationID = TC->sourceID; |
|
459 | 491 | increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID ); |
|
460 | 492 | for( freq=0; freq<6; freq++ ) |
|
461 | 493 | { |
|
462 | 494 | kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq; |
|
463 | 495 | bin = freq + 6; |
|
464 | 496 | // printKCoefficients( freq, bin, k_coeff_intercalib_f2); |
|
465 | 497 | for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ ) |
|
466 | 498 | { |
|
467 | 499 | kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency |
|
468 | 500 | kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ]; |
|
469 | 501 | copyFloatByChar( kCoeffDumpPtr, kCoeffPtr ); |
|
470 | 502 | } |
|
471 | 503 | } |
|
472 | 504 | kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
473 | 505 | kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
474 | 506 | kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
475 | 507 | kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
476 | 508 | kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
477 | 509 | kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
478 | 510 | // SEND DATA |
|
479 | 511 | kcoefficient_node_2.status = 1; |
|
480 | 512 | address = (unsigned int) &kcoefficient_node_2; |
|
481 | 513 | status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) ); |
|
482 | 514 | if (status != RTEMS_SUCCESSFUL) { |
|
483 | 515 | PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status) |
|
484 | 516 | } |
|
485 | 517 | |
|
486 | 518 | return status; |
|
487 | 519 | } |
|
488 | 520 | |
|
489 | 521 | int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
490 | 522 | { |
|
491 | 523 | /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue. |
|
492 | 524 | * |
|
493 | 525 | * @param queue_id is the id of the queue which handles TM related to this execution step. |
|
494 | 526 | * |
|
495 | 527 | * @return RTEMS directive status codes: |
|
496 | 528 | * - RTEMS_SUCCESSFUL - message sent successfully |
|
497 | 529 | * - RTEMS_INVALID_ID - invalid queue id |
|
498 | 530 | * - RTEMS_INVALID_SIZE - invalid message size |
|
499 | 531 | * - RTEMS_INVALID_ADDRESS - buffer is NULL |
|
500 | 532 | * - RTEMS_UNSATISFIED - out of message buffers |
|
501 | 533 | * - RTEMS_TOO_MANY - queue s limit has been reached |
|
502 | 534 | * |
|
503 | 535 | */ |
|
504 | 536 | |
|
505 | 537 | int status; |
|
506 | 538 | |
|
507 | 539 | increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID ); |
|
508 | 540 | parameter_dump_packet.destinationID = TC->sourceID; |
|
509 | 541 | |
|
510 | 542 | // UPDATE TIME |
|
511 | 543 | parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
512 | 544 | parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
513 | 545 | parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
514 | 546 | parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
515 | 547 | parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
516 | 548 | parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
517 | 549 | // SEND DATA |
|
518 | 550 | status = rtems_message_queue_send( queue_id, ¶meter_dump_packet, |
|
519 | 551 | PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
520 | 552 | if (status != RTEMS_SUCCESSFUL) { |
|
521 | 553 | PRINTF1("in action_dump *** ERR sending packet, code %d", status) |
|
522 | 554 | } |
|
523 | 555 | |
|
524 | 556 | return status; |
|
525 | 557 | } |
|
526 | 558 | |
|
527 | 559 | //*********************** |
|
528 | 560 | // NORMAL MODE PARAMETERS |
|
529 | 561 | |
|
530 | 562 | int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
531 | 563 | { |
|
532 | 564 | unsigned char msb; |
|
533 | 565 | unsigned char lsb; |
|
534 | 566 | int flag; |
|
535 | 567 | float aux; |
|
536 | 568 | rtems_status_code status; |
|
537 | 569 | |
|
538 | 570 | unsigned int sy_lfr_n_swf_l; |
|
539 | 571 | unsigned int sy_lfr_n_swf_p; |
|
540 | 572 | unsigned int sy_lfr_n_asm_p; |
|
541 | 573 | unsigned char sy_lfr_n_bp_p0; |
|
542 | 574 | unsigned char sy_lfr_n_bp_p1; |
|
543 | 575 | unsigned char sy_lfr_n_cwf_long_f3; |
|
544 | 576 | |
|
545 | 577 | flag = LFR_SUCCESSFUL; |
|
546 | 578 | |
|
547 | 579 | //*************** |
|
548 | 580 | // get parameters |
|
549 | 581 | msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; |
|
550 | 582 | lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; |
|
551 | 583 | sy_lfr_n_swf_l = msb * 256 + lsb; |
|
552 | 584 | |
|
553 | 585 | msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; |
|
554 | 586 | lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; |
|
555 | 587 | sy_lfr_n_swf_p = msb * 256 + lsb; |
|
556 | 588 | |
|
557 | 589 | msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; |
|
558 | 590 | lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; |
|
559 | 591 | sy_lfr_n_asm_p = msb * 256 + lsb; |
|
560 | 592 | |
|
561 | 593 | sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; |
|
562 | 594 | |
|
563 | 595 | sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; |
|
564 | 596 | |
|
565 | 597 | sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; |
|
566 | 598 | |
|
567 | 599 | //****************** |
|
568 | 600 | // check consistency |
|
569 | 601 | // sy_lfr_n_swf_l |
|
570 | 602 | if (sy_lfr_n_swf_l != 2048) |
|
571 | 603 | { |
|
572 | 604 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l ); |
|
573 | 605 | flag = WRONG_APP_DATA; |
|
574 | 606 | } |
|
575 | 607 | // sy_lfr_n_swf_p |
|
576 | 608 | if (flag == LFR_SUCCESSFUL) |
|
577 | 609 | { |
|
578 | 610 | if ( sy_lfr_n_swf_p < 22 ) |
|
579 | 611 | { |
|
580 | 612 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p ); |
|
581 | 613 | flag = WRONG_APP_DATA; |
|
582 | 614 | } |
|
583 | 615 | } |
|
584 | 616 | // sy_lfr_n_bp_p0 |
|
585 | 617 | if (flag == LFR_SUCCESSFUL) |
|
586 | 618 | { |
|
587 | 619 | if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0) |
|
588 | 620 | { |
|
589 | 621 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 ); |
|
590 | 622 | flag = WRONG_APP_DATA; |
|
591 | 623 | } |
|
592 | 624 | } |
|
593 | 625 | // sy_lfr_n_asm_p |
|
594 | 626 | if (flag == LFR_SUCCESSFUL) |
|
595 | 627 | { |
|
596 | 628 | if (sy_lfr_n_asm_p == 0) |
|
597 | 629 | { |
|
598 | 630 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p ); |
|
599 | 631 | flag = WRONG_APP_DATA; |
|
600 | 632 | } |
|
601 | 633 | } |
|
602 | 634 | // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0 |
|
603 | 635 | if (flag == LFR_SUCCESSFUL) |
|
604 | 636 | { |
|
605 | 637 | aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0); |
|
606 | 638 | if (aux > FLOAT_EQUAL_ZERO) |
|
607 | 639 | { |
|
608 | 640 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p ); |
|
609 | 641 | flag = WRONG_APP_DATA; |
|
610 | 642 | } |
|
611 | 643 | } |
|
612 | 644 | // sy_lfr_n_bp_p1 |
|
613 | 645 | if (flag == LFR_SUCCESSFUL) |
|
614 | 646 | { |
|
615 | 647 | if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1) |
|
616 | 648 | { |
|
617 | 649 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 ); |
|
618 | 650 | flag = WRONG_APP_DATA; |
|
619 | 651 | } |
|
620 | 652 | } |
|
621 | 653 | // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0 |
|
622 | 654 | if (flag == LFR_SUCCESSFUL) |
|
623 | 655 | { |
|
624 | 656 | aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0); |
|
625 | 657 | if (aux > FLOAT_EQUAL_ZERO) |
|
626 | 658 | { |
|
627 | 659 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 ); |
|
628 | 660 | flag = LFR_DEFAULT; |
|
629 | 661 | } |
|
630 | 662 | } |
|
631 | 663 | // sy_lfr_n_cwf_long_f3 |
|
632 | 664 | |
|
633 | 665 | return flag; |
|
634 | 666 | } |
|
635 | 667 | |
|
636 | 668 | int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ) |
|
637 | 669 | { |
|
638 | 670 | /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l). |
|
639 | 671 | * |
|
640 | 672 | * @param TC points to the TeleCommand packet that is being processed |
|
641 | 673 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
642 | 674 | * |
|
643 | 675 | */ |
|
644 | 676 | |
|
645 | 677 | int result; |
|
646 | 678 | |
|
647 | 679 | result = LFR_SUCCESSFUL; |
|
648 | 680 | |
|
649 | 681 | parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; |
|
650 | 682 | parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; |
|
651 | 683 | |
|
652 | 684 | return result; |
|
653 | 685 | } |
|
654 | 686 | |
|
655 | 687 | int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC ) |
|
656 | 688 | { |
|
657 | 689 | /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p). |
|
658 | 690 | * |
|
659 | 691 | * @param TC points to the TeleCommand packet that is being processed |
|
660 | 692 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
661 | 693 | * |
|
662 | 694 | */ |
|
663 | 695 | |
|
664 | 696 | int result; |
|
665 | 697 | |
|
666 | 698 | result = LFR_SUCCESSFUL; |
|
667 | 699 | |
|
668 | 700 | parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; |
|
669 | 701 | parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; |
|
670 | 702 | |
|
671 | 703 | return result; |
|
672 | 704 | } |
|
673 | 705 | |
|
674 | 706 | int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ) |
|
675 | 707 | { |
|
676 | 708 | /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P). |
|
677 | 709 | * |
|
678 | 710 | * @param TC points to the TeleCommand packet that is being processed |
|
679 | 711 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
680 | 712 | * |
|
681 | 713 | */ |
|
682 | 714 | |
|
683 | 715 | int result; |
|
684 | 716 | |
|
685 | 717 | result = LFR_SUCCESSFUL; |
|
686 | 718 | |
|
687 | 719 | parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; |
|
688 | 720 | parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; |
|
689 | 721 | |
|
690 | 722 | return result; |
|
691 | 723 | } |
|
692 | 724 | |
|
693 | 725 | int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ) |
|
694 | 726 | { |
|
695 | 727 | /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0). |
|
696 | 728 | * |
|
697 | 729 | * @param TC points to the TeleCommand packet that is being processed |
|
698 | 730 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
699 | 731 | * |
|
700 | 732 | */ |
|
701 | 733 | |
|
702 | 734 | int status; |
|
703 | 735 | |
|
704 | 736 | status = LFR_SUCCESSFUL; |
|
705 | 737 | |
|
706 | 738 | parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; |
|
707 | 739 | |
|
708 | 740 | return status; |
|
709 | 741 | } |
|
710 | 742 | |
|
711 | 743 | int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC ) |
|
712 | 744 | { |
|
713 | 745 | /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1). |
|
714 | 746 | * |
|
715 | 747 | * @param TC points to the TeleCommand packet that is being processed |
|
716 | 748 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
717 | 749 | * |
|
718 | 750 | */ |
|
719 | 751 | |
|
720 | 752 | int status; |
|
721 | 753 | |
|
722 | 754 | status = LFR_SUCCESSFUL; |
|
723 | 755 | |
|
724 | 756 | parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; |
|
725 | 757 | |
|
726 | 758 | return status; |
|
727 | 759 | } |
|
728 | 760 | |
|
729 | 761 | int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC ) |
|
730 | 762 | { |
|
731 | 763 | /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets. |
|
732 | 764 | * |
|
733 | 765 | * @param TC points to the TeleCommand packet that is being processed |
|
734 | 766 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
735 | 767 | * |
|
736 | 768 | */ |
|
737 | 769 | |
|
738 | 770 | int status; |
|
739 | 771 | |
|
740 | 772 | status = LFR_SUCCESSFUL; |
|
741 | 773 | |
|
742 | 774 | parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; |
|
743 | 775 | |
|
744 | 776 | return status; |
|
745 | 777 | } |
|
746 | 778 | |
|
747 | 779 | //********************** |
|
748 | 780 | // BURST MODE PARAMETERS |
|
749 | 781 | int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC) |
|
750 | 782 | { |
|
751 | 783 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0). |
|
752 | 784 | * |
|
753 | 785 | * @param TC points to the TeleCommand packet that is being processed |
|
754 | 786 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
755 | 787 | * |
|
756 | 788 | */ |
|
757 | 789 | |
|
758 | 790 | int status; |
|
759 | 791 | |
|
760 | 792 | status = LFR_SUCCESSFUL; |
|
761 | 793 | |
|
762 | 794 | parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; |
|
763 | 795 | |
|
764 | 796 | return status; |
|
765 | 797 | } |
|
766 | 798 | |
|
767 | 799 | int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ) |
|
768 | 800 | { |
|
769 | 801 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1). |
|
770 | 802 | * |
|
771 | 803 | * @param TC points to the TeleCommand packet that is being processed |
|
772 | 804 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
773 | 805 | * |
|
774 | 806 | */ |
|
775 | 807 | |
|
776 | 808 | int status; |
|
777 | 809 | |
|
778 | 810 | status = LFR_SUCCESSFUL; |
|
779 | 811 | |
|
780 | 812 | parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; |
|
781 | 813 | |
|
782 | 814 | return status; |
|
783 | 815 | } |
|
784 | 816 | |
|
785 | 817 | //********************* |
|
786 | 818 | // SBM1 MODE PARAMETERS |
|
787 | 819 | int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ) |
|
788 | 820 | { |
|
789 | 821 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0). |
|
790 | 822 | * |
|
791 | 823 | * @param TC points to the TeleCommand packet that is being processed |
|
792 | 824 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
793 | 825 | * |
|
794 | 826 | */ |
|
795 | 827 | |
|
796 | 828 | int status; |
|
797 | 829 | |
|
798 | 830 | status = LFR_SUCCESSFUL; |
|
799 | 831 | |
|
800 | 832 | parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; |
|
801 | 833 | |
|
802 | 834 | return status; |
|
803 | 835 | } |
|
804 | 836 | |
|
805 | 837 | int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ) |
|
806 | 838 | { |
|
807 | 839 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1). |
|
808 | 840 | * |
|
809 | 841 | * @param TC points to the TeleCommand packet that is being processed |
|
810 | 842 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
811 | 843 | * |
|
812 | 844 | */ |
|
813 | 845 | |
|
814 | 846 | int status; |
|
815 | 847 | |
|
816 | 848 | status = LFR_SUCCESSFUL; |
|
817 | 849 | |
|
818 | 850 | parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; |
|
819 | 851 | |
|
820 | 852 | return status; |
|
821 | 853 | } |
|
822 | 854 | |
|
823 | 855 | //********************* |
|
824 | 856 | // SBM2 MODE PARAMETERS |
|
825 | 857 | int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC ) |
|
826 | 858 | { |
|
827 | 859 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0). |
|
828 | 860 | * |
|
829 | 861 | * @param TC points to the TeleCommand packet that is being processed |
|
830 | 862 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
831 | 863 | * |
|
832 | 864 | */ |
|
833 | 865 | |
|
834 | 866 | int status; |
|
835 | 867 | |
|
836 | 868 | status = LFR_SUCCESSFUL; |
|
837 | 869 | |
|
838 | 870 | parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; |
|
839 | 871 | |
|
840 | 872 | return status; |
|
841 | 873 | } |
|
842 | 874 | |
|
843 | 875 | int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ) |
|
844 | 876 | { |
|
845 | 877 | /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1). |
|
846 | 878 | * |
|
847 | 879 | * @param TC points to the TeleCommand packet that is being processed |
|
848 | 880 | * @param queue_id is the id of the queue which handles TM related to this execution step |
|
849 | 881 | * |
|
850 | 882 | */ |
|
851 | 883 | |
|
852 | 884 | int status; |
|
853 | 885 | |
|
854 | 886 | status = LFR_SUCCESSFUL; |
|
855 | 887 | |
|
856 | 888 | parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; |
|
857 | 889 | |
|
858 | 890 | return status; |
|
859 | 891 | } |
|
860 | 892 | |
|
861 | 893 | //******************* |
|
862 | 894 | // TC_LFR_UPDATE_INFO |
|
863 | 895 | unsigned int check_update_info_hk_lfr_mode( unsigned char mode ) |
|
864 | 896 | { |
|
865 | 897 | unsigned int status; |
|
866 | 898 | |
|
867 | 899 | if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL) |
|
868 | 900 | || (mode == LFR_MODE_BURST) |
|
869 | 901 | || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2)) |
|
870 | 902 | { |
|
871 | 903 | status = LFR_SUCCESSFUL; |
|
872 | 904 | } |
|
873 | 905 | else |
|
874 | 906 | { |
|
875 | 907 | status = LFR_DEFAULT; |
|
876 | 908 | } |
|
877 | 909 | |
|
878 | 910 | return status; |
|
879 | 911 | } |
|
880 | 912 | |
|
881 | 913 | unsigned int check_update_info_hk_tds_mode( unsigned char mode ) |
|
882 | 914 | { |
|
883 | 915 | unsigned int status; |
|
884 | 916 | |
|
885 | 917 | if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL) |
|
886 | 918 | || (mode == TDS_MODE_BURST) |
|
887 | 919 | || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2) |
|
888 | 920 | || (mode == TDS_MODE_LFM)) |
|
889 | 921 | { |
|
890 | 922 | status = LFR_SUCCESSFUL; |
|
891 | 923 | } |
|
892 | 924 | else |
|
893 | 925 | { |
|
894 | 926 | status = LFR_DEFAULT; |
|
895 | 927 | } |
|
896 | 928 | |
|
897 | 929 | return status; |
|
898 | 930 | } |
|
899 | 931 | |
|
900 | 932 | unsigned int check_update_info_hk_thr_mode( unsigned char mode ) |
|
901 | 933 | { |
|
902 | 934 | unsigned int status; |
|
903 | 935 | |
|
904 | 936 | if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL) |
|
905 | 937 | || (mode == THR_MODE_BURST)) |
|
906 | 938 | { |
|
907 | 939 | status = LFR_SUCCESSFUL; |
|
908 | 940 | } |
|
909 | 941 | else |
|
910 | 942 | { |
|
911 | 943 | status = LFR_DEFAULT; |
|
912 | 944 | } |
|
913 | 945 | |
|
914 | 946 | return status; |
|
915 | 947 | } |
|
916 | 948 | |
|
949 | void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value ) | |
|
950 | { | |
|
951 | unsigned char flag; | |
|
952 | unsigned char flagPosInByte; | |
|
953 | unsigned char newFlag; | |
|
954 | unsigned char flagMask; | |
|
955 | ||
|
956 | // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered | |
|
957 | if (isnan(value)) | |
|
958 | { | |
|
959 | flag = 0; | |
|
960 | } | |
|
961 | else | |
|
962 | { | |
|
963 | flag = 1; | |
|
964 | } | |
|
965 | ||
|
966 | switch(wheel) | |
|
967 | { | |
|
968 | case 1: | |
|
969 | flagPosInByte = 8 - freq; | |
|
970 | flagMask = ~(1 << flagPosInByte); | |
|
971 | newFlag = flag << flagPosInByte; | |
|
972 | housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag; | |
|
973 | break; | |
|
974 | case 2: | |
|
975 | flagPosInByte = 4 - freq; | |
|
976 | flagMask = ~(1 << flagPosInByte); | |
|
977 | newFlag = flag << flagPosInByte; | |
|
978 | housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag; | |
|
979 | break; | |
|
980 | case 3: | |
|
981 | flagPosInByte = 8 - freq; | |
|
982 | flagMask = ~(1 << flagPosInByte); | |
|
983 | newFlag = flag << flagPosInByte; | |
|
984 | housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag; | |
|
985 | break; | |
|
986 | case 4: | |
|
987 | flagPosInByte = 4 - freq; | |
|
988 | flagMask = ~(1 << flagPosInByte); | |
|
989 | newFlag = flag << flagPosInByte; | |
|
990 | housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag; | |
|
991 | break; | |
|
992 | default: | |
|
993 | break; | |
|
994 | } | |
|
995 | } | |
|
996 | ||
|
997 | void set_hk_lfr_sc_rw_f_flags( void ) | |
|
998 | { | |
|
999 | // RW1 | |
|
1000 | set_hk_lfr_sc_rw_f_flag( 1, 1, rw_f.cp_rpw_sc_rw1_f1 ); | |
|
1001 | set_hk_lfr_sc_rw_f_flag( 1, 2, rw_f.cp_rpw_sc_rw1_f2 ); | |
|
1002 | set_hk_lfr_sc_rw_f_flag( 1, 3, rw_f.cp_rpw_sc_rw1_f3 ); | |
|
1003 | set_hk_lfr_sc_rw_f_flag( 1, 4, rw_f.cp_rpw_sc_rw1_f4 ); | |
|
1004 | ||
|
1005 | // RW2 | |
|
1006 | set_hk_lfr_sc_rw_f_flag( 2, 1, rw_f.cp_rpw_sc_rw2_f1 ); | |
|
1007 | set_hk_lfr_sc_rw_f_flag( 2, 2, rw_f.cp_rpw_sc_rw2_f2 ); | |
|
1008 | set_hk_lfr_sc_rw_f_flag( 2, 3, rw_f.cp_rpw_sc_rw2_f3 ); | |
|
1009 | set_hk_lfr_sc_rw_f_flag( 2, 4, rw_f.cp_rpw_sc_rw2_f4 ); | |
|
1010 | ||
|
1011 | // RW3 | |
|
1012 | set_hk_lfr_sc_rw_f_flag( 3, 1, rw_f.cp_rpw_sc_rw3_f1 ); | |
|
1013 | set_hk_lfr_sc_rw_f_flag( 3, 2, rw_f.cp_rpw_sc_rw3_f2 ); | |
|
1014 | set_hk_lfr_sc_rw_f_flag( 3, 3, rw_f.cp_rpw_sc_rw3_f3 ); | |
|
1015 | set_hk_lfr_sc_rw_f_flag( 3, 4, rw_f.cp_rpw_sc_rw3_f4 ); | |
|
1016 | ||
|
1017 | // RW4 | |
|
1018 | set_hk_lfr_sc_rw_f_flag( 4, 1, rw_f.cp_rpw_sc_rw4_f1 ); | |
|
1019 | set_hk_lfr_sc_rw_f_flag( 4, 2, rw_f.cp_rpw_sc_rw4_f2 ); | |
|
1020 | set_hk_lfr_sc_rw_f_flag( 4, 3, rw_f.cp_rpw_sc_rw4_f3 ); | |
|
1021 | set_hk_lfr_sc_rw_f_flag( 4, 4, rw_f.cp_rpw_sc_rw4_f4 ); | |
|
1022 | } | |
|
1023 | ||
|
917 | 1024 | void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC ) |
|
918 | 1025 | { |
|
919 | 1026 | /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally. |
|
920 | 1027 | * |
|
921 | 1028 | * @param TC points to the TeleCommand packet that is being processed |
|
922 | 1029 | * |
|
923 | 1030 | */ |
|
924 | 1031 | |
|
925 | 1032 | unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet |
|
926 | 1033 | |
|
927 | 1034 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
928 | 1035 | |
|
929 |
// |
|
|
930 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1, | |
|
931 |
|
|
|
932 | ||
|
933 | // cp_rpw_sc_rw1_f2 | |
|
934 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2, | |
|
935 | (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] ); | |
|
1036 | // rw1_f | |
|
1037 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] ); | |
|
1038 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] ); | |
|
1039 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] ); | |
|
1040 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] ); | |
|
936 | 1041 | |
|
937 |
// |
|
|
938 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1, | |
|
939 |
|
|
|
940 | ||
|
941 | // cp_rpw_sc_rw2_f2 | |
|
942 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2, | |
|
943 | (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] ); | |
|
1042 | // rw2_f | |
|
1043 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] ); | |
|
1044 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] ); | |
|
1045 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] ); | |
|
1046 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] ); | |
|
944 | 1047 | |
|
945 |
// |
|
|
946 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1, | |
|
947 |
|
|
|
948 | ||
|
949 | // cp_rpw_sc_rw3_f2 | |
|
950 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2, | |
|
951 | (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] ); | |
|
1048 | // rw3_f | |
|
1049 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] ); | |
|
1050 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] ); | |
|
1051 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] ); | |
|
1052 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] ); | |
|
952 | 1053 | |
|
953 |
// |
|
|
954 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1, | |
|
955 |
|
|
|
1054 | // rw4_f | |
|
1055 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] ); | |
|
1056 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] ); | |
|
1057 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] ); | |
|
1058 | copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] ); | |
|
956 | 1059 | |
|
957 | // cp_rpw_sc_rw4_f2 | |
|
958 | copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2, | |
|
959 | (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] ); | |
|
1060 | // test each reaction wheel frequency value. NaN means that the frequency is not filtered | |
|
1061 | ||
|
1062 | ||
|
960 | 1063 | } |
|
961 | 1064 | |
|
962 | 1065 | void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag ) |
|
963 | 1066 | { |
|
964 | 1067 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
965 | 1068 | * |
|
966 | 1069 | * @param fbins_mask |
|
967 | 1070 | * @param rw_f is the reaction wheel frequency to filter |
|
968 | 1071 | * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel |
|
969 | 1072 | * @param flag [true] filtering enabled [false] filtering disabled |
|
970 | 1073 | * |
|
971 | 1074 | * @return void |
|
972 | 1075 | * |
|
973 | 1076 | */ |
|
974 | 1077 | |
|
975 | 1078 | float f_RW_min; |
|
976 | 1079 | float f_RW_MAX; |
|
977 | 1080 | float fi_min; |
|
978 | 1081 | float fi_MAX; |
|
979 | 1082 | float fi; |
|
980 | 1083 | float deltaBelow; |
|
981 | 1084 | float deltaAbove; |
|
982 | 1085 | int binBelow; |
|
983 | 1086 | int binAbove; |
|
984 | 1087 | int closestBin; |
|
985 | 1088 | unsigned int whichByte; |
|
986 | 1089 | int selectedByte; |
|
987 | 1090 | int bin; |
|
988 | 1091 | int binToRemove[3]; |
|
989 | 1092 | int k; |
|
990 | 1093 | |
|
991 | 1094 | whichByte = 0; |
|
992 | 1095 | bin = 0; |
|
993 | 1096 | |
|
994 | 1097 | binToRemove[0] = -1; |
|
995 | 1098 | binToRemove[1] = -1; |
|
996 | 1099 | binToRemove[2] = -1; |
|
997 | 1100 | |
|
998 | 1101 | // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ] |
|
999 | 1102 | f_RW_min = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.; |
|
1000 | 1103 | f_RW_MAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.; |
|
1001 | 1104 | |
|
1002 | 1105 | // compute the index of the frequency bin immediately below rw_f |
|
1003 | 1106 | binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) ); |
|
1004 | 1107 | deltaBelow = rw_f - binBelow * deltaFreq; |
|
1005 | 1108 | |
|
1006 | 1109 | // compute the index of the frequency bin immediately above rw_f |
|
1007 | 1110 | binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) ); |
|
1008 | 1111 | deltaAbove = binAbove * deltaFreq - rw_f; |
|
1009 | 1112 | |
|
1010 | 1113 | // search the closest bin |
|
1011 | 1114 | if (deltaAbove > deltaBelow) |
|
1012 | 1115 | { |
|
1013 | 1116 | closestBin = binBelow; |
|
1014 | 1117 | } |
|
1015 | 1118 | else |
|
1016 | 1119 | { |
|
1017 | 1120 | closestBin = binAbove; |
|
1018 | 1121 | } |
|
1019 | 1122 | |
|
1020 | 1123 | // compute the fi interval [fi - Delta_f * 0.285, fi + Delta_f * 0.285] |
|
1021 | 1124 | fi = closestBin * deltaFreq; |
|
1022 | 1125 | |
|
1023 | 1126 | fi_min = fi - (deltaFreq * 0.285); |
|
1024 | 1127 | if ( fi_min < 0 ) |
|
1025 | 1128 | { |
|
1026 | 1129 | fi_min = 0; |
|
1027 | 1130 | } |
|
1028 | 1131 | else if ( fi_min > (deltaFreq*127) ) |
|
1029 | 1132 | { |
|
1030 | 1133 | fi_min = -1; |
|
1031 | 1134 | } |
|
1032 | 1135 | |
|
1033 | 1136 | fi_MAX = fi + (deltaFreq * 0.285); |
|
1034 | 1137 | if ( fi_MAX > (deltaFreq*127) ) |
|
1035 | 1138 | { |
|
1036 | 1139 | fi_MAX = -1; |
|
1037 | 1140 | } |
|
1038 | 1141 | |
|
1039 | 1142 | // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ] |
|
1040 | 1143 | // => remove f_(i), f_(i-1) and f_(i+1) |
|
1041 | 1144 | if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) ) |
|
1042 | 1145 | { |
|
1043 | 1146 | binToRemove[0] = closestBin - 1; |
|
1044 | 1147 | binToRemove[1] = closestBin; |
|
1045 | 1148 | binToRemove[2] = closestBin + 1; |
|
1046 | 1149 | } |
|
1047 | 1150 | // 2. ELSE |
|
1048 | 1151 | // => remove the two f_(i) which are around f_RW |
|
1049 | 1152 | else |
|
1050 | 1153 | { |
|
1051 | 1154 | binToRemove[0] = binBelow; |
|
1052 | 1155 | binToRemove[1] = binAbove; |
|
1053 | 1156 | binToRemove[2] = -1; |
|
1054 | 1157 | } |
|
1055 | 1158 | |
|
1056 | 1159 | for (k = 0; k <= 3; k++) |
|
1057 | 1160 | { |
|
1058 | 1161 | bin = binToRemove[k]; |
|
1059 | 1162 | if ( (bin >= 0) && (bin <= 127) ) |
|
1060 | 1163 | { |
|
1061 | 1164 | if (flag == 1) |
|
1062 | 1165 | { |
|
1063 | 1166 | whichByte = (bin >> 3); // division by 8 |
|
1064 | 1167 | selectedByte = ( 1 << (bin - (whichByte * 8)) ); |
|
1065 | 1168 | fbins_mask[15 - whichByte] = fbins_mask[15 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets |
|
1066 | 1169 | } |
|
1067 | 1170 | } |
|
1068 | 1171 | } |
|
1069 | 1172 | } |
|
1070 | 1173 | |
|
1071 | 1174 | void build_sy_lfr_rw_mask( unsigned int channel ) |
|
1072 | 1175 | { |
|
1073 | 1176 | unsigned char local_rw_fbins_mask[16]; |
|
1074 | 1177 | unsigned char *maskPtr; |
|
1075 | 1178 | double deltaF; |
|
1076 | 1179 | unsigned k; |
|
1077 | 1180 | |
|
1078 | 1181 | k = 0; |
|
1079 | 1182 | |
|
1080 | 1183 | maskPtr = NULL; |
|
1081 | 1184 | deltaF = 1.; |
|
1082 | 1185 | |
|
1083 | 1186 | switch (channel) |
|
1084 | 1187 | { |
|
1085 | 1188 | case 0: |
|
1086 | 1189 | maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1; |
|
1087 | 1190 | deltaF = 96.; |
|
1088 | 1191 | break; |
|
1089 | 1192 | case 1: |
|
1090 | 1193 | maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1; |
|
1091 | 1194 | deltaF = 16.; |
|
1092 | 1195 | break; |
|
1093 | 1196 | case 2: |
|
1094 | 1197 | maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1; |
|
1095 | 1198 | deltaF = 1.; |
|
1096 | 1199 | break; |
|
1097 | 1200 | default: |
|
1098 | 1201 | break; |
|
1099 | 1202 | } |
|
1100 | 1203 | |
|
1101 | 1204 | for (k = 0; k < 16; k++) |
|
1102 | 1205 | { |
|
1103 | 1206 | local_rw_fbins_mask[k] = 0xff; |
|
1104 | 1207 | } |
|
1105 | 1208 | |
|
1106 |
// RW1 |
|
|
1107 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); |
|
|
1108 | ||
|
1109 | // RW1 F2 | |
|
1110 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x |
|
|
1209 | // RW1 | |
|
1210 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x80) >> 7 ); // [1000 0000] | |
|
1211 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x40) >> 6 ); // [0100 0000] | |
|
1212 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x20) >> 5 ); // [0010 0000] | |
|
1213 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x10) >> 4 ); // [0001 0000] | |
|
1111 | 1214 | |
|
1112 |
// RW2 |
|
|
1113 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x |
|
|
1114 | ||
|
1115 | // RW2 F2 | |
|
1116 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x |
|
|
1215 | // RW2 | |
|
1216 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x08) >> 3 ); // [0000 1000] | |
|
1217 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x04) >> 2 ); // [0000 0100] | |
|
1218 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x02) >> 1 ); // [0000 0010] | |
|
1219 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw1_rw2_f_flags & 0x01) ); // [0000 0001] | |
|
1117 | 1220 | |
|
1118 |
// RW3 |
|
|
1119 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x |
|
|
1120 | ||
|
1121 | // RW3 F2 | |
|
1122 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x0 |
|
|
1221 | // RW3 | |
|
1222 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x80) >> 7 ); // [1000 0000] | |
|
1223 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x40) >> 6 ); // [0100 0000] | |
|
1224 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x20) >> 5 ); // [0010 0000] | |
|
1225 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x10) >> 4 ); // [0001 0000] | |
|
1123 | 1226 | |
|
1124 |
// RW4 |
|
|
1125 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x0 |
|
|
1126 | ||
|
1127 | // RW4 F2 | |
|
1128 |
setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x0 |
|
|
1227 | // RW4 | |
|
1228 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x08) >> 3 ); // [0000 1000] | |
|
1229 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x04) >> 2 ); // [0000 0100] | |
|
1230 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x02) >> 1 ); // [0000 0010] | |
|
1231 | setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw3_rw4_f_flags & 0x03) ); // [0000 0001] | |
|
1129 | 1232 | |
|
1130 | 1233 | // update the value of the fbins related to reaction wheels frequency filtering |
|
1131 | 1234 | if (maskPtr != NULL) |
|
1132 | 1235 | { |
|
1133 | 1236 | for (k = 0; k < 16; k++) |
|
1134 | 1237 | { |
|
1135 | 1238 | maskPtr[k] = local_rw_fbins_mask[k]; |
|
1136 | 1239 | } |
|
1137 | 1240 | } |
|
1138 | 1241 | } |
|
1139 | 1242 | |
|
1140 | 1243 | void build_sy_lfr_rw_masks( void ) |
|
1141 | 1244 | { |
|
1142 | 1245 | build_sy_lfr_rw_mask( 0 ); |
|
1143 | 1246 | build_sy_lfr_rw_mask( 1 ); |
|
1144 | 1247 | build_sy_lfr_rw_mask( 2 ); |
|
1145 | 1248 | |
|
1146 | 1249 | merge_fbins_masks(); |
|
1147 | 1250 | } |
|
1148 | 1251 | |
|
1149 | 1252 | void merge_fbins_masks( void ) |
|
1150 | 1253 | { |
|
1151 | 1254 | unsigned char k; |
|
1152 | 1255 | |
|
1153 | 1256 | unsigned char *fbins_f0; |
|
1154 | 1257 | unsigned char *fbins_f1; |
|
1155 | 1258 | unsigned char *fbins_f2; |
|
1156 | 1259 | unsigned char *rw_mask_f0; |
|
1157 | 1260 | unsigned char *rw_mask_f1; |
|
1158 | 1261 | unsigned char *rw_mask_f2; |
|
1159 | 1262 | |
|
1160 | 1263 | fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1; |
|
1161 | 1264 | fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1; |
|
1162 | 1265 | fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1; |
|
1163 | 1266 | rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1; |
|
1164 | 1267 | rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1; |
|
1165 | 1268 | rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1; |
|
1166 | 1269 | |
|
1167 | 1270 | for( k=0; k < 16; k++ ) |
|
1168 | 1271 | { |
|
1169 | 1272 | fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k]; |
|
1170 | 1273 | fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k]; |
|
1171 | 1274 | fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k]; |
|
1172 | 1275 | } |
|
1173 | 1276 | } |
|
1174 | 1277 | |
|
1175 | 1278 | //*********** |
|
1176 | 1279 | // FBINS MASK |
|
1177 | 1280 | |
|
1178 | 1281 | int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC ) |
|
1179 | 1282 | { |
|
1180 | 1283 | int status; |
|
1181 | 1284 | unsigned int k; |
|
1182 | 1285 | unsigned char *fbins_mask_dump; |
|
1183 | 1286 | unsigned char *fbins_mask_TC; |
|
1184 | 1287 | |
|
1185 | 1288 | status = LFR_SUCCESSFUL; |
|
1186 | 1289 | |
|
1187 | 1290 | fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1; |
|
1188 | 1291 | fbins_mask_TC = TC->dataAndCRC; |
|
1189 | 1292 | |
|
1190 | 1293 | for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++) |
|
1191 | 1294 | { |
|
1192 | 1295 | fbins_mask_dump[k] = fbins_mask_TC[k]; |
|
1193 | 1296 | } |
|
1194 | 1297 | |
|
1195 | 1298 | return status; |
|
1196 | 1299 | } |
|
1197 | 1300 | |
|
1198 | 1301 | //*************************** |
|
1199 | 1302 | // TC_LFR_LOAD_PAS_FILTER_PAR |
|
1200 | 1303 | |
|
1201 | 1304 | int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
1202 | 1305 | { |
|
1203 | 1306 | int flag; |
|
1204 | 1307 | rtems_status_code status; |
|
1205 | 1308 | |
|
1206 | 1309 | unsigned char sy_lfr_pas_filter_enabled; |
|
1207 | 1310 | unsigned char sy_lfr_pas_filter_modulus; |
|
1208 | 1311 | float sy_lfr_pas_filter_tbad; |
|
1209 | 1312 | unsigned char sy_lfr_pas_filter_offset; |
|
1210 | 1313 | float sy_lfr_pas_filter_shift; |
|
1211 | 1314 | float sy_lfr_sc_rw_delta_f; |
|
1212 | 1315 | char *parPtr; |
|
1213 | 1316 | |
|
1214 | 1317 | flag = LFR_SUCCESSFUL; |
|
1215 | 1318 | sy_lfr_pas_filter_tbad = 0.0; |
|
1216 | 1319 | sy_lfr_pas_filter_shift = 0.0; |
|
1217 | 1320 | sy_lfr_sc_rw_delta_f = 0.0; |
|
1218 | 1321 | parPtr = NULL; |
|
1219 | 1322 | |
|
1220 | 1323 | //*************** |
|
1221 | 1324 | // get parameters |
|
1222 | 1325 | sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001] |
|
1223 | 1326 | sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ]; |
|
1224 | 1327 | copyFloatByChar( |
|
1225 | 1328 | (unsigned char*) &sy_lfr_pas_filter_tbad, |
|
1226 | 1329 | (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ] |
|
1227 | 1330 | ); |
|
1228 | 1331 | sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ]; |
|
1229 | 1332 | copyFloatByChar( |
|
1230 | 1333 | (unsigned char*) &sy_lfr_pas_filter_shift, |
|
1231 | 1334 | (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ] |
|
1232 | 1335 | ); |
|
1233 | 1336 | copyFloatByChar( |
|
1234 | 1337 | (unsigned char*) &sy_lfr_sc_rw_delta_f, |
|
1235 | 1338 | (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ] |
|
1236 | 1339 | ); |
|
1237 | 1340 | |
|
1238 | 1341 | //****************** |
|
1239 | 1342 | // CHECK CONSISTENCY |
|
1240 | 1343 | |
|
1241 | 1344 | //************************** |
|
1242 | 1345 | // sy_lfr_pas_filter_enabled |
|
1243 | 1346 | // nothing to check, value is 0 or 1 |
|
1244 | 1347 | |
|
1245 | 1348 | //************************** |
|
1246 | 1349 | // sy_lfr_pas_filter_modulus |
|
1247 | 1350 | if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) ) |
|
1248 | 1351 | { |
|
1249 | 1352 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus ); |
|
1250 | 1353 | flag = WRONG_APP_DATA; |
|
1251 | 1354 | } |
|
1252 | 1355 | |
|
1253 | 1356 | //*********************** |
|
1254 | 1357 | // sy_lfr_pas_filter_tbad |
|
1255 | 1358 | if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) ) |
|
1256 | 1359 | { |
|
1257 | 1360 | parPtr = (char*) &sy_lfr_pas_filter_tbad; |
|
1258 | 1361 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] ); |
|
1259 | 1362 | flag = WRONG_APP_DATA; |
|
1260 | 1363 | } |
|
1261 | 1364 | |
|
1262 | 1365 | //************************* |
|
1263 | 1366 | // sy_lfr_pas_filter_offset |
|
1264 | 1367 | if (flag == LFR_SUCCESSFUL) |
|
1265 | 1368 | { |
|
1266 | 1369 | if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) ) |
|
1267 | 1370 | { |
|
1268 | 1371 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset ); |
|
1269 | 1372 | flag = WRONG_APP_DATA; |
|
1270 | 1373 | } |
|
1271 | 1374 | } |
|
1272 | 1375 | |
|
1273 | 1376 | //************************ |
|
1274 | 1377 | // sy_lfr_pas_filter_shift |
|
1275 | 1378 | if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) ) |
|
1276 | 1379 | { |
|
1277 | 1380 | parPtr = (char*) &sy_lfr_pas_filter_shift; |
|
1278 | 1381 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] ); |
|
1279 | 1382 | flag = WRONG_APP_DATA; |
|
1280 | 1383 | } |
|
1281 | 1384 | |
|
1282 | 1385 | //********************* |
|
1283 | 1386 | // sy_lfr_sc_rw_delta_f |
|
1284 | 1387 | // nothing to check, no default value in the ICD |
|
1285 | 1388 | |
|
1286 | 1389 | return flag; |
|
1287 | 1390 | } |
|
1288 | 1391 | |
|
1289 | 1392 | //************** |
|
1290 | 1393 | // KCOEFFICIENTS |
|
1291 | 1394 | int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id ) |
|
1292 | 1395 | { |
|
1293 | 1396 | unsigned int kcoeff; |
|
1294 | 1397 | unsigned short sy_lfr_kcoeff_frequency; |
|
1295 | 1398 | unsigned short bin; |
|
1296 | 1399 | unsigned short *freqPtr; |
|
1297 | 1400 | float *kcoeffPtr_norm; |
|
1298 | 1401 | float *kcoeffPtr_sbm; |
|
1299 | 1402 | int status; |
|
1300 | 1403 | unsigned char *kcoeffLoadPtr; |
|
1301 | 1404 | unsigned char *kcoeffNormPtr; |
|
1302 | 1405 | unsigned char *kcoeffSbmPtr_a; |
|
1303 | 1406 | unsigned char *kcoeffSbmPtr_b; |
|
1304 | 1407 | |
|
1305 | 1408 | status = LFR_SUCCESSFUL; |
|
1306 | 1409 | |
|
1307 | 1410 | kcoeffPtr_norm = NULL; |
|
1308 | 1411 | kcoeffPtr_sbm = NULL; |
|
1309 | 1412 | bin = 0; |
|
1310 | 1413 | |
|
1311 | 1414 | freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY]; |
|
1312 | 1415 | sy_lfr_kcoeff_frequency = *freqPtr; |
|
1313 | 1416 | |
|
1314 | 1417 | if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM ) |
|
1315 | 1418 | { |
|
1316 | 1419 | PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency) |
|
1317 | 1420 | status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1, |
|
1318 | 1421 | TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB |
|
1319 | 1422 | status = LFR_DEFAULT; |
|
1320 | 1423 | } |
|
1321 | 1424 | else |
|
1322 | 1425 | { |
|
1323 | 1426 | if ( ( sy_lfr_kcoeff_frequency >= 0 ) |
|
1324 | 1427 | && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) ) |
|
1325 | 1428 | { |
|
1326 | 1429 | kcoeffPtr_norm = k_coeff_intercalib_f0_norm; |
|
1327 | 1430 | kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm; |
|
1328 | 1431 | bin = sy_lfr_kcoeff_frequency; |
|
1329 | 1432 | } |
|
1330 | 1433 | else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 ) |
|
1331 | 1434 | && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) ) |
|
1332 | 1435 | { |
|
1333 | 1436 | kcoeffPtr_norm = k_coeff_intercalib_f1_norm; |
|
1334 | 1437 | kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm; |
|
1335 | 1438 | bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0; |
|
1336 | 1439 | } |
|
1337 | 1440 | else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) |
|
1338 | 1441 | && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) ) |
|
1339 | 1442 | { |
|
1340 | 1443 | kcoeffPtr_norm = k_coeff_intercalib_f2; |
|
1341 | 1444 | kcoeffPtr_sbm = NULL; |
|
1342 | 1445 | bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1); |
|
1343 | 1446 | } |
|
1344 | 1447 | } |
|
1345 | 1448 | |
|
1346 | 1449 | if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products |
|
1347 | 1450 | { |
|
1348 | 1451 | for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++) |
|
1349 | 1452 | { |
|
1350 | 1453 | // destination |
|
1351 | 1454 | kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ]; |
|
1352 | 1455 | // source |
|
1353 | 1456 | kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff]; |
|
1354 | 1457 | // copy source to destination |
|
1355 | 1458 | copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr ); |
|
1356 | 1459 | } |
|
1357 | 1460 | } |
|
1358 | 1461 | |
|
1359 | 1462 | if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products |
|
1360 | 1463 | { |
|
1361 | 1464 | for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++) |
|
1362 | 1465 | { |
|
1363 | 1466 | // destination |
|
1364 | 1467 | kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ]; |
|
1365 | 1468 | kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ]; |
|
1366 | 1469 | // source |
|
1367 | 1470 | kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff]; |
|
1368 | 1471 | // copy source to destination |
|
1369 | 1472 | copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr ); |
|
1370 | 1473 | copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr ); |
|
1371 | 1474 | } |
|
1372 | 1475 | } |
|
1373 | 1476 | |
|
1374 | 1477 | // print_k_coeff(); |
|
1375 | 1478 | |
|
1376 | 1479 | return status; |
|
1377 | 1480 | } |
|
1378 | 1481 | |
|
1379 | 1482 | void copyFloatByChar( unsigned char *destination, unsigned char *source ) |
|
1380 | 1483 | { |
|
1381 | 1484 | destination[0] = source[0]; |
|
1382 | 1485 | destination[1] = source[1]; |
|
1383 | 1486 | destination[2] = source[2]; |
|
1384 | 1487 | destination[3] = source[3]; |
|
1385 | 1488 | } |
|
1386 | 1489 | |
|
1387 | 1490 | void floatToChar( float value, unsigned char* ptr) |
|
1388 | 1491 | { |
|
1389 | 1492 | unsigned char* valuePtr; |
|
1390 | 1493 | |
|
1391 | 1494 | valuePtr = (unsigned char*) &value; |
|
1392 | 1495 | ptr[0] = valuePtr[0]; |
|
1393 | 1496 | ptr[1] = valuePtr[0]; |
|
1394 | 1497 | ptr[2] = valuePtr[0]; |
|
1395 | 1498 | ptr[3] = valuePtr[0]; |
|
1396 | 1499 | } |
|
1397 | 1500 | |
|
1398 | 1501 | //********** |
|
1399 | 1502 | // init dump |
|
1400 | 1503 | |
|
1401 | 1504 | void init_parameter_dump( void ) |
|
1402 | 1505 | { |
|
1403 | 1506 | /** This function initialize the parameter_dump_packet global variable with default values. |
|
1404 | 1507 | * |
|
1405 | 1508 | */ |
|
1406 | 1509 | |
|
1407 | 1510 | unsigned int k; |
|
1408 | 1511 | |
|
1409 | 1512 | parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1410 | 1513 | parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1411 | 1514 | parameter_dump_packet.reserved = CCSDS_RESERVED; |
|
1412 | 1515 | parameter_dump_packet.userApplication = CCSDS_USER_APP; |
|
1413 | 1516 | parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8); |
|
1414 | 1517 | parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP; |
|
1415 | 1518 | parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1416 | 1519 | parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1417 | 1520 | parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8); |
|
1418 | 1521 | parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP; |
|
1419 | 1522 | // DATA FIELD HEADER |
|
1420 | 1523 | parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2; |
|
1421 | 1524 | parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP; |
|
1422 | 1525 | parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP; |
|
1423 | 1526 | parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
1424 | 1527 | parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
1425 | 1528 | parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
1426 | 1529 | parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
1427 | 1530 | parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
1428 | 1531 | parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
1429 | 1532 | parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
1430 | 1533 | parameter_dump_packet.sid = SID_PARAMETER_DUMP; |
|
1431 | 1534 | |
|
1432 | 1535 | //****************** |
|
1433 | 1536 | // COMMON PARAMETERS |
|
1434 | 1537 | parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0; |
|
1435 | 1538 | parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1; |
|
1436 | 1539 | |
|
1437 | 1540 | //****************** |
|
1438 | 1541 | // NORMAL PARAMETERS |
|
1439 | 1542 | parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8); |
|
1440 | 1543 | parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L ); |
|
1441 | 1544 | parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8); |
|
1442 | 1545 | parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P ); |
|
1443 | 1546 | parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8); |
|
1444 | 1547 | parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P ); |
|
1445 | 1548 | parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0; |
|
1446 | 1549 | parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1; |
|
1447 | 1550 | parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3; |
|
1448 | 1551 | |
|
1449 | 1552 | //***************** |
|
1450 | 1553 | // BURST PARAMETERS |
|
1451 | 1554 | parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0; |
|
1452 | 1555 | parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1; |
|
1453 | 1556 | |
|
1454 | 1557 | //**************** |
|
1455 | 1558 | // SBM1 PARAMETERS |
|
1456 | 1559 | 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 |
|
1457 | 1560 | parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1; |
|
1458 | 1561 | |
|
1459 | 1562 | //**************** |
|
1460 | 1563 | // SBM2 PARAMETERS |
|
1461 | 1564 | parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0; |
|
1462 | 1565 | parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1; |
|
1463 | 1566 | |
|
1464 | 1567 | //************ |
|
1465 | 1568 | // FBINS MASKS |
|
1466 | 1569 | for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++) |
|
1467 | 1570 | { |
|
1468 | 1571 | parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff; |
|
1469 | 1572 | } |
|
1470 | 1573 | |
|
1471 | // PAS FILTER PARAMETERS | |
|
1574 | //****************** | |
|
1575 | // FILTER PARAMETERS | |
|
1472 | 1576 | parameter_dump_packet.pa_rpw_spare8_2 = 0x00; |
|
1473 | 1577 | parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00; |
|
1474 | 1578 | parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS; |
|
1475 | 1579 | floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad ); |
|
1476 | 1580 | parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET; |
|
1477 | 1581 | floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift ); |
|
1478 | 1582 | floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f ); |
|
1479 | 1583 | |
|
1584 | // RW1_K | |
|
1585 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1); | |
|
1586 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2); | |
|
1587 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3); | |
|
1588 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4); | |
|
1589 | // RW2_K | |
|
1590 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1); | |
|
1591 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2); | |
|
1592 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3); | |
|
1593 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4); | |
|
1594 | // RW3_K | |
|
1595 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1); | |
|
1596 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2); | |
|
1597 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3); | |
|
1598 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4); | |
|
1599 | // RW4_K | |
|
1600 | floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1); | |
|
1601 | floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2); | |
|
1602 | floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3); | |
|
1603 | floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4); | |
|
1604 | ||
|
1480 | 1605 | // LFR_RW_MASK |
|
1481 | 1606 | for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++) |
|
1482 | 1607 | { |
|
1483 | 1608 | parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff; |
|
1484 | 1609 | } |
|
1485 | 1610 | } |
|
1486 | 1611 | |
|
1487 | 1612 | void init_kcoefficients_dump( void ) |
|
1488 | 1613 | { |
|
1489 | 1614 | init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 ); |
|
1490 | 1615 | init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 ); |
|
1491 | 1616 | |
|
1492 | 1617 | kcoefficient_node_1.previous = NULL; |
|
1493 | 1618 | kcoefficient_node_1.next = NULL; |
|
1494 | 1619 | kcoefficient_node_1.sid = TM_CODE_K_DUMP; |
|
1495 | 1620 | kcoefficient_node_1.coarseTime = 0x00; |
|
1496 | 1621 | kcoefficient_node_1.fineTime = 0x00; |
|
1497 | 1622 | kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1; |
|
1498 | 1623 | kcoefficient_node_1.status = 0x00; |
|
1499 | 1624 | |
|
1500 | 1625 | kcoefficient_node_2.previous = NULL; |
|
1501 | 1626 | kcoefficient_node_2.next = NULL; |
|
1502 | 1627 | kcoefficient_node_2.sid = TM_CODE_K_DUMP; |
|
1503 | 1628 | kcoefficient_node_2.coarseTime = 0x00; |
|
1504 | 1629 | kcoefficient_node_2.fineTime = 0x00; |
|
1505 | 1630 | kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2; |
|
1506 | 1631 | kcoefficient_node_2.status = 0x00; |
|
1507 | 1632 | } |
|
1508 | 1633 | |
|
1509 | 1634 | void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr ) |
|
1510 | 1635 | { |
|
1511 | 1636 | unsigned int k; |
|
1512 | 1637 | unsigned int packetLength; |
|
1513 | 1638 | |
|
1514 | 1639 | packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header |
|
1515 | 1640 | |
|
1516 | 1641 | kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1517 | 1642 | kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1518 | 1643 | kcoefficients_dump->reserved = CCSDS_RESERVED; |
|
1519 | 1644 | kcoefficients_dump->userApplication = CCSDS_USER_APP; |
|
1520 | 1645 | kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);; |
|
1521 | 1646 | kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;; |
|
1522 | 1647 | kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1523 | 1648 | kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1524 | 1649 | kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8); |
|
1525 | 1650 | kcoefficients_dump->packetLength[1] = (unsigned char) packetLength; |
|
1526 | 1651 | // DATA FIELD HEADER |
|
1527 | 1652 | kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2; |
|
1528 | 1653 | kcoefficients_dump->serviceType = TM_TYPE_K_DUMP; |
|
1529 | 1654 | kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP; |
|
1530 | 1655 | kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND; |
|
1531 | 1656 | kcoefficients_dump->time[0] = 0x00; |
|
1532 | 1657 | kcoefficients_dump->time[1] = 0x00; |
|
1533 | 1658 | kcoefficients_dump->time[2] = 0x00; |
|
1534 | 1659 | kcoefficients_dump->time[3] = 0x00; |
|
1535 | 1660 | kcoefficients_dump->time[4] = 0x00; |
|
1536 | 1661 | kcoefficients_dump->time[5] = 0x00; |
|
1537 | 1662 | kcoefficients_dump->sid = SID_K_DUMP; |
|
1538 | 1663 | |
|
1539 | 1664 | kcoefficients_dump->pkt_cnt = 2; |
|
1540 | 1665 | kcoefficients_dump->pkt_nr = pkt_nr; |
|
1541 | 1666 | kcoefficients_dump->blk_nr = blk_nr; |
|
1542 | 1667 | |
|
1543 | 1668 | //****************** |
|
1544 | 1669 | // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR] |
|
1545 | 1670 | // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900) |
|
1546 | 1671 | for (k=0; k<3900; k++) |
|
1547 | 1672 | { |
|
1548 | 1673 | kcoefficients_dump->kcoeff_blks[k] = 0x00; |
|
1549 | 1674 | } |
|
1550 | 1675 | } |
|
1551 | 1676 | |
|
1552 | 1677 | void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id ) |
|
1553 | 1678 | { |
|
1554 | 1679 | /** This function increment the packet sequence control parameter of a TC, depending on its destination ID. |
|
1555 | 1680 | * |
|
1556 | 1681 | * @param packet_sequence_control points to the packet sequence control which will be incremented |
|
1557 | 1682 | * @param destination_id is the destination ID of the TM, there is one counter by destination ID |
|
1558 | 1683 | * |
|
1559 | 1684 | * If the destination ID is not known, a dedicated counter is incremented. |
|
1560 | 1685 | * |
|
1561 | 1686 | */ |
|
1562 | 1687 | |
|
1563 | 1688 | unsigned short sequence_cnt; |
|
1564 | 1689 | unsigned short segmentation_grouping_flag; |
|
1565 | 1690 | unsigned short new_packet_sequence_control; |
|
1566 | 1691 | unsigned char i; |
|
1567 | 1692 | |
|
1568 | 1693 | switch (destination_id) |
|
1569 | 1694 | { |
|
1570 | 1695 | case SID_TC_GROUND: |
|
1571 | 1696 | i = GROUND; |
|
1572 | 1697 | break; |
|
1573 | 1698 | case SID_TC_MISSION_TIMELINE: |
|
1574 | 1699 | i = MISSION_TIMELINE; |
|
1575 | 1700 | break; |
|
1576 | 1701 | case SID_TC_TC_SEQUENCES: |
|
1577 | 1702 | i = TC_SEQUENCES; |
|
1578 | 1703 | break; |
|
1579 | 1704 | case SID_TC_RECOVERY_ACTION_CMD: |
|
1580 | 1705 | i = RECOVERY_ACTION_CMD; |
|
1581 | 1706 | break; |
|
1582 | 1707 | case SID_TC_BACKUP_MISSION_TIMELINE: |
|
1583 | 1708 | i = BACKUP_MISSION_TIMELINE; |
|
1584 | 1709 | break; |
|
1585 | 1710 | case SID_TC_DIRECT_CMD: |
|
1586 | 1711 | i = DIRECT_CMD; |
|
1587 | 1712 | break; |
|
1588 | 1713 | case SID_TC_SPARE_GRD_SRC1: |
|
1589 | 1714 | i = SPARE_GRD_SRC1; |
|
1590 | 1715 | break; |
|
1591 | 1716 | case SID_TC_SPARE_GRD_SRC2: |
|
1592 | 1717 | i = SPARE_GRD_SRC2; |
|
1593 | 1718 | break; |
|
1594 | 1719 | case SID_TC_OBCP: |
|
1595 | 1720 | i = OBCP; |
|
1596 | 1721 | break; |
|
1597 | 1722 | case SID_TC_SYSTEM_CONTROL: |
|
1598 | 1723 | i = SYSTEM_CONTROL; |
|
1599 | 1724 | break; |
|
1600 | 1725 | case SID_TC_AOCS: |
|
1601 | 1726 | i = AOCS; |
|
1602 | 1727 | break; |
|
1603 | 1728 | case SID_TC_RPW_INTERNAL: |
|
1604 | 1729 | i = RPW_INTERNAL; |
|
1605 | 1730 | break; |
|
1606 | 1731 | default: |
|
1607 | 1732 | i = GROUND; |
|
1608 | 1733 | break; |
|
1609 | 1734 | } |
|
1610 | 1735 | |
|
1611 | 1736 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; |
|
1612 | 1737 | sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff; |
|
1613 | 1738 | |
|
1614 | 1739 | new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ; |
|
1615 | 1740 | |
|
1616 | 1741 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); |
|
1617 | 1742 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
1618 | 1743 | |
|
1619 | 1744 | // increment the sequence counter |
|
1620 | 1745 | if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX ) |
|
1621 | 1746 | { |
|
1622 | 1747 | sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1; |
|
1623 | 1748 | } |
|
1624 | 1749 | else |
|
1625 | 1750 | { |
|
1626 | 1751 | sequenceCounters_TM_DUMP[ i ] = 0; |
|
1627 | 1752 | } |
|
1628 | 1753 | } |
General Comments 0
You need to be logged in to leave comments.
Login now