##// END OF EJS Templates
Fusion
paul -
r242:feeb51833794 merge R3
parent child
Show More
@@ -1,79 +1,80
1 /** Global variables of the LFR flight software.
1 /** Global variables of the LFR flight software.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * Among global variables, there are:
6 * Among global variables, there are:
7 * - RTEMS names and id.
7 * - RTEMS names and id.
8 * - APB configuration registers.
8 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
11 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
12 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
13 * - the global dump parameter buffer.
14 *
14 *
15 */
15 */
16
16
17 #include <rtems.h>
17 #include <rtems.h>
18 #include <grspw.h>
18 #include <grspw.h>
19
19
20 #include "ccsds_types.h"
20 #include "ccsds_types.h"
21 #include "grlib_regs.h"
21 #include "grlib_regs.h"
22 #include "fsw_params.h"
22 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
23 #include "fsw_params_wf_handler.h"
24
24
25 // RTEMS GLOBAL VARIABLES
25 // RTEMS GLOBAL VARIABLES
26 rtems_name misc_name[5];
26 rtems_name misc_name[5];
27 rtems_name Task_name[20]; /* array of task names */
27 rtems_name Task_name[20]; /* array of task names */
28 rtems_id Task_id[20]; /* array of task ids */
28 rtems_id Task_id[20]; /* array of task ids */
29 int fdSPW = 0;
29 int fdSPW = 0;
30 int fdUART = 0;
30 int fdUART = 0;
31 unsigned char lfrCurrentMode;
31 unsigned char lfrCurrentMode;
32 unsigned char pa_bia_status_info;
32 unsigned char pa_bia_status_info;
33
33
34 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
34 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
35 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
35 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
36 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
36 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
37 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
37 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
38 // F0 F1 F2 F3
38 // F0 F1 F2 F3
39 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
39 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
40 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
40 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
41 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
42 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
43
43
44 //***********************************
44 //***********************************
45 // SPECTRAL MATRICES GLOBAL VARIABLES
45 // SPECTRAL MATRICES GLOBAL VARIABLES
46
46
47 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
47 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
48 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
48 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
49 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
49 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
50 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
50 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
51
51
52 // APB CONFIGURATION REGISTERS
52 // APB CONFIGURATION REGISTERS
53 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
53 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
54 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
54 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
55 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
55 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
56 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
56 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
57 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
57
58
58 // MODE PARAMETERS
59 // MODE PARAMETERS
59 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
60 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
60 struct param_local_str param_local;
61 struct param_local_str param_local;
61
62
62 // HK PACKETS
63 // HK PACKETS
63 Packet_TM_LFR_HK_t housekeeping_packet;
64 Packet_TM_LFR_HK_t housekeeping_packet;
64 // message queues occupancy
65 // message queues occupancy
65 unsigned char hk_lfr_q_sd_fifo_size_max;
66 unsigned char hk_lfr_q_sd_fifo_size_max;
66 unsigned char hk_lfr_q_rv_fifo_size_max;
67 unsigned char hk_lfr_q_rv_fifo_size_max;
67 unsigned char hk_lfr_q_p0_fifo_size_max;
68 unsigned char hk_lfr_q_p0_fifo_size_max;
68 unsigned char hk_lfr_q_p1_fifo_size_max;
69 unsigned char hk_lfr_q_p1_fifo_size_max;
69 unsigned char hk_lfr_q_p2_fifo_size_max;
70 unsigned char hk_lfr_q_p2_fifo_size_max;
70 // sequence counters are incremented by APID (PID + CAT) and destination ID
71 // sequence counters are incremented by APID (PID + CAT) and destination ID
71 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
72 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
72 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
73 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
73 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
74 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
74 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
75 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
75 unsigned short sequenceCounterHK;
76 unsigned short sequenceCounterHK;
76 spw_stats spacewire_stats;
77 spw_stats spacewire_stats;
77 spw_stats spacewire_stats_backup;
78 spw_stats spacewire_stats_backup;
78
79
79
80
@@ -1,872 +1,880
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
42 #endif
43
43
44 #include <rtems/confdefs.h>
44 #include <rtems/confdefs.h>
45
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
49 /* Add Timer and UART Driver */
50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #endif
52 #endif
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 #endif
55 #endif
56 #endif
56 #endif
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 #include <drvmgr/drvmgr_confdefs.h>
58 #include <drvmgr/drvmgr_confdefs.h>
59 #endif
59 #endif
60
60
61 #include "fsw_init.h"
61 #include "fsw_init.h"
62 #include "fsw_config.c"
62 #include "fsw_config.c"
63 #include "GscMemoryLPP.hpp"
63 #include "GscMemoryLPP.hpp"
64
64
65 void initCache()
65 void initCache()
66 {
66 {
67 unsigned int cacheControlRegister;
67 unsigned int cacheControlRegister;
68
68
69 cacheControlRegister = getCacheControlRegister();
69 cacheControlRegister = getCacheControlRegister();
70 PRINTF1("(0) cacheControlRegister = %x\n", cacheControlRegister)
70 PRINTF1("(0) cacheControlRegister = %x\n", cacheControlRegister)
71
71
72 resetCacheControlRegister();
72 resetCacheControlRegister();
73
73
74 enableInstructionCache();
74 enableInstructionCache();
75 enableDataCache();
75 enableDataCache();
76 enableInstructionBurstFetch();
76 enableInstructionBurstFetch();
77
77
78 cacheControlRegister = getCacheControlRegister();
78 cacheControlRegister = getCacheControlRegister();
79 PRINTF1("(1) cacheControlRegister = %x\n", cacheControlRegister)
79 PRINTF1("(1) cacheControlRegister = %x\n", cacheControlRegister)
80 }
80 }
81
81
82 rtems_task Init( rtems_task_argument ignored )
82 rtems_task Init( rtems_task_argument ignored )
83 {
83 {
84 /** This is the RTEMS INIT taks, it is the first task launched by the system.
84 /** This is the RTEMS INIT taks, it is the first task launched by the system.
85 *
85 *
86 * @param unused is the starting argument of the RTEMS task
86 * @param unused is the starting argument of the RTEMS task
87 *
87 *
88 * The INIT task create and run all other RTEMS tasks.
88 * The INIT task create and run all other RTEMS tasks.
89 *
89 *
90 */
90 */
91
91
92 //***********
92 //***********
93 // INIT CACHE
93 // INIT CACHE
94
94
95 unsigned char *vhdlVersion;
95 unsigned char *vhdlVersion;
96
96
97 reset_lfr();
97 reset_lfr();
98
98
99 reset_local_time();
99 reset_local_time();
100
100
101 rtems_cpu_usage_reset();
101 rtems_cpu_usage_reset();
102
102
103 rtems_status_code status;
103 rtems_status_code status;
104 rtems_status_code status_spw;
104 rtems_status_code status_spw;
105 rtems_isr_entry old_isr_handler;
105 rtems_isr_entry old_isr_handler;
106
106
107 // UART settings
107 // UART settings
108 send_console_outputs_on_apbuart_port();
108 send_console_outputs_on_apbuart_port();
109 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
109 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
110 enable_apbuart_transmitter();
110 enable_apbuart_transmitter();
111
111
112 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
112 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
113
113
114
114
115 PRINTF("\n\n\n\n\n")
115 PRINTF("\n\n\n\n\n")
116
116
117 initCache();
117 initCache();
118
118
119 PRINTF("*************************\n")
119 PRINTF("*************************\n")
120 PRINTF("** LFR Flight Software **\n")
120 PRINTF("** LFR Flight Software **\n")
121 PRINTF1("** %d.", SW_VERSION_N1)
121 PRINTF1("** %d.", SW_VERSION_N1)
122 PRINTF1("%d." , SW_VERSION_N2)
122 PRINTF1("%d." , SW_VERSION_N2)
123 PRINTF1("%d." , SW_VERSION_N3)
123 PRINTF1("%d." , SW_VERSION_N3)
124 PRINTF1("%d **\n", SW_VERSION_N4)
124 PRINTF1("%d **\n", SW_VERSION_N4)
125
125
126 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
126 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
127 PRINTF("** VHDL **\n")
127 PRINTF("** VHDL **\n")
128 PRINTF1("** %d.", vhdlVersion[1])
128 PRINTF1("** %d.", vhdlVersion[1])
129 PRINTF1("%d." , vhdlVersion[2])
129 PRINTF1("%d." , vhdlVersion[2])
130 PRINTF1("%d **\n", vhdlVersion[3])
130 PRINTF1("%d **\n", vhdlVersion[3])
131 PRINTF("*************************\n")
131 PRINTF("*************************\n")
132 PRINTF("\n\n")
132 PRINTF("\n\n")
133
133
134 init_parameter_dump();
134 init_parameter_dump();
135 init_kcoefficients_dump();
135 init_kcoefficients_dump();
136 init_local_mode_parameters();
136 init_local_mode_parameters();
137 init_housekeeping_parameters();
137 init_housekeeping_parameters();
138 init_k_coefficients_prc0();
138 init_k_coefficients_prc0();
139 init_k_coefficients_prc1();
139 init_k_coefficients_prc1();
140 init_k_coefficients_prc2();
140 init_k_coefficients_prc2();
141 pa_bia_status_info = 0x00;
141 pa_bia_status_info = 0x00;
142
142
143 // waveform picker initialization
143 // waveform picker initialization
144 WFP_init_rings(); // initialize the waveform rings
144 WFP_init_rings(); // initialize the waveform rings
145 WFP_reset_current_ring_nodes();
145 WFP_reset_current_ring_nodes();
146 reset_waveform_picker_regs();
146 reset_waveform_picker_regs();
147
147
148 // spectral matrices initialization
148 // spectral matrices initialization
149 SM_init_rings(); // initialize spectral matrices rings
149 SM_init_rings(); // initialize spectral matrices rings
150 SM_reset_current_ring_nodes();
150 SM_reset_current_ring_nodes();
151 reset_spectral_matrix_regs();
151 reset_spectral_matrix_regs();
152
152
153 // configure calibration
153 // configure calibration
154 configureCalibration( false ); // true means interleaved mode, false is for normal mode
154 configureCalibration( false ); // true means interleaved mode, false is for normal mode
155
155
156 updateLFRCurrentMode();
156 updateLFRCurrentMode();
157
157
158 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
158 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
159
159
160 create_names(); // create all names
160 create_names(); // create all names
161
161
162 status = create_message_queues(); // create message queues
162 status = create_message_queues(); // create message queues
163 if (status != RTEMS_SUCCESSFUL)
163 if (status != RTEMS_SUCCESSFUL)
164 {
164 {
165 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
165 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
166 }
166 }
167
167
168 status = create_all_tasks(); // create all tasks
168 status = create_all_tasks(); // create all tasks
169 if (status != RTEMS_SUCCESSFUL)
169 if (status != RTEMS_SUCCESSFUL)
170 {
170 {
171 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
171 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
172 }
172 }
173
173
174 // **************************
174 // **************************
175 // <SPACEWIRE INITIALIZATION>
175 // <SPACEWIRE INITIALIZATION>
176 grspw_timecode_callback = &timecode_irq_handler;
176 grspw_timecode_callback = &timecode_irq_handler;
177
177
178 status_spw = spacewire_open_link(); // (1) open the link
178 status_spw = spacewire_open_link(); // (1) open the link
179 if ( status_spw != RTEMS_SUCCESSFUL )
179 if ( status_spw != RTEMS_SUCCESSFUL )
180 {
180 {
181 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
181 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
182 }
182 }
183
183
184 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
184 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
185 {
185 {
186 status_spw = spacewire_configure_link( fdSPW );
186 status_spw = spacewire_configure_link( fdSPW );
187 if ( status_spw != RTEMS_SUCCESSFUL )
187 if ( status_spw != RTEMS_SUCCESSFUL )
188 {
188 {
189 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
189 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
190 }
190 }
191 }
191 }
192
192
193 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
193 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
194 {
194 {
195 status_spw = spacewire_start_link( fdSPW );
195 status_spw = spacewire_start_link( fdSPW );
196 if ( status_spw != RTEMS_SUCCESSFUL )
196 if ( status_spw != RTEMS_SUCCESSFUL )
197 {
197 {
198 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
198 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
199 }
199 }
200 }
200 }
201 // </SPACEWIRE INITIALIZATION>
201 // </SPACEWIRE INITIALIZATION>
202 // ***************************
202 // ***************************
203
203
204 status = start_all_tasks(); // start all tasks
204 status = start_all_tasks(); // start all tasks
205 if (status != RTEMS_SUCCESSFUL)
205 if (status != RTEMS_SUCCESSFUL)
206 {
206 {
207 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
207 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
208 }
208 }
209
209
210 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
210 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
211 status = start_recv_send_tasks();
211 status = start_recv_send_tasks();
212 if ( status != RTEMS_SUCCESSFUL )
212 if ( status != RTEMS_SUCCESSFUL )
213 {
213 {
214 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
214 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
215 }
215 }
216
216
217 // suspend science tasks, they will be restarted later depending on the mode
217 // suspend science tasks, they will be restarted later depending on the mode
218 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
218 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
219 if (status != RTEMS_SUCCESSFUL)
219 if (status != RTEMS_SUCCESSFUL)
220 {
220 {
221 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
221 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
222 }
222 }
223
223
224 //******************************
224 //******************************
225 // <SPECTRAL MATRICES SIMULATOR>
225 // <SPECTRAL MATRICES SIMULATOR>
226 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
226 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
227 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
227 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
228 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
228 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
229 // </SPECTRAL MATRICES SIMULATOR>
229 // </SPECTRAL MATRICES SIMULATOR>
230 //*******************************
230 //*******************************
231
231
232 // configure IRQ handling for the waveform picker unit
232 // configure IRQ handling for the waveform picker unit
233 status = rtems_interrupt_catch( waveforms_isr,
233 status = rtems_interrupt_catch( waveforms_isr,
234 IRQ_SPARC_WAVEFORM_PICKER,
234 IRQ_SPARC_WAVEFORM_PICKER,
235 &old_isr_handler) ;
235 &old_isr_handler) ;
236 // configure IRQ handling for the spectral matrices unit
236 // configure IRQ handling for the spectral matrices unit
237 status = rtems_interrupt_catch( spectral_matrices_isr,
237 status = rtems_interrupt_catch( spectral_matrices_isr,
238 IRQ_SPARC_SPECTRAL_MATRIX,
238 IRQ_SPARC_SPECTRAL_MATRIX,
239 &old_isr_handler) ;
239 &old_isr_handler) ;
240
240
241 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
241 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
242 if ( status_spw != RTEMS_SUCCESSFUL )
242 if ( status_spw != RTEMS_SUCCESSFUL )
243 {
243 {
244 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
244 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
245 if ( status != RTEMS_SUCCESSFUL ) {
245 if ( status != RTEMS_SUCCESSFUL ) {
246 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
246 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
247 }
247 }
248 }
248 }
249
249
250 BOOT_PRINTF("delete INIT\n")
250 BOOT_PRINTF("delete INIT\n")
251
251
252 set_hk_lfr_sc_potential_flag( true );
252 set_hk_lfr_sc_potential_flag( true );
253
253
254 //*********************************
255 // init GPIO for trigger generation
256 struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
257 grgpio_regs->io_port_direction_register =
258 grgpio_regs->io_port_direction_register | 0x08; // [0000 1000], 0 = output disabled, 1 = output enabled
259 grgpio_regs->io_port_direction_register =
260 grgpio_regs->io_port_direction_register | 0x04; // [0000 0100], 0 = output disabled, 1 = output enabled
261
254 status = rtems_task_delete(RTEMS_SELF);
262 status = rtems_task_delete(RTEMS_SELF);
255
263
256 }
264 }
257
265
258 void init_local_mode_parameters( void )
266 void init_local_mode_parameters( void )
259 {
267 {
260 /** This function initialize the param_local global variable with default values.
268 /** This function initialize the param_local global variable with default values.
261 *
269 *
262 */
270 */
263
271
264 unsigned int i;
272 unsigned int i;
265
273
266 // LOCAL PARAMETERS
274 // LOCAL PARAMETERS
267
275
268 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
276 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
269 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
277 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
270 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
278 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
271
279
272 // init sequence counters
280 // init sequence counters
273
281
274 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
282 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
275 {
283 {
276 sequenceCounters_TC_EXE[i] = 0x00;
284 sequenceCounters_TC_EXE[i] = 0x00;
277 sequenceCounters_TM_DUMP[i] = 0x00;
285 sequenceCounters_TM_DUMP[i] = 0x00;
278 }
286 }
279 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
287 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
280 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
288 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
281 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
289 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
282 }
290 }
283
291
284 void reset_local_time( void )
292 void reset_local_time( void )
285 {
293 {
286 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
294 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
287 }
295 }
288
296
289 void create_names( void ) // create all names for tasks and queues
297 void create_names( void ) // create all names for tasks and queues
290 {
298 {
291 /** This function creates all RTEMS names used in the software for tasks and queues.
299 /** This function creates all RTEMS names used in the software for tasks and queues.
292 *
300 *
293 * @return RTEMS directive status codes:
301 * @return RTEMS directive status codes:
294 * - RTEMS_SUCCESSFUL - successful completion
302 * - RTEMS_SUCCESSFUL - successful completion
295 *
303 *
296 */
304 */
297
305
298 // task names
306 // task names
299 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
307 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
300 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
308 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
301 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
309 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
302 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
310 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
303 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
311 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
304 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
312 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
305 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
313 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
306 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
314 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
307 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
315 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
308 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
316 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
309 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
317 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
310 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
318 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
311 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
319 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
312 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
320 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
313 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
321 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
314 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
322 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
315 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
323 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
316 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
324 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
317 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
325 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
318
326
319 // rate monotonic period names
327 // rate monotonic period names
320 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
328 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
321
329
322 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
330 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
323 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
331 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
324 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
332 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
325 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
333 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
326 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
334 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
327 }
335 }
328
336
329 int create_all_tasks( void ) // create all tasks which run in the software
337 int create_all_tasks( void ) // create all tasks which run in the software
330 {
338 {
331 /** This function creates all RTEMS tasks used in the software.
339 /** This function creates all RTEMS tasks used in the software.
332 *
340 *
333 * @return RTEMS directive status codes:
341 * @return RTEMS directive status codes:
334 * - RTEMS_SUCCESSFUL - task created successfully
342 * - RTEMS_SUCCESSFUL - task created successfully
335 * - RTEMS_INVALID_ADDRESS - id is NULL
343 * - RTEMS_INVALID_ADDRESS - id is NULL
336 * - RTEMS_INVALID_NAME - invalid task name
344 * - RTEMS_INVALID_NAME - invalid task name
337 * - RTEMS_INVALID_PRIORITY - invalid task priority
345 * - RTEMS_INVALID_PRIORITY - invalid task priority
338 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
346 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
339 * - RTEMS_TOO_MANY - too many tasks created
347 * - RTEMS_TOO_MANY - too many tasks created
340 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
348 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
341 * - RTEMS_TOO_MANY - too many global objects
349 * - RTEMS_TOO_MANY - too many global objects
342 *
350 *
343 */
351 */
344
352
345 rtems_status_code status;
353 rtems_status_code status;
346
354
347 //**********
355 //**********
348 // SPACEWIRE
356 // SPACEWIRE
349 // RECV
357 // RECV
350 status = rtems_task_create(
358 status = rtems_task_create(
351 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
359 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
352 RTEMS_DEFAULT_MODES,
360 RTEMS_DEFAULT_MODES,
353 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
361 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
354 );
362 );
355 if (status == RTEMS_SUCCESSFUL) // SEND
363 if (status == RTEMS_SUCCESSFUL) // SEND
356 {
364 {
357 status = rtems_task_create(
365 status = rtems_task_create(
358 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
366 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
359 RTEMS_DEFAULT_MODES,
367 RTEMS_DEFAULT_MODES,
360 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
368 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
361 );
369 );
362 }
370 }
363 if (status == RTEMS_SUCCESSFUL) // WTDG
371 if (status == RTEMS_SUCCESSFUL) // WTDG
364 {
372 {
365 status = rtems_task_create(
373 status = rtems_task_create(
366 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
374 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
367 RTEMS_DEFAULT_MODES,
375 RTEMS_DEFAULT_MODES,
368 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
376 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
369 );
377 );
370 }
378 }
371 if (status == RTEMS_SUCCESSFUL) // ACTN
379 if (status == RTEMS_SUCCESSFUL) // ACTN
372 {
380 {
373 status = rtems_task_create(
381 status = rtems_task_create(
374 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
382 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
375 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
383 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
376 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
384 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
377 );
385 );
378 }
386 }
379 if (status == RTEMS_SUCCESSFUL) // SPIQ
387 if (status == RTEMS_SUCCESSFUL) // SPIQ
380 {
388 {
381 status = rtems_task_create(
389 status = rtems_task_create(
382 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
390 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
383 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
391 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
384 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
392 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
385 );
393 );
386 }
394 }
387
395
388 //******************
396 //******************
389 // SPECTRAL MATRICES
397 // SPECTRAL MATRICES
390 if (status == RTEMS_SUCCESSFUL) // AVF0
398 if (status == RTEMS_SUCCESSFUL) // AVF0
391 {
399 {
392 status = rtems_task_create(
400 status = rtems_task_create(
393 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
401 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
394 RTEMS_DEFAULT_MODES,
402 RTEMS_DEFAULT_MODES,
395 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
403 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
396 );
404 );
397 }
405 }
398 if (status == RTEMS_SUCCESSFUL) // PRC0
406 if (status == RTEMS_SUCCESSFUL) // PRC0
399 {
407 {
400 status = rtems_task_create(
408 status = rtems_task_create(
401 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
409 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
402 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
410 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
403 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
411 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
404 );
412 );
405 }
413 }
406 if (status == RTEMS_SUCCESSFUL) // AVF1
414 if (status == RTEMS_SUCCESSFUL) // AVF1
407 {
415 {
408 status = rtems_task_create(
416 status = rtems_task_create(
409 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
417 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
410 RTEMS_DEFAULT_MODES,
418 RTEMS_DEFAULT_MODES,
411 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
419 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
412 );
420 );
413 }
421 }
414 if (status == RTEMS_SUCCESSFUL) // PRC1
422 if (status == RTEMS_SUCCESSFUL) // PRC1
415 {
423 {
416 status = rtems_task_create(
424 status = rtems_task_create(
417 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
425 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
418 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
426 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
419 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
427 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
420 );
428 );
421 }
429 }
422 if (status == RTEMS_SUCCESSFUL) // AVF2
430 if (status == RTEMS_SUCCESSFUL) // AVF2
423 {
431 {
424 status = rtems_task_create(
432 status = rtems_task_create(
425 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
433 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
426 RTEMS_DEFAULT_MODES,
434 RTEMS_DEFAULT_MODES,
427 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
435 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
428 );
436 );
429 }
437 }
430 if (status == RTEMS_SUCCESSFUL) // PRC2
438 if (status == RTEMS_SUCCESSFUL) // PRC2
431 {
439 {
432 status = rtems_task_create(
440 status = rtems_task_create(
433 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
441 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
434 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
442 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
435 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
443 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
436 );
444 );
437 }
445 }
438
446
439 //****************
447 //****************
440 // WAVEFORM PICKER
448 // WAVEFORM PICKER
441 if (status == RTEMS_SUCCESSFUL) // WFRM
449 if (status == RTEMS_SUCCESSFUL) // WFRM
442 {
450 {
443 status = rtems_task_create(
451 status = rtems_task_create(
444 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
452 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
445 RTEMS_DEFAULT_MODES,
453 RTEMS_DEFAULT_MODES,
446 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
454 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
447 );
455 );
448 }
456 }
449 if (status == RTEMS_SUCCESSFUL) // CWF3
457 if (status == RTEMS_SUCCESSFUL) // CWF3
450 {
458 {
451 status = rtems_task_create(
459 status = rtems_task_create(
452 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
460 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
453 RTEMS_DEFAULT_MODES,
461 RTEMS_DEFAULT_MODES,
454 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
462 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
455 );
463 );
456 }
464 }
457 if (status == RTEMS_SUCCESSFUL) // CWF2
465 if (status == RTEMS_SUCCESSFUL) // CWF2
458 {
466 {
459 status = rtems_task_create(
467 status = rtems_task_create(
460 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
468 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
461 RTEMS_DEFAULT_MODES,
469 RTEMS_DEFAULT_MODES,
462 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
470 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
463 );
471 );
464 }
472 }
465 if (status == RTEMS_SUCCESSFUL) // CWF1
473 if (status == RTEMS_SUCCESSFUL) // CWF1
466 {
474 {
467 status = rtems_task_create(
475 status = rtems_task_create(
468 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
476 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
469 RTEMS_DEFAULT_MODES,
477 RTEMS_DEFAULT_MODES,
470 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
478 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
471 );
479 );
472 }
480 }
473 if (status == RTEMS_SUCCESSFUL) // SWBD
481 if (status == RTEMS_SUCCESSFUL) // SWBD
474 {
482 {
475 status = rtems_task_create(
483 status = rtems_task_create(
476 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
484 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
477 RTEMS_DEFAULT_MODES,
485 RTEMS_DEFAULT_MODES,
478 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
486 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
479 );
487 );
480 }
488 }
481
489
482 //*****
490 //*****
483 // MISC
491 // MISC
484 if (status == RTEMS_SUCCESSFUL) // STAT
492 if (status == RTEMS_SUCCESSFUL) // STAT
485 {
493 {
486 status = rtems_task_create(
494 status = rtems_task_create(
487 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
495 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
488 RTEMS_DEFAULT_MODES,
496 RTEMS_DEFAULT_MODES,
489 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
497 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
490 );
498 );
491 }
499 }
492 if (status == RTEMS_SUCCESSFUL) // DUMB
500 if (status == RTEMS_SUCCESSFUL) // DUMB
493 {
501 {
494 status = rtems_task_create(
502 status = rtems_task_create(
495 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
503 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
496 RTEMS_DEFAULT_MODES,
504 RTEMS_DEFAULT_MODES,
497 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
505 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
498 );
506 );
499 }
507 }
500 if (status == RTEMS_SUCCESSFUL) // HOUS
508 if (status == RTEMS_SUCCESSFUL) // HOUS
501 {
509 {
502 status = rtems_task_create(
510 status = rtems_task_create(
503 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
511 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
504 RTEMS_DEFAULT_MODES,
512 RTEMS_DEFAULT_MODES,
505 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
513 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
506 );
514 );
507 }
515 }
508
516
509 return status;
517 return status;
510 }
518 }
511
519
512 int start_recv_send_tasks( void )
520 int start_recv_send_tasks( void )
513 {
521 {
514 rtems_status_code status;
522 rtems_status_code status;
515
523
516 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
524 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
517 if (status!=RTEMS_SUCCESSFUL) {
525 if (status!=RTEMS_SUCCESSFUL) {
518 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
526 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
519 }
527 }
520
528
521 if (status == RTEMS_SUCCESSFUL) // SEND
529 if (status == RTEMS_SUCCESSFUL) // SEND
522 {
530 {
523 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
531 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
524 if (status!=RTEMS_SUCCESSFUL) {
532 if (status!=RTEMS_SUCCESSFUL) {
525 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
533 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
526 }
534 }
527 }
535 }
528
536
529 return status;
537 return status;
530 }
538 }
531
539
532 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
540 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
533 {
541 {
534 /** This function starts all RTEMS tasks used in the software.
542 /** This function starts all RTEMS tasks used in the software.
535 *
543 *
536 * @return RTEMS directive status codes:
544 * @return RTEMS directive status codes:
537 * - RTEMS_SUCCESSFUL - ask started successfully
545 * - RTEMS_SUCCESSFUL - ask started successfully
538 * - RTEMS_INVALID_ADDRESS - invalid task entry point
546 * - RTEMS_INVALID_ADDRESS - invalid task entry point
539 * - RTEMS_INVALID_ID - invalid task id
547 * - RTEMS_INVALID_ID - invalid task id
540 * - RTEMS_INCORRECT_STATE - task not in the dormant state
548 * - RTEMS_INCORRECT_STATE - task not in the dormant state
541 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
549 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
542 *
550 *
543 */
551 */
544 // starts all the tasks fot eh flight software
552 // starts all the tasks fot eh flight software
545
553
546 rtems_status_code status;
554 rtems_status_code status;
547
555
548 //**********
556 //**********
549 // SPACEWIRE
557 // SPACEWIRE
550 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
558 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
551 if (status!=RTEMS_SUCCESSFUL) {
559 if (status!=RTEMS_SUCCESSFUL) {
552 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
560 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
553 }
561 }
554
562
555 if (status == RTEMS_SUCCESSFUL) // WTDG
563 if (status == RTEMS_SUCCESSFUL) // WTDG
556 {
564 {
557 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
565 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
558 if (status!=RTEMS_SUCCESSFUL) {
566 if (status!=RTEMS_SUCCESSFUL) {
559 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
567 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
560 }
568 }
561 }
569 }
562
570
563 if (status == RTEMS_SUCCESSFUL) // ACTN
571 if (status == RTEMS_SUCCESSFUL) // ACTN
564 {
572 {
565 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
573 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
566 if (status!=RTEMS_SUCCESSFUL) {
574 if (status!=RTEMS_SUCCESSFUL) {
567 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
575 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
568 }
576 }
569 }
577 }
570
578
571 //******************
579 //******************
572 // SPECTRAL MATRICES
580 // SPECTRAL MATRICES
573 if (status == RTEMS_SUCCESSFUL) // AVF0
581 if (status == RTEMS_SUCCESSFUL) // AVF0
574 {
582 {
575 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
583 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
576 if (status!=RTEMS_SUCCESSFUL) {
584 if (status!=RTEMS_SUCCESSFUL) {
577 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
585 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
578 }
586 }
579 }
587 }
580 if (status == RTEMS_SUCCESSFUL) // PRC0
588 if (status == RTEMS_SUCCESSFUL) // PRC0
581 {
589 {
582 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
590 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
583 if (status!=RTEMS_SUCCESSFUL) {
591 if (status!=RTEMS_SUCCESSFUL) {
584 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
592 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
585 }
593 }
586 }
594 }
587 if (status == RTEMS_SUCCESSFUL) // AVF1
595 if (status == RTEMS_SUCCESSFUL) // AVF1
588 {
596 {
589 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
597 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
590 if (status!=RTEMS_SUCCESSFUL) {
598 if (status!=RTEMS_SUCCESSFUL) {
591 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
599 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
592 }
600 }
593 }
601 }
594 if (status == RTEMS_SUCCESSFUL) // PRC1
602 if (status == RTEMS_SUCCESSFUL) // PRC1
595 {
603 {
596 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
604 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
597 if (status!=RTEMS_SUCCESSFUL) {
605 if (status!=RTEMS_SUCCESSFUL) {
598 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
606 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
599 }
607 }
600 }
608 }
601 if (status == RTEMS_SUCCESSFUL) // AVF2
609 if (status == RTEMS_SUCCESSFUL) // AVF2
602 {
610 {
603 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
611 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
604 if (status!=RTEMS_SUCCESSFUL) {
612 if (status!=RTEMS_SUCCESSFUL) {
605 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
613 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
606 }
614 }
607 }
615 }
608 if (status == RTEMS_SUCCESSFUL) // PRC2
616 if (status == RTEMS_SUCCESSFUL) // PRC2
609 {
617 {
610 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
618 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
611 if (status!=RTEMS_SUCCESSFUL) {
619 if (status!=RTEMS_SUCCESSFUL) {
612 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
620 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
613 }
621 }
614 }
622 }
615
623
616 //****************
624 //****************
617 // WAVEFORM PICKER
625 // WAVEFORM PICKER
618 if (status == RTEMS_SUCCESSFUL) // WFRM
626 if (status == RTEMS_SUCCESSFUL) // WFRM
619 {
627 {
620 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
628 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
621 if (status!=RTEMS_SUCCESSFUL) {
629 if (status!=RTEMS_SUCCESSFUL) {
622 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
630 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
623 }
631 }
624 }
632 }
625 if (status == RTEMS_SUCCESSFUL) // CWF3
633 if (status == RTEMS_SUCCESSFUL) // CWF3
626 {
634 {
627 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
635 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
628 if (status!=RTEMS_SUCCESSFUL) {
636 if (status!=RTEMS_SUCCESSFUL) {
629 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
637 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
630 }
638 }
631 }
639 }
632 if (status == RTEMS_SUCCESSFUL) // CWF2
640 if (status == RTEMS_SUCCESSFUL) // CWF2
633 {
641 {
634 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
642 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
635 if (status!=RTEMS_SUCCESSFUL) {
643 if (status!=RTEMS_SUCCESSFUL) {
636 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
644 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
637 }
645 }
638 }
646 }
639 if (status == RTEMS_SUCCESSFUL) // CWF1
647 if (status == RTEMS_SUCCESSFUL) // CWF1
640 {
648 {
641 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
649 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
642 if (status!=RTEMS_SUCCESSFUL) {
650 if (status!=RTEMS_SUCCESSFUL) {
643 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
651 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
644 }
652 }
645 }
653 }
646 if (status == RTEMS_SUCCESSFUL) // SWBD
654 if (status == RTEMS_SUCCESSFUL) // SWBD
647 {
655 {
648 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
656 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
649 if (status!=RTEMS_SUCCESSFUL) {
657 if (status!=RTEMS_SUCCESSFUL) {
650 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
658 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
651 }
659 }
652 }
660 }
653
661
654 //*****
662 //*****
655 // MISC
663 // MISC
656 if (status == RTEMS_SUCCESSFUL) // HOUS
664 if (status == RTEMS_SUCCESSFUL) // HOUS
657 {
665 {
658 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
666 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
659 if (status!=RTEMS_SUCCESSFUL) {
667 if (status!=RTEMS_SUCCESSFUL) {
660 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
668 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
661 }
669 }
662 }
670 }
663 if (status == RTEMS_SUCCESSFUL) // DUMB
671 if (status == RTEMS_SUCCESSFUL) // DUMB
664 {
672 {
665 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
673 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
666 if (status!=RTEMS_SUCCESSFUL) {
674 if (status!=RTEMS_SUCCESSFUL) {
667 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
675 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
668 }
676 }
669 }
677 }
670 if (status == RTEMS_SUCCESSFUL) // STAT
678 if (status == RTEMS_SUCCESSFUL) // STAT
671 {
679 {
672 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
680 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
673 if (status!=RTEMS_SUCCESSFUL) {
681 if (status!=RTEMS_SUCCESSFUL) {
674 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
682 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
675 }
683 }
676 }
684 }
677
685
678 return status;
686 return status;
679 }
687 }
680
688
681 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
689 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
682 {
690 {
683 rtems_status_code status_recv;
691 rtems_status_code status_recv;
684 rtems_status_code status_send;
692 rtems_status_code status_send;
685 rtems_status_code status_q_p0;
693 rtems_status_code status_q_p0;
686 rtems_status_code status_q_p1;
694 rtems_status_code status_q_p1;
687 rtems_status_code status_q_p2;
695 rtems_status_code status_q_p2;
688 rtems_status_code ret;
696 rtems_status_code ret;
689 rtems_id queue_id;
697 rtems_id queue_id;
690
698
691 //****************************************
699 //****************************************
692 // create the queue for handling valid TCs
700 // create the queue for handling valid TCs
693 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
701 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
694 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
702 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
695 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
703 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
696 if ( status_recv != RTEMS_SUCCESSFUL ) {
704 if ( status_recv != RTEMS_SUCCESSFUL ) {
697 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
705 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
698 }
706 }
699
707
700 //************************************************
708 //************************************************
701 // create the queue for handling TM packet sending
709 // create the queue for handling TM packet sending
702 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
710 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
703 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
711 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
704 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
712 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
705 if ( status_send != RTEMS_SUCCESSFUL ) {
713 if ( status_send != RTEMS_SUCCESSFUL ) {
706 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
714 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
707 }
715 }
708
716
709 //*****************************************************************************
717 //*****************************************************************************
710 // create the queue for handling averaged spectral matrices for processing @ f0
718 // create the queue for handling averaged spectral matrices for processing @ f0
711 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
719 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
712 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
720 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
713 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
721 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
714 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
722 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
715 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
723 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
716 }
724 }
717
725
718 //*****************************************************************************
726 //*****************************************************************************
719 // create the queue for handling averaged spectral matrices for processing @ f1
727 // create the queue for handling averaged spectral matrices for processing @ f1
720 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
728 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
721 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
729 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
722 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
730 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
723 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
731 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
724 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
732 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
725 }
733 }
726
734
727 //*****************************************************************************
735 //*****************************************************************************
728 // create the queue for handling averaged spectral matrices for processing @ f2
736 // create the queue for handling averaged spectral matrices for processing @ f2
729 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
737 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
730 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
738 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
731 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
739 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
732 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
740 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
733 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
741 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
734 }
742 }
735
743
736 if ( status_recv != RTEMS_SUCCESSFUL )
744 if ( status_recv != RTEMS_SUCCESSFUL )
737 {
745 {
738 ret = status_recv;
746 ret = status_recv;
739 }
747 }
740 else if( status_send != RTEMS_SUCCESSFUL )
748 else if( status_send != RTEMS_SUCCESSFUL )
741 {
749 {
742 ret = status_send;
750 ret = status_send;
743 }
751 }
744 else if( status_q_p0 != RTEMS_SUCCESSFUL )
752 else if( status_q_p0 != RTEMS_SUCCESSFUL )
745 {
753 {
746 ret = status_q_p0;
754 ret = status_q_p0;
747 }
755 }
748 else if( status_q_p1 != RTEMS_SUCCESSFUL )
756 else if( status_q_p1 != RTEMS_SUCCESSFUL )
749 {
757 {
750 ret = status_q_p1;
758 ret = status_q_p1;
751 }
759 }
752 else
760 else
753 {
761 {
754 ret = status_q_p2;
762 ret = status_q_p2;
755 }
763 }
756
764
757 return ret;
765 return ret;
758 }
766 }
759
767
760 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
768 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
761 {
769 {
762 rtems_status_code status;
770 rtems_status_code status;
763 rtems_name queue_name;
771 rtems_name queue_name;
764
772
765 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
773 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
766
774
767 status = rtems_message_queue_ident( queue_name, 0, queue_id );
775 status = rtems_message_queue_ident( queue_name, 0, queue_id );
768
776
769 return status;
777 return status;
770 }
778 }
771
779
772 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
780 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
773 {
781 {
774 rtems_status_code status;
782 rtems_status_code status;
775 rtems_name queue_name;
783 rtems_name queue_name;
776
784
777 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
785 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
778
786
779 status = rtems_message_queue_ident( queue_name, 0, queue_id );
787 status = rtems_message_queue_ident( queue_name, 0, queue_id );
780
788
781 return status;
789 return status;
782 }
790 }
783
791
784 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
792 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
785 {
793 {
786 rtems_status_code status;
794 rtems_status_code status;
787 rtems_name queue_name;
795 rtems_name queue_name;
788
796
789 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
797 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
790
798
791 status = rtems_message_queue_ident( queue_name, 0, queue_id );
799 status = rtems_message_queue_ident( queue_name, 0, queue_id );
792
800
793 return status;
801 return status;
794 }
802 }
795
803
796 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
804 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
797 {
805 {
798 rtems_status_code status;
806 rtems_status_code status;
799 rtems_name queue_name;
807 rtems_name queue_name;
800
808
801 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
809 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
802
810
803 status = rtems_message_queue_ident( queue_name, 0, queue_id );
811 status = rtems_message_queue_ident( queue_name, 0, queue_id );
804
812
805 return status;
813 return status;
806 }
814 }
807
815
808 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
816 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
809 {
817 {
810 rtems_status_code status;
818 rtems_status_code status;
811 rtems_name queue_name;
819 rtems_name queue_name;
812
820
813 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
821 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
814
822
815 status = rtems_message_queue_ident( queue_name, 0, queue_id );
823 status = rtems_message_queue_ident( queue_name, 0, queue_id );
816
824
817 return status;
825 return status;
818 }
826 }
819
827
820 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
828 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
821 {
829 {
822 u_int32_t count;
830 u_int32_t count;
823 rtems_status_code status;
831 rtems_status_code status;
824
832
825 status = rtems_message_queue_get_number_pending( queue_id, &count );
833 status = rtems_message_queue_get_number_pending( queue_id, &count );
826
834
827 count = count + 1;
835 count = count + 1;
828
836
829 if (status != RTEMS_SUCCESSFUL)
837 if (status != RTEMS_SUCCESSFUL)
830 {
838 {
831 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
839 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
832 }
840 }
833 else
841 else
834 {
842 {
835 if (count > *fifo_size_max)
843 if (count > *fifo_size_max)
836 {
844 {
837 *fifo_size_max = count;
845 *fifo_size_max = count;
838 }
846 }
839 }
847 }
840 }
848 }
841
849
842 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
850 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
843 {
851 {
844 unsigned char i;
852 unsigned char i;
845
853
846 //***************
854 //***************
847 // BUFFER ADDRESS
855 // BUFFER ADDRESS
848 for(i=0; i<nbNodes; i++)
856 for(i=0; i<nbNodes; i++)
849 {
857 {
850 ring[i].coarseTime = 0xffffffff;
858 ring[i].coarseTime = 0xffffffff;
851 ring[i].fineTime = 0xffffffff;
859 ring[i].fineTime = 0xffffffff;
852 ring[i].sid = 0x00;
860 ring[i].sid = 0x00;
853 ring[i].status = 0x00;
861 ring[i].status = 0x00;
854 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
862 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
855 }
863 }
856
864
857 //*****
865 //*****
858 // NEXT
866 // NEXT
859 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
867 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
860 for(i=0; i<nbNodes-1; i++)
868 for(i=0; i<nbNodes-1; i++)
861 {
869 {
862 ring[i].next = (ring_node*) &ring[ i + 1 ];
870 ring[i].next = (ring_node*) &ring[ i + 1 ];
863 }
871 }
864
872
865 //*********
873 //*********
866 // PREVIOUS
874 // PREVIOUS
867 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
875 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
868 for(i=1; i<nbNodes; i++)
876 for(i=1; i<nbNodes; i++)
869 {
877 {
870 ring[i].previous = (ring_node*) &ring[ i - 1 ];
878 ring[i].previous = (ring_node*) &ring[ i - 1 ];
871 }
879 }
872 }
880 }
@@ -1,570 +1,584
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
10 void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29
29
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 if (status!=RTEMS_SUCCESSFUL)
31 if (status!=RTEMS_SUCCESSFUL)
32 {
32 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
34 }
35
35
36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
36 timer_set_clock_divider( gptimer_regs, timer, clock_divider);
37 }
37 }
38
38
39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
39 void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer)
40 {
40 {
41 /** This function starts a GPTIMER timer.
41 /** This function starts a GPTIMER timer.
42 *
42 *
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 *
45 *
46 */
46 */
47
47
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 }
53 }
54
54
55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
55 void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer)
56 {
56 {
57 /** This function stops a GPTIMER timer.
57 /** This function stops a GPTIMER timer.
58 *
58 *
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 *
61 *
62 */
62 */
63
63
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 }
67 }
68
68
69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
69 void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider)
70 {
70 {
71 /** This function sets the clock divider of a GPTIMER timer.
71 /** This function sets the clock divider of a GPTIMER timer.
72 *
72 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
76 *
77 */
77 */
78
78
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
80 }
81
81
82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
82 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 {
83 {
84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85
85
86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87
87
88 return 0;
88 return 0;
89 }
89 }
90
90
91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 {
92 {
93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94
94
95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96
96
97 return 0;
97 return 0;
98 }
98 }
99
99
100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 {
101 {
102 /** This function sets the scaler reload register of the apbuart module
102 /** This function sets the scaler reload register of the apbuart module
103 *
103 *
104 * @param regs is the address of the apbuart registers in memory
104 * @param regs is the address of the apbuart registers in memory
105 * @param value is the value that will be stored in the scaler register
105 * @param value is the value that will be stored in the scaler register
106 *
106 *
107 * The value shall be set by the software to get data on the serial interface.
107 * The value shall be set by the software to get data on the serial interface.
108 *
108 *
109 */
109 */
110
110
111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112
112
113 apbuart_regs->scaler = value;
113 apbuart_regs->scaler = value;
114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 }
115 }
116
116
117 //************
117 //************
118 // RTEMS TASKS
118 // RTEMS TASKS
119
119
120 rtems_task stat_task(rtems_task_argument argument)
120 rtems_task stat_task(rtems_task_argument argument)
121 {
121 {
122 int i;
122 int i;
123 int j;
123 int j;
124 i = 0;
124 i = 0;
125 j = 0;
125 j = 0;
126 BOOT_PRINTF("in STAT *** \n")
126 BOOT_PRINTF("in STAT *** \n")
127 while(1){
127 while(1){
128 rtems_task_wake_after(1000);
128 rtems_task_wake_after(1000);
129 PRINTF1("%d\n", j)
129 PRINTF1("%d\n", j)
130 if (i == CPU_USAGE_REPORT_PERIOD) {
130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 // #ifdef PRINT_TASK_STATISTICS
131 // #ifdef PRINT_TASK_STATISTICS
132 // rtems_cpu_usage_report();
132 // rtems_cpu_usage_report();
133 // rtems_cpu_usage_reset();
133 // rtems_cpu_usage_reset();
134 // #endif
134 // #endif
135 i = 0;
135 i = 0;
136 }
136 }
137 else i++;
137 else i++;
138 j++;
138 j++;
139 }
139 }
140 }
140 }
141
141
142 rtems_task hous_task(rtems_task_argument argument)
142 rtems_task hous_task(rtems_task_argument argument)
143 {
143 {
144 rtems_status_code status;
144 rtems_status_code status;
145 rtems_status_code spare_status;
145 rtems_status_code spare_status;
146 rtems_id queue_id;
146 rtems_id queue_id;
147 rtems_rate_monotonic_period_status period_status;
147 rtems_rate_monotonic_period_status period_status;
148
148
149 status = get_message_queue_id_send( &queue_id );
149 status = get_message_queue_id_send( &queue_id );
150 if (status != RTEMS_SUCCESSFUL)
150 if (status != RTEMS_SUCCESSFUL)
151 {
151 {
152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
153 }
153 }
154
154
155 BOOT_PRINTF("in HOUS ***\n")
155 BOOT_PRINTF("in HOUS ***\n")
156
156
157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
159 if( status != RTEMS_SUCCESSFUL ) {
159 if( status != RTEMS_SUCCESSFUL ) {
160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
161 }
161 }
162 }
162 }
163
163
164 status = rtems_rate_monotonic_cancel(HK_id);
164 status = rtems_rate_monotonic_cancel(HK_id);
165 if( status != RTEMS_SUCCESSFUL ) {
165 if( status != RTEMS_SUCCESSFUL ) {
166 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
166 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
167 }
167 }
168 else {
168 else {
169 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
169 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
170 }
170 }
171
171
172 // startup phase
172 // startup phase
173 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
173 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
174 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
174 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
175 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
175 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
176 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
176 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
177 {
177 {
178 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
178 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
179 {
179 {
180 break; // break if LFR is synchronized
180 break; // break if LFR is synchronized
181 }
181 }
182 else
182 else
183 {
183 {
184 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
184 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
185 // sched_yield();
185 // sched_yield();
186 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
186 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
187 }
187 }
188 }
188 }
189 status = rtems_rate_monotonic_cancel(HK_id);
189 status = rtems_rate_monotonic_cancel(HK_id);
190 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
190 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
191
191
192 set_hk_lfr_reset_cause( POWER_ON );
192 set_hk_lfr_reset_cause( POWER_ON );
193
193
194 while(1){ // launch the rate monotonic task
194 while(1){ // launch the rate monotonic task
195 // //*******
196 // // GPIO 3
197 // struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO;
198 // if ( (grgpio_regs->io_port_output_register & 0x07) == 0x02 ) // [010]
199 // {
200 // grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf8; // [1111 1000]
201 // }
202 // else
203 // {
204 // grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x02; // [0000 0010]
205 // }
206 //
207 //*******
208
195 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
209 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
196 if ( status != RTEMS_SUCCESSFUL ) {
210 if ( status != RTEMS_SUCCESSFUL ) {
197 PRINTF1( "in HOUS *** ERR period: %d\n", status);
211 PRINTF1( "in HOUS *** ERR period: %d\n", status);
198 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
212 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
199 }
213 }
200 else {
214 else {
201 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
215 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
202 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
216 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
203 increment_seq_counter( &sequenceCounterHK );
217 increment_seq_counter( &sequenceCounterHK );
204
218
205 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
219 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
206 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
220 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
207 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
221 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
208 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
222 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
209 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
223 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
210 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
224 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
211
225
212 spacewire_update_statistics();
226 spacewire_update_statistics();
213
227
214 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
228 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
215 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
229 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
216 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
230 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
217 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
231 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
218 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
232 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
219
233
220 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
234 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
221 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
235 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
222 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
236 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
223 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
237 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
224 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
238 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
225
239
226 // SEND PACKET
240 // SEND PACKET
227 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
241 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
228 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
242 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
229 if (status != RTEMS_SUCCESSFUL) {
243 if (status != RTEMS_SUCCESSFUL) {
230 PRINTF1("in HOUS *** ERR send: %d\n", status)
244 PRINTF1("in HOUS *** ERR send: %d\n", status)
231 }
245 }
232 }
246 }
233 }
247 }
234
248
235 PRINTF("in HOUS *** deleting task\n")
249 PRINTF("in HOUS *** deleting task\n")
236
250
237 status = rtems_task_delete( RTEMS_SELF ); // should not return
251 status = rtems_task_delete( RTEMS_SELF ); // should not return
238
252
239 return;
253 return;
240 }
254 }
241
255
242 rtems_task dumb_task( rtems_task_argument unused )
256 rtems_task dumb_task( rtems_task_argument unused )
243 {
257 {
244 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
258 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
245 *
259 *
246 * @param unused is the starting argument of the RTEMS task
260 * @param unused is the starting argument of the RTEMS task
247 *
261 *
248 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
262 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
249 *
263 *
250 */
264 */
251
265
252 unsigned int i;
266 unsigned int i;
253 unsigned int intEventOut;
267 unsigned int intEventOut;
254 unsigned int coarse_time = 0;
268 unsigned int coarse_time = 0;
255 unsigned int fine_time = 0;
269 unsigned int fine_time = 0;
256 rtems_event_set event_out;
270 rtems_event_set event_out;
257
271
258 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
272 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
259 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
273 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
260 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
274 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
261 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
275 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
262 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
276 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
263 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
277 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
264 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
278 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
265 "ready for dump", // RTEMS_EVENT_7
279 "ready for dump", // RTEMS_EVENT_7
266 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
280 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
267 "tick", // RTEMS_EVENT_9
281 "tick", // RTEMS_EVENT_9
268 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
282 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
269 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
283 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
270 };
284 };
271
285
272 BOOT_PRINTF("in DUMB *** \n")
286 BOOT_PRINTF("in DUMB *** \n")
273
287
274 while(1){
288 while(1){
275 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
289 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
276 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
290 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
277 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
291 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
278 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
292 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
279 intEventOut = (unsigned int) event_out;
293 intEventOut = (unsigned int) event_out;
280 for ( i=0; i<32; i++)
294 for ( i=0; i<32; i++)
281 {
295 {
282 if ( ((intEventOut >> i) & 0x0001) != 0)
296 if ( ((intEventOut >> i) & 0x0001) != 0)
283 {
297 {
284 coarse_time = time_management_regs->coarse_time;
298 coarse_time = time_management_regs->coarse_time;
285 fine_time = time_management_regs->fine_time;
299 fine_time = time_management_regs->fine_time;
286 if (i==8)
300 if (i==8)
287 {
301 {
288 }
302 }
289 if (i==10)
303 if (i==10)
290 {
304 {
291 }
305 }
292 }
306 }
293 }
307 }
294 }
308 }
295 }
309 }
296
310
297 //*****************************
311 //*****************************
298 // init housekeeping parameters
312 // init housekeeping parameters
299
313
300 void init_housekeeping_parameters( void )
314 void init_housekeeping_parameters( void )
301 {
315 {
302 /** This function initialize the housekeeping_packet global variable with default values.
316 /** This function initialize the housekeeping_packet global variable with default values.
303 *
317 *
304 */
318 */
305
319
306 unsigned int i = 0;
320 unsigned int i = 0;
307 unsigned char *parameters;
321 unsigned char *parameters;
308 unsigned char sizeOfHK;
322 unsigned char sizeOfHK;
309
323
310 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
324 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
311
325
312 parameters = (unsigned char*) &housekeeping_packet;
326 parameters = (unsigned char*) &housekeeping_packet;
313
327
314 for(i = 0; i< sizeOfHK; i++)
328 for(i = 0; i< sizeOfHK; i++)
315 {
329 {
316 parameters[i] = 0x00;
330 parameters[i] = 0x00;
317 }
331 }
318
332
319 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
333 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
320 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
334 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
321 housekeeping_packet.reserved = DEFAULT_RESERVED;
335 housekeeping_packet.reserved = DEFAULT_RESERVED;
322 housekeeping_packet.userApplication = CCSDS_USER_APP;
336 housekeeping_packet.userApplication = CCSDS_USER_APP;
323 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
337 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
324 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
338 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
325 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
339 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
326 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
340 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
327 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
341 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
328 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
342 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
329 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
343 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
330 housekeeping_packet.serviceType = TM_TYPE_HK;
344 housekeeping_packet.serviceType = TM_TYPE_HK;
331 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
345 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
332 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
346 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
333 housekeeping_packet.sid = SID_HK;
347 housekeeping_packet.sid = SID_HK;
334
348
335 // init status word
349 // init status word
336 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
350 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
337 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
351 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
338 // init software version
352 // init software version
339 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
353 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
340 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
354 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
341 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
355 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
342 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
356 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
343 // init fpga version
357 // init fpga version
344 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
358 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
345 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
359 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
346 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
360 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
347 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
361 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
348
362
349 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
363 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
350 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
364 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
351 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
365 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
352 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
366 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
353 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
367 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
354 }
368 }
355
369
356 void increment_seq_counter( unsigned short *packetSequenceControl )
370 void increment_seq_counter( unsigned short *packetSequenceControl )
357 {
371 {
358 /** This function increment the sequence counter passes in argument.
372 /** This function increment the sequence counter passes in argument.
359 *
373 *
360 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
374 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
361 *
375 *
362 */
376 */
363
377
364 unsigned short segmentation_grouping_flag;
378 unsigned short segmentation_grouping_flag;
365 unsigned short sequence_cnt;
379 unsigned short sequence_cnt;
366
380
367 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
381 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
368 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
382 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
369
383
370 if ( sequence_cnt < SEQ_CNT_MAX)
384 if ( sequence_cnt < SEQ_CNT_MAX)
371 {
385 {
372 sequence_cnt = sequence_cnt + 1;
386 sequence_cnt = sequence_cnt + 1;
373 }
387 }
374 else
388 else
375 {
389 {
376 sequence_cnt = 0;
390 sequence_cnt = 0;
377 }
391 }
378
392
379 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
393 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
380 }
394 }
381
395
382 void getTime( unsigned char *time)
396 void getTime( unsigned char *time)
383 {
397 {
384 /** This function write the current local time in the time buffer passed in argument.
398 /** This function write the current local time in the time buffer passed in argument.
385 *
399 *
386 */
400 */
387
401
388 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
402 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
389 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
403 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
390 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
404 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
391 time[3] = (unsigned char) (time_management_regs->coarse_time);
405 time[3] = (unsigned char) (time_management_regs->coarse_time);
392 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
406 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
393 time[5] = (unsigned char) (time_management_regs->fine_time);
407 time[5] = (unsigned char) (time_management_regs->fine_time);
394 }
408 }
395
409
396 unsigned long long int getTimeAsUnsignedLongLongInt( )
410 unsigned long long int getTimeAsUnsignedLongLongInt( )
397 {
411 {
398 /** This function write the current local time in the time buffer passed in argument.
412 /** This function write the current local time in the time buffer passed in argument.
399 *
413 *
400 */
414 */
401 unsigned long long int time;
415 unsigned long long int time;
402
416
403 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
417 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
404 + time_management_regs->fine_time;
418 + time_management_regs->fine_time;
405
419
406 return time;
420 return time;
407 }
421 }
408
422
409 void send_dumb_hk( void )
423 void send_dumb_hk( void )
410 {
424 {
411 Packet_TM_LFR_HK_t dummy_hk_packet;
425 Packet_TM_LFR_HK_t dummy_hk_packet;
412 unsigned char *parameters;
426 unsigned char *parameters;
413 unsigned int i;
427 unsigned int i;
414 rtems_id queue_id;
428 rtems_id queue_id;
415
429
416 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
430 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
417 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
431 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
418 dummy_hk_packet.reserved = DEFAULT_RESERVED;
432 dummy_hk_packet.reserved = DEFAULT_RESERVED;
419 dummy_hk_packet.userApplication = CCSDS_USER_APP;
433 dummy_hk_packet.userApplication = CCSDS_USER_APP;
420 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
434 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
421 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
435 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
422 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
436 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
423 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
437 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
424 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
438 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
425 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
439 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
426 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
440 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
427 dummy_hk_packet.serviceType = TM_TYPE_HK;
441 dummy_hk_packet.serviceType = TM_TYPE_HK;
428 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
442 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
429 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
443 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
430 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
444 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
431 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
445 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
432 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
446 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
433 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
447 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
434 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
448 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
435 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
449 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
436 dummy_hk_packet.sid = SID_HK;
450 dummy_hk_packet.sid = SID_HK;
437
451
438 // init status word
452 // init status word
439 dummy_hk_packet.lfr_status_word[0] = 0xff;
453 dummy_hk_packet.lfr_status_word[0] = 0xff;
440 dummy_hk_packet.lfr_status_word[1] = 0xff;
454 dummy_hk_packet.lfr_status_word[1] = 0xff;
441 // init software version
455 // init software version
442 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
456 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
443 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
457 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
444 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
458 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
445 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
459 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
446 // init fpga version
460 // init fpga version
447 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
461 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
448 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
462 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
449 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
463 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
450 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
464 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
451
465
452 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
466 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
453
467
454 for (i=0; i<100; i++)
468 for (i=0; i<100; i++)
455 {
469 {
456 parameters[i] = 0xff;
470 parameters[i] = 0xff;
457 }
471 }
458
472
459 get_message_queue_id_send( &queue_id );
473 get_message_queue_id_send( &queue_id );
460
474
461 rtems_message_queue_send( queue_id, &dummy_hk_packet,
475 rtems_message_queue_send( queue_id, &dummy_hk_packet,
462 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
476 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
463 }
477 }
464
478
465 void get_temperatures( unsigned char *temperatures )
479 void get_temperatures( unsigned char *temperatures )
466 {
480 {
467 unsigned char* temp_scm_ptr;
481 unsigned char* temp_scm_ptr;
468 unsigned char* temp_pcb_ptr;
482 unsigned char* temp_pcb_ptr;
469 unsigned char* temp_fpga_ptr;
483 unsigned char* temp_fpga_ptr;
470
484
471 // SEL1 SEL0
485 // SEL1 SEL0
472 // 0 0 => PCB
486 // 0 0 => PCB
473 // 0 1 => FPGA
487 // 0 1 => FPGA
474 // 1 0 => SCM
488 // 1 0 => SCM
475
489
476 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
490 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
477 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
491 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
478 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
492 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
479
493
480 temperatures[0] = temp_scm_ptr[2];
494 temperatures[0] = temp_scm_ptr[2];
481 temperatures[1] = temp_scm_ptr[3];
495 temperatures[1] = temp_scm_ptr[3];
482 temperatures[2] = temp_pcb_ptr[2];
496 temperatures[2] = temp_pcb_ptr[2];
483 temperatures[3] = temp_pcb_ptr[3];
497 temperatures[3] = temp_pcb_ptr[3];
484 temperatures[4] = temp_fpga_ptr[2];
498 temperatures[4] = temp_fpga_ptr[2];
485 temperatures[5] = temp_fpga_ptr[3];
499 temperatures[5] = temp_fpga_ptr[3];
486 }
500 }
487
501
488 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
502 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
489 {
503 {
490 unsigned char* v_ptr;
504 unsigned char* v_ptr;
491 unsigned char* e1_ptr;
505 unsigned char* e1_ptr;
492 unsigned char* e2_ptr;
506 unsigned char* e2_ptr;
493
507
494 v_ptr = (unsigned char *) &waveform_picker_regs->v;
508 v_ptr = (unsigned char *) &waveform_picker_regs->v;
495 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
509 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
496 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
510 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
497
511
498 spacecraft_potential[0] = v_ptr[2];
512 spacecraft_potential[0] = v_ptr[2];
499 spacecraft_potential[1] = v_ptr[3];
513 spacecraft_potential[1] = v_ptr[3];
500 spacecraft_potential[2] = e1_ptr[2];
514 spacecraft_potential[2] = e1_ptr[2];
501 spacecraft_potential[3] = e1_ptr[3];
515 spacecraft_potential[3] = e1_ptr[3];
502 spacecraft_potential[4] = e2_ptr[2];
516 spacecraft_potential[4] = e2_ptr[2];
503 spacecraft_potential[5] = e2_ptr[3];
517 spacecraft_potential[5] = e2_ptr[3];
504 }
518 }
505
519
506 void get_cpu_load( unsigned char *resource_statistics )
520 void get_cpu_load( unsigned char *resource_statistics )
507 {
521 {
508 unsigned char cpu_load;
522 unsigned char cpu_load;
509
523
510 cpu_load = lfr_rtems_cpu_usage_report();
524 cpu_load = lfr_rtems_cpu_usage_report();
511
525
512 // HK_LFR_CPU_LOAD
526 // HK_LFR_CPU_LOAD
513 resource_statistics[0] = cpu_load;
527 resource_statistics[0] = cpu_load;
514
528
515 // HK_LFR_CPU_LOAD_MAX
529 // HK_LFR_CPU_LOAD_MAX
516 if (cpu_load > resource_statistics[1])
530 if (cpu_load > resource_statistics[1])
517 {
531 {
518 resource_statistics[1] = cpu_load;
532 resource_statistics[1] = cpu_load;
519 }
533 }
520
534
521 // CPU_LOAD_AVE
535 // CPU_LOAD_AVE
522 resource_statistics[2] = 0;
536 resource_statistics[2] = 0;
523
537
524 #ifndef PRINT_TASK_STATISTICS
538 #ifndef PRINT_TASK_STATISTICS
525 rtems_cpu_usage_reset();
539 rtems_cpu_usage_reset();
526 #endif
540 #endif
527
541
528 }
542 }
529
543
530 void set_hk_lfr_sc_potential_flag( bool state )
544 void set_hk_lfr_sc_potential_flag( bool state )
531 {
545 {
532 if (state == true)
546 if (state == true)
533 {
547 {
534 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
548 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
535 }
549 }
536 else
550 else
537 {
551 {
538 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
552 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
539 }
553 }
540 }
554 }
541
555
542 void set_hk_lfr_mag_fields_flag( bool state )
556 void set_hk_lfr_mag_fields_flag( bool state )
543 {
557 {
544 if (state == true)
558 if (state == true)
545 {
559 {
546 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000]
560 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000]
547 }
561 }
548 else
562 else
549 {
563 {
550 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xd7; // [1101 1111]
564 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xd7; // [1101 1111]
551 }
565 }
552 }
566 }
553
567
554 void set_hk_lfr_calib_enable( bool state )
568 void set_hk_lfr_calib_enable( bool state )
555 {
569 {
556 if (state == true)
570 if (state == true)
557 {
571 {
558 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
572 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
559 }
573 }
560 else
574 else
561 {
575 {
562 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
576 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
563 }
577 }
564 }
578 }
565
579
566 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
580 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
567 {
581 {
568 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
582 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
569 | (lfr_reset_cause & 0x07 ); // [0000 0111]
583 | (lfr_reset_cause & 0x07 ); // [0000 0111]
570 }
584 }
@@ -1,1308 +1,1316
1 /** Functions related to the SpaceWire interface.
1 /** Functions related to the SpaceWire interface.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle SpaceWire transmissions:
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
11 *
12 */
12 */
13
13
14 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
15
15
16 rtems_name semq_name;
16 rtems_name semq_name;
17 rtems_id semq_id;
17 rtems_id semq_id;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24
24
25 extern struct grgpio_regs_str *grgpio_regs;
26 #define OUTPUT_1 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf8;
27 #define OUTPUT_0 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x02;
28
25 //***********
29 //***********
26 // RTEMS TASK
30 // RTEMS TASK
27 rtems_task spiq_task(rtems_task_argument unused)
31 rtems_task spiq_task(rtems_task_argument unused)
28 {
32 {
29 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
30 *
34 *
31 * @param unused is the starting argument of the RTEMS task
35 * @param unused is the starting argument of the RTEMS task
32 *
36 *
33 */
37 */
34
38
35 rtems_event_set event_out;
39 rtems_event_set event_out;
36 rtems_status_code status;
40 rtems_status_code status;
37 int linkStatus;
41 int linkStatus;
38
42
39 BOOT_PRINTF("in SPIQ *** \n")
43 BOOT_PRINTF("in SPIQ *** \n")
40
44
41 while(true){
45 while(true){
42 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
43 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
44
48
45 // [0] SUSPEND RECV AND SEND TASKS
49 // [0] SUSPEND RECV AND SEND TASKS
46 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
47 if ( status != RTEMS_SUCCESSFUL ) {
51 if ( status != RTEMS_SUCCESSFUL ) {
48 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
49 }
53 }
50 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
51 if ( status != RTEMS_SUCCESSFUL ) {
55 if ( status != RTEMS_SUCCESSFUL ) {
52 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
53 }
57 }
54
58
55 // [1] CHECK THE LINK
59 // [1] CHECK THE LINK
56 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
57 if ( linkStatus != 5) {
61 if ( linkStatus != 5) {
58 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
59 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
60 }
64 }
61
65
62 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
63 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
64 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
68 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
65 {
69 {
66 spacewire_compute_stats_offsets();
70 spacewire_compute_stats_offsets();
67 status = spacewire_reset_link( );
71 status = spacewire_reset_link( );
68 }
72 }
69 else // [2.b] in run state, start the link
73 else // [2.b] in run state, start the link
70 {
74 {
71 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 status = spacewire_stop_and_start_link( fdSPW ); // start the link
72 if ( status != RTEMS_SUCCESSFUL)
76 if ( status != RTEMS_SUCCESSFUL)
73 {
77 {
74 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
75 }
79 }
76 }
80 }
77
81
78 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
79 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
80 {
84 {
81 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
82 if ( status != RTEMS_SUCCESSFUL ) {
86 if ( status != RTEMS_SUCCESSFUL ) {
83 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
84 }
88 }
85 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
86 if ( status != RTEMS_SUCCESSFUL ) {
90 if ( status != RTEMS_SUCCESSFUL ) {
87 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
88 }
92 }
89 }
93 }
90 else // [3.b] the link is not in run state, go in STANDBY mode
94 else // [3.b] the link is not in run state, go in STANDBY mode
91 {
95 {
92 status = enter_mode( LFR_MODE_STANDBY, 0 );
96 status = enter_mode( LFR_MODE_STANDBY, 0 );
93 if ( status != RTEMS_SUCCESSFUL ) {
97 if ( status != RTEMS_SUCCESSFUL ) {
94 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
95 }
99 }
96 // wake the WTDG task up to wait for the link recovery
100 // wake the WTDG task up to wait for the link recovery
97 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
101 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
98 status = rtems_task_suspend( RTEMS_SELF );
102 status = rtems_task_suspend( RTEMS_SELF );
99 }
103 }
100 }
104 }
101 }
105 }
102
106
103 rtems_task recv_task( rtems_task_argument unused )
107 rtems_task recv_task( rtems_task_argument unused )
104 {
108 {
105 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
109 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
106 *
110 *
107 * @param unused is the starting argument of the RTEMS task
111 * @param unused is the starting argument of the RTEMS task
108 *
112 *
109 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
113 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
110 * 1. It reads the incoming data.
114 * 1. It reads the incoming data.
111 * 2. Launches the acceptance procedure.
115 * 2. Launches the acceptance procedure.
112 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
116 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
113 *
117 *
114 */
118 */
115
119
116 int len;
120 int len;
117 ccsdsTelecommandPacket_t currentTC;
121 ccsdsTelecommandPacket_t currentTC;
118 unsigned char computed_CRC[ 2 ];
122 unsigned char computed_CRC[ 2 ];
119 unsigned char currentTC_LEN_RCV[ 2 ];
123 unsigned char currentTC_LEN_RCV[ 2 ];
120 unsigned char destinationID;
124 unsigned char destinationID;
121 unsigned int estimatedPacketLength;
125 unsigned int estimatedPacketLength;
122 unsigned int parserCode;
126 unsigned int parserCode;
123 rtems_status_code status;
127 rtems_status_code status;
124 rtems_id queue_recv_id;
128 rtems_id queue_recv_id;
125 rtems_id queue_send_id;
129 rtems_id queue_send_id;
126
130
127 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
131 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
128
132
129 status = get_message_queue_id_recv( &queue_recv_id );
133 status = get_message_queue_id_recv( &queue_recv_id );
130 if (status != RTEMS_SUCCESSFUL)
134 if (status != RTEMS_SUCCESSFUL)
131 {
135 {
132 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
136 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
133 }
137 }
134
138
135 status = get_message_queue_id_send( &queue_send_id );
139 status = get_message_queue_id_send( &queue_send_id );
136 if (status != RTEMS_SUCCESSFUL)
140 if (status != RTEMS_SUCCESSFUL)
137 {
141 {
138 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
142 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
139 }
143 }
140
144
141 BOOT_PRINTF("in RECV *** \n")
145 BOOT_PRINTF("in RECV *** \n")
142
146
143 while(1)
147 while(1)
144 {
148 {
145 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
149 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
146 if (len == -1){ // error during the read call
150 if (len == -1){ // error during the read call
147 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
151 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
148 }
152 }
149 else {
153 else {
150 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
154 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
151 PRINTF("in RECV *** packet lenght too short\n")
155 PRINTF("in RECV *** packet lenght too short\n")
152 }
156 }
153 else {
157 else {
154 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
158 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
155 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
159 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
156 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
160 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
157 // CHECK THE TC
161 // CHECK THE TC
158 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
162 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
159 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
163 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
160 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
164 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
161 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
165 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
162 || (parserCode == WRONG_SRC_ID) )
166 || (parserCode == WRONG_SRC_ID) )
163 { // send TM_LFR_TC_EXE_CORRUPTED
167 { // send TM_LFR_TC_EXE_CORRUPTED
164 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
168 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
165 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
169 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
166 &&
170 &&
167 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
171 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
168 )
172 )
169 {
173 {
170 if ( parserCode == WRONG_SRC_ID )
174 if ( parserCode == WRONG_SRC_ID )
171 {
175 {
172 destinationID = SID_TC_GROUND;
176 destinationID = SID_TC_GROUND;
173 }
177 }
174 else
178 else
175 {
179 {
176 destinationID = currentTC.sourceID;
180 destinationID = currentTC.sourceID;
177 }
181 }
178 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
182 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
179 computed_CRC, currentTC_LEN_RCV,
183 computed_CRC, currentTC_LEN_RCV,
180 destinationID );
184 destinationID );
181 }
185 }
182 }
186 }
183 else
187 else
184 { // send valid TC to the action launcher
188 { // send valid TC to the action launcher
185 status = rtems_message_queue_send( queue_recv_id, &currentTC,
189 status = rtems_message_queue_send( queue_recv_id, &currentTC,
186 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
190 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
187 }
191 }
188 }
192 }
189 }
193 }
190
194
191 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
195 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
192
196
193 }
197 }
194 }
198 }
195
199
196 rtems_task send_task( rtems_task_argument argument)
200 rtems_task send_task( rtems_task_argument argument)
197 {
201 {
198 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
202 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
199 *
203 *
200 * @param unused is the starting argument of the RTEMS task
204 * @param unused is the starting argument of the RTEMS task
201 *
205 *
202 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
206 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
203 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
207 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
204 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
208 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
205 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
209 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
206 * data it contains.
210 * data it contains.
207 *
211 *
208 */
212 */
209
213
210 rtems_status_code status; // RTEMS status code
214 rtems_status_code status; // RTEMS status code
211 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
215 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
212 ring_node *incomingRingNodePtr;
216 ring_node *incomingRingNodePtr;
213 int ring_node_address;
217 int ring_node_address;
214 char *charPtr;
218 char *charPtr;
215 spw_ioctl_pkt_send *spw_ioctl_send;
219 spw_ioctl_pkt_send *spw_ioctl_send;
216 size_t size; // size of the incoming TC packet
220 size_t size; // size of the incoming TC packet
217 rtems_id queue_send_id;
221 rtems_id queue_send_id;
218 unsigned int sid;
222 unsigned int sid;
219 unsigned char sidAsUnsignedChar;
223 unsigned char sidAsUnsignedChar;
220 unsigned char type;
224 unsigned char type;
221
225
222 incomingRingNodePtr = NULL;
226 incomingRingNodePtr = NULL;
223 ring_node_address = 0;
227 ring_node_address = 0;
224 charPtr = (char *) &ring_node_address;
228 charPtr = (char *) &ring_node_address;
225 sid = 0;
229 sid = 0;
226 sidAsUnsignedChar = 0;
230 sidAsUnsignedChar = 0;
227
231
228 init_header_cwf( &headerCWF );
232 init_header_cwf( &headerCWF );
229 init_header_swf( &headerSWF );
233 init_header_swf( &headerSWF );
230 init_header_asm( &headerASM );
234 init_header_asm( &headerASM );
231
235
232 status = get_message_queue_id_send( &queue_send_id );
236 status = get_message_queue_id_send( &queue_send_id );
233 if (status != RTEMS_SUCCESSFUL)
237 if (status != RTEMS_SUCCESSFUL)
234 {
238 {
235 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
239 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
236 }
240 }
237
241
238 BOOT_PRINTF("in SEND *** \n")
242 BOOT_PRINTF("in SEND *** \n")
239
243
240 while(1)
244 while(1)
241 {
245 {
242 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
246 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
243 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
247 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
244
248
245 if (status!=RTEMS_SUCCESSFUL)
249 if (status!=RTEMS_SUCCESSFUL)
246 {
250 {
247 PRINTF1("in SEND *** (1) ERR = %d\n", status)
251 PRINTF1("in SEND *** (1) ERR = %d\n", status)
248 }
252 }
249 else
253 else
250 {
254 {
251 if ( size == sizeof(ring_node*) )
255 if ( size == sizeof(ring_node*) )
252 {
256 {
253 charPtr[0] = incomingData[0];
257 charPtr[0] = incomingData[0];
254 charPtr[1] = incomingData[1];
258 charPtr[1] = incomingData[1];
255 charPtr[2] = incomingData[2];
259 charPtr[2] = incomingData[2];
256 charPtr[3] = incomingData[3];
260 charPtr[3] = incomingData[3];
257 incomingRingNodePtr = (ring_node*) ring_node_address;
261 incomingRingNodePtr = (ring_node*) ring_node_address;
258 sid = incomingRingNodePtr->sid;
262 sid = incomingRingNodePtr->sid;
259 if ( (sid==SID_NORM_CWF_LONG_F3)
263 if ( (sid==SID_NORM_CWF_LONG_F3)
260 || (sid==SID_BURST_CWF_F2 )
264 || (sid==SID_BURST_CWF_F2 )
261 || (sid==SID_SBM1_CWF_F1 )
265 || (sid==SID_SBM1_CWF_F1 )
262 || (sid==SID_SBM2_CWF_F2 ))
266 || (sid==SID_SBM2_CWF_F2 ))
263 {
267 {
264 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
268 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
265 }
269 }
266 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
270 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
267 {
271 {
268 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
272 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
269 }
273 }
270 else if ( (sid==SID_NORM_CWF_F3) )
274 else if ( (sid==SID_NORM_CWF_F3) )
271 {
275 {
272 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
276 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
273 }
277 }
274 else if (sid==SID_NORM_ASM_F0)
278 else if (sid==SID_NORM_ASM_F0)
275 {
279 {
276 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
280 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
277 }
281 }
278 else if (sid==SID_NORM_ASM_F1)
282 else if (sid==SID_NORM_ASM_F1)
279 {
283 {
280 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
284 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
281 }
285 }
282 else if (sid==SID_NORM_ASM_F2)
286 else if (sid==SID_NORM_ASM_F2)
283 {
287 {
284 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
288 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
285 }
289 }
286 else if ( sid==TM_CODE_K_DUMP )
290 else if ( sid==TM_CODE_K_DUMP )
287 {
291 {
288 spw_send_k_dump( incomingRingNodePtr );
292 spw_send_k_dump( incomingRingNodePtr );
289 }
293 }
290 else
294 else
291 {
295 {
292 PRINTF1("unexpected sid = %d\n", sid);
296 PRINTF1("unexpected sid = %d\n", sid);
293 }
297 }
294 }
298 }
295 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
299 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
296 {
300 {
297 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
301 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
298 sid = sidAsUnsignedChar;
302 sid = sidAsUnsignedChar;
299 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
303 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
300 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
304 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
301 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
305 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
302 {
306 {
303 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
307 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
304 }
308 }
305
309
306 status = write( fdSPW, incomingData, size );
310 status = write( fdSPW, incomingData, size );
307 if (status == -1){
311 if (status == -1){
308 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
312 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
309 }
313 }
310 }
314 }
311 else // the incoming message is a spw_ioctl_pkt_send structure
315 else // the incoming message is a spw_ioctl_pkt_send structure
312 {
316 {
313 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
317 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
314 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
318 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
315 if (status == -1){
319 if (status == -1){
316 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
320 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
317 }
321 }
318 }
322 }
319 }
323 }
320
324
321 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
325 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
322
326
323 }
327 }
324 }
328 }
325
329
326 rtems_task wtdg_task( rtems_task_argument argument )
330 rtems_task wtdg_task( rtems_task_argument argument )
327 {
331 {
328 rtems_event_set event_out;
332 rtems_event_set event_out;
329 rtems_status_code status;
333 rtems_status_code status;
330 int linkStatus;
334 int linkStatus;
331
335
332 BOOT_PRINTF("in WTDG ***\n")
336 BOOT_PRINTF("in WTDG ***\n")
333
337
334 while(1)
338 while(1)
335 {
339 {
336 // wait for an RTEMS_EVENT
340 // wait for an RTEMS_EVENT
337 rtems_event_receive( RTEMS_EVENT_0,
341 rtems_event_receive( RTEMS_EVENT_0,
338 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
342 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
339 PRINTF("in WTDG *** wait for the link\n")
343 PRINTF("in WTDG *** wait for the link\n")
340 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
344 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
341 while( linkStatus != 5) // wait for the link
345 while( linkStatus != 5) // wait for the link
342 {
346 {
343 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
347 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
344 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
345 }
349 }
346
350
347 status = spacewire_stop_and_start_link( fdSPW );
351 status = spacewire_stop_and_start_link( fdSPW );
348
352
349 if (status != RTEMS_SUCCESSFUL)
353 if (status != RTEMS_SUCCESSFUL)
350 {
354 {
351 PRINTF1("in WTDG *** ERR link not started %d\n", status)
355 PRINTF1("in WTDG *** ERR link not started %d\n", status)
352 }
356 }
353 else
357 else
354 {
358 {
355 PRINTF("in WTDG *** OK link started\n")
359 PRINTF("in WTDG *** OK link started\n")
356 }
360 }
357
361
358 // restart the SPIQ task
362 // restart the SPIQ task
359 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
363 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
360 if ( status != RTEMS_SUCCESSFUL ) {
364 if ( status != RTEMS_SUCCESSFUL ) {
361 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
365 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
362 }
366 }
363
367
364 // restart RECV and SEND
368 // restart RECV and SEND
365 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
369 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
366 if ( status != RTEMS_SUCCESSFUL ) {
370 if ( status != RTEMS_SUCCESSFUL ) {
367 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
371 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
368 }
372 }
369 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
373 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
370 if ( status != RTEMS_SUCCESSFUL ) {
374 if ( status != RTEMS_SUCCESSFUL ) {
371 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
375 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
372 }
376 }
373 }
377 }
374 }
378 }
375
379
376 //****************
380 //****************
377 // OTHER FUNCTIONS
381 // OTHER FUNCTIONS
378 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
382 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
379 {
383 {
380 /** This function opens the SpaceWire link.
384 /** This function opens the SpaceWire link.
381 *
385 *
382 * @return a valid file descriptor in case of success, -1 in case of a failure
386 * @return a valid file descriptor in case of success, -1 in case of a failure
383 *
387 *
384 */
388 */
385 rtems_status_code status;
389 rtems_status_code status;
386
390
387 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
391 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
388 if ( fdSPW < 0 ) {
392 if ( fdSPW < 0 ) {
389 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
393 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
390 }
394 }
391 else
395 else
392 {
396 {
393 status = RTEMS_SUCCESSFUL;
397 status = RTEMS_SUCCESSFUL;
394 }
398 }
395
399
396 return status;
400 return status;
397 }
401 }
398
402
399 int spacewire_start_link( int fd )
403 int spacewire_start_link( int fd )
400 {
404 {
401 rtems_status_code status;
405 rtems_status_code status;
402
406
403 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
407 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
404 // -1 default hardcoded driver timeout
408 // -1 default hardcoded driver timeout
405
409
406 return status;
410 return status;
407 }
411 }
408
412
409 int spacewire_stop_and_start_link( int fd )
413 int spacewire_stop_and_start_link( int fd )
410 {
414 {
411 rtems_status_code status;
415 rtems_status_code status;
412
416
413 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
417 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
414 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
418 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
415 // -1 default hardcoded driver timeout
419 // -1 default hardcoded driver timeout
416
420
417 return status;
421 return status;
418 }
422 }
419
423
420 int spacewire_configure_link( int fd )
424 int spacewire_configure_link( int fd )
421 {
425 {
422 /** This function configures the SpaceWire link.
426 /** This function configures the SpaceWire link.
423 *
427 *
424 * @return GR-RTEMS-DRIVER directive status codes:
428 * @return GR-RTEMS-DRIVER directive status codes:
425 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
429 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
426 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
430 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
427 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
431 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
428 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
432 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
429 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
433 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
430 * - 5 EIO - Error when writing to grswp hardware registers.
434 * - 5 EIO - Error when writing to grswp hardware registers.
431 * - 2 ENOENT - No such file or directory
435 * - 2 ENOENT - No such file or directory
432 */
436 */
433
437
434 rtems_status_code status;
438 rtems_status_code status;
435
439
436 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
440 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
437 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
441 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
438
442
439 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
443 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
440 if (status!=RTEMS_SUCCESSFUL) {
444 if (status!=RTEMS_SUCCESSFUL) {
441 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
445 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
442 }
446 }
443 //
447 //
444 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
448 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
445 if (status!=RTEMS_SUCCESSFUL) {
449 if (status!=RTEMS_SUCCESSFUL) {
446 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
450 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
447 }
451 }
448 //
452 //
449 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
453 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
450 if (status!=RTEMS_SUCCESSFUL) {
454 if (status!=RTEMS_SUCCESSFUL) {
451 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
455 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
452 }
456 }
453 //
457 //
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
458 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
455 if (status!=RTEMS_SUCCESSFUL) {
459 if (status!=RTEMS_SUCCESSFUL) {
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
460 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
457 }
461 }
458 //
462 //
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
463 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
460 if (status!=RTEMS_SUCCESSFUL) {
464 if (status!=RTEMS_SUCCESSFUL) {
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
465 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
462 }
466 }
463 //
467 //
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
468 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
465 if (status!=RTEMS_SUCCESSFUL) {
469 if (status!=RTEMS_SUCCESSFUL) {
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
470 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
467 }
471 }
468 //
472 //
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
473 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
470 if (status!=RTEMS_SUCCESSFUL) {
474 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
475 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
472 }
476 }
473
477
474 return status;
478 return status;
475 }
479 }
476
480
477 int spacewire_reset_link( void )
481 int spacewire_reset_link( void )
478 {
482 {
479 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
483 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
480 *
484 *
481 * @return RTEMS directive status code:
485 * @return RTEMS directive status code:
482 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
486 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
483 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
487 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
484 *
488 *
485 */
489 */
486
490
487 rtems_status_code status_spw;
491 rtems_status_code status_spw;
488 rtems_status_code status;
492 rtems_status_code status;
489 int i;
493 int i;
490
494
491 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
495 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
492 {
496 {
493 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
497 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
494
498
495 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
499 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
496
500
497 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
501 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
498
502
499 status_spw = spacewire_stop_and_start_link( fdSPW );
503 status_spw = spacewire_stop_and_start_link( fdSPW );
500 if ( status_spw != RTEMS_SUCCESSFUL )
504 if ( status_spw != RTEMS_SUCCESSFUL )
501 {
505 {
502 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
506 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
503 }
507 }
504
508
505 if ( status_spw == RTEMS_SUCCESSFUL)
509 if ( status_spw == RTEMS_SUCCESSFUL)
506 {
510 {
507 break;
511 break;
508 }
512 }
509 }
513 }
510
514
511 return status_spw;
515 return status_spw;
512 }
516 }
513
517
514 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
518 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
515 {
519 {
516 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
520 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
517 *
521 *
518 * @param val is the value, 0 or 1, used to set the value of the NP bit.
522 * @param val is the value, 0 or 1, used to set the value of the NP bit.
519 * @param regAddr is the address of the GRSPW control register.
523 * @param regAddr is the address of the GRSPW control register.
520 *
524 *
521 * NP is the bit 20 of the GRSPW control register.
525 * NP is the bit 20 of the GRSPW control register.
522 *
526 *
523 */
527 */
524
528
525 unsigned int *spwptr = (unsigned int*) regAddr;
529 unsigned int *spwptr = (unsigned int*) regAddr;
526
530
527 if (val == 1) {
531 if (val == 1) {
528 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
532 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
529 }
533 }
530 if (val== 0) {
534 if (val== 0) {
531 *spwptr = *spwptr & 0xffdfffff;
535 *spwptr = *spwptr & 0xffdfffff;
532 }
536 }
533 }
537 }
534
538
535 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
539 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
536 {
540 {
537 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
541 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
538 *
542 *
539 * @param val is the value, 0 or 1, used to set the value of the RE bit.
543 * @param val is the value, 0 or 1, used to set the value of the RE bit.
540 * @param regAddr is the address of the GRSPW control register.
544 * @param regAddr is the address of the GRSPW control register.
541 *
545 *
542 * RE is the bit 16 of the GRSPW control register.
546 * RE is the bit 16 of the GRSPW control register.
543 *
547 *
544 */
548 */
545
549
546 unsigned int *spwptr = (unsigned int*) regAddr;
550 unsigned int *spwptr = (unsigned int*) regAddr;
547
551
548 if (val == 1)
552 if (val == 1)
549 {
553 {
550 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
554 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
551 }
555 }
552 if (val== 0)
556 if (val== 0)
553 {
557 {
554 *spwptr = *spwptr & 0xfffdffff;
558 *spwptr = *spwptr & 0xfffdffff;
555 }
559 }
556 }
560 }
557
561
558 void spacewire_compute_stats_offsets( void )
562 void spacewire_compute_stats_offsets( void )
559 {
563 {
560 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
564 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
561 *
565 *
562 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
566 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
563 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
567 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
564 * during the open systel call).
568 * during the open systel call).
565 *
569 *
566 */
570 */
567
571
568 spw_stats spacewire_stats_grspw;
572 spw_stats spacewire_stats_grspw;
569 rtems_status_code status;
573 rtems_status_code status;
570
574
571 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
575 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
572
576
573 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
577 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
574 + spacewire_stats.packets_received;
578 + spacewire_stats.packets_received;
575 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
579 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
576 + spacewire_stats.packets_sent;
580 + spacewire_stats.packets_sent;
577 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
581 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
578 + spacewire_stats.parity_err;
582 + spacewire_stats.parity_err;
579 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
583 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
580 + spacewire_stats.disconnect_err;
584 + spacewire_stats.disconnect_err;
581 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
585 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
582 + spacewire_stats.escape_err;
586 + spacewire_stats.escape_err;
583 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
587 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
584 + spacewire_stats.credit_err;
588 + spacewire_stats.credit_err;
585 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
589 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
586 + spacewire_stats.write_sync_err;
590 + spacewire_stats.write_sync_err;
587 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
591 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
588 + spacewire_stats.rx_rmap_header_crc_err;
592 + spacewire_stats.rx_rmap_header_crc_err;
589 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
593 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
590 + spacewire_stats.rx_rmap_data_crc_err;
594 + spacewire_stats.rx_rmap_data_crc_err;
591 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
595 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
592 + spacewire_stats.early_ep;
596 + spacewire_stats.early_ep;
593 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
597 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
594 + spacewire_stats.invalid_address;
598 + spacewire_stats.invalid_address;
595 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
599 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
596 + spacewire_stats.rx_eep_err;
600 + spacewire_stats.rx_eep_err;
597 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
601 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
598 + spacewire_stats.rx_truncated;
602 + spacewire_stats.rx_truncated;
599 }
603 }
600
604
601 void spacewire_update_statistics( void )
605 void spacewire_update_statistics( void )
602 {
606 {
603 rtems_status_code status;
607 rtems_status_code status;
604 spw_stats spacewire_stats_grspw;
608 spw_stats spacewire_stats_grspw;
605
609
606 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
610 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
607
611
608 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
612 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
609 + spacewire_stats_grspw.packets_received;
613 + spacewire_stats_grspw.packets_received;
610 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
614 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
611 + spacewire_stats_grspw.packets_sent;
615 + spacewire_stats_grspw.packets_sent;
612 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
616 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
613 + spacewire_stats_grspw.parity_err;
617 + spacewire_stats_grspw.parity_err;
614 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
618 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
615 + spacewire_stats_grspw.disconnect_err;
619 + spacewire_stats_grspw.disconnect_err;
616 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
620 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
617 + spacewire_stats_grspw.escape_err;
621 + spacewire_stats_grspw.escape_err;
618 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
622 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
619 + spacewire_stats_grspw.credit_err;
623 + spacewire_stats_grspw.credit_err;
620 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
624 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
621 + spacewire_stats_grspw.write_sync_err;
625 + spacewire_stats_grspw.write_sync_err;
622 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
626 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
623 + spacewire_stats_grspw.rx_rmap_header_crc_err;
627 + spacewire_stats_grspw.rx_rmap_header_crc_err;
624 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
628 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
625 + spacewire_stats_grspw.rx_rmap_data_crc_err;
629 + spacewire_stats_grspw.rx_rmap_data_crc_err;
626 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
630 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
627 + spacewire_stats_grspw.early_ep;
631 + spacewire_stats_grspw.early_ep;
628 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
632 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
629 + spacewire_stats_grspw.invalid_address;
633 + spacewire_stats_grspw.invalid_address;
630 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
634 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
631 + spacewire_stats_grspw.rx_eep_err;
635 + spacewire_stats_grspw.rx_eep_err;
632 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
636 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
633 + spacewire_stats_grspw.rx_truncated;
637 + spacewire_stats_grspw.rx_truncated;
634 //spacewire_stats.tx_link_err;
638 //spacewire_stats.tx_link_err;
635
639
636 //****************************
640 //****************************
637 // DPU_SPACEWIRE_IF_STATISTICS
641 // DPU_SPACEWIRE_IF_STATISTICS
638 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
642 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
639 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
643 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
640 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
644 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
641 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
645 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
642 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
646 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
643 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
647 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
644
648
645 //******************************************
649 //******************************************
646 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
650 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
647 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
651 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
648 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
652 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
649 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
653 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
650 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
654 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
651 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
655 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
652
656
653 //*********************************************
657 //*********************************************
654 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
658 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
655 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
659 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
656 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
660 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
657 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
661 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
658 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
662 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
659 }
663 }
660
664
661 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
665 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
662 {
666 {
667 OUTPUT_1;
668
663 // a valid timecode has been received, write it in the HK report
669 // a valid timecode has been received, write it in the HK report
664 unsigned int *grspwPtr;
670 unsigned int *grspwPtr;
665 unsigned char timecodeCtr;
671 unsigned char timecodeCtr;
666 unsigned char updateTimeCtr;
672 unsigned char updateTimeCtr;
667
673
668 grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
674 grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
669
675
670 housekeeping_packet.hk_lfr_dpu_spw_last_timc = (unsigned char) (grspwPtr[0] & 0xff); // [1111 1111]
676 housekeeping_packet.hk_lfr_dpu_spw_last_timc = (unsigned char) (grspwPtr[0] & 0xff); // [1111 1111]
671 timecodeCtr = (unsigned char) (grspwPtr[0] & 0x3f); // [0011 1111]
677 timecodeCtr = (unsigned char) (grspwPtr[0] & 0x3f); // [0011 1111]
672 updateTimeCtr = time_management_regs->coarse_time_load & 0x3f; // [0011 1111]
678 updateTimeCtr = time_management_regs->coarse_time_load & 0x3f; // [0011 1111]
673
679
674 // update the number of valid timecodes that have been received
680 // update the number of valid timecodes that have been received
675 if (housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt == 255)
681 if (housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt == 255)
676 {
682 {
677 housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt = 0;
683 housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt = 0;
678 }
684 }
679 else
685 else
680 {
686 {
681 housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt = housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt + 1;
687 housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt = housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt + 1;
682 }
688 }
683
689
684 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
690 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
685 if (timecodeCtr != updateTimeCtr)
691 if (timecodeCtr != updateTimeCtr)
686 {
692 {
687 if (housekeeping_packet.hk_lfr_time_timecode_ctr == 255)
693 if (housekeeping_packet.hk_lfr_time_timecode_ctr == 255)
688 {
694 {
689 housekeeping_packet.hk_lfr_time_timecode_ctr = 0;
695 housekeeping_packet.hk_lfr_time_timecode_ctr = 0;
690 }
696 }
691 else
697 else
692 {
698 {
693 housekeeping_packet.hk_lfr_time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr + 1;
699 housekeeping_packet.hk_lfr_time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr + 1;
694 }
700 }
695 }
701 }
702
703 OUTPUT_0;
696 }
704 }
697
705
698 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
706 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
699 {
707 {
700 int linkStatus;
708 int linkStatus;
701 rtems_status_code status;
709 rtems_status_code status;
702
710
703 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
711 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
704
712
705 if ( linkStatus == 5) {
713 if ( linkStatus == 5) {
706 PRINTF("in spacewire_reset_link *** link is running\n")
714 PRINTF("in spacewire_reset_link *** link is running\n")
707 status = RTEMS_SUCCESSFUL;
715 status = RTEMS_SUCCESSFUL;
708 }
716 }
709 }
717 }
710
718
711 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
719 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
712 {
720 {
713 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
721 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
714 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
722 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
715 header->reserved = DEFAULT_RESERVED;
723 header->reserved = DEFAULT_RESERVED;
716 header->userApplication = CCSDS_USER_APP;
724 header->userApplication = CCSDS_USER_APP;
717 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
725 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
718 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
726 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
719 header->packetLength[0] = 0x00;
727 header->packetLength[0] = 0x00;
720 header->packetLength[1] = 0x00;
728 header->packetLength[1] = 0x00;
721 // DATA FIELD HEADER
729 // DATA FIELD HEADER
722 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
730 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
723 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
731 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
724 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
732 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
725 header->destinationID = TM_DESTINATION_ID_GROUND;
733 header->destinationID = TM_DESTINATION_ID_GROUND;
726 header->time[0] = 0x00;
734 header->time[0] = 0x00;
727 header->time[0] = 0x00;
735 header->time[0] = 0x00;
728 header->time[0] = 0x00;
736 header->time[0] = 0x00;
729 header->time[0] = 0x00;
737 header->time[0] = 0x00;
730 header->time[0] = 0x00;
738 header->time[0] = 0x00;
731 header->time[0] = 0x00;
739 header->time[0] = 0x00;
732 // AUXILIARY DATA HEADER
740 // AUXILIARY DATA HEADER
733 header->sid = 0x00;
741 header->sid = 0x00;
734 header->hkBIA = DEFAULT_HKBIA;
742 header->hkBIA = DEFAULT_HKBIA;
735 header->blkNr[0] = 0x00;
743 header->blkNr[0] = 0x00;
736 header->blkNr[1] = 0x00;
744 header->blkNr[1] = 0x00;
737 }
745 }
738
746
739 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
747 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
740 {
748 {
741 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
749 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
742 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
750 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
743 header->reserved = DEFAULT_RESERVED;
751 header->reserved = DEFAULT_RESERVED;
744 header->userApplication = CCSDS_USER_APP;
752 header->userApplication = CCSDS_USER_APP;
745 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
753 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
746 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
754 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
747 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
755 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
748 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
756 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
749 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
757 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
750 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
758 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
751 // DATA FIELD HEADER
759 // DATA FIELD HEADER
752 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
760 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
753 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
761 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
754 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
762 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
755 header->destinationID = TM_DESTINATION_ID_GROUND;
763 header->destinationID = TM_DESTINATION_ID_GROUND;
756 header->time[0] = 0x00;
764 header->time[0] = 0x00;
757 header->time[0] = 0x00;
765 header->time[0] = 0x00;
758 header->time[0] = 0x00;
766 header->time[0] = 0x00;
759 header->time[0] = 0x00;
767 header->time[0] = 0x00;
760 header->time[0] = 0x00;
768 header->time[0] = 0x00;
761 header->time[0] = 0x00;
769 header->time[0] = 0x00;
762 // AUXILIARY DATA HEADER
770 // AUXILIARY DATA HEADER
763 header->sid = 0x00;
771 header->sid = 0x00;
764 header->hkBIA = DEFAULT_HKBIA;
772 header->hkBIA = DEFAULT_HKBIA;
765 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
773 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
766 header->pktNr = 0x00;
774 header->pktNr = 0x00;
767 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
775 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
768 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
776 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
769 }
777 }
770
778
771 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
779 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
772 {
780 {
773 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
781 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
774 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
782 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
775 header->reserved = DEFAULT_RESERVED;
783 header->reserved = DEFAULT_RESERVED;
776 header->userApplication = CCSDS_USER_APP;
784 header->userApplication = CCSDS_USER_APP;
777 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
785 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
778 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
786 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
779 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
787 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
780 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
788 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
781 header->packetLength[0] = 0x00;
789 header->packetLength[0] = 0x00;
782 header->packetLength[1] = 0x00;
790 header->packetLength[1] = 0x00;
783 // DATA FIELD HEADER
791 // DATA FIELD HEADER
784 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
792 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
785 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
793 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
786 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
794 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
787 header->destinationID = TM_DESTINATION_ID_GROUND;
795 header->destinationID = TM_DESTINATION_ID_GROUND;
788 header->time[0] = 0x00;
796 header->time[0] = 0x00;
789 header->time[0] = 0x00;
797 header->time[0] = 0x00;
790 header->time[0] = 0x00;
798 header->time[0] = 0x00;
791 header->time[0] = 0x00;
799 header->time[0] = 0x00;
792 header->time[0] = 0x00;
800 header->time[0] = 0x00;
793 header->time[0] = 0x00;
801 header->time[0] = 0x00;
794 // AUXILIARY DATA HEADER
802 // AUXILIARY DATA HEADER
795 header->sid = 0x00;
803 header->sid = 0x00;
796 header->biaStatusInfo = 0x00;
804 header->biaStatusInfo = 0x00;
797 header->pa_lfr_pkt_cnt_asm = 0x00;
805 header->pa_lfr_pkt_cnt_asm = 0x00;
798 header->pa_lfr_pkt_nr_asm = 0x00;
806 header->pa_lfr_pkt_nr_asm = 0x00;
799 header->pa_lfr_asm_blk_nr[0] = 0x00;
807 header->pa_lfr_asm_blk_nr[0] = 0x00;
800 header->pa_lfr_asm_blk_nr[1] = 0x00;
808 header->pa_lfr_asm_blk_nr[1] = 0x00;
801 }
809 }
802
810
803 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
811 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
804 Header_TM_LFR_SCIENCE_CWF_t *header )
812 Header_TM_LFR_SCIENCE_CWF_t *header )
805 {
813 {
806 /** This function sends CWF CCSDS packets (F2, F1 or F0).
814 /** This function sends CWF CCSDS packets (F2, F1 or F0).
807 *
815 *
808 * @param waveform points to the buffer containing the data that will be send.
816 * @param waveform points to the buffer containing the data that will be send.
809 * @param sid is the source identifier of the data that will be sent.
817 * @param sid is the source identifier of the data that will be sent.
810 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
818 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
811 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
819 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
812 * contain information to setup the transmission of the data packets.
820 * contain information to setup the transmission of the data packets.
813 *
821 *
814 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
822 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
815 *
823 *
816 */
824 */
817
825
818 unsigned int i;
826 unsigned int i;
819 int ret;
827 int ret;
820 unsigned int coarseTime;
828 unsigned int coarseTime;
821 unsigned int fineTime;
829 unsigned int fineTime;
822 rtems_status_code status;
830 rtems_status_code status;
823 spw_ioctl_pkt_send spw_ioctl_send_CWF;
831 spw_ioctl_pkt_send spw_ioctl_send_CWF;
824 int *dataPtr;
832 int *dataPtr;
825 unsigned char sid;
833 unsigned char sid;
826
834
827 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
835 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
828 spw_ioctl_send_CWF.options = 0;
836 spw_ioctl_send_CWF.options = 0;
829
837
830 ret = LFR_DEFAULT;
838 ret = LFR_DEFAULT;
831 sid = (unsigned char) ring_node_to_send->sid;
839 sid = (unsigned char) ring_node_to_send->sid;
832
840
833 coarseTime = ring_node_to_send->coarseTime;
841 coarseTime = ring_node_to_send->coarseTime;
834 fineTime = ring_node_to_send->fineTime;
842 fineTime = ring_node_to_send->fineTime;
835 dataPtr = (int*) ring_node_to_send->buffer_address;
843 dataPtr = (int*) ring_node_to_send->buffer_address;
836
844
837 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
845 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
838 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
846 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
839 header->hkBIA = pa_bia_status_info;
847 header->hkBIA = pa_bia_status_info;
840 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
848 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
841 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
849 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
842 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
850 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
843
851
844 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
852 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
845 {
853 {
846 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
854 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
847 spw_ioctl_send_CWF.hdr = (char*) header;
855 spw_ioctl_send_CWF.hdr = (char*) header;
848 // BUILD THE DATA
856 // BUILD THE DATA
849 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
857 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
850
858
851 // SET PACKET SEQUENCE CONTROL
859 // SET PACKET SEQUENCE CONTROL
852 increment_seq_counter_source_id( header->packetSequenceControl, sid );
860 increment_seq_counter_source_id( header->packetSequenceControl, sid );
853
861
854 // SET SID
862 // SET SID
855 header->sid = sid;
863 header->sid = sid;
856
864
857 // SET PACKET TIME
865 // SET PACKET TIME
858 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
866 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
859 //
867 //
860 header->time[0] = header->acquisitionTime[0];
868 header->time[0] = header->acquisitionTime[0];
861 header->time[1] = header->acquisitionTime[1];
869 header->time[1] = header->acquisitionTime[1];
862 header->time[2] = header->acquisitionTime[2];
870 header->time[2] = header->acquisitionTime[2];
863 header->time[3] = header->acquisitionTime[3];
871 header->time[3] = header->acquisitionTime[3];
864 header->time[4] = header->acquisitionTime[4];
872 header->time[4] = header->acquisitionTime[4];
865 header->time[5] = header->acquisitionTime[5];
873 header->time[5] = header->acquisitionTime[5];
866
874
867 // SET PACKET ID
875 // SET PACKET ID
868 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
876 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
869 {
877 {
870 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
878 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
871 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
879 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
872 }
880 }
873 else
881 else
874 {
882 {
875 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
883 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
876 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
884 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
877 }
885 }
878
886
879 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
887 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
880 if (status != RTEMS_SUCCESSFUL) {
888 if (status != RTEMS_SUCCESSFUL) {
881 ret = LFR_DEFAULT;
889 ret = LFR_DEFAULT;
882 }
890 }
883 }
891 }
884
892
885 return ret;
893 return ret;
886 }
894 }
887
895
888 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
896 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
889 Header_TM_LFR_SCIENCE_SWF_t *header )
897 Header_TM_LFR_SCIENCE_SWF_t *header )
890 {
898 {
891 /** This function sends SWF CCSDS packets (F2, F1 or F0).
899 /** This function sends SWF CCSDS packets (F2, F1 or F0).
892 *
900 *
893 * @param waveform points to the buffer containing the data that will be send.
901 * @param waveform points to the buffer containing the data that will be send.
894 * @param sid is the source identifier of the data that will be sent.
902 * @param sid is the source identifier of the data that will be sent.
895 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
903 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
896 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
904 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
897 * contain information to setup the transmission of the data packets.
905 * contain information to setup the transmission of the data packets.
898 *
906 *
899 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
907 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
900 *
908 *
901 */
909 */
902
910
903 unsigned int i;
911 unsigned int i;
904 int ret;
912 int ret;
905 unsigned int coarseTime;
913 unsigned int coarseTime;
906 unsigned int fineTime;
914 unsigned int fineTime;
907 rtems_status_code status;
915 rtems_status_code status;
908 spw_ioctl_pkt_send spw_ioctl_send_SWF;
916 spw_ioctl_pkt_send spw_ioctl_send_SWF;
909 int *dataPtr;
917 int *dataPtr;
910 unsigned char sid;
918 unsigned char sid;
911
919
912 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
920 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
913 spw_ioctl_send_SWF.options = 0;
921 spw_ioctl_send_SWF.options = 0;
914
922
915 ret = LFR_DEFAULT;
923 ret = LFR_DEFAULT;
916
924
917 coarseTime = ring_node_to_send->coarseTime;
925 coarseTime = ring_node_to_send->coarseTime;
918 fineTime = ring_node_to_send->fineTime;
926 fineTime = ring_node_to_send->fineTime;
919 dataPtr = (int*) ring_node_to_send->buffer_address;
927 dataPtr = (int*) ring_node_to_send->buffer_address;
920 sid = ring_node_to_send->sid;
928 sid = ring_node_to_send->sid;
921
929
922 header->hkBIA = pa_bia_status_info;
930 header->hkBIA = pa_bia_status_info;
923 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
931 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
924
932
925 for (i=0; i<7; i++) // send waveform
933 for (i=0; i<7; i++) // send waveform
926 {
934 {
927 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
935 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
928 spw_ioctl_send_SWF.hdr = (char*) header;
936 spw_ioctl_send_SWF.hdr = (char*) header;
929
937
930 // SET PACKET SEQUENCE CONTROL
938 // SET PACKET SEQUENCE CONTROL
931 increment_seq_counter_source_id( header->packetSequenceControl, sid );
939 increment_seq_counter_source_id( header->packetSequenceControl, sid );
932
940
933 // SET PACKET LENGTH AND BLKNR
941 // SET PACKET LENGTH AND BLKNR
934 if (i == 6)
942 if (i == 6)
935 {
943 {
936 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
944 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
937 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
945 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
938 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
946 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
939 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
947 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
940 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
948 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
941 }
949 }
942 else
950 else
943 {
951 {
944 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
952 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
945 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
953 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
946 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
954 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
947 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
955 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
948 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
956 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
949 }
957 }
950
958
951 // SET PACKET TIME
959 // SET PACKET TIME
952 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
960 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
953 //
961 //
954 header->time[0] = header->acquisitionTime[0];
962 header->time[0] = header->acquisitionTime[0];
955 header->time[1] = header->acquisitionTime[1];
963 header->time[1] = header->acquisitionTime[1];
956 header->time[2] = header->acquisitionTime[2];
964 header->time[2] = header->acquisitionTime[2];
957 header->time[3] = header->acquisitionTime[3];
965 header->time[3] = header->acquisitionTime[3];
958 header->time[4] = header->acquisitionTime[4];
966 header->time[4] = header->acquisitionTime[4];
959 header->time[5] = header->acquisitionTime[5];
967 header->time[5] = header->acquisitionTime[5];
960
968
961 // SET SID
969 // SET SID
962 header->sid = sid;
970 header->sid = sid;
963
971
964 // SET PKTNR
972 // SET PKTNR
965 header->pktNr = i+1; // PKT_NR
973 header->pktNr = i+1; // PKT_NR
966
974
967 // SEND PACKET
975 // SEND PACKET
968 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
976 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
969 if (status != RTEMS_SUCCESSFUL) {
977 if (status != RTEMS_SUCCESSFUL) {
970 ret = LFR_DEFAULT;
978 ret = LFR_DEFAULT;
971 }
979 }
972 }
980 }
973
981
974 return ret;
982 return ret;
975 }
983 }
976
984
977 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
985 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
978 Header_TM_LFR_SCIENCE_CWF_t *header )
986 Header_TM_LFR_SCIENCE_CWF_t *header )
979 {
987 {
980 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
988 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
981 *
989 *
982 * @param waveform points to the buffer containing the data that will be send.
990 * @param waveform points to the buffer containing the data that will be send.
983 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
991 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
984 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
992 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
985 * contain information to setup the transmission of the data packets.
993 * contain information to setup the transmission of the data packets.
986 *
994 *
987 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
995 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
988 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
996 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
989 *
997 *
990 */
998 */
991
999
992 unsigned int i;
1000 unsigned int i;
993 int ret;
1001 int ret;
994 unsigned int coarseTime;
1002 unsigned int coarseTime;
995 unsigned int fineTime;
1003 unsigned int fineTime;
996 rtems_status_code status;
1004 rtems_status_code status;
997 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1005 spw_ioctl_pkt_send spw_ioctl_send_CWF;
998 char *dataPtr;
1006 char *dataPtr;
999 unsigned char sid;
1007 unsigned char sid;
1000
1008
1001 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1009 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1002 spw_ioctl_send_CWF.options = 0;
1010 spw_ioctl_send_CWF.options = 0;
1003
1011
1004 ret = LFR_DEFAULT;
1012 ret = LFR_DEFAULT;
1005 sid = ring_node_to_send->sid;
1013 sid = ring_node_to_send->sid;
1006
1014
1007 coarseTime = ring_node_to_send->coarseTime;
1015 coarseTime = ring_node_to_send->coarseTime;
1008 fineTime = ring_node_to_send->fineTime;
1016 fineTime = ring_node_to_send->fineTime;
1009 dataPtr = (char*) ring_node_to_send->buffer_address;
1017 dataPtr = (char*) ring_node_to_send->buffer_address;
1010
1018
1011 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1019 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1012 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1020 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1013 header->hkBIA = pa_bia_status_info;
1021 header->hkBIA = pa_bia_status_info;
1014 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1022 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1015 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1023 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1016 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1024 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1017
1025
1018 //*********************
1026 //*********************
1019 // SEND CWF3_light DATA
1027 // SEND CWF3_light DATA
1020 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1028 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1021 {
1029 {
1022 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1030 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1023 spw_ioctl_send_CWF.hdr = (char*) header;
1031 spw_ioctl_send_CWF.hdr = (char*) header;
1024 // BUILD THE DATA
1032 // BUILD THE DATA
1025 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1033 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1026
1034
1027 // SET PACKET SEQUENCE COUNTER
1035 // SET PACKET SEQUENCE COUNTER
1028 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1036 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1029
1037
1030 // SET SID
1038 // SET SID
1031 header->sid = sid;
1039 header->sid = sid;
1032
1040
1033 // SET PACKET TIME
1041 // SET PACKET TIME
1034 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1042 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1035 //
1043 //
1036 header->time[0] = header->acquisitionTime[0];
1044 header->time[0] = header->acquisitionTime[0];
1037 header->time[1] = header->acquisitionTime[1];
1045 header->time[1] = header->acquisitionTime[1];
1038 header->time[2] = header->acquisitionTime[2];
1046 header->time[2] = header->acquisitionTime[2];
1039 header->time[3] = header->acquisitionTime[3];
1047 header->time[3] = header->acquisitionTime[3];
1040 header->time[4] = header->acquisitionTime[4];
1048 header->time[4] = header->acquisitionTime[4];
1041 header->time[5] = header->acquisitionTime[5];
1049 header->time[5] = header->acquisitionTime[5];
1042
1050
1043 // SET PACKET ID
1051 // SET PACKET ID
1044 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1052 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1045 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1053 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1046
1054
1047 // SEND PACKET
1055 // SEND PACKET
1048 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1056 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1049 if (status != RTEMS_SUCCESSFUL) {
1057 if (status != RTEMS_SUCCESSFUL) {
1050 ret = LFR_DEFAULT;
1058 ret = LFR_DEFAULT;
1051 }
1059 }
1052 }
1060 }
1053
1061
1054 return ret;
1062 return ret;
1055 }
1063 }
1056
1064
1057 void spw_send_asm_f0( ring_node *ring_node_to_send,
1065 void spw_send_asm_f0( ring_node *ring_node_to_send,
1058 Header_TM_LFR_SCIENCE_ASM_t *header )
1066 Header_TM_LFR_SCIENCE_ASM_t *header )
1059 {
1067 {
1060 unsigned int i;
1068 unsigned int i;
1061 unsigned int length = 0;
1069 unsigned int length = 0;
1062 rtems_status_code status;
1070 rtems_status_code status;
1063 unsigned int sid;
1071 unsigned int sid;
1064 float *spectral_matrix;
1072 float *spectral_matrix;
1065 int coarseTime;
1073 int coarseTime;
1066 int fineTime;
1074 int fineTime;
1067 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1075 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1068
1076
1069 sid = ring_node_to_send->sid;
1077 sid = ring_node_to_send->sid;
1070 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1078 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1071 coarseTime = ring_node_to_send->coarseTime;
1079 coarseTime = ring_node_to_send->coarseTime;
1072 fineTime = ring_node_to_send->fineTime;
1080 fineTime = ring_node_to_send->fineTime;
1073
1081
1074 header->biaStatusInfo = pa_bia_status_info;
1082 header->biaStatusInfo = pa_bia_status_info;
1075 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1083 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1076
1084
1077 for (i=0; i<3; i++)
1085 for (i=0; i<3; i++)
1078 {
1086 {
1079 if ((i==0) || (i==1))
1087 if ((i==0) || (i==1))
1080 {
1088 {
1081 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1089 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1082 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1090 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1083 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1091 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1084 ];
1092 ];
1085 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1093 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1086 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1094 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1087 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1095 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1088 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1096 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1089 }
1097 }
1090 else
1098 else
1091 {
1099 {
1092 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1100 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1093 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1101 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1094 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1102 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1095 ];
1103 ];
1096 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1104 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1097 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1105 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1098 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1106 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1099 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1107 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1100 }
1108 }
1101
1109
1102 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1110 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1103 spw_ioctl_send_ASM.hdr = (char *) header;
1111 spw_ioctl_send_ASM.hdr = (char *) header;
1104 spw_ioctl_send_ASM.options = 0;
1112 spw_ioctl_send_ASM.options = 0;
1105
1113
1106 // (2) BUILD THE HEADER
1114 // (2) BUILD THE HEADER
1107 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1115 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1108 header->packetLength[0] = (unsigned char) (length>>8);
1116 header->packetLength[0] = (unsigned char) (length>>8);
1109 header->packetLength[1] = (unsigned char) (length);
1117 header->packetLength[1] = (unsigned char) (length);
1110 header->sid = (unsigned char) sid; // SID
1118 header->sid = (unsigned char) sid; // SID
1111 header->pa_lfr_pkt_cnt_asm = 3;
1119 header->pa_lfr_pkt_cnt_asm = 3;
1112 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1120 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1113
1121
1114 // (3) SET PACKET TIME
1122 // (3) SET PACKET TIME
1115 header->time[0] = (unsigned char) (coarseTime>>24);
1123 header->time[0] = (unsigned char) (coarseTime>>24);
1116 header->time[1] = (unsigned char) (coarseTime>>16);
1124 header->time[1] = (unsigned char) (coarseTime>>16);
1117 header->time[2] = (unsigned char) (coarseTime>>8);
1125 header->time[2] = (unsigned char) (coarseTime>>8);
1118 header->time[3] = (unsigned char) (coarseTime);
1126 header->time[3] = (unsigned char) (coarseTime);
1119 header->time[4] = (unsigned char) (fineTime>>8);
1127 header->time[4] = (unsigned char) (fineTime>>8);
1120 header->time[5] = (unsigned char) (fineTime);
1128 header->time[5] = (unsigned char) (fineTime);
1121 //
1129 //
1122 header->acquisitionTime[0] = header->time[0];
1130 header->acquisitionTime[0] = header->time[0];
1123 header->acquisitionTime[1] = header->time[1];
1131 header->acquisitionTime[1] = header->time[1];
1124 header->acquisitionTime[2] = header->time[2];
1132 header->acquisitionTime[2] = header->time[2];
1125 header->acquisitionTime[3] = header->time[3];
1133 header->acquisitionTime[3] = header->time[3];
1126 header->acquisitionTime[4] = header->time[4];
1134 header->acquisitionTime[4] = header->time[4];
1127 header->acquisitionTime[5] = header->time[5];
1135 header->acquisitionTime[5] = header->time[5];
1128
1136
1129 // (4) SEND PACKET
1137 // (4) SEND PACKET
1130 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1138 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1131 if (status != RTEMS_SUCCESSFUL) {
1139 if (status != RTEMS_SUCCESSFUL) {
1132 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1140 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1133 }
1141 }
1134 }
1142 }
1135 }
1143 }
1136
1144
1137 void spw_send_asm_f1( ring_node *ring_node_to_send,
1145 void spw_send_asm_f1( ring_node *ring_node_to_send,
1138 Header_TM_LFR_SCIENCE_ASM_t *header )
1146 Header_TM_LFR_SCIENCE_ASM_t *header )
1139 {
1147 {
1140 unsigned int i;
1148 unsigned int i;
1141 unsigned int length = 0;
1149 unsigned int length = 0;
1142 rtems_status_code status;
1150 rtems_status_code status;
1143 unsigned int sid;
1151 unsigned int sid;
1144 float *spectral_matrix;
1152 float *spectral_matrix;
1145 int coarseTime;
1153 int coarseTime;
1146 int fineTime;
1154 int fineTime;
1147 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1155 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1148
1156
1149 sid = ring_node_to_send->sid;
1157 sid = ring_node_to_send->sid;
1150 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1158 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1151 coarseTime = ring_node_to_send->coarseTime;
1159 coarseTime = ring_node_to_send->coarseTime;
1152 fineTime = ring_node_to_send->fineTime;
1160 fineTime = ring_node_to_send->fineTime;
1153
1161
1154 header->biaStatusInfo = pa_bia_status_info;
1162 header->biaStatusInfo = pa_bia_status_info;
1155 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1163 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1156
1164
1157 for (i=0; i<3; i++)
1165 for (i=0; i<3; i++)
1158 {
1166 {
1159 if ((i==0) || (i==1))
1167 if ((i==0) || (i==1))
1160 {
1168 {
1161 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1169 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1162 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1170 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1163 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1171 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1164 ];
1172 ];
1165 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1173 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1166 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1174 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1167 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1175 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1168 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1176 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1169 }
1177 }
1170 else
1178 else
1171 {
1179 {
1172 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1180 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1173 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1181 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1174 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1182 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1175 ];
1183 ];
1176 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1184 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1177 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1185 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1178 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1186 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1179 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1187 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1180 }
1188 }
1181
1189
1182 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1190 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1183 spw_ioctl_send_ASM.hdr = (char *) header;
1191 spw_ioctl_send_ASM.hdr = (char *) header;
1184 spw_ioctl_send_ASM.options = 0;
1192 spw_ioctl_send_ASM.options = 0;
1185
1193
1186 // (2) BUILD THE HEADER
1194 // (2) BUILD THE HEADER
1187 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1195 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1188 header->packetLength[0] = (unsigned char) (length>>8);
1196 header->packetLength[0] = (unsigned char) (length>>8);
1189 header->packetLength[1] = (unsigned char) (length);
1197 header->packetLength[1] = (unsigned char) (length);
1190 header->sid = (unsigned char) sid; // SID
1198 header->sid = (unsigned char) sid; // SID
1191 header->pa_lfr_pkt_cnt_asm = 3;
1199 header->pa_lfr_pkt_cnt_asm = 3;
1192 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1200 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1193
1201
1194 // (3) SET PACKET TIME
1202 // (3) SET PACKET TIME
1195 header->time[0] = (unsigned char) (coarseTime>>24);
1203 header->time[0] = (unsigned char) (coarseTime>>24);
1196 header->time[1] = (unsigned char) (coarseTime>>16);
1204 header->time[1] = (unsigned char) (coarseTime>>16);
1197 header->time[2] = (unsigned char) (coarseTime>>8);
1205 header->time[2] = (unsigned char) (coarseTime>>8);
1198 header->time[3] = (unsigned char) (coarseTime);
1206 header->time[3] = (unsigned char) (coarseTime);
1199 header->time[4] = (unsigned char) (fineTime>>8);
1207 header->time[4] = (unsigned char) (fineTime>>8);
1200 header->time[5] = (unsigned char) (fineTime);
1208 header->time[5] = (unsigned char) (fineTime);
1201 //
1209 //
1202 header->acquisitionTime[0] = header->time[0];
1210 header->acquisitionTime[0] = header->time[0];
1203 header->acquisitionTime[1] = header->time[1];
1211 header->acquisitionTime[1] = header->time[1];
1204 header->acquisitionTime[2] = header->time[2];
1212 header->acquisitionTime[2] = header->time[2];
1205 header->acquisitionTime[3] = header->time[3];
1213 header->acquisitionTime[3] = header->time[3];
1206 header->acquisitionTime[4] = header->time[4];
1214 header->acquisitionTime[4] = header->time[4];
1207 header->acquisitionTime[5] = header->time[5];
1215 header->acquisitionTime[5] = header->time[5];
1208
1216
1209 // (4) SEND PACKET
1217 // (4) SEND PACKET
1210 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1218 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1211 if (status != RTEMS_SUCCESSFUL) {
1219 if (status != RTEMS_SUCCESSFUL) {
1212 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1220 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1213 }
1221 }
1214 }
1222 }
1215 }
1223 }
1216
1224
1217 void spw_send_asm_f2( ring_node *ring_node_to_send,
1225 void spw_send_asm_f2( ring_node *ring_node_to_send,
1218 Header_TM_LFR_SCIENCE_ASM_t *header )
1226 Header_TM_LFR_SCIENCE_ASM_t *header )
1219 {
1227 {
1220 unsigned int i;
1228 unsigned int i;
1221 unsigned int length = 0;
1229 unsigned int length = 0;
1222 rtems_status_code status;
1230 rtems_status_code status;
1223 unsigned int sid;
1231 unsigned int sid;
1224 float *spectral_matrix;
1232 float *spectral_matrix;
1225 int coarseTime;
1233 int coarseTime;
1226 int fineTime;
1234 int fineTime;
1227 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1235 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1228
1236
1229 sid = ring_node_to_send->sid;
1237 sid = ring_node_to_send->sid;
1230 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1238 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1231 coarseTime = ring_node_to_send->coarseTime;
1239 coarseTime = ring_node_to_send->coarseTime;
1232 fineTime = ring_node_to_send->fineTime;
1240 fineTime = ring_node_to_send->fineTime;
1233
1241
1234 header->biaStatusInfo = pa_bia_status_info;
1242 header->biaStatusInfo = pa_bia_status_info;
1235 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1243 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1236
1244
1237 for (i=0; i<3; i++)
1245 for (i=0; i<3; i++)
1238 {
1246 {
1239
1247
1240 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1248 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1241 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1249 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1242 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1250 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1243 ];
1251 ];
1244 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1252 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1245 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1253 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1246 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1254 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1247 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1255 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1248
1256
1249 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1257 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1250 spw_ioctl_send_ASM.hdr = (char *) header;
1258 spw_ioctl_send_ASM.hdr = (char *) header;
1251 spw_ioctl_send_ASM.options = 0;
1259 spw_ioctl_send_ASM.options = 0;
1252
1260
1253 // (2) BUILD THE HEADER
1261 // (2) BUILD THE HEADER
1254 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1262 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1255 header->packetLength[0] = (unsigned char) (length>>8);
1263 header->packetLength[0] = (unsigned char) (length>>8);
1256 header->packetLength[1] = (unsigned char) (length);
1264 header->packetLength[1] = (unsigned char) (length);
1257 header->sid = (unsigned char) sid; // SID
1265 header->sid = (unsigned char) sid; // SID
1258 header->pa_lfr_pkt_cnt_asm = 3;
1266 header->pa_lfr_pkt_cnt_asm = 3;
1259 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1267 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1260
1268
1261 // (3) SET PACKET TIME
1269 // (3) SET PACKET TIME
1262 header->time[0] = (unsigned char) (coarseTime>>24);
1270 header->time[0] = (unsigned char) (coarseTime>>24);
1263 header->time[1] = (unsigned char) (coarseTime>>16);
1271 header->time[1] = (unsigned char) (coarseTime>>16);
1264 header->time[2] = (unsigned char) (coarseTime>>8);
1272 header->time[2] = (unsigned char) (coarseTime>>8);
1265 header->time[3] = (unsigned char) (coarseTime);
1273 header->time[3] = (unsigned char) (coarseTime);
1266 header->time[4] = (unsigned char) (fineTime>>8);
1274 header->time[4] = (unsigned char) (fineTime>>8);
1267 header->time[5] = (unsigned char) (fineTime);
1275 header->time[5] = (unsigned char) (fineTime);
1268 //
1276 //
1269 header->acquisitionTime[0] = header->time[0];
1277 header->acquisitionTime[0] = header->time[0];
1270 header->acquisitionTime[1] = header->time[1];
1278 header->acquisitionTime[1] = header->time[1];
1271 header->acquisitionTime[2] = header->time[2];
1279 header->acquisitionTime[2] = header->time[2];
1272 header->acquisitionTime[3] = header->time[3];
1280 header->acquisitionTime[3] = header->time[3];
1273 header->acquisitionTime[4] = header->time[4];
1281 header->acquisitionTime[4] = header->time[4];
1274 header->acquisitionTime[5] = header->time[5];
1282 header->acquisitionTime[5] = header->time[5];
1275
1283
1276 // (4) SEND PACKET
1284 // (4) SEND PACKET
1277 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1285 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1278 if (status != RTEMS_SUCCESSFUL) {
1286 if (status != RTEMS_SUCCESSFUL) {
1279 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1287 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1280 }
1288 }
1281 }
1289 }
1282 }
1290 }
1283
1291
1284 void spw_send_k_dump( ring_node *ring_node_to_send )
1292 void spw_send_k_dump( ring_node *ring_node_to_send )
1285 {
1293 {
1286 rtems_status_code status;
1294 rtems_status_code status;
1287 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1295 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1288 unsigned int packetLength;
1296 unsigned int packetLength;
1289 unsigned int size;
1297 unsigned int size;
1290
1298
1291 PRINTF("spw_send_k_dump\n")
1299 PRINTF("spw_send_k_dump\n")
1292
1300
1293 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1301 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1294
1302
1295 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1303 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1296
1304
1297 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1305 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1298
1306
1299 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1307 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1300
1308
1301 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1309 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1302
1310
1303 if (status == -1){
1311 if (status == -1){
1304 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1312 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1305 }
1313 }
1306
1314
1307 ring_node_to_send->status = 0x00;
1315 ring_node_to_send->status = 0x00;
1308 }
1316 }
@@ -1,689 +1,709
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "fsw_processing.h"
10 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
11 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
12 #include "fsw_init.h"
13
13
14 unsigned int nb_sm_f0;
14 unsigned int nb_sm_f0;
15 unsigned int nb_sm_f0_aux_f1;
15 unsigned int nb_sm_f0_aux_f1;
16 unsigned int nb_sm_f1;
16 unsigned int nb_sm_f1;
17 unsigned int nb_sm_f0_aux_f2;
17 unsigned int nb_sm_f0_aux_f2;
18
18
19 extern struct grgpio_regs_str *grgpio_regs;
20 #define OUTPUT_1 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf8;
21 #define OUTPUT_0 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x02;
22
19 //************************
23 //************************
20 // spectral matrices rings
24 // spectral matrices rings
21 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
25 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
22 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
26 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
23 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
27 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
24 ring_node *current_ring_node_sm_f0;
28 ring_node *current_ring_node_sm_f0;
25 ring_node *current_ring_node_sm_f1;
29 ring_node *current_ring_node_sm_f1;
26 ring_node *current_ring_node_sm_f2;
30 ring_node *current_ring_node_sm_f2;
27 ring_node *ring_node_for_averaging_sm_f0;
31 ring_node *ring_node_for_averaging_sm_f0;
28 ring_node *ring_node_for_averaging_sm_f1;
32 ring_node *ring_node_for_averaging_sm_f1;
29 ring_node *ring_node_for_averaging_sm_f2;
33 ring_node *ring_node_for_averaging_sm_f2;
30
34
31 //
35 //
32 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
36 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
33 {
37 {
34 ring_node *node;
38 ring_node *node;
35
39
36 node = NULL;
40 node = NULL;
37 switch ( frequencyChannel ) {
41 switch ( frequencyChannel ) {
38 case 0:
42 case 0:
39 node = ring_node_for_averaging_sm_f0;
43 node = ring_node_for_averaging_sm_f0;
40 break;
44 break;
41 case 1:
45 case 1:
42 node = ring_node_for_averaging_sm_f1;
46 node = ring_node_for_averaging_sm_f1;
43 break;
47 break;
44 case 2:
48 case 2:
45 node = ring_node_for_averaging_sm_f2;
49 node = ring_node_for_averaging_sm_f2;
46 break;
50 break;
47 default:
51 default:
48 break;
52 break;
49 }
53 }
50
54
51 return node;
55 return node;
52 }
56 }
53
57
54 //***********************************************************
58 //***********************************************************
55 // Interrupt Service Routine for spectral matrices processing
59 // Interrupt Service Routine for spectral matrices processing
56
60
57 void spectral_matrices_isr_f0( unsigned char statusReg )
61 void spectral_matrices_isr_f0( unsigned char statusReg )
58 {
62 {
63 // OUTPUT_1;
64
59 unsigned char status;
65 unsigned char status;
60 rtems_status_code status_code;
66 rtems_status_code status_code;
61 ring_node *full_ring_node;
67 ring_node *full_ring_node;
62
68
63 status = statusReg & 0x03; // [0011] get the status_ready_matrix_f0_x bits
69 status = statusReg & 0x03; // [0011] get the status_ready_matrix_f0_x bits
64
70
65 switch(status)
71 switch(status)
66 {
72 {
67 case 0:
73 case 0:
68 break;
74 break;
69 case 3:
75 case 3:
70 // UNEXPECTED VALUE
76 // UNEXPECTED VALUE
71 spectral_matrix_regs->status = 0x03; // [0011]
77 spectral_matrix_regs->status = 0x03; // [0011]
72 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
78 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
73 break;
79 break;
74 case 1:
80 case 1:
75 full_ring_node = current_ring_node_sm_f0->previous;
81 full_ring_node = current_ring_node_sm_f0->previous;
76 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
82 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
77 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
83 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
78 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
84 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
79 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
85 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
80 // if there are enough ring nodes ready, wake up an AVFx task
86 // if there are enough ring nodes ready, wake up an AVFx task
81 nb_sm_f0 = nb_sm_f0 + 1;
87 nb_sm_f0 = nb_sm_f0 + 1;
82 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
88 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
83 {
89 {
84 ring_node_for_averaging_sm_f0 = full_ring_node;
90 ring_node_for_averaging_sm_f0 = full_ring_node;
85 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
91 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
86 {
92 {
87 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
93 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
88 }
94 }
89 nb_sm_f0 = 0;
95 nb_sm_f0 = 0;
90 }
96 }
91 spectral_matrix_regs->status = 0x01; // [0000 0001]
97 spectral_matrix_regs->status = 0x01; // [0000 0001]
92 break;
98 break;
93 case 2:
99 case 2:
94 full_ring_node = current_ring_node_sm_f0->previous;
100 full_ring_node = current_ring_node_sm_f0->previous;
95 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
101 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
96 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
102 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
97 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
103 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
98 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
104 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
99 // if there are enough ring nodes ready, wake up an AVFx task
105 // if there are enough ring nodes ready, wake up an AVFx task
100 nb_sm_f0 = nb_sm_f0 + 1;
106 nb_sm_f0 = nb_sm_f0 + 1;
101 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
107 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
102 {
108 {
103 ring_node_for_averaging_sm_f0 = full_ring_node;
109 ring_node_for_averaging_sm_f0 = full_ring_node;
104 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
110 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
105 {
111 {
106 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
112 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
107 }
113 }
108 nb_sm_f0 = 0;
114 nb_sm_f0 = 0;
109 }
115 }
110 spectral_matrix_regs->status = 0x02; // [0000 0010]
116 spectral_matrix_regs->status = 0x02; // [0000 0010]
111 break;
117 break;
112 }
118 }
119 // OUTPUT_0;
113 }
120 }
114
121
115 void spectral_matrices_isr_f1( unsigned char statusReg )
122 void spectral_matrices_isr_f1( unsigned char statusReg )
116 {
123 {
124 // OUTPUT_1;
125
117 rtems_status_code status_code;
126 rtems_status_code status_code;
118 unsigned char status;
127 unsigned char status;
119 ring_node *full_ring_node;
128 ring_node *full_ring_node;
120
129
121 status = (statusReg & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
130 status = (statusReg & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits
122
131
123 switch(status)
132 switch(status)
124 {
133 {
125 case 0:
134 case 0:
126 break;
135 break;
127 case 3:
136 case 3:
128 // UNEXPECTED VALUE
137 // UNEXPECTED VALUE
129 spectral_matrix_regs->status = 0xc0; // [1100]
138 spectral_matrix_regs->status = 0xc0; // [1100]
130 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
139 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
131 break;
140 break;
132 case 1:
141 case 1:
133 full_ring_node = current_ring_node_sm_f1->previous;
142 full_ring_node = current_ring_node_sm_f1->previous;
134 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
143 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
135 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
144 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
136 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
145 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
137 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
146 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
138 // if there are enough ring nodes ready, wake up an AVFx task
147 // if there are enough ring nodes ready, wake up an AVFx task
139 nb_sm_f1 = nb_sm_f1 + 1;
148 nb_sm_f1 = nb_sm_f1 + 1;
140 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
149 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
141 {
150 {
142 ring_node_for_averaging_sm_f1 = full_ring_node;
151 ring_node_for_averaging_sm_f1 = full_ring_node;
143 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
152 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
144 {
153 {
145 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
154 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
146 }
155 }
147 nb_sm_f1 = 0;
156 nb_sm_f1 = 0;
148 }
157 }
149 spectral_matrix_regs->status = 0x04; // [0000 0100]
158 spectral_matrix_regs->status = 0x04; // [0000 0100]
150 break;
159 break;
151 case 2:
160 case 2:
152 full_ring_node = current_ring_node_sm_f1->previous;
161 full_ring_node = current_ring_node_sm_f1->previous;
153 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
162 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
154 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
163 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
155 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
164 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
156 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
165 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
157 // if there are enough ring nodes ready, wake up an AVFx task
166 // if there are enough ring nodes ready, wake up an AVFx task
158 nb_sm_f1 = nb_sm_f1 + 1;
167 nb_sm_f1 = nb_sm_f1 + 1;
159 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
168 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
160 {
169 {
161 ring_node_for_averaging_sm_f1 = full_ring_node;
170 ring_node_for_averaging_sm_f1 = full_ring_node;
162 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
171 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
163 {
172 {
164 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
173 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
165 }
174 }
166 nb_sm_f1 = 0;
175 nb_sm_f1 = 0;
167 }
176 }
168 spectral_matrix_regs->status = 0x08; // [1000 0000]
177 spectral_matrix_regs->status = 0x08; // [1000 0000]
169 break;
178 break;
170 }
179 }
180
181 // OUTPUT_0;
171 }
182 }
172
183
173 void spectral_matrices_isr_f2( unsigned char statusReg )
184 void spectral_matrices_isr_f2( unsigned char statusReg )
174 {
185 {
186 // OUTPUT_1;
187
175 unsigned char status;
188 unsigned char status;
176 rtems_status_code status_code;
189 rtems_status_code status_code;
177
190
178 status = (statusReg & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
191 status = (statusReg & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits
179
192
180 switch(status)
193 switch(status)
181 {
194 {
182 case 0:
195 case 0:
183 break;
196 break;
184 case 3:
197 case 3:
185 // UNEXPECTED VALUE
198 // UNEXPECTED VALUE
186 spectral_matrix_regs->status = 0x30; // [0011 0000]
199 spectral_matrix_regs->status = 0x30; // [0011 0000]
187 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
200 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
188 break;
201 break;
189 case 1:
202 case 1:
190 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
203 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
191 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
204 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
192 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
205 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
193 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
206 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
194 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
207 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
195 spectral_matrix_regs->status = 0x10; // [0001 0000]
208 spectral_matrix_regs->status = 0x10; // [0001 0000]
196 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
209 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
197 {
210 {
198 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
211 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
199 }
212 }
200 break;
213 break;
201 case 2:
214 case 2:
202 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
215 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
203 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
216 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
204 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
217 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
205 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
218 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
206 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
219 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
207 spectral_matrix_regs->status = 0x20; // [0010 0000]
220 spectral_matrix_regs->status = 0x20; // [0010 0000]
208 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
221 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
209 {
222 {
210 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
223 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
211 }
224 }
212 break;
225 break;
213 }
226 }
227
228 // OUTPUT_0;
214 }
229 }
215
230
216 void spectral_matrix_isr_error_handler( unsigned char statusReg )
231 void spectral_matrix_isr_error_handler( unsigned char statusReg )
217 {
232 {
218 rtems_status_code status_code;
233 rtems_status_code status_code;
219
234
220 if (statusReg & 0x7c0) // [0111 1100 0000]
235 if (statusReg & 0x7c0) // [0111 1100 0000]
221 {
236 {
222 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
237 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
223 }
238 }
224
239
225 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
240 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
226 }
241 }
227
242
228 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
243 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
229 {
244 {
230 // STATUS REGISTER
245 // STATUS REGISTER
231 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
246 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
232 // 10 9 8
247 // 10 9 8
233 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
248 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
234 // 7 6 5 4 3 2 1 0
249 // 7 6 5 4 3 2 1 0
235
250
236 unsigned char statusReg;
251 unsigned char statusReg;
237
252
253 // OUTPUT_1;
254
238 statusReg = spectral_matrix_regs->status;
255 statusReg = spectral_matrix_regs->status;
239
256
240 spectral_matrices_isr_f0( statusReg );
257 spectral_matrices_isr_f0( statusReg );
241
258
242 spectral_matrices_isr_f1( statusReg );
259 spectral_matrices_isr_f1( statusReg );
243
260
244 spectral_matrices_isr_f2( statusReg );
261 spectral_matrices_isr_f2( statusReg );
245
262
246 spectral_matrix_isr_error_handler( statusReg );
263 spectral_matrix_isr_error_handler( statusReg );
264
265 // OUTPUT_0;
266
247 }
267 }
248
268
249 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
269 rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector )
250 {
270 {
251 rtems_status_code status_code;
271 rtems_status_code status_code;
252
272
253 //***
273 //***
254 // F0
274 // F0
255 nb_sm_f0 = nb_sm_f0 + 1;
275 nb_sm_f0 = nb_sm_f0 + 1;
256 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
276 if (nb_sm_f0 == NB_SM_BEFORE_AVF0 )
257 {
277 {
258 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
278 ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0;
259 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
279 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
260 {
280 {
261 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
281 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
262 }
282 }
263 nb_sm_f0 = 0;
283 nb_sm_f0 = 0;
264 }
284 }
265
285
266 //***
286 //***
267 // F1
287 // F1
268 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
288 nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1;
269 if (nb_sm_f0_aux_f1 == 6)
289 if (nb_sm_f0_aux_f1 == 6)
270 {
290 {
271 nb_sm_f0_aux_f1 = 0;
291 nb_sm_f0_aux_f1 = 0;
272 nb_sm_f1 = nb_sm_f1 + 1;
292 nb_sm_f1 = nb_sm_f1 + 1;
273 }
293 }
274 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
294 if (nb_sm_f1 == NB_SM_BEFORE_AVF1 )
275 {
295 {
276 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
296 ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1;
277 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
297 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
278 {
298 {
279 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
299 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
280 }
300 }
281 nb_sm_f1 = 0;
301 nb_sm_f1 = 0;
282 }
302 }
283
303
284 //***
304 //***
285 // F2
305 // F2
286 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
306 nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1;
287 if (nb_sm_f0_aux_f2 == 96)
307 if (nb_sm_f0_aux_f2 == 96)
288 {
308 {
289 nb_sm_f0_aux_f2 = 0;
309 nb_sm_f0_aux_f2 = 0;
290 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
310 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2;
291 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
311 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
292 {
312 {
293 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
313 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
294 }
314 }
295 }
315 }
296 }
316 }
297
317
298 //******************
318 //******************
299 // Spectral Matrices
319 // Spectral Matrices
300
320
301 void reset_nb_sm( void )
321 void reset_nb_sm( void )
302 {
322 {
303 nb_sm_f0 = 0;
323 nb_sm_f0 = 0;
304 nb_sm_f0_aux_f1 = 0;
324 nb_sm_f0_aux_f1 = 0;
305 nb_sm_f0_aux_f2 = 0;
325 nb_sm_f0_aux_f2 = 0;
306
326
307 nb_sm_f1 = 0;
327 nb_sm_f1 = 0;
308 }
328 }
309
329
310 void SM_init_rings( void )
330 void SM_init_rings( void )
311 {
331 {
312 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
332 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
313 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
333 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
314 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
334 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
315
335
316 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
336 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
317 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
337 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
318 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
338 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
319 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
339 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
320 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
340 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
321 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
341 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
322 }
342 }
323
343
324 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
344 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
325 {
345 {
326 unsigned char i;
346 unsigned char i;
327
347
328 ring[ nbNodes - 1 ].next
348 ring[ nbNodes - 1 ].next
329 = (ring_node_asm*) &ring[ 0 ];
349 = (ring_node_asm*) &ring[ 0 ];
330
350
331 for(i=0; i<nbNodes-1; i++)
351 for(i=0; i<nbNodes-1; i++)
332 {
352 {
333 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
353 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
334 }
354 }
335 }
355 }
336
356
337 void SM_reset_current_ring_nodes( void )
357 void SM_reset_current_ring_nodes( void )
338 {
358 {
339 current_ring_node_sm_f0 = sm_ring_f0[0].next;
359 current_ring_node_sm_f0 = sm_ring_f0[0].next;
340 current_ring_node_sm_f1 = sm_ring_f1[0].next;
360 current_ring_node_sm_f1 = sm_ring_f1[0].next;
341 current_ring_node_sm_f2 = sm_ring_f2[0].next;
361 current_ring_node_sm_f2 = sm_ring_f2[0].next;
342
362
343 ring_node_for_averaging_sm_f0 = NULL;
363 ring_node_for_averaging_sm_f0 = NULL;
344 ring_node_for_averaging_sm_f1 = NULL;
364 ring_node_for_averaging_sm_f1 = NULL;
345 ring_node_for_averaging_sm_f2 = NULL;
365 ring_node_for_averaging_sm_f2 = NULL;
346 }
366 }
347
367
348 //*****************
368 //*****************
349 // Basic Parameters
369 // Basic Parameters
350
370
351 void BP_init_header( bp_packet *packet,
371 void BP_init_header( bp_packet *packet,
352 unsigned int apid, unsigned char sid,
372 unsigned int apid, unsigned char sid,
353 unsigned int packetLength, unsigned char blkNr )
373 unsigned int packetLength, unsigned char blkNr )
354 {
374 {
355 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
375 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
356 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
376 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
357 packet->reserved = 0x00;
377 packet->reserved = 0x00;
358 packet->userApplication = CCSDS_USER_APP;
378 packet->userApplication = CCSDS_USER_APP;
359 packet->packetID[0] = (unsigned char) (apid >> 8);
379 packet->packetID[0] = (unsigned char) (apid >> 8);
360 packet->packetID[1] = (unsigned char) (apid);
380 packet->packetID[1] = (unsigned char) (apid);
361 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
381 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
362 packet->packetSequenceControl[1] = 0x00;
382 packet->packetSequenceControl[1] = 0x00;
363 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
383 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
364 packet->packetLength[1] = (unsigned char) (packetLength);
384 packet->packetLength[1] = (unsigned char) (packetLength);
365 // DATA FIELD HEADER
385 // DATA FIELD HEADER
366 packet->spare1_pusVersion_spare2 = 0x10;
386 packet->spare1_pusVersion_spare2 = 0x10;
367 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
387 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
368 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
388 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
369 packet->destinationID = TM_DESTINATION_ID_GROUND;
389 packet->destinationID = TM_DESTINATION_ID_GROUND;
370 packet->time[0] = 0x00;
390 packet->time[0] = 0x00;
371 packet->time[1] = 0x00;
391 packet->time[1] = 0x00;
372 packet->time[2] = 0x00;
392 packet->time[2] = 0x00;
373 packet->time[3] = 0x00;
393 packet->time[3] = 0x00;
374 packet->time[4] = 0x00;
394 packet->time[4] = 0x00;
375 packet->time[5] = 0x00;
395 packet->time[5] = 0x00;
376 // AUXILIARY DATA HEADER
396 // AUXILIARY DATA HEADER
377 packet->sid = sid;
397 packet->sid = sid;
378 packet->biaStatusInfo = 0x00;
398 packet->biaStatusInfo = 0x00;
379 packet->sy_lfr_common_parameters_spare = 0x00;
399 packet->sy_lfr_common_parameters_spare = 0x00;
380 packet->sy_lfr_common_parameters = 0x00;
400 packet->sy_lfr_common_parameters = 0x00;
381 packet->acquisitionTime[0] = 0x00;
401 packet->acquisitionTime[0] = 0x00;
382 packet->acquisitionTime[1] = 0x00;
402 packet->acquisitionTime[1] = 0x00;
383 packet->acquisitionTime[2] = 0x00;
403 packet->acquisitionTime[2] = 0x00;
384 packet->acquisitionTime[3] = 0x00;
404 packet->acquisitionTime[3] = 0x00;
385 packet->acquisitionTime[4] = 0x00;
405 packet->acquisitionTime[4] = 0x00;
386 packet->acquisitionTime[5] = 0x00;
406 packet->acquisitionTime[5] = 0x00;
387 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
407 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
388 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
408 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
389 }
409 }
390
410
391 void BP_init_header_with_spare( bp_packet_with_spare *packet,
411 void BP_init_header_with_spare( bp_packet_with_spare *packet,
392 unsigned int apid, unsigned char sid,
412 unsigned int apid, unsigned char sid,
393 unsigned int packetLength , unsigned char blkNr)
413 unsigned int packetLength , unsigned char blkNr)
394 {
414 {
395 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
415 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
396 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
416 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
397 packet->reserved = 0x00;
417 packet->reserved = 0x00;
398 packet->userApplication = CCSDS_USER_APP;
418 packet->userApplication = CCSDS_USER_APP;
399 packet->packetID[0] = (unsigned char) (apid >> 8);
419 packet->packetID[0] = (unsigned char) (apid >> 8);
400 packet->packetID[1] = (unsigned char) (apid);
420 packet->packetID[1] = (unsigned char) (apid);
401 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
421 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
402 packet->packetSequenceControl[1] = 0x00;
422 packet->packetSequenceControl[1] = 0x00;
403 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
423 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
404 packet->packetLength[1] = (unsigned char) (packetLength);
424 packet->packetLength[1] = (unsigned char) (packetLength);
405 // DATA FIELD HEADER
425 // DATA FIELD HEADER
406 packet->spare1_pusVersion_spare2 = 0x10;
426 packet->spare1_pusVersion_spare2 = 0x10;
407 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
427 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
408 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
428 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
409 packet->destinationID = TM_DESTINATION_ID_GROUND;
429 packet->destinationID = TM_DESTINATION_ID_GROUND;
410 // AUXILIARY DATA HEADER
430 // AUXILIARY DATA HEADER
411 packet->sid = sid;
431 packet->sid = sid;
412 packet->biaStatusInfo = 0x00;
432 packet->biaStatusInfo = 0x00;
413 packet->sy_lfr_common_parameters_spare = 0x00;
433 packet->sy_lfr_common_parameters_spare = 0x00;
414 packet->sy_lfr_common_parameters = 0x00;
434 packet->sy_lfr_common_parameters = 0x00;
415 packet->time[0] = 0x00;
435 packet->time[0] = 0x00;
416 packet->time[0] = 0x00;
436 packet->time[0] = 0x00;
417 packet->time[0] = 0x00;
437 packet->time[0] = 0x00;
418 packet->time[0] = 0x00;
438 packet->time[0] = 0x00;
419 packet->time[0] = 0x00;
439 packet->time[0] = 0x00;
420 packet->time[0] = 0x00;
440 packet->time[0] = 0x00;
421 packet->source_data_spare = 0x00;
441 packet->source_data_spare = 0x00;
422 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
442 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
423 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
443 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
424 }
444 }
425
445
426 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
446 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
427 {
447 {
428 rtems_status_code status;
448 rtems_status_code status;
429
449
430 // SEND PACKET
450 // SEND PACKET
431 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
451 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
432 if (status != RTEMS_SUCCESSFUL)
452 if (status != RTEMS_SUCCESSFUL)
433 {
453 {
434 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
454 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
435 }
455 }
436 }
456 }
437
457
438 //******************
458 //******************
439 // general functions
459 // general functions
440
460
441 void reset_sm_status( void )
461 void reset_sm_status( void )
442 {
462 {
443 // error
463 // error
444 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
464 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
445 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
465 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
446 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
466 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
447 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
467 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
448
468
449 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
469 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
450 }
470 }
451
471
452 void reset_spectral_matrix_regs( void )
472 void reset_spectral_matrix_regs( void )
453 {
473 {
454 /** This function resets the spectral matrices module registers.
474 /** This function resets the spectral matrices module registers.
455 *
475 *
456 * The registers affected by this function are located at the following offset addresses:
476 * The registers affected by this function are located at the following offset addresses:
457 *
477 *
458 * - 0x00 config
478 * - 0x00 config
459 * - 0x04 status
479 * - 0x04 status
460 * - 0x08 matrixF0_Address0
480 * - 0x08 matrixF0_Address0
461 * - 0x10 matrixFO_Address1
481 * - 0x10 matrixFO_Address1
462 * - 0x14 matrixF1_Address
482 * - 0x14 matrixF1_Address
463 * - 0x18 matrixF2_Address
483 * - 0x18 matrixF2_Address
464 *
484 *
465 */
485 */
466
486
467 set_sm_irq_onError( 0 );
487 set_sm_irq_onError( 0 );
468
488
469 set_sm_irq_onNewMatrix( 0 );
489 set_sm_irq_onNewMatrix( 0 );
470
490
471 reset_sm_status();
491 reset_sm_status();
472
492
473 // F1
493 // F1
474 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
494 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
475 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
495 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
476 // F2
496 // F2
477 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
497 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
478 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
498 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
479 // F3
499 // F3
480 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
500 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
481 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
501 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
482
502
483 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
503 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
484 }
504 }
485
505
486 void set_time( unsigned char *time, unsigned char * timeInBuffer )
506 void set_time( unsigned char *time, unsigned char * timeInBuffer )
487 {
507 {
488 time[0] = timeInBuffer[0];
508 time[0] = timeInBuffer[0];
489 time[1] = timeInBuffer[1];
509 time[1] = timeInBuffer[1];
490 time[2] = timeInBuffer[2];
510 time[2] = timeInBuffer[2];
491 time[3] = timeInBuffer[3];
511 time[3] = timeInBuffer[3];
492 time[4] = timeInBuffer[6];
512 time[4] = timeInBuffer[6];
493 time[5] = timeInBuffer[7];
513 time[5] = timeInBuffer[7];
494 }
514 }
495
515
496 unsigned long long int get_acquisition_time( unsigned char *timePtr )
516 unsigned long long int get_acquisition_time( unsigned char *timePtr )
497 {
517 {
498 unsigned long long int acquisitionTimeAslong;
518 unsigned long long int acquisitionTimeAslong;
499 acquisitionTimeAslong = 0x00;
519 acquisitionTimeAslong = 0x00;
500 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
520 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
501 + ( (unsigned long long int) timePtr[1] << 32 )
521 + ( (unsigned long long int) timePtr[1] << 32 )
502 + ( (unsigned long long int) timePtr[2] << 24 )
522 + ( (unsigned long long int) timePtr[2] << 24 )
503 + ( (unsigned long long int) timePtr[3] << 16 )
523 + ( (unsigned long long int) timePtr[3] << 16 )
504 + ( (unsigned long long int) timePtr[6] << 8 )
524 + ( (unsigned long long int) timePtr[6] << 8 )
505 + ( (unsigned long long int) timePtr[7] );
525 + ( (unsigned long long int) timePtr[7] );
506 return acquisitionTimeAslong;
526 return acquisitionTimeAslong;
507 }
527 }
508
528
509 unsigned char getSID( rtems_event_set event )
529 unsigned char getSID( rtems_event_set event )
510 {
530 {
511 unsigned char sid;
531 unsigned char sid;
512
532
513 rtems_event_set eventSetBURST;
533 rtems_event_set eventSetBURST;
514 rtems_event_set eventSetSBM;
534 rtems_event_set eventSetSBM;
515
535
516 //******
536 //******
517 // BURST
537 // BURST
518 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
538 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
519 | RTEMS_EVENT_BURST_BP1_F1
539 | RTEMS_EVENT_BURST_BP1_F1
520 | RTEMS_EVENT_BURST_BP2_F0
540 | RTEMS_EVENT_BURST_BP2_F0
521 | RTEMS_EVENT_BURST_BP2_F1;
541 | RTEMS_EVENT_BURST_BP2_F1;
522
542
523 //****
543 //****
524 // SBM
544 // SBM
525 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
545 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
526 | RTEMS_EVENT_SBM_BP1_F1
546 | RTEMS_EVENT_SBM_BP1_F1
527 | RTEMS_EVENT_SBM_BP2_F0
547 | RTEMS_EVENT_SBM_BP2_F0
528 | RTEMS_EVENT_SBM_BP2_F1;
548 | RTEMS_EVENT_SBM_BP2_F1;
529
549
530 if (event & eventSetBURST)
550 if (event & eventSetBURST)
531 {
551 {
532 sid = SID_BURST_BP1_F0;
552 sid = SID_BURST_BP1_F0;
533 }
553 }
534 else if (event & eventSetSBM)
554 else if (event & eventSetSBM)
535 {
555 {
536 sid = SID_SBM1_BP1_F0;
556 sid = SID_SBM1_BP1_F0;
537 }
557 }
538 else
558 else
539 {
559 {
540 sid = 0;
560 sid = 0;
541 }
561 }
542
562
543 return sid;
563 return sid;
544 }
564 }
545
565
546 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
566 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
547 {
567 {
548 unsigned int i;
568 unsigned int i;
549 float re;
569 float re;
550 float im;
570 float im;
551
571
552 for (i=0; i<NB_BINS_PER_SM; i++){
572 for (i=0; i<NB_BINS_PER_SM; i++){
553 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
573 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
554 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
574 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
555 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
575 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
556 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
576 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
557 }
577 }
558 }
578 }
559
579
560 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
580 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
561 {
581 {
562 unsigned int i;
582 unsigned int i;
563 float re;
583 float re;
564
584
565 for (i=0; i<NB_BINS_PER_SM; i++){
585 for (i=0; i<NB_BINS_PER_SM; i++){
566 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
586 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
567 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
587 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
568 }
588 }
569 }
589 }
570
590
571 void ASM_patch( float *inputASM, float *outputASM )
591 void ASM_patch( float *inputASM, float *outputASM )
572 {
592 {
573 extractReImVectors( inputASM, outputASM, 1); // b1b2
593 extractReImVectors( inputASM, outputASM, 1); // b1b2
574 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
594 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
575 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
595 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
576 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
596 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
577 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
597 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
578 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
598 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
579 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
599 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
580 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
600 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
581 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
601 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
582 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
602 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
583
603
584 copyReVectors(inputASM, outputASM, 0 ); // b1b1
604 copyReVectors(inputASM, outputASM, 0 ); // b1b1
585 copyReVectors(inputASM, outputASM, 9 ); // b2b2
605 copyReVectors(inputASM, outputASM, 9 ); // b2b2
586 copyReVectors(inputASM, outputASM, 16); // b3b3
606 copyReVectors(inputASM, outputASM, 16); // b3b3
587 copyReVectors(inputASM, outputASM, 21); // e1e1
607 copyReVectors(inputASM, outputASM, 21); // e1e1
588 copyReVectors(inputASM, outputASM, 24); // e2e2
608 copyReVectors(inputASM, outputASM, 24); // e2e2
589 }
609 }
590
610
591 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
611 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
592 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
612 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
593 unsigned char ASMIndexStart,
613 unsigned char ASMIndexStart,
594 unsigned char channel )
614 unsigned char channel )
595 {
615 {
596 //*************
616 //*************
597 // input format
617 // input format
598 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
618 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
599 //**************
619 //**************
600 // output format
620 // output format
601 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
621 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
602 //************
622 //************
603 // compression
623 // compression
604 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
624 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
605 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
625 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
606
626
607 int frequencyBin;
627 int frequencyBin;
608 int asmComponent;
628 int asmComponent;
609 int offsetASM;
629 int offsetASM;
610 int offsetCompressed;
630 int offsetCompressed;
611 int offsetFBin;
631 int offsetFBin;
612 int fBinMask;
632 int fBinMask;
613 int k;
633 int k;
614
634
615 // BUILD DATA
635 // BUILD DATA
616 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
636 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
617 {
637 {
618 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
638 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
619 {
639 {
620 offsetCompressed = // NO TIME OFFSET
640 offsetCompressed = // NO TIME OFFSET
621 frequencyBin * NB_VALUES_PER_SM
641 frequencyBin * NB_VALUES_PER_SM
622 + asmComponent;
642 + asmComponent;
623 offsetASM = // NO TIME OFFSET
643 offsetASM = // NO TIME OFFSET
624 asmComponent * NB_BINS_PER_SM
644 asmComponent * NB_BINS_PER_SM
625 + ASMIndexStart
645 + ASMIndexStart
626 + frequencyBin * nbBinsToAverage;
646 + frequencyBin * nbBinsToAverage;
627 offsetFBin = ASMIndexStart
647 offsetFBin = ASMIndexStart
628 + frequencyBin * nbBinsToAverage;
648 + frequencyBin * nbBinsToAverage;
629 compressed_spec_mat[ offsetCompressed ] = 0;
649 compressed_spec_mat[ offsetCompressed ] = 0;
630 for ( k = 0; k < nbBinsToAverage; k++ )
650 for ( k = 0; k < nbBinsToAverage; k++ )
631 {
651 {
632 fBinMask = getFBinMask( offsetFBin + k, channel );
652 fBinMask = getFBinMask( offsetFBin + k, channel );
633 compressed_spec_mat[offsetCompressed ] =
653 compressed_spec_mat[offsetCompressed ] =
634 ( compressed_spec_mat[ offsetCompressed ]
654 ( compressed_spec_mat[ offsetCompressed ]
635 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
655 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
636 }
656 }
637 compressed_spec_mat[ offsetCompressed ] =
657 compressed_spec_mat[ offsetCompressed ] =
638 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
658 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
639 }
659 }
640 }
660 }
641
661
642 }
662 }
643
663
644 int getFBinMask( int index, unsigned char channel )
664 int getFBinMask( int index, unsigned char channel )
645 {
665 {
646 unsigned int indexInChar;
666 unsigned int indexInChar;
647 unsigned int indexInTheChar;
667 unsigned int indexInTheChar;
648 int fbin;
668 int fbin;
649 unsigned char *sy_lfr_fbins_fx_word1;
669 unsigned char *sy_lfr_fbins_fx_word1;
650
670
651 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
671 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
652
672
653 switch(channel)
673 switch(channel)
654 {
674 {
655 case 0:
675 case 0:
656 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
676 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
657 break;
677 break;
658 case 1:
678 case 1:
659 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
679 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
660 break;
680 break;
661 case 2:
681 case 2:
662 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
682 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
663 break;
683 break;
664 default:
684 default:
665 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
685 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
666 }
686 }
667
687
668 indexInChar = index >> 3;
688 indexInChar = index >> 3;
669 indexInTheChar = index - indexInChar * 8;
689 indexInTheChar = index - indexInChar * 8;
670
690
671 fbin = (int) ((sy_lfr_fbins_fx_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
691 fbin = (int) ((sy_lfr_fbins_fx_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
672
692
673 return fbin;
693 return fbin;
674 }
694 }
675
695
676 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
696 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
677 {
697 {
678 unsigned char bin;
698 unsigned char bin;
679 unsigned char kcoeff;
699 unsigned char kcoeff;
680
700
681 for (bin=0; bin<nb_bins_norm; bin++)
701 for (bin=0; bin<nb_bins_norm; bin++)
682 {
702 {
683 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
703 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
684 {
704 {
685 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
705 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
686 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 + 1 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
706 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 + 1 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
687 }
707 }
688 }
708 }
689 }
709 }
@@ -1,1373 +1,1381
1 /** Functions and tasks related to waveform packet generation.
1 /** Functions and tasks related to waveform packet generation.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
7 *
8 */
8 */
9
9
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11
11
12 extern struct grgpio_regs_str *grgpio_regs;
13 #define OUTPUT_1 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf8;
14 #define OUTPUT_0 grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x02;
15
12 //***************
16 //***************
13 // waveform rings
17 // waveform rings
14 // F0
18 // F0
15 ring_node waveform_ring_f0[NB_RING_NODES_F0];
19 ring_node waveform_ring_f0[NB_RING_NODES_F0];
16 ring_node *current_ring_node_f0;
20 ring_node *current_ring_node_f0;
17 ring_node *ring_node_to_send_swf_f0;
21 ring_node *ring_node_to_send_swf_f0;
18 // F1
22 // F1
19 ring_node waveform_ring_f1[NB_RING_NODES_F1];
23 ring_node waveform_ring_f1[NB_RING_NODES_F1];
20 ring_node *current_ring_node_f1;
24 ring_node *current_ring_node_f1;
21 ring_node *ring_node_to_send_swf_f1;
25 ring_node *ring_node_to_send_swf_f1;
22 ring_node *ring_node_to_send_cwf_f1;
26 ring_node *ring_node_to_send_cwf_f1;
23 // F2
27 // F2
24 ring_node waveform_ring_f2[NB_RING_NODES_F2];
28 ring_node waveform_ring_f2[NB_RING_NODES_F2];
25 ring_node *current_ring_node_f2;
29 ring_node *current_ring_node_f2;
26 ring_node *ring_node_to_send_swf_f2;
30 ring_node *ring_node_to_send_swf_f2;
27 ring_node *ring_node_to_send_cwf_f2;
31 ring_node *ring_node_to_send_cwf_f2;
28 // F3
32 // F3
29 ring_node waveform_ring_f3[NB_RING_NODES_F3];
33 ring_node waveform_ring_f3[NB_RING_NODES_F3];
30 ring_node *current_ring_node_f3;
34 ring_node *current_ring_node_f3;
31 ring_node *ring_node_to_send_cwf_f3;
35 ring_node *ring_node_to_send_cwf_f3;
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ];
36 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ];
33
37
34 bool extractSWF = false;
38 bool extractSWF = false;
35 bool swf_f0_ready = false;
39 bool swf_f0_ready = false;
36 bool swf_f1_ready = false;
40 bool swf_f1_ready = false;
37 bool swf_f2_ready = false;
41 bool swf_f2_ready = false;
38
42
39 int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
43 int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
40 ring_node ring_node_wf_snap_extracted;
44 ring_node ring_node_wf_snap_extracted;
41
45
42 //*********************
46 //*********************
43 // Interrupt SubRoutine
47 // Interrupt SubRoutine
44
48
45 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
49 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
46 {
50 {
47 ring_node *node;
51 ring_node *node;
48
52
49 node = NULL;
53 node = NULL;
50 switch ( frequencyChannel ) {
54 switch ( frequencyChannel ) {
51 case 1:
55 case 1:
52 node = ring_node_to_send_cwf_f1;
56 node = ring_node_to_send_cwf_f1;
53 break;
57 break;
54 case 2:
58 case 2:
55 node = ring_node_to_send_cwf_f2;
59 node = ring_node_to_send_cwf_f2;
56 break;
60 break;
57 case 3:
61 case 3:
58 node = ring_node_to_send_cwf_f3;
62 node = ring_node_to_send_cwf_f3;
59 break;
63 break;
60 default:
64 default:
61 break;
65 break;
62 }
66 }
63
67
64 return node;
68 return node;
65 }
69 }
66
70
67 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
71 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
68 {
72 {
69 ring_node *node;
73 ring_node *node;
70
74
71 node = NULL;
75 node = NULL;
72 switch ( frequencyChannel ) {
76 switch ( frequencyChannel ) {
73 case 0:
77 case 0:
74 node = ring_node_to_send_swf_f0;
78 node = ring_node_to_send_swf_f0;
75 break;
79 break;
76 case 1:
80 case 1:
77 node = ring_node_to_send_swf_f1;
81 node = ring_node_to_send_swf_f1;
78 break;
82 break;
79 case 2:
83 case 2:
80 node = ring_node_to_send_swf_f2;
84 node = ring_node_to_send_swf_f2;
81 break;
85 break;
82 default:
86 default:
83 break;
87 break;
84 }
88 }
85
89
86 return node;
90 return node;
87 }
91 }
88
92
89 void reset_extractSWF( void )
93 void reset_extractSWF( void )
90 {
94 {
91 extractSWF = false;
95 extractSWF = false;
92 swf_f0_ready = false;
96 swf_f0_ready = false;
93 swf_f1_ready = false;
97 swf_f1_ready = false;
94 swf_f2_ready = false;
98 swf_f2_ready = false;
95 }
99 }
96
100
97 inline void waveforms_isr_f3( void )
101 inline void waveforms_isr_f3( void )
98 {
102 {
99 rtems_status_code spare_status;
103 rtems_status_code spare_status;
100
104
101 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
105 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
102 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
106 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
103 { // in modes other than STANDBY and BURST, send the CWF_F3 data
107 { // in modes other than STANDBY and BURST, send the CWF_F3 data
104 //***
108 //***
105 // F3
109 // F3
106 if ( (waveform_picker_regs->status & 0xc0) != 0x00 ) { // [1100 0000] check the f3 full bits
110 if ( (waveform_picker_regs->status & 0xc0) != 0x00 ) { // [1100 0000] check the f3 full bits
107 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
111 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
108 current_ring_node_f3 = current_ring_node_f3->next;
112 current_ring_node_f3 = current_ring_node_f3->next;
109 if ((waveform_picker_regs->status & 0x40) == 0x40){ // [0100 0000] f3 buffer 0 is full
113 if ((waveform_picker_regs->status & 0x40) == 0x40){ // [0100 0000] f3 buffer 0 is full
110 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
114 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
111 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
115 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
112 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
116 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
113 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008840; // [1000 1000 0100 0000]
117 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008840; // [1000 1000 0100 0000]
114 }
118 }
115 else if ((waveform_picker_regs->status & 0x80) == 0x80){ // [1000 0000] f3 buffer 1 is full
119 else if ((waveform_picker_regs->status & 0x80) == 0x80){ // [1000 0000] f3 buffer 1 is full
116 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
120 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
117 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
121 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
118 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
122 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
119 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008880; // [1000 1000 1000 0000]
123 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008880; // [1000 1000 1000 0000]
120 }
124 }
121 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
125 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
122 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
126 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
123 }
127 }
124 }
128 }
125 }
129 }
126 }
130 }
127
131
128 inline void waveforms_isr_normal( void )
132 inline void waveforms_isr_normal( void )
129 {
133 {
130 rtems_status_code status;
134 rtems_status_code status;
131
135
132 if ( ( (waveform_picker_regs->status & 0x30) != 0x00 ) // [0011 0000] check the f2 full bits
136 if ( ( (waveform_picker_regs->status & 0x30) != 0x00 ) // [0011 0000] check the f2 full bits
133 && ( (waveform_picker_regs->status & 0x0c) != 0x00 ) // [0000 1100] check the f1 full bits
137 && ( (waveform_picker_regs->status & 0x0c) != 0x00 ) // [0000 1100] check the f1 full bits
134 && ( (waveform_picker_regs->status & 0x03) != 0x00 )) // [0000 0011] check the f0 full bits
138 && ( (waveform_picker_regs->status & 0x03) != 0x00 )) // [0000 0011] check the f0 full bits
135 {
139 {
136 //***
140 //***
137 // F0
141 // F0
138 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
142 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
139 current_ring_node_f0 = current_ring_node_f0->next;
143 current_ring_node_f0 = current_ring_node_f0->next;
140 if ( (waveform_picker_regs->status & 0x01) == 0x01)
144 if ( (waveform_picker_regs->status & 0x01) == 0x01)
141 {
145 {
142
146
143 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
147 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
144 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
148 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
145 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
149 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
146 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
150 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
147 }
151 }
148 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
152 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
149 {
153 {
150 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
154 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
151 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
155 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
152 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
156 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
153 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
157 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
154 }
158 }
155
159
156 //***
160 //***
157 // F1
161 // F1
158 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
162 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
159 current_ring_node_f1 = current_ring_node_f1->next;
163 current_ring_node_f1 = current_ring_node_f1->next;
160 if ( (waveform_picker_regs->status & 0x04) == 0x04)
164 if ( (waveform_picker_regs->status & 0x04) == 0x04)
161 {
165 {
162 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
166 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
163 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
167 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
164 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
168 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
165 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
169 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
166 }
170 }
167 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
171 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
168 {
172 {
169 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
173 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
170 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
174 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
171 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
175 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
172 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
176 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
173 }
177 }
174
178
175 //***
179 //***
176 // F2
180 // F2
177 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
181 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
178 current_ring_node_f2 = current_ring_node_f2->next;
182 current_ring_node_f2 = current_ring_node_f2->next;
179 if ( (waveform_picker_regs->status & 0x10) == 0x10)
183 if ( (waveform_picker_regs->status & 0x10) == 0x10)
180 {
184 {
181 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
185 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
182 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
186 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
183 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
187 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
184 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
188 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
185 }
189 }
186 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
190 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
187 {
191 {
188 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
192 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
189 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
193 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
190 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
194 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
191 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
195 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
192 }
196 }
193 //
197 //
194 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
198 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
195 if ( status != RTEMS_SUCCESSFUL)
199 if ( status != RTEMS_SUCCESSFUL)
196 {
200 {
197 status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
201 status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
198 }
202 }
199 }
203 }
200 }
204 }
201
205
202 inline void waveforms_isr_burst( void )
206 inline void waveforms_isr_burst( void )
203 {
207 {
204 unsigned char status;
208 unsigned char status;
205 rtems_status_code spare_status;
209 rtems_status_code spare_status;
206
210
207 status = (waveform_picker_regs->status & 0x30) >> 4; // [0011 0000] get the status bits for f2
211 status = (waveform_picker_regs->status & 0x30) >> 4; // [0011 0000] get the status bits for f2
208
212
209
213
210 switch(status)
214 switch(status)
211 {
215 {
212 case 1:
216 case 1:
213 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
217 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
214 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
218 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
215 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
219 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
216 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
220 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
217 current_ring_node_f2 = current_ring_node_f2->next;
221 current_ring_node_f2 = current_ring_node_f2->next;
218 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
222 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
219 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
223 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
220 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
224 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
221 }
225 }
222 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
226 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
223 break;
227 break;
224 case 2:
228 case 2:
225 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
229 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
226 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
230 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
227 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
231 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
228 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
232 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
229 current_ring_node_f2 = current_ring_node_f2->next;
233 current_ring_node_f2 = current_ring_node_f2->next;
230 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
234 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
231 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
235 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
232 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
236 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
233 }
237 }
234 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
238 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
235 break;
239 break;
236 default:
240 default:
237 break;
241 break;
238 }
242 }
239 }
243 }
240
244
241 inline void waveforms_isr_sbm1( void )
245 inline void waveforms_isr_sbm1( void )
242 {
246 {
243 rtems_status_code status;
247 rtems_status_code status;
244
248
245 //***
249 //***
246 // F1
250 // F1
247 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bits
251 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bits
248 // (1) change the receiving buffer for the waveform picker
252 // (1) change the receiving buffer for the waveform picker
249 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
253 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
250 current_ring_node_f1 = current_ring_node_f1->next;
254 current_ring_node_f1 = current_ring_node_f1->next;
251 if ( (waveform_picker_regs->status & 0x04) == 0x04)
255 if ( (waveform_picker_regs->status & 0x04) == 0x04)
252 {
256 {
253 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
257 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
254 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
258 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
255 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
259 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
256 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
260 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
257 }
261 }
258 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
262 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
259 {
263 {
260 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
264 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
261 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
265 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
262 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
266 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
263 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
267 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
264 }
268 }
265 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
269 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
266 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 );
270 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 );
267 }
271 }
268
272
269 //***
273 //***
270 // F0
274 // F0
271 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) { // [0000 0011] check the f0 full bits
275 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) { // [0000 0011] check the f0 full bits
272 swf_f0_ready = true;
276 swf_f0_ready = true;
273 // change f0 buffer
277 // change f0 buffer
274 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
278 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
275 current_ring_node_f0 = current_ring_node_f0->next;
279 current_ring_node_f0 = current_ring_node_f0->next;
276 if ( (waveform_picker_regs->status & 0x01) == 0x01)
280 if ( (waveform_picker_regs->status & 0x01) == 0x01)
277 {
281 {
278
282
279 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
283 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
280 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
284 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
281 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
285 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
282 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
286 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
283 }
287 }
284 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
288 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
285 {
289 {
286 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
290 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
287 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
291 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
288 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
292 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
289 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
293 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
290 }
294 }
291 }
295 }
292
296
293 //***
297 //***
294 // F2
298 // F2
295 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bits
299 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bits
296 swf_f2_ready = true;
300 swf_f2_ready = true;
297 // change f2 buffer
301 // change f2 buffer
298 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
302 ring_node_to_send_swf_f2 = current_ring_node_f2->previous;
299 current_ring_node_f2 = current_ring_node_f2->next;
303 current_ring_node_f2 = current_ring_node_f2->next;
300 if ( (waveform_picker_regs->status & 0x10) == 0x10)
304 if ( (waveform_picker_regs->status & 0x10) == 0x10)
301 {
305 {
302 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
306 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
303 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
307 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
304 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
308 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
305 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
309 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
306 }
310 }
307 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
311 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
308 {
312 {
309 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
313 ring_node_to_send_swf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
310 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
314 ring_node_to_send_swf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
311 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
315 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
312 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
316 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
313 }
317 }
314 }
318 }
315 }
319 }
316
320
317 inline void waveforms_isr_sbm2( void )
321 inline void waveforms_isr_sbm2( void )
318 {
322 {
319 rtems_status_code status;
323 rtems_status_code status;
320
324
321 //***
325 //***
322 // F2
326 // F2
323 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bit
327 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bit
324 // (1) change the receiving buffer for the waveform picker
328 // (1) change the receiving buffer for the waveform picker
325 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
329 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
326 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
330 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
327 current_ring_node_f2 = current_ring_node_f2->next;
331 current_ring_node_f2 = current_ring_node_f2->next;
328 if ( (waveform_picker_regs->status & 0x10) == 0x10)
332 if ( (waveform_picker_regs->status & 0x10) == 0x10)
329 {
333 {
330 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
334 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
331 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
335 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
332 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
336 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
333 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
337 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
334 }
338 }
335 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
339 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
336 {
340 {
337 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
341 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
338 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
342 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
339 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
343 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
340 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
344 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
341 }
345 }
342 // (2) send an event for the waveforms transmission
346 // (2) send an event for the waveforms transmission
343 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 );
347 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 );
344 }
348 }
345
349
346 //***
350 //***
347 // F0
351 // F0
348 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) { // [0000 0011] check the f0 full bit
352 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) { // [0000 0011] check the f0 full bit
349 swf_f0_ready = true;
353 swf_f0_ready = true;
350 // change f0 buffer
354 // change f0 buffer
351 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
355 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
352 current_ring_node_f0 = current_ring_node_f0->next;
356 current_ring_node_f0 = current_ring_node_f0->next;
353 if ( (waveform_picker_regs->status & 0x01) == 0x01)
357 if ( (waveform_picker_regs->status & 0x01) == 0x01)
354 {
358 {
355
359
356 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
360 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
357 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
361 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
358 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
362 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
359 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
363 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
360 }
364 }
361 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
365 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
362 {
366 {
363 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
367 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
364 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
368 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
365 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
369 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
366 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
370 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
367 }
371 }
368 }
372 }
369
373
370 //***
374 //***
371 // F1
375 // F1
372 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bit
376 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bit
373 swf_f1_ready = true;
377 swf_f1_ready = true;
374 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
378 ring_node_to_send_swf_f1 = current_ring_node_f1->previous;
375 current_ring_node_f1 = current_ring_node_f1->next;
379 current_ring_node_f1 = current_ring_node_f1->next;
376 if ( (waveform_picker_regs->status & 0x04) == 0x04)
380 if ( (waveform_picker_regs->status & 0x04) == 0x04)
377 {
381 {
378 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
382 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
379 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
383 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
380 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
384 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
381 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
385 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
382 }
386 }
383 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
387 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
384 {
388 {
385 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
389 ring_node_to_send_swf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
386 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
390 ring_node_to_send_swf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
387 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
391 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
388 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
392 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
389 }
393 }
390 }
394 }
391 }
395 }
392
396
393 rtems_isr waveforms_isr( rtems_vector_number vector )
397 rtems_isr waveforms_isr( rtems_vector_number vector )
394 {
398 {
395 /** This is the interrupt sub routine called by the waveform picker core.
399 /** This is the interrupt sub routine called by the waveform picker core.
396 *
400 *
397 * This ISR launch different actions depending mainly on two pieces of information:
401 * This ISR launch different actions depending mainly on two pieces of information:
398 * 1. the values read in the registers of the waveform picker.
402 * 1. the values read in the registers of the waveform picker.
399 * 2. the current LFR mode.
403 * 2. the current LFR mode.
400 *
404 *
401 */
405 */
402
406
403 // STATUS
407 // STATUS
404 // new error error buffer full
408 // new error error buffer full
405 // 15 14 13 12 11 10 9 8
409 // 15 14 13 12 11 10 9 8
406 // f3 f2 f1 f0 f3 f2 f1 f0
410 // f3 f2 f1 f0 f3 f2 f1 f0
407 //
411 //
408 // ready buffer
412 // ready buffer
409 // 7 6 5 4 3 2 1 0
413 // 7 6 5 4 3 2 1 0
410 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
414 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
411
415
416 // OUTPUT_1;
417
412 rtems_status_code spare_status;
418 rtems_status_code spare_status;
413
419
414 waveforms_isr_f3();
420 waveforms_isr_f3();
415
421
416 if ( (waveform_picker_regs->status & 0xff00) != 0x00) // [1111 1111 0000 0000] check the error bits
422 if ( (waveform_picker_regs->status & 0xff00) != 0x00) // [1111 1111 0000 0000] check the error bits
417 {
423 {
418 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
424 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
419 }
425 }
420
426
421 switch(lfrCurrentMode)
427 switch(lfrCurrentMode)
422 {
428 {
423 //********
429 //********
424 // STANDBY
430 // STANDBY
425 case(LFR_MODE_STANDBY):
431 case(LFR_MODE_STANDBY):
426 break;
432 break;
427
433
428 //******
434 //******
429 // NORMAL
435 // NORMAL
430 case(LFR_MODE_NORMAL):
436 case(LFR_MODE_NORMAL):
431 waveforms_isr_normal();
437 waveforms_isr_normal();
432 break;
438 break;
433
439
434 //******
440 //******
435 // BURST
441 // BURST
436 case(LFR_MODE_BURST):
442 case(LFR_MODE_BURST):
437 waveforms_isr_burst();
443 waveforms_isr_burst();
438 break;
444 break;
439
445
440 //*****
446 //*****
441 // SBM1
447 // SBM1
442 case(LFR_MODE_SBM1):
448 case(LFR_MODE_SBM1):
443 waveforms_isr_sbm1();
449 waveforms_isr_sbm1();
444 break;
450 break;
445
451
446 //*****
452 //*****
447 // SBM2
453 // SBM2
448 case(LFR_MODE_SBM2):
454 case(LFR_MODE_SBM2):
449 waveforms_isr_sbm2();
455 waveforms_isr_sbm2();
450 break;
456 break;
451
457
452 //********
458 //********
453 // DEFAULT
459 // DEFAULT
454 default:
460 default:
455 break;
461 break;
456 }
462 }
463
464 // OUTPUT_0;
457 }
465 }
458
466
459 //************
467 //************
460 // RTEMS TASKS
468 // RTEMS TASKS
461
469
462 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
470 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
463 {
471 {
464 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
472 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
465 *
473 *
466 * @param unused is the starting argument of the RTEMS task
474 * @param unused is the starting argument of the RTEMS task
467 *
475 *
468 * The following data packets are sent by this task:
476 * The following data packets are sent by this task:
469 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
477 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
470 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
478 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
471 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
479 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
472 *
480 *
473 */
481 */
474
482
475 rtems_event_set event_out;
483 rtems_event_set event_out;
476 rtems_id queue_id;
484 rtems_id queue_id;
477 rtems_status_code status;
485 rtems_status_code status;
478 bool resynchronisationEngaged;
486 bool resynchronisationEngaged;
479 ring_node *ring_node_wf_snap_extracted_ptr;
487 ring_node *ring_node_wf_snap_extracted_ptr;
480
488
481 ring_node_wf_snap_extracted_ptr = (ring_node *) &ring_node_wf_snap_extracted;
489 ring_node_wf_snap_extracted_ptr = (ring_node *) &ring_node_wf_snap_extracted;
482
490
483 resynchronisationEngaged = false;
491 resynchronisationEngaged = false;
484
492
485 status = get_message_queue_id_send( &queue_id );
493 status = get_message_queue_id_send( &queue_id );
486 if (status != RTEMS_SUCCESSFUL)
494 if (status != RTEMS_SUCCESSFUL)
487 {
495 {
488 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
496 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status)
489 }
497 }
490
498
491 BOOT_PRINTF("in WFRM ***\n")
499 BOOT_PRINTF("in WFRM ***\n")
492
500
493 while(1){
501 while(1){
494 // wait for an RTEMS_EVENT
502 // wait for an RTEMS_EVENT
495 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
503 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
496 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
504 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
497 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
505 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
498 if(resynchronisationEngaged == false)
506 if(resynchronisationEngaged == false)
499 { // engage resynchronisation
507 { // engage resynchronisation
500 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
508 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
501 resynchronisationEngaged = true;
509 resynchronisationEngaged = true;
502 }
510 }
503 else
511 else
504 { // reset delta_snapshot to the nominal value
512 { // reset delta_snapshot to the nominal value
505 PRINTF("no resynchronisation, reset delta_snapshot to the nominal value\n")
513 PRINTF("no resynchronisation, reset delta_snapshot to the nominal value\n")
506 set_wfp_delta_snapshot();
514 set_wfp_delta_snapshot();
507 resynchronisationEngaged = false;
515 resynchronisationEngaged = false;
508 }
516 }
509 //
517 //
510
518
511 if (event_out == RTEMS_EVENT_MODE_NORMAL)
519 if (event_out == RTEMS_EVENT_MODE_NORMAL)
512 {
520 {
513 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n")
521 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n")
514 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
522 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
515 ring_node_to_send_swf_f1->sid = SID_NORM_SWF_F1;
523 ring_node_to_send_swf_f1->sid = SID_NORM_SWF_F1;
516 ring_node_to_send_swf_f2->sid = SID_NORM_SWF_F2;
524 ring_node_to_send_swf_f2->sid = SID_NORM_SWF_F2;
517 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
525 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
518 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f1, sizeof( ring_node* ) );
526 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f1, sizeof( ring_node* ) );
519 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f2, sizeof( ring_node* ) );
527 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f2, sizeof( ring_node* ) );
520 }
528 }
521 if (event_out == RTEMS_EVENT_MODE_SBM1)
529 if (event_out == RTEMS_EVENT_MODE_SBM1)
522 {
530 {
523 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n")
531 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n")
524 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
532 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
525 ring_node_wf_snap_extracted_ptr->sid = SID_NORM_SWF_F1;
533 ring_node_wf_snap_extracted_ptr->sid = SID_NORM_SWF_F1;
526 ring_node_to_send_swf_f2->sid = SID_NORM_SWF_F2;
534 ring_node_to_send_swf_f2->sid = SID_NORM_SWF_F2;
527 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
535 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
528 status = rtems_message_queue_send( queue_id, &ring_node_wf_snap_extracted_ptr, sizeof( ring_node* ) );
536 status = rtems_message_queue_send( queue_id, &ring_node_wf_snap_extracted_ptr, sizeof( ring_node* ) );
529 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f2, sizeof( ring_node* ) );
537 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f2, sizeof( ring_node* ) );
530 }
538 }
531 if (event_out == RTEMS_EVENT_MODE_SBM2)
539 if (event_out == RTEMS_EVENT_MODE_SBM2)
532 {
540 {
533 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n")
541 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n")
534 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
542 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
535 ring_node_to_send_swf_f1->sid = SID_NORM_SWF_F1;
543 ring_node_to_send_swf_f1->sid = SID_NORM_SWF_F1;
536 ring_node_wf_snap_extracted_ptr->sid = SID_NORM_SWF_F2;
544 ring_node_wf_snap_extracted_ptr->sid = SID_NORM_SWF_F2;
537 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
545 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
538 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f1, sizeof( ring_node* ) );
546 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f1, sizeof( ring_node* ) );
539 status = rtems_message_queue_send( queue_id, &ring_node_wf_snap_extracted_ptr, sizeof( ring_node* ) );
547 status = rtems_message_queue_send( queue_id, &ring_node_wf_snap_extracted_ptr, sizeof( ring_node* ) );
540 }
548 }
541 }
549 }
542 }
550 }
543
551
544 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
552 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
545 {
553 {
546 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
554 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
547 *
555 *
548 * @param unused is the starting argument of the RTEMS task
556 * @param unused is the starting argument of the RTEMS task
549 *
557 *
550 * The following data packet is sent by this task:
558 * The following data packet is sent by this task:
551 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
559 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
552 *
560 *
553 */
561 */
554
562
555 rtems_event_set event_out;
563 rtems_event_set event_out;
556 rtems_id queue_id;
564 rtems_id queue_id;
557 rtems_status_code status;
565 rtems_status_code status;
558 ring_node ring_node_cwf3_light;
566 ring_node ring_node_cwf3_light;
559 ring_node *ring_node_to_send_cwf;
567 ring_node *ring_node_to_send_cwf;
560
568
561 status = get_message_queue_id_send( &queue_id );
569 status = get_message_queue_id_send( &queue_id );
562 if (status != RTEMS_SUCCESSFUL)
570 if (status != RTEMS_SUCCESSFUL)
563 {
571 {
564 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
572 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
565 }
573 }
566
574
567 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
575 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
568
576
569 // init the ring_node_cwf3_light structure
577 // init the ring_node_cwf3_light structure
570 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
578 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
571 ring_node_cwf3_light.coarseTime = 0x00;
579 ring_node_cwf3_light.coarseTime = 0x00;
572 ring_node_cwf3_light.fineTime = 0x00;
580 ring_node_cwf3_light.fineTime = 0x00;
573 ring_node_cwf3_light.next = NULL;
581 ring_node_cwf3_light.next = NULL;
574 ring_node_cwf3_light.previous = NULL;
582 ring_node_cwf3_light.previous = NULL;
575 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
583 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
576 ring_node_cwf3_light.status = 0x00;
584 ring_node_cwf3_light.status = 0x00;
577
585
578 BOOT_PRINTF("in CWF3 ***\n")
586 BOOT_PRINTF("in CWF3 ***\n")
579
587
580 while(1){
588 while(1){
581 // wait for an RTEMS_EVENT
589 // wait for an RTEMS_EVENT
582 rtems_event_receive( RTEMS_EVENT_0,
590 rtems_event_receive( RTEMS_EVENT_0,
583 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
591 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
584 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
592 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
585 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
593 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
586 {
594 {
587 ring_node_to_send_cwf = getRingNodeToSendCWF( 3 );
595 ring_node_to_send_cwf = getRingNodeToSendCWF( 3 );
588 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
596 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
589 {
597 {
590 PRINTF("send CWF_LONG_F3\n")
598 PRINTF("send CWF_LONG_F3\n")
591 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
599 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
592 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
600 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
593 }
601 }
594 else
602 else
595 {
603 {
596 PRINTF("send CWF_F3 (light)\n")
604 PRINTF("send CWF_F3 (light)\n")
597 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
605 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
598 }
606 }
599
607
600 }
608 }
601 else
609 else
602 {
610 {
603 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
611 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
604 }
612 }
605 }
613 }
606 }
614 }
607
615
608 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
616 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
609 {
617 {
610 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
618 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
611 *
619 *
612 * @param unused is the starting argument of the RTEMS task
620 * @param unused is the starting argument of the RTEMS task
613 *
621 *
614 * The following data packet is sent by this function:
622 * The following data packet is sent by this function:
615 * - TM_LFR_SCIENCE_BURST_CWF_F2
623 * - TM_LFR_SCIENCE_BURST_CWF_F2
616 * - TM_LFR_SCIENCE_SBM2_CWF_F2
624 * - TM_LFR_SCIENCE_SBM2_CWF_F2
617 *
625 *
618 */
626 */
619
627
620 rtems_event_set event_out;
628 rtems_event_set event_out;
621 rtems_id queue_id;
629 rtems_id queue_id;
622 rtems_status_code status;
630 rtems_status_code status;
623 ring_node *ring_node_to_send;
631 ring_node *ring_node_to_send;
624 unsigned long long int acquisitionTimeF0_asLong;
632 unsigned long long int acquisitionTimeF0_asLong;
625
633
626 acquisitionTimeF0_asLong = 0x00;
634 acquisitionTimeF0_asLong = 0x00;
627
635
628 status = get_message_queue_id_send( &queue_id );
636 status = get_message_queue_id_send( &queue_id );
629 if (status != RTEMS_SUCCESSFUL)
637 if (status != RTEMS_SUCCESSFUL)
630 {
638 {
631 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
639 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
632 }
640 }
633
641
634 BOOT_PRINTF("in CWF2 ***\n")
642 BOOT_PRINTF("in CWF2 ***\n")
635
643
636 while(1){
644 while(1){
637 // wait for an RTEMS_EVENT
645 // wait for an RTEMS_EVENT
638 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
646 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
639 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
647 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
640 ring_node_to_send = getRingNodeToSendCWF( 2 );
648 ring_node_to_send = getRingNodeToSendCWF( 2 );
641 if (event_out == RTEMS_EVENT_MODE_BURST)
649 if (event_out == RTEMS_EVENT_MODE_BURST)
642 {
650 {
643 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
651 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
644 }
652 }
645 if (event_out == RTEMS_EVENT_MODE_SBM2)
653 if (event_out == RTEMS_EVENT_MODE_SBM2)
646 {
654 {
647 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
655 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
648 // launch snapshot extraction if needed
656 // launch snapshot extraction if needed
649 if (extractSWF == true)
657 if (extractSWF == true)
650 {
658 {
651 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
659 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
652 // extract the snapshot
660 // extract the snapshot
653 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2, acquisitionTimeF0_asLong );
661 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2, acquisitionTimeF0_asLong );
654 // send the snapshot when built
662 // send the snapshot when built
655 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
663 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
656 extractSWF = false;
664 extractSWF = false;
657 }
665 }
658 if (swf_f0_ready && swf_f1_ready)
666 if (swf_f0_ready && swf_f1_ready)
659 {
667 {
660 extractSWF = true;
668 extractSWF = true;
661 // record the acquition time of the fΓ  snapshot to use to build the snapshot at f2
669 // record the acquition time of the fΓ  snapshot to use to build the snapshot at f2
662 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
670 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
663 swf_f0_ready = false;
671 swf_f0_ready = false;
664 swf_f1_ready = false;
672 swf_f1_ready = false;
665 }
673 }
666 }
674 }
667 }
675 }
668 }
676 }
669
677
670 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
678 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
671 {
679 {
672 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
680 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
673 *
681 *
674 * @param unused is the starting argument of the RTEMS task
682 * @param unused is the starting argument of the RTEMS task
675 *
683 *
676 * The following data packet is sent by this function:
684 * The following data packet is sent by this function:
677 * - TM_LFR_SCIENCE_SBM1_CWF_F1
685 * - TM_LFR_SCIENCE_SBM1_CWF_F1
678 *
686 *
679 */
687 */
680
688
681 rtems_event_set event_out;
689 rtems_event_set event_out;
682 rtems_id queue_id;
690 rtems_id queue_id;
683 rtems_status_code status;
691 rtems_status_code status;
684
692
685 ring_node *ring_node_to_send_cwf;
693 ring_node *ring_node_to_send_cwf;
686
694
687 status = get_message_queue_id_send( &queue_id );
695 status = get_message_queue_id_send( &queue_id );
688 if (status != RTEMS_SUCCESSFUL)
696 if (status != RTEMS_SUCCESSFUL)
689 {
697 {
690 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
698 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
691 }
699 }
692
700
693 BOOT_PRINTF("in CWF1 ***\n")
701 BOOT_PRINTF("in CWF1 ***\n")
694
702
695 while(1){
703 while(1){
696 // wait for an RTEMS_EVENT
704 // wait for an RTEMS_EVENT
697 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
705 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
698 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
706 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
699 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
707 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
700 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
708 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
701 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
709 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
702 if (status != 0)
710 if (status != 0)
703 {
711 {
704 PRINTF("cwf sending failed\n")
712 PRINTF("cwf sending failed\n")
705 }
713 }
706 // launch snapshot extraction if needed
714 // launch snapshot extraction if needed
707 if (extractSWF == true)
715 if (extractSWF == true)
708 {
716 {
709 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
717 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
710 // launch the snapshot extraction
718 // launch the snapshot extraction
711 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 );
719 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 );
712 extractSWF = false;
720 extractSWF = false;
713 }
721 }
714 if (swf_f0_ready == true)
722 if (swf_f0_ready == true)
715 {
723 {
716 extractSWF = true;
724 extractSWF = true;
717 swf_f0_ready = false; // this step shall be executed only one time
725 swf_f0_ready = false; // this step shall be executed only one time
718 }
726 }
719 if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction
727 if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction
720 {
728 {
721 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 );
729 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 );
722 swf_f1_ready = false;
730 swf_f1_ready = false;
723 swf_f2_ready = false;
731 swf_f2_ready = false;
724 }
732 }
725 }
733 }
726 }
734 }
727
735
728 rtems_task swbd_task(rtems_task_argument argument)
736 rtems_task swbd_task(rtems_task_argument argument)
729 {
737 {
730 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
738 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
731 *
739 *
732 * @param unused is the starting argument of the RTEMS task
740 * @param unused is the starting argument of the RTEMS task
733 *
741 *
734 */
742 */
735
743
736 rtems_event_set event_out;
744 rtems_event_set event_out;
737 unsigned long long int acquisitionTimeF0_asLong;
745 unsigned long long int acquisitionTimeF0_asLong;
738
746
739 acquisitionTimeF0_asLong = 0x00;
747 acquisitionTimeF0_asLong = 0x00;
740
748
741 BOOT_PRINTF("in SWBD ***\n")
749 BOOT_PRINTF("in SWBD ***\n")
742
750
743 while(1){
751 while(1){
744 // wait for an RTEMS_EVENT
752 // wait for an RTEMS_EVENT
745 rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2,
753 rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2,
746 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
754 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
747 if (event_out == RTEMS_EVENT_MODE_SBM1)
755 if (event_out == RTEMS_EVENT_MODE_SBM1)
748 {
756 {
749 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
757 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
750 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1, acquisitionTimeF0_asLong );
758 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1, acquisitionTimeF0_asLong );
751 swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent
759 swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent
752 }
760 }
753 else
761 else
754 {
762 {
755 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
763 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
756 }
764 }
757 }
765 }
758 }
766 }
759
767
760 //******************
768 //******************
761 // general functions
769 // general functions
762
770
763 void WFP_init_rings( void )
771 void WFP_init_rings( void )
764 {
772 {
765 // F0 RING
773 // F0 RING
766 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
774 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
767 // F1 RING
775 // F1 RING
768 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
776 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
769 // F2 RING
777 // F2 RING
770 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
778 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
771 // F3 RING
779 // F3 RING
772 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
780 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
773
781
774 ring_node_wf_snap_extracted.buffer_address = (int) wf_snap_extracted;
782 ring_node_wf_snap_extracted.buffer_address = (int) wf_snap_extracted;
775
783
776 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
784 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
777 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
785 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
778 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
786 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
779 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
787 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
780 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
788 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
781 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
789 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
782 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
790 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
783 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
791 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
784
792
785 }
793 }
786
794
787 void WFP_reset_current_ring_nodes( void )
795 void WFP_reset_current_ring_nodes( void )
788 {
796 {
789 current_ring_node_f0 = waveform_ring_f0[0].next;
797 current_ring_node_f0 = waveform_ring_f0[0].next;
790 current_ring_node_f1 = waveform_ring_f1[0].next;
798 current_ring_node_f1 = waveform_ring_f1[0].next;
791 current_ring_node_f2 = waveform_ring_f2[0].next;
799 current_ring_node_f2 = waveform_ring_f2[0].next;
792 current_ring_node_f3 = waveform_ring_f3[0].next;
800 current_ring_node_f3 = waveform_ring_f3[0].next;
793
801
794 ring_node_to_send_swf_f0 = waveform_ring_f0;
802 ring_node_to_send_swf_f0 = waveform_ring_f0;
795 ring_node_to_send_swf_f1 = waveform_ring_f1;
803 ring_node_to_send_swf_f1 = waveform_ring_f1;
796 ring_node_to_send_swf_f2 = waveform_ring_f2;
804 ring_node_to_send_swf_f2 = waveform_ring_f2;
797
805
798 ring_node_to_send_cwf_f1 = waveform_ring_f1;
806 ring_node_to_send_cwf_f1 = waveform_ring_f1;
799 ring_node_to_send_cwf_f2 = waveform_ring_f2;
807 ring_node_to_send_cwf_f2 = waveform_ring_f2;
800 ring_node_to_send_cwf_f3 = waveform_ring_f3;
808 ring_node_to_send_cwf_f3 = waveform_ring_f3;
801 }
809 }
802
810
803 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
811 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
804 {
812 {
805 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
813 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
806 *
814 *
807 * @param waveform points to the buffer containing the data that will be send.
815 * @param waveform points to the buffer containing the data that will be send.
808 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
816 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
809 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
817 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
810 * contain information to setup the transmission of the data packets.
818 * contain information to setup the transmission of the data packets.
811 *
819 *
812 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
820 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
813 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
821 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
814 *
822 *
815 */
823 */
816
824
817 unsigned int i;
825 unsigned int i;
818 int ret;
826 int ret;
819 rtems_status_code status;
827 rtems_status_code status;
820
828
821 char *sample;
829 char *sample;
822 int *dataPtr;
830 int *dataPtr;
823
831
824 ret = LFR_DEFAULT;
832 ret = LFR_DEFAULT;
825
833
826 dataPtr = (int*) ring_node_to_send->buffer_address;
834 dataPtr = (int*) ring_node_to_send->buffer_address;
827
835
828 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
836 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
829 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
837 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
830
838
831 //**********************
839 //**********************
832 // BUILD CWF3_light DATA
840 // BUILD CWF3_light DATA
833 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
841 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
834 {
842 {
835 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
843 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
836 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ];
844 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ];
837 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ];
845 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ];
838 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ];
846 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ];
839 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ];
847 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ];
840 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ];
848 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ];
841 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ];
849 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ];
842 }
850 }
843
851
844 // SEND PACKET
852 // SEND PACKET
845 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
853 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
846 if (status != RTEMS_SUCCESSFUL) {
854 if (status != RTEMS_SUCCESSFUL) {
847 ret = LFR_DEFAULT;
855 ret = LFR_DEFAULT;
848 }
856 }
849
857
850 return ret;
858 return ret;
851 }
859 }
852
860
853 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
861 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
854 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
862 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
855 {
863 {
856 unsigned long long int acquisitionTimeAsLong;
864 unsigned long long int acquisitionTimeAsLong;
857 unsigned char localAcquisitionTime[6];
865 unsigned char localAcquisitionTime[6];
858 double deltaT;
866 double deltaT;
859
867
860 deltaT = 0.;
868 deltaT = 0.;
861
869
862 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 );
870 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 );
863 localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 );
871 localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 );
864 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 );
872 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 );
865 localAcquisitionTime[3] = (unsigned char) ( coarseTime );
873 localAcquisitionTime[3] = (unsigned char) ( coarseTime );
866 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 );
874 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 );
867 localAcquisitionTime[5] = (unsigned char) ( fineTime );
875 localAcquisitionTime[5] = (unsigned char) ( fineTime );
868
876
869 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
877 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
870 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
878 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
871 + ( (unsigned long long int) localAcquisitionTime[2] << 24 )
879 + ( (unsigned long long int) localAcquisitionTime[2] << 24 )
872 + ( (unsigned long long int) localAcquisitionTime[3] << 16 )
880 + ( (unsigned long long int) localAcquisitionTime[3] << 16 )
873 + ( (unsigned long long int) localAcquisitionTime[4] << 8 )
881 + ( (unsigned long long int) localAcquisitionTime[4] << 8 )
874 + ( (unsigned long long int) localAcquisitionTime[5] );
882 + ( (unsigned long long int) localAcquisitionTime[5] );
875
883
876 switch( sid )
884 switch( sid )
877 {
885 {
878 case SID_NORM_SWF_F0:
886 case SID_NORM_SWF_F0:
879 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
887 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
880 break;
888 break;
881
889
882 case SID_NORM_SWF_F1:
890 case SID_NORM_SWF_F1:
883 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
891 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
884 break;
892 break;
885
893
886 case SID_NORM_SWF_F2:
894 case SID_NORM_SWF_F2:
887 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
895 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
888 break;
896 break;
889
897
890 case SID_SBM1_CWF_F1:
898 case SID_SBM1_CWF_F1:
891 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
899 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
892 break;
900 break;
893
901
894 case SID_SBM2_CWF_F2:
902 case SID_SBM2_CWF_F2:
895 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
903 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
896 break;
904 break;
897
905
898 case SID_BURST_CWF_F2:
906 case SID_BURST_CWF_F2:
899 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
907 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
900 break;
908 break;
901
909
902 case SID_NORM_CWF_F3:
910 case SID_NORM_CWF_F3:
903 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
911 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
904 break;
912 break;
905
913
906 case SID_NORM_CWF_LONG_F3:
914 case SID_NORM_CWF_LONG_F3:
907 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
915 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
908 break;
916 break;
909
917
910 default:
918 default:
911 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
919 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
912 deltaT = 0.;
920 deltaT = 0.;
913 break;
921 break;
914 }
922 }
915
923
916 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
924 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
917 //
925 //
918 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
926 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
919 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
927 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
920 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
928 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
921 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
929 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
922 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
930 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
923 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
931 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
924
932
925 }
933 }
926
934
927 void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel, unsigned long long int acquisitionTimeF0_asLong )
935 void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel, unsigned long long int acquisitionTimeF0_asLong )
928 {
936 {
929 unsigned int i;
937 unsigned int i;
930 unsigned long long int centerTime_asLong;
938 unsigned long long int centerTime_asLong;
931 unsigned long long int acquisitionTime_asLong;
939 unsigned long long int acquisitionTime_asLong;
932 unsigned long long int bufferAcquisitionTime_asLong;
940 unsigned long long int bufferAcquisitionTime_asLong;
933 unsigned char *ptr1;
941 unsigned char *ptr1;
934 unsigned char *ptr2;
942 unsigned char *ptr2;
935 unsigned char *timeCharPtr;
943 unsigned char *timeCharPtr;
936 unsigned char nb_ring_nodes;
944 unsigned char nb_ring_nodes;
937 unsigned long long int frequency_asLong;
945 unsigned long long int frequency_asLong;
938 unsigned long long int nbTicksPerSample_asLong;
946 unsigned long long int nbTicksPerSample_asLong;
939 unsigned long long int nbSamplesPart1_asLong;
947 unsigned long long int nbSamplesPart1_asLong;
940 unsigned long long int sampleOffset_asLong;
948 unsigned long long int sampleOffset_asLong;
941
949
942 unsigned int deltaT_F0;
950 unsigned int deltaT_F0;
943 unsigned int deltaT_F1;
951 unsigned int deltaT_F1;
944 unsigned long long int deltaT_F2;
952 unsigned long long int deltaT_F2;
945
953
946 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
954 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
947 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
955 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
948 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
956 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
949 sampleOffset_asLong = 0x00;
957 sampleOffset_asLong = 0x00;
950
958
951 // (1) get the f0 acquisition time => the value is passed in argument
959 // (1) get the f0 acquisition time => the value is passed in argument
952
960
953 // (2) compute the central reference time
961 // (2) compute the central reference time
954 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
962 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
955
963
956 // (3) compute the acquisition time of the current snapshot
964 // (3) compute the acquisition time of the current snapshot
957 switch(frequencyChannel)
965 switch(frequencyChannel)
958 {
966 {
959 case 1: // 1 is for F1 = 4096 Hz
967 case 1: // 1 is for F1 = 4096 Hz
960 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
968 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
961 nb_ring_nodes = NB_RING_NODES_F1;
969 nb_ring_nodes = NB_RING_NODES_F1;
962 frequency_asLong = 4096;
970 frequency_asLong = 4096;
963 nbTicksPerSample_asLong = 16; // 65536 / 4096;
971 nbTicksPerSample_asLong = 16; // 65536 / 4096;
964 break;
972 break;
965 case 2: // 2 is for F2 = 256 Hz
973 case 2: // 2 is for F2 = 256 Hz
966 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
974 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
967 nb_ring_nodes = NB_RING_NODES_F2;
975 nb_ring_nodes = NB_RING_NODES_F2;
968 frequency_asLong = 256;
976 frequency_asLong = 256;
969 nbTicksPerSample_asLong = 256; // 65536 / 256;
977 nbTicksPerSample_asLong = 256; // 65536 / 256;
970 break;
978 break;
971 default:
979 default:
972 acquisitionTime_asLong = centerTime_asLong;
980 acquisitionTime_asLong = centerTime_asLong;
973 frequency_asLong = 256;
981 frequency_asLong = 256;
974 nbTicksPerSample_asLong = 256;
982 nbTicksPerSample_asLong = 256;
975 break;
983 break;
976 }
984 }
977
985
978 //****************************************************************************
986 //****************************************************************************
979 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
987 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
980 for (i=0; i<nb_ring_nodes; i++)
988 for (i=0; i<nb_ring_nodes; i++)
981 {
989 {
982 PRINTF1("%d ... ", i)
990 PRINTF1("%d ... ", i)
983 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
991 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
984 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
992 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
985 {
993 {
986 PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong)
994 PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong)
987 break;
995 break;
988 }
996 }
989 ring_node_to_send = ring_node_to_send->previous;
997 ring_node_to_send = ring_node_to_send->previous;
990 }
998 }
991
999
992 // (5) compute the number of samples to take in the current buffer
1000 // (5) compute the number of samples to take in the current buffer
993 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
1001 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
994 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
1002 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
995 PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong)
1003 PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong)
996
1004
997 // (6) compute the final acquisition time
1005 // (6) compute the final acquisition time
998 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
1006 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
999 sampleOffset_asLong * nbTicksPerSample_asLong;
1007 sampleOffset_asLong * nbTicksPerSample_asLong;
1000
1008
1001 // (7) copy the acquisition time at the beginning of the extrated snapshot
1009 // (7) copy the acquisition time at the beginning of the extrated snapshot
1002 ptr1 = (unsigned char*) &acquisitionTime_asLong;
1010 ptr1 = (unsigned char*) &acquisitionTime_asLong;
1003 // fine time
1011 // fine time
1004 ptr2 = (unsigned char*) &ring_node_wf_snap_extracted.fineTime;
1012 ptr2 = (unsigned char*) &ring_node_wf_snap_extracted.fineTime;
1005 ptr2[2] = ptr1[ 4 + 2 ];
1013 ptr2[2] = ptr1[ 4 + 2 ];
1006 ptr2[3] = ptr1[ 5 + 2 ];
1014 ptr2[3] = ptr1[ 5 + 2 ];
1007 // coarse time
1015 // coarse time
1008 ptr2 = (unsigned char*) &ring_node_wf_snap_extracted.coarseTime;
1016 ptr2 = (unsigned char*) &ring_node_wf_snap_extracted.coarseTime;
1009 ptr2[0] = ptr1[ 0 + 2 ];
1017 ptr2[0] = ptr1[ 0 + 2 ];
1010 ptr2[1] = ptr1[ 1 + 2 ];
1018 ptr2[1] = ptr1[ 1 + 2 ];
1011 ptr2[2] = ptr1[ 2 + 2 ];
1019 ptr2[2] = ptr1[ 2 + 2 ];
1012 ptr2[3] = ptr1[ 3 + 2 ];
1020 ptr2[3] = ptr1[ 3 + 2 ];
1013
1021
1014 // re set the synchronization bit
1022 // re set the synchronization bit
1015 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
1023 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
1016 ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000]
1024 ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000]
1017
1025
1018 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
1026 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
1019 {
1027 {
1020 nbSamplesPart1_asLong = 0;
1028 nbSamplesPart1_asLong = 0;
1021 }
1029 }
1022 // copy the part 1 of the snapshot in the extracted buffer
1030 // copy the part 1 of the snapshot in the extracted buffer
1023 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
1031 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
1024 {
1032 {
1025 wf_snap_extracted[i] =
1033 wf_snap_extracted[i] =
1026 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
1034 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
1027 }
1035 }
1028 // copy the part 2 of the snapshot in the extracted buffer
1036 // copy the part 2 of the snapshot in the extracted buffer
1029 ring_node_to_send = ring_node_to_send->next;
1037 ring_node_to_send = ring_node_to_send->next;
1030 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
1038 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
1031 {
1039 {
1032 wf_snap_extracted[i] =
1040 wf_snap_extracted[i] =
1033 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
1041 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
1034 }
1042 }
1035 }
1043 }
1036
1044
1037 void snapshot_resynchronization( unsigned char *timePtr )
1045 void snapshot_resynchronization( unsigned char *timePtr )
1038 {
1046 {
1039 unsigned long long int acquisitionTime;
1047 unsigned long long int acquisitionTime;
1040 unsigned long long int centerTime;
1048 unsigned long long int centerTime;
1041 unsigned long long int previousTick;
1049 unsigned long long int previousTick;
1042 unsigned long long int nextTick;
1050 unsigned long long int nextTick;
1043 unsigned long long int deltaPreviousTick;
1051 unsigned long long int deltaPreviousTick;
1044 unsigned long long int deltaNextTick;
1052 unsigned long long int deltaNextTick;
1045 unsigned int deltaTickInF2;
1053 unsigned int deltaTickInF2;
1046 double deltaPrevious;
1054 double deltaPrevious;
1047 double deltaNext;
1055 double deltaNext;
1048
1056
1049 acquisitionTime = get_acquisition_time( timePtr );
1057 acquisitionTime = get_acquisition_time( timePtr );
1050
1058
1051 // compute center time
1059 // compute center time
1052 centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
1060 centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
1053 previousTick = centerTime - (centerTime & 0xffff);
1061 previousTick = centerTime - (centerTime & 0xffff);
1054 nextTick = previousTick + 65536;
1062 nextTick = previousTick + 65536;
1055
1063
1056 deltaPreviousTick = centerTime - previousTick;
1064 deltaPreviousTick = centerTime - previousTick;
1057 deltaNextTick = nextTick - centerTime;
1065 deltaNextTick = nextTick - centerTime;
1058
1066
1059 deltaPrevious = ((double) deltaPreviousTick) / 65536. * 1000.;
1067 deltaPrevious = ((double) deltaPreviousTick) / 65536. * 1000.;
1060 deltaNext = ((double) deltaNextTick) / 65536. * 1000.;
1068 deltaNext = ((double) deltaNextTick) / 65536. * 1000.;
1061
1069
1062 PRINTF2("delta previous = %f ms, delta next = %f ms\n", deltaPrevious, deltaNext)
1070 PRINTF2("delta previous = %f ms, delta next = %f ms\n", deltaPrevious, deltaNext)
1063 PRINTF2("delta previous = %llu, delta next = %llu\n", deltaPreviousTick, deltaNextTick)
1071 PRINTF2("delta previous = %llu, delta next = %llu\n", deltaPreviousTick, deltaNextTick)
1064
1072
1065 // which tick is the closest
1073 // which tick is the closest
1066 if (deltaPreviousTick > deltaNextTick)
1074 if (deltaPreviousTick > deltaNextTick)
1067 {
1075 {
1068 deltaTickInF2 = floor( (deltaNext * 256. / 1000.) ); // the division by 2 is important here
1076 deltaTickInF2 = floor( (deltaNext * 256. / 1000.) ); // the division by 2 is important here
1069 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + deltaTickInF2;
1077 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + deltaTickInF2;
1070 PRINTF1("correction of = + %u\n", deltaTickInF2)
1078 PRINTF1("correction of = + %u\n", deltaTickInF2)
1071 }
1079 }
1072 else
1080 else
1073 {
1081 {
1074 deltaTickInF2 = floor( (deltaPrevious * 256. / 1000.) ); // the division by 2 is important here
1082 deltaTickInF2 = floor( (deltaPrevious * 256. / 1000.) ); // the division by 2 is important here
1075 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot - deltaTickInF2;
1083 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot - deltaTickInF2;
1076 PRINTF1("correction of = - %u\n", deltaTickInF2)
1084 PRINTF1("correction of = - %u\n", deltaTickInF2)
1077 }
1085 }
1078 }
1086 }
1079
1087
1080 //**************
1088 //**************
1081 // wfp registers
1089 // wfp registers
1082 void reset_wfp_burst_enable( void )
1090 void reset_wfp_burst_enable( void )
1083 {
1091 {
1084 /** This function resets the waveform picker burst_enable register.
1092 /** This function resets the waveform picker burst_enable register.
1085 *
1093 *
1086 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1094 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1087 *
1095 *
1088 */
1096 */
1089
1097
1090 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1098 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1091 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & 0x80;
1099 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & 0x80;
1092 }
1100 }
1093
1101
1094 void reset_wfp_status( void )
1102 void reset_wfp_status( void )
1095 {
1103 {
1096 /** This function resets the waveform picker status register.
1104 /** This function resets the waveform picker status register.
1097 *
1105 *
1098 * All status bits are set to 0 [new_err full_err full].
1106 * All status bits are set to 0 [new_err full_err full].
1099 *
1107 *
1100 */
1108 */
1101
1109
1102 waveform_picker_regs->status = 0xffff;
1110 waveform_picker_regs->status = 0xffff;
1103 }
1111 }
1104
1112
1105 void reset_wfp_buffer_addresses( void )
1113 void reset_wfp_buffer_addresses( void )
1106 {
1114 {
1107 // F0
1115 // F0
1108 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1116 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1109 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1117 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1110 // F1
1118 // F1
1111 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1119 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1112 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1120 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1113 // F2
1121 // F2
1114 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1122 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1115 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1123 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1116 // F3
1124 // F3
1117 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1125 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1118 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1126 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1119 }
1127 }
1120
1128
1121 void reset_waveform_picker_regs( void )
1129 void reset_waveform_picker_regs( void )
1122 {
1130 {
1123 /** This function resets the waveform picker module registers.
1131 /** This function resets the waveform picker module registers.
1124 *
1132 *
1125 * The registers affected by this function are located at the following offset addresses:
1133 * The registers affected by this function are located at the following offset addresses:
1126 * - 0x00 data_shaping
1134 * - 0x00 data_shaping
1127 * - 0x04 run_burst_enable
1135 * - 0x04 run_burst_enable
1128 * - 0x08 addr_data_f0
1136 * - 0x08 addr_data_f0
1129 * - 0x0C addr_data_f1
1137 * - 0x0C addr_data_f1
1130 * - 0x10 addr_data_f2
1138 * - 0x10 addr_data_f2
1131 * - 0x14 addr_data_f3
1139 * - 0x14 addr_data_f3
1132 * - 0x18 status
1140 * - 0x18 status
1133 * - 0x1C delta_snapshot
1141 * - 0x1C delta_snapshot
1134 * - 0x20 delta_f0
1142 * - 0x20 delta_f0
1135 * - 0x24 delta_f0_2
1143 * - 0x24 delta_f0_2
1136 * - 0x28 delta_f1
1144 * - 0x28 delta_f1
1137 * - 0x2c delta_f2
1145 * - 0x2c delta_f2
1138 * - 0x30 nb_data_by_buffer
1146 * - 0x30 nb_data_by_buffer
1139 * - 0x34 nb_snapshot_param
1147 * - 0x34 nb_snapshot_param
1140 * - 0x38 start_date
1148 * - 0x38 start_date
1141 * - 0x3c nb_word_in_buffer
1149 * - 0x3c nb_word_in_buffer
1142 *
1150 *
1143 */
1151 */
1144
1152
1145 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1153 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1146
1154
1147 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1155 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1148
1156
1149 reset_wfp_buffer_addresses();
1157 reset_wfp_buffer_addresses();
1150
1158
1151 reset_wfp_status(); // 0x18
1159 reset_wfp_status(); // 0x18
1152
1160
1153 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1161 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1154
1162
1155 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1163 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1156
1164
1157 set_wfp_delta_f1(); // 0x28
1165 set_wfp_delta_f1(); // 0x28
1158
1166
1159 set_wfp_delta_f2(); // 0x2c
1167 set_wfp_delta_f2(); // 0x2c
1160
1168
1161 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1169 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot)
1162 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1170 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0)
1163 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1171 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2)
1164 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1172 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1)
1165 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1173 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2)
1166 // 2688 = 8 * 336
1174 // 2688 = 8 * 336
1167 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1175 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1168 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1176 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1169 waveform_picker_regs->start_date = 0x7fffffff; // 0x38
1177 waveform_picker_regs->start_date = 0x7fffffff; // 0x38
1170 //
1178 //
1171 // coarse time and fine time registers are not initialized, they are volatile
1179 // coarse time and fine time registers are not initialized, they are volatile
1172 //
1180 //
1173 waveform_picker_regs->buffer_length = 0x1f8;// buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1181 waveform_picker_regs->buffer_length = 0x1f8;// buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1174 }
1182 }
1175
1183
1176 void set_wfp_data_shaping( void )
1184 void set_wfp_data_shaping( void )
1177 {
1185 {
1178 /** This function sets the data_shaping register of the waveform picker module.
1186 /** This function sets the data_shaping register of the waveform picker module.
1179 *
1187 *
1180 * The value is read from one field of the parameter_dump_packet structure:\n
1188 * The value is read from one field of the parameter_dump_packet structure:\n
1181 * bw_sp0_sp1_r0_r1
1189 * bw_sp0_sp1_r0_r1
1182 *
1190 *
1183 */
1191 */
1184
1192
1185 unsigned char data_shaping;
1193 unsigned char data_shaping;
1186
1194
1187 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1195 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1188 // waveform picker : [R1 R0 SP1 SP0 BW]
1196 // waveform picker : [R1 R0 SP1 SP0 BW]
1189
1197
1190 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1198 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1191
1199
1192 waveform_picker_regs->data_shaping =
1200 waveform_picker_regs->data_shaping =
1193 ( (data_shaping & 0x20) >> 5 ) // BW
1201 ( (data_shaping & 0x20) >> 5 ) // BW
1194 + ( (data_shaping & 0x10) >> 3 ) // SP0
1202 + ( (data_shaping & 0x10) >> 3 ) // SP0
1195 + ( (data_shaping & 0x08) >> 1 ) // SP1
1203 + ( (data_shaping & 0x08) >> 1 ) // SP1
1196 + ( (data_shaping & 0x04) << 1 ) // R0
1204 + ( (data_shaping & 0x04) << 1 ) // R0
1197 + ( (data_shaping & 0x02) << 3 ) // R1
1205 + ( (data_shaping & 0x02) << 3 ) // R1
1198 + ( (data_shaping & 0x01) << 5 ); // R2
1206 + ( (data_shaping & 0x01) << 5 ); // R2
1199 }
1207 }
1200
1208
1201 void set_wfp_burst_enable_register( unsigned char mode )
1209 void set_wfp_burst_enable_register( unsigned char mode )
1202 {
1210 {
1203 /** This function sets the waveform picker burst_enable register depending on the mode.
1211 /** This function sets the waveform picker burst_enable register depending on the mode.
1204 *
1212 *
1205 * @param mode is the LFR mode to launch.
1213 * @param mode is the LFR mode to launch.
1206 *
1214 *
1207 * The burst bits shall be before the enable bits.
1215 * The burst bits shall be before the enable bits.
1208 *
1216 *
1209 */
1217 */
1210
1218
1211 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1219 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1212 // the burst bits shall be set first, before the enable bits
1220 // the burst bits shall be set first, before the enable bits
1213 switch(mode) {
1221 switch(mode) {
1214 case(LFR_MODE_NORMAL):
1222 case(LFR_MODE_NORMAL):
1215 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1223 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable
1216 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1224 waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1217 break;
1225 break;
1218 case(LFR_MODE_BURST):
1226 case(LFR_MODE_BURST):
1219 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1227 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1220 // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1228 // waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2
1221 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2
1229 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2
1222 break;
1230 break;
1223 case(LFR_MODE_SBM1):
1231 case(LFR_MODE_SBM1):
1224 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1232 waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled
1225 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1233 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1226 break;
1234 break;
1227 case(LFR_MODE_SBM2):
1235 case(LFR_MODE_SBM2):
1228 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1236 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1229 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1237 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1230 break;
1238 break;
1231 default:
1239 default:
1232 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1240 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1233 break;
1241 break;
1234 }
1242 }
1235 }
1243 }
1236
1244
1237 void set_wfp_delta_snapshot( void )
1245 void set_wfp_delta_snapshot( void )
1238 {
1246 {
1239 /** This function sets the delta_snapshot register of the waveform picker module.
1247 /** This function sets the delta_snapshot register of the waveform picker module.
1240 *
1248 *
1241 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1249 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1242 * - sy_lfr_n_swf_p[0]
1250 * - sy_lfr_n_swf_p[0]
1243 * - sy_lfr_n_swf_p[1]
1251 * - sy_lfr_n_swf_p[1]
1244 *
1252 *
1245 */
1253 */
1246
1254
1247 unsigned int delta_snapshot;
1255 unsigned int delta_snapshot;
1248 unsigned int delta_snapshot_in_T2;
1256 unsigned int delta_snapshot_in_T2;
1249
1257
1250 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1258 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1251 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1259 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1252
1260
1253 delta_snapshot_in_T2 = delta_snapshot * 256;
1261 delta_snapshot_in_T2 = delta_snapshot * 256;
1254 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1262 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1255 }
1263 }
1256
1264
1257 void set_wfp_delta_f0_f0_2( void )
1265 void set_wfp_delta_f0_f0_2( void )
1258 {
1266 {
1259 unsigned int delta_snapshot;
1267 unsigned int delta_snapshot;
1260 unsigned int nb_samples_per_snapshot;
1268 unsigned int nb_samples_per_snapshot;
1261 float delta_f0_in_float;
1269 float delta_f0_in_float;
1262
1270
1263 delta_snapshot = waveform_picker_regs->delta_snapshot;
1271 delta_snapshot = waveform_picker_regs->delta_snapshot;
1264 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1272 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1265 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1273 delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1266
1274
1267 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1275 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1268 waveform_picker_regs->delta_f0_2 = 0x30; // 48 = 11 0000, max 7 bits
1276 waveform_picker_regs->delta_f0_2 = 0x30; // 48 = 11 0000, max 7 bits
1269 }
1277 }
1270
1278
1271 void set_wfp_delta_f1( void )
1279 void set_wfp_delta_f1( void )
1272 {
1280 {
1273 unsigned int delta_snapshot;
1281 unsigned int delta_snapshot;
1274 unsigned int nb_samples_per_snapshot;
1282 unsigned int nb_samples_per_snapshot;
1275 float delta_f1_in_float;
1283 float delta_f1_in_float;
1276
1284
1277 delta_snapshot = waveform_picker_regs->delta_snapshot;
1285 delta_snapshot = waveform_picker_regs->delta_snapshot;
1278 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1286 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1279 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1287 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1280
1288
1281 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1289 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1282 }
1290 }
1283
1291
1284 void set_wfp_delta_f2()
1292 void set_wfp_delta_f2()
1285 {
1293 {
1286 unsigned int delta_snapshot;
1294 unsigned int delta_snapshot;
1287 unsigned int nb_samples_per_snapshot;
1295 unsigned int nb_samples_per_snapshot;
1288
1296
1289 delta_snapshot = waveform_picker_regs->delta_snapshot;
1297 delta_snapshot = waveform_picker_regs->delta_snapshot;
1290 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1298 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1291
1299
1292 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1300 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2;
1293 }
1301 }
1294
1302
1295 //*****************
1303 //*****************
1296 // local parameters
1304 // local parameters
1297
1305
1298 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1306 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1299 {
1307 {
1300 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1308 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1301 *
1309 *
1302 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1310 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1303 * @param sid is the source identifier of the packet being updated.
1311 * @param sid is the source identifier of the packet being updated.
1304 *
1312 *
1305 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1313 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1306 * The sequence counters shall wrap around from 2^14 to zero.
1314 * The sequence counters shall wrap around from 2^14 to zero.
1307 * The sequence counter shall start at zero at startup.
1315 * The sequence counter shall start at zero at startup.
1308 *
1316 *
1309 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1317 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1310 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1318 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1311 *
1319 *
1312 */
1320 */
1313
1321
1314 unsigned short *sequence_cnt;
1322 unsigned short *sequence_cnt;
1315 unsigned short segmentation_grouping_flag;
1323 unsigned short segmentation_grouping_flag;
1316 unsigned short new_packet_sequence_control;
1324 unsigned short new_packet_sequence_control;
1317 rtems_mode initial_mode_set;
1325 rtems_mode initial_mode_set;
1318 rtems_mode current_mode_set;
1326 rtems_mode current_mode_set;
1319 rtems_status_code status;
1327 rtems_status_code status;
1320
1328
1321 //******************************************
1329 //******************************************
1322 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1330 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1323 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1331 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1324
1332
1325 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1333 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1326 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1334 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1327 || (sid == SID_BURST_CWF_F2)
1335 || (sid == SID_BURST_CWF_F2)
1328 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1336 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1329 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1337 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1330 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1338 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1331 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1339 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1332 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1340 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1333 {
1341 {
1334 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1342 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1335 }
1343 }
1336 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1344 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1337 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1345 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1338 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1346 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1339 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1347 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1340 {
1348 {
1341 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1349 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1342 }
1350 }
1343 else
1351 else
1344 {
1352 {
1345 sequence_cnt = (unsigned short *) NULL;
1353 sequence_cnt = (unsigned short *) NULL;
1346 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1354 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1347 }
1355 }
1348
1356
1349 if (sequence_cnt != NULL)
1357 if (sequence_cnt != NULL)
1350 {
1358 {
1351 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1359 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1352 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1360 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1353
1361
1354 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1362 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1355
1363
1356 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1364 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1357 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1365 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1358
1366
1359 // increment the sequence counter
1367 // increment the sequence counter
1360 if ( *sequence_cnt < SEQ_CNT_MAX)
1368 if ( *sequence_cnt < SEQ_CNT_MAX)
1361 {
1369 {
1362 *sequence_cnt = *sequence_cnt + 1;
1370 *sequence_cnt = *sequence_cnt + 1;
1363 }
1371 }
1364 else
1372 else
1365 {
1373 {
1366 *sequence_cnt = 0;
1374 *sequence_cnt = 0;
1367 }
1375 }
1368 }
1376 }
1369
1377
1370 //*************************************
1378 //*************************************
1371 // RESTORE THE MODE OF THE CALLING TASK
1379 // RESTORE THE MODE OF THE CALLING TASK
1372 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1380 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1373 }
1381 }
General Comments 0
You need to be logged in to leave comments. Login now