##// END OF EJS Templates
Added GPL header and documented some more functions
jeandet -
r390:1c936ff95146 No PWD scrub with... draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 7053a75ef0a55a40e950a8302065856f3bd06a26 header/lfr_common_headers
2 f5b83fb540b1cfd5d87c68621fb53f238eb623ae header/lfr_common_headers
@@ -1,8 +1,32
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 #ifndef GRSPW_H_INCLUDED
25 #ifndef GRSPW_H_INCLUDED
2 #define GRSPW_H_INCLUDED
26 #define GRSPW_H_INCLUDED
3
27
4 int grspw_set_ie( unsigned char value, unsigned int *ctrlReg );
28 int grspw_set_ie( unsigned char value, unsigned int *ctrlReg );
5 int grspw_set_tq( unsigned char value, unsigned int *ctrlReg );
29 int grspw_set_tq( unsigned char value, unsigned int *ctrlReg );
6 int grspw_set_tr( unsigned char value, unsigned int *ctrlReg );
30 int grspw_set_tr( unsigned char value, unsigned int *ctrlReg );
7
31
8 #endif // GRSPW_H_INCLUDED
32 #endif // GRSPW_H_INCLUDED
@@ -1,96 +1,119
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
1 /** Global variables of the LFR flight software.
24 /** Global variables of the LFR flight software.
2 *
25 *
3 * @file
26 * @file
4 * @author P. LEROY
27 * @author P. LEROY
5 *
28 *
6 * Among global variables, there are:
29 * Among global variables, there are:
7 * - RTEMS names and id.
30 * - RTEMS names and id.
8 * - APB configuration registers.
31 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
32 * - 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.
33 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
34 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
35 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
36 * - the global dump parameter buffer.
14 *
37 *
15 */
38 */
16
39
17 #include <rtems.h>
40 #include <rtems.h>
18 #include <grspw.h>
41 #include <grspw.h>
19
42
20 #include "ccsds_types.h"
43 #include "ccsds_types.h"
21 #include "grlib_regs.h"
44 #include "grlib_regs.h"
22 #include "fsw_params.h"
45 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
46 #include "fsw_params_wf_handler.h"
24
47
25
48
26 #define NB_OF_MISC_NAMES 5
49 #define NB_OF_MISC_NAMES 5
27
50
28 // RTEMS GLOBAL VARIABLES
51 // RTEMS GLOBAL VARIABLES
29 rtems_name misc_name[NB_OF_MISC_NAMES] = {0};
52 rtems_name misc_name[NB_OF_MISC_NAMES] = {0};
30 rtems_name Task_name[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task names */
53 rtems_name Task_name[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task names */
31 rtems_id Task_id[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task ids */
54 rtems_id Task_id[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task ids */
32 rtems_name timecode_timer_name = 0;
55 rtems_name timecode_timer_name = 0;
33 rtems_id timecode_timer_id = RTEMS_ID_NONE;
56 rtems_id timecode_timer_id = RTEMS_ID_NONE;
34 rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic
57 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
58 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
59 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
60 rtems_id AVGV_id = RTEMS_ID_NONE;// id of the AVGV rate monotonic period
38 int fdSPW = 0;
61 int fdSPW = 0;
39 int fdUART = 0;
62 int fdUART = 0;
40 unsigned char lfrCurrentMode = 0;
63 unsigned char lfrCurrentMode = 0;
41 unsigned char pa_bia_status_info = 0;
64 unsigned char pa_bia_status_info = 0;
42 unsigned char thisIsAnASMRestart = 0;
65 unsigned char thisIsAnASMRestart = 0;
43 unsigned char oneTcLfrUpdateTimeReceived = 0;
66 unsigned char oneTcLfrUpdateTimeReceived = 0;
44
67
45 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
68 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
46 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
69 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
47 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
70 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
48 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
71 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
49 // F0 F1 F2 F3
72 // F0 F1 F2 F3
50 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
73 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
51 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
74 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
52 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
75 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
53 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
76 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))) = {0};
54
77
55 //***********************************
78 //***********************************
56 // SPECTRAL MATRICES GLOBAL VARIABLES
79 // SPECTRAL MATRICES GLOBAL VARIABLES
57
80
58 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
81 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
59 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
82 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
60 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
83 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
61 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
84 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))) = {0};
62
85
63 // APB CONFIGURATION REGISTERS
86 // APB CONFIGURATION REGISTERS
64 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
87 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
65 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
88 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
66 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
89 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
67 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
90 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
68
91
69 // MODE PARAMETERS
92 // MODE PARAMETERS
70 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0};
93 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet = {0};
71 struct param_local_str param_local = {0};
94 struct param_local_str param_local = {0};
72 unsigned int lastValidEnterModeTime = {0};
95 unsigned int lastValidEnterModeTime = {0};
73
96
74 // HK PACKETS
97 // HK PACKETS
75 Packet_TM_LFR_HK_t housekeeping_packet = {0};
98 Packet_TM_LFR_HK_t housekeeping_packet = {0};
76 // message queues occupancy
99 // message queues occupancy
77 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
100 unsigned char hk_lfr_q_sd_fifo_size_max = 0;
78 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
101 unsigned char hk_lfr_q_rv_fifo_size_max = 0;
79 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
102 unsigned char hk_lfr_q_p0_fifo_size_max = 0;
80 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
103 unsigned char hk_lfr_q_p1_fifo_size_max = 0;
81 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
104 unsigned char hk_lfr_q_p2_fifo_size_max = 0;
82 // sequence counters are incremented by APID (PID + CAT) and destination ID
105 // sequence counters are incremented by APID (PID + CAT) and destination ID
83 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST __attribute__((aligned(0x4))) = 0;
106 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST __attribute__((aligned(0x4))) = 0;
84 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 __attribute__((aligned(0x4))) = 0;
107 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2 __attribute__((aligned(0x4))) = 0;
85 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
108 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
86 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
109 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID] __attribute__((aligned(0x4))) = {0};
87 unsigned short sequenceCounterHK __attribute__((aligned(0x4))) = {0};
110 unsigned short sequenceCounterHK __attribute__((aligned(0x4))) = {0};
88 spw_stats grspw_stats __attribute__((aligned(0x4))) = {0};
111 spw_stats grspw_stats __attribute__((aligned(0x4))) = {0};
89
112
90 // TC_LFR_UPDATE_INFO
113 // TC_LFR_UPDATE_INFO
91 rw_f_t rw_f;
114 rw_f_t rw_f;
92
115
93 // TC_LFR_LOAD_FILTER_PAR
116 // TC_LFR_LOAD_FILTER_PAR
94 filterPar_t filterPar = {0};
117 filterPar_t filterPar = {0};
95
118
96 fbins_masks_t fbins_masks = {0};
119 fbins_masks_t fbins_masks = {0};
@@ -1,1009 +1,1029
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** This is the RTEMS initialization module.
25 /** This is the RTEMS initialization module.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * This module contains two very different information:
30 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
31 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
32 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
33 *
10 */
34 */
11
35
12 //*************************
13 // GPL reminder to be added
14 //*************************
15
16 #include <rtems.h>
36 #include <rtems.h>
17
37
18
38
19 /* configuration information */
39 /* configuration information */
20
40
21 #define CONFIGURE_INIT
41 #define CONFIGURE_INIT
22
42
23 #include <bsp.h> /* for device driver prototypes */
43 #include <bsp.h> /* for device driver prototypes */
24
44
25 /* configuration information */
45 /* configuration information */
26
46
27 #include <fsw_params.h>
47 #include <fsw_params.h>
28
48
29 #include <rtems/confdefs.h>
49 #include <rtems/confdefs.h>
30
50
31 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
51 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
32 #ifdef RTEMS_DRVMGR_STARTUP
52 #ifdef RTEMS_DRVMGR_STARTUP
33 #ifdef LEON3
53 #ifdef LEON3
34 /* Add Timer and UART Driver */
54 /* Add Timer and UART Driver */
35
55
36 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
56 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
38 #endif
58 #endif
39
59
40 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
60 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
41 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
61 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
42 #endif
62 #endif
43
63
44 #endif
64 #endif
45 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
65 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
46 #include <drvmgr/drvmgr_confdefs.h>
66 #include <drvmgr/drvmgr_confdefs.h>
47 #endif
67 #endif
48
68
49 #include "fsw_init.h"
69 #include "fsw_init.h"
50 #include "fsw_config.c"
70 #include "fsw_config.c"
51 #include "GscMemoryLPP.hpp"
71 #include "GscMemoryLPP.hpp"
52
72
53 void initCache()
73 void initCache()
54 {
74 {
55 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
75 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
56 // These should only be read and written using 32-bit LDA/STA instructions.
76 // These should only be read and written using 32-bit LDA/STA instructions.
57 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
77 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
58 // The table below shows the register addresses:
78 // The table below shows the register addresses:
59 // 0x00 Cache control register
79 // 0x00 Cache control register
60 // 0x04 Reserved
80 // 0x04 Reserved
61 // 0x08 Instruction cache configuration register
81 // 0x08 Instruction cache configuration register
62 // 0x0C Data cache configuration register
82 // 0x0C Data cache configuration register
63
83
64 // Cache Control Register Leon3 / Leon3FT
84 // Cache Control Register Leon3 / Leon3FT
65 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
85 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
66 // RFT PS TB DS FD FI FT ST IB
86 // RFT PS TB DS FD FI FT ST IB
67 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
87 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
68 // IP DP ITE IDE DTE DDE DF IF DCS ICS
88 // IP DP ITE IDE DTE DDE DF IF DCS ICS
69
89
70 unsigned int cacheControlRegister;
90 unsigned int cacheControlRegister;
71
91
72 CCR_resetCacheControlRegister();
92 CCR_resetCacheControlRegister();
73 ASR16_resetRegisterProtectionControlRegister();
93 ASR16_resetRegisterProtectionControlRegister();
74
94
75 cacheControlRegister = CCR_getValue();
95 cacheControlRegister = CCR_getValue();
76 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
96 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
77 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
97 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
78
98
79 CCR_enableInstructionCache(); // ICS bits
99 CCR_enableInstructionCache(); // ICS bits
80 CCR_enableDataCache(); // DCS bits
100 CCR_enableDataCache(); // DCS bits
81 CCR_enableInstructionBurstFetch(); // IB bit
101 CCR_enableInstructionBurstFetch(); // IB bit
82
102
83 faultTolerantScheme();
103 faultTolerantScheme();
84
104
85 cacheControlRegister = CCR_getValue();
105 cacheControlRegister = CCR_getValue();
86 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
106 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
87 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
107 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
88
108
89 PRINTF("\n");
109 PRINTF("\n");
90 }
110 }
91
111
92 rtems_task Init( rtems_task_argument ignored )
112 rtems_task Init( rtems_task_argument ignored )
93 {
113 {
94 /** This is the RTEMS INIT taks, it is the first task launched by the system.
114 /** This is the RTEMS INIT taks, it is the first task launched by the system.
95 *
115 *
96 * @param unused is the starting argument of the RTEMS task
116 * @param unused is the starting argument of the RTEMS task
97 *
117 *
98 * The INIT task create and run all other RTEMS tasks.
118 * The INIT task create and run all other RTEMS tasks.
99 *
119 *
100 */
120 */
101
121
102 //***********
122 //***********
103 // INIT CACHE
123 // INIT CACHE
104
124
105 unsigned char *vhdlVersion;
125 unsigned char *vhdlVersion;
106
126
107 reset_lfr();
127 reset_lfr();
108
128
109 reset_local_time();
129 reset_local_time();
110
130
111 rtems_cpu_usage_reset();
131 rtems_cpu_usage_reset();
112
132
113 rtems_status_code status;
133 rtems_status_code status;
114 rtems_status_code status_spw;
134 rtems_status_code status_spw;
115 rtems_isr_entry old_isr_handler;
135 rtems_isr_entry old_isr_handler;
116
136
117 old_isr_handler = NULL;
137 old_isr_handler = NULL;
118
138
119 // UART settings
139 // UART settings
120 enable_apbuart_transmitter();
140 enable_apbuart_transmitter();
121 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
141 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
122
142
123 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
143 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
124
144
125
145
126 PRINTF("\n\n\n\n\n")
146 PRINTF("\n\n\n\n\n")
127
147
128 initCache();
148 initCache();
129
149
130 PRINTF("*************************\n")
150 PRINTF("*************************\n")
131 PRINTF("** LFR Flight Software **\n")
151 PRINTF("** LFR Flight Software **\n")
132
152
133 PRINTF1("** %d-", SW_VERSION_N1)
153 PRINTF1("** %d-", SW_VERSION_N1)
134 PRINTF1("%d-" , SW_VERSION_N2)
154 PRINTF1("%d-" , SW_VERSION_N2)
135 PRINTF1("%d-" , SW_VERSION_N3)
155 PRINTF1("%d-" , SW_VERSION_N3)
136 PRINTF1("%d **\n", SW_VERSION_N4)
156 PRINTF1("%d **\n", SW_VERSION_N4)
137
157
138 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
158 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
139 PRINTF("** VHDL **\n")
159 PRINTF("** VHDL **\n")
140 PRINTF1("** %d-", vhdlVersion[1])
160 PRINTF1("** %d-", vhdlVersion[1])
141 PRINTF1("%d-" , vhdlVersion[2])
161 PRINTF1("%d-" , vhdlVersion[2])
142 PRINTF1("%d **\n", vhdlVersion[3])
162 PRINTF1("%d **\n", vhdlVersion[3])
143 PRINTF("*************************\n")
163 PRINTF("*************************\n")
144 PRINTF("\n\n")
164 PRINTF("\n\n")
145
165
146 init_parameter_dump();
166 init_parameter_dump();
147 init_kcoefficients_dump();
167 init_kcoefficients_dump();
148 init_local_mode_parameters();
168 init_local_mode_parameters();
149 init_housekeeping_parameters();
169 init_housekeeping_parameters();
150 init_k_coefficients_prc0();
170 init_k_coefficients_prc0();
151 init_k_coefficients_prc1();
171 init_k_coefficients_prc1();
152 init_k_coefficients_prc2();
172 init_k_coefficients_prc2();
153 pa_bia_status_info = INIT_CHAR;
173 pa_bia_status_info = INIT_CHAR;
154
174
155 // initialize all reaction wheels frequencies to NaN
175 // initialize all reaction wheels frequencies to NaN
156 rw_f.cp_rpw_sc_rw1_f1 = NAN;
176 rw_f.cp_rpw_sc_rw1_f1 = NAN;
157 rw_f.cp_rpw_sc_rw1_f2 = NAN;
177 rw_f.cp_rpw_sc_rw1_f2 = NAN;
158 rw_f.cp_rpw_sc_rw1_f3 = NAN;
178 rw_f.cp_rpw_sc_rw1_f3 = NAN;
159 rw_f.cp_rpw_sc_rw1_f4 = NAN;
179 rw_f.cp_rpw_sc_rw1_f4 = NAN;
160 rw_f.cp_rpw_sc_rw2_f1 = NAN;
180 rw_f.cp_rpw_sc_rw2_f1 = NAN;
161 rw_f.cp_rpw_sc_rw2_f2 = NAN;
181 rw_f.cp_rpw_sc_rw2_f2 = NAN;
162 rw_f.cp_rpw_sc_rw2_f3 = NAN;
182 rw_f.cp_rpw_sc_rw2_f3 = NAN;
163 rw_f.cp_rpw_sc_rw2_f4 = NAN;
183 rw_f.cp_rpw_sc_rw2_f4 = NAN;
164 rw_f.cp_rpw_sc_rw3_f1 = NAN;
184 rw_f.cp_rpw_sc_rw3_f1 = NAN;
165 rw_f.cp_rpw_sc_rw3_f2 = NAN;
185 rw_f.cp_rpw_sc_rw3_f2 = NAN;
166 rw_f.cp_rpw_sc_rw3_f3 = NAN;
186 rw_f.cp_rpw_sc_rw3_f3 = NAN;
167 rw_f.cp_rpw_sc_rw3_f4 = NAN;
187 rw_f.cp_rpw_sc_rw3_f4 = NAN;
168 rw_f.cp_rpw_sc_rw4_f1 = NAN;
188 rw_f.cp_rpw_sc_rw4_f1 = NAN;
169 rw_f.cp_rpw_sc_rw4_f2 = NAN;
189 rw_f.cp_rpw_sc_rw4_f2 = NAN;
170 rw_f.cp_rpw_sc_rw4_f3 = NAN;
190 rw_f.cp_rpw_sc_rw4_f3 = NAN;
171 rw_f.cp_rpw_sc_rw4_f4 = NAN;
191 rw_f.cp_rpw_sc_rw4_f4 = NAN;
172
192
173 // initialize filtering parameters
193 // initialize filtering parameters
174 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
194 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
175 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
195 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
176 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
196 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
177 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
197 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
178 filterPar.modulus_in_finetime = DEFAULT_MODULUS;
198 filterPar.modulus_in_finetime = DEFAULT_MODULUS;
179 filterPar.tbad_in_finetime = DEFAULT_TBAD;
199 filterPar.tbad_in_finetime = DEFAULT_TBAD;
180 filterPar.offset_in_finetime = DEFAULT_OFFSET;
200 filterPar.offset_in_finetime = DEFAULT_OFFSET;
181 filterPar.shift_in_finetime = DEFAULT_SHIFT;
201 filterPar.shift_in_finetime = DEFAULT_SHIFT;
182 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
202 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
183
203
184 // waveform picker initialization
204 // waveform picker initialization
185 WFP_init_rings();
205 WFP_init_rings();
186 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
206 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
187 WFP_reset_current_ring_nodes();
207 WFP_reset_current_ring_nodes();
188 reset_waveform_picker_regs();
208 reset_waveform_picker_regs();
189
209
190 // spectral matrices initialization
210 // spectral matrices initialization
191 SM_init_rings(); // initialize spectral matrices rings
211 SM_init_rings(); // initialize spectral matrices rings
192 SM_reset_current_ring_nodes();
212 SM_reset_current_ring_nodes();
193 reset_spectral_matrix_regs();
213 reset_spectral_matrix_regs();
194
214
195 // configure calibration
215 // configure calibration
196 configureCalibration( false ); // true means interleaved mode, false is for normal mode
216 configureCalibration( false ); // true means interleaved mode, false is for normal mode
197
217
198 updateLFRCurrentMode( LFR_MODE_STANDBY );
218 updateLFRCurrentMode( LFR_MODE_STANDBY );
199
219
200 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
220 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
201
221
202 create_names(); // create all names
222 create_names(); // create all names
203
223
204 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
224 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
205 if (status != RTEMS_SUCCESSFUL)
225 if (status != RTEMS_SUCCESSFUL)
206 {
226 {
207 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
227 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
208 }
228 }
209
229
210 status = create_message_queues(); // create message queues
230 status = create_message_queues(); // create message queues
211 if (status != RTEMS_SUCCESSFUL)
231 if (status != RTEMS_SUCCESSFUL)
212 {
232 {
213 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
233 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
214 }
234 }
215
235
216 status = create_all_tasks(); // create all tasks
236 status = create_all_tasks(); // create all tasks
217 if (status != RTEMS_SUCCESSFUL)
237 if (status != RTEMS_SUCCESSFUL)
218 {
238 {
219 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
239 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
220 }
240 }
221
241
222 // **************************
242 // **************************
223 // <SPACEWIRE INITIALIZATION>
243 // <SPACEWIRE INITIALIZATION>
224 status_spw = spacewire_open_link(); // (1) open the link
244 status_spw = spacewire_open_link(); // (1) open the link
225 if ( status_spw != RTEMS_SUCCESSFUL )
245 if ( status_spw != RTEMS_SUCCESSFUL )
226 {
246 {
227 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
247 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
228 }
248 }
229
249
230 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
250 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
231 {
251 {
232 status_spw = spacewire_configure_link( fdSPW );
252 status_spw = spacewire_configure_link( fdSPW );
233 if ( status_spw != RTEMS_SUCCESSFUL )
253 if ( status_spw != RTEMS_SUCCESSFUL )
234 {
254 {
235 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
255 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
236 }
256 }
237 }
257 }
238
258
239 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
259 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
240 {
260 {
241 status_spw = spacewire_start_link( fdSPW );
261 status_spw = spacewire_start_link( fdSPW );
242 if ( status_spw != RTEMS_SUCCESSFUL )
262 if ( status_spw != RTEMS_SUCCESSFUL )
243 {
263 {
244 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
264 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
245 }
265 }
246 }
266 }
247 // </SPACEWIRE INITIALIZATION>
267 // </SPACEWIRE INITIALIZATION>
248 // ***************************
268 // ***************************
249
269
250 status = start_all_tasks(); // start all tasks
270 status = start_all_tasks(); // start all tasks
251 if (status != RTEMS_SUCCESSFUL)
271 if (status != RTEMS_SUCCESSFUL)
252 {
272 {
253 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
273 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
254 }
274 }
255
275
256 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
276 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
257 status = start_recv_send_tasks();
277 status = start_recv_send_tasks();
258 if ( status != RTEMS_SUCCESSFUL )
278 if ( status != RTEMS_SUCCESSFUL )
259 {
279 {
260 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
280 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
261 }
281 }
262
282
263 // suspend science tasks, they will be restarted later depending on the mode
283 // suspend science tasks, they will be restarted later depending on the mode
264 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
284 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
265 if (status != RTEMS_SUCCESSFUL)
285 if (status != RTEMS_SUCCESSFUL)
266 {
286 {
267 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
287 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
268 }
288 }
269
289
270 // configure IRQ handling for the waveform picker unit
290 // configure IRQ handling for the waveform picker unit
271 status = rtems_interrupt_catch( waveforms_isr,
291 status = rtems_interrupt_catch( waveforms_isr,
272 IRQ_SPARC_WAVEFORM_PICKER,
292 IRQ_SPARC_WAVEFORM_PICKER,
273 &old_isr_handler) ;
293 &old_isr_handler) ;
274 // configure IRQ handling for the spectral matrices unit
294 // configure IRQ handling for the spectral matrices unit
275 status = rtems_interrupt_catch( spectral_matrices_isr,
295 status = rtems_interrupt_catch( spectral_matrices_isr,
276 IRQ_SPARC_SPECTRAL_MATRIX,
296 IRQ_SPARC_SPECTRAL_MATRIX,
277 &old_isr_handler) ;
297 &old_isr_handler) ;
278
298
279 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
299 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
280 if ( status_spw != RTEMS_SUCCESSFUL )
300 if ( status_spw != RTEMS_SUCCESSFUL )
281 {
301 {
282 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
302 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
283 if ( status != RTEMS_SUCCESSFUL ) {
303 if ( status != RTEMS_SUCCESSFUL ) {
284 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
304 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
285 }
305 }
286 }
306 }
287
307
288 BOOT_PRINTF("delete INIT\n")
308 BOOT_PRINTF("delete INIT\n")
289
309
290 set_hk_lfr_sc_potential_flag( true );
310 set_hk_lfr_sc_potential_flag( true );
291
311
292 // start the timer to detect a missing spacewire timecode
312 // start the timer to detect a missing spacewire timecode
293 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
313 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
294 // if a tickout is generated, the timer is restarted
314 // if a tickout is generated, the timer is restarted
295 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
315 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
296
316
297 grspw_timecode_callback = &timecode_irq_handler;
317 grspw_timecode_callback = &timecode_irq_handler;
298
318
299 status = rtems_task_delete(RTEMS_SELF);
319 status = rtems_task_delete(RTEMS_SELF);
300
320
301 }
321 }
302
322
303 void init_local_mode_parameters( void )
323 void init_local_mode_parameters( void )
304 {
324 {
305 /** This function initialize the param_local global variable with default values.
325 /** This function initialize the param_local global variable with default values.
306 *
326 *
307 */
327 */
308
328
309 unsigned int i;
329 unsigned int i;
310
330
311 // LOCAL PARAMETERS
331 // LOCAL PARAMETERS
312
332
313 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
333 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
314 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
334 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
315
335
316 // init sequence counters
336 // init sequence counters
317
337
318 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
338 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
319 {
339 {
320 sequenceCounters_TC_EXE[i] = INIT_CHAR;
340 sequenceCounters_TC_EXE[i] = INIT_CHAR;
321 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
341 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
322 }
342 }
323 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
343 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
324 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
344 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
325 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
345 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
326 }
346 }
327
347
328 void reset_local_time( void )
348 void reset_local_time( void )
329 {
349 {
330 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
350 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
331 }
351 }
332
352
333 void create_names( void ) // create all names for tasks and queues
353 void create_names( void ) // create all names for tasks and queues
334 {
354 {
335 /** This function creates all RTEMS names used in the software for tasks and queues.
355 /** This function creates all RTEMS names used in the software for tasks and queues.
336 *
356 *
337 * @return RTEMS directive status codes:
357 * @return RTEMS directive status codes:
338 * - RTEMS_SUCCESSFUL - successful completion
358 * - RTEMS_SUCCESSFUL - successful completion
339 *
359 *
340 */
360 */
341
361
342 // task names
362 // task names
343 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
363 Task_name[TASKID_AVGV] = rtems_build_name( 'A', 'V', 'G', 'V' );
344 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
364 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
345 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
365 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
346 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
366 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
347 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
367 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
348 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
368 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
349 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
369 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
350 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
370 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
351 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
371 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
352 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
372 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
353 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
373 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
354 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
374 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
355 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
375 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
356 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
376 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
357 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
377 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
358 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
378 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
359 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
379 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
360 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
380 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
361 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
381 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
362 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
382 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
363 Task_name[TASKID_SCRB] = rtems_build_name( 'S', 'C', 'R', 'B' );
383 Task_name[TASKID_SCRB] = rtems_build_name( 'S', 'C', 'R', 'B' );
364 Task_name[TASKID_CALI] = rtems_build_name( 'C', 'A', 'L', 'I' );
384 Task_name[TASKID_CALI] = rtems_build_name( 'C', 'A', 'L', 'I' );
365
385
366 // rate monotonic period names
386 // rate monotonic period names
367 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
387 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
368 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
388 name_avgv_rate_monotonic = rtems_build_name( 'A', 'V', 'G', 'V' );
369
389
370 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
390 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
371 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
391 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
372 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
392 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
373 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
393 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
374 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
394 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
375
395
376 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
396 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
377 }
397 }
378
398
379 int create_all_tasks( void ) // create all tasks which run in the software
399 int create_all_tasks( void ) // create all tasks which run in the software
380 {
400 {
381 /** This function creates all RTEMS tasks used in the software.
401 /** This function creates all RTEMS tasks used in the software.
382 *
402 *
383 * @return RTEMS directive status codes:
403 * @return RTEMS directive status codes:
384 * - RTEMS_SUCCESSFUL - task created successfully
404 * - RTEMS_SUCCESSFUL - task created successfully
385 * - RTEMS_INVALID_ADDRESS - id is NULL
405 * - RTEMS_INVALID_ADDRESS - id is NULL
386 * - RTEMS_INVALID_NAME - invalid task name
406 * - RTEMS_INVALID_NAME - invalid task name
387 * - RTEMS_INVALID_PRIORITY - invalid task priority
407 * - RTEMS_INVALID_PRIORITY - invalid task priority
388 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
408 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
389 * - RTEMS_TOO_MANY - too many tasks created
409 * - RTEMS_TOO_MANY - too many tasks created
390 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
410 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
391 * - RTEMS_TOO_MANY - too many global objects
411 * - RTEMS_TOO_MANY - too many global objects
392 *
412 *
393 */
413 */
394
414
395 rtems_status_code status;
415 rtems_status_code status;
396
416
397 //**********
417 //**********
398 // SPACEWIRE
418 // SPACEWIRE
399 // RECV
419 // RECV
400 status = rtems_task_create(
420 status = rtems_task_create(
401 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
421 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
402 RTEMS_DEFAULT_MODES,
422 RTEMS_DEFAULT_MODES,
403 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
423 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
404 );
424 );
405 if (status == RTEMS_SUCCESSFUL) // SEND
425 if (status == RTEMS_SUCCESSFUL) // SEND
406 {
426 {
407 status = rtems_task_create(
427 status = rtems_task_create(
408 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
428 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
409 RTEMS_DEFAULT_MODES,
429 RTEMS_DEFAULT_MODES,
410 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
430 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
411 );
431 );
412 }
432 }
413 if (status == RTEMS_SUCCESSFUL) // LINK
433 if (status == RTEMS_SUCCESSFUL) // LINK
414 {
434 {
415 status = rtems_task_create(
435 status = rtems_task_create(
416 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
436 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
417 RTEMS_DEFAULT_MODES,
437 RTEMS_DEFAULT_MODES,
418 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
438 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
419 );
439 );
420 }
440 }
421 if (status == RTEMS_SUCCESSFUL) // ACTN
441 if (status == RTEMS_SUCCESSFUL) // ACTN
422 {
442 {
423 status = rtems_task_create(
443 status = rtems_task_create(
424 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
444 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
425 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
445 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
426 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
446 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
427 );
447 );
428 }
448 }
429 if (status == RTEMS_SUCCESSFUL) // SPIQ
449 if (status == RTEMS_SUCCESSFUL) // SPIQ
430 {
450 {
431 status = rtems_task_create(
451 status = rtems_task_create(
432 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
452 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
433 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
453 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
434 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
454 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
435 );
455 );
436 }
456 }
437
457
438 //******************
458 //******************
439 // SPECTRAL MATRICES
459 // SPECTRAL MATRICES
440 if (status == RTEMS_SUCCESSFUL) // AVF0
460 if (status == RTEMS_SUCCESSFUL) // AVF0
441 {
461 {
442 status = rtems_task_create(
462 status = rtems_task_create(
443 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
463 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
444 RTEMS_DEFAULT_MODES,
464 RTEMS_DEFAULT_MODES,
445 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
465 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
446 );
466 );
447 }
467 }
448 if (status == RTEMS_SUCCESSFUL) // PRC0
468 if (status == RTEMS_SUCCESSFUL) // PRC0
449 {
469 {
450 status = rtems_task_create(
470 status = rtems_task_create(
451 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
471 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
452 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
472 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
453 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
473 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
454 );
474 );
455 }
475 }
456 if (status == RTEMS_SUCCESSFUL) // AVF1
476 if (status == RTEMS_SUCCESSFUL) // AVF1
457 {
477 {
458 status = rtems_task_create(
478 status = rtems_task_create(
459 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
479 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
460 RTEMS_DEFAULT_MODES,
480 RTEMS_DEFAULT_MODES,
461 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
481 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
462 );
482 );
463 }
483 }
464 if (status == RTEMS_SUCCESSFUL) // PRC1
484 if (status == RTEMS_SUCCESSFUL) // PRC1
465 {
485 {
466 status = rtems_task_create(
486 status = rtems_task_create(
467 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
487 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
468 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
488 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
469 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
489 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
470 );
490 );
471 }
491 }
472 if (status == RTEMS_SUCCESSFUL) // AVF2
492 if (status == RTEMS_SUCCESSFUL) // AVF2
473 {
493 {
474 status = rtems_task_create(
494 status = rtems_task_create(
475 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
495 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
476 RTEMS_DEFAULT_MODES,
496 RTEMS_DEFAULT_MODES,
477 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
497 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
478 );
498 );
479 }
499 }
480 if (status == RTEMS_SUCCESSFUL) // PRC2
500 if (status == RTEMS_SUCCESSFUL) // PRC2
481 {
501 {
482 status = rtems_task_create(
502 status = rtems_task_create(
483 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
503 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
484 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
504 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
485 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
505 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
486 );
506 );
487 }
507 }
488
508
489 //****************
509 //****************
490 // WAVEFORM PICKER
510 // WAVEFORM PICKER
491 if (status == RTEMS_SUCCESSFUL) // WFRM
511 if (status == RTEMS_SUCCESSFUL) // WFRM
492 {
512 {
493 status = rtems_task_create(
513 status = rtems_task_create(
494 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
514 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
495 RTEMS_DEFAULT_MODES,
515 RTEMS_DEFAULT_MODES,
496 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
516 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
497 );
517 );
498 }
518 }
499 if (status == RTEMS_SUCCESSFUL) // CWF3
519 if (status == RTEMS_SUCCESSFUL) // CWF3
500 {
520 {
501 status = rtems_task_create(
521 status = rtems_task_create(
502 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
522 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
503 RTEMS_DEFAULT_MODES,
523 RTEMS_DEFAULT_MODES,
504 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
524 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
505 );
525 );
506 }
526 }
507 if (status == RTEMS_SUCCESSFUL) // CWF2
527 if (status == RTEMS_SUCCESSFUL) // CWF2
508 {
528 {
509 status = rtems_task_create(
529 status = rtems_task_create(
510 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
530 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
511 RTEMS_DEFAULT_MODES,
531 RTEMS_DEFAULT_MODES,
512 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
532 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
513 );
533 );
514 }
534 }
515 if (status == RTEMS_SUCCESSFUL) // CWF1
535 if (status == RTEMS_SUCCESSFUL) // CWF1
516 {
536 {
517 status = rtems_task_create(
537 status = rtems_task_create(
518 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
538 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
519 RTEMS_DEFAULT_MODES,
539 RTEMS_DEFAULT_MODES,
520 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
540 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
521 );
541 );
522 }
542 }
523 if (status == RTEMS_SUCCESSFUL) // SWBD
543 if (status == RTEMS_SUCCESSFUL) // SWBD
524 {
544 {
525 status = rtems_task_create(
545 status = rtems_task_create(
526 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
546 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
527 RTEMS_DEFAULT_MODES,
547 RTEMS_DEFAULT_MODES,
528 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
548 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
529 );
549 );
530 }
550 }
531
551
532 //*****
552 //*****
533 // MISC
553 // MISC
534 if (status == RTEMS_SUCCESSFUL) // LOAD
554 if (status == RTEMS_SUCCESSFUL) // LOAD
535 {
555 {
536 status = rtems_task_create(
556 status = rtems_task_create(
537 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
557 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
538 RTEMS_DEFAULT_MODES,
558 RTEMS_DEFAULT_MODES,
539 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
559 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
540 );
560 );
541 }
561 }
542 if (status == RTEMS_SUCCESSFUL) // DUMB
562 if (status == RTEMS_SUCCESSFUL) // DUMB
543 {
563 {
544 status = rtems_task_create(
564 status = rtems_task_create(
545 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
565 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
546 RTEMS_DEFAULT_MODES,
566 RTEMS_DEFAULT_MODES,
547 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
567 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
548 );
568 );
549 }
569 }
550 if (status == RTEMS_SUCCESSFUL) // SCRUBBING TASK
570 if (status == RTEMS_SUCCESSFUL) // SCRUBBING TASK
551 {
571 {
552 status = rtems_task_create(
572 status = rtems_task_create(
553 Task_name[TASKID_SCRB], TASK_PRIORITY_SCRB, RTEMS_MINIMUM_STACK_SIZE,
573 Task_name[TASKID_SCRB], TASK_PRIORITY_SCRB, RTEMS_MINIMUM_STACK_SIZE,
554 RTEMS_DEFAULT_MODES,
574 RTEMS_DEFAULT_MODES,
555 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SCRB]
575 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SCRB]
556 );
576 );
557 }
577 }
558 if (status == RTEMS_SUCCESSFUL) // HOUS
578 if (status == RTEMS_SUCCESSFUL) // HOUS
559 {
579 {
560 status = rtems_task_create(
580 status = rtems_task_create(
561 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
581 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
562 RTEMS_DEFAULT_MODES,
582 RTEMS_DEFAULT_MODES,
563 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
583 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
564 );
584 );
565 }
585 }
566 if (status == RTEMS_SUCCESSFUL) // AVGV
586 if (status == RTEMS_SUCCESSFUL) // AVGV
567 {
587 {
568 status = rtems_task_create(
588 status = rtems_task_create(
569 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
589 Task_name[TASKID_AVGV], TASK_PRIORITY_AVGV, RTEMS_MINIMUM_STACK_SIZE,
570 RTEMS_DEFAULT_MODES,
590 RTEMS_DEFAULT_MODES,
571 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
591 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV]
572 );
592 );
573 }
593 }
574 if (status == RTEMS_SUCCESSFUL) // CALI
594 if (status == RTEMS_SUCCESSFUL) // CALI
575 {
595 {
576 status = rtems_task_create(
596 status = rtems_task_create(
577 Task_name[TASKID_CALI], TASK_PRIORITY_CALI, RTEMS_MINIMUM_STACK_SIZE,
597 Task_name[TASKID_CALI], TASK_PRIORITY_CALI, RTEMS_MINIMUM_STACK_SIZE,
578 RTEMS_DEFAULT_MODES,
598 RTEMS_DEFAULT_MODES,
579 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CALI]
599 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CALI]
580 );
600 );
581 }
601 }
582
602
583 return status;
603 return status;
584 }
604 }
585
605
586 int start_recv_send_tasks( void )
606 int start_recv_send_tasks( void )
587 {
607 {
588 rtems_status_code status;
608 rtems_status_code status;
589
609
590 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
610 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
591 if (status!=RTEMS_SUCCESSFUL) {
611 if (status!=RTEMS_SUCCESSFUL) {
592 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
612 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
593 }
613 }
594
614
595 if (status == RTEMS_SUCCESSFUL) // SEND
615 if (status == RTEMS_SUCCESSFUL) // SEND
596 {
616 {
597 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
617 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
598 if (status!=RTEMS_SUCCESSFUL) {
618 if (status!=RTEMS_SUCCESSFUL) {
599 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
619 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
600 }
620 }
601 }
621 }
602
622
603 return status;
623 return status;
604 }
624 }
605
625
606 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
626 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
607 {
627 {
608 /** This function starts all RTEMS tasks used in the software.
628 /** This function starts all RTEMS tasks used in the software.
609 *
629 *
610 * @return RTEMS directive status codes:
630 * @return RTEMS directive status codes:
611 * - RTEMS_SUCCESSFUL - ask started successfully
631 * - RTEMS_SUCCESSFUL - ask started successfully
612 * - RTEMS_INVALID_ADDRESS - invalid task entry point
632 * - RTEMS_INVALID_ADDRESS - invalid task entry point
613 * - RTEMS_INVALID_ID - invalid task id
633 * - RTEMS_INVALID_ID - invalid task id
614 * - RTEMS_INCORRECT_STATE - task not in the dormant state
634 * - RTEMS_INCORRECT_STATE - task not in the dormant state
615 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
635 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
616 *
636 *
617 */
637 */
618 // starts all the tasks fot eh flight software
638 // starts all the tasks fot eh flight software
619
639
620 rtems_status_code status;
640 rtems_status_code status;
621
641
622 //**********
642 //**********
623 // SPACEWIRE
643 // SPACEWIRE
624 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
644 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
625 if (status!=RTEMS_SUCCESSFUL) {
645 if (status!=RTEMS_SUCCESSFUL) {
626 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
646 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
627 }
647 }
628
648
629 if (status == RTEMS_SUCCESSFUL) // LINK
649 if (status == RTEMS_SUCCESSFUL) // LINK
630 {
650 {
631 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
651 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
632 if (status!=RTEMS_SUCCESSFUL) {
652 if (status!=RTEMS_SUCCESSFUL) {
633 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
653 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
634 }
654 }
635 }
655 }
636
656
637 if (status == RTEMS_SUCCESSFUL) // ACTN
657 if (status == RTEMS_SUCCESSFUL) // ACTN
638 {
658 {
639 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
659 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
640 if (status!=RTEMS_SUCCESSFUL) {
660 if (status!=RTEMS_SUCCESSFUL) {
641 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
661 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
642 }
662 }
643 }
663 }
644
664
645 //******************
665 //******************
646 // SPECTRAL MATRICES
666 // SPECTRAL MATRICES
647 if (status == RTEMS_SUCCESSFUL) // AVF0
667 if (status == RTEMS_SUCCESSFUL) // AVF0
648 {
668 {
649 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
669 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
650 if (status!=RTEMS_SUCCESSFUL) {
670 if (status!=RTEMS_SUCCESSFUL) {
651 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
671 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
652 }
672 }
653 }
673 }
654 if (status == RTEMS_SUCCESSFUL) // PRC0
674 if (status == RTEMS_SUCCESSFUL) // PRC0
655 {
675 {
656 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
676 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
657 if (status!=RTEMS_SUCCESSFUL) {
677 if (status!=RTEMS_SUCCESSFUL) {
658 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
678 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
659 }
679 }
660 }
680 }
661 if (status == RTEMS_SUCCESSFUL) // AVF1
681 if (status == RTEMS_SUCCESSFUL) // AVF1
662 {
682 {
663 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
683 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
664 if (status!=RTEMS_SUCCESSFUL) {
684 if (status!=RTEMS_SUCCESSFUL) {
665 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
685 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
666 }
686 }
667 }
687 }
668 if (status == RTEMS_SUCCESSFUL) // PRC1
688 if (status == RTEMS_SUCCESSFUL) // PRC1
669 {
689 {
670 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
690 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
671 if (status!=RTEMS_SUCCESSFUL) {
691 if (status!=RTEMS_SUCCESSFUL) {
672 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
692 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
673 }
693 }
674 }
694 }
675 if (status == RTEMS_SUCCESSFUL) // AVF2
695 if (status == RTEMS_SUCCESSFUL) // AVF2
676 {
696 {
677 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
697 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
678 if (status!=RTEMS_SUCCESSFUL) {
698 if (status!=RTEMS_SUCCESSFUL) {
679 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
699 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
680 }
700 }
681 }
701 }
682 if (status == RTEMS_SUCCESSFUL) // PRC2
702 if (status == RTEMS_SUCCESSFUL) // PRC2
683 {
703 {
684 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
704 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
685 if (status!=RTEMS_SUCCESSFUL) {
705 if (status!=RTEMS_SUCCESSFUL) {
686 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
706 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
687 }
707 }
688 }
708 }
689
709
690 //****************
710 //****************
691 // WAVEFORM PICKER
711 // WAVEFORM PICKER
692 if (status == RTEMS_SUCCESSFUL) // WFRM
712 if (status == RTEMS_SUCCESSFUL) // WFRM
693 {
713 {
694 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
714 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
695 if (status!=RTEMS_SUCCESSFUL) {
715 if (status!=RTEMS_SUCCESSFUL) {
696 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
716 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
697 }
717 }
698 }
718 }
699 if (status == RTEMS_SUCCESSFUL) // CWF3
719 if (status == RTEMS_SUCCESSFUL) // CWF3
700 {
720 {
701 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
721 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
702 if (status!=RTEMS_SUCCESSFUL) {
722 if (status!=RTEMS_SUCCESSFUL) {
703 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
723 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
704 }
724 }
705 }
725 }
706 if (status == RTEMS_SUCCESSFUL) // CWF2
726 if (status == RTEMS_SUCCESSFUL) // CWF2
707 {
727 {
708 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
728 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
709 if (status!=RTEMS_SUCCESSFUL) {
729 if (status!=RTEMS_SUCCESSFUL) {
710 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
730 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
711 }
731 }
712 }
732 }
713 if (status == RTEMS_SUCCESSFUL) // CWF1
733 if (status == RTEMS_SUCCESSFUL) // CWF1
714 {
734 {
715 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
735 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
716 if (status!=RTEMS_SUCCESSFUL) {
736 if (status!=RTEMS_SUCCESSFUL) {
717 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
737 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
718 }
738 }
719 }
739 }
720 if (status == RTEMS_SUCCESSFUL) // SWBD
740 if (status == RTEMS_SUCCESSFUL) // SWBD
721 {
741 {
722 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
742 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
723 if (status!=RTEMS_SUCCESSFUL) {
743 if (status!=RTEMS_SUCCESSFUL) {
724 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
744 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
725 }
745 }
726 }
746 }
727
747
728 //*****
748 //*****
729 // MISC
749 // MISC
730 if (status == RTEMS_SUCCESSFUL) // HOUS
750 if (status == RTEMS_SUCCESSFUL) // HOUS
731 {
751 {
732 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
752 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
733 if (status!=RTEMS_SUCCESSFUL) {
753 if (status!=RTEMS_SUCCESSFUL) {
734 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
754 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
735 }
755 }
736 }
756 }
737 if (status == RTEMS_SUCCESSFUL) // AVGV
757 if (status == RTEMS_SUCCESSFUL) // AVGV
738 {
758 {
739 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
759 status = rtems_task_start( Task_id[TASKID_AVGV], avgv_task, 1 );
740 if (status!=RTEMS_SUCCESSFUL) {
760 if (status!=RTEMS_SUCCESSFUL) {
741 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
761 BOOT_PRINTF("in INIT *** Error starting TASK_AVGV\n")
742 }
762 }
743 }
763 }
744 if (status == RTEMS_SUCCESSFUL) // DUMB
764 if (status == RTEMS_SUCCESSFUL) // DUMB
745 {
765 {
746 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
766 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
747 if (status!=RTEMS_SUCCESSFUL) {
767 if (status!=RTEMS_SUCCESSFUL) {
748 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
768 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
749 }
769 }
750 }
770 }
751 if (status == RTEMS_SUCCESSFUL) // SCRUBBING
771 if (status == RTEMS_SUCCESSFUL) // SCRUBBING
752 {
772 {
753 status = rtems_task_start( Task_id[TASKID_SCRB], scrubbing_task, 1 );
773 status = rtems_task_start( Task_id[TASKID_SCRB], scrubbing_task, 1 );
754 if (status!=RTEMS_SUCCESSFUL) {
774 if (status!=RTEMS_SUCCESSFUL) {
755 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
775 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
756 }
776 }
757 }
777 }
758 if (status == RTEMS_SUCCESSFUL) // LOAD
778 if (status == RTEMS_SUCCESSFUL) // LOAD
759 {
779 {
760 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
780 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
761 if (status!=RTEMS_SUCCESSFUL) {
781 if (status!=RTEMS_SUCCESSFUL) {
762 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
782 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
763 }
783 }
764 }
784 }
765 if (status == RTEMS_SUCCESSFUL) // CALI
785 if (status == RTEMS_SUCCESSFUL) // CALI
766 {
786 {
767 status = rtems_task_start( Task_id[TASKID_CALI], calibration_sweep_task, 1 );
787 status = rtems_task_start( Task_id[TASKID_CALI], calibration_sweep_task, 1 );
768 if (status!=RTEMS_SUCCESSFUL) {
788 if (status!=RTEMS_SUCCESSFUL) {
769 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
789 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
770 }
790 }
771 }
791 }
772
792
773 return status;
793 return status;
774 }
794 }
775
795
776 rtems_status_code create_message_queues( void ) // create the five message queues used in the software
796 rtems_status_code create_message_queues( void ) // create the five message queues used in the software
777 {
797 {
778 rtems_status_code status_recv;
798 rtems_status_code status_recv;
779 rtems_status_code status_send;
799 rtems_status_code status_send;
780 rtems_status_code status_q_p0;
800 rtems_status_code status_q_p0;
781 rtems_status_code status_q_p1;
801 rtems_status_code status_q_p1;
782 rtems_status_code status_q_p2;
802 rtems_status_code status_q_p2;
783 rtems_status_code ret;
803 rtems_status_code ret;
784 rtems_id queue_id;
804 rtems_id queue_id;
785
805
786 ret = RTEMS_SUCCESSFUL;
806 ret = RTEMS_SUCCESSFUL;
787 queue_id = RTEMS_ID_NONE;
807 queue_id = RTEMS_ID_NONE;
788
808
789 //****************************************
809 //****************************************
790 // create the queue for handling valid TCs
810 // create the queue for handling valid TCs
791 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
811 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
792 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
812 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
793 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
813 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
794 if ( status_recv != RTEMS_SUCCESSFUL ) {
814 if ( status_recv != RTEMS_SUCCESSFUL ) {
795 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
815 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
796 }
816 }
797
817
798 //************************************************
818 //************************************************
799 // create the queue for handling TM packet sending
819 // create the queue for handling TM packet sending
800 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
820 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
801 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
821 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
802 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
822 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
803 if ( status_send != RTEMS_SUCCESSFUL ) {
823 if ( status_send != RTEMS_SUCCESSFUL ) {
804 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
824 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
805 }
825 }
806
826
807 //*****************************************************************************
827 //*****************************************************************************
808 // create the queue for handling averaged spectral matrices for processing @ f0
828 // create the queue for handling averaged spectral matrices for processing @ f0
809 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
829 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
810 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
830 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
811 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
831 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
812 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
832 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
813 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
833 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
814 }
834 }
815
835
816 //*****************************************************************************
836 //*****************************************************************************
817 // create the queue for handling averaged spectral matrices for processing @ f1
837 // create the queue for handling averaged spectral matrices for processing @ f1
818 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
838 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
819 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
839 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
820 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
840 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
821 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
841 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
822 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
842 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
823 }
843 }
824
844
825 //*****************************************************************************
845 //*****************************************************************************
826 // create the queue for handling averaged spectral matrices for processing @ f2
846 // create the queue for handling averaged spectral matrices for processing @ f2
827 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
847 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
828 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
848 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
829 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
849 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
830 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
850 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
831 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
851 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
832 }
852 }
833
853
834 if ( status_recv != RTEMS_SUCCESSFUL )
854 if ( status_recv != RTEMS_SUCCESSFUL )
835 {
855 {
836 ret = status_recv;
856 ret = status_recv;
837 }
857 }
838 else if( status_send != RTEMS_SUCCESSFUL )
858 else if( status_send != RTEMS_SUCCESSFUL )
839 {
859 {
840 ret = status_send;
860 ret = status_send;
841 }
861 }
842 else if( status_q_p0 != RTEMS_SUCCESSFUL )
862 else if( status_q_p0 != RTEMS_SUCCESSFUL )
843 {
863 {
844 ret = status_q_p0;
864 ret = status_q_p0;
845 }
865 }
846 else if( status_q_p1 != RTEMS_SUCCESSFUL )
866 else if( status_q_p1 != RTEMS_SUCCESSFUL )
847 {
867 {
848 ret = status_q_p1;
868 ret = status_q_p1;
849 }
869 }
850 else
870 else
851 {
871 {
852 ret = status_q_p2;
872 ret = status_q_p2;
853 }
873 }
854
874
855 return ret;
875 return ret;
856 }
876 }
857
877
858 rtems_status_code create_timecode_timer( void )
878 rtems_status_code create_timecode_timer( void )
859 {
879 {
860 rtems_status_code status;
880 rtems_status_code status;
861
881
862 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
882 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
863
883
864 if ( status != RTEMS_SUCCESSFUL )
884 if ( status != RTEMS_SUCCESSFUL )
865 {
885 {
866 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
886 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
867 }
887 }
868 else
888 else
869 {
889 {
870 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
890 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
871 }
891 }
872
892
873 return status;
893 return status;
874 }
894 }
875
895
876 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
896 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
877 {
897 {
878 rtems_status_code status;
898 rtems_status_code status;
879 rtems_name queue_name;
899 rtems_name queue_name;
880
900
881 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
901 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
882
902
883 status = rtems_message_queue_ident( queue_name, 0, queue_id );
903 status = rtems_message_queue_ident( queue_name, 0, queue_id );
884
904
885 return status;
905 return status;
886 }
906 }
887
907
888 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
908 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
889 {
909 {
890 rtems_status_code status;
910 rtems_status_code status;
891 rtems_name queue_name;
911 rtems_name queue_name;
892
912
893 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
913 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
894
914
895 status = rtems_message_queue_ident( queue_name, 0, queue_id );
915 status = rtems_message_queue_ident( queue_name, 0, queue_id );
896
916
897 return status;
917 return status;
898 }
918 }
899
919
900 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
920 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
901 {
921 {
902 rtems_status_code status;
922 rtems_status_code status;
903 rtems_name queue_name;
923 rtems_name queue_name;
904
924
905 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
925 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
906
926
907 status = rtems_message_queue_ident( queue_name, 0, queue_id );
927 status = rtems_message_queue_ident( queue_name, 0, queue_id );
908
928
909 return status;
929 return status;
910 }
930 }
911
931
912 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
932 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
913 {
933 {
914 rtems_status_code status;
934 rtems_status_code status;
915 rtems_name queue_name;
935 rtems_name queue_name;
916
936
917 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
937 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
918
938
919 status = rtems_message_queue_ident( queue_name, 0, queue_id );
939 status = rtems_message_queue_ident( queue_name, 0, queue_id );
920
940
921 return status;
941 return status;
922 }
942 }
923
943
924 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
944 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
925 {
945 {
926 rtems_status_code status;
946 rtems_status_code status;
927 rtems_name queue_name;
947 rtems_name queue_name;
928
948
929 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
949 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
930
950
931 status = rtems_message_queue_ident( queue_name, 0, queue_id );
951 status = rtems_message_queue_ident( queue_name, 0, queue_id );
932
952
933 return status;
953 return status;
934 }
954 }
935
955
936 /**
956 /**
937 * @brief update_queue_max_count returns max(fifo_size_max, pending_messages + 1)
957 * @brief update_queue_max_count returns max(fifo_size_max, pending_messages + 1)
938 * @param queue_id
958 * @param queue_id
939 * @param fifo_size_max
959 * @param fifo_size_max
940 */
960 */
941 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
961 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
942 {
962 {
943 u_int32_t count;
963 u_int32_t count;
944 rtems_status_code status;
964 rtems_status_code status;
945
965
946 count = 0;
966 count = 0;
947
967
948 status = rtems_message_queue_get_number_pending( queue_id, &count );
968 status = rtems_message_queue_get_number_pending( queue_id, &count );
949
969
950 count = count + 1;
970 count = count + 1;
951
971
952 if (status != RTEMS_SUCCESSFUL)
972 if (status != RTEMS_SUCCESSFUL)
953 {
973 {
954 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
974 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
955 }
975 }
956 else
976 else
957 {
977 {
958 if (count > *fifo_size_max)
978 if (count > *fifo_size_max)
959 {
979 {
960 *fifo_size_max = count;
980 *fifo_size_max = count;
961 }
981 }
962 }
982 }
963 }
983 }
964
984
965 /**
985 /**
966 * @brief init_ring initializes given ring buffer
986 * @brief init_ring initializes given ring buffer
967 * @param ring array of nodes to initialize
987 * @param ring array of nodes to initialize
968 * @param nbNodes number of node in the ring buffer
988 * @param nbNodes number of node in the ring buffer
969 * @param buffer memory space given to the ring buffer
989 * @param buffer memory space given to the ring buffer
970 * @param bufferSize size of the whole ring buffer memory space
990 * @param bufferSize size of the whole ring buffer memory space
971 *
991 *
972 * @details This function creates a circular buffer from a given number of nodes and a given memory space. It first sets all nodes attributes to thier defaults values
992 * @details This function creates a circular buffer from a given number of nodes and a given memory space. It first sets all nodes attributes to thier defaults values
973 * and associates a portion of the given memory space with each node. Then it connects each nodes to build a circular buffer.
993 * and associates a portion of the given memory space with each node. Then it connects each nodes to build a circular buffer.
974 *
994 *
975 * Each node capacity will be bufferSize/nbNodes.
995 * Each node capacity will be bufferSize/nbNodes.
976 *
996 *
977 * https://en.wikipedia.org/wiki/Circular_buffer
997 * https://en.wikipedia.org/wiki/Circular_buffer
978 */
998 */
979 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
999 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
980 {
1000 {
981 unsigned char i;
1001 unsigned char i;
982
1002
983 //***************
1003 //***************
984 // BUFFER ADDRESS
1004 // BUFFER ADDRESS
985 for(i=0; i<nbNodes; i++)
1005 for(i=0; i<nbNodes; i++)
986 {
1006 {
987 ring[i].coarseTime = INT32_ALL_F;
1007 ring[i].coarseTime = INT32_ALL_F;
988 ring[i].fineTime = INT32_ALL_F;
1008 ring[i].fineTime = INT32_ALL_F;
989 ring[i].sid = INIT_CHAR;
1009 ring[i].sid = INIT_CHAR;
990 ring[i].status = INIT_CHAR;
1010 ring[i].status = INIT_CHAR;
991 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
1011 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
992 }
1012 }
993
1013
994 //*****
1014 //*****
995 // NEXT
1015 // NEXT
996 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
1016 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
997 for(i=0; i<nbNodes-1; i++)
1017 for(i=0; i<nbNodes-1; i++)
998 {
1018 {
999 ring[i].next = (ring_node*) &ring[ i + 1 ];
1019 ring[i].next = (ring_node*) &ring[ i + 1 ];
1000 }
1020 }
1001
1021
1002 //*********
1022 //*********
1003 // PREVIOUS
1023 // PREVIOUS
1004 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
1024 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
1005 for(i=1; i<nbNodes; i++)
1025 for(i=1; i<nbNodes; i++)
1006 {
1026 {
1007 ring[i].previous = (ring_node*) &ring[ i - 1 ];
1027 ring[i].previous = (ring_node*) &ring[ i - 1 ];
1008 }
1028 }
1009 }
1029 }
@@ -1,1054 +1,1109
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** General usage functions and RTEMS tasks.
25 /** General usage functions and RTEMS tasks.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 */
30 */
7
31
8 #include "fsw_misc.h"
32 #include "fsw_misc.h"
9
33
10 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
34 int16_t hk_lfr_sc_v_f3_as_int16 = 0;
11 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
35 int16_t hk_lfr_sc_e1_f3_as_int16 = 0;
12 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
36 int16_t hk_lfr_sc_e2_f3_as_int16 = 0;
13
37
14 void timer_configure(unsigned char timer, unsigned int clock_divider,
38 void timer_configure(unsigned char timer, unsigned int clock_divider,
15 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
39 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
16 {
40 {
17 /** This function configures a GPTIMER timer instantiated in the VHDL design.
41 /** This function configures a GPTIMER timer instantiated in the VHDL design.
18 *
42 *
19 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
20 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
21 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
45 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
22 * @param interrupt_level is the interrupt level that the timer drives.
46 * @param interrupt_level is the interrupt level that the timer drives.
23 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
47 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
24 *
48 *
25 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
49 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
26 *
50 *
27 */
51 */
28
52
29 rtems_status_code status;
53 rtems_status_code status;
30 rtems_isr_entry old_isr_handler;
54 rtems_isr_entry old_isr_handler;
31
55
32 old_isr_handler = NULL;
56 old_isr_handler = NULL;
33
57
34 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
58 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
35
59
36 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
60 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
37 if (status!=RTEMS_SUCCESSFUL)
61 if (status!=RTEMS_SUCCESSFUL)
38 {
62 {
39 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
63 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
40 }
64 }
41
65
42 timer_set_clock_divider( timer, clock_divider);
66 timer_set_clock_divider( timer, clock_divider);
43 }
67 }
44
68
45 void timer_start(unsigned char timer)
69 void timer_start(unsigned char timer)
46 {
70 {
47 /** This function starts a GPTIMER timer.
71 /** This function starts a GPTIMER timer.
48 *
72 *
49 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
50 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
51 *
75 *
52 */
76 */
53
77
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
78 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
55 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
79 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
56 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
80 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
57 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
81 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
58 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
82 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
59 }
83 }
60
84
61 void timer_stop(unsigned char timer)
85 void timer_stop(unsigned char timer)
62 {
86 {
63 /** This function stops a GPTIMER timer.
87 /** This function stops a GPTIMER timer.
64 *
88 *
65 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
89 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
66 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
90 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
67 *
91 *
68 */
92 */
69
93
70 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
94 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
71 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
95 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
72 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
96 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
73 }
97 }
74
98
75 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
99 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
76 {
100 {
77 /** This function sets the clock divider of a GPTIMER timer.
101 /** This function sets the clock divider of a GPTIMER timer.
78 *
102 *
79 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
103 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
80 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
104 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
81 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
105 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
82 *
106 *
83 */
107 */
84
108
85 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
109 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
86 }
110 }
87
111
88 // WATCHDOG
112 // WATCHDOG, this ISR should never be triggered.
89
113
90 rtems_isr watchdog_isr( rtems_vector_number vector )
114 rtems_isr watchdog_isr( rtems_vector_number vector )
91 {
115 {
92 rtems_status_code status_code;
116 rtems_status_code status_code;
93
117
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
118 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
95
119
96 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
120 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
97
121
98 exit(0);
122 exit(0);
99 }
123 }
100
124
101 void watchdog_configure(void)
125 void watchdog_configure(void)
102 {
126 {
103 /** This function configure the watchdog.
127 /** This function configure the watchdog.
104 *
128 *
105 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
129 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
106 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
130 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
107 *
131 *
108 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
132 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
109 *
133 *
110 */
134 */
111
135
112 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
136 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
113
137
114 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
138 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
115
139
116 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
140 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 }
141 }
118
142
119 void watchdog_stop(void)
143 void watchdog_stop(void)
120 {
144 {
121 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
145 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
122 timer_stop( TIMER_WATCHDOG );
146 timer_stop( TIMER_WATCHDOG );
123 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
147 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
124 }
148 }
125
149
126 void watchdog_reload(void)
150 void watchdog_reload(void)
127 {
151 {
128 /** This function reloads the watchdog timer counter with the timer reload value.
152 /** This function reloads the watchdog timer counter with the timer reload value.
129 *
153 *
130 * @param void
154 * @param void
131 *
155 *
132 * @return void
156 * @return void
133 *
157 *
134 */
158 */
135
159
136 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
160 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
137 }
161 }
138
162
139 void watchdog_start(void)
163 void watchdog_start(void)
140 {
164 {
141 /** This function starts the watchdog timer.
165 /** This function starts the watchdog timer.
142 *
166 *
143 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
167 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
144 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
168 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
145 *
169 *
146 */
170 */
147
171
148 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
172 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
149
173
150 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
174 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
151 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
175 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
152 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
176 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
153 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
177 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
154
178
155 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
179 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
156
180
157 }
181 }
158
182
159 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
183 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
160 {
184 {
161 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
185 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
162
186
163 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
187 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
164
188
165 return 0;
189 return 0;
166 }
190 }
167
191
168 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
192 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
169 {
193 {
170 /** This function sets the scaler reload register of the apbuart module
194 /** This function sets the scaler reload register of the apbuart module
171 *
195 *
172 * @param regs is the address of the apbuart registers in memory
196 * @param regs is the address of the apbuart registers in memory
173 * @param value is the value that will be stored in the scaler register
197 * @param value is the value that will be stored in the scaler register
174 *
198 *
175 * The value shall be set by the software to get data on the serial interface.
199 * The value shall be set by the software to get data on the serial interface.
176 *
200 *
177 */
201 */
178
202
179 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
203 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
180
204
181 apbuart_regs->scaler = value;
205 apbuart_regs->scaler = value;
182
206
183 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
207 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
184 }
208 }
185
209
186 //************
210 /**
187 // RTEMS TASKS
211 * @brief load_task starts and keeps the watchdog alive.
212 * @param argument
213 * @return
214 */
188
215
189 rtems_task load_task(rtems_task_argument argument)
216 rtems_task load_task(rtems_task_argument argument)
190 {
217 {
191 BOOT_PRINTF("in LOAD *** \n")
218 BOOT_PRINTF("in LOAD *** \n")
192
219
193 rtems_status_code status;
220 rtems_status_code status;
194 unsigned int i;
221 unsigned int i;
195 unsigned int j;
222 unsigned int j;
196 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
223 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
197 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
224 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
198
225
199 watchdog_period_id = RTEMS_ID_NONE;
226 watchdog_period_id = RTEMS_ID_NONE;
200
227
201 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
228 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
202
229
203 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
230 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
204 if( status != RTEMS_SUCCESSFUL ) {
231 if( status != RTEMS_SUCCESSFUL ) {
205 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
232 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
206 }
233 }
207
234
208 i = 0;
235 i = 0;
209 j = 0;
236 j = 0;
210
237
211 watchdog_configure();
238 watchdog_configure();
212
239
213 watchdog_start();
240 watchdog_start();
214
241
215 set_sy_lfr_watchdog_enabled( true );
242 set_sy_lfr_watchdog_enabled( true );
216
243
217 while(1){
244 while(1){
218 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
245 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
219 watchdog_reload();
246 watchdog_reload();
220 i = i + 1;
247 i = i + 1;
221 if ( i == WATCHDOG_LOOP_PRINTF )
248 if ( i == WATCHDOG_LOOP_PRINTF )
222 {
249 {
223 i = 0;
250 i = 0;
224 j = j + 1;
251 j = j + 1;
225 PRINTF1("%d\n", j)
252 PRINTF1("%d\n", j)
226 }
253 }
227 #ifdef DEBUG_WATCHDOG
254 #ifdef DEBUG_WATCHDOG
228 if (j == WATCHDOG_LOOP_DEBUG )
255 if (j == WATCHDOG_LOOP_DEBUG )
229 {
256 {
230 status = rtems_task_delete(RTEMS_SELF);
257 status = rtems_task_delete(RTEMS_SELF);
231 }
258 }
232 #endif
259 #endif
233 }
260 }
234 }
261 }
235
262
263 /**
264 * @brief hous_task produces and sends HK each seconds
265 * @param argument
266 * @return
267 */
236 rtems_task hous_task(rtems_task_argument argument)
268 rtems_task hous_task(rtems_task_argument argument)
237 {
269 {
238 rtems_status_code status;
270 rtems_status_code status;
239 rtems_status_code spare_status;
271 rtems_status_code spare_status;
240 rtems_id queue_id;
272 rtems_id queue_id;
241 rtems_rate_monotonic_period_status period_status;
273 rtems_rate_monotonic_period_status period_status;
242 bool isSynchronized;
274 bool isSynchronized;
243
275
244 queue_id = RTEMS_ID_NONE;
276 queue_id = RTEMS_ID_NONE;
245 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
277 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
246 isSynchronized = false;
278 isSynchronized = false;
247
279
248 status = get_message_queue_id_send( &queue_id );
280 status = get_message_queue_id_send( &queue_id );
249 if (status != RTEMS_SUCCESSFUL)
281 if (status != RTEMS_SUCCESSFUL)
250 {
282 {
251 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
283 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
252 }
284 }
253
285
254 BOOT_PRINTF("in HOUS ***\n");
286 BOOT_PRINTF("in HOUS ***\n");
255
287
256 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
288 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
257 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
289 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
258 if( status != RTEMS_SUCCESSFUL ) {
290 if( status != RTEMS_SUCCESSFUL ) {
259 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
291 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
260 }
292 }
261 }
293 }
262
294
263 status = rtems_rate_monotonic_cancel(HK_id);
295 status = rtems_rate_monotonic_cancel(HK_id);
264 if( status != RTEMS_SUCCESSFUL ) {
296 if( status != RTEMS_SUCCESSFUL ) {
265 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
297 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
266 }
298 }
267 else {
299 else {
268 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
300 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
269 }
301 }
270
302
271 // startup phase
303 // startup phase
272 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
304 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
273 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
305 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
274 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
306 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
275 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
307 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
276 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
308 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
277 {
309 {
278 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
310 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
279 {
311 {
280 isSynchronized = true;
312 isSynchronized = true;
281 }
313 }
282 else
314 else
283 {
315 {
284 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
316 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
285
317
286 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
318 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
287 }
319 }
288 }
320 }
289 status = rtems_rate_monotonic_cancel(HK_id);
321 status = rtems_rate_monotonic_cancel(HK_id);
290 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
322 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
291
323
292 set_hk_lfr_reset_cause( POWER_ON );
324 set_hk_lfr_reset_cause( POWER_ON );
293
325
294 while(1){ // launch the rate monotonic task
326 while(1){ // launch the rate monotonic task
295 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
327 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
296 if ( status != RTEMS_SUCCESSFUL ) {
328 if ( status != RTEMS_SUCCESSFUL ) {
297 PRINTF1( "in HOUS *** ERR period: %d\n", status);
329 PRINTF1( "in HOUS *** ERR period: %d\n", status);
298 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
330 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
299 }
331 }
300 else {
332 else {
301 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
333 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
302 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
334 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
303 increment_seq_counter( &sequenceCounterHK );
335 increment_seq_counter( &sequenceCounterHK );
304
336
305 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
337 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
306 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
338 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
307 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
339 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
308 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
340 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
309 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
341 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
310 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
342 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
311
343
312 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
344 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
313
345
314 spacewire_read_statistics();
346 spacewire_read_statistics();
315
347
316 update_hk_with_grspw_stats();
348 update_hk_with_grspw_stats();
317
349
318 set_hk_lfr_time_not_synchro();
350 set_hk_lfr_time_not_synchro();
319
351
320 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
352 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
321 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
353 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
322 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
354 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
323 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
355 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
324 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
356 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
325
357
326 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
358 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
327 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
359 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
328 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
360 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
329 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
361 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
330 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
362 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
331
363
332 hk_lfr_le_me_he_update();
364 hk_lfr_le_me_he_update();
333
365
334 // SEND PACKET
366 // SEND PACKET
335 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
367 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
336 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
368 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
337 if (status != RTEMS_SUCCESSFUL) {
369 if (status != RTEMS_SUCCESSFUL) {
338 PRINTF1("in HOUS *** ERR send: %d\n", status)
370 PRINTF1("in HOUS *** ERR send: %d\n", status)
339 }
371 }
340 }
372 }
341 }
373 }
342
374
343 PRINTF("in HOUS *** deleting task\n")
375 PRINTF("in HOUS *** deleting task\n")
344
376
345 status = rtems_task_delete( RTEMS_SELF ); // should not return
377 status = rtems_task_delete( RTEMS_SELF ); // should not return
346
378
347 return;
379 return;
348 }
380 }
349
381
382 /**
383 * @brief filter is a Direct-Form-II filter implementation, mostly used to filter electric field for HK
384 * @param x, new sample
385 * @param ctx, filter context, used to store previous input and output samples
386 * @return a new filtered sample
387 */
350 int filter( int x, filter_ctx* ctx )
388 int filter( int x, filter_ctx* ctx )
351 {
389 {
352 static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} };
390 static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} };
353 static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} };
391 static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} };
354 static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2};
392 static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2};
355 static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2};
393 static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2};
356
394
357 int_fast32_t W;
395 int_fast32_t W;
358 int i;
396 int i;
359
397
360 W = INIT_INT;
398 W = INIT_INT;
361 i = INIT_INT;
399 i = INIT_INT;
362
400
363 //Direct-Form-II
401 //Direct-Form-II
364 for ( i = 0; i < NB_COEFFS; i++ )
402 for ( i = 0; i < NB_COEFFS; i++ )
365 {
403 {
366 x = x << a_gain[i];
404 x = x << a_gain[i];
367 W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] )
405 W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] )
368 - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i];
406 - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i];
369 x = ( b[i][COEFF0] * W )
407 x = ( b[i][COEFF0] * W )
370 + ( b[i][COEFF1] * ctx->W[i][COEFF0] )
408 + ( b[i][COEFF1] * ctx->W[i][COEFF0] )
371 + ( b[i][COEFF2] * ctx->W[i][COEFF1] );
409 + ( b[i][COEFF2] * ctx->W[i][COEFF1] );
372 x = x >> b_gain[i];
410 x = x >> b_gain[i];
373 ctx->W[i][1] = ctx->W[i][0];
411 ctx->W[i][1] = ctx->W[i][0];
374 ctx->W[i][0] = W;
412 ctx->W[i][0] = W;
375 }
413 }
376 return x;
414 return x;
377 }
415 }
378
416
417 /**
418 * @brief avgv_task pruduces HK rate elctrical field from F3 data
419 * @param argument
420 * @return
421 */
379 rtems_task avgv_task(rtems_task_argument argument)
422 rtems_task avgv_task(rtems_task_argument argument)
380 {
423 {
381 #define MOVING_AVERAGE 16
424 #define MOVING_AVERAGE 16
382 rtems_status_code status;
425 rtems_status_code status;
383 static int32_t v[MOVING_AVERAGE] = {0};
426 static int32_t v[MOVING_AVERAGE] = {0};
384 static int32_t e1[MOVING_AVERAGE] = {0};
427 static int32_t e1[MOVING_AVERAGE] = {0};
385 static int32_t e2[MOVING_AVERAGE] = {0};
428 static int32_t e2[MOVING_AVERAGE] = {0};
386 static int old_v = 0;
429 static int old_v = 0;
387 static int old_e1 = 0;
430 static int old_e1 = 0;
388 static int old_e2 = 0;
431 static int old_e2 = 0;
389 int32_t current_v;
432 int32_t current_v;
390 int32_t current_e1;
433 int32_t current_e1;
391 int32_t current_e2;
434 int32_t current_e2;
392 int32_t average_v;
435 int32_t average_v;
393 int32_t average_e1;
436 int32_t average_e1;
394 int32_t average_e2;
437 int32_t average_e2;
395 int32_t newValue_v;
438 int32_t newValue_v;
396 int32_t newValue_e1;
439 int32_t newValue_e1;
397 int32_t newValue_e2;
440 int32_t newValue_e2;
398 unsigned char k;
441 unsigned char k;
399 unsigned char indexOfOldValue;
442 unsigned char indexOfOldValue;
400
443
401 static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } };
444 static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } };
402 static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
445 static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
403 static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
446 static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } };
404
447
405 BOOT_PRINTF("in AVGV ***\n");
448 BOOT_PRINTF("in AVGV ***\n");
406
449
407 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) {
450 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) {
408 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
451 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
409 if( status != RTEMS_SUCCESSFUL ) {
452 if( status != RTEMS_SUCCESSFUL ) {
410 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
453 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
411 }
454 }
412 }
455 }
413
456
414 status = rtems_rate_monotonic_cancel(AVGV_id);
457 status = rtems_rate_monotonic_cancel(AVGV_id);
415 if( status != RTEMS_SUCCESSFUL ) {
458 if( status != RTEMS_SUCCESSFUL ) {
416 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
459 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
417 }
460 }
418 else {
461 else {
419 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
462 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
420 }
463 }
421
464
422 // initialize values
465 // initialize values
423 indexOfOldValue = MOVING_AVERAGE - 1;
466 indexOfOldValue = MOVING_AVERAGE - 1;
424 current_v = 0;
467 current_v = 0;
425 current_e1 = 0;
468 current_e1 = 0;
426 current_e2 = 0;
469 current_e2 = 0;
427 average_v = 0;
470 average_v = 0;
428 average_e1 = 0;
471 average_e1 = 0;
429 average_e2 = 0;
472 average_e2 = 0;
430 newValue_v = 0;
473 newValue_v = 0;
431 newValue_e1 = 0;
474 newValue_e1 = 0;
432 newValue_e2 = 0;
475 newValue_e2 = 0;
433
476
434 k = INIT_CHAR;
477 k = INIT_CHAR;
435
478
436 while(1)
479 while(1)
437 { // launch the rate monotonic task
480 { // launch the rate monotonic task
438 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
481 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
439 if ( status != RTEMS_SUCCESSFUL )
482 if ( status != RTEMS_SUCCESSFUL )
440 {
483 {
441 PRINTF1( "in AVGV *** ERR period: %d\n", status);
484 PRINTF1( "in AVGV *** ERR period: %d\n", status);
442 }
485 }
443 else
486 else
444 {
487 {
445 current_v = waveform_picker_regs->v;
488 current_v = waveform_picker_regs->v;
446 current_e1 = waveform_picker_regs->e1;
489 current_e1 = waveform_picker_regs->e1;
447 current_e2 = waveform_picker_regs->e2;
490 current_e2 = waveform_picker_regs->e2;
448 if ( (current_v != old_v)
491 if ( (current_v != old_v)
449 || (current_e1 != old_e1)
492 || (current_e1 != old_e1)
450 || (current_e2 != old_e2))
493 || (current_e2 != old_e2))
451 {
494 {
452 average_v = filter( current_v, &ctx_v );
495 average_v = filter( current_v, &ctx_v );
453 average_e1 = filter( current_e1, &ctx_e1 );
496 average_e1 = filter( current_e1, &ctx_e1 );
454 average_e2 = filter( current_e2, &ctx_e2 );
497 average_e2 = filter( current_e2, &ctx_e2 );
455
498
456 //update int16 values
499 //update int16 values
457 hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v;
500 hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v;
458 hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1;
501 hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1;
459 hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2;
502 hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2;
460 }
503 }
461 old_v = current_v;
504 old_v = current_v;
462 old_e1 = current_e1;
505 old_e1 = current_e1;
463 old_e2 = current_e2;
506 old_e2 = current_e2;
464 }
507 }
465 }
508 }
466
509
467 PRINTF("in AVGV *** deleting task\n");
510 PRINTF("in AVGV *** deleting task\n");
468
511
469 status = rtems_task_delete( RTEMS_SELF ); // should not return
512 status = rtems_task_delete( RTEMS_SELF ); // should not return
470
513
471 return;
514 return;
472 }
515 }
473
516
474 rtems_task dumb_task( rtems_task_argument unused )
517 rtems_task dumb_task( rtems_task_argument unused )
475 {
518 {
476 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
519 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
477 *
520 *
478 * @param unused is the starting argument of the RTEMS task
521 * @param unused is the starting argument of the RTEMS task
479 *
522 *
480 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
523 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
481 *
524 *
482 */
525 */
483
526
484 unsigned int i;
527 unsigned int i;
485 unsigned int intEventOut;
528 unsigned int intEventOut;
486 unsigned int coarse_time = 0;
529 unsigned int coarse_time = 0;
487 unsigned int fine_time = 0;
530 unsigned int fine_time = 0;
488 rtems_event_set event_out;
531 rtems_event_set event_out;
489
532
490 event_out = EVENT_SETS_NONE_PENDING;
533 event_out = EVENT_SETS_NONE_PENDING;
491
534
492 BOOT_PRINTF("in DUMB *** \n")
535 BOOT_PRINTF("in DUMB *** \n")
493
536
494 while(1){
537 while(1){
495 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
538 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
496 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
539 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
497 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
540 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
498 | RTEMS_EVENT_14,
541 | RTEMS_EVENT_14,
499 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
542 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
500 intEventOut = (unsigned int) event_out;
543 intEventOut = (unsigned int) event_out;
501 for ( i=0; i<NB_RTEMS_EVENTS; i++)
544 for ( i=0; i<NB_RTEMS_EVENTS; i++)
502 {
545 {
503 if ( ((intEventOut >> i) & 1) != 0)
546 if ( ((intEventOut >> i) & 1) != 0)
504 {
547 {
505 coarse_time = time_management_regs->coarse_time;
548 coarse_time = time_management_regs->coarse_time;
506 fine_time = time_management_regs->fine_time;
549 fine_time = time_management_regs->fine_time;
507 if (i==EVENT_12)
550 if (i==EVENT_12)
508 {
551 {
509 PRINTF1("%s\n", DUMB_MESSAGE_12)
552 PRINTF1("%s\n", DUMB_MESSAGE_12)
510 }
553 }
511 if (i==EVENT_13)
554 if (i==EVENT_13)
512 {
555 {
513 PRINTF1("%s\n", DUMB_MESSAGE_13)
556 PRINTF1("%s\n", DUMB_MESSAGE_13)
514 }
557 }
515 if (i==EVENT_14)
558 if (i==EVENT_14)
516 {
559 {
517 PRINTF1("%s\n", DUMB_MESSAGE_1)
560 PRINTF1("%s\n", DUMB_MESSAGE_1)
518 }
561 }
519 }
562 }
520 }
563 }
521 }
564 }
522 }
565 }
523
566
524 rtems_task scrubbing_task( rtems_task_argument unused )
567 rtems_task scrubbing_task( rtems_task_argument unused )
525 {
568 {
526 /** This RTEMS taks is used to avoid entering IDLE task and also scrub memory to increase scubbing frequency.
569 /** This RTEMS taks is used to avoid entering IDLE task and also scrub memory to increase scubbing frequency.
527 *
570 *
528 * @param unused is the starting argument of the RTEMS task
571 * @param unused is the starting argument of the RTEMS task
529 *
572 *
530 * The scrubbing reads continuously memory when no other tasks are ready.
573 * The scrubbing reads continuously memory when no other tasks are ready.
531 *
574 *
532 */
575 */
533
576
534 BOOT_PRINTF("in SCRUBBING *** \n");
577 BOOT_PRINTF("in SCRUBBING *** \n");
535 volatile int i=0;
578 volatile int i=0;
536 volatile float valuef = 1.;
579 volatile float valuef = 1.;
537 volatile uint32_t* RAM=(uint32_t*)0x40000000;
580 volatile uint32_t* RAM=(uint32_t*)0x40000000;
538 volatile uint32_t value;
581 volatile uint32_t value;
539 #ifdef ENABLE_SCRUBBING_COUNTER
582 #ifdef ENABLE_SCRUBBING_COUNTER
540 housekeeping_packet.lfr_fpga_version[BYTE_0] = 0;
583 housekeeping_packet.lfr_fpga_version[BYTE_0] = 0;
541 #endif
584 #endif
542 while(1){
585 while(1){
543 i=(i+1)%(1024*1024);
586 i=(i+1)%(1024*1024);
544 valuef += 10.f*(float)RAM[i];
587 valuef += 10.f*(float)RAM[i];
545 #ifdef ENABLE_SCRUBBING_COUNTER
588 #ifdef ENABLE_SCRUBBING_COUNTER
546 if(i==0)
589 if(i==0)
547 {
590 {
548 housekeeping_packet.lfr_fpga_version[BYTE_0] += 1;
591 housekeeping_packet.lfr_fpga_version[BYTE_0] += 1;
549 }
592 }
550 #endif
593 #endif
551 }
594 }
552 }
595 }
553
596
554 rtems_task calibration_sweep_task( rtems_task_argument unused )
597 rtems_task calibration_sweep_task( rtems_task_argument unused )
555 {
598 {
556 /** This RTEMS taks is used to change calibration signal smapling frequency between snapshots.
599 /** This RTEMS taks is used to change calibration signal smapling frequency between snapshots.
557 *
600 *
558 * @param unused is the starting argument of the RTEMS task
601 * @param unused is the starting argument of the RTEMS task
559 *
602 *
560 * If calibration is enabled, this task will divide by two the calibration signal smapling frequency between snapshots.
603 * If calibration is enabled, this task will divide by two the calibration signal smapling frequency between snapshots.
561 * When minimum sampling frequency is reach it will jump to maximum sampling frequency to loop indefinitely.
604 * When minimum sampling frequency is reach it will jump to maximum sampling frequency to loop indefinitely.
562 *
605 *
563 */
606 */
564 rtems_event_set event_out;
607 rtems_event_set event_out;
565 BOOT_PRINTF("in calibration sweep *** \n");
608 BOOT_PRINTF("in calibration sweep *** \n");
566 rtems_interval ticks_per_seconds = rtems_clock_get_ticks_per_second();
609 rtems_interval ticks_per_seconds = rtems_clock_get_ticks_per_second();
567 while(1){
610 while(1){
568 // Waiting for next F0 snapshot
611 // Waiting for next F0 snapshot
569 rtems_event_receive(RTEMS_EVENT_CAL_SWEEP_WAKE, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
612 rtems_event_receive(RTEMS_EVENT_CAL_SWEEP_WAKE, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
570 if(time_management_regs->calDACCtrl & BIT_CAL_ENABLE)
613 if(time_management_regs->calDACCtrl & BIT_CAL_ENABLE)
571 {
614 {
572 unsigned int delta_snapshot;
615 unsigned int delta_snapshot;
573 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
616 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
574 + parameter_dump_packet.sy_lfr_n_swf_p[1];
617 + parameter_dump_packet.sy_lfr_n_swf_p[1];
575 // We are woken almost in the center of a snapshot -> let's wait for sy_lfr_n_swf_p / 2
618 // We are woken almost in the center of a snapshot -> let's wait for sy_lfr_n_swf_p / 2
576 rtems_task_wake_after( ticks_per_seconds * delta_snapshot / 2);
619 rtems_task_wake_after( ticks_per_seconds * delta_snapshot / 2);
577 if(time_management_regs->calDivisor >= CAL_F_DIVISOR_MAX){
620 if(time_management_regs->calDivisor >= CAL_F_DIVISOR_MAX){
578 time_management_regs->calDivisor = CAL_F_DIVISOR_MIN;
621 time_management_regs->calDivisor = CAL_F_DIVISOR_MIN;
579 }
622 }
580 else{
623 else{
581 time_management_regs->calDivisor *= 2;
624 time_management_regs->calDivisor *= 2;
582 }
625 }
583 }
626 }
584
627
585
628
586
629
587 }
630 }
588
631
589 }
632 }
590
633
591
634
592 //*****************************
635 //*****************************
593 // init housekeeping parameters
636 // init housekeeping parameters
594
637
595 void init_housekeeping_parameters( void )
638 void init_housekeeping_parameters( void )
596 {
639 {
597 /** This function initialize the housekeeping_packet global variable with default values.
640 /** This function initialize the housekeeping_packet global variable with default values.
598 *
641 *
599 */
642 */
600
643
601 unsigned int i = 0;
644 unsigned int i = 0;
602 unsigned char *parameters;
645 unsigned char *parameters;
603 unsigned char sizeOfHK;
646 unsigned char sizeOfHK;
604
647
605 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
648 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
606
649
607 parameters = (unsigned char*) &housekeeping_packet;
650 parameters = (unsigned char*) &housekeeping_packet;
608
651
609 for(i = 0; i< sizeOfHK; i++)
652 for(i = 0; i< sizeOfHK; i++)
610 {
653 {
611 parameters[i] = INIT_CHAR;
654 parameters[i] = INIT_CHAR;
612 }
655 }
613
656
614 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
657 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
615 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
658 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
616 housekeeping_packet.reserved = DEFAULT_RESERVED;
659 housekeeping_packet.reserved = DEFAULT_RESERVED;
617 housekeeping_packet.userApplication = CCSDS_USER_APP;
660 housekeeping_packet.userApplication = CCSDS_USER_APP;
618 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
661 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
619 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
662 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
620 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
663 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
621 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
664 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
622 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
665 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
623 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
666 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
624 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
667 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
625 housekeeping_packet.serviceType = TM_TYPE_HK;
668 housekeeping_packet.serviceType = TM_TYPE_HK;
626 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
669 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
627 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
670 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
628 housekeeping_packet.sid = SID_HK;
671 housekeeping_packet.sid = SID_HK;
629
672
630 // init status word
673 // init status word
631 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
674 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
632 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
675 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
633 // init software version
676 // init software version
634 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
677 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
635 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
678 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
636 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
679 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
637 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
680 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
638 // init fpga version
681 // init fpga version
639 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
682 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
640 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
683 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
641 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
684 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
642 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
685 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
643
686
644 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
687 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
645 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
688 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
646 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
689 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
647 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
690 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
648 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
691 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
649 }
692 }
650
693
651 void increment_seq_counter( unsigned short *packetSequenceControl )
694 void increment_seq_counter( unsigned short *packetSequenceControl )
652 {
695 {
653 /** This function increment the sequence counter passes in argument.
696 /** This function increment the sequence counter passes in argument.
654 *
697 *
655 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
698 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
656 *
699 *
657 */
700 */
658
701
659 unsigned short segmentation_grouping_flag;
702 unsigned short segmentation_grouping_flag;
660 unsigned short sequence_cnt;
703 unsigned short sequence_cnt;
661
704
662 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
705 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
663 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
706 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
664
707
665 if ( sequence_cnt < SEQ_CNT_MAX)
708 if ( sequence_cnt < SEQ_CNT_MAX)
666 {
709 {
667 sequence_cnt = sequence_cnt + 1;
710 sequence_cnt = sequence_cnt + 1;
668 }
711 }
669 else
712 else
670 {
713 {
671 sequence_cnt = 0;
714 sequence_cnt = 0;
672 }
715 }
673
716
674 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
717 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
675 }
718 }
676
719
677 void getTime( unsigned char *time)
720 void getTime( unsigned char *time)
678 {
721 {
679 /** This function write the current local time in the time buffer passed in argument.
722 /** This function write the current local time in the time buffer passed in argument.
680 *
723 *
681 */
724 */
682
725
683 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
726 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
684 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
727 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
685 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
728 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
686 time[3] = (unsigned char) (time_management_regs->coarse_time);
729 time[3] = (unsigned char) (time_management_regs->coarse_time);
687 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
730 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
688 time[5] = (unsigned char) (time_management_regs->fine_time);
731 time[5] = (unsigned char) (time_management_regs->fine_time);
689 }
732 }
690
733
691 unsigned long long int getTimeAsUnsignedLongLongInt( )
734 unsigned long long int getTimeAsUnsignedLongLongInt( )
692 {
735 {
693 /** This function write the current local time in the time buffer passed in argument.
736 /** This function write the current local time in the time buffer passed in argument.
694 *
737 *
695 */
738 */
696 unsigned long long int time;
739 unsigned long long int time;
697
740
698 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
741 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
699 + time_management_regs->fine_time;
742 + time_management_regs->fine_time;
700
743
701 return time;
744 return time;
702 }
745 }
703
746
704 void get_temperatures( unsigned char *temperatures )
747 void get_temperatures( unsigned char *temperatures )
705 {
748 {
706 unsigned char* temp_scm_ptr;
749 unsigned char* temp_scm_ptr;
707 unsigned char* temp_pcb_ptr;
750 unsigned char* temp_pcb_ptr;
708 unsigned char* temp_fpga_ptr;
751 unsigned char* temp_fpga_ptr;
709
752
710 // SEL1 SEL0
753 // SEL1 SEL0
711 // 0 0 => PCB
754 // 0 0 => PCB
712 // 0 1 => FPGA
755 // 0 1 => FPGA
713 // 1 0 => SCM
756 // 1 0 => SCM
714
757
715 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
758 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
716 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
759 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
717 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
760 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
718
761
719 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
762 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
720 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
763 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
721 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
764 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
722 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
765 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
723 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
766 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
724 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
767 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
725 }
768 }
726
769
727 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
770 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
728 {
771 {
729 unsigned char* v_ptr;
772 unsigned char* v_ptr;
730 unsigned char* e1_ptr;
773 unsigned char* e1_ptr;
731 unsigned char* e2_ptr;
774 unsigned char* e2_ptr;
732
775
733 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
776 v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16;
734 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
777 e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16;
735 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
778 e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16;
736
779
737 spacecraft_potential[BYTE_0] = v_ptr[0];
780 spacecraft_potential[BYTE_0] = v_ptr[0];
738 spacecraft_potential[BYTE_1] = v_ptr[1];
781 spacecraft_potential[BYTE_1] = v_ptr[1];
739 spacecraft_potential[BYTE_2] = e1_ptr[0];
782 spacecraft_potential[BYTE_2] = e1_ptr[0];
740 spacecraft_potential[BYTE_3] = e1_ptr[1];
783 spacecraft_potential[BYTE_3] = e1_ptr[1];
741 spacecraft_potential[BYTE_4] = e2_ptr[0];
784 spacecraft_potential[BYTE_4] = e2_ptr[0];
742 spacecraft_potential[BYTE_5] = e2_ptr[1];
785 spacecraft_potential[BYTE_5] = e2_ptr[1];
743 }
786 }
744
787
788 /**
789 * @brief get_cpu_load, computes CPU load, CPU load average and CPU load max
790 * @param resource_statistics stores:
791 * - CPU load at index 0
792 * - CPU load max at index 1
793 * - CPU load average at index 2
794 *
795 * The CPU load average is computed on the last 60 values with a simple moving average.
796 */
745 void get_cpu_load( unsigned char *resource_statistics )
797 void get_cpu_load( unsigned char *resource_statistics )
746 {
798 {
747 #define LOAD_AVG_SIZE 60
799 #define LOAD_AVG_SIZE 60
748 static unsigned char cpu_load_hist[LOAD_AVG_SIZE]={0};
800 static unsigned char cpu_load_hist[LOAD_AVG_SIZE]={0};
749 static char old_avg_pos=0;
801 static char old_avg_pos=0;
750 static unsigned int cpu_load_avg;
802 static unsigned int cpu_load_avg;
751 unsigned char cpu_load;
803 unsigned char cpu_load;
752
804
753 cpu_load = lfr_rtems_cpu_usage_report();
805 cpu_load = lfr_rtems_cpu_usage_report();
754
806
755 // HK_LFR_CPU_LOAD
807 // HK_LFR_CPU_LOAD
756 resource_statistics[0] = cpu_load;
808 resource_statistics[BYTE_0] = cpu_load;
757
809
758 // HK_LFR_CPU_LOAD_MAX
810 // HK_LFR_CPU_LOAD_MAX
759 if (cpu_load > resource_statistics[1])
811 if (cpu_load > resource_statistics[BYTE_1])
760 {
812 {
761 resource_statistics[1] = cpu_load;
813 resource_statistics[BYTE_1] = cpu_load;
762 }
814 }
763
815
764 cpu_load_avg = cpu_load_avg - (unsigned int)cpu_load_hist[(int)old_avg_pos] + (unsigned int)cpu_load;
816 cpu_load_avg = cpu_load_avg - (unsigned int)cpu_load_hist[(int)old_avg_pos] + (unsigned int)cpu_load;
765 cpu_load_hist[(int)old_avg_pos] = cpu_load;
817 cpu_load_hist[(int)old_avg_pos] = cpu_load;
766 old_avg_pos += 1;
818 old_avg_pos += 1;
767 old_avg_pos %= LOAD_AVG_SIZE;
819 old_avg_pos %= LOAD_AVG_SIZE;
768 // CPU_LOAD_AVE
820 // CPU_LOAD_AVE
769 resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE);
821 resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE);
770 // this will change the way LFR compute usage
822 // this will change the way LFR compute usage
771 #ifndef PRINT_TASK_STATISTICS
823 #ifndef PRINT_TASK_STATISTICS
772 rtems_cpu_usage_reset();
824 rtems_cpu_usage_reset();
773 #endif
825 #endif
774
826
775 }
827 }
776
828
777 void set_hk_lfr_sc_potential_flag( bool state )
829 void set_hk_lfr_sc_potential_flag( bool state )
778 {
830 {
779 if (state == true)
831 if (state == true)
780 {
832 {
781 housekeeping_packet.lfr_status_word[1] =
833 housekeeping_packet.lfr_status_word[1] =
782 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
834 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
783 }
835 }
784 else
836 else
785 {
837 {
786 housekeeping_packet.lfr_status_word[1] =
838 housekeeping_packet.lfr_status_word[1] =
787 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
839 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
788 }
840 }
789 }
841 }
790
842
791 void set_sy_lfr_pas_filter_enabled( bool state )
843 void set_sy_lfr_pas_filter_enabled( bool state )
792 {
844 {
793 if (state == true)
845 if (state == true)
794 {
846 {
795 housekeeping_packet.lfr_status_word[1] =
847 housekeeping_packet.lfr_status_word[1] =
796 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
848 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
797 }
849 }
798 else
850 else
799 {
851 {
800 housekeeping_packet.lfr_status_word[1] =
852 housekeeping_packet.lfr_status_word[1] =
801 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
853 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
802 }
854 }
803 }
855 }
804
856
805 void set_sy_lfr_watchdog_enabled( bool state )
857 void set_sy_lfr_watchdog_enabled( bool state )
806 {
858 {
807 if (state == true)
859 if (state == true)
808 {
860 {
809 housekeeping_packet.lfr_status_word[1] =
861 housekeeping_packet.lfr_status_word[1] =
810 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
862 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
811 }
863 }
812 else
864 else
813 {
865 {
814 housekeeping_packet.lfr_status_word[1] =
866 housekeeping_packet.lfr_status_word[1] =
815 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
867 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
816 }
868 }
817 }
869 }
818
870
819 void set_hk_lfr_calib_enable( bool state )
871 void set_hk_lfr_calib_enable( bool state )
820 {
872 {
821 if (state == true)
873 if (state == true)
822 {
874 {
823 housekeeping_packet.lfr_status_word[1] =
875 housekeeping_packet.lfr_status_word[1] =
824 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
876 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
825 }
877 }
826 else
878 else
827 {
879 {
828 housekeeping_packet.lfr_status_word[1] =
880 housekeeping_packet.lfr_status_word[1] =
829 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
881 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
830 }
882 }
831 }
883 }
832
884
833 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
885 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
834 {
886 {
835 housekeeping_packet.lfr_status_word[1] =
887 housekeeping_packet.lfr_status_word[1] =
836 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
888 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
837
889
838 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
890 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
839 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
891 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
840
892
841 }
893 }
842
894
843 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
895 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
844 {
896 {
845 int delta;
897 int delta;
846
898
847 delta = 0;
899 delta = 0;
848
900
849 if (newValue >= oldValue)
901 if (newValue >= oldValue)
850 {
902 {
851 delta = newValue - oldValue;
903 delta = newValue - oldValue;
852 }
904 }
853 else
905 else
854 {
906 {
855 delta = (CONST_256 - oldValue) + newValue;
907 delta = (CONST_256 - oldValue) + newValue;
856 }
908 }
857
909
858 *counter = *counter + delta;
910 *counter = *counter + delta;
859 }
911 }
860
912
913 // Low severity error counters update
861 void hk_lfr_le_update( void )
914 void hk_lfr_le_update( void )
862 {
915 {
863 static hk_lfr_le_t old_hk_lfr_le = {0};
916 static hk_lfr_le_t old_hk_lfr_le = {0};
864 hk_lfr_le_t new_hk_lfr_le;
917 hk_lfr_le_t new_hk_lfr_le;
865 unsigned int counter;
918 unsigned int counter;
866
919
867 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
920 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
868
921
869 // DPU
922 // DPU
870 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
923 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
871 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
924 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
872 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
925 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
873 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
926 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
874 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
927 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
875 // TIMECODE
928 // TIMECODE
876 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
929 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
877 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
930 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
878 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
931 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
879 // TIME
932 // TIME
880 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
933 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
881 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
934 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
882 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
935 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
883 //AHB
936 //AHB
884 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
937 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
885 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
938 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
886 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
939 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
887
940
888 // update the le counter
941 // update the le counter
889 // DPU
942 // DPU
890 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
943 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
891 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
944 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
892 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
945 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
893 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
946 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
894 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
947 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
895 // TIMECODE
948 // TIMECODE
896 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
949 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
897 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
950 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
898 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
951 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
899 // TIME
952 // TIME
900 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
953 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
901 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
954 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
902 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
955 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
903 // AHB
956 // AHB
904 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
957 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
905
958
906 // DPU
959 // DPU
907 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
960 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
908 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
961 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
909 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
962 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
910 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
963 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
911 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
964 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
912 // TIMECODE
965 // TIMECODE
913 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
966 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
914 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
967 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
915 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
968 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
916 // TIME
969 // TIME
917 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
970 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
918 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
971 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
919 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
972 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
920 //AHB
973 //AHB
921 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
974 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
922 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
975 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
923 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
976 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
924
977
925 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
978 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
926 // LE
979 // LE
927 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
980 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
928 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
981 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
929 }
982 }
930
983
984 // Medium severity error counters update
931 void hk_lfr_me_update( void )
985 void hk_lfr_me_update( void )
932 {
986 {
933 static hk_lfr_me_t old_hk_lfr_me = {0};
987 static hk_lfr_me_t old_hk_lfr_me = {0};
934 hk_lfr_me_t new_hk_lfr_me;
988 hk_lfr_me_t new_hk_lfr_me;
935 unsigned int counter;
989 unsigned int counter;
936
990
937 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
991 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
938
992
939 // get the current values
993 // get the current values
940 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
994 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
941 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
995 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
942 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
996 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
943 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
997 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
944
998
945 // update the me counter
999 // update the me counter
946 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
1000 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
947 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
1001 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
948 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
1002 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
949 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
1003 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
950
1004
951 // store the counters for the next time
1005 // store the counters for the next time
952 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
1006 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
953 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
1007 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
954 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
1008 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
955 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
1009 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
956
1010
957 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
1011 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
958 // ME
1012 // ME
959 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
1013 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
960 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
1014 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
961 }
1015 }
962
1016
1017 // High severity error counters update
963 void hk_lfr_le_me_he_update()
1018 void hk_lfr_le_me_he_update()
964 {
1019 {
965
1020
966 unsigned int hk_lfr_he_cnt;
1021 unsigned int hk_lfr_he_cnt;
967
1022
968 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
1023 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
969
1024
970 //update the low severity error counter
1025 //update the low severity error counter
971 hk_lfr_le_update( );
1026 hk_lfr_le_update( );
972
1027
973 //update the medium severity error counter
1028 //update the medium severity error counter
974 hk_lfr_me_update();
1029 hk_lfr_me_update();
975
1030
976 //update the high severity error counter
1031 //update the high severity error counter
977 hk_lfr_he_cnt = 0;
1032 hk_lfr_he_cnt = 0;
978
1033
979 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
1034 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
980 // HE
1035 // HE
981 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
1036 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
982 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
1037 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
983
1038
984 }
1039 }
985
1040
986 void set_hk_lfr_time_not_synchro()
1041 void set_hk_lfr_time_not_synchro()
987 {
1042 {
988 static unsigned char synchroLost = 1;
1043 static unsigned char synchroLost = 1;
989 int synchronizationBit;
1044 int synchronizationBit;
990
1045
991 // get the synchronization bit
1046 // get the synchronization bit
992 synchronizationBit =
1047 synchronizationBit =
993 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
1048 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
994
1049
995 switch (synchronizationBit)
1050 switch (synchronizationBit)
996 {
1051 {
997 case 0:
1052 case 0:
998 if (synchroLost == 1)
1053 if (synchroLost == 1)
999 {
1054 {
1000 synchroLost = 0;
1055 synchroLost = 0;
1001 }
1056 }
1002 break;
1057 break;
1003 case 1:
1058 case 1:
1004 if (synchroLost == 0 )
1059 if (synchroLost == 0 )
1005 {
1060 {
1006 synchroLost = 1;
1061 synchroLost = 1;
1007 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
1062 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
1008 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
1063 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
1009 }
1064 }
1010 break;
1065 break;
1011 default:
1066 default:
1012 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
1067 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
1013 break;
1068 break;
1014 }
1069 }
1015
1070
1016 }
1071 }
1017
1072
1018 void set_hk_lfr_ahb_correctable() // CRITICITY L
1073 void set_hk_lfr_ahb_correctable() // CRITICITY L
1019 {
1074 {
1020 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
1075 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
1021 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
1076 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
1022 * detected errors in the cache, in the integer unit and in the floating point unit.
1077 * detected errors in the cache, in the integer unit and in the floating point unit.
1023 *
1078 *
1024 * @param void
1079 * @param void
1025 *
1080 *
1026 * @return void
1081 * @return void
1027 *
1082 *
1028 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
1083 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
1029 *
1084 *
1030 */
1085 */
1031
1086
1032 unsigned int ahb_correctable;
1087 unsigned int ahb_correctable;
1033 unsigned int instructionErrorCounter;
1088 unsigned int instructionErrorCounter;
1034 unsigned int dataErrorCounter;
1089 unsigned int dataErrorCounter;
1035 unsigned int fprfErrorCounter;
1090 unsigned int fprfErrorCounter;
1036 unsigned int iurfErrorCounter;
1091 unsigned int iurfErrorCounter;
1037
1092
1038 instructionErrorCounter = 0;
1093 instructionErrorCounter = 0;
1039 dataErrorCounter = 0;
1094 dataErrorCounter = 0;
1040 fprfErrorCounter = 0;
1095 fprfErrorCounter = 0;
1041 iurfErrorCounter = 0;
1096 iurfErrorCounter = 0;
1042
1097
1043 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
1098 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
1044 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
1099 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
1045
1100
1046 ahb_correctable = instructionErrorCounter
1101 ahb_correctable = instructionErrorCounter
1047 + dataErrorCounter
1102 + dataErrorCounter
1048 + fprfErrorCounter
1103 + fprfErrorCounter
1049 + iurfErrorCounter
1104 + iurfErrorCounter
1050 + housekeeping_packet.hk_lfr_ahb_correctable;
1105 + housekeeping_packet.hk_lfr_ahb_correctable;
1051
1106
1052 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1107 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
1053
1108
1054 }
1109 }
@@ -1,1608 +1,1632
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to the SpaceWire interface.
25 /** Functions related to the SpaceWire interface.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to handle SpaceWire transmissions:
30 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
31 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
32 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
33 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
34 * - reception of TeleCommands by a dedicated RTEMS task
11 *
35 *
12 */
36 */
13
37
14 #include "fsw_spacewire.h"
38 #include "fsw_spacewire.h"
15
39
16 rtems_name semq_name = 0;
40 rtems_name semq_name = 0;
17 rtems_id semq_id = RTEMS_ID_NONE;
41 rtems_id semq_id = RTEMS_ID_NONE;
18
42
19 //*****************
43 //*****************
20 // waveform headers
44 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
45 Header_TM_LFR_SCIENCE_CWF_t headerCWF = {0};
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
46 Header_TM_LFR_SCIENCE_SWF_t headerSWF = {0};
23 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
47 Header_TM_LFR_SCIENCE_ASM_t headerASM = {0};
24
48
25 unsigned char previousTimecodeCtr = 0;
49 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
50 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
51
28 //***********
52 //***********
29 // RTEMS TASK
53 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
54 rtems_task spiq_task(rtems_task_argument unused)
31 {
55 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
56 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
57 *
34 * @param unused is the starting argument of the RTEMS task
58 * @param unused is the starting argument of the RTEMS task
35 *
59 *
36 */
60 */
37
61
38 rtems_event_set event_out;
62 rtems_event_set event_out;
39 rtems_status_code status;
63 rtems_status_code status;
40 int linkStatus;
64 int linkStatus;
41
65
42 event_out = EVENT_SETS_NONE_PENDING;
66 event_out = EVENT_SETS_NONE_PENDING;
43 linkStatus = 0;
67 linkStatus = 0;
44
68
45 BOOT_PRINTF("in SPIQ *** \n")
69 BOOT_PRINTF("in SPIQ *** \n")
46
70
47 while(true){
71 while(true){
48 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
72 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")
73 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
50
74
51 // [0] SUSPEND RECV AND SEND TASKS
75 // [0] SUSPEND RECV AND SEND TASKS
52 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
76 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
53 if ( status != RTEMS_SUCCESSFUL ) {
77 if ( status != RTEMS_SUCCESSFUL ) {
54 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
78 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
55 }
79 }
56 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
80 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
57 if ( status != RTEMS_SUCCESSFUL ) {
81 if ( status != RTEMS_SUCCESSFUL ) {
58 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
82 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
59 }
83 }
60
84
61 // [1] CHECK THE LINK
85 // [1] CHECK THE LINK
62 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
86 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
63 if ( linkStatus != SPW_LINK_OK) {
87 if ( linkStatus != SPW_LINK_OK) {
64 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
88 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
89 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
66 }
90 }
67
91
68 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
92 // [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)
93 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
94 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
71 {
95 {
72 spacewire_read_statistics();
96 spacewire_read_statistics();
73 status = spacewire_several_connect_attemps( );
97 status = spacewire_several_connect_attemps( );
74 }
98 }
75 else // [2.b] in run state, start the link
99 else // [2.b] in run state, start the link
76 {
100 {
77 status = spacewire_stop_and_start_link( fdSPW ); // start the link
101 status = spacewire_stop_and_start_link( fdSPW ); // start the link
78 if ( status != RTEMS_SUCCESSFUL)
102 if ( status != RTEMS_SUCCESSFUL)
79 {
103 {
80 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
104 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
81 }
105 }
82 }
106 }
83
107
84 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
108 // [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
109 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
86 {
110 {
87 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
111 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
88 if ( status != RTEMS_SUCCESSFUL ) {
112 if ( status != RTEMS_SUCCESSFUL ) {
89 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
113 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
90 }
114 }
91 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
115 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
92 if ( status != RTEMS_SUCCESSFUL ) {
116 if ( status != RTEMS_SUCCESSFUL ) {
93 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
117 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
94 }
118 }
95 }
119 }
96 else // [3.b] the link is not in run state, go in STANDBY mode
120 else // [3.b] the link is not in run state, go in STANDBY mode
97 {
121 {
98 status = enter_mode_standby();
122 status = enter_mode_standby();
99 if ( status != RTEMS_SUCCESSFUL )
123 if ( status != RTEMS_SUCCESSFUL )
100 {
124 {
101 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
125 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
102 }
126 }
103 {
127 {
104 updateLFRCurrentMode( LFR_MODE_STANDBY );
128 updateLFRCurrentMode( LFR_MODE_STANDBY );
105 }
129 }
106 // wake the LINK task up to wait for the link recovery
130 // wake the LINK task up to wait for the link recovery
107 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
131 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
108 status = rtems_task_suspend( RTEMS_SELF );
132 status = rtems_task_suspend( RTEMS_SELF );
109 }
133 }
110 }
134 }
111 }
135 }
112
136
113 rtems_task recv_task( rtems_task_argument unused )
137 rtems_task recv_task( rtems_task_argument unused )
114 {
138 {
115 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
139 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
116 *
140 *
117 * @param unused is the starting argument of the RTEMS task
141 * @param unused is the starting argument of the RTEMS task
118 *
142 *
119 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
143 * 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.
144 * 1. It reads the incoming data.
121 * 2. Launches the acceptance procedure.
145 * 2. Launches the acceptance procedure.
122 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
146 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
123 *
147 *
124 */
148 */
125
149
126 int len;
150 int len;
127 ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC;
151 ccsdsTelecommandPacket_t __attribute__((aligned(4))) currentTC;
128 unsigned char computed_CRC[ BYTES_PER_CRC ];
152 unsigned char computed_CRC[ BYTES_PER_CRC ];
129 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
153 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
130 unsigned char destinationID;
154 unsigned char destinationID;
131 unsigned int estimatedPacketLength;
155 unsigned int estimatedPacketLength;
132 unsigned int parserCode;
156 unsigned int parserCode;
133 rtems_status_code status;
157 rtems_status_code status;
134 rtems_id queue_recv_id;
158 rtems_id queue_recv_id;
135 rtems_id queue_send_id;
159 rtems_id queue_send_id;
136
160
137 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
161 memset( &currentTC, 0, sizeof(ccsdsTelecommandPacket_t) );
138 destinationID = 0;
162 destinationID = 0;
139 queue_recv_id = RTEMS_ID_NONE;
163 queue_recv_id = RTEMS_ID_NONE;
140 queue_send_id = RTEMS_ID_NONE;
164 queue_send_id = RTEMS_ID_NONE;
141
165
142 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
166 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
143
167
144 status = get_message_queue_id_recv( &queue_recv_id );
168 status = get_message_queue_id_recv( &queue_recv_id );
145 if (status != RTEMS_SUCCESSFUL)
169 if (status != RTEMS_SUCCESSFUL)
146 {
170 {
147 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
171 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
148 }
172 }
149
173
150 status = get_message_queue_id_send( &queue_send_id );
174 status = get_message_queue_id_send( &queue_send_id );
151 if (status != RTEMS_SUCCESSFUL)
175 if (status != RTEMS_SUCCESSFUL)
152 {
176 {
153 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
177 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
154 }
178 }
155
179
156 BOOT_PRINTF("in RECV *** \n")
180 BOOT_PRINTF("in RECV *** \n")
157
181
158 while(1)
182 while(1)
159 {
183 {
160 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
184 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
161 if (len == -1){ // error during the read call
185 if (len == -1){ // error during the read call
162 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
186 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
163 }
187 }
164 else {
188 else {
165 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
189 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
166 PRINTF("in RECV *** packet lenght too short\n")
190 PRINTF("in RECV *** packet lenght too short\n")
167 }
191 }
168 else {
192 else {
169 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
193 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);
194 PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
171 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
195 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
172 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
196 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
173 // CHECK THE TC
197 // CHECK THE TC
174 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
198 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
175 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
199 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
176 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
200 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
177 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
201 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
178 || (parserCode == WRONG_SRC_ID) )
202 || (parserCode == WRONG_SRC_ID) )
179 { // send TM_LFR_TC_EXE_CORRUPTED
203 { // send TM_LFR_TC_EXE_CORRUPTED
180 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
204 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
181 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
205 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
182 &&
206 &&
183 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
207 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
184 )
208 )
185 {
209 {
186 if ( parserCode == WRONG_SRC_ID )
210 if ( parserCode == WRONG_SRC_ID )
187 {
211 {
188 destinationID = SID_TC_GROUND;
212 destinationID = SID_TC_GROUND;
189 }
213 }
190 else
214 else
191 {
215 {
192 destinationID = currentTC.sourceID;
216 destinationID = currentTC.sourceID;
193 }
217 }
194 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
218 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
195 computed_CRC, currentTC_LEN_RCV,
219 computed_CRC, currentTC_LEN_RCV,
196 destinationID );
220 destinationID );
197 }
221 }
198 }
222 }
199 else
223 else
200 { // send valid TC to the action launcher
224 { // send valid TC to the action launcher
201 status = rtems_message_queue_send( queue_recv_id, &currentTC,
225 status = rtems_message_queue_send( queue_recv_id, &currentTC,
202 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
226 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
203 }
227 }
204 }
228 }
205 }
229 }
206
230
207 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
231 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
208
232
209 }
233 }
210 }
234 }
211
235
212 rtems_task send_task( rtems_task_argument argument)
236 rtems_task send_task( rtems_task_argument argument)
213 {
237 {
214 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
238 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
215 *
239 *
216 * @param unused is the starting argument of the RTEMS task
240 * @param unused is the starting argument of the RTEMS task
217 *
241 *
218 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
242 * 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.
243 * - 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
244 * - 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
245 * 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.
246 * data it contains.
223 *
247 *
224 */
248 */
225
249
226 rtems_status_code status; // RTEMS status code
250 rtems_status_code status; // RTEMS status code
227 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
251 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
228 ring_node *incomingRingNodePtr;
252 ring_node *incomingRingNodePtr;
229 int ring_node_address;
253 int ring_node_address;
230 char *charPtr;
254 char *charPtr;
231 spw_ioctl_pkt_send *spw_ioctl_send;
255 spw_ioctl_pkt_send *spw_ioctl_send;
232 size_t size; // size of the incoming TC packet
256 size_t size; // size of the incoming TC packet
233 rtems_id queue_send_id;
257 rtems_id queue_send_id;
234 unsigned int sid;
258 unsigned int sid;
235 unsigned char sidAsUnsignedChar;
259 unsigned char sidAsUnsignedChar;
236 unsigned char type;
260 unsigned char type;
237
261
238 incomingRingNodePtr = NULL;
262 incomingRingNodePtr = NULL;
239 ring_node_address = 0;
263 ring_node_address = 0;
240 charPtr = (char *) &ring_node_address;
264 charPtr = (char *) &ring_node_address;
241 size = 0;
265 size = 0;
242 queue_send_id = RTEMS_ID_NONE;
266 queue_send_id = RTEMS_ID_NONE;
243 sid = 0;
267 sid = 0;
244 sidAsUnsignedChar = 0;
268 sidAsUnsignedChar = 0;
245
269
246 init_header_cwf( &headerCWF );
270 init_header_cwf( &headerCWF );
247 init_header_swf( &headerSWF );
271 init_header_swf( &headerSWF );
248 init_header_asm( &headerASM );
272 init_header_asm( &headerASM );
249
273
250 status = get_message_queue_id_send( &queue_send_id );
274 status = get_message_queue_id_send( &queue_send_id );
251 if (status != RTEMS_SUCCESSFUL)
275 if (status != RTEMS_SUCCESSFUL)
252 {
276 {
253 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
277 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
254 }
278 }
255
279
256 BOOT_PRINTF("in SEND *** \n")
280 BOOT_PRINTF("in SEND *** \n")
257
281
258 while(1)
282 while(1)
259 {
283 {
260 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
284 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
261 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
285 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
262
286
263 if (status!=RTEMS_SUCCESSFUL)
287 if (status!=RTEMS_SUCCESSFUL)
264 {
288 {
265 PRINTF1("in SEND *** (1) ERR = %d\n", status)
289 PRINTF1("in SEND *** (1) ERR = %d\n", status)
266 }
290 }
267 else
291 else
268 {
292 {
269 if ( size == sizeof(ring_node*) )
293 if ( size == sizeof(ring_node*) )
270 {
294 {
271 charPtr[0] = incomingData[0];
295 charPtr[0] = incomingData[0];
272 charPtr[1] = incomingData[1];
296 charPtr[1] = incomingData[1];
273 charPtr[BYTE_2] = incomingData[BYTE_2];
297 charPtr[BYTE_2] = incomingData[BYTE_2];
274 charPtr[BYTE_3] = incomingData[BYTE_3];
298 charPtr[BYTE_3] = incomingData[BYTE_3];
275 incomingRingNodePtr = (ring_node*) ring_node_address;
299 incomingRingNodePtr = (ring_node*) ring_node_address;
276 sid = incomingRingNodePtr->sid;
300 sid = incomingRingNodePtr->sid;
277 if ( (sid==SID_NORM_CWF_LONG_F3)
301 if ( (sid==SID_NORM_CWF_LONG_F3)
278 || (sid==SID_BURST_CWF_F2 )
302 || (sid==SID_BURST_CWF_F2 )
279 || (sid==SID_SBM1_CWF_F1 )
303 || (sid==SID_SBM1_CWF_F1 )
280 || (sid==SID_SBM2_CWF_F2 ))
304 || (sid==SID_SBM2_CWF_F2 ))
281 {
305 {
282 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
306 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
283 }
307 }
284 else if ( (sid==SID_NORM_SWF_F0) || (sid==SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
308 else if ( (sid==SID_NORM_SWF_F0) || (sid==SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
285 {
309 {
286 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
310 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
287 }
311 }
288 else if (sid==SID_NORM_CWF_F3)
312 else if (sid==SID_NORM_CWF_F3)
289 {
313 {
290 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
314 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
291 }
315 }
292 else if (sid==SID_NORM_ASM_F0)
316 else if (sid==SID_NORM_ASM_F0)
293 {
317 {
294 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
318 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
295 }
319 }
296 else if (sid==SID_NORM_ASM_F1)
320 else if (sid==SID_NORM_ASM_F1)
297 {
321 {
298 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
322 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
299 }
323 }
300 else if (sid==SID_NORM_ASM_F2)
324 else if (sid==SID_NORM_ASM_F2)
301 {
325 {
302 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
326 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
303 }
327 }
304 else if (sid==TM_CODE_K_DUMP)
328 else if (sid==TM_CODE_K_DUMP)
305 {
329 {
306 spw_send_k_dump( incomingRingNodePtr );
330 spw_send_k_dump( incomingRingNodePtr );
307 }
331 }
308 else
332 else
309 {
333 {
310 PRINTF1("unexpected sid = %d\n", sid);
334 PRINTF1("unexpected sid = %d\n", sid);
311 }
335 }
312 }
336 }
313 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
337 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
314 {
338 {
315 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
339 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
316 sid = sidAsUnsignedChar;
340 sid = sidAsUnsignedChar;
317 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
341 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
342 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
343 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
320 {
344 {
321 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
345 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
322 }
346 }
323
347
324 status = write( fdSPW, incomingData, size );
348 status = write( fdSPW, incomingData, size );
325 if (status == -1){
349 if (status == -1){
326 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
350 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
327 }
351 }
328 }
352 }
329 else // the incoming message is a spw_ioctl_pkt_send structure
353 else // the incoming message is a spw_ioctl_pkt_send structure
330 {
354 {
331 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
355 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
332 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
356 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
333 if (status == -1){
357 if (status == -1){
334 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
358 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
335 }
359 }
336 }
360 }
337 }
361 }
338
362
339 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
363 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
340
364
341 }
365 }
342 }
366 }
343
367
344 rtems_task link_task( rtems_task_argument argument )
368 rtems_task link_task( rtems_task_argument argument )
345 {
369 {
346 rtems_event_set event_out;
370 rtems_event_set event_out;
347 rtems_status_code status;
371 rtems_status_code status;
348 int linkStatus;
372 int linkStatus;
349
373
350 event_out = EVENT_SETS_NONE_PENDING;
374 event_out = EVENT_SETS_NONE_PENDING;
351 linkStatus = 0;
375 linkStatus = 0;
352
376
353 BOOT_PRINTF("in LINK ***\n")
377 BOOT_PRINTF("in LINK ***\n")
354
378
355 while(1)
379 while(1)
356 {
380 {
357 // wait for an RTEMS_EVENT
381 // wait for an RTEMS_EVENT
358 rtems_event_receive( RTEMS_EVENT_0,
382 rtems_event_receive( RTEMS_EVENT_0,
359 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
383 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
360 PRINTF("in LINK *** wait for the link\n")
384 PRINTF("in LINK *** wait for the link\n")
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
385 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
362 while( linkStatus != SPW_LINK_OK) // wait for the link
386 while( linkStatus != SPW_LINK_OK) // wait for the link
363 {
387 {
364 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
388 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
389 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
366 watchdog_reload();
390 watchdog_reload();
367 }
391 }
368
392
369 spacewire_read_statistics();
393 spacewire_read_statistics();
370 status = spacewire_stop_and_start_link( fdSPW );
394 status = spacewire_stop_and_start_link( fdSPW );
371
395
372 if (status != RTEMS_SUCCESSFUL)
396 if (status != RTEMS_SUCCESSFUL)
373 {
397 {
374 PRINTF1("in LINK *** ERR link not started %d\n", status)
398 PRINTF1("in LINK *** ERR link not started %d\n", status)
375 }
399 }
376 else
400 else
377 {
401 {
378 PRINTF("in LINK *** OK link started\n")
402 PRINTF("in LINK *** OK link started\n")
379 }
403 }
380
404
381 // restart the SPIQ task
405 // restart the SPIQ task
382 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
406 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
383 if ( status != RTEMS_SUCCESSFUL ) {
407 if ( status != RTEMS_SUCCESSFUL ) {
384 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
408 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
385 }
409 }
386
410
387 // restart RECV and SEND
411 // restart RECV and SEND
388 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
412 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
389 if ( status != RTEMS_SUCCESSFUL ) {
413 if ( status != RTEMS_SUCCESSFUL ) {
390 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
414 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
391 }
415 }
392 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
416 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
393 if ( status != RTEMS_SUCCESSFUL ) {
417 if ( status != RTEMS_SUCCESSFUL ) {
394 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
418 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
395 }
419 }
396 }
420 }
397 }
421 }
398
422
399 //****************
423 //****************
400 // OTHER FUNCTIONS
424 // OTHER FUNCTIONS
401 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
425 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
402 {
426 {
403 /** This function opens the SpaceWire link.
427 /** This function opens the SpaceWire link.
404 *
428 *
405 * @return a valid file descriptor in case of success, -1 in case of a failure
429 * @return a valid file descriptor in case of success, -1 in case of a failure
406 *
430 *
407 */
431 */
408 rtems_status_code status;
432 rtems_status_code status;
409
433
410 status = RTEMS_SUCCESSFUL;
434 status = RTEMS_SUCCESSFUL;
411
435
412 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
436 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
413 if ( fdSPW < 0 ) {
437 if ( fdSPW < 0 ) {
414 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
438 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
415 }
439 }
416 else
440 else
417 {
441 {
418 status = RTEMS_SUCCESSFUL;
442 status = RTEMS_SUCCESSFUL;
419 }
443 }
420
444
421 return status;
445 return status;
422 }
446 }
423
447
424 int spacewire_start_link( int fd )
448 int spacewire_start_link( int fd )
425 {
449 {
426 rtems_status_code status;
450 rtems_status_code status;
427
451
428 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
452 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
429 // -1 default hardcoded driver timeout
453 // -1 default hardcoded driver timeout
430
454
431 return status;
455 return status;
432 }
456 }
433
457
434 int spacewire_stop_and_start_link( int fd )
458 int spacewire_stop_and_start_link( int fd )
435 {
459 {
436 rtems_status_code status;
460 rtems_status_code status;
437
461
438 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
462 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
463 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
440 // -1 default hardcoded driver timeout
464 // -1 default hardcoded driver timeout
441
465
442 return status;
466 return status;
443 }
467 }
444
468
445 int spacewire_configure_link( int fd )
469 int spacewire_configure_link( int fd )
446 {
470 {
447 /** This function configures the SpaceWire link.
471 /** This function configures the SpaceWire link.
448 *
472 *
449 * @return GR-RTEMS-DRIVER directive status codes:
473 * @return GR-RTEMS-DRIVER directive status codes:
450 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
474 * - 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.
475 * - 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.
476 * - 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.
477 * - 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.
478 * - 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.
479 * - 5 EIO - Error when writing to grswp hardware registers.
456 * - 2 ENOENT - No such file or directory
480 * - 2 ENOENT - No such file or directory
457 */
481 */
458
482
459 rtems_status_code status;
483 rtems_status_code status;
460
484
461 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
485 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
486 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;
487 spw_ioctl_packetsize packetsize;
464
488
465 packetsize.rxsize = SPW_RXSIZE;
489 packetsize.rxsize = SPW_RXSIZE;
466 packetsize.txdsize = SPW_TXDSIZE;
490 packetsize.txdsize = SPW_TXDSIZE;
467 packetsize.txhsize = SPW_TXHSIZE;
491 packetsize.txhsize = SPW_TXHSIZE;
468
492
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
493 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
470 if (status!=RTEMS_SUCCESSFUL) {
494 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
495 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
472 }
496 }
473 //
497 //
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
498 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) {
499 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
500 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
477 }
501 }
478 //
502 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
503 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
480 if (status!=RTEMS_SUCCESSFUL) {
504 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
505 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
482 }
506 }
483 //
507 //
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
508 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
485 if (status!=RTEMS_SUCCESSFUL) {
509 if (status!=RTEMS_SUCCESSFUL) {
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
510 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
487 }
511 }
488 //
512 //
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
513 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
490 if (status!=RTEMS_SUCCESSFUL) {
514 if (status!=RTEMS_SUCCESSFUL) {
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
515 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
492 }
516 }
493 //
517 //
494 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
518 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
495 if (status!=RTEMS_SUCCESSFUL) {
519 if (status!=RTEMS_SUCCESSFUL) {
496 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
520 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
497 }
521 }
498 //
522 //
499 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
523 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) {
524 if (status!=RTEMS_SUCCESSFUL) {
501 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
525 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
502 }
526 }
503 //
527 //
504 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
528 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
505 if (status!=RTEMS_SUCCESSFUL) {
529 if (status!=RTEMS_SUCCESSFUL) {
506 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
530 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
507 }
531 }
508
532
509 return status;
533 return status;
510 }
534 }
511
535
512 int spacewire_several_connect_attemps( void )
536 int spacewire_several_connect_attemps( void )
513 {
537 {
514 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
538 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
515 *
539 *
516 * @return RTEMS directive status code:
540 * @return RTEMS directive status code:
517 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
541 * - 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.
542 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
519 *
543 *
520 */
544 */
521
545
522 rtems_status_code status_spw;
546 rtems_status_code status_spw;
523 rtems_status_code status;
547 rtems_status_code status;
524 int i;
548 int i;
525
549
526 status_spw = RTEMS_SUCCESSFUL;
550 status_spw = RTEMS_SUCCESSFUL;
527
551
528 i = 0;
552 i = 0;
529 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
553 while (i < SY_LFR_DPU_CONNECT_ATTEMPT)
530 {
554 {
531 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
555 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
532
556
533 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
557 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
534
558
535 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
559 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
536
560
537 status_spw = spacewire_stop_and_start_link( fdSPW );
561 status_spw = spacewire_stop_and_start_link( fdSPW );
538
562
539 if ( status_spw != RTEMS_SUCCESSFUL )
563 if ( status_spw != RTEMS_SUCCESSFUL )
540 {
564 {
541 i = i + 1;
565 i = i + 1;
542 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
566 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw);
543 }
567 }
544 else
568 else
545 {
569 {
546 i = SY_LFR_DPU_CONNECT_ATTEMPT;
570 i = SY_LFR_DPU_CONNECT_ATTEMPT;
547 }
571 }
548 }
572 }
549
573
550 return status_spw;
574 return status_spw;
551 }
575 }
552
576
553 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
577 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
554 {
578 {
555 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
579 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
556 *
580 *
557 * @param val is the value, 0 or 1, used to set the value of the NP bit.
581 * @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.
582 * @param regAddr is the address of the GRSPW control register.
559 *
583 *
560 * NP is the bit 20 of the GRSPW control register.
584 * NP is the bit 20 of the GRSPW control register.
561 *
585 *
562 */
586 */
563
587
564 unsigned int *spwptr = (unsigned int*) regAddr;
588 unsigned int *spwptr = (unsigned int*) regAddr;
565
589
566 if (val == 1) {
590 if (val == 1) {
567 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
591 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
568 }
592 }
569 if (val== 0) {
593 if (val== 0) {
570 *spwptr = *spwptr & SPW_BIT_NP_MASK;
594 *spwptr = *spwptr & SPW_BIT_NP_MASK;
571 }
595 }
572 }
596 }
573
597
574 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
598 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
575 {
599 {
576 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
600 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
577 *
601 *
578 * @param val is the value, 0 or 1, used to set the value of the RE bit.
602 * @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.
603 * @param regAddr is the address of the GRSPW control register.
580 *
604 *
581 * RE is the bit 16 of the GRSPW control register.
605 * RE is the bit 16 of the GRSPW control register.
582 *
606 *
583 */
607 */
584
608
585 unsigned int *spwptr = (unsigned int*) regAddr;
609 unsigned int *spwptr = (unsigned int*) regAddr;
586
610
587 if (val == 1)
611 if (val == 1)
588 {
612 {
589 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
613 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
590 }
614 }
591 if (val== 0)
615 if (val== 0)
592 {
616 {
593 *spwptr = *spwptr & SPW_BIT_RE_MASK;
617 *spwptr = *spwptr & SPW_BIT_RE_MASK;
594 }
618 }
595 }
619 }
596
620
597 void spacewire_read_statistics( void )
621 void spacewire_read_statistics( void )
598 {
622 {
599 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
623 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
600 *
624 *
601 * @param void
625 * @param void
602 *
626 *
603 * @return void
627 * @return void
604 *
628 *
605 * Once they are read, the counters are stored in a global variable used during the building of the
629 * Once they are read, the counters are stored in a global variable used during the building of the
606 * HK packets.
630 * HK packets.
607 *
631 *
608 */
632 */
609
633
610 rtems_status_code status;
634 rtems_status_code status;
611 spw_stats current;
635 spw_stats current;
612
636
613 memset(&current, 0, sizeof(spw_stats));
637 memset(&current, 0, sizeof(spw_stats));
614
638
615 spacewire_get_last_error();
639 spacewire_get_last_error();
616
640
617 // read the current statistics
641 // read the current statistics
618 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
642 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
619
643
620 // clear the counters
644 // clear the counters
621 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
645 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
622
646
623 // rx_eep_err
647 // rx_eep_err
624 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
648 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
625 // rx_truncated
649 // rx_truncated
626 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
650 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
627 // parity_err
651 // parity_err
628 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
652 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
629 // escape_err
653 // escape_err
630 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
654 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
631 // credit_err
655 // credit_err
632 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
656 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
633 // write_sync_err
657 // write_sync_err
634 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
658 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
635 // disconnect_err
659 // disconnect_err
636 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
660 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
637 // early_ep
661 // early_ep
638 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
662 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
639 // invalid_address
663 // invalid_address
640 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
664 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
641 // packets_sent
665 // packets_sent
642 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
666 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
643 // packets_received
667 // packets_received
644 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
668 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
645
669
646 }
670 }
647
671
648 void spacewire_get_last_error( void )
672 void spacewire_get_last_error( void )
649 {
673 {
650 static spw_stats previous = {0};
674 static spw_stats previous = {0};
651 spw_stats current;
675 spw_stats current;
652 rtems_status_code status;
676 rtems_status_code status;
653
677
654 unsigned int hk_lfr_last_er_rid;
678 unsigned int hk_lfr_last_er_rid;
655 unsigned char hk_lfr_last_er_code;
679 unsigned char hk_lfr_last_er_code;
656 int coarseTime;
680 int coarseTime;
657 int fineTime;
681 int fineTime;
658 unsigned char update_hk_lfr_last_er;
682 unsigned char update_hk_lfr_last_er;
659
683
660 memset(&current, 0, sizeof(spw_stats));
684 memset(&current, 0, sizeof(spw_stats));
661 hk_lfr_last_er_rid = INIT_CHAR;
685 hk_lfr_last_er_rid = INIT_CHAR;
662 hk_lfr_last_er_code = INIT_CHAR;
686 hk_lfr_last_er_code = INIT_CHAR;
663 update_hk_lfr_last_er = INIT_CHAR;
687 update_hk_lfr_last_er = INIT_CHAR;
664
688
665 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
689 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
666
690
667 // get current time
691 // get current time
668 coarseTime = time_management_regs->coarse_time;
692 coarseTime = time_management_regs->coarse_time;
669 fineTime = time_management_regs->fine_time;
693 fineTime = time_management_regs->fine_time;
670
694
671 // tx_link_err *** no code associated to this field
695 // tx_link_err *** no code associated to this field
672 // rx_rmap_header_crc_err *** LE *** in HK
696 // rx_rmap_header_crc_err *** LE *** in HK
673 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
697 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
674 {
698 {
675 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
699 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
676 hk_lfr_last_er_code = CODE_HEADER_CRC;
700 hk_lfr_last_er_code = CODE_HEADER_CRC;
677 update_hk_lfr_last_er = 1;
701 update_hk_lfr_last_er = 1;
678 }
702 }
679 // rx_rmap_data_crc_err *** LE *** NOT IN HK
703 // rx_rmap_data_crc_err *** LE *** NOT IN HK
680 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
704 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
681 {
705 {
682 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
706 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
683 hk_lfr_last_er_code = CODE_DATA_CRC;
707 hk_lfr_last_er_code = CODE_DATA_CRC;
684 update_hk_lfr_last_er = 1;
708 update_hk_lfr_last_er = 1;
685 }
709 }
686 // rx_eep_err
710 // rx_eep_err
687 if (previous.rx_eep_err != current.rx_eep_err)
711 if (previous.rx_eep_err != current.rx_eep_err)
688 {
712 {
689 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
713 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
690 hk_lfr_last_er_code = CODE_EEP;
714 hk_lfr_last_er_code = CODE_EEP;
691 update_hk_lfr_last_er = 1;
715 update_hk_lfr_last_er = 1;
692 }
716 }
693 // rx_truncated
717 // rx_truncated
694 if (previous.rx_truncated != current.rx_truncated)
718 if (previous.rx_truncated != current.rx_truncated)
695 {
719 {
696 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
720 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
697 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
721 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
698 update_hk_lfr_last_er = 1;
722 update_hk_lfr_last_er = 1;
699 }
723 }
700 // parity_err
724 // parity_err
701 if (previous.parity_err != current.parity_err)
725 if (previous.parity_err != current.parity_err)
702 {
726 {
703 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
727 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
704 hk_lfr_last_er_code = CODE_PARITY;
728 hk_lfr_last_er_code = CODE_PARITY;
705 update_hk_lfr_last_er = 1;
729 update_hk_lfr_last_er = 1;
706 }
730 }
707 // escape_err
731 // escape_err
708 if (previous.parity_err != current.parity_err)
732 if (previous.parity_err != current.parity_err)
709 {
733 {
710 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
734 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
711 hk_lfr_last_er_code = CODE_ESCAPE;
735 hk_lfr_last_er_code = CODE_ESCAPE;
712 update_hk_lfr_last_er = 1;
736 update_hk_lfr_last_er = 1;
713 }
737 }
714 // credit_err
738 // credit_err
715 if (previous.credit_err != current.credit_err)
739 if (previous.credit_err != current.credit_err)
716 {
740 {
717 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
741 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
718 hk_lfr_last_er_code = CODE_CREDIT;
742 hk_lfr_last_er_code = CODE_CREDIT;
719 update_hk_lfr_last_er = 1;
743 update_hk_lfr_last_er = 1;
720 }
744 }
721 // write_sync_err
745 // write_sync_err
722 if (previous.write_sync_err != current.write_sync_err)
746 if (previous.write_sync_err != current.write_sync_err)
723 {
747 {
724 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
748 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
725 hk_lfr_last_er_code = CODE_WRITE_SYNC;
749 hk_lfr_last_er_code = CODE_WRITE_SYNC;
726 update_hk_lfr_last_er = 1;
750 update_hk_lfr_last_er = 1;
727 }
751 }
728 // disconnect_err
752 // disconnect_err
729 if (previous.disconnect_err != current.disconnect_err)
753 if (previous.disconnect_err != current.disconnect_err)
730 {
754 {
731 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
755 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
732 hk_lfr_last_er_code = CODE_DISCONNECT;
756 hk_lfr_last_er_code = CODE_DISCONNECT;
733 update_hk_lfr_last_er = 1;
757 update_hk_lfr_last_er = 1;
734 }
758 }
735 // early_ep
759 // early_ep
736 if (previous.early_ep != current.early_ep)
760 if (previous.early_ep != current.early_ep)
737 {
761 {
738 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
762 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
739 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
763 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
740 update_hk_lfr_last_er = 1;
764 update_hk_lfr_last_er = 1;
741 }
765 }
742 // invalid_address
766 // invalid_address
743 if (previous.invalid_address != current.invalid_address)
767 if (previous.invalid_address != current.invalid_address)
744 {
768 {
745 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
769 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
746 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
770 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
747 update_hk_lfr_last_er = 1;
771 update_hk_lfr_last_er = 1;
748 }
772 }
749
773
750 // if a field has changed, update the hk_last_er fields
774 // if a field has changed, update the hk_last_er fields
751 if (update_hk_lfr_last_er == 1)
775 if (update_hk_lfr_last_er == 1)
752 {
776 {
753 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
777 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
754 }
778 }
755
779
756 previous = current;
780 previous = current;
757 }
781 }
758
782
759 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
783 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
760 {
784 {
761 unsigned char *coarseTimePtr;
785 unsigned char *coarseTimePtr;
762 unsigned char *fineTimePtr;
786 unsigned char *fineTimePtr;
763
787
764 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
788 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
765 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
789 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
766
790
767 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
791 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
768 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
792 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
769 housekeeping_packet.hk_lfr_last_er_code = code;
793 housekeeping_packet.hk_lfr_last_er_code = code;
770 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
794 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
771 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
795 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
772 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
796 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
773 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
797 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
774 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
798 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
775 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
799 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
776 }
800 }
777
801
778 void update_hk_with_grspw_stats( void )
802 void update_hk_with_grspw_stats( void )
779 {
803 {
780 //****************************
804 //****************************
781 // DPU_SPACEWIRE_IF_STATISTICS
805 // DPU_SPACEWIRE_IF_STATISTICS
782 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
806 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
807 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
784 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
808 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
809 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
786
810
787 //******************************************
811 //******************************************
788 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
812 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
789 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
813 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
790 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
814 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
791 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
815 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
792 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
816 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
793 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
817 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
794
818
795 //*********************************************
819 //*********************************************
796 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
820 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
797 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
821 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
798 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
822 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
799 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
823 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
800 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
824 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
801 }
825 }
802
826
803 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
827 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
804 {
828 {
805 unsigned int *statusRegisterPtr;
829 unsigned int *statusRegisterPtr;
806 unsigned char linkState;
830 unsigned char linkState;
807
831
808 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
832 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
809 linkState =
833 linkState =
810 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
834 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
811
835
812 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
836 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
813
837
814 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
838 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
815 }
839 }
816
840
817 void increase_unsigned_char_counter( unsigned char *counter )
841 void increase_unsigned_char_counter( unsigned char *counter )
818 {
842 {
819 // update the number of valid timecodes that have been received
843 // update the number of valid timecodes that have been received
820 if (*counter == UINT8_MAX)
844 if (*counter == UINT8_MAX)
821 {
845 {
822 *counter = 0;
846 *counter = 0;
823 }
847 }
824 else
848 else
825 {
849 {
826 *counter = *counter + 1;
850 *counter = *counter + 1;
827 }
851 }
828 }
852 }
829
853
830 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
854 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
831 {
855 {
832 /** This function checks the coherency between the incoming timecode and the last valid timecode.
856 /** This function checks the coherency between the incoming timecode and the last valid timecode.
833 *
857 *
834 * @param currentTimecodeCtr is the incoming timecode
858 * @param currentTimecodeCtr is the incoming timecode
835 *
859 *
836 * @return returned codes::
860 * @return returned codes::
837 * - LFR_DEFAULT
861 * - LFR_DEFAULT
838 * - LFR_SUCCESSFUL
862 * - LFR_SUCCESSFUL
839 *
863 *
840 */
864 */
841
865
842 static unsigned char firstTickout = 1;
866 static unsigned char firstTickout = 1;
843 unsigned char ret;
867 unsigned char ret;
844
868
845 ret = LFR_DEFAULT;
869 ret = LFR_DEFAULT;
846
870
847 if (firstTickout == 0)
871 if (firstTickout == 0)
848 {
872 {
849 if (currentTimecodeCtr == 0)
873 if (currentTimecodeCtr == 0)
850 {
874 {
851 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
875 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
852 {
876 {
853 ret = LFR_SUCCESSFUL;
877 ret = LFR_SUCCESSFUL;
854 }
878 }
855 else
879 else
856 {
880 {
857 ret = LFR_DEFAULT;
881 ret = LFR_DEFAULT;
858 }
882 }
859 }
883 }
860 else
884 else
861 {
885 {
862 if (currentTimecodeCtr == (previousTimecodeCtr +1))
886 if (currentTimecodeCtr == (previousTimecodeCtr +1))
863 {
887 {
864 ret = LFR_SUCCESSFUL;
888 ret = LFR_SUCCESSFUL;
865 }
889 }
866 else
890 else
867 {
891 {
868 ret = LFR_DEFAULT;
892 ret = LFR_DEFAULT;
869 }
893 }
870 }
894 }
871 }
895 }
872 else
896 else
873 {
897 {
874 firstTickout = 0;
898 firstTickout = 0;
875 ret = LFR_SUCCESSFUL;
899 ret = LFR_SUCCESSFUL;
876 }
900 }
877
901
878 return ret;
902 return ret;
879 }
903 }
880
904
881 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
905 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
882 {
906 {
883 unsigned int ret;
907 unsigned int ret;
884
908
885 ret = LFR_DEFAULT;
909 ret = LFR_DEFAULT;
886
910
887 if (timecode == internalTime)
911 if (timecode == internalTime)
888 {
912 {
889 ret = LFR_SUCCESSFUL;
913 ret = LFR_SUCCESSFUL;
890 }
914 }
891 else
915 else
892 {
916 {
893 ret = LFR_DEFAULT;
917 ret = LFR_DEFAULT;
894 }
918 }
895
919
896 return ret;
920 return ret;
897 }
921 }
898
922
899 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
923 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
900 {
924 {
901 // a tickout has been emitted, perform actions on the incoming timecode
925 // a tickout has been emitted, perform actions on the incoming timecode
902
926
903 unsigned char incomingTimecode;
927 unsigned char incomingTimecode;
904 unsigned char updateTime;
928 unsigned char updateTime;
905 unsigned char internalTime;
929 unsigned char internalTime;
906 rtems_status_code status;
930 rtems_status_code status;
907
931
908 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
932 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
909 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
933 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
910 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
934 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
911
935
912 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
936 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
913
937
914 // update the number of tickout that have been generated
938 // update the number of tickout that have been generated
915 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
939 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
916
940
917 //**************************
941 //**************************
918 // HK_LFR_TIMECODE_ERRONEOUS
942 // HK_LFR_TIMECODE_ERRONEOUS
919 // MISSING and INVALID are handled by the timecode_timer_routine service routine
943 // MISSING and INVALID are handled by the timecode_timer_routine service routine
920 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
944 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
921 {
945 {
922 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
946 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
923 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
947 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
924 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
948 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
925 }
949 }
926
950
927 //************************
951 //************************
928 // HK_LFR_TIME_TIMECODE_IT
952 // HK_LFR_TIME_TIMECODE_IT
929 // check the coherency between the SpaceWire timecode and the Internal Time
953 // check the coherency between the SpaceWire timecode and the Internal Time
930 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
954 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
931 {
955 {
932 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
956 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
933 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
957 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
934 }
958 }
935
959
936 //********************
960 //********************
937 // HK_LFR_TIMECODE_CTR
961 // HK_LFR_TIMECODE_CTR
938 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
962 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
939 if (oneTcLfrUpdateTimeReceived == 1)
963 if (oneTcLfrUpdateTimeReceived == 1)
940 {
964 {
941 if ( incomingTimecode != updateTime )
965 if ( incomingTimecode != updateTime )
942 {
966 {
943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
967 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
968 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
945 }
969 }
946 }
970 }
947
971
948 // launch the timecode timer to detect missing or invalid timecodes
972 // launch the timecode timer to detect missing or invalid timecodes
949 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
973 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
950 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
974 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
951 if (status != RTEMS_SUCCESSFUL)
975 if (status != RTEMS_SUCCESSFUL)
952 {
976 {
953 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
977 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
954 }
978 }
955 }
979 }
956
980
957 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
981 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
958 {
982 {
959 static unsigned char initStep = 1;
983 static unsigned char initStep = 1;
960
984
961 unsigned char currentTimecodeCtr;
985 unsigned char currentTimecodeCtr;
962
986
963 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
987 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
964
988
965 if (initStep == 1)
989 if (initStep == 1)
966 {
990 {
967 if (currentTimecodeCtr == previousTimecodeCtr)
991 if (currentTimecodeCtr == previousTimecodeCtr)
968 {
992 {
969 //************************
993 //************************
970 // HK_LFR_TIMECODE_MISSING
994 // HK_LFR_TIMECODE_MISSING
971 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
995 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
972 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
996 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
997 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
974 }
998 }
975 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
999 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
976 {
1000 {
977 // the timecode value has changed and the value is valid, this is unexpected because
1001 // the timecode value has changed and the value is valid, this is unexpected because
978 // the timer should not have fired, the timecode_irq_handler should have been raised
1002 // the timer should not have fired, the timecode_irq_handler should have been raised
979 }
1003 }
980 else
1004 else
981 {
1005 {
982 //************************
1006 //************************
983 // HK_LFR_TIMECODE_INVALID
1007 // HK_LFR_TIMECODE_INVALID
984 // the timecode value has changed and the value is not valid, no tickout has been generated
1008 // the timecode value has changed and the value is not valid, no tickout has been generated
985 // this is why the timer has fired
1009 // this is why the timer has fired
986 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
1010 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
987 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
1011 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
988 }
1012 }
989 }
1013 }
990 else
1014 else
991 {
1015 {
992 initStep = 1;
1016 initStep = 1;
993 //************************
1017 //************************
994 // HK_LFR_TIMECODE_MISSING
1018 // HK_LFR_TIMECODE_MISSING
995 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1019 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
996 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1020 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
997 }
1021 }
998
1022
999 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1023 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1000 }
1024 }
1001
1025
1002 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1026 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1003 {
1027 {
1004 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1028 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1005 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1029 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1006 header->reserved = DEFAULT_RESERVED;
1030 header->reserved = DEFAULT_RESERVED;
1007 header->userApplication = CCSDS_USER_APP;
1031 header->userApplication = CCSDS_USER_APP;
1008 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1032 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1009 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1033 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1010 header->packetLength[0] = INIT_CHAR;
1034 header->packetLength[0] = INIT_CHAR;
1011 header->packetLength[1] = INIT_CHAR;
1035 header->packetLength[1] = INIT_CHAR;
1012 // DATA FIELD HEADER
1036 // DATA FIELD HEADER
1013 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1037 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1014 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1038 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1015 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1039 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1016 header->destinationID = TM_DESTINATION_ID_GROUND;
1040 header->destinationID = TM_DESTINATION_ID_GROUND;
1017 header->time[BYTE_0] = INIT_CHAR;
1041 header->time[BYTE_0] = INIT_CHAR;
1018 header->time[BYTE_1] = INIT_CHAR;
1042 header->time[BYTE_1] = INIT_CHAR;
1019 header->time[BYTE_2] = INIT_CHAR;
1043 header->time[BYTE_2] = INIT_CHAR;
1020 header->time[BYTE_3] = INIT_CHAR;
1044 header->time[BYTE_3] = INIT_CHAR;
1021 header->time[BYTE_4] = INIT_CHAR;
1045 header->time[BYTE_4] = INIT_CHAR;
1022 header->time[BYTE_5] = INIT_CHAR;
1046 header->time[BYTE_5] = INIT_CHAR;
1023 // AUXILIARY DATA HEADER
1047 // AUXILIARY DATA HEADER
1024 header->sid = INIT_CHAR;
1048 header->sid = INIT_CHAR;
1025 header->pa_bia_status_info = DEFAULT_HKBIA;
1049 header->pa_bia_status_info = DEFAULT_HKBIA;
1026 header->blkNr[0] = INIT_CHAR;
1050 header->blkNr[0] = INIT_CHAR;
1027 header->blkNr[1] = INIT_CHAR;
1051 header->blkNr[1] = INIT_CHAR;
1028 }
1052 }
1029
1053
1030 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1054 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1031 {
1055 {
1032 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1056 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1033 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1057 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1034 header->reserved = DEFAULT_RESERVED;
1058 header->reserved = DEFAULT_RESERVED;
1035 header->userApplication = CCSDS_USER_APP;
1059 header->userApplication = CCSDS_USER_APP;
1036 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1060 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1037 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1061 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1038 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1062 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1039 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1063 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1040 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1064 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1041 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1065 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1042 // DATA FIELD HEADER
1066 // DATA FIELD HEADER
1043 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1067 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1044 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1068 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1045 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1069 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1046 header->destinationID = TM_DESTINATION_ID_GROUND;
1070 header->destinationID = TM_DESTINATION_ID_GROUND;
1047 header->time[BYTE_0] = INIT_CHAR;
1071 header->time[BYTE_0] = INIT_CHAR;
1048 header->time[BYTE_1] = INIT_CHAR;
1072 header->time[BYTE_1] = INIT_CHAR;
1049 header->time[BYTE_2] = INIT_CHAR;
1073 header->time[BYTE_2] = INIT_CHAR;
1050 header->time[BYTE_3] = INIT_CHAR;
1074 header->time[BYTE_3] = INIT_CHAR;
1051 header->time[BYTE_4] = INIT_CHAR;
1075 header->time[BYTE_4] = INIT_CHAR;
1052 header->time[BYTE_5] = INIT_CHAR;
1076 header->time[BYTE_5] = INIT_CHAR;
1053 // AUXILIARY DATA HEADER
1077 // AUXILIARY DATA HEADER
1054 header->sid = INIT_CHAR;
1078 header->sid = INIT_CHAR;
1055 header->pa_bia_status_info = DEFAULT_HKBIA;
1079 header->pa_bia_status_info = DEFAULT_HKBIA;
1056 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1080 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1057 header->pktNr = INIT_CHAR;
1081 header->pktNr = INIT_CHAR;
1058 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1082 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1059 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1083 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1060 }
1084 }
1061
1085
1062 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1086 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1063 {
1087 {
1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1088 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1089 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1066 header->reserved = DEFAULT_RESERVED;
1090 header->reserved = DEFAULT_RESERVED;
1067 header->userApplication = CCSDS_USER_APP;
1091 header->userApplication = CCSDS_USER_APP;
1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1092 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1093 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1094 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1095 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1072 header->packetLength[0] = INIT_CHAR;
1096 header->packetLength[0] = INIT_CHAR;
1073 header->packetLength[1] = INIT_CHAR;
1097 header->packetLength[1] = INIT_CHAR;
1074 // DATA FIELD HEADER
1098 // DATA FIELD HEADER
1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1099 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1100 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1101 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1102 header->destinationID = TM_DESTINATION_ID_GROUND;
1079 header->time[BYTE_0] = INIT_CHAR;
1103 header->time[BYTE_0] = INIT_CHAR;
1080 header->time[BYTE_1] = INIT_CHAR;
1104 header->time[BYTE_1] = INIT_CHAR;
1081 header->time[BYTE_2] = INIT_CHAR;
1105 header->time[BYTE_2] = INIT_CHAR;
1082 header->time[BYTE_3] = INIT_CHAR;
1106 header->time[BYTE_3] = INIT_CHAR;
1083 header->time[BYTE_4] = INIT_CHAR;
1107 header->time[BYTE_4] = INIT_CHAR;
1084 header->time[BYTE_5] = INIT_CHAR;
1108 header->time[BYTE_5] = INIT_CHAR;
1085 // AUXILIARY DATA HEADER
1109 // AUXILIARY DATA HEADER
1086 header->sid = INIT_CHAR;
1110 header->sid = INIT_CHAR;
1087 header->pa_bia_status_info = INIT_CHAR;
1111 header->pa_bia_status_info = INIT_CHAR;
1088 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1112 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1089 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1113 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1090 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1114 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1091 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1115 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1092 }
1116 }
1093
1117
1094 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1118 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1095 Header_TM_LFR_SCIENCE_CWF_t *header )
1119 Header_TM_LFR_SCIENCE_CWF_t *header )
1096 {
1120 {
1097 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1121 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1098 *
1122 *
1099 * @param waveform points to the buffer containing the data that will be send.
1123 * @param waveform points to the buffer containing the data that will be send.
1100 * @param sid is the source identifier of the data that will be sent.
1124 * @param sid is the source identifier of the data that will be sent.
1101 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1125 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1102 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1126 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1103 * contain information to setup the transmission of the data packets.
1127 * contain information to setup the transmission of the data packets.
1104 *
1128 *
1105 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1129 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1106 *
1130 *
1107 */
1131 */
1108
1132
1109 unsigned int i;
1133 unsigned int i;
1110 int ret;
1134 int ret;
1111 unsigned int coarseTime;
1135 unsigned int coarseTime;
1112 unsigned int fineTime;
1136 unsigned int fineTime;
1113 rtems_status_code status;
1137 rtems_status_code status;
1114 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1138 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1115 int *dataPtr;
1139 int *dataPtr;
1116 unsigned char sid;
1140 unsigned char sid;
1117
1141
1118 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1142 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1119 spw_ioctl_send_CWF.options = 0;
1143 spw_ioctl_send_CWF.options = 0;
1120
1144
1121 ret = LFR_DEFAULT;
1145 ret = LFR_DEFAULT;
1122 sid = (unsigned char) ring_node_to_send->sid;
1146 sid = (unsigned char) ring_node_to_send->sid;
1123
1147
1124 coarseTime = ring_node_to_send->coarseTime;
1148 coarseTime = ring_node_to_send->coarseTime;
1125 fineTime = ring_node_to_send->fineTime;
1149 fineTime = ring_node_to_send->fineTime;
1126 dataPtr = (int*) ring_node_to_send->buffer_address;
1150 dataPtr = (int*) ring_node_to_send->buffer_address;
1127
1151
1128 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1152 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1129 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1153 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1130 header->pa_bia_status_info = pa_bia_status_info;
1154 header->pa_bia_status_info = pa_bia_status_info;
1131 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1155 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1132 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1156 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1133 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1157 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1134
1158
1135 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1159 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1136 {
1160 {
1137 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1161 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1138 spw_ioctl_send_CWF.hdr = (char*) header;
1162 spw_ioctl_send_CWF.hdr = (char*) header;
1139 // BUILD THE DATA
1163 // BUILD THE DATA
1140 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1164 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1141
1165
1142 // SET PACKET SEQUENCE CONTROL
1166 // SET PACKET SEQUENCE CONTROL
1143 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1167 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1144
1168
1145 // SET SID
1169 // SET SID
1146 header->sid = sid;
1170 header->sid = sid;
1147
1171
1148 // SET PACKET TIME
1172 // SET PACKET TIME
1149 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1173 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1150 //
1174 //
1151 header->time[0] = header->acquisitionTime[0];
1175 header->time[0] = header->acquisitionTime[0];
1152 header->time[1] = header->acquisitionTime[1];
1176 header->time[1] = header->acquisitionTime[1];
1153 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1177 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1154 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1178 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1155 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1179 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1156 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1180 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1157
1181
1158 // SET PACKET ID
1182 // SET PACKET ID
1159 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1183 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1160 {
1184 {
1161 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1185 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1162 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1186 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1163 }
1187 }
1164 else
1188 else
1165 {
1189 {
1166 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1190 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1167 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1191 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1168 }
1192 }
1169
1193
1170 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1194 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1171 if (status != RTEMS_SUCCESSFUL) {
1195 if (status != RTEMS_SUCCESSFUL) {
1172 ret = LFR_DEFAULT;
1196 ret = LFR_DEFAULT;
1173 }
1197 }
1174 }
1198 }
1175
1199
1176 return ret;
1200 return ret;
1177 }
1201 }
1178
1202
1179 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1203 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1180 Header_TM_LFR_SCIENCE_SWF_t *header )
1204 Header_TM_LFR_SCIENCE_SWF_t *header )
1181 {
1205 {
1182 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1206 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1183 *
1207 *
1184 * @param waveform points to the buffer containing the data that will be send.
1208 * @param waveform points to the buffer containing the data that will be send.
1185 * @param sid is the source identifier of the data that will be sent.
1209 * @param sid is the source identifier of the data that will be sent.
1186 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1210 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1187 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1211 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1188 * contain information to setup the transmission of the data packets.
1212 * contain information to setup the transmission of the data packets.
1189 *
1213 *
1190 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1214 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1191 *
1215 *
1192 */
1216 */
1193
1217
1194 unsigned int i;
1218 unsigned int i;
1195 int ret;
1219 int ret;
1196 unsigned int coarseTime;
1220 unsigned int coarseTime;
1197 unsigned int fineTime;
1221 unsigned int fineTime;
1198 rtems_status_code status;
1222 rtems_status_code status;
1199 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1223 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1200 int *dataPtr;
1224 int *dataPtr;
1201 unsigned char sid;
1225 unsigned char sid;
1202
1226
1203 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1227 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1204 spw_ioctl_send_SWF.options = 0;
1228 spw_ioctl_send_SWF.options = 0;
1205
1229
1206 ret = LFR_DEFAULT;
1230 ret = LFR_DEFAULT;
1207
1231
1208 coarseTime = ring_node_to_send->coarseTime;
1232 coarseTime = ring_node_to_send->coarseTime;
1209 fineTime = ring_node_to_send->fineTime;
1233 fineTime = ring_node_to_send->fineTime;
1210 dataPtr = (int*) ring_node_to_send->buffer_address;
1234 dataPtr = (int*) ring_node_to_send->buffer_address;
1211 sid = ring_node_to_send->sid;
1235 sid = ring_node_to_send->sid;
1212
1236
1213 header->pa_bia_status_info = pa_bia_status_info;
1237 header->pa_bia_status_info = pa_bia_status_info;
1214 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1238 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1215
1239
1216 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1240 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1217 {
1241 {
1218 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1242 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1219 spw_ioctl_send_SWF.hdr = (char*) header;
1243 spw_ioctl_send_SWF.hdr = (char*) header;
1220
1244
1221 // SET PACKET SEQUENCE CONTROL
1245 // SET PACKET SEQUENCE CONTROL
1222 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1246 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1223
1247
1224 // SET PACKET LENGTH AND BLKNR
1248 // SET PACKET LENGTH AND BLKNR
1225 if (i == (PKTCNT_SWF-1))
1249 if (i == (PKTCNT_SWF-1))
1226 {
1250 {
1227 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1251 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1228 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1252 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1229 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1253 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1230 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1254 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1231 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1255 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1232 }
1256 }
1233 else
1257 else
1234 {
1258 {
1235 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1259 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1236 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1260 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1237 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1261 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1238 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1262 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1239 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1263 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1240 }
1264 }
1241
1265
1242 // SET PACKET TIME
1266 // SET PACKET TIME
1243 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1267 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1244 //
1268 //
1245 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1269 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1246 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1270 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1247 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1271 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1248 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1272 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1249 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1273 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1250 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1274 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1251
1275
1252 // SET SID
1276 // SET SID
1253 header->sid = sid;
1277 header->sid = sid;
1254
1278
1255 // SET PKTNR
1279 // SET PKTNR
1256 header->pktNr = i+1; // PKT_NR
1280 header->pktNr = i+1; // PKT_NR
1257
1281
1258 // SEND PACKET
1282 // SEND PACKET
1259 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1283 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1260 if (status != RTEMS_SUCCESSFUL) {
1284 if (status != RTEMS_SUCCESSFUL) {
1261 ret = LFR_DEFAULT;
1285 ret = LFR_DEFAULT;
1262 }
1286 }
1263 }
1287 }
1264
1288
1265 return ret;
1289 return ret;
1266 }
1290 }
1267
1291
1268 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1292 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1269 Header_TM_LFR_SCIENCE_CWF_t *header )
1293 Header_TM_LFR_SCIENCE_CWF_t *header )
1270 {
1294 {
1271 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1295 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1272 *
1296 *
1273 * @param waveform points to the buffer containing the data that will be send.
1297 * @param waveform points to the buffer containing the data that will be send.
1274 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1298 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1275 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1299 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1276 * contain information to setup the transmission of the data packets.
1300 * contain information to setup the transmission of the data packets.
1277 *
1301 *
1278 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1302 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1279 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1303 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1280 *
1304 *
1281 */
1305 */
1282
1306
1283 unsigned int i;
1307 unsigned int i;
1284 int ret;
1308 int ret;
1285 unsigned int coarseTime;
1309 unsigned int coarseTime;
1286 unsigned int fineTime;
1310 unsigned int fineTime;
1287 rtems_status_code status;
1311 rtems_status_code status;
1288 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1312 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1289 char *dataPtr;
1313 char *dataPtr;
1290 unsigned char sid;
1314 unsigned char sid;
1291
1315
1292 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1316 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1293 spw_ioctl_send_CWF.options = 0;
1317 spw_ioctl_send_CWF.options = 0;
1294
1318
1295 ret = LFR_DEFAULT;
1319 ret = LFR_DEFAULT;
1296 sid = ring_node_to_send->sid;
1320 sid = ring_node_to_send->sid;
1297
1321
1298 coarseTime = ring_node_to_send->coarseTime;
1322 coarseTime = ring_node_to_send->coarseTime;
1299 fineTime = ring_node_to_send->fineTime;
1323 fineTime = ring_node_to_send->fineTime;
1300 dataPtr = (char*) ring_node_to_send->buffer_address;
1324 dataPtr = (char*) ring_node_to_send->buffer_address;
1301
1325
1302 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1326 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1303 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1327 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1304 header->pa_bia_status_info = pa_bia_status_info;
1328 header->pa_bia_status_info = pa_bia_status_info;
1305 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1329 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1306 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1330 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1307 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1331 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1308
1332
1309 //*********************
1333 //*********************
1310 // SEND CWF3_light DATA
1334 // SEND CWF3_light DATA
1311 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1335 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1312 {
1336 {
1313 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1337 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1314 spw_ioctl_send_CWF.hdr = (char*) header;
1338 spw_ioctl_send_CWF.hdr = (char*) header;
1315 // BUILD THE DATA
1339 // BUILD THE DATA
1316 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1340 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1317
1341
1318 // SET PACKET SEQUENCE COUNTER
1342 // SET PACKET SEQUENCE COUNTER
1319 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1343 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1320
1344
1321 // SET SID
1345 // SET SID
1322 header->sid = sid;
1346 header->sid = sid;
1323
1347
1324 // SET PACKET TIME
1348 // SET PACKET TIME
1325 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1349 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1326 //
1350 //
1327 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1351 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1328 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1352 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1329 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1353 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1330 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1354 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1331 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1355 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1332 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1356 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1333
1357
1334 // SET PACKET ID
1358 // SET PACKET ID
1335 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1359 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1336 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1360 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1337
1361
1338 // SEND PACKET
1362 // SEND PACKET
1339 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1363 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1340 if (status != RTEMS_SUCCESSFUL) {
1364 if (status != RTEMS_SUCCESSFUL) {
1341 ret = LFR_DEFAULT;
1365 ret = LFR_DEFAULT;
1342 }
1366 }
1343 }
1367 }
1344
1368
1345 return ret;
1369 return ret;
1346 }
1370 }
1347
1371
1348 void spw_send_asm_f0( ring_node *ring_node_to_send,
1372 void spw_send_asm_f0( ring_node *ring_node_to_send,
1349 Header_TM_LFR_SCIENCE_ASM_t *header )
1373 Header_TM_LFR_SCIENCE_ASM_t *header )
1350 {
1374 {
1351 unsigned int i;
1375 unsigned int i;
1352 unsigned int length = 0;
1376 unsigned int length = 0;
1353 rtems_status_code status;
1377 rtems_status_code status;
1354 unsigned int sid;
1378 unsigned int sid;
1355 float *spectral_matrix;
1379 float *spectral_matrix;
1356 int coarseTime;
1380 int coarseTime;
1357 int fineTime;
1381 int fineTime;
1358 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1382 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1359
1383
1360 sid = ring_node_to_send->sid;
1384 sid = ring_node_to_send->sid;
1361 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1385 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1362 coarseTime = ring_node_to_send->coarseTime;
1386 coarseTime = ring_node_to_send->coarseTime;
1363 fineTime = ring_node_to_send->fineTime;
1387 fineTime = ring_node_to_send->fineTime;
1364
1388
1365 header->pa_bia_status_info = pa_bia_status_info;
1389 header->pa_bia_status_info = pa_bia_status_info;
1366 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1390 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1367
1391
1368 for (i=0; i<PKTCNT_ASM; i++)
1392 for (i=0; i<PKTCNT_ASM; i++)
1369 {
1393 {
1370 if ((i==0) || (i==1))
1394 if ((i==0) || (i==1))
1371 {
1395 {
1372 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1396 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1373 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1397 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1374 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1398 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1375 ];
1399 ];
1376 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1400 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1377 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1401 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1378 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1402 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1379 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1403 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1380 }
1404 }
1381 else
1405 else
1382 {
1406 {
1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1407 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1384 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1408 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1409 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1386 ];
1410 ];
1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1411 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1412 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1413 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1414 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1391 }
1415 }
1392
1416
1393 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1417 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1394 spw_ioctl_send_ASM.hdr = (char *) header;
1418 spw_ioctl_send_ASM.hdr = (char *) header;
1395 spw_ioctl_send_ASM.options = 0;
1419 spw_ioctl_send_ASM.options = 0;
1396
1420
1397 // (2) BUILD THE HEADER
1421 // (2) BUILD THE HEADER
1398 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1422 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1399 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1423 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1400 header->packetLength[1] = (unsigned char) (length);
1424 header->packetLength[1] = (unsigned char) (length);
1401 header->sid = (unsigned char) sid; // SID
1425 header->sid = (unsigned char) sid; // SID
1402 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1426 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1403 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1427 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1404
1428
1405 // (3) SET PACKET TIME
1429 // (3) SET PACKET TIME
1406 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1430 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1407 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1431 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1408 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1432 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1409 header->time[BYTE_3] = (unsigned char) (coarseTime);
1433 header->time[BYTE_3] = (unsigned char) (coarseTime);
1410 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1434 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1411 header->time[BYTE_5] = (unsigned char) (fineTime);
1435 header->time[BYTE_5] = (unsigned char) (fineTime);
1412 //
1436 //
1413 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1437 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1414 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1438 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1415 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1439 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1416 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1440 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1417 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1441 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1418 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1442 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1419
1443
1420 // (4) SEND PACKET
1444 // (4) SEND PACKET
1421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1445 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1422 if (status != RTEMS_SUCCESSFUL) {
1446 if (status != RTEMS_SUCCESSFUL) {
1423 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1447 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1424 }
1448 }
1425 }
1449 }
1426 }
1450 }
1427
1451
1428 void spw_send_asm_f1( ring_node *ring_node_to_send,
1452 void spw_send_asm_f1( ring_node *ring_node_to_send,
1429 Header_TM_LFR_SCIENCE_ASM_t *header )
1453 Header_TM_LFR_SCIENCE_ASM_t *header )
1430 {
1454 {
1431 unsigned int i;
1455 unsigned int i;
1432 unsigned int length = 0;
1456 unsigned int length = 0;
1433 rtems_status_code status;
1457 rtems_status_code status;
1434 unsigned int sid;
1458 unsigned int sid;
1435 float *spectral_matrix;
1459 float *spectral_matrix;
1436 int coarseTime;
1460 int coarseTime;
1437 int fineTime;
1461 int fineTime;
1438 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1462 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1439
1463
1440 sid = ring_node_to_send->sid;
1464 sid = ring_node_to_send->sid;
1441 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1465 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1442 coarseTime = ring_node_to_send->coarseTime;
1466 coarseTime = ring_node_to_send->coarseTime;
1443 fineTime = ring_node_to_send->fineTime;
1467 fineTime = ring_node_to_send->fineTime;
1444
1468
1445 header->pa_bia_status_info = pa_bia_status_info;
1469 header->pa_bia_status_info = pa_bia_status_info;
1446 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1470 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1447
1471
1448 for (i=0; i<PKTCNT_ASM; i++)
1472 for (i=0; i<PKTCNT_ASM; i++)
1449 {
1473 {
1450 if ((i==0) || (i==1))
1474 if ((i==0) || (i==1))
1451 {
1475 {
1452 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1476 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1453 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1477 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1454 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1478 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1455 ];
1479 ];
1456 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1480 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1457 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1481 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1458 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1482 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1459 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1483 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1460 }
1484 }
1461 else
1485 else
1462 {
1486 {
1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1487 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1464 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1488 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1489 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1466 ];
1490 ];
1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1491 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1492 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1493 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1494 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1471 }
1495 }
1472
1496
1473 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1497 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1474 spw_ioctl_send_ASM.hdr = (char *) header;
1498 spw_ioctl_send_ASM.hdr = (char *) header;
1475 spw_ioctl_send_ASM.options = 0;
1499 spw_ioctl_send_ASM.options = 0;
1476
1500
1477 // (2) BUILD THE HEADER
1501 // (2) BUILD THE HEADER
1478 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1502 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1479 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1503 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1480 header->packetLength[1] = (unsigned char) (length);
1504 header->packetLength[1] = (unsigned char) (length);
1481 header->sid = (unsigned char) sid; // SID
1505 header->sid = (unsigned char) sid; // SID
1482 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1506 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1483 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1507 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1484
1508
1485 // (3) SET PACKET TIME
1509 // (3) SET PACKET TIME
1486 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1510 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1487 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1511 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1488 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1512 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1489 header->time[BYTE_3] = (unsigned char) (coarseTime);
1513 header->time[BYTE_3] = (unsigned char) (coarseTime);
1490 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1514 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1491 header->time[BYTE_5] = (unsigned char) (fineTime);
1515 header->time[BYTE_5] = (unsigned char) (fineTime);
1492 //
1516 //
1493 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1517 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1494 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1518 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1495 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1519 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1496 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1520 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1497 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1521 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1498 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1522 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1499
1523
1500 // (4) SEND PACKET
1524 // (4) SEND PACKET
1501 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1525 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1502 if (status != RTEMS_SUCCESSFUL) {
1526 if (status != RTEMS_SUCCESSFUL) {
1503 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1527 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1504 }
1528 }
1505 }
1529 }
1506 }
1530 }
1507
1531
1508 /**
1532 /**
1509 * @brief spw_send_asm_f2 Sends an ASM packet at F2 over spacewire
1533 * @brief spw_send_asm_f2 Sends an ASM packet at F2 over spacewire
1510 * @param ring_node_to_send node pointing to the actual buffer to send
1534 * @param ring_node_to_send node pointing to the actual buffer to send
1511 * @param header
1535 * @param header
1512 */
1536 */
1513 void spw_send_asm_f2( ring_node *ring_node_to_send,
1537 void spw_send_asm_f2( ring_node *ring_node_to_send,
1514 Header_TM_LFR_SCIENCE_ASM_t *header )
1538 Header_TM_LFR_SCIENCE_ASM_t *header )
1515 {
1539 {
1516 unsigned int i;
1540 unsigned int i;
1517 unsigned int length = 0;
1541 unsigned int length = 0;
1518 rtems_status_code status;
1542 rtems_status_code status;
1519 unsigned int sid;
1543 unsigned int sid;
1520 float *spectral_matrix;
1544 float *spectral_matrix;
1521 int coarseTime;
1545 int coarseTime;
1522 int fineTime;
1546 int fineTime;
1523 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1547 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1524
1548
1525 sid = ring_node_to_send->sid;
1549 sid = ring_node_to_send->sid;
1526 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1550 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1527 coarseTime = ring_node_to_send->coarseTime;
1551 coarseTime = ring_node_to_send->coarseTime;
1528 fineTime = ring_node_to_send->fineTime;
1552 fineTime = ring_node_to_send->fineTime;
1529
1553
1530 header->pa_bia_status_info = pa_bia_status_info;
1554 header->pa_bia_status_info = pa_bia_status_info;
1531 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1555 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1532
1556
1533 for (i=0; i<PKTCNT_ASM; i++)
1557 for (i=0; i<PKTCNT_ASM; i++)
1534 {
1558 {
1535
1559
1536 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1560 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1537 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1561 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1538 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1562 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1539 ];
1563 ];
1540 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1564 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1541 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1565 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1542 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1566 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1543 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1567 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1544
1568
1545 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1569 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1546 spw_ioctl_send_ASM.hdr = (char *) header;
1570 spw_ioctl_send_ASM.hdr = (char *) header;
1547 spw_ioctl_send_ASM.options = 0;
1571 spw_ioctl_send_ASM.options = 0;
1548
1572
1549 // (2) BUILD THE HEADER
1573 // (2) BUILD THE HEADER
1550 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1574 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1551 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1575 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1552 header->packetLength[1] = (unsigned char) (length);
1576 header->packetLength[1] = (unsigned char) (length);
1553 header->sid = (unsigned char) sid; // SID
1577 header->sid = (unsigned char) sid; // SID
1554 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1578 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1555 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1579 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1556
1580
1557 // (3) SET PACKET TIME
1581 // (3) SET PACKET TIME
1558 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1582 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1559 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1583 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1560 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1584 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1561 header->time[BYTE_3] = (unsigned char) (coarseTime);
1585 header->time[BYTE_3] = (unsigned char) (coarseTime);
1562 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1586 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1563 header->time[BYTE_5] = (unsigned char) (fineTime);
1587 header->time[BYTE_5] = (unsigned char) (fineTime);
1564 //
1588 //
1565 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1589 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1566 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1590 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1567 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1591 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1568 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1592 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1569 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1593 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1570 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1594 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1571
1595
1572 // (4) SEND PACKET
1596 // (4) SEND PACKET
1573 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1597 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1574 if (status != RTEMS_SUCCESSFUL) {
1598 if (status != RTEMS_SUCCESSFUL) {
1575 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1599 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1576 }
1600 }
1577 }
1601 }
1578 }
1602 }
1579
1603
1580 /**
1604 /**
1581 * @brief spw_send_k_dump Sends k coefficients dump packet over spacewire
1605 * @brief spw_send_k_dump Sends k coefficients dump packet over spacewire
1582 * @param ring_node_to_send node pointing to the actual buffer to send
1606 * @param ring_node_to_send node pointing to the actual buffer to send
1583 */
1607 */
1584 void spw_send_k_dump( ring_node *ring_node_to_send )
1608 void spw_send_k_dump( ring_node *ring_node_to_send )
1585 {
1609 {
1586 rtems_status_code status;
1610 rtems_status_code status;
1587 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1611 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1588 unsigned int packetLength;
1612 unsigned int packetLength;
1589 unsigned int size;
1613 unsigned int size;
1590
1614
1591 PRINTF("spw_send_k_dump\n")
1615 PRINTF("spw_send_k_dump\n")
1592
1616
1593 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1617 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1594
1618
1595 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1619 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1596
1620
1597 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1621 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1598
1622
1599 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1623 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1600
1624
1601 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1625 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1602
1626
1603 if (status == -1){
1627 if (status == -1){
1604 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1628 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1605 }
1629 }
1606
1630
1607 ring_node_to_send->status = INIT_CHAR;
1631 ring_node_to_send->status = INIT_CHAR;
1608 }
1632 }
@@ -1,423 +1,447
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "avf0_prc0.h"
34 #include "avf0_prc0.h"
11
35
12 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
36 nb_sm_before_bp_asm_f0 nb_sm_before_f0 = {0};
13
37
14 //***
38 //***
15 // F0
39 // F0
16 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
40 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
41 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ] = {0};
18
42
19 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
43 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ] = {0};
20 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
44 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ] = {0};
21
45
22 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
46 float asm_f0_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
47 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
48 float asm_f0_reorganized [ TOTAL_SIZE_SM ] = {0};
25
49
26 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
50 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0] = {0};
27 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
51 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ] = {0};
28
52
29 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
53 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 11 * 32 = 352
30 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
54 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ] = {0}; // 22 * 32 = 704
31
55
32 //************
56 //************
33 // RTEMS TASKS
57 // RTEMS TASKS
34
58
35 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
59 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
36 {
60 {
37 int i;
61 int i;
38
62
39 rtems_event_set event_out;
63 rtems_event_set event_out;
40 rtems_status_code status;
64 rtems_status_code status;
41 rtems_id queue_id_prc0;
65 rtems_id queue_id_prc0;
42 asm_msg msgForPRC;
66 asm_msg msgForPRC;
43 ring_node *nodeForAveraging;
67 ring_node *nodeForAveraging;
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
68 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
69 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
46 ring_node_asm *current_ring_node_asm_norm_f0;
70 ring_node_asm *current_ring_node_asm_norm_f0;
47
71
48 unsigned int nb_norm_bp1;
72 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp2;
73 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_asm;
74 unsigned int nb_norm_asm;
51 unsigned int nb_sbm_bp1;
75 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp2;
76 unsigned int nb_sbm_bp2;
53
77
54 nb_norm_bp1 = 0;
78 nb_norm_bp1 = 0;
55 nb_norm_bp2 = 0;
79 nb_norm_bp2 = 0;
56 nb_norm_asm = 0;
80 nb_norm_asm = 0;
57 nb_sbm_bp1 = 0;
81 nb_sbm_bp1 = 0;
58 nb_sbm_bp2 = 0;
82 nb_sbm_bp2 = 0;
59 event_out = EVENT_SETS_NONE_PENDING;
83 event_out = EVENT_SETS_NONE_PENDING;
60 queue_id_prc0 = RTEMS_ID_NONE;
84 queue_id_prc0 = RTEMS_ID_NONE;
61
85
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
86 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
87 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
88 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
89 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
90 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67
91
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
92 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode);
69
93
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
94 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 if (status != RTEMS_SUCCESSFUL)
95 if (status != RTEMS_SUCCESSFUL)
72 {
96 {
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
97 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 }
98 }
75
99
76 while(1){
100 while(1){
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
101 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78
102
79 //****************************************
103 //****************************************
80 // initialize the mesage for the MATR task
104 // initialize the mesage for the MATR task
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
105 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
106 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
107 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
84 //
108 //
85 //****************************************
109 //****************************************
86
110
87 nodeForAveraging = getRingNodeForAveraging( 0 );
111 nodeForAveraging = getRingNodeForAveraging( 0 );
88
112
89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
113 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
114 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 {
115 {
92 nodeForAveraging = nodeForAveraging->previous;
116 nodeForAveraging = nodeForAveraging->previous;
93 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
117 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
94 }
118 }
95
119
96 // compute the average and store it in the averaged_sm_f1 buffer
120 // compute the average and store it in the averaged_sm_f1 buffer
97 SM_average( current_ring_node_asm_norm_f0->matrix,
121 SM_average( current_ring_node_asm_norm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
122 current_ring_node_asm_burst_sbm_f0->matrix,
99 ring_node_tab,
123 ring_node_tab,
100 nb_norm_bp1, nb_sbm_bp1,
124 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC, 0 ); // 0 => frequency channel 0
125 &msgForPRC, 0 ); // 0 => frequency channel 0
102
126
103 // update nb_average
127 // update nb_average
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
128 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
129 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
130 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
131 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
132 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109
133
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
134 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 {
135 {
112 nb_sbm_bp1 = 0;
136 nb_sbm_bp1 = 0;
113 // set another ring for the ASM storage
137 // set another ring for the ASM storage
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
138 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 if ( lfrCurrentMode == LFR_MODE_BURST )
139 if ( lfrCurrentMode == LFR_MODE_BURST )
116 {
140 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
141 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 }
142 }
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
143 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 {
144 {
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
145 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 }
146 }
123 }
147 }
124
148
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
149 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 {
150 {
127 nb_sbm_bp2 = 0;
151 nb_sbm_bp2 = 0;
128 if ( lfrCurrentMode == LFR_MODE_BURST )
152 if ( lfrCurrentMode == LFR_MODE_BURST )
129 {
153 {
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
154 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 }
155 }
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 {
157 {
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
158 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 }
159 }
136 }
160 }
137
161
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
162 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 {
163 {
140 nb_norm_bp1 = 0;
164 nb_norm_bp1 = 0;
141 // set another ring for the ASM storage
165 // set another ring for the ASM storage
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
166 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
167 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
168 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 {
169 {
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
170 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 }
171 }
148 }
172 }
149
173
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
174 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 {
175 {
152 nb_norm_bp2 = 0;
176 nb_norm_bp2 = 0;
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
177 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
178 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 {
179 {
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
180 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 }
181 }
158 }
182 }
159
183
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
184 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 {
185 {
162 nb_norm_asm = 0;
186 nb_norm_asm = 0;
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
187 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
188 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 {
189 {
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
190 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 }
191 }
168 }
192 }
169
193
170 //*************************
194 //*************************
171 // send the message to PRC
195 // send the message to PRC
172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
196 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 {
197 {
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
198 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 }
199 }
176
200
177 if (status != RTEMS_SUCCESSFUL) {
201 if (status != RTEMS_SUCCESSFUL) {
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
202 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 }
203 }
180 }
204 }
181 }
205 }
182
206
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
207 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 {
208 {
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
209 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 size_t size; // size of the incoming TC packet
210 size_t size; // size of the incoming TC packet
187 asm_msg *incomingMsg;
211 asm_msg *incomingMsg;
188 //
212 //
189 unsigned char sid;
213 unsigned char sid;
190 rtems_status_code status;
214 rtems_status_code status;
191 rtems_id queue_id;
215 rtems_id queue_id;
192 rtems_id queue_id_q_p0;
216 rtems_id queue_id_q_p0;
193 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
217 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
194 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
218 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
195 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
219 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
220 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
197 ring_node *current_ring_node_to_send_asm_f0;
221 ring_node *current_ring_node_to_send_asm_f0;
198 float nbSMInASMNORM;
222 float nbSMInASMNORM;
199 float nbSMInASMSBM;
223 float nbSMInASMSBM;
200
224
201 size = 0;
225 size = 0;
202 queue_id = RTEMS_ID_NONE;
226 queue_id = RTEMS_ID_NONE;
203 queue_id_q_p0 = RTEMS_ID_NONE;
227 queue_id_q_p0 = RTEMS_ID_NONE;
204 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
228 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
205 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
229 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
206 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
230 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
231 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
208
232
209 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
233 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
210 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
234 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
211 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
235 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
212
236
213 //*************
237 //*************
214 // NORM headers
238 // NORM headers
215 BP_init_header_with_spare( &packet_norm_bp1,
239 BP_init_header_with_spare( &packet_norm_bp1,
216 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
240 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
217 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
241 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
218 BP_init_header( &packet_norm_bp2,
242 BP_init_header( &packet_norm_bp2,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
243 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
220 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
244 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
221
245
222 //****************************
246 //****************************
223 // BURST SBM1 and SBM2 headers
247 // BURST SBM1 and SBM2 headers
224 if ( lfrRequestedMode == LFR_MODE_BURST )
248 if ( lfrRequestedMode == LFR_MODE_BURST )
225 {
249 {
226 BP_init_header( &packet_sbm_bp1,
250 BP_init_header( &packet_sbm_bp1,
227 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
251 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
252 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
229 BP_init_header( &packet_sbm_bp2,
253 BP_init_header( &packet_sbm_bp2,
230 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
254 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
255 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
232 }
256 }
233 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
257 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
234 {
258 {
235 BP_init_header( &packet_sbm_bp1,
259 BP_init_header( &packet_sbm_bp1,
236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
260 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
261 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
238 BP_init_header( &packet_sbm_bp2,
262 BP_init_header( &packet_sbm_bp2,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
263 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
264 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
241 }
265 }
242 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
266 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
243 {
267 {
244 BP_init_header( &packet_sbm_bp1,
268 BP_init_header( &packet_sbm_bp1,
245 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
269 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
246 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
270 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
247 BP_init_header( &packet_sbm_bp2,
271 BP_init_header( &packet_sbm_bp2,
248 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
272 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
249 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
273 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
250 }
274 }
251 else
275 else
252 {
276 {
253 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
277 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
254 }
278 }
255
279
256 status = get_message_queue_id_send( &queue_id );
280 status = get_message_queue_id_send( &queue_id );
257 if (status != RTEMS_SUCCESSFUL)
281 if (status != RTEMS_SUCCESSFUL)
258 {
282 {
259 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
283 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
260 }
284 }
261 status = get_message_queue_id_prc0( &queue_id_q_p0);
285 status = get_message_queue_id_prc0( &queue_id_q_p0);
262 if (status != RTEMS_SUCCESSFUL)
286 if (status != RTEMS_SUCCESSFUL)
263 {
287 {
264 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
288 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
265 }
289 }
266
290
267 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
291 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
268
292
269 while(1){
293 while(1){
270 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
294 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
271 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
295 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
272
296
273 incomingMsg = (asm_msg*) incomingData;
297 incomingMsg = (asm_msg*) incomingData;
274
298
275 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
299 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
276 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
300 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
277
301
278 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
302 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
279 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
303 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
280
304
281 //****************
305 //****************
282 //****************
306 //****************
283 // BURST SBM1 SBM2
307 // BURST SBM1 SBM2
284 //****************
308 //****************
285 //****************
309 //****************
286 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
310 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
287 {
311 {
288 sid = getSID( incomingMsg->event );
312 sid = getSID( incomingMsg->event );
289 // 1) compress the matrix for Basic Parameters calculation
313 // 1) compress the matrix for Basic Parameters calculation
290 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
314 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
291 nbSMInASMSBM,
315 nbSMInASMSBM,
292 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
316 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
293 ASM_F0_INDICE_START, CHANNELF0);
317 ASM_F0_INDICE_START, CHANNELF0);
294 // 2) compute the BP1 set
318 // 2) compute the BP1 set
295 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
319 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
296 // 3) send the BP1 set
320 // 3) send the BP1 set
297 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
321 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
298 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
322 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
299 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
323 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
300 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
324 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
301 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
325 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
302 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
326 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
303 sid);
327 sid);
304 // 4) compute the BP2 set if needed
328 // 4) compute the BP2 set if needed
305 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
329 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
306 {
330 {
307 // 1) compute the BP2 set
331 // 1) compute the BP2 set
308 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
332 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
309 // 2) send the BP2 set
333 // 2) send the BP2 set
310 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
334 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
311 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
335 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
312 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
336 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
313 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
337 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
338 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
315 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
339 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
316 sid);
340 sid);
317 }
341 }
318 }
342 }
319
343
320 //*****
344 //*****
321 //*****
345 //*****
322 // NORM
346 // NORM
323 //*****
347 //*****
324 //*****
348 //*****
325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
349 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
326 {
350 {
327 // 1) compress the matrix for Basic Parameters calculation
351 // 1) compress the matrix for Basic Parameters calculation
328 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
352 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
329 nbSMInASMNORM,
353 nbSMInASMNORM,
330 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
354 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
331 ASM_F0_INDICE_START, CHANNELF0 );
355 ASM_F0_INDICE_START, CHANNELF0 );
332 // 2) compute the BP1 set
356 // 2) compute the BP1 set
333 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
357 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
334 // 3) send the BP1 set
358 // 3) send the BP1 set
335 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
359 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
336 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
360 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
337 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
361 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
338 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
362 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
339 BP_send( (char *) &packet_norm_bp1, queue_id,
363 BP_send( (char *) &packet_norm_bp1, queue_id,
340 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
364 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
341 SID_NORM_BP1_F0 );
365 SID_NORM_BP1_F0 );
342 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
366 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
343 {
367 {
344 // 1) compute the BP2 set using the same ASM as the one used for BP1
368 // 1) compute the BP2 set using the same ASM as the one used for BP1
345 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
369 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
346 // 2) send the BP2 set
370 // 2) send the BP2 set
347 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
371 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
348 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
372 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
349 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
373 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
350 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
374 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
351 BP_send( (char *) &packet_norm_bp2, queue_id,
375 BP_send( (char *) &packet_norm_bp2, queue_id,
352 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
376 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
353 SID_NORM_BP2_F0);
377 SID_NORM_BP2_F0);
354 }
378 }
355 }
379 }
356
380
357 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
381 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
358 {
382 {
359 // 1) reorganize the ASM and divide
383 // 1) reorganize the ASM and divide
360 ASM_reorganize_and_divide( asm_f0_patched_norm,
384 ASM_reorganize_and_divide( asm_f0_patched_norm,
361 (float*) current_ring_node_to_send_asm_f0->buffer_address,
385 (float*) current_ring_node_to_send_asm_f0->buffer_address,
362 nbSMInASMNORM );
386 nbSMInASMNORM );
363 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
387 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
364 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
388 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
365 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
389 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
366
390
367 // 3) send the spectral matrix packets
391 // 3) send the spectral matrix packets
368 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
392 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
369
393
370 // change asm ring node
394 // change asm ring node
371 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
395 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
372 }
396 }
373
397
374 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
398 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
375
399
376 }
400 }
377 }
401 }
378
402
379 //**********
403 //**********
380 // FUNCTIONS
404 // FUNCTIONS
381
405
382 void reset_nb_sm_f0( unsigned char lfrMode )
406 void reset_nb_sm_f0( unsigned char lfrMode )
383 {
407 {
384 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
408 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
385 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
409 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
386 nb_sm_before_f0.norm_asm =
410 nb_sm_before_f0.norm_asm =
387 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
411 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
388 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
412 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
389 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
413 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
390 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
414 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
391 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
415 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
392 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
416 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
393 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
417 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
394
418
395 if (lfrMode == LFR_MODE_SBM1)
419 if (lfrMode == LFR_MODE_SBM1)
396 {
420 {
397 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
421 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
398 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
422 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
399 }
423 }
400 else if (lfrMode == LFR_MODE_SBM2)
424 else if (lfrMode == LFR_MODE_SBM2)
401 {
425 {
402 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
426 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
403 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
427 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
404 }
428 }
405 else if (lfrMode == LFR_MODE_BURST)
429 else if (lfrMode == LFR_MODE_BURST)
406 {
430 {
407 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
431 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
408 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
432 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
409 }
433 }
410 else
434 else
411 {
435 {
412 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
436 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
413 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
437 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
414 }
438 }
415 }
439 }
416
440
417 void init_k_coefficients_prc0( void )
441 void init_k_coefficients_prc0( void )
418 {
442 {
419 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
443 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
420
444
421 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
445 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
422 }
446 }
423
447
@@ -1,407 +1,431
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "avf1_prc1.h"
34 #include "avf1_prc1.h"
11
35
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
36 nb_sm_before_bp_asm_f1 nb_sm_before_f1 = {0};
13
37
14 //***
38 //***
15 // F1
39 // F1
16 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
40 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ] = {0};
17 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
41 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ] = {0};
18
42
19 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
43 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ] = {0};
20 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
44 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ] = {0};
21
45
22 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
46 float asm_f1_patched_norm [ TOTAL_SIZE_SM ] = {0};
23 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
47 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ] = {0};
24 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
48 float asm_f1_reorganized [ TOTAL_SIZE_SM ] = {0};
25
49
26 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
50 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1] = {0};
27 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
51 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ] = {0};
28
52
29 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
53 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 13 * 32 = 416
30 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
54 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ] = {0}; // 26 * 32 = 832
31
55
32 //************
56 //************
33 // RTEMS TASKS
57 // RTEMS TASKS
34
58
35 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
59 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
36 {
60 {
37 int i;
61 int i;
38
62
39 rtems_event_set event_out;
63 rtems_event_set event_out;
40 rtems_status_code status;
64 rtems_status_code status;
41 rtems_id queue_id_prc1;
65 rtems_id queue_id_prc1;
42 asm_msg msgForPRC;
66 asm_msg msgForPRC;
43 ring_node *nodeForAveraging;
67 ring_node *nodeForAveraging;
44 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
68 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
45 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
69 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
46 ring_node_asm *current_ring_node_asm_norm_f1;
70 ring_node_asm *current_ring_node_asm_norm_f1;
47
71
48 unsigned int nb_norm_bp1;
72 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp2;
73 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_asm;
74 unsigned int nb_norm_asm;
51 unsigned int nb_sbm_bp1;
75 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp2;
76 unsigned int nb_sbm_bp2;
53
77
54 event_out = EVENT_SETS_NONE_PENDING;
78 event_out = EVENT_SETS_NONE_PENDING;
55 queue_id_prc1 = RTEMS_ID_NONE;
79 queue_id_prc1 = RTEMS_ID_NONE;
56
80
57 nb_norm_bp1 = 0;
81 nb_norm_bp1 = 0;
58 nb_norm_bp2 = 0;
82 nb_norm_bp2 = 0;
59 nb_norm_asm = 0;
83 nb_norm_asm = 0;
60 nb_sbm_bp1 = 0;
84 nb_sbm_bp1 = 0;
61 nb_sbm_bp2 = 0;
85 nb_sbm_bp2 = 0;
62
86
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
87 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
88 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
89 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
90 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
91 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68
92
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
93 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70
94
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
95 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 if (status != RTEMS_SUCCESSFUL)
96 if (status != RTEMS_SUCCESSFUL)
73 {
97 {
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
98 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 }
99 }
76
100
77 while(1){
101 while(1){
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
102 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79
103
80 //****************************************
104 //****************************************
81 // initialize the mesage for the MATR task
105 // initialize the mesage for the MATR task
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
106 msgForPRC.norm = current_ring_node_asm_norm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
107 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
108 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
85 //
109 //
86 //****************************************
110 //****************************************
87
111
88 nodeForAveraging = getRingNodeForAveraging( 1 );
112 nodeForAveraging = getRingNodeForAveraging( 1 );
89
113
90 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
114 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
91 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
115 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
92 {
116 {
93 nodeForAveraging = nodeForAveraging->previous;
117 nodeForAveraging = nodeForAveraging->previous;
94 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
118 ring_node_tab[NB_SM_BEFORE_AVF0_F1 - i - 1] = nodeForAveraging;
95 }
119 }
96
120
97 // compute the average and store it in the averaged_sm_f1 buffer
121 // compute the average and store it in the averaged_sm_f1 buffer
98 SM_average( current_ring_node_asm_norm_f1->matrix,
122 SM_average( current_ring_node_asm_norm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
123 current_ring_node_asm_burst_sbm_f1->matrix,
100 ring_node_tab,
124 ring_node_tab,
101 nb_norm_bp1, nb_sbm_bp1,
125 nb_norm_bp1, nb_sbm_bp1,
102 &msgForPRC, 1 ); // 1 => frequency channel 1
126 &msgForPRC, 1 ); // 1 => frequency channel 1
103
127
104 // update nb_average
128 // update nb_average
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
129 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
130 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
131 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
132 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
133 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
110
134
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
135 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 {
136 {
113 nb_sbm_bp1 = 0;
137 nb_sbm_bp1 = 0;
114 // set another ring for the ASM storage
138 // set another ring for the ASM storage
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
139 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 if ( lfrCurrentMode == LFR_MODE_BURST )
140 if ( lfrCurrentMode == LFR_MODE_BURST )
117 {
141 {
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
142 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
119 }
143 }
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
144 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 {
145 {
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
123 }
147 }
124 }
148 }
125
149
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
150 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 {
151 {
128 nb_sbm_bp2 = 0;
152 nb_sbm_bp2 = 0;
129 if ( lfrCurrentMode == LFR_MODE_BURST )
153 if ( lfrCurrentMode == LFR_MODE_BURST )
130 {
154 {
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
155 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
132 }
156 }
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
157 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 {
158 {
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
159 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
136 }
160 }
137 }
161 }
138
162
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
163 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 {
164 {
141 nb_norm_bp1 = 0;
165 nb_norm_bp1 = 0;
142 // set another ring for the ASM storage
166 // set another ring for the ASM storage
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
167 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
168 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
169 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 {
170 {
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
171 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
148 }
172 }
149 }
173 }
150
174
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
175 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 {
176 {
153 nb_norm_bp2 = 0;
177 nb_norm_bp2 = 0;
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
178 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
179 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 {
180 {
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
181 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
158 }
182 }
159 }
183 }
160
184
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
185 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 {
186 {
163 nb_norm_asm = 0;
187 nb_norm_asm = 0;
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
188 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
189 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 {
190 {
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
191 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
168 }
192 }
169 }
193 }
170
194
171 //*************************
195 //*************************
172 // send the message to PRC
196 // send the message to PRC
173 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
197 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
174 {
198 {
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
199 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
176 }
200 }
177
201
178 if (status != RTEMS_SUCCESSFUL) {
202 if (status != RTEMS_SUCCESSFUL) {
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
203 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 }
204 }
181 }
205 }
182 }
206 }
183
207
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
208 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 {
209 {
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
210 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 size_t size; // size of the incoming TC packet
211 size_t size; // size of the incoming TC packet
188 asm_msg *incomingMsg;
212 asm_msg *incomingMsg;
189 //
213 //
190 unsigned char sid;
214 unsigned char sid;
191 rtems_status_code status;
215 rtems_status_code status;
192 rtems_id queue_id_send;
216 rtems_id queue_id_send;
193 rtems_id queue_id_q_p1;
217 rtems_id queue_id_q_p1;
194 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
218 bp_packet_with_spare __attribute__((aligned(4))) packet_norm_bp1;
195 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
219 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
196 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
220 bp_packet __attribute__((aligned(4))) packet_sbm_bp1;
197 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
221 bp_packet __attribute__((aligned(4))) packet_sbm_bp2;
198 ring_node *current_ring_node_to_send_asm_f1;
222 ring_node *current_ring_node_to_send_asm_f1;
199 float nbSMInASMNORM;
223 float nbSMInASMNORM;
200 float nbSMInASMSBM;
224 float nbSMInASMSBM;
201
225
202 size = 0;
226 size = 0;
203 queue_id_send = RTEMS_ID_NONE;
227 queue_id_send = RTEMS_ID_NONE;
204 queue_id_q_p1 = RTEMS_ID_NONE;
228 queue_id_q_p1 = RTEMS_ID_NONE;
205 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
229 memset( &packet_norm_bp1, 0, sizeof(bp_packet_with_spare) );
206 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
230 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
207 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
231 memset( &packet_sbm_bp1, 0, sizeof(bp_packet) );
208 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
232 memset( &packet_sbm_bp2, 0, sizeof(bp_packet) );
209
233
210 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
234 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
211 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
235 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
212 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
236 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
213
237
214 //*************
238 //*************
215 // NORM headers
239 // NORM headers
216 BP_init_header_with_spare( &packet_norm_bp1,
240 BP_init_header_with_spare( &packet_norm_bp1,
217 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
241 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
218 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
242 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
219 BP_init_header( &packet_norm_bp2,
243 BP_init_header( &packet_norm_bp2,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
244 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
221 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
245 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
222
246
223 //***********************
247 //***********************
224 // BURST and SBM2 headers
248 // BURST and SBM2 headers
225 if ( lfrRequestedMode == LFR_MODE_BURST )
249 if ( lfrRequestedMode == LFR_MODE_BURST )
226 {
250 {
227 BP_init_header( &packet_sbm_bp1,
251 BP_init_header( &packet_sbm_bp1,
228 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
252 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
253 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
230 BP_init_header( &packet_sbm_bp2,
254 BP_init_header( &packet_sbm_bp2,
231 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
255 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
256 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
233 }
257 }
234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
258 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
235 {
259 {
236 BP_init_header( &packet_sbm_bp1,
260 BP_init_header( &packet_sbm_bp1,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
261 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
262 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
239 BP_init_header( &packet_sbm_bp2,
263 BP_init_header( &packet_sbm_bp2,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
264 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
265 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
242 }
266 }
243 else
267 else
244 {
268 {
245 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
269 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
246 }
270 }
247
271
248 status = get_message_queue_id_send( &queue_id_send );
272 status = get_message_queue_id_send( &queue_id_send );
249 if (status != RTEMS_SUCCESSFUL)
273 if (status != RTEMS_SUCCESSFUL)
250 {
274 {
251 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
275 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
252 }
276 }
253 status = get_message_queue_id_prc1( &queue_id_q_p1);
277 status = get_message_queue_id_prc1( &queue_id_q_p1);
254 if (status != RTEMS_SUCCESSFUL)
278 if (status != RTEMS_SUCCESSFUL)
255 {
279 {
256 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
280 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
257 }
281 }
258
282
259 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
283 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
260
284
261 while(1){
285 while(1){
262 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
286 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
287 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
264
288
265 incomingMsg = (asm_msg*) incomingData;
289 incomingMsg = (asm_msg*) incomingData;
266
290
267 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
291 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
292 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
269
293
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
294 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
295 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272
296
273 //***********
297 //***********
274 //***********
298 //***********
275 // BURST SBM2
299 // BURST SBM2
276 //***********
300 //***********
277 //***********
301 //***********
278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
302 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
279 {
303 {
280 sid = getSID( incomingMsg->event );
304 sid = getSID( incomingMsg->event );
281 // 1) compress the matrix for Basic Parameters calculation
305 // 1) compress the matrix for Basic Parameters calculation
282 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
306 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
283 nbSMInASMSBM,
307 nbSMInASMSBM,
284 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
308 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
285 ASM_F1_INDICE_START, CHANNELF1);
309 ASM_F1_INDICE_START, CHANNELF1);
286 // 2) compute the BP1 set
310 // 2) compute the BP1 set
287 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
311 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
288 // 3) send the BP1 set
312 // 3) send the BP1 set
289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
313 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
314 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
315 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
316 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
317 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
318 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
295 sid );
319 sid );
296 // 4) compute the BP2 set if needed
320 // 4) compute the BP2 set if needed
297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
321 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
298 {
322 {
299 // 1) compute the BP2 set
323 // 1) compute the BP2 set
300 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
324 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
301 // 2) send the BP2 set
325 // 2) send the BP2 set
302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
326 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
327 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
328 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
329 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
330 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
331 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
308 sid );
332 sid );
309 }
333 }
310 }
334 }
311
335
312 //*****
336 //*****
313 //*****
337 //*****
314 // NORM
338 // NORM
315 //*****
339 //*****
316 //*****
340 //*****
317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
341 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
318 {
342 {
319 // 1) compress the matrix for Basic Parameters calculation
343 // 1) compress the matrix for Basic Parameters calculation
320 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
344 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
321 nbSMInASMNORM,
345 nbSMInASMNORM,
322 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
346 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
323 ASM_F1_INDICE_START, CHANNELF1 );
347 ASM_F1_INDICE_START, CHANNELF1 );
324 // 2) compute the BP1 set
348 // 2) compute the BP1 set
325 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
349 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
326 // 3) send the BP1 set
350 // 3) send the BP1 set
327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
351 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
352 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
353 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
354 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
331 BP_send( (char *) &packet_norm_bp1, queue_id_send,
355 BP_send( (char *) &packet_norm_bp1, queue_id_send,
332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
356 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
333 SID_NORM_BP1_F1 );
357 SID_NORM_BP1_F1 );
334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
358 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
335 {
359 {
336 // 1) compute the BP2 set
360 // 1) compute the BP2 set
337 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
361 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
338 // 2) send the BP2 set
362 // 2) send the BP2 set
339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
363 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
364 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
365 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
366 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
343 BP_send( (char *) &packet_norm_bp2, queue_id_send,
367 BP_send( (char *) &packet_norm_bp2, queue_id_send,
344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
368 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
345 SID_NORM_BP2_F1 );
369 SID_NORM_BP2_F1 );
346 }
370 }
347 }
371 }
348
372
349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
373 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
350 {
374 {
351 // 1) reorganize the ASM and divide
375 // 1) reorganize the ASM and divide
352 ASM_reorganize_and_divide( asm_f1_patched_norm,
376 ASM_reorganize_and_divide( asm_f1_patched_norm,
353 (float*) current_ring_node_to_send_asm_f1->buffer_address,
377 (float*) current_ring_node_to_send_asm_f1->buffer_address,
354 nbSMInASMNORM );
378 nbSMInASMNORM );
355 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
379 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
356 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
380 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
357 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
381 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
358
382
359 // 3) send the spectral matrix packets
383 // 3) send the spectral matrix packets
360 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
384 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
361
385
362 // change asm ring node
386 // change asm ring node
363 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
387 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
364 }
388 }
365
389
366 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
390 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
367
391
368 }
392 }
369 }
393 }
370
394
371 //**********
395 //**********
372 // FUNCTIONS
396 // FUNCTIONS
373
397
374 void reset_nb_sm_f1( unsigned char lfrMode )
398 void reset_nb_sm_f1( unsigned char lfrMode )
375 {
399 {
376 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
400 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
377 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
401 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
378 nb_sm_before_f1.norm_asm =
402 nb_sm_before_f1.norm_asm =
379 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
403 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
380 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
404 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
381 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
405 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
382 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
406 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
383 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
407 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
384
408
385 if (lfrMode == LFR_MODE_SBM2)
409 if (lfrMode == LFR_MODE_SBM2)
386 {
410 {
387 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
411 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
388 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
412 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
389 }
413 }
390 else if (lfrMode == LFR_MODE_BURST)
414 else if (lfrMode == LFR_MODE_BURST)
391 {
415 {
392 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
416 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
393 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
417 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
394 }
418 }
395 else
419 else
396 {
420 {
397 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
421 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
398 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
422 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
399 }
423 }
400 }
424 }
401
425
402 void init_k_coefficients_prc1( void )
426 void init_k_coefficients_prc1( void )
403 {
427 {
404 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
428 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
405
429
406 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
430 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
407 }
431 }
@@ -1,332 +1,356
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "avf2_prc2.h"
34 #include "avf2_prc2.h"
11
35
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
36 nb_sm_before_bp_asm_f2 nb_sm_before_f2 = {0};
13
37
14 //***
38 //***
15 // F2
39 // F2
16 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
40 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ] = {0};
17
41
18 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
42 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ] = {0};
19 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
43 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ] = {0};
20
44
21 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
45 float asm_f2_patched_norm [ TOTAL_SIZE_SM ] = {0};
22 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
46 float asm_f2_reorganized [ TOTAL_SIZE_SM ] = {0};
23
47
24 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
48 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2] = {0};
25
49
26 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
50 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ] = {0}; // 12 * 32 = 384
27
51
28 //************
52 //************
29 // RTEMS TASKS
53 // RTEMS TASKS
30
54
31 //***
55 //***
32 // F2
56 // F2
33 rtems_task avf2_task( rtems_task_argument argument )
57 rtems_task avf2_task( rtems_task_argument argument )
34 {
58 {
35 rtems_event_set event_out;
59 rtems_event_set event_out;
36 rtems_status_code status;
60 rtems_status_code status;
37 rtems_id queue_id_prc2;
61 rtems_id queue_id_prc2;
38 asm_msg msgForPRC;
62 asm_msg msgForPRC;
39 ring_node *nodeForAveraging;
63 ring_node *nodeForAveraging;
40 ring_node_asm *current_ring_node_asm_norm_f2;
64 ring_node_asm *current_ring_node_asm_norm_f2;
41
65
42 unsigned int nb_norm_bp1;
66 unsigned int nb_norm_bp1;
43 unsigned int nb_norm_bp2;
67 unsigned int nb_norm_bp2;
44 unsigned int nb_norm_asm;
68 unsigned int nb_norm_asm;
45
69
46 event_out = EVENT_SETS_NONE_PENDING;
70 event_out = EVENT_SETS_NONE_PENDING;
47 queue_id_prc2 = RTEMS_ID_NONE;
71 queue_id_prc2 = RTEMS_ID_NONE;
48 nb_norm_bp1 = 0;
72 nb_norm_bp1 = 0;
49 nb_norm_bp2 = 0;
73 nb_norm_bp2 = 0;
50 nb_norm_asm = 0;
74 nb_norm_asm = 0;
51
75
52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
76 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
77 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
78 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
55
79
56 BOOT_PRINTF("in AVF2 ***\n")
80 BOOT_PRINTF("in AVF2 ***\n")
57
81
58 status = get_message_queue_id_prc2( &queue_id_prc2 );
82 status = get_message_queue_id_prc2( &queue_id_prc2 );
59 if (status != RTEMS_SUCCESSFUL)
83 if (status != RTEMS_SUCCESSFUL)
60 {
84 {
61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
85 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
62 }
86 }
63
87
64 while(1){
88 while(1){
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
89 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66
90
67 //****************************************
91 //****************************************
68 // initialize the mesage for the MATR task
92 // initialize the mesage for the MATR task
69 msgForPRC.norm = current_ring_node_asm_norm_f2;
93 msgForPRC.norm = current_ring_node_asm_norm_f2;
70 msgForPRC.burst_sbm = NULL;
94 msgForPRC.burst_sbm = NULL;
71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
95 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
72 //
96 //
73 //****************************************
97 //****************************************
74
98
75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
99 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
76
100
77 // compute the average and store it in the averaged_sm_f2 buffer
101 // compute the average and store it in the averaged_sm_f2 buffer
78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
102 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
79 nodeForAveraging,
103 nodeForAveraging,
80 nb_norm_bp1,
104 nb_norm_bp1,
81 &msgForPRC );
105 &msgForPRC );
82
106
83 // update nb_average
107 // update nb_average
84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
108 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
109 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
110 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
87
111
88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
112 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
89 {
113 {
90 nb_norm_bp1 = 0;
114 nb_norm_bp1 = 0;
91 // set another ring for the ASM storage
115 // set another ring for the ASM storage
92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
116 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
117 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
94 || (lfrCurrentMode == LFR_MODE_SBM2) )
118 || (lfrCurrentMode == LFR_MODE_SBM2) )
95 {
119 {
96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
120 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
97 }
121 }
98 }
122 }
99
123
100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
124 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
101 {
125 {
102 nb_norm_bp2 = 0;
126 nb_norm_bp2 = 0;
103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
127 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
104 || (lfrCurrentMode == LFR_MODE_SBM2) )
128 || (lfrCurrentMode == LFR_MODE_SBM2) )
105 {
129 {
106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
107 }
131 }
108 }
132 }
109
133
110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
134 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
111 {
135 {
112 nb_norm_asm = 0;
136 nb_norm_asm = 0;
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
137 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
114 || (lfrCurrentMode == LFR_MODE_SBM2) )
138 || (lfrCurrentMode == LFR_MODE_SBM2) )
115 {
139 {
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
140 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
117 }
141 }
118 }
142 }
119
143
120 //*************************
144 //*************************
121 // send the message to PRC2
145 // send the message to PRC2
122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
146 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
123 {
147 {
124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
148 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
125 }
149 }
126
150
127 if (status != RTEMS_SUCCESSFUL) {
151 if (status != RTEMS_SUCCESSFUL) {
128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
152 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
129 }
153 }
130 }
154 }
131 }
155 }
132
156
133 rtems_task prc2_task( rtems_task_argument argument )
157 rtems_task prc2_task( rtems_task_argument argument )
134 {
158 {
135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
159 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
136 size_t size; // size of the incoming TC packet
160 size_t size; // size of the incoming TC packet
137 asm_msg *incomingMsg;
161 asm_msg *incomingMsg;
138 //
162 //
139 rtems_status_code status;
163 rtems_status_code status;
140 rtems_id queue_id_send;
164 rtems_id queue_id_send;
141 rtems_id queue_id_q_p2;
165 rtems_id queue_id_q_p2;
142 bp_packet __attribute__((aligned(4))) packet_norm_bp1;
166 bp_packet __attribute__((aligned(4))) packet_norm_bp1;
143 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
167 bp_packet __attribute__((aligned(4))) packet_norm_bp2;
144 ring_node *current_ring_node_to_send_asm_f2;
168 ring_node *current_ring_node_to_send_asm_f2;
145 float nbSMInASMNORM;
169 float nbSMInASMNORM;
146
170
147 unsigned long long int localTime;
171 unsigned long long int localTime;
148
172
149 size = 0;
173 size = 0;
150 queue_id_send = RTEMS_ID_NONE;
174 queue_id_send = RTEMS_ID_NONE;
151 queue_id_q_p2 = RTEMS_ID_NONE;
175 queue_id_q_p2 = RTEMS_ID_NONE;
152 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
176 memset( &packet_norm_bp1, 0, sizeof(bp_packet) );
153 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
177 memset( &packet_norm_bp2, 0, sizeof(bp_packet) );
154
178
155 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
179 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
156 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
180 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
157 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
181 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
158
182
159 //*************
183 //*************
160 // NORM headers
184 // NORM headers
161 BP_init_header( &packet_norm_bp1,
185 BP_init_header( &packet_norm_bp1,
162 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
186 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
163 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
187 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
164 BP_init_header( &packet_norm_bp2,
188 BP_init_header( &packet_norm_bp2,
165 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
189 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
166 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
190 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
167
191
168 status = get_message_queue_id_send( &queue_id_send );
192 status = get_message_queue_id_send( &queue_id_send );
169 if (status != RTEMS_SUCCESSFUL)
193 if (status != RTEMS_SUCCESSFUL)
170 {
194 {
171 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
195 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
172 }
196 }
173 status = get_message_queue_id_prc2( &queue_id_q_p2);
197 status = get_message_queue_id_prc2( &queue_id_q_p2);
174 if (status != RTEMS_SUCCESSFUL)
198 if (status != RTEMS_SUCCESSFUL)
175 {
199 {
176 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
200 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
177 }
201 }
178
202
179 BOOT_PRINTF("in PRC2 ***\n")
203 BOOT_PRINTF("in PRC2 ***\n")
180
204
181 while(1){
205 while(1){
182 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
206 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
183 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
207 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
184
208
185 incomingMsg = (asm_msg*) incomingData;
209 incomingMsg = (asm_msg*) incomingData;
186
210
187 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
211 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
188
212
189 localTime = getTimeAsUnsignedLongLongInt( );
213 localTime = getTimeAsUnsignedLongLongInt( );
190
214
191 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
215 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
192
216
193 //*****
217 //*****
194 //*****
218 //*****
195 // NORM
219 // NORM
196 //*****
220 //*****
197 //*****
221 //*****
198 // 1) compress the matrix for Basic Parameters calculation
222 // 1) compress the matrix for Basic Parameters calculation
199 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
223 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
200 nbSMInASMNORM,
224 nbSMInASMNORM,
201 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
225 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
202 ASM_F2_INDICE_START, CHANNELF2 );
226 ASM_F2_INDICE_START, CHANNELF2 );
203 // BP1_F2
227 // BP1_F2
204 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
228 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
205 {
229 {
206 // 1) compute the BP1 set
230 // 1) compute the BP1 set
207 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
231 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
208 // 2) send the BP1 set
232 // 2) send the BP1 set
209 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
233 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
210 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
234 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
211 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
235 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
212 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
236 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
213 BP_send( (char *) &packet_norm_bp1, queue_id_send,
237 BP_send( (char *) &packet_norm_bp1, queue_id_send,
214 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
238 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
215 SID_NORM_BP1_F2 );
239 SID_NORM_BP1_F2 );
216 }
240 }
217 // BP2_F2
241 // BP2_F2
218 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
242 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
219 {
243 {
220 // 1) compute the BP2 set
244 // 1) compute the BP2 set
221 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
245 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
222 // 2) send the BP2 set
246 // 2) send the BP2 set
223 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
247 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
224 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
248 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
225 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
249 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
226 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
250 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
227 BP_send( (char *) &packet_norm_bp2, queue_id_send,
251 BP_send( (char *) &packet_norm_bp2, queue_id_send,
228 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
252 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
229 SID_NORM_BP2_F2 );
253 SID_NORM_BP2_F2 );
230 }
254 }
231
255
232 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
256 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
233 {
257 {
234 // 1) reorganize the ASM and divide
258 // 1) reorganize the ASM and divide
235 ASM_reorganize_and_divide( asm_f2_patched_norm,
259 ASM_reorganize_and_divide( asm_f2_patched_norm,
236 (float*) current_ring_node_to_send_asm_f2->buffer_address,
260 (float*) current_ring_node_to_send_asm_f2->buffer_address,
237 nb_sm_before_f2.norm_bp1 );
261 nb_sm_before_f2.norm_bp1 );
238 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
262 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
239 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
263 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
240 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
264 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
241
265
242 // 3) send the spectral matrix packets
266 // 3) send the spectral matrix packets
243 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
267 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
244
268
245 // change asm ring node
269 // change asm ring node
246 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
270 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
247 }
271 }
248
272
249 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
273 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
250
274
251 }
275 }
252 }
276 }
253
277
254 //**********
278 //**********
255 // FUNCTIONS
279 // FUNCTIONS
256
280
257 void reset_nb_sm_f2( void )
281 void reset_nb_sm_f2( void )
258 {
282 {
259 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
283 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
260 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
284 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
261 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
285 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
262 }
286 }
263
287
264 void SM_average_f2( float *averaged_spec_mat_f2,
288 void SM_average_f2( float *averaged_spec_mat_f2,
265 ring_node *ring_node,
289 ring_node *ring_node,
266 unsigned int nbAverageNormF2,
290 unsigned int nbAverageNormF2,
267 asm_msg *msgForMATR )
291 asm_msg *msgForMATR )
268 {
292 {
269 float sum;
293 float sum;
270 unsigned int i;
294 unsigned int i;
271 unsigned char keepMatrix;
295 unsigned char keepMatrix;
272
296
273 // test acquisitionTime validity
297 // test acquisitionTime validity
274 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
298 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
275
299
276 for(i=0; i<TOTAL_SIZE_SM; i++)
300 for(i=0; i<TOTAL_SIZE_SM; i++)
277 {
301 {
278 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
302 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
279 if ( (nbAverageNormF2 == 0) ) // average initialization
303 if ( (nbAverageNormF2 == 0) ) // average initialization
280 {
304 {
281 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
305 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
282 {
306 {
283 averaged_spec_mat_f2[ i ] = sum;
307 averaged_spec_mat_f2[ i ] = sum;
284 }
308 }
285 else // drop the matrix and initialize the average
309 else // drop the matrix and initialize the average
286 {
310 {
287 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
311 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
288 }
312 }
289 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
313 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
290 msgForMATR->fineTimeNORM = ring_node->fineTime;
314 msgForMATR->fineTimeNORM = ring_node->fineTime;
291 }
315 }
292 else
316 else
293 {
317 {
294 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
318 if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
295 {
319 {
296 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
320 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
297 }
321 }
298 else
322 else
299 {
323 {
300 // nothing to do, the matrix is not valid
324 // nothing to do, the matrix is not valid
301 }
325 }
302 }
326 }
303 }
327 }
304
328
305 if (keepMatrix == 1)
329 if (keepMatrix == 1)
306 {
330 {
307 if ( (nbAverageNormF2 == 0) )
331 if ( (nbAverageNormF2 == 0) )
308 {
332 {
309 msgForMATR->numberOfSMInASMNORM = 1;
333 msgForMATR->numberOfSMInASMNORM = 1;
310 }
334 }
311 else
335 else
312 {
336 {
313 msgForMATR->numberOfSMInASMNORM++;
337 msgForMATR->numberOfSMInASMNORM++;
314 }
338 }
315 }
339 }
316 else
340 else
317 {
341 {
318 if ( (nbAverageNormF2 == 0) )
342 if ( (nbAverageNormF2 == 0) )
319 {
343 {
320 msgForMATR->numberOfSMInASMNORM = 0;
344 msgForMATR->numberOfSMInASMNORM = 0;
321 }
345 }
322 else
346 else
323 {
347 {
324 // nothing to do
348 // nothing to do
325 }
349 }
326 }
350 }
327 }
351 }
328
352
329 void init_k_coefficients_prc2( void )
353 void init_k_coefficients_prc2( void )
330 {
354 {
331 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
355 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
332 }
356 }
@@ -1,840 +1,898
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions related to data processing.
25 /** Functions related to data processing.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
30 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
31 *
8 */
32 */
9
33
10 #include "fsw_processing.h"
34 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
35 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
36 #include "fsw_init.h"
13
37
14 unsigned int nb_sm_f0 = 0;
38 unsigned int nb_sm_f0 = 0;
15 unsigned int nb_sm_f0_aux_f1= 0;
39 unsigned int nb_sm_f0_aux_f1= 0;
16 unsigned int nb_sm_f1 = 0;
40 unsigned int nb_sm_f1 = 0;
17 unsigned int nb_sm_f0_aux_f2= 0;
41 unsigned int nb_sm_f0_aux_f2= 0;
18
42
19 typedef enum restartState_t
43 typedef enum restartState_t
20 {
44 {
21 WAIT_FOR_F2,
45 WAIT_FOR_F2,
22 WAIT_FOR_F1,
46 WAIT_FOR_F1,
23 WAIT_FOR_F0
47 WAIT_FOR_F0
24 } restartState;
48 } restartState;
25
49
26 //************************
50 //************************
27 // spectral matrices rings
51 // spectral matrices rings
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ] = {0};
52 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ] = {0};
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ] = {0};
53 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ] = {0};
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ] = {0};
54 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ] = {0};
31 ring_node *current_ring_node_sm_f0 = NULL;
55 ring_node *current_ring_node_sm_f0 = NULL;
32 ring_node *current_ring_node_sm_f1 = NULL;
56 ring_node *current_ring_node_sm_f1 = NULL;
33 ring_node *current_ring_node_sm_f2 = NULL;
57 ring_node *current_ring_node_sm_f2 = NULL;
34 ring_node *ring_node_for_averaging_sm_f0= NULL;
58 ring_node *ring_node_for_averaging_sm_f0= NULL;
35 ring_node *ring_node_for_averaging_sm_f1= NULL;
59 ring_node *ring_node_for_averaging_sm_f1= NULL;
36 ring_node *ring_node_for_averaging_sm_f2= NULL;
60 ring_node *ring_node_for_averaging_sm_f2= NULL;
37
61
38 //
62 //
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
63 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
40 {
64 {
41 ring_node *node;
65 ring_node *node;
42
66
43 node = NULL;
67 node = NULL;
44 switch ( frequencyChannel ) {
68 switch ( frequencyChannel ) {
45 case CHANNELF0:
69 case CHANNELF0:
46 node = ring_node_for_averaging_sm_f0;
70 node = ring_node_for_averaging_sm_f0;
47 break;
71 break;
48 case CHANNELF1:
72 case CHANNELF1:
49 node = ring_node_for_averaging_sm_f1;
73 node = ring_node_for_averaging_sm_f1;
50 break;
74 break;
51 case CHANNELF2:
75 case CHANNELF2:
52 node = ring_node_for_averaging_sm_f2;
76 node = ring_node_for_averaging_sm_f2;
53 break;
77 break;
54 default:
78 default:
55 break;
79 break;
56 }
80 }
57
81
58 return node;
82 return node;
59 }
83 }
60
84
61 //***********************************************************
85 //***********************************************************
62 // Interrupt Service Routine for spectral matrices processing
86 // Interrupt Service Routine for spectral matrices processing
63
87
64 void spectral_matrices_isr_f0( int statusReg )
88 void spectral_matrices_isr_f0( int statusReg )
65 {
89 {
66 unsigned char status;
90 unsigned char status;
67 rtems_status_code status_code;
91 rtems_status_code status_code;
68 ring_node *full_ring_node;
92 ring_node *full_ring_node;
69
93
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
94 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
71
95
72 switch(status)
96 switch(status)
73 {
97 {
74 case 0:
98 case 0:
75 break;
99 break;
76 case BIT_READY_0_1:
100 case BIT_READY_0_1:
77 // UNEXPECTED VALUE
101 // UNEXPECTED VALUE
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
102 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
103 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
80 break;
104 break;
81 case BIT_READY_0:
105 case BIT_READY_0:
82 full_ring_node = current_ring_node_sm_f0->previous;
106 full_ring_node = current_ring_node_sm_f0->previous;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
107 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
108 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
109 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
110 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
87 // if there are enough ring nodes ready, wake up an AVFx task
111 // if there are enough ring nodes ready, wake up an AVFx task
88 nb_sm_f0 = nb_sm_f0 + 1;
112 nb_sm_f0 = nb_sm_f0 + 1;
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
113 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
90 {
114 {
91 ring_node_for_averaging_sm_f0 = full_ring_node;
115 ring_node_for_averaging_sm_f0 = full_ring_node;
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
116 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
93 {
117 {
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
118 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
95 }
119 }
96 nb_sm_f0 = 0;
120 nb_sm_f0 = 0;
97 }
121 }
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
122 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
99 break;
123 break;
100 case BIT_READY_1:
124 case BIT_READY_1:
101 full_ring_node = current_ring_node_sm_f0->previous;
125 full_ring_node = current_ring_node_sm_f0->previous;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
126 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
127 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
128 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
129 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
106 // if there are enough ring nodes ready, wake up an AVFx task
130 // if there are enough ring nodes ready, wake up an AVFx task
107 nb_sm_f0 = nb_sm_f0 + 1;
131 nb_sm_f0 = nb_sm_f0 + 1;
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
132 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
109 {
133 {
110 ring_node_for_averaging_sm_f0 = full_ring_node;
134 ring_node_for_averaging_sm_f0 = full_ring_node;
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
135 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
112 {
136 {
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
137 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
114 }
138 }
115 nb_sm_f0 = 0;
139 nb_sm_f0 = 0;
116 }
140 }
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
141 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
118 break;
142 break;
119 default:
143 default:
120 break;
144 break;
121 }
145 }
122 }
146 }
123
147
124 void spectral_matrices_isr_f1( int statusReg )
148 void spectral_matrices_isr_f1( int statusReg )
125 {
149 {
126 rtems_status_code status_code;
150 rtems_status_code status_code;
127 unsigned char status;
151 unsigned char status;
128 ring_node *full_ring_node;
152 ring_node *full_ring_node;
129
153
130 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
154 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
131
155
132 switch(status)
156 switch(status)
133 {
157 {
134 case 0:
158 case 0:
135 break;
159 break;
136 case BIT_READY_0_1:
160 case BIT_READY_0_1:
137 // UNEXPECTED VALUE
161 // UNEXPECTED VALUE
138 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
162 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
163 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
140 break;
164 break;
141 case BIT_READY_0:
165 case BIT_READY_0:
142 full_ring_node = current_ring_node_sm_f1->previous;
166 full_ring_node = current_ring_node_sm_f1->previous;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
167 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
168 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
169 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
170 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
147 // if there are enough ring nodes ready, wake up an AVFx task
171 // if there are enough ring nodes ready, wake up an AVFx task
148 nb_sm_f1 = nb_sm_f1 + 1;
172 nb_sm_f1 = nb_sm_f1 + 1;
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
173 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
150 {
174 {
151 ring_node_for_averaging_sm_f1 = full_ring_node;
175 ring_node_for_averaging_sm_f1 = full_ring_node;
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
176 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
153 {
177 {
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
178 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
155 }
179 }
156 nb_sm_f1 = 0;
180 nb_sm_f1 = 0;
157 }
181 }
158 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
182 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
159 break;
183 break;
160 case BIT_READY_1:
184 case BIT_READY_1:
161 full_ring_node = current_ring_node_sm_f1->previous;
185 full_ring_node = current_ring_node_sm_f1->previous;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
186 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
187 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
188 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
189 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
166 // if there are enough ring nodes ready, wake up an AVFx task
190 // if there are enough ring nodes ready, wake up an AVFx task
167 nb_sm_f1 = nb_sm_f1 + 1;
191 nb_sm_f1 = nb_sm_f1 + 1;
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
192 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
169 {
193 {
170 ring_node_for_averaging_sm_f1 = full_ring_node;
194 ring_node_for_averaging_sm_f1 = full_ring_node;
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
195 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
172 {
196 {
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
197 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
174 }
198 }
175 nb_sm_f1 = 0;
199 nb_sm_f1 = 0;
176 }
200 }
177 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
201 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
178 break;
202 break;
179 default:
203 default:
180 break;
204 break;
181 }
205 }
182 }
206 }
183
207
184 void spectral_matrices_isr_f2( int statusReg )
208 void spectral_matrices_isr_f2( int statusReg )
185 {
209 {
186 unsigned char status;
210 unsigned char status;
187 rtems_status_code status_code;
211 rtems_status_code status_code;
188
212
189 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
213 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
190
214
191 switch(status)
215 switch(status)
192 {
216 {
193 case 0:
217 case 0:
194 break;
218 break;
195 case BIT_READY_0_1:
219 case BIT_READY_0_1:
196 // UNEXPECTED VALUE
220 // UNEXPECTED VALUE
197 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
221 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
222 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
199 break;
223 break;
200 case BIT_READY_0:
224 case BIT_READY_0:
201 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
225 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
202 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
226 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
203 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
227 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
204 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
228 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
205 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
229 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
206 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
230 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
207 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
231 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
208 {
232 {
209 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
233 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
210 }
234 }
211 break;
235 break;
212 case BIT_READY_1:
236 case BIT_READY_1:
213 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
237 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
214 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
238 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
215 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
239 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
216 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
240 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
217 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
241 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
218 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
242 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
219 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
243 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
220 {
244 {
221 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
245 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
222 }
246 }
223 break;
247 break;
224 default:
248 default:
225 break;
249 break;
226 }
250 }
227 }
251 }
228
252
229 void spectral_matrix_isr_error_handler( int statusReg )
253 void spectral_matrix_isr_error_handler( int statusReg )
230 {
254 {
231 // STATUS REGISTER
255 // STATUS REGISTER
232 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
233 // 10 9 8
257 // 10 9 8
234 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
258 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
235 // 7 6 5 4 3 2 1 0
259 // 7 6 5 4 3 2 1 0
236 // [bad_component_err] not defined in the last version of the VHDL code
260 // [bad_component_err] not defined in the last version of the VHDL code
237
261
238 rtems_status_code status_code;
262 rtems_status_code status_code;
239
263
240 //***************************************************
264 //***************************************************
241 // the ASM status register is copied in the HK packet
265 // the ASM status register is copied in the HK packet
242 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
266 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
243
267
244 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
268 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
245 {
269 {
246 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
270 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
247 }
271 }
248
272
249 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
273 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
250
274
251 }
275 }
252
276
253 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
277 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
254 {
278 {
255 // STATUS REGISTER
279 // STATUS REGISTER
256 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
280 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
257 // 10 9 8
281 // 10 9 8
258 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
282 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
259 // 7 6 5 4 3 2 1 0
283 // 7 6 5 4 3 2 1 0
260
284
261 int statusReg;
285 int statusReg;
262
286
263 static restartState state = WAIT_FOR_F2;
287 static restartState state = WAIT_FOR_F2;
264
288
265 statusReg = spectral_matrix_regs->status;
289 statusReg = spectral_matrix_regs->status;
266
290
267 if (thisIsAnASMRestart == 0)
291 if (thisIsAnASMRestart == 0)
268 { // this is not a restart sequence, process incoming matrices normally
292 { // this is not a restart sequence, process incoming matrices normally
269 spectral_matrices_isr_f0( statusReg );
293 spectral_matrices_isr_f0( statusReg );
270
294
271 spectral_matrices_isr_f1( statusReg );
295 spectral_matrices_isr_f1( statusReg );
272
296
273 spectral_matrices_isr_f2( statusReg );
297 spectral_matrices_isr_f2( statusReg );
274 }
298 }
275 else
299 else
276 { // a restart sequence has to be launched
300 { // a restart sequence has to be launched
277 switch (state) {
301 switch (state) {
278 case WAIT_FOR_F2:
302 case WAIT_FOR_F2:
279 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
303 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
280 {
304 {
281 state = WAIT_FOR_F1;
305 state = WAIT_FOR_F1;
282 }
306 }
283 break;
307 break;
284 case WAIT_FOR_F1:
308 case WAIT_FOR_F1:
285 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
309 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
286 {
310 {
287 state = WAIT_FOR_F0;
311 state = WAIT_FOR_F0;
288 }
312 }
289 break;
313 break;
290 case WAIT_FOR_F0:
314 case WAIT_FOR_F0:
291 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
315 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
292 {
316 {
293 state = WAIT_FOR_F2;
317 state = WAIT_FOR_F2;
294 thisIsAnASMRestart = 0;
318 thisIsAnASMRestart = 0;
295 }
319 }
296 break;
320 break;
297 default:
321 default:
298 break;
322 break;
299 }
323 }
300 reset_sm_status();
324 reset_sm_status();
301 }
325 }
302
326
303 spectral_matrix_isr_error_handler( statusReg );
327 spectral_matrix_isr_error_handler( statusReg );
304
328
305 }
329 }
306
330
307 //******************
331 //******************
308 // Spectral Matrices
332 // Spectral Matrices
309
333
310 void reset_nb_sm( void )
334 void reset_nb_sm( void )
311 {
335 {
312 nb_sm_f0 = 0;
336 nb_sm_f0 = 0;
313 nb_sm_f0_aux_f1 = 0;
337 nb_sm_f0_aux_f1 = 0;
314 nb_sm_f0_aux_f2 = 0;
338 nb_sm_f0_aux_f2 = 0;
315
339
316 nb_sm_f1 = 0;
340 nb_sm_f1 = 0;
317 }
341 }
318
342
319 void SM_init_rings( void )
343 void SM_init_rings( void )
320 {
344 {
321 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
345 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
322 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
346 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
323 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
347 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
324
348
325 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
349 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
326 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
350 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
327 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
351 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
328 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
352 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
329 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
353 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
330 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
354 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
331 }
355 }
332
356
333 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
357 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
334 {
358 {
335 unsigned char i;
359 unsigned char i;
336
360
337 ring[ nbNodes - 1 ].next
361 ring[ nbNodes - 1 ].next
338 = (ring_node_asm*) &ring[ 0 ];
362 = (ring_node_asm*) &ring[ 0 ];
339
363
340 for(i=0; i<nbNodes-1; i++)
364 for(i=0; i<nbNodes-1; i++)
341 {
365 {
342 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
366 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
343 }
367 }
344 }
368 }
345
369
346 void SM_reset_current_ring_nodes( void )
370 void SM_reset_current_ring_nodes( void )
347 {
371 {
348 current_ring_node_sm_f0 = sm_ring_f0[0].next;
372 current_ring_node_sm_f0 = sm_ring_f0[0].next;
349 current_ring_node_sm_f1 = sm_ring_f1[0].next;
373 current_ring_node_sm_f1 = sm_ring_f1[0].next;
350 current_ring_node_sm_f2 = sm_ring_f2[0].next;
374 current_ring_node_sm_f2 = sm_ring_f2[0].next;
351
375
352 ring_node_for_averaging_sm_f0 = NULL;
376 ring_node_for_averaging_sm_f0 = NULL;
353 ring_node_for_averaging_sm_f1 = NULL;
377 ring_node_for_averaging_sm_f1 = NULL;
354 ring_node_for_averaging_sm_f2 = NULL;
378 ring_node_for_averaging_sm_f2 = NULL;
355 }
379 }
356
380
357 //*****************
381 //*****************
358 // Basic Parameters
382 // Basic Parameters
359
383
360 void BP_init_header( bp_packet *packet,
384 void BP_init_header( bp_packet *packet,
361 unsigned int apid, unsigned char sid,
385 unsigned int apid, unsigned char sid,
362 unsigned int packetLength, unsigned char blkNr )
386 unsigned int packetLength, unsigned char blkNr )
363 {
387 {
364 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
388 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
365 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
389 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
366 packet->reserved = INIT_CHAR;
390 packet->reserved = INIT_CHAR;
367 packet->userApplication = CCSDS_USER_APP;
391 packet->userApplication = CCSDS_USER_APP;
368 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
392 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
369 packet->packetID[1] = (unsigned char) (apid);
393 packet->packetID[1] = (unsigned char) (apid);
370 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
394 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
371 packet->packetSequenceControl[1] = INIT_CHAR;
395 packet->packetSequenceControl[1] = INIT_CHAR;
372 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
396 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
373 packet->packetLength[1] = (unsigned char) (packetLength);
397 packet->packetLength[1] = (unsigned char) (packetLength);
374 // DATA FIELD HEADER
398 // DATA FIELD HEADER
375 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
399 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
376 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
400 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
377 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
401 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
378 packet->destinationID = TM_DESTINATION_ID_GROUND;
402 packet->destinationID = TM_DESTINATION_ID_GROUND;
379 packet->time[BYTE_0] = INIT_CHAR;
403 packet->time[BYTE_0] = INIT_CHAR;
380 packet->time[BYTE_1] = INIT_CHAR;
404 packet->time[BYTE_1] = INIT_CHAR;
381 packet->time[BYTE_2] = INIT_CHAR;
405 packet->time[BYTE_2] = INIT_CHAR;
382 packet->time[BYTE_3] = INIT_CHAR;
406 packet->time[BYTE_3] = INIT_CHAR;
383 packet->time[BYTE_4] = INIT_CHAR;
407 packet->time[BYTE_4] = INIT_CHAR;
384 packet->time[BYTE_5] = INIT_CHAR;
408 packet->time[BYTE_5] = INIT_CHAR;
385 // AUXILIARY DATA HEADER
409 // AUXILIARY DATA HEADER
386 packet->sid = sid;
410 packet->sid = sid;
387 packet->pa_bia_status_info = INIT_CHAR;
411 packet->pa_bia_status_info = INIT_CHAR;
388 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
412 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
389 packet->sy_lfr_common_parameters = INIT_CHAR;
413 packet->sy_lfr_common_parameters = INIT_CHAR;
390 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
414 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
391 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
415 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
392 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
416 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
393 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
417 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
394 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
418 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
395 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
419 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
396 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
420 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
397 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
421 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
398 }
422 }
399
423
400 void BP_init_header_with_spare( bp_packet_with_spare *packet,
424 void BP_init_header_with_spare( bp_packet_with_spare *packet,
401 unsigned int apid, unsigned char sid,
425 unsigned int apid, unsigned char sid,
402 unsigned int packetLength , unsigned char blkNr)
426 unsigned int packetLength , unsigned char blkNr)
403 {
427 {
404 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
428 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
405 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
429 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
406 packet->reserved = INIT_CHAR;
430 packet->reserved = INIT_CHAR;
407 packet->userApplication = CCSDS_USER_APP;
431 packet->userApplication = CCSDS_USER_APP;
408 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
432 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
409 packet->packetID[1] = (unsigned char) (apid);
433 packet->packetID[1] = (unsigned char) (apid);
410 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
434 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
411 packet->packetSequenceControl[1] = INIT_CHAR;
435 packet->packetSequenceControl[1] = INIT_CHAR;
412 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
436 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
413 packet->packetLength[1] = (unsigned char) (packetLength);
437 packet->packetLength[1] = (unsigned char) (packetLength);
414 // DATA FIELD HEADER
438 // DATA FIELD HEADER
415 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
439 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
416 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
440 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
417 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
441 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
418 packet->destinationID = TM_DESTINATION_ID_GROUND;
442 packet->destinationID = TM_DESTINATION_ID_GROUND;
419 // AUXILIARY DATA HEADER
443 // AUXILIARY DATA HEADER
420 packet->sid = sid;
444 packet->sid = sid;
421 packet->pa_bia_status_info = INIT_CHAR;
445 packet->pa_bia_status_info = INIT_CHAR;
422 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
446 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
423 packet->sy_lfr_common_parameters = INIT_CHAR;
447 packet->sy_lfr_common_parameters = INIT_CHAR;
424 packet->time[BYTE_0] = INIT_CHAR;
448 packet->time[BYTE_0] = INIT_CHAR;
425 packet->time[BYTE_1] = INIT_CHAR;
449 packet->time[BYTE_1] = INIT_CHAR;
426 packet->time[BYTE_2] = INIT_CHAR;
450 packet->time[BYTE_2] = INIT_CHAR;
427 packet->time[BYTE_3] = INIT_CHAR;
451 packet->time[BYTE_3] = INIT_CHAR;
428 packet->time[BYTE_4] = INIT_CHAR;
452 packet->time[BYTE_4] = INIT_CHAR;
429 packet->time[BYTE_5] = INIT_CHAR;
453 packet->time[BYTE_5] = INIT_CHAR;
430 packet->source_data_spare = INIT_CHAR;
454 packet->source_data_spare = INIT_CHAR;
431 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
455 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
432 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
456 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
433 }
457 }
434
458
435 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
459 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
436 {
460 {
437 rtems_status_code status;
461 rtems_status_code status;
438
462
439 // SEND PACKET
463 // SEND PACKET
440 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
464 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
441 if (status != RTEMS_SUCCESSFUL)
465 if (status != RTEMS_SUCCESSFUL)
442 {
466 {
443 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
467 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
444 }
468 }
445 }
469 }
446
470
447 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
471 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
448 {
472 {
449 /** This function is used to send the BP paquets when needed.
473 /** This function is used to send the BP paquets when needed.
450 *
474 *
451 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
475 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
452 *
476 *
453 * @return void
477 * @return void
454 *
478 *
455 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
479 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
456 * BURST paquets are sent everytime.
480 * BURST paquets are sent everytime.
457 *
481 *
458 */
482 */
459
483
460 rtems_status_code status;
484 rtems_status_code status;
461
485
462 // SEND PACKET
486 // SEND PACKET
463 // before lastValidTransitionDate, the data are drops even if they are ready
487 // before lastValidTransitionDate, the data are drops even if they are ready
464 // this guarantees that no SBM packets will be received before the requested enter mode time
488 // this guarantees that no SBM packets will be received before the requested enter mode time
465 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
489 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
466 {
490 {
467 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
491 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
468 if (status != RTEMS_SUCCESSFUL)
492 if (status != RTEMS_SUCCESSFUL)
469 {
493 {
470 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
494 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
471 }
495 }
472 }
496 }
473 }
497 }
474
498
475 //******************
499 //******************
476 // general functions
500 // general functions
477
501
478 void reset_sm_status( void )
502 void reset_sm_status( void )
479 {
503 {
480 // error
504 // error
481 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
505 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
482 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
506 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
483 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
507 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
484 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
508 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
485
509
486 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
510 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
487 }
511 }
488
512
489 void reset_spectral_matrix_regs( void )
513 void reset_spectral_matrix_regs( void )
490 {
514 {
491 /** This function resets the spectral matrices module registers.
515 /** This function resets the spectral matrices module registers.
492 *
516 *
493 * The registers affected by this function are located at the following offset addresses:
517 * The registers affected by this function are located at the following offset addresses:
494 *
518 *
495 * - 0x00 config
519 * - 0x00 config
496 * - 0x04 status
520 * - 0x04 status
497 * - 0x08 matrixF0_Address0
521 * - 0x08 matrixF0_Address0
498 * - 0x10 matrixFO_Address1
522 * - 0x10 matrixFO_Address1
499 * - 0x14 matrixF1_Address
523 * - 0x14 matrixF1_Address
500 * - 0x18 matrixF2_Address
524 * - 0x18 matrixF2_Address
501 *
525 *
502 */
526 */
503
527
504 set_sm_irq_onError( 0 );
528 set_sm_irq_onError( 0 );
505
529
506 set_sm_irq_onNewMatrix( 0 );
530 set_sm_irq_onNewMatrix( 0 );
507
531
508 reset_sm_status();
532 reset_sm_status();
509
533
510 // F1
534 // F1
511 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
535 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
512 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
536 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
513 // F2
537 // F2
514 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
538 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
515 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
539 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
516 // F3
540 // F3
517 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
541 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
518 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
542 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
519
543
520 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
544 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
521 }
545 }
522
546
523 void set_time( unsigned char *time, unsigned char * timeInBuffer )
547 void set_time( unsigned char *time, unsigned char * timeInBuffer )
524 {
548 {
525 time[BYTE_0] = timeInBuffer[BYTE_0];
549 time[BYTE_0] = timeInBuffer[BYTE_0];
526 time[BYTE_1] = timeInBuffer[BYTE_1];
550 time[BYTE_1] = timeInBuffer[BYTE_1];
527 time[BYTE_2] = timeInBuffer[BYTE_2];
551 time[BYTE_2] = timeInBuffer[BYTE_2];
528 time[BYTE_3] = timeInBuffer[BYTE_3];
552 time[BYTE_3] = timeInBuffer[BYTE_3];
529 time[BYTE_4] = timeInBuffer[BYTE_6];
553 time[BYTE_4] = timeInBuffer[BYTE_6];
530 time[BYTE_5] = timeInBuffer[BYTE_7];
554 time[BYTE_5] = timeInBuffer[BYTE_7];
531 }
555 }
532
556
533 unsigned long long int get_acquisition_time( unsigned char *timePtr )
557 unsigned long long int get_acquisition_time( unsigned char *timePtr )
534 {
558 {
535 unsigned long long int acquisitionTimeAslong;
559 unsigned long long int acquisitionTimeAslong;
536 acquisitionTimeAslong = INIT_CHAR;
560 acquisitionTimeAslong = INIT_CHAR;
537 acquisitionTimeAslong =
561 acquisitionTimeAslong =
538 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
562 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
539 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
563 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
540 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
564 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
541 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
565 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
542 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
566 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
543 + ( (unsigned long long int) timePtr[BYTE_7] );
567 + ( (unsigned long long int) timePtr[BYTE_7] );
544 return acquisitionTimeAslong;
568 return acquisitionTimeAslong;
545 }
569 }
546
570
547 unsigned char getSID( rtems_event_set event )
571 unsigned char getSID( rtems_event_set event )
548 {
572 {
549 unsigned char sid;
573 unsigned char sid;
550
574
551 rtems_event_set eventSetBURST;
575 rtems_event_set eventSetBURST;
552 rtems_event_set eventSetSBM;
576 rtems_event_set eventSetSBM;
553
577
554 sid = 0;
578 sid = 0;
555
579
556 //******
580 //******
557 // BURST
581 // BURST
558 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
582 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
559 | RTEMS_EVENT_BURST_BP1_F1
583 | RTEMS_EVENT_BURST_BP1_F1
560 | RTEMS_EVENT_BURST_BP2_F0
584 | RTEMS_EVENT_BURST_BP2_F0
561 | RTEMS_EVENT_BURST_BP2_F1;
585 | RTEMS_EVENT_BURST_BP2_F1;
562
586
563 //****
587 //****
564 // SBM
588 // SBM
565 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
589 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
566 | RTEMS_EVENT_SBM_BP1_F1
590 | RTEMS_EVENT_SBM_BP1_F1
567 | RTEMS_EVENT_SBM_BP2_F0
591 | RTEMS_EVENT_SBM_BP2_F0
568 | RTEMS_EVENT_SBM_BP2_F1;
592 | RTEMS_EVENT_SBM_BP2_F1;
569
593
570 if (event & eventSetBURST)
594 if (event & eventSetBURST)
571 {
595 {
572 sid = SID_BURST_BP1_F0;
596 sid = SID_BURST_BP1_F0;
573 }
597 }
574 else if (event & eventSetSBM)
598 else if (event & eventSetSBM)
575 {
599 {
576 sid = SID_SBM1_BP1_F0;
600 sid = SID_SBM1_BP1_F0;
577 }
601 }
578 else
602 else
579 {
603 {
580 sid = 0;
604 sid = 0;
581 }
605 }
582
606
583 return sid;
607 return sid;
584 }
608 }
585
609
610 /**
611 * @brief extractReImVectors converts a given ASM component from interleaved to split representation
612 * @param inputASM
613 * @param outputASM
614 * @param asmComponent
615 */
586 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
616 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
587 {
617 {
588 unsigned int i;
618 unsigned int i;
589 float re;
619 float re;
590 float im;
620 float im;
591
621
592 for (i=0; i<NB_BINS_PER_SM; i++){
622 for (i=0; i<NB_BINS_PER_SM; i++){
593 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
623 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
594 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
624 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
595 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
625 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
596 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
626 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
597 }
627 }
598 }
628 }
599
629
630 /**
631 * @brief copyReVectors copies real part of a given ASM from inputASM to outputASM
632 * @param inputASM
633 * @param outputASM
634 * @param asmComponent
635 */
600 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
636 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
601 {
637 {
602 unsigned int i;
638 unsigned int i;
603 float re;
639 float re;
604
640
605 for (i=0; i<NB_BINS_PER_SM; i++){
641 for (i=0; i<NB_BINS_PER_SM; i++){
606 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
642 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
607 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
643 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
608 }
644 }
609 }
645 }
610
646
647 /**
648 * @brief ASM_patch, converts ASM from interleaved to split representation
649 * @param inputASM
650 * @param outputASM
651 * @note inputASM and outputASM must be different, in other words this function can't do in place convertion
652 * @see extractReImVectors
653 */
611 void ASM_patch( float *inputASM, float *outputASM )
654 void ASM_patch( float *inputASM, float *outputASM )
612 {
655 {
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
656 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
614 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
657 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
615 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
658 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
616 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
659 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
617 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
660 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
618 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
661 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
619 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
662 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
620 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
663 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
621 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
664 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
622 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
665 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
623
666
624 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
667 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
625 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
668 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
626 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
669 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
627 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
670 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
628 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
671 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
629 }
672 }
630
673
631 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
674 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
632 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
675 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
633 unsigned char ASMIndexStart,
676 unsigned char ASMIndexStart,
634 unsigned char channel )
677 unsigned char channel )
635 {
678 {
636 //*************
679 //*************
637 // input format
680 // input format
638 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
681 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
639 //**************
682 //**************
640 // output format
683 // output format
641 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
684 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
642 //************
685 //************
643 // compression
686 // compression
644 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
687 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
645 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
688 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
646
689
647 int frequencyBin;
690 int frequencyBin;
648 int asmComponent;
691 int asmComponent;
649 int offsetASM;
692 int offsetASM;
650 int offsetCompressed;
693 int offsetCompressed;
651 int offsetFBin;
694 int offsetFBin;
652 int fBinMask;
695 int fBinMask;
653 int k;
696 int k;
654
697
655 // BUILD DATA
698 // BUILD DATA
656 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
699 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
657 {
700 {
658 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
701 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
659 {
702 {
660 offsetCompressed = // NO TIME OFFSET
703 offsetCompressed = // NO TIME OFFSET
661 (frequencyBin * NB_VALUES_PER_SM)
704 (frequencyBin * NB_VALUES_PER_SM)
662 + asmComponent;
705 + asmComponent;
663 offsetASM = // NO TIME OFFSET
706 offsetASM = // NO TIME OFFSET
664 (asmComponent * NB_BINS_PER_SM)
707 (asmComponent * NB_BINS_PER_SM)
665 + ASMIndexStart
708 + ASMIndexStart
666 + (frequencyBin * nbBinsToAverage);
709 + (frequencyBin * nbBinsToAverage);
667 offsetFBin = ASMIndexStart
710 offsetFBin = ASMIndexStart
668 + (frequencyBin * nbBinsToAverage);
711 + (frequencyBin * nbBinsToAverage);
669 compressed_spec_mat[ offsetCompressed ] = 0;
712 compressed_spec_mat[ offsetCompressed ] = 0;
670 for ( k = 0; k < nbBinsToAverage; k++ )
713 for ( k = 0; k < nbBinsToAverage; k++ )
671 {
714 {
672 fBinMask = getFBinMask( offsetFBin + k, channel );
715 fBinMask = getFBinMask( offsetFBin + k, channel );
673 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
716 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
674 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
717 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
675 }
718 }
676 if (divider != 0)
719 if (divider != 0)
677 {
720 {
678 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
721 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
679 }
722 }
680 else
723 else
681 {
724 {
682 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
725 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
683 }
726 }
684 }
727 }
685 }
728 }
686
729
687 }
730 }
688
731
689 int getFBinMask( int index, unsigned char channel )
732 int getFBinMask( int index, unsigned char channel )
690 {
733 {
691 unsigned int indexInChar;
734 unsigned int indexInChar;
692 unsigned int indexInTheChar;
735 unsigned int indexInTheChar;
693 int fbin;
736 int fbin;
694 unsigned char *sy_lfr_fbins_fx_word1;
737 unsigned char *sy_lfr_fbins_fx_word1;
695
738
696 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
739 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
697
740
698 switch(channel)
741 switch(channel)
699 {
742 {
700 case CHANNELF0:
743 case CHANNELF0:
701 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
744 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
702 break;
745 break;
703 case CHANNELF1:
746 case CHANNELF1:
704 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
747 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
705 break;
748 break;
706 case CHANNELF2:
749 case CHANNELF2:
707 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
750 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
708 break;
751 break;
709 default:
752 default:
710 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
753 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
711 }
754 }
712
755
713 indexInChar = index >> SHIFT_3_BITS;
756 indexInChar = index >> SHIFT_3_BITS;
714 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
757 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
715
758
716 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
759 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
717
760
718 return fbin;
761 return fbin;
719 }
762 }
720
763
764 /**
765 * @brief isPolluted returns MATRIX_IS_POLLUTED if there is any overlap between t0:t1 and tbad0:tbad1 ranges
766 * @param t0 Start acquisition time
767 * @param t1 End of acquisition time
768 * @param tbad0 Start time of poluting signal
769 * @param tbad1 End time of poluting signal
770 * @return
771 */
721 unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 )
772 unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 )
722 {
773 {
723 unsigned char polluted;
774 unsigned char polluted;
724
775
725 polluted = MATRIX_IS_NOT_POLLUTED;
776 polluted = MATRIX_IS_NOT_POLLUTED;
726
777
727 if ( ((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range
778 if ( ((tbad0 < t0) && (t0 < tbad1)) // t0 is inside the polluted range
728 || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range
779 || ((tbad0 < t1) && (t1 < tbad1)) // t1 is inside the polluted range
729 || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range
780 || ((t0 < tbad0) && (tbad1 < t1)) // the polluted range is inside the signal range
730 || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range
781 || ((tbad0 < t0) && (t1 < tbad1))) // the signal range is inside the polluted range
731 {
782 {
732 polluted = MATRIX_IS_POLLUTED;
783 polluted = MATRIX_IS_POLLUTED;
733 }
784 }
734
785
735 return polluted;
786 return polluted;
736 }
787 }
737
788
789 /**
790 * @brief acquisitionTimeIsValid checks if the given acquisition time is poluted by PAS
791 * @param coarseTime Coarse acquisition time of the given SM
792 * @param fineTime Fine acquisition time of the given ASM
793 * @param channel Frequency channel to check, will impact SM time footprint
794 * @return MATRIX_IS_POLLUTED if there is any time overlap between SM and PAS poluting signal
795 */
738 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
796 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
739 {
797 {
740 u_int64_t t0;
798 u_int64_t t0;
741 u_int64_t t1;
799 u_int64_t t1;
742 u_int64_t tc;
800 u_int64_t tc;
743 u_int64_t tbad0;
801 u_int64_t tbad0;
744 u_int64_t tbad1;
802 u_int64_t tbad1;
745
803
746 u_int64_t modulusInFineTime;
804 u_int64_t modulusInFineTime;
747 u_int64_t offsetInFineTime;
805 u_int64_t offsetInFineTime;
748 u_int64_t shiftInFineTime;
806 u_int64_t shiftInFineTime;
749 u_int64_t tbadInFineTime;
807 u_int64_t tbadInFineTime;
750
808
751 u_int64_t timecodeReference;
809 u_int64_t timecodeReference;
752
810
753 unsigned char pasFilteringIsEnabled;
811 unsigned char pasFilteringIsEnabled;
754 unsigned char ret;
812 unsigned char ret;
755
813
756 // compute acquisition time from caoarseTime and fineTime
814 // compute acquisition time from caoarseTime and fineTime
757 t0 = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES ) + (u_int64_t) fineTime;
815 t0 = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES ) + (u_int64_t) fineTime;
758 t1 = t0;
816 t1 = t0;
759 tc = t0;
817 tc = t0;
760 tbad0 = t0;
818 tbad0 = t0;
761 tbad1 = t0;
819 tbad1 = t0;
762
820
763 switch(channel)
821 switch(channel)
764 {
822 {
765 case CHANNELF0:
823 case CHANNELF0:
766 t1 = t0 + ACQUISITION_DURATION_F0;
824 t1 = t0 + ACQUISITION_DURATION_F0;
767 tc = t0 + HALF_ACQUISITION_DURATION_F0;
825 tc = t0 + HALF_ACQUISITION_DURATION_F0;
768 break;
826 break;
769 case CHANNELF1:
827 case CHANNELF1:
770 t1 = t0 + ACQUISITION_DURATION_F1;
828 t1 = t0 + ACQUISITION_DURATION_F1;
771 tc = t0 + HALF_ACQUISITION_DURATION_F1;
829 tc = t0 + HALF_ACQUISITION_DURATION_F1;
772 break;
830 break;
773 case CHANNELF2:
831 case CHANNELF2:
774 t1 = t0 + ACQUISITION_DURATION_F2;
832 t1 = t0 + ACQUISITION_DURATION_F2;
775 tc = t0 + HALF_ACQUISITION_DURATION_F2;
833 tc = t0 + HALF_ACQUISITION_DURATION_F2;
776 break;
834 break;
777 default:
835 default:
778 break;
836 break;
779 }
837 }
780
838
781 // compute the acquitionTime range
839 // compute the acquitionTime range
782 modulusInFineTime = filterPar.modulus_in_finetime;
840 modulusInFineTime = filterPar.modulus_in_finetime;
783 offsetInFineTime = filterPar.offset_in_finetime;
841 offsetInFineTime = filterPar.offset_in_finetime;
784 shiftInFineTime = filterPar.shift_in_finetime;
842 shiftInFineTime = filterPar.shift_in_finetime;
785 tbadInFineTime = filterPar.tbad_in_finetime;
843 tbadInFineTime = filterPar.tbad_in_finetime;
786 timecodeReference = INIT_INT;
844 timecodeReference = INIT_INT;
787
845
788 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
846 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
789 ret = MATRIX_IS_NOT_POLLUTED;
847 ret = MATRIX_IS_NOT_POLLUTED;
790
848
791 if ( (tbadInFineTime == 0) || (pasFilteringIsEnabled == 0) )
849 if ( (tbadInFineTime == 0) || (pasFilteringIsEnabled == 0) )
792 {
850 {
793 ret = MATRIX_IS_NOT_POLLUTED;
851 ret = MATRIX_IS_NOT_POLLUTED;
794 }
852 }
795 else
853 else
796 {
854 {
797 // INTERSECTION TEST #1
855 // INTERSECTION TEST #1
798 timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime ;
856 timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime ;
799 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
857 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
800 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
858 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
801 ret = isPolluted( t0, t1, tbad0, tbad1 );
859 ret = isPolluted( t0, t1, tbad0, tbad1 );
802
860
803 // INTERSECTION TEST #2
861 // INTERSECTION TEST #2
804 if (ret == MATRIX_IS_NOT_POLLUTED)
862 if (ret == MATRIX_IS_NOT_POLLUTED)
805 {
863 {
806 timecodeReference = (tc - (tc % modulusInFineTime)) ;
864 timecodeReference = (tc - (tc % modulusInFineTime)) ;
807 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
865 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
808 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
866 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
809 ret = isPolluted( t0, t1, tbad0, tbad1 );
867 ret = isPolluted( t0, t1, tbad0, tbad1 );
810 }
868 }
811
869
812 // INTERSECTION TEST #3
870 // INTERSECTION TEST #3
813 if (ret == MATRIX_IS_NOT_POLLUTED)
871 if (ret == MATRIX_IS_NOT_POLLUTED)
814 {
872 {
815 timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime ;
873 timecodeReference = (tc - (tc % modulusInFineTime)) + modulusInFineTime ;
816 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
874 tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
817 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
875 tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
818 ret = isPolluted( t0, t1, tbad0, tbad1 );
876 ret = isPolluted( t0, t1, tbad0, tbad1 );
819 }
877 }
820 }
878 }
821
879
822 return ret;
880 return ret;
823 }
881 }
824
882
825 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
883 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
826 {
884 {
827 unsigned char bin;
885 unsigned char bin;
828 unsigned char kcoeff;
886 unsigned char kcoeff;
829
887
830 for (bin=0; bin<nb_bins_norm; bin++)
888 for (bin=0; bin<nb_bins_norm; bin++)
831 {
889 {
832 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
890 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
833 {
891 {
834 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
892 output_kcoeff[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
835 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
893 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
836 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
894 output_kcoeff[ ( ( (bin * NB_K_COEFF_PER_BIN ) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ) + 1 ]
837 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
895 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
838 }
896 }
839 }
897 }
840 }
898 }
@@ -1,481 +1,504
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
1 /** Functions related to TeleCommand acceptance.
24 /** Functions related to TeleCommand acceptance.
2 *
25 *
3 * @file
26 * @file
4 * @author P. LEROY
27 * @author P. LEROY
5 *
28 *
6 * A group of functions to handle TeleCommands parsing.\n
29 * A group of functions to handle TeleCommands parsing.\n
7 *
30 *
8 */
31 */
9
32
10 #include "tc_acceptance.h"
33 #include "tc_acceptance.h"
11 #include <stdio.h>
34 #include <stdio.h>
12
35
13 unsigned int lookUpTableForCRC[CONST_256] = {0};
36 unsigned int lookUpTableForCRC[CONST_256] = {0};
14
37
15 //**********************
38 //**********************
16 // GENERAL USE FUNCTIONS
39 // GENERAL USE FUNCTIONS
17 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
40 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
18 {
41 {
19 /** This function generate the CRC for one byte and returns the value of the new syndrome.
42 /** This function generate the CRC for one byte and returns the value of the new syndrome.
20 *
43 *
21 * @param D is the current byte of data.
44 * @param D is the current byte of data.
22 * @param Chk is the current syndrom value.
45 * @param Chk is the current syndrom value.
23 *
46 *
24 * @return the value of the new syndrome on two bytes.
47 * @return the value of the new syndrome on two bytes.
25 *
48 *
26 */
49 */
27
50
28 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
51 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
29 }
52 }
30
53
31 void initLookUpTableForCRC( void )
54 void initLookUpTableForCRC( void )
32 {
55 {
33 /** This function is used to initiates the look-up table for fast CRC computation.
56 /** This function is used to initiates the look-up table for fast CRC computation.
34 *
57 *
35 * The global table lookUpTableForCRC[256] is initiated.
58 * The global table lookUpTableForCRC[256] is initiated.
36 *
59 *
37 */
60 */
38
61
39 unsigned int i;
62 unsigned int i;
40 unsigned int tmp;
63 unsigned int tmp;
41
64
42 for (i=0; i<CONST_256; i++)
65 for (i=0; i<CONST_256; i++)
43 {
66 {
44 tmp = 0;
67 tmp = 0;
45 if((i & BIT_0) != 0) {
68 if((i & BIT_0) != 0) {
46 tmp = tmp ^ CONST_CRC_0;
69 tmp = tmp ^ CONST_CRC_0;
47 }
70 }
48 if((i & BIT_1) != 0) {
71 if((i & BIT_1) != 0) {
49 tmp = tmp ^ CONST_CRC_1;
72 tmp = tmp ^ CONST_CRC_1;
50 }
73 }
51 if((i & BIT_2) != 0) {
74 if((i & BIT_2) != 0) {
52 tmp = tmp ^ CONST_CRC_2;
75 tmp = tmp ^ CONST_CRC_2;
53 }
76 }
54 if((i & BIT_3) != 0) {
77 if((i & BIT_3) != 0) {
55 tmp = tmp ^ CONST_CRC_3;
78 tmp = tmp ^ CONST_CRC_3;
56 }
79 }
57 if((i & BIT_4) != 0) {
80 if((i & BIT_4) != 0) {
58 tmp = tmp ^ CONST_CRC_4;
81 tmp = tmp ^ CONST_CRC_4;
59 }
82 }
60 if((i & BIT_5) != 0) {
83 if((i & BIT_5) != 0) {
61 tmp = tmp ^ CONST_CRC_5;
84 tmp = tmp ^ CONST_CRC_5;
62 }
85 }
63 if((i & BIT_6) != 0) {
86 if((i & BIT_6) != 0) {
64 tmp = tmp ^ CONST_CRC_6;
87 tmp = tmp ^ CONST_CRC_6;
65 }
88 }
66 if((i & BIT_7) != 0) {
89 if((i & BIT_7) != 0) {
67 tmp = tmp ^ CONST_CRC_7;
90 tmp = tmp ^ CONST_CRC_7;
68 }
91 }
69 lookUpTableForCRC[i] = tmp;
92 lookUpTableForCRC[i] = tmp;
70 }
93 }
71 }
94 }
72
95
73 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
96 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
74 {
97 {
75 /** This function calculates a two bytes Cyclic Redundancy Code.
98 /** This function calculates a two bytes Cyclic Redundancy Code.
76 *
99 *
77 * @param data points to a buffer containing the data on which to compute the CRC.
100 * @param data points to a buffer containing the data on which to compute the CRC.
78 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
101 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
79 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
102 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
80 *
103 *
81 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
104 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
82 *
105 *
83 */
106 */
84
107
85 unsigned int Chk;
108 unsigned int Chk;
86 int j;
109 int j;
87 Chk = CRC_RESET; // reset the syndrom to all ones
110 Chk = CRC_RESET; // reset the syndrom to all ones
88 for (j=0; j<sizeOfData; j++) {
111 for (j=0; j<sizeOfData; j++) {
89 Chk = Crc_opt(data[j], Chk);
112 Chk = Crc_opt(data[j], Chk);
90 }
113 }
91 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
114 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
92 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
115 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
93 }
116 }
94
117
95 //*********************
118 //*********************
96 // ACCEPTANCE FUNCTIONS
119 // ACCEPTANCE FUNCTIONS
97 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
120 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
98 {
121 {
99 /** This function parses TeleCommands.
122 /** This function parses TeleCommands.
100 *
123 *
101 * @param TC points to the TeleCommand that will be parsed.
124 * @param TC points to the TeleCommand that will be parsed.
102 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
125 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
103 *
126 *
104 * @return Status code of the parsing.
127 * @return Status code of the parsing.
105 *
128 *
106 * The parsing checks:
129 * The parsing checks:
107 * - process id
130 * - process id
108 * - category
131 * - category
109 * - length: a global check is performed and a per subtype check also
132 * - length: a global check is performed and a per subtype check also
110 * - type
133 * - type
111 * - subtype
134 * - subtype
112 * - crc
135 * - crc
113 *
136 *
114 */
137 */
115
138
116 int status;
139 int status;
117 int status_crc;
140 int status_crc;
118 unsigned char pid;
141 unsigned char pid;
119 unsigned char category;
142 unsigned char category;
120 unsigned int packetLength;
143 unsigned int packetLength;
121 unsigned char packetType;
144 unsigned char packetType;
122 unsigned char packetSubtype;
145 unsigned char packetSubtype;
123 unsigned char sid;
146 unsigned char sid;
124
147
125 status = CCSDS_TM_VALID;
148 status = CCSDS_TM_VALID;
126
149
127 // APID check *** APID on 2 bytes
150 // APID check *** APID on 2 bytes
128 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
151 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
129 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
152 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
130 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
153 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
131 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
154 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
132 packetType = TCPacket->serviceType;
155 packetType = TCPacket->serviceType;
133 packetSubtype = TCPacket->serviceSubType;
156 packetSubtype = TCPacket->serviceSubType;
134 sid = TCPacket->sourceID;
157 sid = TCPacket->sourceID;
135
158
136 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
159 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
137 {
160 {
138 status = ILLEGAL_APID;
161 status = ILLEGAL_APID;
139 }
162 }
140 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
163 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
141 {
164 {
142 if ( category != CCSDS_PACKET_CATEGORY )
165 if ( category != CCSDS_PACKET_CATEGORY )
143 {
166 {
144 status = ILLEGAL_APID;
167 status = ILLEGAL_APID;
145 }
168 }
146 }
169 }
147 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
170 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
148 {
171 {
149 if (packetLength != estimatedPacketLength ) {
172 if (packetLength != estimatedPacketLength ) {
150 status = WRONG_LEN_PKT;
173 status = WRONG_LEN_PKT;
151 }
174 }
152 }
175 }
153 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
176 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
154 {
177 {
155 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
178 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
156 status = WRONG_LEN_PKT;
179 status = WRONG_LEN_PKT;
157 }
180 }
158 }
181 }
159 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
182 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
160 {
183 {
161 status = tc_check_type( packetType );
184 status = tc_check_type( packetType );
162 }
185 }
163 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
186 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
164 {
187 {
165 status = tc_check_type_subtype( packetType, packetSubtype );
188 status = tc_check_type_subtype( packetType, packetSubtype );
166 }
189 }
167 if (status == CCSDS_TM_VALID) // CHECK THE SID
190 if (status == CCSDS_TM_VALID) // CHECK THE SID
168 {
191 {
169 status = tc_check_sid( sid );
192 status = tc_check_sid( sid );
170 }
193 }
171 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
194 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
172 {
195 {
173 status = tc_check_length( packetSubtype, packetLength );
196 status = tc_check_length( packetSubtype, packetLength );
174 }
197 }
175 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
198 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
176 if (status == CCSDS_TM_VALID ) // CHECK CRC
199 if (status == CCSDS_TM_VALID ) // CHECK CRC
177 {
200 {
178 status = status_crc;
201 status = status_crc;
179 }
202 }
180
203
181 return status;
204 return status;
182 }
205 }
183
206
184 int tc_check_type( unsigned char packetType )
207 int tc_check_type( unsigned char packetType )
185 {
208 {
186 /** This function checks that the type of a TeleCommand is valid.
209 /** This function checks that the type of a TeleCommand is valid.
187 *
210 *
188 * @param packetType is the type to check.
211 * @param packetType is the type to check.
189 *
212 *
190 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
213 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
191 *
214 *
192 */
215 */
193
216
194 int status;
217 int status;
195
218
196 status = ILL_TYPE;
219 status = ILL_TYPE;
197
220
198 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
221 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
199 {
222 {
200 status = CCSDS_TM_VALID;
223 status = CCSDS_TM_VALID;
201 }
224 }
202 else
225 else
203 {
226 {
204 status = ILL_TYPE;
227 status = ILL_TYPE;
205 }
228 }
206
229
207 return status;
230 return status;
208 }
231 }
209
232
210 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
233 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
211 {
234 {
212 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
235 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
213 *
236 *
214 * @param packetType is the type of the TC.
237 * @param packetType is the type of the TC.
215 * @param packetSubType is the subtype to check.
238 * @param packetSubType is the subtype to check.
216 *
239 *
217 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
240 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
218 *
241 *
219 */
242 */
220
243
221 int status;
244 int status;
222
245
223 switch(packetType)
246 switch(packetType)
224 {
247 {
225 case TC_TYPE_GEN:
248 case TC_TYPE_GEN:
226 if ( (packetSubType == TC_SUBTYPE_RESET)
249 if ( (packetSubType == TC_SUBTYPE_RESET)
227 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
250 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
228 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
251 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
229 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
252 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
230 || (packetSubType == TC_SUBTYPE_DUMP)
253 || (packetSubType == TC_SUBTYPE_DUMP)
231 || (packetSubType == TC_SUBTYPE_ENTER)
254 || (packetSubType == TC_SUBTYPE_ENTER)
232 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
255 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
233 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
256 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
234 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
257 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
235 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
258 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
236 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
259 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
237 {
260 {
238 status = CCSDS_TM_VALID;
261 status = CCSDS_TM_VALID;
239 }
262 }
240 else
263 else
241 {
264 {
242 status = ILL_SUBTYPE;
265 status = ILL_SUBTYPE;
243 }
266 }
244 break;
267 break;
245
268
246 case TC_TYPE_TIME:
269 case TC_TYPE_TIME:
247 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
270 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
248 {
271 {
249 status = CCSDS_TM_VALID;
272 status = CCSDS_TM_VALID;
250 }
273 }
251 else
274 else
252 {
275 {
253 status = ILL_SUBTYPE;
276 status = ILL_SUBTYPE;
254 }
277 }
255 break;
278 break;
256
279
257 default:
280 default:
258 status = ILL_SUBTYPE;
281 status = ILL_SUBTYPE;
259 break;
282 break;
260 }
283 }
261
284
262 return status;
285 return status;
263 }
286 }
264
287
265 int tc_check_sid( unsigned char sid )
288 int tc_check_sid( unsigned char sid )
266 {
289 {
267 /** This function checks that the sid of a TeleCommand is valid.
290 /** This function checks that the sid of a TeleCommand is valid.
268 *
291 *
269 * @param sid is the sid to check.
292 * @param sid is the sid to check.
270 *
293 *
271 * @return Status code CCSDS_TM_VALID or CORRUPTED.
294 * @return Status code CCSDS_TM_VALID or CORRUPTED.
272 *
295 *
273 */
296 */
274
297
275 int status;
298 int status;
276
299
277 status = WRONG_SRC_ID;
300 status = WRONG_SRC_ID;
278
301
279 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
302 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
280 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
303 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
281 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
304 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
282 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
305 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
283 || (sid == SID_TC_RPW_INTERNAL))
306 || (sid == SID_TC_RPW_INTERNAL))
284 {
307 {
285 status = CCSDS_TM_VALID;
308 status = CCSDS_TM_VALID;
286 }
309 }
287 else
310 else
288 {
311 {
289 status = WRONG_SRC_ID;
312 status = WRONG_SRC_ID;
290 }
313 }
291
314
292 return status;
315 return status;
293 }
316 }
294
317
295 int tc_check_length( unsigned char packetSubType, unsigned int length )
318 int tc_check_length( unsigned char packetSubType, unsigned int length )
296 {
319 {
297 /** This function checks that the subtype and the length are compliant.
320 /** This function checks that the subtype and the length are compliant.
298 *
321 *
299 * @param packetSubType is the subtype to check.
322 * @param packetSubType is the subtype to check.
300 * @param length is the length to check.
323 * @param length is the length to check.
301 *
324 *
302 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
325 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
303 *
326 *
304 */
327 */
305
328
306 int status;
329 int status;
307
330
308 status = LFR_SUCCESSFUL;
331 status = LFR_SUCCESSFUL;
309
332
310 switch(packetSubType)
333 switch(packetSubType)
311 {
334 {
312 case TC_SUBTYPE_RESET:
335 case TC_SUBTYPE_RESET:
313 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
336 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
314 status = WRONG_LEN_PKT;
337 status = WRONG_LEN_PKT;
315 }
338 }
316 else {
339 else {
317 status = CCSDS_TM_VALID;
340 status = CCSDS_TM_VALID;
318 }
341 }
319 break;
342 break;
320 case TC_SUBTYPE_LOAD_COMM:
343 case TC_SUBTYPE_LOAD_COMM:
321 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
344 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
322 status = WRONG_LEN_PKT;
345 status = WRONG_LEN_PKT;
323 }
346 }
324 else {
347 else {
325 status = CCSDS_TM_VALID;
348 status = CCSDS_TM_VALID;
326 }
349 }
327 break;
350 break;
328 case TC_SUBTYPE_LOAD_NORM:
351 case TC_SUBTYPE_LOAD_NORM:
329 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
352 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
330 status = WRONG_LEN_PKT;
353 status = WRONG_LEN_PKT;
331 }
354 }
332 else {
355 else {
333 status = CCSDS_TM_VALID;
356 status = CCSDS_TM_VALID;
334 }
357 }
335 break;
358 break;
336 case TC_SUBTYPE_LOAD_BURST:
359 case TC_SUBTYPE_LOAD_BURST:
337 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
360 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
338 status = WRONG_LEN_PKT;
361 status = WRONG_LEN_PKT;
339 }
362 }
340 else {
363 else {
341 status = CCSDS_TM_VALID;
364 status = CCSDS_TM_VALID;
342 }
365 }
343 break;
366 break;
344 case TC_SUBTYPE_LOAD_SBM1:
367 case TC_SUBTYPE_LOAD_SBM1:
345 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
368 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
346 status = WRONG_LEN_PKT;
369 status = WRONG_LEN_PKT;
347 }
370 }
348 else {
371 else {
349 status = CCSDS_TM_VALID;
372 status = CCSDS_TM_VALID;
350 }
373 }
351 break;
374 break;
352 case TC_SUBTYPE_LOAD_SBM2:
375 case TC_SUBTYPE_LOAD_SBM2:
353 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
376 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
354 status = WRONG_LEN_PKT;
377 status = WRONG_LEN_PKT;
355 }
378 }
356 else {
379 else {
357 status = CCSDS_TM_VALID;
380 status = CCSDS_TM_VALID;
358 }
381 }
359 break;
382 break;
360 case TC_SUBTYPE_DUMP:
383 case TC_SUBTYPE_DUMP:
361 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
384 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
362 status = WRONG_LEN_PKT;
385 status = WRONG_LEN_PKT;
363 }
386 }
364 else {
387 else {
365 status = CCSDS_TM_VALID;
388 status = CCSDS_TM_VALID;
366 }
389 }
367 break;
390 break;
368 case TC_SUBTYPE_ENTER:
391 case TC_SUBTYPE_ENTER:
369 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
392 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
370 status = WRONG_LEN_PKT;
393 status = WRONG_LEN_PKT;
371 }
394 }
372 else {
395 else {
373 status = CCSDS_TM_VALID;
396 status = CCSDS_TM_VALID;
374 }
397 }
375 break;
398 break;
376 case TC_SUBTYPE_UPDT_INFO:
399 case TC_SUBTYPE_UPDT_INFO:
377 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
400 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
378 status = WRONG_LEN_PKT;
401 status = WRONG_LEN_PKT;
379 }
402 }
380 else {
403 else {
381 status = CCSDS_TM_VALID;
404 status = CCSDS_TM_VALID;
382 }
405 }
383 break;
406 break;
384 case TC_SUBTYPE_EN_CAL:
407 case TC_SUBTYPE_EN_CAL:
385 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
408 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
386 status = WRONG_LEN_PKT;
409 status = WRONG_LEN_PKT;
387 }
410 }
388 else {
411 else {
389 status = CCSDS_TM_VALID;
412 status = CCSDS_TM_VALID;
390 }
413 }
391 break;
414 break;
392 case TC_SUBTYPE_DIS_CAL:
415 case TC_SUBTYPE_DIS_CAL:
393 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
416 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
394 status = WRONG_LEN_PKT;
417 status = WRONG_LEN_PKT;
395 }
418 }
396 else {
419 else {
397 status = CCSDS_TM_VALID;
420 status = CCSDS_TM_VALID;
398 }
421 }
399 break;
422 break;
400 case TC_SUBTYPE_LOAD_K:
423 case TC_SUBTYPE_LOAD_K:
401 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
424 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
402 status = WRONG_LEN_PKT;
425 status = WRONG_LEN_PKT;
403 }
426 }
404 else {
427 else {
405 status = CCSDS_TM_VALID;
428 status = CCSDS_TM_VALID;
406 }
429 }
407 break;
430 break;
408 case TC_SUBTYPE_DUMP_K:
431 case TC_SUBTYPE_DUMP_K:
409 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
432 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
410 status = WRONG_LEN_PKT;
433 status = WRONG_LEN_PKT;
411 }
434 }
412 else {
435 else {
413 status = CCSDS_TM_VALID;
436 status = CCSDS_TM_VALID;
414 }
437 }
415 break;
438 break;
416 case TC_SUBTYPE_LOAD_FBINS:
439 case TC_SUBTYPE_LOAD_FBINS:
417 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
440 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
418 status = WRONG_LEN_PKT;
441 status = WRONG_LEN_PKT;
419 }
442 }
420 else {
443 else {
421 status = CCSDS_TM_VALID;
444 status = CCSDS_TM_VALID;
422 }
445 }
423 break;
446 break;
424 case TC_SUBTYPE_LOAD_FILTER_PAR:
447 case TC_SUBTYPE_LOAD_FILTER_PAR:
425 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
448 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
426 status = WRONG_LEN_PKT;
449 status = WRONG_LEN_PKT;
427 }
450 }
428 else {
451 else {
429 status = CCSDS_TM_VALID;
452 status = CCSDS_TM_VALID;
430 }
453 }
431 break;
454 break;
432 case TC_SUBTYPE_UPDT_TIME:
455 case TC_SUBTYPE_UPDT_TIME:
433 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
456 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
434 status = WRONG_LEN_PKT;
457 status = WRONG_LEN_PKT;
435 }
458 }
436 else {
459 else {
437 status = CCSDS_TM_VALID;
460 status = CCSDS_TM_VALID;
438 }
461 }
439 break;
462 break;
440 default: // if the subtype is not a legal value, return ILL_SUBTYPE
463 default: // if the subtype is not a legal value, return ILL_SUBTYPE
441 status = ILL_SUBTYPE;
464 status = ILL_SUBTYPE;
442 break ;
465 break ;
443 }
466 }
444
467
445 return status;
468 return status;
446 }
469 }
447
470
448 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
471 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
449 {
472 {
450 /** This function checks the CRC validity of the corresponding TeleCommand packet.
473 /** This function checks the CRC validity of the corresponding TeleCommand packet.
451 *
474 *
452 * @param TCPacket points to the TeleCommand packet to check.
475 * @param TCPacket points to the TeleCommand packet to check.
453 * @param length is the length of the TC packet.
476 * @param length is the length of the TC packet.
454 *
477 *
455 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
478 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
456 *
479 *
457 */
480 */
458
481
459 int status;
482 int status;
460 unsigned char * CCSDSContent;
483 unsigned char * CCSDSContent;
461
484
462 status = INCOR_CHECKSUM;
485 status = INCOR_CHECKSUM;
463
486
464 CCSDSContent = (unsigned char*) TCPacket->packetID;
487 CCSDSContent = (unsigned char*) TCPacket->packetID;
465 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
488 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
466
489
467 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
490 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
468 status = INCOR_CHECKSUM;
491 status = INCOR_CHECKSUM;
469 }
492 }
470 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
493 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
471 status = INCOR_CHECKSUM;
494 status = INCOR_CHECKSUM;
472 }
495 }
473 else {
496 else {
474 status = CCSDS_TM_VALID;
497 status = CCSDS_TM_VALID;
475 }
498 }
476
499
477 return status;
500 return status;
478 }
501 }
479
502
480
503
481
504
@@ -1,1673 +1,1696
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
1 /** Functions and tasks related to TeleCommand handling.
24 /** Functions and tasks related to TeleCommand handling.
2 *
25 *
3 * @file
26 * @file
4 * @author P. LEROY
27 * @author P. LEROY
5 *
28 *
6 * A group of functions to handle TeleCommands:\n
29 * A group of functions to handle TeleCommands:\n
7 * action launching\n
30 * action launching\n
8 * TC parsing\n
31 * TC parsing\n
9 * ...
32 * ...
10 *
33 *
11 */
34 */
12
35
13 #include "tc_handler.h"
36 #include "tc_handler.h"
14 #include "math.h"
37 #include "math.h"
15
38
16 //***********
39 //***********
17 // RTEMS TASK
40 // RTEMS TASK
18
41
19 rtems_task actn_task( rtems_task_argument unused )
42 rtems_task actn_task( rtems_task_argument unused )
20 {
43 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
44 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
45 *
23 * @param unused is the starting argument of the RTEMS task
46 * @param unused is the starting argument of the RTEMS task
24 *
47 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
48 * 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.
49 * on the incoming TeleCommand.
27 *
50 *
28 */
51 */
29
52
30 int result;
53 int result;
31 rtems_status_code status; // RTEMS status code
54 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
55 ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
56 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
57 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[BYTES_PER_TIME];
58 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
59 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
60 rtems_id queue_snd_id;
38
61
39 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
62 memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t));
40 size = 0;
63 size = 0;
41 queue_rcv_id = RTEMS_ID_NONE;
64 queue_rcv_id = RTEMS_ID_NONE;
42 queue_snd_id = RTEMS_ID_NONE;
65 queue_snd_id = RTEMS_ID_NONE;
43
66
44 status = get_message_queue_id_recv( &queue_rcv_id );
67 status = get_message_queue_id_recv( &queue_rcv_id );
45 if (status != RTEMS_SUCCESSFUL)
68 if (status != RTEMS_SUCCESSFUL)
46 {
69 {
47 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
70 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
48 }
71 }
49
72
50 status = get_message_queue_id_send( &queue_snd_id );
73 status = get_message_queue_id_send( &queue_snd_id );
51 if (status != RTEMS_SUCCESSFUL)
74 if (status != RTEMS_SUCCESSFUL)
52 {
75 {
53 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
76 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
54 }
77 }
55
78
56 result = LFR_SUCCESSFUL;
79 result = LFR_SUCCESSFUL;
57 subtype = 0; // subtype of the current TC packet
80 subtype = 0; // subtype of the current TC packet
58
81
59 BOOT_PRINTF("in ACTN *** \n");
82 BOOT_PRINTF("in ACTN *** \n");
60
83
61 while(1)
84 while(1)
62 {
85 {
63 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
86 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
64 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
87 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
65 getTime( time ); // set time to the current time
88 getTime( time ); // set time to the current time
66 if (status!=RTEMS_SUCCESSFUL)
89 if (status!=RTEMS_SUCCESSFUL)
67 {
90 {
68 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
91 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
69 }
92 }
70 else
93 else
71 {
94 {
72 subtype = TC.serviceSubType;
95 subtype = TC.serviceSubType;
73 switch(subtype)
96 switch(subtype)
74 {
97 {
75 case TC_SUBTYPE_RESET:
98 case TC_SUBTYPE_RESET:
76 result = action_reset( &TC, queue_snd_id, time );
99 result = action_reset( &TC, queue_snd_id, time );
77 close_action( &TC, result, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
78 break;
101 break;
79 case TC_SUBTYPE_LOAD_COMM:
102 case TC_SUBTYPE_LOAD_COMM:
80 result = action_load_common_par( &TC );
103 result = action_load_common_par( &TC );
81 close_action( &TC, result, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
82 break;
105 break;
83 case TC_SUBTYPE_LOAD_NORM:
106 case TC_SUBTYPE_LOAD_NORM:
84 result = action_load_normal_par( &TC, queue_snd_id, time );
107 result = action_load_normal_par( &TC, queue_snd_id, time );
85 close_action( &TC, result, queue_snd_id );
108 close_action( &TC, result, queue_snd_id );
86 break;
109 break;
87 case TC_SUBTYPE_LOAD_BURST:
110 case TC_SUBTYPE_LOAD_BURST:
88 result = action_load_burst_par( &TC, queue_snd_id, time );
111 result = action_load_burst_par( &TC, queue_snd_id, time );
89 close_action( &TC, result, queue_snd_id );
112 close_action( &TC, result, queue_snd_id );
90 break;
113 break;
91 case TC_SUBTYPE_LOAD_SBM1:
114 case TC_SUBTYPE_LOAD_SBM1:
92 result = action_load_sbm1_par( &TC, queue_snd_id, time );
115 result = action_load_sbm1_par( &TC, queue_snd_id, time );
93 close_action( &TC, result, queue_snd_id );
116 close_action( &TC, result, queue_snd_id );
94 break;
117 break;
95 case TC_SUBTYPE_LOAD_SBM2:
118 case TC_SUBTYPE_LOAD_SBM2:
96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
119 result = action_load_sbm2_par( &TC, queue_snd_id, time );
97 close_action( &TC, result, queue_snd_id );
120 close_action( &TC, result, queue_snd_id );
98 break;
121 break;
99 case TC_SUBTYPE_DUMP:
122 case TC_SUBTYPE_DUMP:
100 result = action_dump_par( &TC, queue_snd_id );
123 result = action_dump_par( &TC, queue_snd_id );
101 close_action( &TC, result, queue_snd_id );
124 close_action( &TC, result, queue_snd_id );
102 break;
125 break;
103 case TC_SUBTYPE_ENTER:
126 case TC_SUBTYPE_ENTER:
104 result = action_enter_mode( &TC, queue_snd_id );
127 result = action_enter_mode( &TC, queue_snd_id );
105 close_action( &TC, result, queue_snd_id );
128 close_action( &TC, result, queue_snd_id );
106 break;
129 break;
107 case TC_SUBTYPE_UPDT_INFO:
130 case TC_SUBTYPE_UPDT_INFO:
108 result = action_update_info( &TC, queue_snd_id );
131 result = action_update_info( &TC, queue_snd_id );
109 close_action( &TC, result, queue_snd_id );
132 close_action( &TC, result, queue_snd_id );
110 break;
133 break;
111 case TC_SUBTYPE_EN_CAL:
134 case TC_SUBTYPE_EN_CAL:
112 result = action_enable_calibration( &TC, queue_snd_id, time );
135 result = action_enable_calibration( &TC, queue_snd_id, time );
113 close_action( &TC, result, queue_snd_id );
136 close_action( &TC, result, queue_snd_id );
114 break;
137 break;
115 case TC_SUBTYPE_DIS_CAL:
138 case TC_SUBTYPE_DIS_CAL:
116 result = action_disable_calibration( &TC, queue_snd_id, time );
139 result = action_disable_calibration( &TC, queue_snd_id, time );
117 close_action( &TC, result, queue_snd_id );
140 close_action( &TC, result, queue_snd_id );
118 break;
141 break;
119 case TC_SUBTYPE_LOAD_K:
142 case TC_SUBTYPE_LOAD_K:
120 result = action_load_kcoefficients( &TC, queue_snd_id, time );
143 result = action_load_kcoefficients( &TC, queue_snd_id, time );
121 close_action( &TC, result, queue_snd_id );
144 close_action( &TC, result, queue_snd_id );
122 break;
145 break;
123 case TC_SUBTYPE_DUMP_K:
146 case TC_SUBTYPE_DUMP_K:
124 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
147 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
125 close_action( &TC, result, queue_snd_id );
148 close_action( &TC, result, queue_snd_id );
126 break;
149 break;
127 case TC_SUBTYPE_LOAD_FBINS:
150 case TC_SUBTYPE_LOAD_FBINS:
128 result = action_load_fbins_mask( &TC, queue_snd_id, time );
151 result = action_load_fbins_mask( &TC, queue_snd_id, time );
129 close_action( &TC, result, queue_snd_id );
152 close_action( &TC, result, queue_snd_id );
130 break;
153 break;
131 case TC_SUBTYPE_LOAD_FILTER_PAR:
154 case TC_SUBTYPE_LOAD_FILTER_PAR:
132 result = action_load_filter_par( &TC, queue_snd_id, time );
155 result = action_load_filter_par( &TC, queue_snd_id, time );
133 close_action( &TC, result, queue_snd_id );
156 close_action( &TC, result, queue_snd_id );
134 break;
157 break;
135 case TC_SUBTYPE_UPDT_TIME:
158 case TC_SUBTYPE_UPDT_TIME:
136 result = action_update_time( &TC );
159 result = action_update_time( &TC );
137 close_action( &TC, result, queue_snd_id );
160 close_action( &TC, result, queue_snd_id );
138 break;
161 break;
139 default:
162 default:
140 break;
163 break;
141 }
164 }
142 }
165 }
143 }
166 }
144 }
167 }
145
168
146 //***********
169 //***********
147 // TC ACTIONS
170 // TC ACTIONS
148
171
149 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
172 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
150 {
173 {
151 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
174 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
152 *
175 *
153 * @param TC points to the TeleCommand packet that is being processed
176 * @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
177 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
155 *
178 *
156 */
179 */
157
180
158 PRINTF("this is the end!!!\n");
181 PRINTF("this is the end!!!\n");
159 exit(0);
182 exit(0);
160
183
161 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
184 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
162
185
163 return LFR_DEFAULT;
186 return LFR_DEFAULT;
164 }
187 }
165
188
166 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
189 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
167 {
190 {
168 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
191 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
169 *
192 *
170 * @param TC points to the TeleCommand packet that is being processed
193 * @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
194 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
172 *
195 *
173 */
196 */
174
197
175 rtems_status_code status;
198 rtems_status_code status;
176 unsigned char requestedMode;
199 unsigned char requestedMode;
177 unsigned int transitionCoarseTime;
200 unsigned int transitionCoarseTime;
178 unsigned char * bytePosPtr;
201 unsigned char * bytePosPtr;
179
202
180 bytePosPtr = (unsigned char *) &TC->packetID;
203 bytePosPtr = (unsigned char *) &TC->packetID;
181 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
204 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
182 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
205 copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
183 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
206 transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK;
184 status = check_mode_value( requestedMode );
207 status = check_mode_value( requestedMode );
185
208
186 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
209 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
187 {
210 {
188 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
211 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
189 }
212 }
190
213
191 else // the mode value is valid, check the transition
214 else // the mode value is valid, check the transition
192 {
215 {
193 status = check_mode_transition(requestedMode);
216 status = check_mode_transition(requestedMode);
194 if (status != LFR_SUCCESSFUL)
217 if (status != LFR_SUCCESSFUL)
195 {
218 {
196 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
219 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
197 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
220 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
198 }
221 }
199 }
222 }
200
223
201 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
224 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
202 {
225 {
203 status = check_transition_date( transitionCoarseTime );
226 status = check_transition_date( transitionCoarseTime );
204 if (status != LFR_SUCCESSFUL)
227 if (status != LFR_SUCCESSFUL)
205 {
228 {
206 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
229 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
207 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
230 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
208 }
231 }
209 }
232 }
210
233
211 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
234 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
212 {
235 {
213 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
236 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
214
237
215 switch(requestedMode)
238 switch(requestedMode)
216 {
239 {
217 case LFR_MODE_STANDBY:
240 case LFR_MODE_STANDBY:
218 status = enter_mode_standby();
241 status = enter_mode_standby();
219 break;
242 break;
220 case LFR_MODE_NORMAL:
243 case LFR_MODE_NORMAL:
221 status = enter_mode_normal( transitionCoarseTime );
244 status = enter_mode_normal( transitionCoarseTime );
222 break;
245 break;
223 case LFR_MODE_BURST:
246 case LFR_MODE_BURST:
224 status = enter_mode_burst( transitionCoarseTime );
247 status = enter_mode_burst( transitionCoarseTime );
225 break;
248 break;
226 case LFR_MODE_SBM1:
249 case LFR_MODE_SBM1:
227 status = enter_mode_sbm1( transitionCoarseTime );
250 status = enter_mode_sbm1( transitionCoarseTime );
228 break;
251 break;
229 case LFR_MODE_SBM2:
252 case LFR_MODE_SBM2:
230 status = enter_mode_sbm2( transitionCoarseTime );
253 status = enter_mode_sbm2( transitionCoarseTime );
231 break;
254 break;
232 default:
255 default:
233 break;
256 break;
234 }
257 }
235
258
236 if (status != RTEMS_SUCCESSFUL)
259 if (status != RTEMS_SUCCESSFUL)
237 {
260 {
238 status = LFR_EXE_ERROR;
261 status = LFR_EXE_ERROR;
239 }
262 }
240 }
263 }
241
264
242 return status;
265 return status;
243 }
266 }
244
267
245 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
268 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
246 {
269 {
247 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
270 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
248 *
271 *
249 * @param TC points to the TeleCommand packet that is being processed
272 * @param TC points to the TeleCommand packet that is being processed
250 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
273 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
251 *
274 *
252 * @return LFR directive status code:
275 * @return LFR directive status code:
253 * - LFR_DEFAULT
276 * - LFR_DEFAULT
254 * - LFR_SUCCESSFUL
277 * - LFR_SUCCESSFUL
255 *
278 *
256 */
279 */
257
280
258 unsigned int val;
281 unsigned int val;
259 unsigned int status;
282 unsigned int status;
260 unsigned char mode;
283 unsigned char mode;
261 unsigned char * bytePosPtr;
284 unsigned char * bytePosPtr;
262 int pos;
285 int pos;
263 float value;
286 float value;
264
287
265 pos = INIT_CHAR;
288 pos = INIT_CHAR;
266 value = INIT_FLOAT;
289 value = INIT_FLOAT;
267
290
268 status = LFR_DEFAULT;
291 status = LFR_DEFAULT;
269
292
270 bytePosPtr = (unsigned char *) &TC->packetID;
293 bytePosPtr = (unsigned char *) &TC->packetID;
271
294
272 // check LFR mode
295 // check LFR mode
273 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
296 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
274 status = check_update_info_hk_lfr_mode( mode );
297 status = check_update_info_hk_lfr_mode( mode );
275 if (status == LFR_SUCCESSFUL) // check TDS mode
298 if (status == LFR_SUCCESSFUL) // check TDS mode
276 {
299 {
277 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
300 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
278 status = check_update_info_hk_tds_mode( mode );
301 status = check_update_info_hk_tds_mode( mode );
279 }
302 }
280 if (status == LFR_SUCCESSFUL) // check THR mode
303 if (status == LFR_SUCCESSFUL) // check THR mode
281 {
304 {
282 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
305 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
283 status = check_update_info_hk_thr_mode( mode );
306 status = check_update_info_hk_thr_mode( mode );
284 }
307 }
285 if (status == LFR_SUCCESSFUL) // check reaction wheels frequencies
308 if (status == LFR_SUCCESSFUL) // check reaction wheels frequencies
286 {
309 {
287 status = check_all_sy_lfr_rw_f(TC, &pos, &value);
310 status = check_all_sy_lfr_rw_f(TC, &pos, &value);
288 }
311 }
289
312
290 // if the parameters checking succeeds, udpate all parameters
313 // if the parameters checking succeeds, udpate all parameters
291 if (status == LFR_SUCCESSFUL)
314 if (status == LFR_SUCCESSFUL)
292 {
315 {
293 // pa_bia_status_info
316 // pa_bia_status_info
294 // => pa_bia_mode_mux_set 3 bits
317 // => pa_bia_mode_mux_set 3 bits
295 // => pa_bia_mode_hv_enabled 1 bit
318 // => pa_bia_mode_hv_enabled 1 bit
296 // => pa_bia_mode_bias1_enabled 1 bit
319 // => pa_bia_mode_bias1_enabled 1 bit
297 // => pa_bia_mode_bias2_enabled 1 bit
320 // => pa_bia_mode_bias2_enabled 1 bit
298 // => pa_bia_mode_bias3_enabled 1 bit
321 // => pa_bia_mode_bias3_enabled 1 bit
299 // => pa_bia_on_off (cp_dpu_bias_on_off)
322 // => pa_bia_on_off (cp_dpu_bias_on_off)
300 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
323 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
301 pa_bia_status_info = pa_bia_status_info
324 pa_bia_status_info = pa_bia_status_info
302 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
325 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
303
326
304 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
327 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
305 getReactionWheelsFrequencies( TC );
328 getReactionWheelsFrequencies( TC );
306 set_hk_lfr_sc_rw_f_flags();
329 set_hk_lfr_sc_rw_f_flags();
307 build_sy_lfr_rw_masks();
330 build_sy_lfr_rw_masks();
308
331
309 // once the masks are built, they have to be merged with the fbins_mask
332 // once the masks are built, they have to be merged with the fbins_mask
310 merge_fbins_masks();
333 merge_fbins_masks();
311
334
312 // increase the TC_LFR_UPDATE_INFO counter
335 // increase the TC_LFR_UPDATE_INFO counter
313 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
336 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
314 {
337 {
315 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
338 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
316 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
339 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
317 val++;
340 val++;
318 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
341 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
319 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
342 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
320 }
343 }
321 }
344 }
322
345
323 return status;
346 return status;
324 }
347 }
325
348
326 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
349 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
327 {
350 {
328 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
351 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
329 *
352 *
330 * @param TC points to the TeleCommand packet that is being processed
353 * @param TC points to the TeleCommand packet that is being processed
331 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
354 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
332 *
355 *
333 */
356 */
334
357
335 int result;
358 int result;
336
359
337 result = LFR_DEFAULT;
360 result = LFR_DEFAULT;
338
361
339 setCalibration( true );
362 setCalibration( true );
340
363
341 result = LFR_SUCCESSFUL;
364 result = LFR_SUCCESSFUL;
342
365
343 return result;
366 return result;
344 }
367 }
345
368
346 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
369 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
347 {
370 {
348 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
371 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
349 *
372 *
350 * @param TC points to the TeleCommand packet that is being processed
373 * @param TC points to the TeleCommand packet that is being processed
351 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
374 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
352 *
375 *
353 */
376 */
354
377
355 int result;
378 int result;
356
379
357 result = LFR_DEFAULT;
380 result = LFR_DEFAULT;
358
381
359 setCalibration( false );
382 setCalibration( false );
360
383
361 result = LFR_SUCCESSFUL;
384 result = LFR_SUCCESSFUL;
362
385
363 return result;
386 return result;
364 }
387 }
365
388
366 int action_update_time(ccsdsTelecommandPacket_t *TC)
389 int action_update_time(ccsdsTelecommandPacket_t *TC)
367 {
390 {
368 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
391 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
369 *
392 *
370 * @param TC points to the TeleCommand packet that is being processed
393 * @param TC points to the TeleCommand packet that is being processed
371 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
394 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
372 *
395 *
373 * @return LFR_SUCCESSFUL
396 * @return LFR_SUCCESSFUL
374 *
397 *
375 */
398 */
376
399
377 unsigned int val;
400 unsigned int val;
378
401
379 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
402 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
380 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
403 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
381 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
404 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
382 + TC->dataAndCRC[BYTE_3];
405 + TC->dataAndCRC[BYTE_3];
383
406
384 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
407 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
385 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
408 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
386 val++;
409 val++;
387 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
410 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
388 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
411 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
389
412
390 oneTcLfrUpdateTimeReceived = 1;
413 oneTcLfrUpdateTimeReceived = 1;
391
414
392 return LFR_SUCCESSFUL;
415 return LFR_SUCCESSFUL;
393 }
416 }
394
417
395 //*******************
418 //*******************
396 // ENTERING THE MODES
419 // ENTERING THE MODES
397 int check_mode_value( unsigned char requestedMode )
420 int check_mode_value( unsigned char requestedMode )
398 {
421 {
399 int status;
422 int status;
400
423
401 status = LFR_DEFAULT;
424 status = LFR_DEFAULT;
402
425
403 if ( (requestedMode != LFR_MODE_STANDBY)
426 if ( (requestedMode != LFR_MODE_STANDBY)
404 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
427 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
405 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
428 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
406 {
429 {
407 status = LFR_DEFAULT;
430 status = LFR_DEFAULT;
408 }
431 }
409 else
432 else
410 {
433 {
411 status = LFR_SUCCESSFUL;
434 status = LFR_SUCCESSFUL;
412 }
435 }
413
436
414 return status;
437 return status;
415 }
438 }
416
439
417 int check_mode_transition( unsigned char requestedMode )
440 int check_mode_transition( unsigned char requestedMode )
418 {
441 {
419 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
442 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
420 *
443 *
421 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
444 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
422 *
445 *
423 * @return LFR directive status codes:
446 * @return LFR directive status codes:
424 * - LFR_SUCCESSFUL - the transition is authorized
447 * - LFR_SUCCESSFUL - the transition is authorized
425 * - LFR_DEFAULT - the transition is not authorized
448 * - LFR_DEFAULT - the transition is not authorized
426 *
449 *
427 */
450 */
428
451
429 int status;
452 int status;
430
453
431 switch (requestedMode)
454 switch (requestedMode)
432 {
455 {
433 case LFR_MODE_STANDBY:
456 case LFR_MODE_STANDBY:
434 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
457 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
435 status = LFR_DEFAULT;
458 status = LFR_DEFAULT;
436 }
459 }
437 else
460 else
438 {
461 {
439 status = LFR_SUCCESSFUL;
462 status = LFR_SUCCESSFUL;
440 }
463 }
441 break;
464 break;
442 case LFR_MODE_NORMAL:
465 case LFR_MODE_NORMAL:
443 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
466 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
444 status = LFR_DEFAULT;
467 status = LFR_DEFAULT;
445 }
468 }
446 else {
469 else {
447 status = LFR_SUCCESSFUL;
470 status = LFR_SUCCESSFUL;
448 }
471 }
449 break;
472 break;
450 case LFR_MODE_BURST:
473 case LFR_MODE_BURST:
451 if ( lfrCurrentMode == LFR_MODE_BURST ) {
474 if ( lfrCurrentMode == LFR_MODE_BURST ) {
452 status = LFR_DEFAULT;
475 status = LFR_DEFAULT;
453 }
476 }
454 else {
477 else {
455 status = LFR_SUCCESSFUL;
478 status = LFR_SUCCESSFUL;
456 }
479 }
457 break;
480 break;
458 case LFR_MODE_SBM1:
481 case LFR_MODE_SBM1:
459 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
482 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
460 status = LFR_DEFAULT;
483 status = LFR_DEFAULT;
461 }
484 }
462 else {
485 else {
463 status = LFR_SUCCESSFUL;
486 status = LFR_SUCCESSFUL;
464 }
487 }
465 break;
488 break;
466 case LFR_MODE_SBM2:
489 case LFR_MODE_SBM2:
467 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
490 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
468 status = LFR_DEFAULT;
491 status = LFR_DEFAULT;
469 }
492 }
470 else {
493 else {
471 status = LFR_SUCCESSFUL;
494 status = LFR_SUCCESSFUL;
472 }
495 }
473 break;
496 break;
474 default:
497 default:
475 status = LFR_DEFAULT;
498 status = LFR_DEFAULT;
476 break;
499 break;
477 }
500 }
478
501
479 return status;
502 return status;
480 }
503 }
481
504
482 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
505 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
483 {
506 {
484 if (transitionCoarseTime == 0)
507 if (transitionCoarseTime == 0)
485 {
508 {
486 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
509 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
487 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
510 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
488 }
511 }
489 else
512 else
490 {
513 {
491 lastValidEnterModeTime = transitionCoarseTime;
514 lastValidEnterModeTime = transitionCoarseTime;
492 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
515 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
493 }
516 }
494 }
517 }
495
518
496 int check_transition_date( unsigned int transitionCoarseTime )
519 int check_transition_date( unsigned int transitionCoarseTime )
497 {
520 {
498 int status;
521 int status;
499 unsigned int localCoarseTime;
522 unsigned int localCoarseTime;
500 unsigned int deltaCoarseTime;
523 unsigned int deltaCoarseTime;
501
524
502 status = LFR_SUCCESSFUL;
525 status = LFR_SUCCESSFUL;
503
526
504 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
527 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
505 {
528 {
506 status = LFR_SUCCESSFUL;
529 status = LFR_SUCCESSFUL;
507 }
530 }
508 else
531 else
509 {
532 {
510 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
533 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
511
534
512 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
535 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
513
536
514 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
537 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
515 {
538 {
516 status = LFR_DEFAULT;
539 status = LFR_DEFAULT;
517 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
540 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
518 }
541 }
519
542
520 if (status == LFR_SUCCESSFUL)
543 if (status == LFR_SUCCESSFUL)
521 {
544 {
522 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
545 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
523 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
546 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
524 {
547 {
525 status = LFR_DEFAULT;
548 status = LFR_DEFAULT;
526 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
549 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
527 }
550 }
528 }
551 }
529 }
552 }
530
553
531 return status;
554 return status;
532 }
555 }
533
556
534 int restart_asm_activities( unsigned char lfrRequestedMode )
557 int restart_asm_activities( unsigned char lfrRequestedMode )
535 {
558 {
536 rtems_status_code status;
559 rtems_status_code status;
537
560
538 status = stop_spectral_matrices();
561 status = stop_spectral_matrices();
539
562
540 thisIsAnASMRestart = 1;
563 thisIsAnASMRestart = 1;
541
564
542 status = restart_asm_tasks( lfrRequestedMode );
565 status = restart_asm_tasks( lfrRequestedMode );
543
566
544 launch_spectral_matrix();
567 launch_spectral_matrix();
545
568
546 return status;
569 return status;
547 }
570 }
548
571
549 int stop_spectral_matrices( void )
572 int stop_spectral_matrices( void )
550 {
573 {
551 /** This function stops and restarts the current mode average spectral matrices activities.
574 /** This function stops and restarts the current mode average spectral matrices activities.
552 *
575 *
553 * @return RTEMS directive status codes:
576 * @return RTEMS directive status codes:
554 * - RTEMS_SUCCESSFUL - task restarted successfully
577 * - RTEMS_SUCCESSFUL - task restarted successfully
555 * - RTEMS_INVALID_ID - task id invalid
578 * - RTEMS_INVALID_ID - task id invalid
556 * - RTEMS_ALREADY_SUSPENDED - task already suspended
579 * - RTEMS_ALREADY_SUSPENDED - task already suspended
557 *
580 *
558 */
581 */
559
582
560 rtems_status_code status;
583 rtems_status_code status;
561
584
562 status = RTEMS_SUCCESSFUL;
585 status = RTEMS_SUCCESSFUL;
563
586
564 // (1) mask interruptions
587 // (1) mask interruptions
565 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
588 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
566
589
567 // (2) reset spectral matrices registers
590 // (2) reset spectral matrices registers
568 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
591 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
569 reset_sm_status();
592 reset_sm_status();
570
593
571 // (3) clear interruptions
594 // (3) clear interruptions
572 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
595 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
573
596
574 // suspend several tasks
597 // suspend several tasks
575 if (lfrCurrentMode != LFR_MODE_STANDBY) {
598 if (lfrCurrentMode != LFR_MODE_STANDBY) {
576 status = suspend_asm_tasks();
599 status = suspend_asm_tasks();
577 }
600 }
578
601
579 if (status != RTEMS_SUCCESSFUL)
602 if (status != RTEMS_SUCCESSFUL)
580 {
603 {
581 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
604 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
582 }
605 }
583
606
584 return status;
607 return status;
585 }
608 }
586
609
587 int stop_current_mode( void )
610 int stop_current_mode( void )
588 {
611 {
589 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
612 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
590 *
613 *
591 * @return RTEMS directive status codes:
614 * @return RTEMS directive status codes:
592 * - RTEMS_SUCCESSFUL - task restarted successfully
615 * - RTEMS_SUCCESSFUL - task restarted successfully
593 * - RTEMS_INVALID_ID - task id invalid
616 * - RTEMS_INVALID_ID - task id invalid
594 * - RTEMS_ALREADY_SUSPENDED - task already suspended
617 * - RTEMS_ALREADY_SUSPENDED - task already suspended
595 *
618 *
596 */
619 */
597
620
598 rtems_status_code status;
621 rtems_status_code status;
599
622
600 status = RTEMS_SUCCESSFUL;
623 status = RTEMS_SUCCESSFUL;
601
624
602 // (1) mask interruptions
625 // (1) mask interruptions
603 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
626 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
604 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
627 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
605
628
606 // (2) reset waveform picker registers
629 // (2) reset waveform picker registers
607 reset_wfp_burst_enable(); // reset burst and enable bits
630 reset_wfp_burst_enable(); // reset burst and enable bits
608 reset_wfp_status(); // reset all the status bits
631 reset_wfp_status(); // reset all the status bits
609
632
610 // (3) reset spectral matrices registers
633 // (3) reset spectral matrices registers
611 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
634 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
612 reset_sm_status();
635 reset_sm_status();
613
636
614 // reset lfr VHDL module
637 // reset lfr VHDL module
615 reset_lfr();
638 reset_lfr();
616
639
617 reset_extractSWF(); // reset the extractSWF flag to false
640 reset_extractSWF(); // reset the extractSWF flag to false
618
641
619 // (4) clear interruptions
642 // (4) clear interruptions
620 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
643 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
621 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
644 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
622
645
623 // suspend several tasks
646 // suspend several tasks
624 if (lfrCurrentMode != LFR_MODE_STANDBY) {
647 if (lfrCurrentMode != LFR_MODE_STANDBY) {
625 status = suspend_science_tasks();
648 status = suspend_science_tasks();
626 }
649 }
627
650
628 if (status != RTEMS_SUCCESSFUL)
651 if (status != RTEMS_SUCCESSFUL)
629 {
652 {
630 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
653 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
631 }
654 }
632
655
633 return status;
656 return status;
634 }
657 }
635
658
636 int enter_mode_standby( void )
659 int enter_mode_standby( void )
637 {
660 {
638 /** This function is used to put LFR in the STANDBY mode.
661 /** This function is used to put LFR in the STANDBY mode.
639 *
662 *
640 * @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
641 *
664 *
642 * @return RTEMS directive status codes:
665 * @return RTEMS directive status codes:
643 * - RTEMS_SUCCESSFUL - task restarted successfully
666 * - RTEMS_SUCCESSFUL - task restarted successfully
644 * - RTEMS_INVALID_ID - task id invalid
667 * - RTEMS_INVALID_ID - task id invalid
645 * - RTEMS_INCORRECT_STATE - task never started
668 * - RTEMS_INCORRECT_STATE - task never started
646 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
669 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
647 *
670 *
648 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
671 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
649 * is immediate.
672 * is immediate.
650 *
673 *
651 */
674 */
652
675
653 int status;
676 int status;
654
677
655 status = stop_current_mode(); // STOP THE CURRENT MODE
678 status = stop_current_mode(); // STOP THE CURRENT MODE
656
679
657 #ifdef PRINT_TASK_STATISTICS
680 #ifdef PRINT_TASK_STATISTICS
658 rtems_cpu_usage_report();
681 rtems_cpu_usage_report();
659 #endif
682 #endif
660
683
661 #ifdef PRINT_STACK_REPORT
684 #ifdef PRINT_STACK_REPORT
662 PRINTF("stack report selected\n")
685 PRINTF("stack report selected\n")
663 rtems_stack_checker_report_usage();
686 rtems_stack_checker_report_usage();
664 #endif
687 #endif
665
688
666 return status;
689 return status;
667 }
690 }
668
691
669 int enter_mode_normal( unsigned int transitionCoarseTime )
692 int enter_mode_normal( unsigned int transitionCoarseTime )
670 {
693 {
671 /** This function is used to start the NORMAL mode.
694 /** This function is used to start the NORMAL mode.
672 *
695 *
673 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
696 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
674 *
697 *
675 * @return RTEMS directive status codes:
698 * @return RTEMS directive status codes:
676 * - RTEMS_SUCCESSFUL - task restarted successfully
699 * - RTEMS_SUCCESSFUL - task restarted successfully
677 * - RTEMS_INVALID_ID - task id invalid
700 * - RTEMS_INVALID_ID - task id invalid
678 * - RTEMS_INCORRECT_STATE - task never started
701 * - RTEMS_INCORRECT_STATE - task never started
679 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
702 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
680 *
703 *
681 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
704 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
682 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
705 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
683 *
706 *
684 */
707 */
685
708
686 int status;
709 int status;
687
710
688 #ifdef PRINT_TASK_STATISTICS
711 #ifdef PRINT_TASK_STATISTICS
689 rtems_cpu_usage_reset();
712 rtems_cpu_usage_reset();
690 #endif
713 #endif
691
714
692 status = RTEMS_UNSATISFIED;
715 status = RTEMS_UNSATISFIED;
693
716
694 switch( lfrCurrentMode )
717 switch( lfrCurrentMode )
695 {
718 {
696 case LFR_MODE_STANDBY:
719 case LFR_MODE_STANDBY:
697 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
720 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
698 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
721 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
699 {
722 {
700 launch_spectral_matrix( );
723 launch_spectral_matrix( );
701 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
724 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
702 }
725 }
703 break;
726 break;
704 case LFR_MODE_BURST:
727 case LFR_MODE_BURST:
705 status = stop_current_mode(); // stop the current mode
728 status = stop_current_mode(); // stop the current mode
706 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
729 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
707 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
730 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
708 {
731 {
709 launch_spectral_matrix( );
732 launch_spectral_matrix( );
710 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
733 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
711 }
734 }
712 break;
735 break;
713 case LFR_MODE_SBM1:
736 case LFR_MODE_SBM1:
714 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
737 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
715 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
738 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
716 update_last_valid_transition_date( transitionCoarseTime );
739 update_last_valid_transition_date( transitionCoarseTime );
717 break;
740 break;
718 case LFR_MODE_SBM2:
741 case LFR_MODE_SBM2:
719 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
742 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
720 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
743 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
721 update_last_valid_transition_date( transitionCoarseTime );
744 update_last_valid_transition_date( transitionCoarseTime );
722 break;
745 break;
723 default:
746 default:
724 break;
747 break;
725 }
748 }
726
749
727 if (status != RTEMS_SUCCESSFUL)
750 if (status != RTEMS_SUCCESSFUL)
728 {
751 {
729 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
752 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
730 status = RTEMS_UNSATISFIED;
753 status = RTEMS_UNSATISFIED;
731 }
754 }
732
755
733 return status;
756 return status;
734 }
757 }
735
758
736 int enter_mode_burst( unsigned int transitionCoarseTime )
759 int enter_mode_burst( unsigned int transitionCoarseTime )
737 {
760 {
738 /** This function is used to start the BURST mode.
761 /** This function is used to start the BURST mode.
739 *
762 *
740 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
763 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
741 *
764 *
742 * @return RTEMS directive status codes:
765 * @return RTEMS directive status codes:
743 * - RTEMS_SUCCESSFUL - task restarted successfully
766 * - RTEMS_SUCCESSFUL - task restarted successfully
744 * - RTEMS_INVALID_ID - task id invalid
767 * - RTEMS_INVALID_ID - task id invalid
745 * - RTEMS_INCORRECT_STATE - task never started
768 * - RTEMS_INCORRECT_STATE - task never started
746 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
769 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
747 *
770 *
748 * The way the BURST mode is started does not depend on the LFR current mode.
771 * The way the BURST mode is started does not depend on the LFR current mode.
749 *
772 *
750 */
773 */
751
774
752
775
753 int status;
776 int status;
754
777
755 #ifdef PRINT_TASK_STATISTICS
778 #ifdef PRINT_TASK_STATISTICS
756 rtems_cpu_usage_reset();
779 rtems_cpu_usage_reset();
757 #endif
780 #endif
758
781
759 status = stop_current_mode(); // stop the current mode
782 status = stop_current_mode(); // stop the current mode
760 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
783 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
761 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
784 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
762 {
785 {
763 launch_spectral_matrix( );
786 launch_spectral_matrix( );
764 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
787 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
765 }
788 }
766
789
767 if (status != RTEMS_SUCCESSFUL)
790 if (status != RTEMS_SUCCESSFUL)
768 {
791 {
769 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
792 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
770 status = RTEMS_UNSATISFIED;
793 status = RTEMS_UNSATISFIED;
771 }
794 }
772
795
773 return status;
796 return status;
774 }
797 }
775
798
776 int enter_mode_sbm1( unsigned int transitionCoarseTime )
799 int enter_mode_sbm1( unsigned int transitionCoarseTime )
777 {
800 {
778 /** This function is used to start the SBM1 mode.
801 /** This function is used to start the SBM1 mode.
779 *
802 *
780 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
803 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
781 *
804 *
782 * @return RTEMS directive status codes:
805 * @return RTEMS directive status codes:
783 * - RTEMS_SUCCESSFUL - task restarted successfully
806 * - RTEMS_SUCCESSFUL - task restarted successfully
784 * - RTEMS_INVALID_ID - task id invalid
807 * - RTEMS_INVALID_ID - task id invalid
785 * - RTEMS_INCORRECT_STATE - task never started
808 * - RTEMS_INCORRECT_STATE - task never started
786 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
809 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
787 *
810 *
788 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
811 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
789 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
812 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
790 * cases, the acquisition is completely restarted.
813 * cases, the acquisition is completely restarted.
791 *
814 *
792 */
815 */
793
816
794 int status;
817 int status;
795
818
796 #ifdef PRINT_TASK_STATISTICS
819 #ifdef PRINT_TASK_STATISTICS
797 rtems_cpu_usage_reset();
820 rtems_cpu_usage_reset();
798 #endif
821 #endif
799
822
800 status = RTEMS_UNSATISFIED;
823 status = RTEMS_UNSATISFIED;
801
824
802 switch( lfrCurrentMode )
825 switch( lfrCurrentMode )
803 {
826 {
804 case LFR_MODE_STANDBY:
827 case LFR_MODE_STANDBY:
805 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
828 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
806 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
829 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
807 {
830 {
808 launch_spectral_matrix( );
831 launch_spectral_matrix( );
809 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
832 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
810 }
833 }
811 break;
834 break;
812 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
835 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
813 status = restart_asm_activities( LFR_MODE_SBM1 );
836 status = restart_asm_activities( LFR_MODE_SBM1 );
814 status = LFR_SUCCESSFUL;
837 status = LFR_SUCCESSFUL;
815 update_last_valid_transition_date( transitionCoarseTime );
838 update_last_valid_transition_date( transitionCoarseTime );
816 break;
839 break;
817 case LFR_MODE_BURST:
840 case LFR_MODE_BURST:
818 status = stop_current_mode(); // stop the current mode
841 status = stop_current_mode(); // stop the current mode
819 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
842 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
820 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
843 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
821 {
844 {
822 launch_spectral_matrix( );
845 launch_spectral_matrix( );
823 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
846 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
824 }
847 }
825 break;
848 break;
826 case LFR_MODE_SBM2:
849 case LFR_MODE_SBM2:
827 status = restart_asm_activities( LFR_MODE_SBM1 );
850 status = restart_asm_activities( LFR_MODE_SBM1 );
828 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
851 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
829 update_last_valid_transition_date( transitionCoarseTime );
852 update_last_valid_transition_date( transitionCoarseTime );
830 break;
853 break;
831 default:
854 default:
832 break;
855 break;
833 }
856 }
834
857
835 if (status != RTEMS_SUCCESSFUL)
858 if (status != RTEMS_SUCCESSFUL)
836 {
859 {
837 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
860 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
838 status = RTEMS_UNSATISFIED;
861 status = RTEMS_UNSATISFIED;
839 }
862 }
840
863
841 return status;
864 return status;
842 }
865 }
843
866
844 int enter_mode_sbm2( unsigned int transitionCoarseTime )
867 int enter_mode_sbm2( unsigned int transitionCoarseTime )
845 {
868 {
846 /** This function is used to start the SBM2 mode.
869 /** This function is used to start the SBM2 mode.
847 *
870 *
848 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
871 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
849 *
872 *
850 * @return RTEMS directive status codes:
873 * @return RTEMS directive status codes:
851 * - RTEMS_SUCCESSFUL - task restarted successfully
874 * - RTEMS_SUCCESSFUL - task restarted successfully
852 * - RTEMS_INVALID_ID - task id invalid
875 * - RTEMS_INVALID_ID - task id invalid
853 * - RTEMS_INCORRECT_STATE - task never started
876 * - RTEMS_INCORRECT_STATE - task never started
854 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
877 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
855 *
878 *
856 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
879 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
857 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
880 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
858 * cases, the acquisition is completely restarted.
881 * cases, the acquisition is completely restarted.
859 *
882 *
860 */
883 */
861
884
862 int status;
885 int status;
863
886
864 #ifdef PRINT_TASK_STATISTICS
887 #ifdef PRINT_TASK_STATISTICS
865 rtems_cpu_usage_reset();
888 rtems_cpu_usage_reset();
866 #endif
889 #endif
867
890
868 status = RTEMS_UNSATISFIED;
891 status = RTEMS_UNSATISFIED;
869
892
870 switch( lfrCurrentMode )
893 switch( lfrCurrentMode )
871 {
894 {
872 case LFR_MODE_STANDBY:
895 case LFR_MODE_STANDBY:
873 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
896 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
874 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
897 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
875 {
898 {
876 launch_spectral_matrix( );
899 launch_spectral_matrix( );
877 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
900 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
878 }
901 }
879 break;
902 break;
880 case LFR_MODE_NORMAL:
903 case LFR_MODE_NORMAL:
881 status = restart_asm_activities( LFR_MODE_SBM2 );
904 status = restart_asm_activities( LFR_MODE_SBM2 );
882 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
905 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
883 update_last_valid_transition_date( transitionCoarseTime );
906 update_last_valid_transition_date( transitionCoarseTime );
884 break;
907 break;
885 case LFR_MODE_BURST:
908 case LFR_MODE_BURST:
886 status = stop_current_mode(); // stop the current mode
909 status = stop_current_mode(); // stop the current mode
887 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
910 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
888 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
911 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
889 {
912 {
890 launch_spectral_matrix( );
913 launch_spectral_matrix( );
891 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
914 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
892 }
915 }
893 break;
916 break;
894 case LFR_MODE_SBM1:
917 case LFR_MODE_SBM1:
895 status = restart_asm_activities( LFR_MODE_SBM2 );
918 status = restart_asm_activities( LFR_MODE_SBM2 );
896 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
919 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
897 update_last_valid_transition_date( transitionCoarseTime );
920 update_last_valid_transition_date( transitionCoarseTime );
898 break;
921 break;
899 default:
922 default:
900 break;
923 break;
901 }
924 }
902
925
903 if (status != RTEMS_SUCCESSFUL)
926 if (status != RTEMS_SUCCESSFUL)
904 {
927 {
905 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
928 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
906 status = RTEMS_UNSATISFIED;
929 status = RTEMS_UNSATISFIED;
907 }
930 }
908
931
909 return status;
932 return status;
910 }
933 }
911
934
912 int restart_science_tasks( unsigned char lfrRequestedMode )
935 int restart_science_tasks( unsigned char lfrRequestedMode )
913 {
936 {
914 /** This function is used to restart all science tasks.
937 /** This function is used to restart all science tasks.
915 *
938 *
916 * @return RTEMS directive status codes:
939 * @return RTEMS directive status codes:
917 * - RTEMS_SUCCESSFUL - task restarted successfully
940 * - RTEMS_SUCCESSFUL - task restarted successfully
918 * - RTEMS_INVALID_ID - task id invalid
941 * - RTEMS_INVALID_ID - task id invalid
919 * - RTEMS_INCORRECT_STATE - task never started
942 * - RTEMS_INCORRECT_STATE - task never started
920 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
943 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
921 *
944 *
922 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
945 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
923 *
946 *
924 */
947 */
925
948
926 rtems_status_code status[NB_SCIENCE_TASKS];
949 rtems_status_code status[NB_SCIENCE_TASKS];
927 rtems_status_code ret;
950 rtems_status_code ret;
928
951
929 ret = RTEMS_SUCCESSFUL;
952 ret = RTEMS_SUCCESSFUL;
930
953
931 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
954 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
932 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
955 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
933 {
956 {
934 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
957 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
935 }
958 }
936
959
937 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
960 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
938 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
961 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
939 {
962 {
940 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
963 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
941 }
964 }
942
965
943 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
966 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
944 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
967 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
945 {
968 {
946 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
969 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
947 }
970 }
948
971
949 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
972 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
950 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
973 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
951 {
974 {
952 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
975 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
953 }
976 }
954
977
955 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
978 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
956 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
979 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
957 {
980 {
958 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
981 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
959 }
982 }
960
983
961 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
984 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
962 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
985 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
963 {
986 {
964 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
987 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
965 }
988 }
966
989
967 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
990 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
968 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
991 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
969 {
992 {
970 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
993 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
971 }
994 }
972
995
973 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
996 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
974 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
997 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
975 {
998 {
976 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
999 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
977 }
1000 }
978
1001
979 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1002 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
980 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
1003 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
981 {
1004 {
982 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
1005 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
983 }
1006 }
984
1007
985 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1008 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
986 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
1009 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
987 {
1010 {
988 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
1011 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
989 }
1012 }
990
1013
991 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1014 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
992 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1015 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
993 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
1016 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
994 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
1017 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
995 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
1018 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
996 {
1019 {
997 ret = RTEMS_UNSATISFIED;
1020 ret = RTEMS_UNSATISFIED;
998 }
1021 }
999
1022
1000 return ret;
1023 return ret;
1001 }
1024 }
1002
1025
1003 int restart_asm_tasks( unsigned char lfrRequestedMode )
1026 int restart_asm_tasks( unsigned char lfrRequestedMode )
1004 {
1027 {
1005 /** This function is used to restart average spectral matrices tasks.
1028 /** This function is used to restart average spectral matrices tasks.
1006 *
1029 *
1007 * @return RTEMS directive status codes:
1030 * @return RTEMS directive status codes:
1008 * - RTEMS_SUCCESSFUL - task restarted successfully
1031 * - RTEMS_SUCCESSFUL - task restarted successfully
1009 * - RTEMS_INVALID_ID - task id invalid
1032 * - RTEMS_INVALID_ID - task id invalid
1010 * - RTEMS_INCORRECT_STATE - task never started
1033 * - RTEMS_INCORRECT_STATE - task never started
1011 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1034 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
1012 *
1035 *
1013 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1036 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
1014 *
1037 *
1015 */
1038 */
1016
1039
1017 rtems_status_code status[NB_ASM_TASKS];
1040 rtems_status_code status[NB_ASM_TASKS];
1018 rtems_status_code ret;
1041 rtems_status_code ret;
1019
1042
1020 ret = RTEMS_SUCCESSFUL;
1043 ret = RTEMS_SUCCESSFUL;
1021
1044
1022 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1045 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1023 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1046 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1024 {
1047 {
1025 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1048 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1026 }
1049 }
1027
1050
1028 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1051 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1029 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1052 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1030 {
1053 {
1031 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1054 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1032 }
1055 }
1033
1056
1034 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1057 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1035 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1058 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1036 {
1059 {
1037 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1060 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1038 }
1061 }
1039
1062
1040 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1063 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1041 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1064 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1042 {
1065 {
1043 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1066 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1044 }
1067 }
1045
1068
1046 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1069 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1047 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1070 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1048 {
1071 {
1049 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1072 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1050 }
1073 }
1051
1074
1052 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1075 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1053 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1076 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1054 {
1077 {
1055 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1078 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1056 }
1079 }
1057
1080
1058 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1081 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1059 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1082 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1060 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1083 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1061 {
1084 {
1062 ret = RTEMS_UNSATISFIED;
1085 ret = RTEMS_UNSATISFIED;
1063 }
1086 }
1064
1087
1065 return ret;
1088 return ret;
1066 }
1089 }
1067
1090
1068 int suspend_science_tasks( void )
1091 int suspend_science_tasks( void )
1069 {
1092 {
1070 /** This function suspends the science tasks.
1093 /** This function suspends the science tasks.
1071 *
1094 *
1072 * @return RTEMS directive status codes:
1095 * @return RTEMS directive status codes:
1073 * - RTEMS_SUCCESSFUL - task restarted successfully
1096 * - RTEMS_SUCCESSFUL - task restarted successfully
1074 * - RTEMS_INVALID_ID - task id invalid
1097 * - RTEMS_INVALID_ID - task id invalid
1075 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1098 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1076 *
1099 *
1077 */
1100 */
1078
1101
1079 rtems_status_code status;
1102 rtems_status_code status;
1080
1103
1081 PRINTF("in suspend_science_tasks\n")
1104 PRINTF("in suspend_science_tasks\n")
1082
1105
1083 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1106 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1084 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1107 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1085 {
1108 {
1086 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1109 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1087 }
1110 }
1088 else
1111 else
1089 {
1112 {
1090 status = RTEMS_SUCCESSFUL;
1113 status = RTEMS_SUCCESSFUL;
1091 }
1114 }
1092 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1115 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1093 {
1116 {
1094 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1117 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1095 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1118 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1096 {
1119 {
1097 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1120 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1098 }
1121 }
1099 else
1122 else
1100 {
1123 {
1101 status = RTEMS_SUCCESSFUL;
1124 status = RTEMS_SUCCESSFUL;
1102 }
1125 }
1103 }
1126 }
1104 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1127 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1105 {
1128 {
1106 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1129 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1107 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1130 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1108 {
1131 {
1109 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1132 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1110 }
1133 }
1111 else
1134 else
1112 {
1135 {
1113 status = RTEMS_SUCCESSFUL;
1136 status = RTEMS_SUCCESSFUL;
1114 }
1137 }
1115 }
1138 }
1116 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1139 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1117 {
1140 {
1118 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1141 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1119 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1142 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1120 {
1143 {
1121 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1144 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1122 }
1145 }
1123 else
1146 else
1124 {
1147 {
1125 status = RTEMS_SUCCESSFUL;
1148 status = RTEMS_SUCCESSFUL;
1126 }
1149 }
1127 }
1150 }
1128 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1151 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1129 {
1152 {
1130 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1153 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1131 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1154 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1132 {
1155 {
1133 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1156 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1134 }
1157 }
1135 else
1158 else
1136 {
1159 {
1137 status = RTEMS_SUCCESSFUL;
1160 status = RTEMS_SUCCESSFUL;
1138 }
1161 }
1139 }
1162 }
1140 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1163 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1141 {
1164 {
1142 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1165 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1143 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1166 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1144 {
1167 {
1145 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1168 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1146 }
1169 }
1147 else
1170 else
1148 {
1171 {
1149 status = RTEMS_SUCCESSFUL;
1172 status = RTEMS_SUCCESSFUL;
1150 }
1173 }
1151 }
1174 }
1152 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1175 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1153 {
1176 {
1154 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1177 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1155 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1178 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1156 {
1179 {
1157 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1180 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1158 }
1181 }
1159 else
1182 else
1160 {
1183 {
1161 status = RTEMS_SUCCESSFUL;
1184 status = RTEMS_SUCCESSFUL;
1162 }
1185 }
1163 }
1186 }
1164 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1187 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1165 {
1188 {
1166 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1189 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1167 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1190 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1168 {
1191 {
1169 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1192 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1170 }
1193 }
1171 else
1194 else
1172 {
1195 {
1173 status = RTEMS_SUCCESSFUL;
1196 status = RTEMS_SUCCESSFUL;
1174 }
1197 }
1175 }
1198 }
1176 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1199 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1177 {
1200 {
1178 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1201 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1179 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1202 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1180 {
1203 {
1181 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1204 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1182 }
1205 }
1183 else
1206 else
1184 {
1207 {
1185 status = RTEMS_SUCCESSFUL;
1208 status = RTEMS_SUCCESSFUL;
1186 }
1209 }
1187 }
1210 }
1188 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1211 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1189 {
1212 {
1190 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1213 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1191 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1214 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1192 {
1215 {
1193 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1216 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1194 }
1217 }
1195 else
1218 else
1196 {
1219 {
1197 status = RTEMS_SUCCESSFUL;
1220 status = RTEMS_SUCCESSFUL;
1198 }
1221 }
1199 }
1222 }
1200
1223
1201 return status;
1224 return status;
1202 }
1225 }
1203
1226
1204 int suspend_asm_tasks( void )
1227 int suspend_asm_tasks( void )
1205 {
1228 {
1206 /** This function suspends the science tasks.
1229 /** This function suspends the science tasks.
1207 *
1230 *
1208 * @return RTEMS directive status codes:
1231 * @return RTEMS directive status codes:
1209 * - RTEMS_SUCCESSFUL - task restarted successfully
1232 * - RTEMS_SUCCESSFUL - task restarted successfully
1210 * - RTEMS_INVALID_ID - task id invalid
1233 * - RTEMS_INVALID_ID - task id invalid
1211 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1234 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1212 *
1235 *
1213 */
1236 */
1214
1237
1215 rtems_status_code status;
1238 rtems_status_code status;
1216
1239
1217 PRINTF("in suspend_science_tasks\n")
1240 PRINTF("in suspend_science_tasks\n")
1218
1241
1219 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1242 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1220 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1243 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1221 {
1244 {
1222 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1245 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1223 }
1246 }
1224 else
1247 else
1225 {
1248 {
1226 status = RTEMS_SUCCESSFUL;
1249 status = RTEMS_SUCCESSFUL;
1227 }
1250 }
1228
1251
1229 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1252 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1230 {
1253 {
1231 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1254 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1232 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1255 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1233 {
1256 {
1234 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1257 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1235 }
1258 }
1236 else
1259 else
1237 {
1260 {
1238 status = RTEMS_SUCCESSFUL;
1261 status = RTEMS_SUCCESSFUL;
1239 }
1262 }
1240 }
1263 }
1241
1264
1242 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1265 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1243 {
1266 {
1244 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1267 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1245 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1268 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1246 {
1269 {
1247 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1270 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1248 }
1271 }
1249 else
1272 else
1250 {
1273 {
1251 status = RTEMS_SUCCESSFUL;
1274 status = RTEMS_SUCCESSFUL;
1252 }
1275 }
1253 }
1276 }
1254
1277
1255 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1278 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1256 {
1279 {
1257 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1280 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1258 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1281 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1259 {
1282 {
1260 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1283 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1261 }
1284 }
1262 else
1285 else
1263 {
1286 {
1264 status = RTEMS_SUCCESSFUL;
1287 status = RTEMS_SUCCESSFUL;
1265 }
1288 }
1266 }
1289 }
1267
1290
1268 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1291 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1269 {
1292 {
1270 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1293 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1271 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1294 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1272 {
1295 {
1273 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1296 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1274 }
1297 }
1275 else
1298 else
1276 {
1299 {
1277 status = RTEMS_SUCCESSFUL;
1300 status = RTEMS_SUCCESSFUL;
1278 }
1301 }
1279 }
1302 }
1280
1303
1281 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1304 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1282 {
1305 {
1283 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1306 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1284 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1307 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1285 {
1308 {
1286 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1309 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1287 }
1310 }
1288 else
1311 else
1289 {
1312 {
1290 status = RTEMS_SUCCESSFUL;
1313 status = RTEMS_SUCCESSFUL;
1291 }
1314 }
1292 }
1315 }
1293
1316
1294 return status;
1317 return status;
1295 }
1318 }
1296
1319
1297 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1320 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1298 {
1321 {
1299
1322
1300 WFP_reset_current_ring_nodes();
1323 WFP_reset_current_ring_nodes();
1301
1324
1302 reset_waveform_picker_regs();
1325 reset_waveform_picker_regs();
1303
1326
1304 set_wfp_burst_enable_register( mode );
1327 set_wfp_burst_enable_register( mode );
1305
1328
1306 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1329 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1307 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1330 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1308
1331
1309 if (transitionCoarseTime == 0)
1332 if (transitionCoarseTime == 0)
1310 {
1333 {
1311 // instant transition means transition on the next valid date
1334 // instant transition means transition on the next valid date
1312 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1335 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1313 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1336 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1314 }
1337 }
1315 else
1338 else
1316 {
1339 {
1317 waveform_picker_regs->start_date = transitionCoarseTime;
1340 waveform_picker_regs->start_date = transitionCoarseTime;
1318 }
1341 }
1319
1342
1320 update_last_valid_transition_date(waveform_picker_regs->start_date);
1343 update_last_valid_transition_date(waveform_picker_regs->start_date);
1321
1344
1322 }
1345 }
1323
1346
1324 void launch_spectral_matrix( void )
1347 void launch_spectral_matrix( void )
1325 {
1348 {
1326 SM_reset_current_ring_nodes();
1349 SM_reset_current_ring_nodes();
1327
1350
1328 reset_spectral_matrix_regs();
1351 reset_spectral_matrix_regs();
1329
1352
1330 reset_nb_sm();
1353 reset_nb_sm();
1331
1354
1332 set_sm_irq_onNewMatrix( 1 );
1355 set_sm_irq_onNewMatrix( 1 );
1333
1356
1334 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1357 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1335 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1358 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1336
1359
1337 }
1360 }
1338
1361
1339 void set_sm_irq_onNewMatrix( unsigned char value )
1362 void set_sm_irq_onNewMatrix( unsigned char value )
1340 {
1363 {
1341 if (value == 1)
1364 if (value == 1)
1342 {
1365 {
1343 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1366 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1344 }
1367 }
1345 else
1368 else
1346 {
1369 {
1347 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1370 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1348 }
1371 }
1349 }
1372 }
1350
1373
1351 void set_sm_irq_onError( unsigned char value )
1374 void set_sm_irq_onError( unsigned char value )
1352 {
1375 {
1353 if (value == 1)
1376 if (value == 1)
1354 {
1377 {
1355 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1378 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1356 }
1379 }
1357 else
1380 else
1358 {
1381 {
1359 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1382 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1360 }
1383 }
1361 }
1384 }
1362
1385
1363 //*****************************
1386 //*****************************
1364 // CONFIGURE CALIBRATION SIGNAL
1387 // CONFIGURE CALIBRATION SIGNAL
1365 void setCalibrationPrescaler( unsigned int prescaler )
1388 void setCalibrationPrescaler( unsigned int prescaler )
1366 {
1389 {
1367 // prescaling of the master clock (25 MHz)
1390 // prescaling of the master clock (25 MHz)
1368 // master clock is divided by 2^prescaler
1391 // master clock is divided by 2^prescaler
1369 time_management_regs->calPrescaler = prescaler;
1392 time_management_regs->calPrescaler = prescaler;
1370 }
1393 }
1371
1394
1372 void setCalibrationDivisor( unsigned int divisionFactor )
1395 void setCalibrationDivisor( unsigned int divisionFactor )
1373 {
1396 {
1374 // division of the prescaled clock by the division factor
1397 // division of the prescaled clock by the division factor
1375 time_management_regs->calDivisor = divisionFactor;
1398 time_management_regs->calDivisor = divisionFactor;
1376 }
1399 }
1377
1400
1378 void setCalibrationData( void )
1401 void setCalibrationData( void )
1379 {
1402 {
1380 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1403 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1381 *
1404 *
1382 * @param void
1405 * @param void
1383 *
1406 *
1384 * @return void
1407 * @return void
1385 *
1408 *
1386 */
1409 */
1387
1410
1388 unsigned int k;
1411 unsigned int k;
1389 unsigned short data;
1412 unsigned short data;
1390 float val;
1413 float val;
1391 float Ts;
1414 float Ts;
1392
1415
1393 time_management_regs->calDataPtr = INIT_CHAR;
1416 time_management_regs->calDataPtr = INIT_CHAR;
1394
1417
1395 Ts = 1 / CAL_FS;
1418 Ts = 1 / CAL_FS;
1396
1419
1397 // build the signal for the SCM calibration
1420 // build the signal for the SCM calibration
1398 for (k = 0; k < CAL_NB_PTS; k++)
1421 for (k = 0; k < CAL_NB_PTS; k++)
1399 {
1422 {
1400 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1423 val = CAL_A0 * sin( CAL_W0 * k * Ts )
1401 + CAL_A1 * sin( CAL_W1 * k * Ts );
1424 + CAL_A1 * sin( CAL_W1 * k * Ts );
1402 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1425 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1403 time_management_regs->calData = data & CAL_DATA_MASK;
1426 time_management_regs->calData = data & CAL_DATA_MASK;
1404 }
1427 }
1405 }
1428 }
1406
1429
1407 void setCalibrationDataInterleaved( void )
1430 void setCalibrationDataInterleaved( void )
1408 {
1431 {
1409 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1432 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1410 *
1433 *
1411 * @param void
1434 * @param void
1412 *
1435 *
1413 * @return void
1436 * @return void
1414 *
1437 *
1415 * In interleaved mode, one can store more values than in normal mode.
1438 * In interleaved mode, one can store more values than in normal mode.
1416 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1439 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1417 * T store 3 values, one need two write operations.
1440 * T store 3 values, one need two write operations.
1418 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1441 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1419 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1442 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1420 *
1443 *
1421 */
1444 */
1422
1445
1423 unsigned int k;
1446 unsigned int k;
1424 float val;
1447 float val;
1425 float Ts;
1448 float Ts;
1426 unsigned short data[CAL_NB_PTS_INTER];
1449 unsigned short data[CAL_NB_PTS_INTER];
1427 unsigned char *dataPtr;
1450 unsigned char *dataPtr;
1428
1451
1429 Ts = 1 / CAL_FS_INTER;
1452 Ts = 1 / CAL_FS_INTER;
1430
1453
1431 time_management_regs->calDataPtr = INIT_CHAR;
1454 time_management_regs->calDataPtr = INIT_CHAR;
1432
1455
1433 // build the signal for the SCM calibration
1456 // build the signal for the SCM calibration
1434 for (k=0; k<CAL_NB_PTS_INTER; k++)
1457 for (k=0; k<CAL_NB_PTS_INTER; k++)
1435 {
1458 {
1436 val = sin( 2 * pi * CAL_F0 * k * Ts )
1459 val = sin( 2 * pi * CAL_F0 * k * Ts )
1437 + sin( 2 * pi * CAL_F1 * k * Ts );
1460 + sin( 2 * pi * CAL_F1 * k * Ts );
1438 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1461 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1439 }
1462 }
1440
1463
1441 // write the signal in interleaved mode
1464 // write the signal in interleaved mode
1442 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1465 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1443 {
1466 {
1444 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1467 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1445 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1468 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1446 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1469 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1447 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1470 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1448 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1471 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1449 }
1472 }
1450 }
1473 }
1451
1474
1452 void setCalibrationReload( bool state)
1475 void setCalibrationReload( bool state)
1453 {
1476 {
1454 if (state == true)
1477 if (state == true)
1455 {
1478 {
1456 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1479 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1457 }
1480 }
1458 else
1481 else
1459 {
1482 {
1460 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1483 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1461 }
1484 }
1462 }
1485 }
1463
1486
1464 void setCalibrationEnable( bool state )
1487 void setCalibrationEnable( bool state )
1465 {
1488 {
1466 // this bit drives the multiplexer
1489 // this bit drives the multiplexer
1467 if (state == true)
1490 if (state == true)
1468 {
1491 {
1469 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1492 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1470 }
1493 }
1471 else
1494 else
1472 {
1495 {
1473 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1496 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1474 }
1497 }
1475 }
1498 }
1476
1499
1477 void setCalibrationInterleaved( bool state )
1500 void setCalibrationInterleaved( bool state )
1478 {
1501 {
1479 // this bit drives the multiplexer
1502 // this bit drives the multiplexer
1480 if (state == true)
1503 if (state == true)
1481 {
1504 {
1482 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1505 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1483 }
1506 }
1484 else
1507 else
1485 {
1508 {
1486 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1509 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1487 }
1510 }
1488 }
1511 }
1489
1512
1490 void setCalibration( bool state )
1513 void setCalibration( bool state )
1491 {
1514 {
1492 if (state == true)
1515 if (state == true)
1493 {
1516 {
1494 setCalibrationEnable( true );
1517 setCalibrationEnable( true );
1495 setCalibrationReload( false );
1518 setCalibrationReload( false );
1496 set_hk_lfr_calib_enable( true );
1519 set_hk_lfr_calib_enable( true );
1497 }
1520 }
1498 else
1521 else
1499 {
1522 {
1500 setCalibrationEnable( false );
1523 setCalibrationEnable( false );
1501 setCalibrationReload( true );
1524 setCalibrationReload( true );
1502 set_hk_lfr_calib_enable( false );
1525 set_hk_lfr_calib_enable( false );
1503 }
1526 }
1504 }
1527 }
1505
1528
1506 void configureCalibration( bool interleaved )
1529 void configureCalibration( bool interleaved )
1507 {
1530 {
1508 setCalibration( false );
1531 setCalibration( false );
1509 if ( interleaved == true )
1532 if ( interleaved == true )
1510 {
1533 {
1511 setCalibrationInterleaved( true );
1534 setCalibrationInterleaved( true );
1512 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1535 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1513 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1536 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1514 setCalibrationDataInterleaved();
1537 setCalibrationDataInterleaved();
1515 }
1538 }
1516 else
1539 else
1517 {
1540 {
1518 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1541 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1519 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1542 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1520 setCalibrationData();
1543 setCalibrationData();
1521 }
1544 }
1522 }
1545 }
1523
1546
1524 //****************
1547 //****************
1525 // CLOSING ACTIONS
1548 // CLOSING ACTIONS
1526 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1549 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1527 {
1550 {
1528 /** This function is used to update the HK packets statistics after a successful TC execution.
1551 /** This function is used to update the HK packets statistics after a successful TC execution.
1529 *
1552 *
1530 * @param TC points to the TC being processed
1553 * @param TC points to the TC being processed
1531 * @param time is the time used to date the TC execution
1554 * @param time is the time used to date the TC execution
1532 *
1555 *
1533 */
1556 */
1534
1557
1535 unsigned int val;
1558 unsigned int val;
1536
1559
1537 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1560 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1538 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1561 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1539 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1562 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1540 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1563 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1541 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1564 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1542 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1565 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1543 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1566 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1544 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1567 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1545 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1568 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1546 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1569 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1547 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1570 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1548 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1571 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1549
1572
1550 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1573 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1551 val++;
1574 val++;
1552 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1575 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1553 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1576 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1554 }
1577 }
1555
1578
1556 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1579 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1557 {
1580 {
1558 /** This function is used to update the HK packets statistics after a TC rejection.
1581 /** This function is used to update the HK packets statistics after a TC rejection.
1559 *
1582 *
1560 * @param TC points to the TC being processed
1583 * @param TC points to the TC being processed
1561 * @param time is the time used to date the TC rejection
1584 * @param time is the time used to date the TC rejection
1562 *
1585 *
1563 */
1586 */
1564
1587
1565 unsigned int val;
1588 unsigned int val;
1566
1589
1567 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1590 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1568 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1591 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1569 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1592 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1570 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1593 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1571 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1594 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1572 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1595 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1573 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1596 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1574 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1597 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1575 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1598 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1576 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1599 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1577 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1600 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1578 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1601 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1579
1602
1580 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1603 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1581 val++;
1604 val++;
1582 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1605 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1583 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1606 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1584 }
1607 }
1585
1608
1586 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1609 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1587 {
1610 {
1588 /** This function is the last step of the TC execution workflow.
1611 /** This function is the last step of the TC execution workflow.
1589 *
1612 *
1590 * @param TC points to the TC being processed
1613 * @param TC points to the TC being processed
1591 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1614 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1592 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1615 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1593 * @param time is the time used to date the TC execution
1616 * @param time is the time used to date the TC execution
1594 *
1617 *
1595 */
1618 */
1596
1619
1597 unsigned char requestedMode;
1620 unsigned char requestedMode;
1598
1621
1599 if (result == LFR_SUCCESSFUL)
1622 if (result == LFR_SUCCESSFUL)
1600 {
1623 {
1601 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1624 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1602 &
1625 &
1603 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1626 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1604 )
1627 )
1605 {
1628 {
1606 send_tm_lfr_tc_exe_success( TC, queue_id );
1629 send_tm_lfr_tc_exe_success( TC, queue_id );
1607 }
1630 }
1608 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1631 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1609 {
1632 {
1610 //**********************************
1633 //**********************************
1611 // UPDATE THE LFRMODE LOCAL VARIABLE
1634 // UPDATE THE LFRMODE LOCAL VARIABLE
1612 requestedMode = TC->dataAndCRC[1];
1635 requestedMode = TC->dataAndCRC[1];
1613 updateLFRCurrentMode( requestedMode );
1636 updateLFRCurrentMode( requestedMode );
1614 }
1637 }
1615 }
1638 }
1616 else if (result == LFR_EXE_ERROR)
1639 else if (result == LFR_EXE_ERROR)
1617 {
1640 {
1618 send_tm_lfr_tc_exe_error( TC, queue_id );
1641 send_tm_lfr_tc_exe_error( TC, queue_id );
1619 }
1642 }
1620 }
1643 }
1621
1644
1622 //***************************
1645 //***************************
1623 // Interrupt Service Routines
1646 // Interrupt Service Routines
1624 rtems_isr commutation_isr1( rtems_vector_number vector )
1647 rtems_isr commutation_isr1( rtems_vector_number vector )
1625 {
1648 {
1626 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1649 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1627 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1650 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1628 }
1651 }
1629 }
1652 }
1630
1653
1631 rtems_isr commutation_isr2( rtems_vector_number vector )
1654 rtems_isr commutation_isr2( rtems_vector_number vector )
1632 {
1655 {
1633 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1656 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1634 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1657 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1635 }
1658 }
1636 }
1659 }
1637
1660
1638 //****************
1661 //****************
1639 // OTHER FUNCTIONS
1662 // OTHER FUNCTIONS
1640 void updateLFRCurrentMode( unsigned char requestedMode )
1663 void updateLFRCurrentMode( unsigned char requestedMode )
1641 {
1664 {
1642 /** This function updates the value of the global variable lfrCurrentMode.
1665 /** This function updates the value of the global variable lfrCurrentMode.
1643 *
1666 *
1644 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1667 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1645 *
1668 *
1646 */
1669 */
1647
1670
1648 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1671 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1649 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1672 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1650 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1673 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1651 lfrCurrentMode = requestedMode;
1674 lfrCurrentMode = requestedMode;
1652 }
1675 }
1653
1676
1654 void set_lfr_soft_reset( unsigned char value )
1677 void set_lfr_soft_reset( unsigned char value )
1655 {
1678 {
1656 if (value == 1)
1679 if (value == 1)
1657 {
1680 {
1658 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1681 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1659 }
1682 }
1660 else
1683 else
1661 {
1684 {
1662 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1685 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1663 }
1686 }
1664 }
1687 }
1665
1688
1666 void reset_lfr( void )
1689 void reset_lfr( void )
1667 {
1690 {
1668 set_lfr_soft_reset( 1 );
1691 set_lfr_soft_reset( 1 );
1669
1692
1670 set_lfr_soft_reset( 0 );
1693 set_lfr_soft_reset( 0 );
1671
1694
1672 set_hk_lfr_sc_potential_flag( true );
1695 set_hk_lfr_sc_potential_flag( true );
1673 }
1696 }
@@ -1,2064 +1,2088
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions to load and dump parameters in the LFR registers.
25 /** Functions to load and dump parameters in the LFR registers.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
30 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
31 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
32 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
33 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
34 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
35 * TC_LFR_LOAD_SBM2_PAR\n
12 *
36 *
13 */
37 */
14
38
15 #include "tc_load_dump_parameters.h"
39 #include "tc_load_dump_parameters.h"
16
40
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
41 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1 = {0};
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
42 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2 = {0};
19 ring_node kcoefficient_node_1 = {0};
43 ring_node kcoefficient_node_1 = {0};
20 ring_node kcoefficient_node_2 = {0};
44 ring_node kcoefficient_node_2 = {0};
21
45
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
46 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
47 {
24 /** This function updates the LFR registers with the incoming common parameters.
48 /** This function updates the LFR registers with the incoming common parameters.
25 *
49 *
26 * @param TC points to the TeleCommand packet that is being processed
50 * @param TC points to the TeleCommand packet that is being processed
27 *
51 *
28 *
52 *
29 */
53 */
30
54
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
55 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
56 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
57 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
58 return LFR_SUCCESSFUL;
35 }
59 }
36
60
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
61 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
62 {
39 /** This function updates the LFR registers with the incoming normal parameters.
63 /** This function updates the LFR registers with the incoming normal parameters.
40 *
64 *
41 * @param TC points to the TeleCommand packet that is being processed
65 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
66 * @param queue_id is the id of the queue which handles TM related to this execution step
43 *
67 *
44 */
68 */
45
69
46 int result;
70 int result;
47 int flag;
71 int flag;
48 rtems_status_code status;
72 rtems_status_code status;
49
73
50 flag = LFR_SUCCESSFUL;
74 flag = LFR_SUCCESSFUL;
51
75
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
76 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
77 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
78 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
79 flag = LFR_DEFAULT;
56 }
80 }
57
81
58 // CHECK THE PARAMETERS SET CONSISTENCY
82 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
83 if (flag == LFR_SUCCESSFUL)
60 {
84 {
61 flag = check_normal_par_consistency( TC, queue_id );
85 flag = check_normal_par_consistency( TC, queue_id );
62 }
86 }
63
87
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
88 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
89 if (flag == LFR_SUCCESSFUL)
66 {
90 {
67 result = set_sy_lfr_n_swf_l( TC );
91 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
92 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
93 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
94 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
95 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
96 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
97 }
74
98
75 return flag;
99 return flag;
76 }
100 }
77
101
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
102 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
103 {
80 /** This function updates the LFR registers with the incoming burst parameters.
104 /** This function updates the LFR registers with the incoming burst parameters.
81 *
105 *
82 * @param TC points to the TeleCommand packet that is being processed
106 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
107 * @param queue_id is the id of the queue which handles TM related to this execution step
84 *
108 *
85 */
109 */
86
110
87 int flag;
111 int flag;
88 rtems_status_code status;
112 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
113 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
114 unsigned char sy_lfr_b_bp_p1;
91 float aux;
115 float aux;
92
116
93 flag = LFR_SUCCESSFUL;
117 flag = LFR_SUCCESSFUL;
94
118
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
119 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
120 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
121 flag = LFR_DEFAULT;
98 }
122 }
99
123
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
124 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
125 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
126
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
127 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
128 if (flag == LFR_SUCCESSFUL)
105 {
129 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
130 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
131 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
132 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 flag = WRONG_APP_DATA;
133 flag = WRONG_APP_DATA;
110 }
134 }
111 }
135 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
136 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
137 if (flag == LFR_SUCCESSFUL)
114 {
138 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
139 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
140 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
141 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 flag = WRONG_APP_DATA;
142 flag = WRONG_APP_DATA;
119 }
143 }
120 }
144 }
121 //****************************************************************
145 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
146 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
147 if (flag == LFR_SUCCESSFUL)
124 {
148 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
149 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
150 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
151 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 if (aux > FLOAT_EQUAL_ZERO)
152 if (aux > FLOAT_EQUAL_ZERO)
129 {
153 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
154 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 flag = LFR_DEFAULT;
155 flag = LFR_DEFAULT;
132 }
156 }
133 }
157 }
134
158
135 // SET THE PARAMETERS
159 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
160 if (flag == LFR_SUCCESSFUL)
137 {
161 {
138 flag = set_sy_lfr_b_bp_p0( TC );
162 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
163 flag = set_sy_lfr_b_bp_p1( TC );
140 }
164 }
141
165
142 return flag;
166 return flag;
143 }
167 }
144
168
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
169 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
170 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
171 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
172 *
149 * @param TC points to the TeleCommand packet that is being processed
173 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
174 * @param queue_id is the id of the queue which handles TM related to this execution step
151 *
175 *
152 */
176 */
153
177
154 int flag;
178 int flag;
155 rtems_status_code status;
179 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
180 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
181 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
182 float aux;
159
183
160 flag = LFR_SUCCESSFUL;
184 flag = LFR_SUCCESSFUL;
161
185
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
186 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
187 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
188 flag = LFR_DEFAULT;
165 }
189 }
166
190
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
191 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
192 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
193
170 // sy_lfr_s1_bp_p0
194 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
195 if (flag == LFR_SUCCESSFUL)
172 {
196 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
197 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
198 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
199 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 flag = WRONG_APP_DATA;
200 flag = WRONG_APP_DATA;
177 }
201 }
178 }
202 }
179 // sy_lfr_s1_bp_p1
203 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
204 if (flag == LFR_SUCCESSFUL)
181 {
205 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
206 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
207 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
208 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 flag = WRONG_APP_DATA;
209 flag = WRONG_APP_DATA;
186 }
210 }
187 }
211 }
188 //******************************************************************
212 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
213 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
214 if (flag == LFR_SUCCESSFUL)
191 {
215 {
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
216 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
217 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
194 if (aux > FLOAT_EQUAL_ZERO)
218 if (aux > FLOAT_EQUAL_ZERO)
195 {
219 {
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
220 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
197 flag = LFR_DEFAULT;
221 flag = LFR_DEFAULT;
198 }
222 }
199 }
223 }
200
224
201 // SET THE PARAMETERS
225 // SET THE PARAMETERS
202 if (flag == LFR_SUCCESSFUL)
226 if (flag == LFR_SUCCESSFUL)
203 {
227 {
204 flag = set_sy_lfr_s1_bp_p0( TC );
228 flag = set_sy_lfr_s1_bp_p0( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
229 flag = set_sy_lfr_s1_bp_p1( TC );
206 }
230 }
207
231
208 return flag;
232 return flag;
209 }
233 }
210
234
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
235 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
212 {
236 {
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
237 /** This function updates the LFR registers with the incoming sbm2 parameters.
214 *
238 *
215 * @param TC points to the TeleCommand packet that is being processed
239 * @param TC points to the TeleCommand packet that is being processed
216 * @param queue_id is the id of the queue which handles TM related to this execution step
240 * @param queue_id is the id of the queue which handles TM related to this execution step
217 *
241 *
218 */
242 */
219
243
220 int flag;
244 int flag;
221 rtems_status_code status;
245 rtems_status_code status;
222 unsigned char sy_lfr_s2_bp_p0;
246 unsigned char sy_lfr_s2_bp_p0;
223 unsigned char sy_lfr_s2_bp_p1;
247 unsigned char sy_lfr_s2_bp_p1;
224 float aux;
248 float aux;
225
249
226 flag = LFR_SUCCESSFUL;
250 flag = LFR_SUCCESSFUL;
227
251
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
252 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
253 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
230 flag = LFR_DEFAULT;
254 flag = LFR_DEFAULT;
231 }
255 }
232
256
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
235
259
236 // sy_lfr_s2_bp_p0
260 // sy_lfr_s2_bp_p0
237 if (flag == LFR_SUCCESSFUL)
261 if (flag == LFR_SUCCESSFUL)
238 {
262 {
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
263 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
240 {
264 {
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
265 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
242 flag = WRONG_APP_DATA;
266 flag = WRONG_APP_DATA;
243 }
267 }
244 }
268 }
245 // sy_lfr_s2_bp_p1
269 // sy_lfr_s2_bp_p1
246 if (flag == LFR_SUCCESSFUL)
270 if (flag == LFR_SUCCESSFUL)
247 {
271 {
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
272 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
249 {
273 {
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
274 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
251 flag = WRONG_APP_DATA;
275 flag = WRONG_APP_DATA;
252 }
276 }
253 }
277 }
254 //******************************************************************
278 //******************************************************************
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
279 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
256 if (flag == LFR_SUCCESSFUL)
280 if (flag == LFR_SUCCESSFUL)
257 {
281 {
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
282 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
283 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
284 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
261 if (aux > FLOAT_EQUAL_ZERO)
285 if (aux > FLOAT_EQUAL_ZERO)
262 {
286 {
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
287 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
264 flag = LFR_DEFAULT;
288 flag = LFR_DEFAULT;
265 }
289 }
266 }
290 }
267
291
268 // SET THE PARAMETERS
292 // SET THE PARAMETERS
269 if (flag == LFR_SUCCESSFUL)
293 if (flag == LFR_SUCCESSFUL)
270 {
294 {
271 flag = set_sy_lfr_s2_bp_p0( TC );
295 flag = set_sy_lfr_s2_bp_p0( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
296 flag = set_sy_lfr_s2_bp_p1( TC );
273 }
297 }
274
298
275 return flag;
299 return flag;
276 }
300 }
277
301
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
302 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
279 {
303 {
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
304 /** This function updates the LFR registers with the incoming sbm2 parameters.
281 *
305 *
282 * @param TC points to the TeleCommand packet that is being processed
306 * @param TC points to the TeleCommand packet that is being processed
283 * @param queue_id is the id of the queue which handles TM related to this execution step
307 * @param queue_id is the id of the queue which handles TM related to this execution step
284 *
308 *
285 */
309 */
286
310
287 int flag;
311 int flag;
288
312
289 flag = LFR_DEFAULT;
313 flag = LFR_DEFAULT;
290
314
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
315 flag = set_sy_lfr_kcoeff( TC, queue_id );
292
316
293 return flag;
317 return flag;
294 }
318 }
295
319
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
320 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
297 {
321 {
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
322 /** This function updates the LFR registers with the incoming sbm2 parameters.
299 *
323 *
300 * @param TC points to the TeleCommand packet that is being processed
324 * @param TC points to the TeleCommand packet that is being processed
301 * @param queue_id is the id of the queue which handles TM related to this execution step
325 * @param queue_id is the id of the queue which handles TM related to this execution step
302 *
326 *
303 */
327 */
304
328
305 int flag;
329 int flag;
306
330
307 flag = LFR_DEFAULT;
331 flag = LFR_DEFAULT;
308
332
309 flag = set_sy_lfr_fbins( TC );
333 flag = set_sy_lfr_fbins( TC );
310
334
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
335 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
312 merge_fbins_masks();
336 merge_fbins_masks();
313
337
314 return flag;
338 return flag;
315 }
339 }
316
340
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
341 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
318 {
342 {
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
343 /** This function updates the LFR registers with the incoming sbm2 parameters.
320 *
344 *
321 * @param TC points to the TeleCommand packet that is being processed
345 * @param TC points to the TeleCommand packet that is being processed
322 * @param queue_id is the id of the queue which handles TM related to this execution step
346 * @param queue_id is the id of the queue which handles TM related to this execution step
323 *
347 *
324 */
348 */
325
349
326 int flag;
350 int flag;
327 unsigned char k;
351 unsigned char k;
328
352
329 flag = LFR_DEFAULT;
353 flag = LFR_DEFAULT;
330 k = INIT_CHAR;
354 k = INIT_CHAR;
331
355
332 flag = check_sy_lfr_filter_parameters( TC, queue_id );
356 flag = check_sy_lfr_filter_parameters( TC, queue_id );
333
357
334 if (flag == LFR_SUCCESSFUL)
358 if (flag == LFR_SUCCESSFUL)
335 {
359 {
336 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
360 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
337 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
361 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
362 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
363 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
340 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
364 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
341 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
365 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
342 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
366 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
367 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
368 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
345 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
369 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
346 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
370 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
371 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
372 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
349 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
373 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
350 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
374 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
351
375
352 //****************************
376 //****************************
353 // store PAS filter parameters
377 // store PAS filter parameters
354
378
355 // sy_lfr_pas_filter_enabled
379 // sy_lfr_pas_filter_enabled
356 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
380 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
357 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
381 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
358
382
359 // sy_lfr_pas_filter_modulus
383 // sy_lfr_pas_filter_modulus
360 filterPar.modulus_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_modulus) * CONST_65536;
384 filterPar.modulus_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_modulus) * CONST_65536;
361
385
362 // sy_lfr_pas_filter_tbad
386 // sy_lfr_pas_filter_tbad
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
387 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
364 parameter_dump_packet.sy_lfr_pas_filter_tbad );
388 parameter_dump_packet.sy_lfr_pas_filter_tbad );
365 filterPar.tbad_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_tbad * CONST_65536);
389 filterPar.tbad_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_tbad * CONST_65536);
366
390
367 // sy_lfr_pas_filter_offset
391 // sy_lfr_pas_filter_offset
368 filterPar.offset_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_offset) * CONST_65536;
392 filterPar.offset_in_finetime = ((uint64_t) parameter_dump_packet.sy_lfr_pas_filter_offset) * CONST_65536;
369
393
370 // sy_lfr_pas_filter_shift
394 // sy_lfr_pas_filter_shift
371 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
372 parameter_dump_packet.sy_lfr_pas_filter_shift );
396 parameter_dump_packet.sy_lfr_pas_filter_shift );
373 filterPar.shift_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_shift * CONST_65536);
397 filterPar.shift_in_finetime = (uint64_t) (filterPar.sy_lfr_pas_filter_shift * CONST_65536);
374
398
375 //****************************************************
399 //****************************************************
376 // store the parameter sy_lfr_sc_rw_delta_f as a float
400 // store the parameter sy_lfr_sc_rw_delta_f as a float
377 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
401 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
378 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
402 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
379
403
380 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
404 // copy rw.._k.. from the incoming TC to the local parameter_dump_packet
381 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
405 for (k = 0; k < NB_RW_K_COEFFS * NB_BYTES_PER_RW_K_COEFF; k++)
382 {
406 {
383 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
407 parameter_dump_packet.sy_lfr_rw1_k1[k] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_RW1_K1 + k ];
384 }
408 }
385
409
386 //***********************************************
410 //***********************************************
387 // store the parameter sy_lfr_rw.._k.. as a float
411 // store the parameter sy_lfr_rw.._k.. as a float
388 // rw1_k
412 // rw1_k
389 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
413 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k1, parameter_dump_packet.sy_lfr_rw1_k1 );
390 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
414 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k2, parameter_dump_packet.sy_lfr_rw1_k2 );
391 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
415 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k3, parameter_dump_packet.sy_lfr_rw1_k3 );
392 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
416 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw1_k4, parameter_dump_packet.sy_lfr_rw1_k4 );
393 // rw2_k
417 // rw2_k
394 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
418 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k1, parameter_dump_packet.sy_lfr_rw2_k1 );
395 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
419 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k2, parameter_dump_packet.sy_lfr_rw2_k2 );
396 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
420 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k3, parameter_dump_packet.sy_lfr_rw2_k3 );
397 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
421 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw2_k4, parameter_dump_packet.sy_lfr_rw2_k4 );
398 // rw3_k
422 // rw3_k
399 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
423 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k1, parameter_dump_packet.sy_lfr_rw3_k1 );
400 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
424 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k2, parameter_dump_packet.sy_lfr_rw3_k2 );
401 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
425 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k3, parameter_dump_packet.sy_lfr_rw3_k3 );
402 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
426 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw3_k4, parameter_dump_packet.sy_lfr_rw3_k4 );
403 // rw4_k
427 // rw4_k
404 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
428 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k1, parameter_dump_packet.sy_lfr_rw4_k1 );
405 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
429 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k2, parameter_dump_packet.sy_lfr_rw4_k2 );
406 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
430 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k3, parameter_dump_packet.sy_lfr_rw4_k3 );
407 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
431 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_rw4_k4, parameter_dump_packet.sy_lfr_rw4_k4 );
408
432
409 }
433 }
410
434
411 return flag;
435 return flag;
412 }
436 }
413
437
414 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
438 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
415 {
439 {
416 /** This function updates the LFR registers with the incoming sbm2 parameters.
440 /** This function updates the LFR registers with the incoming sbm2 parameters.
417 *
441 *
418 * @param TC points to the TeleCommand packet that is being processed
442 * @param TC points to the TeleCommand packet that is being processed
419 * @param queue_id is the id of the queue which handles TM related to this execution step
443 * @param queue_id is the id of the queue which handles TM related to this execution step
420 *
444 *
421 */
445 */
422
446
423 unsigned int address;
447 unsigned int address;
424 rtems_status_code status;
448 rtems_status_code status;
425 unsigned int freq;
449 unsigned int freq;
426 unsigned int bin;
450 unsigned int bin;
427 unsigned int coeff;
451 unsigned int coeff;
428 unsigned char *kCoeffPtr;
452 unsigned char *kCoeffPtr;
429 unsigned char *kCoeffDumpPtr;
453 unsigned char *kCoeffDumpPtr;
430
454
431 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
455 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
432 // F0 => 11 bins
456 // F0 => 11 bins
433 // F1 => 13 bins
457 // F1 => 13 bins
434 // F2 => 12 bins
458 // F2 => 12 bins
435 // 36 bins to dump in two packets (30 bins max per packet)
459 // 36 bins to dump in two packets (30 bins max per packet)
436
460
437 //*********
461 //*********
438 // PACKET 1
462 // PACKET 1
439 // 11 F0 bins, 13 F1 bins and 6 F2 bins
463 // 11 F0 bins, 13 F1 bins and 6 F2 bins
440 kcoefficients_dump_1.destinationID = TC->sourceID;
464 kcoefficients_dump_1.destinationID = TC->sourceID;
441 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
465 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
442 for( freq = 0;
466 for( freq = 0;
443 freq < NB_BINS_COMPRESSED_SM_F0;
467 freq < NB_BINS_COMPRESSED_SM_F0;
444 freq++ )
468 freq++ )
445 {
469 {
446 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
470 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
447 bin = freq;
471 bin = freq;
448 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
472 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
449 {
473 {
450 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
474 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
451 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
475 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
452 ]; // 2 for the kcoeff_frequency
476 ]; // 2 for the kcoeff_frequency
453 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
477 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
454 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
478 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
455 }
479 }
456 }
480 }
457 for( freq = NB_BINS_COMPRESSED_SM_F0;
481 for( freq = NB_BINS_COMPRESSED_SM_F0;
458 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
482 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
459 freq++ )
483 freq++ )
460 {
484 {
461 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
485 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
462 bin = freq - NB_BINS_COMPRESSED_SM_F0;
486 bin = freq - NB_BINS_COMPRESSED_SM_F0;
463 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
487 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
464 {
488 {
465 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
489 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
466 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
490 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
467 ]; // 2 for the kcoeff_frequency
491 ]; // 2 for the kcoeff_frequency
468 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
492 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
469 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
493 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
470 }
494 }
471 }
495 }
472 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
496 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
473 freq < KCOEFF_BLK_NR_PKT1 ;
497 freq < KCOEFF_BLK_NR_PKT1 ;
474 freq++ )
498 freq++ )
475 {
499 {
476 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
500 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
477 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
501 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
478 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
502 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
479 {
503 {
480 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
504 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
481 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
505 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
482 ]; // 2 for the kcoeff_frequency
506 ]; // 2 for the kcoeff_frequency
483 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
507 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
484 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
508 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
485 }
509 }
486 }
510 }
487 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
511 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
488 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
512 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
489 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
513 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
490 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
514 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
491 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
515 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
492 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
516 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
493 // SEND DATA
517 // SEND DATA
494 kcoefficient_node_1.status = 1;
518 kcoefficient_node_1.status = 1;
495 address = (unsigned int) &kcoefficient_node_1;
519 address = (unsigned int) &kcoefficient_node_1;
496 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
520 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
497 if (status != RTEMS_SUCCESSFUL) {
521 if (status != RTEMS_SUCCESSFUL) {
498 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
522 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
499 }
523 }
500
524
501 //********
525 //********
502 // PACKET 2
526 // PACKET 2
503 // 6 F2 bins
527 // 6 F2 bins
504 kcoefficients_dump_2.destinationID = TC->sourceID;
528 kcoefficients_dump_2.destinationID = TC->sourceID;
505 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
529 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
506 for( freq = 0;
530 for( freq = 0;
507 freq < KCOEFF_BLK_NR_PKT2;
531 freq < KCOEFF_BLK_NR_PKT2;
508 freq++ )
532 freq++ )
509 {
533 {
510 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
534 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
511 bin = freq + KCOEFF_BLK_NR_PKT2;
535 bin = freq + KCOEFF_BLK_NR_PKT2;
512 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
536 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
513 {
537 {
514 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
538 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
515 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
539 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
516 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
540 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
517 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
541 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
518 }
542 }
519 }
543 }
520 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
544 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
521 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
545 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
522 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
546 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
523 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
547 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
524 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
548 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
525 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
549 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
526 // SEND DATA
550 // SEND DATA
527 kcoefficient_node_2.status = 1;
551 kcoefficient_node_2.status = 1;
528 address = (unsigned int) &kcoefficient_node_2;
552 address = (unsigned int) &kcoefficient_node_2;
529 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
553 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
530 if (status != RTEMS_SUCCESSFUL) {
554 if (status != RTEMS_SUCCESSFUL) {
531 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
555 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
532 }
556 }
533
557
534 return status;
558 return status;
535 }
559 }
536
560
537 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
561 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
538 {
562 {
539 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
563 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
540 *
564 *
541 * @param queue_id is the id of the queue which handles TM related to this execution step.
565 * @param queue_id is the id of the queue which handles TM related to this execution step.
542 *
566 *
543 * @return RTEMS directive status codes:
567 * @return RTEMS directive status codes:
544 * - RTEMS_SUCCESSFUL - message sent successfully
568 * - RTEMS_SUCCESSFUL - message sent successfully
545 * - RTEMS_INVALID_ID - invalid queue id
569 * - RTEMS_INVALID_ID - invalid queue id
546 * - RTEMS_INVALID_SIZE - invalid message size
570 * - RTEMS_INVALID_SIZE - invalid message size
547 * - RTEMS_INVALID_ADDRESS - buffer is NULL
571 * - RTEMS_INVALID_ADDRESS - buffer is NULL
548 * - RTEMS_UNSATISFIED - out of message buffers
572 * - RTEMS_UNSATISFIED - out of message buffers
549 * - RTEMS_TOO_MANY - queue s limit has been reached
573 * - RTEMS_TOO_MANY - queue s limit has been reached
550 *
574 *
551 */
575 */
552
576
553 int status;
577 int status;
554
578
555 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
579 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
556 parameter_dump_packet.destinationID = TC->sourceID;
580 parameter_dump_packet.destinationID = TC->sourceID;
557
581
558 // UPDATE TIME
582 // UPDATE TIME
559 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
583 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
560 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
584 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
561 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
585 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
562 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
586 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
563 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
587 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
564 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
588 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
565 // SEND DATA
589 // SEND DATA
566 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
590 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
567 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
591 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
568 if (status != RTEMS_SUCCESSFUL) {
592 if (status != RTEMS_SUCCESSFUL) {
569 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
593 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
570 }
594 }
571
595
572 return status;
596 return status;
573 }
597 }
574
598
575 //***********************
599 //***********************
576 // NORMAL MODE PARAMETERS
600 // NORMAL MODE PARAMETERS
577
601
578 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
602 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
579 {
603 {
580 unsigned char msb;
604 unsigned char msb;
581 unsigned char lsb;
605 unsigned char lsb;
582 int flag;
606 int flag;
583 float aux;
607 float aux;
584 rtems_status_code status;
608 rtems_status_code status;
585
609
586 unsigned int sy_lfr_n_swf_l;
610 unsigned int sy_lfr_n_swf_l;
587 unsigned int sy_lfr_n_swf_p;
611 unsigned int sy_lfr_n_swf_p;
588 unsigned int sy_lfr_n_asm_p;
612 unsigned int sy_lfr_n_asm_p;
589 unsigned char sy_lfr_n_bp_p0;
613 unsigned char sy_lfr_n_bp_p0;
590 unsigned char sy_lfr_n_bp_p1;
614 unsigned char sy_lfr_n_bp_p1;
591 unsigned char sy_lfr_n_cwf_long_f3;
615 unsigned char sy_lfr_n_cwf_long_f3;
592
616
593 flag = LFR_SUCCESSFUL;
617 flag = LFR_SUCCESSFUL;
594
618
595 //***************
619 //***************
596 // get parameters
620 // get parameters
597 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
621 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
598 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
622 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
599 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
623 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
600
624
601 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
625 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
602 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
626 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
603 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
627 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
604
628
605 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
629 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
606 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
630 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
607 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
631 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
608
632
609 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
633 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
610
634
611 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
635 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
612
636
613 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
637 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
614
638
615 //******************
639 //******************
616 // check consistency
640 // check consistency
617 // sy_lfr_n_swf_l
641 // sy_lfr_n_swf_l
618 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
642 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
619 {
643 {
620 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
644 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
621 flag = WRONG_APP_DATA;
645 flag = WRONG_APP_DATA;
622 }
646 }
623 // sy_lfr_n_swf_p
647 // sy_lfr_n_swf_p
624 if (flag == LFR_SUCCESSFUL)
648 if (flag == LFR_SUCCESSFUL)
625 {
649 {
626 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
650 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
627 {
651 {
628 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
652 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
629 flag = WRONG_APP_DATA;
653 flag = WRONG_APP_DATA;
630 }
654 }
631 }
655 }
632 // sy_lfr_n_bp_p0
656 // sy_lfr_n_bp_p0
633 if (flag == LFR_SUCCESSFUL)
657 if (flag == LFR_SUCCESSFUL)
634 {
658 {
635 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
659 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
636 {
660 {
637 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
661 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
638 flag = WRONG_APP_DATA;
662 flag = WRONG_APP_DATA;
639 }
663 }
640 }
664 }
641 // sy_lfr_n_asm_p
665 // sy_lfr_n_asm_p
642 if (flag == LFR_SUCCESSFUL)
666 if (flag == LFR_SUCCESSFUL)
643 {
667 {
644 if (sy_lfr_n_asm_p == 0)
668 if (sy_lfr_n_asm_p == 0)
645 {
669 {
646 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
670 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
647 flag = WRONG_APP_DATA;
671 flag = WRONG_APP_DATA;
648 }
672 }
649 }
673 }
650 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
674 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
651 if (flag == LFR_SUCCESSFUL)
675 if (flag == LFR_SUCCESSFUL)
652 {
676 {
653 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
677 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
654 if (aux > FLOAT_EQUAL_ZERO)
678 if (aux > FLOAT_EQUAL_ZERO)
655 {
679 {
656 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
680 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
657 flag = WRONG_APP_DATA;
681 flag = WRONG_APP_DATA;
658 }
682 }
659 }
683 }
660 // sy_lfr_n_bp_p1
684 // sy_lfr_n_bp_p1
661 if (flag == LFR_SUCCESSFUL)
685 if (flag == LFR_SUCCESSFUL)
662 {
686 {
663 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
687 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
664 {
688 {
665 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
689 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
666 flag = WRONG_APP_DATA;
690 flag = WRONG_APP_DATA;
667 }
691 }
668 }
692 }
669 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
693 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
670 if (flag == LFR_SUCCESSFUL)
694 if (flag == LFR_SUCCESSFUL)
671 {
695 {
672 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
696 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
673 if (aux > FLOAT_EQUAL_ZERO)
697 if (aux > FLOAT_EQUAL_ZERO)
674 {
698 {
675 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
699 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
676 flag = LFR_DEFAULT;
700 flag = LFR_DEFAULT;
677 }
701 }
678 }
702 }
679 // sy_lfr_n_cwf_long_f3
703 // sy_lfr_n_cwf_long_f3
680
704
681 return flag;
705 return flag;
682 }
706 }
683
707
684 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
708 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
685 {
709 {
686 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
710 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
687 *
711 *
688 * @param TC points to the TeleCommand packet that is being processed
712 * @param TC points to the TeleCommand packet that is being processed
689 * @param queue_id is the id of the queue which handles TM related to this execution step
713 * @param queue_id is the id of the queue which handles TM related to this execution step
690 *
714 *
691 */
715 */
692
716
693 int result;
717 int result;
694
718
695 result = LFR_SUCCESSFUL;
719 result = LFR_SUCCESSFUL;
696
720
697 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
721 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
698 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
722 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
699
723
700 return result;
724 return result;
701 }
725 }
702
726
703 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
727 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
704 {
728 {
705 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
729 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
706 *
730 *
707 * @param TC points to the TeleCommand packet that is being processed
731 * @param TC points to the TeleCommand packet that is being processed
708 * @param queue_id is the id of the queue which handles TM related to this execution step
732 * @param queue_id is the id of the queue which handles TM related to this execution step
709 *
733 *
710 */
734 */
711
735
712 int result;
736 int result;
713
737
714 result = LFR_SUCCESSFUL;
738 result = LFR_SUCCESSFUL;
715
739
716 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
740 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
717 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
741 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
718
742
719 return result;
743 return result;
720 }
744 }
721
745
722 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
746 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
723 {
747 {
724 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
748 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
725 *
749 *
726 * @param TC points to the TeleCommand packet that is being processed
750 * @param TC points to the TeleCommand packet that is being processed
727 * @param queue_id is the id of the queue which handles TM related to this execution step
751 * @param queue_id is the id of the queue which handles TM related to this execution step
728 *
752 *
729 */
753 */
730
754
731 int result;
755 int result;
732
756
733 result = LFR_SUCCESSFUL;
757 result = LFR_SUCCESSFUL;
734
758
735 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
759 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
736 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
760 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
737
761
738 return result;
762 return result;
739 }
763 }
740
764
741 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
765 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
742 {
766 {
743 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
767 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
744 *
768 *
745 * @param TC points to the TeleCommand packet that is being processed
769 * @param TC points to the TeleCommand packet that is being processed
746 * @param queue_id is the id of the queue which handles TM related to this execution step
770 * @param queue_id is the id of the queue which handles TM related to this execution step
747 *
771 *
748 */
772 */
749
773
750 int status;
774 int status;
751
775
752 status = LFR_SUCCESSFUL;
776 status = LFR_SUCCESSFUL;
753
777
754 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
778 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
755
779
756 return status;
780 return status;
757 }
781 }
758
782
759 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
783 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
760 {
784 {
761 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
785 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
762 *
786 *
763 * @param TC points to the TeleCommand packet that is being processed
787 * @param TC points to the TeleCommand packet that is being processed
764 * @param queue_id is the id of the queue which handles TM related to this execution step
788 * @param queue_id is the id of the queue which handles TM related to this execution step
765 *
789 *
766 */
790 */
767
791
768 int status;
792 int status;
769
793
770 status = LFR_SUCCESSFUL;
794 status = LFR_SUCCESSFUL;
771
795
772 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
796 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
773
797
774 return status;
798 return status;
775 }
799 }
776
800
777 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
801 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
778 {
802 {
779 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
803 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
780 *
804 *
781 * @param TC points to the TeleCommand packet that is being processed
805 * @param TC points to the TeleCommand packet that is being processed
782 * @param queue_id is the id of the queue which handles TM related to this execution step
806 * @param queue_id is the id of the queue which handles TM related to this execution step
783 *
807 *
784 */
808 */
785
809
786 int status;
810 int status;
787
811
788 status = LFR_SUCCESSFUL;
812 status = LFR_SUCCESSFUL;
789
813
790 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
814 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
791
815
792 return status;
816 return status;
793 }
817 }
794
818
795 //**********************
819 //**********************
796 // BURST MODE PARAMETERS
820 // BURST MODE PARAMETERS
797
821
798 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
822 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
799 {
823 {
800 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
824 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
801 *
825 *
802 * @param TC points to the TeleCommand packet that is being processed
826 * @param TC points to the TeleCommand packet that is being processed
803 * @param queue_id is the id of the queue which handles TM related to this execution step
827 * @param queue_id is the id of the queue which handles TM related to this execution step
804 *
828 *
805 */
829 */
806
830
807 int status;
831 int status;
808
832
809 status = LFR_SUCCESSFUL;
833 status = LFR_SUCCESSFUL;
810
834
811 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
835 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
812
836
813 return status;
837 return status;
814 }
838 }
815
839
816 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
840 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
817 {
841 {
818 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
842 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
819 *
843 *
820 * @param TC points to the TeleCommand packet that is being processed
844 * @param TC points to the TeleCommand packet that is being processed
821 * @param queue_id is the id of the queue which handles TM related to this execution step
845 * @param queue_id is the id of the queue which handles TM related to this execution step
822 *
846 *
823 */
847 */
824
848
825 int status;
849 int status;
826
850
827 status = LFR_SUCCESSFUL;
851 status = LFR_SUCCESSFUL;
828
852
829 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
853 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
830
854
831 return status;
855 return status;
832 }
856 }
833
857
834 //*********************
858 //*********************
835 // SBM1 MODE PARAMETERS
859 // SBM1 MODE PARAMETERS
836
860
837 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
861 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
838 {
862 {
839 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
863 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
840 *
864 *
841 * @param TC points to the TeleCommand packet that is being processed
865 * @param TC points to the TeleCommand packet that is being processed
842 * @param queue_id is the id of the queue which handles TM related to this execution step
866 * @param queue_id is the id of the queue which handles TM related to this execution step
843 *
867 *
844 */
868 */
845
869
846 int status;
870 int status;
847
871
848 status = LFR_SUCCESSFUL;
872 status = LFR_SUCCESSFUL;
849
873
850 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
874 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
851
875
852 return status;
876 return status;
853 }
877 }
854
878
855 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
879 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
856 {
880 {
857 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
881 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
858 *
882 *
859 * @param TC points to the TeleCommand packet that is being processed
883 * @param TC points to the TeleCommand packet that is being processed
860 * @param queue_id is the id of the queue which handles TM related to this execution step
884 * @param queue_id is the id of the queue which handles TM related to this execution step
861 *
885 *
862 */
886 */
863
887
864 int status;
888 int status;
865
889
866 status = LFR_SUCCESSFUL;
890 status = LFR_SUCCESSFUL;
867
891
868 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
892 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
869
893
870 return status;
894 return status;
871 }
895 }
872
896
873 //*********************
897 //*********************
874 // SBM2 MODE PARAMETERS
898 // SBM2 MODE PARAMETERS
875
899
876 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
900 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
877 {
901 {
878 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
902 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
879 *
903 *
880 * @param TC points to the TeleCommand packet that is being processed
904 * @param TC points to the TeleCommand packet that is being processed
881 * @param queue_id is the id of the queue which handles TM related to this execution step
905 * @param queue_id is the id of the queue which handles TM related to this execution step
882 *
906 *
883 */
907 */
884
908
885 int status;
909 int status;
886
910
887 status = LFR_SUCCESSFUL;
911 status = LFR_SUCCESSFUL;
888
912
889 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
913 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
890
914
891 return status;
915 return status;
892 }
916 }
893
917
894 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
918 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
895 {
919 {
896 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
920 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
897 *
921 *
898 * @param TC points to the TeleCommand packet that is being processed
922 * @param TC points to the TeleCommand packet that is being processed
899 * @param queue_id is the id of the queue which handles TM related to this execution step
923 * @param queue_id is the id of the queue which handles TM related to this execution step
900 *
924 *
901 */
925 */
902
926
903 int status;
927 int status;
904
928
905 status = LFR_SUCCESSFUL;
929 status = LFR_SUCCESSFUL;
906
930
907 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
931 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
908
932
909 return status;
933 return status;
910 }
934 }
911
935
912 //*******************
936 //*******************
913 // TC_LFR_UPDATE_INFO
937 // TC_LFR_UPDATE_INFO
914
938
915 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
939 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
916 {
940 {
917 unsigned int status;
941 unsigned int status;
918
942
919 status = LFR_DEFAULT;
943 status = LFR_DEFAULT;
920
944
921 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
945 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
922 || (mode == LFR_MODE_BURST)
946 || (mode == LFR_MODE_BURST)
923 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
947 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
924 {
948 {
925 status = LFR_SUCCESSFUL;
949 status = LFR_SUCCESSFUL;
926 }
950 }
927 else
951 else
928 {
952 {
929 status = LFR_DEFAULT;
953 status = LFR_DEFAULT;
930 }
954 }
931
955
932 return status;
956 return status;
933 }
957 }
934
958
935 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
959 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
936 {
960 {
937 unsigned int status;
961 unsigned int status;
938
962
939 status = LFR_DEFAULT;
963 status = LFR_DEFAULT;
940
964
941 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
965 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
942 || (mode == TDS_MODE_BURST)
966 || (mode == TDS_MODE_BURST)
943 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
967 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
944 || (mode == TDS_MODE_LFM))
968 || (mode == TDS_MODE_LFM))
945 {
969 {
946 status = LFR_SUCCESSFUL;
970 status = LFR_SUCCESSFUL;
947 }
971 }
948 else
972 else
949 {
973 {
950 status = LFR_DEFAULT;
974 status = LFR_DEFAULT;
951 }
975 }
952
976
953 return status;
977 return status;
954 }
978 }
955
979
956 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
980 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
957 {
981 {
958 unsigned int status;
982 unsigned int status;
959
983
960 status = LFR_DEFAULT;
984 status = LFR_DEFAULT;
961
985
962 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
986 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
963 || (mode == THR_MODE_BURST))
987 || (mode == THR_MODE_BURST))
964 {
988 {
965 status = LFR_SUCCESSFUL;
989 status = LFR_SUCCESSFUL;
966 }
990 }
967 else
991 else
968 {
992 {
969 status = LFR_DEFAULT;
993 status = LFR_DEFAULT;
970 }
994 }
971
995
972 return status;
996 return status;
973 }
997 }
974
998
975 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
999 void set_hk_lfr_sc_rw_f_flag( unsigned char wheel, unsigned char freq, float value )
976 {
1000 {
977 unsigned char flag;
1001 unsigned char flag;
978 unsigned char flagPosInByte;
1002 unsigned char flagPosInByte;
979 unsigned char newFlag;
1003 unsigned char newFlag;
980 unsigned char flagMask;
1004 unsigned char flagMask;
981
1005
982 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
1006 // if the frequency value is not a number, the flag is set to 0 and the frequency RWx_Fy is not filtered
983 if (isnan(value))
1007 if (isnan(value))
984 {
1008 {
985 flag = FLAG_NAN;
1009 flag = FLAG_NAN;
986 }
1010 }
987 else
1011 else
988 {
1012 {
989 flag = FLAG_IAN;
1013 flag = FLAG_IAN;
990 }
1014 }
991
1015
992 switch(wheel)
1016 switch(wheel)
993 {
1017 {
994 case WHEEL_1:
1018 case WHEEL_1:
995 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1019 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
996 flagMask = ~(1 << flagPosInByte);
1020 flagMask = ~(1 << flagPosInByte);
997 newFlag = flag << flagPosInByte;
1021 newFlag = flag << flagPosInByte;
998 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1022 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
999 break;
1023 break;
1000 case WHEEL_2:
1024 case WHEEL_2:
1001 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1025 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1002 flagMask = ~(1 << flagPosInByte);
1026 flagMask = ~(1 << flagPosInByte);
1003 newFlag = flag << flagPosInByte;
1027 newFlag = flag << flagPosInByte;
1004 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1028 housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags = (housekeeping_packet.hk_lfr_sc_rw1_rw2_f_flags & flagMask) | newFlag;
1005 break;
1029 break;
1006 case WHEEL_3:
1030 case WHEEL_3:
1007 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1031 flagPosInByte = FLAG_OFFSET_WHEELS_1_3 - freq;
1008 flagMask = ~(1 << flagPosInByte);
1032 flagMask = ~(1 << flagPosInByte);
1009 newFlag = flag << flagPosInByte;
1033 newFlag = flag << flagPosInByte;
1010 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1034 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1011 break;
1035 break;
1012 case WHEEL_4:
1036 case WHEEL_4:
1013 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1037 flagPosInByte = FLAG_OFFSET_WHEELS_2_4 - freq;
1014 flagMask = ~(1 << flagPosInByte);
1038 flagMask = ~(1 << flagPosInByte);
1015 newFlag = flag << flagPosInByte;
1039 newFlag = flag << flagPosInByte;
1016 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1040 housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags = (housekeeping_packet.hk_lfr_sc_rw3_rw4_f_flags & flagMask) | newFlag;
1017 break;
1041 break;
1018 default:
1042 default:
1019 break;
1043 break;
1020 }
1044 }
1021 }
1045 }
1022
1046
1023 void set_hk_lfr_sc_rw_f_flags( void )
1047 void set_hk_lfr_sc_rw_f_flags( void )
1024 {
1048 {
1025 // RW1
1049 // RW1
1026 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1050 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_1, rw_f.cp_rpw_sc_rw1_f1 );
1027 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1051 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_2, rw_f.cp_rpw_sc_rw1_f2 );
1028 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1052 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_3, rw_f.cp_rpw_sc_rw1_f3 );
1029 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1053 set_hk_lfr_sc_rw_f_flag( WHEEL_1, FREQ_4, rw_f.cp_rpw_sc_rw1_f4 );
1030
1054
1031 // RW2
1055 // RW2
1032 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1056 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_1, rw_f.cp_rpw_sc_rw2_f1 );
1033 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1057 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_2, rw_f.cp_rpw_sc_rw2_f2 );
1034 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1058 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_3, rw_f.cp_rpw_sc_rw2_f3 );
1035 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1059 set_hk_lfr_sc_rw_f_flag( WHEEL_2, FREQ_4, rw_f.cp_rpw_sc_rw2_f4 );
1036
1060
1037 // RW3
1061 // RW3
1038 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1062 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_1, rw_f.cp_rpw_sc_rw3_f1 );
1039 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1063 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_2, rw_f.cp_rpw_sc_rw3_f2 );
1040 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1064 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_3, rw_f.cp_rpw_sc_rw3_f3 );
1041 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1065 set_hk_lfr_sc_rw_f_flag( WHEEL_3, FREQ_4, rw_f.cp_rpw_sc_rw3_f4 );
1042
1066
1043 // RW4
1067 // RW4
1044 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1068 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_1, rw_f.cp_rpw_sc_rw4_f1 );
1045 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1069 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_2, rw_f.cp_rpw_sc_rw4_f2 );
1046 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1070 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_3, rw_f.cp_rpw_sc_rw4_f3 );
1047 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1071 set_hk_lfr_sc_rw_f_flag( WHEEL_4, FREQ_4, rw_f.cp_rpw_sc_rw4_f4 );
1048 }
1072 }
1049
1073
1050 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1074 int check_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1051 {
1075 {
1052 float rw_k;
1076 float rw_k;
1053 int ret;
1077 int ret;
1054
1078
1055 ret = LFR_SUCCESSFUL;
1079 ret = LFR_SUCCESSFUL;
1056 rw_k = INIT_FLOAT;
1080 rw_k = INIT_FLOAT;
1057
1081
1058 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->packetID[ offset ] );
1082 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->packetID[ offset ] );
1059
1083
1060 *pos = offset;
1084 *pos = offset;
1061 *value = rw_k;
1085 *value = rw_k;
1062
1086
1063 if (rw_k < MIN_SY_LFR_RW_F)
1087 if (rw_k < MIN_SY_LFR_RW_F)
1064 {
1088 {
1065 ret = WRONG_APP_DATA;
1089 ret = WRONG_APP_DATA;
1066 }
1090 }
1067
1091
1068 return ret;
1092 return ret;
1069 }
1093 }
1070
1094
1071 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value )
1095 int check_all_sy_lfr_rw_f( ccsdsTelecommandPacket_t *TC, int *pos, float*value )
1072 {
1096 {
1073 int ret;
1097 int ret;
1074
1098
1075 ret = LFR_SUCCESSFUL;
1099 ret = LFR_SUCCESSFUL;
1076
1100
1077 //****
1101 //****
1078 //****
1102 //****
1079 // RW1
1103 // RW1
1080 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1, pos, value ); // F1
1104 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1, pos, value ); // F1
1081 if (ret == LFR_SUCCESSFUL) // F2
1105 if (ret == LFR_SUCCESSFUL) // F2
1082 {
1106 {
1083 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2, pos, value );
1107 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2, pos, value );
1084 }
1108 }
1085 if (ret == LFR_SUCCESSFUL) // F3
1109 if (ret == LFR_SUCCESSFUL) // F3
1086 {
1110 {
1087 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3, pos, value );
1111 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3, pos, value );
1088 }
1112 }
1089 if (ret == LFR_SUCCESSFUL) // F4
1113 if (ret == LFR_SUCCESSFUL) // F4
1090 {
1114 {
1091 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4, pos, value );
1115 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4, pos, value );
1092 }
1116 }
1093
1117
1094 //****
1118 //****
1095 //****
1119 //****
1096 // RW2
1120 // RW2
1097 if (ret == LFR_SUCCESSFUL) // F1
1121 if (ret == LFR_SUCCESSFUL) // F1
1098 {
1122 {
1099 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1, pos, value );
1123 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1, pos, value );
1100 }
1124 }
1101 if (ret == LFR_SUCCESSFUL) // F2
1125 if (ret == LFR_SUCCESSFUL) // F2
1102 {
1126 {
1103 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2, pos, value );
1127 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2, pos, value );
1104 }
1128 }
1105 if (ret == LFR_SUCCESSFUL) // F3
1129 if (ret == LFR_SUCCESSFUL) // F3
1106 {
1130 {
1107 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3, pos, value );
1131 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3, pos, value );
1108 }
1132 }
1109 if (ret == LFR_SUCCESSFUL) // F4
1133 if (ret == LFR_SUCCESSFUL) // F4
1110 {
1134 {
1111 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4, pos, value );
1135 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4, pos, value );
1112 }
1136 }
1113
1137
1114 //****
1138 //****
1115 //****
1139 //****
1116 // RW3
1140 // RW3
1117 if (ret == LFR_SUCCESSFUL) // F1
1141 if (ret == LFR_SUCCESSFUL) // F1
1118 {
1142 {
1119 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1, pos, value );
1143 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1, pos, value );
1120 }
1144 }
1121 if (ret == LFR_SUCCESSFUL) // F2
1145 if (ret == LFR_SUCCESSFUL) // F2
1122 {
1146 {
1123 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2, pos, value );
1147 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2, pos, value );
1124 }
1148 }
1125 if (ret == LFR_SUCCESSFUL) // F3
1149 if (ret == LFR_SUCCESSFUL) // F3
1126 {
1150 {
1127 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3, pos, value );
1151 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3, pos, value );
1128 }
1152 }
1129 if (ret == LFR_SUCCESSFUL) // F4
1153 if (ret == LFR_SUCCESSFUL) // F4
1130 {
1154 {
1131 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4, pos, value );
1155 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4, pos, value );
1132 }
1156 }
1133
1157
1134 //****
1158 //****
1135 //****
1159 //****
1136 // RW4
1160 // RW4
1137 if (ret == LFR_SUCCESSFUL) // F1
1161 if (ret == LFR_SUCCESSFUL) // F1
1138 {
1162 {
1139 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1, pos, value );
1163 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1, pos, value );
1140 }
1164 }
1141 if (ret == LFR_SUCCESSFUL) // F2
1165 if (ret == LFR_SUCCESSFUL) // F2
1142 {
1166 {
1143 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2, pos, value );
1167 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2, pos, value );
1144 }
1168 }
1145 if (ret == LFR_SUCCESSFUL) // F3
1169 if (ret == LFR_SUCCESSFUL) // F3
1146 {
1170 {
1147 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3, pos, value );
1171 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3, pos, value );
1148 }
1172 }
1149 if (ret == LFR_SUCCESSFUL) // F4
1173 if (ret == LFR_SUCCESSFUL) // F4
1150 {
1174 {
1151 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4, pos, value );
1175 ret = check_sy_lfr_rw_f( TC, BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4, pos, value );
1152 }
1176 }
1153
1177
1154 return ret;
1178 return ret;
1155 }
1179 }
1156
1180
1157 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1181 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
1158 {
1182 {
1159 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1183 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
1160 *
1184 *
1161 * @param TC points to the TeleCommand packet that is being processed
1185 * @param TC points to the TeleCommand packet that is being processed
1162 *
1186 *
1163 */
1187 */
1164
1188
1165 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1189 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
1166
1190
1167 bytePosPtr = (unsigned char *) &TC->packetID;
1191 bytePosPtr = (unsigned char *) &TC->packetID;
1168
1192
1169 // rw1_f
1193 // rw1_f
1170 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1194 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
1171 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1195 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
1172 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1196 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F3 ] );
1173 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1197 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw1_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F4 ] );
1174
1198
1175 // rw2_f
1199 // rw2_f
1176 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1200 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
1177 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1201 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
1178 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1202 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F3 ] );
1179 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1203 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw2_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F4 ] );
1180
1204
1181 // rw3_f
1205 // rw3_f
1182 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1206 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
1183 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1207 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
1184 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1208 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F3 ] );
1185 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1209 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw3_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F4 ] );
1186
1210
1187 // rw4_f
1211 // rw4_f
1188 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1212 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f1, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
1189 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1213 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f2, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
1190 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1214 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f3, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F3 ] );
1191 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1215 copyFloatByChar( (unsigned char*) &rw_f.cp_rpw_sc_rw4_f4, (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F4 ] );
1192
1216
1193 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1217 // test each reaction wheel frequency value. NaN means that the frequency is not filtered
1194
1218
1195 }
1219 }
1196
1220
1197 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k )
1221 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, float sy_lfr_rw_k )
1198 {
1222 {
1199 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1223 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
1200 *
1224 *
1201 * @param fbins_mask
1225 * @param fbins_mask
1202 * @param rw_f is the reaction wheel frequency to filter
1226 * @param rw_f is the reaction wheel frequency to filter
1203 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1227 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
1204 * @param flag [true] filtering enabled [false] filtering disabled
1228 * @param flag [true] filtering enabled [false] filtering disabled
1205 *
1229 *
1206 * @return void
1230 * @return void
1207 *
1231 *
1208 */
1232 */
1209
1233
1210 float f_RW_min;
1234 float f_RW_min;
1211 float f_RW_MAX;
1235 float f_RW_MAX;
1212 float fi_min;
1236 float fi_min;
1213 float fi_MAX;
1237 float fi_MAX;
1214 float fi;
1238 float fi;
1215 float deltaBelow;
1239 float deltaBelow;
1216 float deltaAbove;
1240 float deltaAbove;
1217 float freqToFilterOut;
1241 float freqToFilterOut;
1218 int binBelow;
1242 int binBelow;
1219 int binAbove;
1243 int binAbove;
1220 int closestBin;
1244 int closestBin;
1221 unsigned int whichByte;
1245 unsigned int whichByte;
1222 int selectedByte;
1246 int selectedByte;
1223 int bin;
1247 int bin;
1224 int binToRemove[NB_BINS_TO_REMOVE];
1248 int binToRemove[NB_BINS_TO_REMOVE];
1225 int k;
1249 int k;
1226 bool filteringSet;
1250 bool filteringSet;
1227
1251
1228 closestBin = 0;
1252 closestBin = 0;
1229 whichByte = 0;
1253 whichByte = 0;
1230 bin = 0;
1254 bin = 0;
1231 filteringSet = false;
1255 filteringSet = false;
1232
1256
1233 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1257 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1234 {
1258 {
1235 binToRemove[k] = -1;
1259 binToRemove[k] = -1;
1236 }
1260 }
1237
1261
1238 if (!isnan(rw_f))
1262 if (!isnan(rw_f))
1239 {
1263 {
1240 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1264 // compute the frequency range to filter [ rw_f - delta_f; rw_f + delta_f ]
1241 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1265 f_RW_min = rw_f - ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1242 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1266 f_RW_MAX = rw_f + ((filterPar.sy_lfr_sc_rw_delta_f) * sy_lfr_rw_k);
1243
1267
1244 freqToFilterOut = f_RW_min;
1268 freqToFilterOut = f_RW_min;
1245 while ( filteringSet == false )
1269 while ( filteringSet == false )
1246 {
1270 {
1247 // compute the index of the frequency bin immediately below rw_f
1271 // compute the index of the frequency bin immediately below rw_f
1248 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1272 binBelow = (int) ( floor( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1249 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1273 deltaBelow = freqToFilterOut - binBelow * deltaFreq;
1250
1274
1251 // compute the index of the frequency bin immediately above rw_f
1275 // compute the index of the frequency bin immediately above rw_f
1252 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1276 binAbove = (int) ( ceil( ((double) freqToFilterOut) / ((double) deltaFreq)) );
1253 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1277 deltaAbove = binAbove * deltaFreq - freqToFilterOut;
1254
1278
1255 // search the closest bin
1279 // search the closest bin
1256 if (deltaAbove > deltaBelow)
1280 if (deltaAbove > deltaBelow)
1257 {
1281 {
1258 closestBin = binBelow;
1282 closestBin = binBelow;
1259 }
1283 }
1260 else
1284 else
1261 {
1285 {
1262 closestBin = binAbove;
1286 closestBin = binAbove;
1263 }
1287 }
1264
1288
1265 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1289 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1266 fi = closestBin * deltaFreq;
1290 fi = closestBin * deltaFreq;
1267 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1291 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1268 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1292 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1269
1293
1270 //**************************************************************************************
1294 //**************************************************************************************
1271 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1295 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1272 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1296 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1273 //**************************************************************************************
1297 //**************************************************************************************
1274
1298
1275 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1299 // 1. IF freqToFilterOut is included in [ fi_min; fi_MAX ]
1276 // => remove f_(i), f_(i-1) and f_(i+1)
1300 // => remove f_(i), f_(i-1) and f_(i+1)
1277 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1301 if ( ( freqToFilterOut > fi_min ) && ( freqToFilterOut < fi_MAX ) )
1278 {
1302 {
1279 binToRemove[0] = (closestBin - 1) - 1;
1303 binToRemove[0] = (closestBin - 1) - 1;
1280 binToRemove[1] = (closestBin) - 1;
1304 binToRemove[1] = (closestBin) - 1;
1281 binToRemove[2] = (closestBin + 1) - 1;
1305 binToRemove[2] = (closestBin + 1) - 1;
1282 }
1306 }
1283 // 2. ELSE
1307 // 2. ELSE
1284 // => remove the two f_(i) which are around f_RW
1308 // => remove the two f_(i) which are around f_RW
1285 else
1309 else
1286 {
1310 {
1287 binToRemove[0] = (binBelow) - 1;
1311 binToRemove[0] = (binBelow) - 1;
1288 binToRemove[1] = (binAbove) - 1;
1312 binToRemove[1] = (binAbove) - 1;
1289 binToRemove[2] = (-1);
1313 binToRemove[2] = (-1);
1290 }
1314 }
1291
1315
1292 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1316 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1293 {
1317 {
1294 bin = binToRemove[k];
1318 bin = binToRemove[k];
1295 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1319 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1296 {
1320 {
1297 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1321 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1298 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1322 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1299 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1323 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1300 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1324 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1301
1325
1302 }
1326 }
1303 }
1327 }
1304
1328
1305 // update freqToFilterOut
1329 // update freqToFilterOut
1306 if ( freqToFilterOut == f_RW_MAX )
1330 if ( freqToFilterOut == f_RW_MAX )
1307 {
1331 {
1308 filteringSet = true; // end of the loop
1332 filteringSet = true; // end of the loop
1309 }
1333 }
1310 else
1334 else
1311 {
1335 {
1312 freqToFilterOut = freqToFilterOut + deltaFreq;
1336 freqToFilterOut = freqToFilterOut + deltaFreq;
1313 }
1337 }
1314
1338
1315 if ( freqToFilterOut > f_RW_MAX)
1339 if ( freqToFilterOut > f_RW_MAX)
1316 {
1340 {
1317 freqToFilterOut = f_RW_MAX;
1341 freqToFilterOut = f_RW_MAX;
1318 }
1342 }
1319 }
1343 }
1320 }
1344 }
1321 }
1345 }
1322
1346
1323 void build_sy_lfr_rw_mask( unsigned int channel )
1347 void build_sy_lfr_rw_mask( unsigned int channel )
1324 {
1348 {
1325 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1349 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1326 unsigned char *maskPtr;
1350 unsigned char *maskPtr;
1327 double deltaF;
1351 double deltaF;
1328 unsigned k;
1352 unsigned k;
1329
1353
1330 maskPtr = NULL;
1354 maskPtr = NULL;
1331 deltaF = DELTAF_F2;
1355 deltaF = DELTAF_F2;
1332
1356
1333 switch (channel)
1357 switch (channel)
1334 {
1358 {
1335 case CHANNELF0:
1359 case CHANNELF0:
1336 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1360 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1337 deltaF = DELTAF_F0;
1361 deltaF = DELTAF_F0;
1338 break;
1362 break;
1339 case CHANNELF1:
1363 case CHANNELF1:
1340 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1364 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1341 deltaF = DELTAF_F1;
1365 deltaF = DELTAF_F1;
1342 break;
1366 break;
1343 case CHANNELF2:
1367 case CHANNELF2:
1344 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1368 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1345 deltaF = DELTAF_F2;
1369 deltaF = DELTAF_F2;
1346 break;
1370 break;
1347 default:
1371 default:
1348 break;
1372 break;
1349 }
1373 }
1350
1374
1351 for (k = 0; k < BYTES_PER_MASK; k++)
1375 for (k = 0; k < BYTES_PER_MASK; k++)
1352 {
1376 {
1353 local_rw_fbins_mask[k] = INT8_ALL_F;
1377 local_rw_fbins_mask[k] = INT8_ALL_F;
1354 }
1378 }
1355
1379
1356 // RW1
1380 // RW1
1357 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1381 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f1, deltaF, filterPar.sy_lfr_rw1_k1 );
1358 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1382 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f2, deltaF, filterPar.sy_lfr_rw1_k2 );
1359 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1383 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f3, deltaF, filterPar.sy_lfr_rw1_k3 );
1360 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1384 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw1_f4, deltaF, filterPar.sy_lfr_rw1_k4 );
1361
1385
1362 // RW2
1386 // RW2
1363 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1387 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f1, deltaF, filterPar.sy_lfr_rw2_k1 );
1364 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1388 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f2, deltaF, filterPar.sy_lfr_rw2_k2 );
1365 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1389 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f3, deltaF, filterPar.sy_lfr_rw2_k3 );
1366 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1390 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw2_f4, deltaF, filterPar.sy_lfr_rw2_k4 );
1367
1391
1368 // RW3
1392 // RW3
1369 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1393 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f1, deltaF, filterPar.sy_lfr_rw3_k1 );
1370 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1394 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f2, deltaF, filterPar.sy_lfr_rw3_k2 );
1371 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1395 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f3, deltaF, filterPar.sy_lfr_rw3_k3 );
1372 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1396 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw3_f4, deltaF, filterPar.sy_lfr_rw3_k4 );
1373
1397
1374 // RW4
1398 // RW4
1375 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1399 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f1, deltaF, filterPar.sy_lfr_rw4_k1 );
1376 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1400 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f2, deltaF, filterPar.sy_lfr_rw4_k2 );
1377 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1401 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f3, deltaF, filterPar.sy_lfr_rw4_k3 );
1378 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1402 setFBinMask( local_rw_fbins_mask, rw_f.cp_rpw_sc_rw4_f4, deltaF, filterPar.sy_lfr_rw4_k4 );
1379
1403
1380 // update the value of the fbins related to reaction wheels frequency filtering
1404 // update the value of the fbins related to reaction wheels frequency filtering
1381 if (maskPtr != NULL)
1405 if (maskPtr != NULL)
1382 {
1406 {
1383 for (k = 0; k < BYTES_PER_MASK; k++)
1407 for (k = 0; k < BYTES_PER_MASK; k++)
1384 {
1408 {
1385 maskPtr[k] = local_rw_fbins_mask[k];
1409 maskPtr[k] = local_rw_fbins_mask[k];
1386 }
1410 }
1387 }
1411 }
1388 }
1412 }
1389
1413
1390 void build_sy_lfr_rw_masks( void )
1414 void build_sy_lfr_rw_masks( void )
1391 {
1415 {
1392 build_sy_lfr_rw_mask( CHANNELF0 );
1416 build_sy_lfr_rw_mask( CHANNELF0 );
1393 build_sy_lfr_rw_mask( CHANNELF1 );
1417 build_sy_lfr_rw_mask( CHANNELF1 );
1394 build_sy_lfr_rw_mask( CHANNELF2 );
1418 build_sy_lfr_rw_mask( CHANNELF2 );
1395 }
1419 }
1396
1420
1397 void merge_fbins_masks( void )
1421 void merge_fbins_masks( void )
1398 {
1422 {
1399 unsigned char k;
1423 unsigned char k;
1400
1424
1401 unsigned char *fbins_f0;
1425 unsigned char *fbins_f0;
1402 unsigned char *fbins_f1;
1426 unsigned char *fbins_f1;
1403 unsigned char *fbins_f2;
1427 unsigned char *fbins_f2;
1404 unsigned char *rw_mask_f0;
1428 unsigned char *rw_mask_f0;
1405 unsigned char *rw_mask_f1;
1429 unsigned char *rw_mask_f1;
1406 unsigned char *rw_mask_f2;
1430 unsigned char *rw_mask_f2;
1407
1431
1408 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1432 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1409 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1433 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1410 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1434 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1411 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1435 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1412 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1436 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1413 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1437 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1414
1438
1415 for( k=0; k < BYTES_PER_MASK; k++ )
1439 for( k=0; k < BYTES_PER_MASK; k++ )
1416 {
1440 {
1417 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1441 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1418 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1442 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1419 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1443 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1420 }
1444 }
1421 }
1445 }
1422
1446
1423 //***********
1447 //***********
1424 // FBINS MASK
1448 // FBINS MASK
1425
1449
1426 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1450 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1427 {
1451 {
1428 int status;
1452 int status;
1429 unsigned int k;
1453 unsigned int k;
1430 unsigned char *fbins_mask_dump;
1454 unsigned char *fbins_mask_dump;
1431 unsigned char *fbins_mask_TC;
1455 unsigned char *fbins_mask_TC;
1432
1456
1433 status = LFR_SUCCESSFUL;
1457 status = LFR_SUCCESSFUL;
1434
1458
1435 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1459 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1436 fbins_mask_TC = TC->dataAndCRC;
1460 fbins_mask_TC = TC->dataAndCRC;
1437
1461
1438 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1462 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1439 {
1463 {
1440 fbins_mask_dump[k] = fbins_mask_TC[k];
1464 fbins_mask_dump[k] = fbins_mask_TC[k];
1441 }
1465 }
1442
1466
1443 return status;
1467 return status;
1444 }
1468 }
1445
1469
1446 //***************************
1470 //***************************
1447 // TC_LFR_LOAD_PAS_FILTER_PAR
1471 // TC_LFR_LOAD_PAS_FILTER_PAR
1448
1472
1449 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1473 int check_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int offset, int* pos, float* value )
1450 {
1474 {
1451 float rw_k;
1475 float rw_k;
1452 int ret;
1476 int ret;
1453
1477
1454 ret = LFR_SUCCESSFUL;
1478 ret = LFR_SUCCESSFUL;
1455 rw_k = INIT_FLOAT;
1479 rw_k = INIT_FLOAT;
1456
1480
1457 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->dataAndCRC[ offset ] );
1481 copyFloatByChar( (unsigned char*) &rw_k, (unsigned char*) &TC->dataAndCRC[ offset ] );
1458
1482
1459 *pos = offset;
1483 *pos = offset;
1460 *value = rw_k;
1484 *value = rw_k;
1461
1485
1462 if (rw_k < MIN_SY_LFR_RW_F)
1486 if (rw_k < MIN_SY_LFR_RW_F)
1463 {
1487 {
1464 ret = WRONG_APP_DATA;
1488 ret = WRONG_APP_DATA;
1465 }
1489 }
1466
1490
1467 return ret;
1491 return ret;
1468 }
1492 }
1469
1493
1470 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float *value )
1494 int check_all_sy_lfr_rw_k( ccsdsTelecommandPacket_t *TC, int *pos, float *value )
1471 {
1495 {
1472 int ret;
1496 int ret;
1473
1497
1474 ret = LFR_SUCCESSFUL;
1498 ret = LFR_SUCCESSFUL;
1475
1499
1476 //****
1500 //****
1477 //****
1501 //****
1478 // RW1
1502 // RW1
1479 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K1, pos, value ); // K1
1503 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K1, pos, value ); // K1
1480 if (ret == LFR_SUCCESSFUL) // K2
1504 if (ret == LFR_SUCCESSFUL) // K2
1481 {
1505 {
1482 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K2, pos, value );
1506 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K2, pos, value );
1483 }
1507 }
1484 if (ret == LFR_SUCCESSFUL) // K3
1508 if (ret == LFR_SUCCESSFUL) // K3
1485 {
1509 {
1486 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K3, pos, value );
1510 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K3, pos, value );
1487 }
1511 }
1488 if (ret == LFR_SUCCESSFUL) // K4
1512 if (ret == LFR_SUCCESSFUL) // K4
1489 {
1513 {
1490 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K4, pos, value );
1514 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW1_K4, pos, value );
1491 }
1515 }
1492
1516
1493 //****
1517 //****
1494 //****
1518 //****
1495 // RW2
1519 // RW2
1496 if (ret == LFR_SUCCESSFUL) // K1
1520 if (ret == LFR_SUCCESSFUL) // K1
1497 {
1521 {
1498 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K1, pos, value );
1522 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K1, pos, value );
1499 }
1523 }
1500 if (ret == LFR_SUCCESSFUL) // K2
1524 if (ret == LFR_SUCCESSFUL) // K2
1501 {
1525 {
1502 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K2, pos, value );
1526 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K2, pos, value );
1503 }
1527 }
1504 if (ret == LFR_SUCCESSFUL) // K3
1528 if (ret == LFR_SUCCESSFUL) // K3
1505 {
1529 {
1506 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K3, pos, value );
1530 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K3, pos, value );
1507 }
1531 }
1508 if (ret == LFR_SUCCESSFUL) // K4
1532 if (ret == LFR_SUCCESSFUL) // K4
1509 {
1533 {
1510 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K4, pos, value );
1534 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW2_K4, pos, value );
1511 }
1535 }
1512
1536
1513 //****
1537 //****
1514 //****
1538 //****
1515 // RW3
1539 // RW3
1516 if (ret == LFR_SUCCESSFUL) // K1
1540 if (ret == LFR_SUCCESSFUL) // K1
1517 {
1541 {
1518 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K1, pos, value );
1542 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K1, pos, value );
1519 }
1543 }
1520 if (ret == LFR_SUCCESSFUL) // K2
1544 if (ret == LFR_SUCCESSFUL) // K2
1521 {
1545 {
1522 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K2, pos, value );
1546 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K2, pos, value );
1523 }
1547 }
1524 if (ret == LFR_SUCCESSFUL) // K3
1548 if (ret == LFR_SUCCESSFUL) // K3
1525 {
1549 {
1526 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K3, pos, value );
1550 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K3, pos, value );
1527 }
1551 }
1528 if (ret == LFR_SUCCESSFUL) // K4
1552 if (ret == LFR_SUCCESSFUL) // K4
1529 {
1553 {
1530 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K4, pos, value );
1554 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW3_K4, pos, value );
1531 }
1555 }
1532
1556
1533 //****
1557 //****
1534 //****
1558 //****
1535 // RW4
1559 // RW4
1536 if (ret == LFR_SUCCESSFUL) // K1
1560 if (ret == LFR_SUCCESSFUL) // K1
1537 {
1561 {
1538 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K1, pos, value );
1562 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K1, pos, value );
1539 }
1563 }
1540 if (ret == LFR_SUCCESSFUL) // K2
1564 if (ret == LFR_SUCCESSFUL) // K2
1541 {
1565 {
1542 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K2, pos, value );
1566 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K2, pos, value );
1543 }
1567 }
1544 if (ret == LFR_SUCCESSFUL) // K3
1568 if (ret == LFR_SUCCESSFUL) // K3
1545 {
1569 {
1546 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K3, pos, value );
1570 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K3, pos, value );
1547 }
1571 }
1548 if (ret == LFR_SUCCESSFUL) // K4
1572 if (ret == LFR_SUCCESSFUL) // K4
1549 {
1573 {
1550 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K4, pos, value );
1574 ret = check_sy_lfr_rw_k( TC, DATAFIELD_POS_SY_LFR_RW4_K4, pos, value );
1551 }
1575 }
1552
1576
1553 return ret;
1577 return ret;
1554 }
1578 }
1555
1579
1556 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1580 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1557 {
1581 {
1558 int flag;
1582 int flag;
1559 rtems_status_code status;
1583 rtems_status_code status;
1560
1584
1561 unsigned char sy_lfr_pas_filter_enabled;
1585 unsigned char sy_lfr_pas_filter_enabled;
1562 unsigned char sy_lfr_pas_filter_modulus;
1586 unsigned char sy_lfr_pas_filter_modulus;
1563 float sy_lfr_pas_filter_tbad;
1587 float sy_lfr_pas_filter_tbad;
1564 unsigned char sy_lfr_pas_filter_offset;
1588 unsigned char sy_lfr_pas_filter_offset;
1565 float sy_lfr_pas_filter_shift;
1589 float sy_lfr_pas_filter_shift;
1566 float sy_lfr_sc_rw_delta_f;
1590 float sy_lfr_sc_rw_delta_f;
1567 char *parPtr;
1591 char *parPtr;
1568 int datafield_pos;
1592 int datafield_pos;
1569 float rw_k;
1593 float rw_k;
1570
1594
1571 flag = LFR_SUCCESSFUL;
1595 flag = LFR_SUCCESSFUL;
1572 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1596 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1573 sy_lfr_pas_filter_shift = INIT_FLOAT;
1597 sy_lfr_pas_filter_shift = INIT_FLOAT;
1574 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1598 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1575 parPtr = NULL;
1599 parPtr = NULL;
1576 datafield_pos = INIT_INT;
1600 datafield_pos = INIT_INT;
1577 rw_k = INIT_FLOAT;
1601 rw_k = INIT_FLOAT;
1578
1602
1579 //***************
1603 //***************
1580 // get parameters
1604 // get parameters
1581 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1605 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1582 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1606 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1583 copyFloatByChar(
1607 copyFloatByChar(
1584 (unsigned char*) &sy_lfr_pas_filter_tbad,
1608 (unsigned char*) &sy_lfr_pas_filter_tbad,
1585 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1609 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1586 );
1610 );
1587 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1611 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1588 copyFloatByChar(
1612 copyFloatByChar(
1589 (unsigned char*) &sy_lfr_pas_filter_shift,
1613 (unsigned char*) &sy_lfr_pas_filter_shift,
1590 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1614 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1591 );
1615 );
1592 copyFloatByChar(
1616 copyFloatByChar(
1593 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1617 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1594 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1618 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1595 );
1619 );
1596
1620
1597 //******************
1621 //******************
1598 // CHECK CONSISTENCY
1622 // CHECK CONSISTENCY
1599
1623
1600 //**************************
1624 //**************************
1601 // sy_lfr_pas_filter_enabled
1625 // sy_lfr_pas_filter_enabled
1602 // nothing to check, value is 0 or 1
1626 // nothing to check, value is 0 or 1
1603
1627
1604 //**************************
1628 //**************************
1605 // sy_lfr_pas_filter_modulus
1629 // sy_lfr_pas_filter_modulus
1606 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1630 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1607 {
1631 {
1608 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1632 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1609 flag = WRONG_APP_DATA;
1633 flag = WRONG_APP_DATA;
1610 }
1634 }
1611
1635
1612 //***********************
1636 //***********************
1613 // sy_lfr_pas_filter_tbad
1637 // sy_lfr_pas_filter_tbad
1614 if (flag == LFR_SUCCESSFUL)
1638 if (flag == LFR_SUCCESSFUL)
1615 {
1639 {
1616 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1640 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1617 {
1641 {
1618 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1642 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1619 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1643 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1620 flag = WRONG_APP_DATA;
1644 flag = WRONG_APP_DATA;
1621 }
1645 }
1622 }
1646 }
1623
1647
1624 //*************************
1648 //*************************
1625 // sy_lfr_pas_filter_offset
1649 // sy_lfr_pas_filter_offset
1626 if (flag == LFR_SUCCESSFUL)
1650 if (flag == LFR_SUCCESSFUL)
1627 {
1651 {
1628 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1652 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1629 {
1653 {
1630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1654 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1631 flag = WRONG_APP_DATA;
1655 flag = WRONG_APP_DATA;
1632 }
1656 }
1633 }
1657 }
1634
1658
1635 //************************
1659 //************************
1636 // sy_lfr_pas_filter_shift
1660 // sy_lfr_pas_filter_shift
1637 if (flag == LFR_SUCCESSFUL)
1661 if (flag == LFR_SUCCESSFUL)
1638 {
1662 {
1639 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1663 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1640 {
1664 {
1641 parPtr = (char*) &sy_lfr_pas_filter_shift;
1665 parPtr = (char*) &sy_lfr_pas_filter_shift;
1642 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1666 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1643 flag = WRONG_APP_DATA;
1667 flag = WRONG_APP_DATA;
1644 }
1668 }
1645 }
1669 }
1646
1670
1647 //*************************************
1671 //*************************************
1648 // check global coherency of the values
1672 // check global coherency of the values
1649 if (flag == LFR_SUCCESSFUL)
1673 if (flag == LFR_SUCCESSFUL)
1650 {
1674 {
1651 if ( (sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) >= sy_lfr_pas_filter_modulus )
1675 if ( (sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) >= sy_lfr_pas_filter_modulus )
1652 {
1676 {
1653 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1677 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1654 flag = WRONG_APP_DATA;
1678 flag = WRONG_APP_DATA;
1655 }
1679 }
1656 }
1680 }
1657
1681
1658 //*********************
1682 //*********************
1659 // sy_lfr_sc_rw_delta_f
1683 // sy_lfr_sc_rw_delta_f
1660 if (flag == LFR_SUCCESSFUL)
1684 if (flag == LFR_SUCCESSFUL)
1661 {
1685 {
1662 if ( sy_lfr_sc_rw_delta_f < MIN_SY_LFR_SC_RW_DELTA_F )
1686 if ( sy_lfr_sc_rw_delta_f < MIN_SY_LFR_SC_RW_DELTA_F )
1663 {
1687 {
1664 parPtr = (char*) &sy_lfr_sc_rw_delta_f;
1688 parPtr = (char*) &sy_lfr_sc_rw_delta_f;
1665 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1689 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1666 flag = WRONG_APP_DATA;
1690 flag = WRONG_APP_DATA;
1667 }
1691 }
1668 }
1692 }
1669
1693
1670 //************
1694 //************
1671 // sy_lfr_rw_k
1695 // sy_lfr_rw_k
1672 if (flag == LFR_SUCCESSFUL)
1696 if (flag == LFR_SUCCESSFUL)
1673 {
1697 {
1674 flag = check_all_sy_lfr_rw_k( TC, &datafield_pos, &rw_k );
1698 flag = check_all_sy_lfr_rw_k( TC, &datafield_pos, &rw_k );
1675 if (flag != LFR_SUCCESSFUL)
1699 if (flag != LFR_SUCCESSFUL)
1676 {
1700 {
1677 parPtr = (char*) &sy_lfr_pas_filter_shift;
1701 parPtr = (char*) &sy_lfr_pas_filter_shift;
1678 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, datafield_pos + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1702 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, datafield_pos + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1679 }
1703 }
1680 }
1704 }
1681
1705
1682 return flag;
1706 return flag;
1683 }
1707 }
1684
1708
1685 //**************
1709 //**************
1686 // KCOEFFICIENTS
1710 // KCOEFFICIENTS
1687 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1711 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1688 {
1712 {
1689 unsigned int kcoeff;
1713 unsigned int kcoeff;
1690 unsigned short sy_lfr_kcoeff_frequency;
1714 unsigned short sy_lfr_kcoeff_frequency;
1691 unsigned short bin;
1715 unsigned short bin;
1692 float *kcoeffPtr_norm;
1716 float *kcoeffPtr_norm;
1693 float *kcoeffPtr_sbm;
1717 float *kcoeffPtr_sbm;
1694 int status;
1718 int status;
1695 unsigned char *kcoeffLoadPtr;
1719 unsigned char *kcoeffLoadPtr;
1696 unsigned char *kcoeffNormPtr;
1720 unsigned char *kcoeffNormPtr;
1697 unsigned char *kcoeffSbmPtr_a;
1721 unsigned char *kcoeffSbmPtr_a;
1698 unsigned char *kcoeffSbmPtr_b;
1722 unsigned char *kcoeffSbmPtr_b;
1699
1723
1700 sy_lfr_kcoeff_frequency = 0;
1724 sy_lfr_kcoeff_frequency = 0;
1701 bin = 0;
1725 bin = 0;
1702 kcoeffPtr_norm = NULL;
1726 kcoeffPtr_norm = NULL;
1703 kcoeffPtr_sbm = NULL;
1727 kcoeffPtr_sbm = NULL;
1704 status = LFR_SUCCESSFUL;
1728 status = LFR_SUCCESSFUL;
1705
1729
1706 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1730 // copy the value of the frequency byte by byte DO NOT USE A SHORT* POINTER
1707 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1731 copyInt16ByChar( (unsigned char*) &sy_lfr_kcoeff_frequency, &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY] );
1708
1732
1709
1733
1710 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1734 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1711 {
1735 {
1712 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1736 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1713 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET,
1737 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET,
1714 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1738 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1715 status = LFR_DEFAULT;
1739 status = LFR_DEFAULT;
1716 }
1740 }
1717 else
1741 else
1718 {
1742 {
1719 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1743 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1720 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1744 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1721 {
1745 {
1722 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1746 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1723 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1747 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1724 bin = sy_lfr_kcoeff_frequency;
1748 bin = sy_lfr_kcoeff_frequency;
1725 }
1749 }
1726 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1750 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1727 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1751 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1728 {
1752 {
1729 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1753 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1730 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1754 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1731 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1755 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1732 }
1756 }
1733 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1757 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1734 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1758 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1735 {
1759 {
1736 kcoeffPtr_norm = k_coeff_intercalib_f2;
1760 kcoeffPtr_norm = k_coeff_intercalib_f2;
1737 kcoeffPtr_sbm = NULL;
1761 kcoeffPtr_sbm = NULL;
1738 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1762 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1739 }
1763 }
1740 }
1764 }
1741
1765
1742 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1766 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1743 {
1767 {
1744 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1768 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1745 {
1769 {
1746 // destination
1770 // destination
1747 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1771 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1748 // source
1772 // source
1749 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1773 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1750 // copy source to destination
1774 // copy source to destination
1751 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1775 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1752 }
1776 }
1753 }
1777 }
1754
1778
1755 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1779 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1756 {
1780 {
1757 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1781 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1758 {
1782 {
1759 // destination
1783 // destination
1760 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1784 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1761 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1785 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1762 // source
1786 // source
1763 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1787 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1764 // copy source to destination
1788 // copy source to destination
1765 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1789 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1766 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1790 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1767 }
1791 }
1768 }
1792 }
1769
1793
1770 // print_k_coeff();
1794 // print_k_coeff();
1771
1795
1772 return status;
1796 return status;
1773 }
1797 }
1774
1798
1775 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1799 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1776 {
1800 {
1777 destination[BYTE_0] = source[BYTE_0];
1801 destination[BYTE_0] = source[BYTE_0];
1778 destination[BYTE_1] = source[BYTE_1];
1802 destination[BYTE_1] = source[BYTE_1];
1779 destination[BYTE_2] = source[BYTE_2];
1803 destination[BYTE_2] = source[BYTE_2];
1780 destination[BYTE_3] = source[BYTE_3];
1804 destination[BYTE_3] = source[BYTE_3];
1781 }
1805 }
1782
1806
1783 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1807 void copyInt32ByChar( unsigned char *destination, unsigned char *source )
1784 {
1808 {
1785 destination[BYTE_0] = source[BYTE_0];
1809 destination[BYTE_0] = source[BYTE_0];
1786 destination[BYTE_1] = source[BYTE_1];
1810 destination[BYTE_1] = source[BYTE_1];
1787 destination[BYTE_2] = source[BYTE_2];
1811 destination[BYTE_2] = source[BYTE_2];
1788 destination[BYTE_3] = source[BYTE_3];
1812 destination[BYTE_3] = source[BYTE_3];
1789 }
1813 }
1790
1814
1791 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1815 void copyInt16ByChar( unsigned char *destination, unsigned char *source )
1792 {
1816 {
1793 destination[BYTE_0] = source[BYTE_0];
1817 destination[BYTE_0] = source[BYTE_0];
1794 destination[BYTE_1] = source[BYTE_1];
1818 destination[BYTE_1] = source[BYTE_1];
1795 }
1819 }
1796
1820
1797 void floatToChar( float value, unsigned char* ptr)
1821 void floatToChar( float value, unsigned char* ptr)
1798 {
1822 {
1799 unsigned char* valuePtr;
1823 unsigned char* valuePtr;
1800
1824
1801 valuePtr = (unsigned char*) &value;
1825 valuePtr = (unsigned char*) &value;
1802
1826
1803 ptr[BYTE_0] = valuePtr[BYTE_0];
1827 ptr[BYTE_0] = valuePtr[BYTE_0];
1804 ptr[BYTE_1] = valuePtr[BYTE_1];
1828 ptr[BYTE_1] = valuePtr[BYTE_1];
1805 ptr[BYTE_2] = valuePtr[BYTE_2];
1829 ptr[BYTE_2] = valuePtr[BYTE_2];
1806 ptr[BYTE_3] = valuePtr[BYTE_3];
1830 ptr[BYTE_3] = valuePtr[BYTE_3];
1807 }
1831 }
1808
1832
1809 //**********
1833 //**********
1810 // init dump
1834 // init dump
1811
1835
1812 void init_parameter_dump( void )
1836 void init_parameter_dump( void )
1813 {
1837 {
1814 /** This function initialize the parameter_dump_packet global variable with default values.
1838 /** This function initialize the parameter_dump_packet global variable with default values.
1815 *
1839 *
1816 */
1840 */
1817
1841
1818 unsigned int k;
1842 unsigned int k;
1819
1843
1820 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1844 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1821 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1845 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1822 parameter_dump_packet.reserved = CCSDS_RESERVED;
1846 parameter_dump_packet.reserved = CCSDS_RESERVED;
1823 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1847 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1824 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1848 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1825 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1849 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1826 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1850 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1827 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1851 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1828 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1852 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1829 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1853 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1830 // DATA FIELD HEADER
1854 // DATA FIELD HEADER
1831 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1855 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1832 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1856 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1833 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1857 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1834 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1858 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1835 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1859 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1836 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1860 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1837 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1861 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1838 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1862 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1839 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1863 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1840 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1864 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1841 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1865 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1842
1866
1843 //******************
1867 //******************
1844 // COMMON PARAMETERS
1868 // COMMON PARAMETERS
1845 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1869 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1846 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1870 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1847
1871
1848 //******************
1872 //******************
1849 // NORMAL PARAMETERS
1873 // NORMAL PARAMETERS
1850 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1874 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1851 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1875 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1852 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1876 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1853 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1877 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1854 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1878 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1855 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1879 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1856 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1880 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1857 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1881 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1858 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1882 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1859
1883
1860 //*****************
1884 //*****************
1861 // BURST PARAMETERS
1885 // BURST PARAMETERS
1862 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1886 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1863 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1887 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1864
1888
1865 //****************
1889 //****************
1866 // SBM1 PARAMETERS
1890 // SBM1 PARAMETERS
1867 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1891 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1868 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1892 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1869
1893
1870 //****************
1894 //****************
1871 // SBM2 PARAMETERS
1895 // SBM2 PARAMETERS
1872 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1896 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1873 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1897 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1874
1898
1875 //************
1899 //************
1876 // FBINS MASKS
1900 // FBINS MASKS
1877 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1901 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1878 {
1902 {
1879 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1903 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = INT8_ALL_F;
1880 }
1904 }
1881
1905
1882 // PAS FILTER PARAMETERS
1906 // PAS FILTER PARAMETERS
1883 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1907 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1884 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1908 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1885 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1909 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1886 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1910 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1887 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1911 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1888 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1912 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1889 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1913 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1890
1914
1891 // RW1_K
1915 // RW1_K
1892 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1916 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw1_k1);
1893 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1917 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw1_k2);
1894 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1918 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw1_k3);
1895 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1919 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw1_k4);
1896 // RW2_K
1920 // RW2_K
1897 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1921 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw2_k1);
1898 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1922 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw2_k2);
1899 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1923 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw2_k3);
1900 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1924 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw2_k4);
1901 // RW3_K
1925 // RW3_K
1902 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1926 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw3_k1);
1903 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1927 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw3_k2);
1904 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1928 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw3_k3);
1905 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1929 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw3_k4);
1906 // RW4_K
1930 // RW4_K
1907 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1931 floatToChar( DEFAULT_SY_LFR_RW_K1, parameter_dump_packet.sy_lfr_rw4_k1);
1908 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1932 floatToChar( DEFAULT_SY_LFR_RW_K2, parameter_dump_packet.sy_lfr_rw4_k2);
1909 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1933 floatToChar( DEFAULT_SY_LFR_RW_K3, parameter_dump_packet.sy_lfr_rw4_k3);
1910 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1934 floatToChar( DEFAULT_SY_LFR_RW_K4, parameter_dump_packet.sy_lfr_rw4_k4);
1911
1935
1912 // LFR_RW_MASK
1936 // LFR_RW_MASK
1913 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1937 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1914 {
1938 {
1915 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1939 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = INT8_ALL_F;
1916 }
1940 }
1917
1941
1918 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1942 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1919 merge_fbins_masks();
1943 merge_fbins_masks();
1920 }
1944 }
1921
1945
1922 void init_kcoefficients_dump( void )
1946 void init_kcoefficients_dump( void )
1923 {
1947 {
1924 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1948 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1925 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1949 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1926
1950
1927 kcoefficient_node_1.previous = NULL;
1951 kcoefficient_node_1.previous = NULL;
1928 kcoefficient_node_1.next = NULL;
1952 kcoefficient_node_1.next = NULL;
1929 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1953 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1930 kcoefficient_node_1.coarseTime = INIT_CHAR;
1954 kcoefficient_node_1.coarseTime = INIT_CHAR;
1931 kcoefficient_node_1.fineTime = INIT_CHAR;
1955 kcoefficient_node_1.fineTime = INIT_CHAR;
1932 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1956 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1933 kcoefficient_node_1.status = INIT_CHAR;
1957 kcoefficient_node_1.status = INIT_CHAR;
1934
1958
1935 kcoefficient_node_2.previous = NULL;
1959 kcoefficient_node_2.previous = NULL;
1936 kcoefficient_node_2.next = NULL;
1960 kcoefficient_node_2.next = NULL;
1937 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1961 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1938 kcoefficient_node_2.coarseTime = INIT_CHAR;
1962 kcoefficient_node_2.coarseTime = INIT_CHAR;
1939 kcoefficient_node_2.fineTime = INIT_CHAR;
1963 kcoefficient_node_2.fineTime = INIT_CHAR;
1940 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1964 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1941 kcoefficient_node_2.status = INIT_CHAR;
1965 kcoefficient_node_2.status = INIT_CHAR;
1942 }
1966 }
1943
1967
1944 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1968 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1945 {
1969 {
1946 unsigned int k;
1970 unsigned int k;
1947 unsigned int packetLength;
1971 unsigned int packetLength;
1948
1972
1949 packetLength =
1973 packetLength =
1950 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1974 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1951
1975
1952 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1976 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1953 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1977 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1954 kcoefficients_dump->reserved = CCSDS_RESERVED;
1978 kcoefficients_dump->reserved = CCSDS_RESERVED;
1955 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1979 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1956 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1980 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1957 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1981 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1958 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1982 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1959 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1983 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1960 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1984 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1961 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1985 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1962 // DATA FIELD HEADER
1986 // DATA FIELD HEADER
1963 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1987 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1964 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1988 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1965 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1989 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1966 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1990 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1967 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1991 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1968 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1992 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1969 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1993 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1970 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1994 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1971 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1995 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1972 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1996 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1973 kcoefficients_dump->sid = SID_K_DUMP;
1997 kcoefficients_dump->sid = SID_K_DUMP;
1974
1998
1975 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1999 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1976 kcoefficients_dump->pkt_nr = PKTNR_1;
2000 kcoefficients_dump->pkt_nr = PKTNR_1;
1977 kcoefficients_dump->blk_nr = blk_nr;
2001 kcoefficients_dump->blk_nr = blk_nr;
1978
2002
1979 //******************
2003 //******************
1980 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
2004 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1981 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
2005 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1982 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
2006 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1983 {
2007 {
1984 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
2008 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1985 }
2009 }
1986 }
2010 }
1987
2011
1988 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
2012 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1989 {
2013 {
1990 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
2014 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1991 *
2015 *
1992 * @param packet_sequence_control points to the packet sequence control which will be incremented
2016 * @param packet_sequence_control points to the packet sequence control which will be incremented
1993 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
2017 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1994 *
2018 *
1995 * If the destination ID is not known, a dedicated counter is incremented.
2019 * If the destination ID is not known, a dedicated counter is incremented.
1996 *
2020 *
1997 */
2021 */
1998
2022
1999 unsigned short sequence_cnt;
2023 unsigned short sequence_cnt;
2000 unsigned short segmentation_grouping_flag;
2024 unsigned short segmentation_grouping_flag;
2001 unsigned short new_packet_sequence_control;
2025 unsigned short new_packet_sequence_control;
2002 unsigned char i;
2026 unsigned char i;
2003
2027
2004 switch (destination_id)
2028 switch (destination_id)
2005 {
2029 {
2006 case SID_TC_GROUND:
2030 case SID_TC_GROUND:
2007 i = GROUND;
2031 i = GROUND;
2008 break;
2032 break;
2009 case SID_TC_MISSION_TIMELINE:
2033 case SID_TC_MISSION_TIMELINE:
2010 i = MISSION_TIMELINE;
2034 i = MISSION_TIMELINE;
2011 break;
2035 break;
2012 case SID_TC_TC_SEQUENCES:
2036 case SID_TC_TC_SEQUENCES:
2013 i = TC_SEQUENCES;
2037 i = TC_SEQUENCES;
2014 break;
2038 break;
2015 case SID_TC_RECOVERY_ACTION_CMD:
2039 case SID_TC_RECOVERY_ACTION_CMD:
2016 i = RECOVERY_ACTION_CMD;
2040 i = RECOVERY_ACTION_CMD;
2017 break;
2041 break;
2018 case SID_TC_BACKUP_MISSION_TIMELINE:
2042 case SID_TC_BACKUP_MISSION_TIMELINE:
2019 i = BACKUP_MISSION_TIMELINE;
2043 i = BACKUP_MISSION_TIMELINE;
2020 break;
2044 break;
2021 case SID_TC_DIRECT_CMD:
2045 case SID_TC_DIRECT_CMD:
2022 i = DIRECT_CMD;
2046 i = DIRECT_CMD;
2023 break;
2047 break;
2024 case SID_TC_SPARE_GRD_SRC1:
2048 case SID_TC_SPARE_GRD_SRC1:
2025 i = SPARE_GRD_SRC1;
2049 i = SPARE_GRD_SRC1;
2026 break;
2050 break;
2027 case SID_TC_SPARE_GRD_SRC2:
2051 case SID_TC_SPARE_GRD_SRC2:
2028 i = SPARE_GRD_SRC2;
2052 i = SPARE_GRD_SRC2;
2029 break;
2053 break;
2030 case SID_TC_OBCP:
2054 case SID_TC_OBCP:
2031 i = OBCP;
2055 i = OBCP;
2032 break;
2056 break;
2033 case SID_TC_SYSTEM_CONTROL:
2057 case SID_TC_SYSTEM_CONTROL:
2034 i = SYSTEM_CONTROL;
2058 i = SYSTEM_CONTROL;
2035 break;
2059 break;
2036 case SID_TC_AOCS:
2060 case SID_TC_AOCS:
2037 i = AOCS;
2061 i = AOCS;
2038 break;
2062 break;
2039 case SID_TC_RPW_INTERNAL:
2063 case SID_TC_RPW_INTERNAL:
2040 i = RPW_INTERNAL;
2064 i = RPW_INTERNAL;
2041 break;
2065 break;
2042 default:
2066 default:
2043 i = GROUND;
2067 i = GROUND;
2044 break;
2068 break;
2045 }
2069 }
2046
2070
2047 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
2071 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
2048 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
2072 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
2049
2073
2050 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
2074 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
2051
2075
2052 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
2076 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
2053 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
2077 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
2054
2078
2055 // increment the sequence counter
2079 // increment the sequence counter
2056 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
2080 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
2057 {
2081 {
2058 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
2082 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
2059 }
2083 }
2060 else
2084 else
2061 {
2085 {
2062 sequenceCounters_TM_DUMP[ i ] = 0;
2086 sequenceCounters_TM_DUMP[ i ] = 0;
2063 }
2087 }
2064 }
2088 }
@@ -1,512 +1,536
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions to send TM packets related to TC parsing and execution.
25 /** Functions to send TM packets related to TC parsing and execution.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to send appropriate TM packets after parsing and execution:
30 * A group of functions to send appropriate TM packets after parsing and execution:
7 * - TM_LFR_TC_EXE_SUCCESS
31 * - TM_LFR_TC_EXE_SUCCESS
8 * - TM_LFR_TC_EXE_INCONSISTENT
32 * - TM_LFR_TC_EXE_INCONSISTENT
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
33 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
34 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
11 * - TM_LFR_TC_EXE_ERROR
35 * - TM_LFR_TC_EXE_ERROR
12 * - TM_LFR_TC_EXE_CORRUPTED
36 * - TM_LFR_TC_EXE_CORRUPTED
13 *
37 *
14 */
38 */
15
39
16 #include "tm_lfr_tc_exe.h"
40 #include "tm_lfr_tc_exe.h"
17
41
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
42 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
19 {
43 {
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
44 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
21 *
45 *
22 * @param TC points to the TeleCommand packet that is being processed
46 * @param TC points to the TeleCommand packet that is being processed
23 * @param queue_id is the id of the queue which handles TM
47 * @param queue_id is the id of the queue which handles TM
24 *
48 *
25 * @return RTEMS directive status code:
49 * @return RTEMS directive status code:
26 * - RTEMS_SUCCESSFUL - message sent successfully
50 * - RTEMS_SUCCESSFUL - message sent successfully
27 * - RTEMS_INVALID_ID - invalid queue id
51 * - RTEMS_INVALID_ID - invalid queue id
28 * - RTEMS_INVALID_SIZE - invalid message size
52 * - RTEMS_INVALID_SIZE - invalid message size
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
53 * - RTEMS_INVALID_ADDRESS - buffer is NULL
30 * - RTEMS_UNSATISFIED - out of message buffers
54 * - RTEMS_UNSATISFIED - out of message buffers
31 * - RTEMS_TOO_MANY - queue s limit has been reached
55 * - RTEMS_TOO_MANY - queue s limit has been reached
32 *
56 *
33 */
57 */
34
58
35 rtems_status_code status;
59 rtems_status_code status;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
60 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
37 unsigned char messageSize;
61 unsigned char messageSize;
38
62
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
63 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
64 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
41 TM.reserved = DEFAULT_RESERVED;
65 TM.reserved = DEFAULT_RESERVED;
42 TM.userApplication = CCSDS_USER_APP;
66 TM.userApplication = CCSDS_USER_APP;
43 // PACKET HEADER
67 // PACKET HEADER
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
68 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
69 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
70 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
71 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
72 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
49 // DATA FIELD HEADER
73 // DATA FIELD HEADER
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
74 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
51 TM.serviceType = TM_TYPE_TC_EXE;
75 TM.serviceType = TM_TYPE_TC_EXE;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
76 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
53 TM.destinationID = TC->sourceID;
77 TM.destinationID = TC->sourceID;
54 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
78 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
55 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
79 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
56 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
80 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
57 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
81 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
58 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
82 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
59 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
83 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
60 //
84 //
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
85 TM.telecommand_pkt_id[0] = TC->packetID[0];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
86 TM.telecommand_pkt_id[1] = TC->packetID[1];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
87 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
88 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
65
89
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
90 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
67
91
68 // SEND DATA
92 // SEND DATA
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
93 status = rtems_message_queue_send( queue_id, &TM, messageSize);
70 if (status != RTEMS_SUCCESSFUL) {
94 if (status != RTEMS_SUCCESSFUL) {
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
95 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
72 }
96 }
73
97
74 // UPDATE HK FIELDS
98 // UPDATE HK FIELDS
75 update_last_TC_exe( TC, TM.time );
99 update_last_TC_exe( TC, TM.time );
76
100
77 return status;
101 return status;
78 }
102 }
79
103
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
104 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
81 unsigned char byte_position, unsigned char rcv_value )
105 unsigned char byte_position, unsigned char rcv_value )
82 {
106 {
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
107 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
84 *
108 *
85 * @param TC points to the TeleCommand packet that is being processed
109 * @param TC points to the TeleCommand packet that is being processed
86 * @param queue_id is the id of the queue which handles TM
110 * @param queue_id is the id of the queue which handles TM
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
111 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
112 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
89 *
113 *
90 * @return RTEMS directive status code:
114 * @return RTEMS directive status code:
91 * - RTEMS_SUCCESSFUL - message sent successfully
115 * - RTEMS_SUCCESSFUL - message sent successfully
92 * - RTEMS_INVALID_ID - invalid queue id
116 * - RTEMS_INVALID_ID - invalid queue id
93 * - RTEMS_INVALID_SIZE - invalid message size
117 * - RTEMS_INVALID_SIZE - invalid message size
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
118 * - RTEMS_INVALID_ADDRESS - buffer is NULL
95 * - RTEMS_UNSATISFIED - out of message buffers
119 * - RTEMS_UNSATISFIED - out of message buffers
96 * - RTEMS_TOO_MANY - queue s limit has been reached
120 * - RTEMS_TOO_MANY - queue s limit has been reached
97 *
121 *
98 */
122 */
99
123
100 rtems_status_code status;
124 rtems_status_code status;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
125 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
102 unsigned char messageSize;
126 unsigned char messageSize;
103
127
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
128 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
129 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
106 TM.reserved = DEFAULT_RESERVED;
130 TM.reserved = DEFAULT_RESERVED;
107 TM.userApplication = CCSDS_USER_APP;
131 TM.userApplication = CCSDS_USER_APP;
108 // PACKET HEADER
132 // PACKET HEADER
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
133 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
134 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
135 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
136 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
137 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
114 // DATA FIELD HEADER
138 // DATA FIELD HEADER
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
139 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
116 TM.serviceType = TM_TYPE_TC_EXE;
140 TM.serviceType = TM_TYPE_TC_EXE;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
141 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
118 TM.destinationID = TC->sourceID;
142 TM.destinationID = TC->sourceID;
119 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
143 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
120 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
144 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
121 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
145 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
122 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
146 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
123 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
147 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
124 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
148 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
125 //
149 //
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
150 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
151 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
152 TM.telecommand_pkt_id[0] = TC->packetID[0];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
153 TM.telecommand_pkt_id[1] = TC->packetID[1];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
154 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
155 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
132 TM.tc_service = TC->serviceType; // type of the rejected TC
156 TM.tc_service = TC->serviceType; // type of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
157 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
134 TM.byte_position = byte_position;
158 TM.byte_position = byte_position;
135 TM.rcv_value = (unsigned char) rcv_value;
159 TM.rcv_value = (unsigned char) rcv_value;
136
160
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
161 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
138
162
139 // SEND DATA
163 // SEND DATA
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
164 status = rtems_message_queue_send( queue_id, &TM, messageSize);
141 if (status != RTEMS_SUCCESSFUL) {
165 if (status != RTEMS_SUCCESSFUL) {
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
166 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
143 }
167 }
144
168
145 // UPDATE HK FIELDS
169 // UPDATE HK FIELDS
146 update_last_TC_rej( TC, TM.time );
170 update_last_TC_rej( TC, TM.time );
147
171
148 return status;
172 return status;
149 }
173 }
150
174
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
175 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
152 {
176 {
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
177 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
154 *
178 *
155 * @param TC points to the TeleCommand packet that is being processed
179 * @param TC points to the TeleCommand packet that is being processed
156 * @param queue_id is the id of the queue which handles TM
180 * @param queue_id is the id of the queue which handles TM
157 *
181 *
158 * @return RTEMS directive status code:
182 * @return RTEMS directive status code:
159 * - RTEMS_SUCCESSFUL - message sent successfully
183 * - RTEMS_SUCCESSFUL - message sent successfully
160 * - RTEMS_INVALID_ID - invalid queue id
184 * - RTEMS_INVALID_ID - invalid queue id
161 * - RTEMS_INVALID_SIZE - invalid message size
185 * - RTEMS_INVALID_SIZE - invalid message size
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
186 * - RTEMS_INVALID_ADDRESS - buffer is NULL
163 * - RTEMS_UNSATISFIED - out of message buffers
187 * - RTEMS_UNSATISFIED - out of message buffers
164 * - RTEMS_TOO_MANY - queue s limit has been reached
188 * - RTEMS_TOO_MANY - queue s limit has been reached
165 *
189 *
166 */
190 */
167
191
168 rtems_status_code status;
192 rtems_status_code status;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
193 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
170 unsigned char messageSize;
194 unsigned char messageSize;
171
195
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
196 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
197 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
174 TM.reserved = DEFAULT_RESERVED;
198 TM.reserved = DEFAULT_RESERVED;
175 TM.userApplication = CCSDS_USER_APP;
199 TM.userApplication = CCSDS_USER_APP;
176 // PACKET HEADER
200 // PACKET HEADER
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
201 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
202 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
203 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
204 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
205 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
182 // DATA FIELD HEADER
206 // DATA FIELD HEADER
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
207 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
184 TM.serviceType = TM_TYPE_TC_EXE;
208 TM.serviceType = TM_TYPE_TC_EXE;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
209 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
186 TM.destinationID = TC->sourceID; // default destination id
210 TM.destinationID = TC->sourceID; // default destination id
187 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
211 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
188 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
212 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
189 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
213 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
190 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
214 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
191 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
215 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
192 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
216 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
193 //
217 //
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
218 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
219 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
220 TM.telecommand_pkt_id[0] = TC->packetID[0];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
221 TM.telecommand_pkt_id[1] = TC->packetID[1];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
222 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
223 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
200 TM.tc_service = TC->serviceType; // type of the rejected TC
224 TM.tc_service = TC->serviceType; // type of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
225 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
226 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
227 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
204
228
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
229 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
206
230
207 // SEND DATA
231 // SEND DATA
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
232 status = rtems_message_queue_send( queue_id, &TM, messageSize);
209 if (status != RTEMS_SUCCESSFUL) {
233 if (status != RTEMS_SUCCESSFUL) {
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
234 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
211 }
235 }
212
236
213 // UPDATE HK FIELDS
237 // UPDATE HK FIELDS
214 update_last_TC_rej( TC, TM.time );
238 update_last_TC_rej( TC, TM.time );
215
239
216 return status;
240 return status;
217 }
241 }
218
242
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
243 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
220 {
244 {
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
245 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
222 *
246 *
223 * @param TC points to the TeleCommand packet that is being processed
247 * @param TC points to the TeleCommand packet that is being processed
224 * @param queue_id is the id of the queue which handles TM
248 * @param queue_id is the id of the queue which handles TM
225 *
249 *
226 * @return RTEMS directive status code:
250 * @return RTEMS directive status code:
227 * - RTEMS_SUCCESSFUL - message sent successfully
251 * - RTEMS_SUCCESSFUL - message sent successfully
228 * - RTEMS_INVALID_ID - invalid queue id
252 * - RTEMS_INVALID_ID - invalid queue id
229 * - RTEMS_INVALID_SIZE - invalid message size
253 * - RTEMS_INVALID_SIZE - invalid message size
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
254 * - RTEMS_INVALID_ADDRESS - buffer is NULL
231 * - RTEMS_UNSATISFIED - out of message buffers
255 * - RTEMS_UNSATISFIED - out of message buffers
232 * - RTEMS_TOO_MANY - queue s limit has been reached
256 * - RTEMS_TOO_MANY - queue s limit has been reached
233 *
257 *
234 */
258 */
235
259
236 rtems_status_code status;
260 rtems_status_code status;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
261 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
238 unsigned char messageSize;
262 unsigned char messageSize;
239
263
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
264 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
265 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
242 TM.reserved = DEFAULT_RESERVED;
266 TM.reserved = DEFAULT_RESERVED;
243 TM.userApplication = CCSDS_USER_APP;
267 TM.userApplication = CCSDS_USER_APP;
244 // PACKET HEADER
268 // PACKET HEADER
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
269 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
270 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
271 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
272 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
273 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
250 // DATA FIELD HEADER
274 // DATA FIELD HEADER
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
275 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
252 TM.serviceType = TM_TYPE_TC_EXE;
276 TM.serviceType = TM_TYPE_TC_EXE;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
277 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
254 TM.destinationID = TC->sourceID; // default destination id
278 TM.destinationID = TC->sourceID; // default destination id
255 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
279 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
256 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
280 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
257 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
281 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
258 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
282 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
259 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
283 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
260 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
284 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
261 //
285 //
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
286 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
287 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
288 TM.telecommand_pkt_id[0] = TC->packetID[0];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
289 TM.telecommand_pkt_id[1] = TC->packetID[1];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
290 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
291 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
268 TM.tc_service = TC->serviceType; // type of the rejected TC
292 TM.tc_service = TC->serviceType; // type of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
293 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
270
294
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
295 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
272
296
273 // SEND DATA
297 // SEND DATA
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
298 status = rtems_message_queue_send( queue_id, &TM, messageSize);
275 if (status != RTEMS_SUCCESSFUL) {
299 if (status != RTEMS_SUCCESSFUL) {
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
300 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
277 }
301 }
278
302
279 // UPDATE HK FIELDS
303 // UPDATE HK FIELDS
280 update_last_TC_rej( TC, TM.time );
304 update_last_TC_rej( TC, TM.time );
281
305
282 return status;
306 return status;
283 }
307 }
284
308
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
309 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
286 {
310 {
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
311 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
288 *
312 *
289 * @param TC points to the TeleCommand packet that is being processed
313 * @param TC points to the TeleCommand packet that is being processed
290 * @param queue_id is the id of the queue which handles TM
314 * @param queue_id is the id of the queue which handles TM
291 *
315 *
292 * @return RTEMS directive status code:
316 * @return RTEMS directive status code:
293 * - RTEMS_SUCCESSFUL - message sent successfully
317 * - RTEMS_SUCCESSFUL - message sent successfully
294 * - RTEMS_INVALID_ID - invalid queue id
318 * - RTEMS_INVALID_ID - invalid queue id
295 * - RTEMS_INVALID_SIZE - invalid message size
319 * - RTEMS_INVALID_SIZE - invalid message size
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
320 * - RTEMS_INVALID_ADDRESS - buffer is NULL
297 * - RTEMS_UNSATISFIED - out of message buffers
321 * - RTEMS_UNSATISFIED - out of message buffers
298 * - RTEMS_TOO_MANY - queue s limit has been reached
322 * - RTEMS_TOO_MANY - queue s limit has been reached
299 *
323 *
300 */
324 */
301
325
302 rtems_status_code status;
326 rtems_status_code status;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
327 Packet_TM_LFR_TC_EXE_ERROR_t TM;
304 unsigned char messageSize;
328 unsigned char messageSize;
305
329
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
330 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
331 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
308 TM.reserved = DEFAULT_RESERVED;
332 TM.reserved = DEFAULT_RESERVED;
309 TM.userApplication = CCSDS_USER_APP;
333 TM.userApplication = CCSDS_USER_APP;
310 // PACKET HEADER
334 // PACKET HEADER
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
335 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
336 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
337 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
338 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
339 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
316 // DATA FIELD HEADER
340 // DATA FIELD HEADER
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
341 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
318 TM.serviceType = TM_TYPE_TC_EXE;
342 TM.serviceType = TM_TYPE_TC_EXE;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
343 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
320 TM.destinationID = TC->sourceID; // default destination id
344 TM.destinationID = TC->sourceID; // default destination id
321 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
345 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
322 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
346 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
323 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
347 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
324 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
348 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
325 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
349 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
326 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
350 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
327 //
351 //
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
352 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
353 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
354 TM.telecommand_pkt_id[0] = TC->packetID[0];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
355 TM.telecommand_pkt_id[1] = TC->packetID[1];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
356 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
357 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
334 TM.tc_service = TC->serviceType; // type of the rejected TC
358 TM.tc_service = TC->serviceType; // type of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
359 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
336
360
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
361 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
338
362
339 // SEND DATA
363 // SEND DATA
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
364 status = rtems_message_queue_send( queue_id, &TM, messageSize);
341 if (status != RTEMS_SUCCESSFUL) {
365 if (status != RTEMS_SUCCESSFUL) {
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
366 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
343 }
367 }
344
368
345 // UPDATE HK FIELDS
369 // UPDATE HK FIELDS
346 update_last_TC_rej( TC, TM.time );
370 update_last_TC_rej( TC, TM.time );
347
371
348 return status;
372 return status;
349 }
373 }
350
374
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
375 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
376 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
353 unsigned char destinationID )
377 unsigned char destinationID )
354 {
378 {
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
379 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
356 *
380 *
357 * @param TC points to the TeleCommand packet that is being processed
381 * @param TC points to the TeleCommand packet that is being processed
358 * @param queue_id is the id of the queue which handles TM
382 * @param queue_id is the id of the queue which handles TM
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
383 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
384 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
361 *
385 *
362 * @return RTEMS directive status code:
386 * @return RTEMS directive status code:
363 * - RTEMS_SUCCESSFUL - message sent successfully
387 * - RTEMS_SUCCESSFUL - message sent successfully
364 * - RTEMS_INVALID_ID - invalid queue id
388 * - RTEMS_INVALID_ID - invalid queue id
365 * - RTEMS_INVALID_SIZE - invalid message size
389 * - RTEMS_INVALID_SIZE - invalid message size
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
390 * - RTEMS_INVALID_ADDRESS - buffer is NULL
367 * - RTEMS_UNSATISFIED - out of message buffers
391 * - RTEMS_UNSATISFIED - out of message buffers
368 * - RTEMS_TOO_MANY - queue s limit has been reached
392 * - RTEMS_TOO_MANY - queue s limit has been reached
369 *
393 *
370 */
394 */
371
395
372 rtems_status_code status;
396 rtems_status_code status;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
397 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
374 unsigned char messageSize;
398 unsigned char messageSize;
375 unsigned int packetLength;
399 unsigned int packetLength;
376 unsigned int estimatedPacketLength;
400 unsigned int estimatedPacketLength;
377 unsigned char *packetDataField;
401 unsigned char *packetDataField;
378
402
379 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
403 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
380 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
404 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
381 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
405 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
382
406
383 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
407 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
384 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
408 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
385 TM.reserved = DEFAULT_RESERVED;
409 TM.reserved = DEFAULT_RESERVED;
386 TM.userApplication = CCSDS_USER_APP;
410 TM.userApplication = CCSDS_USER_APP;
387 // PACKET HEADER
411 // PACKET HEADER
388 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
412 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
389 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
413 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
390 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
414 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
391 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
415 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
392 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
416 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
393 // DATA FIELD HEADER
417 // DATA FIELD HEADER
394 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
418 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
395 TM.serviceType = TM_TYPE_TC_EXE;
419 TM.serviceType = TM_TYPE_TC_EXE;
396 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
420 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
397 TM.destinationID = destinationID;
421 TM.destinationID = destinationID;
398 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
422 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
399 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
423 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
400 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
424 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
401 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
425 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
402 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
426 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
403 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
427 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
404 //
428 //
405 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
429 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
406 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
430 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
407 TM.telecommand_pkt_id[0] = TC->packetID[0];
431 TM.telecommand_pkt_id[0] = TC->packetID[0];
408 TM.telecommand_pkt_id[1] = TC->packetID[1];
432 TM.telecommand_pkt_id[1] = TC->packetID[1];
409 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
433 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
410 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
434 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
411 TM.tc_service = TC->serviceType; // type of the rejected TC
435 TM.tc_service = TC->serviceType; // type of the rejected TC
412 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
436 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
413 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
437 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
414 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
438 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
415 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
439 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
416 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
440 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
417 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
441 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
418 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
442 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
419 TM.computed_crc[0] = computed_CRC[0];
443 TM.computed_crc[0] = computed_CRC[0];
420 TM.computed_crc[1] = computed_CRC[1];
444 TM.computed_crc[1] = computed_CRC[1];
421
445
422 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
446 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
423
447
424 // SEND DATA
448 // SEND DATA
425 status = rtems_message_queue_send( queue_id, &TM, messageSize);
449 status = rtems_message_queue_send( queue_id, &TM, messageSize);
426 if (status != RTEMS_SUCCESSFUL) {
450 if (status != RTEMS_SUCCESSFUL) {
427 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
451 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
428 }
452 }
429
453
430 // UPDATE HK FIELDS
454 // UPDATE HK FIELDS
431 update_last_TC_rej( TC, TM.time );
455 update_last_TC_rej( TC, TM.time );
432
456
433 return status;
457 return status;
434 }
458 }
435
459
436 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
460 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
437 {
461 {
438 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
462 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
439 *
463 *
440 * @param packet_sequence_control points to the packet sequence control which will be incremented
464 * @param packet_sequence_control points to the packet sequence control which will be incremented
441 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
465 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
442 *
466 *
443 * If the destination ID is not known, a dedicated counter is incremented.
467 * If the destination ID is not known, a dedicated counter is incremented.
444 *
468 *
445 */
469 */
446
470
447 unsigned short sequence_cnt;
471 unsigned short sequence_cnt;
448 unsigned short segmentation_grouping_flag;
472 unsigned short segmentation_grouping_flag;
449 unsigned short new_packet_sequence_control;
473 unsigned short new_packet_sequence_control;
450 unsigned char i;
474 unsigned char i;
451
475
452 switch (destination_id)
476 switch (destination_id)
453 {
477 {
454 case SID_TC_GROUND:
478 case SID_TC_GROUND:
455 i = GROUND;
479 i = GROUND;
456 break;
480 break;
457 case SID_TC_MISSION_TIMELINE:
481 case SID_TC_MISSION_TIMELINE:
458 i = MISSION_TIMELINE;
482 i = MISSION_TIMELINE;
459 break;
483 break;
460 case SID_TC_TC_SEQUENCES:
484 case SID_TC_TC_SEQUENCES:
461 i = TC_SEQUENCES;
485 i = TC_SEQUENCES;
462 break;
486 break;
463 case SID_TC_RECOVERY_ACTION_CMD:
487 case SID_TC_RECOVERY_ACTION_CMD:
464 i = RECOVERY_ACTION_CMD;
488 i = RECOVERY_ACTION_CMD;
465 break;
489 break;
466 case SID_TC_BACKUP_MISSION_TIMELINE:
490 case SID_TC_BACKUP_MISSION_TIMELINE:
467 i = BACKUP_MISSION_TIMELINE;
491 i = BACKUP_MISSION_TIMELINE;
468 break;
492 break;
469 case SID_TC_DIRECT_CMD:
493 case SID_TC_DIRECT_CMD:
470 i = DIRECT_CMD;
494 i = DIRECT_CMD;
471 break;
495 break;
472 case SID_TC_SPARE_GRD_SRC1:
496 case SID_TC_SPARE_GRD_SRC1:
473 i = SPARE_GRD_SRC1;
497 i = SPARE_GRD_SRC1;
474 break;
498 break;
475 case SID_TC_SPARE_GRD_SRC2:
499 case SID_TC_SPARE_GRD_SRC2:
476 i = SPARE_GRD_SRC2;
500 i = SPARE_GRD_SRC2;
477 break;
501 break;
478 case SID_TC_OBCP:
502 case SID_TC_OBCP:
479 i = OBCP;
503 i = OBCP;
480 break;
504 break;
481 case SID_TC_SYSTEM_CONTROL:
505 case SID_TC_SYSTEM_CONTROL:
482 i = SYSTEM_CONTROL;
506 i = SYSTEM_CONTROL;
483 break;
507 break;
484 case SID_TC_AOCS:
508 case SID_TC_AOCS:
485 i = AOCS;
509 i = AOCS;
486 break;
510 break;
487 case SID_TC_RPW_INTERNAL:
511 case SID_TC_RPW_INTERNAL:
488 i = RPW_INTERNAL;
512 i = RPW_INTERNAL;
489 break;
513 break;
490 default:
514 default:
491 i = GROUND;
515 i = GROUND;
492 break;
516 break;
493 }
517 }
494
518
495 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
519 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
496 sequence_cnt = sequenceCounters_TC_EXE[ i ] & SEQ_CNT_MASK;
520 sequence_cnt = sequenceCounters_TC_EXE[ i ] & SEQ_CNT_MASK;
497
521
498 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
522 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
499
523
500 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
524 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
501 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
525 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
502
526
503 // increment the sequence counter
527 // increment the sequence counter
504 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
528 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
505 {
529 {
506 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
530 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
507 }
531 }
508 else
532 else
509 {
533 {
510 sequenceCounters_TC_EXE[ i ] = 0;
534 sequenceCounters_TC_EXE[ i ] = 0;
511 }
535 }
512 }
536 }
@@ -1,1342 +1,1366
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 /** Functions and tasks related to waveform packet generation.
25 /** Functions and tasks related to waveform packet generation.
2 *
26 *
3 * @file
27 * @file
4 * @author P. LEROY
28 * @author P. LEROY
5 *
29 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
30 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
31 *
8 */
32 */
9
33
10 #include "wf_handler.h"
34 #include "wf_handler.h"
11
35
12 //***************
36 //***************
13 // waveform rings
37 // waveform rings
14 // F0
38 // F0
15 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
39 ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0};
16 ring_node *current_ring_node_f0 = NULL;
40 ring_node *current_ring_node_f0 = NULL;
17 ring_node *ring_node_to_send_swf_f0 = NULL;
41 ring_node *ring_node_to_send_swf_f0 = NULL;
18 // F1
42 // F1
19 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
43 ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0};
20 ring_node *current_ring_node_f1 = NULL;
44 ring_node *current_ring_node_f1 = NULL;
21 ring_node *ring_node_to_send_swf_f1 = NULL;
45 ring_node *ring_node_to_send_swf_f1 = NULL;
22 ring_node *ring_node_to_send_cwf_f1 = NULL;
46 ring_node *ring_node_to_send_cwf_f1 = NULL;
23 // F2
47 // F2
24 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
48 ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0};
25 ring_node *current_ring_node_f2 = NULL;
49 ring_node *current_ring_node_f2 = NULL;
26 ring_node *ring_node_to_send_swf_f2 = NULL;
50 ring_node *ring_node_to_send_swf_f2 = NULL;
27 ring_node *ring_node_to_send_cwf_f2 = NULL;
51 ring_node *ring_node_to_send_cwf_f2 = NULL;
28 // F3
52 // F3
29 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
53 ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0};
30 ring_node *current_ring_node_f3 = NULL;
54 ring_node *current_ring_node_f3 = NULL;
31 ring_node *ring_node_to_send_cwf_f3 = NULL;
55 ring_node *ring_node_to_send_cwf_f3 = NULL;
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
56 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0};
33
57
34 bool extractSWF1 = false;
58 bool extractSWF1 = false;
35 bool extractSWF2 = false;
59 bool extractSWF2 = false;
36 bool swf0_ready_flag_f1 = false;
60 bool swf0_ready_flag_f1 = false;
37 bool swf0_ready_flag_f2 = false;
61 bool swf0_ready_flag_f2 = false;
38 bool swf1_ready = false;
62 bool swf1_ready = false;
39 bool swf2_ready = false;
63 bool swf2_ready = false;
40
64
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
65 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
66 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0};
43 ring_node ring_node_swf1_extracted = {0};
67 ring_node ring_node_swf1_extracted = {0};
44 ring_node ring_node_swf2_extracted = {0};
68 ring_node ring_node_swf2_extracted = {0};
45
69
46 typedef enum resynchro_state_t
70 typedef enum resynchro_state_t
47 {
71 {
48 MEASURE,
72 MEASURE,
49 CORRECTION
73 CORRECTION
50 } resynchro_state;
74 } resynchro_state;
51
75
52 //*********************
76 //*********************
53 // Interrupt SubRoutine
77 // Interrupt SubRoutine
54
78
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
79 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
56 {
80 {
57 ring_node *node;
81 ring_node *node;
58
82
59 node = NULL;
83 node = NULL;
60 switch ( frequencyChannel ) {
84 switch ( frequencyChannel ) {
61 case CHANNELF1:
85 case CHANNELF1:
62 node = ring_node_to_send_cwf_f1;
86 node = ring_node_to_send_cwf_f1;
63 break;
87 break;
64 case CHANNELF2:
88 case CHANNELF2:
65 node = ring_node_to_send_cwf_f2;
89 node = ring_node_to_send_cwf_f2;
66 break;
90 break;
67 case CHANNELF3:
91 case CHANNELF3:
68 node = ring_node_to_send_cwf_f3;
92 node = ring_node_to_send_cwf_f3;
69 break;
93 break;
70 default:
94 default:
71 break;
95 break;
72 }
96 }
73
97
74 return node;
98 return node;
75 }
99 }
76
100
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
101 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
78 {
102 {
79 ring_node *node;
103 ring_node *node;
80
104
81 node = NULL;
105 node = NULL;
82 switch ( frequencyChannel ) {
106 switch ( frequencyChannel ) {
83 case CHANNELF0:
107 case CHANNELF0:
84 node = ring_node_to_send_swf_f0;
108 node = ring_node_to_send_swf_f0;
85 break;
109 break;
86 case CHANNELF1:
110 case CHANNELF1:
87 node = ring_node_to_send_swf_f1;
111 node = ring_node_to_send_swf_f1;
88 break;
112 break;
89 case CHANNELF2:
113 case CHANNELF2:
90 node = ring_node_to_send_swf_f2;
114 node = ring_node_to_send_swf_f2;
91 break;
115 break;
92 default:
116 default:
93 break;
117 break;
94 }
118 }
95
119
96 return node;
120 return node;
97 }
121 }
98
122
99 void reset_extractSWF( void )
123 void reset_extractSWF( void )
100 {
124 {
101 extractSWF1 = false;
125 extractSWF1 = false;
102 extractSWF2 = false;
126 extractSWF2 = false;
103 swf0_ready_flag_f1 = false;
127 swf0_ready_flag_f1 = false;
104 swf0_ready_flag_f2 = false;
128 swf0_ready_flag_f2 = false;
105 swf1_ready = false;
129 swf1_ready = false;
106 swf2_ready = false;
130 swf2_ready = false;
107 }
131 }
108
132
109 inline void waveforms_isr_f3( void )
133 inline void waveforms_isr_f3( void )
110 {
134 {
111 rtems_status_code spare_status;
135 rtems_status_code spare_status;
112
136
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
137 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
138 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
139 { // in modes other than STANDBY and BURST, send the CWF_F3 data
116 //***
140 //***
117 // F3
141 // F3
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
142 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
143 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
120 current_ring_node_f3 = current_ring_node_f3->next;
144 current_ring_node_f3 = current_ring_node_f3->next;
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
145 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
146 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
147 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
148 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
149 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
126 }
150 }
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
151 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
152 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
153 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
154 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
155 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
132 }
156 }
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
157 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
135 }
159 }
136 }
160 }
137 }
161 }
138 }
162 }
139
163
140 inline void waveforms_isr_burst( void )
164 inline void waveforms_isr_burst( void )
141 {
165 {
142 unsigned char status;
166 unsigned char status;
143 rtems_status_code spare_status;
167 rtems_status_code spare_status;
144
168
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
169 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
146
170
147 switch(status)
171 switch(status)
148 {
172 {
149 case BIT_WFP_BUFFER_0:
173 case BIT_WFP_BUFFER_0:
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
174 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
175 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
176 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
177 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
154 current_ring_node_f2 = current_ring_node_f2->next;
178 current_ring_node_f2 = current_ring_node_f2->next;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
179 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
180 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
181 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
158 }
182 }
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
183 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
160 break;
184 break;
161 case BIT_WFP_BUFFER_1:
185 case BIT_WFP_BUFFER_1:
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
186 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
187 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
188 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
189 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
166 current_ring_node_f2 = current_ring_node_f2->next;
190 current_ring_node_f2 = current_ring_node_f2->next;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
191 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
192 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
193 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
170 }
194 }
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
195 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
172 break;
196 break;
173 default:
197 default:
174 break;
198 break;
175 }
199 }
176 }
200 }
177
201
178 inline void waveform_isr_normal_sbm1_sbm2( void )
202 inline void waveform_isr_normal_sbm1_sbm2( void )
179 {
203 {
180 rtems_status_code status;
204 rtems_status_code status;
181
205
182 //***
206 //***
183 // F0
207 // F0
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
208 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
185 {
209 {
186 swf0_ready_flag_f1 = true;
210 swf0_ready_flag_f1 = true;
187 swf0_ready_flag_f2 = true;
211 swf0_ready_flag_f2 = true;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
212 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
189 current_ring_node_f0 = current_ring_node_f0->next;
213 current_ring_node_f0 = current_ring_node_f0->next;
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
214 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
191 {
215 {
192
216
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
217 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
218 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
219 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
197 }
221 }
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
199 {
223 {
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
224 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
225 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
226 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
204 }
228 }
205 // send an event to the WFRM task for resynchro activities
229 // send an event to the WFRM task for resynchro activities
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
230 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
207 status = rtems_event_send( Task_id[TASKID_CALI], RTEMS_EVENT_CAL_SWEEP_WAKE );
231 status = rtems_event_send( Task_id[TASKID_CALI], RTEMS_EVENT_CAL_SWEEP_WAKE );
208 }
232 }
209
233
210 //***
234 //***
211 // F1
235 // F1
212 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
236 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
213 // (1) change the receiving buffer for the waveform picker
237 // (1) change the receiving buffer for the waveform picker
214 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
238 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
215 current_ring_node_f1 = current_ring_node_f1->next;
239 current_ring_node_f1 = current_ring_node_f1->next;
216 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
217 {
241 {
218 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
242 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
219 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
243 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
220 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
244 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
221 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
222 }
246 }
223 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
224 {
248 {
225 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
249 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
226 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
250 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
227 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
251 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
228 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
229 }
253 }
230 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
254 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
231 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
255 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
232 }
256 }
233
257
234 //***
258 //***
235 // F2
259 // F2
236 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
260 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
237 // (1) change the receiving buffer for the waveform picker
261 // (1) change the receiving buffer for the waveform picker
238 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
262 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
239 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
263 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
240 current_ring_node_f2 = current_ring_node_f2->next;
264 current_ring_node_f2 = current_ring_node_f2->next;
241 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
265 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
242 {
266 {
243 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
267 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
244 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
268 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
245 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
269 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
246 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
270 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
247 }
271 }
248 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
272 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
249 {
273 {
250 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
274 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
251 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
275 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
252 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
276 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
253 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
277 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
254 }
278 }
255 // (2) send an event for the waveforms transmission
279 // (2) send an event for the waveforms transmission
256 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
280 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
257 }
281 }
258 }
282 }
259
283
260 rtems_isr waveforms_isr( rtems_vector_number vector )
284 rtems_isr waveforms_isr( rtems_vector_number vector )
261 {
285 {
262 /** This is the interrupt sub routine called by the waveform picker core.
286 /** This is the interrupt sub routine called by the waveform picker core.
263 *
287 *
264 * This ISR launch different actions depending mainly on two pieces of information:
288 * This ISR launch different actions depending mainly on two pieces of information:
265 * 1. the values read in the registers of the waveform picker.
289 * 1. the values read in the registers of the waveform picker.
266 * 2. the current LFR mode.
290 * 2. the current LFR mode.
267 *
291 *
268 */
292 */
269
293
270 // STATUS
294 // STATUS
271 // new error error buffer full
295 // new error error buffer full
272 // 15 14 13 12 11 10 9 8
296 // 15 14 13 12 11 10 9 8
273 // f3 f2 f1 f0 f3 f2 f1 f0
297 // f3 f2 f1 f0 f3 f2 f1 f0
274 //
298 //
275 // ready buffer
299 // ready buffer
276 // 7 6 5 4 3 2 1 0
300 // 7 6 5 4 3 2 1 0
277 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
301 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
278
302
279 rtems_status_code spare_status;
303 rtems_status_code spare_status;
280
304
281 waveforms_isr_f3();
305 waveforms_isr_f3();
282
306
283 //*************************************************
307 //*************************************************
284 // copy the status bits in the housekeeping packets
308 // copy the status bits in the housekeeping packets
285 housekeeping_packet.hk_lfr_vhdl_iir_cal =
309 housekeeping_packet.hk_lfr_vhdl_iir_cal =
286 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
310 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
287
311
288 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
312 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
289 {
313 {
290 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
314 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
291 }
315 }
292
316
293 switch(lfrCurrentMode)
317 switch(lfrCurrentMode)
294 {
318 {
295 //********
319 //********
296 // STANDBY
320 // STANDBY
297 case LFR_MODE_STANDBY:
321 case LFR_MODE_STANDBY:
298 break;
322 break;
299 //**************************
323 //**************************
300 // LFR NORMAL, SBM1 and SBM2
324 // LFR NORMAL, SBM1 and SBM2
301 case LFR_MODE_NORMAL:
325 case LFR_MODE_NORMAL:
302 case LFR_MODE_SBM1:
326 case LFR_MODE_SBM1:
303 case LFR_MODE_SBM2:
327 case LFR_MODE_SBM2:
304 waveform_isr_normal_sbm1_sbm2();
328 waveform_isr_normal_sbm1_sbm2();
305 break;
329 break;
306 //******
330 //******
307 // BURST
331 // BURST
308 case LFR_MODE_BURST:
332 case LFR_MODE_BURST:
309 waveforms_isr_burst();
333 waveforms_isr_burst();
310 break;
334 break;
311 //********
335 //********
312 // DEFAULT
336 // DEFAULT
313 default:
337 default:
314 break;
338 break;
315 }
339 }
316 }
340 }
317
341
318 //************
342 //************
319 // RTEMS TASKS
343 // RTEMS TASKS
320
344
321 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
345 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
322 {
346 {
323 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
347 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
324 *
348 *
325 * @param unused is the starting argument of the RTEMS task
349 * @param unused is the starting argument of the RTEMS task
326 *
350 *
327 * The following data packets are sent by this task:
351 * The following data packets are sent by this task:
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
352 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
353 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
330 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
354 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
331 *
355 *
332 */
356 */
333
357
334 rtems_event_set event_out;
358 rtems_event_set event_out;
335 rtems_id queue_id;
359 rtems_id queue_id;
336 rtems_status_code status;
360 rtems_status_code status;
337 ring_node *ring_node_swf1_extracted_ptr;
361 ring_node *ring_node_swf1_extracted_ptr;
338 ring_node *ring_node_swf2_extracted_ptr;
362 ring_node *ring_node_swf2_extracted_ptr;
339
363
340 event_out = EVENT_SETS_NONE_PENDING;
364 event_out = EVENT_SETS_NONE_PENDING;
341 queue_id = RTEMS_ID_NONE;
365 queue_id = RTEMS_ID_NONE;
342
366
343 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
367 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
344 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
368 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
345
369
346 status = get_message_queue_id_send( &queue_id );
370 status = get_message_queue_id_send( &queue_id );
347 if (status != RTEMS_SUCCESSFUL)
371 if (status != RTEMS_SUCCESSFUL)
348 {
372 {
349 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
373 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
350 }
374 }
351
375
352 BOOT_PRINTF("in WFRM ***\n");
376 BOOT_PRINTF("in WFRM ***\n");
353
377
354 while(1){
378 while(1){
355 // wait for an RTEMS_EVENT
379 // wait for an RTEMS_EVENT
356 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
380 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
357 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
381 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
358
382
359 if (event_out == RTEMS_EVENT_MODE_NORMAL)
383 if (event_out == RTEMS_EVENT_MODE_NORMAL)
360 {
384 {
361 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
385 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
362 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
386 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
363 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
387 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
364 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
388 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
365 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
389 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
366 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
390 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
367 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
391 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
368 }
392 }
369 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
393 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
370 {
394 {
371 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
395 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
372 }
396 }
373 }
397 }
374 }
398 }
375
399
376 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
400 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
377 {
401 {
378 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
402 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
379 *
403 *
380 * @param unused is the starting argument of the RTEMS task
404 * @param unused is the starting argument of the RTEMS task
381 *
405 *
382 * The following data packet is sent by this task:
406 * The following data packet is sent by this task:
383 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
407 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
384 *
408 *
385 */
409 */
386
410
387 rtems_event_set event_out;
411 rtems_event_set event_out;
388 rtems_id queue_id;
412 rtems_id queue_id;
389 rtems_status_code status;
413 rtems_status_code status;
390 ring_node ring_node_cwf3_light;
414 ring_node ring_node_cwf3_light;
391 ring_node *ring_node_to_send_cwf;
415 ring_node *ring_node_to_send_cwf;
392
416
393 event_out = EVENT_SETS_NONE_PENDING;
417 event_out = EVENT_SETS_NONE_PENDING;
394 queue_id = RTEMS_ID_NONE;
418 queue_id = RTEMS_ID_NONE;
395
419
396 status = get_message_queue_id_send( &queue_id );
420 status = get_message_queue_id_send( &queue_id );
397 if (status != RTEMS_SUCCESSFUL)
421 if (status != RTEMS_SUCCESSFUL)
398 {
422 {
399 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
423 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
400 }
424 }
401
425
402 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
426 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
403
427
404 // init the ring_node_cwf3_light structure
428 // init the ring_node_cwf3_light structure
405 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
429 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
406 ring_node_cwf3_light.coarseTime = INIT_CHAR;
430 ring_node_cwf3_light.coarseTime = INIT_CHAR;
407 ring_node_cwf3_light.fineTime = INIT_CHAR;
431 ring_node_cwf3_light.fineTime = INIT_CHAR;
408 ring_node_cwf3_light.next = NULL;
432 ring_node_cwf3_light.next = NULL;
409 ring_node_cwf3_light.previous = NULL;
433 ring_node_cwf3_light.previous = NULL;
410 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
434 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
411 ring_node_cwf3_light.status = INIT_CHAR;
435 ring_node_cwf3_light.status = INIT_CHAR;
412
436
413 BOOT_PRINTF("in CWF3 ***\n");
437 BOOT_PRINTF("in CWF3 ***\n");
414
438
415 while(1){
439 while(1){
416 // wait for an RTEMS_EVENT
440 // wait for an RTEMS_EVENT
417 rtems_event_receive( RTEMS_EVENT_0,
441 rtems_event_receive( RTEMS_EVENT_0,
418 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
442 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
419 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
443 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
420 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
444 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
421 {
445 {
422 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
446 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
423 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
447 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
424 {
448 {
425 PRINTF("send CWF_LONG_F3\n");
449 PRINTF("send CWF_LONG_F3\n");
426 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
450 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
427 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
451 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
428 }
452 }
429 else
453 else
430 {
454 {
431 PRINTF("send CWF_F3 (light)\n");
455 PRINTF("send CWF_F3 (light)\n");
432 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
456 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
433 }
457 }
434
458
435 }
459 }
436 else
460 else
437 {
461 {
438 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
462 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
439 }
463 }
440 }
464 }
441 }
465 }
442
466
443 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
467 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
444 {
468 {
445 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
469 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
446 *
470 *
447 * @param unused is the starting argument of the RTEMS task
471 * @param unused is the starting argument of the RTEMS task
448 *
472 *
449 * The following data packet is sent by this function:
473 * The following data packet is sent by this function:
450 * - TM_LFR_SCIENCE_BURST_CWF_F2
474 * - TM_LFR_SCIENCE_BURST_CWF_F2
451 * - TM_LFR_SCIENCE_SBM2_CWF_F2
475 * - TM_LFR_SCIENCE_SBM2_CWF_F2
452 *
476 *
453 */
477 */
454
478
455 rtems_event_set event_out;
479 rtems_event_set event_out;
456 rtems_id queue_id;
480 rtems_id queue_id;
457 rtems_status_code status;
481 rtems_status_code status;
458 ring_node *ring_node_to_send;
482 ring_node *ring_node_to_send;
459 unsigned long long int acquisitionTimeF0_asLong;
483 unsigned long long int acquisitionTimeF0_asLong;
460
484
461 event_out = EVENT_SETS_NONE_PENDING;
485 event_out = EVENT_SETS_NONE_PENDING;
462 queue_id = RTEMS_ID_NONE;
486 queue_id = RTEMS_ID_NONE;
463
487
464 acquisitionTimeF0_asLong = INIT_CHAR;
488 acquisitionTimeF0_asLong = INIT_CHAR;
465
489
466 status = get_message_queue_id_send( &queue_id );
490 status = get_message_queue_id_send( &queue_id );
467 if (status != RTEMS_SUCCESSFUL)
491 if (status != RTEMS_SUCCESSFUL)
468 {
492 {
469 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
493 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
470 }
494 }
471
495
472 BOOT_PRINTF("in CWF2 ***\n");
496 BOOT_PRINTF("in CWF2 ***\n");
473
497
474 while(1){
498 while(1){
475 // wait for an RTEMS_EVENT// send the snapshot when built
499 // wait for an RTEMS_EVENT// send the snapshot when built
476 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
500 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
477 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
501 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
478 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
502 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
479 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
503 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
480 if (event_out == RTEMS_EVENT_MODE_BURST)
504 if (event_out == RTEMS_EVENT_MODE_BURST)
481 { // data are sent whatever the transition time
505 { // data are sent whatever the transition time
482 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
506 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
483 }
507 }
484 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
508 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
485 {
509 {
486 if ( lfrCurrentMode == LFR_MODE_SBM2 )
510 if ( lfrCurrentMode == LFR_MODE_SBM2 )
487 {
511 {
488 // data are sent depending on the transition time
512 // data are sent depending on the transition time
489 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
513 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
490 {
514 {
491 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
515 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
492 }
516 }
493 }
517 }
494 // launch snapshot extraction if needed
518 // launch snapshot extraction if needed
495 if (extractSWF2 == true)
519 if (extractSWF2 == true)
496 {
520 {
497 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
521 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
498 // extract the snapshot
522 // extract the snapshot
499 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
523 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
500 &ring_node_swf2_extracted, swf2_extracted );
524 &ring_node_swf2_extracted, swf2_extracted );
501 extractSWF2 = false;
525 extractSWF2 = false;
502 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
526 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
503 }
527 }
504 if (swf0_ready_flag_f2 == true)
528 if (swf0_ready_flag_f2 == true)
505 {
529 {
506 extractSWF2 = true;
530 extractSWF2 = true;
507 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
531 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
508 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
532 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
509 swf0_ready_flag_f2 = false;
533 swf0_ready_flag_f2 = false;
510 }
534 }
511 }
535 }
512 }
536 }
513 }
537 }
514
538
515 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
539 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
516 {
540 {
517 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
541 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
518 *
542 *
519 * @param unused is the starting argument of the RTEMS task
543 * @param unused is the starting argument of the RTEMS task
520 *
544 *
521 * The following data packet is sent by this function:
545 * The following data packet is sent by this function:
522 * - TM_LFR_SCIENCE_SBM1_CWF_F1
546 * - TM_LFR_SCIENCE_SBM1_CWF_F1
523 *
547 *
524 */
548 */
525
549
526 rtems_event_set event_out;
550 rtems_event_set event_out;
527 rtems_id queue_id;
551 rtems_id queue_id;
528 rtems_status_code status;
552 rtems_status_code status;
529
553
530 ring_node *ring_node_to_send_cwf;
554 ring_node *ring_node_to_send_cwf;
531
555
532 event_out = EVENT_SETS_NONE_PENDING;
556 event_out = EVENT_SETS_NONE_PENDING;
533 queue_id = RTEMS_ID_NONE;
557 queue_id = RTEMS_ID_NONE;
534
558
535 status = get_message_queue_id_send( &queue_id );
559 status = get_message_queue_id_send( &queue_id );
536 if (status != RTEMS_SUCCESSFUL)
560 if (status != RTEMS_SUCCESSFUL)
537 {
561 {
538 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
562 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
539 }
563 }
540
564
541 BOOT_PRINTF("in CWF1 ***\n");
565 BOOT_PRINTF("in CWF1 ***\n");
542
566
543 while(1){
567 while(1){
544 // wait for an RTEMS_EVENT
568 // wait for an RTEMS_EVENT
545 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
569 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
546 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
570 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
547 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
571 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
548 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
572 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
549 if (lfrCurrentMode == LFR_MODE_SBM1)
573 if (lfrCurrentMode == LFR_MODE_SBM1)
550 {
574 {
551 // data are sent depending on the transition time
575 // data are sent depending on the transition time
552 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
576 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
553 {
577 {
554 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
578 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
555 }
579 }
556 }
580 }
557 // launch snapshot extraction if needed
581 // launch snapshot extraction if needed
558 if (extractSWF1 == true)
582 if (extractSWF1 == true)
559 {
583 {
560 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
584 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
561 // launch the snapshot extraction
585 // launch the snapshot extraction
562 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
586 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
563 extractSWF1 = false;
587 extractSWF1 = false;
564 }
588 }
565 if (swf0_ready_flag_f1 == true)
589 if (swf0_ready_flag_f1 == true)
566 {
590 {
567 extractSWF1 = true;
591 extractSWF1 = true;
568 swf0_ready_flag_f1 = false; // this step shall be executed only one time
592 swf0_ready_flag_f1 = false; // this step shall be executed only one time
569 }
593 }
570 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
594 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
571 {
595 {
572 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
596 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
573 swf1_ready = false;
597 swf1_ready = false;
574 swf2_ready = false;
598 swf2_ready = false;
575 }
599 }
576 }
600 }
577 }
601 }
578
602
579 rtems_task swbd_task(rtems_task_argument argument)
603 rtems_task swbd_task(rtems_task_argument argument)
580 {
604 {
581 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
605 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
582 *
606 *
583 * @param unused is the starting argument of the RTEMS task
607 * @param unused is the starting argument of the RTEMS task
584 *
608 *
585 */
609 */
586
610
587 rtems_event_set event_out;
611 rtems_event_set event_out;
588 unsigned long long int acquisitionTimeF0_asLong;
612 unsigned long long int acquisitionTimeF0_asLong;
589
613
590 event_out = EVENT_SETS_NONE_PENDING;
614 event_out = EVENT_SETS_NONE_PENDING;
591 acquisitionTimeF0_asLong = INIT_CHAR;
615 acquisitionTimeF0_asLong = INIT_CHAR;
592
616
593 BOOT_PRINTF("in SWBD ***\n")
617 BOOT_PRINTF("in SWBD ***\n")
594
618
595 while(1){
619 while(1){
596 // wait for an RTEMS_EVENT
620 // wait for an RTEMS_EVENT
597 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
621 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
598 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
622 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
599 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
623 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
600 {
624 {
601 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
625 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
602 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
626 build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong,
603 &ring_node_swf1_extracted, swf1_extracted );
627 &ring_node_swf1_extracted, swf1_extracted );
604 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
628 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
605 }
629 }
606 else
630 else
607 {
631 {
608 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
632 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
609 }
633 }
610 }
634 }
611 }
635 }
612
636
613 //******************
637 //******************
614 // general functions
638 // general functions
615
639
616 void WFP_init_rings( void )
640 void WFP_init_rings( void )
617 {
641 {
618 // F0 RING
642 // F0 RING
619 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
643 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
620 // F1 RING
644 // F1 RING
621 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
645 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
622 // F2 RING
646 // F2 RING
623 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
647 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
624 // F3 RING
648 // F3 RING
625 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
649 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
626
650
627 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
651 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
628 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
652 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
629
653
630 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
654 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
631 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
655 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
632 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
656 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
633 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
657 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
634 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
658 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
635 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
659 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
636 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
660 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
637 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
661 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
638
662
639 }
663 }
640
664
641 void WFP_reset_current_ring_nodes( void )
665 void WFP_reset_current_ring_nodes( void )
642 {
666 {
643 current_ring_node_f0 = waveform_ring_f0[0].next;
667 current_ring_node_f0 = waveform_ring_f0[0].next;
644 current_ring_node_f1 = waveform_ring_f1[0].next;
668 current_ring_node_f1 = waveform_ring_f1[0].next;
645 current_ring_node_f2 = waveform_ring_f2[0].next;
669 current_ring_node_f2 = waveform_ring_f2[0].next;
646 current_ring_node_f3 = waveform_ring_f3[0].next;
670 current_ring_node_f3 = waveform_ring_f3[0].next;
647
671
648 ring_node_to_send_swf_f0 = waveform_ring_f0;
672 ring_node_to_send_swf_f0 = waveform_ring_f0;
649 ring_node_to_send_swf_f1 = waveform_ring_f1;
673 ring_node_to_send_swf_f1 = waveform_ring_f1;
650 ring_node_to_send_swf_f2 = waveform_ring_f2;
674 ring_node_to_send_swf_f2 = waveform_ring_f2;
651
675
652 ring_node_to_send_cwf_f1 = waveform_ring_f1;
676 ring_node_to_send_cwf_f1 = waveform_ring_f1;
653 ring_node_to_send_cwf_f2 = waveform_ring_f2;
677 ring_node_to_send_cwf_f2 = waveform_ring_f2;
654 ring_node_to_send_cwf_f3 = waveform_ring_f3;
678 ring_node_to_send_cwf_f3 = waveform_ring_f3;
655 }
679 }
656
680
657 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
681 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
658 {
682 {
659 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
683 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
660 *
684 *
661 * @param waveform points to the buffer containing the data that will be send.
685 * @param waveform points to the buffer containing the data that will be send.
662 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
686 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
663 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
687 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
664 * contain information to setup the transmission of the data packets.
688 * contain information to setup the transmission of the data packets.
665 *
689 *
666 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
690 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
667 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
691 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
668 *
692 *
669 */
693 */
670
694
671 unsigned int i;
695 unsigned int i;
672 unsigned int j;
696 unsigned int j;
673 int ret;
697 int ret;
674 rtems_status_code status;
698 rtems_status_code status;
675
699
676 char *sample;
700 char *sample;
677 int *dataPtr;
701 int *dataPtr;
678
702
679 ret = LFR_DEFAULT;
703 ret = LFR_DEFAULT;
680
704
681 dataPtr = (int*) ring_node_to_send->buffer_address;
705 dataPtr = (int*) ring_node_to_send->buffer_address;
682
706
683 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
707 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
684 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
708 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
685
709
686 //**********************
710 //**********************
687 // BUILD CWF3_light DATA
711 // BUILD CWF3_light DATA
688 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
712 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
689 {
713 {
690 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
714 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
691 for (j=0; j < CWF_BLK_SIZE; j++)
715 for (j=0; j < CWF_BLK_SIZE; j++)
692 {
716 {
693 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
717 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
694 }
718 }
695 }
719 }
696
720
697 // SEND PACKET
721 // SEND PACKET
698 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
722 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
699 if (status != RTEMS_SUCCESSFUL) {
723 if (status != RTEMS_SUCCESSFUL) {
700 ret = LFR_DEFAULT;
724 ret = LFR_DEFAULT;
701 }
725 }
702
726
703 return ret;
727 return ret;
704 }
728 }
705
729
706 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
730 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
707 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
731 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
708 {
732 {
709 unsigned long long int acquisitionTimeAsLong;
733 unsigned long long int acquisitionTimeAsLong;
710 unsigned char localAcquisitionTime[BYTES_PER_TIME];
734 unsigned char localAcquisitionTime[BYTES_PER_TIME];
711 double deltaT;
735 double deltaT;
712
736
713 deltaT = INIT_FLOAT;
737 deltaT = INIT_FLOAT;
714
738
715 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
739 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
716 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
740 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
717 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
741 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
718 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
742 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
719 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
743 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
720 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
744 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
721
745
722 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
746 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
723 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
747 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
724 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
748 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
725 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
749 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
726 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
750 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
727 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
751 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
728
752
729 switch( sid )
753 switch( sid )
730 {
754 {
731 case SID_NORM_SWF_F0:
755 case SID_NORM_SWF_F0:
732 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
756 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
733 break;
757 break;
734
758
735 case SID_NORM_SWF_F1:
759 case SID_NORM_SWF_F1:
736 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
760 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
737 break;
761 break;
738
762
739 case SID_NORM_SWF_F2:
763 case SID_NORM_SWF_F2:
740 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
764 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
741 break;
765 break;
742
766
743 case SID_SBM1_CWF_F1:
767 case SID_SBM1_CWF_F1:
744 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
768 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
745 break;
769 break;
746
770
747 case SID_SBM2_CWF_F2:
771 case SID_SBM2_CWF_F2:
748 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
772 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
749 break;
773 break;
750
774
751 case SID_BURST_CWF_F2:
775 case SID_BURST_CWF_F2:
752 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
776 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
753 break;
777 break;
754
778
755 case SID_NORM_CWF_F3:
779 case SID_NORM_CWF_F3:
756 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
780 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
757 break;
781 break;
758
782
759 case SID_NORM_CWF_LONG_F3:
783 case SID_NORM_CWF_LONG_F3:
760 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
784 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
761 break;
785 break;
762
786
763 default:
787 default:
764 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
788 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
765 deltaT = 0.;
789 deltaT = 0.;
766 break;
790 break;
767 }
791 }
768
792
769 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
793 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
770 //
794 //
771 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
795 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
772 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
796 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
773 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
797 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
774 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
798 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
775 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
799 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
776 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
800 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
777
801
778 }
802 }
779
803
780 void build_snapshot_from_ring( ring_node *ring_node_to_send,
804 void build_snapshot_from_ring( ring_node *ring_node_to_send,
781 unsigned char frequencyChannel,
805 unsigned char frequencyChannel,
782 unsigned long long int acquisitionTimeF0_asLong,
806 unsigned long long int acquisitionTimeF0_asLong,
783 ring_node *ring_node_swf_extracted,
807 ring_node *ring_node_swf_extracted,
784 int *swf_extracted)
808 int *swf_extracted)
785 {
809 {
786 unsigned int i;
810 unsigned int i;
787 unsigned int node;
811 unsigned int node;
788 unsigned long long int centerTime_asLong;
812 unsigned long long int centerTime_asLong;
789 unsigned long long int acquisitionTime_asLong;
813 unsigned long long int acquisitionTime_asLong;
790 unsigned long long int bufferAcquisitionTime_asLong;
814 unsigned long long int bufferAcquisitionTime_asLong;
791 unsigned char *ptr1;
815 unsigned char *ptr1;
792 unsigned char *ptr2;
816 unsigned char *ptr2;
793 unsigned char *timeCharPtr;
817 unsigned char *timeCharPtr;
794 unsigned char nb_ring_nodes;
818 unsigned char nb_ring_nodes;
795 unsigned long long int frequency_asLong;
819 unsigned long long int frequency_asLong;
796 unsigned long long int nbTicksPerSample_asLong;
820 unsigned long long int nbTicksPerSample_asLong;
797 unsigned long long int nbSamplesPart1_asLong;
821 unsigned long long int nbSamplesPart1_asLong;
798 unsigned long long int sampleOffset_asLong;
822 unsigned long long int sampleOffset_asLong;
799
823
800 unsigned int deltaT_F0;
824 unsigned int deltaT_F0;
801 unsigned int deltaT_F1;
825 unsigned int deltaT_F1;
802 unsigned long long int deltaT_F2;
826 unsigned long long int deltaT_F2;
803
827
804 deltaT_F0 = DELTAT_F0;
828 deltaT_F0 = DELTAT_F0;
805 deltaT_F1 = DELTAT_F1;
829 deltaT_F1 = DELTAT_F1;
806 deltaT_F2 = DELTAT_F2;
830 deltaT_F2 = DELTAT_F2;
807 sampleOffset_asLong = INIT_CHAR;
831 sampleOffset_asLong = INIT_CHAR;
808
832
809 // (1) get the f0 acquisition time => the value is passed in argument
833 // (1) get the f0 acquisition time => the value is passed in argument
810
834
811 // (2) compute the central reference time
835 // (2) compute the central reference time
812 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
836 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
813 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
837 acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
814 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
838 bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2)
815 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
839 nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2)
816
840
817 // (3) compute the acquisition time of the current snapshot
841 // (3) compute the acquisition time of the current snapshot
818 switch(frequencyChannel)
842 switch(frequencyChannel)
819 {
843 {
820 case CHANNELF1: // 1 is for F1 = 4096 Hz
844 case CHANNELF1: // 1 is for F1 = 4096 Hz
821 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
845 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
822 nb_ring_nodes = NB_RING_NODES_F1;
846 nb_ring_nodes = NB_RING_NODES_F1;
823 frequency_asLong = FREQ_F1;
847 frequency_asLong = FREQ_F1;
824 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
848 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
825 break;
849 break;
826 case CHANNELF2: // 2 is for F2 = 256 Hz
850 case CHANNELF2: // 2 is for F2 = 256 Hz
827 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
851 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
828 nb_ring_nodes = NB_RING_NODES_F2;
852 nb_ring_nodes = NB_RING_NODES_F2;
829 frequency_asLong = FREQ_F2;
853 frequency_asLong = FREQ_F2;
830 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
854 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
831 break;
855 break;
832 default:
856 default:
833 acquisitionTime_asLong = centerTime_asLong;
857 acquisitionTime_asLong = centerTime_asLong;
834 nb_ring_nodes = 0;
858 nb_ring_nodes = 0;
835 frequency_asLong = FREQ_F2;
859 frequency_asLong = FREQ_F2;
836 nbTicksPerSample_asLong = TICKS_PER_T2;
860 nbTicksPerSample_asLong = TICKS_PER_T2;
837 break;
861 break;
838 }
862 }
839
863
840 //*****************************************************************************
864 //*****************************************************************************
841 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
865 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
842 node = 0;
866 node = 0;
843 while ( node < nb_ring_nodes)
867 while ( node < nb_ring_nodes)
844 {
868 {
845 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
869 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
846 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
870 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
847 {
871 {
848 node = nb_ring_nodes;
872 node = nb_ring_nodes;
849 }
873 }
850 else
874 else
851 {
875 {
852 node = node + 1;
876 node = node + 1;
853 ring_node_to_send = ring_node_to_send->previous;
877 ring_node_to_send = ring_node_to_send->previous;
854 }
878 }
855 }
879 }
856
880
857 // (5) compute the number of samples to take in the current buffer
881 // (5) compute the number of samples to take in the current buffer
858 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
882 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
859 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
883 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
860
884
861 // (6) compute the final acquisition time
885 // (6) compute the final acquisition time
862 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
886 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
863 (sampleOffset_asLong * nbTicksPerSample_asLong);
887 (sampleOffset_asLong * nbTicksPerSample_asLong);
864
888
865 // (7) copy the acquisition time at the beginning of the extrated snapshot
889 // (7) copy the acquisition time at the beginning of the extrated snapshot
866 ptr1 = (unsigned char*) &acquisitionTime_asLong;
890 ptr1 = (unsigned char*) &acquisitionTime_asLong;
867 // fine time
891 // fine time
868 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
892 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
869 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
893 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
870 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
894 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
871 // coarse time
895 // coarse time
872 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
896 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
873 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
897 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
874 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
898 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
875 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
899 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
876 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
900 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
877
901
878 // re set the synchronization bit
902 // re set the synchronization bit
879 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
903 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
880 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
904 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
881
905
882 if ( (nbSamplesPart1_asLong > NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
906 if ( (nbSamplesPart1_asLong > NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
883 {
907 {
884 nbSamplesPart1_asLong = 0;
908 nbSamplesPart1_asLong = 0;
885 }
909 }
886 // copy the part 1 of the snapshot in the extracted buffer
910 // copy the part 1 of the snapshot in the extracted buffer
887 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
911 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
888 {
912 {
889 swf_extracted[i] =
913 swf_extracted[i] =
890 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
914 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
891 }
915 }
892 // copy the part 2 of the snapshot in the extracted buffer
916 // copy the part 2 of the snapshot in the extracted buffer
893 ring_node_to_send = ring_node_to_send->next;
917 ring_node_to_send = ring_node_to_send->next;
894 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
918 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
895 {
919 {
896 swf_extracted[i] =
920 swf_extracted[i] =
897 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
921 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
898 }
922 }
899 }
923 }
900
924
901 double computeCorrection( unsigned char *timePtr )
925 double computeCorrection( unsigned char *timePtr )
902 {
926 {
903 unsigned long long int acquisitionTime;
927 unsigned long long int acquisitionTime;
904 unsigned long long int centerTime;
928 unsigned long long int centerTime;
905 unsigned long long int previousTick;
929 unsigned long long int previousTick;
906 unsigned long long int nextTick;
930 unsigned long long int nextTick;
907 unsigned long long int deltaPreviousTick;
931 unsigned long long int deltaPreviousTick;
908 unsigned long long int deltaNextTick;
932 unsigned long long int deltaNextTick;
909 double deltaPrevious_ms;
933 double deltaPrevious_ms;
910 double deltaNext_ms;
934 double deltaNext_ms;
911 double correctionInF2;
935 double correctionInF2;
912
936
913 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
937 correctionInF2 = 0; //set to default value (Don_Initialisation_P2)
914
938
915 // get acquisition time in fine time ticks
939 // get acquisition time in fine time ticks
916 acquisitionTime = get_acquisition_time( timePtr );
940 acquisitionTime = get_acquisition_time( timePtr );
917
941
918 // compute center time
942 // compute center time
919 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
943 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
920 previousTick = centerTime - (centerTime & INT16_ALL_F);
944 previousTick = centerTime - (centerTime & INT16_ALL_F);
921 nextTick = previousTick + TICKS_PER_S;
945 nextTick = previousTick + TICKS_PER_S;
922
946
923 deltaPreviousTick = centerTime - previousTick;
947 deltaPreviousTick = centerTime - previousTick;
924 deltaNextTick = nextTick - centerTime;
948 deltaNextTick = nextTick - centerTime;
925
949
926 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
950 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
927 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
951 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
928
952
929 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
953 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
930
954
931 // which tick is the closest?
955 // which tick is the closest?
932 if (deltaPreviousTick > deltaNextTick)
956 if (deltaPreviousTick > deltaNextTick)
933 {
957 {
934 // the snapshot center is just before the second => increase delta_snapshot
958 // the snapshot center is just before the second => increase delta_snapshot
935 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
959 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
936 }
960 }
937 else
961 else
938 {
962 {
939 // the snapshot center is just after the second => decrease delta_snapshot
963 // the snapshot center is just after the second => decrease delta_snapshot
940 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
964 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
941 }
965 }
942
966
943 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
967 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
944
968
945 return correctionInF2;
969 return correctionInF2;
946 }
970 }
947
971
948 void applyCorrection( double correction )
972 void applyCorrection( double correction )
949 {
973 {
950 int correctionInt;
974 int correctionInt;
951
975
952 correctionInt = 0;
976 correctionInt = 0;
953
977
954 if (correction >= 0.)
978 if (correction >= 0.)
955 {
979 {
956 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
980 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
957 {
981 {
958 correctionInt = ONE_TICK_CORR;
982 correctionInt = ONE_TICK_CORR;
959 }
983 }
960 else
984 else
961 {
985 {
962 correctionInt = CORR_MULT * floor(correction);
986 correctionInt = CORR_MULT * floor(correction);
963 }
987 }
964 }
988 }
965 else
989 else
966 {
990 {
967 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
991 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
968 {
992 {
969 correctionInt = -ONE_TICK_CORR;
993 correctionInt = -ONE_TICK_CORR;
970 }
994 }
971 else
995 else
972 {
996 {
973 correctionInt = CORR_MULT * ceil(correction);
997 correctionInt = CORR_MULT * ceil(correction);
974 }
998 }
975 }
999 }
976 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
1000 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
977 }
1001 }
978
1002
979 void snapshot_resynchronization( unsigned char *timePtr )
1003 void snapshot_resynchronization( unsigned char *timePtr )
980 {
1004 {
981 /** This function compute a correction to apply on delta_snapshot.
1005 /** This function compute a correction to apply on delta_snapshot.
982 *
1006 *
983 *
1007 *
984 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
1008 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
985 *
1009 *
986 * @return void
1010 * @return void
987 *
1011 *
988 */
1012 */
989
1013
990 static double correction = INIT_FLOAT;
1014 static double correction = INIT_FLOAT;
991 static resynchro_state state = MEASURE;
1015 static resynchro_state state = MEASURE;
992 static unsigned int nbSnapshots = 0;
1016 static unsigned int nbSnapshots = 0;
993
1017
994 int correctionInt;
1018 int correctionInt;
995
1019
996 correctionInt = 0;
1020 correctionInt = 0;
997
1021
998 switch (state)
1022 switch (state)
999 {
1023 {
1000
1024
1001 case MEASURE:
1025 case MEASURE:
1002 // ********
1026 // ********
1003 PRINTF1("MEASURE === %d\n", nbSnapshots);
1027 PRINTF1("MEASURE === %d\n", nbSnapshots);
1004 state = CORRECTION;
1028 state = CORRECTION;
1005 correction = computeCorrection( timePtr );
1029 correction = computeCorrection( timePtr );
1006 PRINTF1("MEASURE === correction = %.2f\n", correction );
1030 PRINTF1("MEASURE === correction = %.2f\n", correction );
1007 applyCorrection( correction );
1031 applyCorrection( correction );
1008 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1032 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1009 //****
1033 //****
1010 break;
1034 break;
1011
1035
1012 case CORRECTION:
1036 case CORRECTION:
1013 //************
1037 //************
1014 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1038 PRINTF1("CORRECTION === %d\n", nbSnapshots);
1015 state = MEASURE;
1039 state = MEASURE;
1016 computeCorrection( timePtr );
1040 computeCorrection( timePtr );
1017 set_wfp_delta_snapshot();
1041 set_wfp_delta_snapshot();
1018 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1042 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
1019 //****
1043 //****
1020 break;
1044 break;
1021
1045
1022 default:
1046 default:
1023 break;
1047 break;
1024
1048
1025 }
1049 }
1026
1050
1027 nbSnapshots++;
1051 nbSnapshots++;
1028 }
1052 }
1029
1053
1030 //**************
1054 //**************
1031 // wfp registers
1055 // wfp registers
1032 void reset_wfp_burst_enable( void )
1056 void reset_wfp_burst_enable( void )
1033 {
1057 {
1034 /** This function resets the waveform picker burst_enable register.
1058 /** This function resets the waveform picker burst_enable register.
1035 *
1059 *
1036 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1060 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1037 *
1061 *
1038 */
1062 */
1039
1063
1040 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1064 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1041 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1065 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1042 }
1066 }
1043
1067
1044 void reset_wfp_status( void )
1068 void reset_wfp_status( void )
1045 {
1069 {
1046 /** This function resets the waveform picker status register.
1070 /** This function resets the waveform picker status register.
1047 *
1071 *
1048 * All status bits are set to 0 [new_err full_err full].
1072 * All status bits are set to 0 [new_err full_err full].
1049 *
1073 *
1050 */
1074 */
1051
1075
1052 waveform_picker_regs->status = INT16_ALL_F;
1076 waveform_picker_regs->status = INT16_ALL_F;
1053 }
1077 }
1054
1078
1055 void reset_wfp_buffer_addresses( void )
1079 void reset_wfp_buffer_addresses( void )
1056 {
1080 {
1057 // F0
1081 // F0
1058 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1082 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1059 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1083 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1060 // F1
1084 // F1
1061 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1085 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1062 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1086 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1063 // F2
1087 // F2
1064 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1088 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1065 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1089 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1066 // F3
1090 // F3
1067 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1091 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1068 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1092 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1069 }
1093 }
1070
1094
1071 void reset_waveform_picker_regs( void )
1095 void reset_waveform_picker_regs( void )
1072 {
1096 {
1073 /** This function resets the waveform picker module registers.
1097 /** This function resets the waveform picker module registers.
1074 *
1098 *
1075 * The registers affected by this function are located at the following offset addresses:
1099 * The registers affected by this function are located at the following offset addresses:
1076 * - 0x00 data_shaping
1100 * - 0x00 data_shaping
1077 * - 0x04 run_burst_enable
1101 * - 0x04 run_burst_enable
1078 * - 0x08 addr_data_f0
1102 * - 0x08 addr_data_f0
1079 * - 0x0C addr_data_f1
1103 * - 0x0C addr_data_f1
1080 * - 0x10 addr_data_f2
1104 * - 0x10 addr_data_f2
1081 * - 0x14 addr_data_f3
1105 * - 0x14 addr_data_f3
1082 * - 0x18 status
1106 * - 0x18 status
1083 * - 0x1C delta_snapshot
1107 * - 0x1C delta_snapshot
1084 * - 0x20 delta_f0
1108 * - 0x20 delta_f0
1085 * - 0x24 delta_f0_2
1109 * - 0x24 delta_f0_2
1086 * - 0x28 delta_f1 (obsolet parameter)
1110 * - 0x28 delta_f1 (obsolet parameter)
1087 * - 0x2c delta_f2
1111 * - 0x2c delta_f2
1088 * - 0x30 nb_data_by_buffer
1112 * - 0x30 nb_data_by_buffer
1089 * - 0x34 nb_snapshot_param
1113 * - 0x34 nb_snapshot_param
1090 * - 0x38 start_date
1114 * - 0x38 start_date
1091 * - 0x3c nb_word_in_buffer
1115 * - 0x3c nb_word_in_buffer
1092 *
1116 *
1093 */
1117 */
1094
1118
1095 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1119 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1096
1120
1097 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1121 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1098
1122
1099 reset_wfp_buffer_addresses();
1123 reset_wfp_buffer_addresses();
1100
1124
1101 reset_wfp_status(); // 0x18
1125 reset_wfp_status(); // 0x18
1102
1126
1103 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1127 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1104
1128
1105 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1129 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1106
1130
1107 //the parameter delta_f1 [0x28] is not used anymore
1131 //the parameter delta_f1 [0x28] is not used anymore
1108
1132
1109 set_wfp_delta_f2(); // 0x2c
1133 set_wfp_delta_f2(); // 0x2c
1110
1134
1111 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1135 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1112 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1136 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1113 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1137 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1114 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1138 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1115 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1139 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1116 // 2688 = 8 * 336
1140 // 2688 = 8 * 336
1117 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1141 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1118 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1142 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1119 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1143 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1120 //
1144 //
1121 // coarse time and fine time registers are not initialized, they are volatile
1145 // coarse time and fine time registers are not initialized, they are volatile
1122 //
1146 //
1123 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1147 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1124 }
1148 }
1125
1149
1126 void set_wfp_data_shaping( void )
1150 void set_wfp_data_shaping( void )
1127 {
1151 {
1128 /** This function sets the data_shaping register of the waveform picker module.
1152 /** This function sets the data_shaping register of the waveform picker module.
1129 *
1153 *
1130 * The value is read from one field of the parameter_dump_packet structure:\n
1154 * The value is read from one field of the parameter_dump_packet structure:\n
1131 * bw_sp0_sp1_r0_r1
1155 * bw_sp0_sp1_r0_r1
1132 *
1156 *
1133 */
1157 */
1134
1158
1135 unsigned char data_shaping;
1159 unsigned char data_shaping;
1136
1160
1137 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1161 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1138 // waveform picker : [R1 R0 SP1 SP0 BW]
1162 // waveform picker : [R1 R0 SP1 SP0 BW]
1139
1163
1140 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1164 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1141
1165
1142 waveform_picker_regs->data_shaping =
1166 waveform_picker_regs->data_shaping =
1143 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1167 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1144 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1168 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1145 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1169 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1146 + ( (data_shaping & BIT_2) << 1 ) // R0
1170 + ( (data_shaping & BIT_2) << 1 ) // R0
1147 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1171 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1148 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1172 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1149 }
1173 }
1150
1174
1151 void set_wfp_burst_enable_register( unsigned char mode )
1175 void set_wfp_burst_enable_register( unsigned char mode )
1152 {
1176 {
1153 /** This function sets the waveform picker burst_enable register depending on the mode.
1177 /** This function sets the waveform picker burst_enable register depending on the mode.
1154 *
1178 *
1155 * @param mode is the LFR mode to launch.
1179 * @param mode is the LFR mode to launch.
1156 *
1180 *
1157 * The burst bits shall be before the enable bits.
1181 * The burst bits shall be before the enable bits.
1158 *
1182 *
1159 */
1183 */
1160
1184
1161 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1185 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1162 // the burst bits shall be set first, before the enable bits
1186 // the burst bits shall be set first, before the enable bits
1163 switch(mode) {
1187 switch(mode) {
1164 case LFR_MODE_NORMAL:
1188 case LFR_MODE_NORMAL:
1165 case LFR_MODE_SBM1:
1189 case LFR_MODE_SBM1:
1166 case LFR_MODE_SBM2:
1190 case LFR_MODE_SBM2:
1167 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1191 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1168 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0
1192 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0
1169 break;
1193 break;
1170 case LFR_MODE_BURST:
1194 case LFR_MODE_BURST:
1171 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1195 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1172 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2
1196 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2
1173 break;
1197 break;
1174 default:
1198 default:
1175 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1199 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1176 break;
1200 break;
1177 }
1201 }
1178 }
1202 }
1179
1203
1180 void set_wfp_delta_snapshot( void )
1204 void set_wfp_delta_snapshot( void )
1181 {
1205 {
1182 /** This function sets the delta_snapshot register of the waveform picker module.
1206 /** This function sets the delta_snapshot register of the waveform picker module.
1183 *
1207 *
1184 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1208 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1185 * - sy_lfr_n_swf_p[0]
1209 * - sy_lfr_n_swf_p[0]
1186 * - sy_lfr_n_swf_p[1]
1210 * - sy_lfr_n_swf_p[1]
1187 *
1211 *
1188 */
1212 */
1189
1213
1190 unsigned int delta_snapshot;
1214 unsigned int delta_snapshot;
1191 unsigned int delta_snapshot_in_T2;
1215 unsigned int delta_snapshot_in_T2;
1192
1216
1193 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1217 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1194 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1218 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1195
1219
1196 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1220 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1197 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1221 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1198 }
1222 }
1199
1223
1200 void set_wfp_delta_f0_f0_2( void )
1224 void set_wfp_delta_f0_f0_2( void )
1201 {
1225 {
1202 unsigned int delta_snapshot;
1226 unsigned int delta_snapshot;
1203 unsigned int nb_samples_per_snapshot;
1227 unsigned int nb_samples_per_snapshot;
1204 float delta_f0_in_float;
1228 float delta_f0_in_float;
1205
1229
1206 delta_snapshot = waveform_picker_regs->delta_snapshot;
1230 delta_snapshot = waveform_picker_regs->delta_snapshot;
1207 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1231 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1208 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1232 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1209
1233
1210 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1234 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1211 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2;
1235 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2;
1212 }
1236 }
1213
1237
1214 void set_wfp_delta_f1( void )
1238 void set_wfp_delta_f1( void )
1215 {
1239 {
1216 /** Sets the value of the delta_f1 parameter
1240 /** Sets the value of the delta_f1 parameter
1217 *
1241 *
1218 * @param void
1242 * @param void
1219 *
1243 *
1220 * @return void
1244 * @return void
1221 *
1245 *
1222 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1246 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1223 *
1247 *
1224 */
1248 */
1225
1249
1226 unsigned int delta_snapshot;
1250 unsigned int delta_snapshot;
1227 unsigned int nb_samples_per_snapshot;
1251 unsigned int nb_samples_per_snapshot;
1228 float delta_f1_in_float;
1252 float delta_f1_in_float;
1229
1253
1230 delta_snapshot = waveform_picker_regs->delta_snapshot;
1254 delta_snapshot = waveform_picker_regs->delta_snapshot;
1231 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1255 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1232 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1256 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1233
1257
1234 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1258 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1235 }
1259 }
1236
1260
1237 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1261 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1238 {
1262 {
1239 /** Sets the value of the delta_f2 parameter
1263 /** Sets the value of the delta_f2 parameter
1240 *
1264 *
1241 * @param void
1265 * @param void
1242 *
1266 *
1243 * @return void
1267 * @return void
1244 *
1268 *
1245 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1269 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1246 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1270 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1247 *
1271 *
1248 */
1272 */
1249
1273
1250 unsigned int delta_snapshot;
1274 unsigned int delta_snapshot;
1251 unsigned int nb_samples_per_snapshot;
1275 unsigned int nb_samples_per_snapshot;
1252
1276
1253 delta_snapshot = waveform_picker_regs->delta_snapshot;
1277 delta_snapshot = waveform_picker_regs->delta_snapshot;
1254 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1278 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1255
1279
1256 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1280 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1257 }
1281 }
1258
1282
1259 //*****************
1283 //*****************
1260 // local parameters
1284 // local parameters
1261
1285
1262 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1286 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1263 {
1287 {
1264 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1288 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1265 *
1289 *
1266 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1290 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1267 * @param sid is the source identifier of the packet being updated.
1291 * @param sid is the source identifier of the packet being updated.
1268 *
1292 *
1269 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1293 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1270 * The sequence counters shall wrap around from 2^14 to zero.
1294 * The sequence counters shall wrap around from 2^14 to zero.
1271 * The sequence counter shall start at zero at startup.
1295 * The sequence counter shall start at zero at startup.
1272 *
1296 *
1273 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1297 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1274 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1298 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1275 *
1299 *
1276 */
1300 */
1277
1301
1278 unsigned short *sequence_cnt;
1302 unsigned short *sequence_cnt;
1279 unsigned short segmentation_grouping_flag;
1303 unsigned short segmentation_grouping_flag;
1280 unsigned short new_packet_sequence_control;
1304 unsigned short new_packet_sequence_control;
1281 rtems_mode initial_mode_set;
1305 rtems_mode initial_mode_set;
1282 rtems_mode current_mode_set;
1306 rtems_mode current_mode_set;
1283 rtems_status_code status;
1307 rtems_status_code status;
1284
1308
1285 initial_mode_set = RTEMS_DEFAULT_MODES;
1309 initial_mode_set = RTEMS_DEFAULT_MODES;
1286 current_mode_set = RTEMS_DEFAULT_MODES;
1310 current_mode_set = RTEMS_DEFAULT_MODES;
1287 sequence_cnt = NULL;
1311 sequence_cnt = NULL;
1288
1312
1289 //******************************************
1313 //******************************************
1290 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1314 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1291 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1315 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1292
1316
1293 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1317 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1294 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1318 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1295 || (sid == SID_BURST_CWF_F2)
1319 || (sid == SID_BURST_CWF_F2)
1296 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1320 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1297 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1321 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1298 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1322 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1299 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1323 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1300 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1324 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1301 {
1325 {
1302 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1326 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1303 }
1327 }
1304 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1328 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1305 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1329 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1306 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1330 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1307 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1331 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1308 {
1332 {
1309 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1333 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1310 }
1334 }
1311 else
1335 else
1312 {
1336 {
1313 sequence_cnt = (unsigned short *) NULL;
1337 sequence_cnt = (unsigned short *) NULL;
1314 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1338 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1315 }
1339 }
1316
1340
1317 if (sequence_cnt != NULL)
1341 if (sequence_cnt != NULL)
1318 {
1342 {
1319 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1343 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1320 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1344 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1321
1345
1322 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1346 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1323
1347
1324 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1348 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1325 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1349 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1326
1350
1327 // increment the sequence counter
1351 // increment the sequence counter
1328 if ( *sequence_cnt < SEQ_CNT_MAX)
1352 if ( *sequence_cnt < SEQ_CNT_MAX)
1329 {
1353 {
1330 *sequence_cnt = *sequence_cnt + 1;
1354 *sequence_cnt = *sequence_cnt + 1;
1331 }
1355 }
1332 else
1356 else
1333 {
1357 {
1334 *sequence_cnt = 0;
1358 *sequence_cnt = 0;
1335 }
1359 }
1336 }
1360 }
1337
1361
1338 //*************************************
1362 //*************************************
1339 // RESTORE THE MODE OF THE CALLING TASK
1363 // RESTORE THE MODE OF THE CALLING TASK
1340 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1364 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1341 }
1365 }
1342
1366
@@ -1,93 +1,117
1 /*------------------------------------------------------------------------------
2 -- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW),
3 -- This file is a part of the LFR FSW
4 -- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS
5 --
6 -- This program is free software; you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation; either version 2 of the License, or
9 -- (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------*/
20 /*-- Author : Paul Leroy
21 -- Contact : Alexis Jeandet
22 -- Mail : alexis.jeandet@lpp.polytechnique.fr
23 ----------------------------------------------------------------------------*/
24
1 #define NB_VALUES_PER_SM 25
25 #define NB_VALUES_PER_SM 25
2 #define NB_BINS_PER_SM 128
26 #define NB_BINS_PER_SM 128
3
27
4 #define NB_BINS_COMPRESSED_SM_F0 11
28 #define NB_BINS_COMPRESSED_SM_F0 11
5 #define ASM_F0_INDICE_START 17 // 88 bins
29 #define ASM_F0_INDICE_START 17 // 88 bins
6 #define NB_BINS_TO_AVERAGE_ASM_F0 8
30 #define NB_BINS_TO_AVERAGE_ASM_F0 8
7
31
8 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
32 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
9 {
33 {
10 int frequencyBin;
34 int frequencyBin;
11 int asmComponent;
35 int asmComponent;
12 unsigned int offsetASM;
36 unsigned int offsetASM;
13 unsigned int offsetASMReorganized;
37 unsigned int offsetASMReorganized;
14
38
15 // BUILD DATA
39 // BUILD DATA
16 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
40 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
17 {
41 {
18 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
42 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
19 {
43 {
20 offsetASMReorganized =
44 offsetASMReorganized =
21 frequencyBin * NB_VALUES_PER_SM
45 frequencyBin * NB_VALUES_PER_SM
22 + asmComponent;
46 + asmComponent;
23 offsetASM =
47 offsetASM =
24 asmComponent * NB_BINS_PER_SM
48 asmComponent * NB_BINS_PER_SM
25 + frequencyBin;
49 + frequencyBin;
26 averaged_spec_mat_reorganized[offsetASMReorganized ] =
50 averaged_spec_mat_reorganized[offsetASMReorganized ] =
27 averaged_spec_mat[ offsetASM ] / divider;
51 averaged_spec_mat[ offsetASM ] / divider;
28 }
52 }
29 }
53 }
30 }
54 }
31
55
32 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
56 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
33 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
57 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
34 {
58 {
35 int frequencyBin;
59 int frequencyBin;
36 int asmComponent;
60 int asmComponent;
37 int offsetASM;
61 int offsetASM;
38 int offsetCompressed;
62 int offsetCompressed;
39 int k;
63 int k;
40
64
41 // BUILD DATA
65 // BUILD DATA
42 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
66 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
43 {
67 {
44 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
68 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
45 {
69 {
46 offsetCompressed = // NO TIME OFFSET
70 offsetCompressed = // NO TIME OFFSET
47 frequencyBin * NB_VALUES_PER_SM
71 frequencyBin * NB_VALUES_PER_SM
48 + asmComponent;
72 + asmComponent;
49 offsetASM = // NO TIME OFFSET
73 offsetASM = // NO TIME OFFSET
50 asmComponent * NB_BINS_PER_SM
74 asmComponent * NB_BINS_PER_SM
51 + ASMIndexStart
75 + ASMIndexStart
52 + frequencyBin * nbBinsToAverage;
76 + frequencyBin * nbBinsToAverage;
53 compressed_spec_mat[ offsetCompressed ] = 0;
77 compressed_spec_mat[ offsetCompressed ] = 0;
54 for ( k = 0; k < nbBinsToAverage; k++ )
78 for ( k = 0; k < nbBinsToAverage; k++ )
55 {
79 {
56 compressed_spec_mat[offsetCompressed ] =
80 compressed_spec_mat[offsetCompressed ] =
57 ( compressed_spec_mat[ offsetCompressed ]
81 ( compressed_spec_mat[ offsetCompressed ]
58 + averaged_spec_mat[ offsetASM + k ] );
82 + averaged_spec_mat[ offsetASM + k ] );
59 }
83 }
60 compressed_spec_mat[ offsetCompressed ] =
84 compressed_spec_mat[ offsetCompressed ] =
61 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
85 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
62 }
86 }
63 }
87 }
64 }
88 }
65
89
66 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
90 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
67 {
91 {
68 unsigned int i;
92 unsigned int i;
69 float re;
93 float re;
70 float im;
94 float im;
71
95
72 for (i=0; i<NB_BINS_PER_SM; i++){
96 for (i=0; i<NB_BINS_PER_SM; i++){
73 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
97 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
74 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
98 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
75 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
99 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
76 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
100 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
77 }
101 }
78
102
79 }
103 }
80
104
81 void ASM_patch( float *inputASM, float *outputASM )
105 void ASM_patch( float *inputASM, float *outputASM )
82 {
106 {
83 extractReImVectors( inputASM, outputASM, 1); // b1b2
107 extractReImVectors( inputASM, outputASM, 1); // b1b2
84 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
108 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
85 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
109 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
86 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
110 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
87 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
111 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
88 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
112 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
89 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
113 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
90 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
114 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
91 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
115 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
92 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
116 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
93 }
117 }
General Comments 0
You need to be logged in to leave comments. Login now