##// 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 PRIN