##// END OF EJS Templates
FSW modified to have correct answers to TC_LFR_DUMP_PAR
paul@pc-solar1.lab-lpp.local -
r15:d75852f5b698 default
parent child
Show More
@@ -1,46 +1,46
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 <CodeBlocks_layout_file>
2 <CodeBlocks_layout_file>
3 <ActiveTarget name="Debug" />
3 <ActiveTarget name="Debug" />
4 <File name="../header/ccsds_types.h" open="1" top="0" tabpos="2">
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
5 <Cursor position="553" topLine="24" />
5 <Cursor position="417" topLine="3" />
6 </File>
6 </File>
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="3">
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="6">
8 <Cursor position="1521" topLine="15" />
8 <Cursor position="1629" topLine="27" />
9 </File>
9 </File>
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
11 <Cursor position="114" topLine="0" />
11 <Cursor position="114" topLine="0" />
12 </File>
12 </File>
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="2">
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="2">
14 <Cursor position="1358" topLine="31" />
14 <Cursor position="481" topLine="0" />
15 </File>
15 </File>
16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
17 <Cursor position="628" topLine="7" />
17 <Cursor position="628" topLine="7" />
18 </File>
18 </File>
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
20 <Cursor position="1153" topLine="11" />
20 <Cursor position="1153" topLine="16" />
21 </File>
21 </File>
22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
23 <Cursor position="624" topLine="2" />
23 <Cursor position="1380" topLine="35" />
24 </File>
24 </File>
25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
26 <Cursor position="318" topLine="0" />
26 <Cursor position="341" topLine="0" />
27 </File>
27 </File>
28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="3">
28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="5">
29 <Cursor position="378" topLine="1" />
29 <Cursor position="99" topLine="0" />
30 </File>
30 </File>
31 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
31 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
32 <Cursor position="10747" topLine="81" />
32 <Cursor position="12524" topLine="55" />
33 </File>
33 </File>
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
35 <Cursor position="475" topLine="0" />
35 <Cursor position="2621" topLine="0" />
36 </File>
36 </File>
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="0">
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="0">
38 <Cursor position="1696" topLine="59" />
38 <Cursor position="1792" topLine="43" />
39 </File>
39 </File>
40 <File name="../src/tc_handler.c" open="1" top="1" tabpos="3">
40 <File name="../src/tc_handler.c" open="1" top="1" tabpos="2">
41 <Cursor position="11453" topLine="39" />
41 <Cursor position="13883" topLine="80" />
42 </File>
42 </File>
43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="4">
43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="4">
44 <Cursor position="1660" topLine="24" />
44 <Cursor position="4576" topLine="83" />
45 </File>
45 </File>
46 </CodeBlocks_layout_file>
46 </CodeBlocks_layout_file>
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,52 +1,59
1 #ifndef FSW_RTEMS_H_INCLUDED
1 #ifndef FSW_RTEMS_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
2 #define FSW_RTEMS_H_INCLUDED
3
3
4 #include <errno.h>
4 #include <errno.h>
5 #include <fcntl.h>
5 #include <fcntl.h>
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <stdlib.h>
7 #include <stdlib.h>
8
8
9 #include <grspw.h>
9 #include <grspw.h>
10 #include <apbuart.h>
10 #include <apbuart.h>
11
11
12 #include <fsw_params.h>
12 #include <fsw_params.h>
13 #include <fsw_misc.h>
13 #include <fsw_misc.h>
14 #include <fsw_processing.h>
14 #include <fsw_processing.h>
15 #include <tc_handler.h>
15 #include <tc_handler.h>
16 #include <wf_handler.h>
16 #include <wf_handler.h>
17 #include <grlib_regs.h>
17 #include <grlib_regs.h>
18
18
19 extern int sched_yield();
19 extern int sched_yield();
20 extern int errno;
20 extern int errno;
21 extern rtems_id Task_id[ ]; /* array of task ids */
21 extern rtems_id Task_id[ ]; /* array of task ids */
22 extern rtems_name Task_name[ ]; /* array of task names */
22 extern rtems_name Task_name[ ]; /* array of task names */
23 extern rtems_name misc_name[ ]; /* arry of miscellaneous names for rtems objects */
23 extern rtems_name misc_name[ ]; /* arry of miscellaneous names for rtems objects */
24 extern int fdSPW; // grspw file descriptor
24 extern int fdSPW; // grspw file descriptor
25 extern int fdUART; // uart file descriptor
25 extern int fdUART; // uart file descriptor
26
27 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
28
26 // MODE PARAMETERS
29 // MODE PARAMETERS
27 extern struct param_norm_str param_norm;
30 extern struct param_norm_str param_norm;
28 extern struct param_burst_str param_burst;
31 extern struct param_burst_str param_burst;
29 extern struct param_sbm1_str param_sbm1;
32 extern struct param_sbm1_str param_sbm1;
30 extern struct param_sbm2_str param_sbm2;
33 extern struct param_sbm2_str param_sbm2;
31 extern unsigned char param_common[];
34 extern unsigned char param_common[];
32
35
33 // RTEMS TASKS
36 // RTEMS TASKS
34 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
37 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
35 rtems_task recv_task(rtems_task_argument argument);
38 rtems_task recv_task(rtems_task_argument argument);
36 rtems_task spiq_task(rtems_task_argument argument);
39 rtems_task spiq_task(rtems_task_argument argument);
37 rtems_task stat_task(rtems_task_argument argument);
40 rtems_task stat_task(rtems_task_argument argument);
38 rtems_task wfrm_task(rtems_task_argument argument);
41 rtems_task wfrm_task(rtems_task_argument argument);
39 int create_all_tasks();
42 int create_all_tasks();
40 int start_all_tasks();
43 int start_all_tasks();
41 int create_message_queue();
44 int create_message_queue();
42
45
43 // OTHER functions
46 // OTHER functions
44 void init_default_mode_parameters();
47 void init_default_mode_parameters();
48
45 int configure_spw_link();
49 int configure_spw_link();
46 int send_console_outputs_on_serial_port();
50 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
51 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
52
47 extern int rtems_cpu_usage_report();
53 extern int rtems_cpu_usage_report();
48 extern int rtems_cpu_usage_reset();
54 extern int rtems_cpu_usage_reset();
49 void print_statistics(spw_stats *);
55 void print_statistics(spw_stats *);
50 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
56 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
57 void (*grspw_timecode_callback) (void *pDev, void *regs, int minor, unsigned int tc);
51
58
52 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
59 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,69 +1,70
1 #ifndef TC_HANDLER_H_INCLUDED
1 #ifndef TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <bsp.h> // for the LEON_Unmask_interrupt function
5 #include <bsp.h> // for the LEON_Unmask_interrupt function
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <unistd.h> // for the read call
7 #include <unistd.h> // for the read call
8 #include <sys/ioctl.h> // for the ioctl call
8 #include <sys/ioctl.h> // for the ioctl call
9 #include <ccsds_types.h>
9 #include <ccsds_types.h>
10 #include <grspw.h>
10 #include <grspw.h>
11 #include <fsw_init.h>
11 #include <fsw_init.h>
12
12
13 extern int fdSPW;
13 extern int fdSPW;
14 extern rtems_name misc_name[ ];
14 extern rtems_name misc_name[ ];
15 extern rtems_name misc_id[ ];
15 extern rtems_name misc_id[ ];
16 extern rtems_id Task_id[ ]; // array of task ids
16 extern rtems_id Task_id[ ]; // array of task ids
17 // MODE PARAMETERS
17 // MODE PARAMETERS
18 extern struct param_norm_str param_norm;
18 extern struct param_norm_str param_norm;
19 extern struct param_sbm1_str param_sbm1;
19 extern struct param_sbm1_str param_sbm1;
20 extern struct param_sbm2_str param_sbm2;
20 extern struct param_sbm2_str param_sbm2;
21 extern time_management_regs_t *time_management_regs;
21 extern time_management_regs_t *time_management_regs;
22 extern unsigned char param_common[];
22 extern unsigned char param_common[];
23
23
24 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
24 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
25 unsigned char currentTC_COMPUTED_CRC[2];
25 unsigned char currentTC_COMPUTED_CRC[2];
26 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
26 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
27 unsigned int currentTM_length;
27 unsigned int currentTM_length;
28 unsigned char currentTC_processedFlag;
28 unsigned char currentTC_processedFlag;
29
29
30 //****
30 //****
31 // ISR
31 // ISR
32 rtems_isr commutation_isr1( rtems_vector_number vector );
32 rtems_isr commutation_isr1( rtems_vector_number vector );
33 rtems_isr commutation_isr2( rtems_vector_number vector );
33 rtems_isr commutation_isr2( rtems_vector_number vector );
34
34
35 //**********************
35 //**********************
36 // GENERAL USE FUNCTIONS
36 // GENERAL USE FUNCTIONS
37 unsigned int lookUpTableForCRC[256];
37 unsigned int lookUpTableForCRC[256];
38 void initLookUpTableForCRC();
38 void initLookUpTableForCRC();
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
40
40
41 //*********************
41 //*********************
42 // ACCEPTANCE FUNCTIONS
42 // ACCEPTANCE FUNCTIONS
43 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int tc_len_recv);
43 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int tc_len_recv);
44
44
45 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
45 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
46 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader);
46 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader);
47 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC);
47 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC);
48 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV);
48 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV);
49
49
50 //***********
50 //***********
51 // RTEMS TASK
51 // RTEMS TASK
52 rtems_task recv_task( rtems_task_argument unused );
52 rtems_task recv_task( rtems_task_argument unused );
53 rtems_task actn_task( rtems_task_argument unused );
53 rtems_task actn_task( rtems_task_argument unused );
54 rtems_task dumb_task( rtems_task_argument unused );
54 rtems_task dumb_task( rtems_task_argument unused );
55 int create_message_queue();
55 int create_message_queue();
56
56
57 //***********
57 //***********
58 // TC ACTIONS
58 // TC ACTIONS
59 int action_default(ccsdsTelecommandPacket_t *TC);
59 int action_default(ccsdsTelecommandPacket_t *TC);
60 int action_default_alt(ccsdsTelecommandPacket_t *TC);
60 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC);
61 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC);
61 //
62 //
62 int action_load_norm(ccsdsTelecommandPacket_t *TC);
63 int action_load_norm(ccsdsTelecommandPacket_t *TC);
63 int action_enter(ccsdsTelecommandPacket_t *TC);
64 int action_enter(ccsdsTelecommandPacket_t *TC);
64 int action_updt_time(ccsdsTelecommandPacket_t *TC);
65 int action_updt_time(ccsdsTelecommandPacket_t *TC);
65
66
66 #endif // TC_HANDLER_H_INCLUDED
67 #endif // TC_HANDLER_H_INCLUDED
67
68
68
69
69
70
@@ -1,53 +1,55
1 #include <drvmgr/ambapp_bus.h>
1 #include <drvmgr/ambapp_bus.h>
2
2
3 // GRSPW0 resources
3 // GRSPW0 resources
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
5 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
5 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
6 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
6 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
7 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
7 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
8 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+6}}, // 6 is for the auxiliary header, when needed
8 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+6}}, // 6 is for the auxiliary header, when needed
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}},
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}},
10 KEY_EMPTY
10 KEY_EMPTY
11 };
11 };
12
12
13 #if 0
13 #if 0
14 /* APBUART0 */
14 /* APBUART0 */
15 struct drvmgr_key grlib_drv_res_apbuart0[] =
15 struct drvmgr_key grlib_drv_res_apbuart0[] =
16 {
16 {
17 {"mode", KEY_TYPE_INT, {(unsigned int)1}},
17 {"mode", KEY_TYPE_INT, {(unsigned int)1}},
18 {"syscon", KEY_TYPE_INT, {(unsigned int)1}},
18 {"syscon", KEY_TYPE_INT, {(unsigned int)1}},
19 KEY_EMPTY
19 KEY_EMPTY
20 };
20 };
21 /* APBUART1 */
21 /* APBUART1 */
22 struct drvmgr_key grlib_drv_res_apbuart1[] =
22 struct drvmgr_key grlib_drv_res_apbuart1[] =
23 {
23 {
24 {"mode", KEY_TYPE_INT, {(unsigned int)1}},
24 {"mode", KEY_TYPE_INT, {(unsigned int)1}},
25 {"syscon", KEY_TYPE_INT, {(unsigned int)0}},
25 {"syscon", KEY_TYPE_INT, {(unsigned int)0}},
26 KEY_EMPTY
26 KEY_EMPTY
27 };
27 };
28 /* LEON3 System with driver configuration for 2 APBUARTs, the
28 /* LEON3 System with driver configuration for 2 APBUARTs, the
29 * the rest of the AMBA device drivers use their defaults.
29 * the rest of the AMBA device drivers use their defaults.
30 */
30 */
31
31
32 /* Override default debug UART assignment.
32 /* Override default debug UART assignment.
33 * 0 = Default APBUART. APBUART[0], but on MP system CPU0=APBUART0,
33 * 0 = Default APBUART. APBUART[0], but on MP system CPU0=APBUART0,
34 * CPU1=APBUART1...
34 * CPU1=APBUART1...
35 * 1 = APBUART[0]
35 * 1 = APBUART[0]
36 * 2 = APBUART[1]
36 * 2 = APBUART[1]
37 * 3 = APBUART[2]
37 * 3 = APBUART[2]
38 * ...
38 * ...
39 */
39 */
40 //int debug_uart_index = 2; /* second UART -- APBUART[1] */
40 //int debug_uart_index = 2; /* second UART -- APBUART[1] */
41 #endif
41 #endif
42
42
43 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
43 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
44
44
45 struct drvmgr_bus_res grlib_drv_resources = {
45 struct drvmgr_bus_res grlib_drv_resources = {
46 .next = NULL,
46 .next = NULL,
47 .resource = {
47 .resource = {
48 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
48 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
49 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]},
49 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]},
50 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
50 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
51 RES_EMPTY /* Mark end of device resource array */
51 RES_EMPTY /* Mark end of device resource array */
52 }
52 }
53 };
53 };
54
55
@@ -1,44 +1,45
1 #include <fsw_processing.h>
1 #include <fsw_processing.h>
2 #include <rtems.h>
2 #include <rtems.h>
3
3
4 // RTEMS GLOBAL VARIABLES
4 // RTEMS GLOBAL VARIABLES
5 rtems_name misc_name[5];
5 rtems_name misc_name[5];
6 rtems_name misc_id[5];
6 rtems_name misc_id[5];
7 rtems_id Task_id[10]; /* array of task ids */
7 rtems_id Task_id[10]; /* array of task ids */
8 rtems_name Task_name[10]; /* array of task names */
8 rtems_name Task_name[10]; /* array of task names */
9 int fdSPW;
9 int fdSPW;
10 int fdUART;
10 int fdUART;
11
11
12 // APB CONFIGURATION REGISTERS
12 // APB CONFIGURATION REGISTERS
13 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
13 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
14
14
15 // WAVEFORMS GLOBAL VARIABLES
15 // WAVEFORMS GLOBAL VARIABLES
16 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
16 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
17 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
17 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
18 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
18 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
19 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
19 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
20
20
21 // SPECTRAL MATRICES GLOBAL VARIABLES
21 // SPECTRAL MATRICES GLOBAL VARIABLES
22 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
22 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
23 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
23 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
24 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
24 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
25 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
25 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
26 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
26 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
27 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
27 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
28 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
28 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
29 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
29 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
30 //
30 //
31 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
31 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
32 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
32 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
33
33
34 // MODE PARAMETERS
34 // MODE PARAMETERS
35 struct param_norm_str param_norm;
35 struct param_norm_str param_norm;
36 struct param_burst_str param_burst;
36 struct param_burst_str param_burst;
37 struct param_sbm1_str param_sbm1;
37 struct param_sbm1_str param_sbm1;
38 struct param_sbm2_str param_sbm2;
38 struct param_sbm2_str param_sbm2;
39 unsigned char param_common[2];
39 unsigned char param_common[2];
40
40
41 // BASIC PARAMETERS GLOBAL VARIABLES
41 // BASIC PARAMETERS GLOBAL VARIABLES
42 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
42 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
43
43
44 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
44 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
45
@@ -1,304 +1,345
1 //*************************
1 //*************************
2 // GPL reminder to be added
2 // GPL reminder to be added
3 //*************************
3 //*************************
4
4
5 #include <rtems.h>
5 #include <rtems.h>
6
6
7 /* configuration information */
7 /* configuration information */
8
8
9 #define CONFIGURE_INIT
9 #define CONFIGURE_INIT
10
10
11 #include <bsp.h> /* for device driver prototypes */
11 #include <bsp.h> /* for device driver prototypes */
12
12
13 /* configuration information */
13 /* configuration information */
14
14
15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
17
17
18 #define CONFIGURE_MAXIMUM_TASKS 10
18 #define CONFIGURE_MAXIMUM_TASKS 10
19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
22 #define CONFIGURE_INIT_TASK_PRIORITY 100
22 #define CONFIGURE_INIT_TASK_PRIORITY 100
23 #define CONFIGURE_MAXIMUM_DRIVERS 16
23 #define CONFIGURE_MAXIMUM_DRIVERS 16
24 #define CONFIGURE_MAXIMUM_PERIODS 1
24 #define CONFIGURE_MAXIMUM_PERIODS 1
25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
26
26
27 #include <rtems/confdefs.h>
27 #include <rtems/confdefs.h>
28
28
29 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
29 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
30 #ifdef RTEMS_DRVMGR_STARTUP
30 #ifdef RTEMS_DRVMGR_STARTUP
31 #ifdef LEON3
31 #ifdef LEON3
32 /* Add Timer and UART Driver */
32 /* Add Timer and UART Driver */
33 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
33 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
34 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
34 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
35 #endif
35 #endif
36 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
36 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
38 #endif
38 #endif
39 #endif
39 #endif
40 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
40 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
41 #include <drvmgr/drvmgr_confdefs.h>
41 #include <drvmgr/drvmgr_confdefs.h>
42 #endif
42 #endif
43
43
44 #include <fsw_init.h>
44 #include <fsw_init.h>
45 #include <fsw_config.c>
45 #include <fsw_config.c>
46
46
47 char *link_status(int status);
47 char *link_status(int status);
48
48
49 char *lstates[6] = {"Error-reset",
49 char *lstates[6] = {"Error-reset",
50 "Error-wait",
50 "Error-wait",
51 "Ready",
51 "Ready",
52 "Started",
52 "Started",
53 "Connecting",
53 "Connecting",
54 "Run"
54 "Run"
55 };
55 };
56
56
57 rtems_task Init( rtems_task_argument ignored )
57 rtems_task Init( rtems_task_argument ignored )
58 {
58 {
59 rtems_status_code status;
59 rtems_status_code status;
60 rtems_isr_entry old_isr_handler;
60 rtems_isr_entry old_isr_handler;
61
61
62 //send_console_outputs_on_serial_port();
62 //send_console_outputs_on_serial_port();
63
63
64 initLookUpTableForCRC(); // in tc_handler.h
64 initLookUpTableForCRC(); // in tc_handler.h
65 init_default_mode_parameters();
65 init_default_mode_parameters();
66 create_message_queue();
66 create_message_queue();
67 create_all_tasks();
67 create_all_tasks();
68 start_all_tasks();
68 start_all_tasks();
69
69
70 grspw_timecode_callback = &timecode_irq_handler;
71
70 configure_spw_link();
72 configure_spw_link();
71 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
73 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
72 IRQ_SPARC_SM, spectral_matrices_isr );
74 IRQ_SPARC_SM, spectral_matrices_isr );
73 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
75 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
74 IRQ_SPARC_WF, waveforms_isr );
76 IRQ_SPARC_WF, waveforms_isr );
75
77
76 // irq handling of the time management unit
78 // irq handling of the time management unit
77 status = rtems_interrupt_catch( commutation_isr1,
79 status = rtems_interrupt_catch( commutation_isr1,
78 IRQ_SPARC_TIME1,
80 IRQ_SPARC_TIME1,
79 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
81 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
80 if (status==RTEMS_SUCCESSFUL)
82 if (status==RTEMS_SUCCESSFUL)
81 PRINTF("commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
83 PRINTF("commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
82
84
83 status = rtems_interrupt_catch( commutation_isr2,
85 status = rtems_interrupt_catch( commutation_isr2,
84 IRQ_SPARC_TIME2,
86 IRQ_SPARC_TIME2,
85 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
87 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
86 if (status==RTEMS_SUCCESSFUL)
88 if (status==RTEMS_SUCCESSFUL)
87 PRINTF("commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
89 PRINTF("commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
88
90
89 LEON_Unmask_interrupt( IRQ_TIME1 );
91 LEON_Unmask_interrupt( IRQ_TIME1 );
90 LEON_Unmask_interrupt( IRQ_TIME2 );
92 LEON_Unmask_interrupt( IRQ_TIME2 );
91
93
92 status = rtems_task_delete(RTEMS_SELF);
94 status = rtems_task_delete(RTEMS_SELF);
93 }
95 }
94
96
95 rtems_task spiq_task(rtems_task_argument unused)
97 rtems_task spiq_task(rtems_task_argument unused)
96 {
98 {
97 rtems_event_set event_out;
99 rtems_event_set event_out;
98 struct grspw_regs_str *grspw_regs;
100 struct grspw_regs_str *grspw_regs;
99 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
101 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
100
102
101 while(1){
103 while(1){
102 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
104 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
103 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
105 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
104
106
105 if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task
107 if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task
106 PRINTF("In SPIQ *** Error suspending RECV Task\n")
108 PRINTF("In SPIQ *** Error suspending RECV Task\n")
107
109
108 configure_spw_link();
110 configure_spw_link();
109
111
110 if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
112 if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
111 PRINTF("In SPIQ *** Error resume RECV Task\n")
113 PRINTF("In SPIQ *** Error resume RECV Task\n")
112 }
114 }
113 }
115 }
114
116
115 void init_default_mode_parameters()
117 void init_default_mode_parameters()
116 {
118 {
117 // COMMON PARAMETERS
119 // COMMON PARAMETERS
118 param_common[0] = 0x00;
120 param_common[0] = 0x00;
119 param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0
121 param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0
120 // NORMAL MODE
122 // NORMAL MODE
121 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
123 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
122 param_norm.sy_lfr_n_swf_p = 300; // sec
124 param_norm.sy_lfr_n_swf_p = 300; // sec
123 param_norm.sy_lfr_n_asm_p = 3600; // sec
125 param_norm.sy_lfr_n_asm_p = 3600; // sec
124 param_norm.sy_lfr_n_bp_p0 = 4; // sec
126 param_norm.sy_lfr_n_bp_p0 = 4; // sec
125 param_norm.sy_lfr_n_bp_p1 = 20; // sec
127 param_norm.sy_lfr_n_bp_p1 = 20; // sec
126 // BURST MODE
128 // BURST MODE
127 param_burst.sy_lfr_b_bp_p0 = 1; // sec
129 param_burst.sy_lfr_b_bp_p0 = 1; // sec
128 param_burst.sy_lfr_b_bp_p1 = 5; // sec
130 param_burst.sy_lfr_b_bp_p1 = 5; // sec
129 // SBM1 MODE
131 // SBM1 MODE
130 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
132 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
131 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
133 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
132 // SBM2 MODE
134 // SBM2 MODE
133 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
135 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
134 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
136 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
135 }
137 }
136
138
137 int create_all_tasks()
139 int create_all_tasks()
138 {
140 {
139 rtems_status_code status;
141 rtems_status_code status;
140
142
141 Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' );
143 Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' );
142 Task_name[2] = rtems_build_name( 'A', 'C', 'T', 'N' );
144 Task_name[2] = rtems_build_name( 'A', 'C', 'T', 'N' );
143 Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' );
145 Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' );
144 Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' );
146 Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' );
145 Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' );
147 Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' );
146 Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' );
148 Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' );
147 Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' );
149 Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' );
148 Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' );
150 Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' );
149 Task_name[9] = rtems_build_name( 'D', 'U', 'M', 'B' );
151 Task_name[9] = rtems_build_name( 'D', 'U', 'M', 'B' );
150
152
151 // RECV
153 // RECV
152 status = rtems_task_create(
154 status = rtems_task_create(
153 Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
155 Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
154 RTEMS_DEFAULT_MODES,
156 RTEMS_DEFAULT_MODES,
155 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1]
157 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1]
156 );
158 );
157 // ACTN
159 // ACTN
158 status = rtems_task_create(
160 status = rtems_task_create(
159 Task_name[2], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
161 Task_name[2], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
160 RTEMS_DEFAULT_MODES,
162 RTEMS_DEFAULT_MODES,
161 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2]
163 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2]
162 );
164 );
163 // SPIQ
165 // SPIQ
164 status = rtems_task_create(
166 status = rtems_task_create(
165 Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
167 Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
166 RTEMS_DEFAULT_MODES,
168 RTEMS_DEFAULT_MODES,
167 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3]
169 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3]
168 );
170 );
169 // SMIQ
171 // SMIQ
170 status = rtems_task_create(
172 status = rtems_task_create(
171 Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
173 Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
172 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
174 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
173 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4]
175 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4]
174 );
176 );
175 // STAT
177 // STAT
176 status = rtems_task_create(
178 status = rtems_task_create(
177 Task_name[5], 150, RTEMS_MINIMUM_STACK_SIZE * 2,
179 Task_name[5], 150, RTEMS_MINIMUM_STACK_SIZE * 2,
178 RTEMS_DEFAULT_MODES,
180 RTEMS_DEFAULT_MODES,
179 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5]
181 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5]
180 );
182 );
181 // AVF0
183 // AVF0
182 status = rtems_task_create(
184 status = rtems_task_create(
183 Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
185 Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
184 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
186 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
185 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6]
187 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6]
186 );
188 );
187 // BPF0
189 // BPF0
188 status = rtems_task_create(
190 status = rtems_task_create(
189 Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
191 Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
190 RTEMS_DEFAULT_MODES,
192 RTEMS_DEFAULT_MODES,
191 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7]
193 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7]
192 );
194 );
193 // WFRM
195 // WFRM
194 status = rtems_task_create(
196 status = rtems_task_create(
195 Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
197 Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
196 RTEMS_DEFAULT_MODES,
198 RTEMS_DEFAULT_MODES,
197 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8]
199 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8]
198 );
200 );
199 // DUMB
201 // DUMB
200 status = rtems_task_create(
202 status = rtems_task_create(
201 Task_name[9], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
203 Task_name[9], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
202 RTEMS_DEFAULT_MODES,
204 RTEMS_DEFAULT_MODES,
203 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[9]
205 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[9]
204 );
206 );
205
207
206 return 0;
208 return 0;
207 }
209 }
208
210
209 int start_all_tasks()
211 int start_all_tasks()
210 {
212 {
211 rtems_status_code status;
213 rtems_status_code status;
212
214
213 status = rtems_task_start( Task_id[3], spiq_task, 1 );
215 status = rtems_task_start( Task_id[3], spiq_task, 1 );
214 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
216 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
215
217
216 status = rtems_task_start( Task_id[1], recv_task, 1 );
218 status = rtems_task_start( Task_id[1], recv_task, 1 );
217 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
219 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
218
220
219 status = rtems_task_start( Task_id[2], actn_task, 1 );
221 status = rtems_task_start( Task_id[2], actn_task, 1 );
220 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
222 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
221
223
222 status = rtems_task_start( Task_id[4], smiq_task, 1 );
224 status = rtems_task_start( Task_id[4], smiq_task, 1 );
223 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
225 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
224
226
225 status = rtems_task_start( Task_id[5], stat_task, 1 );
227 status = rtems_task_start( Task_id[5], stat_task, 1 );
226 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
228 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
227
229
228 status = rtems_task_start( Task_id[6], avf0_task, 1 );
230 status = rtems_task_start( Task_id[6], avf0_task, 1 );
229 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
231 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
230
232
231 status = rtems_task_start( Task_id[7], bpf0_task, 1 );
233 status = rtems_task_start( Task_id[7], bpf0_task, 1 );
232 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
234 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
233
235
234 status = rtems_task_start( Task_id[8], wfrm_task, 1 );
236 status = rtems_task_start( Task_id[8], wfrm_task, 1 );
235 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
237 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
236
238
237 status = rtems_task_start( Task_id[9], dumb_task, 1 );
239 status = rtems_task_start( Task_id[9], dumb_task, 1 );
238 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")
240 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")
239
241
240 return 0;
242 return 0;
241 }
243 }
242
244
243 int configure_spw_link()
245 int configure_spw_link()
244 {
246 {
245 rtems_status_code status;
247 rtems_status_code status;
246
248
247 close(fdSPW); // close the device if it is already open
249 close(fdSPW); // close the device if it is already open
248 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
250 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
249 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
251 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
250 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
252 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
251 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
253 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
252 close(fdSPW); // close the device
254 close(fdSPW); // close the device
253 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
255 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
254 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
256 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
255 rtems_task_wake_after(100);
257 rtems_task_wake_after(100);
256 }
258 }
257
259
258 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
260 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
259
261
260 // sets a few parameters of the link
262 // sets a few parameters of the link
261 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
263 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
262 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
264 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
263 //
265
266 configure_spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
267 configure_spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
268
264 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
269 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
265 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
270 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
266 //
271 //
267 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
272 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
268 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
273 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
269 //
274 //
270 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
275 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
271 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
276 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
272 //
277 //
273 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
278 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
274 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
279 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
275
280 //
276 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
281 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
277 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
282 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
278
283 //
279 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
284 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
280 PRINTF1("destination address set to: %d\n", CCSDS_DESTINATION_ID)
285 PRINTF1("destination address set to: %d\n", CCSDS_DESTINATION_ID)
281 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
286 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DESTKEY\n")
282
287 //
283 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_NODEADDR, CCSDS_NODE_ADDRESS); // sets the destination key
288 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_NODEADDR, CCSDS_NODE_ADDRESS); // sets the node address
284 PRINTF1("node address set to: %d\n", CCSDS_NODE_ADDRESS)
289 PRINTF1("node address set to: %d\n", CCSDS_NODE_ADDRESS)
285 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
290 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_NODEADDR\n")
291 //
292 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
293 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
286
294
287 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
295 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
288
296
289 return RTEMS_SUCCESSFUL;
297 return RTEMS_SUCCESSFUL;
290 }
298 }
299
300 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // No Port force
301 {
302 unsigned int *spwptr;
303 spwptr = (unsigned int*) regAddr;
304 if (val == 1)
305 {
306 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
307 }
308 if (val== 0)
309 {
310 *spwptr = *spwptr & 0xffdfffff;
311 }
312 }
313
314 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // RMAP Enable
315 {
316 unsigned int *spwptr;
317 spwptr = (unsigned int*) regAddr;
318 if (val == 1)
319 {
320 *spwptr = *spwptr | 0x00010000; // [NP] set the No port force bit
321 }
322 if (val== 0)
323 {
324 *spwptr = *spwptr & 0xfffdffff;
325 }
326 }
291
327
292 char *link_status(int status){
328 char *link_status(int status){
293 return lstates[status];
329 return lstates[status];
294 }
330 }
295
331
296 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
332 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
297 {
333 {
298 rtems_status_code status;
334 rtems_status_code status;
299 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
335 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
300 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
336 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
301 return status;
337 return status;
302 }
338 }
303
339
340 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
341 {
342 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
343 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
344 }
304
345
@@ -1,520 +1,531
1 #include <tc_handler.h>
1 #include <tc_handler.h>
2 #include <fsw_params.h>
2 #include <fsw_params.h>
3
3
4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
5 "WRONG_LEN_PACKET 1",
5 "WRONG_LEN_PACKET 1",
6 "INCOR_CHECKSUM 2",
6 "INCOR_CHECKSUM 2",
7 "ILL_TYPE 3",
7 "ILL_TYPE 3",
8 "ILL_SUBTYPE 4",
8 "ILL_SUBTYPE 4",
9 "WRONG_APP_DATA 5",
9 "WRONG_APP_DATA 5",
10 "WRONG_CMD_CODE 6",
10 "WRONG_CMD_CODE 6",
11 "CCSDS_TM_VALID 7"
11 "CCSDS_TM_VALID 7"
12 };
12 };
13
13
14 //**********************
14 //**********************
15 // GENERAL USE FUNCTIONS
15 // GENERAL USE FUNCTIONS
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 {
17 {
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
19 }
19 }
20
20
21 void initLookUpTableForCRC()
21 void initLookUpTableForCRC()
22 {
22 {
23 unsigned int i, tmp;
23 unsigned int i, tmp;
24 for (i=0; i<256; i++)
24 for (i=0; i<256; i++)
25 {
25 {
26 tmp = 0;
26 tmp = 0;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
35 lookUpTableForCRC[i] = tmp;
35 lookUpTableForCRC[i] = tmp;
36 }
36 }
37 }
37 }
38
38
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
40 {
40 {
41 unsigned int Chk;
41 unsigned int Chk;
42 int j;
42 int j;
43 Chk = 0xffff; // reset the syndrom to all ones
43 Chk = 0xffff; // reset the syndrom to all ones
44 for (j=0; j<sizeOfData; j++) {
44 for (j=0; j<sizeOfData; j++) {
45 Chk = Crc_opt(data[j], Chk);
45 Chk = Crc_opt(data[j], Chk);
46 }
46 }
47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
49 }
49 }
50
50
51
51
52 //*********************
52 //*********************
53 // ACCEPTANCE FUNCTIONS
53 // ACCEPTANCE FUNCTIONS
54 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
54 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
55 {
55 {
56 rtems_status_code status;
56 rtems_status_code status;
57 spw_ioctl_pkt_send spw_ioctl_send;
57 spw_ioctl_pkt_send spw_ioctl_send;
58 TMHeader_t TM_header;
58 TMHeader_t TM_header;
59 unsigned int code = 0;
59 unsigned int code = 0;
60 unsigned char computed_CRC[2];
60 unsigned char computed_CRC[2];
61 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
61 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
62
62
63 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
63 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
64 code = acceptTM( TC, tc_len_recv ) ;
64 code = acceptTM( TC, tc_len_recv ) ;
65 if ( (code == 0) | (code == 1) | (code == 2)
65 if ( (code == 0) | (code == 1) | (code == 2)
66 | (code == 3) | (code == 4) | (code == 5) )
66 | (code == 3) | (code == 4) | (code == 5) )
67 { // generate TM_LFR_TC_EXE_CORRUPTED
67 { // generate TM_LFR_TC_EXE_CORRUPTED
68 // BUILD HEADER
68 // BUILD HEADER
69 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
69 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
70 // BUILD DATA
70 // BUILD DATA
71 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
71 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
72 // PREPARE TM SENDING
72 // PREPARE TM SENDING
73 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
73 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
74 spw_ioctl_send.hdr = (char*) &TM_header;
74 spw_ioctl_send.hdr = (char*) &TM_header;
75 spw_ioctl_send.dlen = 16;
75 spw_ioctl_send.dlen = 16;
76 spw_ioctl_send.data = data;
76 spw_ioctl_send.data = data;
77 // SEND PACKET
77 // SEND PACKET
78 write_spw(&spw_ioctl_send);
78 write_spw(&spw_ioctl_send);
79 }
79 }
80 else { // send valid TC to the action launcher
80 else { // send valid TC to the action launcher
81 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
81 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
82 return -1;
82 return -1;
83 }
83 }
84 return -1;
84 return -1;
85 }
85 }
86
86
87 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
87 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
88 {
88 {
89 unsigned char pid = 0;
89 unsigned char pid = 0;
90 unsigned char category = 0;
90 unsigned char category = 0;
91 unsigned int length = 0;
91 unsigned int length = 0;
92 unsigned char packetType = 0;
92 unsigned char packetType = 0;
93 unsigned char packetSubtype = 0;
93 unsigned char packetSubtype = 0;
94 unsigned char * CCSDSContent;
94 unsigned char * CCSDSContent;
95
95
96 // APID check *** APID on 2 bytes
96 // APID check *** APID on 2 bytes
97 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
97 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
98 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
98 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
99 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
99 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
100 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
100 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
101
101
102 // packet length check
102 // packet length check
103 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
103 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
104 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
104 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
105 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
105 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
106
106
107 packetType = TMPacket->dataFieldHeader[1];
107 packetType = TMPacket->dataFieldHeader[1];
108 packetSubtype = TMPacket->dataFieldHeader[2];
108 packetSubtype = TMPacket->dataFieldHeader[2];
109 // service type, subtype and packet length check
109 // service type, subtype and packet length check
110 if (packetType == 181){
110 if (packetType == 181){
111 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
111 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
112 case 3:
112 case 3:
113 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
113 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
114 break;
114 break;
115 case 20:
115 case 20:
116 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
116 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
117 break;
117 break;
118 case 21:
118 case 21:
119 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
119 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
120 break;
120 break;
121 case 24:
121 case 24:
122 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
122 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
123 break;
123 break;
124 case 27:
124 case 27:
125 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
125 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
126 break;
126 break;
127 case 28:
127 case 28:
128 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
128 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
129 break;
129 break;
130 case 30:
130 case 30:
131 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
131 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
132 break;
132 break;
133 case 40:
133 case 40:
134 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
134 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
135 break;
135 break;
136 case 50:
136 case 50:
137 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
137 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
138 break;
138 break;
139 case 60:
139 case 60:
140 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
140 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
141 break;
141 break;
142 case 61:
142 case 61:
143 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
143 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
144 break;
144 break;
145 default:
145 default:
146 return ILL_SUBTYPE;
146 return ILL_SUBTYPE;
147 break;
147 break;
148 }
148 }
149 }
149 }
150 else if (packetType == 9){
150 else if (packetType == 9){
151 if (packetSubtype!=129) return ILL_SUBTYPE;
151 if (packetSubtype!=129) return ILL_SUBTYPE;
152 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
152 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
153 }
153 }
154 else return ILL_TYPE;
154 else return ILL_TYPE;
155
155
156 // source ID check // Source ID not documented in the ICD
156 // source ID check // Source ID not documented in the ICD
157
157
158 // packet error control, CRC check
158 // packet error control, CRC check
159 CCSDSContent = (unsigned char*) TMPacket->packetID;
159 CCSDSContent = (unsigned char*) TMPacket->packetID;
160 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
160 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
161 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
161 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
162 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
162 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
163
163
164 return CCSDS_TM_VALID;
164 return CCSDS_TM_VALID;
165 }
165 }
166
166
167 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
167 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
168 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
168 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
169 {
169 {
170 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
170 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
171 TMHeader->protocolIdentifier = 0x02;
171 TMHeader->protocolIdentifier = 0x02;
172 TMHeader->reserved = 0x00;
172 TMHeader->reserved = 0x00;
173 TMHeader->userApplication = 0x00;
173 TMHeader->userApplication = 0x00;
174 TMHeader->packetID[0] = 0x0c;
174 TMHeader->packetID[0] = 0x0c;
175 TMHeader->packetSequenceControl[0] = 0xc0;
175 TMHeader->packetSequenceControl[0] = 0xc0;
176 TMHeader->packetSequenceControl[1] = 0x00;
176 TMHeader->packetSequenceControl[1] = 0x00;
177 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
177 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
178 TMHeader->packetLength[1] = (unsigned char) packetLength;
178 TMHeader->packetLength[1] = (unsigned char) packetLength;
179 TMHeader->dataFieldHeader[0] = 0x10;
179 TMHeader->dataFieldHeader[0] = 0x10;
180 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
180 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
181 switch (tm_type){
181 switch (tm_type){
182 case(TM_LFR_TC_EXE_OK):
182 case(TM_LFR_TC_EXE_OK):
183 TMHeader->packetID[1] = 0xc1;
183 TMHeader->packetID[1] = 0xc1;
184 TMHeader->dataFieldHeader[1] = 1; // type
184 TMHeader->dataFieldHeader[1] = 1; // type
185 TMHeader->dataFieldHeader[2] = 7; // subtype
185 TMHeader->dataFieldHeader[2] = 7; // subtype
186 break;
186 break;
187 case(TM_LFR_TC_EXE_ERR):
187 case(TM_LFR_TC_EXE_ERR):
188 TMHeader->packetID[1] = 0xc1;
188 TMHeader->packetID[1] = 0xc1;
189 TMHeader->dataFieldHeader[1] = 1; // type
189 TMHeader->dataFieldHeader[1] = 1; // type
190 TMHeader->dataFieldHeader[2] = 8; // subtype
190 TMHeader->dataFieldHeader[2] = 8; // subtype
191 break;
191 break;
192 case(TM_LFR_HK):
192 case(TM_LFR_HK):
193 TMHeader->packetID[1] = 0xc4;
193 TMHeader->packetID[1] = 0xc4;
194 TMHeader->dataFieldHeader[1] = 3; // type
194 TMHeader->dataFieldHeader[1] = 3; // type
195 TMHeader->dataFieldHeader[2] = 25; // subtype
195 TMHeader->dataFieldHeader[2] = 25; // subtype
196 break;
196 break;
197 case(TM_LFR_SCI):
197 case(TM_LFR_SCI):
198 TMHeader->packetID[1] = 0xcc;
198 TMHeader->packetID[1] = 0xcc;
199 TMHeader->dataFieldHeader[1] = 21; // type
199 TMHeader->dataFieldHeader[1] = 21; // type
200 TMHeader->dataFieldHeader[2] = 3; // subtype
200 TMHeader->dataFieldHeader[2] = 3; // subtype
201 break;
201 break;
202 case(TM_LFR_SCI_SBM):
202 case(TM_LFR_SCI_SBM):
203 TMHeader->packetID[1] = 0xfc;
203 TMHeader->packetID[1] = 0xfc;
204 TMHeader->dataFieldHeader[1] = 21; // type
204 TMHeader->dataFieldHeader[1] = 21; // type
205 TMHeader->dataFieldHeader[2] = 3; // subtype
205 TMHeader->dataFieldHeader[2] = 3; // subtype
206 break;
206 break;
207 case(TM_LFR_PAR_DUMP):
207 case(TM_LFR_PAR_DUMP):
208 TMHeader->packetID[1] = 0xc9;
208 TMHeader->packetID[1] = 0xc9;
209 TMHeader->dataFieldHeader[1] = 181; // type
209 TMHeader->dataFieldHeader[1] = 181; // type
210 TMHeader->dataFieldHeader[2] = 31; // subtype
210 TMHeader->dataFieldHeader[2] = 31; // subtype
211 break;
211 break;
212 default:
212 default:
213 return 0;
213 return 0;
214 }
214 }
215 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
215 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
216 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
216 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
217 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
217 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
218 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
218 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
219 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
219 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
220 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
220 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
221 return 1;
221 return 1;
222 }
222 }
223
223
224 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
224 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
225 {
225 {
226 unsigned int packetLength;
226 unsigned int packetLength;
227 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
227 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
228 switch (SID){
228 switch (SID){
229 case (SID_NOT_EXE):
229 case (SID_NOT_EXE):
230 break;
230 break;
231 case (SID_NOT_IMP):
231 case (SID_NOT_IMP):
232 data[0] = 0x9c;
232 data[0] = 0x9c;
233 data[1] = 0x42;
233 data[1] = 0x42;
234 data[2] = TC->packetID[0];
234 data[2] = TC->packetID[0];
235 data[3] = TC->packetID[1];
235 data[3] = TC->packetID[1];
236 data[4] = TC->packetSequenceControl[0];
236 data[4] = TC->packetSequenceControl[0];
237 data[5] = TC->packetSequenceControl[1];
237 data[5] = TC->packetSequenceControl[1];
238 data[6] = TC->dataFieldHeader[1]; // type
238 data[6] = TC->dataFieldHeader[1]; // type
239 data[7] = TC->dataFieldHeader[2]; // subtype
239 data[7] = TC->dataFieldHeader[2]; // subtype
240 break;
240 break;
241 case (SID_EXE_ERR):
241 case (SID_EXE_ERR):
242 break;
242 break;
243 case (SID_EXE_CORR):
243 case (SID_EXE_CORR):
244 data[0] = 0x9c;
244 data[0] = 0x9c;
245 data[1] = 0x45;
245 data[1] = 0x45;
246 data[2] = TC->packetID[0];
246 data[2] = TC->packetID[0];
247 data[3] = TC->packetID[1];
247 data[3] = TC->packetID[1];
248 data[4] = TC->packetSequenceControl[0];
248 data[4] = TC->packetSequenceControl[0];
249 data[5] = TC->packetSequenceControl[1];
249 data[5] = TC->packetSequenceControl[1];
250 data[6] = TC->dataFieldHeader[1]; // type
250 data[6] = TC->dataFieldHeader[1]; // type
251 data[7] = TC->dataFieldHeader[2]; // subtype
251 data[7] = TC->dataFieldHeader[2]; // subtype
252 data[8] = currentTC_LEN_RCV[0];
252 data[8] = currentTC_LEN_RCV[0];
253 data[9] = currentTC_LEN_RCV[1];
253 data[9] = currentTC_LEN_RCV[1];
254 data[10] = TC->packetLength[0];
254 data[10] = TC->packetLength[0];
255 data[11] = TC->packetLength[1];
255 data[11] = TC->packetLength[1];
256 data[12] = TC->dataAndCRC[packetLength];
256 data[12] = TC->dataAndCRC[packetLength];
257 data[13] = TC->dataAndCRC[packetLength+1];
257 data[13] = TC->dataAndCRC[packetLength+1];
258 data[14] = computed_CRC[0];
258 data[14] = computed_CRC[0];
259 data[15] = computed_CRC[1];
259 data[15] = computed_CRC[1];
260 break;
260 break;
261 default:
261 default:
262 return 0;
262 return 0;
263 }
263 }
264 return 1;
264 return 1;
265 }
265 }
266
266
267 //***********
267 //***********
268 // RTEMS TASK
268 // RTEMS TASK
269 rtems_task recv_task( rtems_task_argument unused )
269 rtems_task recv_task( rtems_task_argument unused )
270 {
270 {
271 int len = 0;
271 int len = 0;
272 unsigned int i = 0;
272 unsigned int i = 0;
273 unsigned int data_length = 0;
273 unsigned int data_length = 0;
274 ccsdsTelecommandPacket_t currentTC;
274 ccsdsTelecommandPacket_t currentTC;
275 char data[100];
275 char data[100];
276
276
277 for(i=0; i<100; i++) data[i] = 0;
277 for(i=0; i<100; i++) data[i] = 0;
278
278
279 PRINTF("In RECV *** \n")
279 PRINTF("In RECV *** \n")
280
280
281 while(1)
281 while(1)
282 {
282 {
283 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
283 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
284 if (len == -1){ // error during the read call
284 if (len == -1){ // error during the read call
285 PRINTF("In RECV *** last read call returned -1\n")
285 PRINTF("In RECV *** last read call returned -1\n")
286 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
286 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
287 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
287 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
288 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
288 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
289 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
289 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
290 }
290 }
291 else {
291 else {
292 PRINTF1("Got pck of length %d\n", len+1)
292 PRINTF1("Got pck of length %d\n", len+1)
293 currentTC_LEN_RCV[0] = 0x00;
293 currentTC_LEN_RCV[0] = 0x00;
294 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
294 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
295 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
295 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
296 // CHECK THE TC AND BUILD THE APPROPRIATE TM
296 // CHECK THE TC AND BUILD THE APPROPRIATE TM
297 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
297 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
298 if (data_length!=-1)
298 if (data_length!=-1)
299 {
299 {
300 }
300 }
301 }
301 }
302 }
302 }
303 }
303 }
304
304
305 rtems_task actn_task( rtems_task_argument unused )
305 rtems_task actn_task( rtems_task_argument unused )
306 {
306 {
307 int result = 0;
307 int result = 0;
308 rtems_status_code status; // RTEMS status code
308 rtems_status_code status; // RTEMS status code
309 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
309 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
310 size_t size; // size of the incoming TC packet
310 size_t size; // size of the incoming TC packet
311 unsigned char subtype = 0; // subtype of the current TC packet
311 unsigned char subtype = 0; // subtype of the current TC packet
312
312
313 PRINTF("In ACTN *** \n")
313 PRINTF("In ACTN *** \n")
314
314
315 while(1)
315 while(1)
316 {
316 {
317 status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size,
317 status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size,
318 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
318 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
319 if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status)
319 if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status)
320 else
320 else
321 {
321 {
322 subtype = TC.dataFieldHeader[2];
322 subtype = TC.dataFieldHeader[2];
323 switch(subtype)
323 switch(subtype)
324 {
324 {
325 case TC_SUBTYPE_RESET:
325 case TC_SUBTYPE_RESET:
326 result = action_default( &TC );
326 result = action_default( &TC );
327 break;
327 break;
328 //
328 //
329 case TC_SUBTYPE_LOAD_COMM:
329 case TC_SUBTYPE_LOAD_COMM:
330 result = action_default( &TC );
330 result = action_default( &TC );
331 break;
331 break;
332 //
332 //
333 case TC_SUBTYPE_LOAD_NORM:
333 case TC_SUBTYPE_LOAD_NORM:
334 result = action_load_norm( &TC );
334 result = action_load_norm( &TC );
335 send_tm_lfr_tc_exe_success( &TC );
335 send_tm_lfr_tc_exe_success( &TC );
336 break;
336 break;
337 //
337 //
338 case TC_SUBTYPE_LOAD_BURST:
338 case TC_SUBTYPE_LOAD_BURST:
339 result = action_default( &TC );
339 result = action_default( &TC );
340 break;
340 break;
341 //
341 //
342 case TC_SUBTYPE_LOAD_SBM1:
342 case TC_SUBTYPE_LOAD_SBM1:
343 result = action_default( &TC );
343 result = action_default( &TC );
344 break;
344 break;
345 //
345 //
346 case TC_SUBTYPE_LOAD_SBM2:
346 case TC_SUBTYPE_LOAD_SBM2:
347 result = action_default( &TC );
347 result = action_default( &TC );
348 break;
348 break;
349 //
349 //
350 case TC_SUBTYPE_DUMP:
350 case TC_SUBTYPE_DUMP:
351 result = action_default( &TC );
351 result = action_default( &TC );
352 break;
352 break;
353 //
353 //
354 case TC_SUBTYPE_ENTER:
354 case TC_SUBTYPE_ENTER:
355 result = action_enter( &TC );
355 result = action_enter( &TC );
356 send_tm_lfr_tc_exe_success( &TC );
356 send_tm_lfr_tc_exe_success( &TC );
357 break;
357 break;
358 //
358 //
359 case TC_SUBTYPE_UPDT_INFO:
359 case TC_SUBTYPE_UPDT_INFO:
360 result = action_default( &TC );
360 result = action_default( &TC );
361 break;
361 break;
362 //
362 //
363 case TC_SUBTYPE_EN_CAL:
363 case TC_SUBTYPE_EN_CAL:
364 result = action_default( &TC );
364 result = action_default( &TC );
365 break;
365 break;
366 //
366 //
367 case TC_SUBTYPE_DIS_CAL:
367 case TC_SUBTYPE_DIS_CAL:
368 result = action_default( &TC );
368 result = action_default( &TC );
369 break;
369 break;
370 //
370 //
371 case TC_SUBTYPE_UPDT_TIME:
371 case TC_SUBTYPE_UPDT_TIME:
372 result = action_updt_time( &TC );
372 result = action_updt_time( &TC );
373 send_tm_lfr_tc_exe_success( &TC );
373 send_tm_lfr_tc_exe_success( &TC );
374 break;
374 break;
375 //
375 //
376 default:
376 default:
377 break;
377 break;
378 }
378 }
379 }
379 }
380 }
380 }
381 }
381 }
382
382
383 int create_message_queue()
383 int create_message_queue()
384 {
384 {
385 rtems_status_code status;
385 rtems_status_code status;
386 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
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,
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] );
388 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
390
390
391 return 0;
391 return 0;
392 }
392 }
393
393
394 //***********
394 //***********
395 // TC ACTIONS
395 // TC ACTIONS
396
396 int action_default(ccsdsTelecommandPacket_t *TC)
397 int action_default(ccsdsTelecommandPacket_t *TC)
397 {
398 {
398 char data[100]; // buffer for the generic TM packet
399 TMHeader_t TM_header;
399 TMHeader_t TM_header; // TM header
400 char data[8];
400 spw_ioctl_pkt_send spw_ioctl_send; // structure to send the TM packet if any
401 spw_ioctl_pkt_send spw_ioctl_send;
401 // BUILD HEADER
402
402 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP, 0, 0, &TM_header);
403 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
403 // BUILD DATA
404 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
404 TM_build_data( TC, data, SID_NOT_IMP, NULL);
405
405 // filling the strture for the spcawire transmission
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
406 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
416 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
407 spw_ioctl_send.hdr = (char*) &TM_header;
417 spw_ioctl_send.hdr = (char*) &TM_header;
408 spw_ioctl_send.dlen = 8;
418 spw_ioctl_send.dlen = 8;
409 spw_ioctl_send.data = data;
419 spw_ioctl_send.data = data;
420
410 // SEND DATA
421 // SEND DATA
411 write_spw(&spw_ioctl_send);
422 write_spw(&spw_ioctl_send);
412
423
413 return 0;
424 return 0;
414 }
425 }
415
426
416 int action_enter(ccsdsTelecommandPacket_t *TC)
427 int action_enter(ccsdsTelecommandPacket_t *TC)
417 {
428 {
418 unsigned char lfr_mode = TC->dataAndCRC[1];
429 unsigned char lfr_mode = TC->dataAndCRC[1];
419 printf("enter mode %d\n", lfr_mode);
430 printf("enter mode %d\n", lfr_mode);
420 switch(lfr_mode)
431 switch(lfr_mode)
421 {
432 {
422 case(LFR_MODE_STANDBY):
433 case(LFR_MODE_STANDBY):
423 LEON_Mask_interrupt( IRQ_WF );
434 LEON_Mask_interrupt( IRQ_WF );
424 LEON_Mask_interrupt( IRQ_SM );
435 LEON_Mask_interrupt( IRQ_SM );
425 break;
436 break;
426 case(LFR_MODE_NORMAL):
437 case(LFR_MODE_NORMAL):
427 LEON_Unmask_interrupt( IRQ_WF );
438 LEON_Unmask_interrupt( IRQ_WF );
428 LEON_Unmask_interrupt( IRQ_SM );
439 LEON_Unmask_interrupt( IRQ_SM );
429 break;
440 break;
430 case(LFR_MODE_BURST):
441 case(LFR_MODE_BURST):
431 break;
442 break;
432 case(LFR_MODE_SBM1):
443 case(LFR_MODE_SBM1):
433 break;
444 break;
434 case(LFR_MODE_SBM2):
445 case(LFR_MODE_SBM2):
435 break;
446 break;
436 }
447 }
437 return 0;
448 return 0;
438 }
449 }
439
450
440 int action_load_norm(ccsdsTelecommandPacket_t *TC)
451 int action_load_norm(ccsdsTelecommandPacket_t *TC)
441 {
452 {
442 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
453 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
443 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
454 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
444 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
455 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
445 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
456 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
446 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
457 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
447 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
458 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
448 param_norm.sy_lfr_n_swf_l, param_norm.sy_lfr_n_swf_p,
459 param_norm.sy_lfr_n_swf_l, param_norm.sy_lfr_n_swf_p,
449 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/
460 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/
450 return 0;
461 return 0;
451 }
462 }
452
463
453 int action_updt_time(ccsdsTelecommandPacket_t *TC)
464 int action_updt_time(ccsdsTelecommandPacket_t *TC)
454 {
465 {
455 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
466 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
456 + (TC->dataAndCRC[1] << 16)
467 + (TC->dataAndCRC[1] << 16)
457 + (TC->dataAndCRC[2] << 8)
468 + (TC->dataAndCRC[2] << 8)
458 + TC->dataAndCRC[3];
469 + TC->dataAndCRC[3];
459 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
470 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
460 return 0;
471 return 0;
461 }
472 }
462
473
463 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
474 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
464 {
475 {
465 TMHeader_t TM_header;
476 TMHeader_t TM_header;
466 char data[4];
477 char data[4];
467 spw_ioctl_pkt_send spw_ioctl_send;
478 spw_ioctl_pkt_send spw_ioctl_send;
468
479
469 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
480 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
470 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
481 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
471
482
472 data[0] = TC->packetID[0];
483 data[0] = TC->packetID[0];
473 data[1] = TC->packetID[1];
484 data[1] = TC->packetID[1];
474 data[2] = TC->packetSequenceControl[0];
485 data[2] = TC->packetSequenceControl[0];
475 data[3] = TC->packetSequenceControl[1];
486 data[3] = TC->packetSequenceControl[1];
476
487
477 // filling the structure for the spacewire transmission
488 // filling the structure for the spacewire transmission
478 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
489 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
479 spw_ioctl_send.hdr = (char*) &TM_header;
490 spw_ioctl_send.hdr = (char*) &TM_header;
480 spw_ioctl_send.dlen = 3;
491 spw_ioctl_send.dlen = 3;
481 spw_ioctl_send.data = data;
492 spw_ioctl_send.data = data;
482
493
483 // SEND DATA
494 // SEND DATA
484 write_spw(&spw_ioctl_send);
495 write_spw(&spw_ioctl_send);
485
496
486 return 0;
497 return 0;
487 }
498 }
488
499
489 //***************************
500 //***************************
490 // Interrupt Service Routines
501 // Interrupt Service Routines
491 rtems_isr commutation_isr1( rtems_vector_number vector )
502 rtems_isr commutation_isr1( rtems_vector_number vector )
492 {
503 {
493 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
504 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
494 printf("In spectral_matrices_isr *** Error sending event to DUMB\n");
505 printf("In commutation_isr1 *** Error sending event to DUMB\n");
495 }
506 }
496
507
497 rtems_isr commutation_isr2( rtems_vector_number vector )
508 rtems_isr commutation_isr2( rtems_vector_number vector )
498 {
509 {
499 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
510 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
500 printf("In spectral_matrices_isr *** Error sending event to DUMB\n");
511 printf("In commutation_isr2 *** Error sending event to DUMB\n");
501 }
512 }
502
513
503 rtems_task dumb_task( rtems_task_argument unused )
514 rtems_task dumb_task( rtems_task_argument unused )
504 {
515 {
505 unsigned int coarse_time;
516 unsigned int coarse_time;
506 unsigned int fine_time;
517 unsigned int fine_time;
507 rtems_event_set event_out;
518 rtems_event_set event_out;
508
519
509 PRINTF("In DUMB *** \n")
520 PRINTF("In DUMB *** \n")
510
521
511 while(1){
522 while(1){
512 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
523 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
513 coarse_time = time_management_regs->coarse_time;
524 coarse_time = time_management_regs->coarse_time;
514 fine_time = time_management_regs->fine_time;
525 fine_time = time_management_regs->fine_time;
515 printf("commutation_isr*, coarse time = %x, fine time = %x\n", coarse_time, fine_time);
526 printf("commutation_isr*, coarse time = %x, fine time = %x\n", coarse_time, fine_time);
516 }
527 }
517 }
528 }
518
529
519
530
520
531
@@ -1,115 +1,115
1 #include <wf_handler.h>
1 #include <wf_handler.h>
2
2
3 rtems_isr waveforms_isr( rtems_vector_number vector )
3 rtems_isr waveforms_isr( rtems_vector_number vector )
4 {
4 {
5 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
5 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
6 printf("In spectral_matrices_isr *** Error sending event to WFRM\n");
6 printf("In waveforms_isr *** Error sending event to WFRM\n");
7 }
7 }
8
8
9 rtems_task wfrm_task(rtems_task_argument argument)
9 rtems_task wfrm_task(rtems_task_argument argument)
10 {
10 {
11 unsigned int length;
11 unsigned int length;
12 unsigned int i = 0;
12 unsigned int i = 0;
13 spw_ioctl_pkt_send spw_ioctl_send;
13 spw_ioctl_pkt_send spw_ioctl_send;
14 rtems_event_set event_out;
14 rtems_event_set event_out;
15 gptimer_regs_t *gptimer_regs;
15 gptimer_regs_t *gptimer_regs;
16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
17 ExtendedTMHeader_t header;
17 ExtendedTMHeader_t header;
18
18
19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
20 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
20 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
21 header.reserved = 0x00;
21 header.reserved = 0x00;
22 header.userApplication = CCSDS_USER_APP;
22 header.userApplication = CCSDS_USER_APP;
23 header.packetID[0] = 0x0c;
23 header.packetID[0] = 0x0c;
24 header.packetID[1] = 0xcc;
24 header.packetID[1] = 0xcc;
25 header.packetSequenceControl[0] = 0x00;
25 header.packetSequenceControl[0] = 0x00;
26 header.packetSequenceControl[1] = 0x00;
26 header.packetSequenceControl[1] = 0x00;
27 header.packetLength[0] = 0x00;
27 header.packetLength[0] = 0x00;
28 header.packetLength[1] = 0x00;
28 header.packetLength[1] = 0x00;
29 header.dataFieldHeader[0] = 0x10;
29 header.dataFieldHeader[0] = 0x10;
30 header.dataFieldHeader[1] = 0x15; // service type
30 header.dataFieldHeader[1] = 0x15; // service type
31 header.dataFieldHeader[2] = 0x03; // service subtype
31 header.dataFieldHeader[2] = 0x03; // service subtype
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID;
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID;
33
33
34 header.auxiliaryHeader[0] = 0x00;
34 header.auxiliaryHeader[0] = 0x00;
35 header.auxiliaryHeader[1] = 0x1f;
35 header.auxiliaryHeader[1] = 0x1f;
36 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
36 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
37 header.auxiliaryHeader[3] = 0x00; // PKT_NR
37 header.auxiliaryHeader[3] = 0x00; // PKT_NR
38 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
38 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
39 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
39 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
40
40
41 // BUILD THE PACKET HEADER
41 // BUILD THE PACKET HEADER
42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
43 spw_ioctl_send.hdr = (char*) &header;
43 spw_ioctl_send.hdr = (char*) &header;
44
44
45 PRINTF("In WFRM *** \n")
45 PRINTF("In WFRM *** \n")
46
46
47 while(1){
47 while(1){
48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
49 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
49 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
50 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
50 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
51 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
51 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
52 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
52 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
53 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
53 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
55 for (i=0; i<7; i++) // send F0
55 for (i=0; i<7; i++) // send F0
56 {
56 {
57 // BUILD THE DATA
57 // BUILD THE DATA
58 if (i==6) {
58 if (i==6) {
59 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
59 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
60 length = TM_LEN_SCI_NORM_SWF_340;
60 length = TM_LEN_SCI_NORM_SWF_340;
61 }
61 }
62 else {
62 else {
63 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
63 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
64 length = TM_LEN_SCI_NORM_SWF_8;
64 length = TM_LEN_SCI_NORM_SWF_8;
65 }
65 }
66 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
66 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
67 // BUILD THE HEADER
67 // BUILD THE HEADER
68 header.packetLength[0] = (unsigned char) (length>>8);
68 header.packetLength[0] = (unsigned char) (length>>8);
69 header.packetLength[1] = (unsigned char) (length);
69 header.packetLength[1] = (unsigned char) (length);
70 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
70 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
71 // SEND PACKET
71 // SEND PACKET
72 write_spw(&spw_ioctl_send);
72 write_spw(&spw_ioctl_send);
73 }
73 }
74 for (i=0; i<7; i++) // send F1
74 for (i=0; i<7; i++) // send F1
75 {
75 {
76 // BUILD THE DATA
76 // BUILD THE DATA
77 if (i==6) {
77 if (i==6) {
78 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
78 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
79 length = TM_LEN_SCI_NORM_SWF_340;
79 length = TM_LEN_SCI_NORM_SWF_340;
80 }
80 }
81 else {
81 else {
82 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
82 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
83 length = TM_LEN_SCI_NORM_SWF_8;
83 length = TM_LEN_SCI_NORM_SWF_8;
84 }
84 }
85 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
85 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
86 // BUILD THE HEADER
86 // BUILD THE HEADER
87 header.packetLength[0] = (unsigned char) (length>>8);
87 header.packetLength[0] = (unsigned char) (length>>8);
88 header.packetLength[1] = (unsigned char) (length);
88 header.packetLength[1] = (unsigned char) (length);
89 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
89 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
90 // SEND PACKET
90 // SEND PACKET
91 write_spw(&spw_ioctl_send);
91 write_spw(&spw_ioctl_send);
92 }
92 }
93 for (i=0; i<7; i++) // send F0
93 for (i=0; i<7; i++) // send F0
94 {
94 {
95 // BUILD THE DATA
95 // BUILD THE DATA
96 if (i==6) {
96 if (i==6) {
97 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
97 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
98 length = TM_LEN_SCI_NORM_SWF_340;
98 length = TM_LEN_SCI_NORM_SWF_340;
99 }
99 }
100 else {
100 else {
101 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
101 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
102 length = TM_LEN_SCI_NORM_SWF_8;
102 length = TM_LEN_SCI_NORM_SWF_8;
103 }
103 }
104 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
104 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
105 // BUILD THE HEADER
105 // BUILD THE HEADER
106 header.packetLength[0] = (unsigned char) (length>>8);
106 header.packetLength[0] = (unsigned char) (length>>8);
107 header.packetLength[1] = (unsigned char) (length);
107 header.packetLength[1] = (unsigned char) (length);
108 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
108 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
109 // SEND PACKET
109 // SEND PACKET
110 write_spw(&spw_ioctl_send);
110 write_spw(&spw_ioctl_send);
111 }
111 }
112 // irq processed, reset the related register of the timer unit
112 // irq processed, reset the related register of the timer unit
113 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
113 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
114 }
114 }
115 }
115 }
General Comments 0
You need to be logged in to leave comments. Login now