@@ -0,0 +1,41 | |||
|
1 | #ifndef TIMEGEN_INIT_H_INCLUDED | |
|
2 | #define TIMEGEN_INIT_H_INCLUDED | |
|
3 | ||
|
4 | #include <rtems.h> | |
|
5 | #include <leon.h> | |
|
6 | ||
|
7 | #include "fsw_params.h" | |
|
8 | #include "fsw_misc.h" | |
|
9 | #include "fsw_processing.h" | |
|
10 | #include "wf_handler.h" | |
|
11 | ||
|
12 | #include "timegen_spacewire.h" | |
|
13 | #include "timegen_misc.h" | |
|
14 | ||
|
15 | extern rtems_name Task_name[20]; /* array of task names */ | |
|
16 | extern rtems_id Task_id[20]; /* array of task ids */ | |
|
17 | ||
|
18 | // RTEMS TASKS | |
|
19 | rtems_task Init( rtems_task_argument argument); | |
|
20 | ||
|
21 | // OTHER functions | |
|
22 | void create_names( void ); | |
|
23 | int create_all_tasks( void ); | |
|
24 | int start_all_tasks( void ); | |
|
25 | // | |
|
26 | rtems_status_code create_message_queues( void ); | |
|
27 | rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); | |
|
28 | rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); | |
|
29 | // | |
|
30 | int start_recv_send_tasks( void ); | |
|
31 | // | |
|
32 | void init_local_mode_parameters( void ); | |
|
33 | void reset_local_time( void ); | |
|
34 | ||
|
35 | extern int rtems_cpu_usage_report( void ); | |
|
36 | extern int rtems_cpu_usage_reset( void ); | |
|
37 | extern void rtems_stack_checker_report_usage( void ); | |
|
38 | ||
|
39 | extern int sched_yield( void ); | |
|
40 | ||
|
41 | #endif // TIMEGEN_INIT_H_INCLUDED |
@@ -0,0 +1,39 | |||
|
1 | #ifndef TIMEGEN_MISC_H_INCLUDED | |
|
2 | #define TIMEGEN_MISC_H_INCLUDED | |
|
3 | ||
|
4 | #include <rtems.h> | |
|
5 | #include <leon.h> | |
|
6 | ||
|
7 | #include "fsw_params.h" | |
|
8 | #include "TC_types.h" | |
|
9 | #include "tc_acceptance.h" | |
|
10 | #include "timegen_init.h" | |
|
11 | ||
|
12 | #define TASK_PRIORITY_UPDT 40 | |
|
13 | ||
|
14 | typedef struct { | |
|
15 | unsigned char targetLogicalAddress; | |
|
16 | unsigned char protocolIdentifier; | |
|
17 | unsigned char reserved; | |
|
18 | unsigned char userApplication; | |
|
19 | // PACKET HEADER | |
|
20 | Packet_TC_LFR_UPDATE_TIME_t update_time; | |
|
21 | } Packet_TC_LFR_UPDATE_TIME_WITH_OVERHEAD_t; | |
|
22 | ||
|
23 | unsigned int coarseTime; | |
|
24 | ||
|
25 | rtems_name rtems_name_updt; | |
|
26 | rtems_id rtems_id_updt; | |
|
27 | ||
|
28 | void timegen_timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); | |
|
29 | ||
|
30 | void initCoarseTime( void ); | |
|
31 | ||
|
32 | rtems_task updt_task( rtems_task_argument unused ); | |
|
33 | ||
|
34 | int send_tc_lfr_update_time( rtems_id queue_id ); | |
|
35 | ||
|
36 | #endif // TIMEGEN_MISC_H_INCLUDED | |
|
37 | ||
|
38 | ||
|
39 |
@@ -0,0 +1,48 | |||
|
1 | #ifndef TIMEGEN_SPACEWIRE_H_INCLUDED | |
|
2 | #define TIMEGEN_SPACEWIRE_H_INCLUDED | |
|
3 | ||
|
4 | #include <rtems.h> | |
|
5 | #include <grspw.h> | |
|
6 | ||
|
7 | #include <fcntl.h> // for O_RDWR | |
|
8 | #include <unistd.h> // for the read call | |
|
9 | #include <sys/ioctl.h> // for the ioctl call | |
|
10 | #include <errno.h> | |
|
11 | ||
|
12 | #include "fsw_params.h" | |
|
13 | #include "tc_acceptance.h" | |
|
14 | #include "timegen_tc_handler.h" | |
|
15 | ||
|
16 | #define DESTINATION_ID_LFR 0xfe | |
|
17 | #define DESTINATION_ID_DPU 0x01 | |
|
18 | #define SPACEWIRE_LINK_LFR 0x01 | |
|
19 | #define NODEADDR_TIMEGEN 0xfd | |
|
20 | ||
|
21 | extern rtems_id Task_id[20]; /* array of task ids */ | |
|
22 | extern int fdSPW; | |
|
23 | ||
|
24 | extern spw_stats spacewire_stats; | |
|
25 | extern spw_stats spacewire_stats_backup; | |
|
26 | ||
|
27 | // RTEMS TASK | |
|
28 | rtems_task spiq_task( rtems_task_argument argument ); | |
|
29 | rtems_task recv_task( rtems_task_argument unused ); | |
|
30 | rtems_task send_task( rtems_task_argument argument ); | |
|
31 | rtems_task wtdg_task( rtems_task_argument argument ); | |
|
32 | ||
|
33 | int spacewire_open_link( void ); | |
|
34 | int spacewire_start_link( int fd ); | |
|
35 | int spacewire_stop_start_link( int fd ); | |
|
36 | int spacewire_configure_link(int fd ); | |
|
37 | int spacewire_reset_link( void ); | |
|
38 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force | |
|
39 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable | |
|
40 | void spacewire_compute_stats_offsets( void ); | |
|
41 | void spacewire_update_statistics( void ); | |
|
42 | ||
|
43 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); | |
|
44 | rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ); | |
|
45 | ||
|
46 | void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc ); | |
|
47 | ||
|
48 | #endif // TIMEGEN_SPACEWIRE_H_INCLUDED |
@@ -0,0 +1,56 | |||
|
1 | #ifndef TIMEGEN_TC_HANDLER_H_INCLUDED | |
|
2 | #define TIMEGEN_TC_HANDLER_H_INCLUDED | |
|
3 | ||
|
4 | #include <rtems.h> | |
|
5 | #include <leon.h> | |
|
6 | ||
|
7 | #include "tc_load_dump_parameters.h" | |
|
8 | #include "tc_acceptance.h" | |
|
9 | #include "tm_lfr_tc_exe.h" | |
|
10 | ||
|
11 | // MODE PARAMETERS | |
|
12 | extern unsigned int maxCount; | |
|
13 | ||
|
14 | //**** | |
|
15 | // ISR | |
|
16 | rtems_isr commutation_isr1( rtems_vector_number vector ); | |
|
17 | rtems_isr commutation_isr2( rtems_vector_number vector ); | |
|
18 | ||
|
19 | //*********** | |
|
20 | // RTEMS TASK | |
|
21 | rtems_task actn_task( rtems_task_argument unused ); | |
|
22 | ||
|
23 | //*********** | |
|
24 | // TC ACTIONS | |
|
25 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); | |
|
26 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); | |
|
27 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); | |
|
28 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); | |
|
29 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); | |
|
30 | int action_update_time(ccsdsTelecommandPacket_t *TC); | |
|
31 | ||
|
32 | // mode transition | |
|
33 | int transition_validation(unsigned char requestedMode); | |
|
34 | int stop_current_mode( void ); | |
|
35 | int enter_mode(unsigned char mode); | |
|
36 | int restart_science_tasks(); | |
|
37 | int suspend_science_tasks(); | |
|
38 | void launch_waveform_picker( unsigned char mode ); | |
|
39 | void launch_spectral_matrix( unsigned char mode ); | |
|
40 | void set_irq_on_new_ready_matrix(unsigned char value ); | |
|
41 | void set_run_matrix_spectral( unsigned char value ); | |
|
42 | void launch_spectral_matrix_simu( unsigned char mode ); | |
|
43 | ||
|
44 | // other functions | |
|
45 | void updateLFRCurrentMode(); | |
|
46 | void update_last_TC_exe(ccsdsTelecommandPacket_t *TC ); | |
|
47 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC ); | |
|
48 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); | |
|
49 | ||
|
50 | extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); | |
|
51 | extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); | |
|
52 | ||
|
53 | #endif // TIMEGEN_TC_HANDLER_H_INCLUDED | |
|
54 | ||
|
55 | ||
|
56 |
@@ -0,0 +1,476 | |||
|
1 | /** This is the RTEMS initialization module. | |
|
2 | * | |
|
3 | * @file | |
|
4 | * @author P. LEROY | |
|
5 | * | |
|
6 | * This module contains two very different information: | |
|
7 | * - specific instructions to configure the compilation of the RTEMS executive | |
|
8 | * - functions related to the fligth softwre initialization, especially the INIT RTEMS task | |
|
9 | * | |
|
10 | */ | |
|
11 | ||
|
12 | //************************* | |
|
13 | // GPL reminder to be added | |
|
14 | //************************* | |
|
15 | ||
|
16 | #include <rtems.h> | |
|
17 | ||
|
18 | /* configuration information */ | |
|
19 | ||
|
20 | #define CONFIGURE_INIT | |
|
21 | ||
|
22 | #include <bsp.h> /* for device driver prototypes */ | |
|
23 | ||
|
24 | /* configuration information */ | |
|
25 | ||
|
26 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER | |
|
27 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER | |
|
28 | ||
|
29 | #define CONFIGURE_MAXIMUM_TASKS 20 | |
|
30 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE | |
|
31 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) | |
|
32 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 | |
|
33 | #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 | |
|
34 | #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) | |
|
35 | #define CONFIGURE_MAXIMUM_DRIVERS 16 | |
|
36 | #define CONFIGURE_MAXIMUM_PERIODS 5 | |
|
37 | #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s) | |
|
38 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 2 | |
|
39 | #ifdef PRINT_STACK_REPORT | |
|
40 | #define CONFIGURE_STACK_CHECKER_ENABLED | |
|
41 | #endif | |
|
42 | ||
|
43 | #include <rtems/confdefs.h> | |
|
44 | ||
|
45 | /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ | |
|
46 | #ifdef RTEMS_DRVMGR_STARTUP | |
|
47 | #ifdef LEON3 | |
|
48 | /* Add Timer and UART Driver */ | |
|
49 | #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER | |
|
50 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER | |
|
51 | #endif | |
|
52 | #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER | |
|
53 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART | |
|
54 | #endif | |
|
55 | #endif | |
|
56 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ | |
|
57 | #include <drvmgr/drvmgr_confdefs.h> | |
|
58 | #endif | |
|
59 | ||
|
60 | #include "timegen_init.h" | |
|
61 | #include "fsw_config.c" | |
|
62 | ||
|
63 | rtems_task Init( rtems_task_argument ignored ) | |
|
64 | { | |
|
65 | /** This is the RTEMS INIT taks, it the first task launched by the system. | |
|
66 | * | |
|
67 | * @param unused is the starting argument of the RTEMS task | |
|
68 | * | |
|
69 | * The INIT task create and run all other RTEMS tasks. | |
|
70 | * | |
|
71 | */ | |
|
72 | ||
|
73 | rtems_status_code status; | |
|
74 | rtems_status_code status_spw; | |
|
75 | ||
|
76 | // initCoarseTime(); | |
|
77 | ||
|
78 | // UART settings | |
|
79 | send_console_outputs_on_apbuart_port(); | |
|
80 | set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); | |
|
81 | enable_apbuart_transmitter(); | |
|
82 | DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") | |
|
83 | ||
|
84 | PRINTF("\n\n\n\n\n") | |
|
85 | PRINTF("*************************\n") | |
|
86 | PRINTF("** Time Generator **\n") | |
|
87 | PRINTF1("** %d.", SW_VERSION_N1) | |
|
88 | PRINTF1("%d.", SW_VERSION_N2) | |
|
89 | PRINTF1("%d.", SW_VERSION_N3) | |
|
90 | PRINTF1("%d **\n", SW_VERSION_N4) | |
|
91 | PRINTF("*************************\n") | |
|
92 | PRINTF("\n\n") | |
|
93 | ||
|
94 | // init_local_mode_parameters(); | |
|
95 | // init_housekeeping_parameters(); | |
|
96 | ||
|
97 | // updateLFRCurrentMode(); | |
|
98 | ||
|
99 | // BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode) | |
|
100 | ||
|
101 | create_names(); // create all names | |
|
102 | ||
|
103 | status = create_message_queues(); // create message queues | |
|
104 | if (status != RTEMS_SUCCESSFUL) | |
|
105 | { | |
|
106 | PRINTF1("in INIT *** ERR in create_message_queues, code %d", status) | |
|
107 | } | |
|
108 | ||
|
109 | status = create_all_tasks(); // create all tasks | |
|
110 | if (status != RTEMS_SUCCESSFUL) | |
|
111 | { | |
|
112 | PRINTF1("in INIT *** ERR in create_all_tasks, code %d", status) | |
|
113 | } | |
|
114 | ||
|
115 | // ************************** | |
|
116 | // <SPACEWIRE INITIALIZATION> | |
|
117 | grspw_timecode_callback = &timegen_timecode_irq_handler; | |
|
118 | ||
|
119 | status_spw = spacewire_open_link(); // (1) open the link | |
|
120 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
|
121 | { | |
|
122 | PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw ) | |
|
123 | } | |
|
124 | ||
|
125 | if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link | |
|
126 | { | |
|
127 | status_spw = spacewire_configure_link( fdSPW ); | |
|
128 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
|
129 | { | |
|
130 | PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw ) | |
|
131 | } | |
|
132 | } | |
|
133 | ||
|
134 | if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link | |
|
135 | { | |
|
136 | status_spw = spacewire_start_link( fdSPW ); | |
|
137 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
|
138 | { | |
|
139 | PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw ) | |
|
140 | } | |
|
141 | } | |
|
142 | // </SPACEWIRE INITIALIZATION> | |
|
143 | // *************************** | |
|
144 | ||
|
145 | status = start_all_tasks(); // start all tasks | |
|
146 | if (status != RTEMS_SUCCESSFUL) | |
|
147 | { | |
|
148 | PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status) | |
|
149 | } | |
|
150 | ||
|
151 | // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization | |
|
152 | status = start_recv_send_tasks(); | |
|
153 | if ( status != RTEMS_SUCCESSFUL ) | |
|
154 | { | |
|
155 | PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status ) | |
|
156 | } | |
|
157 | ||
|
158 | // suspend science tasks. they will be restarted later depending on the mode | |
|
159 | status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY) | |
|
160 | if (status != RTEMS_SUCCESSFUL) | |
|
161 | { | |
|
162 | PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status) | |
|
163 | } | |
|
164 | ||
|
165 | // if the spacewire link is not up then send an event to the SPIQ task for link recovery | |
|
166 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
|
167 | { | |
|
168 | status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ); | |
|
169 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
170 | PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status ) | |
|
171 | } | |
|
172 | } | |
|
173 | ||
|
174 | BOOT_PRINTF("delete INIT\n") | |
|
175 | ||
|
176 | status = rtems_task_delete(RTEMS_SELF); | |
|
177 | ||
|
178 | } | |
|
179 | ||
|
180 | void init_local_mode_parameters( void ) | |
|
181 | { | |
|
182 | /** This function initialize the param_local global variable with default values. | |
|
183 | * | |
|
184 | */ | |
|
185 | ||
|
186 | unsigned int i; | |
|
187 | ||
|
188 | // LOCAL PARAMETERS | |
|
189 | // set_local_nb_interrupt_f0_MAX(); | |
|
190 | ||
|
191 | BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) | |
|
192 | BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) | |
|
193 | BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX) | |
|
194 | ||
|
195 | // init sequence counters | |
|
196 | ||
|
197 | for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++) | |
|
198 | { | |
|
199 | sequenceCounters_TC_EXE[i] = 0x00; | |
|
200 | } | |
|
201 | sequenceCounters_SCIENCE_NORMAL_BURST = 0x00; | |
|
202 | sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00; | |
|
203 | } | |
|
204 | ||
|
205 | void create_names( void ) // create all names for tasks and queues | |
|
206 | { | |
|
207 | /** This function creates all RTEMS names used in the software for tasks and queues. | |
|
208 | * | |
|
209 | * @return RTEMS directive status codes: | |
|
210 | * - RTEMS_SUCCESSFUL - successful completion | |
|
211 | * | |
|
212 | */ | |
|
213 | ||
|
214 | // task names | |
|
215 | Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' ); | |
|
216 | Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' ); | |
|
217 | Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' ); | |
|
218 | Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' ); | |
|
219 | Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' ); | |
|
220 | Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' ); | |
|
221 | Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' ); | |
|
222 | Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' ); | |
|
223 | Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' ); | |
|
224 | Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' ); | |
|
225 | Task_name[TASKID_MATR] = rtems_build_name( 'M', 'A', 'T', 'R' ); | |
|
226 | Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' ); | |
|
227 | Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' ); | |
|
228 | Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' ); | |
|
229 | Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' ); | |
|
230 | Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' ); | |
|
231 | ||
|
232 | // TIMEGEN | |
|
233 | rtems_name_updt = rtems_build_name( 'U', 'P', 'D', 'T' ); | |
|
234 | ||
|
235 | // rate monotonic period names | |
|
236 | name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' ); | |
|
237 | ||
|
238 | misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' ); | |
|
239 | misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' ); | |
|
240 | } | |
|
241 | ||
|
242 | int create_all_tasks( void ) // create all tasks which run in the software | |
|
243 | { | |
|
244 | /** This function creates all RTEMS tasks used in the software. | |
|
245 | * | |
|
246 | * @return RTEMS directive status codes: | |
|
247 | * - RTEMS_SUCCESSFUL - task created successfully | |
|
248 | * - RTEMS_INVALID_ADDRESS - id is NULL | |
|
249 | * - RTEMS_INVALID_NAME - invalid task name | |
|
250 | * - RTEMS_INVALID_PRIORITY - invalid task priority | |
|
251 | * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured | |
|
252 | * - RTEMS_TOO_MANY - too many tasks created | |
|
253 | * - RTEMS_UNSATISFIED - not enough memory for stack/FP context | |
|
254 | * - RTEMS_TOO_MANY - too many global objects | |
|
255 | * | |
|
256 | */ | |
|
257 | ||
|
258 | rtems_status_code status; | |
|
259 | ||
|
260 | //********** | |
|
261 | // SPACEWIRE | |
|
262 | // RECV | |
|
263 | status = rtems_task_create( | |
|
264 | Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE, | |
|
265 | RTEMS_DEFAULT_MODES, | |
|
266 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV] | |
|
267 | ); | |
|
268 | if (status == RTEMS_SUCCESSFUL) // SEND | |
|
269 | { | |
|
270 | status = rtems_task_create( | |
|
271 | Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE, | |
|
272 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, | |
|
273 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND] | |
|
274 | ); | |
|
275 | } | |
|
276 | if (status == RTEMS_SUCCESSFUL) // WTDG | |
|
277 | { | |
|
278 | status = rtems_task_create( | |
|
279 | Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE, | |
|
280 | RTEMS_DEFAULT_MODES, | |
|
281 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG] | |
|
282 | ); | |
|
283 | } | |
|
284 | if (status == RTEMS_SUCCESSFUL) // ACTN | |
|
285 | { | |
|
286 | status = rtems_task_create( | |
|
287 | Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE, | |
|
288 | RTEMS_DEFAULT_MODES, | |
|
289 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN] | |
|
290 | ); | |
|
291 | } | |
|
292 | if (status == RTEMS_SUCCESSFUL) // SPIQ | |
|
293 | { | |
|
294 | status = rtems_task_create( | |
|
295 | Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE, | |
|
296 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, | |
|
297 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ] | |
|
298 | ); | |
|
299 | } | |
|
300 | ||
|
301 | //***** | |
|
302 | // MISC | |
|
303 | if (status == RTEMS_SUCCESSFUL) // STAT | |
|
304 | { | |
|
305 | status = rtems_task_create( | |
|
306 | Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE, | |
|
307 | RTEMS_DEFAULT_MODES, | |
|
308 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT] | |
|
309 | ); | |
|
310 | } | |
|
311 | if (status == RTEMS_SUCCESSFUL) // DUMB | |
|
312 | { | |
|
313 | status = rtems_task_create( | |
|
314 | Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE, | |
|
315 | RTEMS_DEFAULT_MODES, | |
|
316 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB] | |
|
317 | ); | |
|
318 | } | |
|
319 | if (status == RTEMS_SUCCESSFUL) // UPDT | |
|
320 | { | |
|
321 | status = rtems_task_create( | |
|
322 | rtems_name_updt, TASK_PRIORITY_UPDT, RTEMS_MINIMUM_STACK_SIZE, | |
|
323 | RTEMS_DEFAULT_MODES, | |
|
324 | RTEMS_DEFAULT_ATTRIBUTES, &rtems_id_updt | |
|
325 | ); | |
|
326 | } | |
|
327 | ||
|
328 | return status; | |
|
329 | } | |
|
330 | ||
|
331 | int start_recv_send_tasks( void ) | |
|
332 | { | |
|
333 | rtems_status_code status; | |
|
334 | ||
|
335 | status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 ); | |
|
336 | if (status!=RTEMS_SUCCESSFUL) { | |
|
337 | BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n") | |
|
338 | } | |
|
339 | ||
|
340 | if (status == RTEMS_SUCCESSFUL) // SEND | |
|
341 | { | |
|
342 | status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 ); | |
|
343 | if (status!=RTEMS_SUCCESSFUL) { | |
|
344 | BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n") | |
|
345 | } | |
|
346 | } | |
|
347 | ||
|
348 | return status; | |
|
349 | } | |
|
350 | ||
|
351 | int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS | |
|
352 | { | |
|
353 | /** This function starts all RTEMS tasks used in the software. | |
|
354 | * | |
|
355 | * @return RTEMS directive status codes: | |
|
356 | * - RTEMS_SUCCESSFUL - ask started successfully | |
|
357 | * - RTEMS_INVALID_ADDRESS - invalid task entry point | |
|
358 | * - RTEMS_INVALID_ID - invalid task id | |
|
359 | * - RTEMS_INCORRECT_STATE - task not in the dormant state | |
|
360 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task | |
|
361 | * | |
|
362 | */ | |
|
363 | // starts all the tasks fot eh flight software | |
|
364 | ||
|
365 | rtems_status_code status; | |
|
366 | ||
|
367 | //********** | |
|
368 | // SPACEWIRE | |
|
369 | status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 ); | |
|
370 | if (status!=RTEMS_SUCCESSFUL) { | |
|
371 | BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n") | |
|
372 | } | |
|
373 | ||
|
374 | if (status == RTEMS_SUCCESSFUL) // WTDG | |
|
375 | { | |
|
376 | status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 ); | |
|
377 | if (status!=RTEMS_SUCCESSFUL) { | |
|
378 | BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n") | |
|
379 | } | |
|
380 | } | |
|
381 | ||
|
382 | if (status == RTEMS_SUCCESSFUL) // ACTN | |
|
383 | { | |
|
384 | status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 ); | |
|
385 | if (status!=RTEMS_SUCCESSFUL) { | |
|
386 | BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n") | |
|
387 | } | |
|
388 | } | |
|
389 | ||
|
390 | //***** | |
|
391 | // MISC | |
|
392 | if (status == RTEMS_SUCCESSFUL) // DUMB | |
|
393 | { | |
|
394 | status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 ); | |
|
395 | if (status!=RTEMS_SUCCESSFUL) { | |
|
396 | BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") | |
|
397 | } | |
|
398 | } | |
|
399 | ||
|
400 | if (status == RTEMS_SUCCESSFUL) // STAT | |
|
401 | { | |
|
402 | status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 ); | |
|
403 | if (status!=RTEMS_SUCCESSFUL) { | |
|
404 | BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n") | |
|
405 | } | |
|
406 | } | |
|
407 | ||
|
408 | if (status == RTEMS_SUCCESSFUL) // UPDT | |
|
409 | { | |
|
410 | status = rtems_task_start( rtems_id_updt, updt_task, 1 ); | |
|
411 | if (status!=RTEMS_SUCCESSFUL) { | |
|
412 | BOOT_PRINTF("in INIT *** Error starting TASK_UPDT\n") | |
|
413 | } | |
|
414 | } | |
|
415 | ||
|
416 | return status; | |
|
417 | } | |
|
418 | ||
|
419 | rtems_status_code create_message_queues( void ) // create the two message queues used in the software | |
|
420 | { | |
|
421 | rtems_status_code status_recv; | |
|
422 | rtems_status_code status_send; | |
|
423 | rtems_status_code ret; | |
|
424 | rtems_id queue_id; | |
|
425 | ||
|
426 | // create the queue for handling valid TCs | |
|
427 | status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV], | |
|
428 | ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE, | |
|
429 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); | |
|
430 | if ( status_recv != RTEMS_SUCCESSFUL ) { | |
|
431 | PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv) | |
|
432 | } | |
|
433 | ||
|
434 | // create the queue for handling TM packet sending | |
|
435 | status_send = rtems_message_queue_create( misc_name[QUEUE_SEND], | |
|
436 | ACTION_MSG_PKTS_COUNT, ACTION_MSG_PKTS_MAX_SIZE, | |
|
437 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); | |
|
438 | if ( status_send != RTEMS_SUCCESSFUL ) { | |
|
439 | PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send) | |
|
440 | } | |
|
441 | ||
|
442 | if ( status_recv != RTEMS_SUCCESSFUL ) | |
|
443 | { | |
|
444 | ret = status_recv; | |
|
445 | } | |
|
446 | else | |
|
447 | { | |
|
448 | ret = status_send; | |
|
449 | } | |
|
450 | ||
|
451 | return ret; | |
|
452 | } | |
|
453 | ||
|
454 | rtems_status_code get_message_queue_id_send( rtems_id *queue_id ) | |
|
455 | { | |
|
456 | rtems_status_code status; | |
|
457 | rtems_name queue_name; | |
|
458 | ||
|
459 | queue_name = rtems_build_name( 'Q', '_', 'S', 'D' ); | |
|
460 | ||
|
461 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); | |
|
462 | ||
|
463 | return status; | |
|
464 | } | |
|
465 | ||
|
466 | rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ) | |
|
467 | { | |
|
468 | rtems_status_code status; | |
|
469 | rtems_name queue_name; | |
|
470 | ||
|
471 | queue_name = rtems_build_name( 'Q', '_', 'R', 'V' ); | |
|
472 | ||
|
473 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); | |
|
474 | ||
|
475 | return status; | |
|
476 | } |
@@ -0,0 +1,110 | |||
|
1 | /** Functions and tasks related to TeleCommand handling. | |
|
2 | * | |
|
3 | * @file | |
|
4 | * @author P. LEROY | |
|
5 | * | |
|
6 | * A group of functions to handle TeleCommands:\n | |
|
7 | * action launching\n | |
|
8 | * TC parsing\n | |
|
9 | * ... | |
|
10 | * | |
|
11 | */ | |
|
12 | ||
|
13 | #include "timegen_misc.h" | |
|
14 | #include <stdio.h> | |
|
15 | ||
|
16 | void timegen_timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) | |
|
17 | { | |
|
18 | struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; | |
|
19 | ||
|
20 | grgpio_regs->io_port_direction_register = | |
|
21 | grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled | |
|
22 | ||
|
23 | if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 ) | |
|
24 | { | |
|
25 | grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; | |
|
26 | } | |
|
27 | else | |
|
28 | { | |
|
29 | grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; | |
|
30 | } | |
|
31 | ||
|
32 | rtems_event_send( rtems_id_updt, RTEMS_EVENT_0 ); | |
|
33 | } | |
|
34 | ||
|
35 | void initCoarseTime() | |
|
36 | { | |
|
37 | coarseTime = 0x00; | |
|
38 | } | |
|
39 | ||
|
40 | rtems_task updt_task( rtems_task_argument unused ) | |
|
41 | { | |
|
42 | rtems_event_set event_out; | |
|
43 | rtems_id send_queue_id; | |
|
44 | ||
|
45 | get_message_queue_id_send( &send_queue_id ); | |
|
46 | ||
|
47 | BOOT_PRINTF("in UPDT *** waiting for SpaceWire ticks\n") | |
|
48 | ||
|
49 | while(1) | |
|
50 | { | |
|
51 | // wait for an RTEMS_EVENT | |
|
52 | rtems_event_receive( RTEMS_EVENT_0, | |
|
53 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
|
54 | // increment the coarse time | |
|
55 | coarseTime = coarseTime + 1; | |
|
56 | PRINTF2("next valid coarseTime = 0x%x *** %d s\n", coarseTime, coarseTime) | |
|
57 | rtems_task_wake_after(70); // 10 ms * 70 = 700 ms | |
|
58 | send_tc_lfr_update_time( send_queue_id ); | |
|
59 | } | |
|
60 | } | |
|
61 | ||
|
62 | int send_tc_lfr_update_time(rtems_id queue_id ) | |
|
63 | { | |
|
64 | ||
|
65 | rtems_status_code status; | |
|
66 | unsigned char messageSize; | |
|
67 | ||
|
68 | Packet_TC_LFR_UPDATE_TIME_WITH_OVERHEAD_t packet; | |
|
69 | unsigned char crcAsTwoBytes[2]; | |
|
70 | ||
|
71 | // OVERHEAD | |
|
72 | packet.targetLogicalAddress = DESTINATION_ID_LFR; | |
|
73 | packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
|
74 | packet.reserved = DEFAULT_RESERVED; | |
|
75 | packet.userApplication = CCSDS_USER_APP; | |
|
76 | ||
|
77 | // TIME PACKET | |
|
78 | packet.update_time.packetID[0] = (unsigned char) (TC_LFR_PACKET_ID >> 8); | |
|
79 | packet.update_time.packetID[1] = (unsigned char) (TC_LFR_PACKET_ID ); | |
|
80 | packet.update_time.packetSequenceControl[0] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL >> 8); | |
|
81 | packet.update_time.packetSequenceControl[1] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL ); | |
|
82 | packet.update_time.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME >> 8); | |
|
83 | packet.update_time.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME ); | |
|
84 | ||
|
85 | packet.update_time.ccsdsSecHeaderFlag_pusVersion_ack = 0x19; | |
|
86 | packet.update_time.serviceType = TC_TYPE_LFR_UPDATE_TIME; | |
|
87 | packet.update_time.serviceSubType = TC_SUBTYPE_UPDATE_TIME; | |
|
88 | packet.update_time.sourceID = SID_TC_RPW_INTERNAL; | |
|
89 | packet.update_time.cp_rpw_time[0] = (unsigned char) (coarseTime >> 24); | |
|
90 | packet.update_time.cp_rpw_time[1] = (unsigned char) (coarseTime >> 16); | |
|
91 | packet.update_time.cp_rpw_time[2] = (unsigned char) (coarseTime >> 8); | |
|
92 | packet.update_time.cp_rpw_time[3] = (unsigned char) (coarseTime); | |
|
93 | packet.update_time.cp_rpw_time[4] = 0; // fine time MSB | |
|
94 | packet.update_time.cp_rpw_time[5] = 0; // fine time LSB | |
|
95 | ||
|
96 | GetCRCAsTwoBytes((unsigned char*) &packet.update_time, crcAsTwoBytes, | |
|
97 | PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET - 2); | |
|
98 | packet.update_time.crc[0] = crcAsTwoBytes[0]; | |
|
99 | packet.update_time.crc[1] = crcAsTwoBytes[1]; | |
|
100 | ||
|
101 | messageSize = PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; | |
|
102 | ||
|
103 | // SEND DATA | |
|
104 | status = rtems_message_queue_send( queue_id, &packet, messageSize); | |
|
105 | if (status != RTEMS_SUCCESSFUL) { | |
|
106 | PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n") | |
|
107 | } | |
|
108 | ||
|
109 | return status; | |
|
110 | } |
This diff has been collapsed as it changes many lines, (601 lines changed) Show them Hide them | |||
@@ -0,0 +1,601 | |||
|
1 | /** Functions related to the SpaceWire interface. | |
|
2 | * | |
|
3 | * @file | |
|
4 | * @author P. LEROY | |
|
5 | * | |
|
6 | * A group of functions to handle SpaceWire transmissions: | |
|
7 | * - configuration of the SpaceWire link | |
|
8 | * - SpaceWire related interruption requests processing | |
|
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task | |
|
10 | * - reception of TeleCommands by a dedicated RTEMS task | |
|
11 | * | |
|
12 | */ | |
|
13 | ||
|
14 | #include "timegen_spacewire.h" | |
|
15 | ||
|
16 | rtems_name semq_name; | |
|
17 | rtems_id semq_id; | |
|
18 | ||
|
19 | //*********** | |
|
20 | // RTEMS TASK | |
|
21 | rtems_task spiq_task(rtems_task_argument unused) | |
|
22 | { | |
|
23 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. | |
|
24 | * | |
|
25 | * @param unused is the starting argument of the RTEMS task | |
|
26 | * | |
|
27 | */ | |
|
28 | ||
|
29 | rtems_event_set event_out; | |
|
30 | rtems_status_code status; | |
|
31 | int linkStatus; | |
|
32 | ||
|
33 | BOOT_PRINTF("in SPIQ *** \n") | |
|
34 | ||
|
35 | while(true){ | |
|
36 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT | |
|
37 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") | |
|
38 | ||
|
39 | // [0] SUSPEND RECV AND SEND TASKS | |
|
40 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); | |
|
41 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
42 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") | |
|
43 | } | |
|
44 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); | |
|
45 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
46 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") | |
|
47 | } | |
|
48 | ||
|
49 | // [1] CHECK THE LINK | |
|
50 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) | |
|
51 | if ( linkStatus != 5) { | |
|
52 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) | |
|
53 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
|
54 | } | |
|
55 | ||
|
56 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT | |
|
57 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) | |
|
58 | if ( linkStatus != 5 ) // [2.a] not in run state, reset the link | |
|
59 | { | |
|
60 | spacewire_compute_stats_offsets(); | |
|
61 | status = spacewire_reset_link( ); | |
|
62 | } | |
|
63 | else // [2.b] in run state, start the link | |
|
64 | { | |
|
65 | status = spacewire_stop_start_link( fdSPW ); // start the link | |
|
66 | if ( status != RTEMS_SUCCESSFUL) | |
|
67 | { | |
|
68 | PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status) | |
|
69 | } | |
|
70 | } | |
|
71 | ||
|
72 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS | |
|
73 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully | |
|
74 | { | |
|
75 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
|
76 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
77 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") | |
|
78 | } | |
|
79 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
|
80 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
81 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") | |
|
82 | } | |
|
83 | } | |
|
84 | else // [3.b] the link is not in run state, go in STANDBY mode | |
|
85 | { | |
|
86 | status = stop_current_mode(); | |
|
87 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
88 | PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status) | |
|
89 | } | |
|
90 | status = enter_mode( LFR_MODE_STANDBY ); | |
|
91 | if ( status != RTEMS_SUCCESSFUL ) { | |
|
92 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) | |
|
93 | } | |
|
94 | // wake the WTDG task up to wait for the link recovery | |
|
95 | status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); | |
|
96 | status = rtems_task_suspend( RTEMS_SELF ); | |
|
97 | } | |
|
98 | } | |
|
99 | } | |
|
100 | ||
|
101 | rtems_task recv_task( rtems_task_argument unused ) | |
|
102 | { | |
|
103 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. | |
|
104 | * | |
|
105 | * @param unused is the starting argument of the RTEMS task | |
|
106 | * | |
|
107 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: | |
|
108 | * 1. It reads the incoming data. | |
|
109 | * 2. Launches the acceptance procedure. | |
|
110 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. | |
|
111 | * | |
|
112 | */ | |
|
113 | ||
|
114 | int len; | |
|
115 | ccsdsTelecommandPacket_t currentTC; | |
|
116 | unsigned char computed_CRC[ 2 ]; | |
|
117 | unsigned char currentTC_LEN_RCV[ 2 ]; | |
|
118 | unsigned char destinationID; | |
|
119 | unsigned int currentTC_LEN_RCV_AsUnsignedInt; | |
|
120 | unsigned int parserCode; | |
|
121 | unsigned char time[6]; | |
|
122 | rtems_status_code status; | |
|
123 | rtems_id queue_recv_id; | |
|
124 | rtems_id queue_send_id; | |
|
125 | ||
|
126 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes | |
|
127 | ||
|
128 | status = get_message_queue_id_recv( &queue_recv_id ); | |
|
129 | if (status != RTEMS_SUCCESSFUL) | |
|
130 | { | |
|
131 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) | |
|
132 | } | |
|
133 | ||
|
134 | status = get_message_queue_id_send( &queue_send_id ); | |
|
135 | if (status != RTEMS_SUCCESSFUL) | |
|
136 | { | |
|
137 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) | |
|
138 | } | |
|
139 | ||
|
140 | BOOT_PRINTF("in RECV *** \n") | |
|
141 | ||
|
142 | while(1) | |
|
143 | { | |
|
144 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking | |
|
145 | if (len == -1){ // error during the read call | |
|
146 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) | |
|
147 | } | |
|
148 | else { | |
|
149 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { | |
|
150 | PRINTF("in RECV *** packet lenght too short\n") | |
|
151 | } | |
|
152 | else { | |
|
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 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8); | |
|
155 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt ); | |
|
156 | // CHECK THE TC | |
|
157 | parserCode = tc_parser( ¤tTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ; | |
|
158 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) | |
|
159 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) | |
|
160 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) | |
|
161 | || (parserCode == WRONG_SRC_ID) ) | |
|
162 | { // send TM_LFR_TC_EXE_CORRUPTED | |
|
163 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
|
164 | && | |
|
165 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
|
166 | ) | |
|
167 | { | |
|
168 | if ( parserCode == WRONG_SRC_ID ) | |
|
169 | { | |
|
170 | destinationID = SID_TC_GROUND; | |
|
171 | } | |
|
172 | else | |
|
173 | { | |
|
174 | destinationID = currentTC.sourceID; | |
|
175 | } | |
|
176 | getTime( time ); | |
|
177 | close_action( ¤tTC, LFR_DEFAULT, queue_send_id ); | |
|
178 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, | |
|
179 | computed_CRC, currentTC_LEN_RCV, | |
|
180 | destinationID ); | |
|
181 | } | |
|
182 | } | |
|
183 | else | |
|
184 | { // send valid TC to the action launcher | |
|
185 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, | |
|
186 | currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3); | |
|
187 | } | |
|
188 | } | |
|
189 | } | |
|
190 | } | |
|
191 | } | |
|
192 | ||
|
193 | rtems_task send_task( rtems_task_argument argument) | |
|
194 | { | |
|
195 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. | |
|
196 | * | |
|
197 | * @param unused is the starting argument of the RTEMS task | |
|
198 | * | |
|
199 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: | |
|
200 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. | |
|
201 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After | |
|
202 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the | |
|
203 | * data it contains. | |
|
204 | * | |
|
205 | */ | |
|
206 | ||
|
207 | rtems_status_code status; // RTEMS status code | |
|
208 | char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer | |
|
209 | size_t size; // size of the incoming TC packet | |
|
210 | u_int32_t count; | |
|
211 | rtems_id queue_id; | |
|
212 | ||
|
213 | status = get_message_queue_id_send( &queue_id ); | |
|
214 | if (status != RTEMS_SUCCESSFUL) | |
|
215 | { | |
|
216 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
|
217 | } | |
|
218 | ||
|
219 | BOOT_PRINTF("in SEND *** \n") | |
|
220 | ||
|
221 | while(1) | |
|
222 | { | |
|
223 | status = rtems_message_queue_receive( queue_id, incomingData, &size, | |
|
224 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); | |
|
225 | ||
|
226 | if (status!=RTEMS_SUCCESSFUL) | |
|
227 | { | |
|
228 | PRINTF1("in SEND *** (1) ERR = %d\n", status) | |
|
229 | } | |
|
230 | else | |
|
231 | { | |
|
232 | status = write( fdSPW, incomingData, size ); | |
|
233 | if (status == -1){ | |
|
234 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
|
235 | } | |
|
236 | } | |
|
237 | ||
|
238 | status = rtems_message_queue_get_number_pending( queue_id, &count ); | |
|
239 | if (status != RTEMS_SUCCESSFUL) | |
|
240 | { | |
|
241 | PRINTF1("in SEND *** (3) ERR = %d\n", status) | |
|
242 | } | |
|
243 | else | |
|
244 | { | |
|
245 | if (count > maxCount) | |
|
246 | { | |
|
247 | maxCount = count; | |
|
248 | } | |
|
249 | } | |
|
250 | } | |
|
251 | } | |
|
252 | ||
|
253 | rtems_task wtdg_task( rtems_task_argument argument ) | |
|
254 | { | |
|
255 | rtems_event_set event_out; | |
|
256 | rtems_status_code status; | |
|
257 | int linkStatus; | |
|
258 | ||
|
259 | BOOT_PRINTF("in WTDG ***\n") | |
|
260 | ||
|
261 | while(1) | |
|
262 | { | |
|
263 | // wait for an RTEMS_EVENT | |
|
264 | rtems_event_receive( RTEMS_EVENT_0, | |
|
265 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
|
266 | PRINTF("in WTDG *** wait for the link\n") | |
|
267 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
|
268 | while( linkStatus != 5) // wait for the link | |
|
269 | { | |
|
270 | rtems_task_wake_after( 10 ); | |
|
271 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
|
272 | } | |
|
273 | ||
|
274 | status = spacewire_stop_start_link( fdSPW ); | |
|
275 | ||
|
276 | if (status != RTEMS_SUCCESSFUL) | |
|
277 | { | |
|
278 | PRINTF1("in WTDG *** ERR link not started %d\n", status) | |
|
279 | } | |
|
280 | else | |
|
281 | { | |
|
282 | PRINTF("in WTDG *** OK link started\n") | |
|
283 | } | |
|