##// END OF EJS Templates
Merge
paul -
r308:0724e26d58fe merge R3_plus draft
parent child
Show More
@@ -0,0 +1,8
1 [default]
2 name=Défaut
3 device=local
4 runtime=host
5 config-opts=
6 prefix=/home/jeandet/.cache/gnome-builder/install/DEV_PLE/host
7 app-id=
8 default=true
@@ -0,0 +1,14
1 cmake_minimum_required (VERSION 2.6)
2 project (LFR_FSW)
3
4 if(NOT CMAKE_BUILD_TYPE)
5 set(CMAKE_BUILD_TYPE "Release" CACHE STRING
6 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
7 endif(NOT CMAKE_BUILD_TYPE)
8
9 set(LFR_BP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/LFR_basic-parameters/basic_parameters.c)
10
11 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/sparc/")
12
13 add_subdirectory(src)
14 add_subdirectory(timegen)
@@ -0,0 +1,13
1 # LOAD FSW USING LINK 1
2 SpwPlugin0.StarDundeeSelectLinkNumber( 1 )
3
4 dsu3plugin0.openFile("/opt/LFR/LFR-FSW/3.0.0.10/fsw")
5 dsu3plugin0.loadFile()
6
7 dsu3plugin0.run()
8
9 # START SENDING TIMECODES AT 1 Hz
10 SpwPlugin0.StarDundeeStartTimecodes( 1 )
11
12 # it is possible to change the time code frequency
13 #RMAPPlugin0.changeTimecodeFrequency(2)
@@ -0,0 +1,8
1 set(CMAKE_SYSTEM_NAME rtems)
2
3 set(CMAKE_C_COMPILER /opt/rtems-4.10/bin/sparc-rtems-gcc)
4 set(CMAKE_CXX_COMPILER /opt/rtems-4.10/bin/sparc-rtems-g++)
5 set(CMAKE_LINKER /opt/rtems-4.10/bin/sparc-rtems-g++)
6 SET(CMAKE_EXE_LINKER_FLAGS "-static")
7 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
8 include_directories("/opt/rtems-4.10/sparc-rtems/leon3/lib/include")
@@ -0,0 +1,105
1 cmake_minimum_required (VERSION 2.6)
2 project (FSW)
3
4 include(sparc-rtems)
5
6 include_directories("../header"
7 "../header/lfr_common_headers"
8 "../header/processing"
9 "../LFR_basic-parameters"
10 "../src")
11
12 set(SOURCES wf_handler.c
13 tc_handler.c
14 fsw_misc.c
15 fsw_init.c
16 fsw_globals.c
17 fsw_spacewire.c
18 tc_load_dump_parameters.c
19 tm_lfr_tc_exe.c
20 tc_acceptance.c
21 processing/fsw_processing.c
22 processing/avf0_prc0.c
23 processing/avf1_prc1.c
24 processing/avf2_prc2.c
25 lfr_cpu_usage_report.c
26 ${LFR_BP_SRC}
27 ../header/wf_handler.h
28 ../header/tc_handler.h
29 ../header/grlib_regs.h
30 ../header/fsw_misc.h
31 ../header/fsw_init.h
32 ../header/fsw_spacewire.h
33 ../header/tc_load_dump_parameters.h
34 ../header/tm_lfr_tc_exe.h
35 ../header/tc_acceptance.h
36 ../header/processing/fsw_processing.h
37 ../header/processing/avf0_prc0.h
38 ../header/processing/avf1_prc1.h
39 ../header/processing/avf2_prc2.h
40 ../header/fsw_params_wf_handler.h
41 ../header/lfr_cpu_usage_report.h
42 ../header/lfr_common_headers/ccsds_types.h
43 ../header/lfr_common_headers/fsw_params.h
44 ../header/lfr_common_headers/fsw_params_nb_bytes.h
45 ../header/lfr_common_headers/fsw_params_processing.h
46 ../header/lfr_common_headers/tm_byte_positions.h
47 ../LFR_basic-parameters/basic_parameters.h
48 ../LFR_basic-parameters/basic_parameters_params.h
49 ../header/GscMemoryLPP.hpp
50 )
51
52
53 option(FSW_verbose "Enable verbose LFR" ON)
54 option(FSW_boot_messages "Enable LFR boot messages" ON)
55 option(FSW_debug_messages "Enable LFR debug messages" ON)
56 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
57 option(FSW_stack_report "Enable LFR stack report" OFF)
58 option(FSW_vhdl_dev "?" OFF)
59 option(FSW_lpp_dpu_destid "Set to debug at LPP" ON)
60 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
61 option(FSW_debug_tch "?" OFF)
62
63 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
64 set(SW_VERSION_N2 "1" CACHE STRING "Choose N2 FSW Version." FORCE)
65 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
66 set(SW_VERSION_N4 "4" CACHE STRING "Choose N4 FSW Version." FORCE)
67
68
69 if(FSW_verbose)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 endif()
72 if(FSW_boot_messages)
73 add_definitions(-DBOOT_MESSAGES)
74 endif()
75 if(FSW_debug_messages)
76 add_definitions(-DDEBUG_MESSAGES)
77 endif()
78 if(FSW_cpu_usage_report)
79 add_definitions(-DPRINT_TASK_STATISTICS)
80 endif()
81 if(FSW_stack_report)
82 add_definitions(-DPRINT_STACK_REPORT)
83 endif()
84 if(FSW_vhdl_dev)
85 add_definitions(-DVHDL_DEV)
86 endif()
87 if(FSW_lpp_dpu_destid)
88 add_definitions(-DLPP_DPU_DESTID)
89 endif()
90 if(FSW_debug_watchdog)
91 add_definitions(-DDEBUG_WATCHDOG)
92 endif()
93 if(FSW_debug_tch)
94 add_definitions(-DDEBUG_TCH)
95 endif()
96
97 add_definitions(-DMSB_FIRST_TCH)
98
99 add_definitions(-DSWVERSION=-1-0)
100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
104
105 add_executable(FSW ${SOURCES})
@@ -0,0 +1,88
1 cmake_minimum_required (VERSION 2.6)
2 project (timegen)
3
4 include(sparc-rtems)
5
6 include_directories("./src"
7 "./header"
8 "./header/processing"
9 "./src/LFR_basic-parameters")
10
11 set(SOURCES src/tc_handler.c
12 src/fsw_misc.c
13 src/fsw_init.c
14 src/fsw_globals.c
15 src/fsw_spacewire.c
16 src/tc_acceptance.c
17 ../LFR_basic-parameters/basic_parameters.c
18 header/tc_handler.h
19 header/grlib_regs.h
20 header/fsw_params.h
21 header/fsw_misc.h
22 header/fsw_init.h
23 header/ccsds_types.h
24 header/fsw_spacewire.h
25 header/tc_acceptance.h
26 header/fsw_params_nb_bytes.h
27 header/fsw_params_processing.h
28 header/fsw_params_wf_handler.h
29 header/lfr_cpu_usage_report.h
30 ../LFR_basic-parameters/basic_parameters.h
31 ../LFR_basic-parameters/basic_parameters_params.h
32 header/TC_types.h
33 )
34
35
36 option(timegen_verbose "Enable verbose Timegen" ON)
37 option(timegen_boot_messages "Enable Timegen boot messages" ON)
38 option(timegen_debug_messages "Enable Timegen debug messages" ON)
39 option(timegen_cpu_usage_report "Enable Timegen cpu usage report" OFF)
40 option(timegen_stack_report "Enable Timegen stack report" OFF)
41 option(timegen_vhdl_dev "?" OFF)
42 option(timegen_lpp_dpu_destid "Set to debug at LPP" ON)
43 option(timegen_debug_watchdog "Enable debug watchdog" OFF)
44 option(timegen_debug_tch "?" OFF)
45
46 set(TIMEGEN_SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
47 set(TIMEGEN_SW_VERSION_N2 "1" CACHE STRING "Choose N2 FSW Version." FORCE)
48 set(TIMEGEN_SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
49 set(TIMEGEN_SW_VERSION_N4 "4" CACHE STRING "Choose N4 FSW Version." FORCE)
50
51
52 if (timegen_verbose)
53 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
54 endif()
55 if (timegen_boot_messages)
56 add_definitions(-DBOOT_MESSAGES)
57 endif()
58 if (timegen_debug_messages)
59 add_definitions(-DDEBUG_MESSAGES)
60 endif()
61 if (timegen_cpu_usage_report)
62 add_definitions(-DPRINT_TASK_STATISTICS)
63 endif()
64 if (timegen_stack_report)
65 add_definitions(-DPRINT_STACK_REPORT)
66 endif()
67 if (timegen_vhdl_dev)
68 add_definitions(-DVHDL_DEV)
69 endif()
70 if (timegen_lpp_dpu_destid)
71 add_definitions(-DLPP_DPU_DESTID)
72 endif()
73 if (timegen_debug_watchdog)
74 add_definitions(-DDEBUG_WATCHDOG)
75 endif()
76 if (timegen_debug_tch)
77 add_definitions(-DDEBUG_TCH)
78 endif()
79
80 add_definitions(-DMSB_FIRST_TCH)
81
82 add_definitions(-DSWVERSION=-1-0)
83 add_definitions(-DSW_VERSION_N1=${TIMEGEN_SW_VERSION_N1})
84 add_definitions(-DSW_VERSION_N2=${TIMEGEN_SW_VERSION_N2})
85 add_definitions(-DSW_VERSION_N3=${TIMEGEN_SW_VERSION_N3})
86 add_definitions(-DSW_VERSION_N4=${TIMEGEN_SW_VERSION_N4})
87
88 add_executable(timegen ${SOURCES})
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,219
1 #ifndef TC_TYPES_H
2 #define TC_TYPES_H
3
4 #include <ccsds_types.h>
5
6 #define PROTOCOLE_IDENTIFIER 0x02
7
8 // PACKET ID
9 #define TC_LFR_PACKET_ID 0x1ccc // PID 76 CAT 12
10
11 #define PACKET_LENGTH_TC_LFR_RESET (12 - CCSDS_TC_TM_PACKET_OFFSET)
12 #define PACKET_LENGTH_TC_LFR_LOAD_COMMON_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET)
13 #define PACKET_LENGTH_TC_LFR_LOAD_NORMAL_PAR (22 - CCSDS_TC_TM_PACKET_OFFSET)
14 #define PACKET_LENGTH_TC_LFR_LOAD_BURST_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET)
15 #define PACKET_LENGTH_TC_LFR_LOAD_SBM1_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET)
16 #define PACKET_LENGTH_TC_LFR_LOAD_SBM2_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET)
17 #define PACKET_LENGTH_TC_LFR_DUMP_PAR (12 - CCSDS_TC_TM_PACKET_OFFSET)
18 #define PACKET_LENGTH_TC_LFR_ENTER_MODE (20 - CCSDS_TC_TM_PACKET_OFFSET)
19 #define PACKET_LENGTH_TC_LFR_UPDATE_INFO (46 - CCSDS_TC_TM_PACKET_OFFSET)
20 #define PACKET_LENGTH_TC_LFR_ENABLE_CALIBRATION (12 - CCSDS_TC_TM_PACKET_OFFSET)
21 #define PACKET_LENGTH_TC_LFR_DISABLE_CALIBRATION (12 - CCSDS_TC_TM_PACKET_OFFSET)
22 #define PACKET_LENGTH_TC_LFR_UPDATE_TIME (18 - CCSDS_TC_TM_PACKET_OFFSET)
23
24 // TC TYPES
25 #define TC_TYPE_DEFAULT 181
26 #define TC_TYPE_LFR_UPDATE_TIME 9
27
28 // TC SUBTYPES
29 #define TC_SUBTYPE_RESET 1
30 #define TC_SUBTYPE_LOAD_COMMON_PAR 11
31 #define TC_SUBTYPE_LOAD_NORMAL_PAR 13
32 #define TC_SUBTYPE_LOAD_BURST_PAR 19
33 #define TC_SUBTYPE_LOAD_SBM1_PAR 25
34 #define TC_SUBTYPE_LOAD_SBM2_PAR 27
35 #define TC_SUBTYPE_DUMP_PAR 31
36 #define TC_SUBTYPE_ENTER_MODE 41
37 #define TC_SUBTYPE_UPDATE_INFO 51
38 #define TC_SUBTYPE_ENABLE_CALIBRATION 61
39 #define TC_SUBTYPE_DISABLE_CALIBRATION 63
40 #define TC_SUBTYPE_UPDATE_TIME 129
41
42 // OTHER CONSTANTS
43 #define TC_LFR_PACKET_SEQUENCE_CONTROL 0xc000 // PID 76 CAT 12
44 #define TC_LFR_DATA_FIELD_HEADER0 0x19
45 #define TC_LFR_LOAD_COMMON_PAR_SPARE 0x00
46
47 struct Packet_TC_LFR_RESET_str
48 { // the CCSDS header is added by LPPMON
49 unsigned char packetID[2];
50 unsigned char packetSequenceControl[2];
51 unsigned char packetLength[2];
52 // DATA FIELD HEADER
53 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
54 unsigned char serviceType;
55 unsigned char serviceSubType;
56 unsigned char sourceID;
57 unsigned char crc[2];
58 };
59 typedef struct Packet_TC_LFR_RESET_str Packet_TC_LFR_RESET_t;
60
61 struct Packet_TC_LFR_ENTER_MODE_str
62 { // the CCSDS header is added by LPPMON
63 unsigned char packetID[2];
64 unsigned char packetSequenceControl[2];
65 unsigned char packetLength[2];
66 // DATA FIELD HEADER
67 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
68 unsigned char serviceType;
69 unsigned char serviceSubType;
70 unsigned char sourceID;
71 unsigned char spare;
72 unsigned char mode;
73 unsigned char enterModeTime[6];
74 unsigned char crc[2];
75 };
76 typedef struct Packet_TC_LFR_ENTER_MODE_str Packet_TC_LFR_ENTER_MODE_t;
77
78 struct Packet_TC_LFR_UPDATE_INFO_str
79 { // the CCSDS header is added by LPPMON
80 unsigned char packetID[2];
81 unsigned char packetSequenceControl[2];
82 unsigned char packetLength[2];
83 // DATA FIELD HEADER
84 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
85 unsigned char serviceType;
86 unsigned char serviceSubType;
87 unsigned char sourceID;
88 unsigned char set1;
89 unsigned char set2;
90 unsigned char set3_bias_setting_set1[6];
91 unsigned char set3_bias_setting_set2[6];
92 unsigned char set3_bias_voltage[4];
93 unsigned char set4[8];
94 unsigned char set5;
95 unsigned char set6;
96 unsigned char set7[8];
97 unsigned char crc[2];
98 };
99 typedef struct Packet_TC_LFR_UPDATE_INFO_str Packet_TC_LFR_UPDATE_INFO_t;
100
101 struct Packet_TC_LFR_DUMP_PAR_str
102 { // the CCSDS header is added by LPPMON
103 unsigned char packetID[2];
104 unsigned char packetSequenceControl[2];
105 unsigned char packetLength[2];
106 // DATA FIELD HEADER
107 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
108 unsigned char serviceType;
109 unsigned char serviceSubType;
110 unsigned char sourceID;
111 unsigned char crc[2];
112
113 };
114 typedef struct Packet_TC_LFR_DUMP_PAR_str Packet_TC_LFR_DUMP_PAR_t;
115
116 struct Packet_TC_LFR_LOAD_COMMON_PAR_str
117 { // the CCSDS header is added by LPPMON
118 unsigned char packetID[2];
119 unsigned char packetSequenceControl[2];
120 unsigned char packetLength[2];
121 // DATA FIELD HEADER
122 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
123 unsigned char serviceType;
124 unsigned char serviceSubType;
125 unsigned char sourceID;
126 unsigned char spare;
127 unsigned char bw_sp0_sp1_r0_r1;
128 unsigned char crc[2];
129
130 };
131 typedef struct Packet_TC_LFR_LOAD_COMMON_PAR_str Packet_TC_LFR_LOAD_COMMON_PAR_t;
132
133 struct Packet_TC_LFR_LOAD_NORMAL_PAR_str
134 { // the CCSDS header is added by LPPMON
135 unsigned char packetID[2];
136 unsigned char packetSequenceControl[2];
137 unsigned char packetLength[2];
138 // DATA FIELD HEADER
139 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
140 unsigned char serviceType;
141 unsigned char serviceSubType;
142 unsigned char sourceID;
143 unsigned char sy_lfr_n_swf_l[2];
144 unsigned char sy_lfr_n_swf_p[2];
145 unsigned char sy_lfr_n_asm_p[2];
146 unsigned char sy_lfr_n_bp_p0;
147 unsigned char sy_lfr_n_bp_p1;
148 unsigned char sy_lfr_n_cwf_long_f3;
149 unsigned char lfr_normal_parameters_spare;
150 unsigned char crc[2];
151 };
152 typedef struct Packet_TC_LFR_LOAD_NORMAL_PAR_str Packet_TC_LFR_LOAD_NORMAL_PAR_t;
153
154 struct Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_str
155 { // the CCSDS header is added by LPPMON
156 unsigned char packetID[2];
157 unsigned char packetSequenceControl[2];
158 unsigned char packetLength[2];
159 // DATA FIELD HEADER
160 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
161 unsigned char serviceType;
162 unsigned char serviceSubType;
163 unsigned char sourceID;
164 unsigned char sy_lfr_bp_p0;
165 unsigned char sy_lfr_bp_p1;
166 unsigned char crc[2];
167 };
168 typedef struct Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_str Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_t;
169
170 struct Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_str
171 { // the CCSDS header is added by LPPMON
172 unsigned char packetID[2];
173 unsigned char packetSequenceControl[2];
174 unsigned char packetLength[2];
175 // DATA FIELD HEADER
176 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
177 unsigned char serviceType;
178 unsigned char serviceSubType;
179 unsigned char sourceID;
180 unsigned char crc[2];
181 };
182 typedef struct Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_str Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_t;
183
184 struct Packet_TC_LFR_UPDATE_TIME_str
185 { // the CCSDS header is added by LPPMON
186 unsigned char packetID[2];
187 unsigned char packetSequenceControl[2];
188 unsigned char packetLength[2];
189 // DATA FIELD HEADER
190 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
191 unsigned char serviceType;
192 unsigned char serviceSubType;
193 unsigned char sourceID;
194 unsigned char cp_rpw_time[6];
195 unsigned char crc[2];
196 };
197 typedef struct Packet_TC_LFR_UPDATE_TIME_str Packet_TC_LFR_UPDATE_TIME_t;
198
199 struct Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_str
200 {
201 unsigned char targetLogicalAddress;
202 unsigned char protocolIdentifier;
203 unsigned char reserved;
204 unsigned char userApplication;
205 //
206 unsigned char packetID[2];
207 unsigned char packetSequenceControl[2];
208 unsigned char packetLength[2];
209 // DATA FIELD HEADER
210 unsigned char ccsdsSecHeaderFlag_pusVersion_ack;
211 unsigned char serviceType;
212 unsigned char serviceSubType;
213 unsigned char sourceID;
214 unsigned char cp_rpw_time[6];
215 unsigned char crc[2];
216 };
217 typedef struct Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_str Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t;
218
219 #endif // TC_TYPES_H
This diff has been collapsed as it changes many lines, (665 lines changed) Show them Hide them
@@ -0,0 +1,665
1 #ifndef CCSDS_TYPES_H_INCLUDED
2 #define CCSDS_TYPES_H_INCLUDED
3
4 #include "fsw_params_processing.h"
5
6 #define CCSDS_PROTOCOLE_EXTRA_BYTES 4
7 #define CCSDS_TC_TM_PACKET_OFFSET 7
8 #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
9 #define CCSDS_TM_PKT_MAX_SIZE 4412
10 #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4
11 #define CCSDS_TC_PKT_MAX_SIZE 256
12 #define CCSDS_TC_PKT_MIN_SIZE 16
13 #define CCSDS_PROCESS_ID 76
14 #define CCSDS_PACKET_CATEGORY 12
15 #define CCSDS_NODE_ADDRESS 0xfe
16 #define CCSDS_USER_APP 0x00
17
18 #define DEFAULT_SPARE1_PUSVERSION_SPARE2 0x10
19 #define DEFAULT_RESERVED 0x00
20 #define DEFAULT_HKBIA 0x1e // 0001 1110
21
22 // PACKET ID
23 #define APID_TM_TC_EXE 0x0cc1 // PID 76 CAT 1
24 #define APID_TM_HK 0x0cc4 // PID 76 CAT 4
25 #define APID_TM_PARAMETER_DUMP 0x0cc9 // PID 76 CAT 9
26 #define APID_TM_SCIENCE_NORMAL_BURST 0x0ccc // PID 76 CAT 12
27 #define APID_TM_SCIENCE_SBM1_SBM2 0x0cfc // PID 79 CAT 12
28 #define TM_PACKET_PID_DEFAULT 76
29 #define TM_PACKET_PID_BURST_SBM1_SBM2 79
30 #define TM_PACKET_CAT_TC_EXE 1
31 #define TM_PACKET_CAT_HK 4
32 #define TM_PACKET_CAT_PARAMETER_DUMP 9
33 #define TM_PACKET_CAT_SCIENCE 12
34 #define TC_PACKET_CAT 12
35
36 // PACKET SEQUENCE CONTROL
37 #define TM_PACKET_SEQ_CTRL_CONTINUATION 0x00 // [0000 0000]
38 #define TM_PACKET_SEQ_CTRL_FIRST 0x40 // [0100 0000]
39 #define TM_PACKET_SEQ_CTRL_LAST 0x80 // [1000 0000]
40 #define TM_PACKET_SEQ_CTRL_STANDALONE 0xc0 // [1100 0000]
41 #define TM_PACKET_SEQ_CNT_DEFAULT 0x00 // [0000 0000]
42
43 // DESTINATION ID
44 #define TM_DESTINATION_ID_GROUND 0
45 #define TM_DESTINATION_ID_MISSION_TIMELINE 110
46 #define TM_DESTINATION_ID_TC_SEQUENCES 111
47 #define TM_DESTINATION_ID_RECOVERY_ACTION_COMMAND 112
48 #define TM_DESTINATION_ID_BACKUP_MISSION_TIMELINE 113
49 #define TM_DESTINATION_ID_DIRECT_CMD 120
50 #define TM_DESTINATION_ID_SPARE_GRD_SRC1 121
51 #define TM_DESTINATION_ID_SPARE_GRD_SRC2 122
52 #define TM_DESTINATION_ID_OBCP 15
53 #define TM_DESTINATION_ID_SYSTEM_CONTROL 14
54 #define TM_DESTINATION_ID_AOCS 11
55
56 #define CCSDS_DESTINATION_ID 0x01
57 #define CCSDS_PROTOCOLE_ID 0x02
58 #define CCSDS_RESERVED 0x00
59 #define CCSDS_USER_APP 0x00
60
61 #define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24
62 #define SIZE_TM_LFR_TC_EXE_CORRUPTED 32
63 #define SIZE_HK_PARAMETERS 112
64
65 // TC TYPES
66 #define TC_TYPE_GEN 181
67 #define TC_TYPE_TIME 9
68
69 // TC SUBTYPES
70 #define TC_SUBTYPE_RESET 1
71 #define TC_SUBTYPE_LOAD_COMM 11
72 #define TC_SUBTYPE_LOAD_NORM 13
73 #define TC_SUBTYPE_LOAD_BURST 19
74 #define TC_SUBTYPE_LOAD_SBM1 25
75 #define TC_SUBTYPE_LOAD_SBM2 27
76 #define TC_SUBTYPE_DUMP 31
77 #define TC_SUBTYPE_ENTER 41
78 #define TC_SUBTYPE_UPDT_INFO 51
79 #define TC_SUBTYPE_EN_CAL 61
80 #define TC_SUBTYPE_DIS_CAL 63
81 #define TC_SUBTYPE_UPDT_TIME 129
82
83 // TC LEN
84 #define TC_LEN_RESET 12
85 #define TC_LEN_LOAD_COMM 14
86 #define TC_LEN_LOAD_NORM 22
87 #define TC_LEN_LOAD_BURST 14
88 #define TC_LEN_LOAD_SBM1 14
89 #define TC_LEN_LOAD_SBM2 14
90 #define TC_LEN_DUMP 12
91 #define TC_LEN_ENTER 20
92 #define TC_LEN_UPDT_INFO 46
93 #define TC_LEN_EN_CAL 12
94 #define TC_LEN_DIS_CAL 12
95 #define TC_LEN_UPDT_TIME 18
96
97 // TM TYPES
98 #define TM_TYPE_TC_EXE 1
99 #define TM_TYPE_HK 3
100 #define TM_TYPE_PARAMETER_DUMP 3
101 #define TM_TYPE_LFR_SCIENCE 21
102
103 // TM SUBTYPES
104 #define TM_SUBTYPE_EXE_OK 7
105 #define TM_SUBTYPE_EXE_NOK 8
106 #define TM_SUBTYPE_HK 25
107 #define TM_SUBTYPE_PARAMETER_DUMP 25
108 #define TM_SUBTYPE_SCIENCE 3
109 #define TM_SUBTYPE_LFR_SCIENCE 3
110
111 // FAILURE CODES
112 #define ILLEGAL_APID 0
113 #define WRONG_LEN_PKT 1
114 #define INCOR_CHECKSUM 2
115 #define ILL_TYPE 3
116 #define ILL_SUBTYPE 4
117 #define WRONG_APP_DATA 5 // 0x00 0x05
118 #define TC_NOT_EXE 42000 // 0xa4 0x10
119 #define WRONG_SRC_ID 42001 // 0xa4 0x11
120 #define FUNCT_NOT_IMPL 42002 // 0xa4 0x12
121 #define FAIL_DETECTED 42003 // 0xa4 0x13
122 #define NOT_ALLOWED 42004 // 0xa4 0x14
123 #define CORRUPTED 42005 // 0xa4 0x15
124 #define CCSDS_TM_VALID 7
125
126 // TC SID
127 #define SID_TC_GROUND 0
128 #define SID_TC_MISSION_TIMELINE 110
129 #define SID_TC_TC_SEQUENCES 111
130 #define SID_TC_RECOVERY_ACTION_CMD 112
131 #define SID_TC_BACKUP_MISSION_TIMELINE 113
132 #define SID_TC_DIRECT_CMD 120
133 #define SID_TC_SPARE_GRD_SRC1 121
134 #define SID_TC_SPARE_GRD_SRC2 122
135 #define SID_TC_OBCP 15
136 #define SID_TC_SYSTEM_CONTROL 14
137 #define SID_TC_AOCS 11
138 #define SID_TC_RPW_INTERNAL 254
139
140 enum apid_destid{
141 GROUND,
142 MISSION_TIMELINE,
143 TC_SEQUENCES,
144 RECOVERY_ACTION_CMD,
145 BACKUP_MISSION_TIMELINE,
146 DIRECT_CMD,
147 SPARE_GRD_SRC1,
148 SPARE_GRD_SRC2,
149 OBCP,
150 SYSTEM_CONTROL,
151 AOCS,
152 RPW_INTERNAL
153 };
154 // SEQUENCE COUNTERS
155 #define SEQ_CNT_MAX 16383
156 #define SEQ_CNT_NB_DEST_ID 12
157
158 // TM SID
159 #define SID_HK 1
160 #define SID_PARAMETER_DUMP 10
161
162 #define SID_NORM_SWF_F0 3
163 #define SID_NORM_SWF_F1 4
164 #define SID_NORM_SWF_F2 5
165 #define SID_NORM_CWF_F3 1
166 #define SID_BURST_CWF_F2 2
167 #define SID_SBM1_CWF_F1 24
168 #define SID_SBM2_CWF_F2 25
169 #define SID_NORM_ASM_F0 11
170 #define SID_NORM_ASM_F1 12
171 #define SID_NORM_ASM_F2 13
172 #define SID_NORM_BP1_F0 14
173 #define SID_NORM_BP1_F1 15
174 #define SID_NORM_BP1_F2 16
175 #define SID_NORM_BP2_F0 19
176 #define SID_NORM_BP2_F1 20
177 #define SID_NORM_BP2_F2 21
178 #define SID_BURST_BP1_F0 17
179 #define SID_BURST_BP2_F0 22
180 #define SID_BURST_BP1_F1 18
181 #define SID_BURST_BP2_F1 23
182 #define SID_SBM1_BP1_F0 28
183 #define SID_SBM1_BP2_F0 31
184 #define SID_SBM2_BP1_F0 29
185 #define SID_SBM2_BP2_F0 32
186 #define SID_SBM2_BP1_F1 30
187 #define SID_SBM2_BP2_F1 33
188 #define SID_NORM_CWF_LONG_F3 34
189
190 // LENGTH (BYTES)
191 #define LENGTH_TM_LFR_TC_EXE_MAX 32
192 #define LENGTH_TM_LFR_HK 126
193
194 // HEADER_LENGTH
195 #define TM_HEADER_LEN 16
196 #define HEADER_LENGTH_TM_LFR_SCIENCE_ASM 28
197 // PACKET_LENGTH
198 #define PACKET_LENGTH_TC_EXE_SUCCESS (20 - CCSDS_TC_TM_PACKET_OFFSET)
199 #define PACKET_LENGTH_TC_EXE_INCONSISTENT (26 - CCSDS_TC_TM_PACKET_OFFSET)
200 #define PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE (26 - CCSDS_TC_TM_PACKET_OFFSET)
201 #define PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED (24 - CCSDS_TC_TM_PACKET_OFFSET)
202 #define PACKET_LENGTH_TC_EXE_ERROR (24 - CCSDS_TC_TM_PACKET_OFFSET)
203 #define PACKET_LENGTH_TC_EXE_CORRUPTED (32 - CCSDS_TC_TM_PACKET_OFFSET)
204 #define PACKET_LENGTH_HK (124 - CCSDS_TC_TM_PACKET_OFFSET)
205 #define PACKET_LENGTH_PARAMETER_DUMP (36 - CCSDS_TC_TM_PACKET_OFFSET)
206 #define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0 (2228 - CCSDS_TC_TM_PACKET_OFFSET) // 44 * 25 * 2 + 28
207 #define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1 (2628 - CCSDS_TC_TM_PACKET_OFFSET) // 52 * 25 * 2 + 28
208 #define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2 (2428 - CCSDS_TC_TM_PACKET_OFFSET) // 48 * 25 * 2 + 28
209 #define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 (126 - CCSDS_TC_TM_PACKET_OFFSET) // 11 * 9 + 27 (1 spare bit in the header)
210 #define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 (356 - CCSDS_TC_TM_PACKET_OFFSET) // 11 * 30 + 26
211 #define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 (144 - CCSDS_TC_TM_PACKET_OFFSET) // 13 * 9 + 27 (1 spare bit in the header)
212 #define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 (416 - CCSDS_TC_TM_PACKET_OFFSET) // 13 * 30 + 26
213 #define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 (134 - CCSDS_TC_TM_PACKET_OFFSET) // 12 * 9 + 26
214 #define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 (386 - CCSDS_TC_TM_PACKET_OFFSET) // 12 * 30 + 26
215 #define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 (224 - CCSDS_TC_TM_PACKET_OFFSET) // 22 * 9 + 26
216 #define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 (686 - CCSDS_TC_TM_PACKET_OFFSET) // 22 * 30 + 26
217 #define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 (260 - CCSDS_TC_TM_PACKET_OFFSET) // 26 * 9 + 26
218 #define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 (806 - CCSDS_TC_TM_PACKET_OFFSET) // 26 * 30 + 26
219
220 #define PACKET_LENGTH_DELTA 11 // 7 + 4
221
222 #define SPARE1_PUSVERSION_SPARE2 0x10
223
224 // R1
225 #define TM_LEN_SCI_SWF_340 4101 // 340 * 12 + 10 + 12 - 1
226 #define TM_LEN_SCI_SWF_8 117 // 8 * 12 + 10 + 12 - 1
227 #define TM_LEN_SCI_CWF_340 4099 // 340 * 12 + 10 + 10 - 1
228 #define TM_LEN_SCI_CWF_8 115 // 8 * 12 + 10 + 10 - 1
229 #define TM_LEN_SCI_CWF3_LIGHT_340 2059 // 340 * 6 + 10 + 10 - 1
230 #define TM_LEN_SCI_CWF3_LIGHT_8 67 // 8 * 6 + 10 + 10 - 1
231 // R2
232 #define TM_LEN_SCI_SWF_304 3669 // 304 * 12 + 10 + 12 - 1
233 #define TM_LEN_SCI_SWF_224 2709 // 224 * 12 + 10 + 12 - 1
234 #define TM_LEN_SCI_CWF_336 4051 // 336 * 12 + 10 + 10 - 1
235 #define TM_LEN_SCI_CWF_672 4051 // 672 * 6 + 10 + 10 - 1
236 //
237 #define DEFAULT_PKTCNT 0x07
238 #define BLK_NR_304 0x0130
239 #define BLK_NR_224 0x00e0
240 #define BLK_NR_CWF 0x0150 // 336
241 #define BLK_NR_CWF_SHORT_F3 0x02a0 // 672
242
243 enum TM_TYPE{
244 TM_LFR_TC_EXE_OK,
245 TM_LFR_TC_EXE_ERR,
246 TM_LFR_HK,
247 TM_LFR_SCI,
248 TM_LFR_SCI_SBM,
249 TM_LFR_PAR_DUMP
250 };
251
252 typedef struct {
253 unsigned char targetLogicalAddress;
254 unsigned char protocolIdentifier;
255 unsigned char reserved;
256 unsigned char userApplication;
257 // PACKET HEADER
258 unsigned char packetID[2];
259 unsigned char packetSequenceControl[2];
260 unsigned char packetLength[2];
261 // DATA FIELD HEADER
262 unsigned char spare1_pusVersion_spare2;
263 unsigned char serviceType;
264 unsigned char serviceSubType;
265 unsigned char destinationID;
266 unsigned char time[6];
267 //
268 unsigned char telecommand_pkt_id[2];
269 unsigned char pkt_seq_control[2];
270 } Packet_TM_LFR_TC_EXE_SUCCESS_t;
271
272 typedef struct {
273 unsigned char targetLogicalAddress;
274 unsigned char protocolIdentifier;
275 unsigned char reserved;
276 unsigned char userApplication;
277 // PACKET HEADER
278 unsigned char packetID[2];
279 unsigned char packetSequenceControl[2];
280 unsigned char packetLength[2];
281 // DATA FIELD HEADER
282 unsigned char spare1_pusVersion_spare2;
283 unsigned char serviceType;
284 unsigned char serviceSubType;
285 unsigned char destinationID;
286 unsigned char time[6];
287 //
288 unsigned char tc_failure_code[2];
289 unsigned char telecommand_pkt_id[2];
290 unsigned char pkt_seq_control[2];
291 unsigned char tc_service;
292 unsigned char tc_subtype;
293 unsigned char byte_position;
294 unsigned char rcv_value;
295 } Packet_TM_LFR_TC_EXE_INCONSISTENT_t;
296
297 typedef struct {
298 unsigned char targetLogicalAddress;
299 unsigned char protocolIdentifier;
300 unsigned char reserved;
301 unsigned char userApplication;
302 // PACKET HEADER
303 unsigned char packetID[2];
304 unsigned char packetSequenceControl[2];
305 unsigned char packetLength[2];
306 // DATA FIELD HEADER
307 unsigned char spare1_pusVersion_spare2;
308 unsigned char serviceType;
309 unsigned char serviceSubType;
310 unsigned char destinationID;
311 unsigned char time[6];
312 //
313 unsigned char tc_failure_code[2];
314 unsigned char telecommand_pkt_id[2];
315 unsigned char pkt_seq_control[2];
316 unsigned char tc_service;
317 unsigned char tc_subtype;
318 unsigned char lfr_status_word[2];
319 } Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t;
320
321 typedef struct {
322 unsigned char targetLogicalAddress;
323 unsigned char protocolIdentifier;
324 unsigned char reserved;
325 unsigned char userApplication;
326 // PACKET HEADER
327 unsigned char packetID[2];
328 unsigned char packetSequenceControl[2];
329 unsigned char packetLength[2];
330 // DATA FIELD HEADER
331 unsigned char spare1_pusVersion_spare2;
332 unsigned char serviceType;
333 unsigned char serviceSubType;
334 unsigned char destinationID;
335 unsigned char time[6];
336 //
337 unsigned char tc_failure_code[2];
338 unsigned char telecommand_pkt_id[2];
339 unsigned char pkt_seq_control[2];
340 unsigned char tc_service;
341 unsigned char tc_subtype;
342 } Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t;
343
344 typedef struct {
345 unsigned char targetLogicalAddress;
346 unsigned char protocolIdentifier;
347 unsigned char reserved;
348 unsigned char userApplication;
349 // PACKET HEADER
350 unsigned char packetID[2];
351 unsigned char packetSequenceControl[2];
352 unsigned char packetLength[2];
353 // DATA FIELD HEADER
354 unsigned char spare1_pusVersion_spare2;
355 unsigned char serviceType;
356 unsigned char serviceSubType;
357 unsigned char destinationID;
358 unsigned char time[6];
359 //
360 unsigned char tc_failure_code[2];
361 unsigned char telecommand_pkt_id[2];
362 unsigned char pkt_seq_control[2];
363 unsigned char tc_service;
364 unsigned char tc_subtype;
365 } Packet_TM_LFR_TC_EXE_ERROR_t;
366
367 typedef struct {
368 unsigned char targetLogicalAddress;
369 unsigned char protocolIdentifier;
370 unsigned char reserved;
371 unsigned char userApplication;
372 // PACKET HEADER
373 unsigned char packetID[2];
374 unsigned char packetSequenceControl[2];
375 unsigned char packetLength[2];
376 // DATA FIELD HEADER
377 unsigned char spare1_pusVersion_spare2;
378 unsigned char serviceType;
379 unsigned char serviceSubType;
380 unsigned char destinationID;
381 unsigned char time[6];
382 //
383 unsigned char tc_failure_code[2];
384 unsigned char telecommand_pkt_id[2];
385 unsigned char pkt_seq_control[2];
386 unsigned char tc_service;
387 unsigned char tc_subtype;
388 unsigned char pkt_len_rcv_value[2];
389 unsigned char pkt_datafieldsize_cnt[2];
390 unsigned char rcv_crc[2];
391 unsigned char computed_crc[2];
392 } Packet_TM_LFR_TC_EXE_CORRUPTED_t;
393
394 typedef struct {
395 unsigned char targetLogicalAddress;
396 unsigned char protocolIdentifier;
397 unsigned char reserved;
398 unsigned char userApplication;
399 unsigned char packetID[2];
400 unsigned char packetSequenceControl[2];
401 unsigned char packetLength[2];
402 // DATA FIELD HEADER
403 unsigned char spare1_pusVersion_spare2;
404 unsigned char serviceType;
405 unsigned char serviceSubType;
406 unsigned char destinationID;
407 unsigned char time[6];
408 // AUXILIARY HEADER
409 unsigned char sid;
410 unsigned char hkBIA;
411 unsigned char pktCnt;
412 unsigned char pktNr;
413 unsigned char acquisitionTime[6];
414 unsigned char blkNr[2];
415 } Header_TM_LFR_SCIENCE_SWF_t;
416
417 typedef struct {
418 unsigned char targetLogicalAddress;
419 unsigned char protocolIdentifier;
420 unsigned char reserved;
421 unsigned char userApplication;
422 unsigned char packetID[2];
423 unsigned char packetSequenceControl[2];
424 unsigned char packetLength[2];
425 // DATA FIELD HEADER
426 unsigned char spare1_pusVersion_spare2;
427 unsigned char serviceType;
428 unsigned char serviceSubType;
429 unsigned char destinationID;
430 unsigned char time[6];
431 // AUXILIARY DATA HEADER
432 unsigned char sid;
433 unsigned char hkBIA;
434 unsigned char acquisitionTime[6];
435 unsigned char blkNr[2];
436 } Header_TM_LFR_SCIENCE_CWF_t;
437
438 typedef struct {
439 unsigned char targetLogicalAddress;
440 unsigned char protocolIdentifier;
441 unsigned char reserved;
442 unsigned char userApplication;
443 unsigned char packetID[2];
444 unsigned char packetSequenceControl[2];
445 unsigned char packetLength[2];
446 // DATA FIELD HEADER
447 unsigned char spare1_pusVersion_spare2;
448 unsigned char serviceType;
449 unsigned char serviceSubType;
450 unsigned char destinationID;
451 unsigned char time[6];
452 // AUXILIARY HEADER
453 unsigned char sid;
454 unsigned char biaStatusInfo;
455 unsigned char pa_lfr_pkt_cnt_asm;
456 unsigned char pa_lfr_pkt_nr_asm;
457 unsigned char acquisitionTime[6];
458 unsigned char pa_lfr_asm_blk_nr[2];
459 } Header_TM_LFR_SCIENCE_ASM_t;
460
461 typedef struct {
462 unsigned char targetLogicalAddress;
463 unsigned char protocolIdentifier;
464 unsigned char reserved;
465 unsigned char userApplication;
466 unsigned char packetID[2];
467 unsigned char packetSequenceControl[2];
468 unsigned char packetLength[2];
469 // DATA FIELD HEADER
470 unsigned char spare1_pusVersion_spare2;
471 unsigned char serviceType;
472 unsigned char serviceSubType;
473 unsigned char destinationID;
474 unsigned char time[6];
475 // AUXILIARY HEADER
476 unsigned char sid;
477 unsigned char biaStatusInfo;
478 unsigned char acquisitionTime[6];
479 unsigned char source_data_spare;
480 unsigned char pa_lfr_bp_blk_nr[2];
481 } Header_TM_LFR_SCIENCE_BP_with_spare_t;
482
483 typedef struct {
484 unsigned char targetLogicalAddress;
485 unsigned char protocolIdentifier;
486 unsigned char reserved;
487 unsigned char userApplication;
488 unsigned char packetID[2];
489 unsigned char packetSequenceControl[2];
490 unsigned char packetLength[2];
491 // DATA FIELD HEADER
492 unsigned char spare1_pusVersion_spare2;
493 unsigned char serviceType;
494 unsigned char serviceSubType;
495 unsigned char destinationID;
496 unsigned char time[6];
497 // AUXILIARY HEADER
498 unsigned char sid;
499 unsigned char biaStatusInfo;
500 unsigned char acquisitionTime[6];
501 unsigned char pa_lfr_bp_blk_nr[2];
502 } Header_TM_LFR_SCIENCE_BP_t;
503
504 typedef struct {
505 //targetLogicalAddress is removed by the grspw module
506 unsigned char protocolIdentifier;
507 unsigned char reserved;
508 unsigned char userApplication;
509 unsigned char packetID[2];
510 unsigned char packetSequenceControl[2];
511 unsigned char packetLength[2];
512 // DATA FIELD HEADER
513 unsigned char headerFlag_pusVersion_Ack;
514 unsigned char serviceType;
515 unsigned char serviceSubType;
516 unsigned char sourceID;
517 unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
518 } ccsdsTelecommandPacket_t;
519
520 typedef struct {
521 unsigned char targetLogicalAddress;
522 unsigned char protocolIdentifier;
523 unsigned char reserved;
524 unsigned char userApplication;
525 unsigned char packetID[2];
526 unsigned char packetSequenceControl[2];
527 unsigned char packetLength[2];
528 unsigned char spare1_pusVersion_spare2;
529 unsigned char serviceType;
530 unsigned char serviceSubType;
531 unsigned char destinationID;
532 unsigned char time[6];
533 unsigned char sid;
534
535 //**************
536 // HK PARAMETERS
537 unsigned char lfr_status_word[2];
538 unsigned char lfr_sw_version[4];
539 unsigned char lfr_fpga_version[3];
540 // ressource statistics
541 unsigned char hk_lfr_cpu_load;
542 unsigned char hk_lfr_cpu_load_max;
543 unsigned char hk_lfr_cpu_load_aver;
544 // tc statistics
545 unsigned char hk_lfr_update_info_tc_cnt[2];
546 unsigned char hk_lfr_update_time_tc_cnt[2];
547 unsigned char hk_lfr_exe_tc_cnt[2];
548 unsigned char hk_lfr_rej_tc_cnt[2];
549 unsigned char hk_lfr_last_exe_tc_id[2];
550 unsigned char hk_lfr_last_exe_tc_type[2];
551 unsigned char hk_lfr_last_exe_tc_subtype[2];
552 unsigned char hk_lfr_last_exe_tc_time[6];
553 unsigned char hk_lfr_last_rej_tc_id[2];
554 unsigned char hk_lfr_last_rej_tc_type[2];
555 unsigned char hk_lfr_last_rej_tc_subtype[2];
556 unsigned char hk_lfr_last_rej_tc_time[6];
557 // anomaly statistics
558 unsigned char hk_lfr_le_cnt[2];
559 unsigned char hk_lfr_me_cnt[2];
560 unsigned char hk_lfr_he_cnt[2];
561 unsigned char hk_lfr_last_er_rid[2];
562 unsigned char hk_lfr_last_er_code;
563 unsigned char hk_lfr_last_er_time[6];
564 // vhdl_blk_status
565 unsigned char hk_lfr_vhdl_aa_sm;
566 unsigned char hk_lfr_vhdl_fft_sr;
567 unsigned char hk_lfr_vhdl_cic_hk;
568 unsigned char hk_lfr_vhdl_iir_cal;
569 // spacewire_if_statistics
570 unsigned char hk_lfr_dpu_spw_pkt_rcv_cnt[2];
571 unsigned char hk_lfr_dpu_spw_pkt_sent_cnt[2];
572 unsigned char hk_lfr_dpu_spw_tick_out_cnt;
573 unsigned char hk_lfr_dpu_spw_last_timc;
574 // ahb error statistics
575 unsigned char hk_lfr_last_fail_addr[4];
576 // temperatures
577 unsigned char hk_lfr_temp_scm[2];
578 unsigned char hk_lfr_temp_pcb[2];
579 unsigned char hk_lfr_temp_fpga[2];
580 // spacecraft potential
581 unsigned char hk_lfr_sc_v_f3[2];
582 unsigned char hk_lfr_sc_e1_f3[2];
583 unsigned char hk_lfr_sc_e2_f3[2];
584 // error counters
585 unsigned char hk_lfr_dpu_spw_parity;
586 unsigned char hk_lfr_dpu_spw_disconnect;
587 unsigned char hk_lfr_dpu_spw_escape;
588 unsigned char hk_lfr_dpu_spw_credit;
589 unsigned char hk_lfr_dpu_spw_write_sync;
590 unsigned char hk_lfr_dpu_spw_rx_ahb;
591 unsigned char hk_lfr_dpu_spw_tx_ahb;
592 unsigned char hk_lfr_dpu_spw_early_eop;
593 unsigned char hk_lfr_dpu_spw_invalid_addr;
594 unsigned char hk_lfr_dpu_spw_eep;
595 unsigned char hk_lfr_dpu_spw_rx_too_big;
596 // timecode
597 unsigned char hk_lfr_timecode_erroneous;
598 unsigned char hk_lfr_timecode_missing;
599 unsigned char hk_lfr_timecode_invalid;
600 // time
601 unsigned char hk_lfr_time_timecode_it;
602 unsigned char hk_lfr_time_not_synchro;
603 unsigned char hk_lfr_time_timecode_ctr;
604 // hk_lfr_buffer_dpu_
605 unsigned char hk_lfr_buffer_dpu_tc_fifo;
606 unsigned char hk_lfr_buffer_dpu_tm_fifo;
607 // hk_lfr_ahb_
608 unsigned char hk_lfr_ahb_correctable;
609 unsigned char hk_lfr_ahb_uncorrectable;
610 // spare
611 unsigned char parameters_spare;
612 } Packet_TM_LFR_HK_t;
613
614 typedef struct {
615 unsigned char targetLogicalAddress;
616 unsigned char protocolIdentifier;
617 unsigned char reserved;
618 unsigned char userApplication;
619 unsigned char packetID[2];
620 unsigned char packetSequenceControl[2];
621 unsigned char packetLength[2];
622 // DATA FIELD HEADER
623 unsigned char spare1_pusVersion_spare2;
624 unsigned char serviceType;
625 unsigned char serviceSubType;
626 unsigned char destinationID;
627 unsigned char time[6];
628 unsigned char sid;
629
630 //******************
631 // COMMON PARAMETERS
632 unsigned char unused0;
633 unsigned char bw_sp0_sp1_r0_r1;
634
635 //******************
636 // NORMAL PARAMETERS
637 unsigned char sy_lfr_n_swf_l[2];
638 unsigned char sy_lfr_n_swf_p[2];
639 unsigned char sy_lfr_n_asm_p[2];
640 unsigned char sy_lfr_n_bp_p0;
641 unsigned char sy_lfr_n_bp_p1;
642 unsigned char sy_lfr_n_cwf_long_f3;
643 unsigned char lfr_normal_parameters_spare;
644
645 //*****************
646 // BURST PARAMETERS
647 unsigned char sy_lfr_b_bp_p0;
648 unsigned char sy_lfr_b_bp_p1;
649
650 //****************
651 // SBM1 PARAMETERS
652 unsigned char sy_lfr_s1_bp_p0;
653 unsigned char sy_lfr_s1_bp_p1;
654
655 //****************
656 // SBM2 PARAMETERS
657 unsigned char sy_lfr_s2_bp_p0;
658 unsigned char sy_lfr_s2_bp_p1;
659
660 // SPARE
661 unsigned char source_data_spare;
662 } Packet_TM_LFR_PARAMETER_DUMP_t;
663
664
665 #endif // CCSDS_TYPES_H_INCLUDED
@@ -0,0 +1,39
1 #ifndef FSW_INIT_H_INCLUDED
2 #define FSW_INIT_H_INCLUDED
3
4 #include <rtems.h>
5 #include <leon.h>
6
7 #include "fsw_params.h"
8 #include "fsw_misc.h"
9
10 #include "tc_handler.h"
11 #include "fsw_spacewire.h"
12
13 extern rtems_name Task_name[20]; /* array of task names */
14 extern rtems_id Task_id[20]; /* array of task ids */
15
16 // RTEMS TASKS
17 rtems_task Init( rtems_task_argument argument);
18
19 // OTHER functions
20 void create_names( void );
21 int create_all_tasks( void );
22 int start_all_tasks( void );
23 //
24 rtems_status_code create_message_queues( void );
25 rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
26 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
27 //
28 int start_recv_send_tasks( void );
29 //
30 void init_local_mode_parameters( void );
31 void reset_local_time( void );
32
33 extern void rtems_cpu_usage_report( void );
34 extern void rtems_cpu_usage_reset( void );
35 extern void rtems_stack_checker_report_usage( void );
36
37 extern int sched_yield( void );
38
39 #endif // FSW_INIT_H_INCLUDED
@@ -0,0 +1,45
1 #ifndef FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
3
4 #include <rtems.h>
5 #include <stdio.h>
6 #include <grspw.h>
7
8 #include "fsw_params.h"
9 #include "fsw_spacewire.h"
10 #include "lfr_cpu_usage_report.h"
11
12 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
13 rtems_id HK_id; // id of the HK rate monotonic period
14
15 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
16 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
17 void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer );
18 void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer );
19 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider);
20
21 // SERIAL LINK
22 int send_console_outputs_on_apbuart_port( void );
23 int enable_apbuart_transmitter( void );
24 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
25
26 // RTEMS TASKS
27 rtems_task stat_task( rtems_task_argument argument );
28 rtems_task hous_task( rtems_task_argument argument );
29 rtems_task dumb_task( rtems_task_argument unused );
30
31 void init_housekeeping_parameters( void );
32 void increment_seq_counter(unsigned short *packetSequenceControl);
33 void getTime( unsigned char *time);
34 unsigned long long int getTimeAsUnsignedLongLongInt( );
35 void send_dumb_hk( void );
36 void get_v_e1_e2_f3 (unsigned char *spacecraft_potential);
37 void get_cpu_load( unsigned char *resource_statistics );
38
39 extern int sched_yield( void );
40 extern void rtems_cpu_usage_reset();
41 extern ring_node *current_ring_node_f3;
42 extern ring_node *ring_node_to_send_cwf_f3;
43 extern unsigned short sequenceCounterHK;
44
45 #endif // FSW_MISC_H_INCLUDED
@@ -0,0 +1,255
1 #ifndef FSW_PARAMS_H_INCLUDED
2 #define FSW_PARAMS_H_INCLUDED
3
4 #include "grlib_regs.h"
5 #include "fsw_params_processing.h"
6 #include "fsw_params_nb_bytes.h"
7 #include "tm_byte_positions.h"
8 #include "ccsds_types.h"
9
10 #define GRSPW_DEVICE_NAME "/dev/grspw0"
11 #define UART_DEVICE_NAME "/dev/console"
12
13 typedef struct ring_node
14 {
15 struct ring_node *previous;
16 int buffer_address;
17 struct ring_node *next;
18 unsigned int status;
19 } ring_node;
20
21 //************************
22 // flight software version
23 // this parameters is handled by the Qt project options
24
25 #define NB_PACKETS_PER_GROUP_OF_CWF 8 // 8 packets containing 336 blk
26 #define NB_PACKETS_PER_GROUP_OF_CWF_LIGHT 4 // 4 packets containing 672 blk
27 #define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688
28 #define TIME_OFFSET 2
29 #define TIME_OFFSET_IN_BYTES 8
30 #define WAVEFORM_EXTENDED_HEADER_OFFSET 22
31 #define NB_BYTES_SWF_BLK (2 * 6)
32 #define NB_WORDS_SWF_BLK 3
33 #define NB_BYTES_CWF3_LIGHT_BLK 6
34 #define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8
35 #define NB_RING_NODES_F0 3 // AT LEAST 3
36 #define NB_RING_NODES_F1 5 // AT LEAST 3
37 #define NB_RING_NODES_F2 5 // AT LEAST 3
38 #define NB_RING_NODES_F3 3 // AT LEAST 3
39
40 //**********
41 // LFR MODES
42 #define LFR_MODE_STANDBY 0
43 #define LFR_MODE_NORMAL 1
44 #define LFR_MODE_BURST 2
45 #define LFR_MODE_SBM1 3
46 #define LFR_MODE_SBM2 4
47
48 #define TDS_MODE_LFM 5
49 #define TDS_MODE_STANDBY 0
50 #define TDS_MODE_NORMAL 1
51 #define TDS_MODE_BURST 2
52 #define TDS_MODE_SBM1 3
53 #define TDS_MODE_SBM2 4
54
55 #define THR_MODE_STANDBY 0
56 #define THR_MODE_NORMAL 1
57 #define THR_MODE_BURST 2
58
59 #define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0
60 #define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1
61 #define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2
62 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
63 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
64 #define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5
65 #define RTEMS_EVENT_NORM_BP1_F0 RTEMS_EVENT_6
66 #define RTEMS_EVENT_NORM_BP2_F0 RTEMS_EVENT_7
67 #define RTEMS_EVENT_NORM_ASM_F0 RTEMS_EVENT_8 // ASM only in NORM mode
68 #define RTEMS_EVENT_NORM_BP1_F1 RTEMS_EVENT_9
69 #define RTEMS_EVENT_NORM_BP2_F1 RTEMS_EVENT_10
70 #define RTEMS_EVENT_NORM_ASM_F1 RTEMS_EVENT_11 // ASM only in NORM mode
71 #define RTEMS_EVENT_NORM_BP1_F2 RTEMS_EVENT_12
72 #define RTEMS_EVENT_NORM_BP2_F2 RTEMS_EVENT_13
73 #define RTEMS_EVENT_NORM_ASM_F2 RTEMS_EVENT_14 // ASM only in NORM mode
74 #define RTEMS_EVENT_SBM_BP1_F0 RTEMS_EVENT_15
75 #define RTEMS_EVENT_SBM_BP2_F0 RTEMS_EVENT_16
76 #define RTEMS_EVENT_SBM_BP1_F1 RTEMS_EVENT_17
77 #define RTEMS_EVENT_SBM_BP2_F1 RTEMS_EVENT_18
78 #define RTEMS_EVENT_BURST_BP1_F0 RTEMS_EVENT_19
79 #define RTEMS_EVENT_BURST_BP2_F0 RTEMS_EVENT_20
80 #define RTEMS_EVENT_BURST_BP1_F1 RTEMS_EVENT_21
81 #define RTEMS_EVENT_BURST_BP2_F1 RTEMS_EVENT_22
82
83 //****************************
84 // LFR DEFAULT MODE PARAMETERS
85 // COMMON
86 #define DEFAULT_SY_LFR_COMMON0 0x00
87 #define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0
88 // NORM
89 #define DFLT_SY_LFR_N_SWF_L 2048 // nb sample
90 #define DFLT_SY_LFR_N_SWF_P 300 // sec
91 #define DFLT_SY_LFR_N_ASM_P 3600 // sec
92 #define DFLT_SY_LFR_N_BP_P0 4 // sec
93 #define DFLT_SY_LFR_N_BP_P1 20 // sec
94 #define DFLT_SY_LFR_N_CWF_LONG_F3 0 // 0 => production of light continuous waveforms at f3
95 #define MIN_DELTA_SNAPSHOT 16 // sec
96 // BURST
97 #define DEFAULT_SY_LFR_B_BP_P0 1 // sec
98 #define DEFAULT_SY_LFR_B_BP_P1 5 // sec
99 // SBM1
100 #define DEFAULT_SY_LFR_S1_BP_P0 1 // sec
101 #define DEFAULT_SY_LFR_S1_BP_P1 1 // sec
102 // SBM2
103 #define DEFAULT_SY_LFR_S2_BP_P0 1 // sec
104 #define DEFAULT_SY_LFR_S2_BP_P1 5 // sec
105 // ADDITIONAL PARAMETERS
106 #define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms
107 #define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s
108 // STATUS WORD
109 #define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits
110 #define DEFAULT_STATUS_WORD_BYTE1 0x00
111 //
112 #define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s
113 #define SY_LFR_DPU_CONNECT_ATTEMPT 3
114 //****************************
115
116 //*****************************
117 // APB REGISTERS BASE ADDRESSES
118 #define REGS_ADDR_APBUART 0x80000100
119 #define REGS_ADDR_GPTIMER 0x80000300
120 #define REGS_ADDR_GRSPW 0x80000500
121 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
122 #define REGS_ADDR_GRGPIO 0x80000b00
123
124 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
125 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f50
126 #define REGS_ADDR_VHDL_VERSION 0x80000ff0
127
128 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
129 #define APBUART_CTRL_REG_MASK_TE 0x00000002
130 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50)
131
132 //**********
133 // IRQ LINES
134 #define IRQ_SM_SIMULATOR 9
135 #define IRQ_SPARC_SM_SIMULATOR 0x19 // see sparcv8.pdf p.76 for interrupt levels
136 #define IRQ_WAVEFORM_PICKER 14
137 #define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels
138 #define IRQ_SPECTRAL_MATRIX 6
139 #define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels
140
141 //*****
142 // TIME
143 #define CLKDIV_SM_SIMULATOR (10416 - 1) // 10 ms => nominal is 1/96 = 0.010416667, 10417 - 1 = 10416
144 #define TIMER_SM_SIMULATOR 1
145 #define HK_PERIOD 100 // 100 * 10ms => 1s
146 #define SY_LFR_TIME_SYN_TIMEOUT_in_ms 2000
147 #define SY_LFR_TIME_SYN_TIMEOUT_in_ticks 200 // 200 * 10 ms = 2 s
148
149 //**********
150 // LPP CODES
151 #define LFR_SUCCESSFUL 0
152 #define LFR_DEFAULT 1
153 #define LFR_EXE_ERROR 2
154
155 //******
156 // RTEMS
157 #define TASKID_RECV 1
158 #define TASKID_ACTN 2
159 #define TASKID_SPIQ 3
160 #define TASKID_STAT 4
161 #define TASKID_AVF0 5
162 #define TASKID_SWBD 6
163 #define TASKID_WFRM 7
164 #define TASKID_DUMB 8
165 #define TASKID_HOUS 9
166 #define TASKID_PRC0 10
167 #define TASKID_CWF3 11
168 #define TASKID_CWF2 12
169 #define TASKID_CWF1 13
170 #define TASKID_SEND 14
171 #define TASKID_WTDG 15
172 #define TASKID_AVF1 16
173 #define TASKID_PRC1 17
174 #define TASKID_AVF2 18
175 #define TASKID_PRC2 19
176
177 #define TASK_PRIORITY_SPIQ 5
178 #define TASK_PRIORITY_WTDG 20
179 #define TASK_PRIORITY_HOUS 30
180 #define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together
181 #define TASK_PRIORITY_CWF2 35 //
182 #define TASK_PRIORITY_SWBD 37 // SWBD has a lower priority than WFRM, this is to extract the snapshot before sending it
183 #define TASK_PRIORITY_WFRM 40
184 #define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1
185 #define TASK_PRIORITY_SEND 45
186 #define TASK_PRIORITY_RECV 50
187 #define TASK_PRIORITY_ACTN 50
188 #define TASK_PRIORITY_AVF0 60
189 #define TASK_PRIORITY_AVF1 70
190 #define TASK_PRIORITY_PRC0 100
191 #define TASK_PRIORITY_PRC1 100
192 #define TASK_PRIORITY_AVF2 110
193 #define TASK_PRIORITY_PRC2 110
194 #define TASK_PRIORITY_STAT 200
195 #define TASK_PRIORITY_DUMB 200
196
197 #define MSG_QUEUE_COUNT_RECV 10
198 #define MSG_QUEUE_COUNT_SEND 50
199 #define MSG_QUEUE_COUNT_PRC0 10
200 #define MSG_QUEUE_COUNT_PRC1 10
201 #define MSG_QUEUE_COUNT_PRC2 5
202 #define MSG_QUEUE_SIZE_SEND 810 // 806 + 4 => TM_LFR_SCIENCE_BURST_BP2_F1
203 #define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options
204 #define MSG_QUEUE_SIZE_PRC0 20 // two pointers and one rtems_event + 2 integers
205 #define MSG_QUEUE_SIZE_PRC1 20 // two pointers and one rtems_event + 2 integers
206 #define MSG_QUEUE_SIZE_PRC2 20 // two pointers and one rtems_event + 2 integers
207
208 #define QUEUE_RECV 0
209 #define QUEUE_SEND 1
210 #define QUEUE_PRC0 2
211 #define QUEUE_PRC1 3
212 #define QUEUE_PRC2 4
213
214 //*******
215 // MACROS
216 #ifdef PRINT_MESSAGES_ON_CONSOLE
217 #define PRINTF(x) printf(x);
218 #define PRINTF1(x,y) printf(x,y);
219 #define PRINTF2(x,y,z) printf(x,y,z);
220 #else
221 #define PRINTF(x) ;
222 #define PRINTF1(x,y) ;
223 #define PRINTF2(x,y,z) ;
224 #endif
225
226 #ifdef BOOT_MESSAGES
227 #define BOOT_PRINTF(x) printf(x);
228 #define BOOT_PRINTF1(x,y) printf(x,y);
229 #define BOOT_PRINTF2(x,y,z) printf(x,y,z);
230 #else
231 #define BOOT_PRINTF(x) ;
232 #define BOOT_PRINTF1(x,y) ;
233 #define BOOT_PRINTF2(x,y,z) ;
234 #endif
235
236 #ifdef DEBUG_MESSAGES
237 #define DEBUG_PRINTF(x) printf(x);
238 #define DEBUG_PRINTF1(x,y) printf(x,y);
239 #define DEBUG_PRINTF2(x,y,z) printf(x,y,z);
240 #else
241 #define DEBUG_PRINTF(x) ;
242 #define DEBUG_PRINTF1(x,y) ;
243 #define DEBUG_PRINTF2(x,y,z) ;
244 #endif
245
246 #define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period
247
248 struct param_local_str{
249 unsigned int local_sbm1_nb_cwf_sent;
250 unsigned int local_sbm1_nb_cwf_max;
251 unsigned int local_sbm2_nb_cwf_sent;
252 unsigned int local_sbm2_nb_cwf_max;
253 };
254
255 #endif // FSW_PARAMS_H_INCLUDED
@@ -0,0 +1,37
1 #ifndef TM_BYTE_POSITIONS_H
2 #define TM_BYTE_POSITIONS_H
3
4 // SEQUENCE_CNT
5 #define PACKET_POS_SEQUENCE_CNT 6 // 4 + 2
6
7 // TC_LFR_LOAD_COMMON_PAR
8
9 // TC_LFR_LOAD_NORMAL_PAR
10 #define DATAFIELD_POS_SY_LFR_N_SWF_L 0
11 #define DATAFIELD_POS_SY_LFR_N_SWF_P 2
12 #define DATAFIELD_POS_SY_LFR_N_ASM_P 4
13 #define DATAFIELD_POS_SY_LFR_N_BP_P0 6
14 #define DATAFIELD_POS_SY_LFR_N_BP_P1 7
15 #define DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 8
16
17 // TC_LFR_LOAD_BURST_PAR
18 #define DATAFIELD_POS_SY_LFR_B_BP_P0 0
19 #define DATAFIELD_POS_SY_LFR_B_BP_P1 1
20
21 // TC_LFR_LOAD_SBM1_PAR
22 #define DATAFIELD_POS_SY_LFR_S1_BP_P0 0
23 #define DATAFIELD_POS_SY_LFR_S1_BP_P1 1
24
25 // TC_LFR_LOAD_SBM2_PAR
26 #define DATAFIELD_POS_SY_LFR_S2_BP_P0 0
27 #define DATAFIELD_POS_SY_LFR_S2_BP_P1 1
28
29 // TC_LFR_UPDATE_INFO
30 #define BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 34
31 #define BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 35
32
33 // TC_LFR_ENTER_MODE
34 #define BYTE_POS_CP_MODE_LFR_SET 11
35 #define BYTE_POS_CP_LFR_ENTER_MODE_TIME 12
36
37 #endif // TM_BYTE_POSITIONS_H
@@ -0,0 +1,70
1 #ifndef FSW_PARAMS_PROCESSING_H
2 #define FSW_PARAMS_PROCESSING_H
3
4 #define NB_BINS_PER_SM 128
5 #define NB_VALUES_PER_SM 25
6 #define TOTAL_SIZE_SM 3200 // 25 * 128 = 0xC80
7 #define TOTAL_SIZE_NORM_BP1_F0 99 // 11 * 9 = 99
8 #define TOTAL_SIZE_NORM_BP1_F1 117 // 13 * 9 = 117
9 #define TOTAL_SIZE_NORM_BP1_F2 108 // 12 * 9 = 108
10 #define TOTAL_SIZE_SBM1_BP1_F0 198 // 22 * 9 = 198
11 //
12 #define NB_RING_NODES_SM_F0 12 // AT LEAST 3
13 #define NB_RING_NODES_ASM_BURST_SBM_F0 10 // AT LEAST 3
14 #define NB_RING_NODES_ASM_NORM_F0 10 // AT LEAST 3
15 #define NB_RING_NODES_SM_F1 3 // AT LEAST 3
16 #define NB_RING_NODES_ASM_BURST_SBM_F1 5 // AT LEAST 3
17 #define NB_RING_NODES_ASM_NORM_F1 5 // AT LEAST 3
18 #define NB_RING_NODES_SM_F2 3 // AT LEAST 3
19 #define NB_RING_NODES_ASM_BURST_SBM_F2 3 // AT LEAST 3
20 #define NB_RING_NODES_ASM_NORM_F2 3 // AT LEAST 3
21 //
22 #define NB_BINS_PER_ASM_F0 88
23 #define NB_BINS_PER_PKT_ASM_F0 44
24 #define TOTAL_SIZE_ASM_F0_IN_BYTES 4400 // 25 * 88 * 2
25 #define ASM_F0_INDICE_START 17 // 88 bins
26 #define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins
27 //
28 #define NB_BINS_PER_ASM_F1 104
29 #define NB_BINS_PER_PKT_ASM_F1 52
30 #define TOTAL_SIZE_ASM_F1_IN_BYTES 5200 // 25 * 104 * 2
31 #define ASM_F1_INDICE_START 6 // 104 bins
32 #define ASM_F1_INDICE_STOP 109 // 2 packets of 52 bins
33 //
34 #define NB_BINS_PER_ASM_F2 96
35 #define NB_BINS_PER_PKT_ASM_F2 48
36 #define TOTAL_SIZE_ASM_F2_IN_BYTES 4800 // 25 * 96 * 2
37 #define ASM_F2_INDICE_START 7 // 96 bins
38 #define ASM_F2_INDICE_STOP 102 // 2 packets of 48 bins
39 //
40 #define NB_BINS_COMPRESSED_SM_F0 11
41 #define NB_BINS_COMPRESSED_SM_F1 13
42 #define NB_BINS_COMPRESSED_SM_F2 12
43 #define NB_BINS_COMPRESSED_SM_SBM_F0 22
44 #define NB_BINS_COMPRESSED_SM_SBM_F1 26
45 #define NB_BINS_COMPRESSED_SM_SBM_F2 24
46 //
47 #define NB_BYTES_PER_BP1 9
48 //
49 #define NB_BINS_TO_AVERAGE_ASM_F0 8
50 #define NB_BINS_TO_AVERAGE_ASM_F1 8
51 #define NB_BINS_TO_AVERAGE_ASM_F2 8
52 #define NB_BINS_TO_AVERAGE_ASM_SBM_F0 4
53 #define NB_BINS_TO_AVERAGE_ASM_SBM_F1 4
54 #define NB_BINS_TO_AVERAGE_ASM_SBM_F2 4
55 //
56 #define TOTAL_SIZE_COMPRESSED_ASM_NORM_F0 275 // 11 * 25 WORDS
57 #define TOTAL_SIZE_COMPRESSED_ASM_NORM_F1 325 // 13 * 25 WORDS
58 #define TOTAL_SIZE_COMPRESSED_ASM_NORM_F2 300 // 12 * 25 WORDS
59 #define TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 550 // 22 * 25 WORDS
60 #define TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 650 // 26 * 25 WORDS
61 #define TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 600 // 24 * 25 WORDS
62 #define TOTAL_SIZE_BP1_NORM_F0 99 // 9 * 11 UNSIGNED CHAR
63 #define TOTAL_SIZE_BP1_SBM_F0 198 // 9 * 22 UNSIGNED CHAR
64 // GENERAL
65 #define NB_SM_BEFORE_AVF0 8 // must be 8 due to the SM_average() function
66 #define NB_SM_BEFORE_AVF1 8 // must be 8 due to the SM_average() function
67 #define NB_SM_BEFORE_AVF2 1 // must be 1 due to the SM_average_f2() function
68
69 #endif // FSW_PARAMS_PROCESSING_H
70
@@ -0,0 +1,8
1 #ifndef FSW_PARAMS_WF_HANDLER_H
2 #define FSW_PARAMS_WF_HANDLER_H
3
4 #define WFRM_BUFFER 8128 // (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 62
5 // (2688 * 3 ) + 2 + 62 = 8128 = 0X1FC0
6 // 8128 * 4 = 32512 = 0x7F00
7
8 #endif // FSW_PARAMS_WF_HANDLER_H
@@ -0,0 +1,53
1 #ifndef FSW_SPACEWIRE_H_INCLUDED
2 #define FSW_SPACEWIRE_H_INCLUDED
3
4 #include <rtems.h>
5 #include <grspw.h>
6
7 #include <fcntl.h> // for O_RDWR
8 #include <unistd.h> // for the read call
9 #include <sys/ioctl.h> // for the ioctl call
10 #include <errno.h>
11
12 #include "fsw_params.h"
13 #include "tc_handler.h"
14 #include "TC_types.h"
15
16 extern spw_stats spacewire_stats;
17 extern spw_stats spacewire_stats_backup;
18 extern rtems_id rtems_task_id_updt;
19
20 void resetLocalCoarseTime();
21 void setLocalCoarseTime( unsigned int value );
22 unsigned int getLocalCoarseTime();
23 void incrementLocalCoarseTime();
24
25 // TC_LFR_UPDATE_TIME
26 void initLookUpTableForCRC( void );
27 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
28 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
29 void updateTimePacket(unsigned int time, Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t *packet);
30
31 // RTEMS TASK
32 rtems_task spiq_task( rtems_task_argument argument );
33 rtems_task recv_task( rtems_task_argument unused );
34 rtems_task send_task( rtems_task_argument argument );
35 rtems_task wtdg_task( rtems_task_argument argument );
36 rtems_task updt_task( rtems_task_argument unused );
37
38 int spacewire_open_link( void );
39 int spacewire_start_link( int fd );
40 int spacewire_stop_and_start_link( int fd );
41 int spacewire_configure_link(int fd );
42 int spacewire_reset_link( void );
43 void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force
44 void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable
45 void spacewire_compute_stats_offsets( void );
46 void spacewire_update_statistics( void );
47
48 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
49 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data );
50
51 void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc );
52
53 #endif // FSW_SPACEWIRE_H_INCLUDED
@@ -0,0 +1,109
1 #ifndef GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
3
4 #define NB_GPTIMER 3
5
6 struct apbuart_regs_str{
7 volatile unsigned int data;
8 volatile unsigned int status;
9 volatile unsigned int ctrl;
10 volatile unsigned int scaler;
11 volatile unsigned int fifoDebug;
12 };
13
14 struct grgpio_regs_str{
15 volatile int io_port_data_register;
16 int io_port_output_register;
17 int io_port_direction_register;
18 int interrupt_mak_register;
19 int interrupt_polarity_register;
20 int interrupt_edge_register;
21 int bypass_register;
22 int reserved;
23 // 0x20-0x3c interrupt map register(s)
24 };
25
26 typedef struct {
27 volatile unsigned int counter;
28 volatile unsigned int reload;
29 volatile unsigned int ctrl;
30 volatile unsigned int unused;
31 } timer_regs_t;
32
33 typedef struct {
34 volatile unsigned int scaler_value;
35 volatile unsigned int scaler_reload;
36 volatile unsigned int conf;
37 volatile unsigned int unused0;
38 timer_regs_t timer[NB_GPTIMER];
39 } gptimer_regs_t;
40
41 typedef struct {
42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
43 volatile int coarse_time_load;
44 volatile int coarse_time;
45 volatile int fine_time;
46 } time_management_regs_t;
47
48 typedef struct {
49 volatile int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
50 volatile int burst_enable; // 0x04 01 *** burst f2, f1, f0 enable f3, f2, f1, f0
51 volatile int addr_data_f0; // 0x08 10 ***
52 volatile int addr_data_f1; // 0x0c 11 ***
53 volatile int addr_data_f2; // 0x10 100 ***
54 volatile int addr_data_f3; // 0x14 101 ***
55 volatile int status; // 0x18 110 ***
56 volatile int delta_snapshot; // 0x1c 111 ***
57 volatile int delta_f2_f1; // 0x20 0000 ***
58 volatile int delta_f2_f0; // 0x24 0001 ***
59 volatile int nb_burst_available;// 0x28 0010 ***
60 volatile int nb_snapshot_param; // 0x2c 0011 ***
61 } waveform_picker_regs_t;
62
63 typedef struct{
64 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
65 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
66 int addr_data_f0; // 0x08
67 int addr_data_f1; // 0x0c
68 int addr_data_f2; // 0x10
69 int addr_data_f3; // 0x14
70 volatile int status; // 0x18
71 int delta_snapshot; // 0x1c
72 int delta_f0; // 0x20
73 int delta_f0_2; // 0x24
74 int delta_f1; // 0x28
75 int delta_f2; // 0x2c
76 int nb_data_by_buffer; // 0x30
77 int snapshot_param; // 0x34
78 int start_date; // 0x38
79 int nb_word_in_buffer; // 0x3c
80 } waveform_picker_regs_new_t;
81
82 typedef struct {
83 volatile int config; // 0x00
84 volatile int status; // 0x04
85 volatile int f0_0_address; // 0x08
86 volatile int f0_1_address; // 0x0C
87 //
88 volatile int f1_0_address; // 0x10
89 volatile int f1_1_address; // 0x14
90 volatile int f2_0_address; // 0x18
91 volatile int f2_1_address; // 0x1C
92 //
93 volatile unsigned int f0_0_coarse_time; // 0x20
94 volatile unsigned int f0_0_fine_time; // 0x24
95 volatile unsigned int f0_1_coarse_time; // 0x28
96 volatile unsigned int f0_1_fine_time; // 0x2C
97 //
98 volatile unsigned int f1_0_coarse_time; // 0x30
99 volatile unsigned int f1_0_fine_time; // 0x34
100 volatile unsigned int f1_1_coarse_time; // 0x38
101 volatile unsigned int f1_1_time_time; // 0x3C
102 //
103 volatile unsigned int f2_0_coarse_time; // 0x40
104 volatile unsigned int f2_0_fine_time; // 0x44
105 volatile unsigned int f2_1_coarse_time; // 0x48
106 volatile unsigned int f2_1_fine_time; // 0x4C
107 } spectral_matrix_regs_t;
108
109 #endif // GRLIB_REGS_H_INCLUDED
@@ -0,0 +1,32
1 #ifndef LFR_CPU_USAGE_REPORT_H
2 #define LFR_CPU_USAGE_REPORT_H
3
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7
8 #include <rtems.h>
9
10 #include <assert.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <inttypes.h>
16
17 #include <rtems/cpuuse.h>
18 #include <rtems/bspIo.h>
19
20 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
21 #include <rtems/score/timestamp.h>
22 #endif
23
24 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
25 extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
26 #else
27 extern uint32_t CPU_usage_Ticks_at_last_reset;
28 #endif
29
30 unsigned char lfr_rtems_cpu_usage_report( void );
31
32 #endif // LFR_CPU_USAGE_REPORT_H
@@ -0,0 +1,36
1 #ifndef AVF0_PRC0_H_INCLUDED
2 #define AVF0_PRC0_H_INCLUDED
3
4 #include "fsw_processing.h"
5 #include "basic_parameters.h"
6
7 typedef struct {
8 unsigned int norm_bp1;
9 unsigned int norm_bp2;
10 unsigned int norm_asm;
11 unsigned int burst_sbm_bp1;
12 unsigned int burst_sbm_bp2;
13 unsigned int burst_bp1;
14 unsigned int burst_bp2;
15 unsigned int sbm1_bp1;
16 unsigned int sbm1_bp2;
17 unsigned int sbm2_bp1;
18 unsigned int sbm2_bp2;
19 } nb_sm_before_bp_asm_f0;
20
21 //************
22 // RTEMS TASKS
23 rtems_task avf0_task( rtems_task_argument lfrRequestedMode );
24 rtems_task prc0_task( rtems_task_argument lfrRequestedMode );
25
26 //**********
27 // FUNCTIONS
28
29 void reset_nb_sm_f0( unsigned char lfrMode );
30
31 //*******
32 // EXTERN
33 extern ring_node_sm *ring_node_for_averaging_sm_f0;
34 extern rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id );
35
36 #endif // AVF0_PRC0_H_INCLUDED
@@ -0,0 +1,33
1 #ifndef AVF1_PRC1_H
2 #define AVF1_PRC1_H
3
4 #include "fsw_processing.h"
5
6 typedef struct {
7 unsigned int norm_bp1;
8 unsigned int norm_bp2;
9 unsigned int norm_asm;
10 unsigned int burst_sbm_bp1;
11 unsigned int burst_sbm_bp2;
12 unsigned int burst_bp1;
13 unsigned int burst_bp2;
14 unsigned int sbm2_bp1;
15 unsigned int sbm2_bp2;
16 } nb_sm_before_bp_asm_f1;
17
18 //************
19 // RTEMS TASKS
20 rtems_task avf1_task( rtems_task_argument lfrRequestedMode );
21 rtems_task prc1_task( rtems_task_argument lfrRequestedMode );
22
23 //**********
24 // FUNCTIONS
25
26 void reset_nb_sm_f1( unsigned char lfrMode );
27
28 //*******
29 // EXTERN
30 extern struct ring_node_sm *ring_node_for_averaging_sm_f1;
31 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
32
33 #endif // AVF1_PRC1_H
@@ -0,0 +1,28
1 #ifndef AVF2_PRC2_H
2 #define AVF2_PRC2_H
3
4 #include "fsw_processing.h"
5
6 typedef struct {
7 unsigned int norm_bp1;
8 unsigned int norm_bp2;
9 unsigned int norm_asm;
10 } nb_sm_before_bp_asm_f2;
11
12 //************
13 // RTEMS TASKS
14 rtems_task avf2_task( rtems_task_argument lfrRequestedMode );
15 rtems_task prc2_task( rtems_task_argument lfrRequestedMode );
16
17 //**********
18 // FUNCTIONS
19
20 void reset_nb_sm_f2( void );
21 void SM_average_f2( float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 );
22
23 //*******
24 // EXTERN
25 extern struct ring_node_sm *ring_node_for_averaging_sm_f2;
26 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
27
28 #endif // AVF2_PRC2_H
@@ -0,0 +1,243
1 #ifndef FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
3
4 #include <rtems.h>
5 #include <grspw.h>
6 #include <math.h>
7 #include <stdlib.h> // abs() is in the stdlib
8 #include <stdio.h> // printf()
9 #include <math.h>
10
11 #include "fsw_params.h"
12 #include "fsw_spacewire.h"
13
14 typedef struct ring_node_sm
15 {
16 struct ring_node_sm *previous;
17 struct ring_node_sm *next;
18 int buffer_address;
19 unsigned int status;
20 unsigned int coarseTime;
21 unsigned int fineTime;
22 } ring_node_sm;
23
24 typedef struct ring_node_asm
25 {
26 struct ring_node_asm *next;
27 float matrix[ TOTAL_SIZE_SM ];
28 unsigned int status;
29 } ring_node_asm;
30
31 typedef struct
32 {
33 Header_TM_LFR_SCIENCE_BP_t header;
34 unsigned char data[ 30 * 22 ]; // MAX size is 22 * 30 [TM_LFR_SCIENCE_BURST_BP2_F1]
35 } bp_packet;
36
37 typedef struct
38 {
39 Header_TM_LFR_SCIENCE_BP_with_spare_t header;
40 unsigned char data[ 9 * 13 ]; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
41 } bp_packet_with_spare;
42
43 typedef struct
44 {
45 ring_node_asm *norm;
46 ring_node_asm *burst_sbm;
47 rtems_event_set event;
48 unsigned int coarseTime;
49 unsigned int fineTime;
50 } asm_msg;
51
52 extern volatile int sm_f0[ ];
53 extern volatile int sm_f1[ ];
54 extern volatile int sm_f2[ ];
55
56 // parameters
57 extern struct param_local_str param_local;
58
59 // registers
60 extern time_management_regs_t *time_management_regs;
61 extern spectral_matrix_regs_t *spectral_matrix_regs;
62
63 extern rtems_name misc_name[5];
64 extern rtems_id Task_id[20]; /* array of task ids */
65
66 // ISR
67 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
68 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector );
69
70 //******************
71 // Spectral Matrices
72 void reset_nb_sm( void );
73 // SM
74 void SM_init_rings( void );
75 void SM_reset_current_ring_nodes( void );
76 void SM_generic_init_ring(ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] );
77 // ASM
78 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
79 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header);
80 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
81 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id);
82
83 //*****************
84 // Basic Parameters
85
86 void BP_reset_current_ring_nodes( void );
87 void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header,
88 unsigned int apid, unsigned char sid,
89 unsigned int packetLength , unsigned char blkNr);
90 void BP_init_header_with_spare( Header_TM_LFR_SCIENCE_BP_with_spare_t *header,
91 unsigned int apid, unsigned char sid,
92 unsigned int packetLength, unsigned char blkNr );
93 void BP_send( char *data,
94 rtems_id queue_id ,
95 unsigned int nbBytesToSend , unsigned int sid );
96
97 //******************
98 // general functions
99 void reset_spectral_matrix_regs( void );
100 void set_time(unsigned char *time, unsigned char *timeInBuffer );
101 unsigned long long int get_acquisition_time( unsigned char *timePtr );
102 void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
103 ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time);
104 unsigned char getSID( rtems_event_set event );
105
106 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
107 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
108
109 //***************************************
110 // DEFINITIONS OF STATIC INLINE FUNCTIONS
111 static inline void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
112 ring_node_sm *ring_node_tab[],
113 unsigned int nbAverageNORM, unsigned int nbAverageSBM );
114 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
115 float divider );
116 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
117 float divider,
118 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
119 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
120
121 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
122 ring_node_sm *ring_node_tab[],
123 unsigned int nbAverageNORM, unsigned int nbAverageSBM )
124 {
125 float sum;
126 unsigned int i;
127
128 for(i=0; i<TOTAL_SIZE_SM; i++)
129 {
130 sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
131 + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
132 + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
133 + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
134 + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
135 + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
136 + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
137 + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
138
139 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
140 {
141 averaged_spec_mat_NORM[ i ] = sum;
142 averaged_spec_mat_SBM[ i ] = sum;
143 }
144 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
145 {
146 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
147 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
148 }
149 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
150 {
151 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
152 averaged_spec_mat_SBM[ i ] = sum;
153 }
154 else
155 {
156 PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
157 }
158 }
159 }
160
161 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
162 {
163 int frequencyBin;
164 int asmComponent;
165 unsigned int offsetAveragedSpecMatReorganized;
166 unsigned int offsetAveragedSpecMat;
167
168 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
169 {
170 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
171 {
172 offsetAveragedSpecMatReorganized =
173 frequencyBin * NB_VALUES_PER_SM
174 + asmComponent;
175 offsetAveragedSpecMat =
176 asmComponent * NB_BINS_PER_SM
177 + frequencyBin;
178 averaged_spec_mat_reorganized[offsetAveragedSpecMatReorganized ] =
179 averaged_spec_mat[ offsetAveragedSpecMat ] / divider;
180 }
181 }
182 }
183
184 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
185 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
186 {
187 int frequencyBin;
188 int asmComponent;
189 int offsetASM;
190 int offsetCompressed;
191 int k;
192
193 // build data
194 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
195 {
196 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
197 {
198 offsetCompressed = // NO TIME OFFSET
199 frequencyBin * NB_VALUES_PER_SM
200 + asmComponent;
201 offsetASM = // NO TIME OFFSET
202 asmComponent * NB_BINS_PER_SM
203 + ASMIndexStart
204 + frequencyBin * nbBinsToAverage;
205 compressed_spec_mat[ offsetCompressed ] = 0;
206 for ( k = 0; k < nbBinsToAverage; k++ )
207 {
208 compressed_spec_mat[offsetCompressed ] =
209 ( compressed_spec_mat[ offsetCompressed ]
210 + averaged_spec_mat[ offsetASM + k ] ) / (divider * nbBinsToAverage);
211 }
212 }
213 }
214 }
215
216 void ASM_convert( volatile float *input_matrix, char *output_matrix)
217 {
218 unsigned int frequencyBin;
219 unsigned int asmComponent;
220 char * pt_char_input;
221 char * pt_char_output;
222 unsigned int offsetInput;
223 unsigned int offsetOutput;
224
225 pt_char_input = (char*) &input_matrix;
226 pt_char_output = (char*) &output_matrix;
227
228 // convert all other data
229 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
230 {
231 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
232 {
233 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
234 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
235 pt_char_input = (char*) &input_matrix [ offsetInput ];
236 pt_char_output = (char*) &output_matrix[ offsetOutput ];
237 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
238 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
239 }
240 }
241 }
242
243 #endif // FSW_PROCESSING_H_INCLUDED
@@ -0,0 +1,25
1 #ifndef TC_ACCEPTANCE_H_INCLUDED
2 #define TC_ACCEPTANCE_H_INCLUDED
3
4 //#include "tm_lfr_tc_exe.h"
5 #include "fsw_params.h"
6
7 //**********************
8 // GENERAL USE FUNCTIONS
9 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
10 void initLookUpTableForCRC( void );
11 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
12
13 //*********************
14 // ACCEPTANCE FUNCTIONS
15 int tc_parser( ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC );
16 int tc_check_type( unsigned char packetType );
17 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType );
18 int tc_check_sid( unsigned char sid );
19 int tc_check_length( unsigned char packetType, unsigned int length );
20 int tc_check_crc(ccsdsTelecommandPacket_t * TCPacket, unsigned int length , unsigned char *computed_CRC);
21
22 #endif // TC_ACCEPTANCE_H_INCLUDED
23
24
25
@@ -0,0 +1,66
1 #ifndef TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
3
4 #include <rtems.h>
5 #include <leon.h>
6
7 #include "tc_load_dump_parameters.h"
8 #include "tc_acceptance.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "wf_handler.h"
11 #include "fsw_processing.h"
12
13 #include "lfr_cpu_usage_report.h"
14
15 // MODE PARAMETERS
16 extern unsigned int maxCount;
17
18 //****
19 // ISR
20 rtems_isr commutation_isr1( rtems_vector_number vector );
21 rtems_isr commutation_isr2( rtems_vector_number vector );
22
23 void reset_transitionCoarseTime( void );
24 void set_transitionCoarseTime( unsigned int value );
25 unsigned int get_transitionCoarseTime( void );
26
27 //***********
28 // RTEMS TASK
29 rtems_task actn_task( rtems_task_argument unused );
30
31 //***********
32 // TC ACTIONS
33 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
34 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
35 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
36 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
37 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
38 int action_update_time( ccsdsTelecommandPacket_t *TC);
39
40 // mode transition
41 int check_mode_value( unsigned char requestedMode );
42 int check_mode_transition( unsigned char requestedMode );
43 int check_transition_date( unsigned int transitionCoarseTime );
44 int stop_current_mode( void );
45 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
46 int restart_science_tasks(unsigned char lfrRequestedMode );
47 int suspend_science_tasks();
48 void launch_waveform_picker(unsigned char mode , unsigned int transitionCoarseTime);
49 void launch_spectral_matrix( void );
50 void launch_spectral_matrix_simu( void );
51 void set_irq_on_new_ready_matrix(unsigned char value );
52 void set_run_matrix_spectral( unsigned char value );
53
54 // other functions
55 void updateLFRCurrentMode();
56 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
57 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
58 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
59
60 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
61 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
62
63 #endif // TC_HANDLER_H_INCLUDED
64
65
66
@@ -0,0 +1,51
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
3
4 #include <rtems.h>
5 #include <stdio.h>
6
7 #include "fsw_params.h"
8 #include "wf_handler.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "fsw_misc.h"
11
12 #define FLOAT_EQUAL_ZERO 0.001
13
14 extern unsigned short sequenceCounterParameterDump;
15
16 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
17 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
18 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
19 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
20 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
21 int action_dump_par(rtems_id queue_id );
22
23 // NORMAL
24 int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
25 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
26 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
27 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
28 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
29 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
30 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
31
32 // BURST
33 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
34 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
35
36 // SBM1
37 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
38 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
39
40 // SBM2
41 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
42 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
43
44 // TC_LFR_UPDATE_INFO
45 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
46 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
47 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
48
49 void init_parameter_dump( void );
50
51 #endif // TC_LOAD_DUMP_PARAMETERS_H
@@ -0,0 +1,23
1 #ifndef TM_BYTE_POSITIONS_H
2 #define TM_BYTE_POSITIONS_H
3
4 #define BYTE_POS_CP_LFR_MODE 11
5
6 // TC_LFR_LOAD_COMMON_PAR
7
8 // TC_LFR_LOAD_NORMAL_PAR
9 #define BYTE_POS_SY_LFR_N_SWF_L 0
10 #define BYTE_POS_SY_LFR_N_SWF_P 2
11 #define BYTE_POS_SY_LFR_N_ASM_P 4
12 #define BYTE_POS_SY_LFR_N_BP_P0 6
13 #define BYTE_POS_SY_LFR_N_BP_P1 7
14 #define BYTE_POS_SY_LFR_N_CWF_LONG_F3 8
15
16 // TC_LFR_LOAD_BURST_PAR
17
18 // TC_LFR_LOAD_SBM1_PAR
19
20 // TC_LFR_LOAD_SBM2_PAR
21
22
23 #endif // TM_BYTE_POSITIONS_H
@@ -0,0 +1,26
1 #ifndef TM_LFR_TC_EXE_H_INCLUDED
2 #define TM_LFR_TC_EXE_H_INCLUDED
3
4 #include <rtems.h>
5 #include <stdio.h>
6
7 #include "fsw_params.h"
8 #include "fsw_spacewire.h"
9
10 extern unsigned short sequenceCounters_TC_EXE[];
11
12 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
13 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
14 unsigned char byte_position, unsigned char rcv_value );
15 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
16 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
17 int send_tm_lfr_tc_exe_error(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
18 int send_tm_lfr_tc_exe_corrupted( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
19 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV, unsigned char destinationID );
20
21 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id );
22
23 #endif // TM_LFR_TC_EXE_H_INCLUDED
24
25
26
@@ -0,0 +1,92
1 #ifndef WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
3
4 #include <rtems.h>
5 #include <grspw.h>
6 #include <stdio.h>
7 #include <math.h>
8
9 #include "fsw_params.h"
10 #include "fsw_spacewire.h"
11 #include "fsw_misc.h"
12 #include "fsw_params_wf_handler.h"
13
14 #define pi 3.1415
15
16 extern int fdSPW;
17
18 //*****************
19 // waveform buffers
20 extern volatile int wf_snap_f0[ ];
21 extern volatile int wf_snap_f1[ ];
22 extern volatile int wf_snap_f2[ ];
23 extern volatile int wf_cont_f3[ ];
24 extern char wf_cont_f3_light[ ];
25
26 extern waveform_picker_regs_new_t *waveform_picker_regs;
27 extern time_management_regs_t *time_management_regs;
28 extern Packet_TM_LFR_HK_t housekeeping_packet;
29 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
30 extern struct param_local_str param_local;
31
32 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
33 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
34
35 extern rtems_id Task_id[20]; /* array of task ids */
36
37 extern unsigned char lfrCurrentMode;
38
39 //**********
40 // RTEMS_ISR
41 void reset_extractSWF( void );
42 rtems_isr waveforms_isr( rtems_vector_number vector );
43
44 //***********
45 // RTEMS_TASK
46 rtems_task wfrm_task( rtems_task_argument argument );
47 rtems_task cwf3_task( rtems_task_argument argument );
48 rtems_task cwf2_task( rtems_task_argument argument );
49 rtems_task cwf1_task( rtems_task_argument argument );
50 rtems_task swbd_task( rtems_task_argument argument );
51
52 //******************
53 // general functions
54 void WFP_init_rings( void );
55 void init_waveform_ring( ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] );
56 void WFP_reset_current_ring_nodes( void );
57 //
58 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF );
59 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
60 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
61 //
62 int send_waveform_SWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id );
63 int send_waveform_CWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
64 int send_waveform_CWF3( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
65 int send_waveform_CWF3_light( volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id );
66 //
67 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
68 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
69 void build_snapshot_from_ring(ring_node *ring_node_to_send , unsigned char frequencyChannel );
70 void build_acquisition_time( unsigned long long int * acquisitionTimeAslong, ring_node *current_ring_node );
71 //
72 rtems_id get_pkts_queue_id( void );
73
74 //**************
75 // wfp registers
76 // RESET
77 void reset_wfp_burst_enable( void );
78 void reset_wfp_status(void);
79 void reset_waveform_picker_regs( void );
80 // SET
81 void set_wfp_data_shaping(void);
82 void set_wfp_burst_enable_register( unsigned char mode );
83 void set_wfp_delta_snapshot( void );
84 void set_wfp_delta_f0_f0_2( void );
85 void set_wfp_delta_f1( void );
86 void set_wfp_delta_f2( void );
87
88 //*****************
89 // local parameters
90 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
91
92 #endif // WF_HANDLER_H_INCLUDED
@@ -0,0 +1,25
1 #include <drvmgr/ambapp_bus.h>
2
3 // GRSPW0 resources
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
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
6 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
7 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
8 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+12}}, // 12 is for the auxiliary header, when needed
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}},
10 KEY_EMPTY
11 };
12
13 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
14
15 struct drvmgr_bus_res grlib_drv_resources = {
16 .next = NULL,
17 .resource = {
18 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
19 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]},
20 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
21 RES_EMPTY /* Mark end of device resource array */
22 }
23 };
24
25
@@ -0,0 +1,75
1 /** Global variables of the LFR flight software.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * Among global variables, there are:
7 * - RTEMS names and id.
8 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
14 *
15 */
16
17 #include <rtems.h>
18 #include <grspw.h>
19
20 #include "ccsds_types.h"
21 #include "grlib_regs.h"
22 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
24
25 // RTEMS GLOBAL VARIABLES
26 rtems_name misc_name[5];
27 rtems_id misc_id[5];
28 rtems_name Task_name[20]; /* array of task names */
29 rtems_id Task_id[20]; /* array of task ids */
30 unsigned int maxCount;
31 int fdSPW = 0;
32 int fdUART = 0;
33 unsigned char lfrCurrentMode;
34
35 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
36 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
37 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
38 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
39 // F0 F1 F2 F3
40 volatile int wf_snap_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_snap_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_snap_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43 volatile int wf_cont_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
44 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK + TIME_OFFSET_IN_BYTES ] __attribute__((aligned(0x100)));
45
46 //***********************************
47 // SPECTRAL MATRICES GLOBAL VARIABLES
48
49 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
50 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
51 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
52 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
53
54 // APB CONFIGURATION REGISTERS
55 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
56 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
57 waveform_picker_regs_new_t *waveform_picker_regs = (waveform_picker_regs_new_t*) REGS_ADDR_WAVEFORM_PICKER;
58 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
59
60 // MODE PARAMETERS
61 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
62 struct param_local_str param_local;
63
64 // HK PACKETS
65 Packet_TM_LFR_HK_t housekeeping_packet;
66 // sequence counters are incremented by APID (PID + CAT) and destination ID
67 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
68 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
69 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
70 unsigned short sequenceCounterHK;
71 unsigned short sequenceCounterParameterDump;
72 spw_stats spacewire_stats;
73 spw_stats spacewire_stats_backup;
74
75
@@ -0,0 +1,489
1 /** This is the RTEMS initialization module.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
10 */
11
12 //*************************
13 // GPL reminder to be added
14 //*************************
15
16 #include <rtems.h>
17
18 /* configuration information */
19
20 #define CONFIGURE_INIT
21
22 #include <bsp.h> /* for device driver prototypes */
23
24 /* configuration information */
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
43
44 #include <rtems/confdefs.h>
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #endif
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 #endif
56 #endif
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 #include <drvmgr/drvmgr_confdefs.h>
59 #endif
60
61 #include "fsw_init.h"
62 #include "fsw_config.c"
63
64 rtems_id rtems_task_id_updt;
65 rtems_name rtems_task_name_updt;
66
67 rtems_task Init( rtems_task_argument ignored )
68 {
69 /** This is the RTEMS INIT taks, it the first task launched by the system.
70 *
71 * @param unused is the starting argument of the RTEMS task
72 *
73 * The INIT task create and run all other RTEMS tasks.
74 *
75 */
76
77 unsigned char *vhdlVersion;
78
79 reset_local_time();
80
81 rtems_cpu_usage_reset();
82
83 rtems_status_code status;
84 rtems_status_code status_spw;
85
86 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
87
88 // UART settings
89 send_console_outputs_on_apbuart_port();
90 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
91 enable_apbuart_transmitter();
92 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
93
94 PRINTF("\n\n\n\n\n")
95 PRINTF("*************************\n")
96 PRINTF("** timegen for LFR **\n")
97 PRINTF1("** %d.", SW_VERSION_N1)
98 PRINTF1("%d." , SW_VERSION_N2)
99 PRINTF1("%d." , SW_VERSION_N3)
100 PRINTF1("%d **\n", SW_VERSION_N4)
101
102 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
103 PRINTF("** VHDL **\n")
104 PRINTF1("** %d.", vhdlVersion[1])
105 PRINTF1("%d." , vhdlVersion[2])
106 PRINTF1("%d **\n", vhdlVersion[3])
107 PRINTF("*************************\n")
108 PRINTF("\n\n")
109
110 create_names(); // create all names
111
112 status = create_message_queues(); // create message queues
113 if (status != RTEMS_SUCCESSFUL)
114 {
115 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
116 }
117
118 status = create_all_tasks(); // create all tasks
119 if (status != RTEMS_SUCCESSFUL)
120 {
121 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
122 }
123
124 // **************************
125 // <SPACEWIRE INITIALIZATION>
126 grspw_timecode_callback = &timecode_irq_handler;
127
128 status_spw = spacewire_open_link(); // (1) open the link
129 if ( status_spw != RTEMS_SUCCESSFUL )
130 {
131 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
132 }
133
134 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
135 {
136 status_spw = spacewire_configure_link( fdSPW );
137 if ( status_spw != RTEMS_SUCCESSFUL )
138 {
139 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
140 }
141 }
142
143 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
144 {
145 status_spw = spacewire_start_link( fdSPW );
146 if ( status_spw != RTEMS_SUCCESSFUL )
147 {
148 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
149 }
150 }
151 // </SPACEWIRE INITIALIZATION>
152 // ***************************
153
154 status = start_all_tasks(); // start all tasks
155 if (status != RTEMS_SUCCESSFUL)
156 {
157 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
158 }
159
160 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
161 status = start_recv_send_tasks();
162 if ( status != RTEMS_SUCCESSFUL )
163 {
164 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
165 }
166
167 // suspend science tasks, they will be restarted later depending on the mode
168 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
169 if (status != RTEMS_SUCCESSFUL)
170 {
171 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
172 }
173
174 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
175 if ( status_spw != RTEMS_SUCCESSFUL )
176 {
177 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
178 if ( status != RTEMS_SUCCESSFUL ) {
179 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
180 }
181 }
182
183 //*********************************
184 // init GPIO for trigger generation
185 grgpio_regs->io_port_direction_register =
186 grgpio_regs->io_port_direction_register | 0x04; // [0000 0100], 0 = output disabled, 1 = output enabled
187 grgpio_regs->io_port_direction_register =
188 grgpio_regs->io_port_direction_register | 0x08; // [0000 1000], 0 = output disabled, 1 = output enabled
189
190 BOOT_PRINTF("delete INIT\n")
191
192 status = rtems_task_delete(RTEMS_SELF);
193
194 }
195
196 void init_local_mode_parameters( void )
197 {
198 /** This function initialize the param_local global variable with default values.
199 *
200 */
201
202 unsigned int i;
203
204 // LOCAL PARAMETERS
205
206 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
207 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
208 // BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
209
210 // init sequence counters
211
212 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
213 {
214 sequenceCounters_TC_EXE[i] = 0x00;
215 }
216 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
217 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
218 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
219 sequenceCounterParameterDump = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
220 }
221
222 void reset_local_time( void )
223 {
224 time_management_regs->ctrl = 0x02; // software reset, coarse time = 0x80000000
225 }
226
227 void create_names( void ) // create all names for tasks and queues
228 {
229 /** This function creates all RTEMS names used in the software for tasks and queues.
230 *
231 * @return RTEMS directive status codes:
232 * - RTEMS_SUCCESSFUL - successful completion
233 *
234 */
235
236 // task names
237 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
238 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
239 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
240 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
241 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
242 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
243 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
244
245 rtems_task_name_updt = rtems_build_name( 'U', 'P', 'D', 'T' );
246
247 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
248 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
249
250 }
251
252 int create_all_tasks( void ) // create all tasks which run in the software
253 {
254 /** This function creates all RTEMS tasks used in the software.
255 *
256 * @return RTEMS directive status codes:
257 * - RTEMS_SUCCESSFUL - task created successfully
258 * - RTEMS_INVALID_ADDRESS - id is NULL
259 * - RTEMS_INVALID_NAME - invalid task name
260 * - RTEMS_INVALID_PRIORITY - invalid task priority
261 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
262 * - RTEMS_TOO_MANY - too many tasks created
263 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
264 * - RTEMS_TOO_MANY - too many global objects
265 *
266 */
267
268 rtems_status_code status;
269
270 //**********
271 // SPACEWIRE
272 // RECV
273 status = rtems_task_create(
274 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
275 RTEMS_DEFAULT_MODES,
276 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
277 );
278 if (status == RTEMS_SUCCESSFUL) // SEND
279 {
280 status = rtems_task_create(
281 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
282 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
283 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND]
284 );
285 }
286 if (status == RTEMS_SUCCESSFUL) // WTDG
287 {
288 status = rtems_task_create(
289 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
290 RTEMS_DEFAULT_MODES,
291 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
292 );
293 }
294 if (status == RTEMS_SUCCESSFUL) // ACTN
295 {
296 status = rtems_task_create(
297 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
298 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
299 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
300 );
301 }
302 if (status == RTEMS_SUCCESSFUL) // SPIQ
303 {
304 status = rtems_task_create(
305 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
306 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
307 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
308 );
309 }
310
311 //*****
312 // MISC
313 if (status == RTEMS_SUCCESSFUL) // STAT
314 {
315 status = rtems_task_create(
316 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
317 RTEMS_DEFAULT_MODES,
318 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
319 );
320 }
321 if (status == RTEMS_SUCCESSFUL) // DUMB
322 {
323 status = rtems_task_create(
324 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
325 RTEMS_DEFAULT_MODES,
326 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
327 );
328 }
329 if (status == RTEMS_SUCCESSFUL) // UPDT
330 {
331 status = rtems_task_create(
332 rtems_task_name_updt, TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
333 RTEMS_DEFAULT_MODES,
334 RTEMS_DEFAULT_ATTRIBUTES, &rtems_task_id_updt
335 );
336 }
337
338 return status;
339 }
340
341 int start_recv_send_tasks( void )
342 {
343 rtems_status_code status;
344
345 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
346 if (status!=RTEMS_SUCCESSFUL) {
347 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
348 }
349
350 if (status == RTEMS_SUCCESSFUL) // SEND
351 {
352 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
353 if (status!=RTEMS_SUCCESSFUL) {
354 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
355 }
356 }
357
358 return status;
359 }
360
361 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
362 {
363 /** This function starts all RTEMS tasks used in the software.
364 *
365 * @return RTEMS directive status codes:
366 * - RTEMS_SUCCESSFUL - ask started successfully
367 * - RTEMS_INVALID_ADDRESS - invalid task entry point
368 * - RTEMS_INVALID_ID - invalid task id
369 * - RTEMS_INCORRECT_STATE - task not in the dormant state
370 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
371 *
372 */
373 // starts all the tasks fot eh flight software
374
375 rtems_status_code status;
376
377 //**********
378 // SPACEWIRE
379 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
380 if (status!=RTEMS_SUCCESSFUL) {
381 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
382 }
383
384 if (status == RTEMS_SUCCESSFUL) // WTDG
385 {
386 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
387 if (status!=RTEMS_SUCCESSFUL) {
388 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
389 }
390 }
391
392 if (status == RTEMS_SUCCESSFUL) // ACTN
393 {
394 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
395 if (status!=RTEMS_SUCCESSFUL) {
396 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
397 }
398 }
399
400 //*****
401 // MISC
402 if (status == RTEMS_SUCCESSFUL) // DUMB
403 {
404 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
405 if (status!=RTEMS_SUCCESSFUL) {
406 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
407 }
408 }
409 if (status == RTEMS_SUCCESSFUL) // STAT
410 {
411 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
412 if (status!=RTEMS_SUCCESSFUL) {
413 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
414 }
415 }
416 if (status == RTEMS_SUCCESSFUL) // UPDT
417 {
418 status = rtems_task_start( rtems_task_id_updt, updt_task, 1 );
419 if (status!=RTEMS_SUCCESSFUL) {
420 BOOT_PRINTF("in INIT *** Error starting TASK_UPDT\n")
421 }
422 }
423
424 return status;
425 }
426
427 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
428 {
429 rtems_status_code status_recv;
430 rtems_status_code status_send;
431
432 rtems_status_code ret;
433 rtems_id queue_id;
434
435 ret = LFR_SUCCESSFUL;
436
437 //****************************************
438 // create the queue for handling valid TCs
439 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
440 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
441 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
442 if ( status_recv != RTEMS_SUCCESSFUL ) {
443 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
444 }
445
446 //************************************************
447 // create the queue for handling TM packet sending
448 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
449 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
450 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
451 if ( status_send != RTEMS_SUCCESSFUL ) {
452 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
453 }
454
455 if ( status_recv != RTEMS_SUCCESSFUL )
456 {
457 ret = status_recv;
458 }
459 else if( status_send != RTEMS_SUCCESSFUL )
460 {
461 ret = status_send;
462 }
463
464 return ret;
465 }
466
467 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
468 {
469 rtems_status_code status;
470 rtems_name queue_name;
471
472 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
473
474 status = rtems_message_queue_ident( queue_name, 0, queue_id );
475
476 return status;
477 }
478
479 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
480 {
481 rtems_status_code status;
482 rtems_name queue_name;
483
484 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
485
486 status = rtems_message_queue_ident( queue_name, 0, queue_id );
487
488 return status;
489 }
@@ -0,0 +1,252
1 /** General usage functions and RTEMS tasks.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 */
7
8 #include "fsw_misc.h"
9
10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
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).
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.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
23 */
24
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
27
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29
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)
32 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
35
36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
37 }
38
39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
40 {
41 /** This function starts a GPTIMER timer.
42 *
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).
45 *
46 */
47
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
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
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 }
54
55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
56 {
57 /** This function stops a GPTIMER timer.
58 *
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).
61 *
62 */
63
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
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 }
68
69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
70 {
71 /** This function sets the clock divider of a GPTIMER timer.
72 *
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).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
77 */
78
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
81
82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 {
84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85
86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87
88 return 0;
89 }
90
91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 {
93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94
95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96
97 return 0;
98 }
99
100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 {
102 /** This function sets the scaler reload register of the apbuart module
103 *
104 * @param regs is the address of the apbuart registers in memory
105 * @param value is the value that will be stored in the scaler register
106 *
107 * The value shall be set by the software to get data on the serial interface.
108 *
109 */
110
111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112
113 apbuart_regs->scaler = value;
114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 }
116
117 //************
118 // RTEMS TASKS
119
120 rtems_task stat_task(rtems_task_argument argument)
121 {
122 int i;
123 int j;
124 i = 0;
125 j = 0;
126 BOOT_PRINTF("in STAT *** \n")
127 while(1){
128 rtems_task_wake_after(1000);
129 PRINTF1("%d\n", j)
130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 // #ifdef PRINT_TASK_STATISTICS
132 // rtems_cpu_usage_report();
133 // rtems_cpu_usage_reset();
134 // #endif
135 i = 0;
136 }
137 else i++;
138 j++;
139 }
140 }
141
142 rtems_task dumb_task( rtems_task_argument unused )
143 {
144 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
145 *
146 * @param unused is the starting argument of the RTEMS task
147 *
148 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
149 *
150 */
151
152 unsigned int i;
153 unsigned int intEventOut;
154 unsigned int coarse_time = 0;
155 unsigned int fine_time = 0;
156 rtems_event_set event_out;
157
158 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
159 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
160 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
161 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
162 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
163 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
164 "ERR HK", // RTEMS_EVENT_6
165 "ready for dump", // RTEMS_EVENT_7
166 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
167 "tick", // RTEMS_EVENT_9
168 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
169 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
170 };
171
172 BOOT_PRINTF("in DUMB *** \n")
173
174 while(1){
175 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
176 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
177 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
178 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
179 intEventOut = (unsigned int) event_out;
180 for ( i=0; i<32; i++)
181 {
182 if ( ((intEventOut >> i) & 0x0001) != 0)
183 {
184 coarse_time = time_management_regs->coarse_time;
185 fine_time = time_management_regs->fine_time;
186 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
187 if (i==8)
188 {
189 }
190 if (i==10)
191 {
192 }
193 }
194 }
195 }
196 }
197
198 //*****************************
199 // init housekeeping parameters
200
201 void increment_seq_counter( unsigned short *packetSequenceControl )
202 {
203 /** This function increment the sequence counter psased in argument.
204 *
205 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
206 *
207 */
208
209 unsigned short segmentation_grouping_flag;
210 unsigned short sequence_cnt;
211
212 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
213 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
214
215 if ( sequence_cnt < SEQ_CNT_MAX)
216 {
217 sequence_cnt = sequence_cnt + 1;
218 }
219 else
220 {
221 sequence_cnt = 0;
222 }
223
224 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
225 }
226
227 void getTime( unsigned char *time)
228 {
229 /** This function write the current local time in the time buffer passed in argument.
230 *
231 */
232
233 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
234 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
235 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
236 time[3] = (unsigned char) (time_management_regs->coarse_time);
237 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
238 time[5] = (unsigned char) (time_management_regs->fine_time);
239 }
240
241 unsigned long long int getTimeAsUnsignedLongLongInt( )
242 {
243 /** This function write the current local time in the time buffer passed in argument.
244 *
245 */
246 unsigned long long int time;
247
248 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
249 + time_management_regs->fine_time;
250
251 return time;
252 }
@@ -0,0 +1,46
1 /** Global variables used by the processing functions.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 */
7
8 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
9 // SX 12 coefficients
10 float K14_sx_re = 1;
11 float K14_sx_im = 1;
12 float K15_sx_re = 1;
13 float K15_sx_im = 1;
14 float K24_sx_re = 1;
15 float K24_sx_im = 1;
16 float K25_sx_re = 1;
17 float K25_sx_im = 1;
18 float K34_sx_re = 1;
19 float K34_sx_im = 1;
20 float K35_sx_re = 1;
21 float K35_sx_im = 1;
22 // NY 8 coefficients
23 float K24_ny_re = 1;
24 float K24_ny_im = 1;
25 float K25_ny_re = 1;
26 float K25_ny_im = 1;
27 float K34_ny_re = 1;
28 float K34_ny_im = 1;
29 float K35_ny_re = 1;
30 float K35_ny_im = 1;
31 // NZ 8 coefficients
32 float K24_nz_re = 1;
33 float K24_nz_im = 1;
34 float K25_nz_re = 1;
35 float K25_nz_im = 1;
36 float K34_nz_re = 1;
37 float K34_nz_im = 1;
38 float K35_nz_re = 1;
39 float K35_nz_im = 1;
40 // PE 4 coefficients
41 float K44_pe = 1;
42 float K55_pe = 1;
43 float K45_pe_re = 1;
44 float K45_pe_im = 1;
45
46 float Alpha_M = M_PI/4;
This diff has been collapsed as it changes many lines, (728 lines changed) Show them Hide them
@@ -0,0 +1,728
1 /** Functions related to the SpaceWire interface.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
12 */
13
14 #include "fsw_spacewire.h"
15
16 rtems_name semq_name;
17 rtems_id semq_id;
18
19 unsigned int localCoarseTime;
20
21 void resetLocalCoarseTime()
22 {
23 localCoarseTime = 0;
24 }
25
26 void setLocalCoarseTime( unsigned int value )
27 {
28 localCoarseTime = value;
29 }
30
31 unsigned int getLocalCoarseTime()
32 {
33 return localCoarseTime;
34 }
35
36 void incrementLocalCoarseTime()
37 {
38 localCoarseTime = localCoarseTime + 1;
39 }
40
41 //***********
42 // RTEMS TASK
43 rtems_task spiq_task(rtems_task_argument unused)
44 {
45 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
46 *
47 * @param unused is the starting argument of the RTEMS task
48 *
49 */
50
51 rtems_event_set event_out;
52 rtems_status_code status;
53 int linkStatus;
54
55 BOOT_PRINTF("in SPIQ *** \n")
56
57 while(true){
58 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
59 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
60
61 // [0] SUSPEND RECV AND SEND TASKS
62 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
63 if ( status != RTEMS_SUCCESSFUL ) {
64 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
65 }
66 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
67 if ( status != RTEMS_SUCCESSFUL ) {
68 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
69 }
70
71 // [1] CHECK THE LINK
72 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
73 if ( linkStatus != 5) {
74 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
75 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
76 }
77
78 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
79 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
80 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
81 {
82 spacewire_compute_stats_offsets();
83 status = spacewire_reset_link( );
84 }
85 else // [2.b] in run state, start the link
86 {
87 status = spacewire_stop_and_start_link( fdSPW ); // start the link
88 if ( status != RTEMS_SUCCESSFUL)
89 {
90 PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status)
91 }
92 }
93
94 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
95 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
96 {
97 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
98 if ( status != RTEMS_SUCCESSFUL ) {
99 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
100 }
101 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
102 if ( status != RTEMS_SUCCESSFUL ) {
103 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
104 }
105 }
106 else // [3.b] the link is not in run state, go in STANDBY mode
107 {
108 status = stop_current_mode();
109 if ( status != RTEMS_SUCCESSFUL ) {
110 PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status)
111 }
112 status = enter_mode( LFR_MODE_STANDBY, 0 );
113 if ( status != RTEMS_SUCCESSFUL ) {
114 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
115 }
116 // wake the WTDG task up to wait for the link recovery
117 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
118 status = rtems_task_suspend( RTEMS_SELF );
119 }
120 }
121 }
122
123 rtems_task recv_task( rtems_task_argument unused )
124 {
125 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
126 *
127 * @param unused is the starting argument of the RTEMS task
128 *
129 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
130 * 1. It reads the incoming data.
131 * 2. Launches the acceptance procedure.
132 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
133 *
134 */
135
136 int len;
137 ccsdsTelecommandPacket_t currentTC;
138 unsigned char computed_CRC[ 2 ];
139 unsigned char currentTC_LEN_RCV[ 2 ];
140 unsigned char destinationID;
141 unsigned int estimatedPacketLength;
142 unsigned int parserCode;
143 rtems_status_code status;
144 rtems_id queue_recv_id;
145 rtems_id queue_send_id;
146
147 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
148
149 status = get_message_queue_id_recv( &queue_recv_id );
150 if (status != RTEMS_SUCCESSFUL)
151 {
152 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
153 }
154
155 status = get_message_queue_id_send( &queue_send_id );
156 if (status != RTEMS_SUCCESSFUL)
157 {
158 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
159 }
160
161 BOOT_PRINTF("in RECV *** \n")
162
163 while(1)
164 {
165 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
166 if (len == -1){ // error during the read call
167 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
168 }
169 else {
170 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
171 PRINTF("in RECV *** packet lenght too short\n")
172 }
173 else {
174 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
175 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
176 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
177 // CHECK THE TC
178 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
179 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
180 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
181 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
182 || (parserCode == WRONG_SRC_ID) )
183 { // send TM_LFR_TC_EXE_CORRUPTED
184 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
185 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
186 &&
187 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
188 )
189 {
190 if ( parserCode == WRONG_SRC_ID )
191 {
192 destinationID = SID_TC_GROUND;
193 }
194 else
195 {
196 destinationID = currentTC.sourceID;
197 }
198 }
199 }
200 else
201 { // send valid TC to the action launcher
202 status = rtems_message_queue_send( queue_recv_id, &currentTC,
203 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
204 }
205 }
206 }
207 }
208 }
209
210 rtems_task send_task( rtems_task_argument argument)
211 {
212 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
213 *
214 * @param unused is the starting argument of the RTEMS task
215 *
216 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
217 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
218 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
219 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
220 * data it contains.
221 *
222 */
223
224 rtems_status_code status; // RTEMS status code
225 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
226 spw_ioctl_pkt_send *spw_ioctl_send;
227 size_t size; // size of the incoming TC packet
228 u_int32_t count;
229 rtems_id queue_id;
230
231 status = get_message_queue_id_send( &queue_id );
232 if (status != RTEMS_SUCCESSFUL)
233 {
234 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
235 }
236
237 BOOT_PRINTF("in SEND *** \n")
238
239 while(1)
240 {
241 status = rtems_message_queue_receive( queue_id, incomingData, &size,
242 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
243
244 if (status!=RTEMS_SUCCESSFUL)
245 {
246 PRINTF1("in SEND *** (1) ERR = %d\n", status)
247 }
248 else
249 {
250 if ((incomingData[0] == CCSDS_DESTINATION_ID) || (incomingData[0] == (char) 0xfe)) // the incoming message is a ccsds packet
251 {
252 status = write( fdSPW, incomingData, size );
253 if (status == -1){
254 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
255 }
256 }
257 else // the incoming message is a spw_ioctl_pkt_send structure
258 {
259 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
260 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
261 if (status == -1){
262 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
263 }
264 }
265 }
266
267 status = rtems_message_queue_get_number_pending( queue_id, &count );
268 if (status != RTEMS_SUCCESSFUL)
269 {
270 PRINTF1("in SEND *** (3) ERR = %d\n", status)
271 }
272 else
273 {
274 if (count > maxCount)
275 {
276 maxCount = count;
277 }
278 }
279 }
280 }
281
282 rtems_task wtdg_task( rtems_task_argument argument )
283 {
284 rtems_event_set event_out;
285 rtems_status_code status;
286 int linkStatus;
287
288 BOOT_PRINTF("in WTDG ***\n")
289
290 while(1)
291 {
292 // wait for an RTEMS_EVENT
293 rtems_event_receive( RTEMS_EVENT_0,
294 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
295 PRINTF("in WTDG *** wait for the link\n")
296 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
297 while( linkStatus != 5) // wait for the link
298 {
299 rtems_task_wake_after( 10 );
300 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
301 }
302
303 status = spacewire_stop_and_start_link( fdSPW );
304
305 if (status != RTEMS_SUCCESSFUL)
306 {
307 PRINTF1("in WTDG *** ERR link not started %d\n", status)
308 }
309 else
310 {
311 PRINTF("in WTDG *** OK link started\n")
312 }
313
314 // restart the SPIQ task
315 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
316 if ( status != RTEMS_SUCCESSFUL ) {
317 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
318 }
319
320 // restart RECV and SEND
321 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
322 if ( status != RTEMS_SUCCESSFUL ) {
323 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
324 }
325 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
326 if ( status != RTEMS_SUCCESSFUL ) {
327 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
328 }
329 }
330 }
331
332 //****************
333 // OTHER FUNCTIONS
334 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
335 {
336 /** This function opens the SpaceWire link.
337 *
338 * @return a valid file descriptor in case of success, -1 in case of a failure
339 *
340 */
341 rtems_status_code status;
342
343 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
344 if ( fdSPW < 0 ) {
345 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
346 }
347 else
348 {
349 status = RTEMS_SUCCESSFUL;
350 }
351
352 return status;
353 }
354
355 int spacewire_start_link( int fd )
356 {
357 rtems_status_code status;
358
359 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
360 // -1 default hardcoded driver timeout
361
362 return status;
363 }
364
365 int spacewire_stop_and_start_link( int fd )
366 {
367 rtems_status_code status;
368
369 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
370 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
371 // -1 default hardcoded driver timeout
372
373 return status;
374 }
375
376 int spacewire_configure_link( int fd )
377 {
378 /** This function configures the SpaceWire link.
379 *
380 * @return GR-RTEMS-DRIVER directive status codes:
381 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
382 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
383 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
384 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
385 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
386 * - 5 EIO - Error when writing to grswp hardware registers.
387 * - 2 ENOENT - No such file or directory
388 */
389
390 rtems_status_code status;
391
392 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
393 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
394
395 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
396 if (status!=RTEMS_SUCCESSFUL) {
397 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
398 }
399 //
400 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
401 if (status!=RTEMS_SUCCESSFUL) {
402 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
403 }
404 //
405 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
406 if (status!=RTEMS_SUCCESSFUL) {
407 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
408 }
409 //
410 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
411 if (status!=RTEMS_SUCCESSFUL) {
412 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
413 }
414 //
415 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
416 if (status!=RTEMS_SUCCESSFUL) {
417 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
418 }
419 //
420 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
421 if (status!=RTEMS_SUCCESSFUL) {
422 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
423 }
424 //
425 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
426 if (status!=RTEMS_SUCCESSFUL) {
427 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
428 }
429
430 return status;
431 }
432
433 int spacewire_reset_link( void )
434 {
435 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
436 *
437 * @return RTEMS directive status code:
438 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
439 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
440 *
441 */
442
443 rtems_status_code status_spw;
444 int i;
445
446 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
447 {
448 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
449
450 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
451
452 status_spw = spacewire_stop_and_start_link( fdSPW );
453 if ( status_spw != RTEMS_SUCCESSFUL )
454 {
455 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
456 }
457
458 if ( status_spw == RTEMS_SUCCESSFUL)
459 {
460 break;
461 }
462 }
463
464 return status_spw;
465 }
466
467 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
468 {
469 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
470 *
471 * @param val is the value, 0 or 1, used to set the value of the NP bit.
472 * @param regAddr is the address of the GRSPW control register.
473 *
474 * NP is the bit 20 of the GRSPW control register.
475 *
476 */
477
478 unsigned int *spwptr = (unsigned int*) regAddr;
479
480 if (val == 1) {
481 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
482 }
483 if (val== 0) {
484 *spwptr = *spwptr & 0xffdfffff;
485 }
486 }
487
488 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
489 {
490 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
491 *
492 * @param val is the value, 0 or 1, used to set the value of the RE bit.
493 * @param regAddr is the address of the GRSPW control register.
494 *
495 * RE is the bit 16 of the GRSPW control register.
496 *
497 */
498
499 unsigned int *spwptr = (unsigned int*) regAddr;
500
501 if (val == 1)
502 {
503 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
504 }
505 if (val== 0)
506 {
507 *spwptr = *spwptr & 0xfffdffff;
508 }
509 }
510
511 void spacewire_compute_stats_offsets( void )
512 {
513 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
514 *
515 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
516 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
517 * during the open systel call).
518 *
519 */
520
521 spw_stats spacewire_stats_grspw;
522 rtems_status_code status;
523
524 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
525
526 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
527 + spacewire_stats.packets_received;
528 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
529 + spacewire_stats.packets_sent;
530 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
531 + spacewire_stats.parity_err;
532 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
533 + spacewire_stats.disconnect_err;
534 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
535 + spacewire_stats.escape_err;
536 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
537 + spacewire_stats.credit_err;
538 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
539 + spacewire_stats.write_sync_err;
540 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
541 + spacewire_stats.rx_rmap_header_crc_err;
542 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
543 + spacewire_stats.rx_rmap_data_crc_err;
544 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
545 + spacewire_stats.early_ep;
546 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
547 + spacewire_stats.invalid_address;
548 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
549 + spacewire_stats.rx_eep_err;
550 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
551 + spacewire_stats.rx_truncated;
552 }
553
554 void spacewire_update_statistics( void )
555 {
556 rtems_status_code status;
557 spw_stats spacewire_stats_grspw;
558
559 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
560
561 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
562 + spacewire_stats_grspw.packets_received;
563 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
564 + spacewire_stats_grspw.packets_sent;
565 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
566 + spacewire_stats_grspw.parity_err;
567 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
568 + spacewire_stats_grspw.disconnect_err;
569 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
570 + spacewire_stats_grspw.escape_err;
571 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
572 + spacewire_stats_grspw.credit_err;
573 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
574 + spacewire_stats_grspw.write_sync_err;
575 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
576 + spacewire_stats_grspw.rx_rmap_header_crc_err;
577 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
578 + spacewire_stats_grspw.rx_rmap_data_crc_err;
579 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
580 + spacewire_stats_grspw.early_ep;
581 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
582 + spacewire_stats_grspw.invalid_address;
583 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
584 + spacewire_stats_grspw.rx_eep_err;
585 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
586 + spacewire_stats_grspw.rx_truncated;
587 //spacewire_stats.tx_link_err;
588
589 //****************************
590 // DPU_SPACEWIRE_IF_STATISTICS
591 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
592 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
593 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
594 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
595 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
596 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
597
598 //******************************************
599 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
600 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
601 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
602 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
603 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
604 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
605
606 //*********************************************
607 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
608 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
609 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
610 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
611 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
612 }
613
614 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
615 {
616 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
617
618 incrementLocalCoarseTime();
619
620 //*******
621 // GPIO 2
622 if ( get_transitionCoarseTime() == getLocalCoarseTime() )
623 {
624 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x04; // [0000 0100]
625 }
626 else
627 {
628 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xfb; // [1111 1011]
629 }
630
631 //*******
632 // GPIO 3
633 if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 )
634 {
635 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; // [1111 0111]
636 }
637 else
638 {
639 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; // [0000 1000]
640 }
641
642 rtems_event_send( rtems_task_id_updt, RTEMS_EVENT_0);
643 }
644
645 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
646 {
647 int linkStatus;
648 rtems_status_code status;
649
650 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
651
652 if ( linkStatus == 5) {
653 PRINTF("in spacewire_reset_link *** link is running\n")
654 status = RTEMS_SUCCESSFUL;
655 }
656 }
657
658 rtems_task updt_task(rtems_task_argument unused)
659 {
660
661 rtems_event_set event_out;
662 rtems_status_code status;
663 rtems_id queue_id;
664 unsigned int coarseTimeToSend;
665
666 Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t update_time_packet;
667
668 resetLocalCoarseTime();
669 reset_transitionCoarseTime();
670
671 status = get_message_queue_id_send( &queue_id );
672 if (status != RTEMS_SUCCESSFUL)
673 {
674 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
675 }
676
677 update_time_packet.targetLogicalAddress = 0xfe;
678 update_time_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
679 update_time_packet.reserved = DEFAULT_RESERVED;
680 update_time_packet.userApplication = CCSDS_USER_APP;
681 update_time_packet.packetID[0] = (unsigned char) (TC_LFR_PACKET_ID >> 8);
682 update_time_packet.packetID[1] = (unsigned char) (TC_LFR_PACKET_ID );
683 update_time_packet.packetSequenceControl[0] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL >> 8);
684 update_time_packet.packetSequenceControl[1] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL );
685 update_time_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME >> 8);
686 update_time_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME );
687
688 update_time_packet.ccsdsSecHeaderFlag_pusVersion_ack = 0x19;
689 update_time_packet.serviceType = TC_TYPE_LFR_UPDATE_TIME;
690 update_time_packet.serviceSubType = TC_SUBTYPE_UPDATE_TIME;
691 update_time_packet.sourceID = SID_TC_RPW_INTERNAL;
692
693 BOOT_PRINTF("in UPDT *** \n")
694
695 while(true){
696 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
697
698 coarseTimeToSend = getLocalCoarseTime() + 1;
699 updateTimePacket( coarseTimeToSend, &update_time_packet);
700 printf("UPDT will send %x as coarse time in 700 ms\n", coarseTimeToSend);
701
702 rtems_task_wake_after( 70 ); // 70 => 700 ms
703
704 status = rtems_message_queue_urgent( queue_id, &update_time_packet,
705 PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES
706 + 0); // 1 is for the star dundee extra byte
707 if (status != RTEMS_SUCCESSFUL) {
708 PRINTF1("in HOUS *** ERR send: %d\n", status)
709 }
710 }
711 }
712
713 void updateTimePacket(unsigned int time, Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t *packet)
714 {
715 unsigned char crcAsTwoBytes[2];
716
717 packet->cp_rpw_time[0] = (unsigned char) (time >> 24);
718 packet->cp_rpw_time[1] = (unsigned char) (time >> 16);
719 packet->cp_rpw_time[2] = (unsigned char) (time >> 8);
720 packet->cp_rpw_time[3] = (unsigned char) (time);
721 packet->cp_rpw_time[4] = 0; // fine time MSB
722 packet->cp_rpw_time[5] = 0; // fine time LSB
723
724 GetCRCAsTwoBytes((unsigned char*) &packet->packetID, crcAsTwoBytes,
725 PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET - 2);
726 packet->crc[0] = crcAsTwoBytes[0];
727 packet->crc[1] = crcAsTwoBytes[1];
728 }
@@ -0,0 +1,115
1 /*
2 * CPU Usage Reporter
3 *
4 * COPYRIGHT (c) 1989-2009
5 * On-Line Applications Research Corporation (OAR).
6 *
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
9 * http://www.rtems.com/license/LICENSE.
10 *
11 * $Id$
12 */
13
14 #include "lfr_cpu_usage_report.h"
15
16 unsigned char lfr_rtems_cpu_usage_report( void )
17 {
18 uint32_t api_index;
19 Thread_Control *the_thread;
20 Objects_Information *information;
21 uint32_t ival, fval;
22 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
23 Timestamp_Control uptime;
24 Timestamp_Control total;
25 Timestamp_Control ran;
26 #else
27 uint32_t total_units = 0;
28 #endif
29
30 unsigned char cpu_load;
31 cpu_load = 0;
32
33 /*
34 * When not using nanosecond CPU usage resolution, we have to count
35 * the number of "ticks" we gave credit for to give the user a rough
36 * guideline as to what each number means proportionally.
37 */
38 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
39 _TOD_Get_uptime( &uptime );
40 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
41 #else
42 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
43 if ( !_Objects_Information_table[ api_index ] ) { }
44 else
45 {
46 information = _Objects_Information_table[ api_index ][ 1 ];
47 if ( information != NULL )
48 {
49 for ( i=1 ; i <= information->maximum ; i++ ) {
50 the_thread = (Thread_Control *)information->local_table[ i ];
51
52 if ( the_thread != NULL )
53 total_units += the_thread->cpu_time_used;
54 }
55 }
56 }
57 }
58 #endif
59
60 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
61 {
62 if ( !_Objects_Information_table[ api_index ] ) { }
63 else
64 {
65 information = _Objects_Information_table[ api_index ][ 1 ];
66 if ( information != NULL )
67 {
68 the_thread = (Thread_Control *)information->local_table[ 1 ];
69
70 if ( the_thread == NULL ) { }
71 else
72 {
73 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
74 /*
75 * If this is the currently executing thread, account for time
76 * since the last context switch.
77 */
78 ran = the_thread->cpu_time_used;
79 if ( _Thread_Executing->Object.id == the_thread->Object.id )
80 {
81 Timestamp_Control used;
82 _Timestamp_Subtract(
83 &_Thread_Time_of_last_context_switch, &uptime, &used
84 );
85 _Timestamp_Add_to( &ran, &used );
86 }
87 _Timestamp_Divide( &ran, &total, &ival, &fval );
88
89 #else
90 if (total_units != 0)
91 {
92 uint64_t ival_64;
93
94 ival_64 = the_thread->cpu_time_used;
95 ival_64 *= 100000;
96 ival = ival_64 / total_units;
97 }
98 else
99 {
100 ival = 0;
101 }
102
103 fval = ival % 1000;
104 ival /= 1000;
105 #endif
106 }
107 }
108 }
109 }
110 cpu_load = (unsigned char) (100 - ival);
111
112 return cpu_load;
113 }
114
115
@@ -0,0 +1,380
1 /** Functions related to data processing.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
8 */
9
10 #include "avf0_prc0.h"
11 #include "fsw_processing.h"
12
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14
15 //***
16 // F0
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0[ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19
20 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
21 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
22 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
23 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
24 //unsigned char bp1_norm_f0 [ TOTAL_SIZE_BP1_NORM_F0 ];
25 //unsigned char bp1_sbm_f0 [ TOTAL_SIZE_BP1_SBM_F0 ];
26
27 //************
28 // RTEMS TASKS
29
30 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
31 {
32 int i;
33
34 rtems_event_set event_out;
35 rtems_status_code status;
36 rtems_id queue_id_prc0;
37 asm_msg msgForMATR;
38 ring_node_sm *ring_node_tab[8];
39 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
40 ring_node_asm *current_ring_node_asm_norm_f0;
41
42 unsigned int nb_norm_bp1;
43 unsigned int nb_norm_bp2;
44 unsigned int nb_norm_asm;
45 unsigned int nb_sbm_bp1;
46 unsigned int nb_sbm_bp2;
47
48 nb_norm_bp1 = 0;
49 nb_norm_bp2 = 0;
50 nb_norm_asm = 0;
51 nb_sbm_bp1 = 0;
52 nb_sbm_bp2 = 0;
53
54 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
55 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
56 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
57 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
58 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
59
60 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
61
62 status = get_message_queue_id_prc0( &queue_id_prc0 );
63 if (status != RTEMS_SUCCESSFUL)
64 {
65 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
66 }
67
68 while(1){
69 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
70
71 //****************************************
72 // initialize the mesage for the MATR task
73 msgForMATR.norm = current_ring_node_asm_norm_f0;
74 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f0;
75 msgForMATR.event = 0x00; // this composite event will be sent to the MATR task
76 msgForMATR.coarseTime = ring_node_for_averaging_sm_f0->coarseTime;
77 msgForMATR.fineTime = ring_node_for_averaging_sm_f0->fineTime;
78 //
79 //****************************************
80
81 ring_node_tab[NB_SM_BEFORE_AVF0-1] = ring_node_for_averaging_sm_f0;
82 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
83 {
84 ring_node_for_averaging_sm_f0 = ring_node_for_averaging_sm_f0->previous;
85 ring_node_tab[NB_SM_BEFORE_AVF0-i] = ring_node_for_averaging_sm_f0;
86 }
87
88 // compute the average and store it in the averaged_sm_f1 buffer
89 SM_average( current_ring_node_asm_norm_f0->matrix,
90 current_ring_node_asm_burst_sbm_f0->matrix,
91 ring_node_tab,
92 nb_norm_bp1, nb_sbm_bp1 );
93
94 // update nb_average
95 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
96 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
97 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
98 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
99 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
100
101 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
102 {
103 nb_sbm_bp1 = 0;
104 // set another ring for the ASM storage
105 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
106 if ( lfrCurrentMode == LFR_MODE_BURST )
107 {
108 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F0;
109 }
110 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
111 {
112 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F0;
113 }
114 }
115
116 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
117 {
118 nb_sbm_bp2 = 0;
119 if ( lfrCurrentMode == LFR_MODE_BURST )
120 {
121 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F0;
122 }
123 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
124 {
125 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F0;
126 }
127 }
128
129 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
130 {
131 nb_norm_bp1 = 0;
132 // set another ring for the ASM storage
133 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
134 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
135 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
136 {
137 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F0;
138 }
139 }
140
141 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
142 {
143 nb_norm_bp2 = 0;
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 {
147 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F0;
148 }
149 }
150
151 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
152 {
153 nb_norm_asm = 0;
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 {
157 // PRINTF1("%lld\n", localTime)
158 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F0;
159 }
160 }
161
162 //*************************
163 // send the message to MATR
164 if (msgForMATR.event != 0x00)
165 {
166 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0);
167 }
168
169 if (status != RTEMS_SUCCESSFUL) {
170 printf("in AVF0 *** Error sending message to MATR, code %d\n", status);
171 }
172 }
173 }
174
175 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
176 {
177 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
178 size_t size; // size of the incoming TC packet
179 asm_msg *incomingMsg;
180 //
181 unsigned char sid;
182 spw_ioctl_pkt_send spw_ioctl_send_ASM;
183 rtems_status_code status;
184 rtems_id queue_id;
185 rtems_id queue_id_q_p0;
186 Header_TM_LFR_SCIENCE_ASM_t headerASM;
187 bp_packet_with_spare packet_norm_bp1_f0;
188 bp_packet packet_norm_bp2_f0;
189 bp_packet packet_sbm_bp1_f0;
190 bp_packet packet_sbm_bp2_f0;
191
192 unsigned long long int localTime;
193
194 ASM_init_header( &headerASM );
195
196 //*************
197 // NORM headers
198 BP_init_header_with_spare( &packet_norm_bp1_f0.header,
199 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
200 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
201 BP_init_header( &packet_norm_bp2_f0.header,
202 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
203 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
204
205 //****************************
206 // BURST SBM1 and SBM2 headers
207 if ( lfrRequestedMode == LFR_MODE_BURST )
208 {
209 BP_init_header( &packet_sbm_bp1_f0.header,
210 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
211 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
212 BP_init_header( &packet_sbm_bp2_f0.header,
213 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
214 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
215 }
216 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
217 {
218 BP_init_header( &packet_sbm_bp1_f0.header,
219 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
220 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
221 BP_init_header( &packet_sbm_bp2_f0.header,
222 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
223 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
224 }
225 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
226 {
227 BP_init_header( &packet_sbm_bp1_f0.header,
228 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
230 BP_init_header( &packet_sbm_bp2_f0.header,
231 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
233 }
234 else
235 {
236 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
237 }
238
239 status = get_message_queue_id_send( &queue_id );
240 if (status != RTEMS_SUCCESSFUL)
241 {
242 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
243 }
244 status = get_message_queue_id_prc0( &queue_id_q_p0);
245 if (status != RTEMS_SUCCESSFUL)
246 {
247 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
248 }
249
250 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
251
252 while(1){
253 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
254 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
255
256 incomingMsg = (asm_msg*) incomingData;
257
258 localTime = getTimeAsUnsignedLongLongInt( );
259
260 //****************
261 //****************
262 // BURST SBM1 SBM2
263 //****************
264 //****************
265 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
266 {
267 sid = getSID( incomingMsg->event );
268 // 1) compress the matrix for Basic Parameters calculation
269 ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f0,
270 nb_sm_before_f0.burst_sbm_bp1,
271 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
272 ASM_F0_INDICE_START);
273 // 2) compute the BP1 set
274 // BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, bp1_sbm_f0 );
275 // 3) send the BP1 set
276 set_time( packet_sbm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
277 set_time( packet_sbm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
278 BP_send( (char *) &packet_sbm_bp1_f0, queue_id,
279 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
280 sid);
281 // 4) compute the BP2 set if needed
282 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
283 {
284 // 1) compute the BP2 set
285
286 // 2) send the BP2 set
287 set_time( packet_sbm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
288 set_time( packet_sbm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
289 BP_send( (char *) &packet_sbm_bp2_f0, queue_id,
290 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
291 sid);
292 }
293 }
294
295 //*****
296 //*****
297 // NORM
298 //*****
299 //*****
300 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
301 {
302 // 1) compress the matrix for Basic Parameters calculation
303 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f0,
304 nb_sm_before_f0.norm_bp1,
305 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
306 ASM_F0_INDICE_START );
307 // 2) compute the BP1 set
308 // BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, bp1_norm_f0 );
309 // 3) send the BP1 set
310 set_time( packet_norm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
311 set_time( packet_norm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
312 BP_send( (char *) &packet_norm_bp1_f0, queue_id,
313 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
314 SID_NORM_BP1_F0 );
315 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
316 {
317 // 1) compute the BP2 set using the same ASM as the one used for BP1
318
319 // 2) send the BP2 set
320 set_time( packet_norm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime );
321 set_time( packet_norm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
322 BP_send( (char *) &packet_norm_bp2_f0, queue_id,
323 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
324 SID_NORM_BP2_F0);
325 }
326 }
327
328 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
329 {
330 // 1) reorganize the ASM and divide
331 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
332 asm_f0_reorganized,
333 nb_sm_before_f0.norm_bp1 );
334 // 2) convert the float array in a char array
335 ASM_convert( asm_f0_reorganized, asm_f0_char);
336 // 3) send the spectral matrix packets
337 set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime );
338 set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
339 ASM_send( &headerASM, asm_f0_char, SID_NORM_ASM_F0, &spw_ioctl_send_ASM, queue_id);
340 }
341
342 }
343 }
344
345 //**********
346 // FUNCTIONS
347
348 void reset_nb_sm_f0( unsigned char lfrMode )
349 {
350 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
351 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
352 nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96;
353 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
354 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
355 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
356 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
357 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
358 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
359
360 if (lfrMode == LFR_MODE_SBM1)
361 {
362 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
363 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
364 }
365 else if (lfrMode == LFR_MODE_SBM2)
366 {
367 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
368 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
369 }
370 else if (lfrMode == LFR_MODE_BURST)
371 {
372 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
373 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
374 }
375 else
376 {
377 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
378 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
379 }
380 }
@@ -0,0 +1,360
1 /** Functions related to data processing.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
8 */
9
10 #include "avf1_prc1.h"
11
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
13
14 //***
15 // F1
16 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
17 ring_node_asm asm_ring_burst_sbm_f1[ NB_RING_NODES_ASM_BURST_SBM_F1 ];
18
19 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
20 char asm_f1_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
21 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
22 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
23
24 //************
25 // RTEMS TASKS
26
27 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
28 {
29 int i;
30
31 rtems_event_set event_out;
32 rtems_status_code status;
33 rtems_id queue_id_prc1;
34 asm_msg msgForMATR;
35 ring_node_sm *ring_node_tab[8];
36 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
37 ring_node_asm *current_ring_node_asm_norm_f1;
38
39 unsigned int nb_norm_bp1;
40 unsigned int nb_norm_bp2;
41 unsigned int nb_norm_asm;
42 unsigned int nb_sbm_bp1;
43 unsigned int nb_sbm_bp2;
44
45 nb_norm_bp1 = 0;
46 nb_norm_bp2 = 0;
47 nb_norm_asm = 0;
48 nb_sbm_bp1 = 0;
49 nb_sbm_bp2 = 0;
50
51 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
52 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
53 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
54 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
55 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
56
57 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
58
59 status = get_message_queue_id_prc1( &queue_id_prc1 );
60 if (status != RTEMS_SUCCESSFUL)
61 {
62 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
63 }
64
65 while(1){
66 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
67
68 //****************************************
69 // initialize the mesage for the MATR task
70 msgForMATR.event = 0x00; // this composite event will be sent to the PRC1 task
71 msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f1;
72 msgForMATR.norm = current_ring_node_asm_norm_f1;
73 msgForMATR.coarseTime = ring_node_for_averaging_sm_f1->coarseTime;
74 msgForMATR.fineTime = ring_node_for_averaging_sm_f1->fineTime;
75 //
76 //****************************************
77
78 ring_node_tab[NB_SM_BEFORE_AVF1-1] = ring_node_for_averaging_sm_f1;
79 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
80 {
81 ring_node_for_averaging_sm_f1 = ring_node_for_averaging_sm_f1->previous;
82 ring_node_tab[NB_SM_BEFORE_AVF1-i] = ring_node_for_averaging_sm_f1;
83 }
84
85 // compute the average and store it in the averaged_sm_f1 buffer
86 SM_average( current_ring_node_asm_norm_f1->matrix,
87 current_ring_node_asm_burst_sbm_f1->matrix,
88 ring_node_tab,
89 nb_norm_bp1, nb_sbm_bp1 );
90
91 // update nb_average
92 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
93 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
94 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
95 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
96 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
97
98 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
99 {
100 nb_sbm_bp1 = 0;
101 // set another ring for the ASM storage
102 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
103 if ( lfrCurrentMode == LFR_MODE_BURST )
104 {
105 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F1;
106 }
107 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
108 {
109 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F1;
110 }
111 }
112
113 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
114 {
115 nb_sbm_bp2 = 0;
116 if ( lfrCurrentMode == LFR_MODE_BURST )
117 {
118 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F1;
119 }
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 {
122 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F1;
123 }
124 }
125
126 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
127 {
128 nb_norm_bp1 = 0;
129 // set another ring for the ASM storage
130 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
131 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
132 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 {
134 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F1;
135 }
136 }
137
138 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
139 {
140 nb_norm_bp2 = 0;
141 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
142 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
143 {
144 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F1;
145 }
146 }
147
148 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
149 {
150 nb_norm_asm = 0;
151 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
152 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
153 {
154 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F1;
155 }
156 }
157
158 //*************************
159 // send the message to MATR
160 if (msgForMATR.event != 0x00)
161 {
162 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC1);
163 }
164
165 if (status != RTEMS_SUCCESSFUL) {
166 printf("in AVF1 *** Error sending message to PRC1, code %d\n", status);
167 }
168 }
169 }
170
171 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
172 {
173 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
174 size_t size; // size of the incoming TC packet
175 asm_msg *incomingMsg;
176 //
177 unsigned char sid;
178 spw_ioctl_pkt_send spw_ioctl_send_ASM;
179 rtems_status_code status;
180 rtems_id queue_id_send;
181 rtems_id queue_id_q_p1;
182 Header_TM_LFR_SCIENCE_ASM_t headerASM;
183 bp_packet_with_spare packet_norm_bp1;
184 bp_packet packet_norm_bp2;
185 bp_packet packet_sbm_bp1;
186 bp_packet packet_sbm_bp2;
187
188 unsigned long long int localTime;
189
190 ASM_init_header( &headerASM );
191
192 //*************
193 // NORM headers
194 BP_init_header_with_spare( &packet_norm_bp1.header,
195 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
196 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
197 BP_init_header( &packet_norm_bp2.header,
198 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
199 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
200
201 //***********************
202 // BURST and SBM2 headers
203 if ( lfrRequestedMode == LFR_MODE_BURST )
204 {
205 BP_init_header( &packet_sbm_bp1.header,
206 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
207 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
208 BP_init_header( &packet_sbm_bp2.header,
209 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
210 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
211 }
212 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
213 {
214 BP_init_header( &packet_sbm_bp1.header,
215 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
216 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
217 BP_init_header( &packet_sbm_bp2.header,
218 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
219 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
220 }
221 else
222 {
223 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
224 }
225
226 status = get_message_queue_id_send( &queue_id_send );
227 if (status != RTEMS_SUCCESSFUL)
228 {
229 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
230 }
231 status = get_message_queue_id_prc1( &queue_id_q_p1);
232 if (status != RTEMS_SUCCESSFUL)
233 {
234 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
235 }
236
237 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
238
239 while(1){
240 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
241 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
242
243 incomingMsg = (asm_msg*) incomingData;
244
245 localTime = getTimeAsUnsignedLongLongInt( );
246 //***********
247 //***********
248 // BURST SBM2
249 //***********
250 //***********
251 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
252 {
253 sid = getSID( incomingMsg->event );
254 // 1) compress the matrix for Basic Parameters calculation
255 ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f1,
256 nb_sm_before_f1.burst_sbm_bp1,
257 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
258 ASM_F1_INDICE_START);
259 // 2) compute the BP1 set
260
261 // 3) send the BP1 set
262 set_time( packet_sbm_bp1.header.time, (unsigned char *) &incomingMsg->coarseTime );
263 set_time( packet_sbm_bp1.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
264 BP_send( (char *) &packet_sbm_bp1, queue_id_send,
265 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
266 sid );
267 // 4) compute the BP2 set if needed
268 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
269 {
270 // 1) compute the BP2 set
271
272 // 2) send the BP2 set
273 set_time( packet_sbm_bp2.header.time, (unsigned char *) &incomingMsg->coarseTime );
274 set_time( packet_sbm_bp2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
275 BP_send( (char *) &packet_sbm_bp2, queue_id_send,
276 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
277 sid );
278 }
279 }
280
281 //*****
282 //*****
283 // NORM
284 //*****
285 //*****
286 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
287 {
288 // 1) compress the matrix for Basic Parameters calculation
289 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f1,
290 nb_sm_before_f1.norm_bp1,
291 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
292 ASM_F0_INDICE_START );
293 // 2) compute the BP1 set
294
295 // 3) send the BP1 set
296 set_time( packet_norm_bp1.header.time, (unsigned char *) &incomingMsg->coarseTime );
297 set_time( packet_norm_bp1.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
298 BP_send( (char *) &packet_norm_bp1, queue_id_send,
299 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
300 SID_NORM_BP1_F1 );
301 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
302 {
303 // 1) compute the BP2 set
304
305 // 2) send the BP2 set
306 set_time( packet_norm_bp2.header.time, (unsigned char *) &incomingMsg->coarseTime );
307 set_time( packet_norm_bp2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
308 BP_send( (char *) &packet_norm_bp2, queue_id_send,
309 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
310 SID_NORM_BP2_F1 );
311 }
312 }
313
314 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
315 {
316 // 1) reorganize the ASM and divide
317 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
318 asm_f1_reorganized,
319 nb_sm_before_f1.norm_bp1 );
320 // 2) convert the float array in a char array
321 ASM_convert( asm_f1_reorganized, asm_f1_char);
322 // 3) send the spectral matrix packets
323 set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime );
324 set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
325 ASM_send( &headerASM, asm_f1_char, SID_NORM_ASM_F1, &spw_ioctl_send_ASM, queue_id_send);
326 }
327
328 }
329 }
330
331 //**********
332 // FUNCTIONS
333
334 void reset_nb_sm_f1( unsigned char lfrMode )
335 {
336 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
337 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
338 nb_sm_before_f1.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 16;
339 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
340 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
341 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
342 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
343
344 if (lfrMode == LFR_MODE_SBM2)
345 {
346 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
347 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
348 }
349 else if (lfrMode == LFR_MODE_BURST)
350 {
351 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
352 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
353 }
354 else
355 {
356 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
357 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
358 }
359 }
360
@@ -0,0 +1,255
1 /** Functions related to data processing.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
8 */
9
10 #include "avf2_prc2.h"
11
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
13
14 //***
15 // F2
16 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
17 ring_node_asm asm_ring_burst_sbm_f2[ NB_RING_NODES_ASM_BURST_SBM_F2 ];
18
19 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
20 char asm_f2_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
21 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
22 float compressed_sm_sbm_f2 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 ];
23
24 //************
25 // RTEMS TASKS
26
27 //***
28 // F2
29 rtems_task avf2_task( rtems_task_argument argument )
30 {
31 rtems_event_set event_out;
32 rtems_status_code status;
33 rtems_id queue_id_prc2;
34 asm_msg msgForMATR;
35 ring_node_asm *current_ring_node_asm_norm_f2;
36
37 unsigned int nb_norm_bp1;
38 unsigned int nb_norm_bp2;
39 unsigned int nb_norm_asm;
40
41 nb_norm_bp1 = 0;
42 nb_norm_bp2 = 0;
43 nb_norm_asm = 0;
44
45 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
46 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
47 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
48
49 BOOT_PRINTF("in AVF2 ***\n")
50
51 status = get_message_queue_id_prc2( &queue_id_prc2 );
52 if (status != RTEMS_SUCCESSFUL)
53 {
54 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
55 }
56
57 while(1){
58 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
59
60 //****************************************
61 // initialize the mesage for the MATR task
62 msgForMATR.event = 0x00; // this composite event will be sent to the MATR task
63 msgForMATR.burst_sbm = NULL;
64 msgForMATR.norm = current_ring_node_asm_norm_f2;
65 msgForMATR.coarseTime = ring_node_for_averaging_sm_f2->coarseTime;
66 msgForMATR.fineTime = ring_node_for_averaging_sm_f2->fineTime;
67 //
68 //****************************************
69
70 // compute the average and store it in the averaged_sm_f2 buffer
71 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
72 ring_node_for_averaging_sm_f2,
73 nb_norm_bp1 );
74
75 // update nb_average
76 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
77 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
78 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
79
80 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
81 {
82 nb_norm_bp1 = 0;
83 // set another ring for the ASM storage
84 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
85 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
86 || (lfrCurrentMode == LFR_MODE_SBM2) )
87 {
88 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F2;
89 }
90 }
91
92 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
93 {
94 nb_norm_bp2 = 0;
95 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
96 || (lfrCurrentMode == LFR_MODE_SBM2) )
97 {
98 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F2;
99 }
100 }
101
102 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
103 {
104 nb_norm_asm = 0;
105 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
106 || (lfrCurrentMode == LFR_MODE_SBM2) )
107 {
108 // PRINTF1("%lld\n", localTime)
109 msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F2;
110 }
111 }
112
113 //*************************
114 // send the message to MATR
115 if (msgForMATR.event != 0x00)
116 {
117 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0);
118 }
119
120 if (status != RTEMS_SUCCESSFUL) {
121 printf("in AVF2 *** Error sending message to MATR, code %d\n", status);
122 }
123 }
124 }
125
126 rtems_task prc2_task( rtems_task_argument argument )
127 {
128 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
129 size_t size; // size of the incoming TC packet
130 asm_msg *incomingMsg;
131 //
132 spw_ioctl_pkt_send spw_ioctl_send_ASM;
133 rtems_status_code status;
134 rtems_id queue_id;
135 rtems_id queue_id_q_p2;
136 Header_TM_LFR_SCIENCE_ASM_t headerASM;
137 bp_packet packet_norm_bp1_f2;
138 bp_packet packet_norm_bp2_f2;
139
140 unsigned long long int localTime;
141
142 incomingMsg = NULL;
143
144 ASM_init_header( &headerASM );
145
146 //*************
147 // NORM headers
148 BP_init_header( &packet_norm_bp1_f2.header,
149 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
150 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
151 BP_init_header( &packet_norm_bp2_f2.header,
152 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
153 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
154
155 status = get_message_queue_id_send( &queue_id );
156 if (status != RTEMS_SUCCESSFUL)
157 {
158 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
159 }
160 status = get_message_queue_id_prc2( &queue_id_q_p2);
161 if (status != RTEMS_SUCCESSFUL)
162 {
163 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
164 }
165
166 BOOT_PRINTF("in PRC2 ***\n")
167
168 while(1){
169 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
170 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
171
172 incomingMsg = (asm_msg*) incomingData;
173
174 localTime = getTimeAsUnsignedLongLongInt( );
175
176 //*****
177 //*****
178 // NORM
179 //*****
180 //*****
181 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
182 {
183 // 1) compress the matrix for Basic Parameters calculation
184 ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f2,
185 nb_sm_before_f2.norm_bp1,
186 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
187 ASM_F2_INDICE_START );
188 // 2) compute the BP1 set
189
190 // 3) send the BP1 set
191 set_time( packet_norm_bp1_f2.header.time, (unsigned char *) &incomingMsg->coarseTime );
192 set_time( packet_norm_bp1_f2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
193 BP_send( (char *) &packet_norm_bp1_f2, queue_id,
194 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
195 SID_NORM_BP1_F2 );
196 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
197 {
198 // 1) compute the BP2 set using the same ASM as the one used for BP1
199
200 // 2) send the BP2 set
201 set_time( packet_norm_bp2_f2.header.time, (unsigned char *) &incomingMsg->coarseTime );
202 set_time( packet_norm_bp2_f2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
203 BP_send( (char *) &packet_norm_bp2_f2, queue_id,
204 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
205 SID_NORM_BP2_F2 );
206 }
207 }
208
209 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
210 {
211 // 1) reorganize the ASM and divide
212 ASM_reorganize_and_divide( incomingMsg->norm->matrix,
213 asm_f2_reorganized,
214 nb_sm_before_f2.norm_bp1 );
215 // 2) convert the float array in a char array
216 ASM_convert( asm_f2_reorganized, asm_f2_char);
217 // 3) send the spectral matrix packets
218 set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime );
219 set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime );
220 ASM_send( &headerASM, asm_f2_char, SID_NORM_ASM_F2, &spw_ioctl_send_ASM, queue_id);
221 }
222
223 }
224 }
225
226 //**********
227 // FUNCTIONS
228
229 void reset_nb_sm_f2( void )
230 {
231 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
232 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
233 nb_sm_before_f2.norm_asm = parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1];
234 }
235
236 void SM_average_f2( float *averaged_spec_mat_f2,
237 ring_node_sm *ring_node,
238 unsigned int nbAverageNormF2 )
239 {
240 float sum;
241 unsigned int i;
242
243 for(i=0; i<TOTAL_SIZE_SM; i++)
244 {
245 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
246 if ( (nbAverageNormF2 == 0) )
247 {
248 averaged_spec_mat_f2[ i ] = sum;
249 }
250 else
251 {
252 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
253 }
254 }
255 }
This diff has been collapsed as it changes many lines, (696 lines changed) Show them Hide them
@@ -0,0 +1,696
1 /** Functions related to data processing.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
8 */
9
10 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
12
13 unsigned int nb_sm_f0;
14 unsigned int nb_sm_f0_aux_f1;
15 unsigned int nb_sm_f1;
16 unsigned int nb_sm_f0_aux_f2;
17
18 //************************
19 // spectral matrices rings
20 ring_node_sm sm_ring_f0[ NB_RING_NODES_SM_F0 ];
21 ring_node_sm sm_ring_f1[ NB_RING_NODES_SM_F1 ];
22 ring_node_sm sm_ring_f2[ NB_RING_NODES_SM_F2 ];
23 ring_node_sm *current_ring_node_sm_f0;
24 ring_node_sm *current_ring_node_sm_f1;
25 ring_node_sm *current_ring_node_sm_f2;
26 ring_node_sm *ring_node_for_averaging_sm_f0;
27 ring_node_sm *ring_node_for_averaging_sm_f1;
28 ring_node_sm *ring_node_for_averaging_sm_f2;
29
30 //***********************************************************
31 // Interrupt Service Routine for spectral matrices processing
32
33 void spectral_matrices_isr_f0( void )
34 {
35 unsigned char status;
36 unsigned long long int time_0;
37 unsigned long long int time_1;
38 unsigned long long int syncBit0;
39 unsigned long long int syncBit1;
40
41 status = spectral_matrix_regs->status & 0x03; // [0011] get the status_ready_matrix_f0_x bits
42
43 time_0 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_0_coarse_time );
44 time_1 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_1_coarse_time );
45 syncBit0 = ( (unsigned long long int) (spectral_matrix_regs->f0_0_coarse_time & 0x80000000) ) << 16;
46 syncBit1 = ( (unsigned long long int) (spectral_matrix_regs->f0_1_coarse_time & 0x80000000) ) << 16;
47
48 switch(status)
49 {
50 case 0:
51 break;
52 case 3:
53 if ( time_0 < time_1 )
54 {
55 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
56 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0);
57 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
58 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
59 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
60 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1);
61 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
62 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
63 }
64 else
65 {
66 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
67 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1);
68 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
69 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
70 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
71 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0);
72 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
73 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
74 }
75 spectral_matrix_regs->status = 0x03; // [0011]
76 break;
77 case 1:
78 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
79 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0);
80 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
81 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
82 spectral_matrix_regs->status = 0x01; // [0001]
83 break;
84 case 2:
85 close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0],
86 ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1);
87 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
88 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
89 spectral_matrix_regs->status = 0x02; // [0010]
90 break;
91 }
92 }
93
94 void spectral_matrices_isr_f1( void )
95 {
96 unsigned char status;
97 unsigned long long int time;
98 unsigned long long int syncBit;
99 rtems_status_code status_code;
100
101 status = (spectral_matrix_regs->status & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
102
103 switch(status)
104 {
105 case 0:
106 break;
107 case 3:
108 // UNEXPECTED VALUE
109 spectral_matrix_regs->status = 0xc0; // [1100]
110 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
111 break;
112 case 1:
113 time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_0_coarse_time );
114 syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_0_coarse_time & 0x80000000) ) << 16;
115 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1],
116 ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit);
117 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
118 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
119 spectral_matrix_regs->status = 0x04; // [0100]
120 break;
121 case 2:
122 time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_1_coarse_time );
123 syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_1_coarse_time & 0x80000000) ) << 16;
124 close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1],
125 ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit);
126 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
127 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
128 spectral_matrix_regs->status = 0x08; // [1000]
129 break;
130 }
131 }
132
133 void spectral_matrices_isr_f2( void )
134 {
135 unsigned char status;
136 rtems_status_code status_code;
137
138 status = (spectral_matrix_regs->status & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
139
140 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
141
142 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
143
144 switch(status)
145 {
146 case 0:
147 break;
148 case 3:
149 // UNEXPECTED VALUE
150 spectral_matrix_regs->status = 0x30; // [0011 0000]
151 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
152 break;
153 case 1:
154 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
155 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
156 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
157 spectral_matrix_regs->status = 0x10; // [0001 0000]
158 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
159 {
160 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
161 }
162 break;
163 case 2:
164 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
165 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
166 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
167 spectral_matrix_regs->status = 0x20; // [0010 0000]
168 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
169 {
170 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
171 }
172 break;
173 }
174 }
175
176 void spectral_matrix_isr_error_handler( void )
177 {
178 rtems_status_code status_code;
179
180 if (spectral_matrix_regs->status & 0x7c0) // [0111 1100 0000]
181 {
182 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
183 }
184 }
185
186 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
187 {
188 // STATUS REGISTER
189 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
190 // 10 9 8
191 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
192 // 7 6 5 4 3 2 1 0
193
194 spectral_matrices_isr_f0();
195
196 spectral_matrices_isr_f1();
197
198 spectral_matrices_isr_f2();
199
200 // spectral_matrix_isr_error_handler();
201 }
202
203 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
204 {
205 rtems_status_code status_code;
206
207 //***
208 // F0
209 nb_sm_f0 = nb_sm_f0 + 1;
210 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
211 {
212 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
213 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
214 {
215 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
216 }
217 nb_sm_f0 = 0;
218 }
219
220 //***
221 // F1
222 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
223 if (nb_sm_f0_aux_f1 == 6)
224 {
225 nb_sm_f0_aux_f1 = 0;
226 nb_sm_f1 = nb_sm_f1 + 1;
227 }
228 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
229 {
230 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
231 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
232 {
233 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
234 }
235 nb_sm_f1 = 0;
236 }
237
238 //***
239 // F2
240 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
241 if (nb_sm_f0_aux_f2 == 96)
242 {
243 nb_sm_f0_aux_f2 = 0;
244 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
245 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
246 {
247 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
248 }
249 }
250 }
251
252 //******************
253 // Spectral Matrices
254
255 void reset_nb_sm( void )
256 {
257 nb_sm_f0 = 0;
258 nb_sm_f0_aux_f1 = 0;
259 nb_sm_f0_aux_f2 = 0;
260
261 nb_sm_f1 = 0;
262 }
263
264 void SM_init_rings( void )
265 {
266 unsigned char i;
267
268 // F0 RING
269 sm_ring_f0[0].next = (ring_node_sm*) &sm_ring_f0[1];
270 sm_ring_f0[0].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-1];
271 sm_ring_f0[0].buffer_address =
272 (int) &sm_f0[ 0 ];
273
274 sm_ring_f0[NB_RING_NODES_SM_F0-1].next = (ring_node_sm*) &sm_ring_f0[0];
275 sm_ring_f0[NB_RING_NODES_SM_F0-1].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-2];
276 sm_ring_f0[NB_RING_NODES_SM_F0-1].buffer_address =
277 (int) &sm_f0[ (NB_RING_NODES_SM_F0-1) * TOTAL_SIZE_SM ];
278
279 for(i=1; i<NB_RING_NODES_SM_F0-1; i++)
280 {
281 sm_ring_f0[i].next = (ring_node_sm*) &sm_ring_f0[i+1];
282 sm_ring_f0[i].previous = (ring_node_sm*) &sm_ring_f0[i-1];
283 sm_ring_f0[i].buffer_address =
284 (int) &sm_f0[ i * TOTAL_SIZE_SM ];
285 }
286
287 // F1 RING
288 sm_ring_f1[0].next = (ring_node_sm*) &sm_ring_f1[1];
289 sm_ring_f1[0].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-1];
290 sm_ring_f1[0].buffer_address =
291 (int) &sm_f1[ 0 ];
292
293 sm_ring_f1[NB_RING_NODES_SM_F1-1].next = (ring_node_sm*) &sm_ring_f1[0];
294 sm_ring_f1[NB_RING_NODES_SM_F1-1].previous = (ring_node_sm*) &sm_ring_f1[NB_RING_NODES_SM_F1-2];
295 sm_ring_f1[NB_RING_NODES_SM_F1-1].buffer_address =
296 (int) &sm_f1[ (NB_RING_NODES_SM_F1-1) * TOTAL_SIZE_SM ];
297
298 for(i=1; i<NB_RING_NODES_SM_F1-1; i++)
299 {
300 sm_ring_f1[i].next = (ring_node_sm*) &sm_ring_f1[i+1];
301 sm_ring_f1[i].previous = (ring_node_sm*) &sm_ring_f1[i-1];
302 sm_ring_f1[i].buffer_address =
303 (int) &sm_f1[ i * TOTAL_SIZE_SM ];
304 }
305
306 // F2 RING
307 sm_ring_f2[0].next = (ring_node_sm*) &sm_ring_f2[1];
308 sm_ring_f2[0].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-1];
309 sm_ring_f2[0].buffer_address =
310 (int) &sm_f2[ 0 ];
311
312 sm_ring_f2[NB_RING_NODES_SM_F2-1].next = (ring_node_sm*) &sm_ring_f2[0];
313 sm_ring_f2[NB_RING_NODES_SM_F2-1].previous = (ring_node_sm*) &sm_ring_f2[NB_RING_NODES_SM_F2-2];
314 sm_ring_f2[NB_RING_NODES_SM_F2-1].buffer_address =
315 (int) &sm_f2[ (NB_RING_NODES_SM_F2-1) * TOTAL_SIZE_SM ];
316
317 for(i=1; i<NB_RING_NODES_SM_F2-1; i++)
318 {
319 sm_ring_f2[i].next = (ring_node_sm*) &sm_ring_f2[i+1];
320 sm_ring_f2[i].previous = (ring_node_sm*) &sm_ring_f2[i-1];
321 sm_ring_f2[i].buffer_address =
322 (int) &sm_f2[ i * TOTAL_SIZE_SM ];
323 }
324
325 DEBUG_PRINTF1("asm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
326 DEBUG_PRINTF1("asm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
327 DEBUG_PRINTF1("asm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
328
329 spectral_matrix_regs->f0_0_address = sm_ring_f0[0].buffer_address;
330 DEBUG_PRINTF1("spectral_matrix_regs->matrixF0_Address0 @%x\n", spectral_matrix_regs->f0_0_address)
331 }
332
333 void SM_generic_init_ring( ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] )
334 {
335 unsigned char i;
336
337 //***************
338 // BUFFER ADDRESS
339 for(i=0; i<nbNodes; i++)
340 {
341 ring[ i ].buffer_address = (int) &sm_f[ i * TOTAL_SIZE_SM ];
342 }
343
344 //*****
345 // NEXT
346 ring[ nbNodes - 1 ].next = (ring_node_sm*) &ring[ 0 ];
347 for(i=0; i<nbNodes-1; i++)
348 {
349 ring[ i ].next = (ring_node_sm*) &ring[ i + 1 ];
350 }
351
352 //*********
353 // PREVIOUS
354 ring[ 0 ].previous = (ring_node_sm*) &ring[ nbNodes -1 ];
355 for(i=1; i<nbNodes; i++)
356 {
357 ring[ i ].previous = (ring_node_sm*) &ring[ i - 1 ];
358 }
359 }
360
361 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
362 {
363 unsigned char i;
364
365 ring[ nbNodes - 1 ].next
366 = (ring_node_asm*) &ring[ 0 ];
367
368 for(i=0; i<nbNodes-1; i++)
369 {
370 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
371 }
372 }
373
374 void SM_reset_current_ring_nodes( void )
375 {
376 current_ring_node_sm_f0 = sm_ring_f0[0].next;
377 current_ring_node_sm_f1 = sm_ring_f1[0].next;
378 current_ring_node_sm_f2 = sm_ring_f2[0].next;
379
380 ring_node_for_averaging_sm_f0 = sm_ring_f0;
381 ring_node_for_averaging_sm_f1 = sm_ring_f1;
382 ring_node_for_averaging_sm_f2 = sm_ring_f2;
383 }
384
385 void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header)
386 {
387 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
388 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
389 header->reserved = 0x00;
390 header->userApplication = CCSDS_USER_APP;
391 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
392 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
393 header->packetSequenceControl[0] = 0xc0;
394 header->packetSequenceControl[1] = 0x00;
395 header->packetLength[0] = 0x00;
396 header->packetLength[1] = 0x00;
397 // DATA FIELD HEADER
398 header->spare1_pusVersion_spare2 = 0x10;
399 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
400 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
401 header->destinationID = TM_DESTINATION_ID_GROUND;
402 // AUXILIARY DATA HEADER
403 header->sid = 0x00;
404 header->biaStatusInfo = 0x00;
405 header->pa_lfr_pkt_cnt_asm = 0x00;
406 header->pa_lfr_pkt_nr_asm = 0x00;
407 header->time[0] = 0x00;
408 header->time[0] = 0x00;
409 header->time[0] = 0x00;
410 header->time[0] = 0x00;
411 header->time[0] = 0x00;
412 header->time[0] = 0x00;
413 header->pa_lfr_asm_blk_nr[0] = 0x00; // BLK_NR MSB
414 header->pa_lfr_asm_blk_nr[1] = 0x00; // BLK_NR LSB
415 }
416
417 void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix,
418 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id)
419 {
420 unsigned int i;
421 unsigned int length = 0;
422 rtems_status_code status;
423
424 for (i=0; i<2; i++)
425 {
426 // (1) BUILD THE DATA
427 switch(sid)
428 {
429 case SID_NORM_ASM_F0:
430 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2; // 2 packets will be sent
431 spw_ioctl_send->data = &spectral_matrix[
432 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2
433 ];
434 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0;
435 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB
436 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB
437 break;
438 case SID_NORM_ASM_F1:
439 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F1_IN_BYTES / 2; // 2 packets will be sent
440 spw_ioctl_send->data = &spectral_matrix[
441 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1) ) * NB_VALUES_PER_SM ) * 2
442 ];
443 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1;
444 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1) >> 8 ); // BLK_NR MSB
445 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1); // BLK_NR LSB
446 break;
447 case SID_NORM_ASM_F2:
448 spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F2_IN_BYTES / 2; // 2 packets will be sent
449 spw_ioctl_send->data = &spectral_matrix[
450 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) * 2
451 ];
452 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
453 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
454 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
455 break;
456 default:
457 PRINTF1("ERR *** in ASM_send *** unexpected sid %d\n", sid)
458 break;
459 }
460 spw_ioctl_send->hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES;
461 spw_ioctl_send->hdr = (char *) header;
462 spw_ioctl_send->options = 0;
463
464 // (2) BUILD THE HEADER
465 increment_seq_counter_source_id( header->packetSequenceControl, sid );
466 header->packetLength[0] = (unsigned char) (length>>8);
467 header->packetLength[1] = (unsigned char) (length);
468 header->sid = (unsigned char) sid; // SID
469 header->pa_lfr_pkt_cnt_asm = 2;
470 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
471
472 // (3) SET PACKET TIME
473 header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
474 header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
475 header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
476 header->time[3] = (unsigned char) (time_management_regs->coarse_time);
477 header->time[4] = (unsigned char) (time_management_regs->fine_time>>8);
478 header->time[5] = (unsigned char) (time_management_regs->fine_time);
479 //
480 header->acquisitionTime[0] = header->time[0];
481 header->acquisitionTime[1] = header->time[1];
482 header->acquisitionTime[2] = header->time[2];
483 header->acquisitionTime[3] = header->time[3];
484 header->acquisitionTime[4] = header->time[4];
485 header->acquisitionTime[5] = header->time[5];
486
487 // (4) SEND PACKET
488 status = rtems_message_queue_send( queue_id, spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
489 if (status != RTEMS_SUCCESSFUL) {
490 printf("in ASM_send *** ERR %d\n", (int) status);
491 }
492 }
493 }
494
495 //*****************
496 // Basic Parameters
497
498 void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header,
499 unsigned int apid, unsigned char sid,
500 unsigned int packetLength, unsigned char blkNr )
501 {
502 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
503 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
504 header->reserved = 0x00;
505 header->userApplication = CCSDS_USER_APP;
506 header->packetID[0] = (unsigned char) (apid >> 8);
507 header->packetID[1] = (unsigned char) (apid);
508 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
509 header->packetSequenceControl[1] = 0x00;
510 header->packetLength[0] = (unsigned char) (packetLength >> 8);
511 header->packetLength[1] = (unsigned char) (packetLength);
512 // DATA FIELD HEADER
513 header->spare1_pusVersion_spare2 = 0x10;
514 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
515 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
516 header->destinationID = TM_DESTINATION_ID_GROUND;
517 // AUXILIARY DATA HEADER
518 header->sid = sid;
519 header->biaStatusInfo = 0x00;
520 header->time[0] = 0x00;
521 header->time[0] = 0x00;
522 header->time[0] = 0x00;
523 header->time[0] = 0x00;
524 header->time[0] = 0x00;
525 header->time[0] = 0x00;
526 header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
527 header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
528 }
529
530 void BP_init_header_with_spare(Header_TM_LFR_SCIENCE_BP_with_spare_t *header,
531 unsigned int apid, unsigned char sid,
532 unsigned int packetLength , unsigned char blkNr)
533 {
534 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
535 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
536 header->reserved = 0x00;
537 header->userApplication = CCSDS_USER_APP;
538 header->packetID[0] = (unsigned char) (apid >> 8);
539 header->packetID[1] = (unsigned char) (apid);
540 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
541 header->packetSequenceControl[1] = 0x00;
542 header->packetLength[0] = (unsigned char) (packetLength >> 8);
543 header->packetLength[1] = (unsigned char) (packetLength);
544 // DATA FIELD HEADER
545 header->spare1_pusVersion_spare2 = 0x10;
546 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
547 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
548 header->destinationID = TM_DESTINATION_ID_GROUND;
549 // AUXILIARY DATA HEADER
550 header->sid = sid;
551 header->biaStatusInfo = 0x00;
552 header->time[0] = 0x00;
553 header->time[0] = 0x00;
554 header->time[0] = 0x00;
555 header->time[0] = 0x00;
556 header->time[0] = 0x00;
557 header->time[0] = 0x00;
558 header->source_data_spare = 0x00;
559 header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
560 header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
561 }
562
563 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
564 {
565 rtems_status_code status;
566
567 // SET THE SEQUENCE_CNT PARAMETER
568 increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid );
569 // SEND PACKET
570 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
571 if (status != RTEMS_SUCCESSFUL)
572 {
573 printf("ERR *** in BP_send *** ERR %d\n", (int) status);
574 }
575 }
576
577 //******************
578 // general functions
579
580 void reset_spectral_matrix_regs( void )
581 {
582 /** This function resets the spectral matrices module registers.
583 *
584 * The registers affected by this function are located at the following offset addresses:
585 *
586 * - 0x00 config
587 * - 0x04 status
588 * - 0x08 matrixF0_Address0
589 * - 0x10 matrixFO_Address1
590 * - 0x14 matrixF1_Address
591 * - 0x18 matrixF2_Address
592 *
593 */
594
595 spectral_matrix_regs->config = 0x00;
596 spectral_matrix_regs->status = 0x00;
597
598 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
599 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
600 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
601 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
602 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
603 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
604 }
605
606 void set_time( unsigned char *time, unsigned char * timeInBuffer )
607 {
608 time[0] = timeInBuffer[0];
609 time[1] = timeInBuffer[1];
610 time[2] = timeInBuffer[2];
611 time[3] = timeInBuffer[3];
612 time[4] = timeInBuffer[6];
613 time[5] = timeInBuffer[7];
614 }
615
616 unsigned long long int get_acquisition_time( unsigned char *timePtr )
617 {
618 unsigned long long int acquisitionTimeAslong;
619 acquisitionTimeAslong = 0x00;
620 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
621 + ( (unsigned long long int) timePtr[1] << 32 )
622 + ( (unsigned long long int) timePtr[2] << 24 )
623 + ( (unsigned long long int) timePtr[3] << 16 )
624 + ( (unsigned long long int) timePtr[6] << 8 )
625 + ( (unsigned long long int) timePtr[7] );
626 return acquisitionTimeAslong;
627 }
628
629 void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id,
630 ring_node_sm *node_for_averaging, ring_node_sm *ringNode,
631 unsigned long long int time )
632 {
633 unsigned char *timePtr;
634 unsigned char *coarseTimePtr;
635 unsigned char *fineTimePtr;
636 rtems_status_code status_code;
637
638 timePtr = (unsigned char *) &time;
639 coarseTimePtr = (unsigned char *) &node_for_averaging->coarseTime;
640 fineTimePtr = (unsigned char *) &node_for_averaging->fineTime;
641
642 *nb_sm = *nb_sm + 1;
643 if (*nb_sm == nb_sm_before_avf)
644 {
645 node_for_averaging = ringNode;
646 coarseTimePtr[0] = timePtr[2];
647 coarseTimePtr[1] = timePtr[3];
648 coarseTimePtr[2] = timePtr[4];
649 coarseTimePtr[3] = timePtr[5];
650 fineTimePtr[2] = timePtr[6];
651 fineTimePtr[3] = timePtr[7];
652 if (rtems_event_send( avf_task_id, RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
653 {
654 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
655 }
656 *nb_sm = 0;
657 }
658 }
659
660 unsigned char getSID( rtems_event_set event )
661 {
662 unsigned char sid;
663
664 rtems_event_set eventSetBURST;
665 rtems_event_set eventSetSBM;
666
667 //******
668 // BURST
669 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
670 | RTEMS_EVENT_BURST_BP1_F1
671 | RTEMS_EVENT_BURST_BP2_F0
672 | RTEMS_EVENT_BURST_BP2_F1;
673
674 //****
675 // SBM
676 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
677 | RTEMS_EVENT_SBM_BP1_F1
678 | RTEMS_EVENT_SBM_BP2_F0
679 | RTEMS_EVENT_SBM_BP2_F1;
680
681 if (event & eventSetBURST)
682 {
683 sid = SID_BURST_BP1_F0;
684 }
685 else if (event & eventSetSBM)
686 {
687 sid = SID_SBM1_BP1_F0;
688 }
689 else
690 {
691 sid = 0;
692 }
693
694 return sid;
695 }
696
@@ -0,0 +1,437
1 /** Functions related to TeleCommand acceptance.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle TeleCommands parsing.\n
7 *
8 */
9
10 #include "tc_acceptance.h"
11
12 unsigned int lookUpTableForCRC[256];
13
14 //**********************
15 // GENERAL USE FUNCTIONS
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 {
18 /** This function generate the CRC for one byte and returns the value of the new syndrome.
19 *
20 * @param D is the current byte of data.
21 * @param Chk is the current syndrom value.
22 *
23 * @return the value of the new syndrome on two bytes.
24 *
25 */
26
27 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
28 }
29
30 void initLookUpTableForCRC( void )
31 {
32 /** This function is used to initiates the look-up table for fast CRC computation.
33 *
34 * The global table lookUpTableForCRC[256] is initiated.
35 *
36 */
37
38 unsigned int i;
39 unsigned int tmp;
40
41 for (i=0; i<256; i++)
42 {
43 tmp = 0;
44 if((i & 1) != 0) {
45 tmp = tmp ^ 0x1021;
46 }
47 if((i & 2) != 0) {
48 tmp = tmp ^ 0x2042;
49 }
50 if((i & 4) != 0) {
51 tmp = tmp ^ 0x4084;
52 }
53 if((i & 8) != 0) {
54 tmp = tmp ^ 0x8108;
55 }
56 if((i & 16) != 0) {
57 tmp = tmp ^ 0x1231;
58 }
59 if((i & 32) != 0) {
60 tmp = tmp ^ 0x2462;
61 }
62 if((i & 64) != 0) {
63 tmp = tmp ^ 0x48c4;
64 }
65 if((i & 128) != 0) {
66 tmp = tmp ^ 0x9188;
67 }
68 lookUpTableForCRC[i] = tmp;
69 }
70 }
71
72 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
73 {
74 /** This function calculates a two bytes Cyclic Redundancy Code.
75 *
76 * @param data points to a buffer containing the data on which to compute the CRC.
77 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
78 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
79 *
80 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
81 *
82 */
83
84 unsigned int Chk;
85 int j;
86 Chk = 0xffff; // reset the syndrom to all ones
87 for (j=0; j<sizeOfData; j++) {
88 Chk = Crc_opt(data[j], Chk);
89 }
90 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
91 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
92 }
93
94 //*********************
95 // ACCEPTANCE FUNCTIONS
96 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
97 {
98 /** This function parses TeleCommands.
99 *
100 * @param TC points to the TeleCommand that will be parsed.
101 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
102 *
103 * @return Status code of the parsing.
104 *
105 * The parsing checks:
106 * - process id
107 * - category
108 * - length: a global check is performed and a per subtype check also
109 * - type
110 * - subtype
111 * - crc
112 *
113 */
114
115 int status;
116 int status_crc;
117 unsigned char pid;
118 unsigned char category;
119 unsigned int packetLength;
120 unsigned char packetType;
121 unsigned char packetSubtype;
122 unsigned char sid;
123
124 status = CCSDS_TM_VALID;
125
126 // APID check *** APID on 2 bytes
127 pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
128 category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
129 packetLength = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1];
130 packetType = TCPacket->serviceType;
131 packetSubtype = TCPacket->serviceSubType;
132 sid = TCPacket->sourceID;
133
134 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
135 {
136 status = ILLEGAL_APID;
137 }
138 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
139 {
140 if ( category != CCSDS_PACKET_CATEGORY )
141 {
142 status = ILLEGAL_APID;
143 }
144 }
145 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
146 {
147 if (packetLength != estimatedPacketLength ) {
148 status = WRONG_LEN_PKT;
149 }
150 }
151 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
152 {
153 if ( packetLength >= CCSDS_TC_PKT_MAX_SIZE ) {
154 status = WRONG_LEN_PKT;
155 }
156 }
157 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
158 {
159 status = tc_check_type( packetType );
160 }
161 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
162 {
163 status = tc_check_type_subtype( packetType, packetSubtype );
164 }
165 if (status == CCSDS_TM_VALID) // CHECK THE SID
166 {
167 status = tc_check_sid( sid );
168 }
169 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
170 {
171 status = tc_check_length( packetSubtype, packetLength );
172 }
173 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
174 if (status == CCSDS_TM_VALID ) // CHECK CRC
175 {
176 status = status_crc;
177 }
178
179 return status;
180 }
181
182 int tc_check_type( unsigned char packetType )
183 {
184 /** This function checks that the type of a TeleCommand is valid.
185 *
186 * @param packetType is the type to check.
187 *
188 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
189 *
190 */
191
192 int status;
193
194 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
195 {
196 status = CCSDS_TM_VALID;
197 }
198 else
199 {
200 status = ILL_TYPE;
201 }
202
203 return status;
204 }
205
206 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
207 {
208 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
209 *
210 * @param packetType is the type of the TC.
211 * @param packetSubType is the subtype to check.
212 *
213 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
214 *
215 */
216
217 int status;
218
219 switch(packetType)
220 {
221 case TC_TYPE_GEN:
222 if ( (packetSubType == TC_SUBTYPE_RESET)
223 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
224 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
225 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
226 || (packetSubType == TC_SUBTYPE_DUMP)
227 || (packetSubType == TC_SUBTYPE_ENTER)
228 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
229 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL) )
230 {
231 status = CCSDS_TM_VALID;
232 }
233 else
234 {
235 status = ILL_SUBTYPE;
236 }
237 break;
238
239 case TC_TYPE_TIME:
240 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
241 {
242 status = CCSDS_TM_VALID;
243 }
244 else
245 {
246 status = ILL_SUBTYPE;
247 }
248 break;
249
250 default:
251 status = ILL_SUBTYPE;
252 break;
253 }
254
255 return status;
256 }
257
258 int tc_check_sid( unsigned char sid )
259 {
260 /** This function checks that the sid of a TeleCommand is valid.
261 *
262 * @param sid is the sid to check.
263 *
264 * @return Status code CCSDS_TM_VALID or CORRUPTED.
265 *
266 */
267
268 int status;
269
270 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
271 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
272 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
273 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
274 || (sid == SID_TC_RPW_INTERNAL))
275 {
276 status = CCSDS_TM_VALID;
277 }
278 else
279 {
280 status = WRONG_SRC_ID;
281 }
282
283 return status;
284 }
285
286 int tc_check_length( unsigned char packetSubType, unsigned int length )
287 {
288 /** This function checks that the subtype and the length are compliant.
289 *
290 * @param packetSubType is the subtype to check.
291 * @param length is the length to check.
292 *
293 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
294 *
295 */
296
297 int status;
298
299 status = LFR_SUCCESSFUL;
300
301 switch(packetSubType)
302 {
303 case TC_SUBTYPE_RESET:
304 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
305 status = WRONG_LEN_PKT;
306 }
307 else {
308 status = CCSDS_TM_VALID;
309 }
310 break;
311 case TC_SUBTYPE_LOAD_COMM:
312 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
313 status = WRONG_LEN_PKT;
314 }
315 else {
316 status = CCSDS_TM_VALID;
317 }
318 break;
319 case TC_SUBTYPE_LOAD_NORM:
320 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
321 status = WRONG_LEN_PKT;
322 }
323 else {
324 status = CCSDS_TM_VALID;
325 }
326 break;
327 case TC_SUBTYPE_LOAD_BURST:
328 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
329 status = WRONG_LEN_PKT;
330 }
331 else {
332 status = CCSDS_TM_VALID;
333 }
334 break;
335 case TC_SUBTYPE_LOAD_SBM1:
336 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
337 status = WRONG_LEN_PKT;
338 }
339 else {
340 status = CCSDS_TM_VALID;
341 }
342 break;
343 case TC_SUBTYPE_LOAD_SBM2:
344 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
345 status = WRONG_LEN_PKT;
346 }
347 else {
348 status = CCSDS_TM_VALID;
349 }
350 break;
351 case TC_SUBTYPE_DUMP:
352 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
353 status = WRONG_LEN_PKT;
354 }
355 else {
356 status = CCSDS_TM_VALID;
357 }
358 break;
359 case TC_SUBTYPE_ENTER:
360 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
361 status = WRONG_LEN_PKT;
362 }
363 else {
364 status = CCSDS_TM_VALID;
365 }
366 break;
367 case TC_SUBTYPE_UPDT_INFO:
368 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
369 status = WRONG_LEN_PKT;
370 }
371 else {
372 status = CCSDS_TM_VALID;
373 }
374 break;
375 case TC_SUBTYPE_EN_CAL:
376 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
377 status = WRONG_LEN_PKT;
378 }
379 else {
380 status = CCSDS_TM_VALID;
381 }
382 break;
383 case TC_SUBTYPE_DIS_CAL:
384 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
385 status = WRONG_LEN_PKT;
386 }
387 else {
388 status = CCSDS_TM_VALID;
389 }
390 break;
391 case TC_SUBTYPE_UPDT_TIME:
392 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
393 status = WRONG_LEN_PKT;
394 }
395 else {
396 status = CCSDS_TM_VALID;
397 }
398 break;
399 default: // if the subtype is not a legal value, return ILL_SUBTYPE
400 status = ILL_SUBTYPE;
401 break ;
402 }
403
404 return status;
405 }
406
407 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
408 {
409 /** This function checks the CRC validity of the corresponding TeleCommand packet.
410 *
411 * @param TCPacket points to the TeleCommand packet to check.
412 * @param length is the length of the TC packet.
413 *
414 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
415 *
416 */
417
418 int status;
419 unsigned char * CCSDSContent;
420
421 CCSDSContent = (unsigned char*) TCPacket->packetID;
422 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
423 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
424 status = INCOR_CHECKSUM;
425 }
426 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
427 status = INCOR_CHECKSUM;
428 }
429 else {
430 status = CCSDS_TM_VALID;
431 }
432
433 return status;
434 }
435
436
437
@@ -0,0 +1,250
1 /** Functions and tasks related to TeleCommand handling.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
8 * TC parsing\n
9 * ...
10 *
11 */
12
13 #include "tc_handler.h"
14
15 //***********
16 // RTEMS TASK
17
18 unsigned int incomingTransitionCoarseTime;
19
20 void reset_transitionCoarseTime( void )
21 {
22 incomingTransitionCoarseTime = 0xffffffff;
23 }
24
25 void set_transitionCoarseTime( unsigned int value )
26 {
27 incomingTransitionCoarseTime = value;
28 }
29
30 unsigned int get_transitionCoarseTime( void )
31 {
32 return incomingTransitionCoarseTime;
33 }
34
35 rtems_task actn_task( rtems_task_argument unused )
36 {
37 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
38 *
39 * @param unused is the starting argument of the RTEMS task
40 *
41 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
42 * on the incoming TeleCommand.
43 *
44 */
45
46 int result;
47 rtems_status_code status; // RTEMS status code
48 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
49 size_t size; // size of the incoming TC packet
50 unsigned char subtype; // subtype of the current TC packet
51 unsigned char time[6];
52 rtems_id queue_rcv_id;
53 rtems_id queue_snd_id;
54
55 status = get_message_queue_id_recv( &queue_rcv_id );
56 if (status != RTEMS_SUCCESSFUL)
57 {
58 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
59 }
60
61 status = get_message_queue_id_send( &queue_snd_id );
62 if (status != RTEMS_SUCCESSFUL)
63 {
64 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
65 }
66
67 result = LFR_SUCCESSFUL;
68 subtype = 0; // subtype of the current TC packet
69
70 BOOT_PRINTF("in ACTN *** \n")
71
72 while(1)
73 {
74 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
75 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
76 getTime( time ); // set time to the current time
77 if (status!=RTEMS_SUCCESSFUL)
78 {
79 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
80 }
81 else
82 {
83 subtype = TC.serviceSubType;
84 switch(subtype)
85 {
86 case TC_SUBTYPE_ENTER:
87 result = action_enter_mode( &TC, queue_snd_id );
88 break;
89 case TC_SUBTYPE_UPDATE_TIME:
90 result = action_update_time( &TC );
91 break;
92 default:
93 break;
94 }
95 }
96 }
97 }
98
99 //***********
100 // TC ACTIONS
101
102 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
103 {
104 return LFR_SUCCESSFUL;
105 }
106
107 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
108 {
109 unsigned int *transitionCoarseTime_ptr;
110 unsigned int transitionCoarseTime;
111 unsigned char * bytePosPtr;
112
113 bytePosPtr = (unsigned char *) &TC->packetID;
114
115 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
116 transitionCoarseTime = transitionCoarseTime_ptr[0] & 0x7fffffff;
117 printf("local coarse time (without sync bit) = %x, requested transitionCoarseTime = %x\n",
118 getLocalCoarseTime(),
119 transitionCoarseTime);
120
121 set_transitionCoarseTime( transitionCoarseTime );
122
123 return LFR_SUCCESSFUL;
124 }
125
126 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
127 {
128 return LFR_SUCCESSFUL;
129 }
130
131 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
132 {
133 return LFR_SUCCESSFUL;
134 }
135
136 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
137 {
138 return LFR_SUCCESSFUL;
139 }
140
141 int action_update_time(ccsdsTelecommandPacket_t *TC)
142 {
143 unsigned int incomingCoarseTime;
144 unsigned int currentLocalCoarseTime;
145
146 incomingCoarseTime = (TC->dataAndCRC[0] << 24)
147 + (TC->dataAndCRC[1] << 16)
148 + (TC->dataAndCRC[2] << 8)
149 + TC->dataAndCRC[3];
150
151 currentLocalCoarseTime = getLocalCoarseTime();
152 setLocalCoarseTime( incomingCoarseTime );
153 printf( "currentLocalCoarseTime = %x, localCoarseTime set to: %x\n", currentLocalCoarseTime, getLocalCoarseTime() );
154
155 return LFR_SUCCESSFUL;
156 }
157
158 //*******************
159 // ENTERING THE MODES
160 int check_mode_value( unsigned char requestedMode )
161 {
162 return LFR_SUCCESSFUL;
163 }
164
165 int check_mode_transition( unsigned char requestedMode )
166 {
167 return LFR_SUCCESSFUL;
168 }
169
170 int check_transition_date( unsigned int transitionCoarseTime )
171 {
172 return LFR_SUCCESSFUL;
173 }
174
175 int stop_current_mode( void )
176 {
177 return LFR_SUCCESSFUL;
178 }
179
180 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
181 {
182 return LFR_SUCCESSFUL;
183 }
184
185 int restart_science_tasks(unsigned char lfrRequestedMode )
186 {
187 return LFR_SUCCESSFUL;
188 }
189
190 int suspend_science_tasks()
191 {
192 return LFR_SUCCESSFUL;
193 }
194
195 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
196 {
197 }
198
199 void launch_spectral_matrix( void )
200 {
201 }
202
203 void launch_spectral_matrix_simu( void )
204 {
205 }
206
207 void set_irq_on_new_ready_matrix( unsigned char value )
208 {
209 }
210
211 void set_run_matrix_spectral( unsigned char value )
212 {
213 }
214
215 //****************
216 // CLOSING ACTIONS
217 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
218 {
219 }
220
221 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
222 {
223 }
224
225 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
226 {
227 }
228
229 //***************************
230 // Interrupt Service Routines
231 rtems_isr commutation_isr1( rtems_vector_number vector )
232 {
233 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
234 printf("In commutation_isr1 *** Error sending event to DUMB\n");
235 }
236 }
237
238 rtems_isr commutation_isr2( rtems_vector_number vector )
239 {
240 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
241 printf("In commutation_isr2 *** Error sending event to DUMB\n");
242 }
243 }
244
245 //****************
246 // OTHER FUNCTIONS
247 void updateLFRCurrentMode()
248 {
249 }
250
This diff has been collapsed as it changes many lines, (772 lines changed) Show them Hide them
@@ -0,0 +1,772
1 /** Functions to load and dump parameters in the LFR registers.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
12 *
13 */
14
15 #include "tc_load_dump_parameters.h"
16
17 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
18 {
19 /** This function updates the LFR registers with the incoming common parameters.
20 *
21 * @param TC points to the TeleCommand packet that is being processed
22 *
23 *
24 */
25
26 parameter_dump_packet.unused0 = TC->dataAndCRC[0];
27 parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1];
28 set_wfp_data_shaping( );
29 return LFR_SUCCESSFUL;
30 }
31
32 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
33 {
34 /** This function updates the LFR registers with the incoming normal parameters.
35 *
36 * @param TC points to the TeleCommand packet that is being processed
37 * @param queue_id is the id of the queue which handles TM related to this execution step
38 *
39 */
40
41 int result;
42 int flag;
43 rtems_status_code status;
44
45 flag = LFR_SUCCESSFUL;
46
47 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
48 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
49 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
50 flag = LFR_DEFAULT;
51 }
52
53 // CHECK THE PARAMETERS SET CONSISTENCY
54 if (flag == LFR_SUCCESSFUL)
55 {
56 flag = check_common_par_consistency( TC, queue_id );
57 }
58
59 // SET THE PARAMETERS IF THEY ARE CONSISTENT
60 if (flag == LFR_SUCCESSFUL)
61 {
62 result = set_sy_lfr_n_swf_l( TC );
63 result = set_sy_lfr_n_swf_p( TC );
64 result = set_sy_lfr_n_bp_p0( TC );
65 result = set_sy_lfr_n_bp_p1( TC );
66 result = set_sy_lfr_n_asm_p( TC );
67 result = set_sy_lfr_n_cwf_long_f3( TC );
68 }
69
70 return flag;
71 }
72
73 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
74 {
75 /** This function updates the LFR registers with the incoming burst parameters.
76 *
77 * @param TC points to the TeleCommand packet that is being processed
78 * @param queue_id is the id of the queue which handles TM related to this execution step
79 *
80 */
81
82 int flag;
83 rtems_status_code status;
84 unsigned char sy_lfr_b_bp_p0;
85 unsigned char sy_lfr_b_bp_p1;
86 float aux;
87
88 flag = LFR_SUCCESSFUL;
89
90 if ( lfrCurrentMode == LFR_MODE_BURST ) {
91 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
92 flag = LFR_DEFAULT;
93 }
94
95 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
96 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
97
98 // sy_lfr_b_bp_p0
99 if (flag == LFR_SUCCESSFUL)
100 {
101 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
102 {
103 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
104 flag = WRONG_APP_DATA;
105 }
106 }
107 // sy_lfr_b_bp_p1
108 if (flag == LFR_SUCCESSFUL)
109 {
110 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
111 {
112 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
113 flag = WRONG_APP_DATA;
114 }
115 }
116 //****************************************************************
117 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
118 if (flag == LFR_SUCCESSFUL)
119 {
120 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
121 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
122 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
123 if (aux > FLOAT_EQUAL_ZERO)
124 {
125 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
126 flag = LFR_DEFAULT;
127 }
128 }
129
130 // SET HTE PARAMETERS
131 if (flag == LFR_SUCCESSFUL)
132 {
133 flag = set_sy_lfr_b_bp_p0( TC );
134 flag = set_sy_lfr_b_bp_p1( TC );
135 }
136
137 return flag;
138 }
139
140 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
141 {
142 /** This function updates the LFR registers with the incoming sbm1 parameters.
143 *
144 * @param TC points to the TeleCommand packet that is being processed
145 * @param queue_id is the id of the queue which handles TM related to this execution step
146 *
147 */
148
149 int flag;
150 rtems_status_code status;
151 unsigned char sy_lfr_s1_bp_p0;
152 unsigned char sy_lfr_s1_bp_p1;
153 float aux;
154
155 flag = LFR_SUCCESSFUL;
156
157 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
158 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
159 flag = LFR_DEFAULT;
160 }
161
162 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
163 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
164
165 // sy_lfr_s1_bp_p0
166 if (flag == LFR_SUCCESSFUL)
167 {
168 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
169 {
170 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
171 flag = WRONG_APP_DATA;
172 }
173 }
174 // sy_lfr_s1_bp_p1
175 if (flag == LFR_SUCCESSFUL)
176 {
177 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
178 {
179 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
180 flag = WRONG_APP_DATA;
181 }
182 }
183 //******************************************************************
184 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
185 if (flag == LFR_SUCCESSFUL)
186 {
187 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));
188 if (aux > FLOAT_EQUAL_ZERO)
189 {
190 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
191 flag = LFR_DEFAULT;
192 }
193 }
194
195 // SET THE PARAMETERS
196 if (flag == LFR_SUCCESSFUL)
197 {
198 flag = set_sy_lfr_s1_bp_p0( TC );
199 flag = set_sy_lfr_s1_bp_p1( TC );
200 }
201
202 return flag;
203 }
204
205 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
206 {
207 /** This function updates the LFR registers with the incoming sbm2 parameters.
208 *
209 * @param TC points to the TeleCommand packet that is being processed
210 * @param queue_id is the id of the queue which handles TM related to this execution step
211 *
212 */
213
214 int flag;
215 rtems_status_code status;
216 unsigned char sy_lfr_s2_bp_p0;
217 unsigned char sy_lfr_s2_bp_p1;
218 float aux;
219
220 flag = LFR_SUCCESSFUL;
221
222 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
223 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
224 flag = LFR_DEFAULT;
225 }
226
227 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
228 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
229
230 // sy_lfr_s2_bp_p0
231 if (flag == LFR_SUCCESSFUL)
232 {
233 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
234 {
235 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
236 flag = WRONG_APP_DATA;
237 }
238 }
239 // sy_lfr_s2_bp_p1
240 if (flag == LFR_SUCCESSFUL)
241 {
242 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
243 {
244 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
245 flag = WRONG_APP_DATA;
246 }
247 }
248 //******************************************************************
249 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
250 if (flag == LFR_SUCCESSFUL)
251 {
252 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
253 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
254 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
255 if (aux > FLOAT_EQUAL_ZERO)
256 {
257 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
258 flag = LFR_DEFAULT;
259 }
260 }
261
262 // SET THE PARAMETERS
263 if (flag == LFR_SUCCESSFUL)
264 {
265 flag = set_sy_lfr_s2_bp_p0( TC );
266 flag = set_sy_lfr_s2_bp_p1( TC );
267 }
268
269 return flag;
270 }
271
272 int action_dump_par( rtems_id queue_id )
273 {
274 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
275 *
276 * @param queue_id is the id of the queue which handles TM related to this execution step.
277 *
278 * @return RTEMS directive status codes:
279 * - RTEMS_SUCCESSFUL - message sent successfully
280 * - RTEMS_INVALID_ID - invalid queue id
281 * - RTEMS_INVALID_SIZE - invalid message size
282 * - RTEMS_INVALID_ADDRESS - buffer is NULL
283 * - RTEMS_UNSATISFIED - out of message buffers
284 * - RTEMS_TOO_MANY - queue s limit has been reached
285 *
286 */
287
288 int status;
289
290 // UPDATE TIME
291 parameter_dump_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterParameterDump >> 8);
292 parameter_dump_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterParameterDump );
293 increment_seq_counter( &sequenceCounterParameterDump );
294
295 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
296 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
297 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
298 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
299 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
300 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
301 // SEND DATA
302 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
303 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
304 if (status != RTEMS_SUCCESSFUL) {
305 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
306 }
307
308 return status;
309 }
310
311 //***********************
312 // NORMAL MODE PARAMETERS
313
314 int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
315 {
316 unsigned char msb;
317 unsigned char lsb;
318 int flag;
319 float aux;
320 rtems_status_code status;
321
322 unsigned int sy_lfr_n_swf_l;
323 unsigned int sy_lfr_n_swf_p;
324 unsigned int sy_lfr_n_asm_p;
325 unsigned char sy_lfr_n_bp_p0;
326 unsigned char sy_lfr_n_bp_p1;
327 unsigned char sy_lfr_n_cwf_long_f3;
328
329 flag = LFR_SUCCESSFUL;
330
331 //***************
332 // get parameters
333 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
334 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
335 sy_lfr_n_swf_l = msb * 256 + lsb;
336
337 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
338 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
339 sy_lfr_n_swf_p = msb * 256 + lsb;
340
341 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
342 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
343 sy_lfr_n_asm_p = msb * 256 + lsb;
344
345 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
346
347 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
348
349 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
350
351 //******************
352 // check consistency
353 // sy_lfr_n_swf_l
354 if (sy_lfr_n_swf_l != 2048)
355 {
356 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
357 flag = WRONG_APP_DATA;
358 }
359 // sy_lfr_n_swf_p
360 if (flag == LFR_SUCCESSFUL)
361 {
362 if ( sy_lfr_n_swf_p < 16 )
363 {
364 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
365 flag = WRONG_APP_DATA;
366 }
367 }
368 // sy_lfr_n_bp_p0
369 if (flag == LFR_SUCCESSFUL)
370 {
371 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
372 {
373 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
374 flag = WRONG_APP_DATA;
375 }
376 }
377 // sy_lfr_n_asm_p
378 if (flag == LFR_SUCCESSFUL)
379 {
380 if (sy_lfr_n_asm_p == 0)
381 {
382 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
383 flag = WRONG_APP_DATA;
384 }
385 }
386 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
387 if (flag == LFR_SUCCESSFUL)
388 {
389 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
390 if (aux > FLOAT_EQUAL_ZERO)
391 {
392 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
393 flag = WRONG_APP_DATA;
394 }
395 }
396 // sy_lfr_n_bp_p1
397 if (flag == LFR_SUCCESSFUL)
398 {
399 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
400 {
401 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
402 flag = WRONG_APP_DATA;
403 }
404 }
405 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
406 if (flag == LFR_SUCCESSFUL)
407 {
408 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
409 if (aux > FLOAT_EQUAL_ZERO)
410 {
411 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
412 flag = LFR_DEFAULT;
413 }
414 }
415 // sy_lfr_n_cwf_long_f3
416
417 return flag;
418 }
419
420 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
421 {
422 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
423 *
424 * @param TC points to the TeleCommand packet that is being processed
425 * @param queue_id is the id of the queue which handles TM related to this execution step
426 *
427 */
428
429 int result;
430
431 result = LFR_SUCCESSFUL;
432
433 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
434 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
435
436 return result;
437 }
438
439 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
440 {
441 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
442 *
443 * @param TC points to the TeleCommand packet that is being processed
444 * @param queue_id is the id of the queue which handles TM related to this execution step
445 *
446 */
447
448 int result;
449
450 result = LFR_SUCCESSFUL;
451
452 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
453 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
454
455 return result;
456 }
457
458 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
459 {
460 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
461 *
462 * @param TC points to the TeleCommand packet that is being processed
463 * @param queue_id is the id of the queue which handles TM related to this execution step
464 *
465 */
466
467 int result;
468
469 result = LFR_SUCCESSFUL;
470
471 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
472 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
473
474 return result;
475 }
476
477 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
478 {
479 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
480 *
481 * @param TC points to the TeleCommand packet that is being processed
482 * @param queue_id is the id of the queue which handles TM related to this execution step
483 *
484 */
485
486 int status;
487
488 status = LFR_SUCCESSFUL;
489
490 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
491
492 return status;
493 }
494
495 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
496 {
497 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
498 *
499 * @param TC points to the TeleCommand packet that is being processed
500 * @param queue_id is the id of the queue which handles TM related to this execution step
501 *
502 */
503
504 int status;
505
506 status = LFR_SUCCESSFUL;
507
508 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
509
510 return status;
511 }
512
513 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
514 {
515 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
516 *
517 * @param TC points to the TeleCommand packet that is being processed
518 * @param queue_id is the id of the queue which handles TM related to this execution step
519 *
520 */
521
522 int status;
523
524 status = LFR_SUCCESSFUL;
525
526 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
527
528 return status;
529 }
530
531 //**********************
532 // BURST MODE PARAMETERS
533 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
534 {
535 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
536 *
537 * @param TC points to the TeleCommand packet that is being processed
538 * @param queue_id is the id of the queue which handles TM related to this execution step
539 *
540 */
541
542 int status;
543
544 status = LFR_SUCCESSFUL;
545
546 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
547
548 return status;
549 }
550
551 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
552 {
553 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
554 *
555 * @param TC points to the TeleCommand packet that is being processed
556 * @param queue_id is the id of the queue which handles TM related to this execution step
557 *
558 */
559
560 int status;
561
562 status = LFR_SUCCESSFUL;
563
564 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
565
566 return status;
567 }
568
569 //*********************
570 // SBM1 MODE PARAMETERS
571 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
572 {
573 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
574 *
575 * @param TC points to the TeleCommand packet that is being processed
576 * @param queue_id is the id of the queue which handles TM related to this execution step
577 *
578 */
579
580 int status;
581
582 status = LFR_SUCCESSFUL;
583
584 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
585
586 return status;
587 }
588
589 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
590 {
591 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
592 *
593 * @param TC points to the TeleCommand packet that is being processed
594 * @param queue_id is the id of the queue which handles TM related to this execution step
595 *
596 */
597
598 int status;
599
600 status = LFR_SUCCESSFUL;
601
602 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
603
604 return status;
605 }
606
607 //*********************
608 // SBM2 MODE PARAMETERS
609 int set_sy_lfr_s2_bp_p0(ccsdsTelecommandPacket_t *TC)
610 {
611 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
612 *
613 * @param TC points to the TeleCommand packet that is being processed
614 * @param queue_id is the id of the queue which handles TM related to this execution step
615 *
616 */
617
618 int status;
619
620 status = LFR_SUCCESSFUL;
621
622 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
623
624 return status;
625 }
626
627 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
628 {
629 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
630 *
631 * @param TC points to the TeleCommand packet that is being processed
632 * @param queue_id is the id of the queue which handles TM related to this execution step
633 *
634 */
635
636 int status;
637
638 status = LFR_SUCCESSFUL;
639
640 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
641
642 return status;
643 }
644
645
646 //*******************
647 // TC_LFR_UPDATE_INFO
648 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
649 {
650 unsigned int status;
651
652 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
653 || (mode == LFR_MODE_BURST)
654 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
655 {
656 status = LFR_SUCCESSFUL;
657 }
658 else
659 {
660 status = LFR_DEFAULT;
661 }
662
663 return status;
664 }
665
666 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
667 {
668 unsigned int status;
669
670 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
671 || (mode == TDS_MODE_BURST)
672 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
673 || (mode == TDS_MODE_LFM))
674 {
675 status = LFR_SUCCESSFUL;
676 }
677 else
678 {
679 status = LFR_DEFAULT;
680 }
681
682 return status;
683 }
684
685 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
686 {
687 unsigned int status;
688
689 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
690 || (mode == THR_MODE_BURST))
691 {
692 status = LFR_SUCCESSFUL;
693 }
694 else
695 {
696 status = LFR_DEFAULT;
697 }
698
699 return status;
700 }
701
702 //**********
703 // init dump
704
705 void init_parameter_dump( void )
706 {
707 /** This function initialize the parameter_dump_packet global variable with default values.
708 *
709 */
710
711 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
712 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
713 parameter_dump_packet.reserved = CCSDS_RESERVED;
714 parameter_dump_packet.userApplication = CCSDS_USER_APP;
715 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
716 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
717 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
718 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
719 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
720 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
721 // DATA FIELD HEADER
722 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
723 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
724 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
725 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
726 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
727 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
728 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
729 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
730 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
731 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
732 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
733
734 //******************
735 // COMMON PARAMETERS
736 parameter_dump_packet.unused0 = DEFAULT_SY_LFR_COMMON0;
737 parameter_dump_packet.bw_sp0_sp1_r0_r1 = DEFAULT_SY_LFR_COMMON1;
738
739 //******************
740 // NORMAL PARAMETERS
741 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
742 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
743 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
744 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
745 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
746 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
747 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
748 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
749 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
750
751 //*****************
752 // BURST PARAMETERS
753 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
754 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
755
756 //****************
757 // SBM1 PARAMETERS
758 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
759 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
760
761 //****************
762 // SBM2 PARAMETERS
763 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
764 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
765 }
766
767
768
769
770
771
772
This diff has been collapsed as it changes many lines, (510 lines changed) Show them Hide them
@@ -0,0 +1,510
1 /** Functions to send TM packets related to TC parsing and execution.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to send appropriate TM packets after parsing and execution:
7 * - TM_LFR_TC_EXE_SUCCESS
8 * - TM_LFR_TC_EXE_INCONSISTENT
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
11 * - TM_LFR_TC_EXE_ERROR
12 * - TM_LFR_TC_EXE_CORRUPTED
13 *
14 */
15
16 #include "tm_lfr_tc_exe.h"
17
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
19 {
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
21 *
22 * @param TC points to the TeleCommand packet that is being processed
23 * @param queue_id is the id of the queue which handles TM
24 *
25 * @return RTEMS directive status code:
26 * - RTEMS_SUCCESSFUL - message sent successfully
27 * - RTEMS_INVALID_ID - invalid queue id
28 * - RTEMS_INVALID_SIZE - invalid message size
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
30 * - RTEMS_UNSATISFIED - out of message buffers
31 * - RTEMS_TOO_MANY - queue s limit has been reached
32 *
33 */
34
35 rtems_status_code status;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
37 unsigned char messageSize;
38
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
41 TM.reserved = DEFAULT_RESERVED;
42 TM.userApplication = CCSDS_USER_APP;
43 // PACKET HEADER
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> 8);
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
49 // DATA FIELD HEADER
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
51 TM.serviceType = TM_TYPE_TC_EXE;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
53 TM.destinationID = TC->sourceID;
54 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
55 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
56 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
57 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
58 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
59 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
60 //
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
65
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
67
68 // SEND DATA
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
70 if (status != RTEMS_SUCCESSFUL) {
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
72 }
73
74 // UPDATE HK FIELDS
75 update_last_TC_exe( TC, TM.time );
76
77 return status;
78 }
79
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
81 unsigned char byte_position, unsigned char rcv_value )
82 {
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
84 *
85 * @param TC points to the TeleCommand packet that is being processed
86 * @param queue_id is the id of the queue which handles TM
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been deteced as inconsistent
89 *
90 * @return RTEMS directive status code:
91 * - RTEMS_SUCCESSFUL - message sent successfully
92 * - RTEMS_INVALID_ID - invalid queue id
93 * - RTEMS_INVALID_SIZE - invalid message size
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
95 * - RTEMS_UNSATISFIED - out of message buffers
96 * - RTEMS_TOO_MANY - queue s limit has been reached
97 *
98 */
99
100 rtems_status_code status;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
102 unsigned char messageSize;
103
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
106 TM.reserved = DEFAULT_RESERVED;
107 TM.userApplication = CCSDS_USER_APP;
108 // PACKET HEADER
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> 8);
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
114 // DATA FIELD HEADER
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
116 TM.serviceType = TM_TYPE_TC_EXE;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
118 TM.destinationID = TC->sourceID;
119 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
120 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
121 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
122 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
123 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
124 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
125 //
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> 8);
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
132 TM.tc_service = TC->serviceType; // type of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
134 TM.byte_position = byte_position;
135 TM.rcv_value = (unsigned char) rcv_value;
136
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
138
139 // SEND DATA
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
141 if (status != RTEMS_SUCCESSFUL) {
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
143 }
144
145 // UPDATE HK FIELDS
146 update_last_TC_rej( TC, TM.time );
147
148 return status;
149 }
150
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
152 {
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
154 *
155 * @param TC points to the TeleCommand packet that is being processed
156 * @param queue_id is the id of the queue which handles TM
157 *
158 * @return RTEMS directive status code:
159 * - RTEMS_SUCCESSFUL - message sent successfully
160 * - RTEMS_INVALID_ID - invalid queue id
161 * - RTEMS_INVALID_SIZE - invalid message size
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
163 * - RTEMS_UNSATISFIED - out of message buffers
164 * - RTEMS_TOO_MANY - queue s limit has been reached
165 *
166 */
167
168 rtems_status_code status;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
170 unsigned char messageSize;
171
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
174 TM.reserved = DEFAULT_RESERVED;
175 TM.userApplication = CCSDS_USER_APP;
176 // PACKET HEADER
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> 8);
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
182 // DATA FIELD HEADER
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
184 TM.serviceType = TM_TYPE_TC_EXE;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
186 TM.destinationID = TC->sourceID; // default destination id
187 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
188 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
189 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
190 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
191 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
192 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
193 //
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> 8);
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
200 TM.tc_service = TC->serviceType; // type of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
204
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
206
207 // SEND DATA
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
209 if (status != RTEMS_SUCCESSFUL) {
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
211 }
212
213 // UPDATE HK FIELDS
214 update_last_TC_rej( TC, TM.time );
215
216 return status;
217 }
218
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
220 {
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
222 *
223 * @param TC points to the TeleCommand packet that is being processed
224 * @param queue_id is the id of the queue which handles TM
225 *
226 * @return RTEMS directive status code:
227 * - RTEMS_SUCCESSFUL - message sent successfully
228 * - RTEMS_INVALID_ID - invalid queue id
229 * - RTEMS_INVALID_SIZE - invalid message size
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
231 * - RTEMS_UNSATISFIED - out of message buffers
232 * - RTEMS_TOO_MANY - queue s limit has been reached
233 *
234 */
235
236 rtems_status_code status;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
238 unsigned char messageSize;
239
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
242 TM.reserved = DEFAULT_RESERVED;
243 TM.userApplication = CCSDS_USER_APP;
244 // PACKET HEADER
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> 8);
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
250 // DATA FIELD HEADER
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
252 TM.serviceType = TM_TYPE_TC_EXE;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
254 TM.destinationID = TC->sourceID; // default destination id
255 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
256 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
257 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
258 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
259 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
260 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
261 //
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> 8);
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
268 TM.tc_service = TC->serviceType; // type of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
270
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
272
273 // SEND DATA
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
275 if (status != RTEMS_SUCCESSFUL) {
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
277 }
278
279 // UPDATE HK FIELDS
280 update_last_TC_rej( TC, TM.time );
281
282 return status;
283 }
284
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
286 {
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
288 *
289 * @param TC points to the TeleCommand packet that is being processed
290 * @param queue_id is the id of the queue which handles TM
291 *
292 * @return RTEMS directive status code:
293 * - RTEMS_SUCCESSFUL - message sent successfully
294 * - RTEMS_INVALID_ID - invalid queue id
295 * - RTEMS_INVALID_SIZE - invalid message size
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
297 * - RTEMS_UNSATISFIED - out of message buffers
298 * - RTEMS_TOO_MANY - queue s limit has been reached
299 *
300 */
301
302 rtems_status_code status;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
304 unsigned char messageSize;
305
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
308 TM.reserved = DEFAULT_RESERVED;
309 TM.userApplication = CCSDS_USER_APP;
310 // PACKET HEADER
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> 8);
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
316 // DATA FIELD HEADER
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
318 TM.serviceType = TM_TYPE_TC_EXE;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
320 TM.destinationID = TC->sourceID; // default destination id
321 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
322 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
323 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
324 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
325 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
326 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
327 //
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> 8);
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
334 TM.tc_service = TC->serviceType; // type of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
336
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
338
339 // SEND DATA
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
341 if (status != RTEMS_SUCCESSFUL) {
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
343 }
344
345 // UPDATE HK FIELDS
346 update_last_TC_rej( TC, TM.time );
347
348 return status;
349 }
350
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
353 unsigned char destinationID )
354 {
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
356 *
357 * @param TC points to the TeleCommand packet that is being processed
358 * @param queue_id is the id of the queue which handles TM
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
361 *
362 * @return RTEMS directive status code:
363 * - RTEMS_SUCCESSFUL - message sent successfully
364 * - RTEMS_INVALID_ID - invalid queue id
365 * - RTEMS_INVALID_SIZE - invalid message size
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
367 * - RTEMS_UNSATISFIED - out of message buffers
368 * - RTEMS_TOO_MANY - queue s limit has been reached
369 *
370 */
371
372 rtems_status_code status;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
374 unsigned char messageSize;
375 unsigned int packetLength;
376 unsigned char *packetDataField;
377
378 packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1]; // compute the packet length parameter
379 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
380
381 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
382 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
383 TM.reserved = DEFAULT_RESERVED;
384 TM.userApplication = CCSDS_USER_APP;
385 // PACKET HEADER
386 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
387 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
388 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
389 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> 8);
390 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
391 // DATA FIELD HEADER
392 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
393 TM.serviceType = TM_TYPE_TC_EXE;
394 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
395 TM.destinationID = destinationID;
396 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
397 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
398 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
399 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
400 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
401 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
402 //
403 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> 8);
404 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
405 TM.telecommand_pkt_id[0] = TC->packetID[0];
406 TM.telecommand_pkt_id[1] = TC->packetID[1];
407 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
408 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
409 TM.tc_service = TC->serviceType; // type of the rejected TC
410 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
411 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
412 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
413 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
414 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
415 TM.rcv_crc[0] = packetDataField[ packetLength - 1 ];
416 TM.rcv_crc[1] = packetDataField[ packetLength ];
417 TM.computed_crc[0] = computed_CRC[0];
418 TM.computed_crc[1] = computed_CRC[1];
419
420 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
421
422 // SEND DATA
423 status = rtems_message_queue_send( queue_id, &TM, messageSize);
424 if (status != RTEMS_SUCCESSFUL) {
425 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
426 }
427
428 // UPDATE HK FIELDS
429 update_last_TC_rej( TC, TM.time );
430
431 return status;
432 }
433
434 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
435 {
436 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
437 *
438 * @param packet_sequence_control points to the packet sequence control which will be incremented
439 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
440 *
441 * If the destination ID is not known, a dedicated counter is incremented.
442 *
443 */
444
445 unsigned short sequence_cnt;
446 unsigned short segmentation_grouping_flag;
447 unsigned short new_packet_sequence_control;
448 unsigned char i;
449
450 switch (destination_id)
451 {
452 case SID_TC_GROUND:
453 i = GROUND;
454 break;
455 case SID_TC_MISSION_TIMELINE:
456 i = MISSION_TIMELINE;
457 break;
458 case SID_TC_TC_SEQUENCES:
459 i = TC_SEQUENCES;
460 break;
461 case SID_TC_RECOVERY_ACTION_CMD:
462 i = RECOVERY_ACTION_CMD;
463 break;
464 case SID_TC_BACKUP_MISSION_TIMELINE:
465 i = BACKUP_MISSION_TIMELINE;
466 break;
467 case SID_TC_DIRECT_CMD:
468 i = DIRECT_CMD;
469 break;
470 case SID_TC_SPARE_GRD_SRC1:
471 i = SPARE_GRD_SRC1;
472 break;
473 case SID_TC_SPARE_GRD_SRC2:
474 i = SPARE_GRD_SRC2;
475 break;
476 case SID_TC_OBCP:
477 i = OBCP;
478 break;
479 case SID_TC_SYSTEM_CONTROL:
480 i = SYSTEM_CONTROL;
481 break;
482 case SID_TC_AOCS:
483 i = AOCS;
484 break;
485 case SID_TC_RPW_INTERNAL:
486 i = RPW_INTERNAL;
487 break;
488 default:
489 i = GROUND;
490 break;
491 }
492
493 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
494 sequence_cnt = sequenceCounters_TC_EXE[ i ] & 0x3fff;
495
496 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
497
498 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
499 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
500
501 // increment the sequence counter
502 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
503 {
504 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
505 }
506 else
507 {
508 sequenceCounters_TC_EXE[ i ] = 0;
509 }
510 }
This diff has been collapsed as it changes many lines, (1323 lines changed) Show them Hide them
@@ -0,0 +1,1323
1 /** Functions and tasks related to waveform packet generation.
2 *
3 * @file
4 * @author P. LEROY
5 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
8 */
9
10 #include "wf_handler.h"
11
12 //*****************
13 // waveform headers
14 // SWF
15 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7];
16 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7];
17 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7];
18 // CWF
19 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ];
20 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ];
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ];
22 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ];
23 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ];
24
25 //**************
26 // waveform ring
27 ring_node waveform_ring_f0[NB_RING_NODES_F0];
28 ring_node waveform_ring_f1[NB_RING_NODES_F1];
29 ring_node waveform_ring_f2[NB_RING_NODES_F2];
30 ring_node waveform_ring_f3[NB_RING_NODES_F3];
31 ring_node *current_ring_node_f0;
32 ring_node *ring_node_to_send_swf_f0;
33 ring_node *current_ring_node_f1;
34 ring_node *ring_node_to_send_swf_f1;
35 ring_node *ring_node_to_send_cwf_f1;
36 ring_node *current_ring_node_f2;
37 ring_node *ring_node_to_send_swf_f2;
38 ring_node *ring_node_to_send_cwf_f2;
39 ring_node *current_ring_node_f3;
40 ring_node *ring_node_to_send_cwf_f3;
41
42 bool extractSWF = false;
43 bool swf_f0_ready = false;
44 bool swf_f1_ready = false;
45 bool swf_f2_ready = false;
46
47 int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
48
49 //*********************
50 // Interrupt SubRoutine
51
52 void reset_extractSWF( void )
53 {
54 extractSWF = false;
55 swf_f0_ready = false;
56 swf_f1_ready = false;
57 swf_f2_ready = false;
58 }
59
60 rtems_isr waveforms_isr( rtems_vector_number vector )
61 {
62 /** This is the interrupt sub routine called by the waveform picker core.
63 *
64 * This ISR launch different actions depending mainly on two pieces of information:
65 * 1. the values read in the registers of the waveform picker.
66 * 2. the current LFR mode.
67 *
68 */
69
70 rtems_status_code status;
71 rtems_status_code spare_status;
72
73 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
74 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
75 { // in modes other than STANDBY and BURST, send the CWF_F3 data
76 if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full
77 // (1) change the receiving buffer for the waveform picker
78 ring_node_to_send_cwf_f3 = current_ring_node_f3;
79 current_ring_node_f3 = current_ring_node_f3->next;
80 waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address;
81 // (2) send an event for the waveforms transmission
82 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
83 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
84 }
85 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2);
86 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111]
87 }
88 }
89
90 switch(lfrCurrentMode)
91 {
92 //********
93 // STANDBY
94 case(LFR_MODE_STANDBY):
95 break;
96
97 //******
98 // NORMAL
99 case(LFR_MODE_NORMAL):
100 if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits
101 {
102 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
103 }
104 if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits
105 {
106 // change F0 ring node
107 ring_node_to_send_swf_f0 = current_ring_node_f0;
108 current_ring_node_f0 = current_ring_node_f0->next;
109 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address;
110 // change F1 ring node
111 ring_node_to_send_swf_f1 = current_ring_node_f1;
112 current_ring_node_f1 = current_ring_node_f1->next;
113 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
114 // change F2 ring node
115 ring_node_to_send_swf_f2 = current_ring_node_f2;
116 current_ring_node_f2 = current_ring_node_f2->next;
117 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
118 //
119 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL)
120 {
121 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
122 }
123 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000]
124 }
125 break;
126
127 //******
128 // BURST
129 case(LFR_MODE_BURST):
130 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
131 // (1) change the receiving buffer for the waveform picker
132 ring_node_to_send_cwf_f2 = current_ring_node_f2;
133 current_ring_node_f2 = current_ring_node_f2->next;
134 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
135 // (2) send an event for the waveforms transmission
136 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
137 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
138 }
139 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
140 }
141 break;
142
143 //*****
144 // SBM1
145 case(LFR_MODE_SBM1):
146 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
147 // (1) change the receiving buffer for the waveform picker
148 ring_node_to_send_cwf_f1 = current_ring_node_f1;
149 current_ring_node_f1 = current_ring_node_f1->next;
150 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address;
151 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
152 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 );
153 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bits = 0
154 }
155 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
156 swf_f0_ready = true;
157 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0
158 }
159 if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit
160 swf_f2_ready = true;
161 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0
162 }
163 break;
164
165 //*****
166 // SBM2
167 case(LFR_MODE_SBM2):
168 if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit
169 // (1) change the receiving buffer for the waveform picker
170 ring_node_to_send_cwf_f2 = current_ring_node_f2;
171 current_ring_node_f2 = current_ring_node_f2->next;
172 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address;
173 // (2) send an event for the waveforms transmission
174 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 );
175 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
176 }
177 if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit
178 swf_f0_ready = true;
179 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0
180 }
181 if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit
182 swf_f1_ready = true;
183 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1, f0 bits = 0
184 }
185 break;
186
187 //********
188 // DEFAULT
189 default:
190 break;
191 }
192 }
193
194 //************
195 // RTEMS TASKS
196
197 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
198 {
199 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
200 *
201 * @param unused is the starting argument of the RTEMS task
202 *
203 * The following data packets are sent by this task:
204 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
205 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
206 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
207 *
208 */
209
210 rtems_event_set event_out;
211 rtems_id queue_id;
212 rtems_status_code status;
213
214 init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 );
215 init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 );
216 init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 );
217
218 status = get_message_queue_id_send( &queue_id );
219 if (status != RTEMS_SUCCESSFUL)
220 {
221 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
222 }
223
224 BOOT_PRINTF("in WFRM ***\n")
225
226 while(1){
227 // wait for an RTEMS_EVENT
228 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
229 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
230 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
231 if (event_out == RTEMS_EVENT_MODE_NORMAL)
232 {
233 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n")
234 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
235 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
236 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
237 }
238 if (event_out == RTEMS_EVENT_MODE_SBM1)
239 {
240 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n")
241 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
242 send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F1, headerSWF_F1, queue_id);
243 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
244 }
245 if (event_out == RTEMS_EVENT_MODE_SBM2)
246 {
247 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n")
248 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
249 send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
250 send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F2, headerSWF_F2, queue_id);
251 }
252 }
253 }
254
255 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
256 {
257 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
258 *
259 * @param unused is the starting argument of the RTEMS task
260 *
261 * The following data packet is sent by this task:
262 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
263 *
264 */
265
266 rtems_event_set event_out;
267 rtems_id queue_id;
268 rtems_status_code status;
269
270 init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 );
271 init_header_continuous_cwf3_light_table( headerCWF_F3_light );
272
273 status = get_message_queue_id_send( &queue_id );
274 if (status != RTEMS_SUCCESSFUL)
275 {
276 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
277 }
278
279 BOOT_PRINTF("in CWF3 ***\n")
280
281 while(1){
282 // wait for an RTEMS_EVENT
283 rtems_event_receive( RTEMS_EVENT_0,
284 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
285 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
286 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
287 {
288 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
289 {
290 PRINTF("send CWF_LONG_F3\n")
291 send_waveform_CWF(
292 (volatile int*) ring_node_to_send_cwf_f3->buffer_address,
293 SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id );
294 }
295 else
296 {
297 PRINTF("send CWF_F3 (light)\n")
298 send_waveform_CWF3_light(
299 (volatile int*) ring_node_to_send_cwf_f3->buffer_address,
300 headerCWF_F3_light, queue_id );
301 }
302
303 }
304 else
305 {
306 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
307 }
308 }
309 }
310
311 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
312 {
313 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
314 *
315 * @param unused is the starting argument of the RTEMS task
316 *
317 * The following data packet is sent by this function:
318 * - TM_LFR_SCIENCE_BURST_CWF_F2
319 * - TM_LFR_SCIENCE_SBM2_CWF_F2
320 *
321 */
322
323 rtems_event_set event_out;
324 rtems_id queue_id;
325 rtems_status_code status;
326
327 init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST );
328 init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 );
329
330 status = get_message_queue_id_send( &queue_id );
331 if (status != RTEMS_SUCCESSFUL)
332 {
333 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
334 }
335
336 BOOT_PRINTF("in CWF2 ***\n")
337
338 while(1){
339 // wait for an RTEMS_EVENT
340 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
341 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
342 if (event_out == RTEMS_EVENT_MODE_BURST)
343 {
344 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
345 }
346 if (event_out == RTEMS_EVENT_MODE_SBM2)
347 {
348 send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
349 // launch snapshot extraction if needed
350 if (extractSWF == true)
351 {
352 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
353 // extract the snapshot
354 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 );
355 // send the snapshot when built
356 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
357 extractSWF = false;
358 }
359 if (swf_f0_ready && swf_f1_ready)
360 {
361 extractSWF = true;
362 swf_f0_ready = false;
363 swf_f1_ready = false;
364 }
365 }
366 }
367 }
368
369 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
370 {
371 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
372 *
373 * @param unused is the starting argument of the RTEMS task
374 *
375 * The following data packet is sent by this function:
376 * - TM_LFR_SCIENCE_SBM1_CWF_F1
377 *
378 */
379
380 rtems_event_set event_out;
381 rtems_id queue_id;
382 rtems_status_code status;
383
384 init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
385
386 status = get_message_queue_id_send( &queue_id );
387 if (status != RTEMS_SUCCESSFUL)
388 {
389 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
390 }
391
392 BOOT_PRINTF("in CWF1 ***\n")
393
394 while(1){
395 // wait for an RTEMS_EVENT
396 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
397 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
398 send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
399 // launch snapshot extraction if needed
400 if (extractSWF == true)
401 {
402 ring_node_to_send_swf_f1 = ring_node_to_send_cwf_f1;
403 // launch the snapshot extraction
404 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 );
405 extractSWF = false;
406 }
407 if (swf_f0_ready == true)
408 {
409 extractSWF = true;
410 swf_f0_ready = false; // this step shall be executed only one time
411 }
412 if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction
413 {
414 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 );
415 swf_f1_ready = false;
416 swf_f2_ready = false;
417 }
418 }
419 }
420
421 rtems_task swbd_task(rtems_task_argument argument)
422 {
423 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
424 *
425 * @param unused is the starting argument of the RTEMS task
426 *
427 */
428
429 rtems_event_set event_out;
430
431 BOOT_PRINTF("in SWBD ***\n")
432
433 while(1){
434 // wait for an RTEMS_EVENT
435 rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2,
436 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
437 if (event_out == RTEMS_EVENT_MODE_SBM1)
438 {
439 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 );
440 swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent
441 }
442 else
443 {
444 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
445 }
446 }
447 }
448
449 //******************
450 // general functions
451
452 void WFP_init_rings( void )
453 {
454 // F0 RING
455 init_waveform_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_snap_f0 );
456 // F1 RING
457 init_waveform_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_snap_f1 );
458 // F2 RING
459 init_waveform_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_snap_f2 );
460 // F3 RING
461 init_waveform_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_cont_f3 );
462
463 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
464 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
465 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
466 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
467 }
468
469 void init_waveform_ring(ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] )
470 {
471 unsigned char i;
472
473 waveform_ring[0].next = (ring_node*) &waveform_ring[ 1 ];
474 waveform_ring[0].previous = (ring_node*) &waveform_ring[ nbNodes - 1 ];
475 waveform_ring[0].buffer_address = (int) &wfrm[0];
476
477 waveform_ring[nbNodes-1].next = (ring_node*) &waveform_ring[ 0 ];
478 waveform_ring[nbNodes-1].previous = (ring_node*) &waveform_ring[ nbNodes - 2 ];
479 waveform_ring[nbNodes-1].buffer_address = (int) &wfrm[ (nbNodes-1) * WFRM_BUFFER ];
480
481 for(i=1; i<nbNodes-1; i++)
482 {
483 waveform_ring[i].next = (ring_node*) &waveform_ring[ i + 1 ];
484 waveform_ring[i].previous = (ring_node*) &waveform_ring[ i - 1 ];
485 waveform_ring[i].buffer_address = (int) &wfrm[ i * WFRM_BUFFER ];
486 }
487 }
488
489 void WFP_reset_current_ring_nodes( void )
490 {
491 current_ring_node_f0 = waveform_ring_f0;
492 ring_node_to_send_swf_f0 = waveform_ring_f0;
493
494 current_ring_node_f1 = waveform_ring_f1;
495 ring_node_to_send_cwf_f1 = waveform_ring_f1;
496 ring_node_to_send_swf_f1 = waveform_ring_f1;
497
498 current_ring_node_f2 = waveform_ring_f2;
499 ring_node_to_send_cwf_f2 = waveform_ring_f2;
500 ring_node_to_send_swf_f2 = waveform_ring_f2;
501
502 current_ring_node_f3 = waveform_ring_f3;
503 ring_node_to_send_cwf_f3 = waveform_ring_f3;
504 }
505
506 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF)
507 {
508 unsigned char i;
509 int return_value;
510
511 return_value = LFR_SUCCESSFUL;
512
513 for (i=0; i<7; i++)
514 {
515 headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
516 headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
517 headerSWF[ i ].reserved = DEFAULT_RESERVED;
518 headerSWF[ i ].userApplication = CCSDS_USER_APP;
519 headerSWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
520 headerSWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
521 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
522 if (i == 6)
523 {
524 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
525 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
526 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
527 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 );
528 }
529 else
530 {
531 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
532 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
533 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
534 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 );
535 }
536 headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
537 headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT
538 headerSWF[ i ].pktNr = i+1; // PKT_NR
539 // DATA FIELD HEADER
540 headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
541 headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
542 headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
543 headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
544 // AUXILIARY DATA HEADER
545 headerSWF[ i ].time[0] = 0x00;
546 headerSWF[ i ].time[0] = 0x00;
547 headerSWF[ i ].time[0] = 0x00;
548 headerSWF[ i ].time[0] = 0x00;
549 headerSWF[ i ].time[0] = 0x00;
550 headerSWF[ i ].time[0] = 0x00;
551 headerSWF[ i ].sid = sid;
552 headerSWF[ i ].hkBIA = DEFAULT_HKBIA;
553 }
554
555 return return_value;
556 }
557
558 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
559 {
560 unsigned int i;
561 int return_value;
562
563 return_value = LFR_SUCCESSFUL;
564
565 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++)
566 {
567 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
568 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
569 headerCWF[ i ].reserved = DEFAULT_RESERVED;
570 headerCWF[ i ].userApplication = CCSDS_USER_APP;
571 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
572 {
573 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
574 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
575 }
576 else
577 {
578 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
579 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
580 }
581 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
582 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
583 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
584 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
585 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF );
586 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
587 // DATA FIELD HEADER
588 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
589 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
590 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
591 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
592 // AUXILIARY DATA HEADER
593 headerCWF[ i ].sid = sid;
594 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
595 headerCWF[ i ].time[0] = 0x00;
596 headerCWF[ i ].time[0] = 0x00;
597 headerCWF[ i ].time[0] = 0x00;
598 headerCWF[ i ].time[0] = 0x00;
599 headerCWF[ i ].time[0] = 0x00;
600 headerCWF[ i ].time[0] = 0x00;
601 }
602
603 return return_value;
604 }
605
606 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
607 {
608 unsigned int i;
609 int return_value;
610
611 return_value = LFR_SUCCESSFUL;
612
613 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++)
614 {
615 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
616 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
617 headerCWF[ i ].reserved = DEFAULT_RESERVED;
618 headerCWF[ i ].userApplication = CCSDS_USER_APP;
619
620 headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
621 headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
622
623 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
624 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
625 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
626 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
627 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
628
629 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
630 // DATA FIELD HEADER
631 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
632 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
633 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
634 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
635 // AUXILIARY DATA HEADER
636 headerCWF[ i ].sid = SID_NORM_CWF_F3;
637 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
638 headerCWF[ i ].time[0] = 0x00;
639 headerCWF[ i ].time[0] = 0x00;
640 headerCWF[ i ].time[0] = 0x00;
641 headerCWF[ i ].time[0] = 0x00;
642 headerCWF[ i ].time[0] = 0x00;
643 headerCWF[ i ].time[0] = 0x00;
644 }
645
646 return return_value;
647 }
648
649 int send_waveform_SWF( volatile int *waveform, unsigned int sid,
650 Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id )
651 {
652 /** This function sends SWF CCSDS packets (F2, F1 or F0).
653 *
654 * @param waveform points to the buffer containing the data that will be send.
655 * @param sid is the source identifier of the data that will be sent.
656 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
657 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
658 * contain information to setup the transmission of the data packets.
659 *
660 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
661 *
662 */
663
664 unsigned int i;
665 int ret;
666 unsigned int coarseTime;
667 unsigned int fineTime;
668 rtems_status_code status;
669 spw_ioctl_pkt_send spw_ioctl_send_SWF;
670
671 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
672 spw_ioctl_send_SWF.options = 0;
673
674 ret = LFR_DEFAULT;
675
676 coarseTime = waveform[0];
677 fineTime = waveform[1];
678
679 for (i=0; i<7; i++) // send waveform
680 {
681 spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET];
682 spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ];
683 // BUILD THE DATA
684 if (i==6) {
685 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
686 }
687 else {
688 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
689 }
690 // SET PACKET SEQUENCE COUNTER
691 increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid );
692 // SET PACKET TIME
693 compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime );
694 //
695 headerSWF[ i ].time[0] = headerSWF[ i ].acquisitionTime[0];
696 headerSWF[ i ].time[1] = headerSWF[ i ].acquisitionTime[1];
697 headerSWF[ i ].time[2] = headerSWF[ i ].acquisitionTime[2];
698 headerSWF[ i ].time[3] = headerSWF[ i ].acquisitionTime[3];
699 headerSWF[ i ].time[4] = headerSWF[ i ].acquisitionTime[4];
700 headerSWF[ i ].time[5] = headerSWF[ i ].acquisitionTime[5];
701 // SEND PACKET
702 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
703 if (status != RTEMS_SUCCESSFUL) {
704 printf("%d-%d, ERR %d\n", sid, i, (int) status);
705 ret = LFR_DEFAULT;
706 }
707 rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
708 }
709
710 return ret;
711 }
712
713 int send_waveform_CWF(volatile int *waveform, unsigned int sid,
714 Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
715 {
716 /** This function sends CWF CCSDS packets (F2, F1 or F0).
717 *
718 * @param waveform points to the buffer containing the data that will be send.
719 * @param sid is the source identifier of the data that will be sent.
720 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
721 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
722 * contain information to setup the transmission of the data packets.
723 *
724 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
725 *
726 */
727
728 unsigned int i;
729 int ret;
730 unsigned int coarseTime;
731 unsigned int fineTime;
732 rtems_status_code status;
733 spw_ioctl_pkt_send spw_ioctl_send_CWF;
734
735 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
736 spw_ioctl_send_CWF.options = 0;
737
738 ret = LFR_DEFAULT;
739
740 coarseTime = waveform[0];
741 fineTime = waveform[1];
742
743 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
744 {
745 spw_ioctl_send_CWF.data = (char*) &waveform[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) + TIME_OFFSET];
746 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
747 // BUILD THE DATA
748 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
749 // SET PACKET SEQUENCE COUNTER
750 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid );
751 // SET PACKET TIME
752 compute_acquisition_time( coarseTime, fineTime, sid, i, headerCWF[ i ].acquisitionTime);
753 //
754 headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0];
755 headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1];
756 headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2];
757 headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3];
758 headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4];
759 headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5];
760 // SEND PACKET
761 if (sid == SID_NORM_CWF_LONG_F3)
762 {
763 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
764 if (status != RTEMS_SUCCESSFUL) {
765 printf("%d-%d, ERR %d\n", sid, i, (int) status);
766 ret = LFR_DEFAULT;
767 }
768 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
769 }
770 else
771 {
772 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
773 if (status != RTEMS_SUCCESSFUL) {
774 printf("%d-%d, ERR %d\n", sid, i, (int) status);
775 ret = LFR_DEFAULT;
776 }
777 }
778 }
779
780 return ret;
781 }
782
783 int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
784 {
785 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
786 *
787 * @param waveform points to the buffer containing the data that will be send.
788 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
789 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
790 * contain information to setup the transmission of the data packets.
791 *
792 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
793 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
794 *
795 */
796
797 unsigned int i;
798 int ret;
799 unsigned int coarseTime;
800 unsigned int fineTime;
801 rtems_status_code status;
802 spw_ioctl_pkt_send spw_ioctl_send_CWF;
803 char *sample;
804
805 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
806 spw_ioctl_send_CWF.options = 0;
807
808 ret = LFR_DEFAULT;
809
810 //**********************
811 // BUILD CWF3_light DATA
812 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
813 {
814 sample = (char*) &waveform[ (i * NB_WORDS_SWF_BLK) + TIME_OFFSET ];
815 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES ] = sample[ 0 ];
816 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 + TIME_OFFSET_IN_BYTES ] = sample[ 1 ];
817 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 + TIME_OFFSET_IN_BYTES ] = sample[ 2 ];
818 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 + TIME_OFFSET_IN_BYTES ] = sample[ 3 ];
819 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 + TIME_OFFSET_IN_BYTES ] = sample[ 4 ];
820 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 + TIME_OFFSET_IN_BYTES ] = sample[ 5 ];
821 }
822
823 coarseTime = waveform[0];
824 fineTime = waveform[1];
825
826 //*********************
827 // SEND CWF3_light DATA
828 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
829 {
830 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) + TIME_OFFSET_IN_BYTES];
831 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
832 // BUILD THE DATA
833 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
834 // SET PACKET SEQUENCE COUNTER
835 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 );
836 // SET PACKET TIME
837 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, headerCWF[ i ].acquisitionTime );
838 //
839 headerCWF[ i ].time[0] = headerCWF[ i ].acquisitionTime[0];
840 headerCWF[ i ].time[1] = headerCWF[ i ].acquisitionTime[1];
841 headerCWF[ i ].time[2] = headerCWF[ i ].acquisitionTime[2];
842 headerCWF[ i ].time[3] = headerCWF[ i ].acquisitionTime[3];
843 headerCWF[ i ].time[4] = headerCWF[ i ].acquisitionTime[4];
844 headerCWF[ i ].time[5] = headerCWF[ i ].acquisitionTime[5];
845 // SEND PACKET
846 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
847 if (status != RTEMS_SUCCESSFUL) {
848 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
849 ret = LFR_DEFAULT;
850 }
851 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
852 }
853
854 return ret;
855 }
856
857 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
858 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
859 {
860 unsigned long long int acquisitionTimeAsLong;
861 unsigned char localAcquisitionTime[6];
862 double deltaT;
863
864 deltaT = 0.;
865
866 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 );
867 localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 );
868 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 );
869 localAcquisitionTime[3] = (unsigned char) ( coarseTime );
870 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 );
871 localAcquisitionTime[5] = (unsigned char) ( fineTime );
872
873 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
874 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
875 + ( (unsigned long long int) localAcquisitionTime[2] << 24 )
876 + ( (unsigned long long int) localAcquisitionTime[3] << 16 )
877 + ( (unsigned long long int) localAcquisitionTime[4] << 8 )
878 + ( (unsigned long long int) localAcquisitionTime[5] );
879
880 switch( sid )
881 {
882 case SID_NORM_SWF_F0:
883 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
884 break;
885
886 case SID_NORM_SWF_F1:
887 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
888 break;
889
890 case SID_NORM_SWF_F2:
891 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
892 break;
893
894 case SID_SBM1_CWF_F1:
895 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
896 break;
897
898 case SID_SBM2_CWF_F2:
899 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
900 break;
901
902 case SID_BURST_CWF_F2:
903 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
904 break;
905
906 case SID_NORM_CWF_F3:
907 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
908 break;
909
910 case SID_NORM_CWF_LONG_F3:
911 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
912 break;
913
914 default:
915 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid)
916 deltaT = 0.;
917 break;
918 }
919
920 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
921 //
922 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
923 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
924 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
925 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
926 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
927 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
928
929 }
930
931 void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel )
932 {
933 unsigned int i;
934 unsigned long long int centerTime_asLong;
935 unsigned long long int acquisitionTimeF0_asLong;
936 unsigned long long int acquisitionTime_asLong;
937 unsigned long long int bufferAcquisitionTime_asLong;
938 unsigned char *ptr1;
939 unsigned char *ptr2;
940 unsigned char *timeCharPtr;
941 unsigned char nb_ring_nodes;
942 unsigned long long int frequency_asLong;
943 unsigned long long int nbTicksPerSample_asLong;
944 unsigned long long int nbSamplesPart1_asLong;
945 unsigned long long int sampleOffset_asLong;
946
947 unsigned int deltaT_F0;
948 unsigned int deltaT_F1;
949 unsigned long long int deltaT_F2;
950
951 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
952 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
953 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
954 sampleOffset_asLong = 0x00;
955
956 // (1) get the f0 acquisition time
957 build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 );
958
959 // (2) compute the central reference time
960 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
961
962 // (3) compute the acquisition time of the current snapshot
963 switch(frequencyChannel)
964 {
965 case 1: // 1 is for F1 = 4096 Hz
966 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
967 nb_ring_nodes = NB_RING_NODES_F1;
968 frequency_asLong = 4096;
969 nbTicksPerSample_asLong = 16; // 65536 / 4096;
970 break;
971 case 2: // 2 is for F2 = 256 Hz
972 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
973 nb_ring_nodes = NB_RING_NODES_F2;
974 frequency_asLong = 256;
975 nbTicksPerSample_asLong = 256; // 65536 / 256;
976 break;
977 default:
978 acquisitionTime_asLong = centerTime_asLong;
979 frequency_asLong = 256;
980 nbTicksPerSample_asLong = 256;
981 break;
982 }
983
984 //****************************************************************************
985 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
986 for (i=0; i<nb_ring_nodes; i++)
987 {
988 PRINTF1("%d ... ", i)
989 build_acquisition_time( &bufferAcquisitionTime_asLong, ring_node_to_send );
990 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
991 {
992 PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong)
993 break;
994 }
995 ring_node_to_send = ring_node_to_send->previous;
996 }
997
998 // (5) compute the number of samples to take in the current buffer
999 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
1000 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
1001 PRINTF2("sampleOffset_asLong = %llx, nbSamplesPart1_asLong = %llx\n", sampleOffset_asLong, nbSamplesPart1_asLong)
1002
1003 // (6) compute the final acquisition time
1004 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
1005 sampleOffset_asLong * nbTicksPerSample_asLong;
1006
1007 // (7) copy the acquisition time at the beginning of the extrated snapshot
1008 ptr1 = (unsigned char*) &acquisitionTime_asLong;
1009 ptr2 = (unsigned char*) wf_snap_extracted;
1010 ptr2[0] = ptr1[ 0 + 2 ];
1011 ptr2[1] = ptr1[ 1 + 2 ];
1012 ptr2[2] = ptr1[ 2 + 2 ];
1013 ptr2[3] = ptr1[ 3 + 2 ];
1014 ptr2[6] = ptr1[ 4 + 2 ];
1015 ptr2[7] = ptr1[ 5 + 2 ];
1016
1017 // re set the synchronization bit
1018 timeCharPtr = (unsigned char*) ring_node_to_send->buffer_address;
1019 ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000]
1020
1021 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
1022 {
1023 nbSamplesPart1_asLong = 0;
1024 }
1025 // copy the part 1 of the snapshot in the extracted buffer
1026 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
1027 {
1028 wf_snap_extracted[i + TIME_OFFSET] =
1029 ((int*) ring_node_to_send->buffer_address)[i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) + TIME_OFFSET];
1030 }
1031 // copy the part 2 of the snapshot in the extracted buffer
1032 ring_node_to_send = ring_node_to_send->next;
1033 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
1034 {
1035 wf_snap_extracted[i + TIME_OFFSET] =
1036 ((int*) ring_node_to_send->buffer_address)[(i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) + TIME_OFFSET];
1037 }
1038 }
1039
1040 void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node )
1041 {
1042 unsigned char *acquisitionTimeCharPtr;
1043
1044 acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address;
1045
1046 *acquisitionTimeAslong = 0x00;
1047 *acquisitionTimeAslong = ( (unsigned long long int) (acquisitionTimeCharPtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
1048 + ( (unsigned long long int) acquisitionTimeCharPtr[1] << 32 )
1049 + ( (unsigned long long int) acquisitionTimeCharPtr[2] << 24 )
1050 + ( (unsigned long long int) acquisitionTimeCharPtr[3] << 16 )
1051 + ( (unsigned long long int) acquisitionTimeCharPtr[6] << 8 )
1052 + ( (unsigned long long int) acquisitionTimeCharPtr[7] );
1053 }
1054
1055 //**************
1056 // wfp registers
1057 void reset_wfp_burst_enable(void)
1058 {
1059 /** This function resets the waveform picker burst_enable register.
1060 *
1061 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1062 *
1063 */
1064
1065 waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1066 }
1067
1068 void reset_wfp_status( void )
1069 {
1070 /** This function resets the waveform picker status register.
1071 *
1072 * All status bits are set to 0 [new_err full_err full].
1073 *
1074 */
1075
1076 waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1077 }
1078
1079 void reset_waveform_picker_regs(void)
1080 {
1081 /** This function resets the waveform picker module registers.
1082 *
1083 * The registers affected by this function are located at the following offset addresses:
1084 * - 0x00 data_shaping
1085 * - 0x04 run_burst_enable
1086 * - 0x08 addr_data_f0
1087 * - 0x0C addr_data_f1
1088 * - 0x10 addr_data_f2
1089 * - 0x14 addr_data_f3
1090 * - 0x18 status
1091 * - 0x1C delta_snapshot
1092 * - 0x20 delta_f0
1093 * - 0x24 delta_f0_2
1094 * - 0x28 delta_f1
1095 * - 0x2c delta_f2
1096 * - 0x30 nb_data_by_buffer
1097 * - 0x34 nb_snapshot_param
1098 * - 0x38 start_date
1099 * - 0x3c nb_word_in_buffer
1100 *
1101 */
1102
1103 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1104 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1105 waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08
1106 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c
1107 waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10
1108 waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; // 0x14
1109 reset_wfp_status(); // 0x18
1110 //
1111 set_wfp_delta_snapshot(); // 0x1c
1112 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1113 set_wfp_delta_f1(); // 0x28
1114 set_wfp_delta_f2(); // 0x2c
1115 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1116 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1117 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1118 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1119 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1120 // 2688 = 8 * 336
1121 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1122 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1123 waveform_picker_regs->start_date = 0x00; // 0x38
1124 waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066
1125 }
1126
1127 void set_wfp_data_shaping( void )
1128 {
1129 /** This function sets the data_shaping register of the waveform picker module.
1130 *
1131 * The value is read from one field of the parameter_dump_packet structure:\n
1132 * bw_sp0_sp1_r0_r1
1133 *
1134 */
1135
1136 unsigned char data_shaping;
1137
1138 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1139 // waveform picker : [R1 R0 SP1 SP0 BW]
1140
1141 data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1;
1142
1143 waveform_picker_regs->data_shaping =
1144 ( (data_shaping & 0x10) >> 4 ) // BW
1145 + ( (data_shaping & 0x08) >> 2 ) // SP0
1146 + ( (data_shaping & 0x04) ) // SP1
1147 + ( (data_shaping & 0x02) << 2 ) // R0
1148 + ( (data_shaping & 0x01) << 4 ); // R1
1149 }
1150
1151 void set_wfp_burst_enable_register( unsigned char mode )
1152 {
1153 /** This function sets the waveform picker burst_enable register depending on the mode.
1154 *
1155 * @param mode is the LFR mode to launch.
1156 *
1157 * The burst bits shall be before the enable bits.
1158 *
1159 */
1160
1161 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1162 // the burst bits shall be set first, before the enable bits
1163 switch(mode) {
1164 case(LFR_MODE_NORMAL):
1165 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1166 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1167 break;
1168 case(LFR_MODE_BURST):
1169 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1170 // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1171 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2
1172 break;
1173 case(LFR_MODE_SBM1):
1174 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1175 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1176 break;
1177 case(LFR_MODE_SBM2):
1178 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1179 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1180 break;
1181 default:
1182 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1183 break;
1184 }
1185 }
1186
1187 void set_wfp_delta_snapshot( void )
1188 {
1189 /** This function sets the delta_snapshot register of the waveform picker module.
1190 *
1191 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1192 * - sy_lfr_n_swf_p[0]
1193 * - sy_lfr_n_swf_p[1]
1194 *
1195 */
1196
1197 unsigned int delta_snapshot;
1198 unsigned int delta_snapshot_in_T2;
1199
1200 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1201 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1202
1203 delta_snapshot_in_T2 = delta_snapshot * 256;
1204 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1205 }
1206
1207 void set_wfp_delta_f0_f0_2( void )
1208 {
1209 unsigned int delta_snapshot;
1210 unsigned int nb_samples_per_snapshot;
1211 float delta_f0_in_float;
1212
1213 delta_snapshot = waveform_picker_regs->delta_snapshot;
1214 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1215 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1216
1217 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1218 waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits
1219 }
1220
1221 void set_wfp_delta_f1( void )
1222 {
1223 unsigned int delta_snapshot;
1224 unsigned int nb_samples_per_snapshot;
1225 float delta_f1_in_float;
1226
1227 delta_snapshot = waveform_picker_regs->delta_snapshot;
1228 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1229 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1230
1231 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1232 }
1233
1234 void set_wfp_delta_f2()
1235 {
1236 unsigned int delta_snapshot;
1237 unsigned int nb_samples_per_snapshot;
1238
1239 delta_snapshot = waveform_picker_regs->delta_snapshot;
1240 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1241
1242 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1243 }
1244
1245 //*****************
1246 // local parameters
1247
1248 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1249 {
1250 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1251 *
1252 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1253 * @param sid is the source identifier of the packet being updated.
1254 *
1255 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1256 * The sequence counters shall wrap around from 2^14 to zero.
1257 * The sequence counter shall start at zero at startup.
1258 *
1259 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1260 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1261 *
1262 */
1263
1264 unsigned short *sequence_cnt;
1265 unsigned short segmentation_grouping_flag;
1266 unsigned short new_packet_sequence_control;
1267 rtems_mode initial_mode_set;
1268 rtems_mode current_mode_set;
1269 rtems_status_code status;
1270
1271 //******************************************
1272 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1273 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1274
1275 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1276 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1277 || (sid == SID_BURST_CWF_F2)
1278 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1279 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1280 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1281 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1282 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1283 {
1284 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1285 }
1286 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1287 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1288 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1289 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1290 {
1291 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1292 }
1293 else
1294 {
1295 sequence_cnt = (unsigned short *) NULL;
1296 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1297 }
1298
1299 if (sequence_cnt != NULL)
1300 {
1301 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1302 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1303
1304 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1305
1306 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1307 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1308
1309 // increment the sequence counter
1310 if ( *sequence_cnt < SEQ_CNT_MAX)
1311 {
1312 *sequence_cnt = *sequence_cnt + 1;
1313 }
1314 else
1315 {
1316 *sequence_cnt = 0;
1317 }
1318 }
1319
1320 //***********************************
1321 // RESET THE MODE OF THE CALLING TASK
1322 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1323 }
@@ -20,3 +20,4 run2/src
20 20 run2/trace
21 21 run3/src
22 22 run3/trace
23 *CMakeLists.txt.user
@@ -1,2 +1,2
1 1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 1ffa3d630b9ced4a87a362dafb10d9838e9cc0d9 header/lfr_common_headers
2 94f0f2fccbcb8030d9437ffbb69ee0eefaaea188 header/lfr_common_headers
@@ -16,8 +16,8
16 16 #include "avf1_prc1.h"
17 17 #include "avf2_prc2.h"
18 18
19 extern rtems_name Task_name[20]; /* array of task names */
20 extern rtems_id Task_id[20]; /* array of task ids */
19 extern rtems_name Task_name[]; /* array of task names */
20 extern rtems_id Task_id[]; /* array of task ids */
21 21 extern rtems_name timecode_timer_name;
22 22 extern rtems_id timecode_timer_id;
23 23 extern unsigned char pa_bia_status_info;
@@ -28,6 +28,8 extern void CCR_getInstructionAndDataErr
28 28
29 29 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
30 30 rtems_id HK_id; // id of the HK rate monotonic period
31 rtems_name name_avgv_rate_monotonic; // name of the AVGV rate monotonic
32 rtems_id AVGV_id; // id of the AVGV rate monotonic period
31 33
32 34 void timer_configure( unsigned char timer, unsigned int clock_divider,
33 35 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
@@ -50,6 +52,7 void set_apbuart_scaler_reload_register(
50 52 // RTEMS TASKS
51 53 rtems_task load_task( rtems_task_argument argument );
52 54 rtems_task hous_task( rtems_task_argument argument );
55 rtems_task avgv_task( rtems_task_argument argument );
53 56 rtems_task dumb_task( rtems_task_argument unused );
54 57
55 58 void init_housekeeping_parameters( void );
@@ -335,6 +335,91 rtems_task hous_task(rtems_task_argument
335 335 return;
336 336 }
337 337
338 rtems_task avgv_task(rtems_task_argument argument)
339 {
340 #define MOVING_AVERAGE 16
341 rtems_status_code status;
342 unsigned int v[MOVING_AVERAGE];
343 unsigned int e1[MOVING_AVERAGE];
344 unsigned int e2[MOVING_AVERAGE];
345 float average_v;
346 float average_e1;
347 float average_e2;
348 unsigned char k;
349 unsigned char indexOfOldValue;
350
351 BOOT_PRINTF("in AVGV ***\n");
352
353 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
354 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
355 if( status != RTEMS_SUCCESSFUL ) {
356 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
357 }
358 }
359
360 status = rtems_rate_monotonic_cancel(AVGV_id);
361 if( status != RTEMS_SUCCESSFUL ) {
362 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
363 }
364 else {
365 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
366 }
367
368 // initialize values
369 k = 0;
370 indexOfOldValue = MOVING_AVERAGE - 1;
371 for (k = 0; k < MOVING_AVERAGE; k++)
372 {
373 v[k] = 0;
374 e1[k] = 0;
375 e2[k] = 0;
376 average_v = 0.;
377 average_e1 = 0.;
378 average_e2 = 0.;
379 }
380
381 k = 0;
382
383 while(1){ // launch the rate monotonic task
384 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
385 if ( status != RTEMS_SUCCESSFUL ) {
386 PRINTF1( "in AVGV *** ERR period: %d\n", status);
387 }
388 else {
389 // store new value in buffer
390 v[k] = waveform_picker_regs->v;
391 e1[k] = waveform_picker_regs->e1;
392 e2[k] = waveform_picker_regs->e2;
393 if (k == (MOVING_AVERAGE - 1))
394 {
395 indexOfOldValue = 0;
396 }
397 else
398 {
399 indexOfOldValue = k + 1;
400 }
401 average_v = average_v + v[k] - v[indexOfOldValue];
402 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
403 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
404 }
405 if (k == (MOVING_AVERAGE-1))
406 {
407 k = 0;
408 printf("tick\n");
409 }
410 else
411 {
412 k++;
413 }
414 }
415
416 PRINTF("in AVGV *** deleting task\n")
417
418 status = rtems_task_delete( RTEMS_SELF ); // should not return
419
420 return;
421 }
422
338 423 rtems_task dumb_task( rtems_task_argument unused )
339 424 {
340 425 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (665 lines changed) Show them Hide them
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (728 lines changed) Show them Hide them
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (696 lines changed) Show them Hide them
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (772 lines changed) Show them Hide them
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (510 lines changed) Show them Hide them
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1323 lines changed) Show them Hide them
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now