##// END OF EJS Templates
commit before going back to 3.1.0.2 for LESIA compilation
paul -
r295:16a2669a01ce R3_plus draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 c378fa14eadd80b3b873ca7c8f9f387893c07692 header/lfr_common_headers
2 1ffa3d630b9ced4a87a362dafb10d9838e9cc0d9 header/lfr_common_headers
@@ -1,123 +1,125
1 TEMPLATE = app
1 TEMPLATE = app
2 # CONFIG += console v8 sim
2 # CONFIG += console v8 sim
3 # CONFIG options =
3 # CONFIG options =
4 # verbose
4 # verbose
5 # boot_messages
5 # boot_messages
6 # debug_messages
6 # debug_messages
7 # cpu_usage_report
7 # cpu_usage_report
8 # stack_report
8 # stack_report
9 # vhdl_dev
9 # vhdl_dev
10 # debug_tch
10 # debug_tch
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 # debug_watchdog
12 # debug_watchdog
13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
14 CONFIG -= qt
14 CONFIG -= qt
15
15
16 include(./sparc.pri)
16 include(./sparc.pri)
17
17
18 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
19
18 # flight software version
20 # flight software version
19 SWVERSION=-1-0
21 SWVERSION=-1-0
20 DEFINES += SW_VERSION_N1=3 # major
22 DEFINES += SW_VERSION_N1=3 # major
21 DEFINES += SW_VERSION_N2=1 # minor
23 DEFINES += SW_VERSION_N2=1 # minor
22 DEFINES += SW_VERSION_N3=0 # patch
24 DEFINES += SW_VERSION_N3=0 # patch
23 DEFINES += SW_VERSION_N4=2 # internal
25 DEFINES += SW_VERSION_N4=2 # internal
24
26
25 # <GCOV>
27 # <GCOV>
26 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
28 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
27 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
29 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
28 # </GCOV>
30 # </GCOV>
29
31
30 # <CHANGE BEFORE FLIGHT>
32 # <CHANGE BEFORE FLIGHT>
31 contains( CONFIG, lpp_dpu_destid ) {
33 contains( CONFIG, lpp_dpu_destid ) {
32 DEFINES += LPP_DPU_DESTID
34 DEFINES += LPP_DPU_DESTID
33 }
35 }
34 # </CHANGE BEFORE FLIGHT>
36 # </CHANGE BEFORE FLIGHT>
35
37
36 contains( CONFIG, debug_tch ) {
38 contains( CONFIG, debug_tch ) {
37 DEFINES += DEBUG_TCH
39 DEFINES += DEBUG_TCH
38 }
40 }
39 DEFINES += MSB_FIRST_TCH
41 DEFINES += MSB_FIRST_TCH
40
42
41 contains( CONFIG, vhdl_dev ) {
43 contains( CONFIG, vhdl_dev ) {
42 DEFINES += VHDL_DEV
44 DEFINES += VHDL_DEV
43 }
45 }
44
46
45 contains( CONFIG, verbose ) {
47 contains( CONFIG, verbose ) {
46 DEFINES += PRINT_MESSAGES_ON_CONSOLE
48 DEFINES += PRINT_MESSAGES_ON_CONSOLE
47 }
49 }
48
50
49 contains( CONFIG, debug_messages ) {
51 contains( CONFIG, debug_messages ) {
50 DEFINES += DEBUG_MESSAGES
52 DEFINES += DEBUG_MESSAGES
51 }
53 }
52
54
53 contains( CONFIG, cpu_usage_report ) {
55 contains( CONFIG, cpu_usage_report ) {
54 DEFINES += PRINT_TASK_STATISTICS
56 DEFINES += PRINT_TASK_STATISTICS
55 }
57 }
56
58
57 contains( CONFIG, stack_report ) {
59 contains( CONFIG, stack_report ) {
58 DEFINES += PRINT_STACK_REPORT
60 DEFINES += PRINT_STACK_REPORT
59 }
61 }
60
62
61 contains( CONFIG, boot_messages ) {
63 contains( CONFIG, boot_messages ) {
62 DEFINES += BOOT_MESSAGES
64 DEFINES += BOOT_MESSAGES
63 }
65 }
64
66
65 contains( CONFIG, debug_watchdog ) {
67 contains( CONFIG, debug_watchdog ) {
66 DEFINES += DEBUG_WATCHDOG
68 DEFINES += DEBUG_WATCHDOG
67 }
69 }
68
70
69 #doxygen.target = doxygen
71 #doxygen.target = doxygen
70 #doxygen.commands = doxygen ../doc/Doxyfile
72 #doxygen.commands = doxygen ../doc/Doxyfile
71 #QMAKE_EXTRA_TARGETS += doxygen
73 #QMAKE_EXTRA_TARGETS += doxygen
72
74
73 TARGET = fsw
75 TARGET = fsw
74
76
75 INCLUDEPATH += \
77 INCLUDEPATH += \
76 $${PWD}/../src \
78 $${PWD}/../src \
77 $${PWD}/../header \
79 $${PWD}/../header \
78 $${PWD}/../header/lfr_common_headers \
80 $${PWD}/../header/lfr_common_headers \
79 $${PWD}/../header/processing \
81 $${PWD}/../header/processing \
80 $${PWD}/../LFR_basic-parameters
82 $${PWD}/../LFR_basic-parameters
81
83
82 SOURCES += \
84 SOURCES += \
83 ../src/wf_handler.c \
85 ../src/wf_handler.c \
84 ../src/tc_handler.c \
86 ../src/tc_handler.c \
85 ../src/fsw_misc.c \
87 ../src/fsw_misc.c \
86 ../src/fsw_init.c \
88 ../src/fsw_init.c \
87 ../src/fsw_globals.c \
89 ../src/fsw_globals.c \
88 ../src/fsw_spacewire.c \
90 ../src/fsw_spacewire.c \
89 ../src/tc_load_dump_parameters.c \
91 ../src/tc_load_dump_parameters.c \
90 ../src/tm_lfr_tc_exe.c \
92 ../src/tm_lfr_tc_exe.c \
91 ../src/tc_acceptance.c \
93 ../src/tc_acceptance.c \
92 ../src/processing/fsw_processing.c \
94 ../src/processing/fsw_processing.c \
93 ../src/processing/avf0_prc0.c \
95 ../src/processing/avf0_prc0.c \
94 ../src/processing/avf1_prc1.c \
96 ../src/processing/avf1_prc1.c \
95 ../src/processing/avf2_prc2.c \
97 ../src/processing/avf2_prc2.c \
96 ../src/lfr_cpu_usage_report.c \
98 ../src/lfr_cpu_usage_report.c \
97 ../LFR_basic-parameters/basic_parameters.c
99 ../LFR_basic-parameters/basic_parameters.c
98
100
99 HEADERS += \
101 HEADERS += \
100 ../header/wf_handler.h \
102 ../header/wf_handler.h \
101 ../header/tc_handler.h \
103 ../header/tc_handler.h \
102 ../header/grlib_regs.h \
104 ../header/grlib_regs.h \
103 ../header/fsw_misc.h \
105 ../header/fsw_misc.h \
104 ../header/fsw_init.h \
106 ../header/fsw_init.h \
105 ../header/fsw_spacewire.h \
107 ../header/fsw_spacewire.h \
106 ../header/tc_load_dump_parameters.h \
108 ../header/tc_load_dump_parameters.h \
107 ../header/tm_lfr_tc_exe.h \
109 ../header/tm_lfr_tc_exe.h \
108 ../header/tc_acceptance.h \
110 ../header/tc_acceptance.h \
109 ../header/processing/fsw_processing.h \
111 ../header/processing/fsw_processing.h \
110 ../header/processing/avf0_prc0.h \
112 ../header/processing/avf0_prc0.h \
111 ../header/processing/avf1_prc1.h \
113 ../header/processing/avf1_prc1.h \
112 ../header/processing/avf2_prc2.h \
114 ../header/processing/avf2_prc2.h \
113 ../header/fsw_params_wf_handler.h \
115 ../header/fsw_params_wf_handler.h \
114 ../header/lfr_cpu_usage_report.h \
116 ../header/lfr_cpu_usage_report.h \
115 ../header/lfr_common_headers/ccsds_types.h \
117 ../header/lfr_common_headers/ccsds_types.h \
116 ../header/lfr_common_headers/fsw_params.h \
118 ../header/lfr_common_headers/fsw_params.h \
117 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
119 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
118 ../header/lfr_common_headers/fsw_params_processing.h \
120 ../header/lfr_common_headers/fsw_params_processing.h \
119 ../header/lfr_common_headers/tm_byte_positions.h \
121 ../header/lfr_common_headers/tm_byte_positions.h \
120 ../LFR_basic-parameters/basic_parameters.h \
122 ../LFR_basic-parameters/basic_parameters.h \
121 ../LFR_basic-parameters/basic_parameters_params.h \
123 ../LFR_basic-parameters/basic_parameters_params.h \
122 ../header/GscMemoryLPP.hpp
124 ../header/GscMemoryLPP.hpp
123
125
@@ -1,97 +1,99
1 CONFIG += console
1 CONFIG += console
2 CONFIG -= qt
2 CONFIG -= qt
3 QMAKE_CC=sparc-rtems-gcc
3 QMAKE_CC=sparc-rtems-gcc
4 message(C compiler forced to: $$QMAKE_CC)
4 message(C compiler forced to: $$QMAKE_CC)
5 QMAKE_CXX=sparc-rtems-g++
5 QMAKE_CXX=sparc-rtems-g++
6 message(C++ compiler forced to: $$QMAKE_CXX)
6 message(C++ compiler forced to: $$QMAKE_CXX)
7 QMAKE_AR=sparc-rtems-ar rcs
7 QMAKE_AR=sparc-rtems-ar rcs
8 message(Archiver forced to: $$QMAKE_AR)
8 message(Archiver forced to: $$QMAKE_AR)
9 QMAKE_LINK=sparc-rtems-g++
9 QMAKE_LINK=sparc-rtems-g++
10 message(Linker forced to: $$QMAKE_LINK)
10 message(Linker forced to: $$QMAKE_LINK)
11 QMAKE_LINK_SHLIB=sparc-rtems-g++
11 QMAKE_LINK_SHLIB=sparc-rtems-g++
12 QMAKE_OBJCOPY= sparc-rtems-objcopy
12 QMAKE_OBJCOPY= sparc-rtems-objcopy
13 QMAKE_STRIP=sparc-rtems-strip
13 QMAKE_STRIP=sparc-rtems-strip
14 QMAKE_GDB=sparc-rtems-gdb
14 QMAKE_GDB=sparc-rtems-gdb
15
15
16 INCLUDEPATH += /opt/rtems-4.10
16 #INCLUDEPATH += /opt/rtems-4.10
17 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
17
18
18 QMAKE_CFLAGS_DEBUG= -g
19 QMAKE_CFLAGS_DEBUG= -g
19 QMAKE_CFLAGS_RELEASE=""
20 QMAKE_CFLAGS_RELEASE=""
20 QMAKE_CXXFLAGS_DEBUG= -g
21 QMAKE_CXXFLAGS_DEBUG= -g
21 QMAKE_CXXFLAGS_RELEASE=""
22 QMAKE_CXXFLAGS_RELEASE=""
22 QMAKE_LFLAGS_RELEASE=""
23 QMAKE_LFLAGS_RELEASE=""
23 QMAKE_LFLAGS_DEBUG= -g
24 QMAKE_LFLAGS_DEBUG= -g
24 QMAKE_CXXFLAGS_DEPS =
25 QMAKE_CXXFLAGS_DEPS =
25 QMAKE_CXXFLAGS_WARN_ON = -Wall
26 QMAKE_CXXFLAGS_WARN_ON = -Wall
26 QMAKE_CXXFLAGS_WARN_OFF = -w
27 QMAKE_CXXFLAGS_WARN_OFF = -w
27 QMAKE_CXXFLAGS_RELEASE =
28 QMAKE_CXXFLAGS_RELEASE =
28 QMAKE_CXXFLAGS_DEBUG =
29 QMAKE_CXXFLAGS_DEBUG =
29 QMAKE_CXXFLAGS_YACC =
30 QMAKE_CXXFLAGS_YACC =
30 QMAKE_CXXFLAGS_THREAD =
31 QMAKE_CXXFLAGS_THREAD =
31 QMAKE_CXXFLAGS_RTTI_ON =
32 QMAKE_CXXFLAGS_RTTI_ON =
32 QMAKE_CXXFLAGS_RTTI_OFF =
33 QMAKE_CXXFLAGS_RTTI_OFF =
33 QMAKE_CXXFLAGS_EXCEPTIONS_ON =
34 QMAKE_CXXFLAGS_EXCEPTIONS_ON =
34 QMAKE_CXXFLAGS_EXCEPTIONS_OFF =
35 QMAKE_CXXFLAGS_EXCEPTIONS_OFF =
35 QMAKE_CFLAGS_WARN_ON = -Wall
36 QMAKE_CFLAGS_WARN_ON = -Wall
36 QMAKE_CFLAGS_WARN_OFF = -w
37 QMAKE_CFLAGS_WARN_OFF = -w
37 QMAKE_CFLAGS_RELEASE =
38 QMAKE_CFLAGS_RELEASE =
38 QMAKE_CFLAGS_YACC =
39 QMAKE_CFLAGS_YACC =
39 QMAKE_LFLAGS_EXCEPTIONS_ON =
40 QMAKE_LFLAGS_EXCEPTIONS_ON =
40 QMAKE_LFLAGS_EXCEPTIONS_OFF =
41 QMAKE_LFLAGS_EXCEPTIONS_OFF =
41 QMAKE_LFLAGS_RELEASE = -Xlinker -Map=output.map
42 QMAKE_LFLAGS_RELEASE = -Xlinker -Map=output.map
42 QMAKE_LFLAGS_CONSOLE =
43 QMAKE_LFLAGS_CONSOLE =
43 QMAKE_LFLAGS_WINDOWS =
44 QMAKE_LFLAGS_WINDOWS =
44 QMAKE_LFLAGS_DLL =
45 QMAKE_LFLAGS_DLL =
45 QMAKE_INCDIR_QT =
46 QMAKE_INCDIR_QT =
46 QMAKE_INCDIR =
47 QMAKE_INCDIR =
47 QMAKE_CFLAGS_SHLIB =
48 QMAKE_CFLAGS_SHLIB =
48 QMAKE_CFLAGS_STATIC_LIB =
49 QMAKE_CFLAGS_STATIC_LIB =
49 QMAKE_CXXFLAGS_SHLIB =
50 QMAKE_CXXFLAGS_SHLIB =
50 QMAKE_CXXFLAGS_STATIC_LIB =
51 QMAKE_CXXFLAGS_STATIC_LIB =
51 QMAKE_LIBS=""
52 QMAKE_LIBS=""
52 INCLUDEPATH=""
53 INCLUDEPATH=""
53 DEFINES=""
54 DEFINES=""
54
55
55 contains( TEMPLATE, app ) {
56 contains( TEMPLATE, app ) {
56 OBJECTS_DIR=obj
57 OBJECTS_DIR=obj
57 DESTDIR=bin
58 DESTDIR=bin
58 }
59 }
59
60
60 #QMAKE_CFLAGS_RELEASE += -O0
61 #QMAKE_CFLAGS_RELEASE += -O0
61 #QMAKE_CFLAGS_DEBUG += -O0
62 #QMAKE_CFLAGS_DEBUG += -O0
62 #QMAKE_CXXFLAGS_RELEASE += -O0
63 #QMAKE_CXXFLAGS_RELEASE += -O0
63 #QMAKE_CXXFLAGS_DEBUG += -O0
64 #QMAKE_CXXFLAGS_DEBUG += -O0
65
64 QMAKE_CFLAGS_RELEASE += -O3
66 QMAKE_CFLAGS_RELEASE += -O3
65 QMAKE_CFLAGS_DEBUG += -O3
67 QMAKE_CFLAGS_DEBUG += -O3
66 QMAKE_CXXFLAGS_RELEASE += -O3
68 QMAKE_CXXFLAGS_RELEASE += -O3
67 QMAKE_CXXFLAGS_DEBUG += -O3
69 QMAKE_CXXFLAGS_DEBUG += -O3
68
70
69 #QMAKE_CFLAGS_RELEASE+= -O3 -std=c99
71 #QMAKE_CFLAGS_RELEASE += -O3 -std=c99
70 #QMAKE_CFLAGS_DEBUG+= -O3 -std=c99
72 #QMAKE_CFLAGS_DEBUG += -O3 -std=c99
71 #QMAKE_CXXFLAGS_RELEASE+= -O3 -std=c99
73 #QMAKE_CXXFLAGS_RELEASE += -O3 -std=c99
72 #QMAKE_CXXFLAGS_DEBUG+= -O3 -std=c99
74 #QMAKE_CXXFLAGS_DEBUG += -O3 -std=c99
73
75
74 contains( TEMPLATE, app ) {
76 contains( TEMPLATE, app ) {
75 grmon.target = grmon
77 grmon.target = grmon
76 grmon.commands = cd $$DESTDIR && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u
78 grmon.commands = cd $$DESTDIR && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u
77 QMAKE_EXTRA_TARGETS += grmon
79 QMAKE_EXTRA_TARGETS += grmon
78 }
80 }
79
81
80
82
81
83
82
84
83
85
84
86
85
87
86
88
87
89
88
90
89
91
90
92
91
93
92
94
93
95
94
96
95
97
96
98
97
99
@@ -1,83 +1,84
1 #ifndef FSW_MISC_H_INCLUDED
1 #ifndef FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6 #include <grspw.h>
6 #include <grspw.h>
7 #include <grlib_regs.h>
7 #include <grlib_regs.h>
8
8
9 #include "fsw_params.h"
9 #include "fsw_params.h"
10 #include "fsw_spacewire.h"
10 #include "fsw_spacewire.h"
11 #include "lfr_cpu_usage_report.h"
11 #include "lfr_cpu_usage_report.h"
12
12
13
13
14 enum lfr_reset_cause_t{
14 enum lfr_reset_cause_t{
15 UNKNOWN_CAUSE,
15 UNKNOWN_CAUSE,
16 POWER_ON,
16 POWER_ON,
17 TC_RESET,
17 TC_RESET,
18 WATCHDOG,
18 WATCHDOG,
19 ERROR_RESET,
19 ERROR_RESET,
20 UNEXP_RESET
20 UNEXP_RESET
21 };
21 };
22
22
23 extern gptimer_regs_t *gptimer_regs;
23 extern gptimer_regs_t *gptimer_regs;
24 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
24 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
25 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
25 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
26
26
27 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
27 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
28
28
29 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
29 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
30 rtems_id HK_id; // id of the HK rate monotonic period
30 rtems_id HK_id; // id of the HK rate monotonic period
31
31
32 void timer_configure( unsigned char timer, unsigned int clock_divider,
32 void timer_configure( unsigned char timer, unsigned int clock_divider,
33 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
33 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
34 void timer_start( unsigned char timer );
34 void timer_start( unsigned char timer );
35 void timer_stop( unsigned char timer );
35 void timer_stop( unsigned char timer );
36 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
36 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
37
37
38 // WATCHDOG
38 // WATCHDOG
39 rtems_isr watchdog_isr( rtems_vector_number vector );
39 rtems_isr watchdog_isr( rtems_vector_number vector );
40 void watchdog_configure(void);
40 void watchdog_configure(void);
41 void watchdog_stop(void);
41 void watchdog_stop(void);
42 void watchdog_reload(void);
42 void watchdog_reload(void);
43 void watchdog_start(void);
43 void watchdog_start(void);
44
44
45 // SERIAL LINK
45 // SERIAL LINK
46 int send_console_outputs_on_apbuart_port( void );
46 int send_console_outputs_on_apbuart_port( void );
47 int enable_apbuart_transmitter( void );
47 int enable_apbuart_transmitter( void );
48 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
48 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
49
49
50 // RTEMS TASKS
50 // RTEMS TASKS
51 rtems_task load_task( rtems_task_argument argument );
51 rtems_task load_task( rtems_task_argument argument );
52 rtems_task hous_task( rtems_task_argument argument );
52 rtems_task hous_task( rtems_task_argument argument );
53 rtems_task dumb_task( rtems_task_argument unused );
53 rtems_task dumb_task( rtems_task_argument unused );
54
54
55 void init_housekeeping_parameters( void );
55 void init_housekeeping_parameters( void );
56 void increment_seq_counter(unsigned short *packetSequenceControl);
56 void increment_seq_counter(unsigned short *packetSequenceControl);
57 void getTime( unsigned char *time);
57 void getTime( unsigned char *time);
58 unsigned long long int getTimeAsUnsignedLongLongInt( );
58 unsigned long long int getTimeAsUnsignedLongLongInt( );
59 void send_dumb_hk( void );
59 void send_dumb_hk( void );
60 void get_temperatures( unsigned char *temperatures );
60 void get_temperatures( unsigned char *temperatures );
61 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
61 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
62 void get_cpu_load( unsigned char *resource_statistics );
62 void get_cpu_load( unsigned char *resource_statistics );
63 void set_hk_lfr_sc_potential_flag( bool state );
63 void set_hk_lfr_sc_potential_flag( bool state );
64 void set_sy_lfr_pas_filter_enabled( bool state );
64 void set_sy_lfr_watchdog_enabled( bool state );
65 void set_sy_lfr_watchdog_enabled( bool state );
65 void set_hk_lfr_calib_enable( bool state );
66 void set_hk_lfr_calib_enable( bool state );
66 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
67 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
67 void hk_lfr_le_me_he_update();
68 void hk_lfr_le_me_he_update();
68 void set_hk_lfr_time_not_synchro();
69 void set_hk_lfr_time_not_synchro();
69
70
70 extern int sched_yield( void );
71 extern int sched_yield( void );
71 extern void rtems_cpu_usage_reset();
72 extern void rtems_cpu_usage_reset();
72 extern ring_node *current_ring_node_f3;
73 extern ring_node *current_ring_node_f3;
73 extern ring_node *ring_node_to_send_cwf_f3;
74 extern ring_node *ring_node_to_send_cwf_f3;
74 extern ring_node waveform_ring_f3[];
75 extern ring_node waveform_ring_f3[];
75 extern unsigned short sequenceCounterHK;
76 extern unsigned short sequenceCounterHK;
76
77
77 extern unsigned char hk_lfr_q_sd_fifo_size_max;
78 extern unsigned char hk_lfr_q_sd_fifo_size_max;
78 extern unsigned char hk_lfr_q_rv_fifo_size_max;
79 extern unsigned char hk_lfr_q_rv_fifo_size_max;
79 extern unsigned char hk_lfr_q_p0_fifo_size_max;
80 extern unsigned char hk_lfr_q_p0_fifo_size_max;
80 extern unsigned char hk_lfr_q_p1_fifo_size_max;
81 extern unsigned char hk_lfr_q_p1_fifo_size_max;
81 extern unsigned char hk_lfr_q_p2_fifo_size_max;
82 extern unsigned char hk_lfr_q_p2_fifo_size_max;
82
83
83 #endif // FSW_MISC_H_INCLUDED
84 #endif // FSW_MISC_H_INCLUDED
@@ -1,25 +1,35
1 #include <drvmgr/ambapp_bus.h>
1 #include <drvmgr/ambapp_bus.h>
2 #include <drvmgr/drvmgr.h>
2
3
3 // GRSPW0 resources
4 // GRSPW0 resources
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
5 struct drvmgr_key grlib_grspw_0n1_res[] =
6 {
5 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)50}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2
7 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)50}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2
6 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
8 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
7 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
9 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
8 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)34}},
10 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)34}},
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)228+4}},
11 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)200}},
10 KEY_EMPTY
12 KEY_EMPTY
11 };
13 };
12
14
13 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
15 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
14
16
15 struct drvmgr_bus_res grlib_drv_resources = {
17 //struct drvmgr_bus_res grlib_drv_resources =
16 .next = NULL,
18 //{
17 .resource = {
19 // .next = NULL,
20 // .resource = {
21 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
22 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
23 // RES_EMPTY /* Mark end of resource array */
24 // }
25 //};
26
27 struct drvmgr_bus_res grlib_drv_resources =
28 {
29 NULL,
30 {
18 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
31 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
19 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]},
32 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
20 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
33 RES_EMPTY /* Mark end of resource array */
21 RES_EMPTY /* Mark end of device resource array */
22 }
34 }
23 };
35 };
24
25
@@ -1,934 +1,938
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
42 #endif
43
43
44 #include <rtems/confdefs.h>
44 #include <rtems/confdefs.h>
45
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
49 /* Add Timer and UART Driver */
50
50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #endif
53 #endif
54
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 #endif
57 #endif
58
56 #endif
59 #endif
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
58 #include <drvmgr/drvmgr_confdefs.h>
62 #include <drvmgr/drvmgr_confdefs.h>
59 #endif
63 #endif
60
64
61 #include "fsw_init.h"
65 #include "fsw_init.h"
62 #include "fsw_config.c"
66 #include "fsw_config.c"
63 #include "GscMemoryLPP.hpp"
67 #include "GscMemoryLPP.hpp"
64
68
65 void initCache()
69 void initCache()
66 {
70 {
67 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
68 // These should only be read and written using 32-bit LDA/STA instructions.
72 // These should only be read and written using 32-bit LDA/STA instructions.
69 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
70 // The table below shows the register addresses:
74 // The table below shows the register addresses:
71 // 0x00 Cache control register
75 // 0x00 Cache control register
72 // 0x04 Reserved
76 // 0x04 Reserved
73 // 0x08 Instruction cache configuration register
77 // 0x08 Instruction cache configuration register
74 // 0x0C Data cache configuration register
78 // 0x0C Data cache configuration register
75
79
76 // Cache Control Register Leon3 / Leon3FT
80 // Cache Control Register Leon3 / Leon3FT
77 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
78 // RFT PS TB DS FD FI FT ST IB
82 // RFT PS TB DS FD FI FT ST IB
79 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
80 // IP DP ITE IDE DTE DDE DF IF DCS ICS
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
81
85
82 unsigned int cacheControlRegister;
86 unsigned int cacheControlRegister;
83
87
84 CCR_resetCacheControlRegister();
88 CCR_resetCacheControlRegister();
85 ASR16_resetRegisterProtectionControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
86
90
87 cacheControlRegister = CCR_getValue();
91 cacheControlRegister = CCR_getValue();
88 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
89 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
90
94
91 CCR_enableInstructionCache(); // ICS bits
95 CCR_enableInstructionCache(); // ICS bits
92 CCR_enableDataCache(); // DCS bits
96 CCR_enableDataCache(); // DCS bits
93 CCR_enableInstructionBurstFetch(); // IB bit
97 CCR_enableInstructionBurstFetch(); // IB bit
94
98
95 faultTolerantScheme();
99 faultTolerantScheme();
96
100
97 cacheControlRegister = CCR_getValue();
101 cacheControlRegister = CCR_getValue();
98 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
99 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
100
104
101 PRINTF("\n");
105 PRINTF("\n");
102 }
106 }
103
107
104 rtems_task Init( rtems_task_argument ignored )
108 rtems_task Init( rtems_task_argument ignored )
105 {
109 {
106 /** This is the RTEMS INIT taks, it is the first task launched by the system.
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
107 *
111 *
108 * @param unused is the starting argument of the RTEMS task
112 * @param unused is the starting argument of the RTEMS task
109 *
113 *
110 * The INIT task create and run all other RTEMS tasks.
114 * The INIT task create and run all other RTEMS tasks.
111 *
115 *
112 */
116 */
113
117
114 //***********
118 //***********
115 // INIT CACHE
119 // INIT CACHE
116
120
117 unsigned char *vhdlVersion;
121 unsigned char *vhdlVersion;
118
122
119 reset_lfr();
123 reset_lfr();
120
124
121 reset_local_time();
125 reset_local_time();
122
126
123 rtems_cpu_usage_reset();
127 rtems_cpu_usage_reset();
124
128
125 rtems_status_code status;
129 rtems_status_code status;
126 rtems_status_code status_spw;
130 rtems_status_code status_spw;
127 rtems_isr_entry old_isr_handler;
131 rtems_isr_entry old_isr_handler;
128
132
129 // UART settings
133 // UART settings
130 enable_apbuart_transmitter();
134 enable_apbuart_transmitter();
131 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
135 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
132
136
133 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
137 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
134
138
135
139
136 PRINTF("\n\n\n\n\n")
140 PRINTF("\n\n\n\n\n")
137
141
138 initCache();
142 initCache();
139
143
140 PRINTF("*************************\n")
144 PRINTF("*************************\n")
141 PRINTF("** LFR Flight Software **\n")
145 PRINTF("** LFR Flight Software **\n")
142 PRINTF1("** %d.", SW_VERSION_N1)
146 PRINTF1("** %d.", SW_VERSION_N1)
143 PRINTF1("%d." , SW_VERSION_N2)
147 PRINTF1("%d." , SW_VERSION_N2)
144 PRINTF1("%d." , SW_VERSION_N3)
148 PRINTF1("%d." , SW_VERSION_N3)
145 PRINTF1("%d **\n", SW_VERSION_N4)
149 PRINTF1("%d **\n", SW_VERSION_N4)
146
150
147 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
151 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
148 PRINTF("** VHDL **\n")
152 PRINTF("** VHDL **\n")
149 PRINTF1("** %d.", vhdlVersion[1])
153 PRINTF1("** %d.", vhdlVersion[1])
150 PRINTF1("%d." , vhdlVersion[2])
154 PRINTF1("%d." , vhdlVersion[2])
151 PRINTF1("%d **\n", vhdlVersion[3])
155 PRINTF1("%d **\n", vhdlVersion[3])
152 PRINTF("*************************\n")
156 PRINTF("*************************\n")
153 PRINTF("\n\n")
157 PRINTF("\n\n")
154
158
155 init_parameter_dump();
159 init_parameter_dump();
156 init_kcoefficients_dump();
160 init_kcoefficients_dump();
157 init_local_mode_parameters();
161 init_local_mode_parameters();
158 init_housekeeping_parameters();
162 init_housekeeping_parameters();
159 init_k_coefficients_prc0();
163 init_k_coefficients_prc0();
160 init_k_coefficients_prc1();
164 init_k_coefficients_prc1();
161 init_k_coefficients_prc2();
165 init_k_coefficients_prc2();
162 pa_bia_status_info = 0x00;
166 pa_bia_status_info = 0x00;
163 cp_rpw_sc_rw_f_flags = 0x00;
167 cp_rpw_sc_rw_f_flags = 0x00;
164 cp_rpw_sc_rw1_f1 = 0.0;
168 cp_rpw_sc_rw1_f1 = 0.0;
165 cp_rpw_sc_rw1_f2 = 0.0;
169 cp_rpw_sc_rw1_f2 = 0.0;
166 cp_rpw_sc_rw2_f1 = 0.0;
170 cp_rpw_sc_rw2_f1 = 0.0;
167 cp_rpw_sc_rw2_f2 = 0.0;
171 cp_rpw_sc_rw2_f2 = 0.0;
168 cp_rpw_sc_rw3_f1 = 0.0;
172 cp_rpw_sc_rw3_f1 = 0.0;
169 cp_rpw_sc_rw3_f2 = 0.0;
173 cp_rpw_sc_rw3_f2 = 0.0;
170 cp_rpw_sc_rw4_f1 = 0.0;
174 cp_rpw_sc_rw4_f1 = 0.0;
171 cp_rpw_sc_rw4_f2 = 0.0;
175 cp_rpw_sc_rw4_f2 = 0.0;
172 // initialize filtering parameters
176 // initialize filtering parameters
173 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
177 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
174 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
178 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
175 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
179 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
176 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
180 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
177 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
181 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
178 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
182 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
179 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
183 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
180
184
181 // waveform picker initialization
185 // waveform picker initialization
182 WFP_init_rings();
186 WFP_init_rings();
183 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
187 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
184 WFP_reset_current_ring_nodes();
188 WFP_reset_current_ring_nodes();
185 reset_waveform_picker_regs();
189 reset_waveform_picker_regs();
186
190
187 // spectral matrices initialization
191 // spectral matrices initialization
188 SM_init_rings(); // initialize spectral matrices rings
192 SM_init_rings(); // initialize spectral matrices rings
189 SM_reset_current_ring_nodes();
193 SM_reset_current_ring_nodes();
190 reset_spectral_matrix_regs();
194 reset_spectral_matrix_regs();
191
195
192 // configure calibration
196 // configure calibration
193 configureCalibration( false ); // true means interleaved mode, false is for normal mode
197 configureCalibration( false ); // true means interleaved mode, false is for normal mode
194
198
195 updateLFRCurrentMode( LFR_MODE_STANDBY );
199 updateLFRCurrentMode( LFR_MODE_STANDBY );
196
200
197 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
201 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
198
202
199 create_names(); // create all names
203 create_names(); // create all names
200
204
201 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
205 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
202 if (status != RTEMS_SUCCESSFUL)
206 if (status != RTEMS_SUCCESSFUL)
203 {
207 {
204 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
208 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
205 }
209 }
206
210
207 status = create_message_queues(); // create message queues
211 status = create_message_queues(); // create message queues
208 if (status != RTEMS_SUCCESSFUL)
212 if (status != RTEMS_SUCCESSFUL)
209 {
213 {
210 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
214 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
211 }
215 }
212
216
213 status = create_all_tasks(); // create all tasks
217 status = create_all_tasks(); // create all tasks
214 if (status != RTEMS_SUCCESSFUL)
218 if (status != RTEMS_SUCCESSFUL)
215 {
219 {
216 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
220 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
217 }
221 }
218
222
219 // **************************
223 // **************************
220 // <SPACEWIRE INITIALIZATION>
224 // <SPACEWIRE INITIALIZATION>
221 status_spw = spacewire_open_link(); // (1) open the link
225 status_spw = spacewire_open_link(); // (1) open the link
222 if ( status_spw != RTEMS_SUCCESSFUL )
226 if ( status_spw != RTEMS_SUCCESSFUL )
223 {
227 {
224 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
228 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
225 }
229 }
226
230
227 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
231 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
228 {
232 {
229 status_spw = spacewire_configure_link( fdSPW );
233 status_spw = spacewire_configure_link( fdSPW );
230 if ( status_spw != RTEMS_SUCCESSFUL )
234 if ( status_spw != RTEMS_SUCCESSFUL )
231 {
235 {
232 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
236 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
233 }
237 }
234 }
238 }
235
239
236 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
240 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
237 {
241 {
238 status_spw = spacewire_start_link( fdSPW );
242 status_spw = spacewire_start_link( fdSPW );
239 if ( status_spw != RTEMS_SUCCESSFUL )
243 if ( status_spw != RTEMS_SUCCESSFUL )
240 {
244 {
241 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
245 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
242 }
246 }
243 }
247 }
244 // </SPACEWIRE INITIALIZATION>
248 // </SPACEWIRE INITIALIZATION>
245 // ***************************
249 // ***************************
246
250
247 status = start_all_tasks(); // start all tasks
251 status = start_all_tasks(); // start all tasks
248 if (status != RTEMS_SUCCESSFUL)
252 if (status != RTEMS_SUCCESSFUL)
249 {
253 {
250 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
254 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
251 }
255 }
252
256
253 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
257 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
254 status = start_recv_send_tasks();
258 status = start_recv_send_tasks();
255 if ( status != RTEMS_SUCCESSFUL )
259 if ( status != RTEMS_SUCCESSFUL )
256 {
260 {
257 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
261 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
258 }
262 }
259
263
260 // suspend science tasks, they will be restarted later depending on the mode
264 // suspend science tasks, they will be restarted later depending on the mode
261 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
265 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
262 if (status != RTEMS_SUCCESSFUL)
266 if (status != RTEMS_SUCCESSFUL)
263 {
267 {
264 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
268 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
265 }
269 }
266
270
267 // configure IRQ handling for the waveform picker unit
271 // configure IRQ handling for the waveform picker unit
268 status = rtems_interrupt_catch( waveforms_isr,
272 status = rtems_interrupt_catch( waveforms_isr,
269 IRQ_SPARC_WAVEFORM_PICKER,
273 IRQ_SPARC_WAVEFORM_PICKER,
270 &old_isr_handler) ;
274 &old_isr_handler) ;
271 // configure IRQ handling for the spectral matrices unit
275 // configure IRQ handling for the spectral matrices unit
272 status = rtems_interrupt_catch( spectral_matrices_isr,
276 status = rtems_interrupt_catch( spectral_matrices_isr,
273 IRQ_SPARC_SPECTRAL_MATRIX,
277 IRQ_SPARC_SPECTRAL_MATRIX,
274 &old_isr_handler) ;
278 &old_isr_handler) ;
275
279
276 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
280 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
277 if ( status_spw != RTEMS_SUCCESSFUL )
281 if ( status_spw != RTEMS_SUCCESSFUL )
278 {
282 {
279 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
283 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
280 if ( status != RTEMS_SUCCESSFUL ) {
284 if ( status != RTEMS_SUCCESSFUL ) {
281 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
285 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
282 }
286 }
283 }
287 }
284
288
285 BOOT_PRINTF("delete INIT\n")
289 BOOT_PRINTF("delete INIT\n")
286
290
287 set_hk_lfr_sc_potential_flag( true );
291 set_hk_lfr_sc_potential_flag( true );
288
292
289 // start the timer to detect a missing spacewire timecode
293 // start the timer to detect a missing spacewire timecode
290 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
294 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
291 // if a tickout is generated, the timer is restarted
295 // if a tickout is generated, the timer is restarted
292 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
296 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
293
297
294 grspw_timecode_callback = &timecode_irq_handler;
298 grspw_timecode_callback = &timecode_irq_handler;
295
299
296 status = rtems_task_delete(RTEMS_SELF);
300 status = rtems_task_delete(RTEMS_SELF);
297
301
298 }
302 }
299
303
300 void init_local_mode_parameters( void )
304 void init_local_mode_parameters( void )
301 {
305 {
302 /** This function initialize the param_local global variable with default values.
306 /** This function initialize the param_local global variable with default values.
303 *
307 *
304 */
308 */
305
309
306 unsigned int i;
310 unsigned int i;
307
311
308 // LOCAL PARAMETERS
312 // LOCAL PARAMETERS
309
313
310 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
314 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
311 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
315 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
312 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
316 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
313
317
314 // init sequence counters
318 // init sequence counters
315
319
316 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
320 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
317 {
321 {
318 sequenceCounters_TC_EXE[i] = 0x00;
322 sequenceCounters_TC_EXE[i] = 0x00;
319 sequenceCounters_TM_DUMP[i] = 0x00;
323 sequenceCounters_TM_DUMP[i] = 0x00;
320 }
324 }
321 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
325 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
322 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
326 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
323 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
327 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
324 }
328 }
325
329
326 void reset_local_time( void )
330 void reset_local_time( void )
327 {
331 {
328 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
332 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
329 }
333 }
330
334
331 void create_names( void ) // create all names for tasks and queues
335 void create_names( void ) // create all names for tasks and queues
332 {
336 {
333 /** This function creates all RTEMS names used in the software for tasks and queues.
337 /** This function creates all RTEMS names used in the software for tasks and queues.
334 *
338 *
335 * @return RTEMS directive status codes:
339 * @return RTEMS directive status codes:
336 * - RTEMS_SUCCESSFUL - successful completion
340 * - RTEMS_SUCCESSFUL - successful completion
337 *
341 *
338 */
342 */
339
343
340 // task names
344 // task names
341 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
345 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
342 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
346 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
343 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
347 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
344 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
348 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
345 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
349 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
346 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
350 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
347 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
351 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
348 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
352 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
349 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
353 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
350 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
354 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
351 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
355 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
352 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
356 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
353 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
357 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
354 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
358 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
355 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
359 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
356 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
360 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
357 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
361 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
358 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
362 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
359 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
363 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
360
364
361 // rate monotonic period names
365 // rate monotonic period names
362 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
366 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
363
367
364 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
368 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
365 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
369 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
366 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
370 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
367 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
371 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
368 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
372 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
369
373
370 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
374 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
371 }
375 }
372
376
373 int create_all_tasks( void ) // create all tasks which run in the software
377 int create_all_tasks( void ) // create all tasks which run in the software
374 {
378 {
375 /** This function creates all RTEMS tasks used in the software.
379 /** This function creates all RTEMS tasks used in the software.
376 *
380 *
377 * @return RTEMS directive status codes:
381 * @return RTEMS directive status codes:
378 * - RTEMS_SUCCESSFUL - task created successfully
382 * - RTEMS_SUCCESSFUL - task created successfully
379 * - RTEMS_INVALID_ADDRESS - id is NULL
383 * - RTEMS_INVALID_ADDRESS - id is NULL
380 * - RTEMS_INVALID_NAME - invalid task name
384 * - RTEMS_INVALID_NAME - invalid task name
381 * - RTEMS_INVALID_PRIORITY - invalid task priority
385 * - RTEMS_INVALID_PRIORITY - invalid task priority
382 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
386 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
383 * - RTEMS_TOO_MANY - too many tasks created
387 * - RTEMS_TOO_MANY - too many tasks created
384 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
388 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
385 * - RTEMS_TOO_MANY - too many global objects
389 * - RTEMS_TOO_MANY - too many global objects
386 *
390 *
387 */
391 */
388
392
389 rtems_status_code status;
393 rtems_status_code status;
390
394
391 //**********
395 //**********
392 // SPACEWIRE
396 // SPACEWIRE
393 // RECV
397 // RECV
394 status = rtems_task_create(
398 status = rtems_task_create(
395 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
399 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
396 RTEMS_DEFAULT_MODES,
400 RTEMS_DEFAULT_MODES,
397 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
401 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
398 );
402 );
399 if (status == RTEMS_SUCCESSFUL) // SEND
403 if (status == RTEMS_SUCCESSFUL) // SEND
400 {
404 {
401 status = rtems_task_create(
405 status = rtems_task_create(
402 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
406 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
403 RTEMS_DEFAULT_MODES,
407 RTEMS_DEFAULT_MODES,
404 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
408 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
405 );
409 );
406 }
410 }
407 if (status == RTEMS_SUCCESSFUL) // LINK
411 if (status == RTEMS_SUCCESSFUL) // LINK
408 {
412 {
409 status = rtems_task_create(
413 status = rtems_task_create(
410 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
414 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
411 RTEMS_DEFAULT_MODES,
415 RTEMS_DEFAULT_MODES,
412 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
416 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
413 );
417 );
414 }
418 }
415 if (status == RTEMS_SUCCESSFUL) // ACTN
419 if (status == RTEMS_SUCCESSFUL) // ACTN
416 {
420 {
417 status = rtems_task_create(
421 status = rtems_task_create(
418 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
422 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
419 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
423 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
420 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
424 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
421 );
425 );
422 }
426 }
423 if (status == RTEMS_SUCCESSFUL) // SPIQ
427 if (status == RTEMS_SUCCESSFUL) // SPIQ
424 {
428 {
425 status = rtems_task_create(
429 status = rtems_task_create(
426 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
430 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
427 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
431 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
428 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
432 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
429 );
433 );
430 }
434 }
431
435
432 //******************
436 //******************
433 // SPECTRAL MATRICES
437 // SPECTRAL MATRICES
434 if (status == RTEMS_SUCCESSFUL) // AVF0
438 if (status == RTEMS_SUCCESSFUL) // AVF0
435 {
439 {
436 status = rtems_task_create(
440 status = rtems_task_create(
437 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
441 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
438 RTEMS_DEFAULT_MODES,
442 RTEMS_DEFAULT_MODES,
439 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
443 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
440 );
444 );
441 }
445 }
442 if (status == RTEMS_SUCCESSFUL) // PRC0
446 if (status == RTEMS_SUCCESSFUL) // PRC0
443 {
447 {
444 status = rtems_task_create(
448 status = rtems_task_create(
445 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
449 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
446 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
450 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
447 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
451 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
448 );
452 );
449 }
453 }
450 if (status == RTEMS_SUCCESSFUL) // AVF1
454 if (status == RTEMS_SUCCESSFUL) // AVF1
451 {
455 {
452 status = rtems_task_create(
456 status = rtems_task_create(
453 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
457 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
454 RTEMS_DEFAULT_MODES,
458 RTEMS_DEFAULT_MODES,
455 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
459 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
456 );
460 );
457 }
461 }
458 if (status == RTEMS_SUCCESSFUL) // PRC1
462 if (status == RTEMS_SUCCESSFUL) // PRC1
459 {
463 {
460 status = rtems_task_create(
464 status = rtems_task_create(
461 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
465 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
462 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
466 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
463 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
467 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
464 );
468 );
465 }
469 }
466 if (status == RTEMS_SUCCESSFUL) // AVF2
470 if (status == RTEMS_SUCCESSFUL) // AVF2
467 {
471 {
468 status = rtems_task_create(
472 status = rtems_task_create(
469 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
473 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
470 RTEMS_DEFAULT_MODES,
474 RTEMS_DEFAULT_MODES,
471 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
475 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
472 );
476 );
473 }
477 }
474 if (status == RTEMS_SUCCESSFUL) // PRC2
478 if (status == RTEMS_SUCCESSFUL) // PRC2
475 {
479 {
476 status = rtems_task_create(
480 status = rtems_task_create(
477 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
481 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
478 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
482 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
479 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
483 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
480 );
484 );
481 }
485 }
482
486
483 //****************
487 //****************
484 // WAVEFORM PICKER
488 // WAVEFORM PICKER
485 if (status == RTEMS_SUCCESSFUL) // WFRM
489 if (status == RTEMS_SUCCESSFUL) // WFRM
486 {
490 {
487 status = rtems_task_create(
491 status = rtems_task_create(
488 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
492 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
489 RTEMS_DEFAULT_MODES,
493 RTEMS_DEFAULT_MODES,
490 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
494 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
491 );
495 );
492 }
496 }
493 if (status == RTEMS_SUCCESSFUL) // CWF3
497 if (status == RTEMS_SUCCESSFUL) // CWF3
494 {
498 {
495 status = rtems_task_create(
499 status = rtems_task_create(
496 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
500 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
497 RTEMS_DEFAULT_MODES,
501 RTEMS_DEFAULT_MODES,
498 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
502 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
499 );
503 );
500 }
504 }
501 if (status == RTEMS_SUCCESSFUL) // CWF2
505 if (status == RTEMS_SUCCESSFUL) // CWF2
502 {
506 {
503 status = rtems_task_create(
507 status = rtems_task_create(
504 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
508 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
505 RTEMS_DEFAULT_MODES,
509 RTEMS_DEFAULT_MODES,
506 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
510 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
507 );
511 );
508 }
512 }
509 if (status == RTEMS_SUCCESSFUL) // CWF1
513 if (status == RTEMS_SUCCESSFUL) // CWF1
510 {
514 {
511 status = rtems_task_create(
515 status = rtems_task_create(
512 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
516 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
513 RTEMS_DEFAULT_MODES,
517 RTEMS_DEFAULT_MODES,
514 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
518 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
515 );
519 );
516 }
520 }
517 if (status == RTEMS_SUCCESSFUL) // SWBD
521 if (status == RTEMS_SUCCESSFUL) // SWBD
518 {
522 {
519 status = rtems_task_create(
523 status = rtems_task_create(
520 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
524 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
521 RTEMS_DEFAULT_MODES,
525 RTEMS_DEFAULT_MODES,
522 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
526 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
523 );
527 );
524 }
528 }
525
529
526 //*****
530 //*****
527 // MISC
531 // MISC
528 if (status == RTEMS_SUCCESSFUL) // LOAD
532 if (status == RTEMS_SUCCESSFUL) // LOAD
529 {
533 {
530 status = rtems_task_create(
534 status = rtems_task_create(
531 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
535 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
532 RTEMS_DEFAULT_MODES,
536 RTEMS_DEFAULT_MODES,
533 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
537 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
534 );
538 );
535 }
539 }
536 if (status == RTEMS_SUCCESSFUL) // DUMB
540 if (status == RTEMS_SUCCESSFUL) // DUMB
537 {
541 {
538 status = rtems_task_create(
542 status = rtems_task_create(
539 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
543 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
540 RTEMS_DEFAULT_MODES,
544 RTEMS_DEFAULT_MODES,
541 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
545 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
542 );
546 );
543 }
547 }
544 if (status == RTEMS_SUCCESSFUL) // HOUS
548 if (status == RTEMS_SUCCESSFUL) // HOUS
545 {
549 {
546 status = rtems_task_create(
550 status = rtems_task_create(
547 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
551 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
548 RTEMS_DEFAULT_MODES,
552 RTEMS_DEFAULT_MODES,
549 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
553 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
550 );
554 );
551 }
555 }
552
556
553 return status;
557 return status;
554 }
558 }
555
559
556 int start_recv_send_tasks( void )
560 int start_recv_send_tasks( void )
557 {
561 {
558 rtems_status_code status;
562 rtems_status_code status;
559
563
560 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
564 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
561 if (status!=RTEMS_SUCCESSFUL) {
565 if (status!=RTEMS_SUCCESSFUL) {
562 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
566 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
563 }
567 }
564
568
565 if (status == RTEMS_SUCCESSFUL) // SEND
569 if (status == RTEMS_SUCCESSFUL) // SEND
566 {
570 {
567 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
571 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
568 if (status!=RTEMS_SUCCESSFUL) {
572 if (status!=RTEMS_SUCCESSFUL) {
569 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
573 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
570 }
574 }
571 }
575 }
572
576
573 return status;
577 return status;
574 }
578 }
575
579
576 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
580 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
577 {
581 {
578 /** This function starts all RTEMS tasks used in the software.
582 /** This function starts all RTEMS tasks used in the software.
579 *
583 *
580 * @return RTEMS directive status codes:
584 * @return RTEMS directive status codes:
581 * - RTEMS_SUCCESSFUL - ask started successfully
585 * - RTEMS_SUCCESSFUL - ask started successfully
582 * - RTEMS_INVALID_ADDRESS - invalid task entry point
586 * - RTEMS_INVALID_ADDRESS - invalid task entry point
583 * - RTEMS_INVALID_ID - invalid task id
587 * - RTEMS_INVALID_ID - invalid task id
584 * - RTEMS_INCORRECT_STATE - task not in the dormant state
588 * - RTEMS_INCORRECT_STATE - task not in the dormant state
585 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
589 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
586 *
590 *
587 */
591 */
588 // starts all the tasks fot eh flight software
592 // starts all the tasks fot eh flight software
589
593
590 rtems_status_code status;
594 rtems_status_code status;
591
595
592 //**********
596 //**********
593 // SPACEWIRE
597 // SPACEWIRE
594 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
598 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
595 if (status!=RTEMS_SUCCESSFUL) {
599 if (status!=RTEMS_SUCCESSFUL) {
596 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
600 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
597 }
601 }
598
602
599 if (status == RTEMS_SUCCESSFUL) // LINK
603 if (status == RTEMS_SUCCESSFUL) // LINK
600 {
604 {
601 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
605 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
602 if (status!=RTEMS_SUCCESSFUL) {
606 if (status!=RTEMS_SUCCESSFUL) {
603 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
607 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
604 }
608 }
605 }
609 }
606
610
607 if (status == RTEMS_SUCCESSFUL) // ACTN
611 if (status == RTEMS_SUCCESSFUL) // ACTN
608 {
612 {
609 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
613 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
610 if (status!=RTEMS_SUCCESSFUL) {
614 if (status!=RTEMS_SUCCESSFUL) {
611 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
615 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
612 }
616 }
613 }
617 }
614
618
615 //******************
619 //******************
616 // SPECTRAL MATRICES
620 // SPECTRAL MATRICES
617 if (status == RTEMS_SUCCESSFUL) // AVF0
621 if (status == RTEMS_SUCCESSFUL) // AVF0
618 {
622 {
619 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
623 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
620 if (status!=RTEMS_SUCCESSFUL) {
624 if (status!=RTEMS_SUCCESSFUL) {
621 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
625 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
622 }
626 }
623 }
627 }
624 if (status == RTEMS_SUCCESSFUL) // PRC0
628 if (status == RTEMS_SUCCESSFUL) // PRC0
625 {
629 {
626 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
630 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
627 if (status!=RTEMS_SUCCESSFUL) {
631 if (status!=RTEMS_SUCCESSFUL) {
628 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
632 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
629 }
633 }
630 }
634 }
631 if (status == RTEMS_SUCCESSFUL) // AVF1
635 if (status == RTEMS_SUCCESSFUL) // AVF1
632 {
636 {
633 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
637 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
634 if (status!=RTEMS_SUCCESSFUL) {
638 if (status!=RTEMS_SUCCESSFUL) {
635 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
639 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
636 }
640 }
637 }
641 }
638 if (status == RTEMS_SUCCESSFUL) // PRC1
642 if (status == RTEMS_SUCCESSFUL) // PRC1
639 {
643 {
640 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
644 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
641 if (status!=RTEMS_SUCCESSFUL) {
645 if (status!=RTEMS_SUCCESSFUL) {
642 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
646 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
643 }
647 }
644 }
648 }
645 if (status == RTEMS_SUCCESSFUL) // AVF2
649 if (status == RTEMS_SUCCESSFUL) // AVF2
646 {
650 {
647 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
651 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
648 if (status!=RTEMS_SUCCESSFUL) {
652 if (status!=RTEMS_SUCCESSFUL) {
649 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
653 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
650 }
654 }
651 }
655 }
652 if (status == RTEMS_SUCCESSFUL) // PRC2
656 if (status == RTEMS_SUCCESSFUL) // PRC2
653 {
657 {
654 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
658 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
655 if (status!=RTEMS_SUCCESSFUL) {
659 if (status!=RTEMS_SUCCESSFUL) {
656 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
660 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
657 }
661 }
658 }
662 }
659
663
660 //****************
664 //****************
661 // WAVEFORM PICKER
665 // WAVEFORM PICKER
662 if (status == RTEMS_SUCCESSFUL) // WFRM
666 if (status == RTEMS_SUCCESSFUL) // WFRM
663 {
667 {
664 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
668 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
665 if (status!=RTEMS_SUCCESSFUL) {
669 if (status!=RTEMS_SUCCESSFUL) {
666 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
670 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
667 }
671 }
668 }
672 }
669 if (status == RTEMS_SUCCESSFUL) // CWF3
673 if (status == RTEMS_SUCCESSFUL) // CWF3
670 {
674 {
671 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
675 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
672 if (status!=RTEMS_SUCCESSFUL) {
676 if (status!=RTEMS_SUCCESSFUL) {
673 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
677 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
674 }
678 }
675 }
679 }
676 if (status == RTEMS_SUCCESSFUL) // CWF2
680 if (status == RTEMS_SUCCESSFUL) // CWF2
677 {
681 {
678 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
682 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
679 if (status!=RTEMS_SUCCESSFUL) {
683 if (status!=RTEMS_SUCCESSFUL) {
680 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
684 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
681 }
685 }
682 }
686 }
683 if (status == RTEMS_SUCCESSFUL) // CWF1
687 if (status == RTEMS_SUCCESSFUL) // CWF1
684 {
688 {
685 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
689 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
686 if (status!=RTEMS_SUCCESSFUL) {
690 if (status!=RTEMS_SUCCESSFUL) {
687 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
691 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
688 }
692 }
689 }
693 }
690 if (status == RTEMS_SUCCESSFUL) // SWBD
694 if (status == RTEMS_SUCCESSFUL) // SWBD
691 {
695 {
692 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
696 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
693 if (status!=RTEMS_SUCCESSFUL) {
697 if (status!=RTEMS_SUCCESSFUL) {
694 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
698 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
695 }
699 }
696 }
700 }
697
701
698 //*****
702 //*****
699 // MISC
703 // MISC
700 if (status == RTEMS_SUCCESSFUL) // HOUS
704 if (status == RTEMS_SUCCESSFUL) // HOUS
701 {
705 {
702 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
706 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
703 if (status!=RTEMS_SUCCESSFUL) {
707 if (status!=RTEMS_SUCCESSFUL) {
704 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
708 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
705 }
709 }
706 }
710 }
707 if (status == RTEMS_SUCCESSFUL) // DUMB
711 if (status == RTEMS_SUCCESSFUL) // DUMB
708 {
712 {
709 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
713 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
710 if (status!=RTEMS_SUCCESSFUL) {
714 if (status!=RTEMS_SUCCESSFUL) {
711 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
715 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
712 }
716 }
713 }
717 }
714 if (status == RTEMS_SUCCESSFUL) // LOAD
718 if (status == RTEMS_SUCCESSFUL) // LOAD
715 {
719 {
716 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
720 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
717 if (status!=RTEMS_SUCCESSFUL) {
721 if (status!=RTEMS_SUCCESSFUL) {
718 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
722 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
719 }
723 }
720 }
724 }
721
725
722 return status;
726 return status;
723 }
727 }
724
728
725 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
729 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
726 {
730 {
727 rtems_status_code status_recv;
731 rtems_status_code status_recv;
728 rtems_status_code status_send;
732 rtems_status_code status_send;
729 rtems_status_code status_q_p0;
733 rtems_status_code status_q_p0;
730 rtems_status_code status_q_p1;
734 rtems_status_code status_q_p1;
731 rtems_status_code status_q_p2;
735 rtems_status_code status_q_p2;
732 rtems_status_code ret;
736 rtems_status_code ret;
733 rtems_id queue_id;
737 rtems_id queue_id;
734
738
735 //****************************************
739 //****************************************
736 // create the queue for handling valid TCs
740 // create the queue for handling valid TCs
737 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
741 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
738 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
742 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
739 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
743 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
740 if ( status_recv != RTEMS_SUCCESSFUL ) {
744 if ( status_recv != RTEMS_SUCCESSFUL ) {
741 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
745 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
742 }
746 }
743
747
744 //************************************************
748 //************************************************
745 // create the queue for handling TM packet sending
749 // create the queue for handling TM packet sending
746 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
750 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
747 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
751 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
748 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
752 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
749 if ( status_send != RTEMS_SUCCESSFUL ) {
753 if ( status_send != RTEMS_SUCCESSFUL ) {
750 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
754 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
751 }
755 }
752
756
753 //*****************************************************************************
757 //*****************************************************************************
754 // create the queue for handling averaged spectral matrices for processing @ f0
758 // create the queue for handling averaged spectral matrices for processing @ f0
755 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
759 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
756 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
760 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
757 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
761 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
758 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
762 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
759 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
763 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
760 }
764 }
761
765
762 //*****************************************************************************
766 //*****************************************************************************
763 // create the queue for handling averaged spectral matrices for processing @ f1
767 // create the queue for handling averaged spectral matrices for processing @ f1
764 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
768 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
765 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
769 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
766 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
770 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
767 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
771 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
768 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
772 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
769 }
773 }
770
774
771 //*****************************************************************************
775 //*****************************************************************************
772 // create the queue for handling averaged spectral matrices for processing @ f2
776 // create the queue for handling averaged spectral matrices for processing @ f2
773 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
777 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
774 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
778 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
775 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
779 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
776 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
780 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
777 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
781 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
778 }
782 }
779
783
780 if ( status_recv != RTEMS_SUCCESSFUL )
784 if ( status_recv != RTEMS_SUCCESSFUL )
781 {
785 {
782 ret = status_recv;
786 ret = status_recv;
783 }
787 }
784 else if( status_send != RTEMS_SUCCESSFUL )
788 else if( status_send != RTEMS_SUCCESSFUL )
785 {
789 {
786 ret = status_send;
790 ret = status_send;
787 }
791 }
788 else if( status_q_p0 != RTEMS_SUCCESSFUL )
792 else if( status_q_p0 != RTEMS_SUCCESSFUL )
789 {
793 {
790 ret = status_q_p0;
794 ret = status_q_p0;
791 }
795 }
792 else if( status_q_p1 != RTEMS_SUCCESSFUL )
796 else if( status_q_p1 != RTEMS_SUCCESSFUL )
793 {
797 {
794 ret = status_q_p1;
798 ret = status_q_p1;
795 }
799 }
796 else
800 else
797 {
801 {
798 ret = status_q_p2;
802 ret = status_q_p2;
799 }
803 }
800
804
801 return ret;
805 return ret;
802 }
806 }
803
807
804 rtems_status_code create_timecode_timer( void )
808 rtems_status_code create_timecode_timer( void )
805 {
809 {
806 rtems_status_code status;
810 rtems_status_code status;
807
811
808 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
812 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
809
813
810 if ( status != RTEMS_SUCCESSFUL )
814 if ( status != RTEMS_SUCCESSFUL )
811 {
815 {
812 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
816 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
813 }
817 }
814 else
818 else
815 {
819 {
816 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
820 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
817 }
821 }
818
822
819 return status;
823 return status;
820 }
824 }
821
825
822 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
826 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
823 {
827 {
824 rtems_status_code status;
828 rtems_status_code status;
825 rtems_name queue_name;
829 rtems_name queue_name;
826
830
827 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
831 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
828
832
829 status = rtems_message_queue_ident( queue_name, 0, queue_id );
833 status = rtems_message_queue_ident( queue_name, 0, queue_id );
830
834
831 return status;
835 return status;
832 }
836 }
833
837
834 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
838 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
835 {
839 {
836 rtems_status_code status;
840 rtems_status_code status;
837 rtems_name queue_name;
841 rtems_name queue_name;
838
842
839 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
843 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
840
844
841 status = rtems_message_queue_ident( queue_name, 0, queue_id );
845 status = rtems_message_queue_ident( queue_name, 0, queue_id );
842
846
843 return status;
847 return status;
844 }
848 }
845
849
846 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
850 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
847 {
851 {
848 rtems_status_code status;
852 rtems_status_code status;
849 rtems_name queue_name;
853 rtems_name queue_name;
850
854
851 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
855 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
852
856
853 status = rtems_message_queue_ident( queue_name, 0, queue_id );
857 status = rtems_message_queue_ident( queue_name, 0, queue_id );
854
858
855 return status;
859 return status;
856 }
860 }
857
861
858 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
862 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
859 {
863 {
860 rtems_status_code status;
864 rtems_status_code status;
861 rtems_name queue_name;
865 rtems_name queue_name;
862
866
863 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
867 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
864
868
865 status = rtems_message_queue_ident( queue_name, 0, queue_id );
869 status = rtems_message_queue_ident( queue_name, 0, queue_id );
866
870
867 return status;
871 return status;
868 }
872 }
869
873
870 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
874 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
871 {
875 {
872 rtems_status_code status;
876 rtems_status_code status;
873 rtems_name queue_name;
877 rtems_name queue_name;
874
878
875 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
879 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
876
880
877 status = rtems_message_queue_ident( queue_name, 0, queue_id );
881 status = rtems_message_queue_ident( queue_name, 0, queue_id );
878
882
879 return status;
883 return status;
880 }
884 }
881
885
882 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
886 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
883 {
887 {
884 u_int32_t count;
888 u_int32_t count;
885 rtems_status_code status;
889 rtems_status_code status;
886
890
887 status = rtems_message_queue_get_number_pending( queue_id, &count );
891 status = rtems_message_queue_get_number_pending( queue_id, &count );
888
892
889 count = count + 1;
893 count = count + 1;
890
894
891 if (status != RTEMS_SUCCESSFUL)
895 if (status != RTEMS_SUCCESSFUL)
892 {
896 {
893 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
897 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
894 }
898 }
895 else
899 else
896 {
900 {
897 if (count > *fifo_size_max)
901 if (count > *fifo_size_max)
898 {
902 {
899 *fifo_size_max = count;
903 *fifo_size_max = count;
900 }
904 }
901 }
905 }
902 }
906 }
903
907
904 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
908 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
905 {
909 {
906 unsigned char i;
910 unsigned char i;
907
911
908 //***************
912 //***************
909 // BUFFER ADDRESS
913 // BUFFER ADDRESS
910 for(i=0; i<nbNodes; i++)
914 for(i=0; i<nbNodes; i++)
911 {
915 {
912 ring[i].coarseTime = 0xffffffff;
916 ring[i].coarseTime = 0xffffffff;
913 ring[i].fineTime = 0xffffffff;
917 ring[i].fineTime = 0xffffffff;
914 ring[i].sid = 0x00;
918 ring[i].sid = 0x00;
915 ring[i].status = 0x00;
919 ring[i].status = 0x00;
916 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
920 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
917 }
921 }
918
922
919 //*****
923 //*****
920 // NEXT
924 // NEXT
921 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
925 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
922 for(i=0; i<nbNodes-1; i++)
926 for(i=0; i<nbNodes-1; i++)
923 {
927 {
924 ring[i].next = (ring_node*) &ring[ i + 1 ];
928 ring[i].next = (ring_node*) &ring[ i + 1 ];
925 }
929 }
926
930
927 //*********
931 //*********
928 // PREVIOUS
932 // PREVIOUS
929 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
933 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
930 for(i=1; i<nbNodes; i++)
934 for(i=1; i<nbNodes; i++)
931 {
935 {
932 ring[i].previous = (ring_node*) &ring[ i - 1 ];
936 ring[i].previous = (ring_node*) &ring[ i - 1 ];
933 }
937 }
934 }
938 }
@@ -1,801 +1,813
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29
29
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 if (status!=RTEMS_SUCCESSFUL)
31 if (status!=RTEMS_SUCCESSFUL)
32 {
32 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
34 }
35
35
36 timer_set_clock_divider( timer, clock_divider);
36 timer_set_clock_divider( timer, clock_divider);
37 }
37 }
38
38
39 void timer_start(unsigned char timer)
39 void timer_start(unsigned char timer)
40 {
40 {
41 /** This function starts a GPTIMER timer.
41 /** This function starts a GPTIMER timer.
42 *
42 *
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 *
45 *
46 */
46 */
47
47
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 }
53 }
54
54
55 void timer_stop(unsigned char timer)
55 void timer_stop(unsigned char timer)
56 {
56 {
57 /** This function stops a GPTIMER timer.
57 /** This function stops a GPTIMER timer.
58 *
58 *
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 *
61 *
62 */
62 */
63
63
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 }
67 }
68
68
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
70 {
70 {
71 /** This function sets the clock divider of a GPTIMER timer.
71 /** This function sets the clock divider of a GPTIMER timer.
72 *
72 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
76 *
77 */
77 */
78
78
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
80 }
81
81
82 // WATCHDOG
82 // WATCHDOG
83
83
84 rtems_isr watchdog_isr( rtems_vector_number vector )
84 rtems_isr watchdog_isr( rtems_vector_number vector )
85 {
85 {
86 rtems_status_code status_code;
86 rtems_status_code status_code;
87
87
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
89
89
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
91
91
92 exit(0);
92 exit(0);
93 }
93 }
94
94
95 void watchdog_configure(void)
95 void watchdog_configure(void)
96 {
96 {
97 /** This function configure the watchdog.
97 /** This function configure the watchdog.
98 *
98 *
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
101 *
101 *
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
103 *
103 *
104 */
104 */
105
105
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
107
107
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
109
109
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
111 }
111 }
112
112
113 void watchdog_stop(void)
113 void watchdog_stop(void)
114 {
114 {
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
116 timer_stop( TIMER_WATCHDOG );
116 timer_stop( TIMER_WATCHDOG );
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
118 }
118 }
119
119
120 void watchdog_reload(void)
120 void watchdog_reload(void)
121 {
121 {
122 /** This function reloads the watchdog timer counter with the timer reload value.
122 /** This function reloads the watchdog timer counter with the timer reload value.
123 *
123 *
124 * @param void
124 * @param void
125 *
125 *
126 * @return void
126 * @return void
127 *
127 *
128 */
128 */
129
129
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
131 }
131 }
132
132
133 void watchdog_start(void)
133 void watchdog_start(void)
134 {
134 {
135 /** This function starts the watchdog timer.
135 /** This function starts the watchdog timer.
136 *
136 *
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
139 *
139 *
140 */
140 */
141
141
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
143
143
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000010; // clear pending IRQ if any
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000010; // clear pending IRQ if any
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000001; // EN enable the timer
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000001; // EN enable the timer
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000008; // IE interrupt enable
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000008; // IE interrupt enable
148
148
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
150
150
151 }
151 }
152
152
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
154 {
154 {
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
156
156
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
158
158
159 return 0;
159 return 0;
160 }
160 }
161
161
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
163 {
163 {
164 /** This function sets the scaler reload register of the apbuart module
164 /** This function sets the scaler reload register of the apbuart module
165 *
165 *
166 * @param regs is the address of the apbuart registers in memory
166 * @param regs is the address of the apbuart registers in memory
167 * @param value is the value that will be stored in the scaler register
167 * @param value is the value that will be stored in the scaler register
168 *
168 *
169 * The value shall be set by the software to get data on the serial interface.
169 * The value shall be set by the software to get data on the serial interface.
170 *
170 *
171 */
171 */
172
172
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
174
174
175 apbuart_regs->scaler = value;
175 apbuart_regs->scaler = value;
176
176
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
178 }
178 }
179
179
180 //************
180 //************
181 // RTEMS TASKS
181 // RTEMS TASKS
182
182
183 rtems_task load_task(rtems_task_argument argument)
183 rtems_task load_task(rtems_task_argument argument)
184 {
184 {
185 BOOT_PRINTF("in LOAD *** \n")
185 BOOT_PRINTF("in LOAD *** \n")
186
186
187 rtems_status_code status;
187 rtems_status_code status;
188 unsigned int i;
188 unsigned int i;
189 unsigned int j;
189 unsigned int j;
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
192
192
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
194
194
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
196 if( status != RTEMS_SUCCESSFUL ) {
196 if( status != RTEMS_SUCCESSFUL ) {
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
198 }
198 }
199
199
200 i = 0;
200 i = 0;
201 j = 0;
201 j = 0;
202
202
203 watchdog_configure();
203 watchdog_configure();
204
204
205 watchdog_start();
205 watchdog_start();
206
206
207 set_sy_lfr_watchdog_enabled( true );
207 set_sy_lfr_watchdog_enabled( true );
208
208
209 while(1){
209 while(1){
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
211 watchdog_reload();
211 watchdog_reload();
212 i = i + 1;
212 i = i + 1;
213 if ( i == 10 )
213 if ( i == 10 )
214 {
214 {
215 i = 0;
215 i = 0;
216 j = j + 1;
216 j = j + 1;
217 PRINTF1("%d\n", j)
217 PRINTF1("%d\n", j)
218 }
218 }
219 #ifdef DEBUG_WATCHDOG
219 #ifdef DEBUG_WATCHDOG
220 if (j == 3 )
220 if (j == 3 )
221 {
221 {
222 status = rtems_task_delete(RTEMS_SELF);
222 status = rtems_task_delete(RTEMS_SELF);
223 }
223 }
224 #endif
224 #endif
225 }
225 }
226 }
226 }
227
227
228 rtems_task hous_task(rtems_task_argument argument)
228 rtems_task hous_task(rtems_task_argument argument)
229 {
229 {
230 rtems_status_code status;
230 rtems_status_code status;
231 rtems_status_code spare_status;
231 rtems_status_code spare_status;
232 rtems_id queue_id;
232 rtems_id queue_id;
233 rtems_rate_monotonic_period_status period_status;
233 rtems_rate_monotonic_period_status period_status;
234
234
235 status = get_message_queue_id_send( &queue_id );
235 status = get_message_queue_id_send( &queue_id );
236 if (status != RTEMS_SUCCESSFUL)
236 if (status != RTEMS_SUCCESSFUL)
237 {
237 {
238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
239 }
239 }
240
240
241 BOOT_PRINTF("in HOUS ***\n");
241 BOOT_PRINTF("in HOUS ***\n");
242
242
243 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
243 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
244 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
244 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
245 if( status != RTEMS_SUCCESSFUL ) {
245 if( status != RTEMS_SUCCESSFUL ) {
246 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
246 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
247 }
247 }
248 }
248 }
249
249
250 status = rtems_rate_monotonic_cancel(HK_id);
250 status = rtems_rate_monotonic_cancel(HK_id);
251 if( status != RTEMS_SUCCESSFUL ) {
251 if( status != RTEMS_SUCCESSFUL ) {
252 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
252 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
253 }
253 }
254 else {
254 else {
255 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
255 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
256 }
256 }
257
257
258 // startup phase
258 // startup phase
259 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
259 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
260 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
260 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
261 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
261 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
262 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
262 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
263 {
263 {
264 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
264 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
265 {
265 {
266 break; // break if LFR is synchronized
266 break; // break if LFR is synchronized
267 }
267 }
268 else
268 else
269 {
269 {
270 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
270 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
271 // sched_yield();
271 // sched_yield();
272 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
272 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
273 }
273 }
274 }
274 }
275 status = rtems_rate_monotonic_cancel(HK_id);
275 status = rtems_rate_monotonic_cancel(HK_id);
276 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
276 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
277
277
278 set_hk_lfr_reset_cause( POWER_ON );
278 set_hk_lfr_reset_cause( POWER_ON );
279
279
280 while(1){ // launch the rate monotonic task
280 while(1){ // launch the rate monotonic task
281 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
281 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
282 if ( status != RTEMS_SUCCESSFUL ) {
282 if ( status != RTEMS_SUCCESSFUL ) {
283 PRINTF1( "in HOUS *** ERR period: %d\n", status);
283 PRINTF1( "in HOUS *** ERR period: %d\n", status);
284 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
284 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
285 }
285 }
286 else {
286 else {
287 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
287 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
288 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
288 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
289 increment_seq_counter( &sequenceCounterHK );
289 increment_seq_counter( &sequenceCounterHK );
290
290
291 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
291 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
292 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
292 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
293 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
293 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
294 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
294 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
295 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
295 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
296 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
296 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
297
297
298 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
298 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
299
299
300 spacewire_read_statistics();
300 spacewire_read_statistics();
301
301
302 update_hk_with_grspw_stats();
302 update_hk_with_grspw_stats();
303
303
304 set_hk_lfr_time_not_synchro();
304 set_hk_lfr_time_not_synchro();
305
305
306 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
306 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
307 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
307 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
308 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
308 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
309 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
309 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
310 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
310 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
311
311
312 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
312 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
313 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
313 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
314 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
315 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
315 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
316 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
316 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
317
317
318 hk_lfr_le_me_he_update();
318 hk_lfr_le_me_he_update();
319
319
320 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
320 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
321
321
322 // SEND PACKET
322 // SEND PACKET
323 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
323 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
324 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
324 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
325 if (status != RTEMS_SUCCESSFUL) {
325 if (status != RTEMS_SUCCESSFUL) {
326 PRINTF1("in HOUS *** ERR send: %d\n", status)
326 PRINTF1("in HOUS *** ERR send: %d\n", status)
327 }
327 }
328 }
328 }
329 }
329 }
330
330
331 PRINTF("in HOUS *** deleting task\n")
331 PRINTF("in HOUS *** deleting task\n")
332
332
333 status = rtems_task_delete( RTEMS_SELF ); // should not return
333 status = rtems_task_delete( RTEMS_SELF ); // should not return
334
334
335 return;
335 return;
336 }
336 }
337
337
338 rtems_task dumb_task( rtems_task_argument unused )
338 rtems_task dumb_task( rtems_task_argument unused )
339 {
339 {
340 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
340 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
341 *
341 *
342 * @param unused is the starting argument of the RTEMS task
342 * @param unused is the starting argument of the RTEMS task
343 *
343 *
344 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
344 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
345 *
345 *
346 */
346 */
347
347
348 unsigned int i;
348 unsigned int i;
349 unsigned int intEventOut;
349 unsigned int intEventOut;
350 unsigned int coarse_time = 0;
350 unsigned int coarse_time = 0;
351 unsigned int fine_time = 0;
351 unsigned int fine_time = 0;
352 rtems_event_set event_out;
352 rtems_event_set event_out;
353
353
354 char *DumbMessages[15] = {"in DUMB *** default", // RTEMS_EVENT_0
354 char *DumbMessages[15] = {"in DUMB *** default", // RTEMS_EVENT_0
355 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
355 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
356 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
356 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
357 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
357 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
358 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
358 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
359 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
359 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
360 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
360 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
361 "ready for dump", // RTEMS_EVENT_7
361 "ready for dump", // RTEMS_EVENT_7
362 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
362 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
363 "tick", // RTEMS_EVENT_9
363 "tick", // RTEMS_EVENT_9
364 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
364 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
365 "VHDL ERR *** unexpected ready matrix values", // RTEMS_EVENT_11
365 "VHDL ERR *** unexpected ready matrix values", // RTEMS_EVENT_11
366 "WATCHDOG timer", // RTEMS_EVENT_12
366 "WATCHDOG timer", // RTEMS_EVENT_12
367 "TIMECODE timer", // RTEMS_EVENT_13
367 "TIMECODE timer", // RTEMS_EVENT_13
368 "TIMECODE ISR" // RTEMS_EVENT_14
368 "TIMECODE ISR" // RTEMS_EVENT_14
369 };
369 };
370
370
371 BOOT_PRINTF("in DUMB *** \n")
371 BOOT_PRINTF("in DUMB *** \n")
372
372
373 while(1){
373 while(1){
374 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
374 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
375 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
375 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
376 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
376 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
377 | RTEMS_EVENT_14,
377 | RTEMS_EVENT_14,
378 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
378 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
379 intEventOut = (unsigned int) event_out;
379 intEventOut = (unsigned int) event_out;
380 for ( i=0; i<32; i++)
380 for ( i=0; i<32; i++)
381 {
381 {
382 if ( ((intEventOut >> i) & 0x0001) != 0)
382 if ( ((intEventOut >> i) & 0x0001) != 0)
383 {
383 {
384 coarse_time = time_management_regs->coarse_time;
384 coarse_time = time_management_regs->coarse_time;
385 fine_time = time_management_regs->fine_time;
385 fine_time = time_management_regs->fine_time;
386 if (i==12)
386 if (i==12)
387 {
387 {
388 PRINTF1("%s\n", DumbMessages[12])
388 PRINTF1("%s\n", DumbMessages[12])
389 }
389 }
390 if (i==13)
390 if (i==13)
391 {
391 {
392 PRINTF1("%s\n", DumbMessages[13])
392 PRINTF1("%s\n", DumbMessages[13])
393 }
393 }
394 if (i==14)
394 if (i==14)
395 {
395 {
396 PRINTF1("%s\n", DumbMessages[1])
396 PRINTF1("%s\n", DumbMessages[1])
397 }
397 }
398 }
398 }
399 }
399 }
400 }
400 }
401 }
401 }
402
402
403 //*****************************
403 //*****************************
404 // init housekeeping parameters
404 // init housekeeping parameters
405
405
406 void init_housekeeping_parameters( void )
406 void init_housekeeping_parameters( void )
407 {
407 {
408 /** This function initialize the housekeeping_packet global variable with default values.
408 /** This function initialize the housekeeping_packet global variable with default values.
409 *
409 *
410 */
410 */
411
411
412 unsigned int i = 0;
412 unsigned int i = 0;
413 unsigned char *parameters;
413 unsigned char *parameters;
414 unsigned char sizeOfHK;
414 unsigned char sizeOfHK;
415
415
416 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
416 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
417
417
418 parameters = (unsigned char*) &housekeeping_packet;
418 parameters = (unsigned char*) &housekeeping_packet;
419
419
420 for(i = 0; i< sizeOfHK; i++)
420 for(i = 0; i< sizeOfHK; i++)
421 {
421 {
422 parameters[i] = 0x00;
422 parameters[i] = 0x00;
423 }
423 }
424
424
425 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
425 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
426 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
426 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
427 housekeeping_packet.reserved = DEFAULT_RESERVED;
427 housekeeping_packet.reserved = DEFAULT_RESERVED;
428 housekeeping_packet.userApplication = CCSDS_USER_APP;
428 housekeeping_packet.userApplication = CCSDS_USER_APP;
429 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
429 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
430 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
430 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
431 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
431 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
432 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
432 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
433 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
433 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
434 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
434 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
435 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
435 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
436 housekeeping_packet.serviceType = TM_TYPE_HK;
436 housekeeping_packet.serviceType = TM_TYPE_HK;
437 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
437 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
438 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
438 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
439 housekeeping_packet.sid = SID_HK;
439 housekeeping_packet.sid = SID_HK;
440
440
441 // init status word
441 // init status word
442 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
442 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
443 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
443 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
444 // init software version
444 // init software version
445 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
445 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
446 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
446 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
447 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
447 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
448 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
448 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
449 // init fpga version
449 // init fpga version
450 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
450 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
451 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
451 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
452 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
452 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
453 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
453 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
454
454
455 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
455 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
456 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
456 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
457 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
457 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
458 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
458 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
459 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
459 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
460 }
460 }
461
461
462 void increment_seq_counter( unsigned short *packetSequenceControl )
462 void increment_seq_counter( unsigned short *packetSequenceControl )
463 {
463 {
464 /** This function increment the sequence counter passes in argument.
464 /** This function increment the sequence counter passes in argument.
465 *
465 *
466 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
466 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
467 *
467 *
468 */
468 */
469
469
470 unsigned short segmentation_grouping_flag;
470 unsigned short segmentation_grouping_flag;
471 unsigned short sequence_cnt;
471 unsigned short sequence_cnt;
472
472
473 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
473 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
474 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
474 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
475
475
476 if ( sequence_cnt < SEQ_CNT_MAX)
476 if ( sequence_cnt < SEQ_CNT_MAX)
477 {
477 {
478 sequence_cnt = sequence_cnt + 1;
478 sequence_cnt = sequence_cnt + 1;
479 }
479 }
480 else
480 else
481 {
481 {
482 sequence_cnt = 0;
482 sequence_cnt = 0;
483 }
483 }
484
484
485 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
485 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
486 }
486 }
487
487
488 void getTime( unsigned char *time)
488 void getTime( unsigned char *time)
489 {
489 {
490 /** This function write the current local time in the time buffer passed in argument.
490 /** This function write the current local time in the time buffer passed in argument.
491 *
491 *
492 */
492 */
493
493
494 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
494 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
495 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
495 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
496 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
496 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
497 time[3] = (unsigned char) (time_management_regs->coarse_time);
497 time[3] = (unsigned char) (time_management_regs->coarse_time);
498 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
498 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
499 time[5] = (unsigned char) (time_management_regs->fine_time);
499 time[5] = (unsigned char) (time_management_regs->fine_time);
500 }
500 }
501
501
502 unsigned long long int getTimeAsUnsignedLongLongInt( )
502 unsigned long long int getTimeAsUnsignedLongLongInt( )
503 {
503 {
504 /** This function write the current local time in the time buffer passed in argument.
504 /** This function write the current local time in the time buffer passed in argument.
505 *
505 *
506 */
506 */
507 unsigned long long int time;
507 unsigned long long int time;
508
508
509 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
509 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
510 + time_management_regs->fine_time;
510 + time_management_regs->fine_time;
511
511
512 return time;
512 return time;
513 }
513 }
514
514
515 void send_dumb_hk( void )
515 void send_dumb_hk( void )
516 {
516 {
517 Packet_TM_LFR_HK_t dummy_hk_packet;
517 Packet_TM_LFR_HK_t dummy_hk_packet;
518 unsigned char *parameters;
518 unsigned char *parameters;
519 unsigned int i;
519 unsigned int i;
520 rtems_id queue_id;
520 rtems_id queue_id;
521
521
522 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
522 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
523 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
523 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
524 dummy_hk_packet.reserved = DEFAULT_RESERVED;
524 dummy_hk_packet.reserved = DEFAULT_RESERVED;
525 dummy_hk_packet.userApplication = CCSDS_USER_APP;
525 dummy_hk_packet.userApplication = CCSDS_USER_APP;
526 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
526 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
527 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
527 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
528 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
528 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
529 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
529 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
530 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
530 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
531 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
531 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
532 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
532 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
533 dummy_hk_packet.serviceType = TM_TYPE_HK;
533 dummy_hk_packet.serviceType = TM_TYPE_HK;
534 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
534 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
535 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
535 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
536 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
536 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
537 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
537 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
538 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
538 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
539 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
539 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
540 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
540 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
541 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
541 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
542 dummy_hk_packet.sid = SID_HK;
542 dummy_hk_packet.sid = SID_HK;
543
543
544 // init status word
544 // init status word
545 dummy_hk_packet.lfr_status_word[0] = 0xff;
545 dummy_hk_packet.lfr_status_word[0] = 0xff;
546 dummy_hk_packet.lfr_status_word[1] = 0xff;
546 dummy_hk_packet.lfr_status_word[1] = 0xff;
547 // init software version
547 // init software version
548 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
548 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
549 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
549 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
550 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
550 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
551 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
551 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
552 // init fpga version
552 // init fpga version
553 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
553 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
554 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
554 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
555 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
555 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
556 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
556 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
557
557
558 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
558 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
559
559
560 for (i=0; i<100; i++)
560 for (i=0; i<100; i++)
561 {
561 {
562 parameters[i] = 0xff;
562 parameters[i] = 0xff;
563 }
563 }
564
564
565 get_message_queue_id_send( &queue_id );
565 get_message_queue_id_send( &queue_id );
566
566
567 rtems_message_queue_send( queue_id, &dummy_hk_packet,
567 rtems_message_queue_send( queue_id, &dummy_hk_packet,
568 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
568 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
569 }
569 }
570
570
571 void get_temperatures( unsigned char *temperatures )
571 void get_temperatures( unsigned char *temperatures )
572 {
572 {
573 unsigned char* temp_scm_ptr;
573 unsigned char* temp_scm_ptr;
574 unsigned char* temp_pcb_ptr;
574 unsigned char* temp_pcb_ptr;
575 unsigned char* temp_fpga_ptr;
575 unsigned char* temp_fpga_ptr;
576
576
577 // SEL1 SEL0
577 // SEL1 SEL0
578 // 0 0 => PCB
578 // 0 0 => PCB
579 // 0 1 => FPGA
579 // 0 1 => FPGA
580 // 1 0 => SCM
580 // 1 0 => SCM
581
581
582 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
582 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
583 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
583 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
584 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
584 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
585
585
586 temperatures[0] = temp_scm_ptr[2];
586 temperatures[0] = temp_scm_ptr[2];
587 temperatures[1] = temp_scm_ptr[3];
587 temperatures[1] = temp_scm_ptr[3];
588 temperatures[2] = temp_pcb_ptr[2];
588 temperatures[2] = temp_pcb_ptr[2];
589 temperatures[3] = temp_pcb_ptr[3];
589 temperatures[3] = temp_pcb_ptr[3];
590 temperatures[4] = temp_fpga_ptr[2];
590 temperatures[4] = temp_fpga_ptr[2];
591 temperatures[5] = temp_fpga_ptr[3];
591 temperatures[5] = temp_fpga_ptr[3];
592 }
592 }
593
593
594 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
594 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
595 {
595 {
596 unsigned char* v_ptr;
596 unsigned char* v_ptr;
597 unsigned char* e1_ptr;
597 unsigned char* e1_ptr;
598 unsigned char* e2_ptr;
598 unsigned char* e2_ptr;
599
599
600 v_ptr = (unsigned char *) &waveform_picker_regs->v;
600 v_ptr = (unsigned char *) &waveform_picker_regs->v;
601 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
601 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
602 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
602 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
603
603
604 spacecraft_potential[0] = v_ptr[2];
604 spacecraft_potential[0] = v_ptr[2];
605 spacecraft_potential[1] = v_ptr[3];
605 spacecraft_potential[1] = v_ptr[3];
606 spacecraft_potential[2] = e1_ptr[2];
606 spacecraft_potential[2] = e1_ptr[2];
607 spacecraft_potential[3] = e1_ptr[3];
607 spacecraft_potential[3] = e1_ptr[3];
608 spacecraft_potential[4] = e2_ptr[2];
608 spacecraft_potential[4] = e2_ptr[2];
609 spacecraft_potential[5] = e2_ptr[3];
609 spacecraft_potential[5] = e2_ptr[3];
610 }
610 }
611
611
612 void get_cpu_load( unsigned char *resource_statistics )
612 void get_cpu_load( unsigned char *resource_statistics )
613 {
613 {
614 unsigned char cpu_load;
614 unsigned char cpu_load;
615
615
616 cpu_load = lfr_rtems_cpu_usage_report();
616 cpu_load = lfr_rtems_cpu_usage_report();
617
617
618 // HK_LFR_CPU_LOAD
618 // HK_LFR_CPU_LOAD
619 resource_statistics[0] = cpu_load;
619 resource_statistics[0] = cpu_load;
620
620
621 // HK_LFR_CPU_LOAD_MAX
621 // HK_LFR_CPU_LOAD_MAX
622 if (cpu_load > resource_statistics[1])
622 if (cpu_load > resource_statistics[1])
623 {
623 {
624 resource_statistics[1] = cpu_load;
624 resource_statistics[1] = cpu_load;
625 }
625 }
626
626
627 // CPU_LOAD_AVE
627 // CPU_LOAD_AVE
628 resource_statistics[2] = 0;
628 resource_statistics[2] = 0;
629
629
630 #ifndef PRINT_TASK_STATISTICS
630 #ifndef PRINT_TASK_STATISTICS
631 rtems_cpu_usage_reset();
631 rtems_cpu_usage_reset();
632 #endif
632 #endif
633
633
634 }
634 }
635
635
636 void set_hk_lfr_sc_potential_flag( bool state )
636 void set_hk_lfr_sc_potential_flag( bool state )
637 {
637 {
638 if (state == true)
638 if (state == true)
639 {
639 {
640 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
640 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
641 }
641 }
642 else
642 else
643 {
643 {
644 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
644 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
645 }
645 }
646 }
646 }
647
647
648 void set_sy_lfr_pas_filter_enabled( bool state )
649 {
650 if (state == true)
651 {
652 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000]
653 }
654 else
655 {
656 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xdf; // [1101 1111]
657 }
658 }
659
648 void set_sy_lfr_watchdog_enabled( bool state )
660 void set_sy_lfr_watchdog_enabled( bool state )
649 {
661 {
650 if (state == true)
662 if (state == true)
651 {
663 {
652 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x10; // [0001 0000]
664 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x10; // [0001 0000]
653 }
665 }
654 else
666 else
655 {
667 {
656 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xef; // [1110 1111]
668 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xef; // [1110 1111]
657 }
669 }
658 }
670 }
659
671
660 void set_hk_lfr_calib_enable( bool state )
672 void set_hk_lfr_calib_enable( bool state )
661 {
673 {
662 if (state == true)
674 if (state == true)
663 {
675 {
664 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
676 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
665 }
677 }
666 else
678 else
667 {
679 {
668 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
680 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
669 }
681 }
670 }
682 }
671
683
672 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
684 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
673 {
685 {
674 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf8; // [1111 1000]
686 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf8; // [1111 1000]
675
687
676 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
688 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
677 | (lfr_reset_cause & 0x07 ); // [0000 0111]
689 | (lfr_reset_cause & 0x07 ); // [0000 0111]
678
690
679 }
691 }
680
692
681 void hk_lfr_le_me_he_update()
693 void hk_lfr_le_me_he_update()
682 {
694 {
683 unsigned int hk_lfr_le_cnt;
695 unsigned int hk_lfr_le_cnt;
684 unsigned int hk_lfr_me_cnt;
696 unsigned int hk_lfr_me_cnt;
685 unsigned int hk_lfr_he_cnt;
697 unsigned int hk_lfr_he_cnt;
686 unsigned int current_hk_lfr_le_cnt;
698 unsigned int current_hk_lfr_le_cnt;
687 unsigned int current_hk_lfr_me_cnt;
699 unsigned int current_hk_lfr_me_cnt;
688 unsigned int current_hk_lfr_he_cnt;
700 unsigned int current_hk_lfr_he_cnt;
689
701
690 hk_lfr_le_cnt = 0;
702 hk_lfr_le_cnt = 0;
691 hk_lfr_me_cnt = 0;
703 hk_lfr_me_cnt = 0;
692 hk_lfr_he_cnt = 0;
704 hk_lfr_he_cnt = 0;
693 current_hk_lfr_le_cnt = ((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256 + housekeeping_packet.hk_lfr_le_cnt[1];
705 current_hk_lfr_le_cnt = ((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256 + housekeeping_packet.hk_lfr_le_cnt[1];
694 current_hk_lfr_me_cnt = ((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256 + housekeeping_packet.hk_lfr_me_cnt[1];
706 current_hk_lfr_me_cnt = ((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256 + housekeeping_packet.hk_lfr_me_cnt[1];
695 current_hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
707 current_hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
696
708
697 //update the low severity error counter
709 //update the low severity error counter
698 hk_lfr_le_cnt =
710 hk_lfr_le_cnt =
699 current_hk_lfr_le_cnt
711 current_hk_lfr_le_cnt
700 + housekeeping_packet.hk_lfr_dpu_spw_parity
712 + housekeeping_packet.hk_lfr_dpu_spw_parity
701 + housekeeping_packet.hk_lfr_dpu_spw_disconnect
713 + housekeeping_packet.hk_lfr_dpu_spw_disconnect
702 + housekeeping_packet.hk_lfr_dpu_spw_escape
714 + housekeeping_packet.hk_lfr_dpu_spw_escape
703 + housekeeping_packet.hk_lfr_dpu_spw_credit
715 + housekeeping_packet.hk_lfr_dpu_spw_credit
704 + housekeeping_packet.hk_lfr_dpu_spw_write_sync
716 + housekeeping_packet.hk_lfr_dpu_spw_write_sync
705 + housekeeping_packet.hk_lfr_timecode_erroneous
717 + housekeeping_packet.hk_lfr_timecode_erroneous
706 + housekeeping_packet.hk_lfr_timecode_missing
718 + housekeeping_packet.hk_lfr_timecode_missing
707 + housekeeping_packet.hk_lfr_timecode_invalid
719 + housekeeping_packet.hk_lfr_timecode_invalid
708 + housekeeping_packet.hk_lfr_time_timecode_it
720 + housekeeping_packet.hk_lfr_time_timecode_it
709 + housekeeping_packet.hk_lfr_time_not_synchro
721 + housekeeping_packet.hk_lfr_time_not_synchro
710 + housekeeping_packet.hk_lfr_time_timecode_ctr
722 + housekeeping_packet.hk_lfr_time_timecode_ctr
711 + housekeeping_packet.hk_lfr_ahb_correctable;
723 + housekeeping_packet.hk_lfr_ahb_correctable;
712 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
724 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
713 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
725 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
714
726
715 //update the medium severity error counter
727 //update the medium severity error counter
716 hk_lfr_me_cnt =
728 hk_lfr_me_cnt =
717 current_hk_lfr_me_cnt
729 current_hk_lfr_me_cnt
718 + housekeeping_packet.hk_lfr_dpu_spw_early_eop
730 + housekeeping_packet.hk_lfr_dpu_spw_early_eop
719 + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr
731 + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr
720 + housekeeping_packet.hk_lfr_dpu_spw_eep
732 + housekeeping_packet.hk_lfr_dpu_spw_eep
721 + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
733 + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
722
734
723 //update the high severity error counter
735 //update the high severity error counter
724 hk_lfr_he_cnt = 0;
736 hk_lfr_he_cnt = 0;
725
737
726 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
738 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
727 // LE
739 // LE
728 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((hk_lfr_le_cnt & 0xff00) >> 8);
740 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((hk_lfr_le_cnt & 0xff00) >> 8);
729 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (hk_lfr_le_cnt & 0x00ff);
741 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (hk_lfr_le_cnt & 0x00ff);
730 // ME
742 // ME
731 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((hk_lfr_me_cnt & 0xff00) >> 8);
743 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((hk_lfr_me_cnt & 0xff00) >> 8);
732 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (hk_lfr_me_cnt & 0x00ff);
744 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (hk_lfr_me_cnt & 0x00ff);
733 // HE
745 // HE
734 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & 0xff00) >> 8);
746 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & 0xff00) >> 8);
735 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & 0x00ff);
747 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & 0x00ff);
736
748
737 }
749 }
738
750
739 void set_hk_lfr_time_not_synchro()
751 void set_hk_lfr_time_not_synchro()
740 {
752 {
741 static unsigned char synchroLost = 1;
753 static unsigned char synchroLost = 1;
742 int synchronizationBit;
754 int synchronizationBit;
743
755
744 // get the synchronization bit
756 // get the synchronization bit
745 synchronizationBit = (time_management_regs->coarse_time & 0x80000000) >> 31; // 1000 0000 0000 0000
757 synchronizationBit = (time_management_regs->coarse_time & 0x80000000) >> 31; // 1000 0000 0000 0000
746
758
747 switch (synchronizationBit)
759 switch (synchronizationBit)
748 {
760 {
749 case 0:
761 case 0:
750 if (synchroLost == 1)
762 if (synchroLost == 1)
751 {
763 {
752 synchroLost = 0;
764 synchroLost = 0;
753 }
765 }
754 break;
766 break;
755 case 1:
767 case 1:
756 if (synchroLost == 0 )
768 if (synchroLost == 0 )
757 {
769 {
758 synchroLost = 1;
770 synchroLost = 1;
759 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
771 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
760 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
772 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
761 }
773 }
762 break;
774 break;
763 default:
775 default:
764 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
776 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
765 break;
777 break;
766 }
778 }
767
779
768 }
780 }
769
781
770 void set_hk_lfr_ahb_correctable() // CRITICITY L
782 void set_hk_lfr_ahb_correctable() // CRITICITY L
771 {
783 {
772 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
784 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
773 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
785 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
774 * detected errors in the cache, in the integer unit and in the floating point unit.
786 * detected errors in the cache, in the integer unit and in the floating point unit.
775 *
787 *
776 * @param void
788 * @param void
777 *
789 *
778 * @return void
790 * @return void
779 *
791 *
780 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
792 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
781 *
793 *
782 */
794 */
783
795
784 unsigned int ahb_correctable;
796 unsigned int ahb_correctable;
785 unsigned int instructionErrorCounter;
797 unsigned int instructionErrorCounter;
786 unsigned int dataErrorCounter;
798 unsigned int dataErrorCounter;
787 unsigned int fprfErrorCounter;
799 unsigned int fprfErrorCounter;
788 unsigned int iurfErrorCounter;
800 unsigned int iurfErrorCounter;
789
801
790 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
802 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
791 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
803 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
792
804
793 ahb_correctable = instructionErrorCounter
805 ahb_correctable = instructionErrorCounter
794 + dataErrorCounter
806 + dataErrorCounter
795 + fprfErrorCounter
807 + fprfErrorCounter
796 + iurfErrorCounter
808 + iurfErrorCounter
797 + housekeeping_packet.hk_lfr_ahb_correctable;
809 + housekeeping_packet.hk_lfr_ahb_correctable;
798
810
799 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & 0xff); // [1111 1111]
811 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & 0xff); // [1111 1111]
800
812
801 }
813 }
@@ -1,1598 +1,1599
1 /** Functions related to the SpaceWire interface.
1 /** Functions related to the SpaceWire interface.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle SpaceWire transmissions:
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
11 *
12 */
12 */
13
13
14 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
15
15
16 rtems_name semq_name;
16 rtems_name semq_name;
17 rtems_id semq_id;
17 rtems_id semq_id;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24
24
25 unsigned char previousTimecodeCtr = 0;
25 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
27
28 //***********
28 //***********
29 // RTEMS TASK
29 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
30 rtems_task spiq_task(rtems_task_argument unused)
31 {
31 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
33 *
34 * @param unused is the starting argument of the RTEMS task
34 * @param unused is the starting argument of the RTEMS task
35 *
35 *
36 */
36 */
37
37
38 rtems_event_set event_out;
38 rtems_event_set event_out;
39 rtems_status_code status;
39 rtems_status_code status;
40 int linkStatus;
40 int linkStatus;
41
41
42 BOOT_PRINTF("in SPIQ *** \n")
42 BOOT_PRINTF("in SPIQ *** \n")
43
43
44 while(true){
44 while(true){
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47
47
48 // [0] SUSPEND RECV AND SEND TASKS
48 // [0] SUSPEND RECV AND SEND TASKS
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 if ( status != RTEMS_SUCCESSFUL ) {
50 if ( status != RTEMS_SUCCESSFUL ) {
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 }
52 }
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 if ( status != RTEMS_SUCCESSFUL ) {
54 if ( status != RTEMS_SUCCESSFUL ) {
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 }
56 }
57
57
58 // [1] CHECK THE LINK
58 // [1] CHECK THE LINK
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 if ( linkStatus != 5) {
60 if ( linkStatus != 5) {
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 }
63 }
64
64
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
68 {
68 {
69 spacewire_read_statistics();
69 spacewire_read_statistics();
70 status = spacewire_several_connect_attemps( );
70 status = spacewire_several_connect_attemps( );
71 }
71 }
72 else // [2.b] in run state, start the link
72 else // [2.b] in run state, start the link
73 {
73 {
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 if ( status != RTEMS_SUCCESSFUL)
75 if ( status != RTEMS_SUCCESSFUL)
76 {
76 {
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 }
78 }
79 }
79 }
80
80
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 {
83 {
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 if ( status != RTEMS_SUCCESSFUL ) {
85 if ( status != RTEMS_SUCCESSFUL ) {
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 }
87 }
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 if ( status != RTEMS_SUCCESSFUL ) {
89 if ( status != RTEMS_SUCCESSFUL ) {
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 }
91 }
92 }
92 }
93 else // [3.b] the link is not in run state, go in STANDBY mode
93 else // [3.b] the link is not in run state, go in STANDBY mode
94 {
94 {
95 status = enter_mode_standby();
95 status = enter_mode_standby();
96 if ( status != RTEMS_SUCCESSFUL )
96 if ( status != RTEMS_SUCCESSFUL )
97 {
97 {
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
99 }
99 }
100 {
100 {
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
102 }
102 }
103 // wake the LINK task up to wait for the link recovery
103 // wake the LINK task up to wait for the link recovery
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
105 status = rtems_task_suspend( RTEMS_SELF );
105 status = rtems_task_suspend( RTEMS_SELF );
106 }
106 }
107 }
107 }
108 }
108 }
109
109
110 rtems_task recv_task( rtems_task_argument unused )
110 rtems_task recv_task( rtems_task_argument unused )
111 {
111 {
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
113 *
113 *
114 * @param unused is the starting argument of the RTEMS task
114 * @param unused is the starting argument of the RTEMS task
115 *
115 *
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
117 * 1. It reads the incoming data.
117 * 1. It reads the incoming data.
118 * 2. Launches the acceptance procedure.
118 * 2. Launches the acceptance procedure.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
120 *
120 *
121 */
121 */
122
122
123 int len;
123 int len;
124 ccsdsTelecommandPacket_t currentTC;
124 ccsdsTelecommandPacket_t currentTC;
125 unsigned char computed_CRC[ 2 ];
125 unsigned char computed_CRC[ 2 ];
126 unsigned char currentTC_LEN_RCV[ 2 ];
126 unsigned char currentTC_LEN_RCV[ 2 ];
127 unsigned char destinationID;
127 unsigned char destinationID;
128 unsigned int estimatedPacketLength;
128 unsigned int estimatedPacketLength;
129 unsigned int parserCode;
129 unsigned int parserCode;
130 rtems_status_code status;
130 rtems_status_code status;
131 rtems_id queue_recv_id;
131 rtems_id queue_recv_id;
132 rtems_id queue_send_id;
132 rtems_id queue_send_id;
133
133
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
135
135
136 status = get_message_queue_id_recv( &queue_recv_id );
136 status = get_message_queue_id_recv( &queue_recv_id );
137 if (status != RTEMS_SUCCESSFUL)
137 if (status != RTEMS_SUCCESSFUL)
138 {
138 {
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
140 }
140 }
141
141
142 status = get_message_queue_id_send( &queue_send_id );
142 status = get_message_queue_id_send( &queue_send_id );
143 if (status != RTEMS_SUCCESSFUL)
143 if (status != RTEMS_SUCCESSFUL)
144 {
144 {
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
146 }
146 }
147
147
148 BOOT_PRINTF("in RECV *** \n")
148 BOOT_PRINTF("in RECV *** \n")
149
149
150 while(1)
150 while(1)
151 {
151 {
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
153 if (len == -1){ // error during the read call
153 if (len == -1){ // error during the read call
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
155 }
155 }
156 else {
156 else {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
158 PRINTF("in RECV *** packet lenght too short\n")
158 PRINTF("in RECV *** packet lenght too short\n")
159 }
159 }
160 else {
160 else {
161 PRINTF1("incoming TC with len: %d\n", len);
161 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
162 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
162 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
163 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
164 // CHECK THE TC
165 // CHECK THE TC
165 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
166 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
167 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
168 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
169 || (parserCode == WRONG_SRC_ID) )
170 || (parserCode == WRONG_SRC_ID) )
170 { // send TM_LFR_TC_EXE_CORRUPTED
171 { // send TM_LFR_TC_EXE_CORRUPTED
171 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
172 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
173 &&
174 &&
174 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
175 )
176 )
176 {
177 {
177 if ( parserCode == WRONG_SRC_ID )
178 if ( parserCode == WRONG_SRC_ID )
178 {
179 {
179 destinationID = SID_TC_GROUND;
180 destinationID = SID_TC_GROUND;
180 }
181 }
181 else
182 else
182 {
183 {
183 destinationID = currentTC.sourceID;
184 destinationID = currentTC.sourceID;
184 }
185 }
185 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
186 computed_CRC, currentTC_LEN_RCV,
187 computed_CRC, currentTC_LEN_RCV,
187 destinationID );
188 destinationID );
188 }
189 }
189 }
190 }
190 else
191 else
191 { // send valid TC to the action launcher
192 { // send valid TC to the action launcher
192 status = rtems_message_queue_send( queue_recv_id, &currentTC,
193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
193 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
194 }
195 }
195 }
196 }
196 }
197 }
197
198
198 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
199
200
200 }
201 }
201 }
202 }
202
203
203 rtems_task send_task( rtems_task_argument argument)
204 rtems_task send_task( rtems_task_argument argument)
204 {
205 {
205 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
206 *
207 *
207 * @param unused is the starting argument of the RTEMS task
208 * @param unused is the starting argument of the RTEMS task
208 *
209 *
209 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
210 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
211 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
212 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
213 * data it contains.
214 * data it contains.
214 *
215 *
215 */
216 */
216
217
217 rtems_status_code status; // RTEMS status code
218 rtems_status_code status; // RTEMS status code
218 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
219 ring_node *incomingRingNodePtr;
220 ring_node *incomingRingNodePtr;
220 int ring_node_address;
221 int ring_node_address;
221 char *charPtr;
222 char *charPtr;
222 spw_ioctl_pkt_send *spw_ioctl_send;
223 spw_ioctl_pkt_send *spw_ioctl_send;
223 size_t size; // size of the incoming TC packet
224 size_t size; // size of the incoming TC packet
224 rtems_id queue_send_id;
225 rtems_id queue_send_id;
225 unsigned int sid;
226 unsigned int sid;
226 unsigned char sidAsUnsignedChar;
227 unsigned char sidAsUnsignedChar;
227 unsigned char type;
228 unsigned char type;
228
229
229 incomingRingNodePtr = NULL;
230 incomingRingNodePtr = NULL;
230 ring_node_address = 0;
231 ring_node_address = 0;
231 charPtr = (char *) &ring_node_address;
232 charPtr = (char *) &ring_node_address;
232 sid = 0;
233 sid = 0;
233 sidAsUnsignedChar = 0;
234 sidAsUnsignedChar = 0;
234
235
235 init_header_cwf( &headerCWF );
236 init_header_cwf( &headerCWF );
236 init_header_swf( &headerSWF );
237 init_header_swf( &headerSWF );
237 init_header_asm( &headerASM );
238 init_header_asm( &headerASM );
238
239
239 status = get_message_queue_id_send( &queue_send_id );
240 status = get_message_queue_id_send( &queue_send_id );
240 if (status != RTEMS_SUCCESSFUL)
241 if (status != RTEMS_SUCCESSFUL)
241 {
242 {
242 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
243 }
244 }
244
245
245 BOOT_PRINTF("in SEND *** \n")
246 BOOT_PRINTF("in SEND *** \n")
246
247
247 while(1)
248 while(1)
248 {
249 {
249 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
250 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
251
252
252 if (status!=RTEMS_SUCCESSFUL)
253 if (status!=RTEMS_SUCCESSFUL)
253 {
254 {
254 PRINTF1("in SEND *** (1) ERR = %d\n", status)
255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
255 }
256 }
256 else
257 else
257 {
258 {
258 if ( size == sizeof(ring_node*) )
259 if ( size == sizeof(ring_node*) )
259 {
260 {
260 charPtr[0] = incomingData[0];
261 charPtr[0] = incomingData[0];
261 charPtr[1] = incomingData[1];
262 charPtr[1] = incomingData[1];
262 charPtr[2] = incomingData[2];
263 charPtr[2] = incomingData[2];
263 charPtr[3] = incomingData[3];
264 charPtr[3] = incomingData[3];
264 incomingRingNodePtr = (ring_node*) ring_node_address;
265 incomingRingNodePtr = (ring_node*) ring_node_address;
265 sid = incomingRingNodePtr->sid;
266 sid = incomingRingNodePtr->sid;
266 if ( (sid==SID_NORM_CWF_LONG_F3)
267 if ( (sid==SID_NORM_CWF_LONG_F3)
267 || (sid==SID_BURST_CWF_F2 )
268 || (sid==SID_BURST_CWF_F2 )
268 || (sid==SID_SBM1_CWF_F1 )
269 || (sid==SID_SBM1_CWF_F1 )
269 || (sid==SID_SBM2_CWF_F2 ))
270 || (sid==SID_SBM2_CWF_F2 ))
270 {
271 {
271 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
272 }
273 }
273 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
274 {
275 {
275 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
276 }
277 }
277 else if ( (sid==SID_NORM_CWF_F3) )
278 else if ( (sid==SID_NORM_CWF_F3) )
278 {
279 {
279 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
280 }
281 }
281 else if (sid==SID_NORM_ASM_F0)
282 else if (sid==SID_NORM_ASM_F0)
282 {
283 {
283 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
284 }
285 }
285 else if (sid==SID_NORM_ASM_F1)
286 else if (sid==SID_NORM_ASM_F1)
286 {
287 {
287 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
288 }
289 }
289 else if (sid==SID_NORM_ASM_F2)
290 else if (sid==SID_NORM_ASM_F2)
290 {
291 {
291 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
292 }
293 }
293 else if ( sid==TM_CODE_K_DUMP )
294 else if ( sid==TM_CODE_K_DUMP )
294 {
295 {
295 spw_send_k_dump( incomingRingNodePtr );
296 spw_send_k_dump( incomingRingNodePtr );
296 }
297 }
297 else
298 else
298 {
299 {
299 PRINTF1("unexpected sid = %d\n", sid);
300 PRINTF1("unexpected sid = %d\n", sid);
300 }
301 }
301 }
302 }
302 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
303 {
304 {
304 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
305 sid = sidAsUnsignedChar;
306 sid = sidAsUnsignedChar;
306 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
307 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
308 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
309 {
310 {
310 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
311 }
312 }
312
313
313 status = write( fdSPW, incomingData, size );
314 status = write( fdSPW, incomingData, size );
314 if (status == -1){
315 if (status == -1){
315 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
316 }
317 }
317 }
318 }
318 else // the incoming message is a spw_ioctl_pkt_send structure
319 else // the incoming message is a spw_ioctl_pkt_send structure
319 {
320 {
320 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
321 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
322 if (status == -1){
323 if (status == -1){
323 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
324 }
325 }
325 }
326 }
326 }
327 }
327
328
328 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
329
330
330 }
331 }
331 }
332 }
332
333
333 rtems_task link_task( rtems_task_argument argument )
334 rtems_task link_task( rtems_task_argument argument )
334 {
335 {
335 rtems_event_set event_out;
336 rtems_event_set event_out;
336 rtems_status_code status;
337 rtems_status_code status;
337 int linkStatus;
338 int linkStatus;
338
339
339 BOOT_PRINTF("in LINK ***\n")
340 BOOT_PRINTF("in LINK ***\n")
340
341
341 while(1)
342 while(1)
342 {
343 {
343 // wait for an RTEMS_EVENT
344 // wait for an RTEMS_EVENT
344 rtems_event_receive( RTEMS_EVENT_0,
345 rtems_event_receive( RTEMS_EVENT_0,
345 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
346 PRINTF("in LINK *** wait for the link\n")
347 PRINTF("in LINK *** wait for the link\n")
347 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 while( linkStatus != 5) // wait for the link
349 while( linkStatus != 5) // wait for the link
349 {
350 {
350 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
351 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
351 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
352 watchdog_reload();
353 watchdog_reload();
353 }
354 }
354
355
355 spacewire_read_statistics();
356 spacewire_read_statistics();
356 status = spacewire_stop_and_start_link( fdSPW );
357 status = spacewire_stop_and_start_link( fdSPW );
357
358
358 if (status != RTEMS_SUCCESSFUL)
359 if (status != RTEMS_SUCCESSFUL)
359 {
360 {
360 PRINTF1("in LINK *** ERR link not started %d\n", status)
361 PRINTF1("in LINK *** ERR link not started %d\n", status)
361 }
362 }
362 else
363 else
363 {
364 {
364 PRINTF("in LINK *** OK link started\n")
365 PRINTF("in LINK *** OK link started\n")
365 }
366 }
366
367
367 // restart the SPIQ task
368 // restart the SPIQ task
368 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
369 if ( status != RTEMS_SUCCESSFUL ) {
370 if ( status != RTEMS_SUCCESSFUL ) {
370 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
371 }
372 }
372
373
373 // restart RECV and SEND
374 // restart RECV and SEND
374 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
375 if ( status != RTEMS_SUCCESSFUL ) {
376 if ( status != RTEMS_SUCCESSFUL ) {
376 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
377 }
378 }
378 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
379 if ( status != RTEMS_SUCCESSFUL ) {
380 if ( status != RTEMS_SUCCESSFUL ) {
380 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
381 }
382 }
382 }
383 }
383 }
384 }
384
385
385 //****************
386 //****************
386 // OTHER FUNCTIONS
387 // OTHER FUNCTIONS
387 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
388 {
389 {
389 /** This function opens the SpaceWire link.
390 /** This function opens the SpaceWire link.
390 *
391 *
391 * @return a valid file descriptor in case of success, -1 in case of a failure
392 * @return a valid file descriptor in case of success, -1 in case of a failure
392 *
393 *
393 */
394 */
394 rtems_status_code status;
395 rtems_status_code status;
395
396
396 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
397 if ( fdSPW < 0 ) {
398 if ( fdSPW < 0 ) {
398 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
399 }
400 }
400 else
401 else
401 {
402 {
402 status = RTEMS_SUCCESSFUL;
403 status = RTEMS_SUCCESSFUL;
403 }
404 }
404
405
405 return status;
406 return status;
406 }
407 }
407
408
408 int spacewire_start_link( int fd )
409 int spacewire_start_link( int fd )
409 {
410 {
410 rtems_status_code status;
411 rtems_status_code status;
411
412
412 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
413 // -1 default hardcoded driver timeout
414 // -1 default hardcoded driver timeout
414
415
415 return status;
416 return status;
416 }
417 }
417
418
418 int spacewire_stop_and_start_link( int fd )
419 int spacewire_stop_and_start_link( int fd )
419 {
420 {
420 rtems_status_code status;
421 rtems_status_code status;
421
422
422 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
423 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
424 // -1 default hardcoded driver timeout
425 // -1 default hardcoded driver timeout
425
426
426 return status;
427 return status;
427 }
428 }
428
429
429 int spacewire_configure_link( int fd )
430 int spacewire_configure_link( int fd )
430 {
431 {
431 /** This function configures the SpaceWire link.
432 /** This function configures the SpaceWire link.
432 *
433 *
433 * @return GR-RTEMS-DRIVER directive status codes:
434 * @return GR-RTEMS-DRIVER directive status codes:
434 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
435 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
436 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
437 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
438 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
439 * - 5 EIO - Error when writing to grswp hardware registers.
440 * - 5 EIO - Error when writing to grswp hardware registers.
440 * - 2 ENOENT - No such file or directory
441 * - 2 ENOENT - No such file or directory
441 */
442 */
442
443
443 rtems_status_code status;
444 rtems_status_code status;
444
445
445 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
446 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
447
448
448 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
449 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
449 if (status!=RTEMS_SUCCESSFUL) {
450 if (status!=RTEMS_SUCCESSFUL) {
450 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
451 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
451 }
452 }
452 //
453 //
453 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
454 if (status!=RTEMS_SUCCESSFUL) {
455 if (status!=RTEMS_SUCCESSFUL) {
455 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
456 }
457 }
457 //
458 //
458 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
459 if (status!=RTEMS_SUCCESSFUL) {
460 if (status!=RTEMS_SUCCESSFUL) {
460 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
461 }
462 }
462 //
463 //
463 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
464 if (status!=RTEMS_SUCCESSFUL) {
465 if (status!=RTEMS_SUCCESSFUL) {
465 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
466 }
467 }
467 //
468 //
468 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
469 if (status!=RTEMS_SUCCESSFUL) {
470 if (status!=RTEMS_SUCCESSFUL) {
470 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
471 }
472 }
472 //
473 //
473 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
474 if (status!=RTEMS_SUCCESSFUL) {
475 if (status!=RTEMS_SUCCESSFUL) {
475 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
476 }
477 }
477 //
478 //
478 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
479 if (status!=RTEMS_SUCCESSFUL) {
480 if (status!=RTEMS_SUCCESSFUL) {
480 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
481 }
482 }
482
483
483 return status;
484 return status;
484 }
485 }
485
486
486 int spacewire_several_connect_attemps( void )
487 int spacewire_several_connect_attemps( void )
487 {
488 {
488 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
489 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
489 *
490 *
490 * @return RTEMS directive status code:
491 * @return RTEMS directive status code:
491 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
492 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
492 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
493 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
493 *
494 *
494 */
495 */
495
496
496 rtems_status_code status_spw;
497 rtems_status_code status_spw;
497 rtems_status_code status;
498 rtems_status_code status;
498 int i;
499 int i;
499
500
500 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
501 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
501 {
502 {
502 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
503 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
503
504
504 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
505 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
505
506
506 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
507 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
507
508
508 status_spw = spacewire_stop_and_start_link( fdSPW );
509 status_spw = spacewire_stop_and_start_link( fdSPW );
509
510
510 if ( status_spw != RTEMS_SUCCESSFUL )
511 if ( status_spw != RTEMS_SUCCESSFUL )
511 {
512 {
512 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
513 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
513 }
514 }
514
515
515 if ( status_spw == RTEMS_SUCCESSFUL)
516 if ( status_spw == RTEMS_SUCCESSFUL)
516 {
517 {
517 break;
518 break;
518 }
519 }
519 }
520 }
520
521
521 return status_spw;
522 return status_spw;
522 }
523 }
523
524
524 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
525 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
525 {
526 {
526 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
527 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
527 *
528 *
528 * @param val is the value, 0 or 1, used to set the value of the NP bit.
529 * @param val is the value, 0 or 1, used to set the value of the NP bit.
529 * @param regAddr is the address of the GRSPW control register.
530 * @param regAddr is the address of the GRSPW control register.
530 *
531 *
531 * NP is the bit 20 of the GRSPW control register.
532 * NP is the bit 20 of the GRSPW control register.
532 *
533 *
533 */
534 */
534
535
535 unsigned int *spwptr = (unsigned int*) regAddr;
536 unsigned int *spwptr = (unsigned int*) regAddr;
536
537
537 if (val == 1) {
538 if (val == 1) {
538 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
539 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
539 }
540 }
540 if (val== 0) {
541 if (val== 0) {
541 *spwptr = *spwptr & 0xffdfffff;
542 *spwptr = *spwptr & 0xffdfffff;
542 }
543 }
543 }
544 }
544
545
545 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
546 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
546 {
547 {
547 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
548 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
548 *
549 *
549 * @param val is the value, 0 or 1, used to set the value of the RE bit.
550 * @param val is the value, 0 or 1, used to set the value of the RE bit.
550 * @param regAddr is the address of the GRSPW control register.
551 * @param regAddr is the address of the GRSPW control register.
551 *
552 *
552 * RE is the bit 16 of the GRSPW control register.
553 * RE is the bit 16 of the GRSPW control register.
553 *
554 *
554 */
555 */
555
556
556 unsigned int *spwptr = (unsigned int*) regAddr;
557 unsigned int *spwptr = (unsigned int*) regAddr;
557
558
558 if (val == 1)
559 if (val == 1)
559 {
560 {
560 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
561 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
561 }
562 }
562 if (val== 0)
563 if (val== 0)
563 {
564 {
564 *spwptr = *spwptr & 0xfffdffff;
565 *spwptr = *spwptr & 0xfffdffff;
565 }
566 }
566 }
567 }
567
568
568 void spacewire_read_statistics( void )
569 void spacewire_read_statistics( void )
569 {
570 {
570 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
571 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
571 *
572 *
572 * @param void
573 * @param void
573 *
574 *
574 * @return void
575 * @return void
575 *
576 *
576 * Once they are read, the counters are stored in a global variable used during the building of the
577 * Once they are read, the counters are stored in a global variable used during the building of the
577 * HK packets.
578 * HK packets.
578 *
579 *
579 */
580 */
580
581
581 rtems_status_code status;
582 rtems_status_code status;
582 spw_stats current;
583 spw_stats current;
583
584
584 spacewire_get_last_error();
585 spacewire_get_last_error();
585
586
586 // read the current statistics
587 // read the current statistics
587 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
588 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
588
589
589 // clear the counters
590 // clear the counters
590 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
591 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
591
592
592 // typedef struct {
593 // typedef struct {
593 // unsigned int tx_link_err; // NOT IN HK
594 // unsigned int tx_link_err; // NOT IN HK
594 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
595 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
595 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
596 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
596 // unsigned int rx_eep_err;
597 // unsigned int rx_eep_err;
597 // unsigned int rx_truncated;
598 // unsigned int rx_truncated;
598 // unsigned int parity_err;
599 // unsigned int parity_err;
599 // unsigned int escape_err;
600 // unsigned int escape_err;
600 // unsigned int credit_err;
601 // unsigned int credit_err;
601 // unsigned int write_sync_err;
602 // unsigned int write_sync_err;
602 // unsigned int disconnect_err;
603 // unsigned int disconnect_err;
603 // unsigned int early_ep;
604 // unsigned int early_ep;
604 // unsigned int invalid_address;
605 // unsigned int invalid_address;
605 // unsigned int packets_sent;
606 // unsigned int packets_sent;
606 // unsigned int packets_received;
607 // unsigned int packets_received;
607 // } spw_stats;
608 // } spw_stats;
608
609
609 // rx_eep_err
610 // rx_eep_err
610 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
611 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
611 // rx_truncated
612 // rx_truncated
612 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
613 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
613 // parity_err
614 // parity_err
614 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
615 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
615 // escape_err
616 // escape_err
616 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
617 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
617 // credit_err
618 // credit_err
618 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
619 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
619 // write_sync_err
620 // write_sync_err
620 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
621 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
621 // disconnect_err
622 // disconnect_err
622 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
623 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
623 // early_ep
624 // early_ep
624 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
625 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
625 // invalid_address
626 // invalid_address
626 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
627 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
627 // packets_sent
628 // packets_sent
628 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
629 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
629 // packets_received
630 // packets_received
630 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
631 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
631
632
632 }
633 }
633
634
634 void spacewire_get_last_error( void )
635 void spacewire_get_last_error( void )
635 {
636 {
636 static spw_stats previous;
637 static spw_stats previous;
637 spw_stats current;
638 spw_stats current;
638 rtems_status_code status;
639 rtems_status_code status;
639
640
640 unsigned int hk_lfr_last_er_rid;
641 unsigned int hk_lfr_last_er_rid;
641 unsigned char hk_lfr_last_er_code;
642 unsigned char hk_lfr_last_er_code;
642 int coarseTime;
643 int coarseTime;
643 int fineTime;
644 int fineTime;
644 unsigned char update_hk_lfr_last_er;
645 unsigned char update_hk_lfr_last_er;
645
646
646 update_hk_lfr_last_er = 0;
647 update_hk_lfr_last_er = 0;
647
648
648 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
649 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
649
650
650 // get current time
651 // get current time
651 coarseTime = time_management_regs->coarse_time;
652 coarseTime = time_management_regs->coarse_time;
652 fineTime = time_management_regs->fine_time;
653 fineTime = time_management_regs->fine_time;
653
654
654 // typedef struct {
655 // typedef struct {
655 // unsigned int tx_link_err; // NOT IN HK
656 // unsigned int tx_link_err; // NOT IN HK
656 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
657 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
657 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
658 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
658 // unsigned int rx_eep_err;
659 // unsigned int rx_eep_err;
659 // unsigned int rx_truncated;
660 // unsigned int rx_truncated;
660 // unsigned int parity_err;
661 // unsigned int parity_err;
661 // unsigned int escape_err;
662 // unsigned int escape_err;
662 // unsigned int credit_err;
663 // unsigned int credit_err;
663 // unsigned int write_sync_err;
664 // unsigned int write_sync_err;
664 // unsigned int disconnect_err;
665 // unsigned int disconnect_err;
665 // unsigned int early_ep;
666 // unsigned int early_ep;
666 // unsigned int invalid_address;
667 // unsigned int invalid_address;
667 // unsigned int packets_sent;
668 // unsigned int packets_sent;
668 // unsigned int packets_received;
669 // unsigned int packets_received;
669 // } spw_stats;
670 // } spw_stats;
670
671
671 // tx_link_err *** no code associated to this field
672 // tx_link_err *** no code associated to this field
672 // rx_rmap_header_crc_err *** LE *** in HK
673 // rx_rmap_header_crc_err *** LE *** in HK
673 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
674 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
674 {
675 {
675 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
676 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
676 hk_lfr_last_er_code = CODE_HEADER_CRC;
677 hk_lfr_last_er_code = CODE_HEADER_CRC;
677 update_hk_lfr_last_er = 1;
678 update_hk_lfr_last_er = 1;
678 }
679 }
679 // rx_rmap_data_crc_err *** LE *** NOT IN HK
680 // rx_rmap_data_crc_err *** LE *** NOT IN HK
680 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
681 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
681 {
682 {
682 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
683 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
683 hk_lfr_last_er_code = CODE_DATA_CRC;
684 hk_lfr_last_er_code = CODE_DATA_CRC;
684 update_hk_lfr_last_er = 1;
685 update_hk_lfr_last_er = 1;
685 }
686 }
686 // rx_eep_err
687 // rx_eep_err
687 if (previous.rx_eep_err != current.rx_eep_err)
688 if (previous.rx_eep_err != current.rx_eep_err)
688 {
689 {
689 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
690 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
690 hk_lfr_last_er_code = CODE_EEP;
691 hk_lfr_last_er_code = CODE_EEP;
691 update_hk_lfr_last_er = 1;
692 update_hk_lfr_last_er = 1;
692 }
693 }
693 // rx_truncated
694 // rx_truncated
694 if (previous.rx_truncated != current.rx_truncated)
695 if (previous.rx_truncated != current.rx_truncated)
695 {
696 {
696 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
697 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
697 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
698 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
698 update_hk_lfr_last_er = 1;
699 update_hk_lfr_last_er = 1;
699 }
700 }
700 // parity_err
701 // parity_err
701 if (previous.parity_err != current.parity_err)
702 if (previous.parity_err != current.parity_err)
702 {
703 {
703 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
704 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
704 hk_lfr_last_er_code = CODE_PARITY;
705 hk_lfr_last_er_code = CODE_PARITY;
705 update_hk_lfr_last_er = 1;
706 update_hk_lfr_last_er = 1;
706 }
707 }
707 // escape_err
708 // escape_err
708 if (previous.parity_err != current.parity_err)
709 if (previous.parity_err != current.parity_err)
709 {
710 {
710 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
711 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
711 hk_lfr_last_er_code = CODE_ESCAPE;
712 hk_lfr_last_er_code = CODE_ESCAPE;
712 update_hk_lfr_last_er = 1;
713 update_hk_lfr_last_er = 1;
713 }
714 }
714 // credit_err
715 // credit_err
715 if (previous.credit_err != current.credit_err)
716 if (previous.credit_err != current.credit_err)
716 {
717 {
717 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
718 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
718 hk_lfr_last_er_code = CODE_CREDIT;
719 hk_lfr_last_er_code = CODE_CREDIT;
719 update_hk_lfr_last_er = 1;
720 update_hk_lfr_last_er = 1;
720 }
721 }
721 // write_sync_err
722 // write_sync_err
722 if (previous.write_sync_err != current.write_sync_err)
723 if (previous.write_sync_err != current.write_sync_err)
723 {
724 {
724 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
725 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
725 hk_lfr_last_er_code = CODE_WRITE_SYNC;
726 hk_lfr_last_er_code = CODE_WRITE_SYNC;
726 update_hk_lfr_last_er = 1;
727 update_hk_lfr_last_er = 1;
727 }
728 }
728 // disconnect_err
729 // disconnect_err
729 if (previous.disconnect_err != current.disconnect_err)
730 if (previous.disconnect_err != current.disconnect_err)
730 {
731 {
731 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
732 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
732 hk_lfr_last_er_code = CODE_DISCONNECT;
733 hk_lfr_last_er_code = CODE_DISCONNECT;
733 update_hk_lfr_last_er = 1;
734 update_hk_lfr_last_er = 1;
734 }
735 }
735 // early_ep
736 // early_ep
736 if (previous.early_ep != current.early_ep)
737 if (previous.early_ep != current.early_ep)
737 {
738 {
738 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
739 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
739 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
740 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
740 update_hk_lfr_last_er = 1;
741 update_hk_lfr_last_er = 1;
741 }
742 }
742 // invalid_address
743 // invalid_address
743 if (previous.invalid_address != current.invalid_address)
744 if (previous.invalid_address != current.invalid_address)
744 {
745 {
745 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
746 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
746 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
747 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
747 update_hk_lfr_last_er = 1;
748 update_hk_lfr_last_er = 1;
748 }
749 }
749
750
750 // if a field has changed, update the hk_last_er fields
751 // if a field has changed, update the hk_last_er fields
751 if (update_hk_lfr_last_er == 1)
752 if (update_hk_lfr_last_er == 1)
752 {
753 {
753 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
754 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
754 }
755 }
755
756
756 previous = current;
757 previous = current;
757 }
758 }
758
759
759 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
760 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
760 {
761 {
761 unsigned char *coarseTimePtr;
762 unsigned char *coarseTimePtr;
762 unsigned char *fineTimePtr;
763 unsigned char *fineTimePtr;
763
764
764 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
765 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
765 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
766 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
766
767
767 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
768 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
768 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
769 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
769 housekeeping_packet.hk_lfr_last_er_code = code;
770 housekeeping_packet.hk_lfr_last_er_code = code;
770 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
771 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
771 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
772 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
772 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
773 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
773 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
774 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
774 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
775 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
775 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
776 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
776 }
777 }
777
778
778 void update_hk_with_grspw_stats( void )
779 void update_hk_with_grspw_stats( void )
779 {
780 {
780 //****************************
781 //****************************
781 // DPU_SPACEWIRE_IF_STATISTICS
782 // DPU_SPACEWIRE_IF_STATISTICS
782 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
784 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
784 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
786 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
786
787
787 //******************************************
788 //******************************************
788 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
789 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
789 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
790 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
790 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
791 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
791 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
792 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
792 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
793 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
793 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
794 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
794
795
795 //*********************************************
796 //*********************************************
796 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
797 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
797 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
798 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
798 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
799 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
799 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
800 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
800 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
801 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
801 }
802 }
802
803
803 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
804 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
804 {
805 {
805 unsigned int *statusRegisterPtr;
806 unsigned int *statusRegisterPtr;
806 unsigned char linkState;
807 unsigned char linkState;
807
808
808 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
809 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
809 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
810 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
810
811
811 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
812 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
812
813
813 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
814 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
814 }
815 }
815
816
816 void increase_unsigned_char_counter( unsigned char *counter )
817 void increase_unsigned_char_counter( unsigned char *counter )
817 {
818 {
818 // update the number of valid timecodes that have been received
819 // update the number of valid timecodes that have been received
819 if (*counter == 255)
820 if (*counter == 255)
820 {
821 {
821 *counter = 0;
822 *counter = 0;
822 }
823 }
823 else
824 else
824 {
825 {
825 *counter = *counter + 1;
826 *counter = *counter + 1;
826 }
827 }
827 }
828 }
828
829
829 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
830 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
830 {
831 {
831 /** This function checks the coherency between the incoming timecode and the last valid timecode.
832 /** This function checks the coherency between the incoming timecode and the last valid timecode.
832 *
833 *
833 * @param currentTimecodeCtr is the incoming timecode
834 * @param currentTimecodeCtr is the incoming timecode
834 *
835 *
835 * @return returned codes::
836 * @return returned codes::
836 * - LFR_DEFAULT
837 * - LFR_DEFAULT
837 * - LFR_SUCCESSFUL
838 * - LFR_SUCCESSFUL
838 *
839 *
839 */
840 */
840
841
841 static unsigned char firstTickout = 1;
842 static unsigned char firstTickout = 1;
842 unsigned char ret;
843 unsigned char ret;
843
844
844 ret = LFR_DEFAULT;
845 ret = LFR_DEFAULT;
845
846
846 if (firstTickout == 0)
847 if (firstTickout == 0)
847 {
848 {
848 if (currentTimecodeCtr == 0)
849 if (currentTimecodeCtr == 0)
849 {
850 {
850 if (previousTimecodeCtr == 63)
851 if (previousTimecodeCtr == 63)
851 {
852 {
852 ret = LFR_SUCCESSFUL;
853 ret = LFR_SUCCESSFUL;
853 }
854 }
854 else
855 else
855 {
856 {
856 ret = LFR_DEFAULT;
857 ret = LFR_DEFAULT;
857 }
858 }
858 }
859 }
859 else
860 else
860 {
861 {
861 if (currentTimecodeCtr == (previousTimecodeCtr +1))
862 if (currentTimecodeCtr == (previousTimecodeCtr +1))
862 {
863 {
863 ret = LFR_SUCCESSFUL;
864 ret = LFR_SUCCESSFUL;
864 }
865 }
865 else
866 else
866 {
867 {
867 ret = LFR_DEFAULT;
868 ret = LFR_DEFAULT;
868 }
869 }
869 }
870 }
870 }
871 }
871 else
872 else
872 {
873 {
873 firstTickout = 0;
874 firstTickout = 0;
874 ret = LFR_SUCCESSFUL;
875 ret = LFR_SUCCESSFUL;
875 }
876 }
876
877
877 return ret;
878 return ret;
878 }
879 }
879
880
880 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
881 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
881 {
882 {
882 unsigned int ret;
883 unsigned int ret;
883
884
884 ret = LFR_DEFAULT;
885 ret = LFR_DEFAULT;
885
886
886 if (timecode == internalTime)
887 if (timecode == internalTime)
887 {
888 {
888 ret = LFR_SUCCESSFUL;
889 ret = LFR_SUCCESSFUL;
889 }
890 }
890 else
891 else
891 {
892 {
892 ret = LFR_DEFAULT;
893 ret = LFR_DEFAULT;
893 }
894 }
894
895
895 return ret;
896 return ret;
896 }
897 }
897
898
898 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
899 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
899 {
900 {
900 // a tickout has been emitted, perform actions on the incoming timecode
901 // a tickout has been emitted, perform actions on the incoming timecode
901
902
902 unsigned char incomingTimecode;
903 unsigned char incomingTimecode;
903 unsigned char updateTime;
904 unsigned char updateTime;
904 unsigned char internalTime;
905 unsigned char internalTime;
905 rtems_status_code status;
906 rtems_status_code status;
906
907
907 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
908 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
908 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
909 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
909 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
910 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
910
911
911 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
912 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
912
913
913 // update the number of tickout that have been generated
914 // update the number of tickout that have been generated
914 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
915 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
915
916
916 //**************************
917 //**************************
917 // HK_LFR_TIMECODE_ERRONEOUS
918 // HK_LFR_TIMECODE_ERRONEOUS
918 // MISSING and INVALID are handled by the timecode_timer_routine service routine
919 // MISSING and INVALID are handled by the timecode_timer_routine service routine
919 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
920 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
920 {
921 {
921 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
922 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
922 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
923 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
923 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
924 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
924 }
925 }
925
926
926 //************************
927 //************************
927 // HK_LFR_TIME_TIMECODE_IT
928 // HK_LFR_TIME_TIMECODE_IT
928 // check the coherency between the SpaceWire timecode and the Internal Time
929 // check the coherency between the SpaceWire timecode and the Internal Time
929 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
930 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
930 {
931 {
931 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
932 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
932 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
933 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
933 }
934 }
934
935
935 //********************
936 //********************
936 // HK_LFR_TIMECODE_CTR
937 // HK_LFR_TIMECODE_CTR
937 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
938 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
938 if (oneTcLfrUpdateTimeReceived == 1)
939 if (oneTcLfrUpdateTimeReceived == 1)
939 {
940 {
940 if ( incomingTimecode != updateTime )
941 if ( incomingTimecode != updateTime )
941 {
942 {
942 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
943 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
944 }
945 }
945 }
946 }
946
947
947 // launch the timecode timer to detect missing or invalid timecodes
948 // launch the timecode timer to detect missing or invalid timecodes
948 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
949 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
949 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
950 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
950 if (status != RTEMS_SUCCESSFUL)
951 if (status != RTEMS_SUCCESSFUL)
951 {
952 {
952 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
953 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
953 }
954 }
954 }
955 }
955
956
956 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
957 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
957 {
958 {
958 static unsigned char initStep = 1;
959 static unsigned char initStep = 1;
959
960
960 unsigned char currentTimecodeCtr;
961 unsigned char currentTimecodeCtr;
961
962
962 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
963 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
963
964
964 if (initStep == 1)
965 if (initStep == 1)
965 {
966 {
966 if (currentTimecodeCtr == previousTimecodeCtr)
967 if (currentTimecodeCtr == previousTimecodeCtr)
967 {
968 {
968 //************************
969 //************************
969 // HK_LFR_TIMECODE_MISSING
970 // HK_LFR_TIMECODE_MISSING
970 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
971 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
971 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
972 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
972 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
973 }
974 }
974 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
975 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
975 {
976 {
976 // the timecode value has changed and the value is valid, this is unexpected because
977 // the timecode value has changed and the value is valid, this is unexpected because
977 // the timer should not have fired, the timecode_irq_handler should have been raised
978 // the timer should not have fired, the timecode_irq_handler should have been raised
978 }
979 }
979 else
980 else
980 {
981 {
981 //************************
982 //************************
982 // HK_LFR_TIMECODE_INVALID
983 // HK_LFR_TIMECODE_INVALID
983 // the timecode value has changed and the value is not valid, no tickout has been generated
984 // the timecode value has changed and the value is not valid, no tickout has been generated
984 // this is why the timer has fired
985 // this is why the timer has fired
985 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
986 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
986 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
987 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
987 }
988 }
988 }
989 }
989 else
990 else
990 {
991 {
991 initStep = 1;
992 initStep = 1;
992 //************************
993 //************************
993 // HK_LFR_TIMECODE_MISSING
994 // HK_LFR_TIMECODE_MISSING
994 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
995 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
995 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
996 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
996 }
997 }
997
998
998 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
999 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
999 }
1000 }
1000
1001
1001 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1002 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1002 {
1003 {
1003 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1004 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1004 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1005 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1005 header->reserved = DEFAULT_RESERVED;
1006 header->reserved = DEFAULT_RESERVED;
1006 header->userApplication = CCSDS_USER_APP;
1007 header->userApplication = CCSDS_USER_APP;
1007 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1008 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1008 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1009 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1009 header->packetLength[0] = 0x00;
1010 header->packetLength[0] = 0x00;
1010 header->packetLength[1] = 0x00;
1011 header->packetLength[1] = 0x00;
1011 // DATA FIELD HEADER
1012 // DATA FIELD HEADER
1012 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1013 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1013 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1014 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1014 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1015 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1015 header->destinationID = TM_DESTINATION_ID_GROUND;
1016 header->destinationID = TM_DESTINATION_ID_GROUND;
1016 header->time[0] = 0x00;
1017 header->time[0] = 0x00;
1017 header->time[0] = 0x00;
1018 header->time[0] = 0x00;
1018 header->time[0] = 0x00;
1019 header->time[0] = 0x00;
1019 header->time[0] = 0x00;
1020 header->time[0] = 0x00;
1020 header->time[0] = 0x00;
1021 header->time[0] = 0x00;
1021 header->time[0] = 0x00;
1022 header->time[0] = 0x00;
1022 // AUXILIARY DATA HEADER
1023 // AUXILIARY DATA HEADER
1023 header->sid = 0x00;
1024 header->sid = 0x00;
1024 header->pa_bia_status_info = DEFAULT_HKBIA;
1025 header->pa_bia_status_info = DEFAULT_HKBIA;
1025 header->blkNr[0] = 0x00;
1026 header->blkNr[0] = 0x00;
1026 header->blkNr[1] = 0x00;
1027 header->blkNr[1] = 0x00;
1027 }
1028 }
1028
1029
1029 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1030 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1030 {
1031 {
1031 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1032 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1032 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1033 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1033 header->reserved = DEFAULT_RESERVED;
1034 header->reserved = DEFAULT_RESERVED;
1034 header->userApplication = CCSDS_USER_APP;
1035 header->userApplication = CCSDS_USER_APP;
1035 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1036 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1036 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1037 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1037 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1038 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1038 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1039 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1039 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1040 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1040 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1041 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1041 // DATA FIELD HEADER
1042 // DATA FIELD HEADER
1042 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1043 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1043 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1044 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1044 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1045 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1045 header->destinationID = TM_DESTINATION_ID_GROUND;
1046 header->destinationID = TM_DESTINATION_ID_GROUND;
1046 header->time[0] = 0x00;
1047 header->time[0] = 0x00;
1047 header->time[0] = 0x00;
1048 header->time[0] = 0x00;
1048 header->time[0] = 0x00;
1049 header->time[0] = 0x00;
1049 header->time[0] = 0x00;
1050 header->time[0] = 0x00;
1050 header->time[0] = 0x00;
1051 header->time[0] = 0x00;
1051 header->time[0] = 0x00;
1052 header->time[0] = 0x00;
1052 // AUXILIARY DATA HEADER
1053 // AUXILIARY DATA HEADER
1053 header->sid = 0x00;
1054 header->sid = 0x00;
1054 header->pa_bia_status_info = DEFAULT_HKBIA;
1055 header->pa_bia_status_info = DEFAULT_HKBIA;
1055 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1056 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1056 header->pktNr = 0x00;
1057 header->pktNr = 0x00;
1057 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1058 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1058 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1059 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1059 }
1060 }
1060
1061
1061 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1062 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1062 {
1063 {
1063 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1064 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1065 header->reserved = DEFAULT_RESERVED;
1066 header->reserved = DEFAULT_RESERVED;
1066 header->userApplication = CCSDS_USER_APP;
1067 header->userApplication = CCSDS_USER_APP;
1067 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1068 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1069 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1070 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1071 header->packetLength[0] = 0x00;
1072 header->packetLength[0] = 0x00;
1072 header->packetLength[1] = 0x00;
1073 header->packetLength[1] = 0x00;
1073 // DATA FIELD HEADER
1074 // DATA FIELD HEADER
1074 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1075 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1076 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1077 header->destinationID = TM_DESTINATION_ID_GROUND;
1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1078 header->time[0] = 0x00;
1079 header->time[0] = 0x00;
1079 header->time[0] = 0x00;
1080 header->time[0] = 0x00;
1080 header->time[0] = 0x00;
1081 header->time[0] = 0x00;
1081 header->time[0] = 0x00;
1082 header->time[0] = 0x00;
1082 header->time[0] = 0x00;
1083 header->time[0] = 0x00;
1083 header->time[0] = 0x00;
1084 header->time[0] = 0x00;
1084 // AUXILIARY DATA HEADER
1085 // AUXILIARY DATA HEADER
1085 header->sid = 0x00;
1086 header->sid = 0x00;
1086 header->pa_bia_status_info = 0x00;
1087 header->pa_bia_status_info = 0x00;
1087 header->pa_lfr_pkt_cnt_asm = 0x00;
1088 header->pa_lfr_pkt_cnt_asm = 0x00;
1088 header->pa_lfr_pkt_nr_asm = 0x00;
1089 header->pa_lfr_pkt_nr_asm = 0x00;
1089 header->pa_lfr_asm_blk_nr[0] = 0x00;
1090 header->pa_lfr_asm_blk_nr[0] = 0x00;
1090 header->pa_lfr_asm_blk_nr[1] = 0x00;
1091 header->pa_lfr_asm_blk_nr[1] = 0x00;
1091 }
1092 }
1092
1093
1093 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1094 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1094 Header_TM_LFR_SCIENCE_CWF_t *header )
1095 Header_TM_LFR_SCIENCE_CWF_t *header )
1095 {
1096 {
1096 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1097 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1097 *
1098 *
1098 * @param waveform points to the buffer containing the data that will be send.
1099 * @param waveform points to the buffer containing the data that will be send.
1099 * @param sid is the source identifier of the data that will be sent.
1100 * @param sid is the source identifier of the data that will be sent.
1100 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1101 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1101 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1102 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1102 * contain information to setup the transmission of the data packets.
1103 * contain information to setup the transmission of the data packets.
1103 *
1104 *
1104 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1105 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1105 *
1106 *
1106 */
1107 */
1107
1108
1108 unsigned int i;
1109 unsigned int i;
1109 int ret;
1110 int ret;
1110 unsigned int coarseTime;
1111 unsigned int coarseTime;
1111 unsigned int fineTime;
1112 unsigned int fineTime;
1112 rtems_status_code status;
1113 rtems_status_code status;
1113 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1114 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1114 int *dataPtr;
1115 int *dataPtr;
1115 unsigned char sid;
1116 unsigned char sid;
1116
1117
1117 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1118 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1118 spw_ioctl_send_CWF.options = 0;
1119 spw_ioctl_send_CWF.options = 0;
1119
1120
1120 ret = LFR_DEFAULT;
1121 ret = LFR_DEFAULT;
1121 sid = (unsigned char) ring_node_to_send->sid;
1122 sid = (unsigned char) ring_node_to_send->sid;
1122
1123
1123 coarseTime = ring_node_to_send->coarseTime;
1124 coarseTime = ring_node_to_send->coarseTime;
1124 fineTime = ring_node_to_send->fineTime;
1125 fineTime = ring_node_to_send->fineTime;
1125 dataPtr = (int*) ring_node_to_send->buffer_address;
1126 dataPtr = (int*) ring_node_to_send->buffer_address;
1126
1127
1127 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1128 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1128 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1129 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1129 header->pa_bia_status_info = pa_bia_status_info;
1130 header->pa_bia_status_info = pa_bia_status_info;
1130 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1131 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1131 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1132 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1132 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1133 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1133
1134
1134 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1135 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1135 {
1136 {
1136 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1137 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1137 spw_ioctl_send_CWF.hdr = (char*) header;
1138 spw_ioctl_send_CWF.hdr = (char*) header;
1138 // BUILD THE DATA
1139 // BUILD THE DATA
1139 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1140 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1140
1141
1141 // SET PACKET SEQUENCE CONTROL
1142 // SET PACKET SEQUENCE CONTROL
1142 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1143 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1143
1144
1144 // SET SID
1145 // SET SID
1145 header->sid = sid;
1146 header->sid = sid;
1146
1147
1147 // SET PACKET TIME
1148 // SET PACKET TIME
1148 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1149 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1149 //
1150 //
1150 header->time[0] = header->acquisitionTime[0];
1151 header->time[0] = header->acquisitionTime[0];
1151 header->time[1] = header->acquisitionTime[1];
1152 header->time[1] = header->acquisitionTime[1];
1152 header->time[2] = header->acquisitionTime[2];
1153 header->time[2] = header->acquisitionTime[2];
1153 header->time[3] = header->acquisitionTime[3];
1154 header->time[3] = header->acquisitionTime[3];
1154 header->time[4] = header->acquisitionTime[4];
1155 header->time[4] = header->acquisitionTime[4];
1155 header->time[5] = header->acquisitionTime[5];
1156 header->time[5] = header->acquisitionTime[5];
1156
1157
1157 // SET PACKET ID
1158 // SET PACKET ID
1158 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1159 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1159 {
1160 {
1160 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1161 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1161 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1162 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1162 }
1163 }
1163 else
1164 else
1164 {
1165 {
1165 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1166 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1166 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1167 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1167 }
1168 }
1168
1169
1169 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1170 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1170 if (status != RTEMS_SUCCESSFUL) {
1171 if (status != RTEMS_SUCCESSFUL) {
1171 ret = LFR_DEFAULT;
1172 ret = LFR_DEFAULT;
1172 }
1173 }
1173 }
1174 }
1174
1175
1175 return ret;
1176 return ret;
1176 }
1177 }
1177
1178
1178 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1179 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1179 Header_TM_LFR_SCIENCE_SWF_t *header )
1180 Header_TM_LFR_SCIENCE_SWF_t *header )
1180 {
1181 {
1181 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1182 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1182 *
1183 *
1183 * @param waveform points to the buffer containing the data that will be send.
1184 * @param waveform points to the buffer containing the data that will be send.
1184 * @param sid is the source identifier of the data that will be sent.
1185 * @param sid is the source identifier of the data that will be sent.
1185 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1186 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1186 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1187 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1187 * contain information to setup the transmission of the data packets.
1188 * contain information to setup the transmission of the data packets.
1188 *
1189 *
1189 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1190 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1190 *
1191 *
1191 */
1192 */
1192
1193
1193 unsigned int i;
1194 unsigned int i;
1194 int ret;
1195 int ret;
1195 unsigned int coarseTime;
1196 unsigned int coarseTime;
1196 unsigned int fineTime;
1197 unsigned int fineTime;
1197 rtems_status_code status;
1198 rtems_status_code status;
1198 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1199 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1199 int *dataPtr;
1200 int *dataPtr;
1200 unsigned char sid;
1201 unsigned char sid;
1201
1202
1202 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1203 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1203 spw_ioctl_send_SWF.options = 0;
1204 spw_ioctl_send_SWF.options = 0;
1204
1205
1205 ret = LFR_DEFAULT;
1206 ret = LFR_DEFAULT;
1206
1207
1207 coarseTime = ring_node_to_send->coarseTime;
1208 coarseTime = ring_node_to_send->coarseTime;
1208 fineTime = ring_node_to_send->fineTime;
1209 fineTime = ring_node_to_send->fineTime;
1209 dataPtr = (int*) ring_node_to_send->buffer_address;
1210 dataPtr = (int*) ring_node_to_send->buffer_address;
1210 sid = ring_node_to_send->sid;
1211 sid = ring_node_to_send->sid;
1211
1212
1212 header->pa_bia_status_info = pa_bia_status_info;
1213 header->pa_bia_status_info = pa_bia_status_info;
1213 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1214 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1214
1215
1215 for (i=0; i<7; i++) // send waveform
1216 for (i=0; i<7; i++) // send waveform
1216 {
1217 {
1217 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1218 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1218 spw_ioctl_send_SWF.hdr = (char*) header;
1219 spw_ioctl_send_SWF.hdr = (char*) header;
1219
1220
1220 // SET PACKET SEQUENCE CONTROL
1221 // SET PACKET SEQUENCE CONTROL
1221 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1222 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1222
1223
1223 // SET PACKET LENGTH AND BLKNR
1224 // SET PACKET LENGTH AND BLKNR
1224 if (i == 6)
1225 if (i == 6)
1225 {
1226 {
1226 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1227 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1227 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1228 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1228 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1229 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1229 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1230 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1230 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1231 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1231 }
1232 }
1232 else
1233 else
1233 {
1234 {
1234 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1235 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1235 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1236 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1236 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1237 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1237 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1238 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1238 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1239 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1239 }
1240 }
1240
1241
1241 // SET PACKET TIME
1242 // SET PACKET TIME
1242 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1243 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1243 //
1244 //
1244 header->time[0] = header->acquisitionTime[0];
1245 header->time[0] = header->acquisitionTime[0];
1245 header->time[1] = header->acquisitionTime[1];
1246 header->time[1] = header->acquisitionTime[1];
1246 header->time[2] = header->acquisitionTime[2];
1247 header->time[2] = header->acquisitionTime[2];
1247 header->time[3] = header->acquisitionTime[3];
1248 header->time[3] = header->acquisitionTime[3];
1248 header->time[4] = header->acquisitionTime[4];
1249 header->time[4] = header->acquisitionTime[4];
1249 header->time[5] = header->acquisitionTime[5];
1250 header->time[5] = header->acquisitionTime[5];
1250
1251
1251 // SET SID
1252 // SET SID
1252 header->sid = sid;
1253 header->sid = sid;
1253
1254
1254 // SET PKTNR
1255 // SET PKTNR
1255 header->pktNr = i+1; // PKT_NR
1256 header->pktNr = i+1; // PKT_NR
1256
1257
1257 // SEND PACKET
1258 // SEND PACKET
1258 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1259 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1259 if (status != RTEMS_SUCCESSFUL) {
1260 if (status != RTEMS_SUCCESSFUL) {
1260 ret = LFR_DEFAULT;
1261 ret = LFR_DEFAULT;
1261 }
1262 }
1262 }
1263 }
1263
1264
1264 return ret;
1265 return ret;
1265 }
1266 }
1266
1267
1267 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1268 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1268 Header_TM_LFR_SCIENCE_CWF_t *header )
1269 Header_TM_LFR_SCIENCE_CWF_t *header )
1269 {
1270 {
1270 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1271 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1271 *
1272 *
1272 * @param waveform points to the buffer containing the data that will be send.
1273 * @param waveform points to the buffer containing the data that will be send.
1273 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1274 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1274 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1275 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1275 * contain information to setup the transmission of the data packets.
1276 * contain information to setup the transmission of the data packets.
1276 *
1277 *
1277 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1278 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1278 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1279 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1279 *
1280 *
1280 */
1281 */
1281
1282
1282 unsigned int i;
1283 unsigned int i;
1283 int ret;
1284 int ret;
1284 unsigned int coarseTime;
1285 unsigned int coarseTime;
1285 unsigned int fineTime;
1286 unsigned int fineTime;
1286 rtems_status_code status;
1287 rtems_status_code status;
1287 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1288 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1288 char *dataPtr;
1289 char *dataPtr;
1289 unsigned char sid;
1290 unsigned char sid;
1290
1291
1291 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1292 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1292 spw_ioctl_send_CWF.options = 0;
1293 spw_ioctl_send_CWF.options = 0;
1293
1294
1294 ret = LFR_DEFAULT;
1295 ret = LFR_DEFAULT;
1295 sid = ring_node_to_send->sid;
1296 sid = ring_node_to_send->sid;
1296
1297
1297 coarseTime = ring_node_to_send->coarseTime;
1298 coarseTime = ring_node_to_send->coarseTime;
1298 fineTime = ring_node_to_send->fineTime;
1299 fineTime = ring_node_to_send->fineTime;
1299 dataPtr = (char*) ring_node_to_send->buffer_address;
1300 dataPtr = (char*) ring_node_to_send->buffer_address;
1300
1301
1301 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1302 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1302 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1303 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1303 header->pa_bia_status_info = pa_bia_status_info;
1304 header->pa_bia_status_info = pa_bia_status_info;
1304 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1305 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1305 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1306 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1306 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1307 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1307
1308
1308 //*********************
1309 //*********************
1309 // SEND CWF3_light DATA
1310 // SEND CWF3_light DATA
1310 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1311 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1311 {
1312 {
1312 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1313 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1313 spw_ioctl_send_CWF.hdr = (char*) header;
1314 spw_ioctl_send_CWF.hdr = (char*) header;
1314 // BUILD THE DATA
1315 // BUILD THE DATA
1315 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1316 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1316
1317
1317 // SET PACKET SEQUENCE COUNTER
1318 // SET PACKET SEQUENCE COUNTER
1318 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1319 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1319
1320
1320 // SET SID
1321 // SET SID
1321 header->sid = sid;
1322 header->sid = sid;
1322
1323
1323 // SET PACKET TIME
1324 // SET PACKET TIME
1324 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1325 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1325 //
1326 //
1326 header->time[0] = header->acquisitionTime[0];
1327 header->time[0] = header->acquisitionTime[0];
1327 header->time[1] = header->acquisitionTime[1];
1328 header->time[1] = header->acquisitionTime[1];
1328 header->time[2] = header->acquisitionTime[2];
1329 header->time[2] = header->acquisitionTime[2];
1329 header->time[3] = header->acquisitionTime[3];
1330 header->time[3] = header->acquisitionTime[3];
1330 header->time[4] = header->acquisitionTime[4];
1331 header->time[4] = header->acquisitionTime[4];
1331 header->time[5] = header->acquisitionTime[5];
1332 header->time[5] = header->acquisitionTime[5];
1332
1333
1333 // SET PACKET ID
1334 // SET PACKET ID
1334 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1335 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1335 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1336 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1336
1337
1337 // SEND PACKET
1338 // SEND PACKET
1338 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1339 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1339 if (status != RTEMS_SUCCESSFUL) {
1340 if (status != RTEMS_SUCCESSFUL) {
1340 ret = LFR_DEFAULT;
1341 ret = LFR_DEFAULT;
1341 }
1342 }
1342 }
1343 }
1343
1344
1344 return ret;
1345 return ret;
1345 }
1346 }
1346
1347
1347 void spw_send_asm_f0( ring_node *ring_node_to_send,
1348 void spw_send_asm_f0( ring_node *ring_node_to_send,
1348 Header_TM_LFR_SCIENCE_ASM_t *header )
1349 Header_TM_LFR_SCIENCE_ASM_t *header )
1349 {
1350 {
1350 unsigned int i;
1351 unsigned int i;
1351 unsigned int length = 0;
1352 unsigned int length = 0;
1352 rtems_status_code status;
1353 rtems_status_code status;
1353 unsigned int sid;
1354 unsigned int sid;
1354 float *spectral_matrix;
1355 float *spectral_matrix;
1355 int coarseTime;
1356 int coarseTime;
1356 int fineTime;
1357 int fineTime;
1357 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1358 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1358
1359
1359 sid = ring_node_to_send->sid;
1360 sid = ring_node_to_send->sid;
1360 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1361 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1361 coarseTime = ring_node_to_send->coarseTime;
1362 coarseTime = ring_node_to_send->coarseTime;
1362 fineTime = ring_node_to_send->fineTime;
1363 fineTime = ring_node_to_send->fineTime;
1363
1364
1364 header->pa_bia_status_info = pa_bia_status_info;
1365 header->pa_bia_status_info = pa_bia_status_info;
1365 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1366 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1366
1367
1367 for (i=0; i<3; i++)
1368 for (i=0; i<3; i++)
1368 {
1369 {
1369 if ((i==0) || (i==1))
1370 if ((i==0) || (i==1))
1370 {
1371 {
1371 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1372 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1372 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1373 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1373 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1374 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1374 ];
1375 ];
1375 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1376 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1376 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1377 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1377 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1378 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1378 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1379 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1379 }
1380 }
1380 else
1381 else
1381 {
1382 {
1382 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1383 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1384 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1384 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1385 ];
1386 ];
1386 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1387 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1388 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1389 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1390 }
1391 }
1391
1392
1392 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1393 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1393 spw_ioctl_send_ASM.hdr = (char *) header;
1394 spw_ioctl_send_ASM.hdr = (char *) header;
1394 spw_ioctl_send_ASM.options = 0;
1395 spw_ioctl_send_ASM.options = 0;
1395
1396
1396 // (2) BUILD THE HEADER
1397 // (2) BUILD THE HEADER
1397 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1398 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1398 header->packetLength[0] = (unsigned char) (length>>8);
1399 header->packetLength[0] = (unsigned char) (length>>8);
1399 header->packetLength[1] = (unsigned char) (length);
1400 header->packetLength[1] = (unsigned char) (length);
1400 header->sid = (unsigned char) sid; // SID
1401 header->sid = (unsigned char) sid; // SID
1401 header->pa_lfr_pkt_cnt_asm = 3;
1402 header->pa_lfr_pkt_cnt_asm = 3;
1402 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1403 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1403
1404
1404 // (3) SET PACKET TIME
1405 // (3) SET PACKET TIME
1405 header->time[0] = (unsigned char) (coarseTime>>24);
1406 header->time[0] = (unsigned char) (coarseTime>>24);
1406 header->time[1] = (unsigned char) (coarseTime>>16);
1407 header->time[1] = (unsigned char) (coarseTime>>16);
1407 header->time[2] = (unsigned char) (coarseTime>>8);
1408 header->time[2] = (unsigned char) (coarseTime>>8);
1408 header->time[3] = (unsigned char) (coarseTime);
1409 header->time[3] = (unsigned char) (coarseTime);
1409 header->time[4] = (unsigned char) (fineTime>>8);
1410 header->time[4] = (unsigned char) (fineTime>>8);
1410 header->time[5] = (unsigned char) (fineTime);
1411 header->time[5] = (unsigned char) (fineTime);
1411 //
1412 //
1412 header->acquisitionTime[0] = header->time[0];
1413 header->acquisitionTime[0] = header->time[0];
1413 header->acquisitionTime[1] = header->time[1];
1414 header->acquisitionTime[1] = header->time[1];
1414 header->acquisitionTime[2] = header->time[2];
1415 header->acquisitionTime[2] = header->time[2];
1415 header->acquisitionTime[3] = header->time[3];
1416 header->acquisitionTime[3] = header->time[3];
1416 header->acquisitionTime[4] = header->time[4];
1417 header->acquisitionTime[4] = header->time[4];
1417 header->acquisitionTime[5] = header->time[5];
1418 header->acquisitionTime[5] = header->time[5];
1418
1419
1419 // (4) SEND PACKET
1420 // (4) SEND PACKET
1420 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1421 if (status != RTEMS_SUCCESSFUL) {
1422 if (status != RTEMS_SUCCESSFUL) {
1422 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1423 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1423 }
1424 }
1424 }
1425 }
1425 }
1426 }
1426
1427
1427 void spw_send_asm_f1( ring_node *ring_node_to_send,
1428 void spw_send_asm_f1( ring_node *ring_node_to_send,
1428 Header_TM_LFR_SCIENCE_ASM_t *header )
1429 Header_TM_LFR_SCIENCE_ASM_t *header )
1429 {
1430 {
1430 unsigned int i;
1431 unsigned int i;
1431 unsigned int length = 0;
1432 unsigned int length = 0;
1432 rtems_status_code status;
1433 rtems_status_code status;
1433 unsigned int sid;
1434 unsigned int sid;
1434 float *spectral_matrix;
1435 float *spectral_matrix;
1435 int coarseTime;
1436 int coarseTime;
1436 int fineTime;
1437 int fineTime;
1437 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1438 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1438
1439
1439 sid = ring_node_to_send->sid;
1440 sid = ring_node_to_send->sid;
1440 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1441 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1441 coarseTime = ring_node_to_send->coarseTime;
1442 coarseTime = ring_node_to_send->coarseTime;
1442 fineTime = ring_node_to_send->fineTime;
1443 fineTime = ring_node_to_send->fineTime;
1443
1444
1444 header->pa_bia_status_info = pa_bia_status_info;
1445 header->pa_bia_status_info = pa_bia_status_info;
1445 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1446 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1446
1447
1447 for (i=0; i<3; i++)
1448 for (i=0; i<3; i++)
1448 {
1449 {
1449 if ((i==0) || (i==1))
1450 if ((i==0) || (i==1))
1450 {
1451 {
1451 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1452 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1452 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1453 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1453 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1454 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1454 ];
1455 ];
1455 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1456 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1456 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1457 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1457 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1458 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1458 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1459 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1459 }
1460 }
1460 else
1461 else
1461 {
1462 {
1462 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1463 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1464 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1464 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1465 ];
1466 ];
1466 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1467 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1468 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1469 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1470 }
1471 }
1471
1472
1472 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1473 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1473 spw_ioctl_send_ASM.hdr = (char *) header;
1474 spw_ioctl_send_ASM.hdr = (char *) header;
1474 spw_ioctl_send_ASM.options = 0;
1475 spw_ioctl_send_ASM.options = 0;
1475
1476
1476 // (2) BUILD THE HEADER
1477 // (2) BUILD THE HEADER
1477 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1478 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1478 header->packetLength[0] = (unsigned char) (length>>8);
1479 header->packetLength[0] = (unsigned char) (length>>8);
1479 header->packetLength[1] = (unsigned char) (length);
1480 header->packetLength[1] = (unsigned char) (length);
1480 header->sid = (unsigned char) sid; // SID
1481 header->sid = (unsigned char) sid; // SID
1481 header->pa_lfr_pkt_cnt_asm = 3;
1482 header->pa_lfr_pkt_cnt_asm = 3;
1482 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1483 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1483
1484
1484 // (3) SET PACKET TIME
1485 // (3) SET PACKET TIME
1485 header->time[0] = (unsigned char) (coarseTime>>24);
1486 header->time[0] = (unsigned char) (coarseTime>>24);
1486 header->time[1] = (unsigned char) (coarseTime>>16);
1487 header->time[1] = (unsigned char) (coarseTime>>16);
1487 header->time[2] = (unsigned char) (coarseTime>>8);
1488 header->time[2] = (unsigned char) (coarseTime>>8);
1488 header->time[3] = (unsigned char) (coarseTime);
1489 header->time[3] = (unsigned char) (coarseTime);
1489 header->time[4] = (unsigned char) (fineTime>>8);
1490 header->time[4] = (unsigned char) (fineTime>>8);
1490 header->time[5] = (unsigned char) (fineTime);
1491 header->time[5] = (unsigned char) (fineTime);
1491 //
1492 //
1492 header->acquisitionTime[0] = header->time[0];
1493 header->acquisitionTime[0] = header->time[0];
1493 header->acquisitionTime[1] = header->time[1];
1494 header->acquisitionTime[1] = header->time[1];
1494 header->acquisitionTime[2] = header->time[2];
1495 header->acquisitionTime[2] = header->time[2];
1495 header->acquisitionTime[3] = header->time[3];
1496 header->acquisitionTime[3] = header->time[3];
1496 header->acquisitionTime[4] = header->time[4];
1497 header->acquisitionTime[4] = header->time[4];
1497 header->acquisitionTime[5] = header->time[5];
1498 header->acquisitionTime[5] = header->time[5];
1498
1499
1499 // (4) SEND PACKET
1500 // (4) SEND PACKET
1500 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1501 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1501 if (status != RTEMS_SUCCESSFUL) {
1502 if (status != RTEMS_SUCCESSFUL) {
1502 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1503 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1503 }
1504 }
1504 }
1505 }
1505 }
1506 }
1506
1507
1507 void spw_send_asm_f2( ring_node *ring_node_to_send,
1508 void spw_send_asm_f2( ring_node *ring_node_to_send,
1508 Header_TM_LFR_SCIENCE_ASM_t *header )
1509 Header_TM_LFR_SCIENCE_ASM_t *header )
1509 {
1510 {
1510 unsigned int i;
1511 unsigned int i;
1511 unsigned int length = 0;
1512 unsigned int length = 0;
1512 rtems_status_code status;
1513 rtems_status_code status;
1513 unsigned int sid;
1514 unsigned int sid;
1514 float *spectral_matrix;
1515 float *spectral_matrix;
1515 int coarseTime;
1516 int coarseTime;
1516 int fineTime;
1517 int fineTime;
1517 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1518 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1518
1519
1519 sid = ring_node_to_send->sid;
1520 sid = ring_node_to_send->sid;
1520 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1521 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1521 coarseTime = ring_node_to_send->coarseTime;
1522 coarseTime = ring_node_to_send->coarseTime;
1522 fineTime = ring_node_to_send->fineTime;
1523 fineTime = ring_node_to_send->fineTime;
1523
1524
1524 header->pa_bia_status_info = pa_bia_status_info;
1525 header->pa_bia_status_info = pa_bia_status_info;
1525 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1526 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1526
1527
1527 for (i=0; i<3; i++)
1528 for (i=0; i<3; i++)
1528 {
1529 {
1529
1530
1530 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1531 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1531 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1532 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1532 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1533 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1533 ];
1534 ];
1534 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1535 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1535 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1536 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1536 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1537 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1537 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1538 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1538
1539
1539 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1540 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1540 spw_ioctl_send_ASM.hdr = (char *) header;
1541 spw_ioctl_send_ASM.hdr = (char *) header;
1541 spw_ioctl_send_ASM.options = 0;
1542 spw_ioctl_send_ASM.options = 0;
1542
1543
1543 // (2) BUILD THE HEADER
1544 // (2) BUILD THE HEADER
1544 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1545 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1545 header->packetLength[0] = (unsigned char) (length>>8);
1546 header->packetLength[0] = (unsigned char) (length>>8);
1546 header->packetLength[1] = (unsigned char) (length);
1547 header->packetLength[1] = (unsigned char) (length);
1547 header->sid = (unsigned char) sid; // SID
1548 header->sid = (unsigned char) sid; // SID
1548 header->pa_lfr_pkt_cnt_asm = 3;
1549 header->pa_lfr_pkt_cnt_asm = 3;
1549 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1550 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1550
1551
1551 // (3) SET PACKET TIME
1552 // (3) SET PACKET TIME
1552 header->time[0] = (unsigned char) (coarseTime>>24);
1553 header->time[0] = (unsigned char) (coarseTime>>24);
1553 header->time[1] = (unsigned char) (coarseTime>>16);
1554 header->time[1] = (unsigned char) (coarseTime>>16);
1554 header->time[2] = (unsigned char) (coarseTime>>8);
1555 header->time[2] = (unsigned char) (coarseTime>>8);
1555 header->time[3] = (unsigned char) (coarseTime);
1556 header->time[3] = (unsigned char) (coarseTime);
1556 header->time[4] = (unsigned char) (fineTime>>8);
1557 header->time[4] = (unsigned char) (fineTime>>8);
1557 header->time[5] = (unsigned char) (fineTime);
1558 header->time[5] = (unsigned char) (fineTime);
1558 //
1559 //
1559 header->acquisitionTime[0] = header->time[0];
1560 header->acquisitionTime[0] = header->time[0];
1560 header->acquisitionTime[1] = header->time[1];
1561 header->acquisitionTime[1] = header->time[1];
1561 header->acquisitionTime[2] = header->time[2];
1562 header->acquisitionTime[2] = header->time[2];
1562 header->acquisitionTime[3] = header->time[3];
1563 header->acquisitionTime[3] = header->time[3];
1563 header->acquisitionTime[4] = header->time[4];
1564 header->acquisitionTime[4] = header->time[4];
1564 header->acquisitionTime[5] = header->time[5];
1565 header->acquisitionTime[5] = header->time[5];
1565
1566
1566 // (4) SEND PACKET
1567 // (4) SEND PACKET
1567 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1568 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1568 if (status != RTEMS_SUCCESSFUL) {
1569 if (status != RTEMS_SUCCESSFUL) {
1569 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1570 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1570 }
1571 }
1571 }
1572 }
1572 }
1573 }
1573
1574
1574 void spw_send_k_dump( ring_node *ring_node_to_send )
1575 void spw_send_k_dump( ring_node *ring_node_to_send )
1575 {
1576 {
1576 rtems_status_code status;
1577 rtems_status_code status;
1577 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1578 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1578 unsigned int packetLength;
1579 unsigned int packetLength;
1579 unsigned int size;
1580 unsigned int size;
1580
1581
1581 PRINTF("spw_send_k_dump\n")
1582 PRINTF("spw_send_k_dump\n")
1582
1583
1583 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1584 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1584
1585
1585 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1586 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1586
1587
1587 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1588 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1588
1589
1589 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1590 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1590
1591
1591 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1592 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1592
1593
1593 if (status == -1){
1594 if (status == -1){
1594 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1595 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1595 }
1596 }
1596
1597
1597 ring_node_to_send->status = 0x00;
1598 ring_node_to_send->status = 0x00;
1598 }
1599 }
@@ -1,1566 +1,1567
1 /** Functions to load and dump parameters in the LFR registers.
1 /** Functions to load and dump parameters in the LFR registers.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
7 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
12 *
12 *
13 */
13 */
14
14
15 #include "tc_load_dump_parameters.h"
15 #include "tc_load_dump_parameters.h"
16
16
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 ring_node kcoefficient_node_1;
19 ring_node kcoefficient_node_1;
20 ring_node kcoefficient_node_2;
20 ring_node kcoefficient_node_2;
21
21
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
23 {
24 /** This function updates the LFR registers with the incoming common parameters.
24 /** This function updates the LFR registers with the incoming common parameters.
25 *
25 *
26 * @param TC points to the TeleCommand packet that is being processed
26 * @param TC points to the TeleCommand packet that is being processed
27 *
27 *
28 *
28 *
29 */
29 */
30
30
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
33 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
34 return LFR_SUCCESSFUL;
35 }
35 }
36
36
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
38 {
39 /** This function updates the LFR registers with the incoming normal parameters.
39 /** This function updates the LFR registers with the incoming normal parameters.
40 *
40 *
41 * @param TC points to the TeleCommand packet that is being processed
41 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int result;
46 int result;
47 int flag;
47 int flag;
48 rtems_status_code status;
48 rtems_status_code status;
49
49
50 flag = LFR_SUCCESSFUL;
50 flag = LFR_SUCCESSFUL;
51
51
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
55 flag = LFR_DEFAULT;
56 }
56 }
57
57
58 // CHECK THE PARAMETERS SET CONSISTENCY
58 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
59 if (flag == LFR_SUCCESSFUL)
60 {
60 {
61 flag = check_normal_par_consistency( TC, queue_id );
61 flag = check_normal_par_consistency( TC, queue_id );
62 }
62 }
63
63
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
65 if (flag == LFR_SUCCESSFUL)
66 {
66 {
67 result = set_sy_lfr_n_swf_l( TC );
67 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
68 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
71 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
73 }
74
74
75 return flag;
75 return flag;
76 }
76 }
77
77
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
79 {
80 /** This function updates the LFR registers with the incoming burst parameters.
80 /** This function updates the LFR registers with the incoming burst parameters.
81 *
81 *
82 * @param TC points to the TeleCommand packet that is being processed
82 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
87 int flag;
88 rtems_status_code status;
88 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
89 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
90 unsigned char sy_lfr_b_bp_p1;
91 float aux;
91 float aux;
92
92
93 flag = LFR_SUCCESSFUL;
93 flag = LFR_SUCCESSFUL;
94
94
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
97 flag = LFR_DEFAULT;
98 }
98 }
99
99
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
102
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
104 if (flag == LFR_SUCCESSFUL)
105 {
105 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
107 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
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 flag = WRONG_APP_DATA;
109 flag = WRONG_APP_DATA;
110 }
110 }
111 }
111 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
113 if (flag == LFR_SUCCESSFUL)
114 {
114 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
116 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
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 flag = WRONG_APP_DATA;
118 flag = WRONG_APP_DATA;
119 }
119 }
120 }
120 }
121 //****************************************************************
121 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
123 if (flag == LFR_SUCCESSFUL)
124 {
124 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
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 if (aux > FLOAT_EQUAL_ZERO)
128 if (aux > FLOAT_EQUAL_ZERO)
129 {
129 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
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 flag = LFR_DEFAULT;
131 flag = LFR_DEFAULT;
132 }
132 }
133 }
133 }
134
134
135 // SET THE PARAMETERS
135 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
136 if (flag == LFR_SUCCESSFUL)
137 {
137 {
138 flag = set_sy_lfr_b_bp_p0( TC );
138 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
140 }
140 }
141
141
142 return flag;
142 return flag;
143 }
143 }
144
144
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
146 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
148 *
149 * @param TC points to the TeleCommand packet that is being processed
149 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
154 int flag;
155 rtems_status_code status;
155 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
156 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
157 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
158 float aux;
159
159
160 flag = LFR_SUCCESSFUL;
160 flag = LFR_SUCCESSFUL;
161
161
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
164 flag = LFR_DEFAULT;
165 }
165 }
166
166
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
169
170 // sy_lfr_s1_bp_p0
170 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
171 if (flag == LFR_SUCCESSFUL)
172 {
172 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
174 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
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 flag = WRONG_APP_DATA;
176 flag = WRONG_APP_DATA;
177 }
177 }
178 }
178 }
179 // sy_lfr_s1_bp_p1
179 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
180 if (flag == LFR_SUCCESSFUL)
181 {
181 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
183 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
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 flag = WRONG_APP_DATA;
185 flag = WRONG_APP_DATA;
186 }
186 }
187 }
187 }
188 //******************************************************************
188 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
190 if (flag == LFR_SUCCESSFUL)
191 {
191 {
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));
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 if (aux > FLOAT_EQUAL_ZERO)
193 if (aux > FLOAT_EQUAL_ZERO)
194 {
194 {
195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
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 flag = LFR_DEFAULT;
196 flag = LFR_DEFAULT;
197 }
197 }
198 }
198 }
199
199
200 // SET THE PARAMETERS
200 // SET THE PARAMETERS
201 if (flag == LFR_SUCCESSFUL)
201 if (flag == LFR_SUCCESSFUL)
202 {
202 {
203 flag = set_sy_lfr_s1_bp_p0( TC );
203 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p1( TC );
204 flag = set_sy_lfr_s1_bp_p1( TC );
205 }
205 }
206
206
207 return flag;
207 return flag;
208 }
208 }
209
209
210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 {
211 {
212 /** This function updates the LFR registers with the incoming sbm2 parameters.
212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 *
213 *
214 * @param TC points to the TeleCommand packet that is being processed
214 * @param TC points to the TeleCommand packet that is being processed
215 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
219 int flag;
220 rtems_status_code status;
220 rtems_status_code status;
221 unsigned char sy_lfr_s2_bp_p0;
221 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p1;
222 unsigned char sy_lfr_s2_bp_p1;
223 float aux;
223 float aux;
224
224
225 flag = LFR_SUCCESSFUL;
225 flag = LFR_SUCCESSFUL;
226
226
227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 flag = LFR_DEFAULT;
229 flag = LFR_DEFAULT;
230 }
230 }
231
231
232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234
234
235 // sy_lfr_s2_bp_p0
235 // sy_lfr_s2_bp_p0
236 if (flag == LFR_SUCCESSFUL)
236 if (flag == LFR_SUCCESSFUL)
237 {
237 {
238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 {
239 {
240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
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 flag = WRONG_APP_DATA;
241 flag = WRONG_APP_DATA;
242 }
242 }
243 }
243 }
244 // sy_lfr_s2_bp_p1
244 // sy_lfr_s2_bp_p1
245 if (flag == LFR_SUCCESSFUL)
245 if (flag == LFR_SUCCESSFUL)
246 {
246 {
247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 {
248 {
249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
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 flag = WRONG_APP_DATA;
250 flag = WRONG_APP_DATA;
251 }
251 }
252 }
252 }
253 //******************************************************************
253 //******************************************************************
254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 if (flag == LFR_SUCCESSFUL)
255 if (flag == LFR_SUCCESSFUL)
256 {
256 {
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
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 if (aux > FLOAT_EQUAL_ZERO)
260 if (aux > FLOAT_EQUAL_ZERO)
261 {
261 {
262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
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 flag = LFR_DEFAULT;
263 flag = LFR_DEFAULT;
264 }
264 }
265 }
265 }
266
266
267 // SET THE PARAMETERS
267 // SET THE PARAMETERS
268 if (flag == LFR_SUCCESSFUL)
268 if (flag == LFR_SUCCESSFUL)
269 {
269 {
270 flag = set_sy_lfr_s2_bp_p0( TC );
270 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p1( TC );
271 flag = set_sy_lfr_s2_bp_p1( TC );
272 }
272 }
273
273
274 return flag;
274 return flag;
275 }
275 }
276
276
277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 {
278 {
279 /** This function updates the LFR registers with the incoming sbm2 parameters.
279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 *
280 *
281 * @param TC points to the TeleCommand packet that is being processed
281 * @param TC points to the TeleCommand packet that is being processed
282 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
286 int flag;
287
287
288 flag = LFR_DEFAULT;
288 flag = LFR_DEFAULT;
289
289
290 flag = set_sy_lfr_kcoeff( TC, queue_id );
290 flag = set_sy_lfr_kcoeff( TC, queue_id );
291
291
292 return flag;
292 return flag;
293 }
293 }
294
294
295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 {
296 {
297 /** This function updates the LFR registers with the incoming sbm2 parameters.
297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 *
298 *
299 * @param TC points to the TeleCommand packet that is being processed
299 * @param TC points to the TeleCommand packet that is being processed
300 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
304 int flag;
305
305
306 flag = LFR_DEFAULT;
306 flag = LFR_DEFAULT;
307
307
308 flag = set_sy_lfr_fbins( TC );
308 flag = set_sy_lfr_fbins( TC );
309
309
310 return flag;
310 return flag;
311 }
311 }
312
312
313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 {
314 {
315 /** This function updates the LFR registers with the incoming sbm2 parameters.
315 /** This function updates the LFR registers with the incoming sbm2 parameters.
316 *
316 *
317 * @param TC points to the TeleCommand packet that is being processed
317 * @param TC points to the TeleCommand packet that is being processed
318 * @param queue_id is the id of the queue which handles TM related to this execution step
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 int flag;
322 int flag;
323
323
324 flag = LFR_DEFAULT;
324 flag = LFR_DEFAULT;
325
325
326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
327
327
328 if (flag == LFR_SUCCESSFUL)
328 if (flag == LFR_SUCCESSFUL)
329 {
329 {
330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
345
345
346 //****************************
346 //****************************
347 // store PAS filter parameters
347 // store PAS filter parameters
348 // sy_lfr_pas_filter_enabled
348 // sy_lfr_pas_filter_enabled
349 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
349 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
350 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 );
350 // sy_lfr_pas_filter_modulus
351 // sy_lfr_pas_filter_modulus
351 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
352 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
352 // sy_lfr_pas_filter_tbad
353 // sy_lfr_pas_filter_tbad
353 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
354 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
354 parameter_dump_packet.sy_lfr_pas_filter_tbad );
355 parameter_dump_packet.sy_lfr_pas_filter_tbad );
355 // sy_lfr_pas_filter_offset
356 // sy_lfr_pas_filter_offset
356 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
357 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
357 // sy_lfr_pas_filter_shift
358 // sy_lfr_pas_filter_shift
358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
359 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
359 parameter_dump_packet.sy_lfr_pas_filter_shift );
360 parameter_dump_packet.sy_lfr_pas_filter_shift );
360
361
361 //****************************************************
362 //****************************************************
362 // store the parameter sy_lfr_sc_rw_delta_f as a float
363 // store the parameter sy_lfr_sc_rw_delta_f as a float
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
364 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
364 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
365 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
365 }
366 }
366
367
367 return flag;
368 return flag;
368 }
369 }
369
370
370 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
371 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
371 {
372 {
372 /** This function updates the LFR registers with the incoming sbm2 parameters.
373 /** This function updates the LFR registers with the incoming sbm2 parameters.
373 *
374 *
374 * @param TC points to the TeleCommand packet that is being processed
375 * @param TC points to the TeleCommand packet that is being processed
375 * @param queue_id is the id of the queue which handles TM related to this execution step
376 * @param queue_id is the id of the queue which handles TM related to this execution step
376 *
377 *
377 */
378 */
378
379
379 unsigned int address;
380 unsigned int address;
380 rtems_status_code status;
381 rtems_status_code status;
381 unsigned int freq;
382 unsigned int freq;
382 unsigned int bin;
383 unsigned int bin;
383 unsigned int coeff;
384 unsigned int coeff;
384 unsigned char *kCoeffPtr;
385 unsigned char *kCoeffPtr;
385 unsigned char *kCoeffDumpPtr;
386 unsigned char *kCoeffDumpPtr;
386
387
387 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
388 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
388 // F0 => 11 bins
389 // F0 => 11 bins
389 // F1 => 13 bins
390 // F1 => 13 bins
390 // F2 => 12 bins
391 // F2 => 12 bins
391 // 36 bins to dump in two packets (30 bins max per packet)
392 // 36 bins to dump in two packets (30 bins max per packet)
392
393
393 //*********
394 //*********
394 // PACKET 1
395 // PACKET 1
395 // 11 F0 bins, 13 F1 bins and 6 F2 bins
396 // 11 F0 bins, 13 F1 bins and 6 F2 bins
396 kcoefficients_dump_1.destinationID = TC->sourceID;
397 kcoefficients_dump_1.destinationID = TC->sourceID;
397 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
398 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
398 for( freq=0;
399 for( freq=0;
399 freq<NB_BINS_COMPRESSED_SM_F0;
400 freq<NB_BINS_COMPRESSED_SM_F0;
400 freq++ )
401 freq++ )
401 {
402 {
402 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
403 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
403 bin = freq;
404 bin = freq;
404 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
405 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
405 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
406 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
406 {
407 {
407 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
408 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
408 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
409 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
409 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
410 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
410 }
411 }
411 }
412 }
412 for( freq=NB_BINS_COMPRESSED_SM_F0;
413 for( freq=NB_BINS_COMPRESSED_SM_F0;
413 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
414 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
414 freq++ )
415 freq++ )
415 {
416 {
416 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
417 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
417 bin = freq - NB_BINS_COMPRESSED_SM_F0;
418 bin = freq - NB_BINS_COMPRESSED_SM_F0;
418 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
419 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
419 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
420 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
420 {
421 {
421 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
422 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
422 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
423 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
423 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
424 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
424 }
425 }
425 }
426 }
426 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
427 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
427 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
428 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
428 freq++ )
429 freq++ )
429 {
430 {
430 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
431 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
431 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
432 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
432 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
433 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
433 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
434 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
434 {
435 {
435 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
436 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
436 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
437 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
437 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
438 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
438 }
439 }
439 }
440 }
440 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
441 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
441 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
442 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
442 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
443 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
443 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
444 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
444 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
445 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
445 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
446 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
446 // SEND DATA
447 // SEND DATA
447 kcoefficient_node_1.status = 1;
448 kcoefficient_node_1.status = 1;
448 address = (unsigned int) &kcoefficient_node_1;
449 address = (unsigned int) &kcoefficient_node_1;
449 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
450 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
450 if (status != RTEMS_SUCCESSFUL) {
451 if (status != RTEMS_SUCCESSFUL) {
451 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
452 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
452 }
453 }
453
454
454 //********
455 //********
455 // PACKET 2
456 // PACKET 2
456 // 6 F2 bins
457 // 6 F2 bins
457 kcoefficients_dump_2.destinationID = TC->sourceID;
458 kcoefficients_dump_2.destinationID = TC->sourceID;
458 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
459 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
459 for( freq=0; freq<6; freq++ )
460 for( freq=0; freq<6; freq++ )
460 {
461 {
461 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
462 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
462 bin = freq + 6;
463 bin = freq + 6;
463 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
464 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
464 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
465 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
465 {
466 {
466 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
467 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
467 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
468 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
468 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
469 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
469 }
470 }
470 }
471 }
471 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
472 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
472 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
473 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
473 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
474 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
474 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
475 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
475 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
476 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
476 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
477 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
477 // SEND DATA
478 // SEND DATA
478 kcoefficient_node_2.status = 1;
479 kcoefficient_node_2.status = 1;
479 address = (unsigned int) &kcoefficient_node_2;
480 address = (unsigned int) &kcoefficient_node_2;
480 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
481 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
481 if (status != RTEMS_SUCCESSFUL) {
482 if (status != RTEMS_SUCCESSFUL) {
482 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
483 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
483 }
484 }
484
485
485 return status;
486 return status;
486 }
487 }
487
488
488 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
489 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
489 {
490 {
490 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
491 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
491 *
492 *
492 * @param queue_id is the id of the queue which handles TM related to this execution step.
493 * @param queue_id is the id of the queue which handles TM related to this execution step.
493 *
494 *
494 * @return RTEMS directive status codes:
495 * @return RTEMS directive status codes:
495 * - RTEMS_SUCCESSFUL - message sent successfully
496 * - RTEMS_SUCCESSFUL - message sent successfully
496 * - RTEMS_INVALID_ID - invalid queue id
497 * - RTEMS_INVALID_ID - invalid queue id
497 * - RTEMS_INVALID_SIZE - invalid message size
498 * - RTEMS_INVALID_SIZE - invalid message size
498 * - RTEMS_INVALID_ADDRESS - buffer is NULL
499 * - RTEMS_INVALID_ADDRESS - buffer is NULL
499 * - RTEMS_UNSATISFIED - out of message buffers
500 * - RTEMS_UNSATISFIED - out of message buffers
500 * - RTEMS_TOO_MANY - queue s limit has been reached
501 * - RTEMS_TOO_MANY - queue s limit has been reached
501 *
502 *
502 */
503 */
503
504
504 int status;
505 int status;
505
506
506 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
507 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
507 parameter_dump_packet.destinationID = TC->sourceID;
508 parameter_dump_packet.destinationID = TC->sourceID;
508
509
509 // UPDATE TIME
510 // UPDATE TIME
510 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
511 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
511 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
512 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
512 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
513 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
513 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
514 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
514 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
515 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
515 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
516 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
516 // SEND DATA
517 // SEND DATA
517 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
518 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
518 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
519 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
519 if (status != RTEMS_SUCCESSFUL) {
520 if (status != RTEMS_SUCCESSFUL) {
520 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
521 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
521 }
522 }
522
523
523 return status;
524 return status;
524 }
525 }
525
526
526 //***********************
527 //***********************
527 // NORMAL MODE PARAMETERS
528 // NORMAL MODE PARAMETERS
528
529
529 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
530 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
530 {
531 {
531 unsigned char msb;
532 unsigned char msb;
532 unsigned char lsb;
533 unsigned char lsb;
533 int flag;
534 int flag;
534 float aux;
535 float aux;
535 rtems_status_code status;
536 rtems_status_code status;
536
537
537 unsigned int sy_lfr_n_swf_l;
538 unsigned int sy_lfr_n_swf_l;
538 unsigned int sy_lfr_n_swf_p;
539 unsigned int sy_lfr_n_swf_p;
539 unsigned int sy_lfr_n_asm_p;
540 unsigned int sy_lfr_n_asm_p;
540 unsigned char sy_lfr_n_bp_p0;
541 unsigned char sy_lfr_n_bp_p0;
541 unsigned char sy_lfr_n_bp_p1;
542 unsigned char sy_lfr_n_bp_p1;
542 unsigned char sy_lfr_n_cwf_long_f3;
543 unsigned char sy_lfr_n_cwf_long_f3;
543
544
544 flag = LFR_SUCCESSFUL;
545 flag = LFR_SUCCESSFUL;
545
546
546 //***************
547 //***************
547 // get parameters
548 // get parameters
548 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
549 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
549 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
550 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
550 sy_lfr_n_swf_l = msb * 256 + lsb;
551 sy_lfr_n_swf_l = msb * 256 + lsb;
551
552
552 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
553 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
553 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
554 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
554 sy_lfr_n_swf_p = msb * 256 + lsb;
555 sy_lfr_n_swf_p = msb * 256 + lsb;
555
556
556 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
557 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
557 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
558 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
558 sy_lfr_n_asm_p = msb * 256 + lsb;
559 sy_lfr_n_asm_p = msb * 256 + lsb;
559
560
560 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
561 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
561
562
562 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
563 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
563
564
564 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
565 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
565
566
566 //******************
567 //******************
567 // check consistency
568 // check consistency
568 // sy_lfr_n_swf_l
569 // sy_lfr_n_swf_l
569 if (sy_lfr_n_swf_l != 2048)
570 if (sy_lfr_n_swf_l != 2048)
570 {
571 {
571 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
572 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
572 flag = WRONG_APP_DATA;
573 flag = WRONG_APP_DATA;
573 }
574 }
574 // sy_lfr_n_swf_p
575 // sy_lfr_n_swf_p
575 if (flag == LFR_SUCCESSFUL)
576 if (flag == LFR_SUCCESSFUL)
576 {
577 {
577 if ( sy_lfr_n_swf_p < 22 )
578 if ( sy_lfr_n_swf_p < 22 )
578 {
579 {
579 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
580 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
580 flag = WRONG_APP_DATA;
581 flag = WRONG_APP_DATA;
581 }
582 }
582 }
583 }
583 // sy_lfr_n_bp_p0
584 // sy_lfr_n_bp_p0
584 if (flag == LFR_SUCCESSFUL)
585 if (flag == LFR_SUCCESSFUL)
585 {
586 {
586 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
587 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
587 {
588 {
588 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
589 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
589 flag = WRONG_APP_DATA;
590 flag = WRONG_APP_DATA;
590 }
591 }
591 }
592 }
592 // sy_lfr_n_asm_p
593 // sy_lfr_n_asm_p
593 if (flag == LFR_SUCCESSFUL)
594 if (flag == LFR_SUCCESSFUL)
594 {
595 {
595 if (sy_lfr_n_asm_p == 0)
596 if (sy_lfr_n_asm_p == 0)
596 {
597 {
597 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
598 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
598 flag = WRONG_APP_DATA;
599 flag = WRONG_APP_DATA;
599 }
600 }
600 }
601 }
601 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
602 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
602 if (flag == LFR_SUCCESSFUL)
603 if (flag == LFR_SUCCESSFUL)
603 {
604 {
604 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
605 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
605 if (aux > FLOAT_EQUAL_ZERO)
606 if (aux > FLOAT_EQUAL_ZERO)
606 {
607 {
607 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
608 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
608 flag = WRONG_APP_DATA;
609 flag = WRONG_APP_DATA;
609 }
610 }
610 }
611 }
611 // sy_lfr_n_bp_p1
612 // sy_lfr_n_bp_p1
612 if (flag == LFR_SUCCESSFUL)
613 if (flag == LFR_SUCCESSFUL)
613 {
614 {
614 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
615 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
615 {
616 {
616 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
617 flag = WRONG_APP_DATA;
618 flag = WRONG_APP_DATA;
618 }
619 }
619 }
620 }
620 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
621 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
621 if (flag == LFR_SUCCESSFUL)
622 if (flag == LFR_SUCCESSFUL)
622 {
623 {
623 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
624 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
624 if (aux > FLOAT_EQUAL_ZERO)
625 if (aux > FLOAT_EQUAL_ZERO)
625 {
626 {
626 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
627 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
627 flag = LFR_DEFAULT;
628 flag = LFR_DEFAULT;
628 }
629 }
629 }
630 }
630 // sy_lfr_n_cwf_long_f3
631 // sy_lfr_n_cwf_long_f3
631
632
632 return flag;
633 return flag;
633 }
634 }
634
635
635 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
636 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
636 {
637 {
637 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
638 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
638 *
639 *
639 * @param TC points to the TeleCommand packet that is being processed
640 * @param TC points to the TeleCommand packet that is being processed
640 * @param queue_id is the id of the queue which handles TM related to this execution step
641 * @param queue_id is the id of the queue which handles TM related to this execution step
641 *
642 *
642 */
643 */
643
644
644 int result;
645 int result;
645
646
646 result = LFR_SUCCESSFUL;
647 result = LFR_SUCCESSFUL;
647
648
648 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
649 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
649 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
650 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
650
651
651 return result;
652 return result;
652 }
653 }
653
654
654 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
655 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
655 {
656 {
656 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
657 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
657 *
658 *
658 * @param TC points to the TeleCommand packet that is being processed
659 * @param TC points to the TeleCommand packet that is being processed
659 * @param queue_id is the id of the queue which handles TM related to this execution step
660 * @param queue_id is the id of the queue which handles TM related to this execution step
660 *
661 *
661 */
662 */
662
663
663 int result;
664 int result;
664
665
665 result = LFR_SUCCESSFUL;
666 result = LFR_SUCCESSFUL;
666
667
667 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
668 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
668 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
669 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
669
670
670 return result;
671 return result;
671 }
672 }
672
673
673 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
674 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
674 {
675 {
675 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
676 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
676 *
677 *
677 * @param TC points to the TeleCommand packet that is being processed
678 * @param TC points to the TeleCommand packet that is being processed
678 * @param queue_id is the id of the queue which handles TM related to this execution step
679 * @param queue_id is the id of the queue which handles TM related to this execution step
679 *
680 *
680 */
681 */
681
682
682 int result;
683 int result;
683
684
684 result = LFR_SUCCESSFUL;
685 result = LFR_SUCCESSFUL;
685
686
686 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
687 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
687 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
688 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
688
689
689 return result;
690 return result;
690 }
691 }
691
692
692 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
693 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
693 {
694 {
694 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
695 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
695 *
696 *
696 * @param TC points to the TeleCommand packet that is being processed
697 * @param TC points to the TeleCommand packet that is being processed
697 * @param queue_id is the id of the queue which handles TM related to this execution step
698 * @param queue_id is the id of the queue which handles TM related to this execution step
698 *
699 *
699 */
700 */
700
701
701 int status;
702 int status;
702
703
703 status = LFR_SUCCESSFUL;
704 status = LFR_SUCCESSFUL;
704
705
705 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
706 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
706
707
707 return status;
708 return status;
708 }
709 }
709
710
710 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
711 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
711 {
712 {
712 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
713 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
713 *
714 *
714 * @param TC points to the TeleCommand packet that is being processed
715 * @param TC points to the TeleCommand packet that is being processed
715 * @param queue_id is the id of the queue which handles TM related to this execution step
716 * @param queue_id is the id of the queue which handles TM related to this execution step
716 *
717 *
717 */
718 */
718
719
719 int status;
720 int status;
720
721
721 status = LFR_SUCCESSFUL;
722 status = LFR_SUCCESSFUL;
722
723
723 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
724 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
724
725
725 return status;
726 return status;
726 }
727 }
727
728
728 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
729 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
729 {
730 {
730 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
731 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
731 *
732 *
732 * @param TC points to the TeleCommand packet that is being processed
733 * @param TC points to the TeleCommand packet that is being processed
733 * @param queue_id is the id of the queue which handles TM related to this execution step
734 * @param queue_id is the id of the queue which handles TM related to this execution step
734 *
735 *
735 */
736 */
736
737
737 int status;
738 int status;
738
739
739 status = LFR_SUCCESSFUL;
740 status = LFR_SUCCESSFUL;
740
741
741 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
742 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
742
743
743 return status;
744 return status;
744 }
745 }
745
746
746 //**********************
747 //**********************
747 // BURST MODE PARAMETERS
748 // BURST MODE PARAMETERS
748 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
749 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
749 {
750 {
750 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
751 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
751 *
752 *
752 * @param TC points to the TeleCommand packet that is being processed
753 * @param TC points to the TeleCommand packet that is being processed
753 * @param queue_id is the id of the queue which handles TM related to this execution step
754 * @param queue_id is the id of the queue which handles TM related to this execution step
754 *
755 *
755 */
756 */
756
757
757 int status;
758 int status;
758
759
759 status = LFR_SUCCESSFUL;
760 status = LFR_SUCCESSFUL;
760
761
761 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
762 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
762
763
763 return status;
764 return status;
764 }
765 }
765
766
766 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
767 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
767 {
768 {
768 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
769 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
769 *
770 *
770 * @param TC points to the TeleCommand packet that is being processed
771 * @param TC points to the TeleCommand packet that is being processed
771 * @param queue_id is the id of the queue which handles TM related to this execution step
772 * @param queue_id is the id of the queue which handles TM related to this execution step
772 *
773 *
773 */
774 */
774
775
775 int status;
776 int status;
776
777
777 status = LFR_SUCCESSFUL;
778 status = LFR_SUCCESSFUL;
778
779
779 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
780 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
780
781
781 return status;
782 return status;
782 }
783 }
783
784
784 //*********************
785 //*********************
785 // SBM1 MODE PARAMETERS
786 // SBM1 MODE PARAMETERS
786 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
787 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
787 {
788 {
788 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
789 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
789 *
790 *
790 * @param TC points to the TeleCommand packet that is being processed
791 * @param TC points to the TeleCommand packet that is being processed
791 * @param queue_id is the id of the queue which handles TM related to this execution step
792 * @param queue_id is the id of the queue which handles TM related to this execution step
792 *
793 *
793 */
794 */
794
795
795 int status;
796 int status;
796
797
797 status = LFR_SUCCESSFUL;
798 status = LFR_SUCCESSFUL;
798
799
799 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
800 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
800
801
801 return status;
802 return status;
802 }
803 }
803
804
804 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
805 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
805 {
806 {
806 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
807 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
807 *
808 *
808 * @param TC points to the TeleCommand packet that is being processed
809 * @param TC points to the TeleCommand packet that is being processed
809 * @param queue_id is the id of the queue which handles TM related to this execution step
810 * @param queue_id is the id of the queue which handles TM related to this execution step
810 *
811 *
811 */
812 */
812
813
813 int status;
814 int status;
814
815
815 status = LFR_SUCCESSFUL;
816 status = LFR_SUCCESSFUL;
816
817
817 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
818 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
818
819
819 return status;
820 return status;
820 }
821 }
821
822
822 //*********************
823 //*********************
823 // SBM2 MODE PARAMETERS
824 // SBM2 MODE PARAMETERS
824 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
825 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
825 {
826 {
826 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
827 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
827 *
828 *
828 * @param TC points to the TeleCommand packet that is being processed
829 * @param TC points to the TeleCommand packet that is being processed
829 * @param queue_id is the id of the queue which handles TM related to this execution step
830 * @param queue_id is the id of the queue which handles TM related to this execution step
830 *
831 *
831 */
832 */
832
833
833 int status;
834 int status;
834
835
835 status = LFR_SUCCESSFUL;
836 status = LFR_SUCCESSFUL;
836
837
837 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
838 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
838
839
839 return status;
840 return status;
840 }
841 }
841
842
842 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
843 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
843 {
844 {
844 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
845 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
845 *
846 *
846 * @param TC points to the TeleCommand packet that is being processed
847 * @param TC points to the TeleCommand packet that is being processed
847 * @param queue_id is the id of the queue which handles TM related to this execution step
848 * @param queue_id is the id of the queue which handles TM related to this execution step
848 *
849 *
849 */
850 */
850
851
851 int status;
852 int status;
852
853
853 status = LFR_SUCCESSFUL;
854 status = LFR_SUCCESSFUL;
854
855
855 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
856 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
856
857
857 return status;
858 return status;
858 }
859 }
859
860
860 //*******************
861 //*******************
861 // TC_LFR_UPDATE_INFO
862 // TC_LFR_UPDATE_INFO
862 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
863 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
863 {
864 {
864 unsigned int status;
865 unsigned int status;
865
866
866 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
867 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
867 || (mode == LFR_MODE_BURST)
868 || (mode == LFR_MODE_BURST)
868 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
869 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
869 {
870 {
870 status = LFR_SUCCESSFUL;
871 status = LFR_SUCCESSFUL;
871 }
872 }
872 else
873 else
873 {
874 {
874 status = LFR_DEFAULT;
875 status = LFR_DEFAULT;
875 }
876 }
876
877
877 return status;
878 return status;
878 }
879 }
879
880
880 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
881 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
881 {
882 {
882 unsigned int status;
883 unsigned int status;
883
884
884 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
885 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
885 || (mode == TDS_MODE_BURST)
886 || (mode == TDS_MODE_BURST)
886 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
887 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
887 || (mode == TDS_MODE_LFM))
888 || (mode == TDS_MODE_LFM))
888 {
889 {
889 status = LFR_SUCCESSFUL;
890 status = LFR_SUCCESSFUL;
890 }
891 }
891 else
892 else
892 {
893 {
893 status = LFR_DEFAULT;
894 status = LFR_DEFAULT;
894 }
895 }
895
896
896 return status;
897 return status;
897 }
898 }
898
899
899 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
900 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
900 {
901 {
901 unsigned int status;
902 unsigned int status;
902
903
903 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
904 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
904 || (mode == THR_MODE_BURST))
905 || (mode == THR_MODE_BURST))
905 {
906 {
906 status = LFR_SUCCESSFUL;
907 status = LFR_SUCCESSFUL;
907 }
908 }
908 else
909 else
909 {
910 {
910 status = LFR_DEFAULT;
911 status = LFR_DEFAULT;
911 }
912 }
912
913
913 return status;
914 return status;
914 }
915 }
915
916
916 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
917 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
917 {
918 {
918 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
919 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
919 *
920 *
920 * @param TC points to the TeleCommand packet that is being processed
921 * @param TC points to the TeleCommand packet that is being processed
921 *
922 *
922 */
923 */
923
924
924 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
925 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
925
926
926 bytePosPtr = (unsigned char *) &TC->packetID;
927 bytePosPtr = (unsigned char *) &TC->packetID;
927
928
928 // cp_rpw_sc_rw1_f1
929 // cp_rpw_sc_rw1_f1
929 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
930 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
930 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
931 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
931
932
932 // cp_rpw_sc_rw1_f2
933 // cp_rpw_sc_rw1_f2
933 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
934 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
934 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
935 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
935
936
936 // cp_rpw_sc_rw2_f1
937 // cp_rpw_sc_rw2_f1
937 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
938 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
938 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
939 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
939
940
940 // cp_rpw_sc_rw2_f2
941 // cp_rpw_sc_rw2_f2
941 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
942 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
942 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
943 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
943
944
944 // cp_rpw_sc_rw3_f1
945 // cp_rpw_sc_rw3_f1
945 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
946 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
946 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
947 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
947
948
948 // cp_rpw_sc_rw3_f2
949 // cp_rpw_sc_rw3_f2
949 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
950 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
950 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
951 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
951
952
952 // cp_rpw_sc_rw4_f1
953 // cp_rpw_sc_rw4_f1
953 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
954 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
954 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
955 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
955
956
956 // cp_rpw_sc_rw4_f2
957 // cp_rpw_sc_rw4_f2
957 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
958 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
958 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
959 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
959 }
960 }
960
961
961 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
962 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
962 {
963 {
963 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
964 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
964 *
965 *
965 * @param fbins_mask
966 * @param fbins_mask
966 * @param rw_f is the reaction wheel frequency to filter
967 * @param rw_f is the reaction wheel frequency to filter
967 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
968 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
968 * @param flag [true] filtering enabled [false] filtering disabled
969 * @param flag [true] filtering enabled [false] filtering disabled
969 *
970 *
970 * @return void
971 * @return void
971 *
972 *
972 */
973 */
973
974
974 float fmin;
975 float fmin;
975 float fMAX;
976 float fMAX;
976 int binBelow;
977 int binBelow;
977 int binAbove;
978 int binAbove;
978 unsigned int whichByte;
979 unsigned int whichByte;
979 unsigned char selectedByte;
980 unsigned char selectedByte;
980 int bin;
981 int bin;
981
982
982 whichByte = 0;
983 whichByte = 0;
983 bin = 0;
984 bin = 0;
984
985
985 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
986 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
986 fmin = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
987 fmin = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
987 fMAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
988 fMAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
988
989
989 // compute the index of the frequency bin immediately below fmin
990 // compute the index of the frequency bin immediately below fmin
990 binBelow = (int) ( floor( ((double) fmin) / ((double) deltaFreq)) );
991 binBelow = (int) ( floor( ((double) fmin) / ((double) deltaFreq)) );
991
992
992 // compute the index of the frequency bin immediately above fMAX
993 // compute the index of the frequency bin immediately above fMAX
993 binAbove = (int) ( floor( ((double) fMAX) / ((double) deltaFreq)) );
994 binAbove = (int) ( floor( ((double) fMAX) / ((double) deltaFreq)) );
994
995
995 for (bin = binBelow; bin <= binAbove; bin++)
996 for (bin = binBelow; bin <= binAbove; bin++)
996 {
997 {
997 if ( (bin >= 0) && (bin<=127) )
998 if ( (bin >= 0) && (bin<=127) )
998 {
999 {
999 if (flag == 1)
1000 if (flag == 1)
1000 {
1001 {
1001 whichByte = bin >> 3; // division by 8
1002 whichByte = bin >> 3; // division by 8
1002 selectedByte = (unsigned char) ( 1 << (bin - (whichByte * 8)) );
1003 selectedByte = (unsigned char) ( 1 << (bin - (whichByte * 8)) );
1003 fbins_mask[whichByte] = fbins_mask[whichByte] & (~selectedByte);
1004 fbins_mask[whichByte] = fbins_mask[whichByte] & (~selectedByte);
1004 }
1005 }
1005 }
1006 }
1006 }
1007 }
1007 }
1008 }
1008
1009
1009 void build_sy_lfr_rw_mask( unsigned int channel )
1010 void build_sy_lfr_rw_mask( unsigned int channel )
1010 {
1011 {
1011 unsigned char local_rw_fbins_mask[16];
1012 unsigned char local_rw_fbins_mask[16];
1012 unsigned char *maskPtr;
1013 unsigned char *maskPtr;
1013 double deltaF;
1014 double deltaF;
1014 unsigned k;
1015 unsigned k;
1015
1016
1016 k = 0;
1017 k = 0;
1017
1018
1018 maskPtr = NULL;
1019 maskPtr = NULL;
1019 deltaF = 1.;
1020 deltaF = 1.;
1020
1021
1021 switch (channel)
1022 switch (channel)
1022 {
1023 {
1023 case 0:
1024 case 0:
1024 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1025 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1025 deltaF = 96.;
1026 deltaF = 96.;
1026 break;
1027 break;
1027 case 1:
1028 case 1:
1028 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1029 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1029 deltaF = 16.;
1030 deltaF = 16.;
1030 break;
1031 break;
1031 case 2:
1032 case 2:
1032 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1033 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1033 deltaF = 1.;
1034 deltaF = 1.;
1034 break;
1035 break;
1035 default:
1036 default:
1036 break;
1037 break;
1037 }
1038 }
1038
1039
1039 for (k = 0; k < 16; k++)
1040 for (k = 0; k < 16; k++)
1040 {
1041 {
1041 local_rw_fbins_mask[k] = 0xff;
1042 local_rw_fbins_mask[k] = 0xff;
1042 }
1043 }
1043
1044
1044 // RW1 F1
1045 // RW1 F1
1045 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1046 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1046
1047
1047 // RW1 F2
1048 // RW1 F2
1048 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1049 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1049
1050
1050 // RW2 F1
1051 // RW2 F1
1051 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1052 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1052
1053
1053 // RW2 F2
1054 // RW2 F2
1054 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1055 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1055
1056
1056 // RW3 F1
1057 // RW3 F1
1057 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1058 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1058
1059
1059 // RW3 F2
1060 // RW3 F2
1060 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1061 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1061
1062
1062 // RW4 F1
1063 // RW4 F1
1063 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1064 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1064
1065
1065 // RW4 F2
1066 // RW4 F2
1066 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1067 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1067
1068
1068 // update the value of the fbins related to reaction wheels frequency filtering
1069 // update the value of the fbins related to reaction wheels frequency filtering
1069 if (maskPtr != NULL)
1070 if (maskPtr != NULL)
1070 {
1071 {
1071 for (k = 0; k < 16; k++)
1072 for (k = 0; k < 16; k++)
1072 {
1073 {
1073 maskPtr[k] = local_rw_fbins_mask[k];
1074 maskPtr[k] = local_rw_fbins_mask[k];
1074 }
1075 }
1075 }
1076 }
1076 }
1077 }
1077
1078
1078 void build_sy_lfr_rw_masks( void )
1079 void build_sy_lfr_rw_masks( void )
1079 {
1080 {
1080 build_sy_lfr_rw_mask( 0 );
1081 build_sy_lfr_rw_mask( 0 );
1081 build_sy_lfr_rw_mask( 1 );
1082 build_sy_lfr_rw_mask( 1 );
1082 build_sy_lfr_rw_mask( 2 );
1083 build_sy_lfr_rw_mask( 2 );
1083
1084
1084 merge_fbins_masks();
1085 merge_fbins_masks();
1085 }
1086 }
1086
1087
1087 void merge_fbins_masks( void )
1088 void merge_fbins_masks( void )
1088 {
1089 {
1089 unsigned char k;
1090 unsigned char k;
1090
1091
1091 unsigned char *fbins_f0;
1092 unsigned char *fbins_f0;
1092 unsigned char *fbins_f1;
1093 unsigned char *fbins_f1;
1093 unsigned char *fbins_f2;
1094 unsigned char *fbins_f2;
1094 unsigned char *rw_mask_f0;
1095 unsigned char *rw_mask_f0;
1095 unsigned char *rw_mask_f1;
1096 unsigned char *rw_mask_f1;
1096 unsigned char *rw_mask_f2;
1097 unsigned char *rw_mask_f2;
1097
1098
1098 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1099 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1099 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1100 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1100 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1101 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1101 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1102 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1102 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1103 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1103 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1104 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1104
1105
1105 for( k=0; k < 16; k++ )
1106 for( k=0; k < 16; k++ )
1106 {
1107 {
1107 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1108 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1108 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1109 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1109 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1110 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1110 }
1111 }
1111 }
1112 }
1112
1113
1113 //***********
1114 //***********
1114 // FBINS MASK
1115 // FBINS MASK
1115
1116
1116 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1117 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1117 {
1118 {
1118 int status;
1119 int status;
1119 unsigned int k;
1120 unsigned int k;
1120 unsigned char *fbins_mask_dump;
1121 unsigned char *fbins_mask_dump;
1121 unsigned char *fbins_mask_TC;
1122 unsigned char *fbins_mask_TC;
1122
1123
1123 status = LFR_SUCCESSFUL;
1124 status = LFR_SUCCESSFUL;
1124
1125
1125 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1126 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1126 fbins_mask_TC = TC->dataAndCRC;
1127 fbins_mask_TC = TC->dataAndCRC;
1127
1128
1128 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1129 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1129 {
1130 {
1130 fbins_mask_dump[k] = fbins_mask_TC[k];
1131 fbins_mask_dump[k] = fbins_mask_TC[k];
1131 }
1132 }
1132
1133
1133 return status;
1134 return status;
1134 }
1135 }
1135
1136
1136 //***************************
1137 //***************************
1137 // TC_LFR_LOAD_PAS_FILTER_PAR
1138 // TC_LFR_LOAD_PAS_FILTER_PAR
1138
1139
1139 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1140 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1140 {
1141 {
1141 int flag;
1142 int flag;
1142 rtems_status_code status;
1143 rtems_status_code status;
1143
1144
1144 unsigned char sy_lfr_pas_filter_enabled;
1145 unsigned char sy_lfr_pas_filter_enabled;
1145 unsigned char sy_lfr_pas_filter_modulus;
1146 unsigned char sy_lfr_pas_filter_modulus;
1146 float sy_lfr_pas_filter_tbad;
1147 float sy_lfr_pas_filter_tbad;
1147 unsigned char sy_lfr_pas_filter_offset;
1148 unsigned char sy_lfr_pas_filter_offset;
1148 float sy_lfr_pas_filter_shift;
1149 float sy_lfr_pas_filter_shift;
1149 float sy_lfr_sc_rw_delta_f;
1150 float sy_lfr_sc_rw_delta_f;
1150 char *parPtr;
1151 char *parPtr;
1151
1152
1152 flag = LFR_SUCCESSFUL;
1153 flag = LFR_SUCCESSFUL;
1153 sy_lfr_pas_filter_tbad = 0.0;
1154 sy_lfr_pas_filter_tbad = 0.0;
1154 sy_lfr_pas_filter_shift = 0.0;
1155 sy_lfr_pas_filter_shift = 0.0;
1155 sy_lfr_sc_rw_delta_f = 0.0;
1156 sy_lfr_sc_rw_delta_f = 0.0;
1156 parPtr = NULL;
1157 parPtr = NULL;
1157
1158
1158 //***************
1159 //***************
1159 // get parameters
1160 // get parameters
1160 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1161 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1161 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1162 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1162 copyFloatByChar(
1163 copyFloatByChar(
1163 (unsigned char*) &sy_lfr_pas_filter_tbad,
1164 (unsigned char*) &sy_lfr_pas_filter_tbad,
1164 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1165 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1165 );
1166 );
1166 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1167 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1167 copyFloatByChar(
1168 copyFloatByChar(
1168 (unsigned char*) &sy_lfr_pas_filter_shift,
1169 (unsigned char*) &sy_lfr_pas_filter_shift,
1169 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1170 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1170 );
1171 );
1171 copyFloatByChar(
1172 copyFloatByChar(
1172 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1173 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1173 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1174 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1174 );
1175 );
1175
1176
1176 //******************
1177 //******************
1177 // CHECK CONSISTENCY
1178 // CHECK CONSISTENCY
1178
1179
1179 //**************************
1180 //**************************
1180 // sy_lfr_pas_filter_enabled
1181 // sy_lfr_pas_filter_enabled
1181 // nothing to check, value is 0 or 1
1182 // nothing to check, value is 0 or 1
1182
1183
1183 //**************************
1184 //**************************
1184 // sy_lfr_pas_filter_modulus
1185 // sy_lfr_pas_filter_modulus
1185 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1186 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1186 {
1187 {
1187 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1188 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1188 flag = WRONG_APP_DATA;
1189 flag = WRONG_APP_DATA;
1189 }
1190 }
1190
1191
1191 //***********************
1192 //***********************
1192 // sy_lfr_pas_filter_tbad
1193 // sy_lfr_pas_filter_tbad
1193 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1194 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1194 {
1195 {
1195 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1196 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1197 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1197 flag = WRONG_APP_DATA;
1198 flag = WRONG_APP_DATA;
1198 }
1199 }
1199
1200
1200 //*************************
1201 //*************************
1201 // sy_lfr_pas_filter_offset
1202 // sy_lfr_pas_filter_offset
1202 if (flag == LFR_SUCCESSFUL)
1203 if (flag == LFR_SUCCESSFUL)
1203 {
1204 {
1204 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1205 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1205 {
1206 {
1206 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1207 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1207 flag = WRONG_APP_DATA;
1208 flag = WRONG_APP_DATA;
1208 }
1209 }
1209 }
1210 }
1210
1211
1211 //************************
1212 //************************
1212 // sy_lfr_pas_filter_shift
1213 // sy_lfr_pas_filter_shift
1213 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1214 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1214 {
1215 {
1215 parPtr = (char*) &sy_lfr_pas_filter_shift;
1216 parPtr = (char*) &sy_lfr_pas_filter_shift;
1216 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1217 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1217 flag = WRONG_APP_DATA;
1218 flag = WRONG_APP_DATA;
1218 }
1219 }
1219
1220
1220 //*********************
1221 //*********************
1221 // sy_lfr_sc_rw_delta_f
1222 // sy_lfr_sc_rw_delta_f
1222 // nothing to check, no default value in the ICD
1223 // nothing to check, no default value in the ICD
1223
1224
1224 return flag;
1225 return flag;
1225 }
1226 }
1226
1227
1227 //**************
1228 //**************
1228 // KCOEFFICIENTS
1229 // KCOEFFICIENTS
1229 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1230 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1230 {
1231 {
1231 unsigned int kcoeff;
1232 unsigned int kcoeff;
1232 unsigned short sy_lfr_kcoeff_frequency;
1233 unsigned short sy_lfr_kcoeff_frequency;
1233 unsigned short bin;
1234 unsigned short bin;
1234 unsigned short *freqPtr;
1235 unsigned short *freqPtr;
1235 float *kcoeffPtr_norm;
1236 float *kcoeffPtr_norm;
1236 float *kcoeffPtr_sbm;
1237 float *kcoeffPtr_sbm;
1237 int status;
1238 int status;
1238 unsigned char *kcoeffLoadPtr;
1239 unsigned char *kcoeffLoadPtr;
1239 unsigned char *kcoeffNormPtr;
1240 unsigned char *kcoeffNormPtr;
1240 unsigned char *kcoeffSbmPtr_a;
1241 unsigned char *kcoeffSbmPtr_a;
1241 unsigned char *kcoeffSbmPtr_b;
1242 unsigned char *kcoeffSbmPtr_b;
1242
1243
1243 status = LFR_SUCCESSFUL;
1244 status = LFR_SUCCESSFUL;
1244
1245
1245 kcoeffPtr_norm = NULL;
1246 kcoeffPtr_norm = NULL;
1246 kcoeffPtr_sbm = NULL;
1247 kcoeffPtr_sbm = NULL;
1247 bin = 0;
1248 bin = 0;
1248
1249
1249 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1250 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1250 sy_lfr_kcoeff_frequency = *freqPtr;
1251 sy_lfr_kcoeff_frequency = *freqPtr;
1251
1252
1252 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1253 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1253 {
1254 {
1254 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1255 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1255 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1256 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1256 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1257 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1257 status = LFR_DEFAULT;
1258 status = LFR_DEFAULT;
1258 }
1259 }
1259 else
1260 else
1260 {
1261 {
1261 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1262 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1262 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1263 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1263 {
1264 {
1264 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1265 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1265 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1266 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1266 bin = sy_lfr_kcoeff_frequency;
1267 bin = sy_lfr_kcoeff_frequency;
1267 }
1268 }
1268 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1269 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1269 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1270 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1270 {
1271 {
1271 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1272 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1272 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1273 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1273 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1274 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1274 }
1275 }
1275 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1276 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1276 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1277 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1277 {
1278 {
1278 kcoeffPtr_norm = k_coeff_intercalib_f2;
1279 kcoeffPtr_norm = k_coeff_intercalib_f2;
1279 kcoeffPtr_sbm = NULL;
1280 kcoeffPtr_sbm = NULL;
1280 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1281 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1281 }
1282 }
1282 }
1283 }
1283
1284
1284 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1285 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1285 {
1286 {
1286 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1287 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1287 {
1288 {
1288 // destination
1289 // destination
1289 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1290 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1290 // source
1291 // source
1291 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1292 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1292 // copy source to destination
1293 // copy source to destination
1293 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1294 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1294 }
1295 }
1295 }
1296 }
1296
1297
1297 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1298 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1298 {
1299 {
1299 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1300 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1300 {
1301 {
1301 // destination
1302 // destination
1302 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1303 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1303 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1304 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1304 // source
1305 // source
1305 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1306 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1306 // copy source to destination
1307 // copy source to destination
1307 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1308 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1308 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1309 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1309 }
1310 }
1310 }
1311 }
1311
1312
1312 // print_k_coeff();
1313 // print_k_coeff();
1313
1314
1314 return status;
1315 return status;
1315 }
1316 }
1316
1317
1317 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1318 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1318 {
1319 {
1319 destination[0] = source[0];
1320 destination[0] = source[0];
1320 destination[1] = source[1];
1321 destination[1] = source[1];
1321 destination[2] = source[2];
1322 destination[2] = source[2];
1322 destination[3] = source[3];
1323 destination[3] = source[3];
1323 }
1324 }
1324
1325
1325 void floatToChar( float value, unsigned char* ptr)
1326 void floatToChar( float value, unsigned char* ptr)
1326 {
1327 {
1327 unsigned char* valuePtr;
1328 unsigned char* valuePtr;
1328
1329
1329 valuePtr = (unsigned char*) &value;
1330 valuePtr = (unsigned char*) &value;
1330 ptr[0] = valuePtr[0];
1331 ptr[0] = valuePtr[0];
1331 ptr[1] = valuePtr[0];
1332 ptr[1] = valuePtr[0];
1332 ptr[2] = valuePtr[0];
1333 ptr[2] = valuePtr[0];
1333 ptr[3] = valuePtr[0];
1334 ptr[3] = valuePtr[0];
1334 }
1335 }
1335
1336
1336 //**********
1337 //**********
1337 // init dump
1338 // init dump
1338
1339
1339 void init_parameter_dump( void )
1340 void init_parameter_dump( void )
1340 {
1341 {
1341 /** This function initialize the parameter_dump_packet global variable with default values.
1342 /** This function initialize the parameter_dump_packet global variable with default values.
1342 *
1343 *
1343 */
1344 */
1344
1345
1345 unsigned int k;
1346 unsigned int k;
1346
1347
1347 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1348 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1348 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1349 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1349 parameter_dump_packet.reserved = CCSDS_RESERVED;
1350 parameter_dump_packet.reserved = CCSDS_RESERVED;
1350 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1351 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1351 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1352 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1352 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1353 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1353 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1354 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1354 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1355 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1355 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1356 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1356 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1357 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1357 // DATA FIELD HEADER
1358 // DATA FIELD HEADER
1358 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1359 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1359 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1360 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1360 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1361 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1361 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1362 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1362 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1363 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1363 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1364 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1364 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1365 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1365 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1366 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1366 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1367 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1367 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1368 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1368 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1369 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1369
1370
1370 //******************
1371 //******************
1371 // COMMON PARAMETERS
1372 // COMMON PARAMETERS
1372 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1373 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1373 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1374 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1374
1375
1375 //******************
1376 //******************
1376 // NORMAL PARAMETERS
1377 // NORMAL PARAMETERS
1377 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1378 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1378 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1379 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1379 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1380 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1380 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1381 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1381 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1382 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1382 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1383 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1383 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1384 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1384 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1385 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1385 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1386 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1386
1387
1387 //*****************
1388 //*****************
1388 // BURST PARAMETERS
1389 // BURST PARAMETERS
1389 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1390 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1390 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1391 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1391
1392
1392 //****************
1393 //****************
1393 // SBM1 PARAMETERS
1394 // SBM1 PARAMETERS
1394 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
1395 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
1395 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1396 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1396
1397
1397 //****************
1398 //****************
1398 // SBM2 PARAMETERS
1399 // SBM2 PARAMETERS
1399 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1400 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1400 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1401 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1401
1402
1402 //************
1403 //************
1403 // FBINS MASKS
1404 // FBINS MASKS
1404 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1405 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1405 {
1406 {
1406 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1407 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1407 }
1408 }
1408
1409
1409 // PAS FILTER PARAMETERS
1410 // PAS FILTER PARAMETERS
1410 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1411 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1411 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1412 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1412 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1413 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1413 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1414 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1414 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1415 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1415 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1416 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1416 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1417 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1417
1418
1418 // LFR_RW_MASK
1419 // LFR_RW_MASK
1419 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1420 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1420 {
1421 {
1421 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff;
1422 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff;
1422 }
1423 }
1423 }
1424 }
1424
1425
1425 void init_kcoefficients_dump( void )
1426 void init_kcoefficients_dump( void )
1426 {
1427 {
1427 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1428 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1428 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1429 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1429
1430
1430 kcoefficient_node_1.previous = NULL;
1431 kcoefficient_node_1.previous = NULL;
1431 kcoefficient_node_1.next = NULL;
1432 kcoefficient_node_1.next = NULL;
1432 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1433 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1433 kcoefficient_node_1.coarseTime = 0x00;
1434 kcoefficient_node_1.coarseTime = 0x00;
1434 kcoefficient_node_1.fineTime = 0x00;
1435 kcoefficient_node_1.fineTime = 0x00;
1435 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1436 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1436 kcoefficient_node_1.status = 0x00;
1437 kcoefficient_node_1.status = 0x00;
1437
1438
1438 kcoefficient_node_2.previous = NULL;
1439 kcoefficient_node_2.previous = NULL;
1439 kcoefficient_node_2.next = NULL;
1440 kcoefficient_node_2.next = NULL;
1440 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1441 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1441 kcoefficient_node_2.coarseTime = 0x00;
1442 kcoefficient_node_2.coarseTime = 0x00;
1442 kcoefficient_node_2.fineTime = 0x00;
1443 kcoefficient_node_2.fineTime = 0x00;
1443 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1444 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1444 kcoefficient_node_2.status = 0x00;
1445 kcoefficient_node_2.status = 0x00;
1445 }
1446 }
1446
1447
1447 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1448 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1448 {
1449 {
1449 unsigned int k;
1450 unsigned int k;
1450 unsigned int packetLength;
1451 unsigned int packetLength;
1451
1452
1452 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1453 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1453
1454
1454 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1455 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1455 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1456 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1456 kcoefficients_dump->reserved = CCSDS_RESERVED;
1457 kcoefficients_dump->reserved = CCSDS_RESERVED;
1457 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1458 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1458 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1459 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1459 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1460 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1460 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1461 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1461 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1462 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1462 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1463 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1463 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1464 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1464 // DATA FIELD HEADER
1465 // DATA FIELD HEADER
1465 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1466 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1466 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1467 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1467 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1468 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1468 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1469 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1469 kcoefficients_dump->time[0] = 0x00;
1470 kcoefficients_dump->time[0] = 0x00;
1470 kcoefficients_dump->time[1] = 0x00;
1471 kcoefficients_dump->time[1] = 0x00;
1471 kcoefficients_dump->time[2] = 0x00;
1472 kcoefficients_dump->time[2] = 0x00;
1472 kcoefficients_dump->time[3] = 0x00;
1473 kcoefficients_dump->time[3] = 0x00;
1473 kcoefficients_dump->time[4] = 0x00;
1474 kcoefficients_dump->time[4] = 0x00;
1474 kcoefficients_dump->time[5] = 0x00;
1475 kcoefficients_dump->time[5] = 0x00;
1475 kcoefficients_dump->sid = SID_K_DUMP;
1476 kcoefficients_dump->sid = SID_K_DUMP;
1476
1477
1477 kcoefficients_dump->pkt_cnt = 2;
1478 kcoefficients_dump->pkt_cnt = 2;
1478 kcoefficients_dump->pkt_nr = pkt_nr;
1479 kcoefficients_dump->pkt_nr = pkt_nr;
1479 kcoefficients_dump->blk_nr = blk_nr;
1480 kcoefficients_dump->blk_nr = blk_nr;
1480
1481
1481 //******************
1482 //******************
1482 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1483 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1483 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1484 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1484 for (k=0; k<3900; k++)
1485 for (k=0; k<3900; k++)
1485 {
1486 {
1486 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1487 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1487 }
1488 }
1488 }
1489 }
1489
1490
1490 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1491 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1491 {
1492 {
1492 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1493 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1493 *
1494 *
1494 * @param packet_sequence_control points to the packet sequence control which will be incremented
1495 * @param packet_sequence_control points to the packet sequence control which will be incremented
1495 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1496 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1496 *
1497 *
1497 * If the destination ID is not known, a dedicated counter is incremented.
1498 * If the destination ID is not known, a dedicated counter is incremented.
1498 *
1499 *
1499 */
1500 */
1500
1501
1501 unsigned short sequence_cnt;
1502 unsigned short sequence_cnt;
1502 unsigned short segmentation_grouping_flag;
1503 unsigned short segmentation_grouping_flag;
1503 unsigned short new_packet_sequence_control;
1504 unsigned short new_packet_sequence_control;
1504 unsigned char i;
1505 unsigned char i;
1505
1506
1506 switch (destination_id)
1507 switch (destination_id)
1507 {
1508 {
1508 case SID_TC_GROUND:
1509 case SID_TC_GROUND:
1509 i = GROUND;
1510 i = GROUND;
1510 break;
1511 break;
1511 case SID_TC_MISSION_TIMELINE:
1512 case SID_TC_MISSION_TIMELINE:
1512 i = MISSION_TIMELINE;
1513 i = MISSION_TIMELINE;
1513 break;
1514 break;
1514 case SID_TC_TC_SEQUENCES:
1515 case SID_TC_TC_SEQUENCES:
1515 i = TC_SEQUENCES;
1516 i = TC_SEQUENCES;
1516 break;
1517 break;
1517 case SID_TC_RECOVERY_ACTION_CMD:
1518 case SID_TC_RECOVERY_ACTION_CMD:
1518 i = RECOVERY_ACTION_CMD;
1519 i = RECOVERY_ACTION_CMD;
1519 break;
1520 break;
1520 case SID_TC_BACKUP_MISSION_TIMELINE:
1521 case SID_TC_BACKUP_MISSION_TIMELINE:
1521 i = BACKUP_MISSION_TIMELINE;
1522 i = BACKUP_MISSION_TIMELINE;
1522 break;
1523 break;
1523 case SID_TC_DIRECT_CMD:
1524 case SID_TC_DIRECT_CMD:
1524 i = DIRECT_CMD;
1525 i = DIRECT_CMD;
1525 break;
1526 break;
1526 case SID_TC_SPARE_GRD_SRC1:
1527 case SID_TC_SPARE_GRD_SRC1:
1527 i = SPARE_GRD_SRC1;
1528 i = SPARE_GRD_SRC1;
1528 break;
1529 break;
1529 case SID_TC_SPARE_GRD_SRC2:
1530 case SID_TC_SPARE_GRD_SRC2:
1530 i = SPARE_GRD_SRC2;
1531 i = SPARE_GRD_SRC2;
1531 break;
1532 break;
1532 case SID_TC_OBCP:
1533 case SID_TC_OBCP:
1533 i = OBCP;
1534 i = OBCP;
1534 break;
1535 break;
1535 case SID_TC_SYSTEM_CONTROL:
1536 case SID_TC_SYSTEM_CONTROL:
1536 i = SYSTEM_CONTROL;
1537 i = SYSTEM_CONTROL;
1537 break;
1538 break;
1538 case SID_TC_AOCS:
1539 case SID_TC_AOCS:
1539 i = AOCS;
1540 i = AOCS;
1540 break;
1541 break;
1541 case SID_TC_RPW_INTERNAL:
1542 case SID_TC_RPW_INTERNAL:
1542 i = RPW_INTERNAL;
1543 i = RPW_INTERNAL;
1543 break;
1544 break;
1544 default:
1545 default:
1545 i = GROUND;
1546 i = GROUND;
1546 break;
1547 break;
1547 }
1548 }
1548
1549
1549 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1550 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1550 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1551 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1551
1552
1552 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1553 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1553
1554
1554 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1555 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1555 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1556 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1556
1557
1557 // increment the sequence counter
1558 // increment the sequence counter
1558 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1559 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1559 {
1560 {
1560 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1561 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1561 }
1562 }
1562 else
1563 else
1563 {
1564 {
1564 sequenceCounters_TM_DUMP[ i ] = 0;
1565 sequenceCounters_TM_DUMP[ i ] = 0;
1565 }
1566 }
1566 }
1567 }
General Comments 0
You need to be logged in to leave comments. Login now