##// END OF EJS Templates
automatic reconnexion of the spacewire link...
paul@pc-solar1.lab-lpp.local -
r17:3a73d9962d4a default
parent child
Show More
@@ -2,45 +2,45
2 2 <CodeBlocks_layout_file>
3 3 <ActiveTarget name="Debug" />
4 4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
5 <Cursor position="384" topLine="87" />
5 <Cursor position="4971" topLine="100" />
6 6 </File>
7 7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="6">
8 <Cursor position="1133" topLine="22" />
8 <Cursor position="597" topLine="0" />
9 9 </File>
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
11 <Cursor position="545" topLine="0" />
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="3">
11 <Cursor position="279" topLine="0" />
12 12 </File>
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="2">
14 <Cursor position="1157" topLine="0" />
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="3">
14 <Cursor position="1416" topLine="31" />
15 15 </File>
16 16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
17 <Cursor position="628" topLine="7" />
17 <Cursor position="1216" topLine="5" />
18 18 </File>
19 19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
20 <Cursor position="1153" topLine="16" />
20 <Cursor position="444" topLine="0" />
21 21 </File>
22 22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
23 23 <Cursor position="1380" topLine="35" />
24 24 </File>
25 25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
26 <Cursor position="341" topLine="0" />
26 <Cursor position="316" topLine="0" />
27 27 </File>
28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="5">
29 <Cursor position="184" topLine="0" />
28 <File name="../src/fsw_globals.c" open="1" top="0" tabpos="3">
29 <Cursor position="1246" topLine="6" />
30 30 </File>
31 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
32 <Cursor position="12072" topLine="91" />
31 <File name="../src/fsw_init.c" open="1" top="1" tabpos="1">
32 <Cursor position="2317" topLine="59" />
33 33 </File>
34 <File name="../src/fsw_misc.c" open="1" top="1" tabpos="2">
35 <Cursor position="4309" topLine="44" />
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
35 <Cursor position="6076" topLine="0" />
36 36 </File>
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="0">
38 <Cursor position="20570" topLine="67" />
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="4">
38 <Cursor position="19048" topLine="64" />
39 39 </File>
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="2">
41 <Cursor position="15292" topLine="0" />
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="5">
41 <Cursor position="536" topLine="0" />
42 42 </File>
43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="4">
44 <Cursor position="2540" topLine="42" />
43 <File name="../src/wf_handler.c" open="1" top="0" tabpos="2">
44 <Cursor position="5858" topLine="70" />
45 45 </File>
46 46 </CodeBlocks_layout_file>
1 NO CONTENT: modified file, binary diff hidden
@@ -9,7 +9,11
9 9 #define CCSDS_PROCESS_ID 76
10 10 #define CCSDS_PACKET_CATEGORY 12
11 11 #define CCSDS_NODE_ADDRESS 0xfe
12 //
13 #define CCSDS_DESTINATION_ID_GROUND 0x00
12 14 #define CCSDS_DESTINATION_ID 0x01
15 #define CCSDS_DESTINATION_ID_DPU 0x01
16 //
13 17 #define CCSDS_PROTOCOLE_ID 0x02
14 18 #define CCSDS_USER_APP 0x00
15 19
@@ -47,6 +51,7
47 51 #define TC_SUBTYPE_UPDT_TIME 129
48 52
49 53 #define SID_DEFAULT 0
54 #define SID_HK 1
50 55 #define SID_EXE_INC 5
51 56 #define SID_NOT_EXE 40000
52 57 #define SID_NOT_IMP 40002
@@ -80,12 +85,21
80 85 #define SID_SBM1_BP1_F1 30
81 86 #define SID_SBM1_BP2_F1 33
82 87
88 // LENGTH (BYTES)
89 #define LENGTH_TM_LFR_HK 126
90 #define LENGTH_TM_LFR_TC_EXE_MAX 32
91 #define LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX 4102
92 //
83 93 #define TM_LEN_EXE 20 - CCSDS_TC_TM_PACKET_OFFSET
84 94 #define TM_LEN_NOT_EXE 26 - CCSDS_TC_TM_PACKET_OFFSET
85 95 #define TM_LEN_NOT_IMP 24 - CCSDS_TC_TM_PACKET_OFFSET
86 96 #define TM_LEN_EXE_ERR 24 - CCSDS_TC_TM_PACKET_OFFSET
87 97 #define TM_LEN_EXE_CORR 32 - CCSDS_TC_TM_PACKET_OFFSET
88 98 #define TM_HEADER_LEN 16
99
100 #define LEN_TM_LFR_HK 126 + 4
101 #define LEN_TM_LFR_TC_EXE_NOT_IMP 24 +4
102
89 103 #define TM_LEN_SCI_NORM_SWF_340 340 * 12 + 6 + 10 - 1
90 104 #define TM_LEN_SCI_NORM_SWF_8 8 * 12 + 6 + 10 - 1
91 105
@@ -111,6 +125,49 struct TMHeader_str
111 125 };
112 126 typedef struct TMHeader_str TMHeader_t;
113 127
128 struct Packet_TM_LFR_HK_str
129 {
130 volatile unsigned char targetLogicalAddress;
131 volatile unsigned char protocolIdentifier;
132 volatile unsigned char reserved;
133 volatile unsigned char userApplication;
134 volatile unsigned char packetID[2];
135 volatile unsigned char packetSequenceControl[2];
136 volatile unsigned char packetLength[2];
137 volatile unsigned char dataFieldHeader[10];
138 volatile unsigned char data[LENGTH_TM_LFR_HK - 10 + 1];
139 };
140 typedef struct Packet_TM_LFR_HK_str Packet_TM_LFR_HK_t;
141
142 struct Packet_TM_LFR_TC_EXE_str
143 {
144 volatile unsigned char targetLogicalAddress;
145 volatile unsigned char protocolIdentifier;
146 volatile unsigned char reserved;
147 volatile unsigned char userApplication;
148 volatile unsigned char packetID[2];
149 volatile unsigned char packetSequenceControl[2];
150 volatile unsigned char packetLength[2];
151 volatile unsigned char dataFieldHeader[10];
152 volatile unsigned char data[LENGTH_TM_LFR_TC_EXE_MAX - 10 + 1];
153 };
154 typedef struct Packet_TM_LFR_TC_EXE_str Packet_TM_LFR_TC_EXE_t;
155
156 struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str
157 {
158 volatile unsigned char targetLogicalAddress;
159 volatile unsigned char protocolIdentifier;
160 volatile unsigned char reserved;
161 volatile unsigned char userApplication;
162 volatile unsigned char packetID[2];
163 volatile unsigned char packetSequenceControl[2];
164 volatile unsigned char packetLength[2];
165 volatile unsigned char dataFieldHeader[10];
166 volatile unsigned char auxiliaryHeader[6];
167 volatile unsigned char data[LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX - 10 + 1];
168 };
169 typedef struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str Packet_TM_LFR_SCIENCE_NORMAL_WF_t;
170
114 171 struct ExtendedTMHeader_str
115 172 {
116 173 volatile unsigned char targetLogicalAddress;
@@ -39,6 +39,7 rtems_task recv_task(rtems_task_argument
39 39 rtems_task spiq_task(rtems_task_argument argument);
40 40 rtems_task stat_task(rtems_task_argument argument);
41 41 rtems_task wfrm_task(rtems_task_argument argument);
42 int create_names();
42 43 int create_all_tasks();
43 44 int start_all_tasks();
44 45 int create_message_queue();
@@ -10,10 +10,18
10 10 #include <grspw.h>
11 11 #include <ccsds_types.h>
12 12
13 rtems_name HK_name; /* name of the HK rate monotonic */
14 rtems_id HK_id; /* id of the HK rate monotonic period */
15
13 16 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
14 17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
15 18 void print_statistics(spw_stats *stats);
19
20 // SERIAL LINK
16 21 int send_console_outputs_on_serial_port();
22 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
23
24 // RTEMS TASKS
17 25 rtems_task stat_task(rtems_task_argument argument);
18 26 rtems_task hous_task(rtems_task_argument argument);
19 27
@@ -21,6 +21,7
21 21 #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700
22 22
23 23 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
24 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400
24 25
25 26 //**********
26 27 // IRQ LINES
@@ -56,12 +57,9
56 57
57 58 #define ACTION_MSG_QUEUE_COUNT 10
58 59
59 // LENGTH (BYTES)
60 #define LENGTH_TM_LFR_HK 126
61
62 60 //*******
63 61 // MACROS
64 //#define PRINT_TASK_STATISTICS
62 #define PRINT_TASK_STATISTICS
65 63 #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
66 64 #ifdef PRINT_MESSAGES_ON_CONSOLE
67 65 #define PRINTF(x) printf(x);
@@ -75,6 +73,7
75 73
76 74 #define NB_SAMPLES_PER_SNAPSHOT 2048
77 75 #define NB_BYTES_SWF_BLK 2 * 6
76 #define NB_WORDS_SWF_BLK 3
78 77
79 78 struct param_norm_str{
80 79 unsigned int sy_lfr_n_swf_l; // length of the snapshots
@@ -28,17 +28,18 typedef struct BP1_str BP1_t;
28 28
29 29 // ISR
30 30 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
31
31 32 // RTEMS TASKS
32 33 rtems_task spw_bppr_task(rtems_task_argument argument);
33 34 rtems_task avf0_task(rtems_task_argument argument);
34 35 rtems_task bpf0_task(rtems_task_argument argument);
35 36 rtems_task smiq_task(rtems_task_argument argument); // added to test the spectral matrix simulator
36 //
37
37 38 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument);
38 39 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat);
39 40 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat);
40 41 void matrix_reset(float *averaged_spec_mat);
41 42 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1);
42 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
43 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
43 44
44 45 #endif // FSW_RTEMS_PROCESSING_H_INCLUDED
@@ -17,4 +17,9 extern int fdSPW;
17 17 rtems_isr waveforms_isr( rtems_vector_number vector );
18 18 rtems_task wfrm_task(rtems_task_argument argument);
19 19
20 //******************
21 // general functions
22 void init_waveforms();
23 int buil_value(int value1, int value0);
24
20 25 #endif // WF_HANDLER_H_INCLUDED
@@ -40,8 +40,7 struct param_sbm2_str param_sbm2;
40 40 unsigned char param_common[2];
41 41
42 42 // HK PACKETS
43 TMHeader_t housekeeping_header;
44 char housekeeping_data[LENGTH_TM_LFR_HK - 10 + 1];
43 Packet_TM_LFR_HK_t housekeeping_packet;
45 44
46 45 // BASIC PARAMETERS GLOBAL VARIABLES
47 46 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
@@ -21,7 +21,7
21 21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
22 22 #define CONFIGURE_INIT_TASK_PRIORITY 100
23 23 #define CONFIGURE_MAXIMUM_DRIVERS 16
24 #define CONFIGURE_MAXIMUM_PERIODS 1
24 #define CONFIGURE_MAXIMUM_PERIODS 5
25 25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
26 26
27 27 #include <rtems/confdefs.h>
@@ -59,11 +59,20 rtems_task Init( rtems_task_argument ign
59 59 rtems_status_code status;
60 60 rtems_isr_entry old_isr_handler;
61 61
62 PRINTF("\n\n\n\n\n")
63 PRINTF("***************************\n")
64 PRINTF("** START Flight Software **\n")
65 PRINTF("***************************\n")
66 PRINTF("\n\n")
67
62 68 //send_console_outputs_on_serial_port();
69 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
63 70
64 71 initLookUpTableForCRC(); // in tc_handler.h
65 72 init_default_mode_parameters();
66 create_message_queue();
73 create_message_queue();
74
75 create_names();
67 76 create_all_tasks();
68 77 start_all_tasks();
69 78
@@ -71,6 +80,8 rtems_task Init( rtems_task_argument ign
71 80
72 81 configure_spw_link();
73 82
83 init_waveforms();
84
74 85 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
75 86 IRQ_SPARC_SM, spectral_matrices_isr );
76 87 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
@@ -81,13 +92,13 rtems_task Init( rtems_task_argument ign
81 92 IRQ_SPARC_TIME1,
82 93 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
83 94 if (status==RTEMS_SUCCESSFUL)
84 PRINTF("commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
95 PRINTF("OK *** commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
85 96
86 97 status = rtems_interrupt_catch( commutation_isr2,
87 98 IRQ_SPARC_TIME2,
88 99 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
89 100 if (status==RTEMS_SUCCESSFUL)
90 PRINTF("commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
101 PRINTF("OK *** commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
91 102
92 103 LEON_Unmask_interrupt( IRQ_TIME1 );
93 104 LEON_Unmask_interrupt( IRQ_TIME2 );
@@ -100,23 +111,25 rtems_task spiq_task(rtems_task_argument
100 111 rtems_event_set event_out;
101 112 struct grspw_regs_str *grspw_regs;
102 113 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
114 rtems_status_code status;
103 115
104 116 while(1){
105 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
117 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
106 118 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
107 119
108 120 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) // suspend RECV task
109 PRINTF("In SPIQ *** Error suspending RECV Task\n")
121 PRINTF("in SPIQ *** Error suspending RECV Task\n")
110 122 if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) // suspend HOUS task
111 PRINTF("In SPIQ *** Error suspending HOUS Task\n")
123 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
112 124
113 125 configure_spw_link();
126
127 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
128 if (status!=RTEMS_SUCCESSFUL)
129 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
114 130
115 131 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
116 PRINTF("In SPIQ *** Error resume RECV Task\n")
117 if (rtems_task_restart(Task_id[TASKID_HOUS], 1)!=RTEMS_SUCCESSFUL) // restart HOUS task
118 PRINTF("In SPIQ *** Error resume HOUS Task\n")
119
132 PRINTF("in SPIQ *** Error restarting RECV Task\n")
120 133 }
121 134 }
122 135
@@ -142,10 +155,9 void init_default_mode_parameters()
142 155 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
143 156 }
144 157
145 int create_all_tasks()
158 int create_names()
146 159 {
147 rtems_status_code status;
148
160 // task names
149 161 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
150 162 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
151 163 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
@@ -155,7 +167,17 int create_all_tasks()
155 167 Task_name[TASKID_BPF0] = rtems_build_name( 'B', 'P', 'F', '0' );
156 168 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
157 169 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
158 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
170 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
171
172 // rate monotonic period name
173 HK_name = rtems_build_name( 'H', 'O', 'U', 'S' );
174
175 return 0;
176 }
177
178 int create_all_tasks()
179 {
180 rtems_status_code status;
159 181
160 182 // RECV
161 183 status = rtems_task_create(
@@ -171,8 +193,8 int create_all_tasks()
171 193 );
172 194 // SPIQ
173 195 status = rtems_task_create(
174 Task_name[TASKID_SPIQ], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
175 RTEMS_DEFAULT_MODES,
196 Task_name[TASKID_SPIQ], 5, RTEMS_MINIMUM_STACK_SIZE * 2,
197 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
176 198 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
177 199 );
178 200 // SMIQ
@@ -213,7 +235,7 int create_all_tasks()
213 235 );
214 236 // HOUS
215 237 status = rtems_task_create(
216 Task_name[TASKID_HOUS], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
238 Task_name[TASKID_HOUS], 199, RTEMS_MINIMUM_STACK_SIZE * 2,
217 239 RTEMS_DEFAULT_MODES,
218 240 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_HOUS]
219 241 );
@@ -262,53 +284,43 int configure_spw_link()
262 284 {
263 285 rtems_status_code status;
264 286
265 close(fdSPW); // close the device if it is already open
287 close(fdSPW); // close the device if it is already open
288 PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
266 289 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
267 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
290 if (fdSPW<0) PRINTF("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
268 291 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
269 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
292 PRINTF(".")
293 fflush(stdout);
270 294 close(fdSPW); // close the device
271 295 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
272 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
296 if (fdSPW<0) PRINTF("ERR *** In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
273 297 rtems_task_wake_after(100);
274 298 }
275 299
276 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
277
278 // sets a few parameters of the link
279 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
280 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
300 PRINTF("OK *** In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
281 301
282 302 configure_spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
283 303 configure_spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
284 304
285 305 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
286 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
306 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
287 307 //
288 308 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
289 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
309 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
290 310 //
291 311 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
292 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
312 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
293 313 //
294 314 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
295 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
315 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
296 316 //
297 317 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
298 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
299 //
300 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
301 PRINTF1("destination address set to: %d\n", CCSDS_DESTINATION_ID)
302 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DESTKEY\n")
303 //
304 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_NODEADDR, CCSDS_NODE_ADDRESS); // sets the node address
305 PRINTF1("node address set to: %d\n", CCSDS_NODE_ADDRESS)
306 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_NODEADDR\n")
318 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
307 319 //
308 320 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
309 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
321 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
310 322
311 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
323 PRINTF("OK *** in configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
312 324
313 325 return RTEMS_SUCCESSFUL;
314 326 }
@@ -5,6 +5,7 extern rtems_id Task_id[]; /* ar
5 5 extern int fdSPW;
6 6 extern TMHeader_t housekeeping_header;
7 7 extern char housekeeping_data[];
8 extern Packet_TM_LFR_HK_t housekeeping_packet;
8 9
9 10 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
10 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
@@ -55,14 +56,30 int send_console_outputs_on_serial_port(
55 56 return 0;
56 57 }
57 58
59 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
60 {
61 struct apbuart_regs_str *apbuart_regs;
62
63 apbuart_regs = (struct apbuart_regs_str *) regs;
64 apbuart_regs->scaler = value;
65 PRINTF1("OK *** COM port scaler reload register set to %x\n", value)
66
67 return 0;
68 }
69
70 //************
71 // RTEMS TASKS
72
58 73 rtems_task stat_task(rtems_task_argument argument)
59 74 {
60 int i;
61 i = 0;
62 PRINTF("In STAT *** \n")
75 int i;
76 int j;
77 i = 0;
78 j = 0;
79 PRINTF("in STAT *** \n")
63 80 while(1){
64 81 rtems_task_wake_after(1000);
65 PRINTF1("%d\n", i)
82 PRINTF1("%d\n", j)
66 83 if (i == 2) {
67 84 #ifdef PRINT_TASK_STATISTICS
68 85 rtems_cpu_usage_report();
@@ -70,67 +87,70 rtems_task stat_task(rtems_task_argument
70 87 #endif
71 88 i = 0;
72 89 }
73 else i++;
90 else i++;
91 j++;
74 92 }
75 93 }
76 94
77 95 rtems_task hous_task(rtems_task_argument argument)
78 {
96 {
97 PRINTF("in HOUS ***\n")
98
99 int result;
79 100 rtems_status_code status;
80 101
81 spw_ioctl_pkt_send spw_ioctl_send;
102 if (rtems_rate_monotonic_ident( HK_name, &HK_id)!=RTEMS_SUCCESSFUL)
103 {
104 status = rtems_rate_monotonic_create( HK_name, &HK_id );
105 if( status != RTEMS_SUCCESSFUL )
106 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
107 }
108
109 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
110 housekeeping_packet.protocolIdentifier = 0x02;
111 housekeeping_packet.reserved = 0x00;
112 housekeeping_packet.userApplication = 0x00;
113 housekeeping_packet.packetID[0] = 0x0c;
114 housekeeping_packet.packetID[1] = 0xc4;
115 housekeeping_packet.packetSequenceControl[0] = 0xc0;
116 housekeeping_packet.packetSequenceControl[1] = 0x00;
117 housekeeping_packet.packetLength[0] = 0x00;
118 housekeeping_packet.packetLength[1] = 0x77;
119 housekeeping_packet.dataFieldHeader[0] = 0x10;
120 housekeeping_packet.dataFieldHeader[1] = 0x03;
121 housekeeping_packet.dataFieldHeader[2] = 0x19;
122 housekeeping_packet.dataFieldHeader[3] = 0x00;
123
124 status = rtems_rate_monotonic_cancel(HK_id);
125 if( status != RTEMS_SUCCESSFUL )
126 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
127 else
128 PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
82 129
83 rtems_name name;
84 rtems_id period;
85 name = rtems_build_name( 'H', 'O', 'U', 'S' );
86 status = rtems_rate_monotonic_create( name, &period );
87 if( status != RTEMS_SUCCESSFUL ) {
88 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
89 exit( 1 );
130 while(1){ // launch the rate monotonic task
131 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
132 if ( status != RTEMS_SUCCESSFUL ){
133 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_period *** code %d\n", status);
134 }
135 else
136 {
137 housekeeping_packet.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
138 housekeeping_packet.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
139 housekeeping_packet.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
140 housekeeping_packet.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
141 housekeeping_packet.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
142 housekeeping_packet.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
143 housekeeping_packet.data[0] = CCSDS_DESTINATION_ID_DPU;
144 result = write ( fdSPW, &housekeeping_packet, LEN_TM_LFR_HK);
145 if (result==-1)
146 {
147 PRINTF("ERR *** in HOUS *** HK send\n");
148 }
149 }
90 150 }
91 151
92 // filling the structure for the spacewire transmission
93 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
94 spw_ioctl_send.hdr = (char*) &housekeeping_header;
95 spw_ioctl_send.dlen = LENGTH_TM_LFR_HK - 10 + 1;
96 spw_ioctl_send.data = housekeeping_data;
97
98 housekeeping_header.targetLogicalAddress = CCSDS_DESTINATION_ID;
99 housekeeping_header.protocolIdentifier = 0x02;
100 housekeeping_header.reserved = 0x00;
101 housekeeping_header.userApplication = 0x00;
102 housekeeping_header.packetID[0] = 0x0c;
103 housekeeping_header.packetID[1] = 0xc4;
104 housekeeping_header.packetSequenceControl[0] = 0xc0;
105 housekeeping_header.packetSequenceControl[1] = 0x00;
106 housekeeping_header.packetLength[0] = 0x00;
107 housekeeping_header.packetLength[1] = 0x77;
108 housekeeping_header.dataFieldHeader[0] = 0x10;
109 housekeeping_header.dataFieldHeader[1] = 0x03;
110 housekeeping_header.dataFieldHeader[2] = 0x19;
111 housekeeping_header.dataFieldHeader[3] = 0x00;
152 PRINTF("in HOUS *** deleting task\n")
112 153
113 printf("In HOUS ***\n");
114
115 while(1){ // launch the rate monotonic task
116 if ( rtems_rate_monotonic_period( period, HK_PERIOD ) == RTEMS_TIMEOUT ){
117 printf( "ERR *** in hous_task *** RTEMS_TIMEOUT\n" );
118 break;
119 }
120 housekeeping_header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
121 housekeeping_header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
122 housekeeping_header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
123 housekeeping_header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
124 housekeeping_header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
125 housekeeping_header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
126 status = write_spw(&spw_ioctl_send);
127 }
128
129 status = rtems_rate_monotonic_delete( period );
130 if ( status != RTEMS_SUCCESSFUL ) {
131 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
132 exit( 1 );
133 }
134 154 status = rtems_task_delete( RTEMS_SELF ); // should not return
135 155 printf( "rtems_task_delete returned with status of %d.\n", status );
136 156 exit( 1 );
@@ -61,14 +61,17 extern BP1_t data_BP1[ ];
61 61 extern rtems_id Task_id[ ]; /* array of task ids */
62 62
63 63 spectral_matrices_regs_t *spectral_matrices_regs;
64
64
65 //***********************************************************
65 66 // Interrupt Service Routine for spectral matrices processing
66 67 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
67 68 {
68 69 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
69 printf("In spectral_matrices_isr *** Error sending event to AVF0\n");
70 printf("in spectral_matrices_isr *** Error sending event to AVF0\n");
70 71 }
71 72
73 //************
74 // RTEMS TASKS
72 75 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
73 76 {
74 77 rtems_event_set event_out;
@@ -76,17 +79,16 rtems_task smiq_task(rtems_task_argument
76 79 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
77 80 unsigned char nb_interrupt_f0 = 0;
78 81
79 PRINTF("In SMIQ *** \n")
82 PRINTF("in SMIQ *** \n")
80 83
81 84 while(1){
82 85 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
83 86 nb_interrupt_f0 = nb_interrupt_f0 + 1;
84 87 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
85 if (rtems_event_send( Task_id[6], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
86 printf("In smiq_task *** Error sending event to AVF0\n");
88 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
89 printf("in SMIQ *** Error sending event to AVF0\n");
87 90 nb_interrupt_f0 = 0;
88 91 }
89 gptimer_regs->timer[1].ctrl = gptimer_regs->timer[1].ctrl | 0x00000010;
90 92 }
91 93 }
92 94
@@ -104,7 +106,7 rtems_task spw_bppr_task(rtems_task_argu
104 106 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
105 107 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
106 108
107 printf("In BPPR ***\n");
109 printf("in BPPR ***\n");
108 110
109 111 while(1){ // wait for an event to begin with the processing
110 112 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
@@ -131,6 +133,57 rtems_task spw_bppr_task(rtems_task_argu
131 133 }
132 134 }
133 135
136 rtems_task avf0_task(rtems_task_argument argument){
137 int i;
138 static int nb_average;
139 rtems_event_set event_out;
140 rtems_status_code status;
141
142 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
143 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
144 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
145
146 nb_average = 0;
147
148 PRINTF("in AVFO *** \n")
149
150 while(1){
151 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
152 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
153 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
154 + spec_mat_f0_b[i]
155 + spec_mat_f0_c[i]
156 + spec_mat_f0_d[i]
157 + spec_mat_f0_e[i]
158 + spec_mat_f0_f[i]
159 + spec_mat_f0_g[i]
160 + spec_mat_f0_h[i];
161 }
162 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
163 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
164 if (nb_average == NB_AVERAGE_NORMAL_f0) {
165 nb_average = 0;
166 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
167 if (status != RTEMS_SUCCESSFUL) printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
168 }
169 }
170 }
171
172 rtems_task bpf0_task(rtems_task_argument argument){
173 rtems_event_set event_out;
174
175 PRINTF("in BPFO *** \n")
176
177 while(1){
178 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
179 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
180 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
181 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
182 }
183 }
184
185 //*****************************
186 // Spectral matrices processing
134 187 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
135 188 {
136 189 int i;
@@ -172,10 +225,10 void matrix_compression(float *averaged_
172 225 }
173 226 break;
174 227 case 1:
175 // case fChannel = f1 tp be completed later
228 // case fChannel = f1 to be completed later
176 229 break;
177 230 case 2:
178 // case fChannel = f1 tp be completed later
231 // case fChannel = f1 to be completed later
179 232 break;
180 233 default:
181 234 break;
@@ -350,98 +403,4 void BP2_set(float * compressed_spec_mat
350 403 compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux;
351 404 }
352 405 }
353
354 rtems_task avf0_task(rtems_task_argument argument){
355 int i;
356 static int nb_average;
357 rtems_event_set event_out;
358 rtems_status_code status;
359 406
360 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
361 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
362 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
363
364 nb_average = 0;
365
366 PRINTF("In AVFO *** \n")
367
368 while(1){
369 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
370 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
371 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
372 + spec_mat_f0_b[i]
373 + spec_mat_f0_c[i]
374 + spec_mat_f0_d[i]
375 + spec_mat_f0_e[i]
376 + spec_mat_f0_f[i]
377 + spec_mat_f0_g[i]
378 + spec_mat_f0_h[i];
379 }
380 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
381 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
382 if (nb_average == NB_AVERAGE_NORMAL_f0) {
383 nb_average = 0;
384 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
385 if (status != RTEMS_SUCCESSFUL) printf("IN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
386 }
387 }
388 }
389
390 rtems_task bpf0_task(rtems_task_argument argument){
391 rtems_event_set event_out;
392
393 PRINTF("In BPFO *** \n")
394
395 while(1){
396 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
397 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
398 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
399 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
400 }
401 }
402
403 //*******
404 // UNUSED
405 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument)
406 {/*
407 rtems_status_code status;
408 //static int nb_average_f1 = 0;
409 //static int nb_average_f2 = 0;
410
411 rtems_name name;
412 rtems_id period;
413 name = rtems_build_name( 'P', 'E', 'R', 'D' );
414 status = rtems_rate_monotonic_create( name, &period );
415 if( status != RTEMS_SUCCESSFUL ) {
416 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
417 //exit( 1 );
418 }
419
420 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
421 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
422 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
423
424 printf("In BPPR BIS ***\n");
425
426 while(1){ // launch the rate monotonic task
427 if ( rtems_rate_monotonic_period( period, 8 ) == RTEMS_TIMEOUT ){
428 printf("TIMEOUT\n");
429 //break;
430 }
431 status = rtems_event_send( Task_id[6], RTEMS_EVENT_0 ); // sending an event to the task 6, AVF0
432 if (status != RTEMS_SUCCESSFUL) printf("IN TASK BPPR BIS *** Error sending RTEMS_EVENT_0 to AVF0, code %d\n", status);
433 }
434
435 status = rtems_rate_monotonic_delete( period );
436 if ( status != RTEMS_SUCCESSFUL ) {
437 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
438 //exit( 1 );
439 }
440 status = rtems_task_delete( RTEMS_SELF ); // should not return
441 printf( "rtems_task_delete returned with status of %d.\n", status );
442 //exit( 1 );*/
443 }
444
445
446
447
@@ -48,7 +48,6 void GetCRCAsTwoBytes(unsigned char* dat
48 48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
49 49 }
50 50
51
52 51 //*********************
53 52 // ACCEPTANCE FUNCTIONS
54 53 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
@@ -221,6 +220,64 unsigned char TM_build_header( enum TM_T
221 220 return 1;
222 221 }
223 222
223 unsigned char TM_build_header_bis( enum TM_TYPE tm_type, unsigned int packetLength,
224 unsigned int coarseTime, unsigned int fineTime, Packet_TM_LFR_TC_EXE_t *packet)
225 {
226
227 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
228 packet->protocolIdentifier = 0x02;
229 packet->reserved = 0x00;
230 packet->userApplication = 0x00;
231 packet->packetID[0] = 0x0c;
232 packet->packetSequenceControl[0] = 0xc0;
233 packet->packetSequenceControl[1] = 0x00;
234 packet->packetLength[0] = (unsigned char) (packetLength>>8);
235 packet->packetLength[1] = (unsigned char) packetLength;
236 packet->dataFieldHeader[0] = 0x10;
237 packet->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
238 switch (tm_type){
239 case(TM_LFR_TC_EXE_OK):
240 packet->packetID[1] = 0xc1;
241 packet->dataFieldHeader[1] = 1; // type
242 packet->dataFieldHeader[2] = 7; // subtype
243 break;
244 case(TM_LFR_TC_EXE_ERR):
245 packet->packetID[1] = 0xc1;
246 packet->dataFieldHeader[1] = 1; // type
247 packet->dataFieldHeader[2] = 8; // subtype
248 break;
249 case(TM_LFR_HK):
250 packet->packetID[1] = 0xc4;
251 packet->dataFieldHeader[1] = 3; // type
252 packet->dataFieldHeader[2] = 25; // subtype
253 break;
254 case(TM_LFR_SCI):
255 packet->packetID[1] = 0xcc;
256 packet->dataFieldHeader[1] = 21; // type
257 packet->dataFieldHeader[2] = 3; // subtype
258 break;
259 case(TM_LFR_SCI_SBM):
260 packet->packetID[1] = 0xfc;
261 packet->dataFieldHeader[1] = 21; // type
262 packet->dataFieldHeader[2] = 3; // subtype
263 break;
264 case(TM_LFR_PAR_DUMP):
265 packet->packetID[1] = 0xc9;
266 packet->dataFieldHeader[1] = 181; // type
267 packet->dataFieldHeader[2] = 31; // subtype
268 break;
269 default:
270 return 0;
271 }
272 packet->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
273 packet->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
274 packet->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
275 packet->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
276 packet->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
277 packet->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
278 return 1;
279 }
280
224 281 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
225 282 {
226 283 unsigned int packetLength;
@@ -264,6 +321,17 unsigned char TM_build_data(ccsdsTelecom
264 321 return 1;
265 322 }
266 323
324 int create_message_queue()
325 {
326 rtems_status_code status;
327 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
328 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
329 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
330 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
331
332 return 0;
333 }
334
267 335 //***********
268 336 // RTEMS TASK
269 337 rtems_task recv_task( rtems_task_argument unused )
@@ -276,7 +344,7 rtems_task recv_task( rtems_task_argumen
276 344
277 345 for(i=0; i<100; i++) data[i] = 0;
278 346
279 PRINTF("In RECV *** \n")
347 PRINTF("in RECV *** \n")
280 348
281 349 while(1)
282 350 {
@@ -310,7 +378,7 rtems_task actn_task( rtems_task_argumen
310 378 size_t size; // size of the incoming TC packet
311 379 unsigned char subtype = 0; // subtype of the current TC packet
312 380
313 PRINTF("In ACTN *** \n")
381 PRINTF("in ACTN *** \n")
314 382
315 383 while(1)
316 384 {
@@ -380,15 +448,20 rtems_task actn_task( rtems_task_argumen
380 448 }
381 449 }
382 450
383 int create_message_queue()
451 rtems_task dumb_task( rtems_task_argument unused )
384 452 {
385 rtems_status_code status;
386 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
387 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
388 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
453 unsigned int coarse_time;
454 unsigned int fine_time;
455 rtems_event_set event_out;
456
457 PRINTF("in DUMB *** \n")
390 458
391 return 0;
459 while(1){
460 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
461 coarse_time = time_management_regs->coarse_time;
462 fine_time = time_management_regs->fine_time;
463 printf("in DUMB *** coarse time = %x, fine time = %x\n", coarse_time, fine_time);
464 }
392 465 }
393 466
394 467 //***********
@@ -396,30 +469,23 int create_message_queue()
396 469
397 470 int action_default(ccsdsTelecommandPacket_t *TC)
398 471 {
399 TMHeader_t TM_header;
400 char data[8];
401 spw_ioctl_pkt_send spw_ioctl_send;
472 Packet_TM_LFR_TC_EXE_t packet;
402 473
403 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
404 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
474 TM_build_header_bis( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
475 time_management_regs->coarse_time, time_management_regs->fine_time, &packet);
405 476
406 data[0] = 0x9c;
407 data[1] = 0x42;
408 data[2] = TC->packetID[0];
409 data[3] = TC->packetID[1];
410 data[4] = TC->packetSequenceControl[0];
411 data[5] = TC->packetSequenceControl[1];
412 data[6] = TC->dataFieldHeader[1]; // type
413 data[7] = TC->dataFieldHeader[2]; // subtype
414
415 // filling the structure for the spacewire transmission
416 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
417 spw_ioctl_send.hdr = (char*) &TM_header;
418 spw_ioctl_send.dlen = 8;
419 spw_ioctl_send.data = data;
477 packet.data[0] = 0x9c;
478 packet.data[1] = 0x42;
479 packet.data[2] = TC->packetID[0];
480 packet.data[3] = TC->packetID[1];
481 packet.data[4] = TC->packetSequenceControl[0];
482 packet.data[5] = TC->packetSequenceControl[1];
483 packet.data[6] = TC->dataFieldHeader[1]; // type
484 packet.data[7] = TC->dataFieldHeader[2]; // subtype
420 485
421 486 // SEND DATA
422 write_spw(&spw_ioctl_send);
487 if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1)
488 PRINTF("ERR *** in action_default *** send TM packet\n");
423 489
424 490 return 0;
425 491 }
@@ -511,21 +577,6 rtems_isr commutation_isr2( rtems_vector
511 577 printf("In commutation_isr2 *** Error sending event to DUMB\n");
512 578 }
513 579
514 rtems_task dumb_task( rtems_task_argument unused )
515 {
516 unsigned int coarse_time;
517 unsigned int fine_time;
518 rtems_event_set event_out;
519
520 PRINTF("In DUMB *** \n")
521
522 while(1){
523 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
524 coarse_time = time_management_regs->coarse_time;
525 fine_time = time_management_regs->fine_time;
526 printf("commutation_isr*, coarse time = %x, fine time = %x\n", coarse_time, fine_time);
527 }
528 }
529 580
530 581
531 582
@@ -29,7 +29,7 rtems_task wfrm_task(rtems_task_argument
29 29 header.dataFieldHeader[0] = 0x10;
30 30 header.dataFieldHeader[1] = 0x15; // service type
31 31 header.dataFieldHeader[2] = 0x03; // service subtype
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID;
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
33 33
34 34 header.auxiliaryHeader[0] = 0x00;
35 35 header.auxiliaryHeader[1] = 0x1f;
@@ -42,7 +42,7 rtems_task wfrm_task(rtems_task_argument
42 42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
43 43 spw_ioctl_send.hdr = (char*) &header;
44 44
45 PRINTF("In WFRM *** \n")
45 PRINTF("in WFRM *** \n")
46 46
47 47 while(1){
48 48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
@@ -54,14 +54,19 rtems_task wfrm_task(rtems_task_argument
54 54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
55 55 for (i=0; i<7; i++) // send F0
56 56 {
57 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
57 58 // BUILD THE DATA
58 59 if (i==6) {
59 60 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
60 length = TM_LEN_SCI_NORM_SWF_340;
61 }
61 length = TM_LEN_SCI_NORM_SWF_8;
62 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
63 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
64 }
62 65 else {
63 66 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
64 length = TM_LEN_SCI_NORM_SWF_8;
67 length = TM_LEN_SCI_NORM_SWF_340;
68 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
69 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
65 70 }
66 71 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
67 72 // BUILD THE HEADER
@@ -73,14 +78,19 rtems_task wfrm_task(rtems_task_argument
73 78 }
74 79 for (i=0; i<7; i++) // send F1
75 80 {
81 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
76 82 // BUILD THE DATA
77 83 if (i==6) {
78 84 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
79 length = TM_LEN_SCI_NORM_SWF_340;
80 }
85 length = TM_LEN_SCI_NORM_SWF_8;
86 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
87 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
88 }
81 89 else {
82 90 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
83 length = TM_LEN_SCI_NORM_SWF_8;
91 length = TM_LEN_SCI_NORM_SWF_340;
92 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
93 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
84 94 }
85 95 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
86 96 // BUILD THE HEADER
@@ -90,16 +100,21 rtems_task wfrm_task(rtems_task_argument
90 100 // SEND PACKET
91 101 write_spw(&spw_ioctl_send);
92 102 }
93 for (i=0; i<7; i++) // send F0
103 for (i=0; i<7; i++) // send F2
94 104 {
105 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
95 106 // BUILD THE DATA
96 107 if (i==6) {
97 108 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
98 length = TM_LEN_SCI_NORM_SWF_340;
99 }
109 length = TM_LEN_SCI_NORM_SWF_8;
110 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
111 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
112 }
100 113 else {
101 114 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
102 length = TM_LEN_SCI_NORM_SWF_8;
115 length = TM_LEN_SCI_NORM_SWF_340;
116 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
117 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
103 118 }
104 119 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
105 120 // BUILD THE HEADER
@@ -113,3 +128,49 rtems_task wfrm_task(rtems_task_argument
113 128 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
114 129 }
115 130 }
131
132 //******************
133 // general functions
134 void init_waveforms()
135 {
136 int i = 0;
137
138 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
139 {
140 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and e1
141 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( 3*i, 4*i ); // e2 and b1
142 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
143 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
144 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
145 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
146 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
147 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
148 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
149 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
150 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
151 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
152 }
153 }
154
155 int buil_value(int value1, int value0)
156 {
157 int aux = 0;
158 int aux1 = 0;
159 int aux0 = 0;
160 //******
161 // B3 B2
162 aux1 = ( (int) ( (char) (value1 >> 8) ) << 8 )
163 + ( (int) ( (char) (value1 ) ) );
164
165 //******
166 // B1 B0
167 aux0 = ( (int) ( (char) (value0 >> 8) ) << 8 )
168 + ( (int) ( (char) (value0 ) ) );
169
170 aux = (aux1 << 16) + aux0;
171
172 return aux;
173 }
174
175
176
General Comments 0
You need to be logged in to leave comments. Login now