##// END OF EJS Templates
Bug 354, hk_sy_lfr_calib_enabled is set in TM_LFR_HK packets
paul -
r206:f4c6f6db73fc R3
parent child
Show More
@@ -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 cpu_usage_report
5 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
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=3 # major
12 DEFINES += SW_VERSION_N1=3 # major
13 DEFINES += SW_VERSION_N2=0 # minor
13 DEFINES += SW_VERSION_N2=0 # minor
14 DEFINES += SW_VERSION_N3=0 # patch
14 DEFINES += SW_VERSION_N3=0 # patch
15 DEFINES += SW_VERSION_N4=2 # internal
15 DEFINES += SW_VERSION_N4=3 # 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,138 +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 // TEMPERATURES
48 // TEMPERATURES
49 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
49 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
50 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
50 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
51 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
51 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
52 // CALIBRATION
52 // CALIBRATION
53 volatile unsigned int calDACCtrl;
53 volatile unsigned int calDACCtrl;
54 volatile unsigned int calPrescaler;
54 volatile unsigned int calPrescaler;
55 volatile unsigned int calDivisor;
55 volatile unsigned int calDivisor;
56 volatile unsigned int calDataPtr;
56 volatile unsigned int calDataPtr;
57 volatile unsigned int calData;
57 volatile unsigned int calData;
58 } time_management_regs_t;
58 } time_management_regs_t;
59
59
60 // PDB >= 0.1.28
60 // PDB >= 0.1.28, 0x80000f54
61 typedef struct{
61 typedef struct{
62 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
62 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
63 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 ]
64 int addr_data_f0_0; // 0x08
64 int addr_data_f0_0; // 0x08
65 int addr_data_f0_1; // 0x0c
65 int addr_data_f0_1; // 0x0c
66 int addr_data_f1_0; // 0x10
66 int addr_data_f1_0; // 0x10
67 int addr_data_f1_1; // 0x14
67 int addr_data_f1_1; // 0x14
68 int addr_data_f2_0; // 0x18
68 int addr_data_f2_0; // 0x18
69 int addr_data_f2_1; // 0x1c
69 int addr_data_f2_1; // 0x1c
70 int addr_data_f3_0; // 0x20
70 int addr_data_f3_0; // 0x20
71 int addr_data_f3_1; // 0x24
71 int addr_data_f3_1; // 0x24
72 volatile int status; // 0x28
72 volatile int status; // 0x28
73 int delta_snapshot; // 0x2c
73 int delta_snapshot; // 0x2c
74 int delta_f0; // 0x30
74 int delta_f0; // 0x30
75 int delta_f0_2; // 0x34
75 int delta_f0_2; // 0x34
76 int delta_f1; // 0x38
76 int delta_f1; // 0x38
77 int delta_f2; // 0x3c
77 int delta_f2; // 0x3c
78 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
79 int snapshot_param; // 0x44
79 int snapshot_param; // 0x44
80 int start_date; // 0x48
80 int start_date; // 0x48
81 //
81 //
82 volatile unsigned int f0_0_coarse_time; // 0x4c
82 volatile unsigned int f0_0_coarse_time; // 0x4c
83 volatile unsigned int f0_0_fine_time; // 0x50
83 volatile unsigned int f0_0_fine_time; // 0x50
84 volatile unsigned int f0_1_coarse_time; // 0x54
84 volatile unsigned int f0_1_coarse_time; // 0x54
85 volatile unsigned int f0_1_fine_time; // 0x58
85 volatile unsigned int f0_1_fine_time; // 0x58
86 //
86 //
87 volatile unsigned int f1_0_coarse_time; // 0x5c
87 volatile unsigned int f1_0_coarse_time; // 0x5c
88 volatile unsigned int f1_0_fine_time; // 0x60
88 volatile unsigned int f1_0_fine_time; // 0x60
89 volatile unsigned int f1_1_coarse_time; // 0x64
89 volatile unsigned int f1_1_coarse_time; // 0x64
90 volatile unsigned int f1_1_fine_time; // 0x68
90 volatile unsigned int f1_1_fine_time; // 0x68
91 //
91 //
92 volatile unsigned int f2_0_coarse_time; // 0x6c
92 volatile unsigned int f2_0_coarse_time; // 0x6c
93 volatile unsigned int f2_0_fine_time; // 0x70
93 volatile unsigned int f2_0_fine_time; // 0x70
94 volatile unsigned int f2_1_coarse_time; // 0x74
94 volatile unsigned int f2_1_coarse_time; // 0x74
95 volatile unsigned int f2_1_fine_time; // 0x78
95 volatile unsigned int f2_1_fine_time; // 0x78
96 //
96 //
97 volatile unsigned int f3_0_coarse_time; // 0x7c
97 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
98 volatile unsigned int f3_0_fine_time; // 0x80
98 volatile unsigned int f3_0_fine_time; // 0x80
99 volatile unsigned int f3_1_coarse_time; // 0x84
99 volatile unsigned int f3_1_coarse_time; // 0x84
100 volatile unsigned int f3_1_fine_time; // 0x88
100 volatile unsigned int f3_1_fine_time; // 0x88
101 //
101 //
102 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
103 //
103 //
104 volatile unsigned int v; // 0x90
104 volatile unsigned int v; // 0x90
105 volatile unsigned int e1; // 0x94
105 volatile unsigned int e1; // 0x94
106 volatile unsigned int e2; // 0x98
106 volatile unsigned int e2; // 0x98
107 } waveform_picker_regs_0_1_18_t;
107 } waveform_picker_regs_0_1_18_t;
108
108
109 typedef struct {
109 typedef struct {
110 volatile int config; // 0x00
110 volatile int config; // 0x00
111 volatile int status; // 0x04
111 volatile int status; // 0x04
112 volatile int f0_0_address; // 0x08
112 volatile int f0_0_address; // 0x08
113 volatile int f0_1_address; // 0x0C
113 volatile int f0_1_address; // 0x0C
114 //
114 //
115 volatile int f1_0_address; // 0x10
115 volatile int f1_0_address; // 0x10
116 volatile int f1_1_address; // 0x14
116 volatile int f1_1_address; // 0x14
117 volatile int f2_0_address; // 0x18
117 volatile int f2_0_address; // 0x18
118 volatile int f2_1_address; // 0x1C
118 volatile int f2_1_address; // 0x1C
119 //
119 //
120 volatile unsigned int f0_0_coarse_time; // 0x20
120 volatile unsigned int f0_0_coarse_time; // 0x20
121 volatile unsigned int f0_0_fine_time; // 0x24
121 volatile unsigned int f0_0_fine_time; // 0x24
122 volatile unsigned int f0_1_coarse_time; // 0x28
122 volatile unsigned int f0_1_coarse_time; // 0x28
123 volatile unsigned int f0_1_fine_time; // 0x2C
123 volatile unsigned int f0_1_fine_time; // 0x2C
124 //
124 //
125 volatile unsigned int f1_0_coarse_time; // 0x30
125 volatile unsigned int f1_0_coarse_time; // 0x30
126 volatile unsigned int f1_0_fine_time; // 0x34
126 volatile unsigned int f1_0_fine_time; // 0x34
127 volatile unsigned int f1_1_coarse_time; // 0x38
127 volatile unsigned int f1_1_coarse_time; // 0x38
128 volatile unsigned int f1_1_fine_time; // 0x3C
128 volatile unsigned int f1_1_fine_time; // 0x3C
129 //
129 //
130 volatile unsigned int f2_0_coarse_time; // 0x40
130 volatile unsigned int f2_0_coarse_time; // 0x40
131 volatile unsigned int f2_0_fine_time; // 0x44
131 volatile unsigned int f2_0_fine_time; // 0x44
132 volatile unsigned int f2_1_coarse_time; // 0x48
132 volatile unsigned int f2_1_coarse_time; // 0x48
133 volatile unsigned int f2_1_fine_time; // 0x4C
133 volatile unsigned int f2_1_fine_time; // 0x4C
134 //
134 //
135 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
136 } spectral_matrix_regs_t;
136 } spectral_matrix_regs_t;
137
137
138 #endif // GRLIB_REGS_H_INCLUDED
138 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,72 +1,72
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 //****
15 //****
16 // ISR
16 // ISR
17 rtems_isr commutation_isr1( rtems_vector_number vector );
17 rtems_isr commutation_isr1( rtems_vector_number vector );
18 rtems_isr commutation_isr2( rtems_vector_number vector );
18 rtems_isr commutation_isr2( rtems_vector_number vector );
19
19
20 //***********
20 //***********
21 // RTEMS TASK
21 // RTEMS TASK
22 rtems_task actn_task( rtems_task_argument unused );
22 rtems_task actn_task( rtems_task_argument unused );
23
23
24 //***********
24 //***********
25 // TC ACTIONS
25 // TC ACTIONS
26 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
26 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
27 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
27 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
28 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
28 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
29 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
29 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
31 int action_update_time( ccsdsTelecommandPacket_t *TC);
31 int action_update_time( ccsdsTelecommandPacket_t *TC);
32
32
33 // mode transition
33 // mode transition
34 int check_mode_value( unsigned char requestedMode );
34 int check_mode_value( unsigned char requestedMode );
35 int check_mode_transition( unsigned char requestedMode );
35 int check_mode_transition( unsigned char requestedMode );
36 int check_transition_date( unsigned int transitionCoarseTime );
36 int check_transition_date( unsigned int transitionCoarseTime );
37 int stop_current_mode( void );
37 int stop_current_mode( void );
38 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
38 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
39 int restart_science_tasks( unsigned char lfrRequestedMode );
39 int restart_science_tasks( unsigned char lfrRequestedMode );
40 int suspend_science_tasks();
40 int suspend_science_tasks();
41 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
41 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
42 void launch_spectral_matrix( void );
42 void launch_spectral_matrix( void );
43 void launch_spectral_matrix_simu( void );
43 void launch_spectral_matrix_simu( void );
44 void set_sm_irq_onNewMatrix( unsigned char value );
44 void set_sm_irq_onNewMatrix( unsigned char value );
45 void set_sm_irq_onError( unsigned char value );
45 void set_sm_irq_onError( unsigned char value );
46
46
47 // other functions
47 // other functions
48 void updateLFRCurrentMode();
48 void updateLFRCurrentMode();
49 void set_lfr_soft_reset( unsigned char value );
49 void set_lfr_soft_reset( unsigned char value );
50 void reset_lfr( void );
50 void reset_lfr( void );
51 // CALIBRATION
51 // CALIBRATION
52 void setCalibrationPrescaler( unsigned int prescaler );
52 void setCalibrationPrescaler( unsigned int prescaler );
53 void setCalibrationDivisor( unsigned int divisionFactor );
53 void setCalibrationDivisor( unsigned int divisionFactor );
54 void setCalibrationData( void );
54 void setCalibrationData( void );
55 void setCalibrationReload( bool state);
55 void setCalibrationReload( bool state);
56 void setCalibrationEnable( bool state );
56 void setCalibrationEnable( bool state );
57 void setCalibrationInterleaved( bool state );
57 void setCalibrationInterleaved( bool state );
58 void startCalibration( void );
58 void setCalibration( bool state );
59 void stopCalibration( void );
59 void set_hk_lfr_calib_enable( bool state );
60 void configureCalibration( bool interleaved );
60 void configureCalibration( bool interleaved );
61 //
61 //
62 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
62 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
63 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
63 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
64 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
64 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
65
65
66 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
66 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
67 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
67 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
68
68
69 #endif // TC_HANDLER_H_INCLUDED
69 #endif // TC_HANDLER_H_INCLUDED
70
70
71
71
72
72
@@ -1,1159 +1,1175
1 /** Functions and tasks related to TeleCommand handling.
1 /** Functions and tasks related to TeleCommand handling.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands:\n
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
7 * action launching\n
8 * TC parsing\n
8 * TC parsing\n
9 * ...
9 * ...
10 *
10 *
11 */
11 */
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "math.h"
14 #include "math.h"
15
15
16 //***********
16 //***********
17 // RTEMS TASK
17 // RTEMS TASK
18
18
19 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
20 {
20 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
22 *
23 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
24 *
24 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
27 *
27 *
28 */
28 */
29
29
30 int result;
30 int result;
31 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[6];
35 unsigned char time[6];
36 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
38
38
39 status = get_message_queue_id_recv( &queue_rcv_id );
39 status = get_message_queue_id_recv( &queue_rcv_id );
40 if (status != RTEMS_SUCCESSFUL)
40 if (status != RTEMS_SUCCESSFUL)
41 {
41 {
42 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)
43 }
43 }
44
44
45 status = get_message_queue_id_send( &queue_snd_id );
45 status = get_message_queue_id_send( &queue_snd_id );
46 if (status != RTEMS_SUCCESSFUL)
46 if (status != RTEMS_SUCCESSFUL)
47 {
47 {
48 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)
49 }
49 }
50
50
51 result = LFR_SUCCESSFUL;
51 result = LFR_SUCCESSFUL;
52 subtype = 0; // subtype of the current TC packet
52 subtype = 0; // subtype of the current TC packet
53
53
54 BOOT_PRINTF("in ACTN *** \n")
54 BOOT_PRINTF("in ACTN *** \n")
55
55
56 while(1)
56 while(1)
57 {
57 {
58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
60 getTime( time ); // set time to the current time
60 getTime( time ); // set time to the current time
61 if (status!=RTEMS_SUCCESSFUL)
61 if (status!=RTEMS_SUCCESSFUL)
62 {
62 {
63 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)
64 }
64 }
65 else
65 else
66 {
66 {
67 subtype = TC.serviceSubType;
67 subtype = TC.serviceSubType;
68 switch(subtype)
68 switch(subtype)
69 {
69 {
70 case TC_SUBTYPE_RESET:
70 case TC_SUBTYPE_RESET:
71 result = action_reset( &TC, queue_snd_id, time );
71 result = action_reset( &TC, queue_snd_id, time );
72 close_action( &TC, result, queue_snd_id );
72 close_action( &TC, result, queue_snd_id );
73 break;
73 break;
74 case TC_SUBTYPE_LOAD_COMM:
74 case TC_SUBTYPE_LOAD_COMM:
75 result = action_load_common_par( &TC );
75 result = action_load_common_par( &TC );
76 close_action( &TC, result, queue_snd_id );
76 close_action( &TC, result, queue_snd_id );
77 break;
77 break;
78 case TC_SUBTYPE_LOAD_NORM:
78 case TC_SUBTYPE_LOAD_NORM:
79 result = action_load_normal_par( &TC, queue_snd_id, time );
79 result = action_load_normal_par( &TC, queue_snd_id, time );
80 close_action( &TC, result, queue_snd_id );
80 close_action( &TC, result, queue_snd_id );
81 break;
81 break;
82 case TC_SUBTYPE_LOAD_BURST:
82 case TC_SUBTYPE_LOAD_BURST:
83 result = action_load_burst_par( &TC, queue_snd_id, time );
83 result = action_load_burst_par( &TC, queue_snd_id, time );
84 close_action( &TC, result, queue_snd_id );
84 close_action( &TC, result, queue_snd_id );
85 break;
85 break;
86 case TC_SUBTYPE_LOAD_SBM1:
86 case TC_SUBTYPE_LOAD_SBM1:
87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
88 close_action( &TC, result, queue_snd_id );
88 close_action( &TC, result, queue_snd_id );
89 break;
89 break;
90 case TC_SUBTYPE_LOAD_SBM2:
90 case TC_SUBTYPE_LOAD_SBM2:
91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
92 close_action( &TC, result, queue_snd_id );
92 close_action( &TC, result, queue_snd_id );
93 break;
93 break;
94 case TC_SUBTYPE_DUMP:
94 case TC_SUBTYPE_DUMP:
95 result = action_dump_par( queue_snd_id );
95 result = action_dump_par( queue_snd_id );
96 close_action( &TC, result, queue_snd_id );
96 close_action( &TC, result, queue_snd_id );
97 break;
97 break;
98 case TC_SUBTYPE_ENTER:
98 case TC_SUBTYPE_ENTER:
99 result = action_enter_mode( &TC, queue_snd_id );
99 result = action_enter_mode( &TC, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
101 break;
101 break;
102 case TC_SUBTYPE_UPDT_INFO:
102 case TC_SUBTYPE_UPDT_INFO:
103 result = action_update_info( &TC, queue_snd_id );
103 result = action_update_info( &TC, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
105 break;
105 break;
106 case TC_SUBTYPE_EN_CAL:
106 case TC_SUBTYPE_EN_CAL:
107 result = action_enable_calibration( &TC, queue_snd_id, time );
107 result = action_enable_calibration( &TC, queue_snd_id, time );
108 close_action( &TC, result, queue_snd_id );
108 close_action( &TC, result, queue_snd_id );
109 break;
109 break;
110 case TC_SUBTYPE_DIS_CAL:
110 case TC_SUBTYPE_DIS_CAL:
111 result = action_disable_calibration( &TC, queue_snd_id, time );
111 result = action_disable_calibration( &TC, queue_snd_id, time );
112 close_action( &TC, result, queue_snd_id );
112 close_action( &TC, result, queue_snd_id );
113 break;
113 break;
114 case TC_SUBTYPE_LOAD_K:
114 case TC_SUBTYPE_LOAD_K:
115 printf("TC_SUBTYPE_LOAD_K\n");
115 printf("TC_SUBTYPE_LOAD_K\n");
116 result = action_load_kcoefficients( &TC, queue_snd_id, time );
116 result = action_load_kcoefficients( &TC, queue_snd_id, time );
117 close_action( &TC, result, queue_snd_id );
117 close_action( &TC, result, queue_snd_id );
118 break;
118 break;
119 case TC_SUBTYPE_DUMP_K:
119 case TC_SUBTYPE_DUMP_K:
120 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
120 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
121 close_action( &TC, result, queue_snd_id );
122 break;
122 break;
123 case TC_SUBTYPE_LOAD_FBINS:
123 case TC_SUBTYPE_LOAD_FBINS:
124 result = action_load_fbins_mask( &TC, queue_snd_id, time );
124 result = action_load_fbins_mask( &TC, queue_snd_id, time );
125 close_action( &TC, result, queue_snd_id );
125 close_action( &TC, result, queue_snd_id );
126 break;
126 break;
127 case TC_SUBTYPE_UPDT_TIME:
127 case TC_SUBTYPE_UPDT_TIME:
128 result = action_update_time( &TC );
128 result = action_update_time( &TC );
129 close_action( &TC, result, queue_snd_id );
129 close_action( &TC, result, queue_snd_id );
130 break;
130 break;
131 default:
131 default:
132 break;
132 break;
133 }
133 }
134 }
134 }
135 }
135 }
136 }
136 }
137
137
138 //***********
138 //***********
139 // TC ACTIONS
139 // TC ACTIONS
140
140
141 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
141 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
142 {
142 {
143 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
143 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
144 *
144 *
145 * @param TC points to the TeleCommand packet that is being processed
145 * @param TC points to the TeleCommand packet that is being processed
146 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
146 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
147 *
147 *
148 */
148 */
149
149
150 printf("this is the end!!!\n");
150 printf("this is the end!!!\n");
151 exit(0);
151 exit(0);
152 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
152 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
153 return LFR_DEFAULT;
153 return LFR_DEFAULT;
154 }
154 }
155
155
156 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
156 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
157 {
157 {
158 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
158 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
159 *
159 *
160 * @param TC points to the TeleCommand packet that is being processed
160 * @param TC points to the TeleCommand packet that is being processed
161 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
161 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
162 *
162 *
163 */
163 */
164
164
165 rtems_status_code status;
165 rtems_status_code status;
166 unsigned char requestedMode;
166 unsigned char requestedMode;
167 unsigned int *transitionCoarseTime_ptr;
167 unsigned int *transitionCoarseTime_ptr;
168 unsigned int transitionCoarseTime;
168 unsigned int transitionCoarseTime;
169 unsigned char * bytePosPtr;
169 unsigned char * bytePosPtr;
170
170
171 bytePosPtr = (unsigned char *) &TC->packetID;
171 bytePosPtr = (unsigned char *) &TC->packetID;
172
172
173 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
173 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
174 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
174 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
175 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
175 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
176
176
177 status = check_mode_value( requestedMode );
177 status = check_mode_value( requestedMode );
178
178
179 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
179 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
180 {
180 {
181 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
181 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
182 }
182 }
183 else // the mode value is consistent, check the transition
183 else // the mode value is consistent, check the transition
184 {
184 {
185 status = check_mode_transition(requestedMode);
185 status = check_mode_transition(requestedMode);
186 if (status != LFR_SUCCESSFUL)
186 if (status != LFR_SUCCESSFUL)
187 {
187 {
188 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
188 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
189 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
189 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
190 }
190 }
191 }
191 }
192
192
193 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
193 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
194 {
194 {
195 status = check_transition_date( transitionCoarseTime );
195 status = check_transition_date( transitionCoarseTime );
196 if (status != LFR_SUCCESSFUL)
196 if (status != LFR_SUCCESSFUL)
197 {
197 {
198 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
198 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
199 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
199 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
200 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
200 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
201 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
201 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
202 }
202 }
203 }
203 }
204
204
205 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
205 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
206 {
206 {
207 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
207 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
208 status = enter_mode( requestedMode, transitionCoarseTime );
208 status = enter_mode( requestedMode, transitionCoarseTime );
209 }
209 }
210
210
211 return status;
211 return status;
212 }
212 }
213
213
214 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
214 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
215 {
215 {
216 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
216 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
217 *
217 *
218 * @param TC points to the TeleCommand packet that is being processed
218 * @param TC points to the TeleCommand packet that is being processed
219 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
219 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
220 *
220 *
221 * @return LFR directive status code:
221 * @return LFR directive status code:
222 * - LFR_DEFAULT
222 * - LFR_DEFAULT
223 * - LFR_SUCCESSFUL
223 * - LFR_SUCCESSFUL
224 *
224 *
225 */
225 */
226
226
227 unsigned int val;
227 unsigned int val;
228 int result;
228 int result;
229 unsigned int status;
229 unsigned int status;
230 unsigned char mode;
230 unsigned char mode;
231 unsigned char * bytePosPtr;
231 unsigned char * bytePosPtr;
232
232
233 bytePosPtr = (unsigned char *) &TC->packetID;
233 bytePosPtr = (unsigned char *) &TC->packetID;
234
234
235 // check LFR mode
235 // check LFR mode
236 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
236 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
237 status = check_update_info_hk_lfr_mode( mode );
237 status = check_update_info_hk_lfr_mode( mode );
238 if (status == LFR_SUCCESSFUL) // check TDS mode
238 if (status == LFR_SUCCESSFUL) // check TDS mode
239 {
239 {
240 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
240 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
241 status = check_update_info_hk_tds_mode( mode );
241 status = check_update_info_hk_tds_mode( mode );
242 }
242 }
243 if (status == LFR_SUCCESSFUL) // check THR mode
243 if (status == LFR_SUCCESSFUL) // check THR mode
244 {
244 {
245 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
245 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
246 status = check_update_info_hk_thr_mode( mode );
246 status = check_update_info_hk_thr_mode( mode );
247 }
247 }
248 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
248 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
249 {
249 {
250 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
250 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
251 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
251 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
252 val++;
252 val++;
253 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
253 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
254 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
254 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
255 }
255 }
256
256
257 result = status;
257 result = status;
258
258
259 return result;
259 return result;
260 }
260 }
261
261
262 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
262 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
263 {
263 {
264 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
264 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
265 *
265 *
266 * @param TC points to the TeleCommand packet that is being processed
266 * @param TC points to the TeleCommand packet that is being processed
267 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
267 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
268 *
268 *
269 */
269 */
270
270
271 int result;
271 int result;
272
272
273 result = LFR_DEFAULT;
273 result = LFR_DEFAULT;
274
274
275 startCalibration();
275 setCalibration( true );
276
276
277 result = LFR_SUCCESSFUL;
277 result = LFR_SUCCESSFUL;
278
278
279 return result;
279 return result;
280 }
280 }
281
281
282 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
282 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
283 {
283 {
284 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
284 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
285 *
285 *
286 * @param TC points to the TeleCommand packet that is being processed
286 * @param TC points to the TeleCommand packet that is being processed
287 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
287 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
288 *
288 *
289 */
289 */
290
290
291 int result;
291 int result;
292
292
293 result = LFR_DEFAULT;
293 result = LFR_DEFAULT;
294
294
295 stopCalibration();
295 setCalibration( false );
296
296
297 result = LFR_SUCCESSFUL;
297 result = LFR_SUCCESSFUL;
298
298
299 return result;
299 return result;
300 }
300 }
301
301
302 int action_update_time(ccsdsTelecommandPacket_t *TC)
302 int action_update_time(ccsdsTelecommandPacket_t *TC)
303 {
303 {
304 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
304 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
305 *
305 *
306 * @param TC points to the TeleCommand packet that is being processed
306 * @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
307 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
308 *
308 *
309 * @return LFR_SUCCESSFUL
309 * @return LFR_SUCCESSFUL
310 *
310 *
311 */
311 */
312
312
313 unsigned int val;
313 unsigned int val;
314
314
315 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
315 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
316 + (TC->dataAndCRC[1] << 16)
316 + (TC->dataAndCRC[1] << 16)
317 + (TC->dataAndCRC[2] << 8)
317 + (TC->dataAndCRC[2] << 8)
318 + TC->dataAndCRC[3];
318 + TC->dataAndCRC[3];
319
319
320 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
320 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
321 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
321 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
322 val++;
322 val++;
323 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
323 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);
324 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
325
325
326 return LFR_SUCCESSFUL;
326 return LFR_SUCCESSFUL;
327 }
327 }
328
328
329 //*******************
329 //*******************
330 // ENTERING THE MODES
330 // ENTERING THE MODES
331 int check_mode_value( unsigned char requestedMode )
331 int check_mode_value( unsigned char requestedMode )
332 {
332 {
333 int status;
333 int status;
334
334
335 if ( (requestedMode != LFR_MODE_STANDBY)
335 if ( (requestedMode != LFR_MODE_STANDBY)
336 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
336 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
337 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
337 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
338 {
338 {
339 status = LFR_DEFAULT;
339 status = LFR_DEFAULT;
340 }
340 }
341 else
341 else
342 {
342 {
343 status = LFR_SUCCESSFUL;
343 status = LFR_SUCCESSFUL;
344 }
344 }
345
345
346 return status;
346 return status;
347 }
347 }
348
348
349 int check_mode_transition( unsigned char requestedMode )
349 int check_mode_transition( unsigned char requestedMode )
350 {
350 {
351 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
351 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
352 *
352 *
353 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
353 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
354 *
354 *
355 * @return LFR directive status codes:
355 * @return LFR directive status codes:
356 * - LFR_SUCCESSFUL - the transition is authorized
356 * - LFR_SUCCESSFUL - the transition is authorized
357 * - LFR_DEFAULT - the transition is not authorized
357 * - LFR_DEFAULT - the transition is not authorized
358 *
358 *
359 */
359 */
360
360
361 int status;
361 int status;
362
362
363 switch (requestedMode)
363 switch (requestedMode)
364 {
364 {
365 case LFR_MODE_STANDBY:
365 case LFR_MODE_STANDBY:
366 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
366 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
367 status = LFR_DEFAULT;
367 status = LFR_DEFAULT;
368 }
368 }
369 else
369 else
370 {
370 {
371 status = LFR_SUCCESSFUL;
371 status = LFR_SUCCESSFUL;
372 }
372 }
373 break;
373 break;
374 case LFR_MODE_NORMAL:
374 case LFR_MODE_NORMAL:
375 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
375 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
376 status = LFR_DEFAULT;
376 status = LFR_DEFAULT;
377 }
377 }
378 else {
378 else {
379 status = LFR_SUCCESSFUL;
379 status = LFR_SUCCESSFUL;
380 }
380 }
381 break;
381 break;
382 case LFR_MODE_BURST:
382 case LFR_MODE_BURST:
383 if ( lfrCurrentMode == LFR_MODE_BURST ) {
383 if ( lfrCurrentMode == LFR_MODE_BURST ) {
384 status = LFR_DEFAULT;
384 status = LFR_DEFAULT;
385 }
385 }
386 else {
386 else {
387 status = LFR_SUCCESSFUL;
387 status = LFR_SUCCESSFUL;
388 }
388 }
389 break;
389 break;
390 case LFR_MODE_SBM1:
390 case LFR_MODE_SBM1:
391 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
391 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
392 status = LFR_DEFAULT;
392 status = LFR_DEFAULT;
393 }
393 }
394 else {
394 else {
395 status = LFR_SUCCESSFUL;
395 status = LFR_SUCCESSFUL;
396 }
396 }
397 break;
397 break;
398 case LFR_MODE_SBM2:
398 case LFR_MODE_SBM2:
399 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
399 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
400 status = LFR_DEFAULT;
400 status = LFR_DEFAULT;
401 }
401 }
402 else {
402 else {
403 status = LFR_SUCCESSFUL;
403 status = LFR_SUCCESSFUL;
404 }
404 }
405 break;
405 break;
406 default:
406 default:
407 status = LFR_DEFAULT;
407 status = LFR_DEFAULT;
408 break;
408 break;
409 }
409 }
410
410
411 return status;
411 return status;
412 }
412 }
413
413
414 int check_transition_date( unsigned int transitionCoarseTime )
414 int check_transition_date( unsigned int transitionCoarseTime )
415 {
415 {
416 int status;
416 int status;
417 unsigned int localCoarseTime;
417 unsigned int localCoarseTime;
418 unsigned int deltaCoarseTime;
418 unsigned int deltaCoarseTime;
419
419
420 status = LFR_SUCCESSFUL;
420 status = LFR_SUCCESSFUL;
421
421
422 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
422 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
423 {
423 {
424 status = LFR_SUCCESSFUL;
424 status = LFR_SUCCESSFUL;
425 }
425 }
426 else
426 else
427 {
427 {
428 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
428 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
429
429
430 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime)
430 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime)
431
431
432 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
432 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
433 {
433 {
434 status = LFR_DEFAULT;
434 status = LFR_DEFAULT;
435 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n")
435 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n")
436 }
436 }
437
437
438 if (status == LFR_SUCCESSFUL)
438 if (status == LFR_SUCCESSFUL)
439 {
439 {
440 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
440 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
441 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
441 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
442 {
442 {
443 status = LFR_DEFAULT;
443 status = LFR_DEFAULT;
444 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
444 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
445 }
445 }
446 }
446 }
447 }
447 }
448
448
449 return status;
449 return status;
450 }
450 }
451
451
452 int stop_current_mode( void )
452 int stop_current_mode( void )
453 {
453 {
454 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
454 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
455 *
455 *
456 * @return RTEMS directive status codes:
456 * @return RTEMS directive status codes:
457 * - RTEMS_SUCCESSFUL - task restarted successfully
457 * - RTEMS_SUCCESSFUL - task restarted successfully
458 * - RTEMS_INVALID_ID - task id invalid
458 * - RTEMS_INVALID_ID - task id invalid
459 * - RTEMS_ALREADY_SUSPENDED - task already suspended
459 * - RTEMS_ALREADY_SUSPENDED - task already suspended
460 *
460 *
461 */
461 */
462
462
463 rtems_status_code status;
463 rtems_status_code status;
464
464
465 status = RTEMS_SUCCESSFUL;
465 status = RTEMS_SUCCESSFUL;
466
466
467 // (1) mask interruptions
467 // (1) mask interruptions
468 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
468 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
469 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
469 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
470
470
471 // (2) reset waveform picker registers
471 // (2) reset waveform picker registers
472 reset_wfp_burst_enable(); // reset burst and enable bits
472 reset_wfp_burst_enable(); // reset burst and enable bits
473 reset_wfp_status(); // reset all the status bits
473 reset_wfp_status(); // reset all the status bits
474
474
475 // (3) reset spectral matrices registers
475 // (3) reset spectral matrices registers
476 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
476 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
477 reset_sm_status();
477 reset_sm_status();
478
478
479 // reset lfr VHDL module
479 // reset lfr VHDL module
480 reset_lfr();
480 reset_lfr();
481
481
482 reset_extractSWF(); // reset the extractSWF flag to false
482 reset_extractSWF(); // reset the extractSWF flag to false
483
483
484 // (4) clear interruptions
484 // (4) clear interruptions
485 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
485 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
486 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
486 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
487
487
488 // <Spectral Matrices simulator>
488 // <Spectral Matrices simulator>
489 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
489 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
490 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
490 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
491 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
491 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
492 // </Spectral Matrices simulator>
492 // </Spectral Matrices simulator>
493
493
494 // suspend several tasks
494 // suspend several tasks
495 if (lfrCurrentMode != LFR_MODE_STANDBY) {
495 if (lfrCurrentMode != LFR_MODE_STANDBY) {
496 status = suspend_science_tasks();
496 status = suspend_science_tasks();
497 }
497 }
498
498
499 if (status != RTEMS_SUCCESSFUL)
499 if (status != RTEMS_SUCCESSFUL)
500 {
500 {
501 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
501 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
502 }
502 }
503
503
504 return status;
504 return status;
505 }
505 }
506
506
507 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
507 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
508 {
508 {
509 /** This function is launched after a mode transition validation.
509 /** This function is launched after a mode transition validation.
510 *
510 *
511 * @param mode is the mode in which LFR will be put.
511 * @param mode is the mode in which LFR will be put.
512 *
512 *
513 * @return RTEMS directive status codes:
513 * @return RTEMS directive status codes:
514 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
514 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
515 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
515 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
516 *
516 *
517 */
517 */
518
518
519 rtems_status_code status;
519 rtems_status_code status;
520
520
521 //**********************
521 //**********************
522 // STOP THE CURRENT MODE
522 // STOP THE CURRENT MODE
523 status = stop_current_mode();
523 status = stop_current_mode();
524 if (status != RTEMS_SUCCESSFUL)
524 if (status != RTEMS_SUCCESSFUL)
525 {
525 {
526 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
526 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
527 }
527 }
528
528
529 //*************************
529 //*************************
530 // ENTER THE REQUESTED MODE
530 // ENTER THE REQUESTED MODE
531 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
531 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
532 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
532 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
533 {
533 {
534 #ifdef PRINT_TASK_STATISTICS
534 #ifdef PRINT_TASK_STATISTICS
535 rtems_cpu_usage_reset();
535 rtems_cpu_usage_reset();
536 #endif
536 #endif
537 status = restart_science_tasks( mode );
537 status = restart_science_tasks( mode );
538 launch_spectral_matrix( );
538 launch_spectral_matrix( );
539 launch_waveform_picker( mode, transitionCoarseTime );
539 launch_waveform_picker( mode, transitionCoarseTime );
540 // launch_spectral_matrix_simu( );
540 // launch_spectral_matrix_simu( );
541 }
541 }
542 else if ( mode == LFR_MODE_STANDBY )
542 else if ( mode == LFR_MODE_STANDBY )
543 {
543 {
544 #ifdef PRINT_TASK_STATISTICS
544 #ifdef PRINT_TASK_STATISTICS
545 rtems_cpu_usage_report();
545 rtems_cpu_usage_report();
546 #endif
546 #endif
547
547
548 #ifdef PRINT_STACK_REPORT
548 #ifdef PRINT_STACK_REPORT
549 PRINTF("stack report selected\n")
549 PRINTF("stack report selected\n")
550 rtems_stack_checker_report_usage();
550 rtems_stack_checker_report_usage();
551 #endif
551 #endif
552 }
552 }
553 else
553 else
554 {
554 {
555 status = RTEMS_UNSATISFIED;
555 status = RTEMS_UNSATISFIED;
556 }
556 }
557
557
558 if (status != RTEMS_SUCCESSFUL)
558 if (status != RTEMS_SUCCESSFUL)
559 {
559 {
560 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
560 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
561 status = RTEMS_UNSATISFIED;
561 status = RTEMS_UNSATISFIED;
562 }
562 }
563
563
564 return status;
564 return status;
565 }
565 }
566
566
567 int restart_science_tasks(unsigned char lfrRequestedMode )
567 int restart_science_tasks(unsigned char lfrRequestedMode )
568 {
568 {
569 /** This function is used to restart all science tasks.
569 /** This function is used to restart all science tasks.
570 *
570 *
571 * @return RTEMS directive status codes:
571 * @return RTEMS directive status codes:
572 * - RTEMS_SUCCESSFUL - task restarted successfully
572 * - RTEMS_SUCCESSFUL - task restarted successfully
573 * - RTEMS_INVALID_ID - task id invalid
573 * - RTEMS_INVALID_ID - task id invalid
574 * - RTEMS_INCORRECT_STATE - task never started
574 * - RTEMS_INCORRECT_STATE - task never started
575 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
575 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
576 *
576 *
577 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
577 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
578 *
578 *
579 */
579 */
580
580
581 rtems_status_code status[10];
581 rtems_status_code status[10];
582 rtems_status_code ret;
582 rtems_status_code ret;
583
583
584 ret = RTEMS_SUCCESSFUL;
584 ret = RTEMS_SUCCESSFUL;
585
585
586 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
586 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
587 if (status[0] != RTEMS_SUCCESSFUL)
587 if (status[0] != RTEMS_SUCCESSFUL)
588 {
588 {
589 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
589 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
590 }
590 }
591
591
592 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
592 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
593 if (status[1] != RTEMS_SUCCESSFUL)
593 if (status[1] != RTEMS_SUCCESSFUL)
594 {
594 {
595 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
595 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
596 }
596 }
597
597
598 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
598 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
599 if (status[2] != RTEMS_SUCCESSFUL)
599 if (status[2] != RTEMS_SUCCESSFUL)
600 {
600 {
601 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
601 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
602 }
602 }
603
603
604 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
604 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
605 if (status[3] != RTEMS_SUCCESSFUL)
605 if (status[3] != RTEMS_SUCCESSFUL)
606 {
606 {
607 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
607 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
608 }
608 }
609
609
610 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
610 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
611 if (status[4] != RTEMS_SUCCESSFUL)
611 if (status[4] != RTEMS_SUCCESSFUL)
612 {
612 {
613 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
613 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
614 }
614 }
615
615
616 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
616 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
617 if (status[5] != RTEMS_SUCCESSFUL)
617 if (status[5] != RTEMS_SUCCESSFUL)
618 {
618 {
619 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
619 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
620 }
620 }
621
621
622 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
622 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
623 if (status[6] != RTEMS_SUCCESSFUL)
623 if (status[6] != RTEMS_SUCCESSFUL)
624 {
624 {
625 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
625 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
626 }
626 }
627
627
628 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
628 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
629 if (status[7] != RTEMS_SUCCESSFUL)
629 if (status[7] != RTEMS_SUCCESSFUL)
630 {
630 {
631 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
631 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
632 }
632 }
633
633
634 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
634 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
635 if (status[8] != RTEMS_SUCCESSFUL)
635 if (status[8] != RTEMS_SUCCESSFUL)
636 {
636 {
637 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
637 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
638 }
638 }
639
639
640 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
640 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
641 if (status[9] != RTEMS_SUCCESSFUL)
641 if (status[9] != RTEMS_SUCCESSFUL)
642 {
642 {
643 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
643 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
644 }
644 }
645
645
646 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
646 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
647 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
647 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
648 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
648 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
649 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
649 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
650 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
650 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
651 {
651 {
652 ret = RTEMS_UNSATISFIED;
652 ret = RTEMS_UNSATISFIED;
653 }
653 }
654
654
655 return ret;
655 return ret;
656 }
656 }
657
657
658 int suspend_science_tasks()
658 int suspend_science_tasks()
659 {
659 {
660 /** This function suspends the science tasks.
660 /** This function suspends the science tasks.
661 *
661 *
662 * @return RTEMS directive status codes:
662 * @return RTEMS directive status codes:
663 * - RTEMS_SUCCESSFUL - task restarted successfully
663 * - RTEMS_SUCCESSFUL - task restarted successfully
664 * - RTEMS_INVALID_ID - task id invalid
664 * - RTEMS_INVALID_ID - task id invalid
665 * - RTEMS_ALREADY_SUSPENDED - task already suspended
665 * - RTEMS_ALREADY_SUSPENDED - task already suspended
666 *
666 *
667 */
667 */
668
668
669 rtems_status_code status;
669 rtems_status_code status;
670
670
671 printf("in suspend_science_tasks\n");
671 printf("in suspend_science_tasks\n");
672
672
673 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
673 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
674 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
674 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
675 {
675 {
676 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
676 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
677 }
677 }
678 else
678 else
679 {
679 {
680 status = RTEMS_SUCCESSFUL;
680 status = RTEMS_SUCCESSFUL;
681 }
681 }
682 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
682 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
683 {
683 {
684 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
684 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
685 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
685 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
686 {
686 {
687 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
687 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
688 }
688 }
689 else
689 else
690 {
690 {
691 status = RTEMS_SUCCESSFUL;
691 status = RTEMS_SUCCESSFUL;
692 }
692 }
693 }
693 }
694 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
694 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
695 {
695 {
696 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
696 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
697 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
697 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
698 {
698 {
699 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
699 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
700 }
700 }
701 else
701 else
702 {
702 {
703 status = RTEMS_SUCCESSFUL;
703 status = RTEMS_SUCCESSFUL;
704 }
704 }
705 }
705 }
706 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
706 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
707 {
707 {
708 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
708 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
709 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
709 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
710 {
710 {
711 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
711 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
712 }
712 }
713 else
713 else
714 {
714 {
715 status = RTEMS_SUCCESSFUL;
715 status = RTEMS_SUCCESSFUL;
716 }
716 }
717 }
717 }
718 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
718 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
719 {
719 {
720 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
720 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
721 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
721 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
722 {
722 {
723 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
723 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
724 }
724 }
725 else
725 else
726 {
726 {
727 status = RTEMS_SUCCESSFUL;
727 status = RTEMS_SUCCESSFUL;
728 }
728 }
729 }
729 }
730 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
730 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
731 {
731 {
732 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
732 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
733 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
733 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
734 {
734 {
735 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
735 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
736 }
736 }
737 else
737 else
738 {
738 {
739 status = RTEMS_SUCCESSFUL;
739 status = RTEMS_SUCCESSFUL;
740 }
740 }
741 }
741 }
742 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
742 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
743 {
743 {
744 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
744 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
745 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
745 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
746 {
746 {
747 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
747 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
748 }
748 }
749 else
749 else
750 {
750 {
751 status = RTEMS_SUCCESSFUL;
751 status = RTEMS_SUCCESSFUL;
752 }
752 }
753 }
753 }
754 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
754 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
755 {
755 {
756 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
756 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
757 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
757 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
758 {
758 {
759 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
759 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
760 }
760 }
761 else
761 else
762 {
762 {
763 status = RTEMS_SUCCESSFUL;
763 status = RTEMS_SUCCESSFUL;
764 }
764 }
765 }
765 }
766 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
766 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
767 {
767 {
768 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
768 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
769 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
769 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
770 {
770 {
771 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
771 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
772 }
772 }
773 else
773 else
774 {
774 {
775 status = RTEMS_SUCCESSFUL;
775 status = RTEMS_SUCCESSFUL;
776 }
776 }
777 }
777 }
778 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
778 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
779 {
779 {
780 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
780 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
781 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
781 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
782 {
782 {
783 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
783 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
784 }
784 }
785 else
785 else
786 {
786 {
787 status = RTEMS_SUCCESSFUL;
787 status = RTEMS_SUCCESSFUL;
788 }
788 }
789 }
789 }
790
790
791 return status;
791 return status;
792 }
792 }
793
793
794 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
794 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
795 {
795 {
796 WFP_reset_current_ring_nodes();
796 WFP_reset_current_ring_nodes();
797
797
798 reset_waveform_picker_regs();
798 reset_waveform_picker_regs();
799
799
800 set_wfp_burst_enable_register( mode );
800 set_wfp_burst_enable_register( mode );
801
801
802 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
802 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
803 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
803 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
804
804
805 if (transitionCoarseTime == 0)
805 if (transitionCoarseTime == 0)
806 {
806 {
807 waveform_picker_regs->start_date = time_management_regs->coarse_time;
807 waveform_picker_regs->start_date = time_management_regs->coarse_time;
808 }
808 }
809 else
809 else
810 {
810 {
811 waveform_picker_regs->start_date = transitionCoarseTime;
811 waveform_picker_regs->start_date = transitionCoarseTime;
812 }
812 }
813
813
814 }
814 }
815
815
816 void launch_spectral_matrix( void )
816 void launch_spectral_matrix( void )
817 {
817 {
818 SM_reset_current_ring_nodes();
818 SM_reset_current_ring_nodes();
819
819
820 reset_spectral_matrix_regs();
820 reset_spectral_matrix_regs();
821
821
822 reset_nb_sm();
822 reset_nb_sm();
823
823
824 set_sm_irq_onNewMatrix( 1 );
824 set_sm_irq_onNewMatrix( 1 );
825
825
826 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
826 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
827 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
827 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
828
828
829 }
829 }
830
830
831 void launch_spectral_matrix_simu( void )
831 void launch_spectral_matrix_simu( void )
832 {
832 {
833 SM_reset_current_ring_nodes();
833 SM_reset_current_ring_nodes();
834 reset_spectral_matrix_regs();
834 reset_spectral_matrix_regs();
835 reset_nb_sm();
835 reset_nb_sm();
836
836
837 // Spectral Matrices simulator
837 // Spectral Matrices simulator
838 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
838 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
839 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
839 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
840 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
840 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
841 }
841 }
842
842
843 void set_sm_irq_onNewMatrix( unsigned char value )
843 void set_sm_irq_onNewMatrix( unsigned char value )
844 {
844 {
845 if (value == 1)
845 if (value == 1)
846 {
846 {
847 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
847 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
848 }
848 }
849 else
849 else
850 {
850 {
851 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
851 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
852 }
852 }
853 }
853 }
854
854
855 void set_sm_irq_onError( unsigned char value )
855 void set_sm_irq_onError( unsigned char value )
856 {
856 {
857 if (value == 1)
857 if (value == 1)
858 {
858 {
859 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
859 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
860 }
860 }
861 else
861 else
862 {
862 {
863 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
863 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
864 }
864 }
865 }
865 }
866
866
867 //*****************************
867 //*****************************
868 // CONFIGURE CALIBRATION SIGNAL
868 // CONFIGURE CALIBRATION SIGNAL
869 void setCalibrationPrescaler( unsigned int prescaler )
869 void setCalibrationPrescaler( unsigned int prescaler )
870 {
870 {
871 // prescaling of the master clock (25 MHz)
871 // prescaling of the master clock (25 MHz)
872 // master clock is divided by 2^prescaler
872 // master clock is divided by 2^prescaler
873 time_management_regs->calPrescaler = prescaler;
873 time_management_regs->calPrescaler = prescaler;
874 }
874 }
875
875
876 void setCalibrationDivisor( unsigned int divisionFactor )
876 void setCalibrationDivisor( unsigned int divisionFactor )
877 {
877 {
878 // division of the prescaled clock by the division factor
878 // division of the prescaled clock by the division factor
879 time_management_regs->calDivisor = divisionFactor;
879 time_management_regs->calDivisor = divisionFactor;
880 }
880 }
881
881
882 void setCalibrationData( void ){
882 void setCalibrationData( void ){
883 unsigned int k;
883 unsigned int k;
884 unsigned short data;
884 unsigned short data;
885 float val;
885 float val;
886 float f0;
886 float f0;
887 float f1;
887 float f1;
888 float fs;
888 float fs;
889 float Ts;
889 float Ts;
890 float scaleFactor;
890 float scaleFactor;
891
891
892 f0 = 625;
892 f0 = 625;
893 f1 = 10000;
893 f1 = 10000;
894 fs = 160256.410;
894 fs = 160256.410;
895 Ts = 1. / fs;
895 Ts = 1. / fs;
896 scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV
896 scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV
897
897
898 time_management_regs->calDataPtr = 0x00;
898 time_management_regs->calDataPtr = 0x00;
899
899
900 // build the signal for the SCM calibration
900 // build the signal for the SCM calibration
901 for (k=0; k<256; k++)
901 for (k=0; k<256; k++)
902 {
902 {
903 val = sin( 2 * pi * f0 * k * Ts )
903 val = sin( 2 * pi * f0 * k * Ts )
904 + sin( 2 * pi * f1 * k * Ts );
904 + sin( 2 * pi * f1 * k * Ts );
905 data = (unsigned short) ((val * scaleFactor) + 2048);
905 data = (unsigned short) ((val * scaleFactor) + 2048);
906 time_management_regs->calData = data & 0xfff;
906 time_management_regs->calData = data & 0xfff;
907 }
907 }
908 }
908 }
909
909
910 void setCalibrationDataInterleaved( void ){
910 void setCalibrationDataInterleaved( void ){
911 unsigned int k;
911 unsigned int k;
912 float val;
912 float val;
913 float f0;
913 float f0;
914 float f1;
914 float f1;
915 float fs;
915 float fs;
916 float Ts;
916 float Ts;
917 unsigned short data[384];
917 unsigned short data[384];
918 unsigned char *dataPtr;
918 unsigned char *dataPtr;
919
919
920 f0 = 625;
920 f0 = 625;
921 f1 = 10000;
921 f1 = 10000;
922 fs = 240384.615;
922 fs = 240384.615;
923 Ts = 1. / fs;
923 Ts = 1. / fs;
924
924
925 time_management_regs->calDataPtr = 0x00;
925 time_management_regs->calDataPtr = 0x00;
926
926
927 // build the signal for the SCM calibration
927 // build the signal for the SCM calibration
928 for (k=0; k<384; k++)
928 for (k=0; k<384; k++)
929 {
929 {
930 val = sin( 2 * pi * f0 * k * Ts )
930 val = sin( 2 * pi * f0 * k * Ts )
931 + sin( 2 * pi * f1 * k * Ts );
931 + sin( 2 * pi * f1 * k * Ts );
932 data[k] = (unsigned short) (val * 512 + 2048);
932 data[k] = (unsigned short) (val * 512 + 2048);
933 }
933 }
934
934
935 // write the signal in interleaved mode
935 // write the signal in interleaved mode
936 for (k=0; k<128; k++)
936 for (k=0; k<128; k++)
937 {
937 {
938 dataPtr = (unsigned char*) &data[k*3 + 2];
938 dataPtr = (unsigned char*) &data[k*3 + 2];
939 time_management_regs->calData = (data[k*3] & 0xfff)
939 time_management_regs->calData = (data[k*3] & 0xfff)
940 + ( (dataPtr[0] & 0x3f) << 12);
940 + ( (dataPtr[0] & 0x3f) << 12);
941 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
941 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
942 + ( (dataPtr[1] & 0x3f) << 12);
942 + ( (dataPtr[1] & 0x3f) << 12);
943 }
943 }
944 }
944 }
945
945
946 void setCalibrationReload( bool state)
946 void setCalibrationReload( bool state)
947 {
947 {
948 if (state == true)
948 if (state == true)
949 {
949 {
950 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
950 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
951 }
951 }
952 else
952 else
953 {
953 {
954 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
954 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
955 }
955 }
956 }
956 }
957
957
958 void setCalibrationEnable( bool state )
958 void setCalibrationEnable( bool state )
959 {
959 {
960 // this bit drives the multiplexer
960 // this bit drives the multiplexer
961 if (state == true)
961 if (state == true)
962 {
962 {
963 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
963 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
964 }
964 }
965 else
965 else
966 {
966 {
967 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
967 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
968 }
968 }
969 }
969 }
970
970
971 void setCalibrationInterleaved( bool state )
971 void setCalibrationInterleaved( bool state )
972 {
972 {
973 // this bit drives the multiplexer
973 // this bit drives the multiplexer
974 if (state == true)
974 if (state == true)
975 {
975 {
976 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
976 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
977 }
977 }
978 else
978 else
979 {
979 {
980 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
980 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
981 }
981 }
982 }
982 }
983
983
984 void startCalibration( void )
984 void setCalibration( bool state )
985 {
985 {
986 setCalibrationEnable( true );
986 if (state == true)
987 setCalibrationReload( false );
987 {
988 setCalibrationEnable( true );
989 setCalibrationReload( false );
990 set_hk_lfr_calib_enable( true );
991 }
992 else
993 {
994 setCalibrationEnable( false );
995 setCalibrationReload( true );
996 set_hk_lfr_calib_enable( false );
997 }
988 }
998 }
989
999
990 void stopCalibration( void )
1000 void set_hk_lfr_calib_enable( bool state )
991 {
1001 {
992 setCalibrationEnable( false );
1002 if (state == true)
993 setCalibrationReload( true );
1003 {
1004 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
1005 }
1006 else
1007 {
1008 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
1009 }
994 }
1010 }
995
1011
996 void configureCalibration( bool interleaved )
1012 void configureCalibration( bool interleaved )
997 {
1013 {
998 stopCalibration();
1014 setCalibration( false );
999 if ( interleaved == true )
1015 if ( interleaved == true )
1000 {
1016 {
1001 setCalibrationInterleaved( true );
1017 setCalibrationInterleaved( true );
1002 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1018 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1003 setCalibrationDivisor( 26 ); // => 240 384
1019 setCalibrationDivisor( 26 ); // => 240 384
1004 setCalibrationDataInterleaved();
1020 setCalibrationDataInterleaved();
1005 }
1021 }
1006 else
1022 else
1007 {
1023 {
1008 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1024 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1009 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
1025 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
1010 setCalibrationData();
1026 setCalibrationData();
1011 }
1027 }
1012 }
1028 }
1013
1029
1014 //****************
1030 //****************
1015 // CLOSING ACTIONS
1031 // CLOSING ACTIONS
1016 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1032 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1017 {
1033 {
1018 /** This function is used to update the HK packets statistics after a successful TC execution.
1034 /** This function is used to update the HK packets statistics after a successful TC execution.
1019 *
1035 *
1020 * @param TC points to the TC being processed
1036 * @param TC points to the TC being processed
1021 * @param time is the time used to date the TC execution
1037 * @param time is the time used to date the TC execution
1022 *
1038 *
1023 */
1039 */
1024
1040
1025 unsigned int val;
1041 unsigned int val;
1026
1042
1027 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1043 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1028 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1044 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1029 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1045 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1030 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1046 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1031 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1047 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1032 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1048 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1033 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
1049 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
1034 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
1050 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
1035 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
1051 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
1036 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
1052 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
1037 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
1053 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
1038 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
1054 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
1039
1055
1040 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1056 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1041 val++;
1057 val++;
1042 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1058 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1043 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1059 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1044 }
1060 }
1045
1061
1046 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1062 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1047 {
1063 {
1048 /** This function is used to update the HK packets statistics after a TC rejection.
1064 /** This function is used to update the HK packets statistics after a TC rejection.
1049 *
1065 *
1050 * @param TC points to the TC being processed
1066 * @param TC points to the TC being processed
1051 * @param time is the time used to date the TC rejection
1067 * @param time is the time used to date the TC rejection
1052 *
1068 *
1053 */
1069 */
1054
1070
1055 unsigned int val;
1071 unsigned int val;
1056
1072
1057 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1073 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1058 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1074 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1059 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1075 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1060 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1076 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1061 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1077 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1062 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1078 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1063 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1079 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1064 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1080 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1065 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1081 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1066 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1082 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1067 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1083 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1068 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1084 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1069
1085
1070 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1086 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1071 val++;
1087 val++;
1072 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1088 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1073 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1089 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1074 }
1090 }
1075
1091
1076 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1092 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1077 {
1093 {
1078 /** This function is the last step of the TC execution workflow.
1094 /** This function is the last step of the TC execution workflow.
1079 *
1095 *
1080 * @param TC points to the TC being processed
1096 * @param TC points to the TC being processed
1081 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1097 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1082 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1098 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1083 * @param time is the time used to date the TC execution
1099 * @param time is the time used to date the TC execution
1084 *
1100 *
1085 */
1101 */
1086
1102
1087 unsigned char requestedMode;
1103 unsigned char requestedMode;
1088
1104
1089 if (result == LFR_SUCCESSFUL)
1105 if (result == LFR_SUCCESSFUL)
1090 {
1106 {
1091 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1107 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1092 &
1108 &
1093 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1109 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1094 )
1110 )
1095 {
1111 {
1096 send_tm_lfr_tc_exe_success( TC, queue_id );
1112 send_tm_lfr_tc_exe_success( TC, queue_id );
1097 }
1113 }
1098 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1114 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1099 {
1115 {
1100 //**********************************
1116 //**********************************
1101 // UPDATE THE LFRMODE LOCAL VARIABLE
1117 // UPDATE THE LFRMODE LOCAL VARIABLE
1102 requestedMode = TC->dataAndCRC[1];
1118 requestedMode = TC->dataAndCRC[1];
1103 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1119 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1104 updateLFRCurrentMode();
1120 updateLFRCurrentMode();
1105 }
1121 }
1106 }
1122 }
1107 else if (result == LFR_EXE_ERROR)
1123 else if (result == LFR_EXE_ERROR)
1108 {
1124 {
1109 send_tm_lfr_tc_exe_error( TC, queue_id );
1125 send_tm_lfr_tc_exe_error( TC, queue_id );
1110 }
1126 }
1111 }
1127 }
1112
1128
1113 //***************************
1129 //***************************
1114 // Interrupt Service Routines
1130 // Interrupt Service Routines
1115 rtems_isr commutation_isr1( rtems_vector_number vector )
1131 rtems_isr commutation_isr1( rtems_vector_number vector )
1116 {
1132 {
1117 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1133 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1118 printf("In commutation_isr1 *** Error sending event to DUMB\n");
1134 printf("In commutation_isr1 *** Error sending event to DUMB\n");
1119 }
1135 }
1120 }
1136 }
1121
1137
1122 rtems_isr commutation_isr2( rtems_vector_number vector )
1138 rtems_isr commutation_isr2( rtems_vector_number vector )
1123 {
1139 {
1124 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1140 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1125 printf("In commutation_isr2 *** Error sending event to DUMB\n");
1141 printf("In commutation_isr2 *** Error sending event to DUMB\n");
1126 }
1142 }
1127 }
1143 }
1128
1144
1129 //****************
1145 //****************
1130 // OTHER FUNCTIONS
1146 // OTHER FUNCTIONS
1131 void updateLFRCurrentMode()
1147 void updateLFRCurrentMode()
1132 {
1148 {
1133 /** This function updates the value of the global variable lfrCurrentMode.
1149 /** This function updates the value of the global variable lfrCurrentMode.
1134 *
1150 *
1135 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1151 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1136 *
1152 *
1137 */
1153 */
1138 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1154 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1139 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
1155 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
1140 }
1156 }
1141
1157
1142 void set_lfr_soft_reset( unsigned char value )
1158 void set_lfr_soft_reset( unsigned char value )
1143 {
1159 {
1144 if (value == 1)
1160 if (value == 1)
1145 {
1161 {
1146 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1162 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1147 }
1163 }
1148 else
1164 else
1149 {
1165 {
1150 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1166 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1151 }
1167 }
1152 }
1168 }
1153
1169
1154 void reset_lfr( void )
1170 void reset_lfr( void )
1155 {
1171 {
1156 set_lfr_soft_reset( 1 );
1172 set_lfr_soft_reset( 1 );
1157
1173
1158 set_lfr_soft_reset( 0 );
1174 set_lfr_soft_reset( 0 );
1159 }
1175 }
General Comments 0
You need to be logged in to leave comments. Login now