##// END OF EJS Templates
2.0.2.2...
paul -
r187:87f7d2226935 VHDL_0_1_28
parent child
Show More
@@ -1,2 +1,2
1 a586fe639ac179e95bdc150ebdbab0312f31dc30 LFR_basic-parameters
1 a586fe639ac179e95bdc150ebdbab0312f31dc30 LFR_basic-parameters
2 6d02d4b02291d2b25c387fa74037dc7929cd92b5 header/lfr_common_headers
2 be0dc1c1876987307ddfc0fb47044f6d41815866 header/lfr_common_headers
@@ -1,112 +1,112
1 TEMPLATE = app
1 TEMPLATE = app
2 # CONFIG += console v8 sim
2 # CONFIG += console v8 sim
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 # lpp_dpu_destid
4 # lpp_dpu_destid
5 CONFIG += console verbose lpp_dpu_destid
5 CONFIG += console verbose lpp_dpu_destid
6 CONFIG -= qt
6 CONFIG -= qt
7
7
8 include(./sparc.pri)
8 include(./sparc.pri)
9
9
10 # flight software version
10 # flight software version
11 SWVERSION=-1-0
11 SWVERSION=-1-0
12 DEFINES += SW_VERSION_N1=2 # major
12 DEFINES += SW_VERSION_N1=2 # major
13 DEFINES += SW_VERSION_N2=0 # minor
13 DEFINES += SW_VERSION_N2=0 # minor
14 DEFINES += SW_VERSION_N3=2 # patch
14 DEFINES += SW_VERSION_N3=2 # patch
15 DEFINES += SW_VERSION_N4=1 # internal
15 DEFINES += SW_VERSION_N4=2 # internal
16
16
17 # <GCOV>
17 # <GCOV>
18 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
18 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
19 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
19 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
20 # </GCOV>
20 # </GCOV>
21
21
22 # <CHANGE BEFORE FLIGHT>
22 # <CHANGE BEFORE FLIGHT>
23 contains( CONFIG, lpp_dpu_destid ) {
23 contains( CONFIG, lpp_dpu_destid ) {
24 DEFINES += LPP_DPU_DESTID
24 DEFINES += LPP_DPU_DESTID
25 }
25 }
26 # </CHANGE BEFORE FLIGHT>
26 # </CHANGE BEFORE FLIGHT>
27
27
28 contains( CONFIG, debug_tch ) {
28 contains( CONFIG, debug_tch ) {
29 DEFINES += DEBUG_TCH
29 DEFINES += DEBUG_TCH
30 }
30 }
31 DEFINES += MSB_FIRST_TCH
31 DEFINES += MSB_FIRST_TCH
32
32
33 contains( CONFIG, vhdl_dev ) {
33 contains( CONFIG, vhdl_dev ) {
34 DEFINES += VHDL_DEV
34 DEFINES += VHDL_DEV
35 }
35 }
36
36
37 contains( CONFIG, verbose ) {
37 contains( CONFIG, verbose ) {
38 DEFINES += PRINT_MESSAGES_ON_CONSOLE
38 DEFINES += PRINT_MESSAGES_ON_CONSOLE
39 }
39 }
40
40
41 contains( CONFIG, debug_messages ) {
41 contains( CONFIG, debug_messages ) {
42 DEFINES += DEBUG_MESSAGES
42 DEFINES += DEBUG_MESSAGES
43 }
43 }
44
44
45 contains( CONFIG, cpu_usage_report ) {
45 contains( CONFIG, cpu_usage_report ) {
46 DEFINES += PRINT_TASK_STATISTICS
46 DEFINES += PRINT_TASK_STATISTICS
47 }
47 }
48
48
49 contains( CONFIG, stack_report ) {
49 contains( CONFIG, stack_report ) {
50 DEFINES += PRINT_STACK_REPORT
50 DEFINES += PRINT_STACK_REPORT
51 }
51 }
52
52
53 contains( CONFIG, boot_messages ) {
53 contains( CONFIG, boot_messages ) {
54 DEFINES += BOOT_MESSAGES
54 DEFINES += BOOT_MESSAGES
55 }
55 }
56
56
57 #doxygen.target = doxygen
57 #doxygen.target = doxygen
58 #doxygen.commands = doxygen ../doc/Doxyfile
58 #doxygen.commands = doxygen ../doc/Doxyfile
59 #QMAKE_EXTRA_TARGETS += doxygen
59 #QMAKE_EXTRA_TARGETS += doxygen
60
60
61 TARGET = fsw
61 TARGET = fsw
62
62
63 INCLUDEPATH += \
63 INCLUDEPATH += \
64 $${PWD}/../src \
64 $${PWD}/../src \
65 $${PWD}/../header \
65 $${PWD}/../header \
66 $${PWD}/../header/lfr_common_headers \
66 $${PWD}/../header/lfr_common_headers \
67 $${PWD}/../header/processing \
67 $${PWD}/../header/processing \
68 $${PWD}/../LFR_basic-parameters
68 $${PWD}/../LFR_basic-parameters
69
69
70 SOURCES += \
70 SOURCES += \
71 ../src/wf_handler.c \
71 ../src/wf_handler.c \
72 ../src/tc_handler.c \
72 ../src/tc_handler.c \
73 ../src/fsw_misc.c \
73 ../src/fsw_misc.c \
74 ../src/fsw_init.c \
74 ../src/fsw_init.c \
75 ../src/fsw_globals.c \
75 ../src/fsw_globals.c \
76 ../src/fsw_spacewire.c \
76 ../src/fsw_spacewire.c \
77 ../src/tc_load_dump_parameters.c \
77 ../src/tc_load_dump_parameters.c \
78 ../src/tm_lfr_tc_exe.c \
78 ../src/tm_lfr_tc_exe.c \
79 ../src/tc_acceptance.c \
79 ../src/tc_acceptance.c \
80 ../src/processing/fsw_processing.c \
80 ../src/processing/fsw_processing.c \
81 ../src/processing/avf0_prc0.c \
81 ../src/processing/avf0_prc0.c \
82 ../src/processing/avf1_prc1.c \
82 ../src/processing/avf1_prc1.c \
83 ../src/processing/avf2_prc2.c \
83 ../src/processing/avf2_prc2.c \
84 ../src/lfr_cpu_usage_report.c \
84 ../src/lfr_cpu_usage_report.c \
85 ../LFR_basic-parameters/basic_parameters.c
85 ../LFR_basic-parameters/basic_parameters.c
86
86
87 HEADERS += \
87 HEADERS += \
88 ../header/wf_handler.h \
88 ../header/wf_handler.h \
89 ../header/tc_handler.h \
89 ../header/tc_handler.h \
90 ../header/grlib_regs.h \
90 ../header/grlib_regs.h \
91 ../header/fsw_misc.h \
91 ../header/fsw_misc.h \
92 ../header/fsw_init.h \
92 ../header/fsw_init.h \
93 ../header/fsw_spacewire.h \
93 ../header/fsw_spacewire.h \
94 ../header/tc_load_dump_parameters.h \
94 ../header/tc_load_dump_parameters.h \
95 ../header/tm_lfr_tc_exe.h \
95 ../header/tm_lfr_tc_exe.h \
96 ../header/tc_acceptance.h \
96 ../header/tc_acceptance.h \
97 ../header/processing/fsw_processing.h \
97 ../header/processing/fsw_processing.h \
98 ../header/processing/avf0_prc0.h \
98 ../header/processing/avf0_prc0.h \
99 ../header/processing/avf1_prc1.h \
99 ../header/processing/avf1_prc1.h \
100 ../header/processing/avf2_prc2.h \
100 ../header/processing/avf2_prc2.h \
101 ../header/fsw_params_wf_handler.h \
101 ../header/fsw_params_wf_handler.h \
102 ../header/lfr_cpu_usage_report.h \
102 ../header/lfr_cpu_usage_report.h \
103 ../header/lfr_common_headers/ccsds_types.h \
103 ../header/lfr_common_headers/ccsds_types.h \
104 ../header/lfr_common_headers/fsw_params.h \
104 ../header/lfr_common_headers/fsw_params.h \
105 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
105 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
106 ../header/lfr_common_headers/fsw_params_processing.h \
106 ../header/lfr_common_headers/fsw_params_processing.h \
107 ../header/lfr_common_headers/TC_types.h \
107 ../header/lfr_common_headers/TC_types.h \
108 ../header/lfr_common_headers/tm_byte_positions.h \
108 ../header/lfr_common_headers/tm_byte_positions.h \
109 ../LFR_basic-parameters/basic_parameters.h \
109 ../LFR_basic-parameters/basic_parameters.h \
110 ../LFR_basic-parameters/basic_parameters_params.h \
110 ../LFR_basic-parameters/basic_parameters_params.h \
111 ../header/GscMemoryLPP.hpp
111 ../header/GscMemoryLPP.hpp
112
112
@@ -1,66 +1,62
1 #ifndef GSCMEMORY_HPP_
1 #ifndef GSCMEMORY_HPP_
2 #define GSCMEMORY_HPP_
2 #define GSCMEMORY_HPP_
3
3
4 static unsigned int getCacheControlRegister(){
5
6 #ifndef LEON3
4 #ifndef LEON3
7 #define LEON3
5 #define LEON3
8 #endif
6 #endif
9
7
8 static unsigned int getCacheControlRegister(){
10 #ifdef LEON3
9 #ifdef LEON3
11 unsigned int cacheControlRegister = 0;
10 unsigned int cacheControlRegister = 0;
12 __asm__ __volatile__("lda [%%g0] 2, %0" : "=r"(cacheControlRegister) : );
11 __asm__ __volatile__("lda [%%g0] 2, %0" : "=r"(cacheControlRegister) : );
13 return cacheControlRegister;
12 return cacheControlRegister;
14 #endif
13 #endif
15 }
14 }
16
15
17 static void setCacheControlRegister(unsigned int cacheControlRegister){
16 static void setCacheControlRegister(unsigned int cacheControlRegister)
18
17 {
19 #ifdef LEON3
18 #ifdef LEON3
20 __asm__ __volatile__("sta %0, [%%g0] 2" : : "r"(cacheControlRegister));
19 __asm__ __volatile__("sta %0, [%%g0] 2" : : "r"(cacheControlRegister));
21 #endif
20 #endif
22 }
21 }
23
22
24
23
25 /**
24 /**
26 * Flush the data cache and the instruction cache.
25 * Flush the data cache and the instruction cache.
27 *
26 *
28 * @return
27 * @return
29 */
28 */
30 static inline void flushCache() {
29 static inline void flushCache() {
31 asm("flush");
30 asm("flush");
32 }
31 }
33
32
34
33
35 static void enableInstructionCache() {
34 static void enableInstructionCache() {
36
37 #ifdef LEON3
35 #ifdef LEON3
38 unsigned int cacheControlRegister;
36 unsigned int cacheControlRegister;
39 cacheControlRegister = getCacheControlRegister();
37 cacheControlRegister = getCacheControlRegister();
40 cacheControlRegister = (cacheControlRegister | 0x3);
38 cacheControlRegister = (cacheControlRegister | 0x3);
41 setCacheControlRegister(cacheControlRegister);
39 setCacheControlRegister(cacheControlRegister);
42 #endif
40 #endif
43 }
41 }
44
42
45 static void enableDataCache() {
43 static void enableDataCache() {
46
47 #ifdef LEON3
44 #ifdef LEON3
48 unsigned int cacheControlRegister;
45 unsigned int cacheControlRegister;
49 cacheControlRegister = getCacheControlRegister();
46 cacheControlRegister = getCacheControlRegister();
50 cacheControlRegister = (cacheControlRegister | 0xc);
47 cacheControlRegister = (cacheControlRegister | 0xc);
51 setCacheControlRegister(cacheControlRegister);
48 setCacheControlRegister(cacheControlRegister);
52 #endif
49 #endif
53 }
50 }
54
51
55 static void enableInstructionBurstFetch() {
52 static void enableInstructionBurstFetch() {
56
57 #ifdef LEON3
53 #ifdef LEON3
58 unsigned int cacheControlRegister;
54 unsigned int cacheControlRegister;
59 cacheControlRegister = getCacheControlRegister();
55 cacheControlRegister = getCacheControlRegister();
60 // set the bit IB to 1
56 // set the bit IB to 1
61 cacheControlRegister = (cacheControlRegister | 0x10000);
57 cacheControlRegister = (cacheControlRegister | 0x10000);
62 setCacheControlRegister(cacheControlRegister);
58 setCacheControlRegister(cacheControlRegister);
63 #endif
59 #endif
64 }
60 }
65
61
66 #endif /* GSCMEMORY_HPP_ */
62 #endif /* GSCMEMORY_HPP_ */
@@ -1,131 +1,138
1 #ifndef GRLIB_REGS_H_INCLUDED
1 #ifndef GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
3
3
4 #define NB_GPTIMER 3
4 #define NB_GPTIMER 3
5
5
6 struct apbuart_regs_str{
6 struct apbuart_regs_str{
7 volatile unsigned int data;
7 volatile unsigned int data;
8 volatile unsigned int status;
8 volatile unsigned int status;
9 volatile unsigned int ctrl;
9 volatile unsigned int ctrl;
10 volatile unsigned int scaler;
10 volatile unsigned int scaler;
11 volatile unsigned int fifoDebug;
11 volatile unsigned int fifoDebug;
12 };
12 };
13
13
14 struct grgpio_regs_str{
14 struct grgpio_regs_str{
15 volatile int io_port_data_register;
15 volatile int io_port_data_register;
16 int io_port_output_register;
16 int io_port_output_register;
17 int io_port_direction_register;
17 int io_port_direction_register;
18 int interrupt_mak_register;
18 int interrupt_mak_register;
19 int interrupt_polarity_register;
19 int interrupt_polarity_register;
20 int interrupt_edge_register;
20 int interrupt_edge_register;
21 int bypass_register;
21 int bypass_register;
22 int reserved;
22 int reserved;
23 // 0x20-0x3c interrupt map register(s)
23 // 0x20-0x3c interrupt map register(s)
24 };
24 };
25
25
26 typedef struct {
26 typedef struct {
27 volatile unsigned int counter;
27 volatile unsigned int counter;
28 volatile unsigned int reload;
28 volatile unsigned int reload;
29 volatile unsigned int ctrl;
29 volatile unsigned int ctrl;
30 volatile unsigned int unused;
30 volatile unsigned int unused;
31 } timer_regs_t;
31 } timer_regs_t;
32
32
33 typedef struct {
33 typedef struct {
34 volatile unsigned int scaler_value;
34 volatile unsigned int scaler_value;
35 volatile unsigned int scaler_reload;
35 volatile unsigned int scaler_reload;
36 volatile unsigned int conf;
36 volatile unsigned int conf;
37 volatile unsigned int unused0;
37 volatile unsigned int unused0;
38 timer_regs_t timer[NB_GPTIMER];
38 timer_regs_t timer[NB_GPTIMER];
39 } gptimer_regs_t;
39 } gptimer_regs_t;
40
40
41 typedef struct {
41 typedef struct {
42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
43 // bit 1 is the soft reset for the time management module
43 // bit 1 is the soft reset for the time management module
44 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
44 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
45 volatile int coarse_time_load;
45 volatile int coarse_time_load;
46 volatile int coarse_time;
46 volatile int coarse_time;
47 volatile int fine_time;
47 volatile int fine_time;
48 volatile int temp_scm;
48 // TEMPERATURES
49 volatile int temp_pcb;
49 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
50 volatile int temp_fpga;
50 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
51 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
52 // CALIBRATION
53 volatile unsigned int calDACCtrl;
54 volatile unsigned int calPrescaler;
55 volatile unsigned int calDivisor;
56 volatile unsigned int calDataPtr;
57 volatile unsigned int calData;
51 } time_management_regs_t;
58 } time_management_regs_t;
52
59
53 // PDB >= 0.1.28
60 // PDB >= 0.1.28
54 typedef struct{
61 typedef struct{
55 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
62 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
56 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
63 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
57 int addr_data_f0_0; // 0x08
64 int addr_data_f0_0; // 0x08
58 int addr_data_f0_1; // 0x0c
65 int addr_data_f0_1; // 0x0c
59 int addr_data_f1_0; // 0x10
66 int addr_data_f1_0; // 0x10
60 int addr_data_f1_1; // 0x14
67 int addr_data_f1_1; // 0x14
61 int addr_data_f2_0; // 0x18
68 int addr_data_f2_0; // 0x18
62 int addr_data_f2_1; // 0x1c
69 int addr_data_f2_1; // 0x1c
63 int addr_data_f3_0; // 0x20
70 int addr_data_f3_0; // 0x20
64 int addr_data_f3_1; // 0x24
71 int addr_data_f3_1; // 0x24
65 volatile int status; // 0x28
72 volatile int status; // 0x28
66 int delta_snapshot; // 0x2c
73 int delta_snapshot; // 0x2c
67 int delta_f0; // 0x30
74 int delta_f0; // 0x30
68 int delta_f0_2; // 0x34
75 int delta_f0_2; // 0x34
69 int delta_f1; // 0x38
76 int delta_f1; // 0x38
70 int delta_f2; // 0x3c
77 int delta_f2; // 0x3c
71 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
78 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
72 int snapshot_param; // 0x44
79 int snapshot_param; // 0x44
73 int start_date; // 0x48
80 int start_date; // 0x48
74 //
81 //
75 volatile unsigned int f0_0_coarse_time; // 0x4c
82 volatile unsigned int f0_0_coarse_time; // 0x4c
76 volatile unsigned int f0_0_fine_time; // 0x50
83 volatile unsigned int f0_0_fine_time; // 0x50
77 volatile unsigned int f0_1_coarse_time; // 0x54
84 volatile unsigned int f0_1_coarse_time; // 0x54
78 volatile unsigned int f0_1_fine_time; // 0x58
85 volatile unsigned int f0_1_fine_time; // 0x58
79 //
86 //
80 volatile unsigned int f1_0_coarse_time; // 0x5c
87 volatile unsigned int f1_0_coarse_time; // 0x5c
81 volatile unsigned int f1_0_fine_time; // 0x60
88 volatile unsigned int f1_0_fine_time; // 0x60
82 volatile unsigned int f1_1_coarse_time; // 0x64
89 volatile unsigned int f1_1_coarse_time; // 0x64
83 volatile unsigned int f1_1_fine_time; // 0x68
90 volatile unsigned int f1_1_fine_time; // 0x68
84 //
91 //
85 volatile unsigned int f2_0_coarse_time; // 0x6c
92 volatile unsigned int f2_0_coarse_time; // 0x6c
86 volatile unsigned int f2_0_fine_time; // 0x70
93 volatile unsigned int f2_0_fine_time; // 0x70
87 volatile unsigned int f2_1_coarse_time; // 0x74
94 volatile unsigned int f2_1_coarse_time; // 0x74
88 volatile unsigned int f2_1_fine_time; // 0x78
95 volatile unsigned int f2_1_fine_time; // 0x78
89 //
96 //
90 volatile unsigned int f3_0_coarse_time; // 0x7c
97 volatile unsigned int f3_0_coarse_time; // 0x7c
91 volatile unsigned int f3_0_fine_time; // 0x80
98 volatile unsigned int f3_0_fine_time; // 0x80
92 volatile unsigned int f3_1_coarse_time; // 0x84
99 volatile unsigned int f3_1_coarse_time; // 0x84
93 volatile unsigned int f3_1_fine_time; // 0x88
100 volatile unsigned int f3_1_fine_time; // 0x88
94 //
101 //
95 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
102 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
96 //
103 //
97 volatile unsigned int v; // 0x90
104 volatile unsigned int v; // 0x90
98 volatile unsigned int e1; // 0x94
105 volatile unsigned int e1; // 0x94
99 volatile unsigned int e2; // 0x98
106 volatile unsigned int e2; // 0x98
100 } waveform_picker_regs_0_1_18_t;
107 } waveform_picker_regs_0_1_18_t;
101
108
102 typedef struct {
109 typedef struct {
103 volatile int config; // 0x00
110 volatile int config; // 0x00
104 volatile int status; // 0x04
111 volatile int status; // 0x04
105 volatile int f0_0_address; // 0x08
112 volatile int f0_0_address; // 0x08
106 volatile int f0_1_address; // 0x0C
113 volatile int f0_1_address; // 0x0C
107 //
114 //
108 volatile int f1_0_address; // 0x10
115 volatile int f1_0_address; // 0x10
109 volatile int f1_1_address; // 0x14
116 volatile int f1_1_address; // 0x14
110 volatile int f2_0_address; // 0x18
117 volatile int f2_0_address; // 0x18
111 volatile int f2_1_address; // 0x1C
118 volatile int f2_1_address; // 0x1C
112 //
119 //
113 volatile unsigned int f0_0_coarse_time; // 0x20
120 volatile unsigned int f0_0_coarse_time; // 0x20
114 volatile unsigned int f0_0_fine_time; // 0x24
121 volatile unsigned int f0_0_fine_time; // 0x24
115 volatile unsigned int f0_1_coarse_time; // 0x28
122 volatile unsigned int f0_1_coarse_time; // 0x28
116 volatile unsigned int f0_1_fine_time; // 0x2C
123 volatile unsigned int f0_1_fine_time; // 0x2C
117 //
124 //
118 volatile unsigned int f1_0_coarse_time; // 0x30
125 volatile unsigned int f1_0_coarse_time; // 0x30
119 volatile unsigned int f1_0_fine_time; // 0x34
126 volatile unsigned int f1_0_fine_time; // 0x34
120 volatile unsigned int f1_1_coarse_time; // 0x38
127 volatile unsigned int f1_1_coarse_time; // 0x38
121 volatile unsigned int f1_1_fine_time; // 0x3C
128 volatile unsigned int f1_1_fine_time; // 0x3C
122 //
129 //
123 volatile unsigned int f2_0_coarse_time; // 0x40
130 volatile unsigned int f2_0_coarse_time; // 0x40
124 volatile unsigned int f2_0_fine_time; // 0x44
131 volatile unsigned int f2_0_fine_time; // 0x44
125 volatile unsigned int f2_1_coarse_time; // 0x48
132 volatile unsigned int f2_1_coarse_time; // 0x48
126 volatile unsigned int f2_1_fine_time; // 0x4C
133 volatile unsigned int f2_1_fine_time; // 0x4C
127 //
134 //
128 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
135 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
129 } spectral_matrix_regs_t;
136 } spectral_matrix_regs_t;
130
137
131 #endif // GRLIB_REGS_H_INCLUDED
138 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,64 +1,75
1 #ifndef TC_HANDLER_H_INCLUDED
1 #ifndef TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <leon.h>
5 #include <leon.h>
6
6
7 #include "tc_load_dump_parameters.h"
7 #include "tc_load_dump_parameters.h"
8 #include "tc_acceptance.h"
8 #include "tc_acceptance.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11 #include "fsw_processing.h"
11 #include "fsw_processing.h"
12
12
13 #include "lfr_cpu_usage_report.h"
13 #include "lfr_cpu_usage_report.h"
14
14
15 // MODE PARAMETERS
15 // MODE PARAMETERS
16 extern unsigned int maxCount;
16 extern unsigned int maxCount;
17
17
18 //****
18 //****
19 // ISR
19 // ISR
20 rtems_isr commutation_isr1( rtems_vector_number vector );
20 rtems_isr commutation_isr1( rtems_vector_number vector );
21 rtems_isr commutation_isr2( rtems_vector_number vector );
21 rtems_isr commutation_isr2( rtems_vector_number vector );
22
22
23 //***********
23 //***********
24 // RTEMS TASK
24 // RTEMS TASK
25 rtems_task actn_task( rtems_task_argument unused );
25 rtems_task actn_task( rtems_task_argument unused );
26
26
27 //***********
27 //***********
28 // TC ACTIONS
28 // TC ACTIONS
29 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
29 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
30 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
31 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
31 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
32 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
32 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
33 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
33 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
34 int action_update_time( ccsdsTelecommandPacket_t *TC);
34 int action_update_time( ccsdsTelecommandPacket_t *TC);
35
35
36 // mode transition
36 // mode transition
37 int check_mode_value( unsigned char requestedMode );
37 int check_mode_value( unsigned char requestedMode );
38 int check_mode_transition( unsigned char requestedMode );
38 int check_mode_transition( unsigned char requestedMode );
39 int check_transition_date( unsigned int transitionCoarseTime );
39 int check_transition_date( unsigned int transitionCoarseTime );
40 int stop_current_mode( void );
40 int stop_current_mode( void );
41 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
41 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
42 int restart_science_tasks( unsigned char lfrRequestedMode );
42 int restart_science_tasks( unsigned char lfrRequestedMode );
43 int suspend_science_tasks();
43 int suspend_science_tasks();
44 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
44 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
45 void launch_spectral_matrix( void );
45 void launch_spectral_matrix( void );
46 void launch_spectral_matrix_simu( void );
46 void launch_spectral_matrix_simu( void );
47 void set_sm_irq_onNewMatrix( unsigned char value );
47 void set_sm_irq_onNewMatrix( unsigned char value );
48 void set_sm_irq_onError( unsigned char value );
48 void set_sm_irq_onError( unsigned char value );
49
49
50 // other functions
50 // other functions
51 void updateLFRCurrentMode();
51 void updateLFRCurrentMode();
52 void set_lfr_soft_reset( unsigned char value );
52 void set_lfr_soft_reset( unsigned char value );
53 void reset_lfr( void );
53 void reset_lfr( void );
54 // CALIBRATION
55 void setCalibrationPrescaler( unsigned int prescaler );
56 void setCalibrationDivisor( unsigned int divisionFactor );
57 void setCalibrationData( void );
58 void setCalibrationReload( bool state);
59 void setCalibrationEnable( bool state );
60 void setCalibrationInterleaved( bool state );
61 void startCalibration( void );
62 void stopCalibration( void );
63 void configureCalibration( bool interleaved );
64 //
54 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
65 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
55 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
66 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
56 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
67 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
57
68
58 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
69 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
59 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
70 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
60
71
61 #endif // TC_HANDLER_H_INCLUDED
72 #endif // TC_HANDLER_H_INCLUDED
62
73
63
74
64
75
@@ -1,87 +1,87
1 #ifndef WF_HANDLER_H_INCLUDED
1 #ifndef WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <math.h>
7 #include <math.h>
8 #include <fsw_params.h>
8 #include <fsw_params.h>
9
9
10 #include "fsw_spacewire.h"
10 #include "fsw_spacewire.h"
11 #include "fsw_misc.h"
11 #include "fsw_misc.h"
12 #include "fsw_params_wf_handler.h"
12 #include "fsw_params_wf_handler.h"
13
13
14 #define pi 3.1415
14 #define pi 3.14159265359
15
15
16 extern int fdSPW;
16 extern int fdSPW;
17
17
18 //*****************
18 //*****************
19 // waveform buffers
19 // waveform buffers
20 extern volatile int wf_buffer_f0[ ];
20 extern volatile int wf_buffer_f0[ ];
21 extern volatile int wf_buffer_f1[ ];
21 extern volatile int wf_buffer_f1[ ];
22 extern volatile int wf_buffer_f2[ ];
22 extern volatile int wf_buffer_f2[ ];
23 extern volatile int wf_buffer_f3[ ];
23 extern volatile int wf_buffer_f3[ ];
24
24
25 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
25 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
26 extern time_management_regs_t *time_management_regs;
26 extern time_management_regs_t *time_management_regs;
27 extern Packet_TM_LFR_HK_t housekeeping_packet;
27 extern Packet_TM_LFR_HK_t housekeeping_packet;
28 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
28 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
29 extern struct param_local_str param_local;
29 extern struct param_local_str param_local;
30
30
31 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
31 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
32 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
32 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
33
33
34 extern rtems_id Task_id[20]; /* array of task ids */
34 extern rtems_id Task_id[20]; /* array of task ids */
35
35
36 extern unsigned char lfrCurrentMode;
36 extern unsigned char lfrCurrentMode;
37
37
38 //**********
38 //**********
39 // RTEMS_ISR
39 // RTEMS_ISR
40 void reset_extractSWF( void );
40 void reset_extractSWF( void );
41 rtems_isr waveforms_isr( rtems_vector_number vector );
41 rtems_isr waveforms_isr( rtems_vector_number vector );
42
42
43 //***********
43 //***********
44 // RTEMS_TASK
44 // RTEMS_TASK
45 rtems_task wfrm_task( rtems_task_argument argument );
45 rtems_task wfrm_task( rtems_task_argument argument );
46 rtems_task cwf3_task( rtems_task_argument argument );
46 rtems_task cwf3_task( rtems_task_argument argument );
47 rtems_task cwf2_task( rtems_task_argument argument );
47 rtems_task cwf2_task( rtems_task_argument argument );
48 rtems_task cwf1_task( rtems_task_argument argument );
48 rtems_task cwf1_task( rtems_task_argument argument );
49 rtems_task swbd_task( rtems_task_argument argument );
49 rtems_task swbd_task( rtems_task_argument argument );
50
50
51 //******************
51 //******************
52 // general functions
52 // general functions
53 void WFP_init_rings( void );
53 void WFP_init_rings( void );
54 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
54 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
55 void WFP_reset_current_ring_nodes( void );
55 void WFP_reset_current_ring_nodes( void );
56 //
56 //
57 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
57 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
58 //
58 //
59 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
59 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
60 //
60 //
61 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
61 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
62 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
62 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
63 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel , unsigned long long acquisitionTimeF0_asLong);
63 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel , unsigned long long acquisitionTimeF0_asLong);
64 void snapshot_resynchronization( unsigned char *timePtr );
64 void snapshot_resynchronization( unsigned char *timePtr );
65 //
65 //
66 rtems_id get_pkts_queue_id( void );
66 rtems_id get_pkts_queue_id( void );
67
67
68 //**************
68 //**************
69 // wfp registers
69 // wfp registers
70 // RESET
70 // RESET
71 void reset_wfp_burst_enable( void );
71 void reset_wfp_burst_enable( void );
72 void reset_wfp_status( void );
72 void reset_wfp_status( void );
73 void reset_wfp_buffer_addresses( void );
73 void reset_wfp_buffer_addresses( void );
74 void reset_waveform_picker_regs( void );
74 void reset_waveform_picker_regs( void );
75 // SET
75 // SET
76 void set_wfp_data_shaping(void);
76 void set_wfp_data_shaping(void);
77 void set_wfp_burst_enable_register( unsigned char mode );
77 void set_wfp_burst_enable_register( unsigned char mode );
78 void set_wfp_delta_snapshot( void );
78 void set_wfp_delta_snapshot( void );
79 void set_wfp_delta_f0_f0_2( void );
79 void set_wfp_delta_f0_f0_2( void );
80 void set_wfp_delta_f1( void );
80 void set_wfp_delta_f1( void );
81 void set_wfp_delta_f2( void );
81 void set_wfp_delta_f2( void );
82
82
83 //*****************
83 //*****************
84 // local parameters
84 // local parameters
85 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
85 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
86
86
87 #endif // WF_HANDLER_H_INCLUDED
87 #endif // WF_HANDLER_H_INCLUDED
@@ -1,810 +1,813
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
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 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #endif
52 #endif
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 #endif
55 #endif
56 #endif
56 #endif
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 #include <drvmgr/drvmgr_confdefs.h>
58 #include <drvmgr/drvmgr_confdefs.h>
59 #endif
59 #endif
60
60
61 #include "fsw_init.h"
61 #include "fsw_init.h"
62 #include "fsw_config.c"
62 #include "fsw_config.c"
63
63
64 void initCache()
64 void initCache()
65 {
65 {
66 // unsigned int cacheControlRegister;
66 // unsigned int cacheControlRegister;
67
67
68 // cacheControlRegister = getCacheControlRegister();
68 // cacheControlRegister = getCacheControlRegister();
69 // printf("(0) cacheControlRegister = %x\n", cacheControlRegister);
69 // printf("(0) cacheControlRegister = %x\n", cacheControlRegister);
70
70
71 enableInstructionCache();
71 enableInstructionCache();
72 enableDataCache();
72 enableDataCache();
73 enableInstructionBurstFetch();
73 enableInstructionBurstFetch();
74
74
75 // cacheControlRegister = getCacheControlRegister();
75 // cacheControlRegister = getCacheControlRegister();
76 // printf("(1) cacheControlRegister = %x\n", cacheControlRegister);
76 // printf("(1) cacheControlRegister = %x\n", cacheControlRegister);
77 }
77 }
78
78
79 rtems_task Init( rtems_task_argument ignored )
79 rtems_task Init( rtems_task_argument ignored )
80 {
80 {
81 /** This is the RTEMS INIT taks, it the first task launched by the system.
81 /** This is the RTEMS INIT taks, it the first task launched by the system.
82 *
82 *
83 * @param unused is the starting argument of the RTEMS task
83 * @param unused is the starting argument of the RTEMS task
84 *
84 *
85 * The INIT task create and run all other RTEMS tasks.
85 * The INIT task create and run all other RTEMS tasks.
86 *
86 *
87 */
87 */
88
88
89 //***********
89 //***********
90 // INIT CACHE
90 // INIT CACHE
91
91
92 unsigned char *vhdlVersion;
92 unsigned char *vhdlVersion;
93
93
94 reset_lfr();
94 reset_lfr();
95
95
96 reset_local_time();
96 reset_local_time();
97
97
98 rtems_cpu_usage_reset();
98 rtems_cpu_usage_reset();
99
99
100 rtems_status_code status;
100 rtems_status_code status;
101 rtems_status_code status_spw;
101 rtems_status_code status_spw;
102 rtems_isr_entry old_isr_handler;
102 rtems_isr_entry old_isr_handler;
103
103
104 // UART settings
104 // UART settings
105 send_console_outputs_on_apbuart_port();
105 send_console_outputs_on_apbuart_port();
106 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
106 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
107 enable_apbuart_transmitter();
107 enable_apbuart_transmitter();
108
108
109 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
109 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
110
110
111
111
112 PRINTF("\n\n\n\n\n")
112 PRINTF("\n\n\n\n\n")
113
113
114 initCache();
114 initCache();
115
115
116 PRINTF("*************************\n")
116 PRINTF("*************************\n")
117 PRINTF("** LFR Flight Software **\n")
117 PRINTF("** LFR Flight Software **\n")
118 PRINTF1("** %d.", SW_VERSION_N1)
118 PRINTF1("** %d.", SW_VERSION_N1)
119 PRINTF1("%d." , SW_VERSION_N2)
119 PRINTF1("%d." , SW_VERSION_N2)
120 PRINTF1("%d." , SW_VERSION_N3)
120 PRINTF1("%d." , SW_VERSION_N3)
121 PRINTF1("%d **\n", SW_VERSION_N4)
121 PRINTF1("%d **\n", SW_VERSION_N4)
122
122
123 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
123 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
124 PRINTF("** VHDL **\n")
124 PRINTF("** VHDL **\n")
125 PRINTF1("** %d.", vhdlVersion[1])
125 PRINTF1("** %d.", vhdlVersion[1])
126 PRINTF1("%d." , vhdlVersion[2])
126 PRINTF1("%d." , vhdlVersion[2])
127 PRINTF1("%d **\n", vhdlVersion[3])
127 PRINTF1("%d **\n", vhdlVersion[3])
128 PRINTF("*************************\n")
128 PRINTF("*************************\n")
129 PRINTF("\n\n")
129 PRINTF("\n\n")
130
130
131 init_parameter_dump();
131 init_parameter_dump();
132 init_local_mode_parameters();
132 init_local_mode_parameters();
133 init_housekeeping_parameters();
133 init_housekeeping_parameters();
134 init_k_coefficients_f0();
134 init_k_coefficients_f0();
135 init_k_coefficients_f1();
135 init_k_coefficients_f1();
136 init_k_coefficients_f2();
136 init_k_coefficients_f2();
137
137
138 // waveform picker initialization
138 // waveform picker initialization
139 WFP_init_rings(); // initialize the waveform rings
139 WFP_init_rings(); // initialize the waveform rings
140 WFP_reset_current_ring_nodes();
140 WFP_reset_current_ring_nodes();
141 reset_waveform_picker_regs();
141 reset_waveform_picker_regs();
142
142
143 // spectral matrices initialization
143 // spectral matrices initialization
144 SM_init_rings(); // initialize spectral matrices rings
144 SM_init_rings(); // initialize spectral matrices rings
145 SM_reset_current_ring_nodes();
145 SM_reset_current_ring_nodes();
146 reset_spectral_matrix_regs();
146 reset_spectral_matrix_regs();
147
147
148 // configure calibration
149 configureCalibration( false ); // true means interleaved mode, false is for normal mode
150
148 updateLFRCurrentMode();
151 updateLFRCurrentMode();
149
152
150 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
153 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
151
154
152 create_names(); // create all names
155 create_names(); // create all names
153
156
154 status = create_message_queues(); // create message queues
157 status = create_message_queues(); // create message queues
155 if (status != RTEMS_SUCCESSFUL)
158 if (status != RTEMS_SUCCESSFUL)
156 {
159 {
157 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
160 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
158 }
161 }
159
162
160 status = create_all_tasks(); // create all tasks
163 status = create_all_tasks(); // create all tasks
161 if (status != RTEMS_SUCCESSFUL)
164 if (status != RTEMS_SUCCESSFUL)
162 {
165 {
163 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
166 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
164 }
167 }
165
168
166 // **************************
169 // **************************
167 // <SPACEWIRE INITIALIZATION>
170 // <SPACEWIRE INITIALIZATION>
168 grspw_timecode_callback = &timecode_irq_handler;
171 grspw_timecode_callback = &timecode_irq_handler;
169
172
170 status_spw = spacewire_open_link(); // (1) open the link
173 status_spw = spacewire_open_link(); // (1) open the link
171 if ( status_spw != RTEMS_SUCCESSFUL )
174 if ( status_spw != RTEMS_SUCCESSFUL )
172 {
175 {
173 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
176 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
174 }
177 }
175
178
176 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
179 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
177 {
180 {
178 status_spw = spacewire_configure_link( fdSPW );
181 status_spw = spacewire_configure_link( fdSPW );
179 if ( status_spw != RTEMS_SUCCESSFUL )
182 if ( status_spw != RTEMS_SUCCESSFUL )
180 {
183 {
181 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
184 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
182 }
185 }
183 }
186 }
184
187
185 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
188 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
186 {
189 {
187 status_spw = spacewire_start_link( fdSPW );
190 status_spw = spacewire_start_link( fdSPW );
188 if ( status_spw != RTEMS_SUCCESSFUL )
191 if ( status_spw != RTEMS_SUCCESSFUL )
189 {
192 {
190 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
193 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
191 }
194 }
192 }
195 }
193 // </SPACEWIRE INITIALIZATION>
196 // </SPACEWIRE INITIALIZATION>
194 // ***************************
197 // ***************************
195
198
196 status = start_all_tasks(); // start all tasks
199 status = start_all_tasks(); // start all tasks
197 if (status != RTEMS_SUCCESSFUL)
200 if (status != RTEMS_SUCCESSFUL)
198 {
201 {
199 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
202 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
200 }
203 }
201
204
202 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
205 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
203 status = start_recv_send_tasks();
206 status = start_recv_send_tasks();
204 if ( status != RTEMS_SUCCESSFUL )
207 if ( status != RTEMS_SUCCESSFUL )
205 {
208 {
206 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
209 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
207 }
210 }
208
211
209 // suspend science tasks, they will be restarted later depending on the mode
212 // suspend science tasks, they will be restarted later depending on the mode
210 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
213 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
211 if (status != RTEMS_SUCCESSFUL)
214 if (status != RTEMS_SUCCESSFUL)
212 {
215 {
213 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
216 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
214 }
217 }
215
218
216 //******************************
219 //******************************
217 // <SPECTRAL MATRICES SIMULATOR>
220 // <SPECTRAL MATRICES SIMULATOR>
218 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
221 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
219 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
222 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
220 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
223 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
221 // </SPECTRAL MATRICES SIMULATOR>
224 // </SPECTRAL MATRICES SIMULATOR>
222 //*******************************
225 //*******************************
223
226
224 // configure IRQ handling for the waveform picker unit
227 // configure IRQ handling for the waveform picker unit
225 status = rtems_interrupt_catch( waveforms_isr,
228 status = rtems_interrupt_catch( waveforms_isr,
226 IRQ_SPARC_WAVEFORM_PICKER,
229 IRQ_SPARC_WAVEFORM_PICKER,
227 &old_isr_handler) ;
230 &old_isr_handler) ;
228 // configure IRQ handling for the spectral matrices unit
231 // configure IRQ handling for the spectral matrices unit
229 status = rtems_interrupt_catch( spectral_matrices_isr,
232 status = rtems_interrupt_catch( spectral_matrices_isr,
230 IRQ_SPARC_SPECTRAL_MATRIX,
233 IRQ_SPARC_SPECTRAL_MATRIX,
231 &old_isr_handler) ;
234 &old_isr_handler) ;
232
235
233 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
236 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
234 if ( status_spw != RTEMS_SUCCESSFUL )
237 if ( status_spw != RTEMS_SUCCESSFUL )
235 {
238 {
236 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
239 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
237 if ( status != RTEMS_SUCCESSFUL ) {
240 if ( status != RTEMS_SUCCESSFUL ) {
238 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
241 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
239 }
242 }
240 }
243 }
241
244
242 BOOT_PRINTF("delete INIT\n")
245 BOOT_PRINTF("delete INIT\n")
243
246
244 // test_TCH();
247 // test_TCH();
245
248
246 status = rtems_task_delete(RTEMS_SELF);
249 status = rtems_task_delete(RTEMS_SELF);
247
250
248 }
251 }
249
252
250 void init_local_mode_parameters( void )
253 void init_local_mode_parameters( void )
251 {
254 {
252 /** This function initialize the param_local global variable with default values.
255 /** This function initialize the param_local global variable with default values.
253 *
256 *
254 */
257 */
255
258
256 unsigned int i;
259 unsigned int i;
257
260
258 // LOCAL PARAMETERS
261 // LOCAL PARAMETERS
259
262
260 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
263 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
261 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
264 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
262 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
265 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
263
266
264 // init sequence counters
267 // init sequence counters
265
268
266 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
269 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
267 {
270 {
268 sequenceCounters_TC_EXE[i] = 0x00;
271 sequenceCounters_TC_EXE[i] = 0x00;
269 }
272 }
270 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
273 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
271 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
274 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
272 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
275 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
273 sequenceCounterParameterDump = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
276 sequenceCounterParameterDump = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
274 }
277 }
275
278
276 void reset_local_time( void )
279 void reset_local_time( void )
277 {
280 {
278 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
281 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
279 }
282 }
280
283
281 void create_names( void ) // create all names for tasks and queues
284 void create_names( void ) // create all names for tasks and queues
282 {
285 {
283 /** This function creates all RTEMS names used in the software for tasks and queues.
286 /** This function creates all RTEMS names used in the software for tasks and queues.
284 *
287 *
285 * @return RTEMS directive status codes:
288 * @return RTEMS directive status codes:
286 * - RTEMS_SUCCESSFUL - successful completion
289 * - RTEMS_SUCCESSFUL - successful completion
287 *
290 *
288 */
291 */
289
292
290 // task names
293 // task names
291 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
294 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
292 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
295 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
293 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
296 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
294 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
297 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
295 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
298 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
296 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
299 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
297 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
300 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
298 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
301 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
299 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
302 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
300 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
303 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
301 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
304 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
302 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
305 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
303 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
306 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
304 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
307 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
305 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
308 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
306 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
309 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
307 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
310 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
308 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
311 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
309 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
312 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
310
313
311 // rate monotonic period names
314 // rate monotonic period names
312 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
315 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
313
316
314 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
317 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
315 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
318 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
316 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
319 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
317 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
320 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
318 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
321 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
319 }
322 }
320
323
321 int create_all_tasks( void ) // create all tasks which run in the software
324 int create_all_tasks( void ) // create all tasks which run in the software
322 {
325 {
323 /** This function creates all RTEMS tasks used in the software.
326 /** This function creates all RTEMS tasks used in the software.
324 *
327 *
325 * @return RTEMS directive status codes:
328 * @return RTEMS directive status codes:
326 * - RTEMS_SUCCESSFUL - task created successfully
329 * - RTEMS_SUCCESSFUL - task created successfully
327 * - RTEMS_INVALID_ADDRESS - id is NULL
330 * - RTEMS_INVALID_ADDRESS - id is NULL
328 * - RTEMS_INVALID_NAME - invalid task name
331 * - RTEMS_INVALID_NAME - invalid task name
329 * - RTEMS_INVALID_PRIORITY - invalid task priority
332 * - RTEMS_INVALID_PRIORITY - invalid task priority
330 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
333 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
331 * - RTEMS_TOO_MANY - too many tasks created
334 * - RTEMS_TOO_MANY - too many tasks created
332 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
335 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
333 * - RTEMS_TOO_MANY - too many global objects
336 * - RTEMS_TOO_MANY - too many global objects
334 *
337 *
335 */
338 */
336
339
337 rtems_status_code status;
340 rtems_status_code status;
338
341
339 //**********
342 //**********
340 // SPACEWIRE
343 // SPACEWIRE
341 // RECV
344 // RECV
342 status = rtems_task_create(
345 status = rtems_task_create(
343 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
346 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
344 RTEMS_DEFAULT_MODES,
347 RTEMS_DEFAULT_MODES,
345 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
348 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
346 );
349 );
347 if (status == RTEMS_SUCCESSFUL) // SEND
350 if (status == RTEMS_SUCCESSFUL) // SEND
348 {
351 {
349 status = rtems_task_create(
352 status = rtems_task_create(
350 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
353 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
351 RTEMS_DEFAULT_MODES,
354 RTEMS_DEFAULT_MODES,
352 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
355 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
353 );
356 );
354 }
357 }
355 if (status == RTEMS_SUCCESSFUL) // WTDG
358 if (status == RTEMS_SUCCESSFUL) // WTDG
356 {
359 {
357 status = rtems_task_create(
360 status = rtems_task_create(
358 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
361 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
359 RTEMS_DEFAULT_MODES,
362 RTEMS_DEFAULT_MODES,
360 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
363 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
361 );
364 );
362 }
365 }
363 if (status == RTEMS_SUCCESSFUL) // ACTN
366 if (status == RTEMS_SUCCESSFUL) // ACTN
364 {
367 {
365 status = rtems_task_create(
368 status = rtems_task_create(
366 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
369 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
367 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
370 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
368 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
371 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
369 );
372 );
370 }
373 }
371 if (status == RTEMS_SUCCESSFUL) // SPIQ
374 if (status == RTEMS_SUCCESSFUL) // SPIQ
372 {
375 {
373 status = rtems_task_create(
376 status = rtems_task_create(
374 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
377 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
375 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
378 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
376 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
379 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
377 );
380 );
378 }
381 }
379
382
380 //******************
383 //******************
381 // SPECTRAL MATRICES
384 // SPECTRAL MATRICES
382 if (status == RTEMS_SUCCESSFUL) // AVF0
385 if (status == RTEMS_SUCCESSFUL) // AVF0
383 {
386 {
384 status = rtems_task_create(
387 status = rtems_task_create(
385 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
388 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
386 RTEMS_DEFAULT_MODES,
389 RTEMS_DEFAULT_MODES,
387 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
390 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
388 );
391 );
389 }
392 }
390 if (status == RTEMS_SUCCESSFUL) // PRC0
393 if (status == RTEMS_SUCCESSFUL) // PRC0
391 {
394 {
392 status = rtems_task_create(
395 status = rtems_task_create(
393 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
396 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
394 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
397 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
395 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
398 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
396 );
399 );
397 }
400 }
398 if (status == RTEMS_SUCCESSFUL) // AVF1
401 if (status == RTEMS_SUCCESSFUL) // AVF1
399 {
402 {
400 status = rtems_task_create(
403 status = rtems_task_create(
401 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
404 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
402 RTEMS_DEFAULT_MODES,
405 RTEMS_DEFAULT_MODES,
403 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
406 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
404 );
407 );
405 }
408 }
406 if (status == RTEMS_SUCCESSFUL) // PRC1
409 if (status == RTEMS_SUCCESSFUL) // PRC1
407 {
410 {
408 status = rtems_task_create(
411 status = rtems_task_create(
409 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
412 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
410 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
413 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
411 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
414 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
412 );
415 );
413 }
416 }
414 if (status == RTEMS_SUCCESSFUL) // AVF2
417 if (status == RTEMS_SUCCESSFUL) // AVF2
415 {
418 {
416 status = rtems_task_create(
419 status = rtems_task_create(
417 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
420 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
418 RTEMS_DEFAULT_MODES,
421 RTEMS_DEFAULT_MODES,
419 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
422 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
420 );
423 );
421 }
424 }
422 if (status == RTEMS_SUCCESSFUL) // PRC2
425 if (status == RTEMS_SUCCESSFUL) // PRC2
423 {
426 {
424 status = rtems_task_create(
427 status = rtems_task_create(
425 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
428 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
426 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
429 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
427 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
430 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
428 );
431 );
429 }
432 }
430
433
431 //****************
434 //****************
432 // WAVEFORM PICKER
435 // WAVEFORM PICKER
433 if (status == RTEMS_SUCCESSFUL) // WFRM
436 if (status == RTEMS_SUCCESSFUL) // WFRM
434 {
437 {
435 status = rtems_task_create(
438 status = rtems_task_create(
436 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
439 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
437 RTEMS_DEFAULT_MODES,
440 RTEMS_DEFAULT_MODES,
438 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
441 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
439 );
442 );
440 }
443 }
441 if (status == RTEMS_SUCCESSFUL) // CWF3
444 if (status == RTEMS_SUCCESSFUL) // CWF3
442 {
445 {
443 status = rtems_task_create(
446 status = rtems_task_create(
444 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
447 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
445 RTEMS_DEFAULT_MODES,
448 RTEMS_DEFAULT_MODES,
446 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
449 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
447 );
450 );
448 }
451 }
449 if (status == RTEMS_SUCCESSFUL) // CWF2
452 if (status == RTEMS_SUCCESSFUL) // CWF2
450 {
453 {
451 status = rtems_task_create(
454 status = rtems_task_create(
452 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
455 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
453 RTEMS_DEFAULT_MODES,
456 RTEMS_DEFAULT_MODES,
454 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
457 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
455 );
458 );
456 }
459 }
457 if (status == RTEMS_SUCCESSFUL) // CWF1
460 if (status == RTEMS_SUCCESSFUL) // CWF1
458 {
461 {
459 status = rtems_task_create(
462 status = rtems_task_create(
460 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
463 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
461 RTEMS_DEFAULT_MODES,
464 RTEMS_DEFAULT_MODES,
462 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
465 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
463 );
466 );
464 }
467 }
465 if (status == RTEMS_SUCCESSFUL) // SWBD
468 if (status == RTEMS_SUCCESSFUL) // SWBD
466 {
469 {
467 status = rtems_task_create(
470 status = rtems_task_create(
468 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
471 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
469 RTEMS_DEFAULT_MODES,
472 RTEMS_DEFAULT_MODES,
470 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
473 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
471 );
474 );
472 }
475 }
473
476
474 //*****
477 //*****
475 // MISC
478 // MISC
476 if (status == RTEMS_SUCCESSFUL) // STAT
479 if (status == RTEMS_SUCCESSFUL) // STAT
477 {
480 {
478 status = rtems_task_create(
481 status = rtems_task_create(
479 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
482 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
480 RTEMS_DEFAULT_MODES,
483 RTEMS_DEFAULT_MODES,
481 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
484 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
482 );
485 );
483 }
486 }
484 if (status == RTEMS_SUCCESSFUL) // DUMB
487 if (status == RTEMS_SUCCESSFUL) // DUMB
485 {
488 {
486 status = rtems_task_create(
489 status = rtems_task_create(
487 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
490 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
488 RTEMS_DEFAULT_MODES,
491 RTEMS_DEFAULT_MODES,
489 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
492 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
490 );
493 );
491 }
494 }
492 if (status == RTEMS_SUCCESSFUL) // HOUS
495 if (status == RTEMS_SUCCESSFUL) // HOUS
493 {
496 {
494 status = rtems_task_create(
497 status = rtems_task_create(
495 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
498 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
496 RTEMS_DEFAULT_MODES,
499 RTEMS_DEFAULT_MODES,
497 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
500 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
498 );
501 );
499 }
502 }
500
503
501 return status;
504 return status;
502 }
505 }
503
506
504 int start_recv_send_tasks( void )
507 int start_recv_send_tasks( void )
505 {
508 {
506 rtems_status_code status;
509 rtems_status_code status;
507
510
508 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
511 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
509 if (status!=RTEMS_SUCCESSFUL) {
512 if (status!=RTEMS_SUCCESSFUL) {
510 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
513 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
511 }
514 }
512
515
513 if (status == RTEMS_SUCCESSFUL) // SEND
516 if (status == RTEMS_SUCCESSFUL) // SEND
514 {
517 {
515 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
518 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
516 if (status!=RTEMS_SUCCESSFUL) {
519 if (status!=RTEMS_SUCCESSFUL) {
517 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
520 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
518 }
521 }
519 }
522 }
520
523
521 return status;
524 return status;
522 }
525 }
523
526
524 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
527 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
525 {
528 {
526 /** This function starts all RTEMS tasks used in the software.
529 /** This function starts all RTEMS tasks used in the software.
527 *
530 *
528 * @return RTEMS directive status codes:
531 * @return RTEMS directive status codes:
529 * - RTEMS_SUCCESSFUL - ask started successfully
532 * - RTEMS_SUCCESSFUL - ask started successfully
530 * - RTEMS_INVALID_ADDRESS - invalid task entry point
533 * - RTEMS_INVALID_ADDRESS - invalid task entry point
531 * - RTEMS_INVALID_ID - invalid task id
534 * - RTEMS_INVALID_ID - invalid task id
532 * - RTEMS_INCORRECT_STATE - task not in the dormant state
535 * - RTEMS_INCORRECT_STATE - task not in the dormant state
533 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
536 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
534 *
537 *
535 */
538 */
536 // starts all the tasks fot eh flight software
539 // starts all the tasks fot eh flight software
537
540
538 rtems_status_code status;
541 rtems_status_code status;
539
542
540 //**********
543 //**********
541 // SPACEWIRE
544 // SPACEWIRE
542 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
545 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
543 if (status!=RTEMS_SUCCESSFUL) {
546 if (status!=RTEMS_SUCCESSFUL) {
544 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
547 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
545 }
548 }
546
549
547 if (status == RTEMS_SUCCESSFUL) // WTDG
550 if (status == RTEMS_SUCCESSFUL) // WTDG
548 {
551 {
549 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
552 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
550 if (status!=RTEMS_SUCCESSFUL) {
553 if (status!=RTEMS_SUCCESSFUL) {
551 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
554 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
552 }
555 }
553 }
556 }
554
557
555 if (status == RTEMS_SUCCESSFUL) // ACTN
558 if (status == RTEMS_SUCCESSFUL) // ACTN
556 {
559 {
557 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
560 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
558 if (status!=RTEMS_SUCCESSFUL) {
561 if (status!=RTEMS_SUCCESSFUL) {
559 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
562 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
560 }
563 }
561 }
564 }
562
565
563 //******************
566 //******************
564 // SPECTRAL MATRICES
567 // SPECTRAL MATRICES
565 if (status == RTEMS_SUCCESSFUL) // AVF0
568 if (status == RTEMS_SUCCESSFUL) // AVF0
566 {
569 {
567 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
570 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
568 if (status!=RTEMS_SUCCESSFUL) {
571 if (status!=RTEMS_SUCCESSFUL) {
569 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
572 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
570 }
573 }
571 }
574 }
572 if (status == RTEMS_SUCCESSFUL) // PRC0
575 if (status == RTEMS_SUCCESSFUL) // PRC0
573 {
576 {
574 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
577 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
575 if (status!=RTEMS_SUCCESSFUL) {
578 if (status!=RTEMS_SUCCESSFUL) {
576 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
579 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
577 }
580 }
578 }
581 }
579 if (status == RTEMS_SUCCESSFUL) // AVF1
582 if (status == RTEMS_SUCCESSFUL) // AVF1
580 {
583 {
581 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
584 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
582 if (status!=RTEMS_SUCCESSFUL) {
585 if (status!=RTEMS_SUCCESSFUL) {
583 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
586 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
584 }
587 }
585 }
588 }
586 if (status == RTEMS_SUCCESSFUL) // PRC1
589 if (status == RTEMS_SUCCESSFUL) // PRC1
587 {
590 {
588 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
591 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
589 if (status!=RTEMS_SUCCESSFUL) {
592 if (status!=RTEMS_SUCCESSFUL) {
590 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
593 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
591 }
594 }
592 }
595 }
593 if (status == RTEMS_SUCCESSFUL) // AVF2
596 if (status == RTEMS_SUCCESSFUL) // AVF2
594 {
597 {
595 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
598 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
596 if (status!=RTEMS_SUCCESSFUL) {
599 if (status!=RTEMS_SUCCESSFUL) {
597 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
600 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
598 }
601 }
599 }
602 }
600 if (status == RTEMS_SUCCESSFUL) // PRC2
603 if (status == RTEMS_SUCCESSFUL) // PRC2
601 {
604 {
602 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
605 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
603 if (status!=RTEMS_SUCCESSFUL) {
606 if (status!=RTEMS_SUCCESSFUL) {
604 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
607 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
605 }
608 }
606 }
609 }
607
610
608 //****************
611 //****************
609 // WAVEFORM PICKER
612 // WAVEFORM PICKER
610 if (status == RTEMS_SUCCESSFUL) // WFRM
613 if (status == RTEMS_SUCCESSFUL) // WFRM
611 {
614 {
612 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
615 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
613 if (status!=RTEMS_SUCCESSFUL) {
616 if (status!=RTEMS_SUCCESSFUL) {
614 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
617 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
615 }
618 }
616 }
619 }
617 if (status == RTEMS_SUCCESSFUL) // CWF3
620 if (status == RTEMS_SUCCESSFUL) // CWF3
618 {
621 {
619 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
622 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
620 if (status!=RTEMS_SUCCESSFUL) {
623 if (status!=RTEMS_SUCCESSFUL) {
621 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
624 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
622 }
625 }
623 }
626 }
624 if (status == RTEMS_SUCCESSFUL) // CWF2
627 if (status == RTEMS_SUCCESSFUL) // CWF2
625 {
628 {
626 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
629 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
627 if (status!=RTEMS_SUCCESSFUL) {
630 if (status!=RTEMS_SUCCESSFUL) {
628 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
631 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
629 }
632 }
630 }
633 }
631 if (status == RTEMS_SUCCESSFUL) // CWF1
634 if (status == RTEMS_SUCCESSFUL) // CWF1
632 {
635 {
633 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
636 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
634 if (status!=RTEMS_SUCCESSFUL) {
637 if (status!=RTEMS_SUCCESSFUL) {
635 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
638 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
636 }
639 }
637 }
640 }
638 if (status == RTEMS_SUCCESSFUL) // SWBD
641 if (status == RTEMS_SUCCESSFUL) // SWBD
639 {
642 {
640 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
643 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
641 if (status!=RTEMS_SUCCESSFUL) {
644 if (status!=RTEMS_SUCCESSFUL) {
642 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
645 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
643 }
646 }
644 }
647 }
645
648
646 //*****
649 //*****
647 // MISC
650 // MISC
648 if (status == RTEMS_SUCCESSFUL) // HOUS
651 if (status == RTEMS_SUCCESSFUL) // HOUS
649 {
652 {
650 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
653 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
651 if (status!=RTEMS_SUCCESSFUL) {
654 if (status!=RTEMS_SUCCESSFUL) {
652 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
655 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
653 }
656 }
654 }
657 }
655 if (status == RTEMS_SUCCESSFUL) // DUMB
658 if (status == RTEMS_SUCCESSFUL) // DUMB
656 {
659 {
657 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
660 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
658 if (status!=RTEMS_SUCCESSFUL) {
661 if (status!=RTEMS_SUCCESSFUL) {
659 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
662 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
660 }
663 }
661 }
664 }
662 if (status == RTEMS_SUCCESSFUL) // STAT
665 if (status == RTEMS_SUCCESSFUL) // STAT
663 {
666 {
664 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
667 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
665 if (status!=RTEMS_SUCCESSFUL) {
668 if (status!=RTEMS_SUCCESSFUL) {
666 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
669 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
667 }
670 }
668 }
671 }
669
672
670 return status;
673 return status;
671 }
674 }
672
675
673 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
676 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
674 {
677 {
675 rtems_status_code status_recv;
678 rtems_status_code status_recv;
676 rtems_status_code status_send;
679 rtems_status_code status_send;
677 rtems_status_code status_q_p0;
680 rtems_status_code status_q_p0;
678 rtems_status_code status_q_p1;
681 rtems_status_code status_q_p1;
679 rtems_status_code status_q_p2;
682 rtems_status_code status_q_p2;
680 rtems_status_code ret;
683 rtems_status_code ret;
681 rtems_id queue_id;
684 rtems_id queue_id;
682
685
683 //****************************************
686 //****************************************
684 // create the queue for handling valid TCs
687 // create the queue for handling valid TCs
685 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
688 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
686 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
689 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
687 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
690 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
688 if ( status_recv != RTEMS_SUCCESSFUL ) {
691 if ( status_recv != RTEMS_SUCCESSFUL ) {
689 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
692 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
690 }
693 }
691
694
692 //************************************************
695 //************************************************
693 // create the queue for handling TM packet sending
696 // create the queue for handling TM packet sending
694 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
697 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
695 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
698 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
696 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
699 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
697 if ( status_send != RTEMS_SUCCESSFUL ) {
700 if ( status_send != RTEMS_SUCCESSFUL ) {
698 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
701 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
699 }
702 }
700
703
701 //*****************************************************************************
704 //*****************************************************************************
702 // create the queue for handling averaged spectral matrices for processing @ f0
705 // create the queue for handling averaged spectral matrices for processing @ f0
703 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
706 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
704 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
707 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
705 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
708 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
706 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
709 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
707 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
710 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
708 }
711 }
709
712
710 //*****************************************************************************
713 //*****************************************************************************
711 // create the queue for handling averaged spectral matrices for processing @ f1
714 // create the queue for handling averaged spectral matrices for processing @ f1
712 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
715 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
713 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
716 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
714 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
717 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
715 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
718 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
716 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
719 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
717 }
720 }
718
721
719 //*****************************************************************************
722 //*****************************************************************************
720 // create the queue for handling averaged spectral matrices for processing @ f2
723 // create the queue for handling averaged spectral matrices for processing @ f2
721 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
724 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
722 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
725 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
723 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
726 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
724 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
727 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
725 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
728 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
726 }
729 }
727
730
728 if ( status_recv != RTEMS_SUCCESSFUL )
731 if ( status_recv != RTEMS_SUCCESSFUL )
729 {
732 {
730 ret = status_recv;
733 ret = status_recv;
731 }
734 }
732 else if( status_send != RTEMS_SUCCESSFUL )
735 else if( status_send != RTEMS_SUCCESSFUL )
733 {
736 {
734 ret = status_send;
737 ret = status_send;
735 }
738 }
736 else if( status_q_p0 != RTEMS_SUCCESSFUL )
739 else if( status_q_p0 != RTEMS_SUCCESSFUL )
737 {
740 {
738 ret = status_q_p0;
741 ret = status_q_p0;
739 }
742 }
740 else if( status_q_p1 != RTEMS_SUCCESSFUL )
743 else if( status_q_p1 != RTEMS_SUCCESSFUL )
741 {
744 {
742 ret = status_q_p1;
745 ret = status_q_p1;
743 }
746 }
744 else
747 else
745 {
748 {
746 ret = status_q_p2;
749 ret = status_q_p2;
747 }
750 }
748
751
749 return ret;
752 return ret;
750 }
753 }
751
754
752 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
755 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
753 {
756 {
754 rtems_status_code status;
757 rtems_status_code status;
755 rtems_name queue_name;
758 rtems_name queue_name;
756
759
757 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
760 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
758
761
759 status = rtems_message_queue_ident( queue_name, 0, queue_id );
762 status = rtems_message_queue_ident( queue_name, 0, queue_id );
760
763
761 return status;
764 return status;
762 }
765 }
763
766
764 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
767 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
765 {
768 {
766 rtems_status_code status;
769 rtems_status_code status;
767 rtems_name queue_name;
770 rtems_name queue_name;
768
771
769 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
772 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
770
773
771 status = rtems_message_queue_ident( queue_name, 0, queue_id );
774 status = rtems_message_queue_ident( queue_name, 0, queue_id );
772
775
773 return status;
776 return status;
774 }
777 }
775
778
776 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
779 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
777 {
780 {
778 rtems_status_code status;
781 rtems_status_code status;
779 rtems_name queue_name;
782 rtems_name queue_name;
780
783
781 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
784 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
782
785
783 status = rtems_message_queue_ident( queue_name, 0, queue_id );
786 status = rtems_message_queue_ident( queue_name, 0, queue_id );
784
787
785 return status;
788 return status;
786 }
789 }
787
790
788 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
791 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
789 {
792 {
790 rtems_status_code status;
793 rtems_status_code status;
791 rtems_name queue_name;
794 rtems_name queue_name;
792
795
793 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
796 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
794
797
795 status = rtems_message_queue_ident( queue_name, 0, queue_id );
798 status = rtems_message_queue_ident( queue_name, 0, queue_id );
796
799
797 return status;
800 return status;
798 }
801 }
799
802
800 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
803 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
801 {
804 {
802 rtems_status_code status;
805 rtems_status_code status;
803 rtems_name queue_name;
806 rtems_name queue_name;
804
807
805 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
808 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
806
809
807 status = rtems_message_queue_ident( queue_name, 0, queue_id );
810 status = rtems_message_queue_ident( queue_name, 0, queue_id );
808
811
809 return status;
812 return status;
810 }
813 }
@@ -1,506 +1,511
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29
29
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 if (status!=RTEMS_SUCCESSFUL)
31 if (status!=RTEMS_SUCCESSFUL)
32 {
32 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
34 }
35
35
36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
37 }
37 }
38
38
39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
40 {
40 {
41 /** This function starts a GPTIMER timer.
41 /** This function starts a GPTIMER timer.
42 *
42 *
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 *
45 *
46 */
46 */
47
47
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 }
53 }
54
54
55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
56 {
56 {
57 /** This function stops a GPTIMER timer.
57 /** This function stops a GPTIMER timer.
58 *
58 *
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 *
61 *
62 */
62 */
63
63
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 }
67 }
68
68
69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
70 {
70 {
71 /** This function sets the clock divider of a GPTIMER timer.
71 /** This function sets the clock divider of a GPTIMER timer.
72 *
72 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
76 *
77 */
77 */
78
78
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
80 }
81
81
82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 {
83 {
84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85
85
86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87
87
88 return 0;
88 return 0;
89 }
89 }
90
90
91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 {
92 {
93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94
94
95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96
96
97 return 0;
97 return 0;
98 }
98 }
99
99
100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 {
101 {
102 /** This function sets the scaler reload register of the apbuart module
102 /** This function sets the scaler reload register of the apbuart module
103 *
103 *
104 * @param regs is the address of the apbuart registers in memory
104 * @param regs is the address of the apbuart registers in memory
105 * @param value is the value that will be stored in the scaler register
105 * @param value is the value that will be stored in the scaler register
106 *
106 *
107 * The value shall be set by the software to get data on the serial interface.
107 * The value shall be set by the software to get data on the serial interface.
108 *
108 *
109 */
109 */
110
110
111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112
112
113 apbuart_regs->scaler = value;
113 apbuart_regs->scaler = value;
114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 }
115 }
116
116
117 //************
117 //************
118 // RTEMS TASKS
118 // RTEMS TASKS
119
119
120 rtems_task stat_task(rtems_task_argument argument)
120 rtems_task stat_task(rtems_task_argument argument)
121 {
121 {
122 int i;
122 int i;
123 int j;
123 int j;
124 i = 0;
124 i = 0;
125 j = 0;
125 j = 0;
126 BOOT_PRINTF("in STAT *** \n")
126 BOOT_PRINTF("in STAT *** \n")
127 while(1){
127 while(1){
128 rtems_task_wake_after(1000);
128 rtems_task_wake_after(1000);
129 PRINTF1("%d\n", j)
129 PRINTF1("%d\n", j)
130 if (i == CPU_USAGE_REPORT_PERIOD) {
130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 // #ifdef PRINT_TASK_STATISTICS
131 // #ifdef PRINT_TASK_STATISTICS
132 // rtems_cpu_usage_report();
132 // rtems_cpu_usage_report();
133 // rtems_cpu_usage_reset();
133 // rtems_cpu_usage_reset();
134 // #endif
134 // #endif
135 i = 0;
135 i = 0;
136 }
136 }
137 else i++;
137 else i++;
138 j++;
138 j++;
139 }
139 }
140 }
140 }
141
141
142 rtems_task hous_task(rtems_task_argument argument)
142 rtems_task hous_task(rtems_task_argument argument)
143 {
143 {
144 rtems_status_code status;
144 rtems_status_code status;
145 rtems_status_code spare_status;
145 rtems_status_code spare_status;
146 rtems_id queue_id;
146 rtems_id queue_id;
147 rtems_rate_monotonic_period_status period_status;
147 rtems_rate_monotonic_period_status period_status;
148
148
149 status = get_message_queue_id_send( &queue_id );
149 status = get_message_queue_id_send( &queue_id );
150 if (status != RTEMS_SUCCESSFUL)
150 if (status != RTEMS_SUCCESSFUL)
151 {
151 {
152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
153 }
153 }
154
154
155 BOOT_PRINTF("in HOUS ***\n")
155 BOOT_PRINTF("in HOUS ***\n")
156
156
157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
159 if( status != RTEMS_SUCCESSFUL ) {
159 if( status != RTEMS_SUCCESSFUL ) {
160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
161 }
161 }
162 }
162 }
163
163
164 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
164 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
165 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
165 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
166 housekeeping_packet.reserved = DEFAULT_RESERVED;
166 housekeeping_packet.reserved = DEFAULT_RESERVED;
167 housekeeping_packet.userApplication = CCSDS_USER_APP;
167 housekeeping_packet.userApplication = CCSDS_USER_APP;
168 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
168 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
169 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
169 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
170 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
170 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
171 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
171 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
172 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
172 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
173 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
173 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
174 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
174 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
175 housekeeping_packet.serviceType = TM_TYPE_HK;
175 housekeeping_packet.serviceType = TM_TYPE_HK;
176 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
176 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
177 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
177 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
178 housekeeping_packet.sid = SID_HK;
178 housekeeping_packet.sid = SID_HK;
179
179
180 status = rtems_rate_monotonic_cancel(HK_id);
180 status = rtems_rate_monotonic_cancel(HK_id);
181 if( status != RTEMS_SUCCESSFUL ) {
181 if( status != RTEMS_SUCCESSFUL ) {
182 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
182 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
183 }
183 }
184 else {
184 else {
185 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
185 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
186 }
186 }
187
187
188 // startup phase
188 // startup phase
189 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
189 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
190 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
190 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
191 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
191 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
192 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
192 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
193 {
193 {
194 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
194 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
195 {
195 {
196 break; // break if LFR is synchronized
196 break; // break if LFR is synchronized
197 }
197 }
198 else
198 else
199 {
199 {
200 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
200 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
201 // sched_yield();
201 // sched_yield();
202 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
202 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
203 }
203 }
204 }
204 }
205 status = rtems_rate_monotonic_cancel(HK_id);
205 status = rtems_rate_monotonic_cancel(HK_id);
206 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
206 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
207
207
208 while(1){ // launch the rate monotonic task
208 while(1){ // launch the rate monotonic task
209 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
209 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
210 if ( status != RTEMS_SUCCESSFUL ) {
210 if ( status != RTEMS_SUCCESSFUL ) {
211 PRINTF1( "in HOUS *** ERR period: %d\n", status);
211 PRINTF1( "in HOUS *** ERR period: %d\n", status);
212 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
212 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
213 }
213 }
214 else {
214 else {
215 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
215 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
216 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
216 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
217 increment_seq_counter( &sequenceCounterHK );
217 increment_seq_counter( &sequenceCounterHK );
218
218
219 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
219 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
220 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
220 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
221 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
221 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
222 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
222 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
223 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
223 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
224 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
224 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
225
225
226 spacewire_update_statistics();
226 spacewire_update_statistics();
227
227
228 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
228 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
229 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
229 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
230 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
230 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
231
231
232 // SEND PACKET
232 // SEND PACKET
233 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
233 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
234 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
234 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
235 if (status != RTEMS_SUCCESSFUL) {
235 if (status != RTEMS_SUCCESSFUL) {
236 PRINTF1("in HOUS *** ERR send: %d\n", status)
236 PRINTF1("in HOUS *** ERR send: %d\n", status)
237 }
237 }
238 }
238 }
239 }
239 }
240
240
241 PRINTF("in HOUS *** deleting task\n")
241 PRINTF("in HOUS *** deleting task\n")
242
242
243 status = rtems_task_delete( RTEMS_SELF ); // should not return
243 status = rtems_task_delete( RTEMS_SELF ); // should not return
244 printf( "rtems_task_delete returned with status of %d.\n", status );
244 printf( "rtems_task_delete returned with status of %d.\n", status );
245 return;
245 return;
246 }
246 }
247
247
248 rtems_task dumb_task( rtems_task_argument unused )
248 rtems_task dumb_task( rtems_task_argument unused )
249 {
249 {
250 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
250 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
251 *
251 *
252 * @param unused is the starting argument of the RTEMS task
252 * @param unused is the starting argument of the RTEMS task
253 *
253 *
254 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
254 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
255 *
255 *
256 */
256 */
257
257
258 unsigned int i;
258 unsigned int i;
259 unsigned int intEventOut;
259 unsigned int intEventOut;
260 unsigned int coarse_time = 0;
260 unsigned int coarse_time = 0;
261 unsigned int fine_time = 0;
261 unsigned int fine_time = 0;
262 rtems_event_set event_out;
262 rtems_event_set event_out;
263
263
264 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
264 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
265 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
265 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
266 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
266 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
267 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
267 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
268 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
268 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
269 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
269 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
270 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
270 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
271 "ready for dump", // RTEMS_EVENT_7
271 "ready for dump", // RTEMS_EVENT_7
272 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
272 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
273 "tick", // RTEMS_EVENT_9
273 "tick", // RTEMS_EVENT_9
274 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
274 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
275 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
275 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
276 };
276 };
277
277
278 BOOT_PRINTF("in DUMB *** \n")
278 BOOT_PRINTF("in DUMB *** \n")
279
279
280 while(1){
280 while(1){
281 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
281 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
282 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
282 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
283 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
283 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
284 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
284 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
285 intEventOut = (unsigned int) event_out;
285 intEventOut = (unsigned int) event_out;
286 for ( i=0; i<32; i++)
286 for ( i=0; i<32; i++)
287 {
287 {
288 if ( ((intEventOut >> i) & 0x0001) != 0)
288 if ( ((intEventOut >> i) & 0x0001) != 0)
289 {
289 {
290 coarse_time = time_management_regs->coarse_time;
290 coarse_time = time_management_regs->coarse_time;
291 fine_time = time_management_regs->fine_time;
291 fine_time = time_management_regs->fine_time;
292 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
292 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
293 if (i==8)
293 if (i==8)
294 {
294 {
295 }
295 }
296 if (i==10)
296 if (i==10)
297 {
297 {
298 }
298 }
299 }
299 }
300 }
300 }
301 }
301 }
302 }
302 }
303
303
304 //*****************************
304 //*****************************
305 // init housekeeping parameters
305 // init housekeeping parameters
306
306
307 void init_housekeeping_parameters( void )
307 void init_housekeeping_parameters( void )
308 {
308 {
309 /** This function initialize the housekeeping_packet global variable with default values.
309 /** This function initialize the housekeeping_packet global variable with default values.
310 *
310 *
311 */
311 */
312
312
313 unsigned int i = 0;
313 unsigned int i = 0;
314 unsigned char *parameters;
314 unsigned char *parameters;
315
315
316 parameters = (unsigned char*) &housekeeping_packet.lfr_status_word;
316 parameters = (unsigned char*) &housekeeping_packet.lfr_status_word;
317 for(i = 0; i< SIZE_HK_PARAMETERS; i++)
317 for(i = 0; i< SIZE_HK_PARAMETERS; i++)
318 {
318 {
319 parameters[i] = 0x00;
319 parameters[i] = 0x00;
320 }
320 }
321 // init status word
321 // init status word
322 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
322 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
323 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
323 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
324 // init software version
324 // init software version
325 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
325 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
326 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
326 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
327 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
327 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
328 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
328 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
329 // init fpga version
329 // init fpga version
330 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
330 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
331 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
331 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
332 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
332 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
333 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
333 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
334 }
334 }
335
335
336 void increment_seq_counter( unsigned short *packetSequenceControl )
336 void increment_seq_counter( unsigned short *packetSequenceControl )
337 {
337 {
338 /** This function increment the sequence counter psased in argument.
338 /** This function increment the sequence counter psased in argument.
339 *
339 *
340 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
340 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
341 *
341 *
342 */
342 */
343
343
344 unsigned short segmentation_grouping_flag;
344 unsigned short segmentation_grouping_flag;
345 unsigned short sequence_cnt;
345 unsigned short sequence_cnt;
346
346
347 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
347 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
348 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
348 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
349
349
350 if ( sequence_cnt < SEQ_CNT_MAX)
350 if ( sequence_cnt < SEQ_CNT_MAX)
351 {
351 {
352 sequence_cnt = sequence_cnt + 1;
352 sequence_cnt = sequence_cnt + 1;
353 }
353 }
354 else
354 else
355 {
355 {
356 sequence_cnt = 0;
356 sequence_cnt = 0;
357 }
357 }
358
358
359 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
359 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
360 }
360 }
361
361
362 void getTime( unsigned char *time)
362 void getTime( unsigned char *time)
363 {
363 {
364 /** This function write the current local time in the time buffer passed in argument.
364 /** This function write the current local time in the time buffer passed in argument.
365 *
365 *
366 */
366 */
367
367
368 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
368 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
369 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
369 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
370 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
370 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
371 time[3] = (unsigned char) (time_management_regs->coarse_time);
371 time[3] = (unsigned char) (time_management_regs->coarse_time);
372 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
372 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
373 time[5] = (unsigned char) (time_management_regs->fine_time);
373 time[5] = (unsigned char) (time_management_regs->fine_time);
374 }
374 }
375
375
376 unsigned long long int getTimeAsUnsignedLongLongInt( )
376 unsigned long long int getTimeAsUnsignedLongLongInt( )
377 {
377 {
378 /** This function write the current local time in the time buffer passed in argument.
378 /** This function write the current local time in the time buffer passed in argument.
379 *
379 *
380 */
380 */
381 unsigned long long int time;
381 unsigned long long int time;
382
382
383 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
383 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
384 + time_management_regs->fine_time;
384 + time_management_regs->fine_time;
385
385
386 return time;
386 return time;
387 }
387 }
388
388
389 void send_dumb_hk( void )
389 void send_dumb_hk( void )
390 {
390 {
391 Packet_TM_LFR_HK_t dummy_hk_packet;
391 Packet_TM_LFR_HK_t dummy_hk_packet;
392 unsigned char *parameters;
392 unsigned char *parameters;
393 unsigned int i;
393 unsigned int i;
394 rtems_id queue_id;
394 rtems_id queue_id;
395
395
396 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
396 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
397 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
397 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
398 dummy_hk_packet.reserved = DEFAULT_RESERVED;
398 dummy_hk_packet.reserved = DEFAULT_RESERVED;
399 dummy_hk_packet.userApplication = CCSDS_USER_APP;
399 dummy_hk_packet.userApplication = CCSDS_USER_APP;
400 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
400 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
401 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
401 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
402 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
402 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
403 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
403 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
404 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
404 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
405 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
405 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
406 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
406 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
407 dummy_hk_packet.serviceType = TM_TYPE_HK;
407 dummy_hk_packet.serviceType = TM_TYPE_HK;
408 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
408 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
409 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
409 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
410 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
410 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
411 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
411 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
412 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
412 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
413 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
413 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
414 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
414 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
415 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
415 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
416 dummy_hk_packet.sid = SID_HK;
416 dummy_hk_packet.sid = SID_HK;
417
417
418 // init status word
418 // init status word
419 dummy_hk_packet.lfr_status_word[0] = 0xff;
419 dummy_hk_packet.lfr_status_word[0] = 0xff;
420 dummy_hk_packet.lfr_status_word[1] = 0xff;
420 dummy_hk_packet.lfr_status_word[1] = 0xff;
421 // init software version
421 // init software version
422 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
422 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
423 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
423 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
424 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
424 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
425 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
425 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
426 // init fpga version
426 // init fpga version
427 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
427 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
428 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
428 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
429 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
429 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
430 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
430 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
431
431
432 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
432 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
433
433
434 for (i=0; i<100; i++)
434 for (i=0; i<100; i++)
435 {
435 {
436 parameters[i] = 0xff;
436 parameters[i] = 0xff;
437 }
437 }
438
438
439 get_message_queue_id_send( &queue_id );
439 get_message_queue_id_send( &queue_id );
440
440
441 rtems_message_queue_send( queue_id, &dummy_hk_packet,
441 rtems_message_queue_send( queue_id, &dummy_hk_packet,
442 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
442 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
443 }
443 }
444
444
445 void get_temperatures( unsigned char *temperatures )
445 void get_temperatures( unsigned char *temperatures )
446 {
446 {
447 unsigned char* temp_scm_ptr;
447 unsigned char* temp_scm_ptr;
448 unsigned char* temp_pcb_ptr;
448 unsigned char* temp_pcb_ptr;
449 unsigned char* temp_fpga_ptr;
449 unsigned char* temp_fpga_ptr;
450
450
451 // SEL1 SEL0
452 // 0 0 => PCB
453 // 0 1 => FPGA
454 // 1 0 => SCM
455
451 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
456 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
452 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
457 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
453 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
458 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
454
459
455 temperatures[0] = temp_scm_ptr[2];
460 temperatures[0] = temp_scm_ptr[2];
456 temperatures[1] = temp_scm_ptr[3];
461 temperatures[1] = temp_scm_ptr[3];
457 temperatures[2] = temp_pcb_ptr[2];
462 temperatures[2] = temp_pcb_ptr[2];
458 temperatures[3] = temp_pcb_ptr[3];
463 temperatures[3] = temp_pcb_ptr[3];
459 temperatures[4] = temp_fpga_ptr[2];
464 temperatures[4] = temp_fpga_ptr[2];
460 temperatures[5] = temp_fpga_ptr[3];
465 temperatures[5] = temp_fpga_ptr[3];
461 }
466 }
462
467
463 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
468 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
464 {
469 {
465 unsigned char* v_ptr;
470 unsigned char* v_ptr;
466 unsigned char* e1_ptr;
471 unsigned char* e1_ptr;
467 unsigned char* e2_ptr;
472 unsigned char* e2_ptr;
468
473
469 v_ptr = (unsigned char *) &waveform_picker_regs->v;
474 v_ptr = (unsigned char *) &waveform_picker_regs->v;
470 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
475 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
471 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
476 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
472
477
473 spacecraft_potential[0] = v_ptr[2];
478 spacecraft_potential[0] = v_ptr[2];
474 spacecraft_potential[1] = v_ptr[3];
479 spacecraft_potential[1] = v_ptr[3];
475 spacecraft_potential[2] = e1_ptr[2];
480 spacecraft_potential[2] = e1_ptr[2];
476 spacecraft_potential[3] = e1_ptr[3];
481 spacecraft_potential[3] = e1_ptr[3];
477 spacecraft_potential[4] = e2_ptr[2];
482 spacecraft_potential[4] = e2_ptr[2];
478 spacecraft_potential[5] = e2_ptr[3];
483 spacecraft_potential[5] = e2_ptr[3];
479 }
484 }
480
485
481 void get_cpu_load( unsigned char *resource_statistics )
486 void get_cpu_load( unsigned char *resource_statistics )
482 {
487 {
483 unsigned char cpu_load;
488 unsigned char cpu_load;
484
489
485 cpu_load = lfr_rtems_cpu_usage_report();
490 cpu_load = lfr_rtems_cpu_usage_report();
486
491
487 // HK_LFR_CPU_LOAD
492 // HK_LFR_CPU_LOAD
488 resource_statistics[0] = cpu_load;
493 resource_statistics[0] = cpu_load;
489
494
490 // HK_LFR_CPU_LOAD_MAX
495 // HK_LFR_CPU_LOAD_MAX
491 if (cpu_load > resource_statistics[1])
496 if (cpu_load > resource_statistics[1])
492 {
497 {
493 resource_statistics[1] = cpu_load;
498 resource_statistics[1] = cpu_load;
494 }
499 }
495
500
496 // CPU_LOAD_AVE
501 // CPU_LOAD_AVE
497 resource_statistics[2] = 0;
502 resource_statistics[2] = 0;
498
503
499 #ifndef PRINT_TASK_STATISTICS
504 #ifndef PRINT_TASK_STATISTICS
500 rtems_cpu_usage_reset();
505 rtems_cpu_usage_reset();
501 #endif
506 #endif
502
507
503 }
508 }
504
509
505
510
506
511
@@ -1,971 +1,1117
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
15
15 //***********
16 //***********
16 // RTEMS TASK
17 // RTEMS TASK
17
18
18 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
19 {
20 {
20 /** 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.
21 *
22 *
22 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
23 *
24 *
24 * 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
25 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
26 *
27 *
27 */
28 */
28
29
29 int result;
30 int result;
30 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
31 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
33 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char time[6];
35 unsigned char time[6];
35 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
36 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
37
38
38 status = get_message_queue_id_recv( &queue_rcv_id );
39 status = get_message_queue_id_recv( &queue_rcv_id );
39 if (status != RTEMS_SUCCESSFUL)
40 if (status != RTEMS_SUCCESSFUL)
40 {
41 {
41 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 }
43 }
43
44
44 status = get_message_queue_id_send( &queue_snd_id );
45 status = get_message_queue_id_send( &queue_snd_id );
45 if (status != RTEMS_SUCCESSFUL)
46 if (status != RTEMS_SUCCESSFUL)
46 {
47 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 }
49 }
49
50
50 result = LFR_SUCCESSFUL;
51 result = LFR_SUCCESSFUL;
51 subtype = 0; // subtype of the current TC packet
52 subtype = 0; // subtype of the current TC packet
52
53
53 BOOT_PRINTF("in ACTN *** \n")
54 BOOT_PRINTF("in ACTN *** \n")
54
55
55 while(1)
56 while(1)
56 {
57 {
57 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 getTime( time ); // set time to the current time
60 getTime( time ); // set time to the current time
60 if (status!=RTEMS_SUCCESSFUL)
61 if (status!=RTEMS_SUCCESSFUL)
61 {
62 {
62 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 }
64 }
64 else
65 else
65 {
66 {
66 subtype = TC.serviceSubType;
67 subtype = TC.serviceSubType;
67 switch(subtype)
68 switch(subtype)
68 {
69 {
69 case TC_SUBTYPE_RESET:
70 case TC_SUBTYPE_RESET:
70 result = action_reset( &TC, queue_snd_id, time );
71 result = action_reset( &TC, queue_snd_id, time );
71 close_action( &TC, result, queue_snd_id );
72 close_action( &TC, result, queue_snd_id );
72 break;
73 break;
73 //
74 //
74 case TC_SUBTYPE_LOAD_COMM:
75 case TC_SUBTYPE_LOAD_COMM:
75 result = action_load_common_par( &TC );
76 result = action_load_common_par( &TC );
76 close_action( &TC, result, queue_snd_id );
77 close_action( &TC, result, queue_snd_id );
77 break;
78 break;
78 //
79 //
79 case TC_SUBTYPE_LOAD_NORM:
80 case TC_SUBTYPE_LOAD_NORM:
80 result = action_load_normal_par( &TC, queue_snd_id, time );
81 result = action_load_normal_par( &TC, queue_snd_id, time );
81 close_action( &TC, result, queue_snd_id );
82 close_action( &TC, result, queue_snd_id );
82 break;
83 break;
83 //
84 //
84 case TC_SUBTYPE_LOAD_BURST:
85 case TC_SUBTYPE_LOAD_BURST:
85 result = action_load_burst_par( &TC, queue_snd_id, time );
86 result = action_load_burst_par( &TC, queue_snd_id, time );
86 close_action( &TC, result, queue_snd_id );
87 close_action( &TC, result, queue_snd_id );
87 break;
88 break;
88 //
89 //
89 case TC_SUBTYPE_LOAD_SBM1:
90 case TC_SUBTYPE_LOAD_SBM1:
90 result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 close_action( &TC, result, queue_snd_id );
92 close_action( &TC, result, queue_snd_id );
92 break;
93 break;
93 //
94 //
94 case TC_SUBTYPE_LOAD_SBM2:
95 case TC_SUBTYPE_LOAD_SBM2:
95 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 close_action( &TC, result, queue_snd_id );
97 close_action( &TC, result, queue_snd_id );
97 break;
98 break;
98 //
99 //
99 case TC_SUBTYPE_DUMP:
100 case TC_SUBTYPE_DUMP:
100 result = action_dump_par( queue_snd_id );
101 result = action_dump_par( queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
102 close_action( &TC, result, queue_snd_id );
102 break;
103 break;
103 //
104 //
104 case TC_SUBTYPE_ENTER:
105 case TC_SUBTYPE_ENTER:
105 result = action_enter_mode( &TC, queue_snd_id );
106 result = action_enter_mode( &TC, queue_snd_id );
106 close_action( &TC, result, queue_snd_id );
107 close_action( &TC, result, queue_snd_id );
107 break;
108 break;
108 //
109 //
109 case TC_SUBTYPE_UPDT_INFO:
110 case TC_SUBTYPE_UPDT_INFO:
110 result = action_update_info( &TC, queue_snd_id );
111 result = action_update_info( &TC, queue_snd_id );
111 close_action( &TC, result, queue_snd_id );
112 close_action( &TC, result, queue_snd_id );
112 break;
113 break;
113 //
114 //
114 case TC_SUBTYPE_EN_CAL:
115 case TC_SUBTYPE_EN_CAL:
115 result = action_enable_calibration( &TC, queue_snd_id, time );
116 result = action_enable_calibration( &TC, queue_snd_id, time );
116 close_action( &TC, result, queue_snd_id );
117 close_action( &TC, result, queue_snd_id );
117 break;
118 break;
118 //
119 //
119 case TC_SUBTYPE_DIS_CAL:
120 case TC_SUBTYPE_DIS_CAL:
120 result = action_disable_calibration( &TC, queue_snd_id, time );
121 result = action_disable_calibration( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
122 close_action( &TC, result, queue_snd_id );
122 break;
123 break;
123 //
124 //
124 case TC_SUBTYPE_UPDT_TIME:
125 case TC_SUBTYPE_UPDT_TIME:
125 result = action_update_time( &TC );
126 result = action_update_time( &TC );
126 close_action( &TC, result, queue_snd_id );
127 close_action( &TC, result, queue_snd_id );
127 break;
128 break;
128 //
129 //
129 default:
130 default:
130 break;
131 break;
131 }
132 }
132 }
133 }
133 }
134 }
134 }
135 }
135
136
136 //***********
137 //***********
137 // TC ACTIONS
138 // TC ACTIONS
138
139
139 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 {
141 {
141 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 *
143 *
143 * @param TC points to the TeleCommand packet that is being processed
144 * @param TC points to the TeleCommand packet that is being processed
144 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 *
146 *
146 */
147 */
147
148
148 printf("this is the end!!!\n");
149 printf("this is the end!!!\n");
149 exit(0);
150 exit(0);
150 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
151 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
151 return LFR_DEFAULT;
152 return LFR_DEFAULT;
152 }
153 }
153
154
154 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
155 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
155 {
156 {
156 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
157 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
157 *
158 *
158 * @param TC points to the TeleCommand packet that is being processed
159 * @param TC points to the TeleCommand packet that is being processed
159 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
160 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
160 *
161 *
161 */
162 */
162
163
163 rtems_status_code status;
164 rtems_status_code status;
164 unsigned char requestedMode;
165 unsigned char requestedMode;
165 unsigned int *transitionCoarseTime_ptr;
166 unsigned int *transitionCoarseTime_ptr;
166 unsigned int transitionCoarseTime;
167 unsigned int transitionCoarseTime;
167 unsigned char * bytePosPtr;
168 unsigned char * bytePosPtr;
168
169
169 bytePosPtr = (unsigned char *) &TC->packetID;
170 bytePosPtr = (unsigned char *) &TC->packetID;
170
171
171 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
172 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
172 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
173 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
173 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
174 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
174
175
175 status = check_mode_value( requestedMode );
176 status = check_mode_value( requestedMode );
176
177
177 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
178 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
178 {
179 {
179 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
180 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
180 }
181 }
181 else // the mode value is consistent, check the transition
182 else // the mode value is consistent, check the transition
182 {
183 {
183 status = check_mode_transition(requestedMode);
184 status = check_mode_transition(requestedMode);
184 if (status != LFR_SUCCESSFUL)
185 if (status != LFR_SUCCESSFUL)
185 {
186 {
186 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
187 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
187 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
188 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
188 }
189 }
189 }
190 }
190
191
191 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
192 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
192 {
193 {
193 status = check_transition_date( transitionCoarseTime );
194 status = check_transition_date( transitionCoarseTime );
194 if (status != LFR_SUCCESSFUL)
195 if (status != LFR_SUCCESSFUL)
195 {
196 {
196 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
197 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
197 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
198 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
198 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
199 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
199 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
200 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
200 }
201 }
201 }
202 }
202
203
203 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
204 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
204 {
205 {
205 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
206 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
206 status = enter_mode( requestedMode, transitionCoarseTime );
207 status = enter_mode( requestedMode, transitionCoarseTime );
207 }
208 }
208
209
209 return status;
210 return status;
210 }
211 }
211
212
212 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
213 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
213 {
214 {
214 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
215 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
215 *
216 *
216 * @param TC points to the TeleCommand packet that is being processed
217 * @param TC points to the TeleCommand packet that is being processed
217 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
218 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
218 *
219 *
219 * @return LFR directive status code:
220 * @return LFR directive status code:
220 * - LFR_DEFAULT
221 * - LFR_DEFAULT
221 * - LFR_SUCCESSFUL
222 * - LFR_SUCCESSFUL
222 *
223 *
223 */
224 */
224
225
225 unsigned int val;
226 unsigned int val;
226 int result;
227 int result;
227 unsigned int status;
228 unsigned int status;
228 unsigned char mode;
229 unsigned char mode;
229 unsigned char * bytePosPtr;
230 unsigned char * bytePosPtr;
230
231
231 bytePosPtr = (unsigned char *) &TC->packetID;
232 bytePosPtr = (unsigned char *) &TC->packetID;
232
233
233 // check LFR mode
234 // check LFR mode
234 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
235 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
235 status = check_update_info_hk_lfr_mode( mode );
236 status = check_update_info_hk_lfr_mode( mode );
236 if (status == LFR_SUCCESSFUL) // check TDS mode
237 if (status == LFR_SUCCESSFUL) // check TDS mode
237 {
238 {
238 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
239 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
239 status = check_update_info_hk_tds_mode( mode );
240 status = check_update_info_hk_tds_mode( mode );
240 }
241 }
241 if (status == LFR_SUCCESSFUL) // check THR mode
242 if (status == LFR_SUCCESSFUL) // check THR mode
242 {
243 {
243 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
244 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
244 status = check_update_info_hk_thr_mode( mode );
245 status = check_update_info_hk_thr_mode( mode );
245 }
246 }
246 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
247 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
247 {
248 {
248 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
249 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
249 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
250 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
250 val++;
251 val++;
251 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
252 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
252 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
253 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
253 }
254 }
254
255
255 result = status;
256 result = status;
256
257
257 return result;
258 return result;
258 }
259 }
259
260
260 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
261 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
261 {
262 {
262 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
263 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
263 *
264 *
264 * @param TC points to the TeleCommand packet that is being processed
265 * @param TC points to the TeleCommand packet that is being processed
265 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
266 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
266 *
267 *
267 */
268 */
268
269
269 int result;
270 int result;
270 unsigned char lfrMode;
271
271
272 result = LFR_DEFAULT;
272 result = LFR_DEFAULT;
273 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
274
273
275 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
274 startCalibration();
276 result = LFR_DEFAULT;
275
276 result = LFR_SUCCESSFUL;
277
277
278 return result;
278 return result;
279 }
279 }
280
280
281 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
281 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
282 {
282 {
283 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
283 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
284 *
284 *
285 * @param TC points to the TeleCommand packet that is being processed
285 * @param TC points to the TeleCommand packet that is being processed
286 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
286 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
287 *
287 *
288 */
288 */
289
289
290 int result;
290 int result;
291 unsigned char lfrMode;
292
291
293 result = LFR_DEFAULT;
292 result = LFR_DEFAULT;
294 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
295
293
296 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
294 stopCalibration();
297 result = LFR_DEFAULT;
295
296 result = LFR_SUCCESSFUL;
298
297
299 return result;
298 return result;
300 }
299 }
301
300
302 int action_update_time(ccsdsTelecommandPacket_t *TC)
301 int action_update_time(ccsdsTelecommandPacket_t *TC)
303 {
302 {
304 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
303 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
305 *
304 *
306 * @param TC points to the TeleCommand packet that is being processed
305 * @param TC points to the TeleCommand packet that is being processed
307 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
306 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
308 *
307 *
309 * @return LFR_SUCCESSFUL
308 * @return LFR_SUCCESSFUL
310 *
309 *
311 */
310 */
312
311
313 unsigned int val;
312 unsigned int val;
314
313
315 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
314 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
316 + (TC->dataAndCRC[1] << 16)
315 + (TC->dataAndCRC[1] << 16)
317 + (TC->dataAndCRC[2] << 8)
316 + (TC->dataAndCRC[2] << 8)
318 + TC->dataAndCRC[3];
317 + TC->dataAndCRC[3];
319
318
320 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
319 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
321 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
320 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
322 val++;
321 val++;
323 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
322 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
324 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
323 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
325
324
326 return LFR_SUCCESSFUL;
325 return LFR_SUCCESSFUL;
327 }
326 }
328
327
329 //*******************
328 //*******************
330 // ENTERING THE MODES
329 // ENTERING THE MODES
331 int check_mode_value( unsigned char requestedMode )
330 int check_mode_value( unsigned char requestedMode )
332 {
331 {
333 int status;
332 int status;
334
333
335 if ( (requestedMode != LFR_MODE_STANDBY)
334 if ( (requestedMode != LFR_MODE_STANDBY)
336 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
335 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
337 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
336 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
338 {
337 {
339 status = LFR_DEFAULT;
338 status = LFR_DEFAULT;
340 }
339 }
341 else
340 else
342 {
341 {
343 status = LFR_SUCCESSFUL;
342 status = LFR_SUCCESSFUL;
344 }
343 }
345
344
346 return status;
345 return status;
347 }
346 }
348
347
349 int check_mode_transition( unsigned char requestedMode )
348 int check_mode_transition( unsigned char requestedMode )
350 {
349 {
351 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
350 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
352 *
351 *
353 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
352 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
354 *
353 *
355 * @return LFR directive status codes:
354 * @return LFR directive status codes:
356 * - LFR_SUCCESSFUL - the transition is authorized
355 * - LFR_SUCCESSFUL - the transition is authorized
357 * - LFR_DEFAULT - the transition is not authorized
356 * - LFR_DEFAULT - the transition is not authorized
358 *
357 *
359 */
358 */
360
359
361 int status;
360 int status;
362
361
363 switch (requestedMode)
362 switch (requestedMode)
364 {
363 {
365 case LFR_MODE_STANDBY:
364 case LFR_MODE_STANDBY:
366 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
365 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
367 status = LFR_DEFAULT;
366 status = LFR_DEFAULT;
368 }
367 }
369 else
368 else
370 {
369 {
371 status = LFR_SUCCESSFUL;
370 status = LFR_SUCCESSFUL;
372 }
371 }
373 break;
372 break;
374 case LFR_MODE_NORMAL:
373 case LFR_MODE_NORMAL:
375 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
374 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
376 status = LFR_DEFAULT;
375 status = LFR_DEFAULT;
377 }
376 }
378 else {
377 else {
379 status = LFR_SUCCESSFUL;
378 status = LFR_SUCCESSFUL;
380 }
379 }
381 break;
380 break;
382 case LFR_MODE_BURST:
381 case LFR_MODE_BURST:
383 if ( lfrCurrentMode == LFR_MODE_BURST ) {
382 if ( lfrCurrentMode == LFR_MODE_BURST ) {
384 status = LFR_DEFAULT;
383 status = LFR_DEFAULT;
385 }
384 }
386 else {
385 else {
387 status = LFR_SUCCESSFUL;
386 status = LFR_SUCCESSFUL;
388 }
387 }
389 break;
388 break;
390 case LFR_MODE_SBM1:
389 case LFR_MODE_SBM1:
391 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
390 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
392 status = LFR_DEFAULT;
391 status = LFR_DEFAULT;
393 }
392 }
394 else {
393 else {
395 status = LFR_SUCCESSFUL;
394 status = LFR_SUCCESSFUL;
396 }
395 }
397 break;
396 break;
398 case LFR_MODE_SBM2:
397 case LFR_MODE_SBM2:
399 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
398 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
400 status = LFR_DEFAULT;
399 status = LFR_DEFAULT;
401 }
400 }
402 else {
401 else {
403 status = LFR_SUCCESSFUL;
402 status = LFR_SUCCESSFUL;
404 }
403 }
405 break;
404 break;
406 default:
405 default:
407 status = LFR_DEFAULT;
406 status = LFR_DEFAULT;
408 break;
407 break;
409 }
408 }
410
409
411 return status;
410 return status;
412 }
411 }
413
412
414 int check_transition_date( unsigned int transitionCoarseTime )
413 int check_transition_date( unsigned int transitionCoarseTime )
415 {
414 {
416 int status;
415 int status;
417 unsigned int localCoarseTime;
416 unsigned int localCoarseTime;
418 unsigned int deltaCoarseTime;
417 unsigned int deltaCoarseTime;
419
418
420 status = LFR_SUCCESSFUL;
419 status = LFR_SUCCESSFUL;
421
420
422 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
421 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
423 {
422 {
424 status = LFR_SUCCESSFUL;
423 status = LFR_SUCCESSFUL;
425 }
424 }
426 else
425 else
427 {
426 {
428 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
427 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
429
428
430 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
429 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
431 {
430 {
432 status = LFR_DEFAULT;
431 status = LFR_DEFAULT;
433 PRINTF2("ERR *** in check_transition_date *** transition = %x, local = %x\n", transitionCoarseTime, localCoarseTime)
432 PRINTF2("ERR *** in check_transition_date *** transition = %x, local = %x\n", transitionCoarseTime, localCoarseTime)
434 }
433 }
435
434
436 if (status == LFR_SUCCESSFUL)
435 if (status == LFR_SUCCESSFUL)
437 {
436 {
438 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
437 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
439 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
438 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
440 {
439 {
441 status = LFR_DEFAULT;
440 status = LFR_DEFAULT;
442 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
441 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
443 }
442 }
444 }
443 }
445 }
444 }
446
445
447 return status;
446 return status;
448 }
447 }
449
448
450 int stop_current_mode( void )
449 int stop_current_mode( void )
451 {
450 {
452 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
451 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
453 *
452 *
454 * @return RTEMS directive status codes:
453 * @return RTEMS directive status codes:
455 * - RTEMS_SUCCESSFUL - task restarted successfully
454 * - RTEMS_SUCCESSFUL - task restarted successfully
456 * - RTEMS_INVALID_ID - task id invalid
455 * - RTEMS_INVALID_ID - task id invalid
457 * - RTEMS_ALREADY_SUSPENDED - task already suspended
456 * - RTEMS_ALREADY_SUSPENDED - task already suspended
458 *
457 *
459 */
458 */
460
459
461 rtems_status_code status;
460 rtems_status_code status;
462
461
463 status = RTEMS_SUCCESSFUL;
462 status = RTEMS_SUCCESSFUL;
464
463
465 // (1) mask interruptions
464 // (1) mask interruptions
466 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
465 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
467 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
466 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
468
467
469 // (2) reset waveform picker registers
468 // (2) reset waveform picker registers
470 reset_wfp_burst_enable(); // reset burst and enable bits
469 reset_wfp_burst_enable(); // reset burst and enable bits
471 reset_wfp_status(); // reset all the status bits
470 reset_wfp_status(); // reset all the status bits
472
471
473 // (3) reset spectral matrices registers
472 // (3) reset spectral matrices registers
474 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
473 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
475 reset_sm_status();
474 reset_sm_status();
476
475
477 // reset lfr VHDL module
476 // reset lfr VHDL module
478 reset_lfr();
477 reset_lfr();
479
478
480 reset_extractSWF(); // reset the extractSWF flag to false
479 reset_extractSWF(); // reset the extractSWF flag to false
481
480
482 // (4) clear interruptions
481 // (4) clear interruptions
483 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
482 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
484 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
483 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
485
484
486 // <Spectral Matrices simulator>
485 // <Spectral Matrices simulator>
487 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
486 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
488 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
487 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
489 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
488 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
490 // </Spectral Matrices simulator>
489 // </Spectral Matrices simulator>
491
490
492 // suspend several tasks
491 // suspend several tasks
493 if (lfrCurrentMode != LFR_MODE_STANDBY) {
492 if (lfrCurrentMode != LFR_MODE_STANDBY) {
494 status = suspend_science_tasks();
493 status = suspend_science_tasks();
495 }
494 }
496
495
497 if (status != RTEMS_SUCCESSFUL)
496 if (status != RTEMS_SUCCESSFUL)
498 {
497 {
499 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
498 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
500 }
499 }
501
500
502 return status;
501 return status;
503 }
502 }
504
503
505 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
504 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
506 {
505 {
507 /** This function is launched after a mode transition validation.
506 /** This function is launched after a mode transition validation.
508 *
507 *
509 * @param mode is the mode in which LFR will be put.
508 * @param mode is the mode in which LFR will be put.
510 *
509 *
511 * @return RTEMS directive status codes:
510 * @return RTEMS directive status codes:
512 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
511 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
513 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
512 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
514 *
513 *
515 */
514 */
516
515
517 rtems_status_code status;
516 rtems_status_code status;
518
517
519 //**********************
518 //**********************
520 // STOP THE CURRENT MODE
519 // STOP THE CURRENT MODE
521 status = stop_current_mode();
520 status = stop_current_mode();
522 if (status != RTEMS_SUCCESSFUL)
521 if (status != RTEMS_SUCCESSFUL)
523 {
522 {
524 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
523 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
525 }
524 }
526
525
527 //*************************
526 //*************************
528 // ENTER THE REQUESTED MODE
527 // ENTER THE REQUESTED MODE
529 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
528 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
530 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
529 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
531 {
530 {
532 #ifdef PRINT_TASK_STATISTICS
531 #ifdef PRINT_TASK_STATISTICS
533 rtems_cpu_usage_reset();
532 rtems_cpu_usage_reset();
534 maxCount = 0;
533 maxCount = 0;
535 #endif
534 #endif
536 status = restart_science_tasks( mode );
535 status = restart_science_tasks( mode );
537 launch_spectral_matrix( );
536 launch_spectral_matrix( );
538 launch_waveform_picker( mode, transitionCoarseTime );
537 launch_waveform_picker( mode, transitionCoarseTime );
539 // launch_spectral_matrix_simu( );
538 // launch_spectral_matrix_simu( );
540 }
539 }
541 else if ( mode == LFR_MODE_STANDBY )
540 else if ( mode == LFR_MODE_STANDBY )
542 {
541 {
543 #ifdef PRINT_TASK_STATISTICS
542 #ifdef PRINT_TASK_STATISTICS
544 rtems_cpu_usage_report();
543 rtems_cpu_usage_report();
545 #endif
544 #endif
546
545
547 #ifdef PRINT_STACK_REPORT
546 #ifdef PRINT_STACK_REPORT
548 PRINTF("stack report selected\n")
547 PRINTF("stack report selected\n")
549 rtems_stack_checker_report_usage();
548 rtems_stack_checker_report_usage();
550 #endif
549 #endif
551 PRINTF1("maxCount = %d\n", maxCount)
550 PRINTF1("maxCount = %d\n", maxCount)
552 }
551 }
553 else
552 else
554 {
553 {
555 status = RTEMS_UNSATISFIED;
554 status = RTEMS_UNSATISFIED;
556 }
555 }
557
556
558 if (status != RTEMS_SUCCESSFUL)
557 if (status != RTEMS_SUCCESSFUL)
559 {
558 {
560 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
559 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
561 status = RTEMS_UNSATISFIED;
560 status = RTEMS_UNSATISFIED;
562 }
561 }
563
562
564 return status;
563 return status;
565 }
564 }
566
565
567 int restart_science_tasks(unsigned char lfrRequestedMode )
566 int restart_science_tasks(unsigned char lfrRequestedMode )
568 {
567 {
569 /** This function is used to restart all science tasks.
568 /** This function is used to restart all science tasks.
570 *
569 *
571 * @return RTEMS directive status codes:
570 * @return RTEMS directive status codes:
572 * - RTEMS_SUCCESSFUL - task restarted successfully
571 * - RTEMS_SUCCESSFUL - task restarted successfully
573 * - RTEMS_INVALID_ID - task id invalid
572 * - RTEMS_INVALID_ID - task id invalid
574 * - RTEMS_INCORRECT_STATE - task never started
573 * - RTEMS_INCORRECT_STATE - task never started
575 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
574 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
576 *
575 *
577 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
576 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
578 *
577 *
579 */
578 */
580
579
581 rtems_status_code status[10];
580 rtems_status_code status[10];
582 rtems_status_code ret;
581 rtems_status_code ret;
583
582
584 ret = RTEMS_SUCCESSFUL;
583 ret = RTEMS_SUCCESSFUL;
585
584
586 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
585 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
587 if (status[0] != RTEMS_SUCCESSFUL)
586 if (status[0] != RTEMS_SUCCESSFUL)
588 {
587 {
589 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
588 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
590 }
589 }
591
590
592 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
591 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
593 if (status[1] != RTEMS_SUCCESSFUL)
592 if (status[1] != RTEMS_SUCCESSFUL)
594 {
593 {
595 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
594 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
596 }
595 }
597
596
598 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
597 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
599 if (status[2] != RTEMS_SUCCESSFUL)
598 if (status[2] != RTEMS_SUCCESSFUL)
600 {
599 {
601 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
600 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
602 }
601 }
603
602
604 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
603 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
605 if (status[3] != RTEMS_SUCCESSFUL)
604 if (status[3] != RTEMS_SUCCESSFUL)
606 {
605 {
607 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
606 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
608 }
607 }
609
608
610 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
609 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
611 if (status[4] != RTEMS_SUCCESSFUL)
610 if (status[4] != RTEMS_SUCCESSFUL)
612 {
611 {
613 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
612 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
614 }
613 }
615
614
616 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
615 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
617 if (status[5] != RTEMS_SUCCESSFUL)
616 if (status[5] != RTEMS_SUCCESSFUL)
618 {
617 {
619 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
618 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
620 }
619 }
621
620
622 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
621 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
623 if (status[6] != RTEMS_SUCCESSFUL)
622 if (status[6] != RTEMS_SUCCESSFUL)
624 {
623 {
625 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
624 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
626 }
625 }
627
626
628 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
627 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
629 if (status[7] != RTEMS_SUCCESSFUL)
628 if (status[7] != RTEMS_SUCCESSFUL)
630 {
629 {
631 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
630 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
632 }
631 }
633
632
634 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
633 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
635 if (status[8] != RTEMS_SUCCESSFUL)
634 if (status[8] != RTEMS_SUCCESSFUL)
636 {
635 {
637 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
636 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
638 }
637 }
639
638
640 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
639 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
641 if (status[9] != RTEMS_SUCCESSFUL)
640 if (status[9] != RTEMS_SUCCESSFUL)
642 {
641 {
643 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
642 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
644 }
643 }
645
644
646 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
645 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
647 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
646 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
648 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
647 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
649 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
648 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
650 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
649 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
651 {
650 {
652 ret = RTEMS_UNSATISFIED;
651 ret = RTEMS_UNSATISFIED;
653 }
652 }
654
653
655 return ret;
654 return ret;
656 }
655 }
657
656
658 int suspend_science_tasks()
657 int suspend_science_tasks()
659 {
658 {
660 /** This function suspends the science tasks.
659 /** This function suspends the science tasks.
661 *
660 *
662 * @return RTEMS directive status codes:
661 * @return RTEMS directive status codes:
663 * - RTEMS_SUCCESSFUL - task restarted successfully
662 * - RTEMS_SUCCESSFUL - task restarted successfully
664 * - RTEMS_INVALID_ID - task id invalid
663 * - RTEMS_INVALID_ID - task id invalid
665 * - RTEMS_ALREADY_SUSPENDED - task already suspended
664 * - RTEMS_ALREADY_SUSPENDED - task already suspended
666 *
665 *
667 */
666 */
668
667
669 rtems_status_code status;
668 rtems_status_code status;
670
669
671 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
670 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
672 if (status != RTEMS_SUCCESSFUL)
671 if (status != RTEMS_SUCCESSFUL)
673 {
672 {
674 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
673 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
675 }
674 }
676 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
675 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
677 {
676 {
678 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
677 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
679 if (status != RTEMS_SUCCESSFUL)
678 if (status != RTEMS_SUCCESSFUL)
680 {
679 {
681 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
680 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
682 }
681 }
683 }
682 }
684 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
683 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
685 {
684 {
686 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
685 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
687 if (status != RTEMS_SUCCESSFUL)
686 if (status != RTEMS_SUCCESSFUL)
688 {
687 {
689 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
688 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
690 }
689 }
691 }
690 }
692 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
691 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
693 {
692 {
694 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
693 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
695 if (status != RTEMS_SUCCESSFUL)
694 if (status != RTEMS_SUCCESSFUL)
696 {
695 {
697 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
696 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
698 }
697 }
699 }
698 }
700 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
699 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
701 {
700 {
702 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
701 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
703 if (status != RTEMS_SUCCESSFUL)
702 if (status != RTEMS_SUCCESSFUL)
704 {
703 {
705 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
704 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
706 }
705 }
707 }
706 }
708 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
707 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
709 {
708 {
710 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
709 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
711 if (status != RTEMS_SUCCESSFUL)
710 if (status != RTEMS_SUCCESSFUL)
712 {
711 {
713 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
712 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
714 }
713 }
715 }
714 }
716 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
715 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
717 {
716 {
718 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
717 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
719 if (status != RTEMS_SUCCESSFUL)
718 if (status != RTEMS_SUCCESSFUL)
720 {
719 {
721 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
720 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
722 }
721 }
723 }
722 }
724 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
723 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
725 {
724 {
726 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
725 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
727 if (status != RTEMS_SUCCESSFUL)
726 if (status != RTEMS_SUCCESSFUL)
728 {
727 {
729 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
728 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
730 }
729 }
731 }
730 }
732 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
731 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
733 {
732 {
734 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
733 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
735 if (status != RTEMS_SUCCESSFUL)
734 if (status != RTEMS_SUCCESSFUL)
736 {
735 {
737 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
736 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
738 }
737 }
739 }
738 }
740 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
739 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
741 {
740 {
742 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
741 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
743 if (status != RTEMS_SUCCESSFUL)
742 if (status != RTEMS_SUCCESSFUL)
744 {
743 {
745 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
744 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
746 }
745 }
747 }
746 }
748
747
749 return status;
748 return status;
750 }
749 }
751
750
752 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
751 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
753 {
752 {
754 WFP_reset_current_ring_nodes();
753 WFP_reset_current_ring_nodes();
755
754
756 reset_waveform_picker_regs();
755 reset_waveform_picker_regs();
757
756
758 set_wfp_burst_enable_register( mode );
757 set_wfp_burst_enable_register( mode );
759
758
760 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
759 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
761 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
760 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
762
761
763 if (transitionCoarseTime == 0)
762 if (transitionCoarseTime == 0)
764 {
763 {
765 waveform_picker_regs->start_date = time_management_regs->coarse_time;
764 waveform_picker_regs->start_date = time_management_regs->coarse_time;
766 }
765 }
767 else
766 else
768 {
767 {
769 waveform_picker_regs->start_date = transitionCoarseTime;
768 waveform_picker_regs->start_date = transitionCoarseTime;
770 }
769 }
771
770
772 PRINTF1("commutation coarse time = %x\n", transitionCoarseTime)
771 PRINTF1("commutation coarse time = %x\n", transitionCoarseTime)
773 }
772 }
774
773
775 void launch_spectral_matrix( void )
774 void launch_spectral_matrix( void )
776 {
775 {
777 SM_reset_current_ring_nodes();
776 SM_reset_current_ring_nodes();
778
777
779 reset_spectral_matrix_regs();
778 reset_spectral_matrix_regs();
780
779
781 reset_nb_sm();
780 reset_nb_sm();
782
781
783 set_sm_irq_onNewMatrix( 1 );
782 set_sm_irq_onNewMatrix( 1 );
784
783
785 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
784 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
786 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
785 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
787
786
788 }
787 }
789
788
790 void launch_spectral_matrix_simu( void )
789 void launch_spectral_matrix_simu( void )
791 {
790 {
792 SM_reset_current_ring_nodes();
791 SM_reset_current_ring_nodes();
793 reset_spectral_matrix_regs();
792 reset_spectral_matrix_regs();
794 reset_nb_sm();
793 reset_nb_sm();
795
794
796 // Spectral Matrices simulator
795 // Spectral Matrices simulator
797 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
796 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
798 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
797 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
799 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
798 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
800 }
799 }
801
800
802 void set_sm_irq_onNewMatrix( unsigned char value )
801 void set_sm_irq_onNewMatrix( unsigned char value )
803 {
802 {
804 if (value == 1)
803 if (value == 1)
805 {
804 {
806 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
805 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
807 }
806 }
808 else
807 else
809 {
808 {
810 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
809 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
811 }
810 }
812 }
811 }
813
812
814 void set_sm_irq_onError( unsigned char value )
813 void set_sm_irq_onError( unsigned char value )
815 {
814 {
816 if (value == 1)
815 if (value == 1)
817 {
816 {
818 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
817 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
819 }
818 }
820 else
819 else
821 {
820 {
822 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
821 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
823 }
822 }
824 }
823 }
825
824
825 //*****************************
826 // CONFIGURE CALIBRATION SIGNAL
827 void setCalibrationPrescaler( unsigned int prescaler )
828 {
829 // prescaling of the master clock (25 MHz)
830 // master clock is divided by 2^prescaler
831 time_management_regs->calPrescaler = prescaler;
832 }
833
834 void setCalibrationDivisor( unsigned int divisionFactor )
835 {
836 // division of the prescaled clock by the division factor
837 time_management_regs->calDivisor = divisionFactor;
838 }
839
840 void setCalibrationData( void ){
841 unsigned int k;
842 unsigned short data;
843 float val;
844 float f0;
845 float f1;
846 float fs;
847 float Ts;
848 float scaleFactor;
849
850 f0 = 625;
851 f1 = 10000;
852 fs = 160256.410;
853 Ts = 1. / fs;
854 scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV
855
856 time_management_regs->calDataPtr = 0x00;
857
858 // build the signal for the SCM calibration
859 for (k=0; k<256; k++)
860 {
861 val = sin( 2 * pi * f0 * k * Ts )
862 + sin( 2 * pi * f1 * k * Ts );
863 data = (unsigned short) ((val * scaleFactor) + 2048);
864 time_management_regs->calData = data & 0xfff;
865 }
866 }
867
868 void setCalibrationDataInterleaved( void ){
869 unsigned int k;
870 float val;
871 float f0;
872 float f1;
873 float fs;
874 float Ts;
875 unsigned short data[384];
876 unsigned char *dataPtr;
877
878 f0 = 625;
879 f1 = 10000;
880 fs = 240384.615;
881 Ts = 1. / fs;
882
883 time_management_regs->calDataPtr = 0x00;
884
885 // build the signal for the SCM calibration
886 for (k=0; k<384; k++)
887 {
888 val = sin( 2 * pi * f0 * k * Ts )
889 + sin( 2 * pi * f1 * k * Ts );
890 data[k] = (unsigned short) (val * 512 + 2048);
891 }
892
893 // write the signal in interleaved mode
894 for (k=0; k<128; k++)
895 {
896 dataPtr = (unsigned char*) &data[k*3 + 2];
897 time_management_regs->calData = (data[k*3] & 0xfff)
898 + ( (dataPtr[0] & 0x3f) << 12);
899 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
900 + ( (dataPtr[1] & 0x3f) << 12);
901 }
902 }
903
904 void setCalibrationReload( bool state)
905 {
906 if (state == true)
907 {
908 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
909 }
910 else
911 {
912 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
913 }
914 }
915
916 void setCalibrationEnable( bool state )
917 {
918 // this bit drives the multiplexer
919 if (state == true)
920 {
921 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
922 }
923 else
924 {
925 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
926 }
927 }
928
929 void setCalibrationInterleaved( bool state )
930 {
931 // this bit drives the multiplexer
932 if (state == true)
933 {
934 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
935 }
936 else
937 {
938 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
939 }
940 }
941
942 void startCalibration( void )
943 {
944 setCalibrationEnable( true );
945 setCalibrationReload( false );
946 }
947
948 void stopCalibration( void )
949 {
950 setCalibrationEnable( false );
951 setCalibrationReload( true );
952 }
953
954 void configureCalibration( bool interleaved )
955 {
956 stopCalibration();
957 if ( interleaved == true )
958 {
959 setCalibrationInterleaved( true );
960 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
961 setCalibrationDivisor( 26 ); // => 240 384
962 setCalibrationDataInterleaved();
963 }
964 else
965 {
966 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
967 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
968 setCalibrationData();
969 }
970 }
971
826 //****************
972 //****************
827 // CLOSING ACTIONS
973 // CLOSING ACTIONS
828 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
974 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
829 {
975 {
830 /** This function is used to update the HK packets statistics after a successful TC execution.
976 /** This function is used to update the HK packets statistics after a successful TC execution.
831 *
977 *
832 * @param TC points to the TC being processed
978 * @param TC points to the TC being processed
833 * @param time is the time used to date the TC execution
979 * @param time is the time used to date the TC execution
834 *
980 *
835 */
981 */
836
982
837 unsigned int val;
983 unsigned int val;
838
984
839 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
985 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
840 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
986 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
841 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
987 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
842 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
988 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
843 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
989 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
844 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
990 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
845 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
991 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
846 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
992 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
847 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
993 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
848 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
994 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
849 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
995 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
850 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
996 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
851
997
852 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
998 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
853 val++;
999 val++;
854 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1000 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
855 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1001 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
856 }
1002 }
857
1003
858 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1004 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
859 {
1005 {
860 /** This function is used to update the HK packets statistics after a TC rejection.
1006 /** This function is used to update the HK packets statistics after a TC rejection.
861 *
1007 *
862 * @param TC points to the TC being processed
1008 * @param TC points to the TC being processed
863 * @param time is the time used to date the TC rejection
1009 * @param time is the time used to date the TC rejection
864 *
1010 *
865 */
1011 */
866
1012
867 unsigned int val;
1013 unsigned int val;
868
1014
869 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1015 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
870 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1016 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
871 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1017 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
872 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1018 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
873 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1019 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
874 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1020 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
875 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1021 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
876 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1022 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
877 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1023 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
878 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1024 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
879 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1025 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
880 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1026 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
881
1027
882 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1028 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
883 val++;
1029 val++;
884 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1030 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
885 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1031 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
886 }
1032 }
887
1033
888 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1034 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
889 {
1035 {
890 /** This function is the last step of the TC execution workflow.
1036 /** This function is the last step of the TC execution workflow.
891 *
1037 *
892 * @param TC points to the TC being processed
1038 * @param TC points to the TC being processed
893 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1039 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
894 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1040 * @param queue_id is the id of the RTEMS message queue used to send TM packets
895 * @param time is the time used to date the TC execution
1041 * @param time is the time used to date the TC execution
896 *
1042 *
897 */
1043 */
898
1044
899 unsigned char requestedMode;
1045 unsigned char requestedMode;
900
1046
901 if (result == LFR_SUCCESSFUL)
1047 if (result == LFR_SUCCESSFUL)
902 {
1048 {
903 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1049 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
904 &
1050 &
905 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1051 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
906 )
1052 )
907 {
1053 {
908 send_tm_lfr_tc_exe_success( TC, queue_id );
1054 send_tm_lfr_tc_exe_success( TC, queue_id );
909 }
1055 }
910 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1056 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
911 {
1057 {
912 //**********************************
1058 //**********************************
913 // UPDATE THE LFRMODE LOCAL VARIABLE
1059 // UPDATE THE LFRMODE LOCAL VARIABLE
914 requestedMode = TC->dataAndCRC[1];
1060 requestedMode = TC->dataAndCRC[1];
915 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1061 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
916 updateLFRCurrentMode();
1062 updateLFRCurrentMode();
917 }
1063 }
918 }
1064 }
919 else if (result == LFR_EXE_ERROR)
1065 else if (result == LFR_EXE_ERROR)
920 {
1066 {
921 send_tm_lfr_tc_exe_error( TC, queue_id );
1067 send_tm_lfr_tc_exe_error( TC, queue_id );
922 }
1068 }
923 }
1069 }
924
1070
925 //***************************
1071 //***************************
926 // Interrupt Service Routines
1072 // Interrupt Service Routines
927 rtems_isr commutation_isr1( rtems_vector_number vector )
1073 rtems_isr commutation_isr1( rtems_vector_number vector )
928 {
1074 {
929 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1075 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
930 printf("In commutation_isr1 *** Error sending event to DUMB\n");
1076 printf("In commutation_isr1 *** Error sending event to DUMB\n");
931 }
1077 }
932 }
1078 }
933
1079
934 rtems_isr commutation_isr2( rtems_vector_number vector )
1080 rtems_isr commutation_isr2( rtems_vector_number vector )
935 {
1081 {
936 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1082 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
937 printf("In commutation_isr2 *** Error sending event to DUMB\n");
1083 printf("In commutation_isr2 *** Error sending event to DUMB\n");
938 }
1084 }
939 }
1085 }
940
1086
941 //****************
1087 //****************
942 // OTHER FUNCTIONS
1088 // OTHER FUNCTIONS
943 void updateLFRCurrentMode()
1089 void updateLFRCurrentMode()
944 {
1090 {
945 /** This function updates the value of the global variable lfrCurrentMode.
1091 /** This function updates the value of the global variable lfrCurrentMode.
946 *
1092 *
947 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1093 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
948 *
1094 *
949 */
1095 */
950 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1096 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
951 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
1097 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
952 }
1098 }
953
1099
954 void set_lfr_soft_reset( unsigned char value )
1100 void set_lfr_soft_reset( unsigned char value )
955 {
1101 {
956 if (value == 1)
1102 if (value == 1)
957 {
1103 {
958 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1104 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
959 }
1105 }
960 else
1106 else
961 {
1107 {
962 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1108 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
963 }
1109 }
964 }
1110 }
965
1111
966 void reset_lfr( void )
1112 void reset_lfr( void )
967 {
1113 {
968 set_lfr_soft_reset( 1 );
1114 set_lfr_soft_reset( 1 );
969
1115
970 set_lfr_soft_reset( 0 );
1116 set_lfr_soft_reset( 0 );
971 }
1117 }
General Comments 0
You need to be logged in to leave comments. Login now