##// END OF EJS Templates
Updates of the ICD taken into account...
paul@pc-solar1.lab-lpp.local -
r18:bab57f7b9093 default
parent child
Show More
@@ -2,45 +2,45
2 <CodeBlocks_layout_file>
2 <CodeBlocks_layout_file>
3 <ActiveTarget name="Debug" />
3 <ActiveTarget name="Debug" />
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
5 <Cursor position="4971" topLine="100" />
5 <Cursor position="1196" topLine="121" />
6 </File>
6 </File>
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="6">
7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="4">
8 <Cursor position="597" topLine="0" />
8 <Cursor position="232" topLine="0" />
9 </File>
9 </File>
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="3">
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="3">
11 <Cursor position="279" topLine="0" />
11 <Cursor position="292" topLine="0" />
12 </File>
12 </File>
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="3">
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="2">
14 <Cursor position="1416" topLine="31" />
14 <Cursor position="1815" topLine="53" />
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="1216" topLine="5" />
17 <Cursor position="576" topLine="0" />
18 </File>
18 </File>
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
20 <Cursor position="444" topLine="0" />
20 <Cursor position="1318" topLine="36" />
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="1380" topLine="35" />
23 <Cursor position="658" topLine="36" />
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="3">
26 <Cursor position="316" topLine="0" />
26 <Cursor position="732" topLine="7" />
27 </File>
27 </File>
28 <File name="../src/fsw_globals.c" open="1" top="0" tabpos="3">
28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="5">
29 <Cursor position="1246" topLine="6" />
29 <Cursor position="663" topLine="18" />
30 </File>
30 </File>
31 <File name="../src/fsw_init.c" open="1" top="1" tabpos="1">
31 <File name="../src/fsw_init.c" open="0" top="0" tabpos="1">
32 <Cursor position="2317" topLine="59" />
32 <Cursor position="3984" topLine="98" />
33 </File>
33 </File>
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
35 <Cursor position="6076" topLine="0" />
35 <Cursor position="1183" topLine="46" />
36 </File>
36 </File>
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="4">
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="4">
38 <Cursor position="19048" topLine="64" />
38 <Cursor position="79" topLine="0" />
39 </File>
39 </File>
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="5">
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="3">
41 <Cursor position="536" topLine="0" />
41 <Cursor position="22195" topLine="58" />
42 </File>
42 </File>
43 <File name="../src/wf_handler.c" open="1" top="0" tabpos="2">
43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="2">
44 <Cursor position="5858" topLine="70" />
44 <Cursor position="5903" topLine="117" />
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
@@ -28,27 +28,48
28 #define WRONG_APP_DATA 5
28 #define WRONG_APP_DATA 5
29 #define WRONG_CMD_CODE 6
29 #define WRONG_CMD_CODE 6
30 #define CCSDS_TM_VALID 7
30 #define CCSDS_TM_VALID 7
31 //
31
32 #define TC_NOT_EXE 40000
32 // TC TYPES
33 #define WRONG_SRC_ID 40001
33 #define TC_TYPE_GEN 181
34 #define FUNCT_NOT_IMPL 40002
34 #define TC_TYPE_TIME 9
35 #define FAIL_DETECTED 40003
35
36 #define NOT_ALLOWED 40004
36 // TC SUBTYPES
37 #define CORRUPTED 40005
37 #define TC_SUBTYPE_RESET 1
38 #define TC_SUBTYPE_LOAD_COMM 11
39 #define TC_SUBTYPE_LOAD_NORM 13
40 #define TC_SUBTYPE_LOAD_BURST 19
41 #define TC_SUBTYPE_LOAD_SBM1 25
42 #define TC_SUBTYPE_LOAD_SBM2 27
43 #define TC_SUBTYPE_DUMP 31
44 #define TC_SUBTYPE_ENTER 41
45 #define TC_SUBTYPE_UPDT_INFO 51
46 #define TC_SUBTYPE_EN_CAL 61
47 #define TC_SUBTYPE_DIS_CAL 63
48 #define TC_SUBTYPE_UPDT_TIME 129
38
49
39 // // TC SUBTYPES
50 // TC LEN
40 #define TC_SUBTYPE_RESET 3
51 #define TC_LEN_RESET 12
41 #define TC_SUBTYPE_LOAD_COMM 20
52 #define TC_LEN_LOAD_COMM 14
42 #define TC_SUBTYPE_LOAD_NORM 21
53 #define TC_LEN_LOAD_NORM 20
43 #define TC_SUBTYPE_LOAD_BURST 24
54 #define TC_LEN_LOAD_BURST 14
44 #define TC_SUBTYPE_LOAD_SBM1 27
55 #define TC_LEN_LOAD_SBM1 14
45 #define TC_SUBTYPE_LOAD_SBM2 28
56 #define TC_LEN_LOAD_SBM2 14
46 #define TC_SUBTYPE_DUMP 30
57 #define TC_LEN_DUMP 12
47 #define TC_SUBTYPE_ENTER 40
58 #define TC_LEN_ENTER 20
48 #define TC_SUBTYPE_UPDT_INFO 50
59 #define TC_LEN_UPDT_INFO 48
49 #define TC_SUBTYPE_EN_CAL 60
60 #define TC_LEN_EN_CAL 12
50 #define TC_SUBTYPE_DIS_CAL 61
61 #define TC_LEN_DIS_CAL 12
51 #define TC_SUBTYPE_UPDT_TIME 129
62 #define TC_LEN_UPDT_TIME 18
63
64 // TM TYPES
65 #define TM_TYPE_LFR_SCIENCE 21
66
67 // TM SUBTYPES
68 #define TM_SUBTYPE_EXE_OK 7
69 #define TM_SUBTYPE_EXE_NOK 8
70 #define TM_SUBTYPE_HK 25
71 #define TM_SUBTYPE_SCIENCE 3
72 #define TM_SUBTYPE_LFR_SCIENCE 3
52
73
53 #define SID_DEFAULT 0
74 #define SID_DEFAULT 0
54 #define SID_HK 1
75 #define SID_HK 1
@@ -16,7 +16,7
16 #include <wf_handler.h>
16 #include <wf_handler.h>
17 #include <grlib_regs.h>
17 #include <grlib_regs.h>
18
18
19 extern int sched_yield();
19 extern int sched_yield( void );
20 extern int errno;
20 extern int errno;
21 extern rtems_id Task_id[ ]; /* array of task ids */
21 extern rtems_id Task_id[ ]; /* array of task ids */
22 extern rtems_name Task_name[ ]; /* array of task names */
22 extern rtems_name Task_name[ ]; /* array of task names */
@@ -39,21 +39,21 rtems_task recv_task(rtems_task_argument
39 rtems_task spiq_task(rtems_task_argument argument);
39 rtems_task spiq_task(rtems_task_argument argument);
40 rtems_task stat_task(rtems_task_argument argument);
40 rtems_task stat_task(rtems_task_argument argument);
41 rtems_task wfrm_task(rtems_task_argument argument);
41 rtems_task wfrm_task(rtems_task_argument argument);
42 int create_names();
42 int create_names( void );
43 int create_all_tasks();
43 int create_all_tasks( void );
44 int start_all_tasks();
44 int start_all_tasks( void );
45 int create_message_queue();
45 int create_message_queue( void );
46
46
47 // OTHER functions
47 // OTHER functions
48 void init_default_mode_parameters();
48 void init_default_mode_parameters( void );
49
49
50 int configure_spw_link();
50 int configure_spw_link( void );
51 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
51 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
52 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
52 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
53
53
54 extern int rtems_cpu_usage_report();
54 extern int rtems_cpu_usage_report( void );
55 extern int rtems_cpu_usage_reset();
55 extern int rtems_cpu_usage_reset( void );
56 void print_statistics(spw_stats *);
56
57 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
57 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
58 void (*grspw_timecode_callback) (void *pDev, void *regs, int minor, unsigned int tc);
58 void (*grspw_timecode_callback) (void *pDev, void *regs, int minor, unsigned int tc);
59
59
@@ -10,15 +10,15
10 #include <grspw.h>
10 #include <grspw.h>
11 #include <ccsds_types.h>
11 #include <ccsds_types.h>
12
12
13 rtems_name HK_name; /* name of the HK rate monotonic */
13 rtems_name HK_name; // name of the HK rate monotonic
14 rtems_id HK_id; /* id of the HK rate monotonic period */
14 rtems_id HK_id; // id of the HK rate monotonic period
15
15
16 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
16 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
18 void print_statistics(spw_stats *stats);
18 void print_statistics(spw_stats *stats);
19
19
20 // SERIAL LINK
20 // SERIAL LINK
21 int send_console_outputs_on_serial_port();
21 int send_console_outputs_on_serial_port( void );
22 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
22 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
23
23
24 // RTEMS TASKS
24 // RTEMS TASKS
@@ -19,6 +19,7
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 #define REGS_ADDR_WAVEFORM_PICKER 0x80000f20
22
23
23 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
24 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
24 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400
25 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400
@@ -33,6 +34,8
33 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
34 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
34 #define IRQ_TIME2 13
35 #define IRQ_TIME2 13
35 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
36 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
37 #define IRQ_WAVEFORM_PICKER 14
38 #define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels
36
39
37 //*****
40 //*****
38 // TIME
41 // TIME
@@ -59,8 +62,6
59
62
60 //*******
63 //*******
61 // MACROS
64 // MACROS
62 #define PRINT_TASK_STATISTICS
63 #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
64 #ifdef PRINT_MESSAGES_ON_CONSOLE
65 #ifdef PRINT_MESSAGES_ON_CONSOLE
65 #define PRINTF(x) printf(x);
66 #define PRINTF(x) printf(x);
66 #define PRINTF1(x,y) printf(x,y);
67 #define PRINTF1(x,y) printf(x,y);
@@ -72,6 +73,8
72 #endif
73 #endif
73
74
74 #define NB_SAMPLES_PER_SNAPSHOT 2048
75 #define NB_SAMPLES_PER_SNAPSHOT 2048
76 #define TIME_OFFSET 2
77 #define WAVEFORM_EXTENDED_HEADER_OFFSET 22
75 #define NB_BYTES_SWF_BLK 2 * 6
78 #define NB_BYTES_SWF_BLK 2 * 6
76 #define NB_WORDS_SWF_BLK 3
79 #define NB_WORDS_SWF_BLK 3
77
80
@@ -98,9 +101,4 struct param_sbm2_str{
98 unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set
101 unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set
99 };
102 };
100
103
101 extern volatile int wf_snap_f0[ ]; // 24576 bytes
102 extern volatile int wf_snap_f1[ ]; // 24576 bytes
103 extern volatile int wf_snap_f2[ ]; // 24576 bytes
104 extern volatile int wf_cont_f3[ ]; // 24576 bytes
105
106 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
104 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -14,6 +14,9
14 #include <rtems.h>
14 #include <rtems.h>
15 #include <grlib_regs.h>
15 #include <grlib_regs.h>
16 #include <fsw_params.h>
16 #include <fsw_params.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <leon.h>
17
20
18 struct BP1_str{
21 struct BP1_str{
19 volatile unsigned char PE[2];
22 volatile unsigned char PE[2];
@@ -26,6 +29,24 struct BP1_str{
26 };
29 };
27 typedef struct BP1_str BP1_t;
30 typedef struct BP1_str BP1_t;
28
31
32 extern volatile int spec_mat_f0_a[ ];
33 extern volatile int spec_mat_f0_b[ ];
34 extern volatile int spec_mat_f0_c[ ];
35 extern volatile int spec_mat_f0_d[ ];
36 extern volatile int spec_mat_f0_e[ ];
37 extern volatile int spec_mat_f0_f[ ];
38 extern volatile int spec_mat_f0_g[ ];
39 extern volatile int spec_mat_f0_h[ ];
40 extern float averaged_spec_mat_f0[ ];
41 extern float compressed_spec_mat_f0[ ];
42 extern unsigned char LFR_BP1_F0[ ];
43
44 extern BP1_t data_BP1[ ];
45
46 extern rtems_id Task_id[ ]; /* array of task ids */
47
48 extern spectral_matrices_regs_t *spectral_matrices_regs;
49
29 // ISR
50 // ISR
30 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
51 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
31
52
@@ -45,4 +45,20 struct time_management_regs_str{
45 };
45 };
46 typedef struct time_management_regs_str time_management_regs_t;
46 typedef struct time_management_regs_str time_management_regs_t;
47
47
48 struct waveform_picker_regs_str{
49 volatile int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
50 volatile int burst_enable; // 0x04 01 *** burst f2, f1, f0 enable f3, f2, f1, f0
51 volatile int addr_data_f0; // 0x08 10 ***
52 volatile int addr_data_f1; // 0x0c 11 ***
53 volatile int addr_data_f2; // 0x10 100 ***
54 volatile int addr_data_f3; // 0x14 101 ***
55 volatile int status; // 0x18 110 ***
56 volatile int delta_snapshot; // 0x1c 111 ***
57 volatile int delta_f2_f1; // 0x20 0000 ***
58 volatile int delta_f2_f0; // 0x24 0001 ***
59 volatile int nb_burst_available;// 0x28 0010 ***
60 volatile int nb_snapshot_param; // 0x2c 0011 ***
61 };
62 typedef struct waveform_picker_regs_str waveform_picker_regs_t;
63
48 #endif // GRLIBREGS_H_INCLUDED
64 #endif // GRLIBREGS_H_INCLUDED
@@ -19,14 +19,10 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 waveform_picker_regs_t *waveform_picker_regs;
23 extern gptimer_regs_t *gptimer_regs;
22 extern unsigned char param_common[];
24 extern unsigned char param_common[];
23
25
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];
26 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
27 unsigned int currentTM_length;
28 unsigned char currentTC_processedFlag;
29
30 //****
26 //****
31 // ISR
27 // ISR
32 rtems_isr commutation_isr1( rtems_vector_number vector );
28 rtems_isr commutation_isr1( rtems_vector_number vector );
@@ -34,8 +30,7 rtems_isr commutation_isr2( rtems_vector
34
30
35 //**********************
31 //**********************
36 // GENERAL USE FUNCTIONS
32 // GENERAL USE FUNCTIONS
37 unsigned int lookUpTableForCRC[256];
33 void initLookUpTableForCRC( void );
38 void initLookUpTableForCRC();
39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
34 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
40
35
41 //*********************
36 //*********************
@@ -52,7 +47,7 int TC_checker(ccsdsTelecommandPacket_t
52 rtems_task recv_task( rtems_task_argument unused );
47 rtems_task recv_task( rtems_task_argument unused );
53 rtems_task actn_task( rtems_task_argument unused );
48 rtems_task actn_task( rtems_task_argument unused );
54 rtems_task dumb_task( rtems_task_argument unused );
49 rtems_task dumb_task( rtems_task_argument unused );
55 int create_message_queue();
50 int create_message_queue( void );
56
51
57 //***********
52 //***********
58 // TC ACTIONS
53 // TC ACTIONS
@@ -8,18 +8,30
8 #include <ccsds_types.h>
8 #include <ccsds_types.h>
9 #include <stdio.h>
9 #include <stdio.h>
10 #include <fsw_init.h>
10 #include <fsw_init.h>
11 #include <math.h>
12
13 #define pi 3.1415
11
14
12 //#include <sys/ioctl.h>
15 //#include <sys/ioctl.h>
13
16
14 extern rtems_id Task_id[]; /* array of task ids */
17 extern rtems_id Task_id[]; /* array of task ids */
15 extern int fdSPW;
18 extern int fdSPW;
19 extern volatile int wf_snap_f0[ ];
20 extern volatile int wf_snap_f1[ ];
21 extern volatile int wf_snap_f2[ ];
22 extern volatile int wf_cont_f3[ ];
23 extern waveform_picker_regs_t *waveform_picker_regs;
16
24
17 rtems_isr waveforms_isr( rtems_vector_number vector );
25 rtems_isr waveforms_isr( rtems_vector_number vector );
26 rtems_isr waveforms_simulator_isr( rtems_vector_number vector );
18 rtems_task wfrm_task(rtems_task_argument argument);
27 rtems_task wfrm_task(rtems_task_argument argument);
19
28
20 //******************
29 //******************
21 // general functions
30 // general functions
22 void init_waveforms();
31 void init_waveforms( void );
23 int buil_value(int value1, int value0);
32 void reset_waveforms( void );
33 void send_waveform( ExtendedTMHeader_t *header, volatile int *waveform, unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send);
34 void init_waveform_picker_regs();
35 int build_value(int value1, int value0);
24
36
25 #endif // WF_HANDLER_H_INCLUDED
37 #endif // WF_HANDLER_H_INCLUDED
@@ -7,17 +7,21 rtems_name misc_name[5];
7 rtems_name misc_id[5];
7 rtems_name misc_id[5];
8 rtems_id Task_id[15]; /* array of task ids */
8 rtems_id Task_id[15]; /* array of task ids */
9 rtems_name Task_name[15]; /* array of task names */
9 rtems_name Task_name[15]; /* array of task names */
10 int fdSPW;
10 int fdSPW = 0;
11 int fdUART;
11 int fdUART = 0;
12
13 spectral_matrices_regs_t *spectral_matrices_regs = NULL;
12
14
13 // APB CONFIGURATION REGISTERS
15 // APB CONFIGURATION REGISTERS
14 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
16 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
17 waveform_picker_regs_t *waveform_picker_regs = (waveform_picker_regs_t*) REGS_ADDR_WAVEFORM_PICKER;
18 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
15
19
16 // WAVEFORMS GLOBAL VARIABLES
20 // WAVEFORMS GLOBAL VARIABLES
17 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
21 volatile int wf_snap_f0[ 2 * NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK + 2]; // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes
18 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
22 volatile int wf_snap_f1[ 2 * NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK + 2]; // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes
19 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
23 volatile int wf_snap_f2[ 2 * NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK + 2]; // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes
20 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
24 volatile int wf_cont_f3[ 2 * NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK + 2]; // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes
21
25
22 // SPECTRAL MATRICES GLOBAL VARIABLES
26 // SPECTRAL MATRICES GLOBAL VARIABLES
23 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
27 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
@@ -44,8 +44,6
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);
48
49 char *lstates[6] = {"Error-reset",
47 char *lstates[6] = {"Error-reset",
50 "Error-wait",
48 "Error-wait",
51 "Ready",
49 "Ready",
@@ -80,58 +78,87 rtems_task Init( rtems_task_argument ign
80
78
81 configure_spw_link();
79 configure_spw_link();
82
80
83 init_waveforms();
81 //****************************
84
82 // Spectral Matrices simulator
85 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
83 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
86 IRQ_SPARC_SM, spectral_matrices_isr );
84 IRQ_SPARC_SM, spectral_matrices_isr );
85
86 //**********
87 // WAVEFORMS
88 // simulator
89
90 #ifdef GSA
87 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
91 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
88 IRQ_SPARC_WF, waveforms_isr );
92 IRQ_SPARC_WF, waveforms_simulator_isr );
93 #else
94 // configure the registers of the waveform picker
95 init_waveform_picker_regs();
96 // configure the waveform picker interrupt service routine
97 status = rtems_interrupt_catch( waveforms_isr,
98 IRQ_SPARC_WAVEFORM_PICKER,
99 &old_isr_handler) ;
100 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER );
101 #endif
89
102
103 //**********
104
105 //*****************************************
90 // irq handling of the time management unit
106 // irq handling of the time management unit
91 status = rtems_interrupt_catch( commutation_isr1,
107 status = rtems_interrupt_catch( commutation_isr1,
92 IRQ_SPARC_TIME1,
108 IRQ_SPARC_TIME1,
93 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
109 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
94 if (status==RTEMS_SUCCESSFUL)
110 if (status==RTEMS_SUCCESSFUL) {
95 PRINTF("OK *** commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
111 PRINTF("OK *** commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
112 }
96
113
97 status = rtems_interrupt_catch( commutation_isr2,
114 status = rtems_interrupt_catch( commutation_isr2,
98 IRQ_SPARC_TIME2,
115 IRQ_SPARC_TIME2,
99 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
116 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
100 if (status==RTEMS_SUCCESSFUL)
117 if (status==RTEMS_SUCCESSFUL) {
101 PRINTF("OK *** commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
118 PRINTF("OK *** commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
119 }
102
120
103 LEON_Unmask_interrupt( IRQ_TIME1 );
121 LEON_Unmask_interrupt( IRQ_TIME1 );
104 LEON_Unmask_interrupt( IRQ_TIME2 );
122 LEON_Unmask_interrupt( IRQ_TIME2 );
105
123
124 #ifdef GSA
125 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
126 printf("in INIT *** Error sending event to WFRM\n");
127 }
128 #endif
129
106 status = rtems_task_delete(RTEMS_SELF);
130 status = rtems_task_delete(RTEMS_SELF);
131
107 }
132 }
108
133
109 rtems_task spiq_task(rtems_task_argument unused)
134 rtems_task spiq_task(rtems_task_argument unused)
110 {
135 {
111 rtems_event_set event_out;
136 rtems_event_set event_out;
112 struct grspw_regs_str *grspw_regs;
113 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
114 rtems_status_code status;
137 rtems_status_code status;
115
138
116 while(1){
139 while(true){
117 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
140 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
118 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
141 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
119
142
120 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) // suspend RECV task
143 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) { // suspend RECV task
121 PRINTF("in SPIQ *** Error suspending RECV Task\n")
144 PRINTF("in SPIQ *** Error suspending RECV Task\n")
122 if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) // suspend HOUS task
145 }
146 if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) { // suspend HOUS task
123 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
147 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
148 }
124
149
125 configure_spw_link();
150 configure_spw_link();
126
151
127 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
152 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
128 if (status!=RTEMS_SUCCESSFUL)
153 if (status!=RTEMS_SUCCESSFUL) {
129 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
154 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
155 }
130
156
131 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
157 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) { // restart RECV task
132 PRINTF("in SPIQ *** Error restarting RECV Task\n")
158 PRINTF("in SPIQ *** Error restarting RECV Task\n")
133 }
159 }
134 }
160 }
161 }
135
162
136 void init_default_mode_parameters()
163 void init_default_mode_parameters()
137 {
164 {
@@ -155,7 +182,7 void init_default_mode_parameters()
155 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
182 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
156 }
183 }
157
184
158 int create_names()
185 int create_names( void )
159 {
186 {
160 // task names
187 // task names
161 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
188 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
@@ -175,7 +202,7 int create_names()
175 return 0;
202 return 0;
176 }
203 }
177
204
178 int create_all_tasks()
205 int create_all_tasks( void )
179 {
206 {
180 rtems_status_code status;
207 rtems_status_code status;
181
208
@@ -243,44 +270,64 int create_all_tasks()
243 return 0;
270 return 0;
244 }
271 }
245
272
246 int start_all_tasks()
273 int start_all_tasks( void )
247 {
274 {
248 rtems_status_code status;
275 rtems_status_code status;
249
276
250 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
277 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
251 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
278 if (status!=RTEMS_SUCCESSFUL) {
279 PRINTF("In INIT *** Error starting TASK_SPIQ\n")
280 }
252
281
253 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
282 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
254 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
283 if (status!=RTEMS_SUCCESSFUL) {
284 PRINTF("In INIT *** Error starting TASK_RECV\n")
285 }
255
286
256 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
287 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
257 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
288 if (status!=RTEMS_SUCCESSFUL) {
289 PRINTF("In INIT *** Error starting TASK_ACTN\n")
290 }
258
291
259 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
292 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
260 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
293 if (status!=RTEMS_SUCCESSFUL) {
294 PRINTF("In INIT *** Error starting TASK_BPPR\n")
295 }
261
296
262 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
297 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
263 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
298 if (status!=RTEMS_SUCCESSFUL) {
299 PRINTF("In INIT *** Error starting TASK_STAT\n")
300 }
264
301
265 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
302 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
266 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
303 if (status!=RTEMS_SUCCESSFUL) {
304 PRINTF("In INIT *** Error starting TASK_AVF0\n")
305 }
267
306
268 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
307 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
269 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
308 if (status!=RTEMS_SUCCESSFUL) {
309 PRINTF("In INIT *** Error starting TASK_BPF0\n")
310 }
270
311
271 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
312 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
272 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
313 if (status!=RTEMS_SUCCESSFUL) {
314 PRINTF("In INIT *** Error starting TASK_WFRM\n")
315 }
273
316
274 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
317 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
275 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")
318 if (status!=RTEMS_SUCCESSFUL) {
319 PRINTF("In INIT *** Error starting TASK_DUMB\n")
320 }
276
321
277 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
322 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
278 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_HOUS\n")
323 if (status!=RTEMS_SUCCESSFUL) {
324 PRINTF("In INIT *** Error starting TASK_HOUS\n")
325 }
279
326
280 return 0;
327 return 0;
281 }
328 }
282
329
283 int configure_spw_link()
330 int configure_spw_link( void )
284 {
331 {
285 rtems_status_code status;
332 rtems_status_code status;
286
333
@@ -314,7 +361,7 int configure_spw_link()
314 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
361 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
315 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
362 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
316 //
363 //
317 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
364 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 0); // transmission blocks on full
318 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
365 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
319 //
366 //
320 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
367 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
@@ -325,27 +372,25 int configure_spw_link()
325 return RTEMS_SUCCESSFUL;
372 return RTEMS_SUCCESSFUL;
326 }
373 }
327
374
328 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // No Port force
375 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // [N]o [P]ort force
329 {
376 {
330 unsigned int *spwptr;
377 unsigned int *spwptr = (unsigned int*) regAddr;
331 spwptr = (unsigned int*) regAddr;
378
332 if (val == 1)
379 if (val == 1) {
333 {
334 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
380 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
335 }
381 }
336 if (val== 0)
382 if (val== 0) {
337 {
338 *spwptr = *spwptr & 0xffdfffff;
383 *spwptr = *spwptr & 0xffdfffff;
339 }
384 }
340 }
385 }
341
386
342 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // RMAP Enable
387 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // [R]MAP [E]nable
343 {
388 {
344 unsigned int *spwptr;
389 unsigned int *spwptr = (unsigned int*) regAddr;
345 spwptr = (unsigned int*) regAddr;
390
346 if (val == 1)
391 if (val == 1)
347 {
392 {
348 *spwptr = *spwptr | 0x00010000; // [NP] set the No port force bit
393 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
349 }
394 }
350 if (val== 0)
395 if (val== 0)
351 {
396 {
@@ -353,21 +398,17 void configure_spacewire_set_RE(unsigned
353 }
398 }
354 }
399 }
355
400
356 char *link_status(int status){
357 return lstates[status];
358 }
359
360 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
401 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
361 {
402 {
362 rtems_status_code status;
403 rtems_status_code status;
363 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
404 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
364 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
365 return status;
405 return status;
366 }
406 }
367
407
368 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
408 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
369 {
409 {
370 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
410 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) {
371 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
411 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
372 }
412 }
413 }
373
414
@@ -45,11 +45,10 void print_statistics(spw_stats *stats)
45 printf("Packets received: %i\n", stats->packets_received);
45 printf("Packets received: %i\n", stats->packets_received);
46 }
46 }
47
47
48 int send_console_outputs_on_serial_port() // Send the console outputs on the serial port
48 int send_console_outputs_on_serial_port( void ) // Send the console outputs on the serial port
49 {
49 {
50 struct apbuart_regs_str *apbuart_regs;
50 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
51
51
52 apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
53 apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
52 apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
54 PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
53 PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
55
54
@@ -58,9 +57,8 int send_console_outputs_on_serial_port(
58
57
59 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
58 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
60 {
59 {
61 struct apbuart_regs_str *apbuart_regs;
60 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
62
61
63 apbuart_regs = (struct apbuart_regs_str *) regs;
64 apbuart_regs->scaler = value;
62 apbuart_regs->scaler = value;
65 PRINTF1("OK *** COM port scaler reload register set to %x\n", value)
63 PRINTF1("OK *** COM port scaler reload register set to %x\n", value)
66
64
@@ -94,17 +92,17 rtems_task stat_task(rtems_task_argument
94
92
95 rtems_task hous_task(rtems_task_argument argument)
93 rtems_task hous_task(rtems_task_argument argument)
96 {
94 {
97 PRINTF("in HOUS ***\n")
98
99 int result;
95 int result;
100 rtems_status_code status;
96 rtems_status_code status;
101
97
102 if (rtems_rate_monotonic_ident( HK_name, &HK_id)!=RTEMS_SUCCESSFUL)
98 PRINTF("in HOUS ***\n")
103 {
99
100 if (rtems_rate_monotonic_ident( HK_name, &HK_id)!=RTEMS_SUCCESSFUL) {
104 status = rtems_rate_monotonic_create( HK_name, &HK_id );
101 status = rtems_rate_monotonic_create( HK_name, &HK_id );
105 if( status != RTEMS_SUCCESSFUL )
102 if( status != RTEMS_SUCCESSFUL ) {
106 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
103 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
107 }
104 }
105 }
108
106
109 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
107 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
110 housekeeping_packet.protocolIdentifier = 0x02;
108 housekeeping_packet.protocolIdentifier = 0x02;
@@ -1,82 +1,22
1 #include <fsw_processing.h>
1 #include <fsw_processing.h>
2 #include <math.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <leon.h>
6
3
7 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
4 #include <fsw_processing_globals.c>
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;
44
45 float alpha_M = M_PI/4;
46
47 extern volatile int spec_mat_f0_a[ ];
48 extern volatile int spec_mat_f0_b[ ];
49 extern volatile int spec_mat_f0_c[ ];
50 extern volatile int spec_mat_f0_d[ ];
51 extern volatile int spec_mat_f0_e[ ];
52 extern volatile int spec_mat_f0_f[ ];
53 extern volatile int spec_mat_f0_g[ ];
54 extern volatile int spec_mat_f0_h[ ];
55 extern float averaged_spec_mat_f0[ ];
56 extern float compressed_spec_mat_f0[ ];
57 extern unsigned char LFR_BP1_F0[ ];
58
59 extern BP1_t data_BP1[ ];
60
61 extern rtems_id Task_id[ ]; /* array of task ids */
62
63 spectral_matrices_regs_t *spectral_matrices_regs;
64
5
65 //***********************************************************
6 //***********************************************************
66 // Interrupt Service Routine for spectral matrices processing
7 // Interrupt Service Routine for spectral matrices processing
67 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
8 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
68 {
9 {
69 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
10 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
70 printf("in spectral_matrices_isr *** Error sending event to AVF0\n");
11 printf("in spectral_matrices_isr *** Error sending event to AVF0\n");
71 }
12 }
13 }
72
14
73 //************
15 //************
74 // RTEMS TASKS
16 // RTEMS TASKS
75 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
17 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
76 {
18 {
77 rtems_event_set event_out;
19 rtems_event_set event_out;
78 gptimer_regs_t *gptimer_regs;
79 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
80 unsigned char nb_interrupt_f0 = 0;
20 unsigned char nb_interrupt_f0 = 0;
81
21
82 PRINTF("in SMIQ *** \n")
22 PRINTF("in SMIQ *** \n")
@@ -96,37 +36,35 rtems_task spw_bppr_task(rtems_task_argu
96 {
36 {
97 rtems_status_code status;
37 rtems_status_code status;
98 rtems_event_set event_out;
38 rtems_event_set event_out;
99 static int nb_average_f0 = 0;
39 static int Nb_average_f0 = 0;
100 //static int nb_average_f1 = 0;
40 //static int nb_average_f1 = 0;
101 //static int nb_average_f2 = 0;
41 //static int nb_average_f2 = 0;
102
42
103 while(1)
104
105 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
43 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
106 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
44 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
107 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
45 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
108
46
109 printf("in BPPR ***\n");
47 printf("in BPPR ***\n");
110
48
111 while(1){ // wait for an event to begin with the processing
49 while(true){ // wait for an event to begin with the processing
112 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
50 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
113 if (status == RTEMS_SUCCESSFUL){
51 if (status == RTEMS_SUCCESSFUL) {
114 if ((spectral_matrices_regs->ctrl & 0x00000001)==1){
52 if ((spectral_matrices_regs->ctrl & 0x00000001)==1) {
115 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
53 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
116 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
54 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
117 //printf("f0_a\n");
55 //printf("f0_a\n");
118 nb_average_f0++;
56 Nb_average_f0++;
119 }
57 }
120 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){
58 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1) {
121 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
59 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
122 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
60 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
123 //printf("f0_b\n");
61 //printf("f0_b\n");
124 nb_average_f0++;
62 Nb_average_f0++;
125 }
63 }
126 if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){
64 if (Nb_average_f0 == NB_AVERAGE_NORMAL_f0) {
127 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
65 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
128 //printf("f0 compressed\n");
66 //printf("f0 compressed\n");
129 nb_average_f0 = 0;
67 Nb_average_f0 = 0;
130 matrix_reset(averaged_spec_mat_f0);
68 matrix_reset(averaged_spec_mat_f0);
131 }
69 }
132 }
70 }
@@ -164,7 +102,9 rtems_task avf0_task(rtems_task_argument
164 if (nb_average == NB_AVERAGE_NORMAL_f0) {
102 if (nb_average == NB_AVERAGE_NORMAL_f0) {
165 nb_average = 0;
103 nb_average = 0;
166 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
104 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
167 if (status != RTEMS_SUCCESSFUL) printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
105 if (status != RTEMS_SUCCESSFUL) {
106 printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
107 }
168 }
108 }
169 }
109 }
170 }
110 }
@@ -209,11 +149,12 void matrix_reset(float *averaged_spec_m
209
149
210 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
150 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
211 {
151 {
212 int i, j;
152 int i;
153 int j;
213 switch (fChannel){
154 switch (fChannel){
214 case 0:
155 case 0:
215 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
156 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
216 j = 17 + i * 8;
157 j = 17 + (i * 8);
217 compressed_spec_mat[i] = (averaged_spec_mat[j]
158 compressed_spec_mat[i] = (averaged_spec_mat[j]
218 + averaged_spec_mat[j+1]
159 + averaged_spec_mat[j+1]
219 + averaged_spec_mat[j+2]
160 + averaged_spec_mat[j+2]
@@ -236,53 +177,61 void matrix_compression(float *averaged_
236 }
177 }
237
178
238 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
179 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
239 int i, j;
180 int i;
181 int j;
240 unsigned char tmp_u_char;
182 unsigned char tmp_u_char;
241 unsigned char * pt_char;
183 unsigned char * pt_char = NULL;
242 float PSDB, PSDE;
184 float PSDB, PSDE;
243 float NVEC_V0, NVEC_V1, NVEC_V2;
185 float NVEC_V0;
186 float NVEC_V1;
187 float NVEC_V2;
244 //float significand;
188 //float significand;
245 //int exponent;
189 //int exponent;
246 float aux, tr_SB_SB, tmp;
190 float aux;
247 float sx_re, sx_im;
191 float tr_SB_SB;
248 float nebx_re = 0, nebx_im = 0;
192 float tmp;
249 float ny = 0, nz = 0;
193 float sx_re;
194 float sx_im;
195 float nebx_re = 0;
196 float nebx_im = 0;
197 float ny = 0;
198 float nz = 0;
250 float bx_bx_star = 0;
199 float bx_bx_star = 0;
251 for(i=0; i<nb_bins_compressed_spec_mat; i++){
200 for(i=0; i<nb_bins_compressed_spec_mat; i++){
252 //==============================================
201 //==============================================
253 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
202 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
254 PSDB = compressed_spec_mat[i*30] // S11
203 PSDB = compressed_spec_mat[i*30] // S11
255 + compressed_spec_mat[i*30+10] // S22
204 + compressed_spec_mat[(i*30) + 10] // S22
256 + compressed_spec_mat[i*30+18]; // S33
205 + compressed_spec_mat[(i*30) + 18]; // S33
257 //significand = frexp(PSDB, &exponent);
206 //significand = frexp(PSDB, &exponent);
258 pt_char = (unsigned char*) &PSDB;
207 pt_char = (unsigned char*) &PSDB;
259 LFR_BP1[i*9+2] = pt_char[0]; // bits 31 downto 24 of the float
208 LFR_BP1[(i*9) + 2] = pt_char[0]; // bits 31 downto 24 of the float
260 LFR_BP1[i*9+3] = pt_char[1]; // bits 23 downto 16 of the float
209 LFR_BP1[(i*9) + 3] = pt_char[1]; // bits 23 downto 16 of the float
261 //==============================================
210 //==============================================
262 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
211 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
263 PSDE = compressed_spec_mat[i*30+24] * k44_pe // S44
212 PSDE = compressed_spec_mat[(i*30) + 24] * K44_pe // S44
264 + compressed_spec_mat[i*30+28] * k55_pe // S55
213 + compressed_spec_mat[(i*30) + 28] * K55_pe // S55
265 + compressed_spec_mat[i*30+26] * k45_pe_re // S45
214 + compressed_spec_mat[(i*30) + 26] * K45_pe_re // S45
266 - compressed_spec_mat[i*30+27] * k45_pe_im; // S45
215 - compressed_spec_mat[(i*30) + 27] * K45_pe_im; // S45
267 pt_char = (unsigned char*) &PSDE;
216 pt_char = (unsigned char*) &PSDE;
268 LFR_BP1[i*9+0] = pt_char[0]; // bits 31 downto 24 of the float
217 LFR_BP1[(i*9) + 0] = pt_char[0]; // bits 31 downto 24 of the float
269 LFR_BP1[i*9+1] = pt_char[1]; // bits 23 downto 16 of the float
218 LFR_BP1[(i*9) + 1] = pt_char[1]; // bits 23 downto 16 of the float
270 //==============================================================================
219 //==============================================================================
271 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
220 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
272 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
221 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
273 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
222 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
274 tmp = sqrt(
223 tmp = sqrt(
275 compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12
224 compressed_spec_mat[(i*30) + 3]*compressed_spec_mat[(i*30) + 3] //Im S12
276 +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13
225 +compressed_spec_mat[(i*30) + 5]*compressed_spec_mat[(i*30) + 5] //Im S13
277 +compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13] //Im S23
226 +compressed_spec_mat[(i*30) + 13]*compressed_spec_mat[(i*30) + 13] //Im S23
278 );
227 );
279 NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23
228 NVEC_V0 = compressed_spec_mat[(i*30) + 13] / tmp; // Im S23
280 NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13
229 NVEC_V1 = -compressed_spec_mat[(i*30) + 5] / tmp; // Im S13
281 NVEC_V2 = compressed_spec_mat[i*30+3] / tmp; // Im S12
230 NVEC_V2 = compressed_spec_mat[(i*30) + 3] / tmp; // Im S12
282 LFR_BP1[i*9+4] = (char) (NVEC_V0*127);
231 LFR_BP1[(i*9) + 4] = (char) (NVEC_V0*127);
283 LFR_BP1[i*9+5] = (char) (NVEC_V1*127);
232 LFR_BP1[(i*9) + 5] = (char) (NVEC_V1*127);
284 pt_char = (unsigned char*) &NVEC_V2;
233 pt_char = (unsigned char*) &NVEC_V2;
285 LFR_BP1[i*9+6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
234 LFR_BP1[(i*9) + 6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
286 //=======================================================
235 //=======================================================
287 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
236 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
288 aux = 2*tmp / PSDB; // compute the ellipticity
237 aux = 2*tmp / PSDB; // compute the ellipticity
@@ -292,115 +241,121 void BP1_set(float * compressed_spec_mat
292 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
241 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
293 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
242 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
294 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
243 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
295 + compressed_spec_mat[i*30+10] * compressed_spec_mat[i*30+10]
244 + compressed_spec_mat[(i*30) + 10] * compressed_spec_mat[(i*30) + 10]
296 + compressed_spec_mat[i*30+18] * compressed_spec_mat[i*30+18]
245 + compressed_spec_mat[(i*30) + 18] * compressed_spec_mat[(i*30) + 18]
297 + 2 * compressed_spec_mat[i*30+2] * compressed_spec_mat[i*30+2]
246 + 2 * compressed_spec_mat[(i*30) + 2] * compressed_spec_mat[(i*30) + 2]
298 + 2 * compressed_spec_mat[i*30+3] * compressed_spec_mat[i*30+3]
247 + 2 * compressed_spec_mat[(i*30) + 3] * compressed_spec_mat[(i*30) + 3]
299 + 2 * compressed_spec_mat[i*30+4] * compressed_spec_mat[i*30+4]
248 + 2 * compressed_spec_mat[(i*30) + 4] * compressed_spec_mat[(i*30) + 4]
300 + 2 * compressed_spec_mat[i*30+5] * compressed_spec_mat[i*30+5]
249 + 2 * compressed_spec_mat[(i*30) + 5] * compressed_spec_mat[(i*30) + 5]
301 + 2 * compressed_spec_mat[i*30+12] * compressed_spec_mat[i*30+12]
250 + 2 * compressed_spec_mat[(i*30) + 12] * compressed_spec_mat[(i*30) + 12]
302 + 2 * compressed_spec_mat[i*30+13] * compressed_spec_mat[i*30+13];
251 + 2 * compressed_spec_mat[(i*30) + 13] * compressed_spec_mat[(i*30) + 13];
303 }
252 }
304 aux = PSDB*PSDB;
253 aux = PSDB*PSDB;
305 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
254 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
306 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
255 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
307 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
256 LFR_BP1[(i*9) + 6] = LFR_BP1[(i*9) + 6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
308 //=======================================================================================
257 //=======================================================================================
309 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
258 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
310 sx_re = compressed_spec_mat[i*30+20] * k34_sx_re
259 sx_re = compressed_spec_mat[(i*30) + 20] * K34_sx_re
311 + compressed_spec_mat[i*30+6] * k14_sx_re
260 + compressed_spec_mat[(i*30) + 6] * K14_sx_re
312 + compressed_spec_mat[i*30+8] * k15_sx_re
261 + compressed_spec_mat[(i*30) + 8] * K15_sx_re
313 + compressed_spec_mat[i*30+14] * k24_sx_re
262 + compressed_spec_mat[(i*30) + 14] * K24_sx_re
314 + compressed_spec_mat[i*30+16] * k25_sx_re
263 + compressed_spec_mat[(i*30) + 16] * K25_sx_re
315 + compressed_spec_mat[i*30+22] * k35_sx_re;
264 + compressed_spec_mat[(i*30) + 22] * K35_sx_re;
316 sx_im = compressed_spec_mat[i*30+21] * k34_sx_im
265 sx_im = compressed_spec_mat[(i*30) + 21] * K34_sx_im
317 + compressed_spec_mat[i*30+7] * k14_sx_im
266 + compressed_spec_mat[(i*30) + 7] * K14_sx_im
318 + compressed_spec_mat[i*30+9] * k15_sx_im
267 + compressed_spec_mat[(i*30) + 9] * K15_sx_im
319 + compressed_spec_mat[i*30+15] * k24_sx_im
268 + compressed_spec_mat[(i*30) + 15] * K24_sx_im
320 + compressed_spec_mat[i*30+17] * k25_sx_im
269 + compressed_spec_mat[(i*30) + 17] * K25_sx_im
321 + compressed_spec_mat[i*30+23] * k35_sx_im;
270 + compressed_spec_mat[(i*30) + 23] * K35_sx_im;
322 LFR_BP1[i*9+7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
271 LFR_BP1[(i*9) + 7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
323 if ( abs(sx_re) > abs(sx_im) )
272 if ( abs(sx_re) > abs(sx_im) ) {
324 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] | (0x80); // extract the sector of sx
273 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] | (0x80); // extract the sector of sx
325 else
274 }
326 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] & (0x7f); // extract the sector of sx
275 else {
276 LFR_BP1[(i*9) + 7] = LFR_BP1[(i*9) + 1] & (0x7f); // extract the sector of sx
277 }
327 //======================================================================
278 //======================================================================
328 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
279 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
329 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
280 ny = sin(Alpha_M)*NVEC_V1 + cos(Alpha_M)*NVEC_V2;
330 nz = NVEC_V0;
281 nz = NVEC_V0;
331 bx_bx_star = cos(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+10] // re S22
282 bx_bx_star = cos(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+10] // re S22
332 + sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+18] // re S33
283 + sin(Alpha_M) * sin(Alpha_M) * compressed_spec_mat[i*30+18] // re S33
333 - 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+12]; // re S23
284 - 2 * sin(Alpha_M) * cos(Alpha_M) * compressed_spec_mat[i*30+12]; // re S23
334 nebx_re = ny * (compressed_spec_mat[i*30+14] * k24_ny_re
285 nebx_re = ny * (compressed_spec_mat[(i*30) + 14] * K24_ny_re
335 +compressed_spec_mat[i*30+16] * k25_ny_re
286 +compressed_spec_mat[(i*30) + 16] * K25_ny_re
336 +compressed_spec_mat[i*30+20] * k34_ny_re
287 +compressed_spec_mat[(i*30) + 20] * K34_ny_re
337 +compressed_spec_mat[i*30+22] * k35_ny_re)
288 +compressed_spec_mat[(i*30) + 22] * K35_ny_re)
338 + nz * (compressed_spec_mat[i*30+14] * k24_nz_re
289 + nz * (compressed_spec_mat[(i*30) + 14] * K24_nz_re
339 +compressed_spec_mat[i*30+16] * k25_nz_re
290 +compressed_spec_mat[(i*30) + 16] * K25_nz_re
340 +compressed_spec_mat[i*30+20] * k34_nz_re
291 +compressed_spec_mat[(i*30) + 20] * K34_nz_re
341 +compressed_spec_mat[i*30+22] * k35_nz_re);
292 +compressed_spec_mat[(i*30) + 22] * K35_nz_re);
342 nebx_im = ny * (compressed_spec_mat[i*30+15]*k24_ny_re
293 nebx_im = ny * (compressed_spec_mat[(i*30) + 15]*K24_ny_re
343 +compressed_spec_mat[i*30+17] * k25_ny_re
294 +compressed_spec_mat[(i*30) + 17] * K25_ny_re
344 +compressed_spec_mat[i*30+21] * k34_ny_re
295 +compressed_spec_mat[(i*30) + 21] * K34_ny_re
345 +compressed_spec_mat[i*30+23] * k35_ny_re)
296 +compressed_spec_mat[(i*30) + 23] * K35_ny_re)
346 + nz * (compressed_spec_mat[i*30+15] * k24_nz_im
297 + nz * (compressed_spec_mat[(i*30) + 15] * K24_nz_im
347 +compressed_spec_mat[i*30+17] * k25_nz_im
298 +compressed_spec_mat[(i*30) + 17] * K25_nz_im
348 +compressed_spec_mat[i*30+21] * k34_nz_im
299 +compressed_spec_mat[(i*30) + 21] * K34_nz_im
349 +compressed_spec_mat[i*30+23] * k35_nz_im);
300 +compressed_spec_mat[(i*30) + 23] * K35_nz_im);
350 tmp = nebx_re / bx_bx_star;
301 tmp = nebx_re / bx_bx_star;
351 LFR_BP1[i*9+8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
302 LFR_BP1[(i*9) + 8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
352 if ( abs(nebx_re) > abs(nebx_im) )
303 if ( abs(nebx_re) > abs(nebx_im) ) {
353 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] | (0x80); // extract the sector of nebx
304 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] | (0x80); // extract the sector of nebx
354 else
305 }
355 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] & (0x7f); // extract the sector of nebx
306 else {
307 LFR_BP1[(i*9) + 8] = LFR_BP1[(i*9) + 8] & (0x7f); // extract the sector of nebx
308 }
356 }
309 }
357
310
358 }
311 }
359
312
360 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
313 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
361 // BP2 autocorrelation
314 // BP2 autocorrelation
362 int i, aux = 0;
315 int i;
316 int aux = 0;
317
363 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
318 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
364 // S12
319 // S12
365 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]);
320 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 10]);
366 compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux;
321 compressed_spec_mat[(i*30) + 2] = compressed_spec_mat[(i*30) + 2] / aux;
367 compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux;
322 compressed_spec_mat[(i*30) + 3] = compressed_spec_mat[(i*30) + 3] / aux;
368 // S13
323 // S13
369 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]);
324 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 18]);
370 compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux;
325 compressed_spec_mat[(i*30) + 4] = compressed_spec_mat[(i*30) + 4] / aux;
371 compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux;
326 compressed_spec_mat[(i*30) + 5] = compressed_spec_mat[(i*30) + 5] / aux;
372 // S23
327 // S23
373 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]);
328 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[(i*30) + 18]);
374 compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux;
329 compressed_spec_mat[(i*30) + 12] = compressed_spec_mat[(i*30) + 12] / aux;
375 compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux;
330 compressed_spec_mat[(i*30) + 13] = compressed_spec_mat[(i*30) + 13] / aux;
376 // S45
331 // S45
377 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]);
332 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[(i*30) + 28]);
378 compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux;
333 compressed_spec_mat[(i*30) + 26] = compressed_spec_mat[(i*30) + 26] / aux;
379 compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux;
334 compressed_spec_mat[(i*30) + 27] = compressed_spec_mat[(i*30) + 27] / aux;
380 // S14
335 // S14
381 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]);
336 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) +24]);
382 compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux;
337 compressed_spec_mat[(i*30) + 6] = compressed_spec_mat[(i*30) + 6] / aux;
383 compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux;
338 compressed_spec_mat[(i*30) + 7] = compressed_spec_mat[(i*30) + 7] / aux;
384 // S15
339 // S15
385 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]);
340 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[(i*30) + 28]);
386 compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux;
341 compressed_spec_mat[(i*30) + 8] = compressed_spec_mat[(i*30) + 8] / aux;
387 compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux;
342 compressed_spec_mat[(i*30) + 9] = compressed_spec_mat[(i*30) + 9] / aux;
388 // S24
343 // S24
389 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]);
344 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 24]);
390 compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux;
345 compressed_spec_mat[(i*30) + 14] = compressed_spec_mat[(i*30) + 14] / aux;
391 compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux;
346 compressed_spec_mat[(i*30) + 15] = compressed_spec_mat[(i*30) + 15] / aux;
392 // S25
347 // S25
393 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]);
348 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[(i*30) + 28]);
394 compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux;
349 compressed_spec_mat[(i*30) + 16] = compressed_spec_mat[(i*30) + 16] / aux;
395 compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux;
350 compressed_spec_mat[(i*30) + 17] = compressed_spec_mat[(i*30) + 17] / aux;
396 // S34
351 // S34
397 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]);
352 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 24]);
398 compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux;
353 compressed_spec_mat[(i*30) + 20] = compressed_spec_mat[(i*30) + 20] / aux;
399 compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux;
354 compressed_spec_mat[(i*30) + 21] = compressed_spec_mat[(i*30) + 21] / aux;
400 // S35
355 // S35
401 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]);
356 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[(i*30) + 28]);
402 compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux;
357 compressed_spec_mat[(i*30) + 22] = compressed_spec_mat[(i*30) + 22] / aux;
403 compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux;
358 compressed_spec_mat[(i*30) + 23] = compressed_spec_mat[(i*30) + 23] / aux;
404 }
359 }
405 }
360 }
406
361
@@ -1,16 +1,21
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 *DumbMessages[5] = {"default",
5 "WRONG_LEN_PACKET 1",
5 "timecode_irq_handler",
6 "INCOR_CHECKSUM 2",
6 "waveforms_isr",
7 "ILL_TYPE 3",
7 "",
8 "ILL_SUBTYPE 4",
8 ""
9 "WRONG_APP_DATA 5",
10 "WRONG_CMD_CODE 6",
11 "CCSDS_TM_VALID 7"
12 };
9 };
13
10
11 unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
12 unsigned char currentTC_COMPUTED_CRC[2];
13 unsigned int currentTC_LEN_RCV_AsUnsignedInt;
14 unsigned int currentTM_length;
15 unsigned char currentTC_processedFlag;
16
17 unsigned int lookUpTableForCRC[256];
18
14 //**********************
19 //**********************
15 // GENERAL USE FUNCTIONS
20 // GENERAL USE FUNCTIONS
16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
21 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
@@ -18,20 +23,38 unsigned int Crc_opt( unsigned char D, u
18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
23 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
19 }
24 }
20
25
21 void initLookUpTableForCRC()
26 void initLookUpTableForCRC( void )
22 {
27 {
23 unsigned int i, tmp;
28 unsigned int i;
29 unsigned int tmp;
30
24 for (i=0; i<256; i++)
31 for (i=0; i<256; i++)
25 {
32 {
26 tmp = 0;
33 tmp = 0;
27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
34 if((i & 1) != 0) {
28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
35 tmp = tmp ^ 0x1021;
29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
36 }
30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
37 if((i & 2) != 0) {
31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
38 tmp = tmp ^ 0x2042;
32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
39 }
33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
40 if((i & 4) != 0) {
34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
41 tmp = tmp ^ 0x4084;
42 }
43 if((i & 8) != 0) {
44 tmp = tmp ^ 0x8108;
45 }
46 if((i & 16) != 0) {
47 tmp = tmp ^ 0x1231;
48 }
49 if((i & 32) != 0) {
50 tmp = tmp ^ 0x2462;
51 }
52 if((i & 64) != 0) {
53 tmp = tmp ^ 0x48c4;
54 }
55 if((i & 128) != 0) {
56 tmp = tmp ^ 0x9188;
57 }
35 lookUpTableForCRC[i] = tmp;
58 lookUpTableForCRC[i] = tmp;
36 }
59 }
37 }
60 }
@@ -52,6 +75,7 void GetCRCAsTwoBytes(unsigned char* dat
52 // ACCEPTANCE FUNCTIONS
75 // ACCEPTANCE FUNCTIONS
53 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
76 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
54 {
77 {
78 int ret = 0;
55 rtems_status_code status;
79 rtems_status_code status;
56 spw_ioctl_pkt_send spw_ioctl_send;
80 spw_ioctl_pkt_send spw_ioctl_send;
57 TMHeader_t TM_header;
81 TMHeader_t TM_header;
@@ -78,89 +102,166 int TC_checker(ccsdsTelecommandPacket_t
78 }
102 }
79 else { // send valid TC to the action launcher
103 else { // send valid TC to the action launcher
80 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
104 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
81 return -1;
105 ret = -1;
82 }
106 }
83 return -1;
107 return ret;
84 }
108 }
85
109
86 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
110 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
87 {
111 {
112 unsigned char ret = 0;
88 unsigned char pid = 0;
113 unsigned char pid = 0;
89 unsigned char category = 0;
114 unsigned char category = 0;
90 unsigned int length = 0;
115 unsigned int length = 0;
91 unsigned char packetType = 0;
116 unsigned char packetType = 0;
92 unsigned char packetSubtype = 0;
117 unsigned char packetSubtype = 0;
93 unsigned char * CCSDSContent;
118 unsigned char * CCSDSContent = NULL;
94
119
95 // APID check *** APID on 2 bytes
120 // APID check *** APID on 2 bytes
96 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
121 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
97 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
122 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
98 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
123 length = (TMPacket->packetLength[0] * 256) + TMPacket->packetLength[1];
99 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
100
101 // packet length check
102 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
103 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
104 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
105
106 packetType = TMPacket->dataFieldHeader[1];
124 packetType = TMPacket->dataFieldHeader[1];
107 packetSubtype = TMPacket->dataFieldHeader[2];
125 packetSubtype = TMPacket->dataFieldHeader[2];
108 // service type, subtype and packet length check
126
109 if (packetType == 181){
127 if (pid!=CCSDS_PROCESS_ID) {
128 ret = ILLEGAL_APID;
129 }
130 else if (category!=CCSDS_PACKET_CATEGORY) {
131 ret = ILLEGAL_APID;
132 }
133 else if (length != TC_LEN_RCV ) { // packet length check
134 ret = WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
135 }
136 else if (length >= CCSDS_TC_PKT_MAX_SIZE) {
137 ret = WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
138 }
139 else if (packetType == TC_TYPE_GEN){ // service type, subtype and packet length check
110 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
140 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
111 case 3:
141 case TC_SUBTYPE_RESET:
112 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
142 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
113 break;
143 ret = WRONG_LEN_PACKET;
114 case 20:
144 }
115 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
145 else {
146 ret = CCSDS_TM_VALID;
147 }
116 break;
148 break;
117 case 21:
149 case TC_SUBTYPE_LOAD_COMM:
118 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
150 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
151 ret = WRONG_LEN_PACKET;
152 }
153 else {
154 ret = CCSDS_TM_VALID;
155 }
119 break;
156 break;
120 case 24:
157 case TC_SUBTYPE_LOAD_NORM:
121 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
158 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
159 ret = WRONG_LEN_PACKET;
160 }
161 else {
162 ret = CCSDS_TM_VALID;
163 }
122 break;
164 break;
123 case 27:
165 case TC_SUBTYPE_LOAD_BURST:
124 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
166 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
167 ret = WRONG_LEN_PACKET;
168 }
169 else {
170 ret = CCSDS_TM_VALID;
171 }
125 break;
172 break;
126 case 28:
173 case TC_SUBTYPE_LOAD_SBM1:
127 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
174 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
175 ret = WRONG_LEN_PACKET;
176 }
177 else {
178 ret = CCSDS_TM_VALID;
179 }
128 break;
180 break;
129 case 30:
181 case TC_SUBTYPE_LOAD_SBM2:
130 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
182 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
183 ret = WRONG_LEN_PACKET;
184 }
185 else {
186 ret = CCSDS_TM_VALID;
187 }
131 break;
188 break;
132 case 40:
189 case TC_SUBTYPE_DUMP:
133 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
190 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
191 ret = WRONG_LEN_PACKET;
192 }
193 else {
194 ret = CCSDS_TM_VALID;
195 }
134 break;
196 break;
135 case 50:
197 case TC_SUBTYPE_ENTER:
136 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
198 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
199 ret = WRONG_LEN_PACKET;
200 }
201 else {
202 ret = CCSDS_TM_VALID;
203 }
204 break;
205 case TC_SUBTYPE_UPDT_INFO:
206 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
207 ret = WRONG_LEN_PACKET;
208 }
209 else {
210 ret = CCSDS_TM_VALID;
211 }
137 break;
212 break;
138 case 60:
213 case TC_SUBTYPE_EN_CAL:
139 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
214 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
215 ret = WRONG_LEN_PACKET;
216 }
217 else {
218 ret = CCSDS_TM_VALID;
219 }
140 break;
220 break;
141 case 61:
221 case TC_SUBTYPE_DIS_CAL:
142 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
222 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
223 ret = WRONG_LEN_PACKET;
224 }
225 else {
226 ret = CCSDS_TM_VALID;
227 }
143 break;
228 break;
144 default:
229 default:
145 return ILL_SUBTYPE;
230 ret = ILL_SUBTYPE;
146 break;
231 break;
147 }
232 }
148 }
233 }
149 else if (packetType == 9){
234 else if (packetType == TC_TYPE_TIME){
150 if (packetSubtype!=129) return ILL_SUBTYPE;
235 if (packetSubtype!=TC_SUBTYPE_UPDT_TIME) {
151 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
236 ret = ILL_SUBTYPE;
237 }
238 else if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
239 ret = WRONG_LEN_PACKET;
152 }
240 }
153 else return ILL_TYPE;
241 else {
242 ret = CCSDS_TM_VALID;
243 }
244 }
245 else {
246 ret = ILL_TYPE;
247 }
154
248
155 // source ID check // Source ID not documented in the ICD
249 // source ID check // Source ID not documented in the ICD
156
250
157 // packet error control, CRC check
251 // packet error control, CRC check
158 CCSDSContent = (unsigned char*) TMPacket->packetID;
252 CCSDSContent = (unsigned char*) TMPacket->packetID;
159 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
253 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
160 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
254 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
161 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
255 ret = INCOR_CHECKSUM;
256 }
257 else if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
258 ret = INCOR_CHECKSUM;
259 }
260 else {
261 ret = CCSDS_TM_VALID;
262 }
162
263
163 return CCSDS_TM_VALID;
264 return ret;
164 }
265 }
165
266
166 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
267 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
@@ -281,7 +382,7 unsigned char TM_build_header_bis( enum
281 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
382 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
282 {
383 {
283 unsigned int packetLength;
384 unsigned int packetLength;
284 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
385 packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1];
285 switch (SID){
386 switch (SID){
286 case (SID_NOT_EXE):
387 case (SID_NOT_EXE):
287 break;
388 break;
@@ -321,13 +422,15 unsigned char TM_build_data(ccsdsTelecom
321 return 1;
422 return 1;
322 }
423 }
323
424
324 int create_message_queue()
425 int create_message_queue( void )
325 {
426 {
326 rtems_status_code status;
427 rtems_status_code status;
327 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
428 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
328 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
429 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
329 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
430 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
330 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
431 if (status!=RTEMS_SUCCESSFUL) {
432 PRINTF("in create_message_queue *** error creating message queue\n")
433 }
331
434
332 return 0;
435 return 0;
333 }
436 }
@@ -351,16 +454,18 rtems_task recv_task( rtems_task_argumen
351 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
454 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
352 if (len == -1){ // error during the read call
455 if (len == -1){ // error during the read call
353 PRINTF("In RECV *** last read call returned -1\n")
456 PRINTF("In RECV *** last read call returned -1\n")
354 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
457 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL) {
355 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
458 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
356 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
459 }
460 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL) {
357 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
461 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
358 }
462 }
463 }
359 else {
464 else {
360 PRINTF1("Got pck of length %d\n", len+1)
465 PRINTF1("Got pck of length %d\n", len+1)
361 currentTC_LEN_RCV[0] = 0x00;
466 currentTC_LEN_RCV[0] = 0x00;
362 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
467 currentTC_LEN_RCV[1] = (unsigned char) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // build the corresponding packet size field
363 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
468 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
364 // CHECK THE TC AND BUILD THE APPROPRIATE TM
469 // CHECK THE TC AND BUILD THE APPROPRIATE TM
365 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
470 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
366 if (data_length!=-1)
471 if (data_length!=-1)
@@ -450,17 +555,26 rtems_task actn_task( rtems_task_argumen
450
555
451 rtems_task dumb_task( rtems_task_argument unused )
556 rtems_task dumb_task( rtems_task_argument unused )
452 {
557 {
453 unsigned int coarse_time;
558 unsigned int coarse_time = 0;
454 unsigned int fine_time;
559 unsigned int fine_time = 0;
560 unsigned int indice = 0;
561 unsigned int shiftedIndice = 0;
455 rtems_event_set event_out;
562 rtems_event_set event_out;
456
563
457 PRINTF("in DUMB *** \n")
564 PRINTF("in DUMB *** \n")
458
565
459 while(1){
566 while(1){
460 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
567 rtems_event_receive(RTEMS_EVENT_1, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
568 indice = 0;
569 shiftedIndice = (unsigned int) event_out;
570 while(!(shiftedIndice & 0x0001))
571 {
572 shiftedIndice = shiftedIndice >> 1;
573 indice++;
574 }
461 coarse_time = time_management_regs->coarse_time;
575 coarse_time = time_management_regs->coarse_time;
462 fine_time = time_management_regs->fine_time;
576 fine_time = time_management_regs->fine_time;
463 printf("in DUMB *** coarse time = %x, fine time = %x\n", coarse_time, fine_time);
577 printf("in DUMB *** time = coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[indice]);
464 }
578 }
465 }
579 }
466
580
@@ -484,8 +598,9 int action_default(ccsdsTelecommandPacke
484 packet.data[7] = TC->dataFieldHeader[2]; // subtype
598 packet.data[7] = TC->dataFieldHeader[2]; // subtype
485
599
486 // SEND DATA
600 // SEND DATA
487 if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1)
601 if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1) {
488 PRINTF("ERR *** in action_default *** send TM packet\n");
602 PRINTF("ERR *** in action_default *** send TM packet\n");
603 }
489
604
490 return 0;
605 return 0;
491 }
606 }
@@ -499,10 +614,20 int action_enter(ccsdsTelecommandPacket_
499 case(LFR_MODE_STANDBY):
614 case(LFR_MODE_STANDBY):
500 LEON_Mask_interrupt( IRQ_WF );
615 LEON_Mask_interrupt( IRQ_WF );
501 LEON_Mask_interrupt( IRQ_SM );
616 LEON_Mask_interrupt( IRQ_SM );
617 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER );
618 waveform_picker_regs->burst_enable = 0x00;
502 break;
619 break;
503 case(LFR_MODE_NORMAL):
620 case(LFR_MODE_NORMAL):
621
622 #ifdef GSA
504 LEON_Unmask_interrupt( IRQ_WF );
623 LEON_Unmask_interrupt( IRQ_WF );
505 LEON_Unmask_interrupt( IRQ_SM );
624 #else
625 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
626 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
627 waveform_picker_regs->burst_enable = 0x07;
628 waveform_picker_regs->status = 0x00;
629 #endif
630
506 break;
631 break;
507 case(LFR_MODE_BURST):
632 case(LFR_MODE_BURST):
508 break;
633 break;
@@ -510,15 +635,17 int action_enter(ccsdsTelecommandPacket_
510 break;
635 break;
511 case(LFR_MODE_SBM2):
636 case(LFR_MODE_SBM2):
512 break;
637 break;
638 default:
639 break;
513 }
640 }
514 return 0;
641 return 0;
515 }
642 }
516
643
517 int action_load_norm(ccsdsTelecommandPacket_t *TC)
644 int action_load_norm(ccsdsTelecommandPacket_t *TC)
518 {
645 {
519 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
646 param_norm.sy_lfr_n_swf_l = (TC->dataAndCRC[0] * 256) + TC->dataAndCRC[1];
520 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
647 param_norm.sy_lfr_n_swf_p = (TC->dataAndCRC[2] * 256) + TC->dataAndCRC[3];
521 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
648 param_norm.sy_lfr_n_asm_p = (TC->dataAndCRC[4] * 256) + TC->dataAndCRC[5];
522 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
649 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
523 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
650 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
524 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
651 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
@@ -567,15 +694,17 int send_tm_lfr_tc_exe_success(ccsdsTele
567 // Interrupt Service Routines
694 // Interrupt Service Routines
568 rtems_isr commutation_isr1( rtems_vector_number vector )
695 rtems_isr commutation_isr1( rtems_vector_number vector )
569 {
696 {
570 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
697 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
571 printf("In commutation_isr1 *** Error sending event to DUMB\n");
698 printf("In commutation_isr1 *** Error sending event to DUMB\n");
572 }
699 }
700 }
573
701
574 rtems_isr commutation_isr2( rtems_vector_number vector )
702 rtems_isr commutation_isr2( rtems_vector_number vector )
575 {
703 {
576 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
704 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
577 printf("In commutation_isr2 *** Error sending event to DUMB\n");
705 printf("In commutation_isr2 *** Error sending event to DUMB\n");
578 }
706 }
707 }
579
708
580
709
581
710
@@ -2,18 +2,32
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 ( (waveform_picker_regs->burst_enable & 0x7) == 0x0 ){// if no channel is enable
6 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ) != RTEMS_SUCCESSFUL) {
7 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
8 }
9 }
10 else {
11 if ( (waveform_picker_regs->status & 0x7) == 0x7 ){ // f2 f1 and f0 are full
12 waveform_picker_regs->burst_enable = 0x00;
13 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
6 printf("In waveforms_isr *** Error sending event to WFRM\n");
14 printf("In waveforms_isr *** Error sending event to WFRM\n");
7 }
15 }
16 }
17 }
18 }
8
19
9 rtems_task wfrm_task(rtems_task_argument argument)
20 rtems_isr waveforms_simulator_isr( rtems_vector_number vector )
10 {
21 {
11 unsigned int length;
22 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
12 unsigned int i = 0;
23 printf("In waveforms_isr *** Error sending event to WFRM\n");
24 }
25 }
26
27 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
28 {
13 spw_ioctl_pkt_send spw_ioctl_send;
29 spw_ioctl_pkt_send spw_ioctl_send;
14 rtems_event_set event_out;
30 rtems_event_set event_out;
15 gptimer_regs_t *gptimer_regs;
16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
17 ExtendedTMHeader_t header;
31 ExtendedTMHeader_t header;
18
32
19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
33 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
@@ -27,8 +41,8 rtems_task wfrm_task(rtems_task_argument
27 header.packetLength[0] = 0x00;
41 header.packetLength[0] = 0x00;
28 header.packetLength[1] = 0x00;
42 header.packetLength[1] = 0x00;
29 header.dataFieldHeader[0] = 0x10;
43 header.dataFieldHeader[0] = 0x10;
30 header.dataFieldHeader[1] = 0x15; // service type
44 header.dataFieldHeader[1] = TM_TYPE_LFR_SCIENCE; // service type
31 header.dataFieldHeader[2] = 0x03; // service subtype
45 header.dataFieldHeader[2] = TM_SUBTYPE_LFR_SCIENCE; // service subtype
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
46 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
33
47
34 header.auxiliaryHeader[0] = 0x00;
48 header.auxiliaryHeader[0] = 0x00;
@@ -42,135 +56,254 rtems_task wfrm_task(rtems_task_argument
42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
56 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
43 spw_ioctl_send.hdr = (char*) &header;
57 spw_ioctl_send.hdr = (char*) &header;
44
58
59 init_waveforms();
60
45 PRINTF("in WFRM *** \n")
61 PRINTF("in WFRM ***\n")
46
62
47 while(1){
63 while(1){
64
48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
66 PRINTF("in WFRM *** send wfrm\n")
49 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
67 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
50 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
68 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
51 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
69 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
52 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
70 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
53 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
71 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
72 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
55 for (i=0; i<7; i++) // send F0
73
56 {
74 //***************
57 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
75 // send snapshots
58 // BUILD THE DATA
76 // F0
59 if (i==6) {
77 send_waveform( &header, wf_snap_f0, SID_NORM_SWF_F0, &spw_ioctl_send);
60 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
78 // F1
61 length = TM_LEN_SCI_NORM_SWF_8;
79 send_waveform( &header, wf_snap_f1, SID_NORM_SWF_F1, &spw_ioctl_send);
62 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
80 // F2
63 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
81 send_waveform( &header, wf_snap_f2, SID_NORM_SWF_F2, &spw_ioctl_send);
64 }
82
65 else {
83 #ifdef GSA
66 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
67 length = TM_LEN_SCI_NORM_SWF_340;
68 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
69 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
70 }
71 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
72 // BUILD THE HEADER
73 header.packetLength[0] = (unsigned char) (length>>8);
74 header.packetLength[1] = (unsigned char) (length);
75 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
76 // SEND PACKET
77 write_spw(&spw_ioctl_send);
78 }
79 for (i=0; i<7; i++) // send F1
80 {
81 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
82 // BUILD THE DATA
83 if (i==6) {
84 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
85 length = TM_LEN_SCI_NORM_SWF_8;
86 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
87 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
88 }
89 else {
90 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
91 length = TM_LEN_SCI_NORM_SWF_340;
92 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
93 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
94 }
95 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
96 // BUILD THE HEADER
97 header.packetLength[0] = (unsigned char) (length>>8);
98 header.packetLength[1] = (unsigned char) (length);
99 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
100 // SEND PACKET
101 write_spw(&spw_ioctl_send);
102 }
103 for (i=0; i<7; i++) // send F2
104 {
105 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
106 // BUILD THE DATA
107 if (i==6) {
108 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
109 length = TM_LEN_SCI_NORM_SWF_8;
110 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
111 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
112 }
113 else {
114 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
115 length = TM_LEN_SCI_NORM_SWF_340;
116 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
117 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
118 }
119 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
120 // BUILD THE HEADER
121 header.packetLength[0] = (unsigned char) (length>>8);
122 header.packetLength[1] = (unsigned char) (length);
123 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
124 // SEND PACKET
125 write_spw(&spw_ioctl_send);
126 }
127 // irq processed, reset the related register of the timer unit
84 // irq processed, reset the related register of the timer unit
128 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
85 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
86 #else
87 // irq processed, reset the related register of the waveform picker
88 waveform_picker_regs->status = 0x00;
89 waveform_picker_regs->burst_enable = 0x07;
90 #endif
91
129 }
92 }
130 }
93 }
131
94
132 //******************
95 //******************
133 // general functions
96 // general functions
134 void init_waveforms()
97 void init_waveforms( void )
98 {
99 int i = 0;
100 int aux1 = 0;
101 int aux2 = 0;
102 int val1 = 0;
103 int val2 = 0;
104 int val3 = 0;
105 int val4 = 0;
106 int amplitude1 = pow(2, 10);
107 static int delta_phi = 0;
108
109 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
110 {
111 aux1 = (int) (amplitude1 * cos((2*pi*i)/2048 + (delta_phi*pi)/180));
112 aux2 = (int) (amplitude1 * sin((2*pi*i)/2048 + (delta_phi*pi)/180));
113 val1 = build_value(aux1, aux2);
114 val2 = build_value(i, 2*i);
115 val3 = build_value(-aux1, -aux2);
116 val4 = build_value(-i, -2*i);
117 //***
118 // F0
119 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = 0x88887777; //
120 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = 0x22221111; //
121 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0x44443333; //
122
123 //***
124 // F1
125 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = val1;
126 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = val2;
127 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
128
129 //***
130 // F2
131 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET ] = val1;
132 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET ] = val2;
133 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET ] = 0xaaaa0000;
134
135 //***
136 // F3
137 //wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 0 ] = val1;
138 //wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 1 ] = val2;
139 //wf_cont_f3[ (i* NB_WORDS_SWF_BLK) + 2 ] = 0xaaaa0000;
140 }
141
142 delta_phi = delta_phi + 10;
143
144 }
145
146 void init_waveform_header( ExtendedTMHeader_t * header, unsigned int sid )
147 {
148
149 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
150 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
151 header->reserved = 0x00;
152 header->userApplication = CCSDS_USER_APP;
153 header->packetID[0] = 0x0c;
154 header->packetID[1] = 0xcc;
155 header->packetSequenceControl[0] = 0x00;
156 header->packetSequenceControl[1] = 0x00;
157 header->packetLength[0] = 0x00;
158 header->packetLength[1] = 0x00;
159 header->dataFieldHeader[0] = 0x10;
160 header->dataFieldHeader[1] = TM_TYPE_LFR_SCIENCE; // service type
161 header->dataFieldHeader[2] = TM_SUBTYPE_LFR_SCIENCE; // service subtype
162 header->dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
163
164 header->auxiliaryHeader[0] = sid;
165 header->auxiliaryHeader[1] = 0x1f;
166 header->auxiliaryHeader[2] = 0x07; // PKT_CNT
167 header->auxiliaryHeader[3] = 0x00; // PKT_NR
168 header->auxiliaryHeader[4] = 0x00; // BLK_NR MSB
169 header->auxiliaryHeader[5] = 0x00; // BLK_NR LSB
170 }
171
172 void reset_waveforms( void )
135 {
173 {
136 int i = 0;
174 int i = 0;
137
175
138 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
176 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
139 {
177 {
140 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and e1
178 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x10002000;
141 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( 3*i, 4*i ); // e2 and b1
179 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0x20001000;
142 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
180 wf_snap_f0[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x40008000;
143 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
181
144 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
182 //***
145 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
183 // F1
146 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
184 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x1000f000;
147 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
185 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0xf0001000;
148 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
186 wf_snap_f1[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x40008000;
149 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
187
150 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
188 //***
151 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
189 // F2
190 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 0 + TIME_OFFSET] = 0x40008000;
191 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 1 + TIME_OFFSET] = 0x20001000;
192 wf_snap_f2[ (i* NB_WORDS_SWF_BLK) + 2 + TIME_OFFSET] = 0x10002000;
193
194 //***
195 // F3
196 /*wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = build_value( i, i ); // v and 1
197 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = build_value( i, i ); // e2 and b1
198 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = build_value( i, i ); // b2 and b3*/
152 }
199 }
153 }
200 }
154
201
155 int buil_value(int value1, int value0)
202 void send_waveform( ExtendedTMHeader_t *header, volatile int *waveform,
203 unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send)
204 {
205 unsigned int i = 0;
206 unsigned int length = 0;
207 rtems_status_code status;
208
209 for (i=0; i<7; i++) // send waveform
210 {
211 header->auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
212 // BUILD THE DATA
213 if (i==6) {
214 spw_ioctl_send->dlen = 8 * NB_BYTES_SWF_BLK;
215 length = TM_LEN_SCI_NORM_SWF_8;
216 header->auxiliaryHeader[4] = 0x00; // BLK_NR MSB
217 header->auxiliaryHeader[5] = 0x08; // BLK_NR LSB
218 }
219 else {
220 spw_ioctl_send->dlen = 340 * NB_BYTES_SWF_BLK;
221 length = TM_LEN_SCI_NORM_SWF_340;
222 header->auxiliaryHeader[4] = 0x01; // BLK_NR MSB
223 header->auxiliaryHeader[5] = 0x54; // BLK_NR LSB
224 }
225 if (sid == SID_NORM_SWF_F0) {
226 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) + (1 * TIME_OFFSET) ];
227 }
228 else if (sid == SID_NORM_SWF_F1) {
229 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) + (1 * TIME_OFFSET) ];
230 }
231 else if (sid == SID_NORM_SWF_F2) {
232 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) + (0 * TIME_OFFSET) ];
233 }
234 else {
235 spw_ioctl_send->data = (char*) &waveform[ (i * 340 * NB_WORDS_SWF_BLK) ];
236 }
237 // BUILD THE HEADER
238 header->packetLength[0] = (unsigned char) (length>>8);
239 header->packetLength[1] = (unsigned char) (length);
240 header->auxiliaryHeader[0] = sid; // SID
241 // SEND PACKET
242 status = write_spw(spw_ioctl_send);
243 if (status != RTEMS_SUCCESSFUL) {
244 while (true) {
245 if (status != RTEMS_SUCCESSFUL) {
246 status = write_spw(spw_ioctl_send);
247 //PRINTF1("%d", i)
248 sched_yield();
249 }
250 else {
251 //PRINTF("\n")
252 break;
253 }
254 }
255 }
256 }
257 }
258
259 int build_value(int value1, int value0)
156 {
260 {
157 int aux = 0;
261 int aux = 0;
158 int aux1 = 0;
262 int aux1 = 0;
159 int aux0 = 0;
263 int aux0 = 0;
264 int value1_aux = 0;
265 int value0_aux = 0;
266
267 value1_aux = value1;
268 value0_aux = value0;
269
160 //******
270 //******
161 // B3 B2
271 // B3 B2
162 aux1 = ( (int) ( (char) (value1 >> 8) ) << 8 )
272 if (value1_aux > 8191) value1_aux = 8191;
163 + ( (int) ( (char) (value1 ) ) );
273 if (value1_aux < -8192) value1_aux = -8192;
274 aux1 = ( (int) ( ( (unsigned char) (value1_aux / 256 ) ) << 8 ) )
275 + ( (int) ( (unsigned char) (value1_aux ) ) );
164
276
165 //******
277 //******
166 // B1 B0
278 // B1 B0
167 aux0 = ( (int) ( (char) (value0 >> 8) ) << 8 )
279 if (value0_aux > 8191) value0_aux = 8191;
168 + ( (int) ( (char) (value0 ) ) );
280 if (value0_aux < -8192) value0_aux = -8192;
281 aux0 = ( (int) ( ( (unsigned char) (value0_aux / 256) ) << 8 ) )
282 + ( (int) ( (unsigned char) (value0_aux ) ) );
169
283
170 aux = (aux1 << 16) + aux0;
284 aux = (aux1 << 16) + aux0;
171
285
172 return aux;
286 return aux;
173 }
287 }
174
288
289 void init_waveform_picker_regs()
290 { // 1 1 0 0 0 BW = 0 => BIAS_WORKS
291 waveform_picker_regs->data_shaping = 0x18; // R1 R0 SP1 SP0 BW
292 waveform_picker_regs->burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0
293 waveform_picker_regs->addr_data_f0 = (int) (wf_snap_f0); //
294 waveform_picker_regs->addr_data_f1 = (int) (wf_snap_f1); //
295 waveform_picker_regs->addr_data_f2 = (int) (wf_snap_f2); //
296 waveform_picker_regs->addr_data_f3 = (int) (wf_cont_f3); //
297 waveform_picker_regs->status = 0x00; //
298 waveform_picker_regs->delta_snapshot = 0x5; // max 2 bytes
299 waveform_picker_regs->delta_f2_f1 = 0xffff; // max 4 bytes
300 waveform_picker_regs->delta_f2_f0 = 0x17c00; // max 5 bytes
301 waveform_picker_regs->nb_burst_available = 0x180; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
302 waveform_picker_regs->nb_snapshot_param = 0x7ff; // max 3 octets, 2048 - 1
303 //waveform_picker_regs->delta_snapshot = 0x2; // max 2 bytes, = period / 2
304 //waveform_picker_regs->delta_f2_f1 = 0x2d00; // max 4 bytes
305 //waveform_picker_regs->delta_f2_f0 = 0x2f80; // max 5 bytes
306 //waveform_picker_regs->nb_burst_available = 0x30; // max 3 bytes, size of the buffer in burst (1 burst = 16 x 4 octets)
307 //waveform_picker_regs->nb_snapshot_param = 0xff; // max 3 octets, 256 - 1
308 }
175
309
176
General Comments 0
You need to be logged in to leave comments. Login now