##// END OF EJS Templates
3.2.0.1...
paul -
r346:698df4d9c944 R3++ draft
parent child
Show More
@@ -1,107 +1,107
1 cmake_minimum_required (VERSION 2.6)
1 cmake_minimum_required (VERSION 2.6)
2 project (fsw)
2 project (fsw)
3
3
4 include(sparc-rtems)
4 include(sparc-rtems)
5 include(cppcheck)
5 include(cppcheck)
6
6
7 include_directories("../header"
7 include_directories("../header"
8 "../header/lfr_common_headers"
8 "../header/lfr_common_headers"
9 "../header/processing"
9 "../header/processing"
10 "../LFR_basic-parameters"
10 "../LFR_basic-parameters"
11 "../src")
11 "../src")
12
12
13 set(SOURCES wf_handler.c
13 set(SOURCES wf_handler.c
14 tc_handler.c
14 tc_handler.c
15 fsw_misc.c
15 fsw_misc.c
16 fsw_init.c
16 fsw_init.c
17 fsw_globals.c
17 fsw_globals.c
18 fsw_spacewire.c
18 fsw_spacewire.c
19 tc_load_dump_parameters.c
19 tc_load_dump_parameters.c
20 tm_lfr_tc_exe.c
20 tm_lfr_tc_exe.c
21 tc_acceptance.c
21 tc_acceptance.c
22 processing/fsw_processing.c
22 processing/fsw_processing.c
23 processing/avf0_prc0.c
23 processing/avf0_prc0.c
24 processing/avf1_prc1.c
24 processing/avf1_prc1.c
25 processing/avf2_prc2.c
25 processing/avf2_prc2.c
26 lfr_cpu_usage_report.c
26 lfr_cpu_usage_report.c
27 ${LFR_BP_SRC}
27 ${LFR_BP_SRC}
28 ../header/wf_handler.h
28 ../header/wf_handler.h
29 ../header/tc_handler.h
29 ../header/tc_handler.h
30 ../header/grlib_regs.h
30 ../header/grlib_regs.h
31 ../header/fsw_misc.h
31 ../header/fsw_misc.h
32 ../header/fsw_init.h
32 ../header/fsw_init.h
33 ../header/fsw_spacewire.h
33 ../header/fsw_spacewire.h
34 ../header/tc_load_dump_parameters.h
34 ../header/tc_load_dump_parameters.h
35 ../header/tm_lfr_tc_exe.h
35 ../header/tm_lfr_tc_exe.h
36 ../header/tc_acceptance.h
36 ../header/tc_acceptance.h
37 ../header/processing/fsw_processing.h
37 ../header/processing/fsw_processing.h
38 ../header/processing/avf0_prc0.h
38 ../header/processing/avf0_prc0.h
39 ../header/processing/avf1_prc1.h
39 ../header/processing/avf1_prc1.h
40 ../header/processing/avf2_prc2.h
40 ../header/processing/avf2_prc2.h
41 ../header/fsw_params_wf_handler.h
41 ../header/fsw_params_wf_handler.h
42 ../header/lfr_cpu_usage_report.h
42 ../header/lfr_cpu_usage_report.h
43 ../header/lfr_common_headers/ccsds_types.h
43 ../header/lfr_common_headers/ccsds_types.h
44 ../header/lfr_common_headers/fsw_params.h
44 ../header/lfr_common_headers/fsw_params.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
46 ../header/lfr_common_headers/fsw_params_processing.h
46 ../header/lfr_common_headers/fsw_params_processing.h
47 ../header/lfr_common_headers/tm_byte_positions.h
47 ../header/lfr_common_headers/tm_byte_positions.h
48 ../LFR_basic-parameters/basic_parameters.h
48 ../LFR_basic-parameters/basic_parameters.h
49 ../LFR_basic-parameters/basic_parameters_params.h
49 ../LFR_basic-parameters/basic_parameters_params.h
50 ../header/GscMemoryLPP.hpp
50 ../header/GscMemoryLPP.hpp
51 )
51 )
52
52
53
53
54 option(FSW_verbose "Enable verbose LFR" OFF)
54 option(FSW_verbose "Enable verbose LFR" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
59 option(FSW_vhdl_dev "?" OFF)
59 option(FSW_vhdl_dev "?" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" ON)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" ON)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
62 option(FSW_debug_tch "?" OFF)
62 option(FSW_debug_tch "?" OFF)
63
63
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
67 set(SW_VERSION_N4 "0" CACHE STRING "Choose N4 FSW Version." FORCE)
67 set(SW_VERSION_N4 "1" CACHE STRING "Choose N4 FSW Version." FORCE)
68
68
69 if(FSW_verbose)
69 if(FSW_verbose)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 endif()
71 endif()
72 if(FSW_boot_messages)
72 if(FSW_boot_messages)
73 add_definitions(-DBOOT_MESSAGES)
73 add_definitions(-DBOOT_MESSAGES)
74 endif()
74 endif()
75 if(FSW_debug_messages)
75 if(FSW_debug_messages)
76 add_definitions(-DDEBUG_MESSAGES)
76 add_definitions(-DDEBUG_MESSAGES)
77 endif()
77 endif()
78 if(FSW_cpu_usage_report)
78 if(FSW_cpu_usage_report)
79 add_definitions(-DPRINT_TASK_STATISTICS)
79 add_definitions(-DPRINT_TASK_STATISTICS)
80 endif()
80 endif()
81 if(FSW_stack_report)
81 if(FSW_stack_report)
82 add_definitions(-DPRINT_STACK_REPORT)
82 add_definitions(-DPRINT_STACK_REPORT)
83 endif()
83 endif()
84 if(FSW_vhdl_dev)
84 if(FSW_vhdl_dev)
85 add_definitions(-DVHDL_DEV)
85 add_definitions(-DVHDL_DEV)
86 endif()
86 endif()
87 if(FSW_lpp_dpu_destid)
87 if(FSW_lpp_dpu_destid)
88 add_definitions(-DLPP_DPU_DESTID)
88 add_definitions(-DLPP_DPU_DESTID)
89 endif()
89 endif()
90 if(FSW_debug_watchdog)
90 if(FSW_debug_watchdog)
91 add_definitions(-DDEBUG_WATCHDOG)
91 add_definitions(-DDEBUG_WATCHDOG)
92 endif()
92 endif()
93 if(FSW_debug_tch)
93 if(FSW_debug_tch)
94 add_definitions(-DDEBUG_TCH)
94 add_definitions(-DDEBUG_TCH)
95 endif()
95 endif()
96
96
97 add_definitions(-DMSB_FIRST_TCH)
97 add_definitions(-DMSB_FIRST_TCH)
98
98
99 add_definitions(-DSWVERSION=-1-0)
99 add_definitions(-DSWVERSION=-1-0)
100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
104
104
105 add_executable(fsw ${SOURCES})
105 add_executable(fsw ${SOURCES})
106 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
106 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
107
107
@@ -1,958 +1,975
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
29 #define CONFIGURE_MAXIMUM_TASKS 21 // number of tasks concurrently active including INIT
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_PERIODS 5 // [hous] [load] [avgv]
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
42 #endif
43
43
44 #include <rtems/confdefs.h>
44 #include <rtems/confdefs.h>
45
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
49 /* Add Timer and UART Driver */
50
50
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
53 #endif
53 #endif
54
54
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
57 #endif
57 #endif
58
58
59 #endif
59 #endif
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
61
62 #include <drvmgr/drvmgr_confdefs.h>
62 #include <drvmgr/drvmgr_confdefs.h>
63 #endif
63 #endif
64
64
65 #include "fsw_init.h"
65 #include "fsw_init.h"
66 #include "fsw_config.c"
66 #include "fsw_config.c"
67 #include "GscMemoryLPP.hpp"
67 #include "GscMemoryLPP.hpp"
68
68
69 void initCache()
69 void initCache()
70 {
70 {
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
72 // These should only be read and written using 32-bit LDA/STA instructions.
72 // These should only be read and written using 32-bit LDA/STA instructions.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
74 // The table below shows the register addresses:
74 // The table below shows the register addresses:
75 // 0x00 Cache control register
75 // 0x00 Cache control register
76 // 0x04 Reserved
76 // 0x04 Reserved
77 // 0x08 Instruction cache configuration register
77 // 0x08 Instruction cache configuration register
78 // 0x0C Data cache configuration register
78 // 0x0C Data cache configuration register
79
79
80 // Cache Control Register Leon3 / Leon3FT
80 // Cache Control Register Leon3 / Leon3FT
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
82 // RFT PS TB DS FD FI FT ST IB
82 // RFT PS TB DS FD FI FT ST IB
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
85
85
86 unsigned int cacheControlRegister;
86 unsigned int cacheControlRegister;
87
87
88 CCR_resetCacheControlRegister();
88 CCR_resetCacheControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
90
90
91 cacheControlRegister = CCR_getValue();
91 cacheControlRegister = CCR_getValue();
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
94
94
95 CCR_enableInstructionCache(); // ICS bits
95 CCR_enableInstructionCache(); // ICS bits
96 CCR_enableDataCache(); // DCS bits
96 CCR_enableDataCache(); // DCS bits
97 CCR_enableInstructionBurstFetch(); // IB bit
97 CCR_enableInstructionBurstFetch(); // IB bit
98
98
99 faultTolerantScheme();
99 faultTolerantScheme();
100
100
101 cacheControlRegister = CCR_getValue();
101 cacheControlRegister = CCR_getValue();
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
104
104
105 PRINTF("\n");
105 PRINTF("\n");
106 }
106 }
107
107
108 rtems_task Init( rtems_task_argument ignored )
108 rtems_task Init( rtems_task_argument ignored )
109 {
109 {
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
111 *
111 *
112 * @param unused is the starting argument of the RTEMS task
112 * @param unused is the starting argument of the RTEMS task
113 *
113 *
114 * The INIT task create and run all other RTEMS tasks.
114 * The INIT task create and run all other RTEMS tasks.
115 *
115 *
116 */
116 */
117
117
118 //***********
118 //***********
119 // INIT CACHE
119 // INIT CACHE
120
120
121 unsigned char *vhdlVersion;
121 unsigned char *vhdlVersion;
122
122
123 reset_lfr();
123 reset_lfr();
124
124
125 reset_local_time();
125 reset_local_time();
126
126
127 rtems_cpu_usage_reset();
127 rtems_cpu_usage_reset();
128
128
129 rtems_status_code status;
129 rtems_status_code status;
130 rtems_status_code status_spw;
130 rtems_status_code status_spw;
131 rtems_isr_entry old_isr_handler;
131 rtems_isr_entry old_isr_handler;
132
132
133 old_isr_handler = NULL;
133 old_isr_handler = NULL;
134
134
135 // UART settings
135 // UART settings
136 enable_apbuart_transmitter();
136 enable_apbuart_transmitter();
137 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
137 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
138
138
139 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
139 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
140
140
141
141
142 PRINTF("\n\n\n\n\n")
142 PRINTF("\n\n\n\n\n")
143
143
144 initCache();
144 initCache();
145
145
146 PRINTF("*************************\n")
146 PRINTF("*************************\n")
147 PRINTF("** LFR Flight Software **\n")
147 PRINTF("** LFR Flight Software **\n")
148
148
149 PRINTF1("** %d-", SW_VERSION_N1)
149 PRINTF1("** %d-", SW_VERSION_N1)
150 PRINTF1("%d-" , SW_VERSION_N2)
150 PRINTF1("%d-" , SW_VERSION_N2)
151 PRINTF1("%d-" , SW_VERSION_N3)
151 PRINTF1("%d-" , SW_VERSION_N3)
152 PRINTF1("%d **\n", SW_VERSION_N4)
152 PRINTF1("%d **\n", SW_VERSION_N4)
153
153
154 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
154 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
155 PRINTF("** VHDL **\n")
155 PRINTF("** VHDL **\n")
156 PRINTF1("** %d-", vhdlVersion[1])
156 PRINTF1("** %d-", vhdlVersion[1])
157 PRINTF1("%d-" , vhdlVersion[2])
157 PRINTF1("%d-" , vhdlVersion[2])
158 PRINTF1("%d **\n", vhdlVersion[3])
158 PRINTF1("%d **\n", vhdlVersion[3])
159 PRINTF("*************************\n")
159 PRINTF("*************************\n")
160 PRINTF("\n\n")
160 PRINTF("\n\n")
161
161
162 init_parameter_dump();
162 init_parameter_dump();
163 init_kcoefficients_dump();
163 init_kcoefficients_dump();
164 init_local_mode_parameters();
164 init_local_mode_parameters();
165 init_housekeeping_parameters();
165 init_housekeeping_parameters();
166 init_k_coefficients_prc0();
166 init_k_coefficients_prc0();
167 init_k_coefficients_prc1();
167 init_k_coefficients_prc1();
168 init_k_coefficients_prc2();
168 init_k_coefficients_prc2();
169 pa_bia_status_info = INIT_CHAR;
169 pa_bia_status_info = INIT_CHAR;
170
170
171 // initialize all reaction wheels frequencies to NaN
171 // initialize all reaction wheels frequencies to NaN
172 rw_f.cp_rpw_sc_rw1_f1 = NAN;
172 rw_f.cp_rpw_sc_rw1_f1 = NAN;
173 rw_f.cp_rpw_sc_rw1_f2 = NAN;
173 rw_f.cp_rpw_sc_rw1_f2 = NAN;
174 rw_f.cp_rpw_sc_rw1_f3 = NAN;
174 rw_f.cp_rpw_sc_rw1_f3 = NAN;
175 rw_f.cp_rpw_sc_rw1_f4 = NAN;
175 rw_f.cp_rpw_sc_rw1_f4 = NAN;
176 rw_f.cp_rpw_sc_rw2_f1 = NAN;
176 rw_f.cp_rpw_sc_rw2_f1 = NAN;
177 rw_f.cp_rpw_sc_rw2_f2 = NAN;
177 rw_f.cp_rpw_sc_rw2_f2 = NAN;
178 rw_f.cp_rpw_sc_rw2_f3 = NAN;
178 rw_f.cp_rpw_sc_rw2_f3 = NAN;
179 rw_f.cp_rpw_sc_rw2_f4 = NAN;
179 rw_f.cp_rpw_sc_rw2_f4 = NAN;
180 rw_f.cp_rpw_sc_rw3_f1 = NAN;
180 rw_f.cp_rpw_sc_rw3_f1 = NAN;
181 rw_f.cp_rpw_sc_rw3_f2 = NAN;
181 rw_f.cp_rpw_sc_rw3_f2 = NAN;
182 rw_f.cp_rpw_sc_rw3_f3 = NAN;
182 rw_f.cp_rpw_sc_rw3_f3 = NAN;
183 rw_f.cp_rpw_sc_rw3_f4 = NAN;
183 rw_f.cp_rpw_sc_rw3_f4 = NAN;
184 rw_f.cp_rpw_sc_rw4_f1 = NAN;
184 rw_f.cp_rpw_sc_rw4_f1 = NAN;
185 rw_f.cp_rpw_sc_rw4_f2 = NAN;
185 rw_f.cp_rpw_sc_rw4_f2 = NAN;
186 rw_f.cp_rpw_sc_rw4_f3 = NAN;
186 rw_f.cp_rpw_sc_rw4_f3 = NAN;
187 rw_f.cp_rpw_sc_rw4_f4 = NAN;
187 rw_f.cp_rpw_sc_rw4_f4 = NAN;
188
188
189 cp_rpw_sc_rw1_rw2_f_flags = INIT_CHAR;
189 cp_rpw_sc_rw1_rw2_f_flags = INIT_CHAR;
190 cp_rpw_sc_rw3_rw4_f_flags = INIT_CHAR;
190 cp_rpw_sc_rw3_rw4_f_flags = INIT_CHAR;
191
191
192 // initialize filtering parameters
192 // initialize filtering parameters
193 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
193 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
194 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
194 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
195 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
195 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
196 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
196 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
197 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
197 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
198 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
198 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
199 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
199 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
200
200
201 // waveform picker initialization
201 // waveform picker initialization
202 WFP_init_rings();
202 WFP_init_rings();
203 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
203 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
204 WFP_reset_current_ring_nodes();
204 WFP_reset_current_ring_nodes();
205 reset_waveform_picker_regs();
205 reset_waveform_picker_regs();
206
206
207 // spectral matrices initialization
207 // spectral matrices initialization
208 SM_init_rings(); // initialize spectral matrices rings
208 SM_init_rings(); // initialize spectral matrices rings
209 SM_reset_current_ring_nodes();
209 SM_reset_current_ring_nodes();
210 reset_spectral_matrix_regs();
210 reset_spectral_matrix_regs();
211
211
212 // configure calibration
212 // configure calibration
213 configureCalibration( false ); // true means interleaved mode, false is for normal mode
213 configureCalibration( false ); // true means interleaved mode, false is for normal mode
214
214
215 updateLFRCurrentMode( LFR_MODE_STANDBY );
215 updateLFRCurrentMode( LFR_MODE_STANDBY );
216
216
217 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
217 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
218
218
219 create_names(); // create all names
219 create_names(); // create all names
220
220
221 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
221 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
222 if (status != RTEMS_SUCCESSFUL)
222 if (status != RTEMS_SUCCESSFUL)
223 {
223 {
224 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
224 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
225 }
225 }
226
226
227 status = create_message_queues(); // create message queues
227 status = create_message_queues(); // create message queues
228 if (status != RTEMS_SUCCESSFUL)
228 if (status != RTEMS_SUCCESSFUL)
229 {
229 {
230 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
230 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
231 }
231 }
232
232
233 status = create_all_tasks(); // create all tasks
233 status = create_all_tasks(); // create all tasks
234 if (status != RTEMS_SUCCESSFUL)
234 if (status != RTEMS_SUCCESSFUL)
235 {
235 {
236 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
236 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
237 }
237 }
238
238
239 // **************************
239 // **************************
240 // <SPACEWIRE INITIALIZATION>
240 // <SPACEWIRE INITIALIZATION>
241 status_spw = spacewire_open_link(); // (1) open the link
241 status_spw = spacewire_open_link(); // (1) open the link
242 if ( status_spw != RTEMS_SUCCESSFUL )
242 if ( status_spw != RTEMS_SUCCESSFUL )
243 {
243 {
244 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
244 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
245 }
245 }
246
246
247 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
247 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
248 {
248 {
249 status_spw = spacewire_configure_link( fdSPW );
249 status_spw = spacewire_configure_link( fdSPW );
250 if ( status_spw != RTEMS_SUCCESSFUL )
250 if ( status_spw != RTEMS_SUCCESSFUL )
251 {
251 {
252 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
252 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
253 }
253 }
254 }
254 }
255
255
256 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
256 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
257 {
257 {
258 status_spw = spacewire_start_link( fdSPW );
258 status_spw = spacewire_start_link( fdSPW );
259 if ( status_spw != RTEMS_SUCCESSFUL )
259 if ( status_spw != RTEMS_SUCCESSFUL )
260 {
260 {
261 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
261 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
262 }
262 }
263 }
263 }
264 // </SPACEWIRE INITIALIZATION>
264 // </SPACEWIRE INITIALIZATION>
265 // ***************************
265 // ***************************
266
266
267 status = start_all_tasks(); // start all tasks
267 status = start_all_tasks(); // start all tasks
268 if (status != RTEMS_SUCCESSFUL)
268 if (status != RTEMS_SUCCESSFUL)
269 {
269 {
270 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
270 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
271 }
271 }
272
272
273 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
273 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
274 status = start_recv_send_tasks();
274 status = start_recv_send_tasks();
275 if ( status != RTEMS_SUCCESSFUL )
275 if ( status != RTEMS_SUCCESSFUL )
276 {
276 {
277 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
277 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
278 }
278 }
279
279
280 // suspend science tasks, they will be restarted later depending on the mode
280 // suspend science tasks, they will be restarted later depending on the mode
281 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
281 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
282 if (status != RTEMS_SUCCESSFUL)
282 if (status != RTEMS_SUCCESSFUL)
283 {
283 {
284 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
284 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
285 }
285 }
286
286
287 // configure IRQ handling for the waveform picker unit
287 // configure IRQ handling for the waveform picker unit
288 status = rtems_interrupt_catch( waveforms_isr,
288 status = rtems_interrupt_catch( waveforms_isr,
289 IRQ_SPARC_WAVEFORM_PICKER,
289 IRQ_SPARC_WAVEFORM_PICKER,
290 &old_isr_handler) ;
290 &old_isr_handler) ;
291 // configure IRQ handling for the spectral matrices unit
291 // configure IRQ handling for the spectral matrices unit
292 status = rtems_interrupt_catch( spectral_matrices_isr,
292 status = rtems_interrupt_catch( spectral_matrices_isr,
293 IRQ_SPARC_SPECTRAL_MATRIX,
293 IRQ_SPARC_SPECTRAL_MATRIX,
294 &old_isr_handler) ;
294 &old_isr_handler) ;
295
295
296 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
296 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
297 if ( status_spw != RTEMS_SUCCESSFUL )
297 if ( status_spw != RTEMS_SUCCESSFUL )
298 {
298 {
299 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
299 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
300 if ( status != RTEMS_SUCCESSFUL ) {
300 if ( status != RTEMS_SUCCESSFUL ) {
301 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
301 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
302 }
302 }
303 }
303 }
304
304
305 BOOT_PRINTF("delete INIT\n")
305 BOOT_PRINTF("delete INIT\n")
306
306
307 set_hk_lfr_sc_potential_flag( true );
307 set_hk_lfr_sc_potential_flag( true );
308
308
309 // start the timer to detect a missing spacewire timecode
309 // start the timer to detect a missing spacewire timecode
310 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
310 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
311 // if a tickout is generated, the timer is restarted
311 // if a tickout is generated, the timer is restarted
312 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
312 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
313
313
314 grspw_timecode_callback = &timecode_irq_handler;
314 grspw_timecode_callback = &timecode_irq_handler;
315
315
316 status = rtems_task_delete(RTEMS_SELF);
316 status = rtems_task_delete(RTEMS_SELF);
317
317
318 }
318 }
319
319
320 void init_local_mode_parameters( void )
320 void init_local_mode_parameters( void )
321 {
321 {
322 /** This function initialize the param_local global variable with default values.
322 /** This function initialize the param_local global variable with default values.
323 *
323 *
324 */
324 */
325
325
326 unsigned int i;
326 unsigned int i;
327
327
328 // LOCAL PARAMETERS
328 // LOCAL PARAMETERS
329
329
330 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
330 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
331 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
331 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
332
332
333 // init sequence counters
333 // init sequence counters
334
334
335 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
335 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
336 {
336 {
337 sequenceCounters_TC_EXE[i] = INIT_CHAR;
337 sequenceCounters_TC_EXE[i] = INIT_CHAR;
338 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
338 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
339 }
339 }
340 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
340 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
341 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
341 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
342 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
342 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
343 }
343 }
344
344
345 void reset_local_time( void )
345 void reset_local_time( void )
346 {
346 {
347 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
347 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
348 }
348 }
349
349
350 void create_names( void ) // create all names for tasks and queues
350 void create_names( void ) // create all names for tasks and queues
351 {
351 {
352 /** This function creates all RTEMS names used in the software for tasks and queues.
352 /** This function creates all RTEMS names used in the software for tasks and queues.
353 *
353 *
354 * @return RTEMS directive status codes:
354 * @return RTEMS directive status codes:
355 * - RTEMS_SUCCESSFUL - successful completion
355 * - RTEMS_SUCCESSFUL - successful completion
356 *
356 *
357 */
357 */
358
358
359 // task names
359 // task names
360 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
360 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
361 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
361 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
362 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
362 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
363 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
363 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
364 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
364 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
365 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
365 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
366 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
366 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
367 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
367 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
368 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
368 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
369 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
369 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
370 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
370 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
371 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
371 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
372 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
372 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
373 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
373 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
374 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
374 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
375 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
375 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
376 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
376 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
377 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
377 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
378 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
378 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
379 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
379
380
380 // rate monotonic period names
381 // rate monotonic period names
381 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
382 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
383 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
382
384
383 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
385 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
384 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
386 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
385 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
387 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
386 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
388 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
387 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
389 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
388
390
389 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
391 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
390 }
392 }
391
393
392 int create_all_tasks( void ) // create all tasks which run in the software
394 int create_all_tasks( void ) // create all tasks which run in the software
393 {
395 {
394 /** This function creates all RTEMS tasks used in the software.
396 /** This function creates all RTEMS tasks used in the software.
395 *
397 *
396 * @return RTEMS directive status codes:
398 * @return RTEMS directive status codes:
397 * - RTEMS_SUCCESSFUL - task created successfully
399 * - RTEMS_SUCCESSFUL - task created successfully
398 * - RTEMS_INVALID_ADDRESS - id is NULL
400 * - RTEMS_INVALID_ADDRESS - id is NULL
399 * - RTEMS_INVALID_NAME - invalid task name
401 * - RTEMS_INVALID_NAME - invalid task name
400 * - RTEMS_INVALID_PRIORITY - invalid task priority
402 * - RTEMS_INVALID_PRIORITY - invalid task priority
401 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
403 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
402 * - RTEMS_TOO_MANY - too many tasks created
404 * - RTEMS_TOO_MANY - too many tasks created
403 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
405 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
404 * - RTEMS_TOO_MANY - too many global objects
406 * - RTEMS_TOO_MANY - too many global objects
405 *
407 *
406 */
408 */
407
409
408 rtems_status_code status;
410 rtems_status_code status;
409
411
410 //**********
412 //**********
411 // SPACEWIRE
413 // SPACEWIRE
412 // RECV
414 // RECV
413 status = rtems_task_create(
415 status = rtems_task_create(
414 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
416 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
415 RTEMS_DEFAULT_MODES,
417 RTEMS_DEFAULT_MODES,
416 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
418 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
417 );
419 );
418 if (status == RTEMS_SUCCESSFUL) // SEND
420 if (status == RTEMS_SUCCESSFUL) // SEND
419 {
421 {
420 status = rtems_task_create(
422 status = rtems_task_create(
421 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
423 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
422 RTEMS_DEFAULT_MODES,
424 RTEMS_DEFAULT_MODES,
423 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
425 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
424 );
426 );
425 }
427 }
426 if (status == RTEMS_SUCCESSFUL) // LINK
428 if (status == RTEMS_SUCCESSFUL) // LINK
427 {
429 {
428 status = rtems_task_create(
430 status = rtems_task_create(
429 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
431 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
430 RTEMS_DEFAULT_MODES,
432 RTEMS_DEFAULT_MODES,
431 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
433 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
432 );
434 );
433 }
435 }
434 if (status == RTEMS_SUCCESSFUL) // ACTN
436 if (status == RTEMS_SUCCESSFUL) // ACTN
435 {
437 {
436 status = rtems_task_create(
438 status = rtems_task_create(
437 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
439 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
438 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
440 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
439 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
441 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
440 );
442 );
441 }
443 }
442 if (status == RTEMS_SUCCESSFUL) // SPIQ
444 if (status == RTEMS_SUCCESSFUL) // SPIQ
443 {
445 {
444 status = rtems_task_create(
446 status = rtems_task_create(
445 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
447 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
446 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
448 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
447 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
449 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
448 );
450 );
449 }
451 }
450
452
451 //******************
453 //******************
452 // SPECTRAL MATRICES
454 // SPECTRAL MATRICES
453 if (status == RTEMS_SUCCESSFUL) // AVF0
455 if (status == RTEMS_SUCCESSFUL) // AVF0
454 {
456 {
455 status = rtems_task_create(
457 status = rtems_task_create(
456 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
458 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
457 RTEMS_DEFAULT_MODES,
459 RTEMS_DEFAULT_MODES,
458 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
460 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
459 );
461 );
460 }
462 }
461 if (status == RTEMS_SUCCESSFUL) // PRC0
463 if (status == RTEMS_SUCCESSFUL) // PRC0
462 {
464 {
463 status = rtems_task_create(
465 status = rtems_task_create(
464 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
466 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
465 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
467 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
466 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
468 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
467 );
469 );
468 }
470 }
469 if (status == RTEMS_SUCCESSFUL) // AVF1
471 if (status == RTEMS_SUCCESSFUL) // AVF1
470 {
472 {
471 status = rtems_task_create(
473 status = rtems_task_create(
472 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
474 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
473 RTEMS_DEFAULT_MODES,
475 RTEMS_DEFAULT_MODES,
474 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
476 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
475 );
477 );
476 }
478 }
477 if (status == RTEMS_SUCCESSFUL) // PRC1
479 if (status == RTEMS_SUCCESSFUL) // PRC1
478 {
480 {
479 status = rtems_task_create(
481 status = rtems_task_create(
480 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
482 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
481 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
483 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
482 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
484 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
483 );
485 );
484 }
486 }
485 if (status == RTEMS_SUCCESSFUL) // AVF2
487 if (status == RTEMS_SUCCESSFUL) // AVF2
486 {
488 {
487 status = rtems_task_create(
489 status = rtems_task_create(
488 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
490 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
489 RTEMS_DEFAULT_MODES,
491 RTEMS_DEFAULT_MODES,
490 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
492 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
491 );
493 );
492 }
494 }
493 if (status == RTEMS_SUCCESSFUL) // PRC2
495 if (status == RTEMS_SUCCESSFUL) // PRC2
494 {
496 {
495 status = rtems_task_create(
497 status = rtems_task_create(
496 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
498 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
497 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
499 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
498 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
500 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
499 );
501 );
500 }
502 }
501
503
502 //****************
504 //****************
503 // WAVEFORM PICKER
505 // WAVEFORM PICKER
504 if (status == RTEMS_SUCCESSFUL) // WFRM
506 if (status == RTEMS_SUCCESSFUL) // WFRM
505 {
507 {
506 status = rtems_task_create(
508 status = rtems_task_create(
507 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
509 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
508 RTEMS_DEFAULT_MODES,
510 RTEMS_DEFAULT_MODES,
509 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
511 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
510 );
512 );
511 }
513 }
512 if (status == RTEMS_SUCCESSFUL) // CWF3
514 if (status == RTEMS_SUCCESSFUL) // CWF3
513 {
515 {
514 status = rtems_task_create(
516 status = rtems_task_create(
515 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
517 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
516 RTEMS_DEFAULT_MODES,
518 RTEMS_DEFAULT_MODES,
517 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
519 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
518 );
520 );
519 }
521 }
520 if (status == RTEMS_SUCCESSFUL) // CWF2
522 if (status == RTEMS_SUCCESSFUL) // CWF2
521 {
523 {
522 status = rtems_task_create(
524 status = rtems_task_create(
523 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
525 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
524 RTEMS_DEFAULT_MODES,
526 RTEMS_DEFAULT_MODES,
525 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
527 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
526 );
528 );
527 }
529 }
528 if (status == RTEMS_SUCCESSFUL) // CWF1
530 if (status == RTEMS_SUCCESSFUL) // CWF1
529 {
531 {
530 status = rtems_task_create(
532 status = rtems_task_create(
531 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
533 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
532 RTEMS_DEFAULT_MODES,
534 RTEMS_DEFAULT_MODES,
533 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
535 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
534 );
536 );
535 }
537 }
536 if (status == RTEMS_SUCCESSFUL) // SWBD
538 if (status == RTEMS_SUCCESSFUL) // SWBD
537 {
539 {
538 status = rtems_task_create(
540 status = rtems_task_create(
539 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
541 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
540 RTEMS_DEFAULT_MODES,
542 RTEMS_DEFAULT_MODES,
541 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
543 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
542 );
544 );
543 }
545 }
544
546
545 //*****
547 //*****
546 // MISC
548 // MISC
547 if (status == RTEMS_SUCCESSFUL) // LOAD
549 if (status == RTEMS_SUCCESSFUL) // LOAD
548 {
550 {
549 status = rtems_task_create(
551 status = rtems_task_create(
550 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
552 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
551 RTEMS_DEFAULT_MODES,
553 RTEMS_DEFAULT_MODES,
552 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
554 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
553 );
555 );
554 }
556 }
555 if (status == RTEMS_SUCCESSFUL) // DUMB
557 if (status == RTEMS_SUCCESSFUL) // DUMB
556 {
558 {
557 status = rtems_task_create(
559 status = rtems_task_create(
558 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
560 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
559 RTEMS_DEFAULT_MODES,
561 RTEMS_DEFAULT_MODES,
560 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
562 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
561 );
563 );
562 }
564 }
563 if (status == RTEMS_SUCCESSFUL) // HOUS
565 if (status == RTEMS_SUCCESSFUL) // HOUS
564 {
566 {
565 status = rtems_task_create(
567 status = rtems_task_create(
566 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
568 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
567 RTEMS_DEFAULT_MODES,
569 RTEMS_DEFAULT_MODES,
568 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
570 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
569 );
571 );
570 }
572 }
573 if (status == RTEMS_SUCCESSFUL) // AVGV
574 {
575 status = rtems_task_create(
576 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
577 RTEMS_DEFAULT_MODES,
578 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
579 );
580 }
571
581
572 return status;
582 return status;
573 }
583 }
574
584
575 int start_recv_send_tasks( void )
585 int start_recv_send_tasks( void )
576 {
586 {
577 rtems_status_code status;
587 rtems_status_code status;
578
588
579 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
589 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
580 if (status!=RTEMS_SUCCESSFUL) {
590 if (status!=RTEMS_SUCCESSFUL) {
581 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
591 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
582 }
592 }
583
593
584 if (status == RTEMS_SUCCESSFUL) // SEND
594 if (status == RTEMS_SUCCESSFUL) // SEND
585 {
595 {
586 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
596 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
587 if (status!=RTEMS_SUCCESSFUL) {
597 if (status!=RTEMS_SUCCESSFUL) {
588 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
598 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
589 }
599 }
590 }
600 }
591
601
592 return status;
602 return status;
593 }
603 }
594
604
595 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
605 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
596 {
606 {
597 /** This function starts all RTEMS tasks used in the software.
607 /** This function starts all RTEMS tasks used in the software.
598 *
608 *
599 * @return RTEMS directive status codes:
609 * @return RTEMS directive status codes:
600 * - RTEMS_SUCCESSFUL - ask started successfully
610 * - RTEMS_SUCCESSFUL - ask started successfully
601 * - RTEMS_INVALID_ADDRESS - invalid task entry point
611 * - RTEMS_INVALID_ADDRESS - invalid task entry point
602 * - RTEMS_INVALID_ID - invalid task id
612 * - RTEMS_INVALID_ID - invalid task id
603 * - RTEMS_INCORRECT_STATE - task not in the dormant state
613 * - RTEMS_INCORRECT_STATE - task not in the dormant state
604 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
614 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
605 *
615 *
606 */
616 */
607 // starts all the tasks fot eh flight software
617 // starts all the tasks fot eh flight software
608
618
609 rtems_status_code status;
619 rtems_status_code status;
610
620
611 //**********
621 //**********
612 // SPACEWIRE
622 // SPACEWIRE
613 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
623 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
614 if (status!=RTEMS_SUCCESSFUL) {
624 if (status!=RTEMS_SUCCESSFUL) {
615 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
625 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
616 }
626 }
617
627
618 if (status == RTEMS_SUCCESSFUL) // LINK
628 if (status == RTEMS_SUCCESSFUL) // LINK
619 {
629 {
620 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
630 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
621 if (status!=RTEMS_SUCCESSFUL) {
631 if (status!=RTEMS_SUCCESSFUL) {
622 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
632 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
623 }
633 }
624 }
634 }
625
635
626 if (status == RTEMS_SUCCESSFUL) // ACTN
636 if (status == RTEMS_SUCCESSFUL) // ACTN
627 {
637 {
628 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
638 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
629 if (status!=RTEMS_SUCCESSFUL) {
639 if (status!=RTEMS_SUCCESSFUL) {
630 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
640 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
631 }
641 }
632 }
642 }
633
643
634 //******************
644 //******************
635 // SPECTRAL MATRICES
645 // SPECTRAL MATRICES
636 if (status == RTEMS_SUCCESSFUL) // AVF0
646 if (status == RTEMS_SUCCESSFUL) // AVF0
637 {
647 {
638 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
648 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
639 if (status!=RTEMS_SUCCESSFUL) {
649 if (status!=RTEMS_SUCCESSFUL) {
640 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
650 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
641 }
651 }
642 }
652 }
643 if (status == RTEMS_SUCCESSFUL) // PRC0
653 if (status == RTEMS_SUCCESSFUL) // PRC0
644 {
654 {
645 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
655 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
646 if (status!=RTEMS_SUCCESSFUL) {
656 if (status!=RTEMS_SUCCESSFUL) {
647 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
657 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
648 }
658 }
649 }
659 }
650 if (status == RTEMS_SUCCESSFUL) // AVF1
660 if (status == RTEMS_SUCCESSFUL) // AVF1
651 {
661 {
652 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
662 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
653 if (status!=RTEMS_SUCCESSFUL) {
663 if (status!=RTEMS_SUCCESSFUL) {
654 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
664 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
655 }
665 }
656 }
666 }
657 if (status == RTEMS_SUCCESSFUL) // PRC1
667 if (status == RTEMS_SUCCESSFUL) // PRC1
658 {
668 {
659 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
669 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
660 if (status!=RTEMS_SUCCESSFUL) {
670 if (status!=RTEMS_SUCCESSFUL) {
661 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
671 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
662 }
672 }
663 }
673 }
664 if (status == RTEMS_SUCCESSFUL) // AVF2
674 if (status == RTEMS_SUCCESSFUL) // AVF2
665 {
675 {
666 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
676 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
667 if (status!=RTEMS_SUCCESSFUL) {
677 if (status!=RTEMS_SUCCESSFUL) {
668 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
678 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
669 }
679 }
670 }
680 }
671 if (status == RTEMS_SUCCESSFUL) // PRC2
681 if (status == RTEMS_SUCCESSFUL) // PRC2
672 {
682 {
673 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
683 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
674 if (status!=RTEMS_SUCCESSFUL) {
684 if (status!=RTEMS_SUCCESSFUL) {
675 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
685 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
676 }
686 }
677 }
687 }
678
688
679 //****************
689 //****************
680 // WAVEFORM PICKER
690 // WAVEFORM PICKER
681 if (status == RTEMS_SUCCESSFUL) // WFRM
691 if (status == RTEMS_SUCCESSFUL) // WFRM
682 {
692 {
683 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
693 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
684 if (status!=RTEMS_SUCCESSFUL) {
694 if (status!=RTEMS_SUCCESSFUL) {
685 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
695 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
686 }
696 }
687 }
697 }
688 if (status == RTEMS_SUCCESSFUL) // CWF3
698 if (status == RTEMS_SUCCESSFUL) // CWF3
689 {
699 {
690 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
700 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
691 if (status!=RTEMS_SUCCESSFUL) {
701 if (status!=RTEMS_SUCCESSFUL) {
692 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
702 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
693 }
703 }
694 }
704 }
695 if (status == RTEMS_SUCCESSFUL) // CWF2
705 if (status == RTEMS_SUCCESSFUL) // CWF2
696 {
706 {
697 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
707 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
698 if (status!=RTEMS_SUCCESSFUL) {
708 if (status!=RTEMS_SUCCESSFUL) {
699 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
709 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
700 }
710 }
701 }
711 }
702 if (status == RTEMS_SUCCESSFUL) // CWF1
712 if (status == RTEMS_SUCCESSFUL) // CWF1
703 {
713 {
704 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
714 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
705 if (status!=RTEMS_SUCCESSFUL) {
715 if (status!=RTEMS_SUCCESSFUL) {
706 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
716 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
707 }
717 }
708 }
718 }
709 if (status == RTEMS_SUCCESSFUL) // SWBD
719 if (status == RTEMS_SUCCESSFUL) // SWBD
710 {
720 {
711 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
721 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
712 if (status!=RTEMS_SUCCESSFUL) {
722 if (status!=RTEMS_SUCCESSFUL) {
713 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
723 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
714 }
724 }
715 }
725 }
716
726
717 //*****
727 //*****
718 // MISC
728 // MISC
719 if (status == RTEMS_SUCCESSFUL) // HOUS
729 if (status == RTEMS_SUCCESSFUL) // HOUS
720 {
730 {
721 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
731 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
722 if (status!=RTEMS_SUCCESSFUL) {
732 if (status!=RTEMS_SUCCESSFUL) {
723 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
733 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
724 }
734 }
725 }
735 }
736 if (status == RTEMS_SUCCESSFUL) // AVGV
737 {
738 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
739 if (status!=RTEMS_SUCCESSFUL) {
740 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
741 }
742 }
726 if (status == RTEMS_SUCCESSFUL) // DUMB
743 if (status == RTEMS_SUCCESSFUL) // DUMB
727 {
744 {
728 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
745 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
729 if (status!=RTEMS_SUCCESSFUL) {
746 if (status!=RTEMS_SUCCESSFUL) {
730 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
747 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
731 }
748 }
732 }
749 }
733 if (status == RTEMS_SUCCESSFUL) // LOAD
750 if (status == RTEMS_SUCCESSFUL) // LOAD
734 {
751 {
735 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
752 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
736 if (status!=RTEMS_SUCCESSFUL) {
753 if (status!=RTEMS_SUCCESSFUL) {
737 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
754 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
738 }
755 }
739 }
756 }
740
757
741 return status;
758 return status;
742 }
759 }
743
760
744 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
761 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
745 {
762 {
746 rtems_status_code status_recv;
763 rtems_status_code status_recv;
747 rtems_status_code status_send;
764 rtems_status_code status_send;
748 rtems_status_code status_q_p0;
765 rtems_status_code status_q_p0;
749 rtems_status_code status_q_p1;
766 rtems_status_code status_q_p1;
750 rtems_status_code status_q_p2;
767 rtems_status_code status_q_p2;
751 rtems_status_code ret;
768 rtems_status_code ret;
752 rtems_id queue_id;
769 rtems_id queue_id;
753
770
754 ret = RTEMS_SUCCESSFUL;
771 ret = RTEMS_SUCCESSFUL;
755 queue_id = RTEMS_ID_NONE;
772 queue_id = RTEMS_ID_NONE;
756
773
757 //****************************************
774 //****************************************
758 // create the queue for handling valid TCs
775 // create the queue for handling valid TCs
759 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
776 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
760 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
777 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
761 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
778 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
762 if ( status_recv != RTEMS_SUCCESSFUL ) {
779 if ( status_recv != RTEMS_SUCCESSFUL ) {
763 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
780 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
764 }
781 }
765
782
766 //************************************************
783 //************************************************
767 // create the queue for handling TM packet sending
784 // create the queue for handling TM packet sending
768 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
785 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
769 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
786 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
770 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
787 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
771 if ( status_send != RTEMS_SUCCESSFUL ) {
788 if ( status_send != RTEMS_SUCCESSFUL ) {
772 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
789 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
773 }
790 }
774
791
775 //*****************************************************************************
792 //*****************************************************************************
776 // create the queue for handling averaged spectral matrices for processing @ f0
793 // create the queue for handling averaged spectral matrices for processing @ f0
777 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
794 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
778 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
795 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
779 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
796 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
780 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
797 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
781 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
798 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
782 }
799 }
783
800
784 //*****************************************************************************
801 //*****************************************************************************
785 // create the queue for handling averaged spectral matrices for processing @ f1
802 // create the queue for handling averaged spectral matrices for processing @ f1
786 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
803 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
787 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
804 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
788 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
805 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
789 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
806 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
790 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
807 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
791 }
808 }
792
809
793 //*****************************************************************************
810 //*****************************************************************************
794 // create the queue for handling averaged spectral matrices for processing @ f2
811 // create the queue for handling averaged spectral matrices for processing @ f2
795 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
812 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
796 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
813 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
797 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
814 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
798 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
815 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
799 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
816 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
800 }
817 }
801
818
802 if ( status_recv != RTEMS_SUCCESSFUL )
819 if ( status_recv != RTEMS_SUCCESSFUL )
803 {
820 {
804 ret = status_recv;
821 ret = status_recv;
805 }
822 }
806 else if( status_send != RTEMS_SUCCESSFUL )
823 else if( status_send != RTEMS_SUCCESSFUL )
807 {
824 {
808 ret = status_send;
825 ret = status_send;
809 }
826 }
810 else if( status_q_p0 != RTEMS_SUCCESSFUL )
827 else if( status_q_p0 != RTEMS_SUCCESSFUL )
811 {
828 {
812 ret = status_q_p0;
829 ret = status_q_p0;
813 }
830 }
814 else if( status_q_p1 != RTEMS_SUCCESSFUL )
831 else if( status_q_p1 != RTEMS_SUCCESSFUL )
815 {
832 {
816 ret = status_q_p1;
833 ret = status_q_p1;
817 }
834 }
818 else
835 else
819 {
836 {
820 ret = status_q_p2;
837 ret = status_q_p2;
821 }
838 }
822
839
823 return ret;
840 return ret;
824 }
841 }
825
842
826 rtems_status_code create_timecode_timer( void )
843 rtems_status_code create_timecode_timer( void )
827 {
844 {
828 rtems_status_code status;
845 rtems_status_code status;
829
846
830 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
847 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
831
848
832 if ( status != RTEMS_SUCCESSFUL )
849 if ( status != RTEMS_SUCCESSFUL )
833 {
850 {
834 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
851 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
835 }
852 }
836 else
853 else
837 {
854 {
838 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
855 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
839 }
856 }
840
857
841 return status;
858 return status;
842 }
859 }
843
860
844 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
861 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
845 {
862 {
846 rtems_status_code status;
863 rtems_status_code status;
847 rtems_name queue_name;
864 rtems_name queue_name;
848
865
849 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
866 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
850
867
851 status = rtems_message_queue_ident( queue_name, 0, queue_id );
868 status = rtems_message_queue_ident( queue_name, 0, queue_id );
852
869
853 return status;
870 return status;
854 }
871 }
855
872
856 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
873 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
857 {
874 {
858 rtems_status_code status;
875 rtems_status_code status;
859 rtems_name queue_name;
876 rtems_name queue_name;
860
877
861 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
878 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
862
879
863 status = rtems_message_queue_ident( queue_name, 0, queue_id );
880 status = rtems_message_queue_ident( queue_name, 0, queue_id );
864
881
865 return status;
882 return status;
866 }
883 }
867
884
868 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
885 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
869 {
886 {
870 rtems_status_code status;
887 rtems_status_code status;
871 rtems_name queue_name;
888 rtems_name queue_name;
872
889
873 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
890 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
874
891
875 status = rtems_message_queue_ident( queue_name, 0, queue_id );
892 status = rtems_message_queue_ident( queue_name, 0, queue_id );
876
893
877 return status;
894 return status;
878 }
895 }
879
896
880 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
897 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
881 {
898 {
882 rtems_status_code status;
899 rtems_status_code status;
883 rtems_name queue_name;
900 rtems_name queue_name;
884
901
885 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
902 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
886
903
887 status = rtems_message_queue_ident( queue_name, 0, queue_id );
904 status = rtems_message_queue_ident( queue_name, 0, queue_id );
888
905
889 return status;
906 return status;
890 }
907 }
891
908
892 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
909 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
893 {
910 {
894 rtems_status_code status;
911 rtems_status_code status;
895 rtems_name queue_name;
912 rtems_name queue_name;
896
913
897 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
914 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
898
915
899 status = rtems_message_queue_ident( queue_name, 0, queue_id );
916 status = rtems_message_queue_ident( queue_name, 0, queue_id );
900
917
901 return status;
918 return status;
902 }
919 }
903
920
904 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
921 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
905 {
922 {
906 u_int32_t count;
923 u_int32_t count;
907 rtems_status_code status;
924 rtems_status_code status;
908
925
909 count = 0;
926 count = 0;
910
927
911 status = rtems_message_queue_get_number_pending( queue_id, &count );
928 status = rtems_message_queue_get_number_pending( queue_id, &count );
912
929
913 count = count + 1;
930 count = count + 1;
914
931
915 if (status != RTEMS_SUCCESSFUL)
932 if (status != RTEMS_SUCCESSFUL)
916 {
933 {
917 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
934 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
918 }
935 }
919 else
936 else
920 {
937 {
921 if (count > *fifo_size_max)
938 if (count > *fifo_size_max)
922 {
939 {
923 *fifo_size_max = count;
940 *fifo_size_max = count;
924 }
941 }
925 }
942 }
926 }
943 }
927
944
928 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
945 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
929 {
946 {
930 unsigned char i;
947 unsigned char i;
931
948
932 //***************
949 //***************
933 // BUFFER ADDRESS
950 // BUFFER ADDRESS
934 for(i=0; i<nbNodes; i++)
951 for(i=0; i<nbNodes; i++)
935 {
952 {
936 ring[i].coarseTime = INT32_ALL_F;
953 ring[i].coarseTime = INT32_ALL_F;
937 ring[i].fineTime = INT32_ALL_F;
954 ring[i].fineTime = INT32_ALL_F;
938 ring[i].sid = INIT_CHAR;
955 ring[i].sid = INIT_CHAR;
939 ring[i].status = INIT_CHAR;
956 ring[i].status = INIT_CHAR;
940 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
957 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
941 }
958 }
942
959
943 //*****
960 //*****
944 // NEXT
961 // NEXT
945 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
962 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
946 for(i=0; i<nbNodes-1; i++)
963 for(i=0; i<nbNodes-1; i++)
947 {
964 {
948 ring[i].next = (ring_node*) &ring[ i + 1 ];
965 ring[i].next = (ring_node*) &ring[ i + 1 ];
949 }
966 }
950
967
951 //*********
968 //*********
952 // PREVIOUS
969 // PREVIOUS
953 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
970 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
954 for(i=1; i<nbNodes; i++)
971 for(i=1; i<nbNodes; i++)
955 {
972 {
956 ring[i].previous = (ring_node*) &ring[ i - 1 ];
973 ring[i].previous = (ring_node*) &ring[ i - 1 ];
957 }
974 }
958 }
975 }
@@ -1,1005 +1,1004
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
10 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
13
13
14 void timer_configure(unsigned char timer, unsigned int clock_divider,
14 void timer_configure(unsigned char timer, unsigned int clock_divider,
15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
16 {
16 {
17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
18 *
18 *
19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
22 * @param interrupt_level is the interrupt level that the timer drives.
22 * @param interrupt_level is the interrupt level that the timer drives.
23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
24 *
24 *
25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
26 *
26 *
27 */
27 */
28
28
29 rtems_status_code status;
29 rtems_status_code status;
30 rtems_isr_entry old_isr_handler;
30 rtems_isr_entry old_isr_handler;
31
31
32 old_isr_handler = NULL;
32 old_isr_handler = NULL;
33
33
34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
35
35
36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
37 if (status!=RTEMS_SUCCESSFUL)
37 if (status!=RTEMS_SUCCESSFUL)
38 {
38 {
39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
40 }
40 }
41
41
42 timer_set_clock_divider( timer, clock_divider);
42 timer_set_clock_divider( timer, clock_divider);
43 }
43 }
44
44
45 void timer_start(unsigned char timer)
45 void timer_start(unsigned char timer)
46 {
46 {
47 /** This function starts a GPTIMER timer.
47 /** This function starts a GPTIMER timer.
48 *
48 *
49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
51 *
51 *
52 */
52 */
53
53
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
59 }
59 }
60
60
61 void timer_stop(unsigned char timer)
61 void timer_stop(unsigned char timer)
62 {
62 {
63 /** This function stops a GPTIMER timer.
63 /** This function stops a GPTIMER timer.
64 *
64 *
65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
67 *
67 *
68 */
68 */
69
69
70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
73 }
73 }
74
74
75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
76 {
76 {
77 /** This function sets the clock divider of a GPTIMER timer.
77 /** This function sets the clock divider of a GPTIMER timer.
78 *
78 *
79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
82 *
82 *
83 */
83 */
84
84
85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
86 }
86 }
87
87
88 // WATCHDOG
88 // WATCHDOG
89
89
90 rtems_isr watchdog_isr( rtems_vector_number vector )
90 rtems_isr watchdog_isr( rtems_vector_number vector )
91 {
91 {
92 rtems_status_code status_code;
92 rtems_status_code status_code;
93
93
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
95
95
96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
97
97
98 exit(0);
98 exit(0);
99 }
99 }
100
100
101 void watchdog_configure(void)
101 void watchdog_configure(void)
102 {
102 {
103 /** This function configure the watchdog.
103 /** This function configure the watchdog.
104 *
104 *
105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
107 *
107 *
108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
109 *
109 *
110 */
110 */
111
111
112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
113
113
114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
115
115
116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 }
117 }
118
118
119 void watchdog_stop(void)
119 void watchdog_stop(void)
120 {
120 {
121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
122 timer_stop( TIMER_WATCHDOG );
122 timer_stop( TIMER_WATCHDOG );
123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
124 }
124 }
125
125
126 void watchdog_reload(void)
126 void watchdog_reload(void)
127 {
127 {
128 /** This function reloads the watchdog timer counter with the timer reload value.
128 /** This function reloads the watchdog timer counter with the timer reload value.
129 *
129 *
130 * @param void
130 * @param void
131 *
131 *
132 * @return void
132 * @return void
133 *
133 *
134 */
134 */
135
135
136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
137 }
137 }
138
138
139 void watchdog_start(void)
139 void watchdog_start(void)
140 {
140 {
141 /** This function starts the watchdog timer.
141 /** This function starts the watchdog timer.
142 *
142 *
143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
145 *
145 *
146 */
146 */
147
147
148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
149
149
150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
154
154
155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
156
156
157 }
157 }
158
158
159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
160 {
160 {
161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
162
162
163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
164
164
165 return 0;
165 return 0;
166 }
166 }
167
167
168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
169 {
169 {
170 /** This function sets the scaler reload register of the apbuart module
170 /** This function sets the scaler reload register of the apbuart module
171 *
171 *
172 * @param regs is the address of the apbuart registers in memory
172 * @param regs is the address of the apbuart registers in memory
173 * @param value is the value that will be stored in the scaler register
173 * @param value is the value that will be stored in the scaler register
174 *
174 *
175 * The value shall be set by the software to get data on the serial interface.
175 * The value shall be set by the software to get data on the serial interface.
176 *
176 *
177 */
177 */
178
178
179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
180
180
181 apbuart_regs->scaler = value;
181 apbuart_regs->scaler = value;
182
182
183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
184 }
184 }
185
185
186 //************
186 //************
187 // RTEMS TASKS
187 // RTEMS TASKS
188
188
189 rtems_task load_task(rtems_task_argument argument)
189 rtems_task load_task(rtems_task_argument argument)
190 {
190 {
191 BOOT_PRINTF("in LOAD *** \n")
191 BOOT_PRINTF("in LOAD *** \n")
192
192
193 rtems_status_code status;
193 rtems_status_code status;
194 unsigned int i;
194 unsigned int i;
195 unsigned int j;
195 unsigned int j;
196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
198
198
199 watchdog_period_id = RTEMS_ID_NONE;
199 watchdog_period_id = RTEMS_ID_NONE;
200
200
201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
202
202
203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
204 if( status != RTEMS_SUCCESSFUL ) {
204 if( status != RTEMS_SUCCESSFUL ) {
205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
206 }
206 }
207
207
208 i = 0;
208 i = 0;
209 j = 0;
209 j = 0;
210
210
211 watchdog_configure();
211 watchdog_configure();
212
212
213 watchdog_start();
213 watchdog_start();
214
214
215 set_sy_lfr_watchdog_enabled( true );
215 set_sy_lfr_watchdog_enabled( true );
216
216
217 while(1){
217 while(1){
218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
219 watchdog_reload();
219 watchdog_reload();
220 i = i + 1;
220 i = i + 1;
221 if ( i == WATCHDOG_LOOP_PRINTF )
221 if ( i == WATCHDOG_LOOP_PRINTF )
222 {
222 {
223 i = 0;
223 i = 0;
224 j = j + 1;
224 j = j + 1;
225 PRINTF1("%d\n", j)
225 PRINTF1("%d\n", j)
226 }
226 }
227 #ifdef DEBUG_WATCHDOG
227 #ifdef DEBUG_WATCHDOG
228 if (j == WATCHDOG_LOOP_DEBUG )
228 if (j == WATCHDOG_LOOP_DEBUG )
229 {
229 {
230 status = rtems_task_delete(RTEMS_SELF);
230 status = rtems_task_delete(RTEMS_SELF);
231 }
231 }
232 #endif
232 #endif
233 }
233 }
234 }
234 }
235
235
236 rtems_task hous_task(rtems_task_argument argument)
236 rtems_task hous_task(rtems_task_argument argument)
237 {
237 {
238 rtems_status_code status;
238 rtems_status_code status;
239 rtems_status_code spare_status;
239 rtems_status_code spare_status;
240 rtems_id queue_id;
240 rtems_id queue_id;
241 rtems_rate_monotonic_period_status period_status;
241 rtems_rate_monotonic_period_status period_status;
242 bool isSynchronized;
242 bool isSynchronized;
243
243
244 queue_id = RTEMS_ID_NONE;
244 queue_id = RTEMS_ID_NONE;
245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
246 isSynchronized = false;
246 isSynchronized = false;
247
247
248 status = get_message_queue_id_send( &queue_id );
248 status = get_message_queue_id_send( &queue_id );
249 if (status != RTEMS_SUCCESSFUL)
249 if (status != RTEMS_SUCCESSFUL)
250 {
250 {
251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
252 }
252 }
253
253
254 BOOT_PRINTF("in HOUS ***\n");
254 BOOT_PRINTF("in HOUS ***\n");
255
255
256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
258 if( status != RTEMS_SUCCESSFUL ) {
258 if( status != RTEMS_SUCCESSFUL ) {
259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
260 }
260 }
261 }
261 }
262
262
263 status = rtems_rate_monotonic_cancel(HK_id);
263 status = rtems_rate_monotonic_cancel(HK_id);
264 if( status != RTEMS_SUCCESSFUL ) {
264 if( status != RTEMS_SUCCESSFUL ) {
265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
266 }
266 }
267 else {
267 else {
268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
269 }
269 }
270
270
271 // startup phase
271 // startup phase
272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
277 {
277 {
278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
279 {
279 {
280 isSynchronized = true;
280 isSynchronized = true;
281 }
281 }
282 else
282 else
283 {
283 {
284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
285
285
286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
287 }
287 }
288 }
288 }
289 status = rtems_rate_monotonic_cancel(HK_id);
289 status = rtems_rate_monotonic_cancel(HK_id);
290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
291
291
292 set_hk_lfr_reset_cause( POWER_ON );
292 set_hk_lfr_reset_cause( POWER_ON );
293
293
294 while(1){ // launch the rate monotonic task
294 while(1){ // launch the rate monotonic task
295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
296 if ( status != RTEMS_SUCCESSFUL ) {
296 if ( status != RTEMS_SUCCESSFUL ) {
297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
299 }
299 }
300 else {
300 else {
301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
303 increment_seq_counter( &sequenceCounterHK );
303 increment_seq_counter( &sequenceCounterHK );
304
304
305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
311
311
312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
313
313
314 spacewire_read_statistics();
314 spacewire_read_statistics();
315
315
316 update_hk_with_grspw_stats();
316 update_hk_with_grspw_stats();
317
317
318 set_hk_lfr_time_not_synchro();
318 set_hk_lfr_time_not_synchro();
319
319
320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
325
325
326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
331
331
332 hk_lfr_le_me_he_update();
332 hk_lfr_le_me_he_update();
333
333
334 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = cp_rpw_sc_rw1_rw2_f_flags;
334 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = cp_rpw_sc_rw1_rw2_f_flags;
335 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = cp_rpw_sc_rw3_rw4_f_flags;
335 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = cp_rpw_sc_rw3_rw4_f_flags;
336
336
337 // SEND PACKET
337 // SEND PACKET
338 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
338 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
339 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
339 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
340 if (status != RTEMS_SUCCESSFUL) {
340 if (status != RTEMS_SUCCESSFUL) {
341 PRINTF1("in HOUS *** ERR send: %d\n", status)
341 PRINTF1("in HOUS *** ERR send: %d\n", status)
342 }
342 }
343 }
343 }
344 }
344 }
345
345
346 PRINTF("in HOUS *** deleting task\n")
346 PRINTF("in HOUS *** deleting task\n")
347
347
348 status = rtems_task_delete( RTEMS_SELF ); // should not return
348 status = rtems_task_delete( RTEMS_SELF ); // should not return
349
349
350 return;
350 return;
351 }
351 }
352
352
353 rtems_task avgv_task(rtems_task_argument argument)
353 rtems_task avgv_task(rtems_task_argument argument)
354 {
354 {
355 #define MOVING_AVERAGE 16
355 #define MOVING_AVERAGE 16
356 rtems_status_code status;
356 rtems_status_code status;
357 static unsigned int v[MOVING_AVERAGE] = {0};
357 static unsigned int v[MOVING_AVERAGE] = {0};
358 static unsigned int e1[MOVING_AVERAGE] = {0};
358 static unsigned int e1[MOVING_AVERAGE] = {0};
359 static unsigned int e2[MOVING_AVERAGE] = {0};
359 static unsigned int e2[MOVING_AVERAGE] = {0};
360 float average_v;
360 float average_v;
361 float average_e1;
361 float average_e1;
362 float average_e2;
362 float average_e2;
363 float newValue_v;
363 float newValue_v;
364 float newValue_e1;
364 float newValue_e1;
365 float newValue_e2;
365 float newValue_e2;
366 unsigned char k;
366 unsigned char k;
367 unsigned char indexOfOldValue;
367 unsigned char indexOfOldValue;
368
368
369 BOOT_PRINTF("in AVGV ***\n");
369 BOOT_PRINTF("in AVGV ***\n");
370
370
371 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
371 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
372 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
372 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
373 if( status != RTEMS_SUCCESSFUL ) {
373 if( status != RTEMS_SUCCESSFUL ) {
374 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
374 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
375 }
375 }
376 }
376 }
377
377
378 status = rtems_rate_monotonic_cancel(AVGV_id);
378 status = rtems_rate_monotonic_cancel(AVGV_id);
379 if( status != RTEMS_SUCCESSFUL ) {
379 if( status != RTEMS_SUCCESSFUL ) {
380 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
380 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
381 }
381 }
382 else {
382 else {
383 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
383 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
384 }
384 }
385
385
386 // initialize values
386 // initialize values
387 indexOfOldValue = MOVING_AVERAGE - 1;
387 indexOfOldValue = MOVING_AVERAGE - 1;
388 average_v = INIT_FLOAT;
388 average_v = INIT_FLOAT;
389 average_e1 = INIT_FLOAT;
389 average_e1 = INIT_FLOAT;
390 average_e2 = INIT_FLOAT;
390 average_e2 = INIT_FLOAT;
391 newValue_v = INIT_FLOAT;
391 newValue_v = INIT_FLOAT;
392 newValue_e1 = INIT_FLOAT;
392 newValue_e1 = INIT_FLOAT;
393 newValue_e2 = INIT_FLOAT;
393 newValue_e2 = INIT_FLOAT;
394
394
395 k = INIT_CHAR;
395 k = INIT_CHAR;
396
396
397 while(1)
397 while(1)
398 { // launch the rate monotonic task
398 { // launch the rate monotonic task
399 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
399 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
400 if ( status != RTEMS_SUCCESSFUL )
400 if ( status != RTEMS_SUCCESSFUL )
401 {
401 {
402 PRINTF1( "in AVGV *** ERR period: %d\n", status);
402 PRINTF1( "in AVGV *** ERR period: %d\n", status);
403 }
403 }
404 else
404 else
405 {
405 {
406 // get new values
406 // get new values
407 newValue_v = waveform_picker_regs->v;
407 newValue_v = waveform_picker_regs->v;
408 newValue_e1 = waveform_picker_regs->e1;
408 newValue_e1 = waveform_picker_regs->e1;
409 newValue_e2 = waveform_picker_regs->e2;
409 newValue_e2 = waveform_picker_regs->e2;
410
410
411 // compute the moving average
411 // compute the moving average
412 average_v = average_v + newValue_v - v[k];
412 average_v = average_v + newValue_v - v[k];
413 average_e1 = average_e1 + newValue_e1 - e1[k];
413 average_e1 = average_e1 + newValue_e1 - e1[k];
414 average_e2 = average_e2 + newValue_e2 - e2[k];
414 average_e2 = average_e2 + newValue_e2 - e2[k];
415
415
416 // store new values in buffers
416 // store new values in buffers
417 v[k] = newValue_v;
417 v[k] = newValue_v;
418 e1[k] = newValue_e1;
418 e1[k] = newValue_e1;
419 e2[k] = newValue_e2;
419 e2[k] = newValue_e2;
420 }
420 }
421 if (k == (MOVING_AVERAGE-1))
421 if (k == (MOVING_AVERAGE-1))
422 {
422 {
423 k = 0;
423 k = 0;
424 PRINTF("tick\n");
425 }
424 }
426 else
425 else
427 {
426 {
428 k++;
427 k++;
429 }
428 }
430 //update int16 values
429 //update int16 values
431 hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / ((float) MOVING_AVERAGE) );
430 hk_lfr_sc_v_f3_as_int16 = (int16_t) (average_v / ((float) MOVING_AVERAGE) );
432 hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / ((float) MOVING_AVERAGE) );
431 hk_lfr_sc_e1_f3_as_int16 = (int16_t) (average_e1 / ((float) MOVING_AVERAGE) );
433 hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / ((float) MOVING_AVERAGE) );
432 hk_lfr_sc_e2_f3_as_int16 = (int16_t) (average_e2 / ((float) MOVING_AVERAGE) );
434 }
433 }
435
434
436 PRINTF("in AVGV *** deleting task\n");
435 PRINTF("in AVGV *** deleting task\n");
437
436
438 status = rtems_task_delete( RTEMS_SELF ); // should not return
437 status = rtems_task_delete( RTEMS_SELF ); // should not return
439
438
440 return;
439 return;
441 }
440 }
442
441
443 rtems_task dumb_task( rtems_task_argument unused )
442 rtems_task dumb_task( rtems_task_argument unused )
444 {
443 {
445 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
444 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
446 *
445 *
447 * @param unused is the starting argument of the RTEMS task
446 * @param unused is the starting argument of the RTEMS task
448 *
447 *
449 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
448 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
450 *
449 *
451 */
450 */
452
451
453 unsigned int i;
452 unsigned int i;
454 unsigned int intEventOut;
453 unsigned int intEventOut;
455 unsigned int coarse_time = 0;
454 unsigned int coarse_time = 0;
456 unsigned int fine_time = 0;
455 unsigned int fine_time = 0;
457 rtems_event_set event_out;
456 rtems_event_set event_out;
458
457
459 event_out = EVENT_SETS_NONE_PENDING;
458 event_out = EVENT_SETS_NONE_PENDING;
460
459
461 BOOT_PRINTF("in DUMB *** \n")
460 BOOT_PRINTF("in DUMB *** \n")
462
461
463 while(1){
462 while(1){
464 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
463 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
465 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
464 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
466 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
465 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
467 | RTEMS_EVENT_14,
466 | RTEMS_EVENT_14,
468 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
467 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
469 intEventOut = (unsigned int) event_out;
468 intEventOut = (unsigned int) event_out;
470 for ( i=0; i<NB_RTEMS_EVENTS; i++)
469 for ( i=0; i<NB_RTEMS_EVENTS; i++)
471 {
470 {
472 if ( ((intEventOut >> i) & 1) != 0)
471 if ( ((intEventOut >> i) & 1) != 0)
473 {
472 {
474 coarse_time = time_management_regs->coarse_time;
473 coarse_time = time_management_regs->coarse_time;
475 fine_time = time_management_regs->fine_time;
474 fine_time = time_management_regs->fine_time;
476 if (i==EVENT_12)
475 if (i==EVENT_12)
477 {
476 {
478 PRINTF1("%s\n", DUMB_MESSAGE_12)
477 PRINTF1("%s\n", DUMB_MESSAGE_12)
479 }
478 }
480 if (i==EVENT_13)
479 if (i==EVENT_13)
481 {
480 {
482 PRINTF1("%s\n", DUMB_MESSAGE_13)
481 PRINTF1("%s\n", DUMB_MESSAGE_13)
483 }
482 }
484 if (i==EVENT_14)
483 if (i==EVENT_14)
485 {
484 {
486 PRINTF1("%s\n", DUMB_MESSAGE_1)
485 PRINTF1("%s\n", DUMB_MESSAGE_1)
487 }
486 }
488 }
487 }
489 }
488 }
490 }
489 }
491 }
490 }
492
491
493 //*****************************
492 //*****************************
494 // init housekeeping parameters
493 // init housekeeping parameters
495
494
496 void init_housekeeping_parameters( void )
495 void init_housekeeping_parameters( void )
497 {
496 {
498 /** This function initialize the housekeeping_packet global variable with default values.
497 /** This function initialize the housekeeping_packet global variable with default values.
499 *
498 *
500 */
499 */
501
500
502 unsigned int i = 0;
501 unsigned int i = 0;
503 unsigned char *parameters;
502 unsigned char *parameters;
504 unsigned char sizeOfHK;
503 unsigned char sizeOfHK;
505
504
506 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
505 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
507
506
508 parameters = (unsigned char*) &housekeeping_packet;
507 parameters = (unsigned char*) &housekeeping_packet;
509
508
510 for(i = 0; i< sizeOfHK; i++)
509 for(i = 0; i< sizeOfHK; i++)
511 {
510 {
512 parameters[i] = INIT_CHAR;
511 parameters[i] = INIT_CHAR;
513 }
512 }
514
513
515 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
514 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
516 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
515 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
517 housekeeping_packet.reserved = DEFAULT_RESERVED;
516 housekeeping_packet.reserved = DEFAULT_RESERVED;
518 housekeeping_packet.userApplication = CCSDS_USER_APP;
517 housekeeping_packet.userApplication = CCSDS_USER_APP;
519 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
518 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
520 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
519 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
521 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
520 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
522 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
521 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
523 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
522 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
524 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
523 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
525 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
524 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
526 housekeeping_packet.serviceType = TM_TYPE_HK;
525 housekeeping_packet.serviceType = TM_TYPE_HK;
527 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
526 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
528 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
527 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
529 housekeeping_packet.sid = SID_HK;
528 housekeeping_packet.sid = SID_HK;
530
529
531 // init status word
530 // init status word
532 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
531 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
533 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
532 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
534 // init software version
533 // init software version
535 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
534 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
536 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
535 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
537 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
536 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
538 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
537 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
539 // init fpga version
538 // init fpga version
540 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
539 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
541 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
540 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
542 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
541 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
543 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
542 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
544
543
545 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
544 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
546 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
545 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
547 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
546 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
548 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
547 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
549 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
548 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
550 }
549 }
551
550
552 void increment_seq_counter( unsigned short *packetSequenceControl )
551 void increment_seq_counter( unsigned short *packetSequenceControl )
553 {
552 {
554 /** This function increment the sequence counter passes in argument.
553 /** This function increment the sequence counter passes in argument.
555 *
554 *
556 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
555 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
557 *
556 *
558 */
557 */
559
558
560 unsigned short segmentation_grouping_flag;
559 unsigned short segmentation_grouping_flag;
561 unsigned short sequence_cnt;
560 unsigned short sequence_cnt;
562
561
563 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
562 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
564 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
563 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
565
564
566 if ( sequence_cnt < SEQ_CNT_MAX)
565 if ( sequence_cnt < SEQ_CNT_MAX)
567 {
566 {
568 sequence_cnt = sequence_cnt + 1;
567 sequence_cnt = sequence_cnt + 1;
569 }
568 }
570 else
569 else
571 {
570 {
572 sequence_cnt = 0;
571 sequence_cnt = 0;
573 }
572 }
574
573
575 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
574 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
576 }
575 }
577
576
578 void getTime( unsigned char *time)
577 void getTime( unsigned char *time)
579 {
578 {
580 /** This function write the current local time in the time buffer passed in argument.
579 /** This function write the current local time in the time buffer passed in argument.
581 *
580 *
582 */
581 */
583
582
584 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
583 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
585 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
584 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
586 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
585 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
587 time[3] = (unsigned char) (time_management_regs->coarse_time);
586 time[3] = (unsigned char) (time_management_regs->coarse_time);
588 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
587 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
589 time[5] = (unsigned char) (time_management_regs->fine_time);
588 time[5] = (unsigned char) (time_management_regs->fine_time);
590 }
589 }
591
590
592 unsigned long long int getTimeAsUnsignedLongLongInt( )
591 unsigned long long int getTimeAsUnsignedLongLongInt( )
593 {
592 {
594 /** This function write the current local time in the time buffer passed in argument.
593 /** This function write the current local time in the time buffer passed in argument.
595 *
594 *
596 */
595 */
597 unsigned long long int time;
596 unsigned long long int time;
598
597
599 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
598 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
600 + time_management_regs->fine_time;
599 + time_management_regs->fine_time;
601
600
602 return time;
601 return time;
603 }
602 }
604
603
605 void send_dumb_hk( void )
604 void send_dumb_hk( void )
606 {
605 {
607 Packet_TM_LFR_HK_t dummy_hk_packet;
606 Packet_TM_LFR_HK_t dummy_hk_packet;
608 unsigned char *parameters;
607 unsigned char *parameters;
609 unsigned int i;
608 unsigned int i;
610 rtems_id queue_id;
609 rtems_id queue_id;
611
610
612 queue_id = RTEMS_ID_NONE;
611 queue_id = RTEMS_ID_NONE;
613
612
614 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
613 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
615 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
614 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
616 dummy_hk_packet.reserved = DEFAULT_RESERVED;
615 dummy_hk_packet.reserved = DEFAULT_RESERVED;
617 dummy_hk_packet.userApplication = CCSDS_USER_APP;
616 dummy_hk_packet.userApplication = CCSDS_USER_APP;
618 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
617 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
619 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
618 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
620 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
619 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
621 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
620 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
622 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
621 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
623 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
622 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
624 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
623 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
625 dummy_hk_packet.serviceType = TM_TYPE_HK;
624 dummy_hk_packet.serviceType = TM_TYPE_HK;
626 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
625 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
627 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
626 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
628 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
627 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
629 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
628 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
630 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
629 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
631 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
630 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
632 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
631 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
633 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
632 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
634 dummy_hk_packet.sid = SID_HK;
633 dummy_hk_packet.sid = SID_HK;
635
634
636 // init status word
635 // init status word
637 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
636 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
638 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
637 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
639 // init software version
638 // init software version
640 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
639 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
641 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
640 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
642 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
641 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
643 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
642 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
644 // init fpga version
643 // init fpga version
645 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
644 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
646 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
645 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
647 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
646 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
648 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
647 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
649
648
650 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
649 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
651
650
652 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
651 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
653 {
652 {
654 parameters[i] = INT8_ALL_F;
653 parameters[i] = INT8_ALL_F;
655 }
654 }
656
655
657 get_message_queue_id_send( &queue_id );
656 get_message_queue_id_send( &queue_id );
658
657
659 rtems_message_queue_send( queue_id, &dummy_hk_packet,
658 rtems_message_queue_send( queue_id, &dummy_hk_packet,
660 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
659 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
661 }
660 }
662
661
663 void get_temperatures( unsigned char *temperatures )
662 void get_temperatures( unsigned char *temperatures )
664 {
663 {
665 unsigned char* temp_scm_ptr;
664 unsigned char* temp_scm_ptr;
666 unsigned char* temp_pcb_ptr;
665 unsigned char* temp_pcb_ptr;
667 unsigned char* temp_fpga_ptr;
666 unsigned char* temp_fpga_ptr;
668
667
669 // SEL1 SEL0
668 // SEL1 SEL0
670 // 0 0 => PCB
669 // 0 0 => PCB
671 // 0 1 => FPGA
670 // 0 1 => FPGA
672 // 1 0 => SCM
671 // 1 0 => SCM
673
672
674 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
673 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
675 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
674 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
676 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
675 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
677
676
678 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
677 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
679 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
678 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
680 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
679 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
681 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
680 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
682 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
681 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
683 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
682 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
684 }
683 }
685
684
686 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
685 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
687 {
686 {
688 unsigned char* v_ptr;
687 unsigned char* v_ptr;
689 unsigned char* e1_ptr;
688 unsigned char* e1_ptr;
690 unsigned char* e2_ptr;
689 unsigned char* e2_ptr;
691
690
692 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
691 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
693 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
692 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
694 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
693 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
695
694
696 spacecraft_potential[BYTE_0] = v_ptr[0];
695 spacecraft_potential[BYTE_0] = v_ptr[0];
697 spacecraft_potential[BYTE_1] = v_ptr[1];
696 spacecraft_potential[BYTE_1] = v_ptr[1];
698 spacecraft_potential[BYTE_2] = e1_ptr[0];
697 spacecraft_potential[BYTE_2] = e1_ptr[0];
699 spacecraft_potential[BYTE_3] = e1_ptr[1];
698 spacecraft_potential[BYTE_3] = e1_ptr[1];
700 spacecraft_potential[BYTE_4] = e2_ptr[0];
699 spacecraft_potential[BYTE_4] = e2_ptr[0];
701 spacecraft_potential[BYTE_5] = e2_ptr[1];
700 spacecraft_potential[BYTE_5] = e2_ptr[1];
702 }
701 }
703
702
704 void get_cpu_load( unsigned char *resource_statistics )
703 void get_cpu_load( unsigned char *resource_statistics )
705 {
704 {
706 unsigned char cpu_load;
705 unsigned char cpu_load;
707
706
708 cpu_load = lfr_rtems_cpu_usage_report();
707 cpu_load = lfr_rtems_cpu_usage_report();
709
708
710 // HK_LFR_CPU_LOAD
709 // HK_LFR_CPU_LOAD
711 resource_statistics[0] = cpu_load;
710 resource_statistics[0] = cpu_load;
712
711
713 // HK_LFR_CPU_LOAD_MAX
712 // HK_LFR_CPU_LOAD_MAX
714 if (cpu_load > resource_statistics[1])
713 if (cpu_load > resource_statistics[1])
715 {
714 {
716 resource_statistics[1] = cpu_load;
715 resource_statistics[1] = cpu_load;
717 }
716 }
718
717
719 // CPU_LOAD_AVE
718 // CPU_LOAD_AVE
720 resource_statistics[BYTE_2] = 0;
719 resource_statistics[BYTE_2] = 0;
721
720
722 #ifndef PRINT_TASK_STATISTICS
721 #ifndef PRINT_TASK_STATISTICS
723 rtems_cpu_usage_reset();
722 rtems_cpu_usage_reset();
724 #endif
723 #endif
725
724
726 }
725 }
727
726
728 void set_hk_lfr_sc_potential_flag( bool state )
727 void set_hk_lfr_sc_potential_flag( bool state )
729 {
728 {
730 if (state == true)
729 if (state == true)
731 {
730 {
732 housekeeping_packet.lfr_status_word[1] =
731 housekeeping_packet.lfr_status_word[1] =
733 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
732 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
734 }
733 }
735 else
734 else
736 {
735 {
737 housekeeping_packet.lfr_status_word[1] =
736 housekeeping_packet.lfr_status_word[1] =
738 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
737 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
739 }
738 }
740 }
739 }
741
740
742 void set_sy_lfr_pas_filter_enabled( bool state )
741 void set_sy_lfr_pas_filter_enabled( bool state )
743 {
742 {
744 if (state == true)
743 if (state == true)
745 {
744 {
746 housekeeping_packet.lfr_status_word[1] =
745 housekeeping_packet.lfr_status_word[1] =
747 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
746 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
748 }
747 }
749 else
748 else
750 {
749 {
751 housekeeping_packet.lfr_status_word[1] =
750 housekeeping_packet.lfr_status_word[1] =
752 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
751 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
753 }
752 }
754 }
753 }
755
754
756 void set_sy_lfr_watchdog_enabled( bool state )
755 void set_sy_lfr_watchdog_enabled( bool state )
757 {
756 {
758 if (state == true)
757 if (state == true)
759 {
758 {
760 housekeeping_packet.lfr_status_word[1] =
759 housekeeping_packet.lfr_status_word[1] =
761 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
760 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
762 }
761 }
763 else
762 else
764 {
763 {
765 housekeeping_packet.lfr_status_word[1] =
764 housekeeping_packet.lfr_status_word[1] =
766 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
765 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
767 }
766 }
768 }
767 }
769
768
770 void set_hk_lfr_calib_enable( bool state )
769 void set_hk_lfr_calib_enable( bool state )
771 {
770 {
772 if (state == true)
771 if (state == true)
773 {
772 {
774 housekeeping_packet.lfr_status_word[1] =
773 housekeeping_packet.lfr_status_word[1] =
775 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
774 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
776 }
775 }
777 else
776 else
778 {
777 {
779 housekeeping_packet.lfr_status_word[1] =
778 housekeeping_packet.lfr_status_word[1] =
780 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
779 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
781 }
780 }
782 }
781 }
783
782
784 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
783 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
785 {
784 {
786 housekeeping_packet.lfr_status_word[1] =
785 housekeeping_packet.lfr_status_word[1] =
787 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
786 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
788
787
789 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
788 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
790 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
789 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
791
790
792 }
791 }
793
792
794 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
793 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
795 {
794 {
796 int delta;
795 int delta;
797
796
798 delta = 0;
797 delta = 0;
799
798
800 if (newValue >= oldValue)
799 if (newValue >= oldValue)
801 {
800 {
802 delta = newValue - oldValue;
801 delta = newValue - oldValue;
803 }
802 }
804 else
803 else
805 {
804 {
806 delta = (CONST_256 - oldValue) + newValue;
805 delta = (CONST_256 - oldValue) + newValue;
807 }
806 }
808
807
809 *counter = *counter + delta;
808 *counter = *counter + delta;
810 }
809 }
811
810
812 void hk_lfr_le_update( void )
811 void hk_lfr_le_update( void )
813 {
812 {
814 static hk_lfr_le_t old_hk_lfr_le = {0};
813 static hk_lfr_le_t old_hk_lfr_le = {0};
815 hk_lfr_le_t new_hk_lfr_le;
814 hk_lfr_le_t new_hk_lfr_le;
816 unsigned int counter;
815 unsigned int counter;
817
816
818 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
817 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
819
818
820 // DPU
819 // DPU
821 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
820 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
822 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
821 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
823 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
822 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
824 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
823 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
825 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
824 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
826 // TIMECODE
825 // TIMECODE
827 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
826 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
828 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
827 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
829 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
828 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
830 // TIME
829 // TIME
831 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
830 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
832 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
831 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
833 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
832 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
834 //AHB
833 //AHB
835 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
834 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
836 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
835 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
837 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
836 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
838
837
839 // update the le counter
838 // update the le counter
840 // DPU
839 // DPU
841 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
840 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
842 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
841 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
843 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
842 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
844 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
843 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
845 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
844 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
846 // TIMECODE
845 // TIMECODE
847 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
846 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
848 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
847 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
849 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
848 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
850 // TIME
849 // TIME
851 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
850 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
852 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
851 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
853 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
852 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
854 // AHB
853 // AHB
855 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
854 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
856
855
857 // DPU
856 // DPU
858 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
857 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
859 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
858 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
860 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
859 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
861 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
860 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
862 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
861 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
863 // TIMECODE
862 // TIMECODE
864 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
863 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
865 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
864 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
866 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
865 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
867 // TIME
866 // TIME
868 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
867 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
869 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
868 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
870 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
869 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
871 //AHB
870 //AHB
872 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
871 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
873 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
872 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
874 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
873 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
875
874
876 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
875 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
877 // LE
876 // LE
878 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
877 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
879 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
878 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
880 }
879 }
881
880
882 void hk_lfr_me_update( void )
881 void hk_lfr_me_update( void )
883 {
882 {
884 static hk_lfr_me_t old_hk_lfr_me = {0};
883 static hk_lfr_me_t old_hk_lfr_me = {0};
885 hk_lfr_me_t new_hk_lfr_me;
884 hk_lfr_me_t new_hk_lfr_me;
886 unsigned int counter;
885 unsigned int counter;
887
886
888 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
887 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
889
888
890 // get the current values
889 // get the current values
891 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
890 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
892 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
891 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
893 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
892 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
894 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
893 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
895
894
896 // update the me counter
895 // update the me counter
897 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
896 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
898 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
897 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
899 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
898 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
900 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
899 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
901
900
902 // store the counters for the next time
901 // store the counters for the next time
903 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
902 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
904 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
903 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
905 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
904 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
906 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
905 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
907
906
908 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
907 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
909 // ME
908 // ME
910 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
909 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
911 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
910 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
912 }
911 }
913
912
914 void hk_lfr_le_me_he_update()
913 void hk_lfr_le_me_he_update()
915 {
914 {
916
915
917 unsigned int hk_lfr_he_cnt;
916 unsigned int hk_lfr_he_cnt;
918
917
919 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
918 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
920
919
921 //update the low severity error counter
920 //update the low severity error counter
922 hk_lfr_le_update( );
921 hk_lfr_le_update( );
923
922
924 //update the medium severity error counter
923 //update the medium severity error counter
925 hk_lfr_me_update();
924 hk_lfr_me_update();
926
925
927 //update the high severity error counter
926 //update the high severity error counter
928 hk_lfr_he_cnt = 0;
927 hk_lfr_he_cnt = 0;
929
928
930 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
929 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
931 // HE
930 // HE
932 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
931 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
933 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
932 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
934
933
935 }
934 }
936
935
937 void set_hk_lfr_time_not_synchro()
936 void set_hk_lfr_time_not_synchro()
938 {
937 {
939 static unsigned char synchroLost = 1;
938 static unsigned char synchroLost = 1;
940 int synchronizationBit;
939 int synchronizationBit;
941
940
942 // get the synchronization bit
941 // get the synchronization bit
943 synchronizationBit =
942 synchronizationBit =
944 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
943 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
945
944
946 switch (synchronizationBit)
945 switch (synchronizationBit)
947 {
946 {
948 case 0:
947 case 0:
949 if (synchroLost == 1)
948 if (synchroLost == 1)
950 {
949 {
951 synchroLost = 0;
950 synchroLost = 0;
952 }
951 }
953 break;
952 break;
954 case 1:
953 case 1:
955 if (synchroLost == 0 )
954 if (synchroLost == 0 )
956 {
955 {
957 synchroLost = 1;
956 synchroLost = 1;
958 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
957 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
959 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
958 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
960 }
959 }
961 break;
960 break;
962 default:
961 default:
963 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
962 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
964 break;
963 break;
965 }
964 }
966
965
967 }
966 }
968
967
969 void set_hk_lfr_ahb_correctable() // CRITICITY L
968 void set_hk_lfr_ahb_correctable() // CRITICITY L
970 {
969 {
971 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
970 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
972 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
971 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
973 * detected errors in the cache, in the integer unit and in the floating point unit.
972 * detected errors in the cache, in the integer unit and in the floating point unit.
974 *
973 *
975 * @param void
974 * @param void
976 *
975 *
977 * @return void
976 * @return void
978 *
977 *
979 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
978 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
980 *
979 *
981 */
980 */
982
981
983 unsigned int ahb_correctable;
982 unsigned int ahb_correctable;
984 unsigned int instructionErrorCounter;
983 unsigned int instructionErrorCounter;
985 unsigned int dataErrorCounter;
984 unsigned int dataErrorCounter;
986 unsigned int fprfErrorCounter;
985 unsigned int fprfErrorCounter;
987 unsigned int iurfErrorCounter;
986 unsigned int iurfErrorCounter;
988
987
989 instructionErrorCounter = 0;
988 instructionErrorCounter = 0;
990 dataErrorCounter = 0;
989 dataErrorCounter = 0;
991 fprfErrorCounter = 0;
990 fprfErrorCounter = 0;
992 iurfErrorCounter = 0;
991 iurfErrorCounter = 0;
993
992
994 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
993 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
995 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
994 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
996
995
997 ahb_correctable = instructionErrorCounter
996 ahb_correctable = instructionErrorCounter
998 + dataErrorCounter
997 + dataErrorCounter
999 + fprfErrorCounter
998 + fprfErrorCounter
1000 + iurfErrorCounter
999 + iurfErrorCounter
1001 + housekeeping_packet.hk_lfr_ahb_correctable;
1000 + housekeeping_packet.hk_lfr_ahb_correctable;
1002
1001
1003 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1002 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1004
1003
1005 }
1004 }
@@ -1,1661 +1,1659
1 /** Functions and tasks related to TeleCommand handling.
1 /** Functions and tasks related to TeleCommand handling.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands:\n
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
7 * action launching\n
8 * TC parsing\n
8 * TC parsing\n
9 * ...
9 * ...
10 *
10 *
11 */
11 */
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "math.h"
14 #include "math.h"
15
15
16 //***********
16 //***********
17 // RTEMS TASK
17 // RTEMS TASK
18
18
19 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
20 {
20 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
22 *
23 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
24 *
24 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
27 *
27 *
28 */
28 */
29
29
30 int result;
30 int result;
31 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[BYTES_PER_TIME];
35 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
38
38
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 size = 0;
40 size = 0;
41 queue_rcv_id = RTEMS_ID_NONE;
41 queue_rcv_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
43
43
44 status = get_message_queue_id_recv( &queue_rcv_id );
44 status = get_message_queue_id_recv( &queue_rcv_id );
45 if (status != RTEMS_SUCCESSFUL)
45 if (status != RTEMS_SUCCESSFUL)
46 {
46 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
48 }
48 }
49
49
50 status = get_message_queue_id_send( &queue_snd_id );
50 status = get_message_queue_id_send( &queue_snd_id );
51 if (status != RTEMS_SUCCESSFUL)
51 if (status != RTEMS_SUCCESSFUL)
52 {
52 {
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
54 }
54 }
55
55
56 result = LFR_SUCCESSFUL;
56 result = LFR_SUCCESSFUL;
57 subtype = 0; // subtype of the current TC packet
57 subtype = 0; // subtype of the current TC packet
58
58
59 BOOT_PRINTF("in ACTN *** \n");
59 BOOT_PRINTF("in ACTN *** \n");
60
60
61 while(1)
61 while(1)
62 {
62 {
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
65 getTime( time ); // set time to the current time
65 getTime( time ); // set time to the current time
66 if (status!=RTEMS_SUCCESSFUL)
66 if (status!=RTEMS_SUCCESSFUL)
67 {
67 {
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
69 }
69 }
70 else
70 else
71 {
71 {
72 subtype = TC.serviceSubType;
72 subtype = TC.serviceSubType;
73 switch(subtype)
73 switch(subtype)
74 {
74 {
75 case TC_SUBTYPE_RESET:
75 case TC_SUBTYPE_RESET:
76 result = action_reset( &TC, queue_snd_id, time );
76 result = action_reset( &TC, queue_snd_id, time );
77 close_action( &TC, result, queue_snd_id );
77 close_action( &TC, result, queue_snd_id );
78 break;
78 break;
79 case TC_SUBTYPE_LOAD_COMM:
79 case TC_SUBTYPE_LOAD_COMM:
80 result = action_load_common_par( &TC );
80 result = action_load_common_par( &TC );
81 close_action( &TC, result, queue_snd_id );
81 close_action( &TC, result, queue_snd_id );
82 break;
82 break;
83 case TC_SUBTYPE_LOAD_NORM:
83 case TC_SUBTYPE_LOAD_NORM:
84 result = action_load_normal_par( &TC, queue_snd_id, time );
84 result = action_load_normal_par( &TC, queue_snd_id, time );
85 close_action( &TC, result, queue_snd_id );
85 close_action( &TC, result, queue_snd_id );
86 break;
86 break;
87 case TC_SUBTYPE_LOAD_BURST:
87 case TC_SUBTYPE_LOAD_BURST:
88 result = action_load_burst_par( &TC, queue_snd_id, time );
88 result = action_load_burst_par( &TC, queue_snd_id, time );
89 close_action( &TC, result, queue_snd_id );
89 close_action( &TC, result, queue_snd_id );
90 break;
90 break;
91 case TC_SUBTYPE_LOAD_SBM1:
91 case TC_SUBTYPE_LOAD_SBM1:
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
93 close_action( &TC, result, queue_snd_id );
93 close_action( &TC, result, queue_snd_id );
94 break;
94 break;
95 case TC_SUBTYPE_LOAD_SBM2:
95 case TC_SUBTYPE_LOAD_SBM2:
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
97 close_action( &TC, result, queue_snd_id );
97 close_action( &TC, result, queue_snd_id );
98 break;
98 break;
99 case TC_SUBTYPE_DUMP:
99 case TC_SUBTYPE_DUMP:
100 result = action_dump_par( &TC, queue_snd_id );
100 result = action_dump_par( &TC, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
102 break;
102 break;
103 case TC_SUBTYPE_ENTER:
103 case TC_SUBTYPE_ENTER:
104 result = action_enter_mode( &TC, queue_snd_id );
104 result = action_enter_mode( &TC, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
106 break;
106 break;
107 case TC_SUBTYPE_UPDT_INFO:
107 case TC_SUBTYPE_UPDT_INFO:
108 result = action_update_info( &TC, queue_snd_id );
108 result = action_update_info( &TC, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
110 break;
110 break;
111 case TC_SUBTYPE_EN_CAL:
111 case TC_SUBTYPE_EN_CAL:
112 result = action_enable_calibration( &TC, queue_snd_id, time );
112 result = action_enable_calibration( &TC, queue_snd_id, time );
113 close_action( &TC, result, queue_snd_id );
113 close_action( &TC, result, queue_snd_id );
114 break;
114 break;
115 case TC_SUBTYPE_DIS_CAL:
115 case TC_SUBTYPE_DIS_CAL:
116 result = action_disable_calibration( &TC, queue_snd_id, time );
116 result = action_disable_calibration( &TC, queue_snd_id, time );
117 close_action( &TC, result, queue_snd_id );
117 close_action( &TC, result, queue_snd_id );
118 break;
118 break;
119 case TC_SUBTYPE_LOAD_K:
119 case TC_SUBTYPE_LOAD_K:
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
121 close_action( &TC, result, queue_snd_id );
122 break;
122 break;
123 case TC_SUBTYPE_DUMP_K:
123 case TC_SUBTYPE_DUMP_K:
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
125 close_action( &TC, result, queue_snd_id );
125 close_action( &TC, result, queue_snd_id );
126 break;
126 break;
127 case TC_SUBTYPE_LOAD_FBINS:
127 case TC_SUBTYPE_LOAD_FBINS:
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
129 close_action( &TC, result, queue_snd_id );
129 close_action( &TC, result, queue_snd_id );
130 break;
130 break;
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
132 result = action_load_filter_par( &TC, queue_snd_id, time );
132 result = action_load_filter_par( &TC, queue_snd_id, time );
133 close_action( &TC, result, queue_snd_id );
133 close_action( &TC, result, queue_snd_id );
134 break;
134 break;
135 case TC_SUBTYPE_UPDT_TIME:
135 case TC_SUBTYPE_UPDT_TIME:
136 result = action_update_time( &TC );
136 result = action_update_time( &TC );
137 close_action( &TC, result, queue_snd_id );
137 close_action( &TC, result, queue_snd_id );
138 break;
138 break;
139 default:
139 default:
140 break;
140 break;
141 }
141 }
142 }
142 }
143 }
143 }
144 }
144 }
145
145
146 //***********
146 //***********
147 // TC ACTIONS
147 // TC ACTIONS
148
148
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
150 {
150 {
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
152 *
152 *
153 * @param TC points to the TeleCommand packet that is being processed
153 * @param TC points to the TeleCommand packet that is being processed
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
154 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
155 *
155 *
156 */
156 */
157
157
158 PRINTF("this is the end!!!\n");
158 PRINTF("this is the end!!!\n");
159 exit(0);
159 exit(0);
160
160
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
162
162
163 return LFR_DEFAULT;
163 return LFR_DEFAULT;
164 }
164 }
165
165
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
167 {
167 {
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
169 *
169 *
170 * @param TC points to the TeleCommand packet that is being processed
170 * @param TC points to the TeleCommand packet that is being processed
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
171 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
172 *
172 *
173 */
173 */
174
174
175 rtems_status_code status;
175 rtems_status_code status;
176 unsigned char requestedMode;
176 unsigned char requestedMode;
177 unsigned int transitionCoarseTime;
177 unsigned int transitionCoarseTime;
178 unsigned char * bytePosPtr;
178 unsigned char * bytePosPtr;
179
179
180 bytePosPtr = (unsigned char *) &TC->packetID;
180 bytePosPtr = (unsigned char *) &TC->packetID;
181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
184 status = check_mode_value( requestedMode );
184 status = check_mode_value( requestedMode );
185
185
186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
187 {
187 {
188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
189 }
189 }
190
190
191 else // the mode value is valid, check the transition
191 else // the mode value is valid, check the transition
192 {
192 {
193 status = check_mode_transition(requestedMode);
193 status = check_mode_transition(requestedMode);
194 if (status != LFR_SUCCESSFUL)
194 if (status != LFR_SUCCESSFUL)
195 {
195 {
196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
198 }
198 }
199 }
199 }
200
200
201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
202 {
202 {
203 status = check_transition_date( transitionCoarseTime );
203 status = check_transition_date( transitionCoarseTime );
204 if (status != LFR_SUCCESSFUL)
204 if (status != LFR_SUCCESSFUL)
205 {
205 {
206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
208 }
208 }
209 }
209 }
210
210
211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
212 {
212 {
213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
214
214
215 switch(requestedMode)
215 switch(requestedMode)
216 {
216 {
217 case LFR_MODE_STANDBY:
217 case LFR_MODE_STANDBY:
218 status = enter_mode_standby();
218 status = enter_mode_standby();
219 break;
219 break;
220 case LFR_MODE_NORMAL:
220 case LFR_MODE_NORMAL:
221 status = enter_mode_normal( transitionCoarseTime );
221 status = enter_mode_normal( transitionCoarseTime );
222 break;
222 break;
223 case LFR_MODE_BURST:
223 case LFR_MODE_BURST:
224 status = enter_mode_burst( transitionCoarseTime );
224 status = enter_mode_burst( transitionCoarseTime );
225 break;
225 break;
226 case LFR_MODE_SBM1:
226 case LFR_MODE_SBM1:
227 status = enter_mode_sbm1( transitionCoarseTime );
227 status = enter_mode_sbm1( transitionCoarseTime );
228 break;
228 break;
229 case LFR_MODE_SBM2:
229 case LFR_MODE_SBM2:
230 status = enter_mode_sbm2( transitionCoarseTime );
230 status = enter_mode_sbm2( transitionCoarseTime );
231 break;
231 break;
232 default:
232 default:
233 break;
233 break;
234 }
234 }
235
235
236 if (status != RTEMS_SUCCESSFUL)
236 if (status != RTEMS_SUCCESSFUL)
237 {
237 {
238 status = LFR_EXE_ERROR;
238 status = LFR_EXE_ERROR;
239 }
239 }
240 }
240 }
241
241
242 return status;
242 return status;
243 }
243 }
244
244
245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
246 {
246 {
247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
248 *
248 *
249 * @param TC points to the TeleCommand packet that is being processed
249 * @param TC points to the TeleCommand packet that is being processed
250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
251 *
251 *
252 * @return LFR directive status code:
252 * @return LFR directive status code:
253 * - LFR_DEFAULT
253 * - LFR_DEFAULT
254 * - LFR_SUCCESSFUL
254 * - LFR_SUCCESSFUL
255 *
255 *
256 */
256 */
257
257
258 unsigned int val;
258 unsigned int val;
259 int result;
259 int result;
260 unsigned int status;
260 unsigned int status;
261 unsigned char mode;
261 unsigned char mode;
262 unsigned char * bytePosPtr;
262 unsigned char * bytePosPtr;
263
263
264 bytePosPtr = (unsigned char *) &TC->packetID;
264 bytePosPtr = (unsigned char *) &TC->packetID;
265
265
266 // check LFR mode
266 // check LFR mode
267 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
267 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
268 status = check_update_info_hk_lfr_mode( mode );
268 status = check_update_info_hk_lfr_mode( mode );
269 if (status == LFR_SUCCESSFUL) // check TDS mode
269 if (status == LFR_SUCCESSFUL) // check TDS mode
270 {
270 {
271 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
271 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
272 status = check_update_info_hk_tds_mode( mode );
272 status = check_update_info_hk_tds_mode( mode );
273 }
273 }
274 if (status == LFR_SUCCESSFUL) // check THR mode
274 if (status == LFR_SUCCESSFUL) // check THR mode
275 {
275 {
276 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
276 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
277 status = check_update_info_hk_thr_mode( mode );
277 status = check_update_info_hk_thr_mode( mode );
278 }
278 }
279 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
279 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
280 {
280 {
281 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
281 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
282 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
282 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
283 val++;
283 val++;
284 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
284 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
285 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
285 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
286 }
286 }
287
287
288 // pa_bia_status_info
288 // pa_bia_status_info
289 // => pa_bia_mode_mux_set 3 bits
289 // => pa_bia_mode_mux_set 3 bits
290 // => pa_bia_mode_hv_enabled 1 bit
290 // => pa_bia_mode_hv_enabled 1 bit
291 // => pa_bia_mode_bias1_enabled 1 bit
291 // => pa_bia_mode_bias1_enabled 1 bit
292 // => pa_bia_mode_bias2_enabled 1 bit
292 // => pa_bia_mode_bias2_enabled 1 bit
293 // => pa_bia_mode_bias3_enabled 1 bit
293 // => pa_bia_mode_bias3_enabled 1 bit
294 // => pa_bia_on_off (cp_dpu_bias_on_off)
294 // => pa_bia_on_off (cp_dpu_bias_on_off)
295 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
295 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
296 pa_bia_status_info = pa_bia_status_info
296 pa_bia_status_info = pa_bia_status_info
297 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
297 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
298
298
299 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
299 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
300
301 //cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
302 getReactionWheelsFrequencies( TC );
300 getReactionWheelsFrequencies( TC );
303 set_hk_lfr_sc_rw_f_flags();
301 set_hk_lfr_sc_rw_f_flags();
304 build_sy_lfr_rw_masks();
302 build_sy_lfr_rw_masks();
305
303
306 // once the masks are built, they have to be merged with the fbins_mask
304 // once the masks are built, they have to be merged with the fbins_mask
307 merge_fbins_masks();
305 merge_fbins_masks();
308
306
309 result = status;
307 result = status;
310
308
311 return result;
309 return result;
312 }
310 }
313
311
314 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
312 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
315 {
313 {
316 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
314 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
317 *
315 *
318 * @param TC points to the TeleCommand packet that is being processed
316 * @param TC points to the TeleCommand packet that is being processed
319 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
317 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
320 *
318 *
321 */
319 */
322
320
323 int result;
321 int result;
324
322
325 result = LFR_DEFAULT;
323 result = LFR_DEFAULT;
326
324
327 setCalibration( true );
325 setCalibration( true );
328
326
329 result = LFR_SUCCESSFUL;
327 result = LFR_SUCCESSFUL;
330
328
331 return result;
329 return result;
332 }
330 }
333
331
334 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
332 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
335 {
333 {
336 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
334 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
337 *
335 *
338 * @param TC points to the TeleCommand packet that is being processed
336 * @param TC points to the TeleCommand packet that is being processed
339 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
337 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
340 *
338 *
341 */
339 */
342
340
343 int result;
341 int result;
344
342
345 result = LFR_DEFAULT;
343 result = LFR_DEFAULT;
346
344
347 setCalibration( false );
345 setCalibration( false );
348
346
349 result = LFR_SUCCESSFUL;
347 result = LFR_SUCCESSFUL;
350
348
351 return result;
349 return result;
352 }
350 }
353
351
354 int action_update_time(ccsdsTelecommandPacket_t *TC)
352 int action_update_time(ccsdsTelecommandPacket_t *TC)
355 {
353 {
356 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
354 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
357 *
355 *
358 * @param TC points to the TeleCommand packet that is being processed
356 * @param TC points to the TeleCommand packet that is being processed
359 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
357 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
360 *
358 *
361 * @return LFR_SUCCESSFUL
359 * @return LFR_SUCCESSFUL
362 *
360 *
363 */
361 */
364
362
365 unsigned int val;
363 unsigned int val;
366
364
367 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
365 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
368 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
366 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
369 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
367 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
370 + TC->dataAndCRC[BYTE_3];
368 + TC->dataAndCRC[BYTE_3];
371
369
372 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
370 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
373 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
371 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
374 val++;
372 val++;
375 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
373 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
376 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
374 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
377
375
378 oneTcLfrUpdateTimeReceived = 1;
376 oneTcLfrUpdateTimeReceived = 1;
379
377
380 return LFR_SUCCESSFUL;
378 return LFR_SUCCESSFUL;
381 }
379 }
382
380
383 //*******************
381 //*******************
384 // ENTERING THE MODES
382 // ENTERING THE MODES
385 int check_mode_value( unsigned char requestedMode )
383 int check_mode_value( unsigned char requestedMode )
386 {
384 {
387 int status;
385 int status;
388
386
389 status = LFR_DEFAULT;
387 status = LFR_DEFAULT;
390
388
391 if ( (requestedMode != LFR_MODE_STANDBY)
389 if ( (requestedMode != LFR_MODE_STANDBY)
392 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
390 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
393 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
391 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
394 {
392 {
395 status = LFR_DEFAULT;
393 status = LFR_DEFAULT;
396 }
394 }
397 else
395 else
398 {
396 {
399 status = LFR_SUCCESSFUL;
397 status = LFR_SUCCESSFUL;
400 }
398 }
401
399
402 return status;
400 return status;
403 }
401 }
404
402
405 int check_mode_transition( unsigned char requestedMode )
403 int check_mode_transition( unsigned char requestedMode )
406 {
404 {
407 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
405 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
408 *
406 *
409 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
407 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
410 *
408 *
411 * @return LFR directive status codes:
409 * @return LFR directive status codes:
412 * - LFR_SUCCESSFUL - the transition is authorized
410 * - LFR_SUCCESSFUL - the transition is authorized
413 * - LFR_DEFAULT - the transition is not authorized
411 * - LFR_DEFAULT - the transition is not authorized
414 *
412 *
415 */
413 */
416
414
417 int status;
415 int status;
418
416
419 switch (requestedMode)
417 switch (requestedMode)
420 {
418 {
421 case LFR_MODE_STANDBY:
419 case LFR_MODE_STANDBY:
422 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
420 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
423 status = LFR_DEFAULT;
421 status = LFR_DEFAULT;
424 }
422 }
425 else
423 else
426 {
424 {
427 status = LFR_SUCCESSFUL;
425 status = LFR_SUCCESSFUL;
428 }
426 }
429 break;
427 break;
430 case LFR_MODE_NORMAL:
428 case LFR_MODE_NORMAL:
431 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
429 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
432 status = LFR_DEFAULT;
430 status = LFR_DEFAULT;
433 }
431 }
434 else {
432 else {
435 status = LFR_SUCCESSFUL;
433 status = LFR_SUCCESSFUL;
436 }
434 }
437 break;
435 break;
438 case LFR_MODE_BURST:
436 case LFR_MODE_BURST:
439 if ( lfrCurrentMode == LFR_MODE_BURST ) {
437 if ( lfrCurrentMode == LFR_MODE_BURST ) {
440 status = LFR_DEFAULT;
438 status = LFR_DEFAULT;
441 }
439 }
442 else {
440 else {
443 status = LFR_SUCCESSFUL;
441 status = LFR_SUCCESSFUL;
444 }
442 }
445 break;
443 break;
446 case LFR_MODE_SBM1:
444 case LFR_MODE_SBM1:
447 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
445 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
448 status = LFR_DEFAULT;
446 status = LFR_DEFAULT;
449 }
447 }
450 else {
448 else {
451 status = LFR_SUCCESSFUL;
449 status = LFR_SUCCESSFUL;
452 }
450 }
453 break;
451 break;
454 case LFR_MODE_SBM2:
452 case LFR_MODE_SBM2:
455 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
453 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
456 status = LFR_DEFAULT;
454 status = LFR_DEFAULT;
457 }
455 }
458 else {
456 else {
459 status = LFR_SUCCESSFUL;
457 status = LFR_SUCCESSFUL;
460 }
458 }
461 break;
459 break;
462 default:
460 default:
463 status = LFR_DEFAULT;
461 status = LFR_DEFAULT;
464 break;
462 break;
465 }
463 }
466
464
467 return status;
465 return status;
468 }
466 }
469
467
470 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
468 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
471 {
469 {
472 if (transitionCoarseTime == 0)
470 if (transitionCoarseTime == 0)
473 {
471 {
474 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
472 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
475 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
473 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
476 }
474 }
477 else
475 else
478 {
476 {
479 lastValidEnterModeTime = transitionCoarseTime;
477 lastValidEnterModeTime = transitionCoarseTime;
480 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
478 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
481 }
479 }
482 }
480 }
483
481
484 int check_transition_date( unsigned int transitionCoarseTime )
482 int check_transition_date( unsigned int transitionCoarseTime )
485 {
483 {
486 int status;
484 int status;
487 unsigned int localCoarseTime;
485 unsigned int localCoarseTime;
488 unsigned int deltaCoarseTime;
486 unsigned int deltaCoarseTime;
489
487
490 status = LFR_SUCCESSFUL;
488 status = LFR_SUCCESSFUL;
491
489
492 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
490 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
493 {
491 {
494 status = LFR_SUCCESSFUL;
492 status = LFR_SUCCESSFUL;
495 }
493 }
496 else
494 else
497 {
495 {
498 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
496 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
499
497
500 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
498 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
501
499
502 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
500 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
503 {
501 {
504 status = LFR_DEFAULT;
502 status = LFR_DEFAULT;
505 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
503 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
506 }
504 }
507
505
508 if (status == LFR_SUCCESSFUL)
506 if (status == LFR_SUCCESSFUL)
509 {
507 {
510 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
508 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
511 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
509 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
512 {
510 {
513 status = LFR_DEFAULT;
511 status = LFR_DEFAULT;
514 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
512 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
515 }
513 }
516 }
514 }
517 }
515 }
518
516
519 return status;
517 return status;
520 }
518 }
521
519
522 int restart_asm_activities( unsigned char lfrRequestedMode )
520 int restart_asm_activities( unsigned char lfrRequestedMode )
523 {
521 {
524 rtems_status_code status;
522 rtems_status_code status;
525
523
526 status = stop_spectral_matrices();
524 status = stop_spectral_matrices();
527
525
528 thisIsAnASMRestart = 1;
526 thisIsAnASMRestart = 1;
529
527
530 status = restart_asm_tasks( lfrRequestedMode );
528 status = restart_asm_tasks( lfrRequestedMode );
531
529
532 launch_spectral_matrix();
530 launch_spectral_matrix();
533
531
534 return status;
532 return status;
535 }
533 }
536
534
537 int stop_spectral_matrices( void )
535 int stop_spectral_matrices( void )
538 {
536 {
539 /** This function stops and restarts the current mode average spectral matrices activities.
537 /** This function stops and restarts the current mode average spectral matrices activities.
540 *
538 *
541 * @return RTEMS directive status codes:
539 * @return RTEMS directive status codes:
542 * - RTEMS_SUCCESSFUL - task restarted successfully
540 * - RTEMS_SUCCESSFUL - task restarted successfully
543 * - RTEMS_INVALID_ID - task id invalid
541 * - RTEMS_INVALID_ID - task id invalid
544 * - RTEMS_ALREADY_SUSPENDED - task already suspended
542 * - RTEMS_ALREADY_SUSPENDED - task already suspended
545 *
543 *
546 */
544 */
547
545
548 rtems_status_code status;
546 rtems_status_code status;
549
547
550 status = RTEMS_SUCCESSFUL;
548 status = RTEMS_SUCCESSFUL;
551
549
552 // (1) mask interruptions
550 // (1) mask interruptions
553 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
551 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
554
552
555 // (2) reset spectral matrices registers
553 // (2) reset spectral matrices registers
556 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
554 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
557 reset_sm_status();
555 reset_sm_status();
558
556
559 // (3) clear interruptions
557 // (3) clear interruptions
560 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
558 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
561
559
562 // suspend several tasks
560 // suspend several tasks
563 if (lfrCurrentMode != LFR_MODE_STANDBY) {
561 if (lfrCurrentMode != LFR_MODE_STANDBY) {
564 status = suspend_asm_tasks();
562 status = suspend_asm_tasks();
565 }
563 }
566
564
567 if (status != RTEMS_SUCCESSFUL)
565 if (status != RTEMS_SUCCESSFUL)
568 {
566 {
569 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
567 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
570 }
568 }
571
569
572 return status;
570 return status;
573 }
571 }
574
572
575 int stop_current_mode( void )
573 int stop_current_mode( void )
576 {
574 {
577 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
575 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
578 *
576 *
579 * @return RTEMS directive status codes:
577 * @return RTEMS directive status codes:
580 * - RTEMS_SUCCESSFUL - task restarted successfully
578 * - RTEMS_SUCCESSFUL - task restarted successfully
581 * - RTEMS_INVALID_ID - task id invalid
579 * - RTEMS_INVALID_ID - task id invalid
582 * - RTEMS_ALREADY_SUSPENDED - task already suspended
580 * - RTEMS_ALREADY_SUSPENDED - task already suspended
583 *
581 *
584 */
582 */
585
583
586 rtems_status_code status;
584 rtems_status_code status;
587
585
588 status = RTEMS_SUCCESSFUL;
586 status = RTEMS_SUCCESSFUL;
589
587
590 // (1) mask interruptions
588 // (1) mask interruptions
591 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
589 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
592 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
590 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
593
591
594 // (2) reset waveform picker registers
592 // (2) reset waveform picker registers
595 reset_wfp_burst_enable(); // reset burst and enable bits
593 reset_wfp_burst_enable(); // reset burst and enable bits
596 reset_wfp_status(); // reset all the status bits
594 reset_wfp_status(); // reset all the status bits
597
595
598 // (3) reset spectral matrices registers
596 // (3) reset spectral matrices registers
599 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
597 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
600 reset_sm_status();
598 reset_sm_status();
601
599
602 // reset lfr VHDL module
600 // reset lfr VHDL module
603 reset_lfr();
601 reset_lfr();
604
602
605 reset_extractSWF(); // reset the extractSWF flag to false
603 reset_extractSWF(); // reset the extractSWF flag to false
606
604
607 // (4) clear interruptions
605 // (4) clear interruptions
608 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
606 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
609 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
607 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
610
608
611 // suspend several tasks
609 // suspend several tasks
612 if (lfrCurrentMode != LFR_MODE_STANDBY) {
610 if (lfrCurrentMode != LFR_MODE_STANDBY) {
613 status = suspend_science_tasks();
611 status = suspend_science_tasks();
614 }
612 }
615
613
616 if (status != RTEMS_SUCCESSFUL)
614 if (status != RTEMS_SUCCESSFUL)
617 {
615 {
618 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
616 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
619 }
617 }
620
618
621 return status;
619 return status;
622 }
620 }
623
621
624 int enter_mode_standby( void )
622 int enter_mode_standby( void )
625 {
623 {
626 /** This function is used to put LFR in the STANDBY mode.
624 /** This function is used to put LFR in the STANDBY mode.
627 *
625 *
628 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
626 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
629 *
627 *
630 * @return RTEMS directive status codes:
628 * @return RTEMS directive status codes:
631 * - RTEMS_SUCCESSFUL - task restarted successfully
629 * - RTEMS_SUCCESSFUL - task restarted successfully
632 * - RTEMS_INVALID_ID - task id invalid
630 * - RTEMS_INVALID_ID - task id invalid
633 * - RTEMS_INCORRECT_STATE - task never started
631 * - RTEMS_INCORRECT_STATE - task never started
634 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
632 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
635 *
633 *
636 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
634 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
637 * is immediate.
635 * is immediate.
638 *
636 *
639 */
637 */
640
638
641 int status;
639 int status;
642
640
643 status = stop_current_mode(); // STOP THE CURRENT MODE
641 status = stop_current_mode(); // STOP THE CURRENT MODE
644
642
645 #ifdef PRINT_TASK_STATISTICS
643 #ifdef PRINT_TASK_STATISTICS
646 rtems_cpu_usage_report();
644 rtems_cpu_usage_report();
647 #endif
645 #endif
648
646
649 #ifdef PRINT_STACK_REPORT
647 #ifdef PRINT_STACK_REPORT
650 PRINTF("stack report selected\n")
648 PRINTF("stack report selected\n")
651 rtems_stack_checker_report_usage();
649 rtems_stack_checker_report_usage();
652 #endif
650 #endif
653
651
654 return status;
652 return status;
655 }
653 }
656
654
657 int enter_mode_normal( unsigned int transitionCoarseTime )
655 int enter_mode_normal( unsigned int transitionCoarseTime )
658 {
656 {
659 /** This function is used to start the NORMAL mode.
657 /** This function is used to start the NORMAL mode.
660 *
658 *
661 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
659 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
662 *
660 *
663 * @return RTEMS directive status codes:
661 * @return RTEMS directive status codes:
664 * - RTEMS_SUCCESSFUL - task restarted successfully
662 * - RTEMS_SUCCESSFUL - task restarted successfully
665 * - RTEMS_INVALID_ID - task id invalid
663 * - RTEMS_INVALID_ID - task id invalid
666 * - RTEMS_INCORRECT_STATE - task never started
664 * - RTEMS_INCORRECT_STATE - task never started
667 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
665 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
668 *
666 *
669 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
667 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
670 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
668 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
671 *
669 *
672 */
670 */
673
671
674 int status;
672 int status;
675
673
676 #ifdef PRINT_TASK_STATISTICS
674 #ifdef PRINT_TASK_STATISTICS
677 rtems_cpu_usage_reset();
675 rtems_cpu_usage_reset();
678 #endif
676 #endif
679
677
680 status = RTEMS_UNSATISFIED;
678 status = RTEMS_UNSATISFIED;
681
679
682 switch( lfrCurrentMode )
680 switch( lfrCurrentMode )
683 {
681 {
684 case LFR_MODE_STANDBY:
682 case LFR_MODE_STANDBY:
685 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
683 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
686 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
684 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
687 {
685 {
688 launch_spectral_matrix( );
686 launch_spectral_matrix( );
689 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
687 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
690 }
688 }
691 break;
689 break;
692 case LFR_MODE_BURST:
690 case LFR_MODE_BURST:
693 status = stop_current_mode(); // stop the current mode
691 status = stop_current_mode(); // stop the current mode
694 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
692 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
695 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
693 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
696 {
694 {
697 launch_spectral_matrix( );
695 launch_spectral_matrix( );
698 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
696 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
699 }
697 }
700 break;
698 break;
701 case LFR_MODE_SBM1:
699 case LFR_MODE_SBM1:
702 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
700 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
703 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
701 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
704 update_last_valid_transition_date( transitionCoarseTime );
702 update_last_valid_transition_date( transitionCoarseTime );
705 break;
703 break;
706 case LFR_MODE_SBM2:
704 case LFR_MODE_SBM2:
707 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
705 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
708 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
706 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
709 update_last_valid_transition_date( transitionCoarseTime );
707 update_last_valid_transition_date( transitionCoarseTime );
710 break;
708 break;
711 default:
709 default:
712 break;
710 break;
713 }
711 }
714
712
715 if (status != RTEMS_SUCCESSFUL)
713 if (status != RTEMS_SUCCESSFUL)
716 {
714 {
717 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
715 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
718 status = RTEMS_UNSATISFIED;
716 status = RTEMS_UNSATISFIED;
719 }
717 }
720
718
721 return status;
719 return status;
722 }
720 }
723
721
724 int enter_mode_burst( unsigned int transitionCoarseTime )
722 int enter_mode_burst( unsigned int transitionCoarseTime )
725 {
723 {
726 /** This function is used to start the BURST mode.
724 /** This function is used to start the BURST mode.
727 *
725 *
728 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
726 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
729 *
727 *
730 * @return RTEMS directive status codes:
728 * @return RTEMS directive status codes:
731 * - RTEMS_SUCCESSFUL - task restarted successfully
729 * - RTEMS_SUCCESSFUL - task restarted successfully
732 * - RTEMS_INVALID_ID - task id invalid
730 * - RTEMS_INVALID_ID - task id invalid
733 * - RTEMS_INCORRECT_STATE - task never started
731 * - RTEMS_INCORRECT_STATE - task never started
734 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
732 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
735 *
733 *
736 * The way the BURST mode is started does not depend on the LFR current mode.
734 * The way the BURST mode is started does not depend on the LFR current mode.
737 *
735 *
738 */
736 */
739
737
740
738
741 int status;
739 int status;
742
740
743 #ifdef PRINT_TASK_STATISTICS
741 #ifdef PRINT_TASK_STATISTICS
744 rtems_cpu_usage_reset();
742 rtems_cpu_usage_reset();
745 #endif
743 #endif
746
744
747 status = stop_current_mode(); // stop the current mode
745 status = stop_current_mode(); // stop the current mode
748 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
746 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
749 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
747 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
750 {
748 {
751 launch_spectral_matrix( );
749 launch_spectral_matrix( );
752 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
750 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
753 }
751 }
754
752
755 if (status != RTEMS_SUCCESSFUL)
753 if (status != RTEMS_SUCCESSFUL)
756 {
754 {
757 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
755 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
758 status = RTEMS_UNSATISFIED;
756 status = RTEMS_UNSATISFIED;
759 }
757 }
760
758
761 return status;
759 return status;
762 }
760 }
763
761
764 int enter_mode_sbm1( unsigned int transitionCoarseTime )
762 int enter_mode_sbm1( unsigned int transitionCoarseTime )
765 {
763 {
766 /** This function is used to start the SBM1 mode.
764 /** This function is used to start the SBM1 mode.
767 *
765 *
768 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
766 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
769 *
767 *
770 * @return RTEMS directive status codes:
768 * @return RTEMS directive status codes:
771 * - RTEMS_SUCCESSFUL - task restarted successfully
769 * - RTEMS_SUCCESSFUL - task restarted successfully
772 * - RTEMS_INVALID_ID - task id invalid
770 * - RTEMS_INVALID_ID - task id invalid
773 * - RTEMS_INCORRECT_STATE - task never started
771 * - RTEMS_INCORRECT_STATE - task never started
774 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
772 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
775 *
773 *
776 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
774 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
777 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
775 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
778 * cases, the acquisition is completely restarted.
776 * cases, the acquisition is completely restarted.
779 *
777 *
780 */
778 */
781
779
782 int status;
780 int status;
783
781
784 #ifdef PRINT_TASK_STATISTICS
782 #ifdef PRINT_TASK_STATISTICS
785 rtems_cpu_usage_reset();
783 rtems_cpu_usage_reset();
786 #endif
784 #endif
787
785
788 status = RTEMS_UNSATISFIED;
786 status = RTEMS_UNSATISFIED;
789
787
790 switch( lfrCurrentMode )
788 switch( lfrCurrentMode )
791 {
789 {
792 case LFR_MODE_STANDBY:
790 case LFR_MODE_STANDBY:
793 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
791 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
794 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
792 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
795 {
793 {
796 launch_spectral_matrix( );
794 launch_spectral_matrix( );
797 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
795 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
798 }
796 }
799 break;
797 break;
800 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
798 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
801 status = restart_asm_activities( LFR_MODE_SBM1 );
799 status = restart_asm_activities( LFR_MODE_SBM1 );
802 status = LFR_SUCCESSFUL;
800 status = LFR_SUCCESSFUL;
803 update_last_valid_transition_date( transitionCoarseTime );
801 update_last_valid_transition_date( transitionCoarseTime );
804 break;
802 break;
805 case LFR_MODE_BURST:
803 case LFR_MODE_BURST:
806 status = stop_current_mode(); // stop the current mode
804 status = stop_current_mode(); // stop the current mode
807 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
805 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
808 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
806 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
809 {
807 {
810 launch_spectral_matrix( );
808 launch_spectral_matrix( );
811 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
809 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
812 }
810 }
813 break;
811 break;
814 case LFR_MODE_SBM2:
812 case LFR_MODE_SBM2:
815 status = restart_asm_activities( LFR_MODE_SBM1 );
813 status = restart_asm_activities( LFR_MODE_SBM1 );
816 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
814 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
817 update_last_valid_transition_date( transitionCoarseTime );
815 update_last_valid_transition_date( transitionCoarseTime );
818 break;
816 break;
819 default:
817 default:
820 break;
818 break;
821 }
819 }
822
820
823 if (status != RTEMS_SUCCESSFUL)
821 if (status != RTEMS_SUCCESSFUL)
824 {
822 {
825 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
823 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
826 status = RTEMS_UNSATISFIED;
824 status = RTEMS_UNSATISFIED;
827 }
825 }
828
826
829 return status;
827 return status;
830 }
828 }
831
829
832 int enter_mode_sbm2( unsigned int transitionCoarseTime )
830 int enter_mode_sbm2( unsigned int transitionCoarseTime )
833 {
831 {
834 /** This function is used to start the SBM2 mode.
832 /** This function is used to start the SBM2 mode.
835 *
833 *
836 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
834 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
837 *
835 *
838 * @return RTEMS directive status codes:
836 * @return RTEMS directive status codes:
839 * - RTEMS_SUCCESSFUL - task restarted successfully
837 * - RTEMS_SUCCESSFUL - task restarted successfully
840 * - RTEMS_INVALID_ID - task id invalid
838 * - RTEMS_INVALID_ID - task id invalid
841 * - RTEMS_INCORRECT_STATE - task never started
839 * - RTEMS_INCORRECT_STATE - task never started
842 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
840 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
843 *
841 *
844 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
842 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
845 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
843 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
846 * cases, the acquisition is completely restarted.
844 * cases, the acquisition is completely restarted.
847 *
845 *
848 */
846 */
849
847
850 int status;
848 int status;
851
849
852 #ifdef PRINT_TASK_STATISTICS
850 #ifdef PRINT_TASK_STATISTICS
853 rtems_cpu_usage_reset();
851 rtems_cpu_usage_reset();
854 #endif
852 #endif
855
853
856 status = RTEMS_UNSATISFIED;
854 status = RTEMS_UNSATISFIED;
857
855
858 switch( lfrCurrentMode )
856 switch( lfrCurrentMode )
859 {
857 {
860 case LFR_MODE_STANDBY:
858 case LFR_MODE_STANDBY:
861 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
859 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
862 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
860 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
863 {
861 {
864 launch_spectral_matrix( );
862 launch_spectral_matrix( );
865 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
863 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
866 }
864 }
867 break;
865 break;
868 case LFR_MODE_NORMAL:
866 case LFR_MODE_NORMAL:
869 status = restart_asm_activities( LFR_MODE_SBM2 );
867 status = restart_asm_activities( LFR_MODE_SBM2 );
870 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
868 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
871 update_last_valid_transition_date( transitionCoarseTime );
869 update_last_valid_transition_date( transitionCoarseTime );
872 break;
870 break;
873 case LFR_MODE_BURST:
871 case LFR_MODE_BURST:
874 status = stop_current_mode(); // stop the current mode
872 status = stop_current_mode(); // stop the current mode
875 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
873 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
876 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
874 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
877 {
875 {
878 launch_spectral_matrix( );
876 launch_spectral_matrix( );
879 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
877 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
880 }
878 }
881 break;
879 break;
882 case LFR_MODE_SBM1:
880 case LFR_MODE_SBM1:
883 status = restart_asm_activities( LFR_MODE_SBM2 );
881 status = restart_asm_activities( LFR_MODE_SBM2 );
884 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
882 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
885 update_last_valid_transition_date( transitionCoarseTime );
883 update_last_valid_transition_date( transitionCoarseTime );
886 break;
884 break;
887 default:
885 default:
888 break;
886 break;
889 }
887 }
890
888
891 if (status != RTEMS_SUCCESSFUL)
889 if (status != RTEMS_SUCCESSFUL)
892 {
890 {
893 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
891 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
894 status = RTEMS_UNSATISFIED;
892 status = RTEMS_UNSATISFIED;
895 }
893 }
896
894
897 return status;
895 return status;
898 }
896 }
899
897
900 int restart_science_tasks( unsigned char lfrRequestedMode )
898 int restart_science_tasks( unsigned char lfrRequestedMode )
901 {
899 {
902 /** This function is used to restart all science tasks.
900 /** This function is used to restart all science tasks.
903 *
901 *
904 * @return RTEMS directive status codes:
902 * @return RTEMS directive status codes:
905 * - RTEMS_SUCCESSFUL - task restarted successfully
903 * - RTEMS_SUCCESSFUL - task restarted successfully
906 * - RTEMS_INVALID_ID - task id invalid
904 * - RTEMS_INVALID_ID - task id invalid
907 * - RTEMS_INCORRECT_STATE - task never started
905 * - RTEMS_INCORRECT_STATE - task never started
908 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
906 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
909 *
907 *
910 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
908 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
911 *
909 *
912 */
910 */
913
911
914 rtems_status_code status[NB_SCIENCE_TASKS];
912 rtems_status_code status[NB_SCIENCE_TASKS];
915 rtems_status_code ret;
913 rtems_status_code ret;
916
914
917 ret = RTEMS_SUCCESSFUL;
915 ret = RTEMS_SUCCESSFUL;
918
916
919 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
917 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
920 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
918 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
921 {
919 {
922 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
920 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
923 }
921 }
924
922
925 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
923 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
926 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
924 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
927 {
925 {
928 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
926 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
929 }
927 }
930
928
931 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
929 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
932 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
930 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
933 {
931 {
934 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
932 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
935 }
933 }
936
934
937 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
935 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
938 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
936 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
939 {
937 {
940 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
938 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
941 }
939 }
942
940
943 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
941 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
944 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
942 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
945 {
943 {
946 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
944 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
947 }
945 }
948
946
949 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
947 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
950 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
948 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
951 {
949 {
952 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
950 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
953 }
951 }
954
952
955 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
953 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
956 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
954 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
957 {
955 {
958 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
956 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
959 }
957 }
960
958
961 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
959 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
962 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
960 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
963 {
961 {
964 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
962 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
965 }
963 }
966
964
967 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
965 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
968 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
966 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
969 {
967 {
970 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
968 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
971 }
969 }
972
970
973 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
971 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
974 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
972 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
975 {
973 {
976 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
974 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
977 }
975 }
978
976
979 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
977 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
980 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
978 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
981 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
979 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
982 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
980 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
983 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
981 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
984 {
982 {
985 ret = RTEMS_UNSATISFIED;
983 ret = RTEMS_UNSATISFIED;
986 }
984 }
987
985
988 return ret;
986 return ret;
989 }
987 }
990
988
991 int restart_asm_tasks( unsigned char lfrRequestedMode )
989 int restart_asm_tasks( unsigned char lfrRequestedMode )
992 {
990 {
993 /** This function is used to restart average spectral matrices tasks.
991 /** This function is used to restart average spectral matrices tasks.
994 *
992 *
995 * @return RTEMS directive status codes:
993 * @return RTEMS directive status codes:
996 * - RTEMS_SUCCESSFUL - task restarted successfully
994 * - RTEMS_SUCCESSFUL - task restarted successfully
997 * - RTEMS_INVALID_ID - task id invalid
995 * - RTEMS_INVALID_ID - task id invalid
998 * - RTEMS_INCORRECT_STATE - task never started
996 * - RTEMS_INCORRECT_STATE - task never started
999 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
997 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1000 *
998 *
1001 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
999 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1002 *
1000 *
1003 */
1001 */
1004
1002
1005 rtems_status_code status[NB_ASM_TASKS];
1003 rtems_status_code status[NB_ASM_TASKS];
1006 rtems_status_code ret;
1004 rtems_status_code ret;
1007
1005
1008 ret = RTEMS_SUCCESSFUL;
1006 ret = RTEMS_SUCCESSFUL;
1009
1007
1010 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1008 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1011 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1009 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1012 {
1010 {
1013 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1011 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1014 }
1012 }
1015
1013
1016 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1014 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1017 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1015 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1018 {
1016 {
1019 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1017 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1020 }
1018 }
1021
1019
1022 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1020 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1023 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1021 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1024 {
1022 {
1025 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1023 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1026 }
1024 }
1027
1025
1028 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1026 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1029 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1027 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1030 {
1028 {
1031 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1029 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1032 }
1030 }
1033
1031
1034 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1032 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1035 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1033 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1036 {
1034 {
1037 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1035 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1038 }
1036 }
1039
1037
1040 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1038 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1041 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1039 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1042 {
1040 {
1043 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1041 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1044 }
1042 }
1045
1043
1046 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1044 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1047 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1045 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1048 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1046 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1049 {
1047 {
1050 ret = RTEMS_UNSATISFIED;
1048 ret = RTEMS_UNSATISFIED;
1051 }
1049 }
1052
1050
1053 return ret;
1051 return ret;
1054 }
1052 }
1055
1053
1056 int suspend_science_tasks( void )
1054 int suspend_science_tasks( void )
1057 {
1055 {
1058 /** This function suspends the science tasks.
1056 /** This function suspends the science tasks.
1059 *
1057 *
1060 * @return RTEMS directive status codes:
1058 * @return RTEMS directive status codes:
1061 * - RTEMS_SUCCESSFUL - task restarted successfully
1059 * - RTEMS_SUCCESSFUL - task restarted successfully
1062 * - RTEMS_INVALID_ID - task id invalid
1060 * - RTEMS_INVALID_ID - task id invalid
1063 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1061 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1064 *
1062 *
1065 */
1063 */
1066
1064
1067 rtems_status_code status;
1065 rtems_status_code status;
1068
1066
1069 PRINTF("in suspend_science_tasks\n")
1067 PRINTF("in suspend_science_tasks\n")
1070
1068
1071 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1069 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1072 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1070 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1073 {
1071 {
1074 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1072 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1075 }
1073 }
1076 else
1074 else
1077 {
1075 {
1078 status = RTEMS_SUCCESSFUL;
1076 status = RTEMS_SUCCESSFUL;
1079 }
1077 }
1080 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1078 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1081 {
1079 {
1082 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1080 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1083 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1081 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1084 {
1082 {
1085 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1083 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1086 }
1084 }
1087 else
1085 else
1088 {
1086 {
1089 status = RTEMS_SUCCESSFUL;
1087 status = RTEMS_SUCCESSFUL;
1090 }
1088 }
1091 }
1089 }
1092 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1090 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1093 {
1091 {
1094 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1092 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1095 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1093 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1096 {
1094 {
1097 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1095 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1098 }
1096 }
1099 else
1097 else
1100 {
1098 {
1101 status = RTEMS_SUCCESSFUL;
1099 status = RTEMS_SUCCESSFUL;
1102 }
1100 }
1103 }
1101 }
1104 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1102 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1105 {
1103 {
1106 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1104 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1107 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1105 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1108 {
1106 {
1109 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1107 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1110 }
1108 }
1111 else
1109 else
1112 {
1110 {
1113 status = RTEMS_SUCCESSFUL;
1111 status = RTEMS_SUCCESSFUL;
1114 }
1112 }
1115 }
1113 }
1116 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1114 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1117 {
1115 {
1118 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1116 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1119 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1117 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1120 {
1118 {
1121 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1119 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1122 }
1120 }
1123 else
1121 else
1124 {
1122 {
1125 status = RTEMS_SUCCESSFUL;
1123 status = RTEMS_SUCCESSFUL;
1126 }
1124 }
1127 }
1125 }
1128 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1126 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1129 {
1127 {
1130 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1128 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1131 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1129 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1132 {
1130 {
1133 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1131 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1134 }
1132 }
1135 else
1133 else
1136 {
1134 {
1137 status = RTEMS_SUCCESSFUL;
1135 status = RTEMS_SUCCESSFUL;
1138 }
1136 }
1139 }
1137 }
1140 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1138 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1141 {
1139 {
1142 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1140 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1143 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1141 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1144 {
1142 {
1145 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1143 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1146 }
1144 }
1147 else
1145 else
1148 {
1146 {
1149 status = RTEMS_SUCCESSFUL;
1147 status = RTEMS_SUCCESSFUL;
1150 }
1148 }
1151 }
1149 }
1152 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1150 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1153 {
1151 {
1154 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1152 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1155 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1153 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1156 {
1154 {
1157 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1155 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1158 }
1156 }
1159 else
1157 else
1160 {
1158 {
1161 status = RTEMS_SUCCESSFUL;
1159 status = RTEMS_SUCCESSFUL;
1162 }
1160 }
1163 }
1161 }
1164 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1162 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1165 {
1163 {
1166 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1164 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1167 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1165 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1168 {
1166 {
1169 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1167 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1170 }
1168 }
1171 else
1169 else
1172 {
1170 {
1173 status = RTEMS_SUCCESSFUL;
1171 status = RTEMS_SUCCESSFUL;
1174 }
1172 }
1175 }
1173 }
1176 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1174 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1177 {
1175 {
1178 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1176 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1179 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1177 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1180 {
1178 {
1181 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1179 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1182 }
1180 }
1183 else
1181 else
1184 {
1182 {
1185 status = RTEMS_SUCCESSFUL;
1183 status = RTEMS_SUCCESSFUL;
1186 }
1184 }
1187 }
1185 }
1188
1186
1189 return status;
1187 return status;
1190 }
1188 }
1191
1189
1192 int suspend_asm_tasks( void )
1190 int suspend_asm_tasks( void )
1193 {
1191 {
1194 /** This function suspends the science tasks.
1192 /** This function suspends the science tasks.
1195 *
1193 *
1196 * @return RTEMS directive status codes:
1194 * @return RTEMS directive status codes:
1197 * - RTEMS_SUCCESSFUL - task restarted successfully
1195 * - RTEMS_SUCCESSFUL - task restarted successfully
1198 * - RTEMS_INVALID_ID - task id invalid
1196 * - RTEMS_INVALID_ID - task id invalid
1199 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1197 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1200 *
1198 *
1201 */
1199 */
1202
1200
1203 rtems_status_code status;
1201 rtems_status_code status;
1204
1202
1205 PRINTF("in suspend_science_tasks\n")
1203 PRINTF("in suspend_science_tasks\n")
1206
1204
1207 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1205 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1208 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1206 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1209 {
1207 {
1210 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1208 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1211 }
1209 }
1212 else
1210 else
1213 {
1211 {
1214 status = RTEMS_SUCCESSFUL;
1212 status = RTEMS_SUCCESSFUL;
1215 }
1213 }
1216
1214
1217 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1215 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1218 {
1216 {
1219 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1217 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1220 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1218 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1221 {
1219 {
1222 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1220 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1223 }
1221 }
1224 else
1222 else
1225 {
1223 {
1226 status = RTEMS_SUCCESSFUL;
1224 status = RTEMS_SUCCESSFUL;
1227 }
1225 }
1228 }
1226 }
1229
1227
1230 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1228 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1231 {
1229 {
1232 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1230 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1233 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1231 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1234 {
1232 {
1235 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1233 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1236 }
1234 }
1237 else
1235 else
1238 {
1236 {
1239 status = RTEMS_SUCCESSFUL;
1237 status = RTEMS_SUCCESSFUL;
1240 }
1238 }
1241 }
1239 }
1242
1240
1243 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1241 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1244 {
1242 {
1245 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1243 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1246 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1244 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1247 {
1245 {
1248 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1246 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1249 }
1247 }
1250 else
1248 else
1251 {
1249 {
1252 status = RTEMS_SUCCESSFUL;
1250 status = RTEMS_SUCCESSFUL;
1253 }
1251 }
1254 }
1252 }
1255
1253
1256 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1254 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1257 {
1255 {
1258 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1256 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1259 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1257 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1260 {
1258 {
1261 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1259 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1262 }
1260 }
1263 else
1261 else
1264 {
1262 {
1265 status = RTEMS_SUCCESSFUL;
1263 status = RTEMS_SUCCESSFUL;
1266 }
1264 }
1267 }
1265 }
1268
1266
1269 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1267 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1270 {
1268 {
1271 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1269 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1272 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1270 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1273 {
1271 {
1274 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1272 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1275 }
1273 }
1276 else
1274 else
1277 {
1275 {
1278 status = RTEMS_SUCCESSFUL;
1276 status = RTEMS_SUCCESSFUL;
1279 }
1277 }
1280 }
1278 }
1281
1279
1282 return status;
1280 return status;
1283 }
1281 }
1284
1282
1285 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1283 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1286 {
1284 {
1287
1285
1288 WFP_reset_current_ring_nodes();
1286 WFP_reset_current_ring_nodes();
1289
1287
1290 reset_waveform_picker_regs();
1288 reset_waveform_picker_regs();
1291
1289
1292 set_wfp_burst_enable_register( mode );
1290 set_wfp_burst_enable_register( mode );
1293
1291
1294 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1292 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1295 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1293 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1296
1294
1297 if (transitionCoarseTime == 0)
1295 if (transitionCoarseTime == 0)
1298 {
1296 {
1299 // instant transition means transition on the next valid date
1297 // instant transition means transition on the next valid date
1300 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1298 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1301 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1299 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1302 }
1300 }
1303 else
1301 else
1304 {
1302 {
1305 waveform_picker_regs->start_date = transitionCoarseTime;
1303 waveform_picker_regs->start_date = transitionCoarseTime;
1306 }
1304 }
1307
1305
1308 update_last_valid_transition_date(waveform_picker_regs->start_date);
1306 update_last_valid_transition_date(waveform_picker_regs->start_date);
1309
1307
1310 }
1308 }
1311
1309
1312 void launch_spectral_matrix( void )
1310 void launch_spectral_matrix( void )
1313 {
1311 {
1314 SM_reset_current_ring_nodes();
1312 SM_reset_current_ring_nodes();
1315
1313
1316 reset_spectral_matrix_regs();
1314 reset_spectral_matrix_regs();
1317
1315
1318 reset_nb_sm();
1316 reset_nb_sm();
1319
1317
1320 set_sm_irq_onNewMatrix( 1 );
1318 set_sm_irq_onNewMatrix( 1 );
1321
1319
1322 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1320 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1323 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1321 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1324
1322
1325 }
1323 }
1326
1324
1327 void set_sm_irq_onNewMatrix( unsigned char value )
1325 void set_sm_irq_onNewMatrix( unsigned char value )
1328 {
1326 {
1329 if (value == 1)
1327 if (value == 1)
1330 {
1328 {
1331 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1329 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1332 }
1330 }
1333 else
1331 else
1334 {
1332 {
1335 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1333 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1336 }
1334 }
1337 }
1335 }
1338
1336
1339 void set_sm_irq_onError( unsigned char value )
1337 void set_sm_irq_onError( unsigned char value )
1340 {
1338 {
1341 if (value == 1)
1339 if (value == 1)
1342 {
1340 {
1343 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1341 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1344 }
1342 }
1345 else
1343 else
1346 {
1344 {
1347 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1345 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1348 }
1346 }
1349 }
1347 }
1350
1348
1351 //*****************************
1349 //*****************************
1352 // CONFIGURE CALIBRATION SIGNAL
1350 // CONFIGURE CALIBRATION SIGNAL
1353 void setCalibrationPrescaler( unsigned int prescaler )
1351 void setCalibrationPrescaler( unsigned int prescaler )
1354 {
1352 {
1355 // prescaling of the master clock (25 MHz)
1353 // prescaling of the master clock (25 MHz)
1356 // master clock is divided by 2^prescaler
1354 // master clock is divided by 2^prescaler
1357 time_management_regs->calPrescaler = prescaler;
1355 time_management_regs->calPrescaler = prescaler;
1358 }
1356 }
1359
1357
1360 void setCalibrationDivisor( unsigned int divisionFactor )
1358 void setCalibrationDivisor( unsigned int divisionFactor )
1361 {
1359 {
1362 // division of the prescaled clock by the division factor
1360 // division of the prescaled clock by the division factor
1363 time_management_regs->calDivisor = divisionFactor;
1361 time_management_regs->calDivisor = divisionFactor;
1364 }
1362 }
1365
1363
1366 void setCalibrationData( void )
1364 void setCalibrationData( void )
1367 {
1365 {
1368 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1366 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1369 *
1367 *
1370 * @param void
1368 * @param void
1371 *
1369 *
1372 * @return void
1370 * @return void
1373 *
1371 *
1374 */
1372 */
1375
1373
1376 unsigned int k;
1374 unsigned int k;
1377 unsigned short data;
1375 unsigned short data;
1378 float val;
1376 float val;
1379 float Ts;
1377 float Ts;
1380
1378
1381 time_management_regs->calDataPtr = INIT_CHAR;
1379 time_management_regs->calDataPtr = INIT_CHAR;
1382
1380
1383 Ts = 1 / CAL_FS;
1381 Ts = 1 / CAL_FS;
1384
1382
1385 // build the signal for the SCM calibration
1383 // build the signal for the SCM calibration
1386 for (k = 0; k < CAL_NB_PTS; k++)
1384 for (k = 0; k < CAL_NB_PTS; k++)
1387 {
1385 {
1388 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1386 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1389 + CAL_A1 * sin( CAL_W1 * k * Ts );
1387 + CAL_A1 * sin( CAL_W1 * k * Ts );
1390 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1388 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1391 time_management_regs->calData = data & CAL_DATA_MASK;
1389 time_management_regs->calData = data & CAL_DATA_MASK;
1392 }
1390 }
1393 }
1391 }
1394
1392
1395 void setCalibrationDataInterleaved( void )
1393 void setCalibrationDataInterleaved( void )
1396 {
1394 {
1397 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1395 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1398 *
1396 *
1399 * @param void
1397 * @param void
1400 *
1398 *
1401 * @return void
1399 * @return void
1402 *
1400 *
1403 * In interleaved mode, one can store more values than in normal mode.
1401 * In interleaved mode, one can store more values than in normal mode.
1404 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1402 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1405 * T store 3 values, one need two write operations.
1403 * T store 3 values, one need two write operations.
1406 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1404 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1407 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1405 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1408 *
1406 *
1409 */
1407 */
1410
1408
1411 unsigned int k;
1409 unsigned int k;
1412 float val;
1410 float val;
1413 float Ts;
1411 float Ts;
1414 unsigned short data[CAL_NB_PTS_INTER];
1412 unsigned short data[CAL_NB_PTS_INTER];
1415 unsigned char *dataPtr;
1413 unsigned char *dataPtr;
1416
1414
1417 Ts = 1 / CAL_FS_INTER;
1415 Ts = 1 / CAL_FS_INTER;
1418
1416
1419 time_management_regs->calDataPtr = INIT_CHAR;
1417 time_management_regs->calDataPtr = INIT_CHAR;
1420
1418
1421 // build the signal for the SCM calibration
1419 // build the signal for the SCM calibration
1422 for (k=0; k<CAL_NB_PTS_INTER; k++)
1420 for (k=0; k<CAL_NB_PTS_INTER; k++)
1423 {
1421 {
1424 val = sin( 2 * pi * CAL_F0 * k * Ts )
1422 val = sin( 2 * pi * CAL_F0 * k * Ts )
1425 + sin( 2 * pi * CAL_F1 * k * Ts );
1423 + sin( 2 * pi * CAL_F1 * k * Ts );
1426 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1424 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1427 }
1425 }
1428
1426
1429 // write the signal in interleaved mode
1427 // write the signal in interleaved mode
1430 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1428 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1431 {
1429 {
1432 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1430 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1433 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1431 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1434 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1432 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1435 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1433 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1436 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1434 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1437 }
1435 }
1438 }
1436 }
1439
1437
1440 void setCalibrationReload( bool state)
1438 void setCalibrationReload( bool state)
1441 {
1439 {
1442 if (state == true)
1440 if (state == true)
1443 {
1441 {
1444 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1442 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1445 }
1443 }
1446 else
1444 else
1447 {
1445 {
1448 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1446 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1449 }
1447 }
1450 }
1448 }
1451
1449
1452 void setCalibrationEnable( bool state )
1450 void setCalibrationEnable( bool state )
1453 {
1451 {
1454 // this bit drives the multiplexer
1452 // this bit drives the multiplexer
1455 if (state == true)
1453 if (state == true)
1456 {
1454 {
1457 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1455 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1458 }
1456 }
1459 else
1457 else
1460 {
1458 {
1461 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1459 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1462 }
1460 }
1463 }
1461 }
1464
1462
1465 void setCalibrationInterleaved( bool state )
1463 void setCalibrationInterleaved( bool state )
1466 {
1464 {
1467 // this bit drives the multiplexer
1465 // this bit drives the multiplexer
1468 if (state == true)
1466 if (state == true)
1469 {
1467 {
1470 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1468 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1471 }
1469 }
1472 else
1470 else
1473 {
1471 {
1474 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1472 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1475 }
1473 }
1476 }
1474 }
1477
1475
1478 void setCalibration( bool state )
1476 void setCalibration( bool state )
1479 {
1477 {
1480 if (state == true)
1478 if (state == true)
1481 {
1479 {
1482 setCalibrationEnable( true );
1480 setCalibrationEnable( true );
1483 setCalibrationReload( false );
1481 setCalibrationReload( false );
1484 set_hk_lfr_calib_enable( true );
1482 set_hk_lfr_calib_enable( true );
1485 }
1483 }
1486 else
1484 else
1487 {
1485 {
1488 setCalibrationEnable( false );
1486 setCalibrationEnable( false );
1489 setCalibrationReload( true );
1487 setCalibrationReload( true );
1490 set_hk_lfr_calib_enable( false );
1488 set_hk_lfr_calib_enable( false );
1491 }
1489 }
1492 }
1490 }
1493
1491
1494 void configureCalibration( bool interleaved )
1492 void configureCalibration( bool interleaved )
1495 {
1493 {
1496 setCalibration( false );
1494 setCalibration( false );
1497 if ( interleaved == true )
1495 if ( interleaved == true )
1498 {
1496 {
1499 setCalibrationInterleaved( true );
1497 setCalibrationInterleaved( true );
1500 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1498 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1501 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1499 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1502 setCalibrationDataInterleaved();
1500 setCalibrationDataInterleaved();
1503 }
1501 }
1504 else
1502 else
1505 {
1503 {
1506 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1504 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1507 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1505 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1508 setCalibrationData();
1506 setCalibrationData();
1509 }
1507 }
1510 }
1508 }
1511
1509
1512 //****************
1510 //****************
1513 // CLOSING ACTIONS
1511 // CLOSING ACTIONS
1514 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1512 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1515 {
1513 {
1516 /** This function is used to update the HK packets statistics after a successful TC execution.
1514 /** This function is used to update the HK packets statistics after a successful TC execution.
1517 *
1515 *
1518 * @param TC points to the TC being processed
1516 * @param TC points to the TC being processed
1519 * @param time is the time used to date the TC execution
1517 * @param time is the time used to date the TC execution
1520 *
1518 *
1521 */
1519 */
1522
1520
1523 unsigned int val;
1521 unsigned int val;
1524
1522
1525 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1523 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1526 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1524 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1527 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1525 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1528 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1526 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1529 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1527 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1530 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1528 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1531 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1529 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1532 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1530 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1533 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1531 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1534 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1532 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1535 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1533 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1536 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1534 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1537
1535
1538 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1536 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1539 val++;
1537 val++;
1540 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1538 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1541 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1539 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1542 }
1540 }
1543
1541
1544 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1542 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1545 {
1543 {
1546 /** This function is used to update the HK packets statistics after a TC rejection.
1544 /** This function is used to update the HK packets statistics after a TC rejection.
1547 *
1545 *
1548 * @param TC points to the TC being processed
1546 * @param TC points to the TC being processed
1549 * @param time is the time used to date the TC rejection
1547 * @param time is the time used to date the TC rejection
1550 *
1548 *
1551 */
1549 */
1552
1550
1553 unsigned int val;
1551 unsigned int val;
1554
1552
1555 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1553 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1556 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1554 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1557 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1555 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1558 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1556 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1559 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1557 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1560 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1558 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1561 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1559 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1562 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1560 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1563 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1561 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1564 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1562 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1565 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1563 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1566 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1564 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1567
1565
1568 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1566 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1569 val++;
1567 val++;
1570 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1568 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1571 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1569 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1572 }
1570 }
1573
1571
1574 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1572 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1575 {
1573 {
1576 /** This function is the last step of the TC execution workflow.
1574 /** This function is the last step of the TC execution workflow.
1577 *
1575 *
1578 * @param TC points to the TC being processed
1576 * @param TC points to the TC being processed
1579 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1577 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1580 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1578 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1581 * @param time is the time used to date the TC execution
1579 * @param time is the time used to date the TC execution
1582 *
1580 *
1583 */
1581 */
1584
1582
1585 unsigned char requestedMode;
1583 unsigned char requestedMode;
1586
1584
1587 if (result == LFR_SUCCESSFUL)
1585 if (result == LFR_SUCCESSFUL)
1588 {
1586 {
1589 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1587 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1590 &
1588 &
1591 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1589 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1592 )
1590 )
1593 {
1591 {
1594 send_tm_lfr_tc_exe_success( TC, queue_id );
1592 send_tm_lfr_tc_exe_success( TC, queue_id );
1595 }
1593 }
1596 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1594 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1597 {
1595 {
1598 //**********************************
1596 //**********************************
1599 // UPDATE THE LFRMODE LOCAL VARIABLE
1597 // UPDATE THE LFRMODE LOCAL VARIABLE
1600 requestedMode = TC->dataAndCRC[1];
1598 requestedMode = TC->dataAndCRC[1];
1601 updateLFRCurrentMode( requestedMode );
1599 updateLFRCurrentMode( requestedMode );
1602 }
1600 }
1603 }
1601 }
1604 else if (result == LFR_EXE_ERROR)
1602 else if (result == LFR_EXE_ERROR)
1605 {
1603 {
1606 send_tm_lfr_tc_exe_error( TC, queue_id );
1604 send_tm_lfr_tc_exe_error( TC, queue_id );
1607 }
1605 }
1608 }
1606 }
1609
1607
1610 //***************************
1608 //***************************
1611 // Interrupt Service Routines
1609 // Interrupt Service Routines
1612 rtems_isr commutation_isr1( rtems_vector_number vector )
1610 rtems_isr commutation_isr1( rtems_vector_number vector )
1613 {
1611 {
1614 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1612 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1615 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1613 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1616 }
1614 }
1617 }
1615 }
1618
1616
1619 rtems_isr commutation_isr2( rtems_vector_number vector )
1617 rtems_isr commutation_isr2( rtems_vector_number vector )
1620 {
1618 {
1621 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1619 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1622 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1620 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1623 }
1621 }
1624 }
1622 }
1625
1623
1626 //****************
1624 //****************
1627 // OTHER FUNCTIONS
1625 // OTHER FUNCTIONS
1628 void updateLFRCurrentMode( unsigned char requestedMode )
1626 void updateLFRCurrentMode( unsigned char requestedMode )
1629 {
1627 {
1630 /** This function updates the value of the global variable lfrCurrentMode.
1628 /** This function updates the value of the global variable lfrCurrentMode.
1631 *
1629 *
1632 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1630 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1633 *
1631 *
1634 */
1632 */
1635
1633
1636 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1634 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1637 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1635 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1638 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1636 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1639 lfrCurrentMode = requestedMode;
1637 lfrCurrentMode = requestedMode;
1640 }
1638 }
1641
1639
1642 void set_lfr_soft_reset( unsigned char value )
1640 void set_lfr_soft_reset( unsigned char value )
1643 {
1641 {
1644 if (value == 1)
1642 if (value == 1)
1645 {
1643 {
1646 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1644 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1647 }
1645 }
1648 else
1646 else
1649 {
1647 {
1650 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1648 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1651 }
1649 }
1652 }
1650 }
1653
1651
1654 void reset_lfr( void )
1652 void reset_lfr( void )
1655 {
1653 {
1656 set_lfr_soft_reset( 1 );
1654 set_lfr_soft_reset( 1 );
1657
1655
1658 set_lfr_soft_reset( 0 );
1656 set_lfr_soft_reset( 0 );
1659
1657
1660 set_hk_lfr_sc_potential_flag( true );
1658 set_hk_lfr_sc_potential_flag( true );
1661 }
1659 }
General Comments 0
You need to be logged in to leave comments. Login now