##// END OF EJS Templates
fsw-0-20
paul -
r58:95058e78e811 default
parent child
Show More
@@ -1,211 +1,211
1 1 #ifndef FSW_PARAMS_H_INCLUDED
2 2 #define FSW_PARAMS_H_INCLUDED
3 3
4 4 #include "grlib_regs.h"
5 5 #include "fsw_params_processing.h"
6 6 #include "tm_byte_positions.h"
7 7 #include "ccsds_types.h"
8 8
9 9 #define GRSPW_DEVICE_NAME "/dev/grspw0"
10 10 #define UART_DEVICE_NAME "/dev/console"
11 11
12 12 //************************
13 13 // flight software version
14 14 // this parameters is handled by the Qt project options
15 15
16 16 //**********
17 17 // LFR MODES
18 18 #define LFR_MODE_STANDBY 0
19 19 #define LFR_MODE_NORMAL 1
20 20 #define LFR_MODE_BURST 2
21 21 #define LFR_MODE_SBM1 3
22 22 #define LFR_MODE_SBM2 4
23 23 #define LFR_MODE_NORMAL_CWF_F3 5
24 24
25 25 #define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0
26 26 #define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1
27 27 #define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2
28 28 #define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3
29 29 #define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4
30 30 #define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5
31 31
32 32 //****************************
33 33 // LFR DEFAULT MODE PARAMETERS
34 34 // COMMON
35 35 #define DEFAULT_SY_LFR_COMMON0 0x00
36 36 #define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0
37 37 // NORM
38 38 #define SY_LFR_N_SWF_L 2048 // nb sample
39 #define SY_LFR_N_SWF_P 300 // sec
39 #define SY_LFR_N_SWF_P 296 // sec
40 40 #define SY_LFR_N_ASM_P 3600 // sec
41 41 #define SY_LFR_N_BP_P0 4 // sec
42 42 #define SY_LFR_N_BP_P1 20 // sec
43 43 #define MIN_DELTA_SNAPSHOT 16 // sec
44 44 // BURST
45 45 #define DEFAULT_SY_LFR_B_BP_P0 1 // sec
46 46 #define DEFAULT_SY_LFR_B_BP_P1 5 // sec
47 47 // SBM1
48 48 #define DEFAULT_SY_LFR_S1_BP_P0 1 // sec
49 49 #define DEFAULT_SY_LFR_S1_BP_P1 1 // sec
50 50 // SBM2
51 51 #define DEFAULT_SY_LFR_S2_BP_P0 1 // sec
52 52 #define DEFAULT_SY_LFR_S2_BP_P1 5 // sec
53 53 // ADDITIONAL PARAMETERS
54 54 #define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms
55 55 #define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s
56 56 // STATUS WORD
57 57 #define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits
58 58 #define DEFAULT_STATUS_WORD_BYTE1 0x00
59 59 //
60 60 #define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s
61 61 #define SY_LFR_DPU_CONNECT_ATTEMPT 3
62 62 //****************************
63 63
64 64 //*****************************
65 65 // APB REGISTERS BASE ADDRESSES
66 66 #define REGS_ADDR_APBUART 0x80000100
67 67 #define REGS_ADDR_GPTIMER 0x80000300
68 68 #define REGS_ADDR_GRSPW 0x80000500
69 69 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
70 70 #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00
71 71
72 72 #ifdef GSA
73 73 #else
74 74 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f20
75 75 #endif
76 76
77 77 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
78 78 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50)
79 79
80 80 //**********
81 81 // IRQ LINES
82 82 #define IRQ_SM 9
83 83 #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels
84 84 #define IRQ_WF 10
85 85 #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels
86 86 #define IRQ_TIME1 12
87 87 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
88 88 #define IRQ_TIME2 13
89 89 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
90 90 #define IRQ_WAVEFORM_PICKER 14
91 91 #define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels
92 92 #define IRQ_SPECTRAL_MATRIX 6
93 93 #define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels
94 94
95 95 //*****
96 96 // TIME
97 97 #define CLKDIV_SM_SIMULATOR (10000 - 1) // 10 ms
98 98 #define CLKDIV_WF_SIMULATOR (10000000 - 1) // 10 000 000 * 1 us = 10 s
99 99 #define TIMER_SM_SIMULATOR 1
100 100 #define TIMER_WF_SIMULATOR 2
101 101 #define HK_PERIOD 100 // 100 * 10ms => 1sec
102 102
103 103 //**********
104 104 // LPP CODES
105 105 #define LFR_SUCCESSFUL 0
106 106 #define LFR_DEFAULT 1
107 107
108 108 //******
109 109 // RTEMS
110 110 #define TASKID_RECV 1
111 111 #define TASKID_ACTN 2
112 112 #define TASKID_SPIQ 3
113 113 #define TASKID_SMIQ 4
114 114 #define TASKID_STAT 5
115 115 #define TASKID_AVF0 6
116 116 #define TASKID_BPF0 7
117 117 #define TASKID_WFRM 8
118 118 #define TASKID_DUMB 9
119 119 #define TASKID_HOUS 10
120 120 #define TASKID_MATR 11
121 121 #define TASKID_CWF3 12
122 122 #define TASKID_CWF2 13
123 123 #define TASKID_CWF1 14
124 124 #define TASKID_SEND 15
125 125 #define TASKID_WTDG 16
126 126
127 127 #define TASK_PRIORITY_SPIQ 5
128 128 #define TASK_PRIORITY_SMIQ 10
129 129 //
130 130 #define TASK_PRIORITY_WTDG 20
131 131 //
132 132 #define TASK_PRIORITY_HOUS 30
133 133 //
134 134 #define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together
135 135 #define TASK_PRIORITY_CWF2 35 //
136 136 //
137 137 #define TASK_PRIORITY_WFRM 40
138 138 #define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1
139 139 //
140 140 #define TASK_PRIORITY_SEND 45
141 141 //
142 142 #define TASK_PRIORITY_RECV 50
143 143 #define TASK_PRIORITY_ACTN 50
144 144 //
145 145 #define TASK_PRIORITY_AVF0 60
146 146 #define TASK_PRIORITY_BPF0 60
147 147 #define TASK_PRIORITY_MATR 100
148 148 #define TASK_PRIORITY_STAT 200
149 149 #define TASK_PRIORITY_DUMB 200
150 150
151 151 #define SEMQ_PRIORITY_CEILING 30
152 152
153 153 #define ACTION_MSG_QUEUE_COUNT 10
154 154 #define ACTION_MSG_PKTS_COUNT 50
155 155 #define ACTION_MSG_PKTS_MAX_SIZE (PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES)
156 156 #define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options
157 157
158 158 #define QUEUE_RECV 0
159 159 #define QUEUE_SEND 1
160 160
161 161 //*******
162 162 // MACROS
163 163 #ifdef PRINT_MESSAGES_ON_CONSOLE
164 164 #define PRINTF(x) printf(x);
165 165 #define PRINTF1(x,y) printf(x,y);
166 166 #define PRINTF2(x,y,z) printf(x,y,z);
167 167 #else
168 168 #define PRINTF(x) ;
169 169 #define PRINTF1(x,y) ;
170 170 #define PRINTF2(x,y,z) ;
171 171 #endif
172 172
173 173 #ifdef BOOT_MESSAGES
174 174 #define BOOT_PRINTF(x) printf(x);
175 175 #define BOOT_PRINTF1(x,y) printf(x,y);
176 176 #define BOOT_PRINTF2(x,y,z) printf(x,y,z);
177 177 #else
178 178 #define BOOT_PRINTF(x) ;
179 179 #define BOOT_PRINTF1(x,y) ;
180 180 #define BOOT_PRINTF2(x,y,z) ;
181 181 #endif
182 182
183 183 #ifdef DEBUG_MESSAGES
184 184 #define DEBUG_PRINTF(x) printf(x);
185 185 #define DEBUG_PRINTF1(x,y) printf(x,y);
186 186 #define DEBUG_PRINTF2(x,y,z) printf(x,y,z);
187 187 #else
188 188 #define DEBUG_PRINTF(x) ;
189 189 #define DEBUG_PRINTF1(x,y) ;
190 190 #define DEBUG_PRINTF2(x,y,z) ;
191 191 #endif
192 192
193 193 #define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period
194 194
195 195 #define NB_SAMPLES_PER_SNAPSHOT 2048
196 196 #define TIME_OFFSET 2
197 197 #define WAVEFORM_EXTENDED_HEADER_OFFSET 22
198 198 #define NB_BYTES_SWF_BLK (2 * 6)
199 199 #define NB_WORDS_SWF_BLK 3
200 200 #define NB_BYTES_CWF3_LIGHT_BLK 6
201 201 #define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8
202 202
203 203 struct param_local_str{
204 204 unsigned int local_sbm1_nb_cwf_sent;
205 205 unsigned int local_sbm1_nb_cwf_max;
206 206 unsigned int local_sbm2_nb_cwf_sent;
207 207 unsigned int local_sbm2_nb_cwf_max;
208 208 unsigned int local_nb_interrupt_f0_MAX;
209 209 };
210 210
211 211 #endif // FSW_PARAMS_H_INCLUDED
@@ -1,586 +1,586
1 1 /** This is the RTEMS initialization module.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * This module contains two very different information:
7 7 * - specific instructions to configure the compilation of the RTEMS executive
8 8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 9 *
10 10 */
11 11
12 12 //*************************
13 13 // GPL reminder to be added
14 14 //*************************
15 15
16 16 #include <rtems.h>
17 17
18 18 /* configuration information */
19 19
20 20 #define CONFIGURE_INIT
21 21
22 22 #include <bsp.h> /* for device driver prototypes */
23 23
24 24 /* configuration information */
25 25
26 26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28 28
29 29 #define CONFIGURE_MAXIMUM_TASKS 20
30 30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 35 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 36 #define CONFIGURE_MAXIMUM_PERIODS 5
37 37 #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
38 38 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 2
39 39 #ifdef PRINT_STACK_REPORT
40 40 #define CONFIGURE_STACK_CHECKER_ENABLED
41 41 #endif
42 42
43 43 #include <rtems/confdefs.h>
44 44
45 45 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 46 #ifdef RTEMS_DRVMGR_STARTUP
47 47 #ifdef LEON3
48 48 /* Add Timer and UART Driver */
49 49 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
50 50 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
51 51 #endif
52 52 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
53 53 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
54 54 #endif
55 55 #endif
56 56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
57 57 #include <drvmgr/drvmgr_confdefs.h>
58 58 #endif
59 59
60 60 #include "fsw_init.h"
61 61 #include "fsw_config.c"
62 62
63 63 rtems_task Init( rtems_task_argument ignored )
64 64 {
65 65 /** This is the RTEMS INIT taks, it the first task launched by the system.
66 66 *
67 67 * @param unused is the starting argument of the RTEMS task
68 68 *
69 69 * The INIT task create and run all other RTEMS tasks.
70 70 *
71 71 */
72 72
73 73
74 74 rtems_status_code status;
75 75 rtems_status_code status_spw;
76 76 rtems_isr_entry old_isr_handler;
77 77
78 78 BOOT_PRINTF("\n\n\n\n\n")
79 79 BOOT_PRINTF("***************************\n")
80 80 BOOT_PRINTF("** START Flight Software **\n")
81 81 BOOT_PRINTF("***************************\n")
82 82 BOOT_PRINTF("\n\n")
83 83
84 84 //send_console_outputs_on_apbuart_port();
85 85 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
86 86
87 87 reset_wfp_burst_enable(); // stop the waveform picker if it was running
88 88
89 89 init_parameter_dump();
90 90 init_local_mode_parameters();
91 91 init_housekeeping_parameters();
92 92
93 93 updateLFRCurrentMode();
94 94
95 95 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
96 96
97 97 create_names(); // create all names
98 98
99 99 status = create_message_queues(); // create message queues
100 100 if (status != RTEMS_SUCCESSFUL)
101 101 {
102 102 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
103 103 }
104 104
105 105 status = create_all_tasks(); // create all tasks
106 106 if (status != RTEMS_SUCCESSFUL)
107 107 {
108 108 PRINTF1("in INIT *** ERR in create_all_tasks, code %d", status)
109 109 }
110 110
111 111 // **************************
112 112 // <SPACEWIRE INITIALIZATION>
113 113 grspw_timecode_callback = &timecode_irq_handler;
114 114
115 115 status_spw = spacewire_open_link(); // (1) open the link
116 116 if ( status_spw != RTEMS_SUCCESSFUL )
117 117 {
118 118 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
119 119 }
120 120
121 121 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
122 122 {
123 123 status_spw = spacewire_configure_link( fdSPW );
124 124 if ( status_spw != RTEMS_SUCCESSFUL )
125 125 {
126 126 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
127 127 }
128 128 }
129 129
130 130 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
131 131 {
132 132 status_spw = spacewire_start_link( fdSPW );
133 133 if ( status_spw != RTEMS_SUCCESSFUL )
134 134 {
135 135 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
136 136 }
137 137 }
138 138 // </SPACEWIRE INITIALIZATION>
139 139 // ***************************
140 140
141 141 status = start_all_tasks(); // start all tasks
142 142 if (status != RTEMS_SUCCESSFUL)
143 143 {
144 144 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
145 145 }
146 146
147 147 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
148 148 status = start_recv_send_tasks();
149 149 if ( status != RTEMS_SUCCESSFUL )
150 150 {
151 151 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
152 152 }
153 153
154 154 // suspend science tasks. they will be restarted later depending on the mode
155 155 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
156 156 if (status != RTEMS_SUCCESSFUL)
157 157 {
158 158 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
159 159 }
160 160
161 161 #ifdef GSA
162 162 // mask IRQ lines
163 163 LEON_Mask_interrupt( IRQ_SM );
164 164 LEON_Mask_interrupt( IRQ_WF );
165 165 // Spectral Matrices simulator
166 166 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
167 167 IRQ_SPARC_SM, spectral_matrices_isr );
168 168 // WaveForms
169 169 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
170 170 IRQ_SPARC_WF, waveforms_simulator_isr );
171 171 #else
172 172 // configure IRQ handling for the waveform picker unit
173 173 status = rtems_interrupt_catch( waveforms_isr,
174 174 IRQ_SPARC_WAVEFORM_PICKER,
175 175 &old_isr_handler) ;
176 176 #endif
177 177
178 178 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
179 179 if ( status_spw != RTEMS_SUCCESSFUL )
180 180 {
181 181 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
182 182 if ( status != RTEMS_SUCCESSFUL ) {
183 183 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
184 184 }
185 185 }
186 186
187 187 BOOT_PRINTF("delete INIT\n")
188 188
189 189 status = rtems_task_delete(RTEMS_SELF);
190 190
191 191 }
192 192
193 193 void init_local_mode_parameters( void )
194 194 {
195 195 /** This function initialize the param_local global variable with default values.
196 196 *
197 197 */
198 198
199 199 unsigned int i;
200 200
201 201 // LOCAL PARAMETERS
202 202 set_local_sbm1_nb_cwf_max();
203 203 set_local_sbm2_nb_cwf_max();
204 204 set_local_nb_interrupt_f0_MAX();
205 205
206 206 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
207 207 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
208 208 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
209 209
210 210 reset_local_sbm1_nb_cwf_sent();
211 211 reset_local_sbm2_nb_cwf_sent();
212 212
213 213 // init sequence counters
214 214
215 215 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
216 216 {
217 217 sequenceCounters_TC_EXE[i] = 0x00;
218 218 }
219 219 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
220 220 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
221 221 }
222 222
223 223 void create_names( void ) // create all names for tasks and queues
224 224 {
225 225 /** This function creates all RTEMS names used in the software for tasks and queues.
226 226 *
227 227 * @return RTEMS directive status codes:
228 228 * - RTEMS_SUCCESSFUL - successful completion
229 229 *
230 230 */
231 231
232 232 // task names
233 233 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
234 234 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
235 235 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
236 236 Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' );
237 237 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
238 238 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
239 239 Task_name[TASKID_BPF0] = rtems_build_name( 'B', 'P', 'F', '0' );
240 240 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
241 241 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
242 242 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
243 243 Task_name[TASKID_MATR] = rtems_build_name( 'M', 'A', 'T', 'R' );
244 244 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
245 245 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
246 246 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
247 247 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
248 248 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
249 249
250 250 // rate monotonic period names
251 251 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
252 252
253 253 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
254 254 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
255 255 }
256 256
257 257 int create_all_tasks( void ) // create all tasks which run in the software
258 258 {
259 259 /** This function creates all RTEMS tasks used in the software.
260 260 *
261 261 * @return RTEMS directive status codes:
262 262 * - RTEMS_SUCCESSFUL - task created successfully
263 263 * - RTEMS_INVALID_ADDRESS - id is NULL
264 264 * - RTEMS_INVALID_NAME - invalid task name
265 265 * - RTEMS_INVALID_PRIORITY - invalid task priority
266 266 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
267 267 * - RTEMS_TOO_MANY - too many tasks created
268 268 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
269 269 * - RTEMS_TOO_MANY - too many global objects
270 270 *
271 271 */
272 272
273 273 rtems_status_code status;
274 274
275 275 // RECV
276 276 status = rtems_task_create(
277 277 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
278 278 RTEMS_DEFAULT_MODES,
279 279 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
280 280 );
281 281
282 282 if (status == RTEMS_SUCCESSFUL) // ACTN
283 283 {
284 284 status = rtems_task_create(
285 285 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
286 286 RTEMS_DEFAULT_MODES,
287 287 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
288 288 );
289 289 }
290 290 if (status == RTEMS_SUCCESSFUL) // SPIQ
291 291 {
292 292 status = rtems_task_create(
293 293 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
294 294 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
295 295 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
296 296 );
297 297 }
298 298 if (status == RTEMS_SUCCESSFUL) // SMIQ
299 299 {
300 300 status = rtems_task_create(
301 301 Task_name[TASKID_SMIQ], TASK_PRIORITY_SMIQ, RTEMS_MINIMUM_STACK_SIZE,
302 302 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
303 303 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SMIQ]
304 304 );
305 305 }
306 306 if (status == RTEMS_SUCCESSFUL) // STAT
307 307 {
308 308 status = rtems_task_create(
309 309 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
310 310 RTEMS_DEFAULT_MODES,
311 311 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
312 312 );
313 313 }
314 314 if (status == RTEMS_SUCCESSFUL) // AVF0
315 315 {
316 316 status = rtems_task_create(
317 317 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
318 318 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
319 319 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
320 320 );
321 321 }
322 322 if (status == RTEMS_SUCCESSFUL) // BPF0
323 323 {
324 324 status = rtems_task_create(
325 325 Task_name[TASKID_BPF0], TASK_PRIORITY_BPF0, RTEMS_MINIMUM_STACK_SIZE,
326 326 RTEMS_DEFAULT_MODES,
327 327 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_BPF0]
328 328 );
329 329 }
330 330 if (status == RTEMS_SUCCESSFUL) // WFRM
331 331 {
332 332 status = rtems_task_create(
333 333 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
334 334 RTEMS_DEFAULT_MODES,
335 335 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
336 336 );
337 337 }
338 338 if (status == RTEMS_SUCCESSFUL) // DUMB
339 339 {
340 340 status = rtems_task_create(
341 341 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
342 342 RTEMS_DEFAULT_MODES,
343 343 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
344 344 );
345 345 }
346 346 if (status == RTEMS_SUCCESSFUL) // HOUS
347 347 {
348 348 status = rtems_task_create(
349 349 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
350 350 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
351 351 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_HOUS]
352 352 );
353 353 }
354 354 if (status == RTEMS_SUCCESSFUL) // MATR
355 355 {
356 356 status = rtems_task_create(
357 357 Task_name[TASKID_MATR], TASK_PRIORITY_MATR, RTEMS_MINIMUM_STACK_SIZE,
358 358 RTEMS_DEFAULT_MODES,
359 359 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_MATR]
360 360 );
361 361 }
362 362 if (status == RTEMS_SUCCESSFUL) // CWF3
363 363 {
364 364 status = rtems_task_create(
365 365 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
366 366 RTEMS_DEFAULT_MODES,
367 367 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_CWF3]
368 368 );
369 369 }
370 370 if (status == RTEMS_SUCCESSFUL) // CWF2
371 371 {
372 372 status = rtems_task_create(
373 373 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
374 374 RTEMS_DEFAULT_MODES,
375 375 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_CWF2]
376 376 );
377 377 }
378 378 if (status == RTEMS_SUCCESSFUL) // CWF1
379 379 {
380 380 status = rtems_task_create(
381 381 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
382 382 RTEMS_DEFAULT_MODES,
383 383 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_CWF1]
384 384 );
385 385 }
386 386 if (status == RTEMS_SUCCESSFUL) // SEND
387 387 {
388 388 status = rtems_task_create(
389 389 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE,
390 RTEMS_DEFAULT_MODES,
390 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
391 391 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND]
392 392 );
393 393 }
394 394 if (status == RTEMS_SUCCESSFUL) // WTDG
395 395 {
396 396 status = rtems_task_create(
397 397 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
398 398 RTEMS_DEFAULT_MODES,
399 399 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
400 400 );
401 401 }
402 402
403 403 return status;
404 404 }
405 405
406 406 int start_recv_send_tasks( void )
407 407 {
408 408 rtems_status_code status;
409 409
410 410 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
411 411 if (status!=RTEMS_SUCCESSFUL) {
412 412 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
413 413 }
414 414
415 415 if (status == RTEMS_SUCCESSFUL) // SEND
416 416 {
417 417 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
418 418 if (status!=RTEMS_SUCCESSFUL) {
419 419 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
420 420 }
421 421 }
422 422
423 423 return status;
424 424 }
425 425
426 426 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
427 427 {
428 428 /** This function starts all RTEMS tasks used in the software.
429 429 *
430 430 * @return RTEMS directive status codes:
431 431 * - RTEMS_SUCCESSFUL - ask started successfully
432 432 * - RTEMS_INVALID_ADDRESS - invalid task entry point
433 433 * - RTEMS_INVALID_ID - invalid task id
434 434 * - RTEMS_INCORRECT_STATE - task not in the dormant state
435 435 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
436 436 *
437 437 */
438 438 // starts all the tasks fot eh flight software
439 439
440 440 rtems_status_code status;
441 441
442 442 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
443 443 if (status!=RTEMS_SUCCESSFUL) {
444 444 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
445 445 }
446 446
447 447 if (status == RTEMS_SUCCESSFUL) // WTDG
448 448 {
449 449 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
450 450 if (status!=RTEMS_SUCCESSFUL) {
451 451 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
452 452 }
453 453 }
454 454
455 455 if (status == RTEMS_SUCCESSFUL) // SMIQ
456 456 {
457 457 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
458 458 if (status!=RTEMS_SUCCESSFUL) {
459 459 BOOT_PRINTF("in INIT *** Error starting TASK_BPPR\n")
460 460 }
461 461 }
462 462
463 463 if (status == RTEMS_SUCCESSFUL) // ACTN
464 464 {
465 465 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
466 466 if (status!=RTEMS_SUCCESSFUL) {
467 467 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
468 468 }
469 469 }
470 470
471 471 if (status == RTEMS_SUCCESSFUL) // STAT
472 472 {
473 473 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
474 474 if (status!=RTEMS_SUCCESSFUL) {
475 475 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
476 476 }
477 477 }
478 478
479 479 if (status == RTEMS_SUCCESSFUL) // AVF0
480 480 {
481 481 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
482 482 if (status!=RTEMS_SUCCESSFUL) {
483 483 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
484 484 }
485 485 }
486 486
487 487 if (status == RTEMS_SUCCESSFUL) // BPF0
488 488 {
489 489 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
490 490 if (status!=RTEMS_SUCCESSFUL) {
491 491 BOOT_PRINTF("in INIT *** Error starting TASK_BPF0\n")
492 492 }
493 493 }
494 494
495 495 if (status == RTEMS_SUCCESSFUL) // WFRM
496 496 {
497 497 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
498 498 if (status!=RTEMS_SUCCESSFUL) {
499 499 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
500 500 }
501 501 }
502 502
503 503 if (status == RTEMS_SUCCESSFUL) // DUMB
504 504 {
505 505 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
506 506 if (status!=RTEMS_SUCCESSFUL) {
507 507 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
508 508 }
509 509 }
510 510
511 511 if (status == RTEMS_SUCCESSFUL) // HOUS
512 512 {
513 513 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
514 514 if (status!=RTEMS_SUCCESSFUL) {
515 515 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
516 516 }
517 517 }
518 518
519 519 if (status == RTEMS_SUCCESSFUL) // MATR
520 520 {
521 521 status = rtems_task_start( Task_id[TASKID_MATR], matr_task, 1 );
522 522 if (status!=RTEMS_SUCCESSFUL) {
523 523 BOOT_PRINTF("in INIT *** Error starting TASK_MATR\n")
524 524 }
525 525 }
526 526
527 527 if (status == RTEMS_SUCCESSFUL) // CWF3
528 528 {
529 529 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
530 530 if (status!=RTEMS_SUCCESSFUL) {
531 531 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
532 532 }
533 533 }
534 534
535 535 if (status == RTEMS_SUCCESSFUL) // CWF2
536 536 {
537 537 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
538 538 if (status!=RTEMS_SUCCESSFUL) {
539 539 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
540 540 }
541 541 }
542 542
543 543 if (status == RTEMS_SUCCESSFUL) // CWF1
544 544 {
545 545 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
546 546 if (status!=RTEMS_SUCCESSFUL) {
547 547 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
548 548 }
549 549 }
550 550 return status;
551 551 }
552 552
553 553 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
554 554 {
555 555 rtems_status_code status_recv;
556 556 rtems_status_code status_send;
557 557 rtems_status_code ret;
558 558 rtems_id queue_id;
559 559
560 560 // create the queue for handling valid TCs
561 561 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
562 562 ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
563 563 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
564 564 if ( status_recv != RTEMS_SUCCESSFUL ) {
565 565 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
566 566 }
567 567
568 568 // create the queue for handling TM packet sending
569 569 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
570 570 ACTION_MSG_PKTS_COUNT, ACTION_MSG_PKTS_MAX_SIZE,
571 571 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
572 572 if ( status_send != RTEMS_SUCCESSFUL ) {
573 573 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
574 574 }
575 575
576 576 if ( status_recv != RTEMS_SUCCESSFUL )
577 577 {
578 578 ret = status_recv;
579 579 }
580 580 else
581 581 {
582 582 ret = status_send;
583 583 }
584 584
585 585 return ret;
586 586 }
@@ -1,623 +1,612
1 1 /** Functions related to the SpaceWire interface.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle SpaceWire transmissions:
7 7 * - configuration of the SpaceWire link
8 8 * - SpaceWire related interruption requests processing
9 9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 10 * - reception of TeleCommands by a dedicated RTEMS task
11 11 *
12 12 */
13 13
14 14 #include "fsw_spacewire.h"
15 15
16 16 char *lstates[6] = {"Error-reset",
17 17 "Error-wait",
18 18 "Ready",
19 19 "Started",
20 20 "Connecting",
21 21 "Run"
22 22 };
23 23
24 24 rtems_name semq_name;
25 25 rtems_id semq_id;
26 26
27 27 //***********
28 28 // RTEMS TASK
29 29 rtems_task spiq_task(rtems_task_argument unused)
30 30 {
31 31 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
32 32 *
33 33 * @param unused is the starting argument of the RTEMS task
34 34 *
35 35 */
36 36
37 37 rtems_event_set event_out;
38 38 rtems_status_code status;
39 39 int linkStatus;
40 40
41 41 BOOT_PRINTF("in SPIQ *** \n")
42 42
43 43 while(true){
44 44 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
45 45 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
46 46
47 47 // [0] SUSPEND RECV AND SEND TASKS
48 48 rtems_task_suspend( Task_id[ TASKID_RECV ] );
49 49 rtems_task_suspend( Task_id[ TASKID_SEND ] );
50 50
51 51 // [1] CHECK THE LINK
52 52 ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
53 53 if ( linkStatus != 5) {
54 54 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
55 55 rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
56 56 }
57 57
58 58 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
59 59 ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
60 60 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
61 61 {
62 62 spacewire_compute_stats_offsets();
63 63 status = spacewire_reset_link( );
64 64 }
65 65 else // [2.b] in run state, start the link
66 66 {
67 67 status = spacewire_stop_start_link( fdSPW ); // start the link
68 68 if ( status != RTEMS_SUCCESSFUL)
69 69 {
70 70 PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status)
71 71 }
72 72 }
73 73
74 74 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
75 75 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
76 76 {
77 77 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
78 78 if ( status != RTEMS_SUCCESSFUL ) {
79 79 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
80 80 }
81 81 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
82 82 if ( status != RTEMS_SUCCESSFUL ) {
83 83 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
84 84 }
85 85 }
86 86 else // [3.b] the link is not in run state, go in STANDBY mode
87 87 {
88 88 status = stop_current_mode();
89 89 if ( status != RTEMS_SUCCESSFUL ) {
90 90 PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status)
91 91 }
92 92 status = enter_standby_mode();
93 93 if ( status != RTEMS_SUCCESSFUL ) {
94 94 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
95 95 }
96 96 // wake the WTDG task up to wait for the link recovery
97 97 status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 );
98 98 rtems_task_suspend( RTEMS_SELF );
99 99 }
100 100 }
101 101 }
102 102
103 103 rtems_task recv_task( rtems_task_argument unused )
104 104 {
105 105 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
106 106 *
107 107 * @param unused is the starting argument of the RTEMS task
108 108 *
109 109 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
110 110 * 1. It reads the incoming data.
111 111 * 2. Launches the acceptance procedure.
112 112 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
113 113 *
114 114 */
115 115
116 116 int len;
117 117 ccsdsTelecommandPacket_t currentTC;
118 118 unsigned char computed_CRC[ 2 ];
119 119 unsigned char currentTC_LEN_RCV[ 2 ];
120 120 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
121 121 unsigned int parserCode;
122 122 rtems_status_code status;
123 123 rtems_id queue_recv_id;
124 124 rtems_id queue_send_id;
125 125
126 126 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
127 127
128 128 status = rtems_message_queue_ident( misc_name[QUEUE_RECV], 0, &queue_recv_id );
129 129 if (status != RTEMS_SUCCESSFUL)
130 130 {
131 131 PRINTF1("in RECV *** ERR getting QUEUE_RECV id, %d\n", status)
132 132 }
133 133
134 134 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_send_id );
135 135 if (status != RTEMS_SUCCESSFUL)
136 136 {
137 137 PRINTF1("in RECV *** ERR getting QUEUE_SEND id, %d\n", status)
138 138 }
139 139
140 140 BOOT_PRINTF("in RECV *** \n")
141 141
142 142 while(1)
143 143 {
144 144 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
145 145 if (len == -1){ // error during the read call
146 146 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
147 147 }
148 148 else {
149 149 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
150 150 PRINTF("in RECV *** packet lenght too short\n")
151 151 }
152 152 else {
153 153 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
154 154 currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8);
155 155 currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt );
156 156 // CHECK THE TC
157 157 parserCode = tc_parser( &currentTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ;
158 158 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
159 159 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
160 160 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
161 161 || (parserCode == WRONG_SRC_ID) )
162 162 { // send TM_LFR_TC_EXE_CORRUPTED
163 163 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
164 164 &&
165 165 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
166 166 )
167 167 {
168 168 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id, computed_CRC, currentTC_LEN_RCV );
169 169 }
170 170 }
171 171 else
172 172 { // send valid TC to the action launcher
173 173 status = rtems_message_queue_send( queue_recv_id, &currentTC,
174 174 currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3);
175 175 }
176 176 }
177 177 }
178 178 }
179 179 }
180 180
181 181 rtems_task send_task( rtems_task_argument argument)
182 182 {
183 183 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
184 184 *
185 185 * @param unused is the starting argument of the RTEMS task
186 186 *
187 187 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
188 188 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
189 189 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
190 190 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
191 191 * data it contains.
192 192 *
193 193 */
194 194
195 195 rtems_status_code status; // RTEMS status code
196 196 char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer
197 197 spw_ioctl_pkt_send *spw_ioctl_send;
198 198 size_t size; // size of the incoming TC packet
199 199 u_int32_t count;
200 200 rtems_id queue_id;
201 201
202 202 status = rtems_message_queue_ident( misc_name[QUEUE_SEND], 0, &queue_id );
203 203 if (status != RTEMS_SUCCESSFUL)
204 204 {
205 205 PRINTF1("in SEND *** ERR getting queue id, %d\n", status)
206 206 }
207 207
208 208 BOOT_PRINTF("in SEND *** \n")
209 209
210 210 while(1)
211 211 {
212 212 status = rtems_message_queue_receive( queue_id, incomingData, &size,
213 213 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
214 214
215 215 if (status!=RTEMS_SUCCESSFUL)
216 216 {
217 217 PRINTF1("in SEND *** (1) ERR = %d\n", status)
218 218 }
219 219 else
220 220 {
221 221 if ( incomingData[0] == CCSDS_DESTINATION_ID) // the incoming message is a ccsds packet
222 222 {
223 223 status = write( fdSPW, incomingData, size );
224 224 if (status == -1){
225 225 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
226 226 }
227 227 }
228 228 else // the incoming message is a spw_ioctl_pkt_send structure
229 229 {
230 230 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
231 if (spw_ioctl_send->hlen == 0)
232 {
233 status = write( fdSPW, spw_ioctl_send->data, spw_ioctl_send->dlen );
234 if (status == -1){
235 PRINTF2("in SEND *** (2.b) ERRNO = %d, dlen = %d\n", errno, spw_ioctl_send->dlen)
236 }
237 }
238 else
239 {
240 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
241 if (status == -1){
242 PRINTF2("in SEND *** (2.c) ERRNO = %d, dlen = %d\n", errno, spw_ioctl_send->dlen)
243 PRINTF1(" hlen = %d\n", spw_ioctl_send->hlen)
244 }
231 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
232 if (status == -1){
233 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
245 234 }
246 235 }
247 236 }
248 237
249 238 status = rtems_message_queue_get_number_pending( queue_id, &count );
250 239 if (status != RTEMS_SUCCESSFUL)
251 240 {
252 241 PRINTF1("in SEND *** (3) ERR = %d\n", status)
253 242 }
254 243 else
255 244 {
256 245 if (count > maxCount)
257 246 {
258 247 maxCount = count;
259 248 }
260 249 }
261 250 }
262 251 }
263 252
264 253 rtems_task wtdg_task( rtems_task_argument argument )
265 254 {
266 255 rtems_event_set event_out;
267 256 rtems_status_code status;
268 257 int linkStatus;
269 258
270 259 BOOT_PRINTF("in WTDG ***\n")
271 260
272 261 while(1)
273 262 {
274 263 // wait for an RTEMS_EVENT
275 264 rtems_event_receive( RTEMS_EVENT_0,
276 265 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
277 266 PRINTF("in WTDG *** wait for the link\n")
278 267 ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
279 268 while( linkStatus != 5) // wait for the link
280 269 {
281 270 rtems_task_wake_after( 10 );
282 271 ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
283 272 }
284 273
285 274 status = spacewire_stop_start_link( fdSPW );
286 275
287 276 if (status != RTEMS_SUCCESSFUL)
288 277 {
289 278 PRINTF1("in WTDG *** ERR link not started %d\n", status)
290 279 }
291 280 else
292 281 {
293 282 PRINTF("in WTDG *** OK link started\n")
294 283 }
295 284
296 285 // restart the SPIQ task
297 286 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
298 287 if ( status != RTEMS_SUCCESSFUL ) {
299 288 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
300 289 }
301 290
302 291 // restart RECV and SEND
303 292 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
304 293 if ( status != RTEMS_SUCCESSFUL ) {
305 294 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
306 295 }
307 296 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
308 297 if ( status != RTEMS_SUCCESSFUL ) {
309 298 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
310 299 }
311 300 }
312 301 }
313 302
314 303 //****************
315 304 // OTHER FUNCTIONS
316 305 int spacewire_open_link( void )
317 306 {
318 307 /** This function opens the SpaceWire link.
319 308 *
320 309 * @return a valid file descriptor in case of success, -1 in case of a failure
321 310 *
322 311 */
323 312 rtems_status_code status;
324 313
325 314 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
326 315 if ( fdSPW < 0 ) {
327 316 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
328 317 }
329 318 else
330 319 {
331 320 status = RTEMS_SUCCESSFUL;
332 321 }
333 322
334 323 return status;
335 324 }
336 325
337 326 int spacewire_start_link( int fd )
338 327 {
339 328 rtems_status_code status;
340 329
341 330 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
342 331 // -1 default hardcoded driver timeout
343 332
344 333 return status;
345 334 }
346 335
347 336 int spacewire_stop_start_link( int fd )
348 337 {
349 338 rtems_status_code status;
350 339
351 340 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
352 341 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
353 342 // -1 default hardcoded driver timeout
354 343
355 344 return status;
356 345 }
357 346
358 347 int spacewire_configure_link( int fd )
359 348 {
360 349 /** This function configures the SpaceWire link.
361 350 *
362 351 * @return GR-RTEMS-DRIVER directive status codes:
363 352 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
364 353 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
365 354 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
366 355 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
367 356 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
368 357 * - 5 EIO - Error when writing to grswp hardware registers.
369 358 * - 2 ENOENT - No such file or directory
370 359 */
371 360
372 361 rtems_status_code status;
373 362
374 363 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
375 364 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
376 365
377 366 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
378 367 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
379 368 //
380 369 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
381 370 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
382 371 //
383 372 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
384 373 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
385 374 //
386 375 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
387 376 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
388 377 //
389 378 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks
390 379 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
391 380 //
392 381 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
393 382 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
394 383 //
395 384 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
396 385 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
397 386
398 387 return status;
399 388 }
400 389
401 390 int spacewire_reset_link( void )
402 391 {
403 392 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
404 393 *
405 394 * @return RTEMS directive status code:
406 395 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
407 396 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
408 397 *
409 398 */
410 399
411 400 rtems_status_code status_spw;
412 401 int i;
413 402
414 403 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
415 404 {
416 405 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
417 406
418 407 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
419 408
420 409 status_spw = spacewire_stop_start_link( fdSPW );
421 410 if ( status_spw != RTEMS_SUCCESSFUL )
422 411 {
423 412 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
424 413 }
425 414
426 415 if ( status_spw == RTEMS_SUCCESSFUL)
427 416 {
428 417 break;
429 418 }
430 419 }
431 420
432 421 return status_spw;
433 422 }
434 423
435 424 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
436 425 {
437 426 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
438 427 *
439 428 * @param val is the value, 0 or 1, used to set the value of the NP bit.
440 429 * @param regAddr is the address of the GRSPW control register.
441 430 *
442 431 * NP is the bit 20 of the GRSPW control register.
443 432 *
444 433 */
445 434
446 435 unsigned int *spwptr = (unsigned int*) regAddr;
447 436
448 437 if (val == 1) {
449 438 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
450 439 }
451 440 if (val== 0) {
452 441 *spwptr = *spwptr & 0xffdfffff;
453 442 }
454 443 }
455 444
456 445 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
457 446 {
458 447 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
459 448 *
460 449 * @param val is the value, 0 or 1, used to set the value of the RE bit.
461 450 * @param regAddr is the address of the GRSPW control register.
462 451 *
463 452 * RE is the bit 16 of the GRSPW control register.
464 453 *
465 454 */
466 455
467 456 unsigned int *spwptr = (unsigned int*) regAddr;
468 457
469 458 if (val == 1)
470 459 {
471 460 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
472 461 }
473 462 if (val== 0)
474 463 {
475 464 *spwptr = *spwptr & 0xfffdffff;
476 465 }
477 466 }
478 467
479 468 void spacewire_compute_stats_offsets( void )
480 469 {
481 470 /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising.
482 471 *
483 472 * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics
484 473 * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it
485 474 * during the open systel call).
486 475 *
487 476 */
488 477
489 478 spw_stats spacewire_stats_grspw;
490 479 rtems_status_code status;
491 480
492 481 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
493 482
494 483 spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received
495 484 + spacewire_stats.packets_received;
496 485 spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent
497 486 + spacewire_stats.packets_sent;
498 487 spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err
499 488 + spacewire_stats.parity_err;
500 489 spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err
501 490 + spacewire_stats.disconnect_err;
502 491 spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err
503 492 + spacewire_stats.escape_err;
504 493 spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err
505 494 + spacewire_stats.credit_err;
506 495 spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err
507 496 + spacewire_stats.write_sync_err;
508 497 spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err
509 498 + spacewire_stats.rx_rmap_header_crc_err;
510 499 spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err
511 500 + spacewire_stats.rx_rmap_data_crc_err;
512 501 spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep
513 502 + spacewire_stats.early_ep;
514 503 spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address
515 504 + spacewire_stats.invalid_address;
516 505 spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err
517 506 + spacewire_stats.rx_eep_err;
518 507 spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated
519 508 + spacewire_stats.rx_truncated;
520 509 }
521 510
522 511 void spacewire_update_statistics( void )
523 512 {
524 513 rtems_status_code status;
525 514 spw_stats spacewire_stats_grspw;
526 515
527 516 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw );
528 517
529 518 spacewire_stats.packets_received = spacewire_stats_backup.packets_received
530 519 + spacewire_stats_grspw.packets_received;
531 520 spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent
532 521 + spacewire_stats_grspw.packets_sent;
533 522 spacewire_stats.parity_err = spacewire_stats_backup.parity_err
534 523 + spacewire_stats_grspw.parity_err;
535 524 spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err
536 525 + spacewire_stats_grspw.disconnect_err;
537 526 spacewire_stats.escape_err = spacewire_stats_backup.escape_err
538 527 + spacewire_stats_grspw.escape_err;
539 528 spacewire_stats.credit_err = spacewire_stats_backup.credit_err
540 529 + spacewire_stats_grspw.credit_err;
541 530 spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err
542 531 + spacewire_stats_grspw.write_sync_err;
543 532 spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err
544 533 + spacewire_stats_grspw.rx_rmap_header_crc_err;
545 534 spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err
546 535 + spacewire_stats_grspw.rx_rmap_data_crc_err;
547 536 spacewire_stats.early_ep = spacewire_stats_backup.early_ep
548 537 + spacewire_stats_grspw.early_ep;
549 538 spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address
550 539 + spacewire_stats_grspw.invalid_address;
551 540 spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err
552 541 + spacewire_stats_grspw.rx_eep_err;
553 542 spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated
554 543 + spacewire_stats_grspw.rx_truncated;
555 544 //spacewire_stats.tx_link_err;
556 545
557 546 //****************************
558 547 // DPU_SPACEWIRE_IF_STATISTICS
559 548 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8);
560 549 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received);
561 550 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8);
562 551 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent);
563 552 //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt;
564 553 //housekeeping_packet.hk_lfr_dpu_spw_last_timc;
565 554
566 555 //******************************************
567 556 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
568 557 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err;
569 558 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err;
570 559 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err;
571 560 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err;
572 561 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err;
573 562 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb;
574 563 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb;
575 564 housekeeping_packet.hk_lfr_dpu_spw_header_crc = (unsigned char) spacewire_stats.rx_rmap_header_crc_err;
576 565 housekeeping_packet.hk_lfr_dpu_spw_data_crc = (unsigned char) spacewire_stats.rx_rmap_data_crc_err;
577 566
578 567 //*********************************************
579 568 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
580 569 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep;
581 570 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address;
582 571 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err;
583 572 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated;
584 573
585 574 }
586 575
587 576 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
588 577 {
589 578 //if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) {
590 579 // printf("In timecode_irq_handler *** Error sending event to DUMB\n");
591 580 //}
592 581 }
593 582
594 583 rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data )
595 584 {
596 585 int linkStatus;
597 586 rtems_status_code status;
598 587
599 588 ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
600 589
601 590 if ( linkStatus == 5) {
602 591 PRINTF("in spacewire_reset_link *** link is running\n")
603 592 status = RTEMS_SUCCESSFUL;
604 593 }
605 594 }
606 595
607 596 rtems_status_code rtems_message_queue_send_lfr( rtems_id id, const void *buffer, size_t size )
608 597 {
609 598 rtems_status_code status;
610 599 rtems_mode previous_mode_set;
611 600
612 601 // set the preemption OFF
613 602 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &previous_mode_set );
614 603
615 604 // use the message queue
616 605 status = rtems_message_queue_send_lfr( id, buffer, size );
617 606
618 607 // set the preemption ON
619 608 status = rtems_task_mode( RTEMS_PREEMPT , RTEMS_PREEMPT_MASK, &previous_mode_set );
620 609
621 610 return status;
622 611 }
623 612
@@ -1,449 +1,449
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
18 18 {
19 19 /** This function updates the LFR registers with the incoming common parameters.
20 20 *
21 21 * @param TC points to the TeleCommand packet that is being processed
22 22 *
23 23 *
24 24 */
25 25
26 26 parameter_dump_packet.unused0 = TC->dataAndCRC[0];
27 27 parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1];
28 28 set_wfp_data_shaping(parameter_dump_packet.bw_sp0_sp1_r0_r1);
29 29 return LFR_SUCCESSFUL;
30 30 }
31 31
32 32 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
33 33 {
34 34 /** This function updates the LFR registers with the incoming normal parameters.
35 35 *
36 36 * @param TC points to the TeleCommand packet that is being processed
37 37 * @param queue_id is the id of the queue which handles TM related to this execution step
38 38 *
39 39 */
40 40
41 41 int result;
42 42 int flag;
43 43
44 44 flag = LFR_SUCCESSFUL;
45 result = LFR_SUCCESSFUL;
46 45
47 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
46 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
47 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
48 48 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
49 49 flag = LFR_DEFAULT;
50 50 }
51 51
52 52 //***************
53 53 // sy_lfr_n_swf_l
54 54 if (flag == LFR_SUCCESSFUL)
55 55 {
56 56 result = set_sy_lfr_n_swf_l( TC, queue_id );
57 57 if (result != LFR_SUCCESSFUL)
58 58 {
59 59 flag = LFR_DEFAULT;
60 60 }
61 61 }
62 62
63 63 //***************
64 64 // sy_lfr_n_swf_p
65 65 if (flag == LFR_SUCCESSFUL)
66 66 {
67 67 result = set_sy_lfr_n_swf_p( TC, queue_id );
68 68 if (result != LFR_SUCCESSFUL)
69 69 {
70 70 flag = LFR_DEFAULT;
71 71 }
72 72 }
73 73
74 74 //***************
75 75 // SY_LFR_N_ASM_P
76 76 if (flag == LFR_SUCCESSFUL)
77 77 {
78 78 result = set_sy_lfr_n_asm_p( TC, queue_id );
79 79 if (result != LFR_SUCCESSFUL)
80 80 {
81 81 flag = LFR_DEFAULT;
82 82 }
83 83 }
84 84
85 85 //***************
86 86 // SY_LFR_N_BP_P0
87 87 if (flag == LFR_SUCCESSFUL)
88 88 {
89 89 result = set_sy_lfr_n_bp_p0( TC, queue_id );
90 90 if (result != LFR_SUCCESSFUL)
91 91 {
92 92 flag = LFR_DEFAULT;
93 93 }
94 94 }
95 95
96 96 //***************
97 97 // sy_lfr_n_bp_p1
98 98 if (flag == LFR_SUCCESSFUL)
99 99 {
100 100 result = set_sy_lfr_n_bp_p1( TC, queue_id );
101 101 if (result != LFR_SUCCESSFUL)
102 102 {
103 103 flag = LFR_DEFAULT;
104 104 }
105 105 }
106 106
107 return result;
107 return flag;
108 108 }
109 109
110 110 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
111 111 {
112 112 /** This function updates the LFR registers with the incoming burst parameters.
113 113 *
114 114 * @param TC points to the TeleCommand packet that is being processed
115 115 * @param queue_id is the id of the queue which handles TM related to this execution step
116 116 *
117 117 */
118 118
119 119 int result;
120 120 unsigned char lfrMode;
121 121
122 122 result = LFR_DEFAULT;
123 123 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
124 124
125 125 if ( lfrMode == LFR_MODE_BURST ) {
126 126 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
127 127 result = LFR_DEFAULT;
128 128 }
129 129 else {
130 130 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[0];
131 131 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[1];
132 132
133 133 result = LFR_SUCCESSFUL;
134 134 }
135 135
136 136 return result;
137 137 }
138 138
139 139 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
140 140 {
141 141 /** This function updates the LFR registers with the incoming sbm1 parameters.
142 142 *
143 143 * @param TC points to the TeleCommand packet that is being processed
144 144 * @param queue_id is the id of the queue which handles TM related to this execution step
145 145 *
146 146 */
147 147 int result;
148 148 unsigned char lfrMode;
149 149
150 150 result = LFR_DEFAULT;
151 151 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
152 152
153 153 if ( (lfrMode == LFR_MODE_SBM1) || (lfrMode == LFR_MODE_SBM2) ) {
154 154 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
155 155 result = LFR_DEFAULT;
156 156 }
157 157 else {
158 158 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[0];
159 159 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[1];
160 160
161 161 result = LFR_SUCCESSFUL;
162 162 }
163 163
164 164 return result;
165 165 }
166 166
167 167 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
168 168 {
169 169 /** This function updates the LFR registers with the incoming sbm2 parameters.
170 170 *
171 171 * @param TC points to the TeleCommand packet that is being processed
172 172 * @param queue_id is the id of the queue which handles TM related to this execution step
173 173 *
174 174 */
175 175
176 176 int result;
177 177 unsigned char lfrMode;
178 178
179 179 result = LFR_DEFAULT;
180 180 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
181 181
182 182 if ( (lfrMode == LFR_MODE_SBM2) || (lfrMode == LFR_MODE_SBM2) ) {
183 183 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
184 184 result = LFR_DEFAULT;
185 185 }
186 186 else {
187 187 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[0];
188 188 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[1];
189 189
190 190 result = LFR_SUCCESSFUL;
191 191 }
192 192
193 193 return result;
194 194 }
195 195
196 196 int action_dump_par( rtems_id queue_id )
197 197 {
198 198 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
199 199 *
200 200 * @param queue_id is the id of the queue which handles TM related to this execution step.
201 201 *
202 202 * @return RTEMS directive status codes:
203 203 * - RTEMS_SUCCESSFUL - message sent successfully
204 204 * - RTEMS_INVALID_ID - invalid queue id
205 205 * - RTEMS_INVALID_SIZE - invalid message size
206 206 * - RTEMS_INVALID_ADDRESS - buffer is NULL
207 207 * - RTEMS_UNSATISFIED - out of message buffers
208 208 * - RTEMS_TOO_MANY - queue s limit has been reached
209 209 *
210 210 */
211 211
212 212 int status;
213 213
214 214 // UPDATE TIME
215 215 increment_seq_counter( parameter_dump_packet.packetSequenceControl );
216 216 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
217 217 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
218 218 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
219 219 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
220 220 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
221 221 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
222 222 // SEND DATA
223 223 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
224 224 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
225 225 if (status != RTEMS_SUCCESSFUL) {
226 226 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
227 227 }
228 228
229 229 return status;
230 230 }
231 231
232 232 //***********************
233 233 // NORMAL MODE PARAMETERS
234 234
235 235 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
236 236 {
237 237 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
238 238 *
239 239 * @param TC points to the TeleCommand packet that is being processed
240 240 * @param queue_id is the id of the queue which handles TM related to this execution step
241 241 *
242 242 */
243 243
244 244 unsigned int tmp;
245 245 int result;
246 246 unsigned char msb;
247 247 unsigned char lsb;
248 248
249 249 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_L ];
250 250 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_L+1 ];
251 251
252 252 tmp = ( unsigned int ) floor(
253 253 ( ( msb*256 ) + lsb ) / 16
254 254 ) * 16;
255 255
256 256 if ( (tmp < 16) || (tmp > 2048) ) // the snapshot period is a multiple of 16
257 257 { // 2048 is the maximum limit due to the size of the buffers
258 258 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_SY_LFR_N_SWF_L+10, lsb );
259 259 result = WRONG_APP_DATA;
260 260 }
261 261 else if (tmp != 2048)
262 262 {
263 263 send_tm_lfr_tc_exe_not_implemented( TC, queue_id );
264 264 result = FUNCT_NOT_IMPL;
265 265 }
266 266 else
267 267 {
268 268 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (tmp >> 8);
269 269 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (tmp );
270 270 result = LFR_SUCCESSFUL;
271 271 }
272 272
273 273 return result;
274 274 }
275 275
276 276 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
277 277 {
278 278 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
279 279 *
280 280 * @param TC points to the TeleCommand packet that is being processed
281 281 * @param queue_id is the id of the queue which handles TM related to this execution step
282 282 *
283 283 */
284 284
285 285 unsigned int tmp;
286 286 int result;
287 287 unsigned char msb;
288 288 unsigned char lsb;
289 289
290 290 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_P ];
291 291 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_SWF_P+1 ];
292 292
293 293 tmp = ( unsigned int ) floor(
294 294 ( ( msb*256 ) + lsb ) / 8
295 295 ) * 8;
296 296
297 297 if ( (tmp < 16) || (tmp > 65528) )
298 298 {
299 299 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_SY_LFR_N_SWF_P+10, lsb );
300 300 result = WRONG_APP_DATA;
301 301 }
302 302 else
303 303 {
304 304 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (tmp >> 8);
305 305 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (tmp );
306 306 result = LFR_SUCCESSFUL;
307 307 }
308 308
309 309 return result;
310 310 }
311 311
312 312 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
313 313 {
314 314 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
315 315 *
316 316 * @param TC points to the TeleCommand packet that is being processed
317 317 * @param queue_id is the id of the queue which handles TM related to this execution step
318 318 *
319 319 */
320 320
321 321 int result;
322 322 unsigned char msb;
323 323 unsigned char lsb;
324 324
325 325 msb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_ASM_P ];
326 326 lsb = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_ASM_P+1 ];
327 327
328 328 parameter_dump_packet.sy_lfr_n_asm_p[0] = msb;
329 329 parameter_dump_packet.sy_lfr_n_asm_p[1] = lsb;
330 330 result = LFR_SUCCESSFUL;
331 331
332 332 return result;
333 333 }
334 334
335 335 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
336 336 {
337 337 /** This function sets the time between two basic parameter sets, in s (SY_LFR_N_BP_P0).
338 338 *
339 339 * @param TC points to the TeleCommand packet that is being processed
340 340 * @param queue_id is the id of the queue which handles TM related to this execution step
341 341 *
342 342 */
343 343
344 344 int status;
345 345
346 346 status = LFR_SUCCESSFUL;
347 347
348 348 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_BP_P0 ];
349 349
350 350 return status;
351 351 }
352 352
353 353 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
354 354 {
355 355 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
356 356 *
357 357 * @param TC points to the TeleCommand packet that is being processed
358 358 * @param queue_id is the id of the queue which handles TM related to this execution step
359 359 *
360 360 */
361 361
362 362 int status;
363 363
364 364 status = LFR_SUCCESSFUL;
365 365
366 366 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ BYTE_POS_SY_LFR_N_BP_P1 ];
367 367
368 368 return status;
369 369 }
370 370
371 371 //**********************
372 372 // BURST MODE PARAMETERS
373 373
374 374 //*********************
375 375 // SBM1 MODE PARAMETERS
376 376
377 377 //*********************
378 378 // SBM2 MODE PARAMETERS
379 379
380 380 //**********
381 381 // init dump
382 382
383 383 void init_parameter_dump( void )
384 384 {
385 385 /** This function initialize the parameter_dump_packet global variable with default values.
386 386 *
387 387 */
388 388
389 389 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
390 390 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
391 391 parameter_dump_packet.reserved = CCSDS_RESERVED;
392 392 parameter_dump_packet.userApplication = CCSDS_USER_APP;
393 393 parameter_dump_packet.packetID[0] = (unsigned char) (TM_PACKET_ID_PARAMETER_DUMP >> 8);
394 394 parameter_dump_packet.packetID[1] = (unsigned char) TM_PACKET_ID_PARAMETER_DUMP;
395 395 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
396 396 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
397 397 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
398 398 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
399 399 // DATA FIELD HEADER
400 400 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
401 401 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
402 402 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
403 403 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
404 404 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
405 405 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
406 406 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
407 407 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
408 408 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
409 409 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
410 410 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
411 411
412 412 //******************
413 413 // COMMON PARAMETERS
414 414 parameter_dump_packet.unused0 = DEFAULT_SY_LFR_COMMON0;
415 415 parameter_dump_packet.bw_sp0_sp1_r0_r1 = DEFAULT_SY_LFR_COMMON1;
416 416
417 417 //******************
418 418 // NORMAL PARAMETERS
419 419 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (SY_LFR_N_SWF_L >> 8);
420 420 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (SY_LFR_N_SWF_L );
421 421 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (SY_LFR_N_SWF_P >> 8);
422 422 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (SY_LFR_N_SWF_P );
423 423 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (SY_LFR_N_ASM_P >> 8);
424 424 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (SY_LFR_N_ASM_P );
425 425 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) SY_LFR_N_BP_P0;
426 426 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) SY_LFR_N_BP_P1;
427 427
428 428 //*****************
429 429 // BURST PARAMETERS
430 430 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
431 431 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
432 432
433 433 //****************
434 434 // SBM1 PARAMETERS
435 435 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
436 436 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
437 437
438 438 //****************
439 439 // SBM2 PARAMETERS
440 440 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
441 441 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
442 442 }
443 443
444 444
445 445
446 446
447 447
448 448
449 449
@@ -1,1219 +1,1219
1 1 /** Functions and tasks related to waveform packet generation.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 7 *
8 8 */
9 9
10 10 #include "wf_handler.h"
11 11
12 12 // SWF
13 13 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7];
14 14 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7];
15 15 Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7];
16 16 // CWF
17 17 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[7];
18 18 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[7];
19 19 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[7];
20 20 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[7];
21 21 Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[7];
22 22
23 23 unsigned char doubleSendCWF1 = 0;
24 24 unsigned char doubleSendCWF2 = 0;
25 25
26 26 rtems_isr waveforms_isr( rtems_vector_number vector )
27 27 {
28 28 /** This is the interrupt sub routine called by the waveform picker core.
29 29 *
30 30 * This ISR launch different actions depending mainly on two pieces of information:
31 31 * 1. the values read in the registers of the waveform picker.
32 32 * 2. the current LFR mode.
33 33 *
34 34 */
35 35
36 36 #ifdef GSA
37 37 #else
38 38 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
39 39 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
40 40 { // in modes other than STANDBY and BURST, send the CWF_F3 data
41 41 if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full
42 42 // (1) change the receiving buffer for the waveform picker
43 43 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3) {
44 44 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3_bis);
45 45 }
46 46 else {
47 47 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3);
48 48 }
49 49 // (2) send an event for the waveforms transmission
50 50 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
51 51 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
52 52 }
53 53 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111]
54 54 }
55 55 }
56 56 #endif
57 57
58 58 switch(lfrCurrentMode)
59 59 {
60 60 //********
61 61 // STANDBY
62 62 case(LFR_MODE_STANDBY):
63 63 break;
64 64
65 65 //******
66 66 // NORMAL
67 67 case(LFR_MODE_NORMAL):
68 68 #ifdef GSA
69 69 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
70 70 #else
71 71 if ( (waveform_picker_regs->burst_enable & 0x7) == 0x0 ){ // if no channel is enable
72 72 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
73 73 }
74 74 else {
75 75 if ( (waveform_picker_regs->status & 0x7) == 0x7 ){ // f2 f1 and f0 are full
76 76 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable & 0x08;
77 77 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
78 78 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
79 79 }
80 80 // waveform_picker_regs->status = waveform_picker_regs->status & 0x00;
81 81 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888;
82 82 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x07; // [0111] enable f2 f1 f0
83 83 }
84 84 }
85 85 #endif
86 86 break;
87 87
88 88 //******
89 89 // BURST
90 90 case(LFR_MODE_BURST):
91 91 #ifdef GSA
92 92 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
93 93 #else
94 94 if ((waveform_picker_regs->status & 0x04) == 0x04){ // [0100] check the f2 full bit
95 95 // (1) change the receiving buffer for the waveform picker
96 96 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
97 97 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_bis);
98 98 }
99 99 else {
100 100 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2);
101 101 }
102 102 // (2) send an event for the waveforms transmission
103 103 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
104 104 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
105 105 }
106 106 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0
107 107 }
108 108 #endif
109 109 break;
110 110
111 111 //*****
112 112 // SBM1
113 113 case(LFR_MODE_SBM1):
114 114 #ifdef GSA
115 115 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
116 116 #else
117 117 if ((waveform_picker_regs->status & 0x02) == 0x02){ // [0010] check the f1 full bit
118 118 // (1) change the receiving buffer for the waveform picker
119 119 if ( param_local.local_sbm1_nb_cwf_sent == (param_local.local_sbm1_nb_cwf_max-1) )
120 120 {
121 121 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1_norm);
122 122 }
123 123 else if ( waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1_norm )
124 124 {
125 125 doubleSendCWF1 = 1;
126 126 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1);
127 127 }
128 128 else if ( waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1 ) {
129 129 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1_bis);
130 130 }
131 131 else {
132 132 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1);
133 133 }
134 134 // (2) send an event for the waveforms transmission
135 135 if (rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ) != RTEMS_SUCCESSFUL) {
136 136 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
137 137 }
138 138 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bit = 0
139 139 }
140 140 if ( ( (waveform_picker_regs->status & 0x05) == 0x05 ) ) { // [0101] check the f2 and f0 full bit
141 141 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
142 142 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
143 143 }
144 144 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffaaa; // [1111 1010 1010 1010] f2 and f0 bits = 0
145 145 reset_local_sbm1_nb_cwf_sent();
146 146 }
147 147
148 148 #endif
149 149 break;
150 150
151 151 //*****
152 152 // SBM2
153 153 case(LFR_MODE_SBM2):
154 154 #ifdef GSA
155 155 PRINTF("in waveform_isr *** unexpected waveform picker interruption\n")
156 156 #else
157 157 if ((waveform_picker_regs->status & 0x04) == 0x04){ // [0100] check the f2 full bit
158 158 // (1) change the receiving buffer for the waveform picker
159 159 if ( param_local.local_sbm2_nb_cwf_sent == (param_local.local_sbm2_nb_cwf_max-1) )
160 160 {
161 161 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_norm);
162 162 }
163 163 else if ( waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2_norm ) {
164 164 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2);
165 165 doubleSendCWF2 = 1;
166 166 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2_WFRM ) != RTEMS_SUCCESSFUL) {
167 167 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
168 168 }
169 169 reset_local_sbm2_nb_cwf_sent();
170 170 }
171 171 else if ( waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2 ) {
172 172 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2_bis);
173 173 }
174 174 else {
175 175 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2);
176 176 }
177 177 // (2) send an event for the waveforms transmission
178 178 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) {
179 179 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
180 180 }
181 181 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0
182 182 }
183 183 if ( ( (waveform_picker_regs->status & 0x03) == 0x03 ) ) { // [0011] f3 f2 f1 f0, f1 and f0 are full
184 184 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ) != RTEMS_SUCCESSFUL) {
185 185 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 );
186 186 }
187 187 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffccc; // [1111 1100 1100 1100] f1, f0 bits = 0
188 188 }
189 189 #endif
190 190 break;
191 191
192 192 //********
193 193 // DEFAULT
194 194 default:
195 195 break;
196 196 }
197 197 }
198 198
199 199 rtems_isr waveforms_simulator_isr( rtems_vector_number vector )
200 200 {
201 201 /** This is the interrupt sub routine called by the waveform picker simulator.
202 202 *
203 203 * This ISR is for debug purpose only.
204 204 *
205 205 */
206 206
207 207 unsigned char lfrMode;
208 208 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
209 209
210 210 switch(lfrMode) {
211 211 case (LFR_MODE_STANDBY):
212 212 break;
213 213 case (LFR_MODE_NORMAL):
214 214 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) {
215 215 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_5 );
216 216 }
217 217 break;
218 218 case (LFR_MODE_BURST):
219 219 break;
220 220 case (LFR_MODE_SBM1):
221 221 break;
222 222 case (LFR_MODE_SBM2):
223 223 break;
224 224 }
225 225 }
226 226
227 227 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
228 228 {
229 229 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
230 230 *
231 231 * @param unused is the starting argument of the RTEMS task
232 232 *
233 233 * The following data packets are sent by this task:
234 234 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
235 235 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
236 236 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
237 237 *
238 238 */
239 239
240 240 rtems_event_set event_out;
241 241 rtems_id queue_id;
242 242
243 243 init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 );
244 244 init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 );
245 245 init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 );
246 246
247 247 init_waveforms();
248 248
249 249 queue_id = get_pkts_queue_id();
250 250
251 251 BOOT_PRINTF("in WFRM ***\n")
252 252
253 253 while(1){
254 254 // wait for an RTEMS_EVENT
255 255 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1
256 256 | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM,
257 257 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
258 258
259 259 if (event_out == RTEMS_EVENT_MODE_NORMAL)
260 260 {
261 261 send_waveform_SWF(wf_snap_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
262 262 send_waveform_SWF(wf_snap_f1, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
263 263 send_waveform_SWF(wf_snap_f2, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
264 264 #ifdef GSA
265 265 waveform_picker_regs->status = waveform_picker_regs->status & 0xf888; // [1111 1000 1000 1000] f2, f1, f0 bits =0
266 266 #endif
267 267 }
268 268 else if (event_out == RTEMS_EVENT_MODE_SBM1)
269 269 {
270 270 send_waveform_SWF(wf_snap_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
271 271 send_waveform_SWF(wf_snap_f1_norm, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
272 272 send_waveform_SWF(wf_snap_f2, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
273 273 #ifdef GSA
274 274 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffaaa; // [1111 1010 1010 1010] f2, f0 bits = 0
275 275 #endif
276 276 }
277 277 else if (event_out == RTEMS_EVENT_MODE_SBM2)
278 278 {
279 279 send_waveform_SWF(wf_snap_f0, SID_NORM_SWF_F0, headerSWF_F0, queue_id);
280 280 send_waveform_SWF(wf_snap_f1, SID_NORM_SWF_F1, headerSWF_F1, queue_id);
281 281 #ifdef GSA
282 282 waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffccc; // [1111 1100 1100 1100] f1, f0 bits = 0
283 283 #endif
284 284 }
285 285 else if (event_out == RTEMS_EVENT_MODE_SBM2_WFRM)
286 286 {
287 287 send_waveform_SWF(wf_snap_f2_norm, SID_NORM_SWF_F2, headerSWF_F2, queue_id);
288 288 }
289 289 else
290 290 {
291 291 PRINTF("in WFRM *** unexpected event")
292 292 }
293 293
294 294
295 295 #ifdef GSA
296 296 // irq processed, reset the related register of the timer unit
297 297 gptimer_regs->timer[TIMER_WF_SIMULATOR].ctrl = gptimer_regs->timer[TIMER_WF_SIMULATOR].ctrl | 0x00000010;
298 298 // clear the interruption
299 299 LEON_Unmask_interrupt( IRQ_WF );
300 300 #endif
301 301 }
302 302 }
303 303
304 304 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
305 305 {
306 306 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
307 307 *
308 308 * @param unused is the starting argument of the RTEMS task
309 309 *
310 310 * The following data packet is sent by this task:
311 311 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
312 312 *
313 313 */
314 314
315 315 rtems_event_set event_out;
316 316 rtems_id queue_id;
317 317
318 318 init_header_continuous_wf_table( SID_NORM_CWF_F3, headerCWF_F3 );
319 319 init_header_continuous_wf3_light_table( headerCWF_F3_light );
320 320
321 321 queue_id = get_pkts_queue_id();
322 322
323 323 BOOT_PRINTF("in CWF3 ***\n")
324 324
325 325 while(1){
326 326 // wait for an RTEMS_EVENT
327 327 rtems_event_receive( RTEMS_EVENT_0,
328 328 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
329 329 PRINTF("send CWF F3 \n")
330 330 #ifdef GSA
331 331 #else
332 332 if (waveform_picker_regs->addr_data_f3 == (int) wf_cont_f3) {
333 333 send_waveform_CWF3_light( wf_cont_f3_bis, headerCWF_F3_light, queue_id );
334 334 }
335 335 else {
336 336 send_waveform_CWF3_light( wf_cont_f3, headerCWF_F3_light, queue_id );
337 337 }
338 338 #endif
339 339 }
340 340 }
341 341
342 342 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
343 343 {
344 344 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
345 345 *
346 346 * @param unused is the starting argument of the RTEMS task
347 347 *
348 348 * The following data packet is sent by this function:
349 349 * - TM_LFR_SCIENCE_BURST_CWF_F2
350 350 * - TM_LFR_SCIENCE_SBM2_CWF_F2
351 351 *
352 352 */
353 353
354 354 rtems_event_set event_out;
355 355 rtems_id queue_id;
356 356
357 357 init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST );
358 358 init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 );
359 359
360 360 queue_id = get_pkts_queue_id();
361 361
362 362 BOOT_PRINTF("in CWF2 ***\n")
363 363
364 364 while(1){
365 365 // wait for an RTEMS_EVENT
366 366 rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2,
367 367 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
368 368
369 369 if (event_out == RTEMS_EVENT_MODE_BURST)
370 370 {
371 371 // F2
372 372 #ifdef GSA
373 373 #else
374 374 if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
375 375 send_waveform_CWF( wf_snap_f2_bis, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
376 376 }
377 377 else {
378 378 send_waveform_CWF( wf_snap_f2, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id );
379 379 }
380 380 #endif
381 381 }
382 382
383 383 else if (event_out == RTEMS_EVENT_MODE_SBM2)
384 384 {
385 385 #ifdef GSA
386 386 #else
387 387 if (doubleSendCWF2 == 1)
388 388 {
389 389 doubleSendCWF2 = 0;
390 390 send_waveform_CWF( wf_snap_f2_norm, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
391 391 }
392 392 else if (waveform_picker_regs->addr_data_f2 == (int) wf_snap_f2) {
393 393 send_waveform_CWF( wf_snap_f2_bis, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
394 394 }
395 395 else {
396 396 send_waveform_CWF( wf_snap_f2, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id );
397 397 }
398 398 param_local.local_sbm2_nb_cwf_sent ++;
399 399 #endif
400 400 }
401 401 else
402 402 {
403 403 PRINTF1("in CWF2 *** ERR mode = %d\n", lfrCurrentMode)
404 404 }
405 405 }
406 406 }
407 407
408 408 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
409 409 {
410 410 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
411 411 *
412 412 * @param unused is the starting argument of the RTEMS task
413 413 *
414 414 * The following data packet is sent by this function:
415 415 * - TM_LFR_SCIENCE_SBM1_CWF_F1
416 416 *
417 417 */
418 418
419 419 rtems_event_set event_out;
420 420 rtems_id queue_id;
421 421
422 422 init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 );
423 423
424 424 queue_id = get_pkts_queue_id();
425 425
426 426 BOOT_PRINTF("in CWF1 ***\n")
427 427
428 428 while(1){
429 429 // wait for an RTEMS_EVENT
430 430 rtems_event_receive( RTEMS_EVENT_MODE_SBM1,
431 431 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
432 432 if (event_out == RTEMS_EVENT_MODE_SBM1)
433 433 {
434 434 #ifdef GSA
435 435 #else
436 436 if (doubleSendCWF1 == 1)
437 437 {
438 438 doubleSendCWF1 = 0;
439 439 send_waveform_CWF( wf_snap_f1_norm, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
440 440 }
441 441 else if (waveform_picker_regs->addr_data_f1 == (int) wf_snap_f1) {
442 442 send_waveform_CWF( wf_snap_f1_bis, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
443 443 }
444 444 else {
445 445 send_waveform_CWF( wf_snap_f1, SID_SBM1_CWF_F1, headerCWF_F1, queue_id );
446 446 }
447 447 param_local.local_sbm1_nb_cwf_sent ++;
448 448 #endif
449 449 }
450 450 else
451 451 {
452 452 PRINTF1("in CWF1 *** ERR mode = %d\n", lfrCurrentMode)
453 453 }
454 454 }
455 455 }
456 456
457 457 //******************
458 458 // general functions
459 459 void init_waveforms( void )
460 460 {
461 461 int i = 0;
462 462
463 463 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
464 464 {
465 465 //***
466 466 // F0
467 467 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x88887777; //
468 468 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111; //
469 469 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0x44443333; //
470 470
471 471 //***
472 472 // F1
473 473 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x22221111;
474 474 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x44443333;
475 475 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
476 476
477 477 //***
478 478 // F2
479 479 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x44443333;
480 480 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111;
481 481 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
482 482
483 483 //***
484 484 // F3
485 485 //wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 0 ] = val1;
486 486 //wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 1 ] = val2;
487 487 //wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 2 ] = 0xaaaa0000;
488 488 }
489 489 }
490 490
491 491 int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF)
492 492 {
493 493 unsigned char i;
494 494
495 495 for (i=0; i<7; i++)
496 496 {
497 497 headerSWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
498 498 headerSWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
499 499 headerSWF[ i ].reserved = DEFAULT_RESERVED;
500 500 headerSWF[ i ].userApplication = CCSDS_USER_APP;
501 501 headerSWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
502 502 headerSWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
503 503 if (i == 0)
504 504 {
505 505 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_FIRST;
506 506 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_340 >> 8);
507 507 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_340 );
508 508 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8);
509 509 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 );
510 510 }
511 511 else if (i == 6)
512 512 {
513 513 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_LAST;
514 514 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_8 >> 8);
515 515 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_8 );
516 516 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_8 >> 8);
517 517 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_8 );
518 518 }
519 519 else
520 520 {
521 521 headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_CONTINUATION;
522 522 headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_340 >> 8);
523 523 headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_340 );
524 524 headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8);
525 525 headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 );
526 526 }
527 527 headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
528 528 headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT
529 529 headerSWF[ i ].pktNr = i+1; // PKT_NR
530 530 // DATA FIELD HEADER
531 531 headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
532 532 headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
533 533 headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
534 534 headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
535 535 // AUXILIARY DATA HEADER
536 536 headerSWF[ i ].time[0] = 0x00;
537 537 headerSWF[ i ].time[0] = 0x00;
538 538 headerSWF[ i ].time[0] = 0x00;
539 539 headerSWF[ i ].time[0] = 0x00;
540 540 headerSWF[ i ].time[0] = 0x00;
541 541 headerSWF[ i ].time[0] = 0x00;
542 542 headerSWF[ i ].sid = sid;
543 543 headerSWF[ i ].hkBIA = DEFAULT_HKBIA;
544 544 }
545 545 return LFR_SUCCESSFUL;
546 546 }
547 547
548 548 int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
549 549 {
550 550 unsigned int i;
551 551
552 552 for (i=0; i<7; i++)
553 553 {
554 554 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
555 555 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
556 556 headerCWF[ i ].reserved = DEFAULT_RESERVED;
557 557 headerCWF[ i ].userApplication = CCSDS_USER_APP;
558 558 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
559 559 {
560 560 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2 >> 8);
561 561 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_SBM1_SBM2);
562 562 }
563 563 else
564 564 {
565 565 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
566 566 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
567 567 }
568 568 if (i == 0)
569 569 {
570 570 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_FIRST;
571 571 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_340 >> 8);
572 572 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_340 );
573 573 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8);
574 574 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 );
575 575 }
576 576 else if (i == 6)
577 577 {
578 578 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_LAST;
579 579 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_8 >> 8);
580 580 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_8 );
581 581 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_8 >> 8);
582 582 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_8 );
583 583 }
584 584 else
585 585 {
586 586 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_CONTINUATION;
587 587 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_340 >> 8);
588 588 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_340 );
589 589 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8);
590 590 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 );
591 591 }
592 592 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
593 593 // PKT_CNT
594 594 // PKT_NR
595 595 // DATA FIELD HEADER
596 596 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
597 597 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
598 598 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
599 599 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
600 600 // AUXILIARY DATA HEADER
601 601 headerCWF[ i ].sid = sid;
602 602 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
603 603 headerCWF[ i ].time[0] = 0x00;
604 604 headerCWF[ i ].time[0] = 0x00;
605 605 headerCWF[ i ].time[0] = 0x00;
606 606 headerCWF[ i ].time[0] = 0x00;
607 607 headerCWF[ i ].time[0] = 0x00;
608 608 headerCWF[ i ].time[0] = 0x00;
609 609 }
610 610 return LFR_SUCCESSFUL;
611 611 }
612 612
613 613 int init_header_continuous_wf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF )
614 614 {
615 615 unsigned int i;
616 616
617 617 for (i=0; i<7; i++)
618 618 {
619 619 headerCWF[ i ].targetLogicalAddress = CCSDS_DESTINATION_ID;
620 620 headerCWF[ i ].protocolIdentifier = CCSDS_PROTOCOLE_ID;
621 621 headerCWF[ i ].reserved = DEFAULT_RESERVED;
622 622 headerCWF[ i ].userApplication = CCSDS_USER_APP;
623 623
624 624 headerCWF[ i ].packetID[0] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST >> 8);
625 625 headerCWF[ i ].packetID[1] = (unsigned char) (TM_PACKET_ID_SCIENCE_NORMAL_BURST);
626 626 if (i == 0)
627 627 {
628 628 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_FIRST;
629 629 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 >> 8);
630 630 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 );
631 631 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8);
632 632 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 );
633 633 }
634 634 else if (i == 6)
635 635 {
636 636 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_LAST;
637 637 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_8 >> 8);
638 638 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_8 );
639 639 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_8 >> 8);
640 640 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_8 );
641 641 }
642 642 else
643 643 {
644 644 headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_CONTINUATION;
645 645 headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 >> 8);
646 646 headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF3_LIGHT_340 );
647 647 headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_340 >> 8);
648 648 headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_340 );
649 649 }
650 650 headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
651 651 // DATA FIELD HEADER
652 652 headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
653 653 headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type
654 654 headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype
655 655 headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND;
656 656 // AUXILIARY DATA HEADER
657 657 headerCWF[ i ].sid = SID_NORM_CWF_F3;
658 658 headerCWF[ i ].hkBIA = DEFAULT_HKBIA;
659 659 headerCWF[ i ].time[0] = 0x00;
660 660 headerCWF[ i ].time[0] = 0x00;
661 661 headerCWF[ i ].time[0] = 0x00;
662 662 headerCWF[ i ].time[0] = 0x00;
663 663 headerCWF[ i ].time[0] = 0x00;
664 664 headerCWF[ i ].time[0] = 0x00;
665 665 }
666 666 return LFR_SUCCESSFUL;
667 667 }
668 668
669 669 void reset_waveforms( void )
670 670 {
671 671 int i = 0;
672 672
673 673 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
674 674 {
675 675 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x10002000;
676 676 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0x20001000;
677 677 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x40008000;
678 678
679 679 //***
680 680 // F1
681 681 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x1000f000;
682 682 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0xf0001000;
683 683 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x40008000;
684 684
685 685 //***
686 686 // F2
687 687 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x40008000;
688 688 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0x20001000;
689 689 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x10002000;
690 690
691 691 //***
692 692 // F3
693 693 /*wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = build_value( i, i ); // v and 1
694 694 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = build_value( i, i ); // e2 and b1
695 695 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = build_value( i, i ); // b2 and b3*/
696 696 }
697 697 }
698 698
699 699 int send_waveform_SWF( volatile int *waveform, unsigned int sid,
700 700 Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id )
701 701 {
702 702 /** This function sends SWF CCSDS packets (F2, F1 or F0).
703 703 *
704 704 * @param waveform points to the buffer containing the data that will be send.
705 705 * @param sid is the source identifier of the data that will be sent.
706 706 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
707 707 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
708 708 * contain information to setup the transmission of the data packets.
709 709 *
710 710 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
711 711 *
712 712 */
713 713
714 714 unsigned int i;
715 715 int ret;
716 716 rtems_status_code status;
717 717 spw_ioctl_pkt_send spw_ioctl_send_SWF;
718 718
719 719 spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header
720 720 spw_ioctl_send_SWF.options = 0;
721 721
722 722 ret = LFR_DEFAULT;
723 723
724 724 for (i=0; i<7; i++) // send waveform
725 725 {
726 726 spw_ioctl_send_SWF.data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ];
727 727 spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ];
728 728 // BUILD THE DATA
729 729 if (i==6) {
730 730 spw_ioctl_send_SWF.dlen = 8 * NB_BYTES_SWF_BLK;
731 731 }
732 732 else {
733 733 spw_ioctl_send_SWF.dlen = 340 * NB_BYTES_SWF_BLK;
734 734 }
735 735 // SET PACKET SEQUENCE COUNTER
736 736 increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid );
737 737 // SET PACKET TIME
738 738 headerSWF[ i ].acquisitionTime[0] = (unsigned char) (time_management_regs->coarse_time>>24);
739 739 headerSWF[ i ].acquisitionTime[1] = (unsigned char) (time_management_regs->coarse_time>>16);
740 740 headerSWF[ i ].acquisitionTime[2] = (unsigned char) (time_management_regs->coarse_time>>8);
741 741 headerSWF[ i ].acquisitionTime[3] = (unsigned char) (time_management_regs->coarse_time);
742 742 headerSWF[ i ].acquisitionTime[4] = (unsigned char) (time_management_regs->fine_time>>8);
743 743 headerSWF[ i ].acquisitionTime[5] = (unsigned char) (time_management_regs->fine_time);
744 744 headerSWF[ i ].time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
745 745 headerSWF[ i ].time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
746 746 headerSWF[ i ].time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
747 747 headerSWF[ i ].time[3] = (unsigned char) (time_management_regs->coarse_time);
748 748 headerSWF[ i ].time[4] = (unsigned char) (time_management_regs->fine_time>>8);
749 749 headerSWF[ i ].time[5] = (unsigned char) (time_management_regs->fine_time);
750 750 // SEND PACKET
751 751 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE);
752 752 if (status != RTEMS_SUCCESSFUL) {
753 753 printf("%d-%d, ERR %d\n", sid, i, (int) status);
754 754 ret = LFR_DEFAULT;
755 755 }
756 756 rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds
757 757 }
758 758
759 759 return ret;
760 760 }
761 761
762 762 int send_waveform_CWF(volatile int *waveform, unsigned int sid,
763 763 Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
764 764 {
765 765 /** This function sends CWF CCSDS packets (F2, F1 or F0).
766 766 *
767 767 * @param waveform points to the buffer containing the data that will be send.
768 768 * @param sid is the source identifier of the data that will be sent.
769 769 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
770 770 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
771 771 * contain information to setup the transmission of the data packets.
772 772 *
773 773 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
774 774 *
775 775 */
776 776
777 777 unsigned int i;
778 778 int ret;
779 779 rtems_status_code status;
780 780 spw_ioctl_pkt_send spw_ioctl_send_CWF;
781 781
782 782 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
783 783 spw_ioctl_send_CWF.options = 0;
784 784
785 785 ret = LFR_DEFAULT;
786 786
787 787 for (i=0; i<7; i++) // send waveform
788 788 {
789 789 int coarseTime = 0x00;
790 790 int fineTime = 0x00;
791 791 spw_ioctl_send_CWF.data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ];
792 792 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
793 793 // BUILD THE DATA
794 794 if (i==6) {
795 795 spw_ioctl_send_CWF.dlen = 8 * NB_BYTES_SWF_BLK;
796 796 }
797 797 else {
798 798 spw_ioctl_send_CWF.dlen = 340 * NB_BYTES_SWF_BLK;
799 799 }
800 800 // SET PACKET SEQUENCE COUNTER
801 801 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, sid );
802 802 // SET PACKET TIME
803 803 coarseTime = time_management_regs->coarse_time;
804 804 fineTime = time_management_regs->fine_time;
805 805 headerCWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime>>24);
806 806 headerCWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime>>16);
807 807 headerCWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime>>8);
808 808 headerCWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime);
809 809 headerCWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime>>8);
810 810 headerCWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime);
811 811 headerCWF[ i ].time[0] = (unsigned char) (coarseTime>>24);
812 812 headerCWF[ i ].time[1] = (unsigned char) (coarseTime>>16);
813 813 headerCWF[ i ].time[2] = (unsigned char) (coarseTime>>8);
814 814 headerCWF[ i ].time[3] = (unsigned char) (coarseTime);
815 815 headerCWF[ i ].time[4] = (unsigned char) (fineTime>>8);
816 816 headerCWF[ i ].time[5] = (unsigned char) (fineTime);
817 817 // SEND PACKET
818 818 if (sid == SID_NORM_CWF_F3)
819 819 {
820 820 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
821 821 if (status != RTEMS_SUCCESSFUL) {
822 822 printf("%d-%d, ERR %d\n", sid, i, (int) status);
823 823 ret = LFR_DEFAULT;
824 824 }
825 825 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
826 826 }
827 827 else
828 828 {
829 829 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
830 830 if (status != RTEMS_SUCCESSFUL) {
831 831 printf("%d-%d, ERR %d\n", sid, i, (int) status);
832 832 ret = LFR_DEFAULT;
833 833 }
834 834 }
835 835 }
836 836
837 837 return ret;
838 838 }
839 839
840 840 int send_waveform_CWF3_light(volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id)
841 841 {
842 842 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
843 843 *
844 844 * @param waveform points to the buffer containing the data that will be send.
845 845 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
846 846 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
847 847 * contain information to setup the transmission of the data packets.
848 848 *
849 849 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
850 850 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
851 851 *
852 852 */
853 853
854 854 unsigned int i;
855 855 int ret;
856 856 rtems_status_code status;
857 857 spw_ioctl_pkt_send spw_ioctl_send_CWF;
858 858 char *sample;
859 859
860 860 spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header
861 861 spw_ioctl_send_CWF.options = 0;
862 862
863 863 ret = LFR_DEFAULT;
864 864
865 865 //**********************
866 866 // BUILD CWF3_light DATA
867 867 for ( i=0; i< 2048; i++)
868 868 {
869 869 sample = (char*) &waveform[ i * NB_WORDS_SWF_BLK ];
870 870 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ];
871 871 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ];
872 872 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ];
873 873 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ];
874 874 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ];
875 875 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ];
876 876 }
877 877
878 878 //*********************
879 879 // SEND CWF3_light DATA
880 880
881 881 for (i=0; i<7; i++) // send waveform
882 882 {
883 883 int coarseTime = 0x00;
884 884 int fineTime = 0x00;
885 885 spw_ioctl_send_CWF.data = (char*) &wf_cont_f3_light[ (i * 340 * NB_BYTES_CWF3_LIGHT_BLK) ];
886 886 spw_ioctl_send_CWF.hdr = (char*) &headerCWF[ i ];
887 887 // BUILD THE DATA
888 888 if ( i == WFRM_INDEX_OF_LAST_PACKET ) {
889 889 spw_ioctl_send_CWF.dlen = 8 * NB_BYTES_CWF3_LIGHT_BLK;
890 890 }
891 891 else {
892 892 spw_ioctl_send_CWF.dlen = 340 * NB_BYTES_CWF3_LIGHT_BLK;
893 893 }
894 894 // SET PACKET SEQUENCE COUNTER
895 895 increment_seq_counter_source_id( headerCWF[ i ].packetSequenceControl, SID_NORM_CWF_F3 );
896 896 // SET PACKET TIME
897 897 coarseTime = time_management_regs->coarse_time;
898 898 fineTime = time_management_regs->fine_time;
899 899 headerCWF[ i ].acquisitionTime[0] = (unsigned char) (coarseTime>>24);
900 900 headerCWF[ i ].acquisitionTime[1] = (unsigned char) (coarseTime>>16);
901 901 headerCWF[ i ].acquisitionTime[2] = (unsigned char) (coarseTime>>8);
902 902 headerCWF[ i ].acquisitionTime[3] = (unsigned char) (coarseTime);
903 903 headerCWF[ i ].acquisitionTime[4] = (unsigned char) (fineTime>>8);
904 904 headerCWF[ i ].acquisitionTime[5] = (unsigned char) (fineTime);
905 905 headerCWF[ i ].time[0] = (unsigned char) (coarseTime>>24);
906 906 headerCWF[ i ].time[1] = (unsigned char) (coarseTime>>16);
907 907 headerCWF[ i ].time[2] = (unsigned char) (coarseTime>>8);
908 908 headerCWF[ i ].time[3] = (unsigned char) (coarseTime);
909 909 headerCWF[ i ].time[4] = (unsigned char) (fineTime>>8);
910 910 headerCWF[ i ].time[5] = (unsigned char) (fineTime);
911 911 // SEND PACKET
912 912 status = rtems_message_queue_send( queue_id, &spw_ioctl_send_CWF, sizeof(spw_ioctl_send_CWF));
913 913 if (status != RTEMS_SUCCESSFUL) {
914 914 printf("%d-%d, ERR %d\n", SID_NORM_CWF_F3, i, (int) status);
915 915 ret = LFR_DEFAULT;
916 916 }
917 917 rtems_task_wake_after(TIME_BETWEEN_TWO_CWF3_PACKETS);
918 918 }
919 919
920 920 return ret;
921 921 }
922 922
923 923
924 924 //**************
925 925 // wfp registers
926 926 void set_wfp_data_shaping()
927 927 {
928 928 /** This function sets the data_shaping register of the waveform picker module.
929 929 *
930 930 * The value is read from one field of the parameter_dump_packet structure:\n
931 931 * bw_sp0_sp1_r0_r1
932 932 *
933 933 */
934 934
935 935 unsigned char data_shaping;
936 936
937 937 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
938 938 // waveform picker : [R1 R0 SP1 SP0 BW]
939 939
940 940 data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1;
941 941
942 942 #ifdef GSA
943 943 #else
944 944 waveform_picker_regs->data_shaping =
945 945 ( (data_shaping & 0x10) >> 4 ) // BW
946 946 + ( (data_shaping & 0x08) >> 2 ) // SP0
947 947 + ( (data_shaping & 0x04) ) // SP1
948 948 + ( (data_shaping & 0x02) << 2 ) // R0
949 949 + ( (data_shaping & 0x01) << 4 ); // R1
950 950 #endif
951 951 }
952 952
953 953 char set_wfp_delta_snapshot()
954 954 {
955 955 /** This function sets the delta_snapshot register of the waveform picker module.
956 956 *
957 957 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
958 958 * - sy_lfr_n_swf_p[0]
959 959 * - sy_lfr_n_swf_p[1]
960 960 *
961 961 */
962 962
963 963 char ret;
964 964 unsigned int delta_snapshot;
965 965 unsigned int aux;
966 966
967 967 aux = 0;
968 968 ret = LFR_DEFAULT;
969 969
970 970 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
971 971 + parameter_dump_packet.sy_lfr_n_swf_p[1];
972 972
973 973 #ifdef GSA
974 974 #else
975 975 if ( delta_snapshot < MIN_DELTA_SNAPSHOT )
976 976 {
977 977 aux = MIN_DELTA_SNAPSHOT;
978 978 ret = LFR_DEFAULT;
979 979 }
980 980 else
981 981 {
982 982 aux = delta_snapshot ;
983 983 ret = LFR_SUCCESSFUL;
984 984 }
985 985 waveform_picker_regs->delta_snapshot = aux - 1; // max 2 bytes
986 986 #endif
987 987
988 988 return ret;
989 989 }
990 990
991 991 void set_wfp_burst_enable_register( unsigned char mode)
992 992 {
993 993 /** This function sets the waveform picker burst_enable register depending on the mode.
994 994 *
995 995 * @param mode is the LFR mode to launch.
996 996 *
997 997 * The burst bits shall be before the enable bits.
998 998 *
999 999 */
1000 1000
1001 1001 #ifdef GSA
1002 1002 #else
1003 1003 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1004 1004 // the burst bits shall be set first, before the enable bits
1005 1005 switch(mode) {
1006 1006 case(LFR_MODE_NORMAL):
1007 1007 waveform_picker_regs->burst_enable = 0x00; // [0000 0000] no burst enable
1008 1008 waveform_picker_regs->burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0
1009 1009 break;
1010 1010 case(LFR_MODE_BURST):
1011 1011 waveform_picker_regs->burst_enable = 0x40; // [0100 0000] f2 burst enabled
1012 1012 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x04; // [0100] enable f2
1013 1013 break;
1014 1014 case(LFR_MODE_SBM1):
1015 1015 waveform_picker_regs->burst_enable = 0x20; // [0010 0000] f1 burst enabled
1016 1016 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1017 1017 break;
1018 1018 case(LFR_MODE_SBM2):
1019 1019 waveform_picker_regs->burst_enable = 0x40; // [0100 0000] f2 burst enabled
1020 1020 waveform_picker_regs->burst_enable = waveform_picker_regs->burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1021 1021 break;
1022 1022 default:
1023 1023 waveform_picker_regs->burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1024 1024 break;
1025 1025 }
1026 1026 #endif
1027 1027 }
1028 1028
1029 1029 void reset_wfp_burst_enable()
1030 1030 {
1031 1031 /** This function resets the waveform picker burst_enable register.
1032 1032 *
1033 1033 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1034 1034 *
1035 1035 */
1036 1036
1037 1037 #ifdef GSA
1038 1038 #else
1039 1039 waveform_picker_regs->burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1040 1040 #endif
1041 1041 }
1042 1042
1043 1043 void reset_wfp_status()
1044 1044 {
1045 1045 /** This function resets the waveform picker status register.
1046 1046 *
1047 1047 * All status bits are set to 0 [new_err full_err full].
1048 1048 *
1049 1049 */
1050 1050
1051 1051 #ifdef GSA
1052 1052 #else
1053 1053 waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
1054 1054 #endif
1055 1055 }
1056 1056
1057 1057 void reset_waveform_picker_regs()
1058 1058 {
1059 1059 /** This function resets the waveform picker module registers.
1060 1060 *
1061 1061 * The registers affected by this function are located at the following offset addresses:
1062 1062 * - 0x00 data_shaping
1063 1063 * - 0x04 burst_enable
1064 1064 * - 0x08 addr_data_f0
1065 1065 * - 0x0C addr_data_f1
1066 1066 * - 0x10 addr_data_f2
1067 1067 * - 0x14 addr_data_f3
1068 1068 * - 0x18 status
1069 1069 * - 0x1C delta_snapshot
1070 1070 * - 0x20 delta_f2_f1
1071 1071 * - 0x24 delta_f2_f0
1072 1072 * - 0x28 nb_burst
1073 1073 * - 0x2C nb_snapshot
1074 1074 *
1075 1075 */
1076 1076
1077 1077 #ifdef GSA
1078 1078 #else
1079 1079 reset_wfp_burst_enable();
1080 1080 reset_wfp_status();
1081 1081 // set buffer addresses
1082 1082 waveform_picker_regs->addr_data_f0 = (int) (wf_snap_f0); //
1083 1083 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); //
1084 1084 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); //
1085 1085 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3); //
1086 1086 // set other parameters
1087 1087 set_wfp_data_shaping();
1088 1088 set_wfp_delta_snapshot(); // time in seconds between two snapshots
1089 1089 waveform_picker_regs->delta_f2_f1 = 0xffff; // 0x16800 => 92160 (max 4 bytes)
1090 1090 waveform_picker_regs->delta_f2_f0 = 0x17c00; // 97 280 (max 5 bytes)
1091 1091 waveform_picker_regs->nb_burst_available = 0x180; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
1092 1092 waveform_picker_regs->nb_snapshot_param = 0x7ff; // max 3 octets, 2048 - 1
1093 1093 #endif
1094 1094 }
1095 1095
1096 1096 //*****************
1097 1097 // local parameters
1098 1098 void set_local_sbm1_nb_cwf_max()
1099 1099 {
1100 1100 /** This function sets the value of the sbm1_nb_cwf_max local parameter.
1101 1101 *
1102 1102 * The sbm1_nb_cwf_max parameter counts the number of CWF_F1 records that have been sent.\n
1103 1103 * This parameter is used to send CWF_F1 data as normal data when the SBM1 is active.\n\n
1104 1104 * (2 snapshots of 2048 points per seconds) * (period of the NORM snashots) - 8 s (duration of the f2 snapshot)
1105 1105 *
1106 1106 */
1107 1107 param_local.local_sbm1_nb_cwf_max = 2 *
1108 1108 (parameter_dump_packet.sy_lfr_n_swf_p[0] * 256
1109 1109 + parameter_dump_packet.sy_lfr_n_swf_p[1]) - 8; // 16 CWF1 parts during 1 SWF2
1110 1110 }
1111 1111
1112 1112 void set_local_sbm2_nb_cwf_max()
1113 1113 {
1114 1114 /** This function sets the value of the sbm1_nb_cwf_max local parameter.
1115 1115 *
1116 1116 * The sbm1_nb_cwf_max parameter counts the number of CWF_F1 records that have been sent.\n
1117 1117 * This parameter is used to send CWF_F2 data as normal data when the SBM2 is active.\n\n
1118 1118 * (period of the NORM snashots) / (8 seconds per snapshot at f2 = 256 Hz)
1119 1119 *
1120 1120 */
1121 1121
1122 1122 param_local.local_sbm2_nb_cwf_max = (parameter_dump_packet.sy_lfr_n_swf_p[0] * 256
1123 1123 + parameter_dump_packet.sy_lfr_n_swf_p[1]) / 8;
1124 1124 }
1125 1125
1126 1126 void set_local_nb_interrupt_f0_MAX()
1127 1127 {
1128 1128 /** This function sets the value of the nb_interrupt_f0_MAX local parameter.
1129 1129 *
1130 1130 * This parameter is used for the SM validation only.\n
1131 1131 * The software waits param_local.local_nb_interrupt_f0_MAX interruptions from the spectral matrices
1132 1132 * module before launching a basic processing.
1133 1133 *
1134 1134 */
1135 1135
1136 1136 param_local.local_nb_interrupt_f0_MAX = ( (parameter_dump_packet.sy_lfr_n_asm_p[0]) * 256
1137 1137 + parameter_dump_packet.sy_lfr_n_asm_p[1] ) * 100;
1138 1138 }
1139 1139
1140 1140 void reset_local_sbm1_nb_cwf_sent()
1141 1141 {
1142 1142 /** This function resets the value of the sbm1_nb_cwf_sent local parameter.
1143 1143 *
1144 1144 * The sbm1_nb_cwf_sent parameter counts the number of CWF_F1 records that have been sent.\n
1145 1145 * This parameter is used to send CWF_F1 data as normal data when the SBM1 is active.
1146 1146 *
1147 1147 */
1148 1148
1149 1149 param_local.local_sbm1_nb_cwf_sent = 0;
1150 1150 }
1151 1151
1152 1152 void reset_local_sbm2_nb_cwf_sent()
1153 1153 {
1154 1154 /** This function resets the value of the sbm2_nb_cwf_sent local parameter.
1155 1155 *
1156 1156 * The sbm2_nb_cwf_sent parameter counts the number of CWF_F2 records that have been sent.\n
1157 1157 * This parameter is used to send CWF_F2 data as normal data when the SBM2 mode is active.
1158 1158 *
1159 1159 */
1160 1160
1161 1161 param_local.local_sbm2_nb_cwf_sent = 0;
1162 1162 }
1163 1163
1164 1164 rtems_id get_pkts_queue_id( void )
1165 1165 {
1166 1166 rtems_id queue_id;
1167 1167 rtems_status_code status;
1168 1168 rtems_name queue_send_name;
1169 1169
1170 1170 queue_send_name = rtems_build_name( 'Q', '_', 'S', 'D' );
1171 1171
1172 1172 status = rtems_message_queue_ident( queue_send_name, 0, &queue_id );
1173 1173 if (status != RTEMS_SUCCESSFUL)
1174 1174 {
1175 1175 PRINTF1("in get_pkts_queue_id *** ERR %d\n", status)
1176 1176 }
1177 1177 return queue_id;
1178 1178 }
1179 1179
1180 1180 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1181 1181 {
1182 1182 unsigned short *sequence_cnt;
1183 1183 unsigned short segmentation_grouping_flag;
1184 1184 unsigned short new_packet_sequence_control;
1185 1185
1186 if ( (sid ==SID_NORM_SWF_F0) || (sid ==SID_NORM_SWF_F1) || (sid ==SID_NORM_SWF_F2)
1187 || (sid ==SID_BURST_CWF_F2) )
1186 if ( (sid ==SID_NORM_SWF_F0) || (sid ==SID_NORM_SWF_F1) || (sid ==SID_NORM_SWF_F2)
1187 || (sid ==SID_NORM_CWF_F3) || (sid ==SID_BURST_CWF_F2) )
1188 1188 {
1189 1189 sequence_cnt = &sequenceCounters_SCIENCE_NORMAL_BURST;
1190 1190 }
1191 1191 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) )
1192 1192 {
1193 1193 sequence_cnt = &sequenceCounters_SCIENCE_SBM1_SBM2;
1194 1194 }
1195 1195 else
1196 1196 {
1197 1197 sequence_cnt = &sequenceCounters_TC_EXE[ UNKNOWN ];
1198 1198 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1199 1199 }
1200 1200
1201 1201 segmentation_grouping_flag = (packet_sequence_control[ 0 ] & 0xc0) << 8;
1202 1202 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1203 1203
1204 1204 new_packet_sequence_control = segmentation_grouping_flag | *sequence_cnt ;
1205 1205
1206 1206 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1207 1207 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1208 1208
1209 1209 // increment the seuqence counter for the next packet
1210 1210 if ( *sequence_cnt < SEQ_CNT_MAX)
1211 1211 {
1212 1212 *sequence_cnt = *sequence_cnt + 1;
1213 1213 }
1214 1214 else
1215 1215 {
1216 1216 *sequence_cnt = 0;
1217 1217 }
1218 1218
1219 1219 }
General Comments 0
You need to be logged in to leave comments. Login now