@@ -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=" |
|
4 | <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3"> | |
5 | <Cursor position="3403" topLine="101" /> |
|
5 | <Cursor position="3403" topLine="101" /> | |
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="3"> | |
8 |
<Cursor position="8 |
|
8 | <Cursor position="378" topLine="0" /> | |
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=" |
|
13 | <File name="../header/fsw_params.h" open="0" top="0" tabpos="2"> | |
14 |
<Cursor position=" |
|
14 | <Cursor position="1358" topLine="31" /> | |
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=" |
|
17 | <Cursor position="628" topLine="7" /> | |
18 | </File> |
|
18 | </File> | |
19 |
<File name="../header/grlib_regs.h" open="0" top="0" tabpos=" |
|
19 | <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4"> | |
20 |
<Cursor position="1 |
|
20 | <Cursor position="1153" topLine="11" /> | |
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="4 |
|
23 | <Cursor position="624" topLine="2" /> | |
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=" |
|
26 | <Cursor position="318" topLine="0" /> | |
27 | </File> |
|
27 | </File> | |
28 |
<File name="../src/fsw_globals.c" open="0" top="0" tabpos=" |
|
28 | <File name="../src/fsw_globals.c" open="0" top="0" tabpos="3"> | |
29 |
<Cursor position=" |
|
29 | <Cursor position="378" topLine="1" /> | |
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=" |
|
32 | <Cursor position="2303" topLine="54" /> | |
33 | </File> |
|
33 | </File> | |
34 |
<File name="../src/fsw_misc.c" open="0" top="0" tabpos=" |
|
34 | <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2"> | |
35 |
<Cursor position=" |
|
35 | <Cursor position="475" topLine="0" /> | |
36 | </File> |
|
36 | </File> | |
37 |
<File name="../src/fsw_processing.c" open="0" top="0" tabpos=" |
|
37 | <File name="../src/fsw_processing.c" open="0" top="0" tabpos="0"> | |
38 |
<Cursor position="1 |
|
38 | <Cursor position="1696" topLine="59" /> | |
39 | </File> |
|
39 | </File> | |
40 | <File name="../src/tc_handler.c" open="1" top="1" tabpos="2"> |
|
40 | <File name="../src/tc_handler.c" open="1" top="1" tabpos="2"> | |
41 |
<Cursor position="1 |
|
41 | <Cursor position="17607" topLine="36" /> | |
42 | </File> |
|
42 | </File> | |
43 |
<File name="../src/wf_handler.c" open="0" top="0" tabpos=" |
|
43 | <File name="../src/wf_handler.c" open="0" top="0" tabpos="4"> | |
44 |
<Cursor position=" |
|
44 | <Cursor position="1660" topLine="24" /> | |
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,92 +1,100 | |||||
1 | #ifndef FSW_RTEMS_CONFIG_H_INCLUDED |
|
1 | #ifndef FSW_RTEMS_CONFIG_H_INCLUDED | |
2 | #define FSW_RTEMS_CONFIG_H_INCLUDED |
|
2 | #define FSW_RTEMS_CONFIG_H_INCLUDED | |
3 |
|
3 | |||
4 | #define GRSPW_DEVICE_NAME "/dev/grspw0" |
|
4 | #define GRSPW_DEVICE_NAME "/dev/grspw0" | |
5 | #define UART_DEVICE_NAME "/dev/console" |
|
5 | #define UART_DEVICE_NAME "/dev/console" | |
6 |
|
6 | |||
7 | //********** |
|
7 | //********** | |
8 | // LFR MODES |
|
8 | // LFR MODES | |
9 | #define LFR_MODE_STANDBY 0 |
|
9 | #define LFR_MODE_STANDBY 0 | |
10 | #define LFR_MODE_NORMAL 1 |
|
10 | #define LFR_MODE_NORMAL 1 | |
11 | #define LFR_MODE_BURST 2 |
|
11 | #define LFR_MODE_BURST 2 | |
12 | #define LFR_MODE_SBM1 3 |
|
12 | #define LFR_MODE_SBM1 3 | |
13 | #define LFR_MODE_SBM2 4 |
|
13 | #define LFR_MODE_SBM2 4 | |
14 |
|
14 | |||
15 | //***************************** |
|
15 | //***************************** | |
16 | // APB REGISTERS BASE ADDRESSES |
|
16 | // APB REGISTERS BASE ADDRESSES | |
17 | #define REGS_ADDR_APBUART 0x80000100 |
|
17 | #define REGS_ADDR_APBUART 0x80000100 | |
18 | #define REGS_ADDR_GPTIMER 0x80000300 |
|
18 | #define REGS_ADDR_GPTIMER 0x80000300 | |
19 | #define REGS_ADDR_GRSPW 0x80000500 |
|
19 | #define REGS_ADDR_GRSPW 0x80000500 | |
20 | #define REGS_ADDR_TIME_MANAGEMENT 0x80000600 |
|
20 | #define REGS_ADDR_TIME_MANAGEMENT 0x80000600 | |
21 | #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700 |
|
21 | #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700 | |
22 |
|
22 | |||
23 | #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff |
|
23 | #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff | |
24 |
|
24 | |||
|
25 | //********** | |||
|
26 | // IRQ LINES | |||
25 | #define IRQ_SM 9 |
|
27 | #define IRQ_SM 9 | |
26 | #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels |
|
28 | #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels | |
27 | #define IRQ_WF 10 |
|
29 | #define IRQ_WF 10 | |
28 | #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels |
|
30 | #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels | |
|
31 | #define IRQ_TIME1 12 | |||
|
32 | #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels | |||
|
33 | #define IRQ_TIME2 13 | |||
|
34 | #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels | |||
29 |
|
35 | |||
30 | #define CLKDIV_SM_SIMULATOR 9999 |
|
36 | #define CLKDIV_SM_SIMULATOR 9999 | |
31 | #define CLKDIV_WF_SIMULATOR 9999999 |
|
37 | #define CLKDIV_WF_SIMULATOR 9999999 | |
32 | #define TIMER_SM_SIMULATOR 1 |
|
38 | #define TIMER_SM_SIMULATOR 1 | |
33 | #define TIMER_WF_SIMULATOR 2 |
|
39 | #define TIMER_WF_SIMULATOR 2 | |
34 |
|
40 | |||
35 | //****** |
|
41 | //****** | |
36 | // RTEMS |
|
42 | // RTEMS | |
37 | #define TASKID_RECV 1 |
|
43 | #define TASKID_RECV 1 | |
38 | #define TASKID_ACTN 1 |
|
44 | #define TASKID_ACTN 1 | |
39 | #define TASKID_SPIQ 3 |
|
45 | #define TASKID_SPIQ 3 | |
40 | #define TASKID_SMIQ 4 |
|
46 | #define TASKID_SMIQ 4 | |
41 | #define TASKID_STAT 5 |
|
47 | #define TASKID_STAT 5 | |
42 | #define TASKID_AVF0 6 |
|
48 | #define TASKID_AVF0 6 | |
43 | #define TASKID_BPF0 7 |
|
49 | #define TASKID_BPF0 7 | |
44 | #define TASKID_WFRM 8 |
|
50 | #define TASKID_WFRM 8 | |
|
51 | #define TASKID_DUMB 9 | |||
45 |
|
52 | |||
46 | #define ACTION_MSG_QUEUE_COUNT 10 |
|
53 | #define ACTION_MSG_QUEUE_COUNT 10 | |
47 |
|
54 | |||
48 | //******* |
|
55 | //******* | |
49 | // MACROS |
|
56 | // MACROS | |
|
57 | //#define PRINT_TASK_STATISTICS | |||
50 | #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions |
|
58 | #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions | |
51 | #ifdef PRINT_MESSAGES_ON_CONSOLE |
|
59 | #ifdef PRINT_MESSAGES_ON_CONSOLE | |
52 | #define PRINTF(x) printf(x); |
|
60 | #define PRINTF(x) printf(x); | |
53 | #define PRINTF1(x,y) printf(x,y); |
|
61 | #define PRINTF1(x,y) printf(x,y); | |
54 | #define PRINTF2(x,y,z) printf(x,y,z); |
|
62 | #define PRINTF2(x,y,z) printf(x,y,z); | |
55 | #else |
|
63 | #else | |
56 | #define PRINTF(x) ; |
|
64 | #define PRINTF(x) ; | |
57 | #define PRINTF1(x,y) ; |
|
65 | #define PRINTF1(x,y) ; | |
58 | #define PRINTF2(x,y,z) ; |
|
66 | #define PRINTF2(x,y,z) ; | |
59 | #endif |
|
67 | #endif | |
60 |
|
68 | |||
61 | #define NB_SAMPLES_PER_SNAPSHOT 2048 |
|
69 | #define NB_SAMPLES_PER_SNAPSHOT 2048 | |
62 | #define NB_BYTES_SWF_BLK 2 * 6 |
|
70 | #define NB_BYTES_SWF_BLK 2 * 6 | |
63 |
|
71 | |||
64 | struct param_norm_str{ |
|
72 | struct param_norm_str{ | |
65 | unsigned int sy_lfr_n_swf_l; // length of the snapshots |
|
73 | unsigned int sy_lfr_n_swf_l; // length of the snapshots | |
66 | unsigned int sy_lfr_n_swf_p; // time between two snapshots |
|
74 | unsigned int sy_lfr_n_swf_p; // time between two snapshots | |
67 | unsigned int sy_lfr_n_asm_p; // time between two asm |
|
75 | unsigned int sy_lfr_n_asm_p; // time between two asm | |
68 | unsigned char sy_lfr_n_bp_p0; // timebetween two products BP1 set |
|
76 | unsigned char sy_lfr_n_bp_p0; // timebetween two products BP1 set | |
69 | unsigned char sy_lfr_n_bp_p1; // time between two products BP2 set |
|
77 | unsigned char sy_lfr_n_bp_p1; // time between two products BP2 set | |
70 | }; |
|
78 | }; | |
71 |
|
79 | |||
72 | struct param_burst_str{ |
|
80 | struct param_burst_str{ | |
73 | unsigned char sy_lfr_b_bp_p0; // timebetween two products BP1 set |
|
81 | unsigned char sy_lfr_b_bp_p0; // timebetween two products BP1 set | |
74 | unsigned char sy_lfr_b_bp_p1; // time between two products BP2 set |
|
82 | unsigned char sy_lfr_b_bp_p1; // time between two products BP2 set | |
75 | }; |
|
83 | }; | |
76 |
|
84 | |||
77 | struct param_sbm1_str{ |
|
85 | struct param_sbm1_str{ | |
78 | unsigned char sy_lfr_s1_bp_p0; // timebetween two products BP1 set |
|
86 | unsigned char sy_lfr_s1_bp_p0; // timebetween two products BP1 set | |
79 | unsigned char sy_lfr_s1_bp_p1; // time between two products BP2 set |
|
87 | unsigned char sy_lfr_s1_bp_p1; // time between two products BP2 set | |
80 | }; |
|
88 | }; | |
81 |
|
89 | |||
82 | struct param_sbm2_str{ |
|
90 | struct param_sbm2_str{ | |
83 | unsigned char sy_lfr_s2_bp_p0; // timebetween two products BP1 set |
|
91 | unsigned char sy_lfr_s2_bp_p0; // timebetween two products BP1 set | |
84 | unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set |
|
92 | unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set | |
85 | }; |
|
93 | }; | |
86 |
|
94 | |||
87 | extern volatile int wf_snap_f0[ ]; // 24576 bytes |
|
95 | extern volatile int wf_snap_f0[ ]; // 24576 bytes | |
88 | extern volatile int wf_snap_f1[ ]; // 24576 bytes |
|
96 | extern volatile int wf_snap_f1[ ]; // 24576 bytes | |
89 | extern volatile int wf_snap_f2[ ]; // 24576 bytes |
|
97 | extern volatile int wf_snap_f2[ ]; // 24576 bytes | |
90 | extern volatile int wf_cont_f3[ ]; // 24576 bytes |
|
98 | extern volatile int wf_cont_f3[ ]; // 24576 bytes | |
91 |
|
99 | |||
92 | #endif // FSW_RTEMS_CONFIG_H_INCLUDED |
|
100 | #endif // FSW_RTEMS_CONFIG_H_INCLUDED |
@@ -1,63 +1,69 | |||||
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 | //**** | |||
|
31 | // ISR | |||
|
32 | rtems_isr commutation_isr1( rtems_vector_number vector ); | |||
|
33 | rtems_isr commutation_isr2( rtems_vector_number vector ); | |||
|
34 | ||||
30 | //********************** |
|
35 | //********************** | |
31 | // GENERAL USE FUNCTIONS |
|
36 | // GENERAL USE FUNCTIONS | |
32 | unsigned int lookUpTableForCRC[256]; |
|
37 | unsigned int lookUpTableForCRC[256]; | |
33 | void initLookUpTableForCRC(); |
|
38 | void initLookUpTableForCRC(); | |
34 | void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData); |
|
39 | void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData); | |
35 |
|
40 | |||
36 | //********************* |
|
41 | //********************* | |
37 | // ACCEPTANCE FUNCTIONS |
|
42 | // ACCEPTANCE FUNCTIONS | |
38 | unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int tc_len_recv); |
|
43 | unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int tc_len_recv); | |
39 |
|
44 | |||
40 | 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, | |
41 | unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader); |
|
46 | unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader); | |
42 | 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); | |
43 | int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV); |
|
48 | int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int TC_LEN_RCV); | |
44 |
|
49 | |||
45 | //*********** |
|
50 | //*********** | |
46 | // RTEMS TASK |
|
51 | // RTEMS TASK | |
47 | rtems_task recv_task( rtems_task_argument unused ); |
|
52 | rtems_task recv_task( rtems_task_argument unused ); | |
48 | 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 ); | |||
49 | int create_message_queue(); |
|
55 | int create_message_queue(); | |
50 |
|
56 | |||
51 | //*********** |
|
57 | //*********** | |
52 | // TC ACTIONS |
|
58 | // TC ACTIONS | |
53 | int action_default(ccsdsTelecommandPacket_t *TC); |
|
59 | int action_default(ccsdsTelecommandPacket_t *TC); | |
54 | int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC); |
|
60 | int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC); | |
55 | // |
|
61 | // | |
56 | int action_load_norm(ccsdsTelecommandPacket_t *TC); |
|
62 | int action_load_norm(ccsdsTelecommandPacket_t *TC); | |
57 | int action_enter(ccsdsTelecommandPacket_t *TC); |
|
63 | int action_enter(ccsdsTelecommandPacket_t *TC); | |
58 | int action_updt_time(ccsdsTelecommandPacket_t *TC); |
|
64 | int action_updt_time(ccsdsTelecommandPacket_t *TC); | |
59 |
|
65 | |||
60 | #endif // TC_HANDLER_H_INCLUDED |
|
66 | #endif // TC_HANDLER_H_INCLUDED | |
61 |
|
67 | |||
62 |
|
68 | |||
63 |
|
69 |
@@ -1,272 +1,299 | |||||
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 |
|
61 | |||
61 | //send_console_outputs_on_serial_port(); |
|
62 | //send_console_outputs_on_serial_port(); | |
62 |
|
63 | |||
63 | initLookUpTableForCRC(); // in tc_handler.h |
|
64 | initLookUpTableForCRC(); // in tc_handler.h | |
64 | init_default_mode_parameters(); |
|
65 | init_default_mode_parameters(); | |
65 | create_message_queue(); |
|
66 | create_message_queue(); | |
66 | create_all_tasks(); |
|
67 | create_all_tasks(); | |
67 | start_all_tasks(); |
|
68 | start_all_tasks(); | |
68 |
|
69 | |||
69 | configure_spw_link(); |
|
70 | configure_spw_link(); | |
70 | configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR, |
|
71 | configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR, | |
71 | IRQ_SPARC_SM, spectral_matrices_isr ); |
|
72 | IRQ_SPARC_SM, spectral_matrices_isr ); | |
72 | configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR, |
|
73 | configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR, | |
73 | IRQ_SPARC_WF, waveforms_isr ); |
|
74 | IRQ_SPARC_WF, waveforms_isr ); | |
|
75 | ||||
|
76 | // irq handling of the time management unit | |||
|
77 | /*status = rtems_interrupt_catch( commutation_isr1, | |||
|
78 | IRQ_SPARC_TIME1, | |||
|
79 | &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | |||
|
80 | if (status==RTEMS_SUCCESSFUL) | |||
|
81 | PRINTF("commutation_isr1 *** rtems_interrupt_catch successfullly configured\n") | |||
|
82 | ||||
|
83 | status = rtems_interrupt_catch( commutation_isr2, | |||
|
84 | IRQ_SPARC_TIME2, | |||
|
85 | &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | |||
|
86 | if (status==RTEMS_SUCCESSFUL) | |||
|
87 | PRINTF("commutation_isr2 *** rtems_interrupt_catch successfullly configured\n") | |||
|
88 | ||||
|
89 | LEON_Unmask_interrupt( IRQ_TIME1 ); | |||
|
90 | LEON_Unmask_interrupt( IRQ_TIME2 );*/ | |||
74 |
|
91 | |||
75 | status = rtems_task_delete(RTEMS_SELF); |
|
92 | status = rtems_task_delete(RTEMS_SELF); | |
76 | } |
|
93 | } | |
77 |
|
94 | |||
78 | rtems_task spiq_task(rtems_task_argument unused) |
|
95 | rtems_task spiq_task(rtems_task_argument unused) | |
79 | { |
|
96 | { | |
80 | rtems_event_set event_out; |
|
97 | rtems_event_set event_out; | |
81 | struct grspw_regs_str *grspw_regs; |
|
98 | struct grspw_regs_str *grspw_regs; | |
82 | grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW; |
|
99 | grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW; | |
83 |
|
100 | |||
84 | while(1){ |
|
101 | while(1){ | |
85 | PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n") |
|
102 | PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n") | |
86 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
103 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT | |
87 |
|
104 | |||
88 | if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task |
|
105 | if (rtems_task_suspend(Task_id[1])!=RTEMS_SUCCESSFUL) // suspend RECV task | |
89 | PRINTF("In SPIQ *** Error suspending RECV Task\n") |
|
106 | PRINTF("In SPIQ *** Error suspending RECV Task\n") | |
90 |
|
107 | |||
91 | configure_spw_link(); |
|
108 | configure_spw_link(); | |
92 |
|
109 | |||
93 | if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task |
|
110 | if (rtems_task_restart(Task_id[1], 1)!=RTEMS_SUCCESSFUL) // restart RECV task | |
94 | PRINTF("In SPIQ *** Error resume RECV Task\n") |
|
111 | PRINTF("In SPIQ *** Error resume RECV Task\n") | |
95 | } |
|
112 | } | |
96 | } |
|
113 | } | |
97 |
|
114 | |||
98 | void init_default_mode_parameters() |
|
115 | void init_default_mode_parameters() | |
99 | { |
|
116 | { | |
100 | // COMMON PARAMETERS |
|
117 | // COMMON PARAMETERS | |
101 | param_common[0] = 0x00; |
|
118 | param_common[0] = 0x00; | |
102 | param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0 |
|
119 | param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0 | |
103 | // NORMAL MODE |
|
120 | // NORMAL MODE | |
104 | param_norm.sy_lfr_n_swf_l = 2048; // nb sample |
|
121 | param_norm.sy_lfr_n_swf_l = 2048; // nb sample | |
105 | param_norm.sy_lfr_n_swf_p = 300; // sec |
|
122 | param_norm.sy_lfr_n_swf_p = 300; // sec | |
106 | param_norm.sy_lfr_n_asm_p = 3600; // sec |
|
123 | param_norm.sy_lfr_n_asm_p = 3600; // sec | |
107 | param_norm.sy_lfr_n_bp_p0 = 4; // sec |
|
124 | param_norm.sy_lfr_n_bp_p0 = 4; // sec | |
108 | param_norm.sy_lfr_n_bp_p1 = 20; // sec |
|
125 | param_norm.sy_lfr_n_bp_p1 = 20; // sec | |
109 | // BURST MODE |
|
126 | // BURST MODE | |
110 | param_burst.sy_lfr_b_bp_p0 = 1; // sec |
|
127 | param_burst.sy_lfr_b_bp_p0 = 1; // sec | |
111 | param_burst.sy_lfr_b_bp_p1 = 5; // sec |
|
128 | param_burst.sy_lfr_b_bp_p1 = 5; // sec | |
112 | // SBM1 MODE |
|
129 | // SBM1 MODE | |
113 | param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec |
|
130 | param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec | |
114 | param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec |
|
131 | param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec | |
115 | // SBM2 MODE |
|
132 | // SBM2 MODE | |
116 | param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec |
|
133 | param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec | |
117 | param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec |
|
134 | param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec | |
118 | } |
|
135 | } | |
119 |
|
136 | |||
120 | int create_all_tasks() |
|
137 | int create_all_tasks() | |
121 | { |
|
138 | { | |
122 | rtems_status_code status; |
|
139 | rtems_status_code status; | |
123 |
|
140 | |||
124 | Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' ); |
|
141 | Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' ); | |
125 | Task_name[2] = rtems_build_name( 'A', 'C', 'T', 'N' ); |
|
142 | Task_name[2] = rtems_build_name( 'A', 'C', 'T', 'N' ); | |
126 | Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' ); |
|
143 | Task_name[3] = rtems_build_name( 'S', 'P', 'I', 'Q' ); | |
127 | Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' ); |
|
144 | Task_name[4] = rtems_build_name( 'S', 'M', 'I', 'Q' ); | |
128 | Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' ); |
|
145 | Task_name[5] = rtems_build_name( 'S', 'T', 'A', 'T' ); | |
129 | Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' ); |
|
146 | Task_name[6] = rtems_build_name( 'A', 'V', 'F', '0' ); | |
130 | Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' ); |
|
147 | Task_name[7] = rtems_build_name( 'B', 'P', 'F', '0' ); | |
131 | Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' ); |
|
148 | Task_name[8] = rtems_build_name( 'W', 'F', 'R', 'M' ); | |
|
149 | //Task_name[9] = rtems_build_name( 'D', 'U', 'M', 'B' ); | |||
132 |
|
150 | |||
133 | // RECV |
|
151 | // RECV | |
134 | status = rtems_task_create( |
|
152 | status = rtems_task_create( | |
135 | Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
153 | Task_name[1], 200, RTEMS_MINIMUM_STACK_SIZE * 2, | |
136 | RTEMS_DEFAULT_MODES, |
|
154 | RTEMS_DEFAULT_MODES, | |
137 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1] |
|
155 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1] | |
138 | ); |
|
156 | ); | |
139 | // ACTN |
|
157 | // ACTN | |
140 | status = rtems_task_create( |
|
158 | status = rtems_task_create( | |
141 | Task_name[2], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
159 | Task_name[2], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
142 | RTEMS_DEFAULT_MODES, |
|
160 | RTEMS_DEFAULT_MODES, | |
143 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2] |
|
161 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2] | |
144 | ); |
|
162 | ); | |
145 | // SPIQ |
|
163 | // SPIQ | |
146 | status = rtems_task_create( |
|
164 | status = rtems_task_create( | |
147 | Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
165 | Task_name[3], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
148 | RTEMS_DEFAULT_MODES, |
|
166 | RTEMS_DEFAULT_MODES, | |
149 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3] |
|
167 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3] | |
150 | ); |
|
168 | ); | |
151 | // SMIQ |
|
169 | // SMIQ | |
152 | status = rtems_task_create( |
|
170 | status = rtems_task_create( | |
153 | Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
171 | Task_name[4], 10, RTEMS_MINIMUM_STACK_SIZE * 2, | |
154 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
172 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, | |
155 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4] |
|
173 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[4] | |
156 | ); |
|
174 | ); | |
157 | // STAT |
|
175 | // STAT | |
158 | status = rtems_task_create( |
|
176 | status = rtems_task_create( | |
159 |
Task_name[5], |
|
177 | Task_name[5], 150, RTEMS_MINIMUM_STACK_SIZE * 2, | |
160 | RTEMS_DEFAULT_MODES, |
|
178 | RTEMS_DEFAULT_MODES, | |
161 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5] |
|
179 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[5] | |
162 | ); |
|
180 | ); | |
163 | // AVF0 |
|
181 | // AVF0 | |
164 | status = rtems_task_create( |
|
182 | status = rtems_task_create( | |
165 | Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
183 | Task_name[6], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
166 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
184 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, | |
167 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6] |
|
185 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[6] | |
168 | ); |
|
186 | ); | |
169 | // BPF0 |
|
187 | // BPF0 | |
170 | status = rtems_task_create( |
|
188 | status = rtems_task_create( | |
171 | Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
189 | Task_name[7], 50, RTEMS_MINIMUM_STACK_SIZE * 2, | |
172 | RTEMS_DEFAULT_MODES, |
|
190 | RTEMS_DEFAULT_MODES, | |
173 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7] |
|
191 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[7] | |
174 | ); |
|
192 | ); | |
175 | // WFRM |
|
193 | // WFRM | |
176 | status = rtems_task_create( |
|
194 | status = rtems_task_create( | |
177 | Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
195 | Task_name[8], 100, RTEMS_MINIMUM_STACK_SIZE * 2, | |
178 | RTEMS_DEFAULT_MODES, |
|
196 | RTEMS_DEFAULT_MODES, | |
179 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8] |
|
197 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[8] | |
180 | ); |
|
198 | ); | |
|
199 | // DUMB | |||
|
200 | /*status = rtems_task_create( | |||
|
201 | Task_name[9], 200, RTEMS_MINIMUM_STACK_SIZE * 2, | |||
|
202 | RTEMS_DEFAULT_MODES, | |||
|
203 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[9] | |||
|
204 | );*/ | |||
181 |
|
205 | |||
182 | return 0; |
|
206 | return 0; | |
183 | } |
|
207 | } | |
184 |
|
208 | |||
185 | int start_all_tasks() |
|
209 | int start_all_tasks() | |
186 | { |
|
210 | { | |
187 | rtems_status_code status; |
|
211 | rtems_status_code status; | |
188 |
|
212 | |||
189 | status = rtems_task_start( Task_id[3], spiq_task, 1 ); |
|
213 | status = rtems_task_start( Task_id[3], spiq_task, 1 ); | |
190 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n") |
|
214 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n") | |
191 |
|
215 | |||
192 | status = rtems_task_start( Task_id[1], recv_task, 1 ); |
|
216 | status = rtems_task_start( Task_id[1], recv_task, 1 ); | |
193 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n") |
|
217 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n") | |
194 |
|
218 | |||
195 | status = rtems_task_start( Task_id[2], actn_task, 1 ); |
|
219 | status = rtems_task_start( Task_id[2], actn_task, 1 ); | |
196 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n") |
|
220 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n") | |
197 |
|
221 | |||
198 | status = rtems_task_start( Task_id[4], smiq_task, 1 ); |
|
222 | status = rtems_task_start( Task_id[4], smiq_task, 1 ); | |
199 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n") |
|
223 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n") | |
200 |
|
224 | |||
201 | status = rtems_task_start( Task_id[5], stat_task, 1 ); |
|
225 | status = rtems_task_start( Task_id[5], stat_task, 1 ); | |
202 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n") |
|
226 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n") | |
203 |
|
227 | |||
204 | status = rtems_task_start( Task_id[6], avf0_task, 1 ); |
|
228 | status = rtems_task_start( Task_id[6], avf0_task, 1 ); | |
205 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n") |
|
229 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n") | |
206 |
|
230 | |||
207 | status = rtems_task_start( Task_id[7], bpf0_task, 1 ); |
|
231 | status = rtems_task_start( Task_id[7], bpf0_task, 1 ); | |
208 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n") |
|
232 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n") | |
209 |
|
233 | |||
210 | status = rtems_task_start( Task_id[8], wfrm_task, 1 ); |
|
234 | status = rtems_task_start( Task_id[8], wfrm_task, 1 ); | |
211 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n") |
|
235 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n") | |
212 |
|
236 | |||
|
237 | /*status = rtems_task_start( Task_id[9], dumb_task, 1 ); | |||
|
238 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")*/ | |||
|
239 | ||||
213 | return 0; |
|
240 | return 0; | |
214 | } |
|
241 | } | |
215 |
|
242 | |||
216 | int configure_spw_link() |
|
243 | int configure_spw_link() | |
217 | { |
|
244 | { | |
218 | rtems_status_code status; |
|
245 | rtems_status_code status; | |
219 |
|
246 | |||
220 | close(fdSPW); // close the device if it is already open |
|
247 | close(fdSPW); // close the device if it is already open | |
221 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware |
|
248 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware | |
222 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") |
|
249 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") | |
223 | while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){ |
|
250 | while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){ | |
224 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n") |
|
251 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n") | |
225 | close(fdSPW); // close the device |
|
252 | close(fdSPW); // close the device | |
226 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware |
|
253 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware | |
227 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") |
|
254 | if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n") | |
228 | rtems_task_wake_after(100); |
|
255 | rtems_task_wake_after(100); | |
229 | } |
|
256 | } | |
230 |
|
257 | |||
231 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n") |
|
258 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n") | |
232 |
|
259 | |||
233 | // sets a few parameters of the link |
|
260 | // sets a few parameters of the link | |
234 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit |
|
261 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit | |
235 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n") |
|
262 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n") | |
236 | // |
|
263 | // | |
237 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
264 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception | |
238 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
265 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") | |
239 | // |
|
266 | // | |
240 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a |
|
267 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a | |
241 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
268 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs | |
242 | // |
|
269 | // | |
243 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts |
|
270 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts | |
244 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") |
|
271 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") | |
245 | // |
|
272 | // | |
246 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
273 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit | |
247 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
274 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |
248 |
|
275 | |||
249 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit |
|
276 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit | |
250 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") |
|
277 | if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") | |
251 | // |
|
278 | // | |
252 | //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key |
|
279 | //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key | |
253 | //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
280 | //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |
254 | // |
|
281 | // | |
255 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n") |
|
282 | PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n") | |
256 |
|
283 | |||
257 | return RTEMS_SUCCESSFUL; |
|
284 | return RTEMS_SUCCESSFUL; | |
258 | } |
|
285 | } | |
259 |
|
286 | |||
260 | char *link_status(int status){ |
|
287 | char *link_status(int status){ | |
261 | return lstates[status]; |
|
288 | return lstates[status]; | |
262 | } |
|
289 | } | |
263 |
|
290 | |||
264 | rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send) |
|
291 | rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send) | |
265 | { |
|
292 | { | |
266 | rtems_status_code status; |
|
293 | rtems_status_code status; | |
267 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); |
|
294 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); | |
268 | if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n"); |
|
295 | if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n"); | |
269 | return status; |
|
296 | return status; | |
270 | } |
|
297 | } | |
271 |
|
298 | |||
272 |
|
299 |
@@ -1,73 +1,75 | |||||
1 | #include <fsw_misc.h> |
|
1 | #include <fsw_misc.h> | |
2 | #include <fsw_params.h> |
|
2 | #include <fsw_params.h> | |
3 |
|
3 | |||
4 | extern rtems_id Task_id[]; /* array of task ids */ |
|
4 | extern rtems_id Task_id[]; /* array of task ids */ | |
5 | extern int fdSPW; |
|
5 | extern int fdSPW; | |
6 |
|
6 | |||
7 | int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, |
|
7 | int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, | |
8 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
8 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) | |
9 | { // configure the timer for the waveforms simulation |
|
9 | { // configure the timer for the waveforms simulation | |
10 | rtems_status_code status; |
|
10 | rtems_status_code status; | |
11 | rtems_isr_entry old_isr_handler; |
|
11 | rtems_isr_entry old_isr_handler; | |
12 |
|
12 | |||
13 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
13 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | |
14 | //if (status==RTEMS_SUCCESSFUL) PRINTF("In configure_timer_for_wf_simulation *** rtems_interrupt_catch successfullly configured\n") |
|
14 | //if (status==RTEMS_SUCCESSFUL) PRINTF("In configure_timer_for_wf_simulation *** rtems_interrupt_catch successfullly configured\n") | |
15 |
|
15 | |||
16 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
16 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz | |
17 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
17 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any | |
18 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register |
|
18 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register | |
19 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer |
|
19 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer | |
20 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart |
|
20 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart | |
21 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable |
|
21 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable | |
22 |
|
22 | |||
23 | return 1; |
|
23 | return 1; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void print_statistics(spw_stats *stats) |
|
26 | void print_statistics(spw_stats *stats) | |
27 | { |
|
27 | { | |
28 | //printf(" ******** STATISTICS ******** \n"); |
|
28 | //printf(" ******** STATISTICS ******** \n"); | |
29 | printf("Transmit link errors: %i\n", stats->tx_link_err); |
|
29 | printf("Transmit link errors: %i\n", stats->tx_link_err); | |
30 | printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err); |
|
30 | printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err); | |
31 | printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err); |
|
31 | printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err); | |
32 | printf("Receiver EEP errors: %i\n", stats->rx_eep_err); |
|
32 | printf("Receiver EEP errors: %i\n", stats->rx_eep_err); | |
33 | printf("Receiver truncation errors: %i\n", stats->rx_truncated); |
|
33 | printf("Receiver truncation errors: %i\n", stats->rx_truncated); | |
34 | printf("Parity errors: %i\n", stats->parity_err); |
|
34 | printf("Parity errors: %i\n", stats->parity_err); | |
35 | printf("Escape errors: %i\n", stats->escape_err); |
|
35 | printf("Escape errors: %i\n", stats->escape_err); | |
36 | printf("Credit errors: %i\n", stats->credit_err); |
|
36 | printf("Credit errors: %i\n", stats->credit_err); | |
37 | printf("Disconnect errors: %i\n", stats->disconnect_err); |
|
37 | printf("Disconnect errors: %i\n", stats->disconnect_err); | |
38 | printf("Write synchronization errors: %i\n", stats->write_sync_err); |
|
38 | printf("Write synchronization errors: %i\n", stats->write_sync_err); | |
39 | printf("Early EOP/EEP: %i\n", stats->early_ep); |
|
39 | printf("Early EOP/EEP: %i\n", stats->early_ep); | |
40 | printf("Invalid Node Address: %i\n", stats->invalid_address); |
|
40 | printf("Invalid Node Address: %i\n", stats->invalid_address); | |
41 | printf("Packets transmitted: %i\n", stats->packets_sent); |
|
41 | printf("Packets transmitted: %i\n", stats->packets_sent); | |
42 | printf("Packets received: %i\n", stats->packets_received); |
|
42 | printf("Packets received: %i\n", stats->packets_received); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | int send_console_outputs_on_serial_port() // Send the console outputs on the serial port |
|
45 | int send_console_outputs_on_serial_port() // Send the console outputs on the serial port | |
46 | { |
|
46 | { | |
47 | struct apbuart_regs_str *apbuart_regs; |
|
47 | struct apbuart_regs_str *apbuart_regs; | |
48 |
|
48 | |||
49 | apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
49 | apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | |
50 | apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB; |
|
50 | apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB; | |
51 | PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") |
|
51 | PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") | |
52 |
|
52 | |||
53 | return 0; |
|
53 | return 0; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | rtems_task stat_task(rtems_task_argument argument) |
|
56 | rtems_task stat_task(rtems_task_argument argument) | |
57 | { |
|
57 | { | |
58 | int i; |
|
58 | int i; | |
59 | i = 0; |
|
59 | i = 0; | |
60 | PRINTF("In STAT *** \n") |
|
60 | PRINTF("In STAT *** \n") | |
61 | while(1){ |
|
61 | while(1){ | |
62 | rtems_task_wake_after(1000); |
|
62 | rtems_task_wake_after(1000); | |
63 | PRINTF1("%d\n", i) |
|
63 | PRINTF1("%d\n", i) | |
64 | if (i == 2) { |
|
64 | if (i == 2) { | |
|
65 | #ifdef PRINT_TASK_STATISTICS | |||
65 | rtems_cpu_usage_report(); |
|
66 | rtems_cpu_usage_report(); | |
66 | rtems_cpu_usage_reset(); |
|
67 | rtems_cpu_usage_reset(); | |
|
68 | #endif | |||
67 | i = 0; |
|
69 | i = 0; | |
68 | } |
|
70 | } | |
69 | else i++; |
|
71 | else i++; | |
70 | } |
|
72 | } | |
71 | } |
|
73 | } | |
72 |
|
74 | |||
73 |
|
75 |
@@ -1,427 +1,447 | |||||
1 | #include <fsw_processing.h> |
|
1 | #include <fsw_processing.h> | |
2 | #include <math.h> |
|
2 | #include <math.h> | |
3 | #include <stdio.h> |
|
3 | #include <stdio.h> | |
|
4 | #include <stdlib.h> | |||
4 | #include <leon.h> |
|
5 | #include <leon.h> | |
|
6 | ||||
|
7 | // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets | |||
|
8 | // SX 12 coefficients | |||
|
9 | float k14_sx_re = 1; | |||
|
10 | float k14_sx_im = 1; | |||
|
11 | float k15_sx_re = 1; | |||
|
12 | float k15_sx_im = 1; | |||
|
13 | float k24_sx_re = 1; | |||
|
14 | float k24_sx_im = 1; | |||
|
15 | float k25_sx_re = 1; | |||
|
16 | float k25_sx_im = 1; | |||
|
17 | float k34_sx_re = 1; | |||
|
18 | float k34_sx_im = 1; | |||
|
19 | float k35_sx_re = 1; | |||
|
20 | float k35_sx_im = 1; | |||
|
21 | // NY 8 coefficients | |||
|
22 | float k24_ny_re = 1; | |||
|
23 | float k24_ny_im = 1; | |||
|
24 | float k25_ny_re = 1; | |||
|
25 | float k25_ny_im = 1; | |||
|
26 | float k34_ny_re = 1; | |||
|
27 | float k34_ny_im = 1; | |||
|
28 | float k35_ny_re = 1; | |||
|
29 | float k35_ny_im = 1; | |||
|
30 | // NZ 8 coefficients | |||
|
31 | float k24_nz_re = 1; | |||
|
32 | float k24_nz_im = 1; | |||
|
33 | float k25_nz_re = 1; | |||
|
34 | float k25_nz_im = 1; | |||
|
35 | float k34_nz_re = 1; | |||
|
36 | float k34_nz_im = 1; | |||
|
37 | float k35_nz_re = 1; | |||
|
38 | float k35_nz_im = 1; | |||
|
39 | // PE 4 coefficients | |||
|
40 | float k44_pe = 1; | |||
|
41 | float k55_pe = 1; | |||
|
42 | float k45_pe_re = 1; | |||
|
43 | float k45_pe_im = 1; | |||
5 |
|
44 | |||
6 | float k14_re = 1; |
|
|||
7 | float k14_im = 1; |
|
|||
8 | float k14_bis_re = 1; |
|
|||
9 | float k14_bis_im = 1; |
|
|||
10 | float k14_tris_re = 1; |
|
|||
11 | float k14_tris_im = 1; |
|
|||
12 | float k15_re = 1; |
|
|||
13 | float k15_im = 1; |
|
|||
14 | float k15_bis_re = 1; |
|
|||
15 | float k15_bis_im = 1; |
|
|||
16 | float k24_re = 1; |
|
|||
17 | float k24_im = 1; |
|
|||
18 | float k24_bis_re = 1; |
|
|||
19 | float k24_bis_im = 1; |
|
|||
20 | float k24_tris_re = 1; |
|
|||
21 | float k24_tris_im = 1; |
|
|||
22 | float k25_re = 1; |
|
|||
23 | float k25_im = 1; |
|
|||
24 | float k25_bis_re = 1; |
|
|||
25 | float k25_bis_im = 1; |
|
|||
26 | float k34_re = 1; |
|
|||
27 | float k34_im = 1; |
|
|||
28 | float k44 = 1; |
|
|||
29 | float k55 = 1; |
|
|||
30 | float k45_re = 1; |
|
|||
31 | float k45_im = 1; |
|
|||
32 | float alpha_M = M_PI/4; |
|
45 | float alpha_M = M_PI/4; | |
33 |
|
46 | |||
34 | extern volatile int spec_mat_f0_a[ ]; |
|
47 | extern volatile int spec_mat_f0_a[ ]; | |
35 | extern volatile int spec_mat_f0_b[ ]; |
|
48 | extern volatile int spec_mat_f0_b[ ]; | |
36 | extern volatile int spec_mat_f0_c[ ]; |
|
49 | extern volatile int spec_mat_f0_c[ ]; | |
37 | extern volatile int spec_mat_f0_d[ ]; |
|
50 | extern volatile int spec_mat_f0_d[ ]; | |
38 | extern volatile int spec_mat_f0_e[ ]; |
|
51 | extern volatile int spec_mat_f0_e[ ]; | |
39 | extern volatile int spec_mat_f0_f[ ]; |
|
52 | extern volatile int spec_mat_f0_f[ ]; | |
40 | extern volatile int spec_mat_f0_g[ ]; |
|
53 | extern volatile int spec_mat_f0_g[ ]; | |
41 | extern volatile int spec_mat_f0_h[ ]; |
|
54 | extern volatile int spec_mat_f0_h[ ]; | |
42 | extern float averaged_spec_mat_f0[ ]; |
|
55 | extern float averaged_spec_mat_f0[ ]; | |
43 | extern float compressed_spec_mat_f0[ ]; |
|
56 | extern float compressed_spec_mat_f0[ ]; | |
44 | extern unsigned char LFR_BP1_F0[ ]; |
|
57 | extern unsigned char LFR_BP1_F0[ ]; | |
45 |
|
58 | |||
46 | extern BP1_t data_BP1[ ]; |
|
59 | extern BP1_t data_BP1[ ]; | |
47 |
|
60 | |||
48 | extern rtems_id Task_id[ ]; /* array of task ids */ |
|
61 | extern rtems_id Task_id[ ]; /* array of task ids */ | |
49 |
|
62 | |||
50 | spectral_matrices_regs_t *spectral_matrices_regs; |
|
63 | spectral_matrices_regs_t *spectral_matrices_regs; | |
51 |
|
64 | |||
52 | // Interrupt Service Routine for spectral matrices processing |
|
65 | // Interrupt Service Routine for spectral matrices processing | |
53 | rtems_isr spectral_matrices_isr( rtems_vector_number vector ) |
|
66 | rtems_isr spectral_matrices_isr( rtems_vector_number vector ) | |
54 | { |
|
67 | { | |
55 | if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) |
|
68 | if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) | |
56 | printf("In spectral_matrices_isr *** Error sending event to AVF0\n"); |
|
69 | printf("In spectral_matrices_isr *** Error sending event to AVF0\n"); | |
57 | } |
|
70 | } | |
58 |
|
71 | |||
59 | rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ |
|
72 | rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ | |
60 | { |
|
73 | { | |
61 | rtems_event_set event_out; |
|
74 | rtems_event_set event_out; | |
62 | gptimer_regs_t *gptimer_regs; |
|
75 | gptimer_regs_t *gptimer_regs; | |
63 | gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; |
|
76 | gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; | |
64 | unsigned char nb_interrupt_f0 = 0; |
|
77 | unsigned char nb_interrupt_f0 = 0; | |
65 |
|
78 | |||
66 | PRINTF("In SMIQ *** \n") |
|
79 | PRINTF("In SMIQ *** \n") | |
67 |
|
80 | |||
68 | while(1){ |
|
81 | while(1){ | |
69 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 |
|
82 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 | |
70 | nb_interrupt_f0 = nb_interrupt_f0 + 1; |
|
83 | nb_interrupt_f0 = nb_interrupt_f0 + 1; | |
71 | if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){ |
|
84 | if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){ | |
72 | if (rtems_event_send( Task_id[6], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) |
|
85 | if (rtems_event_send( Task_id[6], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) | |
73 | printf("In smiq_task *** Error sending event to AVF0\n"); |
|
86 | printf("In smiq_task *** Error sending event to AVF0\n"); | |
74 | nb_interrupt_f0 = 0; |
|
87 | nb_interrupt_f0 = 0; | |
75 | } |
|
88 | } | |
76 | gptimer_regs->timer[1].ctrl = gptimer_regs->timer[1].ctrl | 0x00000010; |
|
89 | gptimer_regs->timer[1].ctrl = gptimer_regs->timer[1].ctrl | 0x00000010; | |
77 | } |
|
90 | } | |
78 | } |
|
91 | } | |
79 |
|
92 | |||
80 | rtems_task spw_bppr_task(rtems_task_argument argument) |
|
93 | rtems_task spw_bppr_task(rtems_task_argument argument) | |
81 | { |
|
94 | { | |
82 | rtems_status_code status; |
|
95 | rtems_status_code status; | |
83 | rtems_event_set event_out; |
|
96 | rtems_event_set event_out; | |
84 | static int nb_average_f0 = 0; |
|
97 | static int nb_average_f0 = 0; | |
85 | //static int nb_average_f1 = 0; |
|
98 | //static int nb_average_f1 = 0; | |
86 | //static int nb_average_f2 = 0; |
|
99 | //static int nb_average_f2 = 0; | |
87 |
|
100 | |||
88 | while(1) |
|
101 | while(1) | |
89 |
|
102 | |||
90 | spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; |
|
103 | spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; | |
91 | spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; |
|
104 | spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; | |
92 | spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; |
|
105 | spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; | |
93 |
|
106 | |||
94 | printf("In BPPR ***\n"); |
|
107 | printf("In BPPR ***\n"); | |
95 |
|
108 | |||
96 | while(1){ // wait for an event to begin with the processing |
|
109 | while(1){ // wait for an event to begin with the processing | |
97 | status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); |
|
110 | status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); | |
98 | if (status == RTEMS_SUCCESSFUL){ |
|
111 | if (status == RTEMS_SUCCESSFUL){ | |
99 | if ((spectral_matrices_regs->ctrl & 0x00000001)==1){ |
|
112 | if ((spectral_matrices_regs->ctrl & 0x00000001)==1){ | |
100 | matrix_average(spec_mat_f0_a, averaged_spec_mat_f0); |
|
113 | matrix_average(spec_mat_f0_a, averaged_spec_mat_f0); | |
101 | spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; |
|
114 | spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; | |
102 | //printf("f0_a\n"); |
|
115 | //printf("f0_a\n"); | |
103 | nb_average_f0++; |
|
116 | nb_average_f0++; | |
104 | } |
|
117 | } | |
105 | if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){ |
|
118 | if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){ | |
106 | matrix_average(spec_mat_f0_b, compressed_spec_mat_f0); |
|
119 | matrix_average(spec_mat_f0_b, compressed_spec_mat_f0); | |
107 | spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd; |
|
120 | spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd; | |
108 | //printf("f0_b\n"); |
|
121 | //printf("f0_b\n"); | |
109 | nb_average_f0++; |
|
122 | nb_average_f0++; | |
110 | } |
|
123 | } | |
111 | if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){ |
|
124 | if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){ | |
112 | matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0); |
|
125 | matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0); | |
113 | //printf("f0 compressed\n"); |
|
126 | //printf("f0 compressed\n"); | |
114 | nb_average_f0 = 0; |
|
127 | nb_average_f0 = 0; | |
115 | matrix_reset(averaged_spec_mat_f0); |
|
128 | matrix_reset(averaged_spec_mat_f0); | |
116 | } |
|
129 | } | |
117 | } |
|
130 | } | |
118 | } |
|
131 | } | |
119 | } |
|
132 | } | |
120 |
|
133 | |||
121 | void matrix_average(volatile int *spec_mat, float *averaged_spec_mat) |
|
134 | void matrix_average(volatile int *spec_mat, float *averaged_spec_mat) | |
122 | { |
|
135 | { | |
123 | int i; |
|
136 | int i; | |
124 | for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){ |
|
137 | for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){ | |
125 | averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i] |
|
138 | averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i] | |
126 | + spec_mat_f0_b[i] |
|
139 | + spec_mat_f0_b[i] | |
127 | + spec_mat_f0_c[i] |
|
140 | + spec_mat_f0_c[i] | |
128 | + spec_mat_f0_d[i] |
|
141 | + spec_mat_f0_d[i] | |
129 | + spec_mat_f0_e[i] |
|
142 | + spec_mat_f0_e[i] | |
130 | + spec_mat_f0_f[i] |
|
143 | + spec_mat_f0_f[i] | |
131 | + spec_mat_f0_g[i] |
|
144 | + spec_mat_f0_g[i] | |
132 | + spec_mat_f0_h[i]; |
|
145 | + spec_mat_f0_h[i]; | |
133 | } |
|
146 | } | |
134 | } |
|
147 | } | |
135 |
|
148 | |||
136 | void matrix_reset(float *averaged_spec_mat) |
|
149 | void matrix_reset(float *averaged_spec_mat) | |
137 | { |
|
150 | { | |
138 | int i; |
|
151 | int i; | |
139 | for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){ |
|
152 | for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){ | |
140 | averaged_spec_mat_f0[i] = 0; |
|
153 | averaged_spec_mat_f0[i] = 0; | |
141 | } |
|
154 | } | |
142 | } |
|
155 | } | |
143 |
|
156 | |||
144 | void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat) |
|
157 | void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat) | |
145 | { |
|
158 | { | |
146 | int i, j; |
|
159 | int i, j; | |
147 | switch (fChannel){ |
|
160 | switch (fChannel){ | |
148 | case 0: |
|
161 | case 0: | |
149 | for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){ |
|
162 | for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){ | |
150 | j = 17 + i * 8; |
|
163 | j = 17 + i * 8; | |
151 | compressed_spec_mat[i] = (averaged_spec_mat[j] |
|
164 | compressed_spec_mat[i] = (averaged_spec_mat[j] | |
152 | + averaged_spec_mat[j+1] |
|
165 | + averaged_spec_mat[j+1] | |
153 | + averaged_spec_mat[j+2] |
|
166 | + averaged_spec_mat[j+2] | |
154 | + averaged_spec_mat[j+3] |
|
167 | + averaged_spec_mat[j+3] | |
155 | + averaged_spec_mat[j+4] |
|
168 | + averaged_spec_mat[j+4] | |
156 | + averaged_spec_mat[j+5] |
|
169 | + averaged_spec_mat[j+5] | |
157 | + averaged_spec_mat[j+6] |
|
170 | + averaged_spec_mat[j+6] | |
158 | + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0); |
|
171 | + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0); | |
159 | } |
|
172 | } | |
160 | break; |
|
173 | break; | |
161 | case 1: |
|
174 | case 1: | |
162 | // case fChannel = f1 tp be completed later |
|
175 | // case fChannel = f1 tp be completed later | |
163 | break; |
|
176 | break; | |
164 | case 2: |
|
177 | case 2: | |
165 | // case fChannel = f1 tp be completed later |
|
178 | // case fChannel = f1 tp be completed later | |
166 | break; |
|
179 | break; | |
167 | default: |
|
180 | default: | |
168 | break; |
|
181 | break; | |
169 | } |
|
182 | } | |
170 | } |
|
183 | } | |
171 |
|
184 | |||
172 | void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){ |
|
185 | void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){ | |
173 | int i, j; |
|
186 | int i, j; | |
174 | unsigned char tmp_u_char; |
|
187 | unsigned char tmp_u_char; | |
175 | unsigned char * pt_char; |
|
188 | unsigned char * pt_char; | |
176 | float PSDB, PSDE; |
|
189 | float PSDB, PSDE; | |
177 | float NVEC_V0, NVEC_V1, NVEC_V2; |
|
190 | float NVEC_V0, NVEC_V1, NVEC_V2; | |
178 | float significand; |
|
191 | //float significand; | |
179 | int exponent; |
|
192 | //int exponent; | |
180 | float aux, tr_SB_SB, tmp; |
|
193 | float aux, tr_SB_SB, tmp; | |
181 |
float |
|
194 | float sx_re, sx_im; | |
182 |
float n |
|
195 | float nebx_re = 0, nebx_im = 0; | |
183 |
float n |
|
196 | float ny = 0, nz = 0; | |
184 |
float b |
|
197 | float bx_bx_star = 0; | |
185 | for(i=0; i<nb_bins_compressed_spec_mat; i++){ |
|
198 | for(i=0; i<nb_bins_compressed_spec_mat; i++){ | |
186 | //============================================== |
|
199 | //============================================== | |
187 | // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits |
|
200 | // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits | |
188 | PSDB = compressed_spec_mat[i*30] // S11 |
|
201 | PSDB = compressed_spec_mat[i*30] // S11 | |
189 | + compressed_spec_mat[i*30+10] // S22 |
|
202 | + compressed_spec_mat[i*30+10] // S22 | |
190 | + compressed_spec_mat[i*30+18]; // S33 |
|
203 | + compressed_spec_mat[i*30+18]; // S33 | |
191 | significand = frexp(PSDB, &exponent); |
|
204 | //significand = frexp(PSDB, &exponent); | |
192 | pt_char = (unsigned char*) &PSDB; |
|
205 | pt_char = (unsigned char*) &PSDB; | |
193 |
LFR_BP1[i*9+ |
|
206 | LFR_BP1[i*9+2] = pt_char[0]; // bits 31 downto 24 of the float | |
194 |
LFR_BP1[i*9+ |
|
207 | LFR_BP1[i*9+3] = pt_char[1]; // bits 23 downto 16 of the float | |
195 | //============================================== |
|
208 | //============================================== | |
196 | // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits |
|
209 | // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits | |
197 | PSDE = compressed_spec_mat[i*30+24] * k44 // S44 |
|
210 | PSDE = compressed_spec_mat[i*30+24] * k44_pe // S44 | |
198 | + compressed_spec_mat[i*30+28] * k55 // S55 |
|
211 | + compressed_spec_mat[i*30+28] * k55_pe // S55 | |
199 | + compressed_spec_mat[i*30+26] * k45_re // S45 |
|
212 | + compressed_spec_mat[i*30+26] * k45_pe_re // S45 | |
200 | - compressed_spec_mat[i*30+27] * k45_im; // S45 |
|
213 | - compressed_spec_mat[i*30+27] * k45_pe_im; // S45 | |
201 | pt_char = (unsigned char*) &PSDE; |
|
214 | pt_char = (unsigned char*) &PSDE; | |
202 |
LFR_BP1[i*9+ |
|
215 | LFR_BP1[i*9+0] = pt_char[0]; // bits 31 downto 24 of the float | |
203 |
LFR_BP1[i*9+ |
|
216 | LFR_BP1[i*9+1] = pt_char[1]; // bits 23 downto 16 of the float | |
204 | //============================================================================== |
|
217 | //============================================================================== | |
205 | // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits |
|
218 | // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits | |
206 | // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits |
|
219 | // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits | |
207 | // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits |
|
220 | // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits | |
208 | tmp = sqrt( |
|
221 | tmp = sqrt( | |
209 | compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12 |
|
222 | compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12 | |
210 | +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13 |
|
223 | +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13 | |
211 |
+compressed_spec_mat[i*30+ |
|
224 | +compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13] //Im S23 | |
212 | ); |
|
225 | ); | |
213 | NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23 |
|
226 | NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23 | |
214 | NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13 |
|
227 | NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13 | |
215 |
NVEC_V2 = compressed_spec_mat[i*30+ |
|
228 | NVEC_V2 = compressed_spec_mat[i*30+3] / tmp; // Im S12 | |
216 |
LFR_BP1[i*9+4] = (char) (NVEC_V0* |
|
229 | LFR_BP1[i*9+4] = (char) (NVEC_V0*127); | |
217 |
LFR_BP1[i*9+ |
|
230 | LFR_BP1[i*9+5] = (char) (NVEC_V1*127); | |
218 | pt_char = (unsigned char*) &NVEC_V2; |
|
231 | pt_char = (unsigned char*) &NVEC_V2; | |
219 |
LFR_BP1[i*9+ |
|
232 | LFR_BP1[i*9+6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2 | |
220 | //======================================================= |
|
233 | //======================================================= | |
221 | // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits |
|
234 | // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits | |
222 | aux = 2*tmp / PSDB; // compute the ellipticity |
|
235 | aux = 2*tmp / PSDB; // compute the ellipticity | |
223 | tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity |
|
236 | tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity | |
224 |
LFR_BP1[i*9+ |
|
237 | LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char | |
225 | //============================================================== |
|
238 | //============================================================== | |
226 | // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits |
|
239 | // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits | |
227 | for(j = 0; j<NB_VALUES_PER_spec_mat;j++){ |
|
240 | for(j = 0; j<NB_VALUES_PER_spec_mat;j++){ | |
228 | tr_SB_SB = compressed_spec_mat[i*30]*compressed_spec_mat[i*30] |
|
241 | tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30] | |
229 | + compressed_spec_mat[i*30+10]*compressed_spec_mat[i*30+10] |
|
242 | + compressed_spec_mat[i*30+10] * compressed_spec_mat[i*30+10] | |
230 | + compressed_spec_mat[i*30+18]*compressed_spec_mat[i*30+18] |
|
243 | + compressed_spec_mat[i*30+18] * compressed_spec_mat[i*30+18] | |
231 | + 2 * compressed_spec_mat[i*30+2]*compressed_spec_mat[i*30+2] |
|
244 | + 2 * compressed_spec_mat[i*30+2] * compressed_spec_mat[i*30+2] | |
232 | + 2 * compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] |
|
245 | + 2 * compressed_spec_mat[i*30+3] * compressed_spec_mat[i*30+3] | |
233 | + 2 * compressed_spec_mat[i*30+4]*compressed_spec_mat[i*30+4] |
|
246 | + 2 * compressed_spec_mat[i*30+4] * compressed_spec_mat[i*30+4] | |
234 | + 2 * compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] |
|
247 | + 2 * compressed_spec_mat[i*30+5] * compressed_spec_mat[i*30+5] | |
235 | + 2 * compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+12] |
|
248 | + 2 * compressed_spec_mat[i*30+12] * compressed_spec_mat[i*30+12] | |
236 | + 2 * compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13]; |
|
249 | + 2 * compressed_spec_mat[i*30+13] * compressed_spec_mat[i*30+13]; | |
237 | } |
|
250 | } | |
238 | aux = PSDB*PSDB; |
|
251 | aux = PSDB*PSDB; | |
239 | tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); |
|
252 | tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) ); | |
240 | tmp_u_char = (unsigned char) (NVEC_V0*(8-1)); |
|
253 | tmp_u_char = (unsigned char) (NVEC_V0*(8-1)); | |
241 |
LFR_BP1[i*9+ |
|
254 | LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char | |
242 | //======================================================================================= |
|
255 | //======================================================================================= | |
243 |
// BP1 |
|
256 | // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1) | |
244 |
|
|
257 | sx_re = compressed_spec_mat[i*30+20] * k34_sx_re | |
245 | + compressed_spec_mat[i*30+6]*k14_re |
|
258 | + compressed_spec_mat[i*30+6] * k14_sx_re | |
246 | + compressed_spec_mat[i*30+8]*k15_re |
|
259 | + compressed_spec_mat[i*30+8] * k15_sx_re | |
247 | + compressed_spec_mat[i*30+14]*k24_re |
|
260 | + compressed_spec_mat[i*30+14] * k24_sx_re | |
248 |
+ compressed_spec_mat[i*30+16]*k25_re |
|
261 | + compressed_spec_mat[i*30+16] * k25_sx_re | |
249 |
|
|
262 | + compressed_spec_mat[i*30+22] * k35_sx_re; | |
250 |
|
|
263 | sx_im = compressed_spec_mat[i*30+21] * k34_sx_im | |
251 |
+ compressed_spec_mat[i*30+ |
|
264 | + compressed_spec_mat[i*30+7] * k14_sx_im | |
252 |
+ compressed_spec_mat[i*30+ |
|
265 | + compressed_spec_mat[i*30+9] * k15_sx_im | |
253 |
+ compressed_spec_mat[i*30+1 |
|
266 | + compressed_spec_mat[i*30+15] * k24_sx_im | |
254 | tmp = e_cross_b_re / PSDE; // compute ReaSz |
|
267 | + compressed_spec_mat[i*30+17] * k25_sx_im | |
255 | LFR_BP1[i*9+1] = ((unsigned char) (tmp * 128)) & 0x7f; // is it always positive? |
|
268 | + compressed_spec_mat[i*30+23] * k35_sx_im; | |
256 | tmp = e_cross_b_re * e_cross_b_im; |
|
269 | LFR_BP1[i*9+7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression | |
257 | pt_char = (unsigned char*) &tmp; |
|
270 | if ( abs(sx_re) > abs(sx_im) ) | |
258 |
LFR_BP1[i*9+ |
|
271 | LFR_BP1[i*9+7] = LFR_BP1[i*9+1] | (0x80); // extract the sector of sx | |
|
272 | else | |||
|
273 | LFR_BP1[i*9+7] = LFR_BP1[i*9+1] & (0x7f); // extract the sector of sx | |||
259 | //====================================================================== |
|
274 | //====================================================================== | |
260 | // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1) |
|
275 | // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1) | |
261 |
n |
|
276 | ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2; | |
262 |
n |
|
277 | nz = NVEC_V0; | |
263 |
b |
|
278 | bx_bx_star = cos(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+10] // re S22 | |
264 |
+ sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+1 |
|
279 | + sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+18] // re S33 | |
265 |
- 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+2]; // re S |
|
280 | - 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+12]; // re S23 | |
266 |
n |
|
281 | nebx_re = ny * (compressed_spec_mat[i*30+14] * k24_ny_re | |
267 |
+compressed_spec_mat[i*30+6]* |
|
282 | +compressed_spec_mat[i*30+16] * k25_ny_re | |
268 |
+compressed_spec_mat[i*30+ |
|
283 | +compressed_spec_mat[i*30+20] * k34_ny_re | |
269 |
+compressed_spec_mat[i*30+ |
|
284 | +compressed_spec_mat[i*30+22] * k35_ny_re) | |
270 |
+ n |
|
285 | + nz * (compressed_spec_mat[i*30+14] * k24_nz_re | |
271 |
+compressed_spec_mat[i*30+1 |
|
286 | +compressed_spec_mat[i*30+16] * k25_nz_re | |
272 | n_cross_e_scal_b_im = nx * (compressed_spec_mat[i*30+8]*k15_bis_im |
|
287 | +compressed_spec_mat[i*30+20] * k34_nz_re | |
273 |
+compressed_spec_mat[i*30+ |
|
288 | +compressed_spec_mat[i*30+22] * k35_nz_re); | |
274 |
|
|
289 | nebx_im = ny * (compressed_spec_mat[i*30+15]*k24_ny_re | |
275 |
+compressed_spec_mat[i*30+1 |
|
290 | +compressed_spec_mat[i*30+17] * k25_ny_re | |
276 |
+ |
|
291 | +compressed_spec_mat[i*30+21] * k34_ny_re | |
277 |
+compressed_spec_mat[i*30+ |
|
292 | +compressed_spec_mat[i*30+23] * k35_ny_re) | |
278 | tmp = n_cross_e_scal_b_re / bz_bz_star; |
|
293 | + nz * (compressed_spec_mat[i*30+15] * k24_nz_im | |
279 | LFR_BP1[i*9+0] = ((unsigned char) (tmp * 128)) & 0x7f; // is it always positive? |
|
294 | +compressed_spec_mat[i*30+17] * k25_nz_im | |
280 | tmp = n_cross_e_scal_b_re * n_cross_e_scal_b_im; |
|
295 | +compressed_spec_mat[i*30+21] * k34_nz_im | |
281 | pt_char = (unsigned char*) &tmp; |
|
296 | +compressed_spec_mat[i*30+23] * k35_nz_im); | |
282 | LFR_BP1[i*9+1] = LFR_BP1[i*9+0] | (pt_char[0] & 0x80); // extract the sign of ArgV |
|
297 | tmp = nebx_re / bx_bx_star; | |
|
298 | LFR_BP1[i*9+8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression | |||
|
299 | if ( abs(nebx_re) > abs(nebx_im) ) | |||
|
300 | LFR_BP1[i*9+8] = LFR_BP1[i*9+8] | (0x80); // extract the sector of nebx | |||
|
301 | else | |||
|
302 | LFR_BP1[i*9+8] = LFR_BP1[i*9+8] & (0x7f); // extract the sector of nebx | |||
283 | } |
|
303 | } | |
284 |
|
304 | |||
285 | } |
|
305 | } | |
286 |
|
306 | |||
287 | void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){ |
|
307 | void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){ | |
288 | // BP2 autocorrelation |
|
308 | // BP2 autocorrelation | |
289 | int i, aux = 0; |
|
309 | int i, aux = 0; | |
290 | for(i = 0; i<nb_bins_compressed_spec_mat; i++){ |
|
310 | for(i = 0; i<nb_bins_compressed_spec_mat; i++){ | |
291 | // S12 |
|
311 | // S12 | |
292 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]); |
|
312 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]); | |
293 | compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux; |
|
313 | compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux; | |
294 | compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux; |
|
314 | compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux; | |
295 | // S13 |
|
315 | // S13 | |
296 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]); |
|
316 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]); | |
297 | compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux; |
|
317 | compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux; | |
298 | compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux; |
|
318 | compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux; | |
299 | // S23 |
|
319 | // S23 | |
300 | aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]); |
|
320 | aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]); | |
301 | compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux; |
|
321 | compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux; | |
302 | compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux; |
|
322 | compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux; | |
303 | // S45 |
|
323 | // S45 | |
304 | aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]); |
|
324 | aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]); | |
305 | compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux; |
|
325 | compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux; | |
306 | compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux; |
|
326 | compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux; | |
307 | // S14 |
|
327 | // S14 | |
308 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]); |
|
328 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]); | |
309 | compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux; |
|
329 | compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux; | |
310 | compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux; |
|
330 | compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux; | |
311 | // S15 |
|
331 | // S15 | |
312 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]); |
|
332 | aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]); | |
313 | compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux; |
|
333 | compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux; | |
314 | compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux; |
|
334 | compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux; | |
315 | // S24 |
|
335 | // S24 | |
316 | aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]); |
|
336 | aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]); | |
317 | compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux; |
|
337 | compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux; | |
318 | compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux; |
|
338 | compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux; | |
319 | // S25 |
|
339 | // S25 | |
320 | aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]); |
|
340 | aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]); | |
321 | compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux; |
|
341 | compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux; | |
322 | compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux; |
|
342 | compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux; | |
323 | // S34 |
|
343 | // S34 | |
324 | aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]); |
|
344 | aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]); | |
325 | compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux; |
|
345 | compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux; | |
326 | compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux; |
|
346 | compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux; | |
327 | // S35 |
|
347 | // S35 | |
328 | aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]); |
|
348 | aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]); | |
329 | compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux; |
|
349 | compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux; | |
330 | compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux; |
|
350 | compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux; | |
331 | } |
|
351 | } | |
332 | } |
|
352 | } | |
333 |
|
353 | |||
334 | rtems_task avf0_task(rtems_task_argument argument){ |
|
354 | rtems_task avf0_task(rtems_task_argument argument){ | |
335 | int i; |
|
355 | int i; | |
336 | static int nb_average; |
|
356 | static int nb_average; | |
337 | rtems_event_set event_out; |
|
357 | rtems_event_set event_out; | |
338 | rtems_status_code status; |
|
358 | rtems_status_code status; | |
339 |
|
359 | |||
340 | spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; |
|
360 | spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; | |
341 | spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; |
|
361 | spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; | |
342 | spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; |
|
362 | spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; | |
343 |
|
363 | |||
344 | nb_average = 0; |
|
364 | nb_average = 0; | |
345 |
|
365 | |||
346 | PRINTF("In AVFO *** \n") |
|
366 | PRINTF("In AVFO *** \n") | |
347 |
|
367 | |||
348 | while(1){ |
|
368 | while(1){ | |
349 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 |
|
369 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 | |
350 | for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){ |
|
370 | for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){ | |
351 | averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i] |
|
371 | averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i] | |
352 | + spec_mat_f0_b[i] |
|
372 | + spec_mat_f0_b[i] | |
353 | + spec_mat_f0_c[i] |
|
373 | + spec_mat_f0_c[i] | |
354 | + spec_mat_f0_d[i] |
|
374 | + spec_mat_f0_d[i] | |
355 | + spec_mat_f0_e[i] |
|
375 | + spec_mat_f0_e[i] | |
356 | + spec_mat_f0_f[i] |
|
376 | + spec_mat_f0_f[i] | |
357 | + spec_mat_f0_g[i] |
|
377 | + spec_mat_f0_g[i] | |
358 | + spec_mat_f0_h[i]; |
|
378 | + spec_mat_f0_h[i]; | |
359 | } |
|
379 | } | |
360 | spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register |
|
380 | spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register | |
361 | nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0; |
|
381 | nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0; | |
362 | if (nb_average == NB_AVERAGE_NORMAL_f0) { |
|
382 | if (nb_average == NB_AVERAGE_NORMAL_f0) { | |
363 | nb_average = 0; |
|
383 | nb_average = 0; | |
364 | status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0 |
|
384 | status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0 | |
365 | if (status != RTEMS_SUCCESSFUL) printf("IN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status); |
|
385 | if (status != RTEMS_SUCCESSFUL) printf("IN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status); | |
366 | } |
|
386 | } | |
367 | } |
|
387 | } | |
368 | } |
|
388 | } | |
369 |
|
389 | |||
370 | rtems_task bpf0_task(rtems_task_argument argument){ |
|
390 | rtems_task bpf0_task(rtems_task_argument argument){ | |
371 | rtems_event_set event_out; |
|
391 | rtems_event_set event_out; | |
372 |
|
392 | |||
373 | PRINTF("In BPFO *** \n") |
|
393 | PRINTF("In BPFO *** \n") | |
374 |
|
394 | |||
375 | while(1){ |
|
395 | while(1){ | |
376 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 |
|
396 | rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 | |
377 | matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0); |
|
397 | matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0); | |
378 | BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0); |
|
398 | BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0); | |
379 | //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n") |
|
399 | //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n") | |
380 | } |
|
400 | } | |
381 | } |
|
401 | } | |
382 |
|
402 | |||
383 | //******* |
|
403 | //******* | |
384 | // UNUSED |
|
404 | // UNUSED | |
385 | rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument) |
|
405 | rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument) | |
386 | {/* |
|
406 | {/* | |
387 | rtems_status_code status; |
|
407 | rtems_status_code status; | |
388 | //static int nb_average_f1 = 0; |
|
408 | //static int nb_average_f1 = 0; | |
389 | //static int nb_average_f2 = 0; |
|
409 | //static int nb_average_f2 = 0; | |
390 |
|
410 | |||
391 | rtems_name name; |
|
411 | rtems_name name; | |
392 | rtems_id period; |
|
412 | rtems_id period; | |
393 | name = rtems_build_name( 'P', 'E', 'R', 'D' ); |
|
413 | name = rtems_build_name( 'P', 'E', 'R', 'D' ); | |
394 | status = rtems_rate_monotonic_create( name, &period ); |
|
414 | status = rtems_rate_monotonic_create( name, &period ); | |
395 | if( status != RTEMS_SUCCESSFUL ) { |
|
415 | if( status != RTEMS_SUCCESSFUL ) { | |
396 | printf( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
416 | printf( "rtems_rate_monotonic_create failed with status of %d\n", status ); | |
397 | //exit( 1 ); |
|
417 | //exit( 1 ); | |
398 | } |
|
418 | } | |
399 |
|
419 | |||
400 | spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; |
|
420 | spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES; | |
401 | spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; |
|
421 | spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a; | |
402 | spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; |
|
422 | spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b; | |
403 |
|
423 | |||
404 | printf("In BPPR BIS ***\n"); |
|
424 | printf("In BPPR BIS ***\n"); | |
405 |
|
425 | |||
406 | while(1){ // launch the rate monotonic task |
|
426 | while(1){ // launch the rate monotonic task | |
407 | if ( rtems_rate_monotonic_period( period, 8 ) == RTEMS_TIMEOUT ){ |
|
427 | if ( rtems_rate_monotonic_period( period, 8 ) == RTEMS_TIMEOUT ){ | |
408 | printf("TIMEOUT\n"); |
|
428 | printf("TIMEOUT\n"); | |
409 | //break; |
|
429 | //break; | |
410 | } |
|
430 | } | |
411 | status = rtems_event_send( Task_id[6], RTEMS_EVENT_0 ); // sending an event to the task 6, AVF0 |
|
431 | status = rtems_event_send( Task_id[6], RTEMS_EVENT_0 ); // sending an event to the task 6, AVF0 | |
412 | if (status != RTEMS_SUCCESSFUL) printf("IN TASK BPPR BIS *** Error sending RTEMS_EVENT_0 to AVF0, code %d\n", status); |
|
432 | if (status != RTEMS_SUCCESSFUL) printf("IN TASK BPPR BIS *** Error sending RTEMS_EVENT_0 to AVF0, code %d\n", status); | |
413 | } |
|
433 | } | |
414 |
|
434 | |||
415 | status = rtems_rate_monotonic_delete( period ); |
|
435 | status = rtems_rate_monotonic_delete( period ); | |
416 | if ( status != RTEMS_SUCCESSFUL ) { |
|
436 | if ( status != RTEMS_SUCCESSFUL ) { | |
417 | printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status ); |
|
437 | printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status ); | |
418 | //exit( 1 ); |
|
438 | //exit( 1 ); | |
419 | } |
|
439 | } | |
420 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
440 | status = rtems_task_delete( RTEMS_SELF ); // should not return | |
421 | printf( "rtems_task_delete returned with status of %d.\n", status ); |
|
441 | printf( "rtems_task_delete returned with status of %d.\n", status ); | |
422 | //exit( 1 );*/ |
|
442 | //exit( 1 );*/ | |
423 | } |
|
443 | } | |
424 |
|
444 | |||
425 |
|
445 | |||
426 |
|
446 | |||
427 |
|
447 |
@@ -1,489 +1,520 | |||||
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*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking |
|
283 | len = read(fdSPW, (char*) ¤tTC, 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 |
|
|
292 | PRINTF1("In RECV *** Got Message of length %d\n", len) | |
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(¤tTC, currentTC_LEN_RCV_AsUnsignedInt); |
|
297 | data_length = TC_checker(¤tTC, 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 | int action_default(ccsdsTelecommandPacket_t *TC) |
|
396 | int action_default(ccsdsTelecommandPacket_t *TC) | |
397 | { |
|
397 | { | |
398 | char data[100]; // buffer for the generic TM packet |
|
398 | char data[100]; // buffer for the generic TM packet | |
399 | TMHeader_t TM_header; // TM header |
|
399 | TMHeader_t TM_header; // TM header | |
400 | spw_ioctl_pkt_send spw_ioctl_send; // structure to send the TM packet if any |
|
400 | spw_ioctl_pkt_send spw_ioctl_send; // structure to send the TM packet if any | |
401 | // BUILD HEADER |
|
401 | // BUILD HEADER | |
402 | TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP, 0, 0, &TM_header); |
|
402 | TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP, 0, 0, &TM_header); | |
403 | // BUILD DATA |
|
403 | // BUILD DATA | |
404 | TM_build_data( TC, data, SID_NOT_IMP, NULL); |
|
404 | TM_build_data( TC, data, SID_NOT_IMP, NULL); | |
405 | // filling the strture for the spcawire transmission |
|
405 | // filling the strture for the spcawire transmission | |
406 | spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header |
|
406 | spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header | |
407 | spw_ioctl_send.hdr = (char*) &TM_header; |
|
407 | spw_ioctl_send.hdr = (char*) &TM_header; | |
408 | spw_ioctl_send.dlen = 8; |
|
408 | spw_ioctl_send.dlen = 8; | |
409 | spw_ioctl_send.data = data; |
|
409 | spw_ioctl_send.data = data; | |
410 | // SEND DATA |
|
410 | // SEND DATA | |
411 | write_spw(&spw_ioctl_send); |
|
411 | write_spw(&spw_ioctl_send); | |
412 |
|
412 | |||
413 | return 0; |
|
413 | return 0; | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | int action_enter(ccsdsTelecommandPacket_t *TC) |
|
416 | int action_enter(ccsdsTelecommandPacket_t *TC) | |
417 | { |
|
417 | { | |
418 | unsigned char lfr_mode = TC->dataAndCRC[1]; |
|
418 | unsigned char lfr_mode = TC->dataAndCRC[1]; | |
419 | printf("enter mode %d\n", lfr_mode); |
|
419 | printf("enter mode %d\n", lfr_mode); | |
420 | switch(lfr_mode) |
|
420 | switch(lfr_mode) | |
421 | { |
|
421 | { | |
422 | case(LFR_MODE_STANDBY): |
|
422 | case(LFR_MODE_STANDBY): | |
423 | LEON_Mask_interrupt( IRQ_WF ); |
|
423 | LEON_Mask_interrupt( IRQ_WF ); | |
424 | LEON_Mask_interrupt( IRQ_SM ); |
|
424 | LEON_Mask_interrupt( IRQ_SM ); | |
425 | break; |
|
425 | break; | |
426 | case(LFR_MODE_NORMAL): |
|
426 | case(LFR_MODE_NORMAL): | |
427 | LEON_Unmask_interrupt( IRQ_WF ); |
|
427 | LEON_Unmask_interrupt( IRQ_WF ); | |
428 | LEON_Unmask_interrupt( IRQ_SM ); |
|
428 | LEON_Unmask_interrupt( IRQ_SM ); | |
429 | break; |
|
429 | break; | |
430 | case(LFR_MODE_BURST): |
|
430 | case(LFR_MODE_BURST): | |
431 | break; |
|
431 | break; | |
432 | case(LFR_MODE_SBM1): |
|
432 | case(LFR_MODE_SBM1): | |
433 | break; |
|
433 | break; | |
434 | case(LFR_MODE_SBM2): |
|
434 | case(LFR_MODE_SBM2): | |
435 | break; |
|
435 | break; | |
436 | } |
|
436 | } | |
437 | return 0; |
|
437 | return 0; | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | int action_load_norm(ccsdsTelecommandPacket_t *TC) |
|
440 | int action_load_norm(ccsdsTelecommandPacket_t *TC) | |
441 | { |
|
441 | { | |
442 | param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1]; |
|
442 | 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]; |
|
443 | 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]; |
|
444 | 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]; |
|
445 | param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6]; | |
446 | param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7]; |
|
446 | 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", |
|
447 | /*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, |
|
448 | 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);*/ |
|
449 | param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/ | |
450 | return 0; |
|
450 | return 0; | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | int action_updt_time(ccsdsTelecommandPacket_t *TC) |
|
453 | int action_updt_time(ccsdsTelecommandPacket_t *TC) | |
454 | { |
|
454 | { | |
455 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) |
|
455 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) | |
456 | + (TC->dataAndCRC[1] << 16) |
|
456 | + (TC->dataAndCRC[1] << 16) | |
457 | + (TC->dataAndCRC[2] << 8) |
|
457 | + (TC->dataAndCRC[2] << 8) | |
458 | + TC->dataAndCRC[3]; |
|
458 | + TC->dataAndCRC[3]; | |
459 | time_management_regs->ctrl = time_management_regs->ctrl | 1; |
|
459 | //time_management_regs->ctrl = time_management_regs->ctrl | 1; | |
460 | return 0; |
|
460 | return 0; | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC) |
|
463 | int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC) | |
464 | { |
|
464 | { | |
465 | TMHeader_t TM_header; |
|
465 | TMHeader_t TM_header; | |
466 | char data[4]; |
|
466 | char data[4]; | |
467 | spw_ioctl_pkt_send spw_ioctl_send; |
|
467 | spw_ioctl_pkt_send spw_ioctl_send; | |
468 |
|
468 | |||
469 | TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE, |
|
469 | TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE, | |
470 | time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header); |
|
470 | time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header); | |
471 |
|
471 | |||
472 | data[0] = TC->packetID[0]; |
|
472 | data[0] = TC->packetID[0]; | |
473 | data[1] = TC->packetID[1]; |
|
473 | data[1] = TC->packetID[1]; | |
474 | data[2] = TC->packetSequenceControl[0]; |
|
474 | data[2] = TC->packetSequenceControl[0]; | |
475 | data[3] = TC->packetSequenceControl[1]; |
|
475 | data[3] = TC->packetSequenceControl[1]; | |
476 |
|
476 | |||
477 | // filling the structure for the spacewire transmission |
|
477 | // filling the structure for the spacewire transmission | |
478 | spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header |
|
478 | spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header | |
479 | spw_ioctl_send.hdr = (char*) &TM_header; |
|
479 | spw_ioctl_send.hdr = (char*) &TM_header; | |
480 | spw_ioctl_send.dlen = 3; |
|
480 | spw_ioctl_send.dlen = 3; | |
481 | spw_ioctl_send.data = data; |
|
481 | spw_ioctl_send.data = data; | |
482 |
|
482 | |||
483 | // SEND DATA |
|
483 | // SEND DATA | |
484 | write_spw(&spw_ioctl_send); |
|
484 | write_spw(&spw_ioctl_send); | |
485 |
|
485 | |||
486 | return 0; |
|
486 | return 0; | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
|
489 | //*************************** | |||
|
490 | // Interrupt Service Routines | |||
|
491 | rtems_isr commutation_isr1( rtems_vector_number vector ) | |||
|
492 | { | |||
|
493 | 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"); | |||
|
495 | } | |||
489 |
|
496 | |||
|
497 | rtems_isr commutation_isr2( rtems_vector_number vector ) | |||
|
498 | { | |||
|
499 | 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"); | |||
|
501 | } | |||
|
502 | ||||
|
503 | rtems_task dumb_task( rtems_task_argument unused ) | |||
|
504 | { | |||
|
505 | unsigned int coarse_time; | |||
|
506 | unsigned int fine_time; | |||
|
507 | rtems_event_set event_out; | |||
|
508 | ||||
|
509 | PRINTF("In DUMB *** \n") | |||
|
510 | ||||
|
511 | while(1){ | |||
|
512 | 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; | |||
|
514 | fine_time = time_management_regs->fine_time; | |||
|
515 | printf("commutation_isr*, coarse time = %x, fine time = %x\n", coarse_time, fine_time); | |||
|
516 | } | |||
|
517 | } | |||
|
518 | ||||
|
519 | ||||
|
520 |
@@ -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 spectral_matrices_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 | header.dataFieldHeader[4] = 0xaa; |
|
|||
34 | header.dataFieldHeader[5] = 0xbb; |
|
|||
35 | header.dataFieldHeader[6] = 0xcc; |
|
|||
36 | header.dataFieldHeader[7] = 0xdd; |
|
|||
37 | header.dataFieldHeader[8] = 0xee; |
|
|||
38 | header.dataFieldHeader[9] = 0xff; |
|
|||
39 |
|
33 | |||
40 | header.auxiliaryHeader[0] = 0x00; |
|
34 | header.auxiliaryHeader[0] = 0x00; | |
41 | header.auxiliaryHeader[1] = 0x1f; |
|
35 | header.auxiliaryHeader[1] = 0x1f; | |
42 | header.auxiliaryHeader[2] = 0x07; // PKT_CNT |
|
36 | header.auxiliaryHeader[2] = 0x07; // PKT_CNT | |
43 | header.auxiliaryHeader[3] = 0x00; // PKT_NR |
|
37 | header.auxiliaryHeader[3] = 0x00; // PKT_NR | |
44 | header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB |
|
38 | header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB | |
45 | header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB |
|
39 | header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB | |
46 |
|
40 | |||
47 | // BUILD THE PACKET HEADER |
|
41 | // BUILD THE PACKET HEADER | |
48 | 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 | |
49 | spw_ioctl_send.hdr = (char*) &header; |
|
43 | spw_ioctl_send.hdr = (char*) &header; | |
50 |
|
44 | |||
51 | PRINTF("In WFRM *** \n") |
|
45 | PRINTF("In WFRM *** \n") | |
52 |
|
46 | |||
53 | while(1){ |
|
47 | while(1){ | |
54 | 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); | |||
|
50 | header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16); | |||
|
51 | header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8); | |||
|
52 | header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time); | |||
|
53 | header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8); | |||
|
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