@@ -1,131 +1,131 | |||||
1 | #ifndef FSW_MISC_H_INCLUDED |
|
1 | #ifndef FSW_MISC_H_INCLUDED | |
2 | #define FSW_MISC_H_INCLUDED |
|
2 | #define FSW_MISC_H_INCLUDED | |
3 |
|
3 | |||
4 | #include <rtems.h> |
|
4 | #include <rtems.h> | |
5 | #include <stdio.h> |
|
5 | #include <stdio.h> | |
6 | #include <grspw.h> |
|
6 | #include <grspw.h> | |
7 | #include <grlib_regs.h> |
|
7 | #include <grlib_regs.h> | |
8 |
|
8 | |||
9 | #include "fsw_params.h" |
|
9 | #include "fsw_params.h" | |
10 | #include "fsw_spacewire.h" |
|
10 | #include "fsw_spacewire.h" | |
11 | #include "lfr_cpu_usage_report.h" |
|
11 | #include "lfr_cpu_usage_report.h" | |
12 |
|
12 | |||
13 | #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0 |
|
13 | #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0 | |
14 | #define WATCHDOG_LOOP_PRINTF 10 |
|
14 | #define WATCHDOG_LOOP_PRINTF 10 | |
15 | #define WATCHDOG_LOOP_DEBUG 3 |
|
15 | #define WATCHDOG_LOOP_DEBUG 3 | |
16 |
|
16 | |||
17 | #define DUMB_MESSAGE_NB 15 |
|
17 | #define DUMB_MESSAGE_NB 15 | |
18 | #define NB_RTEMS_EVENTS 32 |
|
18 | #define NB_RTEMS_EVENTS 32 | |
19 | #define EVENT_12 12 |
|
19 | #define EVENT_12 12 | |
20 | #define EVENT_13 13 |
|
20 | #define EVENT_13 13 | |
21 | #define EVENT_14 14 |
|
21 | #define EVENT_14 14 | |
22 | #define DUMB_MESSAGE_0 "in DUMB *** default" |
|
22 | #define DUMB_MESSAGE_0 "in DUMB *** default" | |
23 | #define DUMB_MESSAGE_1 "in DUMB *** timecode_irq_handler" |
|
23 | #define DUMB_MESSAGE_1 "in DUMB *** timecode_irq_handler" | |
24 | #define DUMB_MESSAGE_2 "in DUMB *** f3 buffer changed" |
|
24 | #define DUMB_MESSAGE_2 "in DUMB *** f3 buffer changed" | |
25 | #define DUMB_MESSAGE_3 "in DUMB *** in SMIQ *** Error sending event to AVF0" |
|
25 | #define DUMB_MESSAGE_3 "in DUMB *** in SMIQ *** Error sending event to AVF0" | |
26 | #define DUMB_MESSAGE_4 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ" |
|
26 | #define DUMB_MESSAGE_4 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ" | |
27 | #define DUMB_MESSAGE_5 "in DUMB *** waveforms_simulator_isr" |
|
27 | #define DUMB_MESSAGE_5 "in DUMB *** waveforms_simulator_isr" | |
28 | #define DUMB_MESSAGE_6 "VHDL SM *** two buffers f0 ready" |
|
28 | #define DUMB_MESSAGE_6 "VHDL SM *** two buffers f0 ready" | |
29 | #define DUMB_MESSAGE_7 "ready for dump" |
|
29 | #define DUMB_MESSAGE_7 "ready for dump" | |
30 | #define DUMB_MESSAGE_8 "VHDL ERR *** spectral matrix" |
|
30 | #define DUMB_MESSAGE_8 "VHDL ERR *** spectral matrix" | |
31 | #define DUMB_MESSAGE_9 "tick" |
|
31 | #define DUMB_MESSAGE_9 "tick" | |
32 | #define DUMB_MESSAGE_10 "VHDL ERR *** waveform picker" |
|
32 | #define DUMB_MESSAGE_10 "VHDL ERR *** waveform picker" | |
33 | #define DUMB_MESSAGE_11 "VHDL ERR *** unexpected ready matrix values" |
|
33 | #define DUMB_MESSAGE_11 "VHDL ERR *** unexpected ready matrix values" | |
34 | #define DUMB_MESSAGE_12 "WATCHDOG timer" |
|
34 | #define DUMB_MESSAGE_12 "WATCHDOG timer" | |
35 | #define DUMB_MESSAGE_13 "TIMECODE timer" |
|
35 | #define DUMB_MESSAGE_13 "TIMECODE timer" | |
36 | #define DUMB_MESSAGE_14 "TIMECODE ISR" |
|
36 | #define DUMB_MESSAGE_14 "TIMECODE ISR" | |
37 |
|
37 | |||
38 | enum lfr_reset_cause_t{ |
|
38 | enum lfr_reset_cause_t{ | |
39 | UNKNOWN_CAUSE, |
|
39 | UNKNOWN_CAUSE, | |
40 | POWER_ON, |
|
40 | POWER_ON, | |
41 | TC_RESET, |
|
41 | TC_RESET, | |
42 | WATCHDOG, |
|
42 | WATCHDOG, | |
43 | ERROR_RESET, |
|
43 | ERROR_RESET, | |
44 | UNEXP_RESET |
|
44 | UNEXP_RESET | |
45 | }; |
|
45 | }; | |
46 |
|
46 | |||
47 | typedef struct{ |
|
47 | typedef struct{ | |
48 | unsigned char dpu_spw_parity; |
|
48 | unsigned char dpu_spw_parity; | |
49 | unsigned char dpu_spw_disconnect; |
|
49 | unsigned char dpu_spw_disconnect; | |
50 | unsigned char dpu_spw_escape; |
|
50 | unsigned char dpu_spw_escape; | |
51 | unsigned char dpu_spw_credit; |
|
51 | unsigned char dpu_spw_credit; | |
52 | unsigned char dpu_spw_write_sync; |
|
52 | unsigned char dpu_spw_write_sync; | |
53 | unsigned char timecode_erroneous; |
|
53 | unsigned char timecode_erroneous; | |
54 | unsigned char timecode_missing; |
|
54 | unsigned char timecode_missing; | |
55 | unsigned char timecode_invalid; |
|
55 | unsigned char timecode_invalid; | |
56 | unsigned char time_timecode_it; |
|
56 | unsigned char time_timecode_it; | |
57 | unsigned char time_not_synchro; |
|
57 | unsigned char time_not_synchro; | |
58 | unsigned char time_timecode_ctr; |
|
58 | unsigned char time_timecode_ctr; | |
59 | unsigned char ahb_correctable; |
|
59 | unsigned char ahb_correctable; | |
60 | } hk_lfr_le_t; |
|
60 | } hk_lfr_le_t; | |
61 |
|
61 | |||
62 | typedef struct{ |
|
62 | typedef struct{ | |
63 | unsigned char dpu_spw_early_eop; |
|
63 | unsigned char dpu_spw_early_eop; | |
64 | unsigned char dpu_spw_invalid_addr; |
|
64 | unsigned char dpu_spw_invalid_addr; | |
65 | unsigned char dpu_spw_eep; |
|
65 | unsigned char dpu_spw_eep; | |
66 | unsigned char dpu_spw_rx_too_big; |
|
66 | unsigned char dpu_spw_rx_too_big; | |
67 | } hk_lfr_me_t; |
|
67 | } hk_lfr_me_t; | |
68 |
|
68 | |||
69 | extern gptimer_regs_t *gptimer_regs; |
|
69 | extern gptimer_regs_t *gptimer_regs; | |
70 | extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* ); |
|
70 | extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* ); | |
71 | extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* ); |
|
71 | extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* ); | |
72 |
|
72 | |||
73 |
rtems_name name_hk_rate_monotonic |
|
73 | extern rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic | |
74 |
rtems_id HK_id |
|
74 | extern rtems_id HK_id;// id of the HK rate monotonic period | |
75 |
rtems_name name_avgv_rate_monotonic |
|
75 | extern rtems_name name_avgv_rate_monotonic; // name of the AVGV rate monotonic | |
76 |
rtems_id AVGV_id |
|
76 | extern rtems_id AVGV_id;// id of the AVGV rate monotonic period | |
77 |
|
77 | |||
78 | void timer_configure( unsigned char timer, unsigned int clock_divider, |
|
78 | void timer_configure( unsigned char timer, unsigned int clock_divider, | |
79 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); |
|
79 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); | |
80 | void timer_start( unsigned char timer ); |
|
80 | void timer_start( unsigned char timer ); | |
81 | void timer_stop( unsigned char timer ); |
|
81 | void timer_stop( unsigned char timer ); | |
82 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider); |
|
82 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider); | |
83 |
|
83 | |||
84 | // WATCHDOG |
|
84 | // WATCHDOG | |
85 | rtems_isr watchdog_isr( rtems_vector_number vector ); |
|
85 | rtems_isr watchdog_isr( rtems_vector_number vector ); | |
86 | void watchdog_configure(void); |
|
86 | void watchdog_configure(void); | |
87 | void watchdog_stop(void); |
|
87 | void watchdog_stop(void); | |
88 | void watchdog_reload(void); |
|
88 | void watchdog_reload(void); | |
89 | void watchdog_start(void); |
|
89 | void watchdog_start(void); | |
90 |
|
90 | |||
91 | // SERIAL LINK |
|
91 | // SERIAL LINK | |
92 | int send_console_outputs_on_apbuart_port( void ); |
|
92 | int send_console_outputs_on_apbuart_port( void ); | |
93 | int enable_apbuart_transmitter( void ); |
|
93 | int enable_apbuart_transmitter( void ); | |
94 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); |
|
94 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); | |
95 |
|
95 | |||
96 | // RTEMS TASKS |
|
96 | // RTEMS TASKS | |
97 | rtems_task load_task( rtems_task_argument argument ); |
|
97 | rtems_task load_task( rtems_task_argument argument ); | |
98 | rtems_task hous_task( rtems_task_argument argument ); |
|
98 | rtems_task hous_task( rtems_task_argument argument ); | |
99 | rtems_task avgv_task( rtems_task_argument argument ); |
|
99 | rtems_task avgv_task( rtems_task_argument argument ); | |
100 | rtems_task dumb_task( rtems_task_argument unused ); |
|
100 | rtems_task dumb_task( rtems_task_argument unused ); | |
101 |
|
101 | |||
102 | void init_housekeeping_parameters( void ); |
|
102 | void init_housekeeping_parameters( void ); | |
103 | void increment_seq_counter(unsigned short *packetSequenceControl); |
|
103 | void increment_seq_counter(unsigned short *packetSequenceControl); | |
104 | void getTime( unsigned char *time); |
|
104 | void getTime( unsigned char *time); | |
105 | unsigned long long int getTimeAsUnsignedLongLongInt( ); |
|
105 | unsigned long long int getTimeAsUnsignedLongLongInt( ); | |
106 | void send_dumb_hk( void ); |
|
106 | void send_dumb_hk( void ); | |
107 | void get_temperatures( unsigned char *temperatures ); |
|
107 | void get_temperatures( unsigned char *temperatures ); | |
108 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); |
|
108 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); | |
109 | void get_cpu_load( unsigned char *resource_statistics ); |
|
109 | void get_cpu_load( unsigned char *resource_statistics ); | |
110 | void set_hk_lfr_sc_potential_flag( bool state ); |
|
110 | void set_hk_lfr_sc_potential_flag( bool state ); | |
111 | void set_sy_lfr_pas_filter_enabled( bool state ); |
|
111 | void set_sy_lfr_pas_filter_enabled( bool state ); | |
112 | void set_sy_lfr_watchdog_enabled( bool state ); |
|
112 | void set_sy_lfr_watchdog_enabled( bool state ); | |
113 | void set_hk_lfr_calib_enable( bool state ); |
|
113 | void set_hk_lfr_calib_enable( bool state ); | |
114 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ); |
|
114 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ); | |
115 | void hk_lfr_le_me_he_update(); |
|
115 | void hk_lfr_le_me_he_update(); | |
116 | void set_hk_lfr_time_not_synchro(); |
|
116 | void set_hk_lfr_time_not_synchro(); | |
117 |
|
117 | |||
118 | extern int sched_yield( void ); |
|
118 | extern int sched_yield( void ); | |
119 | extern void rtems_cpu_usage_reset(); |
|
119 | extern void rtems_cpu_usage_reset(); | |
120 | extern ring_node *current_ring_node_f3; |
|
120 | extern ring_node *current_ring_node_f3; | |
121 | extern ring_node *ring_node_to_send_cwf_f3; |
|
121 | extern ring_node *ring_node_to_send_cwf_f3; | |
122 | extern ring_node waveform_ring_f3[]; |
|
122 | extern ring_node waveform_ring_f3[]; | |
123 | extern unsigned short sequenceCounterHK; |
|
123 | extern unsigned short sequenceCounterHK; | |
124 |
|
124 | |||
125 | extern unsigned char hk_lfr_q_sd_fifo_size_max; |
|
125 | extern unsigned char hk_lfr_q_sd_fifo_size_max; | |
126 | extern unsigned char hk_lfr_q_rv_fifo_size_max; |
|
126 | extern unsigned char hk_lfr_q_rv_fifo_size_max; | |
127 | extern unsigned char hk_lfr_q_p0_fifo_size_max; |
|
127 | extern unsigned char hk_lfr_q_p0_fifo_size_max; | |
128 | extern unsigned char hk_lfr_q_p1_fifo_size_max; |
|
128 | extern unsigned char hk_lfr_q_p1_fifo_size_max; | |
129 | extern unsigned char hk_lfr_q_p2_fifo_size_max; |
|
129 | extern unsigned char hk_lfr_q_p2_fifo_size_max; | |
130 |
|
130 | |||
131 | #endif // FSW_MISC_H_INCLUDED |
|
131 | #endif // FSW_MISC_H_INCLUDED |
@@ -1,102 +1,106 | |||||
1 | /** Global variables of the LFR flight software. |
|
1 | /** Global variables of the LFR flight software. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | * Among global variables, there are: |
|
6 | * Among global variables, there are: | |
7 | * - RTEMS names and id. |
|
7 | * - RTEMS names and id. | |
8 | * - APB configuration registers. |
|
8 | * - APB configuration registers. | |
9 | * - waveforms global buffers, used by the waveform picker hardware module to store data. |
|
9 | * - waveforms global buffers, used by the waveform picker hardware module to store data. | |
10 | * - spectral matrices buffesr, used by the hardware module to store data. |
|
10 | * - spectral matrices buffesr, used by the hardware module to store data. | |
11 | * - variable related to LFR modes parameters. |
|
11 | * - variable related to LFR modes parameters. | |
12 | * - the global HK packet buffer. |
|
12 | * - the global HK packet buffer. | |
13 | * - the global dump parameter buffer. |
|
13 | * - the global dump parameter buffer. | |
14 | * |
|
14 | * | |
15 | */ |
|
15 | */ | |
16 |
|
16 | |||
17 | #include <rtems.h> |
|
17 | #include <rtems.h> | |
18 | #include <grspw.h> |
|
18 | #include <grspw.h> | |
19 |
|
19 | |||
20 | #include "ccsds_types.h" |
|
20 | #include "ccsds_types.h" | |
21 | #include "grlib_regs.h" |
|
21 | #include "grlib_regs.h" | |
22 | #include "fsw_params.h" |
|
22 | #include "fsw_params.h" | |
23 | #include "fsw_params_wf_handler.h" |
|
23 | #include "fsw_params_wf_handler.h" | |
24 |
|
24 | |||
25 | #define NB_OF_TASKS 20 |
|
25 | #define NB_OF_TASKS 20 | |
26 | #define NB_OF_MISC_NAMES 5 |
|
26 | #define NB_OF_MISC_NAMES 5 | |
27 |
|
27 | |||
28 | // RTEMS GLOBAL VARIABLES |
|
28 | // RTEMS GLOBAL VARIABLES | |
29 | rtems_name misc_name[NB_OF_MISC_NAMES] = {0}; |
|
29 | rtems_name misc_name[NB_OF_MISC_NAMES] = {0}; | |
30 | rtems_name Task_name[NB_OF_TASKS] = {0}; /* array of task names */ |
|
30 | rtems_name Task_name[NB_OF_TASKS] = {0}; /* array of task names */ | |
31 | rtems_id Task_id[NB_OF_TASKS] = {0}; /* array of task ids */ |
|
31 | rtems_id Task_id[NB_OF_TASKS] = {0}; /* array of task ids */ | |
32 |
rtems_name timecode_timer_name = |
|
32 | rtems_name timecode_timer_name = 0; | |
33 |
rtems_id timecode_timer_id = |
|
33 | rtems_id timecode_timer_id = RTEMS_ID_NONE; | |
|
34 | rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic | |||
|
35 | rtems_id HK_id = RTEMS_ID_NONE;// id of the HK rate monotonic period | |||
|
36 | rtems_name name_avgv_rate_monotonic = 0; // name of the AVGV rate monotonic | |||
|
37 | rtems_id AVGV_id = RTEMS_ID_NONE;// id of the AVGV rate monotonic period | |||
34 | int fdSPW = 0; |
|
38 | int fdSPW = 0; | |
35 | int fdUART = 0; |
|
39 | int fdUART = 0; | |
36 | unsigned char lfrCurrentMode = 0; |
|
40 | unsigned char lfrCurrentMode = 0; | |
37 | unsigned char pa_bia_status_info = 0; |
|
41 | unsigned char pa_bia_status_info = 0; | |
38 | unsigned char thisIsAnASMRestart = 0; |
|
42 | unsigned char thisIsAnASMRestart = 0; | |
39 | unsigned char oneTcLfrUpdateTimeReceived = 0; |
|
43 | unsigned char oneTcLfrUpdateTimeReceived = 0; | |
40 |
|
44 | |||
41 | // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584 |
|
45 | // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584 | |
42 | // 97 * 256 = 24832 => delta = 248 bytes = 62 words |
|
46 | // 97 * 256 = 24832 => delta = 248 bytes = 62 words | |
43 | // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264 |
|
47 | // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264 | |
44 | // 127 * 256 = 32512 => delta = 248 bytes = 62 words |
|
48 | // 127 * 256 = 32512 => delta = 248 bytes = 62 words | |
45 | // F0 F1 F2 F3 |
|
49 | // F0 F1 F2 F3 | |
46 | volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; |
|
50 | volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; | |
47 | volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; |
|
51 | volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; | |
48 | volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; |
|
52 | volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; | |
49 | volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; |
|
53 | volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0}; | |
50 |
|
54 | |||
51 | //*********************************** |
|
55 | //*********************************** | |
52 | // SPECTRAL MATRICES GLOBAL VARIABLES |
|
56 | // SPECTRAL MATRICES GLOBAL VARIABLES | |
53 |
|
57 | |||
54 | // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00 |
|
58 | // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00 | |
55 | volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0}; |
|
59 | volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0}; | |
56 | volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0}; |
|
60 | volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0}; | |
57 | volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0}; |
|
61 | volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0}; | |
58 |
|
62 | |||
59 | // APB CONFIGURATION REGISTERS |
|
63 | // APB CONFIGURATION REGISTERS | |
60 | time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT; |
|
64 | time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT; | |
61 | gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; |
|
65 | gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; | |
62 | waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER; |
|
66 | waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER; | |
63 | spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX; |
|
67 | spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX; | |
64 |
|
68 | |||
65 | // MODE PARAMETERS |
|
69 | // MODE PARAMETERS | |
66 | Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0}; |
|
70 | Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0}; | |
67 | struct param_local_str param_local = {0}; |
|
71 | struct param_local_str param_local = {0}; | |
68 | unsigned int lastValidEnterModeTime = {0}; |
|
72 | unsigned int lastValidEnterModeTime = {0}; | |
69 |
|
73 | |||
70 | // HK PACKETS |
|
74 | // HK PACKETS | |
71 | Packet_TM_LFR_HK_t housekeeping_packet = {0}; |
|
75 | Packet_TM_LFR_HK_t housekeeping_packet = {0}; | |
72 | unsigned char cp_rpw_sc_rw_f_flags = 0; |
|
76 | unsigned char cp_rpw_sc_rw_f_flags = 0; | |
73 | // message queues occupancy |
|
77 | // message queues occupancy | |
74 | unsigned char hk_lfr_q_sd_fifo_size_max = 0; |
|
78 | unsigned char hk_lfr_q_sd_fifo_size_max = 0; | |
75 | unsigned char hk_lfr_q_rv_fifo_size_max = 0; |
|
79 | unsigned char hk_lfr_q_rv_fifo_size_max = 0; | |
76 | unsigned char hk_lfr_q_p0_fifo_size_max = 0; |
|
80 | unsigned char hk_lfr_q_p0_fifo_size_max = 0; | |
77 | unsigned char hk_lfr_q_p1_fifo_size_max = 0; |
|
81 | unsigned char hk_lfr_q_p1_fifo_size_max = 0; | |
78 | unsigned char hk_lfr_q_p2_fifo_size_max = 0; |
|
82 | unsigned char hk_lfr_q_p2_fifo_size_max = 0; | |
79 | // sequence counters are incremented by APID (PID + CAT) and destination ID |
|
83 | // sequence counters are incremented by APID (PID + CAT) and destination ID | |
80 | unsigned short sequenceCounters_SCIENCE_NORMAL_BURST = 0; |
|
84 | unsigned short sequenceCounters_SCIENCE_NORMAL_BURST = 0; | |
81 | unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 = 0; |
|
85 | unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 = 0; | |
82 | unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] = {0}; |
|
86 | unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] = {0}; | |
83 | unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] = {0}; |
|
87 | unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] = {0}; | |
84 | unsigned short sequenceCounterHK; |
|
88 | unsigned short sequenceCounterHK; | |
85 | spw_stats grspw_stats = {0}; |
|
89 | spw_stats grspw_stats = {0}; | |
86 |
|
90 | |||
87 | // TC_LFR_UPDATE_INFO |
|
91 | // TC_LFR_UPDATE_INFO | |
88 | float cp_rpw_sc_rw1_f1 = INIT_FLOAT; |
|
92 | float cp_rpw_sc_rw1_f1 = INIT_FLOAT; | |
89 | float cp_rpw_sc_rw1_f2 = INIT_FLOAT; |
|
93 | float cp_rpw_sc_rw1_f2 = INIT_FLOAT; | |
90 | float cp_rpw_sc_rw2_f1 = INIT_FLOAT; |
|
94 | float cp_rpw_sc_rw2_f1 = INIT_FLOAT; | |
91 | float cp_rpw_sc_rw2_f2 = INIT_FLOAT; |
|
95 | float cp_rpw_sc_rw2_f2 = INIT_FLOAT; | |
92 | float cp_rpw_sc_rw3_f1 = INIT_FLOAT; |
|
96 | float cp_rpw_sc_rw3_f1 = INIT_FLOAT; | |
93 | float cp_rpw_sc_rw3_f2 = INIT_FLOAT; |
|
97 | float cp_rpw_sc_rw3_f2 = INIT_FLOAT; | |
94 | float cp_rpw_sc_rw4_f1 = INIT_FLOAT; |
|
98 | float cp_rpw_sc_rw4_f1 = INIT_FLOAT; | |
95 | float cp_rpw_sc_rw4_f2 = INIT_FLOAT; |
|
99 | float cp_rpw_sc_rw4_f2 = INIT_FLOAT; | |
96 |
|
100 | |||
97 | // TC_LFR_LOAD_FILTER_PAR |
|
101 | // TC_LFR_LOAD_FILTER_PAR | |
98 | filterPar_t filterPar = {0}; |
|
102 | filterPar_t filterPar = {0}; | |
99 |
|
103 | |||
100 | fbins_masks_t fbins_masks = {0}; |
|
104 | fbins_masks_t fbins_masks = {0}; | |
101 | unsigned int acquisitionDurations[NB_ACQUISITION_DURATION] |
|
105 | unsigned int acquisitionDurations[NB_ACQUISITION_DURATION] | |
102 | = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2}; |
|
106 | = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2}; |
@@ -1,1631 +1,1631 | |||||
1 | /** Functions related to the SpaceWire interface. |
|
1 | /** Functions related to the SpaceWire interface. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | * A group of functions to handle SpaceWire transmissions: |
|
6 | * A group of functions to handle SpaceWire transmissions: | |
7 | * - configuration of the SpaceWire link |
|
7 | * - configuration of the SpaceWire link | |
8 | * - SpaceWire related interruption requests processing |
|
8 | * - SpaceWire related interruption requests processing | |
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task |
|
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task | |
10 | * - reception of TeleCommands by a dedicated RTEMS task |
|
10 | * - reception of TeleCommands by a dedicated RTEMS task | |
11 | * |
|
11 | * | |
12 | */ |
|
12 | */ | |
13 |
|
13 | |||
14 | #include "fsw_spacewire.h" |
|
14 | #include "fsw_spacewire.h" | |
15 |
|
15 | |||
16 | rtems_name semq_name = 0; |
|
16 | rtems_name semq_name = 0; | |
17 | rtems_id semq_id = RTEMS_ID_NONE; |
|
17 | rtems_id semq_id = RTEMS_ID_NONE; | |
18 |
|
18 | |||
19 | //***************** |
|
19 | //***************** | |
20 | // waveform headers |
|
20 | // waveform headers | |
21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0}; |
|
21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0}; | |
22 |
Header_TM_LFR_SCIENCE_SWF_t headerSW |
|
22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0}; | |
23 | Header_TM_LFR_SCIENCE_ASM_t headerASM = {0}; |
|
23 | Header_TM_LFR_SCIENCE_ASM_t headerASM = {0}; | |
24 |
|
24 | |||
25 | unsigned char previousTimecodeCtr = 0; |
|
25 | unsigned char previousTimecodeCtr = 0; | |
26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); |
|
26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); | |
27 |
|
27 | |||
28 | //*********** |
|
28 | //*********** | |
29 | // RTEMS TASK |
|
29 | // RTEMS TASK | |
30 | rtems_task spiq_task(rtems_task_argument unused) |
|
30 | rtems_task spiq_task(rtems_task_argument unused) | |
31 | { |
|
31 | { | |
32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. |
|
32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. | |
33 | * |
|
33 | * | |
34 | * @param unused is the starting argument of the RTEMS task |
|
34 | * @param unused is the starting argument of the RTEMS task | |
35 | * |
|
35 | * | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | rtems_event_set event_out; |
|
38 | rtems_event_set event_out; | |
39 | rtems_status_code status; |
|
39 | rtems_status_code status; | |
40 | int linkStatus; |
|
40 | int linkStatus; | |
41 |
|
41 | |||
42 | event_out = EVENT_SETS_NONE_PENDING; |
|
42 | event_out = EVENT_SETS_NONE_PENDING; | |
43 | linkStatus = 0; |
|
43 | linkStatus = 0; | |
44 |
|
44 | |||
45 | BOOT_PRINTF("in SPIQ *** \n") |
|
45 | BOOT_PRINTF("in SPIQ *** \n") | |
46 |
|
46 | |||
47 | while(true){ |
|
47 | while(true){ | |
48 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
48 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT | |
49 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") |
|
49 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") | |
50 |
|
50 | |||
51 | // [0] SUSPEND RECV AND SEND TASKS |
|
51 | // [0] SUSPEND RECV AND SEND TASKS | |
52 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); |
|
52 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); | |
53 | if ( status != RTEMS_SUCCESSFUL ) { |
|
53 | if ( status != RTEMS_SUCCESSFUL ) { | |
54 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") |
|
54 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") | |
55 | } |
|
55 | } | |
56 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); |
|
56 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); | |
57 | if ( status != RTEMS_SUCCESSFUL ) { |
|
57 | if ( status != RTEMS_SUCCESSFUL ) { | |
58 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") |
|
58 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | // [1] CHECK THE LINK |
|
61 | // [1] CHECK THE LINK | |
62 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) |
|
62 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) | |
63 | if ( linkStatus != SPW_LINK_OK) { |
|
63 | if ( linkStatus != SPW_LINK_OK) { | |
64 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) |
|
64 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) | |
65 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
65 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT |
|
68 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT | |
69 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) |
|
69 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) | |
70 | if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link |
|
70 | if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link | |
71 | { |
|
71 | { | |
72 | spacewire_read_statistics(); |
|
72 | spacewire_read_statistics(); | |
73 | status = spacewire_several_connect_attemps( ); |
|
73 | status = spacewire_several_connect_attemps( ); | |
74 | } |
|
74 | } | |
75 | else // [2.b] in run state, start the link |
|
75 | else // [2.b] in run state, start the link | |
76 | { |
|
76 | { | |
77 | status = spacewire_stop_and_start_link( fdSPW ); // start the link |
|
77 | status = spacewire_stop_and_start_link( fdSPW ); // start the link | |
78 | if ( status != RTEMS_SUCCESSFUL) |
|
78 | if ( status != RTEMS_SUCCESSFUL) | |
79 | { |
|
79 | { | |
80 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) |
|
80 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS |
|
84 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS | |
85 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully |
|
85 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully | |
86 | { |
|
86 | { | |
87 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
87 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
88 | if ( status != RTEMS_SUCCESSFUL ) { |
|
88 | if ( status != RTEMS_SUCCESSFUL ) { | |
89 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") |
|
89 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") | |
90 | } |
|
90 | } | |
91 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
91 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
92 | if ( status != RTEMS_SUCCESSFUL ) { |
|
92 | if ( status != RTEMS_SUCCESSFUL ) { | |
93 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") |
|
93 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 | else // [3.b] the link is not in run state, go in STANDBY mode |
|
96 | else // [3.b] the link is not in run state, go in STANDBY mode | |
97 | { |
|
97 | { | |
98 | status = enter_mode_standby(); |
|
98 | status = enter_mode_standby(); | |
99 | if ( status != RTEMS_SUCCESSFUL ) |
|
99 | if ( status != RTEMS_SUCCESSFUL ) | |
100 | { |
|
100 | { | |
101 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) |
|
101 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) | |
102 | } |
|
102 | } | |
103 | { |
|
103 | { | |
104 | updateLFRCurrentMode( LFR_MODE_STANDBY ); |
|
104 | updateLFRCurrentMode( LFR_MODE_STANDBY ); | |
105 | } |
|
105 | } | |
106 | // wake the LINK task up to wait for the link recovery |
|
106 | // wake the LINK task up to wait for the link recovery | |
107 | status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 ); |
|
107 | status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 ); | |
108 | status = rtems_task_suspend( RTEMS_SELF ); |
|
108 | status = rtems_task_suspend( RTEMS_SELF ); | |
109 | } |
|
109 | } | |
110 | } |
|
110 | } | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | rtems_task recv_task( rtems_task_argument unused ) |
|
113 | rtems_task recv_task( rtems_task_argument unused ) | |
114 | { |
|
114 | { | |
115 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. |
|
115 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. | |
116 | * |
|
116 | * | |
117 | * @param unused is the starting argument of the RTEMS task |
|
117 | * @param unused is the starting argument of the RTEMS task | |
118 | * |
|
118 | * | |
119 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: |
|
119 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: | |
120 | * 1. It reads the incoming data. |
|
120 | * 1. It reads the incoming data. | |
121 | * 2. Launches the acceptance procedure. |
|
121 | * 2. Launches the acceptance procedure. | |
122 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. |
|
122 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. | |
123 | * |
|
123 | * | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | int len; |
|
126 | int len; | |
127 | ccsdsTelecommandPacket_t currentTC; |
|
127 | ccsdsTelecommandPacket_t currentTC; | |
128 | unsigned char computed_CRC[ BYTES_PER_CRC ]; |
|
128 | unsigned char computed_CRC[ BYTES_PER_CRC ]; | |
129 | unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ]; |
|
129 | unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ]; | |
130 | unsigned char destinationID; |
|
130 | unsigned char destinationID; | |
131 | unsigned int estimatedPacketLength; |
|
131 | unsigned int estimatedPacketLength; | |
132 | unsigned int parserCode; |
|
132 | unsigned int parserCode; | |
133 | rtems_status_code status; |
|
133 | rtems_status_code status; | |
134 | rtems_id queue_recv_id; |
|
134 | rtems_id queue_recv_id; | |
135 | rtems_id queue_send_id; |
|
135 | rtems_id queue_send_id; | |
136 |
|
136 | |||
137 | memset( ¤tTC, 0, sizeof(ccsdsTelecommandPacket_t) ); |
|
137 | memset( ¤tTC, 0, sizeof(ccsdsTelecommandPacket_t) ); | |
138 | destinationID = 0; |
|
138 | destinationID = 0; | |
139 | queue_recv_id = RTEMS_ID_NONE; |
|
139 | queue_recv_id = RTEMS_ID_NONE; | |
140 | queue_send_id = RTEMS_ID_NONE; |
|
140 | queue_send_id = RTEMS_ID_NONE; | |
141 |
|
141 | |||
142 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes |
|
142 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes | |
143 |
|
143 | |||
144 | status = get_message_queue_id_recv( &queue_recv_id ); |
|
144 | status = get_message_queue_id_recv( &queue_recv_id ); | |
145 | if (status != RTEMS_SUCCESSFUL) |
|
145 | if (status != RTEMS_SUCCESSFUL) | |
146 | { |
|
146 | { | |
147 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) |
|
147 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | status = get_message_queue_id_send( &queue_send_id ); |
|
150 | status = get_message_queue_id_send( &queue_send_id ); | |
151 | if (status != RTEMS_SUCCESSFUL) |
|
151 | if (status != RTEMS_SUCCESSFUL) | |
152 | { |
|
152 | { | |
153 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) |
|
153 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | BOOT_PRINTF("in RECV *** \n") |
|
156 | BOOT_PRINTF("in RECV *** \n") | |
157 |
|
157 | |||
158 | while(1) |
|
158 | while(1) | |
159 | { |
|
159 | { | |
160 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking |
|
160 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking | |
161 | if (len == -1){ // error during the read call |
|
161 | if (len == -1){ // error during the read call | |
162 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) |
|
162 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) | |
163 | } |
|
163 | } | |
164 | else { |
|
164 | else { | |
165 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { |
|
165 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { | |
166 | PRINTF("in RECV *** packet lenght too short\n") |
|
166 | PRINTF("in RECV *** packet lenght too short\n") | |
167 | } |
|
167 | } | |
168 | else { |
|
168 | else { | |
169 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes |
|
169 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes | |
170 | //PRINTF1("incoming TC with Length (byte): %d\n", len - 3); |
|
170 | //PRINTF1("incoming TC with Length (byte): %d\n", len - 3); | |
171 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE); |
|
171 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE); | |
172 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); |
|
172 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); | |
173 | // CHECK THE TC |
|
173 | // CHECK THE TC | |
174 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; |
|
174 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; | |
175 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) |
|
175 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) | |
176 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) |
|
176 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) | |
177 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) |
|
177 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) | |
178 | || (parserCode == WRONG_SRC_ID) ) |
|
178 | || (parserCode == WRONG_SRC_ID) ) | |
179 | { // send TM_LFR_TC_EXE_CORRUPTED |
|
179 | { // send TM_LFR_TC_EXE_CORRUPTED | |
180 | PRINTF1("TC corrupted received, with code: %d\n", parserCode); |
|
180 | PRINTF1("TC corrupted received, with code: %d\n", parserCode); | |
181 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
181 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
182 | && |
|
182 | && | |
183 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
183 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
184 | ) |
|
184 | ) | |
185 | { |
|
185 | { | |
186 | if ( parserCode == WRONG_SRC_ID ) |
|
186 | if ( parserCode == WRONG_SRC_ID ) | |
187 | { |
|
187 | { | |
188 | destinationID = SID_TC_GROUND; |
|
188 | destinationID = SID_TC_GROUND; | |
189 | } |
|
189 | } | |
190 | else |
|
190 | else | |
191 | { |
|
191 | { | |
192 | destinationID = currentTC.sourceID; |
|
192 | destinationID = currentTC.sourceID; | |
193 | } |
|
193 | } | |
194 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, |
|
194 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, | |
195 | computed_CRC, currentTC_LEN_RCV, |
|
195 | computed_CRC, currentTC_LEN_RCV, | |
196 | destinationID ); |
|
196 | destinationID ); | |
197 | } |
|
197 | } | |
198 | } |
|
198 | } | |
199 | else |
|
199 | else | |
200 | { // send valid TC to the action launcher |
|
200 | { // send valid TC to the action launcher | |
201 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, |
|
201 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, | |
202 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP); |
|
202 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP); | |
203 | } |
|
203 | } | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); |
|
207 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); | |
208 |
|
208 | |||
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | rtems_task send_task( rtems_task_argument argument) |
|
212 | rtems_task send_task( rtems_task_argument argument) | |
213 | { |
|
213 | { | |
214 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. |
|
214 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. | |
215 | * |
|
215 | * | |
216 | * @param unused is the starting argument of the RTEMS task |
|
216 | * @param unused is the starting argument of the RTEMS task | |
217 | * |
|
217 | * | |
218 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: |
|
218 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: | |
219 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. |
|
219 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. | |
220 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After |
|
220 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After | |
221 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the |
|
221 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the | |
222 | * data it contains. |
|
222 | * data it contains. | |
223 | * |
|
223 | * | |
224 | */ |
|
224 | */ | |
225 |
|
225 | |||
226 | rtems_status_code status; // RTEMS status code |
|
226 | rtems_status_code status; // RTEMS status code | |
227 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
227 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer | |
228 | ring_node *incomingRingNodePtr; |
|
228 | ring_node *incomingRingNodePtr; | |
229 | int ring_node_address; |
|
229 | int ring_node_address; | |
230 | char *charPtr; |
|
230 | char *charPtr; | |
231 | spw_ioctl_pkt_send *spw_ioctl_send; |
|
231 | spw_ioctl_pkt_send *spw_ioctl_send; | |
232 | size_t size; // size of the incoming TC packet |
|
232 | size_t size; // size of the incoming TC packet | |
233 | rtems_id queue_send_id; |
|
233 | rtems_id queue_send_id; | |
234 | unsigned int sid; |
|
234 | unsigned int sid; | |
235 | unsigned char sidAsUnsignedChar; |
|
235 | unsigned char sidAsUnsignedChar; | |
236 | unsigned char type; |
|
236 | unsigned char type; | |
237 |
|
237 | |||
238 | incomingRingNodePtr = NULL; |
|
238 | incomingRingNodePtr = NULL; | |
239 | ring_node_address = 0; |
|
239 | ring_node_address = 0; | |
240 | charPtr = (char *) &ring_node_address; |
|
240 | charPtr = (char *) &ring_node_address; | |
241 | size = 0; |
|
241 | size = 0; | |
242 | queue_send_id = RTEMS_ID_NONE; |
|
242 | queue_send_id = RTEMS_ID_NONE; | |
243 | sid = 0; |
|
243 | sid = 0; | |
244 | sidAsUnsignedChar = 0; |
|
244 | sidAsUnsignedChar = 0; | |
245 |
|
245 | |||
246 | init_header_cwf( &headerCWF ); |
|
246 | init_header_cwf( &headerCWF ); | |
247 | init_header_swf( &headerSWF ); |
|
247 | init_header_swf( &headerSWF ); | |
248 | init_header_asm( &headerASM ); |
|
248 | init_header_asm( &headerASM ); | |
249 |
|
249 | |||
250 | status = get_message_queue_id_send( &queue_send_id ); |
|
250 | status = get_message_queue_id_send( &queue_send_id ); | |
251 | if (status != RTEMS_SUCCESSFUL) |
|
251 | if (status != RTEMS_SUCCESSFUL) | |
252 | { |
|
252 | { | |
253 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
253 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | BOOT_PRINTF("in SEND *** \n") |
|
256 | BOOT_PRINTF("in SEND *** \n") | |
257 |
|
257 | |||
258 | while(1) |
|
258 | while(1) | |
259 | { |
|
259 | { | |
260 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, |
|
260 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, | |
261 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
|
261 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); | |
262 |
|
262 | |||
263 | if (status!=RTEMS_SUCCESSFUL) |
|
263 | if (status!=RTEMS_SUCCESSFUL) | |
264 | { |
|
264 | { | |
265 | PRINTF1("in SEND *** (1) ERR = %d\n", status) |
|
265 | PRINTF1("in SEND *** (1) ERR = %d\n", status) | |
266 | } |
|
266 | } | |
267 | else |
|
267 | else | |
268 | { |
|
268 | { | |
269 | if ( size == sizeof(ring_node*) ) |
|
269 | if ( size == sizeof(ring_node*) ) | |
270 | { |
|
270 | { | |
271 | charPtr[0] = incomingData[0]; |
|
271 | charPtr[0] = incomingData[0]; | |
272 | charPtr[1] = incomingData[1]; |
|
272 | charPtr[1] = incomingData[1]; | |
273 | charPtr[BYTE_2] = incomingData[BYTE_2]; |
|
273 | charPtr[BYTE_2] = incomingData[BYTE_2]; | |
274 | charPtr[BYTE_3] = incomingData[BYTE_3]; |
|
274 | charPtr[BYTE_3] = incomingData[BYTE_3]; | |
275 | incomingRingNodePtr = (ring_node*) ring_node_address; |
|
275 | incomingRingNodePtr = (ring_node*) ring_node_address; | |
276 | sid = incomingRingNodePtr->sid; |
|
276 | sid = incomingRingNodePtr->sid; | |
277 | if ( (sid==SID_NORM_CWF_LONG_F3) |
|
277 | if ( (sid==SID_NORM_CWF_LONG_F3) | |
278 | || (sid==SID_BURST_CWF_F2 ) |
|
278 | || (sid==SID_BURST_CWF_F2 ) | |
279 | || (sid==SID_SBM1_CWF_F1 ) |
|
279 | || (sid==SID_SBM1_CWF_F1 ) | |
280 | || (sid==SID_SBM2_CWF_F2 )) |
|
280 | || (sid==SID_SBM2_CWF_F2 )) | |
281 | { |
|
281 | { | |
282 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); |
|
282 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); | |
283 | } |
|
283 | } | |
284 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) |
|
284 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) | |
285 | { |
|
285 | { | |
286 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); |
|
286 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); | |
287 | } |
|
287 | } | |
288 | else if ( (sid==SID_NORM_CWF_F3) ) |
|
288 | else if ( (sid==SID_NORM_CWF_F3) ) | |
289 | { |
|
289 | { | |
290 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); |
|
290 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); | |
291 | } |
|
291 | } | |
292 | else if (sid==SID_NORM_ASM_F0) |
|
292 | else if (sid==SID_NORM_ASM_F0) | |
293 | { |
|
293 | { | |
294 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); |
|
294 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); | |
295 | } |
|
295 | } | |
296 | else if (sid==SID_NORM_ASM_F1) |
|
296 | else if (sid==SID_NORM_ASM_F1) | |
297 | { |
|
297 | { | |
298 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); |
|
298 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); | |
299 | } |
|
299 | } | |
300 | else if (sid==SID_NORM_ASM_F2) |
|
300 | else if (sid==SID_NORM_ASM_F2) | |
301 | { |
|
301 | { | |
302 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); |
|
302 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); | |
303 | } |
|
303 | } | |
304 | else if ( sid==TM_CODE_K_DUMP ) |
|
304 | else if ( sid==TM_CODE_K_DUMP ) | |
305 | { |
|
305 | { | |
306 | spw_send_k_dump( incomingRingNodePtr ); |
|
306 | spw_send_k_dump( incomingRingNodePtr ); | |
307 | } |
|
307 | } | |
308 | else |
|
308 | else | |
309 | { |
|
309 | { | |
310 | PRINTF1("unexpected sid = %d\n", sid); |
|
310 | PRINTF1("unexpected sid = %d\n", sid); | |
311 | } |
|
311 | } | |
312 | } |
|
312 | } | |
313 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet |
|
313 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet | |
314 | { |
|
314 | { | |
315 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; |
|
315 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; | |
316 | sid = sidAsUnsignedChar; |
|
316 | sid = sidAsUnsignedChar; | |
317 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; |
|
317 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; | |
318 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently |
|
318 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently | |
319 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS |
|
319 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS | |
320 | { |
|
320 | { | |
321 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); |
|
321 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | status = write( fdSPW, incomingData, size ); |
|
324 | status = write( fdSPW, incomingData, size ); | |
325 | if (status == -1){ |
|
325 | if (status == -1){ | |
326 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
326 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
327 | } |
|
327 | } | |
328 | } |
|
328 | } | |
329 | else // the incoming message is a spw_ioctl_pkt_send structure |
|
329 | else // the incoming message is a spw_ioctl_pkt_send structure | |
330 | { |
|
330 | { | |
331 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; |
|
331 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; | |
332 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); |
|
332 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); | |
333 | if (status == -1){ |
|
333 | if (status == -1){ | |
334 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) |
|
334 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); |
|
339 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); | |
340 |
|
340 | |||
341 | } |
|
341 | } | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | rtems_task link_task( rtems_task_argument argument ) |
|
344 | rtems_task link_task( rtems_task_argument argument ) | |
345 | { |
|
345 | { | |
346 | rtems_event_set event_out; |
|
346 | rtems_event_set event_out; | |
347 | rtems_status_code status; |
|
347 | rtems_status_code status; | |
348 | int linkStatus; |
|
348 | int linkStatus; | |
349 |
|
349 | |||
350 | event_out = EVENT_SETS_NONE_PENDING; |
|
350 | event_out = EVENT_SETS_NONE_PENDING; | |
351 | linkStatus = 0; |
|
351 | linkStatus = 0; | |
352 |
|
352 | |||
353 | BOOT_PRINTF("in LINK ***\n") |
|
353 | BOOT_PRINTF("in LINK ***\n") | |
354 |
|
354 | |||
355 | while(1) |
|
355 | while(1) | |
356 | { |
|
356 | { | |
357 | // wait for an RTEMS_EVENT |
|
357 | // wait for an RTEMS_EVENT | |
358 | rtems_event_receive( RTEMS_EVENT_0, |
|
358 | rtems_event_receive( RTEMS_EVENT_0, | |
359 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
359 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
360 | PRINTF("in LINK *** wait for the link\n") |
|
360 | PRINTF("in LINK *** wait for the link\n") | |
361 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
361 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
362 | while( linkStatus != SPW_LINK_OK) // wait for the link |
|
362 | while( linkStatus != SPW_LINK_OK) // wait for the link | |
363 | { |
|
363 | { | |
364 | status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms |
|
364 | status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms | |
365 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
365 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
366 | watchdog_reload(); |
|
366 | watchdog_reload(); | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | spacewire_read_statistics(); |
|
369 | spacewire_read_statistics(); | |
370 | status = spacewire_stop_and_start_link( fdSPW ); |
|
370 | status = spacewire_stop_and_start_link( fdSPW ); | |
371 |
|
371 | |||
372 | if (status != RTEMS_SUCCESSFUL) |
|
372 | if (status != RTEMS_SUCCESSFUL) | |
373 | { |
|
373 | { | |
374 | PRINTF1("in LINK *** ERR link not started %d\n", status) |
|
374 | PRINTF1("in LINK *** ERR link not started %d\n", status) | |
375 | } |
|
375 | } | |
376 | else |
|
376 | else | |
377 | { |
|
377 | { | |
378 | PRINTF("in LINK *** OK link started\n") |
|
378 | PRINTF("in LINK *** OK link started\n") | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | // restart the SPIQ task |
|
381 | // restart the SPIQ task | |
382 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); |
|
382 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); | |
383 | if ( status != RTEMS_SUCCESSFUL ) { |
|
383 | if ( status != RTEMS_SUCCESSFUL ) { | |
384 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") |
|
384 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | // restart RECV and SEND |
|
387 | // restart RECV and SEND | |
388 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
388 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
389 | if ( status != RTEMS_SUCCESSFUL ) { |
|
389 | if ( status != RTEMS_SUCCESSFUL ) { | |
390 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") |
|
390 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") | |
391 | } |
|
391 | } | |
392 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
392 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
393 | if ( status != RTEMS_SUCCESSFUL ) { |
|
393 | if ( status != RTEMS_SUCCESSFUL ) { | |
394 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") |
|
394 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") | |
395 | } |
|
395 | } | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | //**************** |
|
399 | //**************** | |
400 | // OTHER FUNCTIONS |
|
400 | // OTHER FUNCTIONS | |
401 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] |
|
401 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] | |
402 | { |
|
402 | { | |
403 | /** This function opens the SpaceWire link. |
|
403 | /** This function opens the SpaceWire link. | |
404 | * |
|
404 | * | |
405 | * @return a valid file descriptor in case of success, -1 in case of a failure |
|
405 | * @return a valid file descriptor in case of success, -1 in case of a failure | |
406 | * |
|
406 | * | |
407 | */ |
|
407 | */ | |
408 | rtems_status_code status; |
|
408 | rtems_status_code status; | |
409 |
|
409 | |||
410 | status = RTEMS_SUCCESSFUL; |
|
410 | status = RTEMS_SUCCESSFUL; | |
411 |
|
411 | |||
412 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware |
|
412 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware | |
413 | if ( fdSPW < 0 ) { |
|
413 | if ( fdSPW < 0 ) { | |
414 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) |
|
414 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) | |
415 | } |
|
415 | } | |
416 | else |
|
416 | else | |
417 | { |
|
417 | { | |
418 | status = RTEMS_SUCCESSFUL; |
|
418 | status = RTEMS_SUCCESSFUL; | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | return status; |
|
421 | return status; | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | int spacewire_start_link( int fd ) |
|
424 | int spacewire_start_link( int fd ) | |
425 | { |
|
425 | { | |
426 | rtems_status_code status; |
|
426 | rtems_status_code status; | |
427 |
|
427 | |||
428 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
428 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started | |
429 | // -1 default hardcoded driver timeout |
|
429 | // -1 default hardcoded driver timeout | |
430 |
|
430 | |||
431 | return status; |
|
431 | return status; | |
432 | } |
|
432 | } | |
433 |
|
433 | |||
434 | int spacewire_stop_and_start_link( int fd ) |
|
434 | int spacewire_stop_and_start_link( int fd ) | |
435 | { |
|
435 | { | |
436 | rtems_status_code status; |
|
436 | rtems_status_code status; | |
437 |
|
437 | |||
438 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 |
|
438 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 | |
439 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
439 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started | |
440 | // -1 default hardcoded driver timeout |
|
440 | // -1 default hardcoded driver timeout | |
441 |
|
441 | |||
442 | return status; |
|
442 | return status; | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | int spacewire_configure_link( int fd ) |
|
445 | int spacewire_configure_link( int fd ) | |
446 | { |
|
446 | { | |
447 | /** This function configures the SpaceWire link. |
|
447 | /** This function configures the SpaceWire link. | |
448 | * |
|
448 | * | |
449 | * @return GR-RTEMS-DRIVER directive status codes: |
|
449 | * @return GR-RTEMS-DRIVER directive status codes: | |
450 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. |
|
450 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. | |
451 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. |
|
451 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. | |
452 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. |
|
452 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. | |
453 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. |
|
453 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. | |
454 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. |
|
454 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. | |
455 | * - 5 EIO - Error when writing to grswp hardware registers. |
|
455 | * - 5 EIO - Error when writing to grswp hardware registers. | |
456 | * - 2 ENOENT - No such file or directory |
|
456 | * - 2 ENOENT - No such file or directory | |
457 | */ |
|
457 | */ | |
458 |
|
458 | |||
459 | rtems_status_code status; |
|
459 | rtems_status_code status; | |
460 |
|
460 | |||
461 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force |
|
461 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force | |
462 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration |
|
462 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration | |
463 | spw_ioctl_packetsize packetsize; |
|
463 | spw_ioctl_packetsize packetsize; | |
464 |
|
464 | |||
465 | packetsize.rxsize = SPW_RXSIZE; |
|
465 | packetsize.rxsize = SPW_RXSIZE; | |
466 | packetsize.txdsize = SPW_TXDSIZE; |
|
466 | packetsize.txdsize = SPW_TXDSIZE; | |
467 | packetsize.txhsize = SPW_TXHSIZE; |
|
467 | packetsize.txhsize = SPW_TXHSIZE; | |
468 |
|
468 | |||
469 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
469 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception | |
470 | if (status!=RTEMS_SUCCESSFUL) { |
|
470 | if (status!=RTEMS_SUCCESSFUL) { | |
471 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
471 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") | |
472 | } |
|
472 | } | |
473 | // |
|
473 | // | |
474 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a |
|
474 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a | |
475 | if (status!=RTEMS_SUCCESSFUL) { |
|
475 | if (status!=RTEMS_SUCCESSFUL) { | |
476 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
476 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs | |
477 | } |
|
477 | } | |
478 | // |
|
478 | // | |
479 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts |
|
479 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts | |
480 | if (status!=RTEMS_SUCCESSFUL) { |
|
480 | if (status!=RTEMS_SUCCESSFUL) { | |
481 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") |
|
481 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") | |
482 | } |
|
482 | } | |
483 | // |
|
483 | // | |
484 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
484 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit | |
485 | if (status!=RTEMS_SUCCESSFUL) { |
|
485 | if (status!=RTEMS_SUCCESSFUL) { | |
486 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
486 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |
487 | } |
|
487 | } | |
488 | // |
|
488 | // | |
489 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks |
|
489 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks | |
490 | if (status!=RTEMS_SUCCESSFUL) { |
|
490 | if (status!=RTEMS_SUCCESSFUL) { | |
491 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") |
|
491 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") | |
492 | } |
|
492 | } | |
493 | // |
|
493 | // | |
494 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available |
|
494 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available | |
495 | if (status!=RTEMS_SUCCESSFUL) { |
|
495 | if (status!=RTEMS_SUCCESSFUL) { | |
496 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") |
|
496 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") | |
497 | } |
|
497 | } | |
498 | // |
|
498 | // | |
499 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ] |
|
499 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ] | |
500 | if (status!=RTEMS_SUCCESSFUL) { |
|
500 | if (status!=RTEMS_SUCCESSFUL) { | |
501 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") |
|
501 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") | |
502 | } |
|
502 | } | |
503 | // |
|
503 | // | |
504 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize |
|
504 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize | |
505 | if (status!=RTEMS_SUCCESSFUL) { |
|
505 | if (status!=RTEMS_SUCCESSFUL) { | |
506 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n") |
|
506 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n") | |
507 | } |
|
507 | } | |
508 |
|
508 | |||
509 | return status; |
|
509 | return status; | |
510 | } |
|
510 | } | |
511 |
|
511 | |||
512 | int spacewire_several_connect_attemps( void ) |
|
512 | int spacewire_several_connect_attemps( void ) | |
513 | { |
|
513 | { | |
514 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. |
|
514 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. | |
515 | * |
|
515 | * | |
516 | * @return RTEMS directive status code: |
|
516 | * @return RTEMS directive status code: | |
517 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. |
|
517 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. | |
518 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. |
|
518 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. | |
519 | * |
|
519 | * | |
520 | */ |
|
520 | */ | |
521 |
|
521 | |||
522 | rtems_status_code status_spw; |
|
522 | rtems_status_code status_spw; | |
523 | rtems_status_code status; |
|
523 | rtems_status_code status; | |
524 | int i; |
|
524 | int i; | |
525 |
|
525 | |||
526 | status_spw = RTEMS_SUCCESSFUL; |
|
526 | status_spw = RTEMS_SUCCESSFUL; | |
527 |
|
527 | |||
528 | i = 0; |
|
528 | i = 0; | |
529 | while (i < SY_LFR_DPU_CONNECT_ATTEMPT) |
|
529 | while (i < SY_LFR_DPU_CONNECT_ATTEMPT) | |
530 | { |
|
530 | { | |
531 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); |
|
531 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); | |
532 |
|
532 | |||
533 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM |
|
533 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM | |
534 |
|
534 | |||
535 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
535 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
536 |
|
536 | |||
537 | status_spw = spacewire_stop_and_start_link( fdSPW ); |
|
537 | status_spw = spacewire_stop_and_start_link( fdSPW ); | |
538 |
|
538 | |||
539 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
539 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
540 | { |
|
540 | { | |
541 | i = i + 1; |
|
541 | i = i + 1; | |
542 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw); |
|
542 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw); | |
543 | } |
|
543 | } | |
544 | else |
|
544 | else | |
545 | { |
|
545 | { | |
546 | i = SY_LFR_DPU_CONNECT_ATTEMPT; |
|
546 | i = SY_LFR_DPU_CONNECT_ATTEMPT; | |
547 | } |
|
547 | } | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | return status_spw; |
|
550 | return status_spw; | |
551 | } |
|
551 | } | |
552 |
|
552 | |||
553 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force |
|
553 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force | |
554 | { |
|
554 | { | |
555 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. |
|
555 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. | |
556 | * |
|
556 | * | |
557 | * @param val is the value, 0 or 1, used to set the value of the NP bit. |
|
557 | * @param val is the value, 0 or 1, used to set the value of the NP bit. | |
558 | * @param regAddr is the address of the GRSPW control register. |
|
558 | * @param regAddr is the address of the GRSPW control register. | |
559 | * |
|
559 | * | |
560 | * NP is the bit 20 of the GRSPW control register. |
|
560 | * NP is the bit 20 of the GRSPW control register. | |
561 | * |
|
561 | * | |
562 | */ |
|
562 | */ | |
563 |
|
563 | |||
564 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
564 | unsigned int *spwptr = (unsigned int*) regAddr; | |
565 |
|
565 | |||
566 | if (val == 1) { |
|
566 | if (val == 1) { | |
567 | *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit |
|
567 | *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit | |
568 | } |
|
568 | } | |
569 | if (val== 0) { |
|
569 | if (val== 0) { | |
570 | *spwptr = *spwptr & SPW_BIT_NP_MASK; |
|
570 | *spwptr = *spwptr & SPW_BIT_NP_MASK; | |
571 | } |
|
571 | } | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable |
|
574 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable | |
575 | { |
|
575 | { | |
576 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. |
|
576 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. | |
577 | * |
|
577 | * | |
578 | * @param val is the value, 0 or 1, used to set the value of the RE bit. |
|
578 | * @param val is the value, 0 or 1, used to set the value of the RE bit. | |
579 | * @param regAddr is the address of the GRSPW control register. |
|
579 | * @param regAddr is the address of the GRSPW control register. | |
580 | * |
|
580 | * | |
581 | * RE is the bit 16 of the GRSPW control register. |
|
581 | * RE is the bit 16 of the GRSPW control register. | |
582 | * |
|
582 | * | |
583 | */ |
|
583 | */ | |
584 |
|
584 | |||
585 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
585 | unsigned int *spwptr = (unsigned int*) regAddr; | |
586 |
|
586 | |||
587 | if (val == 1) |
|
587 | if (val == 1) | |
588 | { |
|
588 | { | |
589 | *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit |
|
589 | *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit | |
590 | } |
|
590 | } | |
591 | if (val== 0) |
|
591 | if (val== 0) | |
592 | { |
|
592 | { | |
593 | *spwptr = *spwptr & SPW_BIT_RE_MASK; |
|
593 | *spwptr = *spwptr & SPW_BIT_RE_MASK; | |
594 | } |
|
594 | } | |
595 | } |
|
595 | } | |
596 |
|
596 | |||
597 | void spacewire_read_statistics( void ) |
|
597 | void spacewire_read_statistics( void ) | |
598 | { |
|
598 | { | |
599 | /** This function reads the SpaceWire statistics from the grspw RTEMS driver. |
|
599 | /** This function reads the SpaceWire statistics from the grspw RTEMS driver. | |
600 | * |
|
600 | * | |
601 | * @param void |
|
601 | * @param void | |
602 | * |
|
602 | * | |
603 | * @return void |
|
603 | * @return void | |
604 | * |
|
604 | * | |
605 | * Once they are read, the counters are stored in a global variable used during the building of the |
|
605 | * Once they are read, the counters are stored in a global variable used during the building of the | |
606 | * HK packets. |
|
606 | * HK packets. | |
607 | * |
|
607 | * | |
608 | */ |
|
608 | */ | |
609 |
|
609 | |||
610 | rtems_status_code status; |
|
610 | rtems_status_code status; | |
611 | spw_stats current; |
|
611 | spw_stats current; | |
612 |
|
612 | |||
613 | memset(¤t, 0, sizeof(spw_stats)); |
|
613 | memset(¤t, 0, sizeof(spw_stats)); | |
614 |
|
614 | |||
615 | spacewire_get_last_error(); |
|
615 | spacewire_get_last_error(); | |
616 |
|
616 | |||
617 | // read the current statistics |
|
617 | // read the current statistics | |
618 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, ¤t ); |
|
618 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, ¤t ); | |
619 |
|
619 | |||
620 | // clear the counters |
|
620 | // clear the counters | |
621 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS ); |
|
621 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS ); | |
622 |
|
622 | |||
623 | // typedef struct { |
|
623 | // typedef struct { | |
624 | // unsigned int tx_link_err; // NOT IN HK |
|
624 | // unsigned int tx_link_err; // NOT IN HK | |
625 | // unsigned int rx_rmap_header_crc_err; // NOT IN HK |
|
625 | // unsigned int rx_rmap_header_crc_err; // NOT IN HK | |
626 | // unsigned int rx_rmap_data_crc_err; // NOT IN HK |
|
626 | // unsigned int rx_rmap_data_crc_err; // NOT IN HK | |
627 | // unsigned int rx_eep_err; |
|
627 | // unsigned int rx_eep_err; | |
628 | // unsigned int rx_truncated; |
|
628 | // unsigned int rx_truncated; | |
629 | // unsigned int parity_err; |
|
629 | // unsigned int parity_err; | |
630 | // unsigned int escape_err; |
|
630 | // unsigned int escape_err; | |
631 | // unsigned int credit_err; |
|
631 | // unsigned int credit_err; | |
632 | // unsigned int write_sync_err; |
|
632 | // unsigned int write_sync_err; | |
633 | // unsigned int disconnect_err; |
|
633 | // unsigned int disconnect_err; | |
634 | // unsigned int early_ep; |
|
634 | // unsigned int early_ep; | |
635 | // unsigned int invalid_address; |
|
635 | // unsigned int invalid_address; | |
636 | // unsigned int packets_sent; |
|
636 | // unsigned int packets_sent; | |
637 | // unsigned int packets_received; |
|
637 | // unsigned int packets_received; | |
638 | // } spw_stats; |
|
638 | // } spw_stats; | |
639 |
|
639 | |||
640 | // rx_eep_err |
|
640 | // rx_eep_err | |
641 | grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err; |
|
641 | grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err; | |
642 | // rx_truncated |
|
642 | // rx_truncated | |
643 | grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated; |
|
643 | grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated; | |
644 | // parity_err |
|
644 | // parity_err | |
645 | grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err; |
|
645 | grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err; | |
646 | // escape_err |
|
646 | // escape_err | |
647 | grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err; |
|
647 | grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err; | |
648 | // credit_err |
|
648 | // credit_err | |
649 | grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err; |
|
649 | grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err; | |
650 | // write_sync_err |
|
650 | // write_sync_err | |
651 | grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err; |
|
651 | grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err; | |
652 | // disconnect_err |
|
652 | // disconnect_err | |
653 | grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err; |
|
653 | grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err; | |
654 | // early_ep |
|
654 | // early_ep | |
655 | grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep; |
|
655 | grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep; | |
656 | // invalid_address |
|
656 | // invalid_address | |
657 | grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address; |
|
657 | grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address; | |
658 | // packets_sent |
|
658 | // packets_sent | |
659 | grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent; |
|
659 | grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent; | |
660 | // packets_received |
|
660 | // packets_received | |
661 | grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received; |
|
661 | grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received; | |
662 |
|
662 | |||
663 | } |
|
663 | } | |
664 |
|
664 | |||
665 | void spacewire_get_last_error( void ) |
|
665 | void spacewire_get_last_error( void ) | |
666 | { |
|
666 | { | |
667 | static spw_stats previous = {0}; |
|
667 | static spw_stats previous = {0}; | |
668 | spw_stats current; |
|
668 | spw_stats current; | |
669 | rtems_status_code status; |
|
669 | rtems_status_code status; | |
670 |
|
670 | |||
671 | unsigned int hk_lfr_last_er_rid; |
|
671 | unsigned int hk_lfr_last_er_rid; | |
672 | unsigned char hk_lfr_last_er_code; |
|
672 | unsigned char hk_lfr_last_er_code; | |
673 | int coarseTime; |
|
673 | int coarseTime; | |
674 | int fineTime; |
|
674 | int fineTime; | |
675 | unsigned char update_hk_lfr_last_er; |
|
675 | unsigned char update_hk_lfr_last_er; | |
676 |
|
676 | |||
677 | memset(¤t, 0, sizeof(spw_stats)); |
|
677 | memset(¤t, 0, sizeof(spw_stats)); | |
678 | update_hk_lfr_last_er = 0; |
|
678 | update_hk_lfr_last_er = 0; | |
679 |
|
679 | |||
680 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, ¤t ); |
|
680 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, ¤t ); | |
681 |
|
681 | |||
682 | // get current time |
|
682 | // get current time | |
683 | coarseTime = time_management_regs->coarse_time; |
|
683 | coarseTime = time_management_regs->coarse_time; | |
684 | fineTime = time_management_regs->fine_time; |
|
684 | fineTime = time_management_regs->fine_time; | |
685 |
|
685 | |||
686 | // typedef struct { |
|
686 | // typedef struct { | |
687 | // unsigned int tx_link_err; // NOT IN HK |
|
687 | // unsigned int tx_link_err; // NOT IN HK | |
688 | // unsigned int rx_rmap_header_crc_err; // NOT IN HK |
|
688 | // unsigned int rx_rmap_header_crc_err; // NOT IN HK | |
689 | // unsigned int rx_rmap_data_crc_err; // NOT IN HK |
|
689 | // unsigned int rx_rmap_data_crc_err; // NOT IN HK | |
690 | // unsigned int rx_eep_err; |
|
690 | // unsigned int rx_eep_err; | |
691 | // unsigned int rx_truncated; |
|
691 | // unsigned int rx_truncated; | |
692 | // unsigned int parity_err; |
|
692 | // unsigned int parity_err; | |
693 | // unsigned int escape_err; |
|
693 | // unsigned int escape_err; | |
694 | // unsigned int credit_err; |
|
694 | // unsigned int credit_err; | |
695 | // unsigned int write_sync_err; |
|
695 | // unsigned int write_sync_err; | |
696 | // unsigned int disconnect_err; |
|
696 | // unsigned int disconnect_err; | |
697 | // unsigned int early_ep; |
|
697 | // unsigned int early_ep; | |
698 | // unsigned int invalid_address; |
|
698 | // unsigned int invalid_address; | |
699 | // unsigned int packets_sent; |
|
699 | // unsigned int packets_sent; | |
700 | // unsigned int packets_received; |
|
700 | // unsigned int packets_received; | |
701 | // } spw_stats; |
|
701 | // } spw_stats; | |
702 |
|
702 | |||
703 | // tx_link_err *** no code associated to this field |
|
703 | // tx_link_err *** no code associated to this field | |
704 | // rx_rmap_header_crc_err *** LE *** in HK |
|
704 | // rx_rmap_header_crc_err *** LE *** in HK | |
705 | if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err) |
|
705 | if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err) | |
706 | { |
|
706 | { | |
707 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
707 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
708 | hk_lfr_last_er_code = CODE_HEADER_CRC; |
|
708 | hk_lfr_last_er_code = CODE_HEADER_CRC; | |
709 | update_hk_lfr_last_er = 1; |
|
709 | update_hk_lfr_last_er = 1; | |
710 | } |
|
710 | } | |
711 | // rx_rmap_data_crc_err *** LE *** NOT IN HK |
|
711 | // rx_rmap_data_crc_err *** LE *** NOT IN HK | |
712 | if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err) |
|
712 | if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err) | |
713 | { |
|
713 | { | |
714 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
714 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
715 | hk_lfr_last_er_code = CODE_DATA_CRC; |
|
715 | hk_lfr_last_er_code = CODE_DATA_CRC; | |
716 | update_hk_lfr_last_er = 1; |
|
716 | update_hk_lfr_last_er = 1; | |
717 | } |
|
717 | } | |
718 | // rx_eep_err |
|
718 | // rx_eep_err | |
719 | if (previous.rx_eep_err != current.rx_eep_err) |
|
719 | if (previous.rx_eep_err != current.rx_eep_err) | |
720 | { |
|
720 | { | |
721 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
721 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; | |
722 | hk_lfr_last_er_code = CODE_EEP; |
|
722 | hk_lfr_last_er_code = CODE_EEP; | |
723 | update_hk_lfr_last_er = 1; |
|
723 | update_hk_lfr_last_er = 1; | |
724 | } |
|
724 | } | |
725 | // rx_truncated |
|
725 | // rx_truncated | |
726 | if (previous.rx_truncated != current.rx_truncated) |
|
726 | if (previous.rx_truncated != current.rx_truncated) | |
727 | { |
|
727 | { | |
728 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
728 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; | |
729 | hk_lfr_last_er_code = CODE_RX_TOO_BIG; |
|
729 | hk_lfr_last_er_code = CODE_RX_TOO_BIG; | |
730 | update_hk_lfr_last_er = 1; |
|
730 | update_hk_lfr_last_er = 1; | |
731 | } |
|
731 | } | |
732 | // parity_err |
|
732 | // parity_err | |
733 | if (previous.parity_err != current.parity_err) |
|
733 | if (previous.parity_err != current.parity_err) | |
734 | { |
|
734 | { | |
735 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
735 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
736 | hk_lfr_last_er_code = CODE_PARITY; |
|
736 | hk_lfr_last_er_code = CODE_PARITY; | |
737 | update_hk_lfr_last_er = 1; |
|
737 | update_hk_lfr_last_er = 1; | |
738 | } |
|
738 | } | |
739 | // escape_err |
|
739 | // escape_err | |
740 | if (previous.parity_err != current.parity_err) |
|
740 | if (previous.parity_err != current.parity_err) | |
741 | { |
|
741 | { | |
742 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
742 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
743 | hk_lfr_last_er_code = CODE_ESCAPE; |
|
743 | hk_lfr_last_er_code = CODE_ESCAPE; | |
744 | update_hk_lfr_last_er = 1; |
|
744 | update_hk_lfr_last_er = 1; | |
745 | } |
|
745 | } | |
746 | // credit_err |
|
746 | // credit_err | |
747 | if (previous.credit_err != current.credit_err) |
|
747 | if (previous.credit_err != current.credit_err) | |
748 | { |
|
748 | { | |
749 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
749 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
750 | hk_lfr_last_er_code = CODE_CREDIT; |
|
750 | hk_lfr_last_er_code = CODE_CREDIT; | |
751 | update_hk_lfr_last_er = 1; |
|
751 | update_hk_lfr_last_er = 1; | |
752 | } |
|
752 | } | |
753 | // write_sync_err |
|
753 | // write_sync_err | |
754 | if (previous.write_sync_err != current.write_sync_err) |
|
754 | if (previous.write_sync_err != current.write_sync_err) | |
755 | { |
|
755 | { | |
756 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
756 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
757 | hk_lfr_last_er_code = CODE_WRITE_SYNC; |
|
757 | hk_lfr_last_er_code = CODE_WRITE_SYNC; | |
758 | update_hk_lfr_last_er = 1; |
|
758 | update_hk_lfr_last_er = 1; | |
759 | } |
|
759 | } | |
760 | // disconnect_err |
|
760 | // disconnect_err | |
761 | if (previous.disconnect_err != current.disconnect_err) |
|
761 | if (previous.disconnect_err != current.disconnect_err) | |
762 | { |
|
762 | { | |
763 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; |
|
763 | hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW; | |
764 | hk_lfr_last_er_code = CODE_DISCONNECT; |
|
764 | hk_lfr_last_er_code = CODE_DISCONNECT; | |
765 | update_hk_lfr_last_er = 1; |
|
765 | update_hk_lfr_last_er = 1; | |
766 | } |
|
766 | } | |
767 | // early_ep |
|
767 | // early_ep | |
768 | if (previous.early_ep != current.early_ep) |
|
768 | if (previous.early_ep != current.early_ep) | |
769 | { |
|
769 | { | |
770 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
770 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; | |
771 | hk_lfr_last_er_code = CODE_EARLY_EOP_EEP; |
|
771 | hk_lfr_last_er_code = CODE_EARLY_EOP_EEP; | |
772 | update_hk_lfr_last_er = 1; |
|
772 | update_hk_lfr_last_er = 1; | |
773 | } |
|
773 | } | |
774 | // invalid_address |
|
774 | // invalid_address | |
775 | if (previous.invalid_address != current.invalid_address) |
|
775 | if (previous.invalid_address != current.invalid_address) | |
776 | { |
|
776 | { | |
777 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; |
|
777 | hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW; | |
778 | hk_lfr_last_er_code = CODE_INVALID_ADDRESS; |
|
778 | hk_lfr_last_er_code = CODE_INVALID_ADDRESS; | |
779 | update_hk_lfr_last_er = 1; |
|
779 | update_hk_lfr_last_er = 1; | |
780 | } |
|
780 | } | |
781 |
|
781 | |||
782 | // if a field has changed, update the hk_last_er fields |
|
782 | // if a field has changed, update the hk_last_er fields | |
783 | if (update_hk_lfr_last_er == 1) |
|
783 | if (update_hk_lfr_last_er == 1) | |
784 | { |
|
784 | { | |
785 | update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code ); |
|
785 | update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code ); | |
786 | } |
|
786 | } | |
787 |
|
787 | |||
788 | previous = current; |
|
788 | previous = current; | |
789 | } |
|
789 | } | |
790 |
|
790 | |||
791 | void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code) |
|
791 | void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code) | |
792 | { |
|
792 | { | |
793 | unsigned char *coarseTimePtr; |
|
793 | unsigned char *coarseTimePtr; | |
794 | unsigned char *fineTimePtr; |
|
794 | unsigned char *fineTimePtr; | |
795 |
|
795 | |||
796 | coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time; |
|
796 | coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time; | |
797 | fineTimePtr = (unsigned char*) &time_management_regs->fine_time; |
|
797 | fineTimePtr = (unsigned char*) &time_management_regs->fine_time; | |
798 |
|
798 | |||
799 | housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE ); |
|
799 | housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE ); | |
800 | housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK); |
|
800 | housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK); | |
801 | housekeeping_packet.hk_lfr_last_er_code = code; |
|
801 | housekeeping_packet.hk_lfr_last_er_code = code; | |
802 | housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0]; |
|
802 | housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0]; | |
803 | housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1]; |
|
803 | housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1]; | |
804 | housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2]; |
|
804 | housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2]; | |
805 | housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3]; |
|
805 | housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3]; | |
806 | housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2]; |
|
806 | housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2]; | |
807 | housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3]; |
|
807 | housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3]; | |
808 | } |
|
808 | } | |
809 |
|
809 | |||
810 | void update_hk_with_grspw_stats( void ) |
|
810 | void update_hk_with_grspw_stats( void ) | |
811 | { |
|
811 | { | |
812 | //**************************** |
|
812 | //**************************** | |
813 | // DPU_SPACEWIRE_IF_STATISTICS |
|
813 | // DPU_SPACEWIRE_IF_STATISTICS | |
814 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE); |
|
814 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE); | |
815 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received); |
|
815 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received); | |
816 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE); |
|
816 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE); | |
817 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent); |
|
817 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent); | |
818 |
|
818 | |||
819 | //****************************************** |
|
819 | //****************************************** | |
820 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY |
|
820 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY | |
821 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err; |
|
821 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err; | |
822 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err; |
|
822 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err; | |
823 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err; |
|
823 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err; | |
824 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err; |
|
824 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err; | |
825 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err; |
|
825 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err; | |
826 |
|
826 | |||
827 | //********************************************* |
|
827 | //********************************************* | |
828 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY |
|
828 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY | |
829 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep; |
|
829 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep; | |
830 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address; |
|
830 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address; | |
831 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err; |
|
831 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err; | |
832 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated; |
|
832 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated; | |
833 | } |
|
833 | } | |
834 |
|
834 | |||
835 | void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 ) |
|
835 | void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 ) | |
836 | { |
|
836 | { | |
837 | unsigned int *statusRegisterPtr; |
|
837 | unsigned int *statusRegisterPtr; | |
838 | unsigned char linkState; |
|
838 | unsigned char linkState; | |
839 |
|
839 | |||
840 | statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER); |
|
840 | statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER); | |
841 | linkState = |
|
841 | linkState = | |
842 | (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111] |
|
842 | (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111] | |
843 |
|
843 | |||
844 | *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0 |
|
844 | *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0 | |
845 |
|
845 | |||
846 | *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state |
|
846 | *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state | |
847 | } |
|
847 | } | |
848 |
|
848 | |||
849 | void increase_unsigned_char_counter( unsigned char *counter ) |
|
849 | void increase_unsigned_char_counter( unsigned char *counter ) | |
850 | { |
|
850 | { | |
851 | // update the number of valid timecodes that have been received |
|
851 | // update the number of valid timecodes that have been received | |
852 | if (*counter == UINT8_MAX) |
|
852 | if (*counter == UINT8_MAX) | |
853 | { |
|
853 | { | |
854 | *counter = 0; |
|
854 | *counter = 0; | |
855 | } |
|
855 | } | |
856 | else |
|
856 | else | |
857 | { |
|
857 | { | |
858 | *counter = *counter + 1; |
|
858 | *counter = *counter + 1; | |
859 | } |
|
859 | } | |
860 | } |
|
860 | } | |
861 |
|
861 | |||
862 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) |
|
862 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) | |
863 | { |
|
863 | { | |
864 | /** This function checks the coherency between the incoming timecode and the last valid timecode. |
|
864 | /** This function checks the coherency between the incoming timecode and the last valid timecode. | |
865 | * |
|
865 | * | |
866 | * @param currentTimecodeCtr is the incoming timecode |
|
866 | * @param currentTimecodeCtr is the incoming timecode | |
867 | * |
|
867 | * | |
868 | * @return returned codes:: |
|
868 | * @return returned codes:: | |
869 | * - LFR_DEFAULT |
|
869 | * - LFR_DEFAULT | |
870 | * - LFR_SUCCESSFUL |
|
870 | * - LFR_SUCCESSFUL | |
871 | * |
|
871 | * | |
872 | */ |
|
872 | */ | |
873 |
|
873 | |||
874 | static unsigned char firstTickout = 1; |
|
874 | static unsigned char firstTickout = 1; | |
875 | unsigned char ret; |
|
875 | unsigned char ret; | |
876 |
|
876 | |||
877 | ret = LFR_DEFAULT; |
|
877 | ret = LFR_DEFAULT; | |
878 |
|
878 | |||
879 | if (firstTickout == 0) |
|
879 | if (firstTickout == 0) | |
880 | { |
|
880 | { | |
881 | if (currentTimecodeCtr == 0) |
|
881 | if (currentTimecodeCtr == 0) | |
882 | { |
|
882 | { | |
883 | if (previousTimecodeCtr == SPW_TIMECODE_MAX) |
|
883 | if (previousTimecodeCtr == SPW_TIMECODE_MAX) | |
884 | { |
|
884 | { | |
885 | ret = LFR_SUCCESSFUL; |
|
885 | ret = LFR_SUCCESSFUL; | |
886 | } |
|
886 | } | |
887 | else |
|
887 | else | |
888 | { |
|
888 | { | |
889 | ret = LFR_DEFAULT; |
|
889 | ret = LFR_DEFAULT; | |
890 | } |
|
890 | } | |
891 | } |
|
891 | } | |
892 | else |
|
892 | else | |
893 | { |
|
893 | { | |
894 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) |
|
894 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) | |
895 | { |
|
895 | { | |
896 | ret = LFR_SUCCESSFUL; |
|
896 | ret = LFR_SUCCESSFUL; | |
897 | } |
|
897 | } | |
898 | else |
|
898 | else | |
899 | { |
|
899 | { | |
900 | ret = LFR_DEFAULT; |
|
900 | ret = LFR_DEFAULT; | |
901 | } |
|
901 | } | |
902 | } |
|
902 | } | |
903 | } |
|
903 | } | |
904 | else |
|
904 | else | |
905 | { |
|
905 | { | |
906 | firstTickout = 0; |
|
906 | firstTickout = 0; | |
907 | ret = LFR_SUCCESSFUL; |
|
907 | ret = LFR_SUCCESSFUL; | |
908 | } |
|
908 | } | |
909 |
|
909 | |||
910 | return ret; |
|
910 | return ret; | |
911 | } |
|
911 | } | |
912 |
|
912 | |||
913 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) |
|
913 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) | |
914 | { |
|
914 | { | |
915 | unsigned int ret; |
|
915 | unsigned int ret; | |
916 |
|
916 | |||
917 | ret = LFR_DEFAULT; |
|
917 | ret = LFR_DEFAULT; | |
918 |
|
918 | |||
919 | if (timecode == internalTime) |
|
919 | if (timecode == internalTime) | |
920 | { |
|
920 | { | |
921 | ret = LFR_SUCCESSFUL; |
|
921 | ret = LFR_SUCCESSFUL; | |
922 | } |
|
922 | } | |
923 | else |
|
923 | else | |
924 | { |
|
924 | { | |
925 | ret = LFR_DEFAULT; |
|
925 | ret = LFR_DEFAULT; | |
926 | } |
|
926 | } | |
927 |
|
927 | |||
928 | return ret; |
|
928 | return ret; | |
929 | } |
|
929 | } | |
930 |
|
930 | |||
931 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) |
|
931 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) | |
932 | { |
|
932 | { | |
933 | // a tickout has been emitted, perform actions on the incoming timecode |
|
933 | // a tickout has been emitted, perform actions on the incoming timecode | |
934 |
|
934 | |||
935 | unsigned char incomingTimecode; |
|
935 | unsigned char incomingTimecode; | |
936 | unsigned char updateTime; |
|
936 | unsigned char updateTime; | |
937 | unsigned char internalTime; |
|
937 | unsigned char internalTime; | |
938 | rtems_status_code status; |
|
938 | rtems_status_code status; | |
939 |
|
939 | |||
940 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
940 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); | |
941 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; |
|
941 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; | |
942 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; |
|
942 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; | |
943 |
|
943 | |||
944 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; |
|
944 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; | |
945 |
|
945 | |||
946 | // update the number of tickout that have been generated |
|
946 | // update the number of tickout that have been generated | |
947 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); |
|
947 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); | |
948 |
|
948 | |||
949 | //************************** |
|
949 | //************************** | |
950 | // HK_LFR_TIMECODE_ERRONEOUS |
|
950 | // HK_LFR_TIMECODE_ERRONEOUS | |
951 | // MISSING and INVALID are handled by the timecode_timer_routine service routine |
|
951 | // MISSING and INVALID are handled by the timecode_timer_routine service routine | |
952 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) |
|
952 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) | |
953 | { |
|
953 | { | |
954 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous |
|
954 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous | |
955 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); |
|
955 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); | |
956 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS ); |
|
956 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS ); | |
957 | } |
|
957 | } | |
958 |
|
958 | |||
959 | //************************ |
|
959 | //************************ | |
960 | // HK_LFR_TIME_TIMECODE_IT |
|
960 | // HK_LFR_TIME_TIMECODE_IT | |
961 | // check the coherency between the SpaceWire timecode and the Internal Time |
|
961 | // check the coherency between the SpaceWire timecode and the Internal Time | |
962 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) |
|
962 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) | |
963 | { |
|
963 | { | |
964 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); |
|
964 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); | |
965 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT ); |
|
965 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT ); | |
966 | } |
|
966 | } | |
967 |
|
967 | |||
968 | //******************** |
|
968 | //******************** | |
969 | // HK_LFR_TIMECODE_CTR |
|
969 | // HK_LFR_TIMECODE_CTR | |
970 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 |
|
970 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 | |
971 | if (oneTcLfrUpdateTimeReceived == 1) |
|
971 | if (oneTcLfrUpdateTimeReceived == 1) | |
972 | { |
|
972 | { | |
973 | if ( incomingTimecode != updateTime ) |
|
973 | if ( incomingTimecode != updateTime ) | |
974 | { |
|
974 | { | |
975 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); |
|
975 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); | |
976 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR ); |
|
976 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR ); | |
977 | } |
|
977 | } | |
978 | } |
|
978 | } | |
979 |
|
979 | |||
980 | // launch the timecode timer to detect missing or invalid timecodes |
|
980 | // launch the timecode timer to detect missing or invalid timecodes | |
981 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value |
|
981 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value | |
982 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); |
|
982 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); | |
983 | if (status != RTEMS_SUCCESSFUL) |
|
983 | if (status != RTEMS_SUCCESSFUL) | |
984 | { |
|
984 | { | |
985 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 ); |
|
985 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 ); | |
986 | } |
|
986 | } | |
987 | } |
|
987 | } | |
988 |
|
988 | |||
989 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) |
|
989 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) | |
990 | { |
|
990 | { | |
991 | static unsigned char initStep = 1; |
|
991 | static unsigned char initStep = 1; | |
992 |
|
992 | |||
993 | unsigned char currentTimecodeCtr; |
|
993 | unsigned char currentTimecodeCtr; | |
994 |
|
994 | |||
995 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
995 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); | |
996 |
|
996 | |||
997 | if (initStep == 1) |
|
997 | if (initStep == 1) | |
998 | { |
|
998 | { | |
999 | if (currentTimecodeCtr == previousTimecodeCtr) |
|
999 | if (currentTimecodeCtr == previousTimecodeCtr) | |
1000 | { |
|
1000 | { | |
1001 | //************************ |
|
1001 | //************************ | |
1002 | // HK_LFR_TIMECODE_MISSING |
|
1002 | // HK_LFR_TIMECODE_MISSING | |
1003 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING |
|
1003 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING | |
1004 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); |
|
1004 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); | |
1005 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING ); |
|
1005 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING ); | |
1006 | } |
|
1006 | } | |
1007 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) |
|
1007 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) | |
1008 | { |
|
1008 | { | |
1009 | // the timecode value has changed and the value is valid, this is unexpected because |
|
1009 | // the timecode value has changed and the value is valid, this is unexpected because | |
1010 | // the timer should not have fired, the timecode_irq_handler should have been raised |
|
1010 | // the timer should not have fired, the timecode_irq_handler should have been raised | |
1011 | } |
|
1011 | } | |
1012 | else |
|
1012 | else | |
1013 | { |
|
1013 | { | |
1014 | //************************ |
|
1014 | //************************ | |
1015 | // HK_LFR_TIMECODE_INVALID |
|
1015 | // HK_LFR_TIMECODE_INVALID | |
1016 | // the timecode value has changed and the value is not valid, no tickout has been generated |
|
1016 | // the timecode value has changed and the value is not valid, no tickout has been generated | |
1017 | // this is why the timer has fired |
|
1017 | // this is why the timer has fired | |
1018 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); |
|
1018 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); | |
1019 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID ); |
|
1019 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID ); | |
1020 | } |
|
1020 | } | |
1021 | } |
|
1021 | } | |
1022 | else |
|
1022 | else | |
1023 | { |
|
1023 | { | |
1024 | initStep = 1; |
|
1024 | initStep = 1; | |
1025 | //************************ |
|
1025 | //************************ | |
1026 | // HK_LFR_TIMECODE_MISSING |
|
1026 | // HK_LFR_TIMECODE_MISSING | |
1027 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); |
|
1027 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); | |
1028 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING ); |
|
1028 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING ); | |
1029 | } |
|
1029 | } | |
1030 |
|
1030 | |||
1031 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); |
|
1031 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); | |
1032 | } |
|
1032 | } | |
1033 |
|
1033 | |||
1034 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1034 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) | |
1035 | { |
|
1035 | { | |
1036 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1036 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
1037 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1037 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
1038 | header->reserved = DEFAULT_RESERVED; |
|
1038 | header->reserved = DEFAULT_RESERVED; | |
1039 | header->userApplication = CCSDS_USER_APP; |
|
1039 | header->userApplication = CCSDS_USER_APP; | |
1040 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1040 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; | |
1041 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; |
|
1041 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; | |
1042 | header->packetLength[0] = INIT_CHAR; |
|
1042 | header->packetLength[0] = INIT_CHAR; | |
1043 | header->packetLength[1] = INIT_CHAR; |
|
1043 | header->packetLength[1] = INIT_CHAR; | |
1044 | // DATA FIELD HEADER |
|
1044 | // DATA FIELD HEADER | |
1045 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
1045 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
1046 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
1046 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
1047 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
1047 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype | |
1048 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
1048 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
1049 | header->time[BYTE_0] = INIT_CHAR; |
|
1049 | header->time[BYTE_0] = INIT_CHAR; | |
1050 | header->time[BYTE_1] = INIT_CHAR; |
|
1050 | header->time[BYTE_1] = INIT_CHAR; | |
1051 | header->time[BYTE_2] = INIT_CHAR; |
|
1051 | header->time[BYTE_2] = INIT_CHAR; | |
1052 | header->time[BYTE_3] = INIT_CHAR; |
|
1052 | header->time[BYTE_3] = INIT_CHAR; | |
1053 | header->time[BYTE_4] = INIT_CHAR; |
|
1053 | header->time[BYTE_4] = INIT_CHAR; | |
1054 | header->time[BYTE_5] = INIT_CHAR; |
|
1054 | header->time[BYTE_5] = INIT_CHAR; | |
1055 | // AUXILIARY DATA HEADER |
|
1055 | // AUXILIARY DATA HEADER | |
1056 | header->sid = INIT_CHAR; |
|
1056 | header->sid = INIT_CHAR; | |
1057 | header->pa_bia_status_info = DEFAULT_HKBIA; |
|
1057 | header->pa_bia_status_info = DEFAULT_HKBIA; | |
1058 | header->blkNr[0] = INIT_CHAR; |
|
1058 | header->blkNr[0] = INIT_CHAR; | |
1059 | header->blkNr[1] = INIT_CHAR; |
|
1059 | header->blkNr[1] = INIT_CHAR; | |
1060 | } |
|
1060 | } | |
1061 |
|
1061 | |||
1062 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
1062 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) | |
1063 | { |
|
1063 | { | |
1064 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1064 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
1065 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1065 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
1066 | header->reserved = DEFAULT_RESERVED; |
|
1066 | header->reserved = DEFAULT_RESERVED; | |
1067 | header->userApplication = CCSDS_USER_APP; |
|
1067 | header->userApplication = CCSDS_USER_APP; | |
1068 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1068 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); | |
1069 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1069 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
1070 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1070 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
1071 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1071 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
1072 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE); |
|
1072 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE); | |
1073 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
1073 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | |
1074 | // DATA FIELD HEADER |
|
1074 | // DATA FIELD HEADER | |
1075 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
1075 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
1076 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
1076 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
1077 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
1077 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype | |
1078 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
1078 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
1079 | header->time[BYTE_0] = INIT_CHAR; |
|
1079 | header->time[BYTE_0] = INIT_CHAR; | |
1080 | header->time[BYTE_1] = INIT_CHAR; |
|
1080 | header->time[BYTE_1] = INIT_CHAR; | |
1081 | header->time[BYTE_2] = INIT_CHAR; |
|
1081 | header->time[BYTE_2] = INIT_CHAR; | |
1082 | header->time[BYTE_3] = INIT_CHAR; |
|
1082 | header->time[BYTE_3] = INIT_CHAR; | |
1083 | header->time[BYTE_4] = INIT_CHAR; |
|
1083 | header->time[BYTE_4] = INIT_CHAR; | |
1084 | header->time[BYTE_5] = INIT_CHAR; |
|
1084 | header->time[BYTE_5] = INIT_CHAR; | |
1085 | // AUXILIARY DATA HEADER |
|
1085 | // AUXILIARY DATA HEADER | |
1086 | header->sid = INIT_CHAR; |
|
1086 | header->sid = INIT_CHAR; | |
1087 | header->pa_bia_status_info = DEFAULT_HKBIA; |
|
1087 | header->pa_bia_status_info = DEFAULT_HKBIA; | |
1088 | header->pktCnt = PKTCNT_SWF; // PKT_CNT |
|
1088 | header->pktCnt = PKTCNT_SWF; // PKT_CNT | |
1089 | header->pktNr = INIT_CHAR; |
|
1089 | header->pktNr = INIT_CHAR; | |
1090 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE); |
|
1090 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE); | |
1091 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
1091 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); | |
1092 | } |
|
1092 | } | |
1093 |
|
1093 | |||
1094 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1094 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1095 | { |
|
1095 | { | |
1096 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
1096 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
1097 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
1097 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
1098 | header->reserved = DEFAULT_RESERVED; |
|
1098 | header->reserved = DEFAULT_RESERVED; | |
1099 | header->userApplication = CCSDS_USER_APP; |
|
1099 | header->userApplication = CCSDS_USER_APP; | |
1100 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1100 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); | |
1101 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1101 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
1102 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
1102 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
1103 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
1103 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
1104 | header->packetLength[0] = INIT_CHAR; |
|
1104 | header->packetLength[0] = INIT_CHAR; | |
1105 | header->packetLength[1] = INIT_CHAR; |
|
1105 | header->packetLength[1] = INIT_CHAR; | |
1106 | // DATA FIELD HEADER |
|
1106 | // DATA FIELD HEADER | |
1107 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
1107 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
1108 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
1108 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
1109 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype |
|
1109 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype | |
1110 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
1110 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
1111 | header->time[BYTE_0] = INIT_CHAR; |
|
1111 | header->time[BYTE_0] = INIT_CHAR; | |
1112 | header->time[BYTE_1] = INIT_CHAR; |
|
1112 | header->time[BYTE_1] = INIT_CHAR; | |
1113 | header->time[BYTE_2] = INIT_CHAR; |
|
1113 | header->time[BYTE_2] = INIT_CHAR; | |
1114 | header->time[BYTE_3] = INIT_CHAR; |
|
1114 | header->time[BYTE_3] = INIT_CHAR; | |
1115 | header->time[BYTE_4] = INIT_CHAR; |
|
1115 | header->time[BYTE_4] = INIT_CHAR; | |
1116 | header->time[BYTE_5] = INIT_CHAR; |
|
1116 | header->time[BYTE_5] = INIT_CHAR; | |
1117 | // AUXILIARY DATA HEADER |
|
1117 | // AUXILIARY DATA HEADER | |
1118 | header->sid = INIT_CHAR; |
|
1118 | header->sid = INIT_CHAR; | |
1119 | header->pa_bia_status_info = INIT_CHAR; |
|
1119 | header->pa_bia_status_info = INIT_CHAR; | |
1120 | header->pa_lfr_pkt_cnt_asm = INIT_CHAR; |
|
1120 | header->pa_lfr_pkt_cnt_asm = INIT_CHAR; | |
1121 | header->pa_lfr_pkt_nr_asm = INIT_CHAR; |
|
1121 | header->pa_lfr_pkt_nr_asm = INIT_CHAR; | |
1122 | header->pa_lfr_asm_blk_nr[0] = INIT_CHAR; |
|
1122 | header->pa_lfr_asm_blk_nr[0] = INIT_CHAR; | |
1123 | header->pa_lfr_asm_blk_nr[1] = INIT_CHAR; |
|
1123 | header->pa_lfr_asm_blk_nr[1] = INIT_CHAR; | |
1124 | } |
|
1124 | } | |
1125 |
|
1125 | |||
1126 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, |
|
1126 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, | |
1127 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1127 | Header_TM_LFR_SCIENCE_CWF_t *header ) | |
1128 | { |
|
1128 | { | |
1129 | /** This function sends CWF CCSDS packets (F2, F1 or F0). |
|
1129 | /** This function sends CWF CCSDS packets (F2, F1 or F0). | |
1130 | * |
|
1130 | * | |
1131 | * @param waveform points to the buffer containing the data that will be send. |
|
1131 | * @param waveform points to the buffer containing the data that will be send. | |
1132 | * @param sid is the source identifier of the data that will be sent. |
|
1132 | * @param sid is the source identifier of the data that will be sent. | |
1133 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
1133 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
1134 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1134 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1135 | * contain information to setup the transmission of the data packets. |
|
1135 | * contain information to setup the transmission of the data packets. | |
1136 | * |
|
1136 | * | |
1137 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
1137 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | |
1138 | * |
|
1138 | * | |
1139 | */ |
|
1139 | */ | |
1140 |
|
1140 | |||
1141 | unsigned int i; |
|
1141 | unsigned int i; | |
1142 | int ret; |
|
1142 | int ret; | |
1143 | unsigned int coarseTime; |
|
1143 | unsigned int coarseTime; | |
1144 | unsigned int fineTime; |
|
1144 | unsigned int fineTime; | |
1145 | rtems_status_code status; |
|
1145 | rtems_status_code status; | |
1146 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
1146 | spw_ioctl_pkt_send spw_ioctl_send_CWF; | |
1147 | int *dataPtr; |
|
1147 | int *dataPtr; | |
1148 | unsigned char sid; |
|
1148 | unsigned char sid; | |
1149 |
|
1149 | |||
1150 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1150 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; | |
1151 | spw_ioctl_send_CWF.options = 0; |
|
1151 | spw_ioctl_send_CWF.options = 0; | |
1152 |
|
1152 | |||
1153 | ret = LFR_DEFAULT; |
|
1153 | ret = LFR_DEFAULT; | |
1154 | sid = (unsigned char) ring_node_to_send->sid; |
|
1154 | sid = (unsigned char) ring_node_to_send->sid; | |
1155 |
|
1155 | |||
1156 | coarseTime = ring_node_to_send->coarseTime; |
|
1156 | coarseTime = ring_node_to_send->coarseTime; | |
1157 | fineTime = ring_node_to_send->fineTime; |
|
1157 | fineTime = ring_node_to_send->fineTime; | |
1158 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
1158 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
1159 |
|
1159 | |||
1160 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE); |
|
1160 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE); | |
1161 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
1161 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | |
1162 | header->pa_bia_status_info = pa_bia_status_info; |
|
1162 | header->pa_bia_status_info = pa_bia_status_info; | |
1163 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1163 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1164 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE); |
|
1164 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE); | |
1165 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
1165 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); | |
1166 |
|
1166 | |||
1167 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform |
|
1167 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform | |
1168 | { |
|
1168 | { | |
1169 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; |
|
1169 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; | |
1170 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1170 | spw_ioctl_send_CWF.hdr = (char*) header; | |
1171 | // BUILD THE DATA |
|
1171 | // BUILD THE DATA | |
1172 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; |
|
1172 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; | |
1173 |
|
1173 | |||
1174 | // SET PACKET SEQUENCE CONTROL |
|
1174 | // SET PACKET SEQUENCE CONTROL | |
1175 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1175 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1176 |
|
1176 | |||
1177 | // SET SID |
|
1177 | // SET SID | |
1178 | header->sid = sid; |
|
1178 | header->sid = sid; | |
1179 |
|
1179 | |||
1180 | // SET PACKET TIME |
|
1180 | // SET PACKET TIME | |
1181 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); |
|
1181 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); | |
1182 | // |
|
1182 | // | |
1183 | header->time[0] = header->acquisitionTime[0]; |
|
1183 | header->time[0] = header->acquisitionTime[0]; | |
1184 | header->time[1] = header->acquisitionTime[1]; |
|
1184 | header->time[1] = header->acquisitionTime[1]; | |
1185 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; |
|
1185 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; | |
1186 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; |
|
1186 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; | |
1187 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; |
|
1187 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; | |
1188 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; |
|
1188 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; | |
1189 |
|
1189 | |||
1190 | // SET PACKET ID |
|
1190 | // SET PACKET ID | |
1191 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) |
|
1191 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) | |
1192 | { |
|
1192 | { | |
1193 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE); |
|
1193 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE); | |
1194 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); |
|
1194 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); | |
1195 | } |
|
1195 | } | |
1196 | else |
|
1196 | else | |
1197 | { |
|
1197 | { | |
1198 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1198 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); | |
1199 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1199 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
1200 | } |
|
1200 | } | |
1201 |
|
1201 | |||
1202 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1202 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); | |
1203 | if (status != RTEMS_SUCCESSFUL) { |
|
1203 | if (status != RTEMS_SUCCESSFUL) { | |
1204 | ret = LFR_DEFAULT; |
|
1204 | ret = LFR_DEFAULT; | |
1205 | } |
|
1205 | } | |
1206 | } |
|
1206 | } | |
1207 |
|
1207 | |||
1208 | return ret; |
|
1208 | return ret; | |
1209 | } |
|
1209 | } | |
1210 |
|
1210 | |||
1211 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, |
|
1211 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, | |
1212 | Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
1212 | Header_TM_LFR_SCIENCE_SWF_t *header ) | |
1213 | { |
|
1213 | { | |
1214 | /** This function sends SWF CCSDS packets (F2, F1 or F0). |
|
1214 | /** This function sends SWF CCSDS packets (F2, F1 or F0). | |
1215 | * |
|
1215 | * | |
1216 | * @param waveform points to the buffer containing the data that will be send. |
|
1216 | * @param waveform points to the buffer containing the data that will be send. | |
1217 | * @param sid is the source identifier of the data that will be sent. |
|
1217 | * @param sid is the source identifier of the data that will be sent. | |
1218 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. |
|
1218 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. | |
1219 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1219 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1220 | * contain information to setup the transmission of the data packets. |
|
1220 | * contain information to setup the transmission of the data packets. | |
1221 | * |
|
1221 | * | |
1222 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
1222 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | |
1223 | * |
|
1223 | * | |
1224 | */ |
|
1224 | */ | |
1225 |
|
1225 | |||
1226 | unsigned int i; |
|
1226 | unsigned int i; | |
1227 | int ret; |
|
1227 | int ret; | |
1228 | unsigned int coarseTime; |
|
1228 | unsigned int coarseTime; | |
1229 | unsigned int fineTime; |
|
1229 | unsigned int fineTime; | |
1230 | rtems_status_code status; |
|
1230 | rtems_status_code status; | |
1231 | spw_ioctl_pkt_send spw_ioctl_send_SWF; |
|
1231 | spw_ioctl_pkt_send spw_ioctl_send_SWF; | |
1232 | int *dataPtr; |
|
1232 | int *dataPtr; | |
1233 | unsigned char sid; |
|
1233 | unsigned char sid; | |
1234 |
|
1234 | |||
1235 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; |
|
1235 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; | |
1236 | spw_ioctl_send_SWF.options = 0; |
|
1236 | spw_ioctl_send_SWF.options = 0; | |
1237 |
|
1237 | |||
1238 | ret = LFR_DEFAULT; |
|
1238 | ret = LFR_DEFAULT; | |
1239 |
|
1239 | |||
1240 | coarseTime = ring_node_to_send->coarseTime; |
|
1240 | coarseTime = ring_node_to_send->coarseTime; | |
1241 | fineTime = ring_node_to_send->fineTime; |
|
1241 | fineTime = ring_node_to_send->fineTime; | |
1242 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
1242 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
1243 | sid = ring_node_to_send->sid; |
|
1243 | sid = ring_node_to_send->sid; | |
1244 |
|
1244 | |||
1245 | header->pa_bia_status_info = pa_bia_status_info; |
|
1245 | header->pa_bia_status_info = pa_bia_status_info; | |
1246 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1246 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1247 |
|
1247 | |||
1248 | for (i=0; i<PKTCNT_SWF; i++) // send waveform |
|
1248 | for (i=0; i<PKTCNT_SWF; i++) // send waveform | |
1249 | { |
|
1249 | { | |
1250 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; |
|
1250 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; | |
1251 | spw_ioctl_send_SWF.hdr = (char*) header; |
|
1251 | spw_ioctl_send_SWF.hdr = (char*) header; | |
1252 |
|
1252 | |||
1253 | // SET PACKET SEQUENCE CONTROL |
|
1253 | // SET PACKET SEQUENCE CONTROL | |
1254 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1254 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1255 |
|
1255 | |||
1256 | // SET PACKET LENGTH AND BLKNR |
|
1256 | // SET PACKET LENGTH AND BLKNR | |
1257 | if (i == (PKTCNT_SWF-1)) |
|
1257 | if (i == (PKTCNT_SWF-1)) | |
1258 | { |
|
1258 | { | |
1259 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; |
|
1259 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; | |
1260 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE); |
|
1260 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE); | |
1261 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); |
|
1261 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); | |
1262 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE); |
|
1262 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE); | |
1263 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); |
|
1263 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); | |
1264 | } |
|
1264 | } | |
1265 | else |
|
1265 | else | |
1266 | { |
|
1266 | { | |
1267 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; |
|
1267 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; | |
1268 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE); |
|
1268 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE); | |
1269 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); |
|
1269 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); | |
1270 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE); |
|
1270 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE); | |
1271 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); |
|
1271 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); | |
1272 | } |
|
1272 | } | |
1273 |
|
1273 | |||
1274 | // SET PACKET TIME |
|
1274 | // SET PACKET TIME | |
1275 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); |
|
1275 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); | |
1276 | // |
|
1276 | // | |
1277 | header->time[BYTE_0] = header->acquisitionTime[BYTE_0]; |
|
1277 | header->time[BYTE_0] = header->acquisitionTime[BYTE_0]; | |
1278 | header->time[BYTE_1] = header->acquisitionTime[BYTE_1]; |
|
1278 | header->time[BYTE_1] = header->acquisitionTime[BYTE_1]; | |
1279 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; |
|
1279 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; | |
1280 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; |
|
1280 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; | |
1281 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; |
|
1281 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; | |
1282 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; |
|
1282 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; | |
1283 |
|
1283 | |||
1284 | // SET SID |
|
1284 | // SET SID | |
1285 | header->sid = sid; |
|
1285 | header->sid = sid; | |
1286 |
|
1286 | |||
1287 | // SET PKTNR |
|
1287 | // SET PKTNR | |
1288 | header->pktNr = i+1; // PKT_NR |
|
1288 | header->pktNr = i+1; // PKT_NR | |
1289 |
|
1289 | |||
1290 | // SEND PACKET |
|
1290 | // SEND PACKET | |
1291 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); |
|
1291 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); | |
1292 | if (status != RTEMS_SUCCESSFUL) { |
|
1292 | if (status != RTEMS_SUCCESSFUL) { | |
1293 | ret = LFR_DEFAULT; |
|
1293 | ret = LFR_DEFAULT; | |
1294 | } |
|
1294 | } | |
1295 | } |
|
1295 | } | |
1296 |
|
1296 | |||
1297 | return ret; |
|
1297 | return ret; | |
1298 | } |
|
1298 | } | |
1299 |
|
1299 | |||
1300 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, |
|
1300 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, | |
1301 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1301 | Header_TM_LFR_SCIENCE_CWF_t *header ) | |
1302 | { |
|
1302 | { | |
1303 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
1303 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. | |
1304 | * |
|
1304 | * | |
1305 | * @param waveform points to the buffer containing the data that will be send. |
|
1305 | * @param waveform points to the buffer containing the data that will be send. | |
1306 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
1306 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
1307 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1307 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1308 | * contain information to setup the transmission of the data packets. |
|
1308 | * contain information to setup the transmission of the data packets. | |
1309 | * |
|
1309 | * | |
1310 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
1310 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer | |
1311 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
1311 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. | |
1312 | * |
|
1312 | * | |
1313 | */ |
|
1313 | */ | |
1314 |
|
1314 | |||
1315 | unsigned int i; |
|
1315 | unsigned int i; | |
1316 | int ret; |
|
1316 | int ret; | |
1317 | unsigned int coarseTime; |
|
1317 | unsigned int coarseTime; | |
1318 | unsigned int fineTime; |
|
1318 | unsigned int fineTime; | |
1319 | rtems_status_code status; |
|
1319 | rtems_status_code status; | |
1320 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
1320 | spw_ioctl_pkt_send spw_ioctl_send_CWF; | |
1321 | char *dataPtr; |
|
1321 | char *dataPtr; | |
1322 | unsigned char sid; |
|
1322 | unsigned char sid; | |
1323 |
|
1323 | |||
1324 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1324 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; | |
1325 | spw_ioctl_send_CWF.options = 0; |
|
1325 | spw_ioctl_send_CWF.options = 0; | |
1326 |
|
1326 | |||
1327 | ret = LFR_DEFAULT; |
|
1327 | ret = LFR_DEFAULT; | |
1328 | sid = ring_node_to_send->sid; |
|
1328 | sid = ring_node_to_send->sid; | |
1329 |
|
1329 | |||
1330 | coarseTime = ring_node_to_send->coarseTime; |
|
1330 | coarseTime = ring_node_to_send->coarseTime; | |
1331 | fineTime = ring_node_to_send->fineTime; |
|
1331 | fineTime = ring_node_to_send->fineTime; | |
1332 | dataPtr = (char*) ring_node_to_send->buffer_address; |
|
1332 | dataPtr = (char*) ring_node_to_send->buffer_address; | |
1333 |
|
1333 | |||
1334 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE); |
|
1334 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE); | |
1335 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); |
|
1335 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); | |
1336 | header->pa_bia_status_info = pa_bia_status_info; |
|
1336 | header->pa_bia_status_info = pa_bia_status_info; | |
1337 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1337 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1338 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE); |
|
1338 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE); | |
1339 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); |
|
1339 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); | |
1340 |
|
1340 | |||
1341 | //********************* |
|
1341 | //********************* | |
1342 | // SEND CWF3_light DATA |
|
1342 | // SEND CWF3_light DATA | |
1343 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform |
|
1343 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform | |
1344 | { |
|
1344 | { | |
1345 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; |
|
1345 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; | |
1346 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1346 | spw_ioctl_send_CWF.hdr = (char*) header; | |
1347 | // BUILD THE DATA |
|
1347 | // BUILD THE DATA | |
1348 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; |
|
1348 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; | |
1349 |
|
1349 | |||
1350 | // SET PACKET SEQUENCE COUNTER |
|
1350 | // SET PACKET SEQUENCE COUNTER | |
1351 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1351 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1352 |
|
1352 | |||
1353 | // SET SID |
|
1353 | // SET SID | |
1354 | header->sid = sid; |
|
1354 | header->sid = sid; | |
1355 |
|
1355 | |||
1356 | // SET PACKET TIME |
|
1356 | // SET PACKET TIME | |
1357 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); |
|
1357 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); | |
1358 | // |
|
1358 | // | |
1359 | header->time[BYTE_0] = header->acquisitionTime[BYTE_0]; |
|
1359 | header->time[BYTE_0] = header->acquisitionTime[BYTE_0]; | |
1360 | header->time[BYTE_1] = header->acquisitionTime[BYTE_1]; |
|
1360 | header->time[BYTE_1] = header->acquisitionTime[BYTE_1]; | |
1361 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; |
|
1361 | header->time[BYTE_2] = header->acquisitionTime[BYTE_2]; | |
1362 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; |
|
1362 | header->time[BYTE_3] = header->acquisitionTime[BYTE_3]; | |
1363 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; |
|
1363 | header->time[BYTE_4] = header->acquisitionTime[BYTE_4]; | |
1364 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; |
|
1364 | header->time[BYTE_5] = header->acquisitionTime[BYTE_5]; | |
1365 |
|
1365 | |||
1366 | // SET PACKET ID |
|
1366 | // SET PACKET ID | |
1367 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); |
|
1367 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE); | |
1368 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1368 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
1369 |
|
1369 | |||
1370 | // SEND PACKET |
|
1370 | // SEND PACKET | |
1371 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1371 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); | |
1372 | if (status != RTEMS_SUCCESSFUL) { |
|
1372 | if (status != RTEMS_SUCCESSFUL) { | |
1373 | ret = LFR_DEFAULT; |
|
1373 | ret = LFR_DEFAULT; | |
1374 | } |
|
1374 | } | |
1375 | } |
|
1375 | } | |
1376 |
|
1376 | |||
1377 | return ret; |
|
1377 | return ret; | |
1378 | } |
|
1378 | } | |
1379 |
|
1379 | |||
1380 | void spw_send_asm_f0( ring_node *ring_node_to_send, |
|
1380 | void spw_send_asm_f0( ring_node *ring_node_to_send, | |
1381 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1381 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1382 | { |
|
1382 | { | |
1383 | unsigned int i; |
|
1383 | unsigned int i; | |
1384 | unsigned int length = 0; |
|
1384 | unsigned int length = 0; | |
1385 | rtems_status_code status; |
|
1385 | rtems_status_code status; | |
1386 | unsigned int sid; |
|
1386 | unsigned int sid; | |
1387 | float *spectral_matrix; |
|
1387 | float *spectral_matrix; | |
1388 | int coarseTime; |
|
1388 | int coarseTime; | |
1389 | int fineTime; |
|
1389 | int fineTime; | |
1390 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1390 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1391 |
|
1391 | |||
1392 | sid = ring_node_to_send->sid; |
|
1392 | sid = ring_node_to_send->sid; | |
1393 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1393 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1394 | coarseTime = ring_node_to_send->coarseTime; |
|
1394 | coarseTime = ring_node_to_send->coarseTime; | |
1395 | fineTime = ring_node_to_send->fineTime; |
|
1395 | fineTime = ring_node_to_send->fineTime; | |
1396 |
|
1396 | |||
1397 | header->pa_bia_status_info = pa_bia_status_info; |
|
1397 | header->pa_bia_status_info = pa_bia_status_info; | |
1398 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1398 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1399 |
|
1399 | |||
1400 | for (i=0; i<PKTCNT_ASM; i++) |
|
1400 | for (i=0; i<PKTCNT_ASM; i++) | |
1401 | { |
|
1401 | { | |
1402 | if ((i==0) || (i==1)) |
|
1402 | if ((i==0) || (i==1)) | |
1403 | { |
|
1403 | { | |
1404 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; |
|
1404 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; | |
1405 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1405 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1406 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1406 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) | |
1407 | ]; |
|
1407 | ]; | |
1408 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; |
|
1408 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; | |
1409 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1409 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1410 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1410 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB | |
1411 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB |
|
1411 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB | |
1412 | } |
|
1412 | } | |
1413 | else |
|
1413 | else | |
1414 | { |
|
1414 | { | |
1415 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; |
|
1415 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; | |
1416 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1416 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ | |
1417 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1417 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) | |
1418 | ]; |
|
1418 | ]; | |
1419 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; |
|
1419 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; | |
1420 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1420 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1421 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1421 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB | |
1422 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB |
|
1422 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB | |
1423 | } |
|
1423 | } | |
1424 |
|
1424 | |||
1425 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1425 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1426 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1426 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1427 | spw_ioctl_send_ASM.options = 0; |
|
1427 | spw_ioctl_send_ASM.options = 0; | |
1428 |
|
1428 | |||
1429 | // (2) BUILD THE HEADER |
|
1429 | // (2) BUILD THE HEADER | |
1430 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1430 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1431 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); |
|
1431 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); | |
1432 | header->packetLength[1] = (unsigned char) (length); |
|
1432 | header->packetLength[1] = (unsigned char) (length); | |
1433 | header->sid = (unsigned char) sid; // SID |
|
1433 | header->sid = (unsigned char) sid; // SID | |
1434 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; |
|
1434 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; | |
1435 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1435 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1436 |
|
1436 | |||
1437 | // (3) SET PACKET TIME |
|
1437 | // (3) SET PACKET TIME | |
1438 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); |
|
1438 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); | |
1439 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); |
|
1439 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); | |
1440 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); |
|
1440 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); | |
1441 | header->time[BYTE_3] = (unsigned char) (coarseTime); |
|
1441 | header->time[BYTE_3] = (unsigned char) (coarseTime); | |
1442 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); |
|
1442 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); | |
1443 | header->time[BYTE_5] = (unsigned char) (fineTime); |
|
1443 | header->time[BYTE_5] = (unsigned char) (fineTime); | |
1444 | // |
|
1444 | // | |
1445 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; |
|
1445 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; | |
1446 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; |
|
1446 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; | |
1447 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; |
|
1447 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; | |
1448 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; |
|
1448 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; | |
1449 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; |
|
1449 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; | |
1450 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; |
|
1450 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; | |
1451 |
|
1451 | |||
1452 | // (4) SEND PACKET |
|
1452 | // (4) SEND PACKET | |
1453 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1453 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1454 | if (status != RTEMS_SUCCESSFUL) { |
|
1454 | if (status != RTEMS_SUCCESSFUL) { | |
1455 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1455 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1456 | } |
|
1456 | } | |
1457 | } |
|
1457 | } | |
1458 | } |
|
1458 | } | |
1459 |
|
1459 | |||
1460 | void spw_send_asm_f1( ring_node *ring_node_to_send, |
|
1460 | void spw_send_asm_f1( ring_node *ring_node_to_send, | |
1461 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1461 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1462 | { |
|
1462 | { | |
1463 | unsigned int i; |
|
1463 | unsigned int i; | |
1464 | unsigned int length = 0; |
|
1464 | unsigned int length = 0; | |
1465 | rtems_status_code status; |
|
1465 | rtems_status_code status; | |
1466 | unsigned int sid; |
|
1466 | unsigned int sid; | |
1467 | float *spectral_matrix; |
|
1467 | float *spectral_matrix; | |
1468 | int coarseTime; |
|
1468 | int coarseTime; | |
1469 | int fineTime; |
|
1469 | int fineTime; | |
1470 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1470 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1471 |
|
1471 | |||
1472 | sid = ring_node_to_send->sid; |
|
1472 | sid = ring_node_to_send->sid; | |
1473 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1473 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1474 | coarseTime = ring_node_to_send->coarseTime; |
|
1474 | coarseTime = ring_node_to_send->coarseTime; | |
1475 | fineTime = ring_node_to_send->fineTime; |
|
1475 | fineTime = ring_node_to_send->fineTime; | |
1476 |
|
1476 | |||
1477 | header->pa_bia_status_info = pa_bia_status_info; |
|
1477 | header->pa_bia_status_info = pa_bia_status_info; | |
1478 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1478 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1479 |
|
1479 | |||
1480 | for (i=0; i<PKTCNT_ASM; i++) |
|
1480 | for (i=0; i<PKTCNT_ASM; i++) | |
1481 | { |
|
1481 | { | |
1482 | if ((i==0) || (i==1)) |
|
1482 | if ((i==0) || (i==1)) | |
1483 | { |
|
1483 | { | |
1484 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; |
|
1484 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; | |
1485 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1485 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1486 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1486 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) | |
1487 | ]; |
|
1487 | ]; | |
1488 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; |
|
1488 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; | |
1489 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1489 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1490 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1490 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB | |
1491 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB |
|
1491 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB | |
1492 | } |
|
1492 | } | |
1493 | else |
|
1493 | else | |
1494 | { |
|
1494 | { | |
1495 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; |
|
1495 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; | |
1496 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1496 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ | |
1497 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1497 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) | |
1498 | ]; |
|
1498 | ]; | |
1499 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; |
|
1499 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; | |
1500 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1500 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1501 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1501 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB | |
1502 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB |
|
1502 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB | |
1503 | } |
|
1503 | } | |
1504 |
|
1504 | |||
1505 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1505 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1506 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1506 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1507 | spw_ioctl_send_ASM.options = 0; |
|
1507 | spw_ioctl_send_ASM.options = 0; | |
1508 |
|
1508 | |||
1509 | // (2) BUILD THE HEADER |
|
1509 | // (2) BUILD THE HEADER | |
1510 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1510 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1511 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); |
|
1511 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); | |
1512 | header->packetLength[1] = (unsigned char) (length); |
|
1512 | header->packetLength[1] = (unsigned char) (length); | |
1513 | header->sid = (unsigned char) sid; // SID |
|
1513 | header->sid = (unsigned char) sid; // SID | |
1514 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; |
|
1514 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; | |
1515 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1515 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1516 |
|
1516 | |||
1517 | // (3) SET PACKET TIME |
|
1517 | // (3) SET PACKET TIME | |
1518 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); |
|
1518 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); | |
1519 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); |
|
1519 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); | |
1520 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); |
|
1520 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); | |
1521 | header->time[BYTE_3] = (unsigned char) (coarseTime); |
|
1521 | header->time[BYTE_3] = (unsigned char) (coarseTime); | |
1522 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); |
|
1522 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); | |
1523 | header->time[BYTE_5] = (unsigned char) (fineTime); |
|
1523 | header->time[BYTE_5] = (unsigned char) (fineTime); | |
1524 | // |
|
1524 | // | |
1525 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; |
|
1525 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; | |
1526 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; |
|
1526 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; | |
1527 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; |
|
1527 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; | |
1528 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; |
|
1528 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; | |
1529 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; |
|
1529 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; | |
1530 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; |
|
1530 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; | |
1531 |
|
1531 | |||
1532 | // (4) SEND PACKET |
|
1532 | // (4) SEND PACKET | |
1533 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1533 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1534 | if (status != RTEMS_SUCCESSFUL) { |
|
1534 | if (status != RTEMS_SUCCESSFUL) { | |
1535 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1535 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1536 | } |
|
1536 | } | |
1537 | } |
|
1537 | } | |
1538 | } |
|
1538 | } | |
1539 |
|
1539 | |||
1540 | void spw_send_asm_f2( ring_node *ring_node_to_send, |
|
1540 | void spw_send_asm_f2( ring_node *ring_node_to_send, | |
1541 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1541 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1542 | { |
|
1542 | { | |
1543 | unsigned int i; |
|
1543 | unsigned int i; | |
1544 | unsigned int length = 0; |
|
1544 | unsigned int length = 0; | |
1545 | rtems_status_code status; |
|
1545 | rtems_status_code status; | |
1546 | unsigned int sid; |
|
1546 | unsigned int sid; | |
1547 | float *spectral_matrix; |
|
1547 | float *spectral_matrix; | |
1548 | int coarseTime; |
|
1548 | int coarseTime; | |
1549 | int fineTime; |
|
1549 | int fineTime; | |
1550 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1550 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1551 |
|
1551 | |||
1552 | sid = ring_node_to_send->sid; |
|
1552 | sid = ring_node_to_send->sid; | |
1553 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1553 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1554 | coarseTime = ring_node_to_send->coarseTime; |
|
1554 | coarseTime = ring_node_to_send->coarseTime; | |
1555 | fineTime = ring_node_to_send->fineTime; |
|
1555 | fineTime = ring_node_to_send->fineTime; | |
1556 |
|
1556 | |||
1557 | header->pa_bia_status_info = pa_bia_status_info; |
|
1557 | header->pa_bia_status_info = pa_bia_status_info; | |
1558 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1558 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1559 |
|
1559 | |||
1560 | for (i=0; i<PKTCNT_ASM; i++) |
|
1560 | for (i=0; i<PKTCNT_ASM; i++) | |
1561 | { |
|
1561 | { | |
1562 |
|
1562 | |||
1563 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; |
|
1563 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; | |
1564 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1564 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1565 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) |
|
1565 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) | |
1566 | ]; |
|
1566 | ]; | |
1567 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; |
|
1567 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; | |
1568 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; |
|
1568 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; | |
1569 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB |
|
1569 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB | |
1570 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB |
|
1570 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB | |
1571 |
|
1571 | |||
1572 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1572 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1573 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1573 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1574 | spw_ioctl_send_ASM.options = 0; |
|
1574 | spw_ioctl_send_ASM.options = 0; | |
1575 |
|
1575 | |||
1576 | // (2) BUILD THE HEADER |
|
1576 | // (2) BUILD THE HEADER | |
1577 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1577 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1578 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); |
|
1578 | header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE); | |
1579 | header->packetLength[1] = (unsigned char) (length); |
|
1579 | header->packetLength[1] = (unsigned char) (length); | |
1580 | header->sid = (unsigned char) sid; // SID |
|
1580 | header->sid = (unsigned char) sid; // SID | |
1581 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; |
|
1581 | header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM; | |
1582 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1582 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1583 |
|
1583 | |||
1584 | // (3) SET PACKET TIME |
|
1584 | // (3) SET PACKET TIME | |
1585 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); |
|
1585 | header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES); | |
1586 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); |
|
1586 | header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES); | |
1587 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); |
|
1587 | header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE); | |
1588 | header->time[BYTE_3] = (unsigned char) (coarseTime); |
|
1588 | header->time[BYTE_3] = (unsigned char) (coarseTime); | |
1589 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); |
|
1589 | header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE); | |
1590 | header->time[BYTE_5] = (unsigned char) (fineTime); |
|
1590 | header->time[BYTE_5] = (unsigned char) (fineTime); | |
1591 | // |
|
1591 | // | |
1592 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; |
|
1592 | header->acquisitionTime[BYTE_0] = header->time[BYTE_0]; | |
1593 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; |
|
1593 | header->acquisitionTime[BYTE_1] = header->time[BYTE_1]; | |
1594 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; |
|
1594 | header->acquisitionTime[BYTE_2] = header->time[BYTE_2]; | |
1595 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; |
|
1595 | header->acquisitionTime[BYTE_3] = header->time[BYTE_3]; | |
1596 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; |
|
1596 | header->acquisitionTime[BYTE_4] = header->time[BYTE_4]; | |
1597 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; |
|
1597 | header->acquisitionTime[BYTE_5] = header->time[BYTE_5]; | |
1598 |
|
1598 | |||
1599 | // (4) SEND PACKET |
|
1599 | // (4) SEND PACKET | |
1600 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1600 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1601 | if (status != RTEMS_SUCCESSFUL) { |
|
1601 | if (status != RTEMS_SUCCESSFUL) { | |
1602 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1602 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1603 | } |
|
1603 | } | |
1604 | } |
|
1604 | } | |
1605 | } |
|
1605 | } | |
1606 |
|
1606 | |||
1607 | void spw_send_k_dump( ring_node *ring_node_to_send ) |
|
1607 | void spw_send_k_dump( ring_node *ring_node_to_send ) | |
1608 | { |
|
1608 | { | |
1609 | rtems_status_code status; |
|
1609 | rtems_status_code status; | |
1610 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; |
|
1610 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; | |
1611 | unsigned int packetLength; |
|
1611 | unsigned int packetLength; | |
1612 | unsigned int size; |
|
1612 | unsigned int size; | |
1613 |
|
1613 | |||
1614 | PRINTF("spw_send_k_dump\n") |
|
1614 | PRINTF("spw_send_k_dump\n") | |
1615 |
|
1615 | |||
1616 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; |
|
1616 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; | |
1617 |
|
1617 | |||
1618 | packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1]; |
|
1618 | packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1]; | |
1619 |
|
1619 | |||
1620 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
1620 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; | |
1621 |
|
1621 | |||
1622 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) |
|
1622 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) | |
1623 |
|
1623 | |||
1624 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); |
|
1624 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); | |
1625 |
|
1625 | |||
1626 | if (status == -1){ |
|
1626 | if (status == -1){ | |
1627 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
1627 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
1628 | } |
|
1628 | } | |
1629 |
|
1629 | |||
1630 | ring_node_to_send->status = INIT_CHAR; |
|
1630 | ring_node_to_send->status = INIT_CHAR; | |
1631 | } |
|
1631 | } |
@@ -1,1661 +1,1663 | |||||
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[BYTES_PER_TIME]; |
|
35 | unsigned char time[BYTES_PER_TIME]; | |
36 | rtems_id queue_rcv_id; |
|
36 | rtems_id queue_rcv_id; | |
37 | rtems_id queue_snd_id; |
|
37 | rtems_id queue_snd_id; | |
38 |
|
38 | |||
39 | memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t)); |
|
39 | memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t)); | |
40 | size = 0; |
|
40 | size = 0; | |
41 | queue_rcv_id = RTEMS_ID_NONE; |
|
41 | queue_rcv_id = RTEMS_ID_NONE; | |
42 | queue_snd_id = RTEMS_ID_NONE; |
|
42 | queue_snd_id = RTEMS_ID_NONE; | |
43 |
|
43 | |||
44 | status = get_message_queue_id_recv( &queue_rcv_id ); |
|
44 | status = get_message_queue_id_recv( &queue_rcv_id ); | |
45 | if (status != RTEMS_SUCCESSFUL) |
|
45 | if (status != RTEMS_SUCCESSFUL) | |
46 | { |
|
46 | { | |
47 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) |
|
47 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | status = get_message_queue_id_send( &queue_snd_id ); |
|
50 | status = get_message_queue_id_send( &queue_snd_id ); | |
51 | if (status != RTEMS_SUCCESSFUL) |
|
51 | if (status != RTEMS_SUCCESSFUL) | |
52 | { |
|
52 | { | |
53 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) |
|
53 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | result = LFR_SUCCESSFUL; |
|
56 | result = LFR_SUCCESSFUL; | |
57 | subtype = 0; // subtype of the current TC packet |
|
57 | subtype = 0; // subtype of the current TC packet | |
58 |
|
58 | |||
59 | BOOT_PRINTF("in ACTN *** \n"); |
|
59 | BOOT_PRINTF("in ACTN *** \n"); | |
60 |
|
60 | |||
61 | while(1) |
|
61 | while(1) | |
62 | { |
|
62 | { | |
63 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
63 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, | |
64 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
64 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); | |
65 | getTime( time ); // set time to the current time |
|
65 | getTime( time ); // set time to the current time | |
66 | if (status!=RTEMS_SUCCESSFUL) |
|
66 | if (status!=RTEMS_SUCCESSFUL) | |
67 | { |
|
67 | { | |
68 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
68 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) | |
69 | } |
|
69 | } | |
70 | else |
|
70 | else | |
71 | { |
|
71 | { | |
72 | subtype = TC.serviceSubType; |
|
72 | subtype = TC.serviceSubType; | |
73 | switch(subtype) |
|
73 | switch(subtype) | |
74 | { |
|
74 | { | |
75 | case TC_SUBTYPE_RESET: |
|
75 | case TC_SUBTYPE_RESET: | |
76 | result = action_reset( &TC, queue_snd_id, time ); |
|
76 | result = action_reset( &TC, queue_snd_id, time ); | |
77 | close_action( &TC, result, queue_snd_id ); |
|
77 | close_action( &TC, result, queue_snd_id ); | |
78 | break; |
|
78 | break; | |
79 | case TC_SUBTYPE_LOAD_COMM: |
|
79 | case TC_SUBTYPE_LOAD_COMM: | |
80 | result = action_load_common_par( &TC ); |
|
80 | result = action_load_common_par( &TC ); | |
81 | close_action( &TC, result, queue_snd_id ); |
|
81 | close_action( &TC, result, queue_snd_id ); | |
82 | break; |
|
82 | break; | |
83 | case TC_SUBTYPE_LOAD_NORM: |
|
83 | case TC_SUBTYPE_LOAD_NORM: | |
84 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
84 | result = action_load_normal_par( &TC, queue_snd_id, time ); | |
85 | close_action( &TC, result, queue_snd_id ); |
|
85 | close_action( &TC, result, queue_snd_id ); | |
86 | break; |
|
86 | break; | |
87 | case TC_SUBTYPE_LOAD_BURST: |
|
87 | case TC_SUBTYPE_LOAD_BURST: | |
88 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
88 | result = action_load_burst_par( &TC, queue_snd_id, time ); | |
89 | close_action( &TC, result, queue_snd_id ); |
|
89 | close_action( &TC, result, queue_snd_id ); | |
90 | break; |
|
90 | break; | |
91 | case TC_SUBTYPE_LOAD_SBM1: |
|
91 | case TC_SUBTYPE_LOAD_SBM1: | |
92 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
92 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); | |
93 | close_action( &TC, result, queue_snd_id ); |
|
93 | close_action( &TC, result, queue_snd_id ); | |
94 | break; |
|
94 | break; | |
95 | case TC_SUBTYPE_LOAD_SBM2: |
|
95 | case TC_SUBTYPE_LOAD_SBM2: | |
96 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
96 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); | |
97 | close_action( &TC, result, queue_snd_id ); |
|
97 | close_action( &TC, result, queue_snd_id ); | |
98 | break; |
|
98 | break; | |
99 | case TC_SUBTYPE_DUMP: |
|
99 | case TC_SUBTYPE_DUMP: | |
100 | result = action_dump_par( &TC, queue_snd_id ); |
|
100 | result = action_dump_par( &TC, queue_snd_id ); | |
101 | close_action( &TC, result, queue_snd_id ); |
|
101 | close_action( &TC, result, queue_snd_id ); | |
102 | break; |
|
102 | break; | |
103 | case TC_SUBTYPE_ENTER: |
|
103 | case TC_SUBTYPE_ENTER: | |
104 | result = action_enter_mode( &TC, queue_snd_id ); |
|
104 | result = action_enter_mode( &TC, queue_snd_id ); | |
105 | close_action( &TC, result, queue_snd_id ); |
|
105 | close_action( &TC, result, queue_snd_id ); | |
106 | break; |
|
106 | break; | |
107 | case TC_SUBTYPE_UPDT_INFO: |
|
107 | case TC_SUBTYPE_UPDT_INFO: | |
108 | result = action_update_info( &TC, queue_snd_id ); |
|
108 | result = action_update_info( &TC, queue_snd_id ); | |
109 | close_action( &TC, result, queue_snd_id ); |
|
109 | close_action( &TC, result, queue_snd_id ); | |
110 | break; |
|
110 | break; | |
111 | case TC_SUBTYPE_EN_CAL: |
|
111 | case TC_SUBTYPE_EN_CAL: | |
112 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
112 | result = action_enable_calibration( &TC, queue_snd_id, time ); | |
113 | close_action( &TC, result, queue_snd_id ); |
|
113 | close_action( &TC, result, queue_snd_id ); | |
114 | break; |
|
114 | break; | |
115 | case TC_SUBTYPE_DIS_CAL: |
|
115 | case TC_SUBTYPE_DIS_CAL: | |
116 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
116 | result = action_disable_calibration( &TC, queue_snd_id, time ); | |
117 | close_action( &TC, result, queue_snd_id ); |
|
117 | close_action( &TC, result, queue_snd_id ); | |
118 | break; |
|
118 | break; | |
119 | case TC_SUBTYPE_LOAD_K: |
|
119 | case TC_SUBTYPE_LOAD_K: | |
120 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); |
|
120 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); | |
121 | close_action( &TC, result, queue_snd_id ); |
|
121 | close_action( &TC, result, queue_snd_id ); | |
122 | break; |
|
122 | break; | |
123 | case TC_SUBTYPE_DUMP_K: |
|
123 | case TC_SUBTYPE_DUMP_K: | |
124 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); |
|
124 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); | |
125 | close_action( &TC, result, queue_snd_id ); |
|
125 | close_action( &TC, result, queue_snd_id ); | |
126 | break; |
|
126 | break; | |
127 | case TC_SUBTYPE_LOAD_FBINS: |
|
127 | case TC_SUBTYPE_LOAD_FBINS: | |
128 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); |
|
128 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); | |
129 | close_action( &TC, result, queue_snd_id ); |
|
129 | close_action( &TC, result, queue_snd_id ); | |
130 | break; |
|
130 | break; | |
131 | case TC_SUBTYPE_LOAD_FILTER_PAR: |
|
131 | case TC_SUBTYPE_LOAD_FILTER_PAR: | |
132 | result = action_load_filter_par( &TC, queue_snd_id, time ); |
|
132 | result = action_load_filter_par( &TC, queue_snd_id, time ); | |
133 | close_action( &TC, result, queue_snd_id ); |
|
133 | close_action( &TC, result, queue_snd_id ); | |
134 | break; |
|
134 | break; | |
135 | case TC_SUBTYPE_UPDT_TIME: |
|
135 | case TC_SUBTYPE_UPDT_TIME: | |
136 | result = action_update_time( &TC ); |
|
136 | result = action_update_time( &TC ); | |
137 | close_action( &TC, result, queue_snd_id ); |
|
137 | close_action( &TC, result, queue_snd_id ); | |
138 | break; |
|
138 | break; | |
139 | default: |
|
139 | default: | |
140 | break; |
|
140 | break; | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 | } |
|
143 | } | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | //*********** |
|
146 | //*********** | |
147 | // TC ACTIONS |
|
147 | // TC ACTIONS | |
148 |
|
148 | |||
149 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
149 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
150 | { |
|
150 | { | |
151 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
151 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. | |
152 | * |
|
152 | * | |
153 | * @param TC points to the TeleCommand packet that is being processed |
|
153 | * @param TC points to the TeleCommand packet that is being processed | |
154 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
154 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
155 | * |
|
155 | * | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | PRINTF("this is the end!!!\n"); |
|
158 | PRINTF("this is the end!!!\n"); | |
159 | exit(0); |
|
159 | exit(0); | |
160 |
|
160 | |||
161 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
161 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); | |
162 |
|
162 | |||
163 | return LFR_DEFAULT; |
|
163 | return LFR_DEFAULT; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
166 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) | |
167 | { |
|
167 | { | |
168 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
168 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. | |
169 | * |
|
169 | * | |
170 | * @param TC points to the TeleCommand packet that is being processed |
|
170 | * @param TC points to the TeleCommand packet that is being processed | |
171 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
171 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
172 | * |
|
172 | * | |
173 | */ |
|
173 | */ | |
174 |
|
174 | |||
175 | rtems_status_code status; |
|
175 | rtems_status_code status; | |
176 | unsigned char requestedMode; |
|
176 | unsigned char requestedMode; | |
177 | unsigned int *transitionCoarseTime_ptr; |
|
177 | unsigned int *transitionCoarseTime_ptr; | |
178 | unsigned int transitionCoarseTime; |
|
178 | unsigned int transitionCoarseTime; | |
179 | unsigned char * bytePosPtr; |
|
179 | unsigned char * bytePosPtr; | |
180 |
|
180 | |||
181 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
181 | bytePosPtr = (unsigned char *) &TC->packetID; | |
182 |
|
182 | |||
183 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; |
|
183 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; | |
184 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); |
|
184 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); | |
185 | transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK; |
|
185 | transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK; | |
186 |
|
186 | |||
187 | status = check_mode_value( requestedMode ); |
|
187 | status = check_mode_value( requestedMode ); | |
188 |
|
188 | |||
189 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent |
|
189 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent | |
190 | { |
|
190 | { | |
191 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); |
|
191 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | else // the mode value is valid, check the transition |
|
194 | else // the mode value is valid, check the transition | |
195 | { |
|
195 | { | |
196 | status = check_mode_transition(requestedMode); |
|
196 | status = check_mode_transition(requestedMode); | |
197 | if (status != LFR_SUCCESSFUL) |
|
197 | if (status != LFR_SUCCESSFUL) | |
198 | { |
|
198 | { | |
199 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") |
|
199 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") | |
200 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
200 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); | |
201 | } |
|
201 | } | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date |
|
204 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date | |
205 | { |
|
205 | { | |
206 | status = check_transition_date( transitionCoarseTime ); |
|
206 | status = check_transition_date( transitionCoarseTime ); | |
207 | if (status != LFR_SUCCESSFUL) |
|
207 | if (status != LFR_SUCCESSFUL) | |
208 | { |
|
208 | { | |
209 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n"); |
|
209 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n"); | |
210 | send_tm_lfr_tc_exe_not_executable(TC, queue_id ); |
|
210 | send_tm_lfr_tc_exe_not_executable(TC, queue_id ); | |
211 | } |
|
211 | } | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode |
|
214 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode | |
215 | { |
|
215 | { | |
216 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); |
|
216 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); | |
217 |
|
217 | |||
218 | switch(requestedMode) |
|
218 | switch(requestedMode) | |
219 | { |
|
219 | { | |
220 | case LFR_MODE_STANDBY: |
|
220 | case LFR_MODE_STANDBY: | |
221 | status = enter_mode_standby(); |
|
221 | status = enter_mode_standby(); | |
222 | break; |
|
222 | break; | |
223 | case LFR_MODE_NORMAL: |
|
223 | case LFR_MODE_NORMAL: | |
224 | status = enter_mode_normal( transitionCoarseTime ); |
|
224 | status = enter_mode_normal( transitionCoarseTime ); | |
225 | break; |
|
225 | break; | |
226 | case LFR_MODE_BURST: |
|
226 | case LFR_MODE_BURST: | |
227 | status = enter_mode_burst( transitionCoarseTime ); |
|
227 | status = enter_mode_burst( transitionCoarseTime ); | |
228 | break; |
|
228 | break; | |
229 | case LFR_MODE_SBM1: |
|
229 | case LFR_MODE_SBM1: | |
230 | status = enter_mode_sbm1( transitionCoarseTime ); |
|
230 | status = enter_mode_sbm1( transitionCoarseTime ); | |
231 | break; |
|
231 | break; | |
232 | case LFR_MODE_SBM2: |
|
232 | case LFR_MODE_SBM2: | |
233 | status = enter_mode_sbm2( transitionCoarseTime ); |
|
233 | status = enter_mode_sbm2( transitionCoarseTime ); | |
234 | break; |
|
234 | break; | |
235 | default: |
|
235 | default: | |
236 | break; |
|
236 | break; | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | if (status != RTEMS_SUCCESSFUL) |
|
239 | if (status != RTEMS_SUCCESSFUL) | |
240 | { |
|
240 | { | |
241 | status = LFR_EXE_ERROR; |
|
241 | status = LFR_EXE_ERROR; | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | return status; |
|
245 | return status; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
248 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) | |
249 | { |
|
249 | { | |
250 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
250 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. | |
251 | * |
|
251 | * | |
252 | * @param TC points to the TeleCommand packet that is being processed |
|
252 | * @param TC points to the TeleCommand packet that is being processed | |
253 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
253 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
254 | * |
|
254 | * | |
255 | * @return LFR directive status code: |
|
255 | * @return LFR directive status code: | |
256 | * - LFR_DEFAULT |
|
256 | * - LFR_DEFAULT | |
257 | * - LFR_SUCCESSFUL |
|
257 | * - LFR_SUCCESSFUL | |
258 | * |
|
258 | * | |
259 | */ |
|
259 | */ | |
260 |
|
260 | |||
261 | unsigned int val; |
|
261 | unsigned int val; | |
262 | int result; |
|
262 | int result; | |
263 | unsigned int status; |
|
263 | unsigned int status; | |
264 | unsigned char mode; |
|
264 | unsigned char mode; | |
265 | unsigned char * bytePosPtr; |
|
265 | unsigned char * bytePosPtr; | |
266 |
|
266 | |||
267 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
267 | bytePosPtr = (unsigned char *) &TC->packetID; | |
268 |
|
268 | |||
269 | // check LFR mode |
|
269 | // check LFR mode | |
270 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE; |
|
270 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE; | |
271 | status = check_update_info_hk_lfr_mode( mode ); |
|
271 | status = check_update_info_hk_lfr_mode( mode ); | |
272 | if (status == LFR_SUCCESSFUL) // check TDS mode |
|
272 | if (status == LFR_SUCCESSFUL) // check TDS mode | |
273 | { |
|
273 | { | |
274 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE; |
|
274 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE; | |
275 | status = check_update_info_hk_tds_mode( mode ); |
|
275 | status = check_update_info_hk_tds_mode( mode ); | |
276 | } |
|
276 | } | |
277 | if (status == LFR_SUCCESSFUL) // check THR mode |
|
277 | if (status == LFR_SUCCESSFUL) // check THR mode | |
278 | { |
|
278 | { | |
279 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE); |
|
279 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE); | |
280 | status = check_update_info_hk_thr_mode( mode ); |
|
280 | status = check_update_info_hk_thr_mode( mode ); | |
281 | } |
|
281 | } | |
282 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful |
|
282 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful | |
283 | { |
|
283 | { | |
284 | val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256) |
|
284 | val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256) | |
285 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
285 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; | |
286 | val++; |
|
286 | val++; | |
287 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
287 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | |
288 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
288 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | // pa_bia_status_info |
|
291 | // pa_bia_status_info | |
292 | // => pa_bia_mode_mux_set 3 bits |
|
292 | // => pa_bia_mode_mux_set 3 bits | |
293 | // => pa_bia_mode_hv_enabled 1 bit |
|
293 | // => pa_bia_mode_hv_enabled 1 bit | |
294 | // => pa_bia_mode_bias1_enabled 1 bit |
|
294 | // => pa_bia_mode_bias1_enabled 1 bit | |
295 | // => pa_bia_mode_bias2_enabled 1 bit |
|
295 | // => pa_bia_mode_bias2_enabled 1 bit | |
296 | // => pa_bia_mode_bias3_enabled 1 bit |
|
296 | // => pa_bia_mode_bias3_enabled 1 bit | |
297 | // => pa_bia_on_off (cp_dpu_bias_on_off) |
|
297 | // => pa_bia_on_off (cp_dpu_bias_on_off) | |
298 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110] |
|
298 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110] | |
299 | pa_bia_status_info = pa_bia_status_info |
|
299 | pa_bia_status_info = pa_bia_status_info | |
300 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1); |
|
300 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1); | |
301 |
|
301 | |||
302 | // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets) |
|
302 | // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets) | |
303 |
|
303 | |||
304 | cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ]; |
|
304 | cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ]; | |
305 | getReactionWheelsFrequencies( TC ); |
|
305 | getReactionWheelsFrequencies( TC ); | |
306 | build_sy_lfr_rw_masks(); |
|
306 | build_sy_lfr_rw_masks(); | |
307 |
|
307 | |||
308 | // once the masks are built, they have to be merged with the fbins_mask |
|
308 | // once the masks are built, they have to be merged with the fbins_mask | |
309 | merge_fbins_masks(); |
|
309 | merge_fbins_masks(); | |
310 |
|
310 | |||
311 | result = status; |
|
311 | result = status; | |
312 |
|
312 | |||
313 | return result; |
|
313 | return result; | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
316 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
317 | { |
|
317 | { | |
318 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
318 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. | |
319 | * |
|
319 | * | |
320 | * @param TC points to the TeleCommand packet that is being processed |
|
320 | * @param TC points to the TeleCommand packet that is being processed | |
321 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
321 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
322 | * |
|
322 | * | |
323 | */ |
|
323 | */ | |
324 |
|
324 | |||
325 | int result; |
|
325 | int result; | |
326 |
|
326 | |||
327 | result = LFR_DEFAULT; |
|
327 | result = LFR_DEFAULT; | |
328 |
|
328 | |||
329 | setCalibration( true ); |
|
329 | setCalibration( true ); | |
330 |
|
330 | |||
331 | result = LFR_SUCCESSFUL; |
|
331 | result = LFR_SUCCESSFUL; | |
332 |
|
332 | |||
333 | return result; |
|
333 | return result; | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
336 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
337 | { |
|
337 | { | |
338 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
338 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. | |
339 | * |
|
339 | * | |
340 | * @param TC points to the TeleCommand packet that is being processed |
|
340 | * @param TC points to the TeleCommand packet that is being processed | |
341 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
341 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
342 | * |
|
342 | * | |
343 | */ |
|
343 | */ | |
344 |
|
344 | |||
345 | int result; |
|
345 | int result; | |
346 |
|
346 | |||
347 | result = LFR_DEFAULT; |
|
347 | result = LFR_DEFAULT; | |
348 |
|
348 | |||
349 | setCalibration( false ); |
|
349 | setCalibration( false ); | |
350 |
|
350 | |||
351 | result = LFR_SUCCESSFUL; |
|
351 | result = LFR_SUCCESSFUL; | |
352 |
|
352 | |||
353 | return result; |
|
353 | return result; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
356 | int action_update_time(ccsdsTelecommandPacket_t *TC) | |
357 | { |
|
357 | { | |
358 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
358 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. | |
359 | * |
|
359 | * | |
360 | * @param TC points to the TeleCommand packet that is being processed |
|
360 | * @param TC points to the TeleCommand packet that is being processed | |
361 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
361 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
362 | * |
|
362 | * | |
363 | * @return LFR_SUCCESSFUL |
|
363 | * @return LFR_SUCCESSFUL | |
364 | * |
|
364 | * | |
365 | */ |
|
365 | */ | |
366 |
|
366 | |||
367 | unsigned int val; |
|
367 | unsigned int val; | |
368 |
|
368 | |||
369 | time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES) |
|
369 | time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES) | |
370 | + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES) |
|
370 | + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES) | |
371 | + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE) |
|
371 | + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE) | |
372 | + TC->dataAndCRC[BYTE_3]; |
|
372 | + TC->dataAndCRC[BYTE_3]; | |
373 |
|
373 | |||
374 | val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256) |
|
374 | val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256) | |
375 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
375 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; | |
376 | val++; |
|
376 | val++; | |
377 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
377 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | |
378 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
378 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); | |
379 |
|
379 | |||
380 | oneTcLfrUpdateTimeReceived = 1; |
|
380 | oneTcLfrUpdateTimeReceived = 1; | |
381 |
|
381 | |||
382 | return LFR_SUCCESSFUL; |
|
382 | return LFR_SUCCESSFUL; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | //******************* |
|
385 | //******************* | |
386 | // ENTERING THE MODES |
|
386 | // ENTERING THE MODES | |
387 | int check_mode_value( unsigned char requestedMode ) |
|
387 | int check_mode_value( unsigned char requestedMode ) | |
388 | { |
|
388 | { | |
389 | int status; |
|
389 | int status; | |
390 |
|
390 | |||
391 | status = LFR_DEFAULT; |
|
391 | status = LFR_DEFAULT; | |
392 |
|
392 | |||
393 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
393 | if ( (requestedMode != LFR_MODE_STANDBY) | |
394 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
394 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) | |
395 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
395 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) | |
396 | { |
|
396 | { | |
397 | status = LFR_DEFAULT; |
|
397 | status = LFR_DEFAULT; | |
398 | } |
|
398 | } | |
399 | else |
|
399 | else | |
400 | { |
|
400 | { | |
401 | status = LFR_SUCCESSFUL; |
|
401 | status = LFR_SUCCESSFUL; | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | return status; |
|
404 | return status; | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | int check_mode_transition( unsigned char requestedMode ) |
|
407 | int check_mode_transition( unsigned char requestedMode ) | |
408 | { |
|
408 | { | |
409 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. |
|
409 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. | |
410 | * |
|
410 | * | |
411 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE |
|
411 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE | |
412 | * |
|
412 | * | |
413 | * @return LFR directive status codes: |
|
413 | * @return LFR directive status codes: | |
414 | * - LFR_SUCCESSFUL - the transition is authorized |
|
414 | * - LFR_SUCCESSFUL - the transition is authorized | |
415 | * - LFR_DEFAULT - the transition is not authorized |
|
415 | * - LFR_DEFAULT - the transition is not authorized | |
416 | * |
|
416 | * | |
417 | */ |
|
417 | */ | |
418 |
|
418 | |||
419 | int status; |
|
419 | int status; | |
420 |
|
420 | |||
421 | switch (requestedMode) |
|
421 | switch (requestedMode) | |
422 | { |
|
422 | { | |
423 | case LFR_MODE_STANDBY: |
|
423 | case LFR_MODE_STANDBY: | |
424 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
424 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { | |
425 | status = LFR_DEFAULT; |
|
425 | status = LFR_DEFAULT; | |
426 | } |
|
426 | } | |
427 | else |
|
427 | else | |
428 | { |
|
428 | { | |
429 | status = LFR_SUCCESSFUL; |
|
429 | status = LFR_SUCCESSFUL; | |
430 | } |
|
430 | } | |
431 | break; |
|
431 | break; | |
432 | case LFR_MODE_NORMAL: |
|
432 | case LFR_MODE_NORMAL: | |
433 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
433 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { | |
434 | status = LFR_DEFAULT; |
|
434 | status = LFR_DEFAULT; | |
435 | } |
|
435 | } | |
436 | else { |
|
436 | else { | |
437 | status = LFR_SUCCESSFUL; |
|
437 | status = LFR_SUCCESSFUL; | |
438 | } |
|
438 | } | |
439 | break; |
|
439 | break; | |
440 | case LFR_MODE_BURST: |
|
440 | case LFR_MODE_BURST: | |
441 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
441 | if ( lfrCurrentMode == LFR_MODE_BURST ) { | |
442 | status = LFR_DEFAULT; |
|
442 | status = LFR_DEFAULT; | |
443 | } |
|
443 | } | |
444 | else { |
|
444 | else { | |
445 | status = LFR_SUCCESSFUL; |
|
445 | status = LFR_SUCCESSFUL; | |
446 | } |
|
446 | } | |
447 | break; |
|
447 | break; | |
448 | case LFR_MODE_SBM1: |
|
448 | case LFR_MODE_SBM1: | |
449 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
449 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { | |
450 | status = LFR_DEFAULT; |
|
450 | status = LFR_DEFAULT; | |
451 | } |
|
451 | } | |
452 | else { |
|
452 | else { | |
453 | status = LFR_SUCCESSFUL; |
|
453 | status = LFR_SUCCESSFUL; | |
454 | } |
|
454 | } | |
455 | break; |
|
455 | break; | |
456 | case LFR_MODE_SBM2: |
|
456 | case LFR_MODE_SBM2: | |
457 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
457 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { | |
458 | status = LFR_DEFAULT; |
|
458 | status = LFR_DEFAULT; | |
459 | } |
|
459 | } | |
460 | else { |
|
460 | else { | |
461 | status = LFR_SUCCESSFUL; |
|
461 | status = LFR_SUCCESSFUL; | |
462 | } |
|
462 | } | |
463 | break; |
|
463 | break; | |
464 | default: |
|
464 | default: | |
465 | status = LFR_DEFAULT; |
|
465 | status = LFR_DEFAULT; | |
466 | break; |
|
466 | break; | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | return status; |
|
469 | return status; | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) |
|
472 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) | |
473 | { |
|
473 | { | |
474 | if (transitionCoarseTime == 0) |
|
474 | if (transitionCoarseTime == 0) | |
475 | { |
|
475 | { | |
476 | lastValidEnterModeTime = time_management_regs->coarse_time + 1; |
|
476 | lastValidEnterModeTime = time_management_regs->coarse_time + 1; | |
477 | PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime); |
|
477 | PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime); | |
478 | } |
|
478 | } | |
479 | else |
|
479 | else | |
480 | { |
|
480 | { | |
481 | lastValidEnterModeTime = transitionCoarseTime; |
|
481 | lastValidEnterModeTime = transitionCoarseTime; | |
482 | PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); |
|
482 | PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); | |
483 | } |
|
483 | } | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | int check_transition_date( unsigned int transitionCoarseTime ) |
|
486 | int check_transition_date( unsigned int transitionCoarseTime ) | |
487 | { |
|
487 | { | |
488 | int status; |
|
488 | int status; | |
489 | unsigned int localCoarseTime; |
|
489 | unsigned int localCoarseTime; | |
490 | unsigned int deltaCoarseTime; |
|
490 | unsigned int deltaCoarseTime; | |
491 |
|
491 | |||
492 | status = LFR_SUCCESSFUL; |
|
492 | status = LFR_SUCCESSFUL; | |
493 |
|
493 | |||
494 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition |
|
494 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition | |
495 | { |
|
495 | { | |
496 | status = LFR_SUCCESSFUL; |
|
496 | status = LFR_SUCCESSFUL; | |
497 | } |
|
497 | } | |
498 | else |
|
498 | else | |
499 | { |
|
499 | { | |
500 | localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK; |
|
500 | localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK; | |
501 |
|
501 | |||
502 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime); |
|
502 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime); | |
503 |
|
503 | |||
504 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 |
|
504 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 | |
505 | { |
|
505 | { | |
506 | status = LFR_DEFAULT; |
|
506 | status = LFR_DEFAULT; | |
507 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n"); |
|
507 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n"); | |
508 | } |
|
508 | } | |
509 |
|
509 | |||
510 | if (status == LFR_SUCCESSFUL) |
|
510 | if (status == LFR_SUCCESSFUL) | |
511 | { |
|
511 | { | |
512 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; |
|
512 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; | |
513 | if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323 |
|
513 | if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323 | |
514 | { |
|
514 | { | |
515 | status = LFR_DEFAULT; |
|
515 | status = LFR_DEFAULT; | |
516 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) |
|
516 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) | |
517 | } |
|
517 | } | |
518 | } |
|
518 | } | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | return status; |
|
521 | return status; | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | int restart_asm_activities( unsigned char lfrRequestedMode ) |
|
524 | int restart_asm_activities( unsigned char lfrRequestedMode ) | |
525 | { |
|
525 | { | |
526 | rtems_status_code status; |
|
526 | rtems_status_code status; | |
527 |
|
527 | |||
528 | status = stop_spectral_matrices(); |
|
528 | status = stop_spectral_matrices(); | |
529 |
|
529 | |||
530 | thisIsAnASMRestart = 1; |
|
530 | thisIsAnASMRestart = 1; | |
531 |
|
531 | |||
532 | status = restart_asm_tasks( lfrRequestedMode ); |
|
532 | status = restart_asm_tasks( lfrRequestedMode ); | |
533 |
|
533 | |||
534 | launch_spectral_matrix(); |
|
534 | launch_spectral_matrix(); | |
535 |
|
535 | |||
536 | return status; |
|
536 | return status; | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | int stop_spectral_matrices( void ) |
|
539 | int stop_spectral_matrices( void ) | |
540 | { |
|
540 | { | |
541 | /** This function stops and restarts the current mode average spectral matrices activities. |
|
541 | /** This function stops and restarts the current mode average spectral matrices activities. | |
542 | * |
|
542 | * | |
543 | * @return RTEMS directive status codes: |
|
543 | * @return RTEMS directive status codes: | |
544 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
544 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
545 | * - RTEMS_INVALID_ID - task id invalid |
|
545 | * - RTEMS_INVALID_ID - task id invalid | |
546 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
546 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
547 | * |
|
547 | * | |
548 | */ |
|
548 | */ | |
549 |
|
549 | |||
550 | rtems_status_code status; |
|
550 | rtems_status_code status; | |
551 |
|
551 | |||
552 | status = RTEMS_SUCCESSFUL; |
|
552 | status = RTEMS_SUCCESSFUL; | |
553 |
|
553 | |||
554 | // (1) mask interruptions |
|
554 | // (1) mask interruptions | |
555 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt |
|
555 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt | |
556 |
|
556 | |||
557 | // (2) reset spectral matrices registers |
|
557 | // (2) reset spectral matrices registers | |
558 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
558 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | |
559 | reset_sm_status(); |
|
559 | reset_sm_status(); | |
560 |
|
560 | |||
561 | // (3) clear interruptions |
|
561 | // (3) clear interruptions | |
562 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
562 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
563 |
|
563 | |||
564 | // suspend several tasks |
|
564 | // suspend several tasks | |
565 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
565 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | |
566 | status = suspend_asm_tasks(); |
|
566 | status = suspend_asm_tasks(); | |
567 | } |
|
567 | } | |
568 |
|
568 | |||
569 | if (status != RTEMS_SUCCESSFUL) |
|
569 | if (status != RTEMS_SUCCESSFUL) | |
570 | { |
|
570 | { | |
571 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
571 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | return status; |
|
574 | return status; | |
575 | } |
|
575 | } | |
576 |
|
576 | |||
577 | int stop_current_mode( void ) |
|
577 | int stop_current_mode( void ) | |
578 | { |
|
578 | { | |
579 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
579 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. | |
580 | * |
|
580 | * | |
581 | * @return RTEMS directive status codes: |
|
581 | * @return RTEMS directive status codes: | |
582 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
582 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
583 | * - RTEMS_INVALID_ID - task id invalid |
|
583 | * - RTEMS_INVALID_ID - task id invalid | |
584 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
584 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
585 | * |
|
585 | * | |
586 | */ |
|
586 | */ | |
587 |
|
587 | |||
588 | rtems_status_code status; |
|
588 | rtems_status_code status; | |
589 |
|
589 | |||
590 | status = RTEMS_SUCCESSFUL; |
|
590 | status = RTEMS_SUCCESSFUL; | |
591 |
|
591 | |||
592 | // (1) mask interruptions |
|
592 | // (1) mask interruptions | |
593 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
593 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt | |
594 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
594 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
595 |
|
595 | |||
596 | // (2) reset waveform picker registers |
|
596 | // (2) reset waveform picker registers | |
597 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
597 | reset_wfp_burst_enable(); // reset burst and enable bits | |
598 | reset_wfp_status(); // reset all the status bits |
|
598 | reset_wfp_status(); // reset all the status bits | |
599 |
|
599 | |||
600 | // (3) reset spectral matrices registers |
|
600 | // (3) reset spectral matrices registers | |
601 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
601 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | |
602 | reset_sm_status(); |
|
602 | reset_sm_status(); | |
603 |
|
603 | |||
604 | // reset lfr VHDL module |
|
604 | // reset lfr VHDL module | |
605 | reset_lfr(); |
|
605 | reset_lfr(); | |
606 |
|
606 | |||
607 | reset_extractSWF(); // reset the extractSWF flag to false |
|
607 | reset_extractSWF(); // reset the extractSWF flag to false | |
608 |
|
608 | |||
609 | // (4) clear interruptions |
|
609 | // (4) clear interruptions | |
610 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
610 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt | |
611 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
611 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
612 |
|
612 | |||
613 | // suspend several tasks |
|
613 | // suspend several tasks | |
614 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
614 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | |
615 | status = suspend_science_tasks(); |
|
615 | status = suspend_science_tasks(); | |
616 | } |
|
616 | } | |
617 |
|
617 | |||
618 | if (status != RTEMS_SUCCESSFUL) |
|
618 | if (status != RTEMS_SUCCESSFUL) | |
619 | { |
|
619 | { | |
620 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
620 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
623 | return status; |
|
623 | return status; | |
624 | } |
|
624 | } | |
625 |
|
625 | |||
626 | int enter_mode_standby( void ) |
|
626 | int enter_mode_standby( void ) | |
627 | { |
|
627 | { | |
628 | /** This function is used to put LFR in the STANDBY mode. |
|
628 | /** This function is used to put LFR in the STANDBY mode. | |
629 | * |
|
629 | * | |
630 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
630 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
631 | * |
|
631 | * | |
632 | * @return RTEMS directive status codes: |
|
632 | * @return RTEMS directive status codes: | |
633 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
633 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
634 | * - RTEMS_INVALID_ID - task id invalid |
|
634 | * - RTEMS_INVALID_ID - task id invalid | |
635 | * - RTEMS_INCORRECT_STATE - task never started |
|
635 | * - RTEMS_INCORRECT_STATE - task never started | |
636 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
636 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
637 | * |
|
637 | * | |
638 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE |
|
638 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE | |
639 | * is immediate. |
|
639 | * is immediate. | |
640 | * |
|
640 | * | |
641 | */ |
|
641 | */ | |
642 |
|
642 | |||
643 | int status; |
|
643 | int status; | |
644 |
|
644 | |||
645 | status = stop_current_mode(); // STOP THE CURRENT MODE |
|
645 | status = stop_current_mode(); // STOP THE CURRENT MODE | |
646 |
|
646 | |||
647 | #ifdef PRINT_TASK_STATISTICS |
|
647 | #ifdef PRINT_TASK_STATISTICS | |
648 | rtems_cpu_usage_report(); |
|
648 | rtems_cpu_usage_report(); | |
649 | #endif |
|
649 | #endif | |
650 |
|
650 | |||
651 | #ifdef PRINT_STACK_REPORT |
|
651 | #ifdef PRINT_STACK_REPORT | |
652 | PRINTF("stack report selected\n") |
|
652 | PRINTF("stack report selected\n") | |
653 | rtems_stack_checker_report_usage(); |
|
653 | rtems_stack_checker_report_usage(); | |
654 | #endif |
|
654 | #endif | |
655 |
|
655 | |||
656 | return status; |
|
656 | return status; | |
657 | } |
|
657 | } | |
658 |
|
658 | |||
659 | int enter_mode_normal( unsigned int transitionCoarseTime ) |
|
659 | int enter_mode_normal( unsigned int transitionCoarseTime ) | |
660 | { |
|
660 | { | |
661 | /** This function is used to start the NORMAL mode. |
|
661 | /** This function is used to start the NORMAL mode. | |
662 | * |
|
662 | * | |
663 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
663 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
664 | * |
|
664 | * | |
665 | * @return RTEMS directive status codes: |
|
665 | * @return RTEMS directive status codes: | |
666 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
666 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
667 | * - RTEMS_INVALID_ID - task id invalid |
|
667 | * - RTEMS_INVALID_ID - task id invalid | |
668 | * - RTEMS_INCORRECT_STATE - task never started |
|
668 | * - RTEMS_INCORRECT_STATE - task never started | |
669 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
669 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
670 | * |
|
670 | * | |
671 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, |
|
671 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, | |
672 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. |
|
672 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. | |
673 | * |
|
673 | * | |
674 | */ |
|
674 | */ | |
675 |
|
675 | |||
676 | int status; |
|
676 | int status; | |
677 |
|
677 | |||
678 | #ifdef PRINT_TASK_STATISTICS |
|
678 | #ifdef PRINT_TASK_STATISTICS | |
679 | rtems_cpu_usage_reset(); |
|
679 | rtems_cpu_usage_reset(); | |
680 | #endif |
|
680 | #endif | |
681 |
|
681 | |||
682 | status = RTEMS_UNSATISFIED; |
|
682 | status = RTEMS_UNSATISFIED; | |
683 |
|
683 | |||
684 | switch( lfrCurrentMode ) |
|
684 | switch( lfrCurrentMode ) | |
685 | { |
|
685 | { | |
686 | case LFR_MODE_STANDBY: |
|
686 | case LFR_MODE_STANDBY: | |
687 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks |
|
687 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks | |
688 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
688 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
689 | { |
|
689 | { | |
690 | launch_spectral_matrix( ); |
|
690 | launch_spectral_matrix( ); | |
691 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
691 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); | |
692 | } |
|
692 | } | |
693 | break; |
|
693 | break; | |
694 | case LFR_MODE_BURST: |
|
694 | case LFR_MODE_BURST: | |
695 | status = stop_current_mode(); // stop the current mode |
|
695 | status = stop_current_mode(); // stop the current mode | |
696 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks |
|
696 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks | |
697 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
697 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
698 | { |
|
698 | { | |
699 | launch_spectral_matrix( ); |
|
699 | launch_spectral_matrix( ); | |
700 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
700 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); | |
701 | } |
|
701 | } | |
702 | break; |
|
702 | break; | |
703 | case LFR_MODE_SBM1: |
|
703 | case LFR_MODE_SBM1: | |
704 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters |
|
704 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | |
705 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
705 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
706 | update_last_valid_transition_date( transitionCoarseTime ); |
|
706 | update_last_valid_transition_date( transitionCoarseTime ); | |
707 | break; |
|
707 | break; | |
708 | case LFR_MODE_SBM2: |
|
708 | case LFR_MODE_SBM2: | |
709 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters |
|
709 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | |
710 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
710 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
711 | update_last_valid_transition_date( transitionCoarseTime ); |
|
711 | update_last_valid_transition_date( transitionCoarseTime ); | |
712 | break; |
|
712 | break; | |
713 | default: |
|
713 | default: | |
714 | break; |
|
714 | break; | |
715 | } |
|
715 | } | |
716 |
|
716 | |||
717 | if (status != RTEMS_SUCCESSFUL) |
|
717 | if (status != RTEMS_SUCCESSFUL) | |
718 | { |
|
718 | { | |
719 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) |
|
719 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) | |
720 | status = RTEMS_UNSATISFIED; |
|
720 | status = RTEMS_UNSATISFIED; | |
721 | } |
|
721 | } | |
722 |
|
722 | |||
723 | return status; |
|
723 | return status; | |
724 | } |
|
724 | } | |
725 |
|
725 | |||
726 | int enter_mode_burst( unsigned int transitionCoarseTime ) |
|
726 | int enter_mode_burst( unsigned int transitionCoarseTime ) | |
727 | { |
|
727 | { | |
728 | /** This function is used to start the BURST mode. |
|
728 | /** This function is used to start the BURST mode. | |
729 | * |
|
729 | * | |
730 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
730 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
731 | * |
|
731 | * | |
732 | * @return RTEMS directive status codes: |
|
732 | * @return RTEMS directive status codes: | |
733 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
733 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
734 | * - RTEMS_INVALID_ID - task id invalid |
|
734 | * - RTEMS_INVALID_ID - task id invalid | |
735 | * - RTEMS_INCORRECT_STATE - task never started |
|
735 | * - RTEMS_INCORRECT_STATE - task never started | |
736 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
736 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
737 | * |
|
737 | * | |
738 | * The way the BURST mode is started does not depend on the LFR current mode. |
|
738 | * The way the BURST mode is started does not depend on the LFR current mode. | |
739 | * |
|
739 | * | |
740 | */ |
|
740 | */ | |
741 |
|
741 | |||
742 |
|
742 | |||
743 | int status; |
|
743 | int status; | |
744 |
|
744 | |||
745 | #ifdef PRINT_TASK_STATISTICS |
|
745 | #ifdef PRINT_TASK_STATISTICS | |
746 | rtems_cpu_usage_reset(); |
|
746 | rtems_cpu_usage_reset(); | |
747 | #endif |
|
747 | #endif | |
748 |
|
748 | |||
749 | status = stop_current_mode(); // stop the current mode |
|
749 | status = stop_current_mode(); // stop the current mode | |
750 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks |
|
750 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks | |
751 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
751 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
752 | { |
|
752 | { | |
753 | launch_spectral_matrix( ); |
|
753 | launch_spectral_matrix( ); | |
754 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); |
|
754 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); | |
755 | } |
|
755 | } | |
756 |
|
756 | |||
757 | if (status != RTEMS_SUCCESSFUL) |
|
757 | if (status != RTEMS_SUCCESSFUL) | |
758 | { |
|
758 | { | |
759 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) |
|
759 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) | |
760 | status = RTEMS_UNSATISFIED; |
|
760 | status = RTEMS_UNSATISFIED; | |
761 | } |
|
761 | } | |
762 |
|
762 | |||
763 | return status; |
|
763 | return status; | |
764 | } |
|
764 | } | |
765 |
|
765 | |||
766 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) |
|
766 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) | |
767 | { |
|
767 | { | |
768 | /** This function is used to start the SBM1 mode. |
|
768 | /** This function is used to start the SBM1 mode. | |
769 | * |
|
769 | * | |
770 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
770 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
771 | * |
|
771 | * | |
772 | * @return RTEMS directive status codes: |
|
772 | * @return RTEMS directive status codes: | |
773 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
773 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
774 | * - RTEMS_INVALID_ID - task id invalid |
|
774 | * - RTEMS_INVALID_ID - task id invalid | |
775 | * - RTEMS_INCORRECT_STATE - task never started |
|
775 | * - RTEMS_INCORRECT_STATE - task never started | |
776 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
776 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
777 | * |
|
777 | * | |
778 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, |
|
778 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, | |
779 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
779 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | |
780 | * cases, the acquisition is completely restarted. |
|
780 | * cases, the acquisition is completely restarted. | |
781 | * |
|
781 | * | |
782 | */ |
|
782 | */ | |
783 |
|
783 | |||
784 | int status; |
|
784 | int status; | |
785 |
|
785 | |||
786 | #ifdef PRINT_TASK_STATISTICS |
|
786 | #ifdef PRINT_TASK_STATISTICS | |
787 | rtems_cpu_usage_reset(); |
|
787 | rtems_cpu_usage_reset(); | |
788 | #endif |
|
788 | #endif | |
789 |
|
789 | |||
790 | status = RTEMS_UNSATISFIED; |
|
790 | status = RTEMS_UNSATISFIED; | |
791 |
|
791 | |||
792 | switch( lfrCurrentMode ) |
|
792 | switch( lfrCurrentMode ) | |
793 | { |
|
793 | { | |
794 | case LFR_MODE_STANDBY: |
|
794 | case LFR_MODE_STANDBY: | |
795 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks |
|
795 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks | |
796 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
796 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
797 | { |
|
797 | { | |
798 | launch_spectral_matrix( ); |
|
798 | launch_spectral_matrix( ); | |
799 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
799 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); | |
800 | } |
|
800 | } | |
801 | break; |
|
801 | break; | |
802 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action |
|
802 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action | |
803 | status = restart_asm_activities( LFR_MODE_SBM1 ); |
|
803 | status = restart_asm_activities( LFR_MODE_SBM1 ); | |
804 | status = LFR_SUCCESSFUL; |
|
804 | status = LFR_SUCCESSFUL; | |
805 | update_last_valid_transition_date( transitionCoarseTime ); |
|
805 | update_last_valid_transition_date( transitionCoarseTime ); | |
806 | break; |
|
806 | break; | |
807 | case LFR_MODE_BURST: |
|
807 | case LFR_MODE_BURST: | |
808 | status = stop_current_mode(); // stop the current mode |
|
808 | status = stop_current_mode(); // stop the current mode | |
809 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks |
|
809 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks | |
810 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
810 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
811 | { |
|
811 | { | |
812 | launch_spectral_matrix( ); |
|
812 | launch_spectral_matrix( ); | |
813 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
813 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); | |
814 | } |
|
814 | } | |
815 | break; |
|
815 | break; | |
816 | case LFR_MODE_SBM2: |
|
816 | case LFR_MODE_SBM2: | |
817 | status = restart_asm_activities( LFR_MODE_SBM1 ); |
|
817 | status = restart_asm_activities( LFR_MODE_SBM1 ); | |
818 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
818 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
819 | update_last_valid_transition_date( transitionCoarseTime ); |
|
819 | update_last_valid_transition_date( transitionCoarseTime ); | |
820 | break; |
|
820 | break; | |
821 | default: |
|
821 | default: | |
822 | break; |
|
822 | break; | |
823 | } |
|
823 | } | |
824 |
|
824 | |||
825 | if (status != RTEMS_SUCCESSFUL) |
|
825 | if (status != RTEMS_SUCCESSFUL) | |
826 | { |
|
826 | { | |
827 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status); |
|
827 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status); | |
828 | status = RTEMS_UNSATISFIED; |
|
828 | status = RTEMS_UNSATISFIED; | |
829 | } |
|
829 | } | |
830 |
|
830 | |||
831 | return status; |
|
831 | return status; | |
832 | } |
|
832 | } | |
833 |
|
833 | |||
834 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) |
|
834 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) | |
835 | { |
|
835 | { | |
836 | /** This function is used to start the SBM2 mode. |
|
836 | /** This function is used to start the SBM2 mode. | |
837 | * |
|
837 | * | |
838 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE |
|
838 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
839 | * |
|
839 | * | |
840 | * @return RTEMS directive status codes: |
|
840 | * @return RTEMS directive status codes: | |
841 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
841 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
842 | * - RTEMS_INVALID_ID - task id invalid |
|
842 | * - RTEMS_INVALID_ID - task id invalid | |
843 | * - RTEMS_INCORRECT_STATE - task never started |
|
843 | * - RTEMS_INCORRECT_STATE - task never started | |
844 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
844 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
845 | * |
|
845 | * | |
846 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, |
|
846 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, | |
847 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other |
|
847 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | |
848 | * cases, the acquisition is completely restarted. |
|
848 | * cases, the acquisition is completely restarted. | |
849 | * |
|
849 | * | |
850 | */ |
|
850 | */ | |
851 |
|
851 | |||
852 | int status; |
|
852 | int status; | |
853 |
|
853 | |||
854 | #ifdef PRINT_TASK_STATISTICS |
|
854 | #ifdef PRINT_TASK_STATISTICS | |
855 | rtems_cpu_usage_reset(); |
|
855 | rtems_cpu_usage_reset(); | |
856 | #endif |
|
856 | #endif | |
857 |
|
857 | |||
858 | status = RTEMS_UNSATISFIED; |
|
858 | status = RTEMS_UNSATISFIED; | |
859 |
|
859 | |||
860 | switch( lfrCurrentMode ) |
|
860 | switch( lfrCurrentMode ) | |
861 | { |
|
861 | { | |
862 | case LFR_MODE_STANDBY: |
|
862 | case LFR_MODE_STANDBY: | |
863 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks |
|
863 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks | |
864 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
864 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
865 | { |
|
865 | { | |
866 | launch_spectral_matrix( ); |
|
866 | launch_spectral_matrix( ); | |
867 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
867 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); | |
868 | } |
|
868 | } | |
869 | break; |
|
869 | break; | |
870 | case LFR_MODE_NORMAL: |
|
870 | case LFR_MODE_NORMAL: | |
871 | status = restart_asm_activities( LFR_MODE_SBM2 ); |
|
871 | status = restart_asm_activities( LFR_MODE_SBM2 ); | |
872 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
872 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
873 | update_last_valid_transition_date( transitionCoarseTime ); |
|
873 | update_last_valid_transition_date( transitionCoarseTime ); | |
874 | break; |
|
874 | break; | |
875 | case LFR_MODE_BURST: |
|
875 | case LFR_MODE_BURST: | |
876 | status = stop_current_mode(); // stop the current mode |
|
876 | status = stop_current_mode(); // stop the current mode | |
877 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks |
|
877 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks | |
878 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
878 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | |
879 | { |
|
879 | { | |
880 | launch_spectral_matrix( ); |
|
880 | launch_spectral_matrix( ); | |
881 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
881 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); | |
882 | } |
|
882 | } | |
883 | break; |
|
883 | break; | |
884 | case LFR_MODE_SBM1: |
|
884 | case LFR_MODE_SBM1: | |
885 | status = restart_asm_activities( LFR_MODE_SBM2 ); |
|
885 | status = restart_asm_activities( LFR_MODE_SBM2 ); | |
886 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
886 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
887 | update_last_valid_transition_date( transitionCoarseTime ); |
|
887 | update_last_valid_transition_date( transitionCoarseTime ); | |
888 | break; |
|
888 | break; | |
889 | default: |
|
889 | default: | |
890 | break; |
|
890 | break; | |
891 | } |
|
891 | } | |
892 |
|
892 | |||
893 | if (status != RTEMS_SUCCESSFUL) |
|
893 | if (status != RTEMS_SUCCESSFUL) | |
894 | { |
|
894 | { | |
895 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) |
|
895 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) | |
896 | status = RTEMS_UNSATISFIED; |
|
896 | status = RTEMS_UNSATISFIED; | |
897 | } |
|
897 | } | |
898 |
|
898 | |||
899 | return status; |
|
899 | return status; | |
900 | } |
|
900 | } | |
901 |
|
901 | |||
902 | int restart_science_tasks( unsigned char lfrRequestedMode ) |
|
902 | int restart_science_tasks( unsigned char lfrRequestedMode ) | |
903 | { |
|
903 | { | |
904 | /** This function is used to restart all science tasks. |
|
904 | /** This function is used to restart all science tasks. | |
905 | * |
|
905 | * | |
906 | * @return RTEMS directive status codes: |
|
906 | * @return RTEMS directive status codes: | |
907 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
907 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
908 | * - RTEMS_INVALID_ID - task id invalid |
|
908 | * - RTEMS_INVALID_ID - task id invalid | |
909 | * - RTEMS_INCORRECT_STATE - task never started |
|
909 | * - RTEMS_INCORRECT_STATE - task never started | |
910 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
910 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
911 | * |
|
911 | * | |
912 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 |
|
912 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 | |
913 | * |
|
913 | * | |
914 | */ |
|
914 | */ | |
915 |
|
915 | |||
916 | rtems_status_code status[NB_SCIENCE_TASKS]; |
|
916 | rtems_status_code status[NB_SCIENCE_TASKS]; | |
917 | rtems_status_code ret; |
|
917 | rtems_status_code ret; | |
918 |
|
918 | |||
919 | ret = RTEMS_SUCCESSFUL; |
|
919 | ret = RTEMS_SUCCESSFUL; | |
920 |
|
920 | |||
921 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
921 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | |
922 | if (status[STATUS_0] != RTEMS_SUCCESSFUL) |
|
922 | if (status[STATUS_0] != RTEMS_SUCCESSFUL) | |
923 | { |
|
923 | { | |
924 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) |
|
924 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) | |
925 | } |
|
925 | } | |
926 |
|
926 | |||
927 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
927 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | |
928 | if (status[STATUS_1] != RTEMS_SUCCESSFUL) |
|
928 | if (status[STATUS_1] != RTEMS_SUCCESSFUL) | |
929 | { |
|
929 | { | |
930 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) |
|
930 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) | |
931 | } |
|
931 | } | |
932 |
|
932 | |||
933 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
933 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); | |
934 | if (status[STATUS_2] != RTEMS_SUCCESSFUL) |
|
934 | if (status[STATUS_2] != RTEMS_SUCCESSFUL) | |
935 | { |
|
935 | { | |
936 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2]) |
|
936 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2]) | |
937 | } |
|
937 | } | |
938 |
|
938 | |||
939 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
939 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); | |
940 | if (status[STATUS_3] != RTEMS_SUCCESSFUL) |
|
940 | if (status[STATUS_3] != RTEMS_SUCCESSFUL) | |
941 | { |
|
941 | { | |
942 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3]) |
|
942 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3]) | |
943 | } |
|
943 | } | |
944 |
|
944 | |||
945 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
945 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); | |
946 | if (status[STATUS_4] != RTEMS_SUCCESSFUL) |
|
946 | if (status[STATUS_4] != RTEMS_SUCCESSFUL) | |
947 | { |
|
947 | { | |
948 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4]) |
|
948 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4]) | |
949 | } |
|
949 | } | |
950 |
|
950 | |||
951 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
951 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); | |
952 | if (status[STATUS_5] != RTEMS_SUCCESSFUL) |
|
952 | if (status[STATUS_5] != RTEMS_SUCCESSFUL) | |
953 | { |
|
953 | { | |
954 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5]) |
|
954 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5]) | |
955 | } |
|
955 | } | |
956 |
|
956 | |||
957 | status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
957 | status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | |
958 | if (status[STATUS_6] != RTEMS_SUCCESSFUL) |
|
958 | if (status[STATUS_6] != RTEMS_SUCCESSFUL) | |
959 | { |
|
959 | { | |
960 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6]) |
|
960 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6]) | |
961 | } |
|
961 | } | |
962 |
|
962 | |||
963 | status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
963 | status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | |
964 | if (status[STATUS_7] != RTEMS_SUCCESSFUL) |
|
964 | if (status[STATUS_7] != RTEMS_SUCCESSFUL) | |
965 | { |
|
965 | { | |
966 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7]) |
|
966 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7]) | |
967 | } |
|
967 | } | |
968 |
|
968 | |||
969 | status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
969 | status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | |
970 | if (status[STATUS_8] != RTEMS_SUCCESSFUL) |
|
970 | if (status[STATUS_8] != RTEMS_SUCCESSFUL) | |
971 | { |
|
971 | { | |
972 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8]) |
|
972 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8]) | |
973 | } |
|
973 | } | |
974 |
|
974 | |||
975 | status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
975 | status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | |
976 | if (status[STATUS_9] != RTEMS_SUCCESSFUL) |
|
976 | if (status[STATUS_9] != RTEMS_SUCCESSFUL) | |
977 | { |
|
977 | { | |
978 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9]) |
|
978 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9]) | |
979 | } |
|
979 | } | |
980 |
|
980 | |||
981 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || |
|
981 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || | |
982 | (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || |
|
982 | (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || | |
983 | (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) || |
|
983 | (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) || | |
984 | (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) || |
|
984 | (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) || | |
985 | (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) ) |
|
985 | (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) ) | |
986 | { |
|
986 | { | |
987 | ret = RTEMS_UNSATISFIED; |
|
987 | ret = RTEMS_UNSATISFIED; | |
988 | } |
|
988 | } | |
989 |
|
989 | |||
990 | return ret; |
|
990 | return ret; | |
991 | } |
|
991 | } | |
992 |
|
992 | |||
993 | int restart_asm_tasks( unsigned char lfrRequestedMode ) |
|
993 | int restart_asm_tasks( unsigned char lfrRequestedMode ) | |
994 | { |
|
994 | { | |
995 | /** This function is used to restart average spectral matrices tasks. |
|
995 | /** This function is used to restart average spectral matrices tasks. | |
996 | * |
|
996 | * | |
997 | * @return RTEMS directive status codes: |
|
997 | * @return RTEMS directive status codes: | |
998 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
998 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
999 | * - RTEMS_INVALID_ID - task id invalid |
|
999 | * - RTEMS_INVALID_ID - task id invalid | |
1000 | * - RTEMS_INCORRECT_STATE - task never started |
|
1000 | * - RTEMS_INCORRECT_STATE - task never started | |
1001 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
1001 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
1002 | * |
|
1002 | * | |
1003 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 |
|
1003 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 | |
1004 | * |
|
1004 | * | |
1005 | */ |
|
1005 | */ | |
1006 |
|
1006 | |||
1007 | rtems_status_code status[NB_ASM_TASKS]; |
|
1007 | rtems_status_code status[NB_ASM_TASKS]; | |
1008 | rtems_status_code ret; |
|
1008 | rtems_status_code ret; | |
1009 |
|
1009 | |||
1010 | ret = RTEMS_SUCCESSFUL; |
|
1010 | ret = RTEMS_SUCCESSFUL; | |
1011 |
|
1011 | |||
1012 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
1012 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | |
1013 | if (status[STATUS_0] != RTEMS_SUCCESSFUL) |
|
1013 | if (status[STATUS_0] != RTEMS_SUCCESSFUL) | |
1014 | { |
|
1014 | { | |
1015 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) |
|
1015 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) | |
1016 | } |
|
1016 | } | |
1017 |
|
1017 | |||
1018 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
1018 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | |
1019 | if (status[STATUS_1] != RTEMS_SUCCESSFUL) |
|
1019 | if (status[STATUS_1] != RTEMS_SUCCESSFUL) | |
1020 | { |
|
1020 | { | |
1021 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) |
|
1021 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) | |
1022 | } |
|
1022 | } | |
1023 |
|
1023 | |||
1024 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
1024 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | |
1025 | if (status[STATUS_2] != RTEMS_SUCCESSFUL) |
|
1025 | if (status[STATUS_2] != RTEMS_SUCCESSFUL) | |
1026 | { |
|
1026 | { | |
1027 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2]) |
|
1027 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2]) | |
1028 | } |
|
1028 | } | |
1029 |
|
1029 | |||
1030 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
1030 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | |
1031 | if (status[STATUS_3] != RTEMS_SUCCESSFUL) |
|
1031 | if (status[STATUS_3] != RTEMS_SUCCESSFUL) | |
1032 | { |
|
1032 | { | |
1033 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3]) |
|
1033 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3]) | |
1034 | } |
|
1034 | } | |
1035 |
|
1035 | |||
1036 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
1036 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | |
1037 | if (status[STATUS_4] != RTEMS_SUCCESSFUL) |
|
1037 | if (status[STATUS_4] != RTEMS_SUCCESSFUL) | |
1038 | { |
|
1038 | { | |
1039 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4]) |
|
1039 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4]) | |
1040 | } |
|
1040 | } | |
1041 |
|
1041 | |||
1042 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
1042 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | |
1043 | if (status[STATUS_5] != RTEMS_SUCCESSFUL) |
|
1043 | if (status[STATUS_5] != RTEMS_SUCCESSFUL) | |
1044 | { |
|
1044 | { | |
1045 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5]) |
|
1045 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5]) | |
1046 | } |
|
1046 | } | |
1047 |
|
1047 | |||
1048 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || |
|
1048 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || | |
1049 | (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || |
|
1049 | (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || | |
1050 | (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ) |
|
1050 | (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ) | |
1051 | { |
|
1051 | { | |
1052 | ret = RTEMS_UNSATISFIED; |
|
1052 | ret = RTEMS_UNSATISFIED; | |
1053 | } |
|
1053 | } | |
1054 |
|
1054 | |||
1055 | return ret; |
|
1055 | return ret; | |
1056 | } |
|
1056 | } | |
1057 |
|
1057 | |||
1058 | int suspend_science_tasks( void ) |
|
1058 | int suspend_science_tasks( void ) | |
1059 | { |
|
1059 | { | |
1060 | /** This function suspends the science tasks. |
|
1060 | /** This function suspends the science tasks. | |
1061 | * |
|
1061 | * | |
1062 | * @return RTEMS directive status codes: |
|
1062 | * @return RTEMS directive status codes: | |
1063 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1063 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
1064 | * - RTEMS_INVALID_ID - task id invalid |
|
1064 | * - RTEMS_INVALID_ID - task id invalid | |
1065 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1065 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
1066 | * |
|
1066 | * | |
1067 | */ |
|
1067 | */ | |
1068 |
|
1068 | |||
1069 | rtems_status_code status; |
|
1069 | rtems_status_code status; | |
1070 |
|
1070 | |||
1071 | PRINTF("in suspend_science_tasks\n") |
|
1071 | PRINTF("in suspend_science_tasks\n") | |
1072 |
|
1072 | |||
1073 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1073 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | |
1074 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1074 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1075 | { |
|
1075 | { | |
1076 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1076 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | |
1077 | } |
|
1077 | } | |
1078 | else |
|
1078 | else | |
1079 | { |
|
1079 | { | |
1080 | status = RTEMS_SUCCESSFUL; |
|
1080 | status = RTEMS_SUCCESSFUL; | |
1081 | } |
|
1081 | } | |
1082 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1082 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | |
1083 | { |
|
1083 | { | |
1084 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1084 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | |
1085 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1085 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1086 | { |
|
1086 | { | |
1087 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1087 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | |
1088 | } |
|
1088 | } | |
1089 | else |
|
1089 | else | |
1090 | { |
|
1090 | { | |
1091 | status = RTEMS_SUCCESSFUL; |
|
1091 | status = RTEMS_SUCCESSFUL; | |
1092 | } |
|
1092 | } | |
1093 | } |
|
1093 | } | |
1094 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1094 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | |
1095 | { |
|
1095 | { | |
1096 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1096 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | |
1097 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1097 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1098 | { |
|
1098 | { | |
1099 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1099 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | |
1100 | } |
|
1100 | } | |
1101 | else |
|
1101 | else | |
1102 | { |
|
1102 | { | |
1103 | status = RTEMS_SUCCESSFUL; |
|
1103 | status = RTEMS_SUCCESSFUL; | |
1104 | } |
|
1104 | } | |
1105 | } |
|
1105 | } | |
1106 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1106 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | |
1107 | { |
|
1107 | { | |
1108 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1108 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | |
1109 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1109 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1110 | { |
|
1110 | { | |
1111 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1111 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | |
1112 | } |
|
1112 | } | |
1113 | else |
|
1113 | else | |
1114 | { |
|
1114 | { | |
1115 | status = RTEMS_SUCCESSFUL; |
|
1115 | status = RTEMS_SUCCESSFUL; | |
1116 | } |
|
1116 | } | |
1117 | } |
|
1117 | } | |
1118 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1118 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | |
1119 | { |
|
1119 | { | |
1120 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1120 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | |
1121 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1121 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1122 | { |
|
1122 | { | |
1123 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1123 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | |
1124 | } |
|
1124 | } | |
1125 | else |
|
1125 | else | |
1126 | { |
|
1126 | { | |
1127 | status = RTEMS_SUCCESSFUL; |
|
1127 | status = RTEMS_SUCCESSFUL; | |
1128 | } |
|
1128 | } | |
1129 | } |
|
1129 | } | |
1130 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1130 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | |
1131 | { |
|
1131 | { | |
1132 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1132 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | |
1133 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1133 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1134 | { |
|
1134 | { | |
1135 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1135 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | |
1136 | } |
|
1136 | } | |
1137 | else |
|
1137 | else | |
1138 | { |
|
1138 | { | |
1139 | status = RTEMS_SUCCESSFUL; |
|
1139 | status = RTEMS_SUCCESSFUL; | |
1140 | } |
|
1140 | } | |
1141 | } |
|
1141 | } | |
1142 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
1142 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM | |
1143 | { |
|
1143 | { | |
1144 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
1144 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); | |
1145 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1145 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1146 | { |
|
1146 | { | |
1147 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
1147 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) | |
1148 | } |
|
1148 | } | |
1149 | else |
|
1149 | else | |
1150 | { |
|
1150 | { | |
1151 | status = RTEMS_SUCCESSFUL; |
|
1151 | status = RTEMS_SUCCESSFUL; | |
1152 | } |
|
1152 | } | |
1153 | } |
|
1153 | } | |
1154 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
1154 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 | |
1155 | { |
|
1155 | { | |
1156 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
1156 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); | |
1157 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1157 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1158 | { |
|
1158 | { | |
1159 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
1159 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) | |
1160 | } |
|
1160 | } | |
1161 | else |
|
1161 | else | |
1162 | { |
|
1162 | { | |
1163 | status = RTEMS_SUCCESSFUL; |
|
1163 | status = RTEMS_SUCCESSFUL; | |
1164 | } |
|
1164 | } | |
1165 | } |
|
1165 | } | |
1166 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
1166 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 | |
1167 | { |
|
1167 | { | |
1168 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
1168 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); | |
1169 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1169 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1170 | { |
|
1170 | { | |
1171 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
1171 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) | |
1172 | } |
|
1172 | } | |
1173 | else |
|
1173 | else | |
1174 | { |
|
1174 | { | |
1175 | status = RTEMS_SUCCESSFUL; |
|
1175 | status = RTEMS_SUCCESSFUL; | |
1176 | } |
|
1176 | } | |
1177 | } |
|
1177 | } | |
1178 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
1178 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 | |
1179 | { |
|
1179 | { | |
1180 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
1180 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); | |
1181 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1181 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1182 | { |
|
1182 | { | |
1183 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
1183 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) | |
1184 | } |
|
1184 | } | |
1185 | else |
|
1185 | else | |
1186 | { |
|
1186 | { | |
1187 | status = RTEMS_SUCCESSFUL; |
|
1187 | status = RTEMS_SUCCESSFUL; | |
1188 | } |
|
1188 | } | |
1189 | } |
|
1189 | } | |
1190 |
|
1190 | |||
1191 | return status; |
|
1191 | return status; | |
1192 | } |
|
1192 | } | |
1193 |
|
1193 | |||
1194 | int suspend_asm_tasks( void ) |
|
1194 | int suspend_asm_tasks( void ) | |
1195 | { |
|
1195 | { | |
1196 | /** This function suspends the science tasks. |
|
1196 | /** This function suspends the science tasks. | |
1197 | * |
|
1197 | * | |
1198 | * @return RTEMS directive status codes: |
|
1198 | * @return RTEMS directive status codes: | |
1199 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1199 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
1200 | * - RTEMS_INVALID_ID - task id invalid |
|
1200 | * - RTEMS_INVALID_ID - task id invalid | |
1201 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1201 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
1202 | * |
|
1202 | * | |
1203 | */ |
|
1203 | */ | |
1204 |
|
1204 | |||
1205 | rtems_status_code status; |
|
1205 | rtems_status_code status; | |
1206 |
|
1206 | |||
1207 | PRINTF("in suspend_science_tasks\n") |
|
1207 | PRINTF("in suspend_science_tasks\n") | |
1208 |
|
1208 | |||
1209 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1209 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | |
1210 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1210 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1211 | { |
|
1211 | { | |
1212 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1212 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | |
1213 | } |
|
1213 | } | |
1214 | else |
|
1214 | else | |
1215 | { |
|
1215 | { | |
1216 | status = RTEMS_SUCCESSFUL; |
|
1216 | status = RTEMS_SUCCESSFUL; | |
1217 | } |
|
1217 | } | |
1218 |
|
1218 | |||
1219 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1219 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | |
1220 | { |
|
1220 | { | |
1221 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1221 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | |
1222 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1222 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1223 | { |
|
1223 | { | |
1224 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1224 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | |
1225 | } |
|
1225 | } | |
1226 | else |
|
1226 | else | |
1227 | { |
|
1227 | { | |
1228 | status = RTEMS_SUCCESSFUL; |
|
1228 | status = RTEMS_SUCCESSFUL; | |
1229 | } |
|
1229 | } | |
1230 | } |
|
1230 | } | |
1231 |
|
1231 | |||
1232 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1232 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | |
1233 | { |
|
1233 | { | |
1234 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1234 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | |
1235 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1235 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1236 | { |
|
1236 | { | |
1237 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1237 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | |
1238 | } |
|
1238 | } | |
1239 | else |
|
1239 | else | |
1240 | { |
|
1240 | { | |
1241 | status = RTEMS_SUCCESSFUL; |
|
1241 | status = RTEMS_SUCCESSFUL; | |
1242 | } |
|
1242 | } | |
1243 | } |
|
1243 | } | |
1244 |
|
1244 | |||
1245 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1245 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | |
1246 | { |
|
1246 | { | |
1247 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1247 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | |
1248 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1248 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1249 | { |
|
1249 | { | |
1250 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1250 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | |
1251 | } |
|
1251 | } | |
1252 | else |
|
1252 | else | |
1253 | { |
|
1253 | { | |
1254 | status = RTEMS_SUCCESSFUL; |
|
1254 | status = RTEMS_SUCCESSFUL; | |
1255 | } |
|
1255 | } | |
1256 | } |
|
1256 | } | |
1257 |
|
1257 | |||
1258 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1258 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | |
1259 | { |
|
1259 | { | |
1260 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1260 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | |
1261 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1261 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1262 | { |
|
1262 | { | |
1263 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1263 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | |
1264 | } |
|
1264 | } | |
1265 | else |
|
1265 | else | |
1266 | { |
|
1266 | { | |
1267 | status = RTEMS_SUCCESSFUL; |
|
1267 | status = RTEMS_SUCCESSFUL; | |
1268 | } |
|
1268 | } | |
1269 | } |
|
1269 | } | |
1270 |
|
1270 | |||
1271 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1271 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | |
1272 | { |
|
1272 | { | |
1273 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1273 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | |
1274 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1274 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
1275 | { |
|
1275 | { | |
1276 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1276 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | |
1277 | } |
|
1277 | } | |
1278 | else |
|
1278 | else | |
1279 | { |
|
1279 | { | |
1280 | status = RTEMS_SUCCESSFUL; |
|
1280 | status = RTEMS_SUCCESSFUL; | |
1281 | } |
|
1281 | } | |
1282 | } |
|
1282 | } | |
1283 |
|
1283 | |||
1284 | return status; |
|
1284 | return status; | |
1285 | } |
|
1285 | } | |
1286 |
|
1286 | |||
1287 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) |
|
1287 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) | |
1288 | { |
|
1288 | { | |
1289 |
|
1289 | |||
1290 | WFP_reset_current_ring_nodes(); |
|
1290 | WFP_reset_current_ring_nodes(); | |
1291 |
|
1291 | |||
1292 | reset_waveform_picker_regs(); |
|
1292 | reset_waveform_picker_regs(); | |
1293 |
|
1293 | |||
1294 | set_wfp_burst_enable_register( mode ); |
|
1294 | set_wfp_burst_enable_register( mode ); | |
1295 |
|
1295 | |||
1296 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1296 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | |
1297 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1297 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | |
1298 |
|
1298 | |||
1299 | if (transitionCoarseTime == 0) |
|
1299 | if (transitionCoarseTime == 0) | |
1300 | { |
|
1300 | { | |
1301 | // instant transition means transition on the next valid date |
|
1301 | // instant transition means transition on the next valid date | |
1302 | // this is mandatory to have a good snapshot period and a good correction of the snapshot period |
|
1302 | // this is mandatory to have a good snapshot period and a good correction of the snapshot period | |
1303 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; |
|
1303 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; | |
1304 | } |
|
1304 | } | |
1305 | else |
|
1305 | else | |
1306 | { |
|
1306 | { | |
1307 | waveform_picker_regs->start_date = transitionCoarseTime; |
|
1307 | waveform_picker_regs->start_date = transitionCoarseTime; | |
1308 | } |
|
1308 | } | |
1309 |
|
1309 | |||
1310 | update_last_valid_transition_date(waveform_picker_regs->start_date); |
|
1310 | update_last_valid_transition_date(waveform_picker_regs->start_date); | |
1311 |
|
1311 | |||
1312 | } |
|
1312 | } | |
1313 |
|
1313 | |||
1314 | void launch_spectral_matrix( void ) |
|
1314 | void launch_spectral_matrix( void ) | |
1315 | { |
|
1315 | { | |
1316 | SM_reset_current_ring_nodes(); |
|
1316 | SM_reset_current_ring_nodes(); | |
1317 |
|
1317 | |||
1318 | reset_spectral_matrix_regs(); |
|
1318 | reset_spectral_matrix_regs(); | |
1319 |
|
1319 | |||
1320 | reset_nb_sm(); |
|
1320 | reset_nb_sm(); | |
1321 |
|
1321 | |||
1322 | set_sm_irq_onNewMatrix( 1 ); |
|
1322 | set_sm_irq_onNewMatrix( 1 ); | |
1323 |
|
1323 | |||
1324 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1324 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); | |
1325 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1325 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); | |
1326 |
|
1326 | |||
1327 | } |
|
1327 | } | |
1328 |
|
1328 | |||
1329 | void set_sm_irq_onNewMatrix( unsigned char value ) |
|
1329 | void set_sm_irq_onNewMatrix( unsigned char value ) | |
1330 | { |
|
1330 | { | |
1331 | if (value == 1) |
|
1331 | if (value == 1) | |
1332 | { |
|
1332 | { | |
1333 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX; |
|
1333 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX; | |
1334 | } |
|
1334 | } | |
1335 | else |
|
1335 | else | |
1336 | { |
|
1336 | { | |
1337 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110 |
|
1337 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110 | |
1338 | } |
|
1338 | } | |
1339 | } |
|
1339 | } | |
1340 |
|
1340 | |||
1341 | void set_sm_irq_onError( unsigned char value ) |
|
1341 | void set_sm_irq_onError( unsigned char value ) | |
1342 | { |
|
1342 | { | |
1343 | if (value == 1) |
|
1343 | if (value == 1) | |
1344 | { |
|
1344 | { | |
1345 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR; |
|
1345 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR; | |
1346 | } |
|
1346 | } | |
1347 | else |
|
1347 | else | |
1348 | { |
|
1348 | { | |
1349 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101 |
|
1349 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101 | |
1350 | } |
|
1350 | } | |
1351 | } |
|
1351 | } | |
1352 |
|
1352 | |||
1353 | //***************************** |
|
1353 | //***************************** | |
1354 | // CONFIGURE CALIBRATION SIGNAL |
|
1354 | // CONFIGURE CALIBRATION SIGNAL | |
1355 | void setCalibrationPrescaler( unsigned int prescaler ) |
|
1355 | void setCalibrationPrescaler( unsigned int prescaler ) | |
1356 | { |
|
1356 | { | |
1357 | // prescaling of the master clock (25 MHz) |
|
1357 | // prescaling of the master clock (25 MHz) | |
1358 | // master clock is divided by 2^prescaler |
|
1358 | // master clock is divided by 2^prescaler | |
1359 | time_management_regs->calPrescaler = prescaler; |
|
1359 | time_management_regs->calPrescaler = prescaler; | |
1360 | } |
|
1360 | } | |
1361 |
|
1361 | |||
1362 | void setCalibrationDivisor( unsigned int divisionFactor ) |
|
1362 | void setCalibrationDivisor( unsigned int divisionFactor ) | |
1363 | { |
|
1363 | { | |
1364 | // division of the prescaled clock by the division factor |
|
1364 | // division of the prescaled clock by the division factor | |
1365 | time_management_regs->calDivisor = divisionFactor; |
|
1365 | time_management_regs->calDivisor = divisionFactor; | |
1366 | } |
|
1366 | } | |
1367 |
|
1367 | |||
1368 | void setCalibrationData( void ) |
|
1368 | void setCalibrationData( void ) | |
1369 | { |
|
1369 | { | |
1370 | /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal |
|
1370 | /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal | |
1371 | * |
|
1371 | * | |
1372 | * @param void |
|
1372 | * @param void | |
1373 | * |
|
1373 | * | |
1374 | * @return void |
|
1374 | * @return void | |
1375 | * |
|
1375 | * | |
1376 | */ |
|
1376 | */ | |
1377 |
|
1377 | |||
1378 | unsigned int k; |
|
1378 | unsigned int k; | |
1379 | unsigned short data; |
|
1379 | unsigned short data; | |
1380 | float val; |
|
1380 | float val; | |
1381 | float Ts; |
|
1381 | float Ts; | |
1382 |
|
1382 | |||
1383 | time_management_regs->calDataPtr = INIT_CHAR; |
|
1383 | time_management_regs->calDataPtr = INIT_CHAR; | |
1384 |
|
1384 | |||
|
1385 | Ts = 1 / CAL_FS; | |||
|
1386 | ||||
1385 | // build the signal for the SCM calibration |
|
1387 | // build the signal for the SCM calibration | |
1386 | for (k = 0; k < CAL_NB_PTS; k++) |
|
1388 | for (k = 0; k < CAL_NB_PTS; k++) | |
1387 | { |
|
1389 | { | |
1388 | val = sin( 2 * pi * CAL_F0 * k * Ts ) |
|
1390 | val = sin( 2 * pi * CAL_F0 * k * Ts ) | |
1389 | + sin( 2 * pi * CAL_F1 * k * Ts ); |
|
1391 | + sin( 2 * pi * CAL_F1 * k * Ts ); | |
1390 | data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048); |
|
1392 | data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048); | |
1391 | time_management_regs->calData = data & CAL_DATA_MASK; |
|
1393 | time_management_regs->calData = data & CAL_DATA_MASK; | |
1392 | } |
|
1394 | } | |
1393 | } |
|
1395 | } | |
1394 |
|
1396 | |||
1395 | void setCalibrationDataInterleaved( void ) |
|
1397 | void setCalibrationDataInterleaved( void ) | |
1396 | { |
|
1398 | { | |
1397 | /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal |
|
1399 | /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal | |
1398 | * |
|
1400 | * | |
1399 | * @param void |
|
1401 | * @param void | |
1400 | * |
|
1402 | * | |
1401 | * @return void |
|
1403 | * @return void | |
1402 | * |
|
1404 | * | |
1403 | * In interleaved mode, one can store more values than in normal mode. |
|
1405 | * In interleaved mode, one can store more values than in normal mode. | |
1404 | * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample. |
|
1406 | * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample. | |
1405 | * T store 3 values, one need two write operations. |
|
1407 | * T store 3 values, one need two write operations. | |
1406 | * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] |
|
1408 | * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] | |
1407 | * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] |
|
1409 | * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] | |
1408 | * |
|
1410 | * | |
1409 | */ |
|
1411 | */ | |
1410 |
|
1412 | |||
1411 | unsigned int k; |
|
1413 | unsigned int k; | |
1412 | float val; |
|
1414 | float val; | |
1413 | float Ts; |
|
1415 | float Ts; | |
1414 | unsigned short data[CAL_NB_PTS_INTER]; |
|
1416 | unsigned short data[CAL_NB_PTS_INTER]; | |
1415 | unsigned char *dataPtr; |
|
1417 | unsigned char *dataPtr; | |
1416 |
|
1418 | |||
1417 |
Ts = 1 |
|
1419 | Ts = 1 / CAL_FS_INTER; | |
1418 |
|
1420 | |||
1419 | time_management_regs->calDataPtr = INIT_CHAR; |
|
1421 | time_management_regs->calDataPtr = INIT_CHAR; | |
1420 |
|
1422 | |||
1421 | // build the signal for the SCM calibration |
|
1423 | // build the signal for the SCM calibration | |
1422 | for (k=0; k<CAL_NB_PTS_INTER; k++) |
|
1424 | for (k=0; k<CAL_NB_PTS_INTER; k++) | |
1423 | { |
|
1425 | { | |
1424 | val = sin( 2 * pi * CAL_F0 * k * Ts ) |
|
1426 | val = sin( 2 * pi * CAL_F0 * k * Ts ) | |
1425 | + sin( 2 * pi * CAL_F1 * k * Ts ); |
|
1427 | + sin( 2 * pi * CAL_F1 * k * Ts ); | |
1426 | data[k] = (unsigned short) ((val * CONST_512) + CONST_2048); |
|
1428 | data[k] = (unsigned short) ((val * CONST_512) + CONST_2048); | |
1427 | } |
|
1429 | } | |
1428 |
|
1430 | |||
1429 | // write the signal in interleaved mode |
|
1431 | // write the signal in interleaved mode | |
1430 | for (k=0; k < STEPS_FOR_STORAGE_INTER; k++) |
|
1432 | for (k=0; k < STEPS_FOR_STORAGE_INTER; k++) | |
1431 | { |
|
1433 | { | |
1432 | dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ]; |
|
1434 | dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ]; | |
1433 | time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK ) |
|
1435 | time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK ) | |
1434 | + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); |
|
1436 | + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); | |
1435 | time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK ) |
|
1437 | time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK ) | |
1436 | + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); |
|
1438 | + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); | |
1437 | } |
|
1439 | } | |
1438 | } |
|
1440 | } | |
1439 |
|
1441 | |||
1440 | void setCalibrationReload( bool state) |
|
1442 | void setCalibrationReload( bool state) | |
1441 | { |
|
1443 | { | |
1442 | if (state == true) |
|
1444 | if (state == true) | |
1443 | { |
|
1445 | { | |
1444 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000] |
|
1446 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000] | |
1445 | } |
|
1447 | } | |
1446 | else |
|
1448 | else | |
1447 | { |
|
1449 | { | |
1448 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111] |
|
1450 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111] | |
1449 | } |
|
1451 | } | |
1450 | } |
|
1452 | } | |
1451 |
|
1453 | |||
1452 | void setCalibrationEnable( bool state ) |
|
1454 | void setCalibrationEnable( bool state ) | |
1453 | { |
|
1455 | { | |
1454 | // this bit drives the multiplexer |
|
1456 | // this bit drives the multiplexer | |
1455 | if (state == true) |
|
1457 | if (state == true) | |
1456 | { |
|
1458 | { | |
1457 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000] |
|
1459 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000] | |
1458 | } |
|
1460 | } | |
1459 | else |
|
1461 | else | |
1460 | { |
|
1462 | { | |
1461 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111] |
|
1463 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111] | |
1462 | } |
|
1464 | } | |
1463 | } |
|
1465 | } | |
1464 |
|
1466 | |||
1465 | void setCalibrationInterleaved( bool state ) |
|
1467 | void setCalibrationInterleaved( bool state ) | |
1466 | { |
|
1468 | { | |
1467 | // this bit drives the multiplexer |
|
1469 | // this bit drives the multiplexer | |
1468 | if (state == true) |
|
1470 | if (state == true) | |
1469 | { |
|
1471 | { | |
1470 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000] |
|
1472 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000] | |
1471 | } |
|
1473 | } | |
1472 | else |
|
1474 | else | |
1473 | { |
|
1475 | { | |
1474 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111] |
|
1476 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111] | |
1475 | } |
|
1477 | } | |
1476 | } |
|
1478 | } | |
1477 |
|
1479 | |||
1478 | void setCalibration( bool state ) |
|
1480 | void setCalibration( bool state ) | |
1479 | { |
|
1481 | { | |
1480 | if (state == true) |
|
1482 | if (state == true) | |
1481 | { |
|
1483 | { | |
1482 | setCalibrationEnable( true ); |
|
1484 | setCalibrationEnable( true ); | |
1483 | setCalibrationReload( false ); |
|
1485 | setCalibrationReload( false ); | |
1484 | set_hk_lfr_calib_enable( true ); |
|
1486 | set_hk_lfr_calib_enable( true ); | |
1485 | } |
|
1487 | } | |
1486 | else |
|
1488 | else | |
1487 | { |
|
1489 | { | |
1488 | setCalibrationEnable( false ); |
|
1490 | setCalibrationEnable( false ); | |
1489 | setCalibrationReload( true ); |
|
1491 | setCalibrationReload( true ); | |
1490 | set_hk_lfr_calib_enable( false ); |
|
1492 | set_hk_lfr_calib_enable( false ); | |
1491 | } |
|
1493 | } | |
1492 | } |
|
1494 | } | |
1493 |
|
1495 | |||
1494 | void configureCalibration( bool interleaved ) |
|
1496 | void configureCalibration( bool interleaved ) | |
1495 | { |
|
1497 | { | |
1496 | setCalibration( false ); |
|
1498 | setCalibration( false ); | |
1497 | if ( interleaved == true ) |
|
1499 | if ( interleaved == true ) | |
1498 | { |
|
1500 | { | |
1499 | setCalibrationInterleaved( true ); |
|
1501 | setCalibrationInterleaved( true ); | |
1500 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1502 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | |
1501 | setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384 |
|
1503 | setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384 | |
1502 | setCalibrationDataInterleaved(); |
|
1504 | setCalibrationDataInterleaved(); | |
1503 | } |
|
1505 | } | |
1504 | else |
|
1506 | else | |
1505 | { |
|
1507 | { | |
1506 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1508 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | |
1507 | setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1) |
|
1509 | setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1) | |
1508 | setCalibrationData(); |
|
1510 | setCalibrationData(); | |
1509 | } |
|
1511 | } | |
1510 | } |
|
1512 | } | |
1511 |
|
1513 | |||
1512 | //**************** |
|
1514 | //**************** | |
1513 | // CLOSING ACTIONS |
|
1515 | // CLOSING ACTIONS | |
1514 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1516 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) | |
1515 | { |
|
1517 | { | |
1516 | /** This function is used to update the HK packets statistics after a successful TC execution. |
|
1518 | /** This function is used to update the HK packets statistics after a successful TC execution. | |
1517 | * |
|
1519 | * | |
1518 | * @param TC points to the TC being processed |
|
1520 | * @param TC points to the TC being processed | |
1519 | * @param time is the time used to date the TC execution |
|
1521 | * @param time is the time used to date the TC execution | |
1520 | * |
|
1522 | * | |
1521 | */ |
|
1523 | */ | |
1522 |
|
1524 | |||
1523 | unsigned int val; |
|
1525 | unsigned int val; | |
1524 |
|
1526 | |||
1525 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
1527 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; | |
1526 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
1528 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; | |
1527 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR; |
|
1529 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR; | |
1528 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
1530 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; | |
1529 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR; |
|
1531 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR; | |
1530 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
1532 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; | |
1531 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0]; |
|
1533 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0]; | |
1532 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1]; |
|
1534 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1]; | |
1533 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2]; |
|
1535 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2]; | |
1534 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3]; |
|
1536 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3]; | |
1535 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4]; |
|
1537 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4]; | |
1536 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5]; |
|
1538 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5]; | |
1537 |
|
1539 | |||
1538 | val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; |
|
1540 | val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; | |
1539 | val++; |
|
1541 | val++; | |
1540 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
1542 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | |
1541 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); |
|
1543 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); | |
1542 | } |
|
1544 | } | |
1543 |
|
1545 | |||
1544 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1546 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) | |
1545 | { |
|
1547 | { | |
1546 | /** This function is used to update the HK packets statistics after a TC rejection. |
|
1548 | /** This function is used to update the HK packets statistics after a TC rejection. | |
1547 | * |
|
1549 | * | |
1548 | * @param TC points to the TC being processed |
|
1550 | * @param TC points to the TC being processed | |
1549 | * @param time is the time used to date the TC rejection |
|
1551 | * @param time is the time used to date the TC rejection | |
1550 | * |
|
1552 | * | |
1551 | */ |
|
1553 | */ | |
1552 |
|
1554 | |||
1553 | unsigned int val; |
|
1555 | unsigned int val; | |
1554 |
|
1556 | |||
1555 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
1557 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; | |
1556 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
1558 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; | |
1557 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR; |
|
1559 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR; | |
1558 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
1560 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; | |
1559 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR; |
|
1561 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR; | |
1560 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
1562 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; | |
1561 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0]; |
|
1563 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0]; | |
1562 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1]; |
|
1564 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1]; | |
1563 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2]; |
|
1565 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2]; | |
1564 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3]; |
|
1566 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3]; | |
1565 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4]; |
|
1567 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4]; | |
1566 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5]; |
|
1568 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5]; | |
1567 |
|
1569 | |||
1568 | val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; |
|
1570 | val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; | |
1569 | val++; |
|
1571 | val++; | |
1570 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); |
|
1572 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | |
1571 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); |
|
1573 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); | |
1572 | } |
|
1574 | } | |
1573 |
|
1575 | |||
1574 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) |
|
1576 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) | |
1575 | { |
|
1577 | { | |
1576 | /** This function is the last step of the TC execution workflow. |
|
1578 | /** This function is the last step of the TC execution workflow. | |
1577 | * |
|
1579 | * | |
1578 | * @param TC points to the TC being processed |
|
1580 | * @param TC points to the TC being processed | |
1579 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) |
|
1581 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) | |
1580 | * @param queue_id is the id of the RTEMS message queue used to send TM packets |
|
1582 | * @param queue_id is the id of the RTEMS message queue used to send TM packets | |
1581 | * @param time is the time used to date the TC execution |
|
1583 | * @param time is the time used to date the TC execution | |
1582 | * |
|
1584 | * | |
1583 | */ |
|
1585 | */ | |
1584 |
|
1586 | |||
1585 | unsigned char requestedMode; |
|
1587 | unsigned char requestedMode; | |
1586 |
|
1588 | |||
1587 | if (result == LFR_SUCCESSFUL) |
|
1589 | if (result == LFR_SUCCESSFUL) | |
1588 | { |
|
1590 | { | |
1589 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
1591 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
1590 | & |
|
1592 | & | |
1591 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
1593 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
1592 | ) |
|
1594 | ) | |
1593 | { |
|
1595 | { | |
1594 | send_tm_lfr_tc_exe_success( TC, queue_id ); |
|
1596 | send_tm_lfr_tc_exe_success( TC, queue_id ); | |
1595 | } |
|
1597 | } | |
1596 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) |
|
1598 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) | |
1597 | { |
|
1599 | { | |
1598 | //********************************** |
|
1600 | //********************************** | |
1599 | // UPDATE THE LFRMODE LOCAL VARIABLE |
|
1601 | // UPDATE THE LFRMODE LOCAL VARIABLE | |
1600 | requestedMode = TC->dataAndCRC[1]; |
|
1602 | requestedMode = TC->dataAndCRC[1]; | |
1601 | updateLFRCurrentMode( requestedMode ); |
|
1603 | updateLFRCurrentMode( requestedMode ); | |
1602 | } |
|
1604 | } | |
1603 | } |
|
1605 | } | |
1604 | else if (result == LFR_EXE_ERROR) |
|
1606 | else if (result == LFR_EXE_ERROR) | |
1605 | { |
|
1607 | { | |
1606 | send_tm_lfr_tc_exe_error( TC, queue_id ); |
|
1608 | send_tm_lfr_tc_exe_error( TC, queue_id ); | |
1607 | } |
|
1609 | } | |
1608 | } |
|
1610 | } | |
1609 |
|
1611 | |||
1610 | //*************************** |
|
1612 | //*************************** | |
1611 | // Interrupt Service Routines |
|
1613 | // Interrupt Service Routines | |
1612 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
1614 | rtems_isr commutation_isr1( rtems_vector_number vector ) | |
1613 | { |
|
1615 | { | |
1614 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1616 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | |
1615 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") |
|
1617 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") | |
1616 | } |
|
1618 | } | |
1617 | } |
|
1619 | } | |
1618 |
|
1620 | |||
1619 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
1621 | rtems_isr commutation_isr2( rtems_vector_number vector ) | |
1620 | { |
|
1622 | { | |
1621 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1623 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | |
1622 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") |
|
1624 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") | |
1623 | } |
|
1625 | } | |
1624 | } |
|
1626 | } | |
1625 |
|
1627 | |||
1626 | //**************** |
|
1628 | //**************** | |
1627 | // OTHER FUNCTIONS |
|
1629 | // OTHER FUNCTIONS | |
1628 | void updateLFRCurrentMode( unsigned char requestedMode ) |
|
1630 | void updateLFRCurrentMode( unsigned char requestedMode ) | |
1629 | { |
|
1631 | { | |
1630 | /** This function updates the value of the global variable lfrCurrentMode. |
|
1632 | /** This function updates the value of the global variable lfrCurrentMode. | |
1631 | * |
|
1633 | * | |
1632 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
1634 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. | |
1633 | * |
|
1635 | * | |
1634 | */ |
|
1636 | */ | |
1635 |
|
1637 | |||
1636 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
1638 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure | |
1637 | housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK) |
|
1639 | housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK) | |
1638 | + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT ); |
|
1640 | + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT ); | |
1639 | lfrCurrentMode = requestedMode; |
|
1641 | lfrCurrentMode = requestedMode; | |
1640 | } |
|
1642 | } | |
1641 |
|
1643 | |||
1642 | void set_lfr_soft_reset( unsigned char value ) |
|
1644 | void set_lfr_soft_reset( unsigned char value ) | |
1643 | { |
|
1645 | { | |
1644 | if (value == 1) |
|
1646 | if (value == 1) | |
1645 | { |
|
1647 | { | |
1646 | time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100] |
|
1648 | time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100] | |
1647 | } |
|
1649 | } | |
1648 | else |
|
1650 | else | |
1649 | { |
|
1651 | { | |
1650 | time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011] |
|
1652 | time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011] | |
1651 | } |
|
1653 | } | |
1652 | } |
|
1654 | } | |
1653 |
|
1655 | |||
1654 | void reset_lfr( void ) |
|
1656 | void reset_lfr( void ) | |
1655 | { |
|
1657 | { | |
1656 | set_lfr_soft_reset( 1 ); |
|
1658 | set_lfr_soft_reset( 1 ); | |
1657 |
|
1659 | |||
1658 | set_lfr_soft_reset( 0 ); |
|
1660 | set_lfr_soft_reset( 0 ); | |
1659 |
|
1661 | |||
1660 | set_hk_lfr_sc_potential_flag( true ); |
|
1662 | set_hk_lfr_sc_potential_flag( true ); | |
1661 | } |
|
1663 | } |
General Comments 0
You need to be logged in to leave comments.
Login now