##// END OF EJS Templates
automatic reconnexion of the spacewire link...
paul@pc-solar1.lab-lpp.local -
r17:3a73d9962d4a default
parent child
Show More
@@ -1,46 +1,46
1 1 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2 2 <CodeBlocks_layout_file>
3 3 <ActiveTarget name="Debug" />
4 4 <File name="../header/ccsds_types.h" open="0" top="0" tabpos="3">
5 <Cursor position="384" topLine="87" />
5 <Cursor position="4971" topLine="100" />
6 6 </File>
7 7 <File name="../header/fsw_init.h" open="0" top="0" tabpos="6">
8 <Cursor position="1133" topLine="22" />
8 <Cursor position="597" topLine="0" />
9 9 </File>
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="0">
11 <Cursor position="545" topLine="0" />
10 <File name="../header/fsw_misc.h" open="0" top="0" tabpos="3">
11 <Cursor position="279" topLine="0" />
12 12 </File>
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="2">
14 <Cursor position="1157" topLine="0" />
13 <File name="../header/fsw_params.h" open="0" top="0" tabpos="3">
14 <Cursor position="1416" topLine="31" />
15 15 </File>
16 16 <File name="../header/fsw_processing.h" open="0" top="0" tabpos="0">
17 <Cursor position="628" topLine="7" />
17 <Cursor position="1216" topLine="5" />
18 18 </File>
19 19 <File name="../header/grlib_regs.h" open="0" top="0" tabpos="4">
20 <Cursor position="1153" topLine="16" />
20 <Cursor position="444" topLine="0" />
21 21 </File>
22 22 <File name="../header/tc_handler.h" open="0" top="0" tabpos="4">
23 23 <Cursor position="1380" topLine="35" />
24 24 </File>
25 25 <File name="../header/wf_handler.h" open="0" top="0" tabpos="0">
26 <Cursor position="341" topLine="0" />
26 <Cursor position="316" topLine="0" />
27 27 </File>
28 <File name="../src/fsw_globals.c" open="0" top="0" tabpos="5">
29 <Cursor position="184" topLine="0" />
28 <File name="../src/fsw_globals.c" open="1" top="0" tabpos="3">
29 <Cursor position="1246" topLine="6" />
30 30 </File>
31 <File name="../src/fsw_init.c" open="1" top="0" tabpos="1">
32 <Cursor position="12072" topLine="91" />
31 <File name="../src/fsw_init.c" open="1" top="1" tabpos="1">
32 <Cursor position="2317" topLine="59" />
33 33 </File>
34 <File name="../src/fsw_misc.c" open="1" top="1" tabpos="2">
35 <Cursor position="4309" topLine="44" />
34 <File name="../src/fsw_misc.c" open="0" top="0" tabpos="2">
35 <Cursor position="6076" topLine="0" />
36 36 </File>
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="0">
38 <Cursor position="20570" topLine="67" />
37 <File name="../src/fsw_processing.c" open="0" top="0" tabpos="4">
38 <Cursor position="19048" topLine="64" />
39 39 </File>
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="2">
41 <Cursor position="15292" topLine="0" />
40 <File name="../src/tc_handler.c" open="0" top="0" tabpos="5">
41 <Cursor position="536" topLine="0" />
42 42 </File>
43 <File name="../src/wf_handler.c" open="0" top="0" tabpos="4">
44 <Cursor position="2540" topLine="42" />
43 <File name="../src/wf_handler.c" open="1" top="0" tabpos="2">
44 <Cursor position="5858" topLine="70" />
45 45 </File>
46 46 </CodeBlocks_layout_file>
1 NO CONTENT: modified file, binary diff hidden
@@ -1,142 +1,199
1 1 #ifndef CCSDS_H_INCLUDED
2 2 #define CCSDS_H_INCLUDED
3 3
4 4 #define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
5 5 #define CCSDS_TM_PKT_MAX_SIZE 4412
6 6 #define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4
7 7 #define CCSDS_TC_PKT_MAX_SIZE 50 // size of the TC_LFR_UPDATE_INFO packet
8 8 #define CCSDS_TC_TM_PACKET_OFFSET 7
9 9 #define CCSDS_PROCESS_ID 76
10 10 #define CCSDS_PACKET_CATEGORY 12
11 11 #define CCSDS_NODE_ADDRESS 0xfe
12 //
13 #define CCSDS_DESTINATION_ID_GROUND 0x00
12 14 #define CCSDS_DESTINATION_ID 0x01
15 #define CCSDS_DESTINATION_ID_DPU 0x01
16 //
13 17 #define CCSDS_PROTOCOLE_ID 0x02
14 18 #define CCSDS_USER_APP 0x00
15 19
16 20 #define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24
17 21 #define SIZE_TM_LFR_TC_EXE_CORRUPTED 32
18 22
19 23 #define ILLEGAL_APID 0
20 24 #define WRONG_LEN_PACKET 1
21 25 #define INCOR_CHECKSUM 2
22 26 #define ILL_TYPE 3
23 27 #define ILL_SUBTYPE 4
24 28 #define WRONG_APP_DATA 5
25 29 #define WRONG_CMD_CODE 6
26 30 #define CCSDS_TM_VALID 7
27 31 //
28 32 #define TC_NOT_EXE 40000
29 33 #define WRONG_SRC_ID 40001
30 34 #define FUNCT_NOT_IMPL 40002
31 35 #define FAIL_DETECTED 40003
32 36 #define NOT_ALLOWED 40004
33 37 #define CORRUPTED 40005
34 38
35 39 // // TC SUBTYPES
36 40 #define TC_SUBTYPE_RESET 3
37 41 #define TC_SUBTYPE_LOAD_COMM 20
38 42 #define TC_SUBTYPE_LOAD_NORM 21
39 43 #define TC_SUBTYPE_LOAD_BURST 24
40 44 #define TC_SUBTYPE_LOAD_SBM1 27
41 45 #define TC_SUBTYPE_LOAD_SBM2 28
42 46 #define TC_SUBTYPE_DUMP 30
43 47 #define TC_SUBTYPE_ENTER 40
44 48 #define TC_SUBTYPE_UPDT_INFO 50
45 49 #define TC_SUBTYPE_EN_CAL 60
46 50 #define TC_SUBTYPE_DIS_CAL 61
47 51 #define TC_SUBTYPE_UPDT_TIME 129
48 52
49 53 #define SID_DEFAULT 0
54 #define SID_HK 1
50 55 #define SID_EXE_INC 5
51 56 #define SID_NOT_EXE 40000
52 57 #define SID_NOT_IMP 40002
53 58 #define SID_EXE_ERR 40003
54 59 #define SID_EXE_CORR 40005
55 60
56 61 #define SID_NORM_SWF_F0 3
57 62 #define SID_NORM_SWF_F1 4
58 63 #define SID_NORM_SWF_F2 5
59 64 #define SID_NORM_CWF_F3 1
60 65 #define SID_BURST_CWF_F2 2
61 66 #define SID_SBM1_CWF_F1 24
62 67 #define SID_SBM2_CWF_F2 25
63 68 #define SID_NORM_ASM_F0 11
64 69 #define SID_NORM_ASM_F1 12
65 70 #define SID_NORM_ASM_F2 13
66 71 #define SID_NORM_BP1_F0 14
67 72 #define SID_NORM_BP1_F1 15
68 73 #define SID_NORM_BP1_F2 16
69 74 #define SID_NORM_BP2_F0 19
70 75 #define SID_NORM_BP2_F1 20
71 76 #define SID_NORM_BP2_F2 21
72 77 #define SID_BURST_BP1_F0 17
73 78 #define SID_BURST_BP2_F0 22
74 79 #define SID_BURST_BP1_F1 18
75 80 #define SID_BURST_BP2_F1 23
76 81 #define SID_SBM1_BP1_F0 28
77 82 #define SID_SBM1_BP2_F0 31
78 83 #define SID_SBM2_BP1_F0 29
79 84 #define SID_SBM2_BP2_F0 32
80 85 #define SID_SBM1_BP1_F1 30
81 86 #define SID_SBM1_BP2_F1 33
82 87
88 // LENGTH (BYTES)
89 #define LENGTH_TM_LFR_HK 126
90 #define LENGTH_TM_LFR_TC_EXE_MAX 32
91 #define LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX 4102
92 //
83 93 #define TM_LEN_EXE 20 - CCSDS_TC_TM_PACKET_OFFSET
84 94 #define TM_LEN_NOT_EXE 26 - CCSDS_TC_TM_PACKET_OFFSET
85 95 #define TM_LEN_NOT_IMP 24 - CCSDS_TC_TM_PACKET_OFFSET
86 96 #define TM_LEN_EXE_ERR 24 - CCSDS_TC_TM_PACKET_OFFSET
87 97 #define TM_LEN_EXE_CORR 32 - CCSDS_TC_TM_PACKET_OFFSET
88 98 #define TM_HEADER_LEN 16
99
100 #define LEN_TM_LFR_HK 126 + 4
101 #define LEN_TM_LFR_TC_EXE_NOT_IMP 24 +4
102
89 103 #define TM_LEN_SCI_NORM_SWF_340 340 * 12 + 6 + 10 - 1
90 104 #define TM_LEN_SCI_NORM_SWF_8 8 * 12 + 6 + 10 - 1
91 105
92 106 enum TM_TYPE{
93 107 TM_LFR_TC_EXE_OK,
94 108 TM_LFR_TC_EXE_ERR,
95 109 TM_LFR_HK,
96 110 TM_LFR_SCI,
97 111 TM_LFR_SCI_SBM,
98 112 TM_LFR_PAR_DUMP
99 113 };
100 114
101 115 struct TMHeader_str
102 116 {
103 117 volatile unsigned char targetLogicalAddress;
104 118 volatile unsigned char protocolIdentifier;
105 119 volatile unsigned char reserved;
106 120 volatile unsigned char userApplication;
107 121 volatile unsigned char packetID[2];
108 122 volatile unsigned char packetSequenceControl[2];
109 123 volatile unsigned char packetLength[2];
110 124 volatile unsigned char dataFieldHeader[10];
111 125 };
112 126 typedef struct TMHeader_str TMHeader_t;
113 127
128 struct Packet_TM_LFR_HK_str
129 {
130 volatile unsigned char targetLogicalAddress;
131 volatile unsigned char protocolIdentifier;
132 volatile unsigned char reserved;
133 volatile unsigned char userApplication;
134 volatile unsigned char packetID[2];
135 volatile unsigned char packetSequenceControl[2];
136 volatile unsigned char packetLength[2];
137 volatile unsigned char dataFieldHeader[10];
138 volatile unsigned char data[LENGTH_TM_LFR_HK - 10 + 1];
139 };
140 typedef struct Packet_TM_LFR_HK_str Packet_TM_LFR_HK_t;
141
142 struct Packet_TM_LFR_TC_EXE_str
143 {
144 volatile unsigned char targetLogicalAddress;
145 volatile unsigned char protocolIdentifier;
146 volatile unsigned char reserved;
147 volatile unsigned char userApplication;
148 volatile unsigned char packetID[2];
149 volatile unsigned char packetSequenceControl[2];
150 volatile unsigned char packetLength[2];
151 volatile unsigned char dataFieldHeader[10];
152 volatile unsigned char data[LENGTH_TM_LFR_TC_EXE_MAX - 10 + 1];
153 };
154 typedef struct Packet_TM_LFR_TC_EXE_str Packet_TM_LFR_TC_EXE_t;
155
156 struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str
157 {
158 volatile unsigned char targetLogicalAddress;
159 volatile unsigned char protocolIdentifier;
160 volatile unsigned char reserved;
161 volatile unsigned char userApplication;
162 volatile unsigned char packetID[2];
163 volatile unsigned char packetSequenceControl[2];
164 volatile unsigned char packetLength[2];
165 volatile unsigned char dataFieldHeader[10];
166 volatile unsigned char auxiliaryHeader[6];
167 volatile unsigned char data[LENGTH_TM_LFR_SCIENCE_NORMAL_WF_MAX - 10 + 1];
168 };
169 typedef struct Packet_TM_LFR_SCIENCE_NORMAL_WF_str Packet_TM_LFR_SCIENCE_NORMAL_WF_t;
170
114 171 struct ExtendedTMHeader_str
115 172 {
116 173 volatile unsigned char targetLogicalAddress;
117 174 volatile unsigned char protocolIdentifier;
118 175 volatile unsigned char reserved;
119 176 volatile unsigned char userApplication;
120 177 volatile unsigned char packetID[2];
121 178 volatile unsigned char packetSequenceControl[2];
122 179 volatile unsigned char packetLength[2];
123 180 volatile unsigned char dataFieldHeader[10];
124 181 volatile unsigned char auxiliaryHeader[6];
125 182 };
126 183 typedef struct ExtendedTMHeader_str ExtendedTMHeader_t;
127 184
128 185 struct ccsdsTelecommandPacket_str
129 186 {
130 187 //unsigned char targetLogicalAddress; // removed by the grspw module
131 188 volatile unsigned char protocolIdentifier;
132 189 volatile unsigned char reserved;
133 190 volatile unsigned char userApplication;
134 191 volatile unsigned char packetID[2];
135 192 volatile unsigned char packetSequenceControl[2];
136 193 volatile unsigned char packetLength[2];
137 194 volatile unsigned char dataFieldHeader[4];
138 195 volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
139 196 };
140 197 typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t;
141 198
142 199 #endif // CCSDS_H_INCLUDED
@@ -1,59 +1,60
1 1 #ifndef FSW_RTEMS_H_INCLUDED
2 2 #define FSW_RTEMS_H_INCLUDED
3 3
4 4 #include <errno.h>
5 5 #include <fcntl.h>
6 6 #include <stdio.h>
7 7 #include <stdlib.h>
8 8
9 9 #include <grspw.h>
10 10 #include <apbuart.h>
11 11
12 12 #include <fsw_params.h>
13 13 #include <fsw_misc.h>
14 14 #include <fsw_processing.h>
15 15 #include <tc_handler.h>
16 16 #include <wf_handler.h>
17 17 #include <grlib_regs.h>
18 18
19 19 extern int sched_yield();
20 20 extern int errno;
21 21 extern rtems_id Task_id[ ]; /* array of task ids */
22 22 extern rtems_name Task_name[ ]; /* array of task names */
23 23 extern rtems_name misc_name[ ]; /* arry of miscellaneous names for rtems objects */
24 24 extern int fdSPW; // grspw file descriptor
25 25 extern int fdUART; // uart file descriptor
26 26
27 27 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc);
28 28
29 29 // MODE PARAMETERS
30 30 extern struct param_norm_str param_norm;
31 31 extern struct param_burst_str param_burst;
32 32 extern struct param_sbm1_str param_sbm1;
33 33 extern struct param_sbm2_str param_sbm2;
34 34 extern unsigned char param_common[];
35 35
36 36 // RTEMS TASKS
37 37 rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
38 38 rtems_task recv_task(rtems_task_argument argument);
39 39 rtems_task spiq_task(rtems_task_argument argument);
40 40 rtems_task stat_task(rtems_task_argument argument);
41 41 rtems_task wfrm_task(rtems_task_argument argument);
42 int create_names();
42 43 int create_all_tasks();
43 44 int start_all_tasks();
44 45 int create_message_queue();
45 46
46 47 // OTHER functions
47 48 void init_default_mode_parameters();
48 49
49 50 int configure_spw_link();
50 51 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr); // No Port force
51 52 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr); // RMAP Enable
52 53
53 54 extern int rtems_cpu_usage_report();
54 55 extern int rtems_cpu_usage_reset();
55 56 void print_statistics(spw_stats *);
56 57 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send);
57 58 void (*grspw_timecode_callback) (void *pDev, void *regs, int minor, unsigned int tc);
58 59
59 60 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,20 +1,28
1 1 #ifndef FSW_MISC_H_INCLUDED
2 2 #define FSW_MISC_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <stdio.h>
6 6
7 7 #include <fsw_init.h>
8 8 #include <fsw_params.h>
9 9 #include <grlib_regs.h>
10 10 #include <grspw.h>
11 11 #include <ccsds_types.h>
12 12
13 rtems_name HK_name; /* name of the HK rate monotonic */
14 rtems_id HK_id; /* id of the HK rate monotonic period */
15
13 16 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
14 17 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
15 18 void print_statistics(spw_stats *stats);
19
20 // SERIAL LINK
16 21 int send_console_outputs_on_serial_port();
22 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
23
24 // RTEMS TASKS
17 25 rtems_task stat_task(rtems_task_argument argument);
18 26 rtems_task hous_task(rtems_task_argument argument);
19 27
20 28 #endif // FSW_MISC_H_INCLUDED
@@ -1,107 +1,106
1 1 #ifndef FSW_RTEMS_CONFIG_H_INCLUDED
2 2 #define FSW_RTEMS_CONFIG_H_INCLUDED
3 3
4 4 #define GRSPW_DEVICE_NAME "/dev/grspw0"
5 5 #define UART_DEVICE_NAME "/dev/console"
6 6
7 7 //**********
8 8 // LFR MODES
9 9 #define LFR_MODE_STANDBY 0
10 10 #define LFR_MODE_NORMAL 1
11 11 #define LFR_MODE_BURST 2
12 12 #define LFR_MODE_SBM1 3
13 13 #define LFR_MODE_SBM2 4
14 14
15 15 //*****************************
16 16 // APB REGISTERS BASE ADDRESSES
17 17 #define REGS_ADDR_APBUART 0x80000100
18 18 #define REGS_ADDR_GPTIMER 0x80000300
19 19 #define REGS_ADDR_GRSPW 0x80000500
20 20 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600
21 21 #define REGS_ADDR_SPECTRAL_MATRICES 0x80000700
22 22
23 23 #define APBUART_CTRL_REG_MASK_DB 0xfffff7ff
24 #define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400
24 25
25 26 //**********
26 27 // IRQ LINES
27 28 #define IRQ_SM 9
28 29 #define IRQ_SPARC_SM 0x19 // see sparcv8.pdf p.76 for interrupt levels
29 30 #define IRQ_WF 10
30 31 #define IRQ_SPARC_WF 0x1a // see sparcv8.pdf p.76 for interrupt levels
31 32 #define IRQ_TIME1 12
32 33 #define IRQ_SPARC_TIME1 0x1c // see sparcv8.pdf p.76 for interrupt levels
33 34 #define IRQ_TIME2 13
34 35 #define IRQ_SPARC_TIME2 0x1d // see sparcv8.pdf p.76 for interrupt levels
35 36
36 37 //*****
37 38 // TIME
38 39 #define CLKDIV_SM_SIMULATOR 9999
39 40 #define CLKDIV_WF_SIMULATOR 9999999
40 41 #define TIMER_SM_SIMULATOR 1
41 42 #define TIMER_WF_SIMULATOR 2
42 43 #define HK_PERIOD 100 // 100 * 10ms => 1sec
43 44
44 45 //******
45 46 // RTEMS
46 47 #define TASKID_RECV 1
47 48 #define TASKID_ACTN 2
48 49 #define TASKID_SPIQ 3
49 50 #define TASKID_SMIQ 4
50 51 #define TASKID_STAT 5
51 52 #define TASKID_AVF0 6
52 53 #define TASKID_BPF0 7
53 54 #define TASKID_WFRM 8
54 55 #define TASKID_DUMB 9
55 56 #define TASKID_HOUS 10
56 57
57 58 #define ACTION_MSG_QUEUE_COUNT 10
58 59
59 // LENGTH (BYTES)
60 #define LENGTH_TM_LFR_HK 126
61
62 60 //*******
63 61 // MACROS
64 //#define PRINT_TASK_STATISTICS
62 #define PRINT_TASK_STATISTICS
65 63 #define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
66 64 #ifdef PRINT_MESSAGES_ON_CONSOLE
67 65 #define PRINTF(x) printf(x);
68 66 #define PRINTF1(x,y) printf(x,y);
69 67 #define PRINTF2(x,y,z) printf(x,y,z);
70 68 #else
71 69 #define PRINTF(x) ;
72 70 #define PRINTF1(x,y) ;
73 71 #define PRINTF2(x,y,z) ;
74 72 #endif
75 73
76 74 #define NB_SAMPLES_PER_SNAPSHOT 2048
77 75 #define NB_BYTES_SWF_BLK 2 * 6
76 #define NB_WORDS_SWF_BLK 3
78 77
79 78 struct param_norm_str{
80 79 unsigned int sy_lfr_n_swf_l; // length of the snapshots
81 80 unsigned int sy_lfr_n_swf_p; // time between two snapshots
82 81 unsigned int sy_lfr_n_asm_p; // time between two asm
83 82 unsigned char sy_lfr_n_bp_p0; // timebetween two products BP1 set
84 83 unsigned char sy_lfr_n_bp_p1; // time between two products BP2 set
85 84 };
86 85
87 86 struct param_burst_str{
88 87 unsigned char sy_lfr_b_bp_p0; // timebetween two products BP1 set
89 88 unsigned char sy_lfr_b_bp_p1; // time between two products BP2 set
90 89 };
91 90
92 91 struct param_sbm1_str{
93 92 unsigned char sy_lfr_s1_bp_p0; // timebetween two products BP1 set
94 93 unsigned char sy_lfr_s1_bp_p1; // time between two products BP2 set
95 94 };
96 95
97 96 struct param_sbm2_str{
98 97 unsigned char sy_lfr_s2_bp_p0; // timebetween two products BP1 set
99 98 unsigned char sy_lfr_s2_bp_p1; // time between two products BP2 set
100 99 };
101 100
102 101 extern volatile int wf_snap_f0[ ]; // 24576 bytes
103 102 extern volatile int wf_snap_f1[ ]; // 24576 bytes
104 103 extern volatile int wf_snap_f2[ ]; // 24576 bytes
105 104 extern volatile int wf_cont_f3[ ]; // 24576 bytes
106 105
107 106 #endif // FSW_RTEMS_CONFIG_H_INCLUDED
@@ -1,44 +1,45
1 1 #ifndef FSW_RTEMS_PROCESSING_H_INCLUDED
2 2 #define FSW_RTEMS_PROCESSING_H_INCLUDED
3 3
4 4 #define NB_BINS_spec_mat 128
5 5 #define NB_VALUES_PER_spec_mat 25
6 6 #define TOTAL_SIZE_SPEC_MAT NB_BINS_spec_mat * NB_VALUES_PER_spec_mat
7 7 #define NB_BINS_COMPRESSED_MATRIX_f0 11
8 8 #define SIZE_COMPRESSED_spec_mat_f1 13
9 9 #define SIZE_COMPRESSED_spec_mat_f2 12
10 10 #define TOTAL_SIZE_COMPRESSED_MATRIX_f0 NB_BINS_COMPRESSED_MATRIX_f0 * NB_VALUES_PER_spec_mat
11 11 #define NB_AVERAGE_NORMAL_f0 96*4
12 12 #define NB_SM_TO_RECEIVE_BEFORE_AVF0 8
13 13
14 14 #include <rtems.h>
15 15 #include <grlib_regs.h>
16 16 #include <fsw_params.h>
17 17
18 18 struct BP1_str{
19 19 volatile unsigned char PE[2];
20 20 volatile unsigned char PB[2];
21 21 volatile unsigned char V0;
22 22 volatile unsigned char V1;
23 23 volatile unsigned char V2_ELLIP_DOP;
24 24 volatile unsigned char SZ;
25 25 volatile unsigned char VPHI;
26 26 };
27 27 typedef struct BP1_str BP1_t;
28 28
29 29 // ISR
30 30 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
31
31 32 // RTEMS TASKS
32 33 rtems_task spw_bppr_task(rtems_task_argument argument);
33 34 rtems_task avf0_task(rtems_task_argument argument);
34 35 rtems_task bpf0_task(rtems_task_argument argument);
35 36 rtems_task smiq_task(rtems_task_argument argument); // added to test the spectral matrix simulator
36 //
37
37 38 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument);
38 39 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat);
39 40 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat);
40 41 void matrix_reset(float *averaged_spec_mat);
41 42 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1);
42 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
43 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat);
43 44
44 45 #endif // FSW_RTEMS_PROCESSING_H_INCLUDED
@@ -1,20 +1,25
1 1 #ifndef WF_HANDLER_H_INCLUDED
2 2 #define WF_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <fsw_params.h>
6 6 #include <grspw.h>
7 7 #include <grlib_regs.h>
8 8 #include <ccsds_types.h>
9 9 #include <stdio.h>
10 10 #include <fsw_init.h>
11 11
12 12 //#include <sys/ioctl.h>
13 13
14 14 extern rtems_id Task_id[]; /* array of task ids */
15 15 extern int fdSPW;
16 16
17 17 rtems_isr waveforms_isr( rtems_vector_number vector );
18 18 rtems_task wfrm_task(rtems_task_argument argument);
19 19
20 //******************
21 // general functions
22 void init_waveforms();
23 int buil_value(int value1, int value0);
24
20 25 #endif // WF_HANDLER_H_INCLUDED
@@ -1,49 +1,48
1 1 #include <fsw_processing.h>
2 2 #include <rtems.h>
3 3 #include <ccsds_types.h>
4 4
5 5 // RTEMS GLOBAL VARIABLES
6 6 rtems_name misc_name[5];
7 7 rtems_name misc_id[5];
8 8 rtems_id Task_id[15]; /* array of task ids */
9 9 rtems_name Task_name[15]; /* array of task names */
10 10 int fdSPW;
11 11 int fdUART;
12 12
13 13 // APB CONFIGURATION REGISTERS
14 14 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
15 15
16 16 // WAVEFORMS GLOBAL VARIABLES
17 17 volatile int wf_snap_f0[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
18 18 volatile int wf_snap_f1[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
19 19 volatile int wf_snap_f2[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
20 20 volatile int wf_cont_f3[ NB_SAMPLES_PER_SNAPSHOT * NB_BYTES_SWF_BLK ]; // 24576 bytes
21 21
22 22 // SPECTRAL MATRICES GLOBAL VARIABLES
23 23 volatile int spec_mat_f0_a[ TOTAL_SIZE_SPEC_MAT ];
24 24 volatile int spec_mat_f0_b[ TOTAL_SIZE_SPEC_MAT ];
25 25 volatile int spec_mat_f0_c[ TOTAL_SIZE_SPEC_MAT ];
26 26 volatile int spec_mat_f0_d[ TOTAL_SIZE_SPEC_MAT ];
27 27 volatile int spec_mat_f0_e[ TOTAL_SIZE_SPEC_MAT ];
28 28 volatile int spec_mat_f0_f[ TOTAL_SIZE_SPEC_MAT ];
29 29 volatile int spec_mat_f0_g[ TOTAL_SIZE_SPEC_MAT ];
30 30 volatile int spec_mat_f0_h[ TOTAL_SIZE_SPEC_MAT ];
31 31 //
32 32 float averaged_spec_mat_f0[ TOTAL_SIZE_SPEC_MAT ];
33 33 float compressed_spec_mat_f0[ TOTAL_SIZE_COMPRESSED_MATRIX_f0 ];
34 34
35 35 // MODE PARAMETERS
36 36 struct param_norm_str param_norm;
37 37 struct param_burst_str param_burst;
38 38 struct param_sbm1_str param_sbm1;
39 39 struct param_sbm2_str param_sbm2;
40 40 unsigned char param_common[2];
41 41
42 42 // HK PACKETS
43 TMHeader_t housekeeping_header;
44 char housekeeping_data[LENGTH_TM_LFR_HK - 10 + 1];
43 Packet_TM_LFR_HK_t housekeeping_packet;
45 44
46 45 // BASIC PARAMETERS GLOBAL VARIABLES
47 46 unsigned char LFR_BP1_F0[ NB_BINS_COMPRESSED_MATRIX_f0 * 9 ];
48 47 BP1_t data_BP1[ NB_BINS_COMPRESSED_MATRIX_f0 ];
49 48
@@ -1,361 +1,373
1 1 //*************************
2 2 // GPL reminder to be added
3 3 //*************************
4 4
5 5 #include <rtems.h>
6 6
7 7 /* configuration information */
8 8
9 9 #define CONFIGURE_INIT
10 10
11 11 #include <bsp.h> /* for device driver prototypes */
12 12
13 13 /* configuration information */
14 14
15 15 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
16 16 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
17 17
18 18 #define CONFIGURE_MAXIMUM_TASKS 15
19 19 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
20 20 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
21 21 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
22 22 #define CONFIGURE_INIT_TASK_PRIORITY 100
23 23 #define CONFIGURE_MAXIMUM_DRIVERS 16
24 #define CONFIGURE_MAXIMUM_PERIODS 1
24 #define CONFIGURE_MAXIMUM_PERIODS 5
25 25 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
26 26
27 27 #include <rtems/confdefs.h>
28 28
29 29 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
30 30 #ifdef RTEMS_DRVMGR_STARTUP
31 31 #ifdef LEON3
32 32 /* Add Timer and UART Driver */
33 33 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
34 34 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
35 35 #endif
36 36 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
37 37 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
38 38 #endif
39 39 #endif
40 40 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
41 41 #include <drvmgr/drvmgr_confdefs.h>
42 42 #endif
43 43
44 44 #include <fsw_init.h>
45 45 #include <fsw_config.c>
46 46
47 47 char *link_status(int status);
48 48
49 49 char *lstates[6] = {"Error-reset",
50 50 "Error-wait",
51 51 "Ready",
52 52 "Started",
53 53 "Connecting",
54 54 "Run"
55 55 };
56 56
57 57 rtems_task Init( rtems_task_argument ignored )
58 58 {
59 59 rtems_status_code status;
60 60 rtems_isr_entry old_isr_handler;
61 61
62 PRINTF("\n\n\n\n\n")
63 PRINTF("***************************\n")
64 PRINTF("** START Flight Software **\n")
65 PRINTF("***************************\n")
66 PRINTF("\n\n")
67
62 68 //send_console_outputs_on_serial_port();
69 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
63 70
64 71 initLookUpTableForCRC(); // in tc_handler.h
65 72 init_default_mode_parameters();
66 create_message_queue();
73 create_message_queue();
74
75 create_names();
67 76 create_all_tasks();
68 77 start_all_tasks();
69 78
70 79 grspw_timecode_callback = &timecode_irq_handler;
71 80
72 81 configure_spw_link();
73 82
83 init_waveforms();
84
74 85 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
75 86 IRQ_SPARC_SM, spectral_matrices_isr );
76 87 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR,
77 88 IRQ_SPARC_WF, waveforms_isr );
78 89
79 90 // irq handling of the time management unit
80 91 status = rtems_interrupt_catch( commutation_isr1,
81 92 IRQ_SPARC_TIME1,
82 93 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
83 94 if (status==RTEMS_SUCCESSFUL)
84 PRINTF("commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
95 PRINTF("OK *** commutation_isr1 *** rtems_interrupt_catch successfullly configured\n")
85 96
86 97 status = rtems_interrupt_catch( commutation_isr2,
87 98 IRQ_SPARC_TIME2,
88 99 &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
89 100 if (status==RTEMS_SUCCESSFUL)
90 PRINTF("commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
101 PRINTF("OK *** commutation_isr2 *** rtems_interrupt_catch successfullly configured\n")
91 102
92 103 LEON_Unmask_interrupt( IRQ_TIME1 );
93 104 LEON_Unmask_interrupt( IRQ_TIME2 );
94 105
95 106 status = rtems_task_delete(RTEMS_SELF);
96 107 }
97 108
98 109 rtems_task spiq_task(rtems_task_argument unused)
99 110 {
100 111 rtems_event_set event_out;
101 112 struct grspw_regs_str *grspw_regs;
102 113 grspw_regs = (struct grspw_regs_str *) REGS_ADDR_GRSPW;
114 rtems_status_code status;
103 115
104 116 while(1){
105 PRINTF("In SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
117 PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n")
106 118 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
107 119
108 120 if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) // suspend RECV task
109 PRINTF("In SPIQ *** Error suspending RECV Task\n")
121 PRINTF("in SPIQ *** Error suspending RECV Task\n")
110 122 if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) // suspend HOUS task
111 PRINTF("In SPIQ *** Error suspending HOUS Task\n")
123 PRINTF("in SPIQ *** Error suspending HOUS Task\n")
112 124
113 125 configure_spw_link();
126
127 status = rtems_task_restart( Task_id[TASKID_HOUS], 1 );
128 if (status!=RTEMS_SUCCESSFUL)
129 PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status)
114 130
115 131 if (rtems_task_restart(Task_id[TASKID_RECV], 1)!=RTEMS_SUCCESSFUL) // restart RECV task
116 PRINTF("In SPIQ *** Error resume RECV Task\n")
117 if (rtems_task_restart(Task_id[TASKID_HOUS], 1)!=RTEMS_SUCCESSFUL) // restart HOUS task
118 PRINTF("In SPIQ *** Error resume HOUS Task\n")
119
132 PRINTF("in SPIQ *** Error restarting RECV Task\n")
120 133 }
121 134 }
122 135
123 136 void init_default_mode_parameters()
124 137 {
125 138 // COMMON PARAMETERS
126 139 param_common[0] = 0x00;
127 140 param_common[1] = 0x10; // default value 0 0 0 1 0 0 0 0
128 141 // NORMAL MODE
129 142 param_norm.sy_lfr_n_swf_l = 2048; // nb sample
130 143 param_norm.sy_lfr_n_swf_p = 300; // sec
131 144 param_norm.sy_lfr_n_asm_p = 3600; // sec
132 145 param_norm.sy_lfr_n_bp_p0 = 4; // sec
133 146 param_norm.sy_lfr_n_bp_p1 = 20; // sec
134 147 // BURST MODE
135 148 param_burst.sy_lfr_b_bp_p0 = 1; // sec
136 149 param_burst.sy_lfr_b_bp_p1 = 5; // sec
137 150 // SBM1 MODE
138 151 param_sbm1.sy_lfr_s1_bp_p0 = 1; // sec
139 152 param_sbm1.sy_lfr_s1_bp_p1 = 1; // sec
140 153 // SBM2 MODE
141 154 param_sbm2.sy_lfr_s2_bp_p0 = 1; // sec
142 155 param_sbm2.sy_lfr_s2_bp_p0 = 5; // sec
143 156 }
144 157
145 int create_all_tasks()
158 int create_names()
146 159 {
147 rtems_status_code status;
148
160 // task names
149 161 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
150 162 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
151 163 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
152 164 Task_name[TASKID_SMIQ] = rtems_build_name( 'S', 'M', 'I', 'Q' );
153 165 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
154 166 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
155 167 Task_name[TASKID_BPF0] = rtems_build_name( 'B', 'P', 'F', '0' );
156 168 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
157 169 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
158 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
170 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
171
172 // rate monotonic period name
173 HK_name = rtems_build_name( 'H', 'O', 'U', 'S' );
174
175 return 0;
176 }
177
178 int create_all_tasks()
179 {
180 rtems_status_code status;
159 181
160 182 // RECV
161 183 status = rtems_task_create(
162 184 Task_name[TASKID_RECV], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
163 185 RTEMS_DEFAULT_MODES,
164 186 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
165 187 );
166 188 // ACTN
167 189 status = rtems_task_create(
168 190 Task_name[TASKID_ACTN], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
169 191 RTEMS_DEFAULT_MODES,
170 192 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_ACTN]
171 193 );
172 194 // SPIQ
173 195 status = rtems_task_create(
174 Task_name[TASKID_SPIQ], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
175 RTEMS_DEFAULT_MODES,
196 Task_name[TASKID_SPIQ], 5, RTEMS_MINIMUM_STACK_SIZE * 2,
197 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
176 198 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
177 199 );
178 200 // SMIQ
179 201 status = rtems_task_create(
180 202 Task_name[TASKID_SMIQ], 10, RTEMS_MINIMUM_STACK_SIZE * 2,
181 203 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
182 204 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SMIQ]
183 205 );
184 206 // STAT
185 207 status = rtems_task_create(
186 208 Task_name[TASKID_STAT], 150, RTEMS_MINIMUM_STACK_SIZE * 2,
187 209 RTEMS_DEFAULT_MODES,
188 210 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
189 211 );
190 212 // AVF0
191 213 status = rtems_task_create(
192 214 Task_name[TASKID_AVF0], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
193 215 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
194 216 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
195 217 );
196 218 // BPF0
197 219 status = rtems_task_create(
198 220 Task_name[TASKID_BPF0], 50, RTEMS_MINIMUM_STACK_SIZE * 2,
199 221 RTEMS_DEFAULT_MODES,
200 222 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_BPF0]
201 223 );
202 224 // WFRM
203 225 status = rtems_task_create(
204 226 Task_name[TASKID_WFRM], 100, RTEMS_MINIMUM_STACK_SIZE * 2,
205 227 RTEMS_DEFAULT_MODES,
206 228 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
207 229 );
208 230 // DUMB
209 231 status = rtems_task_create(
210 232 Task_name[TASKID_DUMB], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
211 233 RTEMS_DEFAULT_MODES,
212 234 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
213 235 );
214 236 // HOUS
215 237 status = rtems_task_create(
216 Task_name[TASKID_HOUS], 200, RTEMS_MINIMUM_STACK_SIZE * 2,
238 Task_name[TASKID_HOUS], 199, RTEMS_MINIMUM_STACK_SIZE * 2,
217 239 RTEMS_DEFAULT_MODES,
218 240 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_HOUS]
219 241 );
220 242
221 243 return 0;
222 244 }
223 245
224 246 int start_all_tasks()
225 247 {
226 248 rtems_status_code status;
227 249
228 250 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
229 251 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_SPIQ\n")
230 252
231 253 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
232 254 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_RECV\n")
233 255
234 256 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
235 257 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_ACTN\n")
236 258
237 259 status = rtems_task_start( Task_id[TASKID_SMIQ], smiq_task, 1 );
238 260 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPPR\n")
239 261
240 262 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
241 263 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_STAT\n")
242 264
243 265 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, 1 );
244 266 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_AVF0\n")
245 267
246 268 status = rtems_task_start( Task_id[TASKID_BPF0], bpf0_task, 1 );
247 269 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_BPF0\n")
248 270
249 271 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
250 272 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_WFRM\n")
251 273
252 274 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
253 275 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_DUMB\n")
254 276
255 277 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
256 278 if (status!=RTEMS_SUCCESSFUL) PRINTF("In INIT *** Error starting TASK_HOUS\n")
257 279
258 280 return 0;
259 281 }
260 282
261 283 int configure_spw_link()
262 284 {
263 285 rtems_status_code status;
264 286
265 close(fdSPW); // close the device if it is already open
287 close(fdSPW); // close the device if it is already open
288 PRINTF("OK *** in configure_spw_link *** try to open "GRSPW_DEVICE_NAME"\n")
266 289 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
267 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
290 if (fdSPW<0) PRINTF("ERR *** in configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
268 291 while(ioctl(fdSPW, SPACEWIRE_IOCTRL_START, 0) != RTEMS_SUCCESSFUL){
269 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" not started, retry\n")
292 PRINTF(".")
293 fflush(stdout);
270 294 close(fdSPW); // close the device
271 295 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call reset the hardware
272 if (fdSPW<0) PRINTF("In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
296 if (fdSPW<0) PRINTF("ERR *** In configure_spw_link *** Error opening"GRSPW_DEVICE_NAME"\n")
273 297 rtems_task_wake_after(100);
274 298 }
275 299
276 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
277
278 // sets a few parameters of the link
279 //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
280 //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
300 PRINTF("OK *** In configure_spw_link *** "GRSPW_DEVICE_NAME" opened and started successfully\n")
281 301
282 302 configure_spacewire_set_NP(1, REGS_ADDR_GRSPW); // No Port force
283 303 configure_spacewire_set_RE(1, REGS_ADDR_GRSPW); // the dedicated call seems to break the no port force configuration
284 304
285 305 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
286 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
306 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
287 307 //
288 308 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
289 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
309 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
290 310 //
291 311 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
292 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
312 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
293 313 //
294 314 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
295 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
315 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
296 316 //
297 317 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // sets the link-error interrupt bit
298 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
299 //
300 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destination key
301 PRINTF1("destination address set to: %d\n", CCSDS_DESTINATION_ID)
302 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DESTKEY\n")
303 //
304 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_NODEADDR, CCSDS_NODE_ADDRESS); // sets the node address
305 PRINTF1("node address set to: %d\n", CCSDS_NODE_ADDRESS)
306 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_NODEADDR\n")
318 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
307 319 //
308 320 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909);
309 if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
321 if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
310 322
311 PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
323 PRINTF("OK *** in configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
312 324
313 325 return RTEMS_SUCCESSFUL;
314 326 }
315 327
316 328 void configure_spacewire_set_NP(unsigned char val, unsigned int regAddr) // No Port force
317 329 {
318 330 unsigned int *spwptr;
319 331 spwptr = (unsigned int*) regAddr;
320 332 if (val == 1)
321 333 {
322 334 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
323 335 }
324 336 if (val== 0)
325 337 {
326 338 *spwptr = *spwptr & 0xffdfffff;
327 339 }
328 340 }
329 341
330 342 void configure_spacewire_set_RE(unsigned char val, unsigned int regAddr) // RMAP Enable
331 343 {
332 344 unsigned int *spwptr;
333 345 spwptr = (unsigned int*) regAddr;
334 346 if (val == 1)
335 347 {
336 348 *spwptr = *spwptr | 0x00010000; // [NP] set the No port force bit
337 349 }
338 350 if (val== 0)
339 351 {
340 352 *spwptr = *spwptr & 0xfffdffff;
341 353 }
342 354 }
343 355
344 356 char *link_status(int status){
345 357 return lstates[status];
346 358 }
347 359
348 360 rtems_status_code write_spw(spw_ioctl_pkt_send* spw_ioctl_send)
349 361 {
350 362 rtems_status_code status;
351 363 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
352 364 if (status!=RTEMS_SUCCESSFUL) printf("In write_spw *** Error SPACEWIRE_IOCTRL_SEND\n");
353 365 return status;
354 366 }
355 367
356 368 void timecode_irq_handler(void *pDev, void *regs, int minor, unsigned int tc)
357 369 {
358 370 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
359 371 printf("In timecode_irq_handler *** Error sending event to DUMB\n");
360 372 }
361 373
@@ -1,138 +1,158
1 1 #include <fsw_misc.h>
2 2 #include <fsw_params.h>
3 3
4 4 extern rtems_id Task_id[]; /* array of task ids */
5 5 extern int fdSPW;
6 6 extern TMHeader_t housekeeping_header;
7 7 extern char housekeeping_data[];
8 extern Packet_TM_LFR_HK_t housekeeping_packet;
8 9
9 10 int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider,
10 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 12 { // configure the timer for the waveforms simulation
12 13 rtems_status_code status;
13 14 rtems_isr_entry old_isr_handler;
14 15
15 16 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
16 17 //if (status==RTEMS_SUCCESSFUL) PRINTF("In configure_timer_for_wf_simulation *** rtems_interrupt_catch successfullly configured\n")
17 18
18 19 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
19 20 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
20 21 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
21 22 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
22 23 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
23 24 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
24 25
25 26 return 1;
26 27 }
27 28
28 29 void print_statistics(spw_stats *stats)
29 30 {
30 31 //printf(" ******** STATISTICS ******** \n");
31 32 printf("Transmit link errors: %i\n", stats->tx_link_err);
32 33 printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err);
33 34 printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err);
34 35 printf("Receiver EEP errors: %i\n", stats->rx_eep_err);
35 36 printf("Receiver truncation errors: %i\n", stats->rx_truncated);
36 37 printf("Parity errors: %i\n", stats->parity_err);
37 38 printf("Escape errors: %i\n", stats->escape_err);
38 39 printf("Credit errors: %i\n", stats->credit_err);
39 40 printf("Disconnect errors: %i\n", stats->disconnect_err);
40 41 printf("Write synchronization errors: %i\n", stats->write_sync_err);
41 42 printf("Early EOP/EEP: %i\n", stats->early_ep);
42 43 printf("Invalid Node Address: %i\n", stats->invalid_address);
43 44 printf("Packets transmitted: %i\n", stats->packets_sent);
44 45 printf("Packets received: %i\n", stats->packets_received);
45 46 }
46 47
47 48 int send_console_outputs_on_serial_port() // Send the console outputs on the serial port
48 49 {
49 50 struct apbuart_regs_str *apbuart_regs;
50 51
51 52 apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
52 53 apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
53 54 PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
54 55
55 56 return 0;
56 57 }
57 58
59 int set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
60 {
61 struct apbuart_regs_str *apbuart_regs;
62
63 apbuart_regs = (struct apbuart_regs_str *) regs;
64 apbuart_regs->scaler = value;
65 PRINTF1("OK *** COM port scaler reload register set to %x\n", value)
66
67 return 0;
68 }
69
70 //************
71 // RTEMS TASKS
72
58 73 rtems_task stat_task(rtems_task_argument argument)
59 74 {
60 int i;
61 i = 0;
62 PRINTF("In STAT *** \n")
75 int i;
76 int j;
77 i = 0;
78 j = 0;
79 PRINTF("in STAT *** \n")
63 80 while(1){
64 81 rtems_task_wake_after(1000);
65 PRINTF1("%d\n", i)
82 PRINTF1("%d\n", j)
66 83 if (i == 2) {
67 84 #ifdef PRINT_TASK_STATISTICS
68 85 rtems_cpu_usage_report();
69 86 rtems_cpu_usage_reset();
70 87 #endif
71 88 i = 0;
72 89 }
73 else i++;
90 else i++;
91 j++;
74 92 }
75 93 }
76 94
77 95 rtems_task hous_task(rtems_task_argument argument)
78 {
96 {
97 PRINTF("in HOUS ***\n")
98
99 int result;
79 100 rtems_status_code status;
80 101
81 spw_ioctl_pkt_send spw_ioctl_send;
102 if (rtems_rate_monotonic_ident( HK_name, &HK_id)!=RTEMS_SUCCESSFUL)
103 {
104 status = rtems_rate_monotonic_create( HK_name, &HK_id );
105 if( status != RTEMS_SUCCESSFUL )
106 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
107 }
108
109 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
110 housekeeping_packet.protocolIdentifier = 0x02;
111 housekeeping_packet.reserved = 0x00;
112 housekeeping_packet.userApplication = 0x00;
113 housekeeping_packet.packetID[0] = 0x0c;
114 housekeeping_packet.packetID[1] = 0xc4;
115 housekeeping_packet.packetSequenceControl[0] = 0xc0;
116 housekeeping_packet.packetSequenceControl[1] = 0x00;
117 housekeeping_packet.packetLength[0] = 0x00;
118 housekeeping_packet.packetLength[1] = 0x77;
119 housekeeping_packet.dataFieldHeader[0] = 0x10;
120 housekeeping_packet.dataFieldHeader[1] = 0x03;
121 housekeeping_packet.dataFieldHeader[2] = 0x19;
122 housekeeping_packet.dataFieldHeader[3] = 0x00;
123
124 status = rtems_rate_monotonic_cancel(HK_id);
125 if( status != RTEMS_SUCCESSFUL )
126 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
127 else
128 PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
82 129
83 rtems_name name;
84 rtems_id period;
85 name = rtems_build_name( 'H', 'O', 'U', 'S' );
86 status = rtems_rate_monotonic_create( name, &period );
87 if( status != RTEMS_SUCCESSFUL ) {
88 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
89 exit( 1 );
130 while(1){ // launch the rate monotonic task
131 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
132 if ( status != RTEMS_SUCCESSFUL ){
133 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_period *** code %d\n", status);
134 }
135 else
136 {
137 housekeeping_packet.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
138 housekeeping_packet.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
139 housekeeping_packet.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
140 housekeeping_packet.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
141 housekeeping_packet.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
142 housekeeping_packet.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
143 housekeeping_packet.data[0] = CCSDS_DESTINATION_ID_DPU;
144 result = write ( fdSPW, &housekeeping_packet, LEN_TM_LFR_HK);
145 if (result==-1)
146 {
147 PRINTF("ERR *** in HOUS *** HK send\n");
148 }
149 }
90 150 }
91 151
92 // filling the structure for the spacewire transmission
93 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
94 spw_ioctl_send.hdr = (char*) &housekeeping_header;
95 spw_ioctl_send.dlen = LENGTH_TM_LFR_HK - 10 + 1;
96 spw_ioctl_send.data = housekeeping_data;
97
98 housekeeping_header.targetLogicalAddress = CCSDS_DESTINATION_ID;
99 housekeeping_header.protocolIdentifier = 0x02;
100 housekeeping_header.reserved = 0x00;
101 housekeeping_header.userApplication = 0x00;
102 housekeeping_header.packetID[0] = 0x0c;
103 housekeeping_header.packetID[1] = 0xc4;
104 housekeeping_header.packetSequenceControl[0] = 0xc0;
105 housekeeping_header.packetSequenceControl[1] = 0x00;
106 housekeeping_header.packetLength[0] = 0x00;
107 housekeeping_header.packetLength[1] = 0x77;
108 housekeeping_header.dataFieldHeader[0] = 0x10;
109 housekeeping_header.dataFieldHeader[1] = 0x03;
110 housekeeping_header.dataFieldHeader[2] = 0x19;
111 housekeeping_header.dataFieldHeader[3] = 0x00;
152 PRINTF("in HOUS *** deleting task\n")
112 153
113 printf("In HOUS ***\n");
114
115 while(1){ // launch the rate monotonic task
116 if ( rtems_rate_monotonic_period( period, HK_PERIOD ) == RTEMS_TIMEOUT ){
117 printf( "ERR *** in hous_task *** RTEMS_TIMEOUT\n" );
118 break;
119 }
120 housekeeping_header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
121 housekeeping_header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
122 housekeeping_header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
123 housekeeping_header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
124 housekeeping_header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
125 housekeeping_header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
126 status = write_spw(&spw_ioctl_send);
127 }
128
129 status = rtems_rate_monotonic_delete( period );
130 if ( status != RTEMS_SUCCESSFUL ) {
131 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
132 exit( 1 );
133 }
134 154 status = rtems_task_delete( RTEMS_SELF ); // should not return
135 155 printf( "rtems_task_delete returned with status of %d.\n", status );
136 156 exit( 1 );
137 157 }
138 158
@@ -1,447 +1,406
1 1 #include <fsw_processing.h>
2 2 #include <math.h>
3 3 #include <stdio.h>
4 4 #include <stdlib.h>
5 5 #include <leon.h>
6 6
7 7 // TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
8 8 // SX 12 coefficients
9 9 float k14_sx_re = 1;
10 10 float k14_sx_im = 1;
11 11 float k15_sx_re = 1;
12 12 float k15_sx_im = 1;
13 13 float k24_sx_re = 1;
14 14 float k24_sx_im = 1;
15 15 float k25_sx_re = 1;
16 16 float k25_sx_im = 1;
17 17 float k34_sx_re = 1;
18 18 float k34_sx_im = 1;
19 19 float k35_sx_re = 1;
20 20 float k35_sx_im = 1;
21 21 // NY 8 coefficients
22 22 float k24_ny_re = 1;
23 23 float k24_ny_im = 1;
24 24 float k25_ny_re = 1;
25 25 float k25_ny_im = 1;
26 26 float k34_ny_re = 1;
27 27 float k34_ny_im = 1;
28 28 float k35_ny_re = 1;
29 29 float k35_ny_im = 1;
30 30 // NZ 8 coefficients
31 31 float k24_nz_re = 1;
32 32 float k24_nz_im = 1;
33 33 float k25_nz_re = 1;
34 34 float k25_nz_im = 1;
35 35 float k34_nz_re = 1;
36 36 float k34_nz_im = 1;
37 37 float k35_nz_re = 1;
38 38 float k35_nz_im = 1;
39 39 // PE 4 coefficients
40 40 float k44_pe = 1;
41 41 float k55_pe = 1;
42 42 float k45_pe_re = 1;
43 43 float k45_pe_im = 1;
44 44
45 45 float alpha_M = M_PI/4;
46 46
47 47 extern volatile int spec_mat_f0_a[ ];
48 48 extern volatile int spec_mat_f0_b[ ];
49 49 extern volatile int spec_mat_f0_c[ ];
50 50 extern volatile int spec_mat_f0_d[ ];
51 51 extern volatile int spec_mat_f0_e[ ];
52 52 extern volatile int spec_mat_f0_f[ ];
53 53 extern volatile int spec_mat_f0_g[ ];
54 54 extern volatile int spec_mat_f0_h[ ];
55 55 extern float averaged_spec_mat_f0[ ];
56 56 extern float compressed_spec_mat_f0[ ];
57 57 extern unsigned char LFR_BP1_F0[ ];
58 58
59 59 extern BP1_t data_BP1[ ];
60 60
61 61 extern rtems_id Task_id[ ]; /* array of task ids */
62 62
63 63 spectral_matrices_regs_t *spectral_matrices_regs;
64
64
65 //***********************************************************
65 66 // Interrupt Service Routine for spectral matrices processing
66 67 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
67 68 {
68 69 if (rtems_event_send( Task_id[TASKID_SMIQ], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
69 printf("In spectral_matrices_isr *** Error sending event to AVF0\n");
70 printf("in spectral_matrices_isr *** Error sending event to AVF0\n");
70 71 }
71 72
73 //************
74 // RTEMS TASKS
72 75 rtems_task smiq_task(rtems_task_argument argument) // process the Spectral Matrices IRQ
73 76 {
74 77 rtems_event_set event_out;
75 78 gptimer_regs_t *gptimer_regs;
76 79 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
77 80 unsigned char nb_interrupt_f0 = 0;
78 81
79 PRINTF("In SMIQ *** \n")
82 PRINTF("in SMIQ *** \n")
80 83
81 84 while(1){
82 85 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
83 86 nb_interrupt_f0 = nb_interrupt_f0 + 1;
84 87 if (nb_interrupt_f0 == (NB_SM_TO_RECEIVE_BEFORE_AVF0-1) ){
85 if (rtems_event_send( Task_id[6], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
86 printf("In smiq_task *** Error sending event to AVF0\n");
88 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
89 printf("in SMIQ *** Error sending event to AVF0\n");
87 90 nb_interrupt_f0 = 0;
88 91 }
89 gptimer_regs->timer[1].ctrl = gptimer_regs->timer[1].ctrl | 0x00000010;
90 92 }
91 93 }
92 94
93 95 rtems_task spw_bppr_task(rtems_task_argument argument)
94 96 {
95 97 rtems_status_code status;
96 98 rtems_event_set event_out;
97 99 static int nb_average_f0 = 0;
98 100 //static int nb_average_f1 = 0;
99 101 //static int nb_average_f2 = 0;
100 102
101 103 while(1)
102 104
103 105 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
104 106 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
105 107 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
106 108
107 printf("In BPPR ***\n");
109 printf("in BPPR ***\n");
108 110
109 111 while(1){ // wait for an event to begin with the processing
110 112 status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
111 113 if (status == RTEMS_SUCCESSFUL){
112 114 if ((spectral_matrices_regs->ctrl & 0x00000001)==1){
113 115 matrix_average(spec_mat_f0_a, averaged_spec_mat_f0);
114 116 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe;
115 117 //printf("f0_a\n");
116 118 nb_average_f0++;
117 119 }
118 120 if (((spectral_matrices_regs->ctrl>>1) & 0x00000001)==1){
119 121 matrix_average(spec_mat_f0_b, compressed_spec_mat_f0);
120 122 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffd;
121 123 //printf("f0_b\n");
122 124 nb_average_f0++;
123 125 }
124 126 if (nb_average_f0 == NB_AVERAGE_NORMAL_f0){
125 127 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
126 128 //printf("f0 compressed\n");
127 129 nb_average_f0 = 0;
128 130 matrix_reset(averaged_spec_mat_f0);
129 131 }
130 132 }
131 133 }
132 134 }
133 135
136 rtems_task avf0_task(rtems_task_argument argument){
137 int i;
138 static int nb_average;
139 rtems_event_set event_out;
140 rtems_status_code status;
141
142 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
143 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
144 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
145
146 nb_average = 0;
147
148 PRINTF("in AVFO *** \n")
149
150 while(1){
151 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
152 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
153 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
154 + spec_mat_f0_b[i]
155 + spec_mat_f0_c[i]
156 + spec_mat_f0_d[i]
157 + spec_mat_f0_e[i]
158 + spec_mat_f0_f[i]
159 + spec_mat_f0_g[i]
160 + spec_mat_f0_h[i];
161 }
162 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
163 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
164 if (nb_average == NB_AVERAGE_NORMAL_f0) {
165 nb_average = 0;
166 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
167 if (status != RTEMS_SUCCESSFUL) printf("iN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
168 }
169 }
170 }
171
172 rtems_task bpf0_task(rtems_task_argument argument){
173 rtems_event_set event_out;
174
175 PRINTF("in BPFO *** \n")
176
177 while(1){
178 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
179 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
180 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
181 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
182 }
183 }
184
185 //*****************************
186 // Spectral matrices processing
134 187 void matrix_average(volatile int *spec_mat, float *averaged_spec_mat)
135 188 {
136 189 int i;
137 190 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
138 191 averaged_spec_mat[i] = averaged_spec_mat[i] + spec_mat_f0_a[i]
139 192 + spec_mat_f0_b[i]
140 193 + spec_mat_f0_c[i]
141 194 + spec_mat_f0_d[i]
142 195 + spec_mat_f0_e[i]
143 196 + spec_mat_f0_f[i]
144 197 + spec_mat_f0_g[i]
145 198 + spec_mat_f0_h[i];
146 199 }
147 200 }
148 201
149 202 void matrix_reset(float *averaged_spec_mat)
150 203 {
151 204 int i;
152 205 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
153 206 averaged_spec_mat_f0[i] = 0;
154 207 }
155 208 }
156 209
157 210 void matrix_compression(float *averaged_spec_mat, unsigned char fChannel, float *compressed_spec_mat)
158 211 {
159 212 int i, j;
160 213 switch (fChannel){
161 214 case 0:
162 215 for(i=0;i<NB_BINS_COMPRESSED_MATRIX_f0;i++){
163 216 j = 17 + i * 8;
164 217 compressed_spec_mat[i] = (averaged_spec_mat[j]
165 218 + averaged_spec_mat[j+1]
166 219 + averaged_spec_mat[j+2]
167 220 + averaged_spec_mat[j+3]
168 221 + averaged_spec_mat[j+4]
169 222 + averaged_spec_mat[j+5]
170 223 + averaged_spec_mat[j+6]
171 224 + averaged_spec_mat[j+7])/(8*NB_AVERAGE_NORMAL_f0);
172 225 }
173 226 break;
174 227 case 1:
175 // case fChannel = f1 tp be completed later
228 // case fChannel = f1 to be completed later
176 229 break;
177 230 case 2:
178 // case fChannel = f1 tp be completed later
231 // case fChannel = f1 to be completed later
179 232 break;
180 233 default:
181 234 break;
182 235 }
183 236 }
184 237
185 238 void BP1_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1){
186 239 int i, j;
187 240 unsigned char tmp_u_char;
188 241 unsigned char * pt_char;
189 242 float PSDB, PSDE;
190 243 float NVEC_V0, NVEC_V1, NVEC_V2;
191 244 //float significand;
192 245 //int exponent;
193 246 float aux, tr_SB_SB, tmp;
194 247 float sx_re, sx_im;
195 248 float nebx_re = 0, nebx_im = 0;
196 249 float ny = 0, nz = 0;
197 250 float bx_bx_star = 0;
198 251 for(i=0; i<nb_bins_compressed_spec_mat; i++){
199 252 //==============================================
200 253 // BP1 PSD == B PAR_LFR_SC_BP1_PE_FL0 == 16 bits
201 254 PSDB = compressed_spec_mat[i*30] // S11
202 255 + compressed_spec_mat[i*30+10] // S22
203 256 + compressed_spec_mat[i*30+18]; // S33
204 257 //significand = frexp(PSDB, &exponent);
205 258 pt_char = (unsigned char*) &PSDB;
206 259 LFR_BP1[i*9+2] = pt_char[0]; // bits 31 downto 24 of the float
207 260 LFR_BP1[i*9+3] = pt_char[1]; // bits 23 downto 16 of the float
208 261 //==============================================
209 262 // BP1 PSD == E PAR_LFR_SC_BP1_PB_FL0 == 16 bits
210 263 PSDE = compressed_spec_mat[i*30+24] * k44_pe // S44
211 264 + compressed_spec_mat[i*30+28] * k55_pe // S55
212 265 + compressed_spec_mat[i*30+26] * k45_pe_re // S45
213 266 - compressed_spec_mat[i*30+27] * k45_pe_im; // S45
214 267 pt_char = (unsigned char*) &PSDE;
215 268 LFR_BP1[i*9+0] = pt_char[0]; // bits 31 downto 24 of the float
216 269 LFR_BP1[i*9+1] = pt_char[1]; // bits 23 downto 16 of the float
217 270 //==============================================================================
218 271 // BP1 normal wave vector == PAR_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
219 272 // == PAR_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
220 273 // == PAR_LFR_SC_BP1_NVEC_V2_F0 == 1 bits
221 274 tmp = sqrt(
222 275 compressed_spec_mat[i*30+3]*compressed_spec_mat[i*30+3] //Im S12
223 276 +compressed_spec_mat[i*30+5]*compressed_spec_mat[i*30+5] //Im S13
224 277 +compressed_spec_mat[i*30+13]*compressed_spec_mat[i*30+13] //Im S23
225 278 );
226 279 NVEC_V0 = compressed_spec_mat[i*30+13] / tmp; // Im S23
227 280 NVEC_V1 = -compressed_spec_mat[i*30+5] / tmp; // Im S13
228 281 NVEC_V2 = compressed_spec_mat[i*30+3] / tmp; // Im S12
229 282 LFR_BP1[i*9+4] = (char) (NVEC_V0*127);
230 283 LFR_BP1[i*9+5] = (char) (NVEC_V1*127);
231 284 pt_char = (unsigned char*) &NVEC_V2;
232 285 LFR_BP1[i*9+6] = pt_char[0] & 0x80; // extract the sign of NVEC_V2
233 286 //=======================================================
234 287 // BP1 ellipticity == PAR_LFR_SC_BP1_ELLIP_F0 == 4 bits
235 288 aux = 2*tmp / PSDB; // compute the ellipticity
236 289 tmp_u_char = (unsigned char) (aux*(16-1)); // convert the ellipticity
237 290 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | ((tmp_u_char&0x0f)<<3); // keeps 4 bits of the resulting unsigned char
238 291 //==============================================================
239 292 // BP1 degree of polarization == PAR_LFR_SC_BP1_DOP_F0 == 3 bits
240 293 for(j = 0; j<NB_VALUES_PER_spec_mat;j++){
241 294 tr_SB_SB = compressed_spec_mat[i*30] * compressed_spec_mat[i*30]
242 295 + compressed_spec_mat[i*30+10] * compressed_spec_mat[i*30+10]
243 296 + compressed_spec_mat[i*30+18] * compressed_spec_mat[i*30+18]
244 297 + 2 * compressed_spec_mat[i*30+2] * compressed_spec_mat[i*30+2]
245 298 + 2 * compressed_spec_mat[i*30+3] * compressed_spec_mat[i*30+3]
246 299 + 2 * compressed_spec_mat[i*30+4] * compressed_spec_mat[i*30+4]
247 300 + 2 * compressed_spec_mat[i*30+5] * compressed_spec_mat[i*30+5]
248 301 + 2 * compressed_spec_mat[i*30+12] * compressed_spec_mat[i*30+12]
249 302 + 2 * compressed_spec_mat[i*30+13] * compressed_spec_mat[i*30+13];
250 303 }
251 304 aux = PSDB*PSDB;
252 305 tmp = sqrt( abs( ( 3*tr_SB_SB - aux ) / ( 2 * aux ) ) );
253 306 tmp_u_char = (unsigned char) (NVEC_V0*(8-1));
254 307 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | (tmp_u_char & 0x07); // keeps 3 bits of the resulting unsigned char
255 308 //=======================================================================================
256 309 // BP1 x-component of the normalized Poynting flux == PAR_LFR_SC_BP1_SZ_F0 == 8 bits (7+1)
257 310 sx_re = compressed_spec_mat[i*30+20] * k34_sx_re
258 311 + compressed_spec_mat[i*30+6] * k14_sx_re
259 312 + compressed_spec_mat[i*30+8] * k15_sx_re
260 313 + compressed_spec_mat[i*30+14] * k24_sx_re
261 314 + compressed_spec_mat[i*30+16] * k25_sx_re
262 315 + compressed_spec_mat[i*30+22] * k35_sx_re;
263 316 sx_im = compressed_spec_mat[i*30+21] * k34_sx_im
264 317 + compressed_spec_mat[i*30+7] * k14_sx_im
265 318 + compressed_spec_mat[i*30+9] * k15_sx_im
266 319 + compressed_spec_mat[i*30+15] * k24_sx_im
267 320 + compressed_spec_mat[i*30+17] * k25_sx_im
268 321 + compressed_spec_mat[i*30+23] * k35_sx_im;
269 322 LFR_BP1[i*9+7] = ((unsigned char) (sx_re * 128)) & 0x7f; // cf DOC for the compression
270 323 if ( abs(sx_re) > abs(sx_im) )
271 324 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] | (0x80); // extract the sector of sx
272 325 else
273 326 LFR_BP1[i*9+7] = LFR_BP1[i*9+1] & (0x7f); // extract the sector of sx
274 327 //======================================================================
275 328 // BP1 phase velocity estimator == PAR_LFR_SC_BP1_VPHI_F0 == 8 bits (7+1)
276 329 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
277 330 nz = NVEC_V0;
278 331 bx_bx_star = cos(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+10] // re S22
279 332 + sin(alpha_M) * sin(alpha_M) * compressed_spec_mat[i*30+18] // re S33
280 333 - 2 * sin(alpha_M) * cos(alpha_M) * compressed_spec_mat[i*30+12]; // re S23
281 334 nebx_re = ny * (compressed_spec_mat[i*30+14] * k24_ny_re
282 335 +compressed_spec_mat[i*30+16] * k25_ny_re
283 336 +compressed_spec_mat[i*30+20] * k34_ny_re
284 337 +compressed_spec_mat[i*30+22] * k35_ny_re)
285 338 + nz * (compressed_spec_mat[i*30+14] * k24_nz_re
286 339 +compressed_spec_mat[i*30+16] * k25_nz_re
287 340 +compressed_spec_mat[i*30+20] * k34_nz_re
288 341 +compressed_spec_mat[i*30+22] * k35_nz_re);
289 342 nebx_im = ny * (compressed_spec_mat[i*30+15]*k24_ny_re
290 343 +compressed_spec_mat[i*30+17] * k25_ny_re
291 344 +compressed_spec_mat[i*30+21] * k34_ny_re
292 345 +compressed_spec_mat[i*30+23] * k35_ny_re)
293 346 + nz * (compressed_spec_mat[i*30+15] * k24_nz_im
294 347 +compressed_spec_mat[i*30+17] * k25_nz_im
295 348 +compressed_spec_mat[i*30+21] * k34_nz_im
296 349 +compressed_spec_mat[i*30+23] * k35_nz_im);
297 350 tmp = nebx_re / bx_bx_star;
298 351 LFR_BP1[i*9+8] = ((unsigned char) (tmp * 128)) & 0x7f; // cf DOC for the compression
299 352 if ( abs(nebx_re) > abs(nebx_im) )
300 353 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] | (0x80); // extract the sector of nebx
301 354 else
302 355 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] & (0x7f); // extract the sector of nebx
303 356 }
304 357
305 358 }
306 359
307 360 void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat){
308 361 // BP2 autocorrelation
309 362 int i, aux = 0;
310 363 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
311 364 // S12
312 365 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+10]);
313 366 compressed_spec_mat[i*30+2] = compressed_spec_mat[i*30+2] / aux;
314 367 compressed_spec_mat[i*30+3] = compressed_spec_mat[i*30+3] / aux;
315 368 // S13
316 369 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+18]);
317 370 compressed_spec_mat[i*30+4] = compressed_spec_mat[i*30+4] / aux;
318 371 compressed_spec_mat[i*30+5] = compressed_spec_mat[i*30+5] / aux;
319 372 // S23
320 373 aux = sqrt(compressed_spec_mat[i*30+12]*compressed_spec_mat[i*30+18]);
321 374 compressed_spec_mat[i*30+12] = compressed_spec_mat[i*30+12] / aux;
322 375 compressed_spec_mat[i*30+13] = compressed_spec_mat[i*30+13] / aux;
323 376 // S45
324 377 aux = sqrt(compressed_spec_mat[i*30+24]*compressed_spec_mat[i*30+28]);
325 378 compressed_spec_mat[i*30+26] = compressed_spec_mat[i*30+26] / aux;
326 379 compressed_spec_mat[i*30+27] = compressed_spec_mat[i*30+27] / aux;
327 380 // S14
328 381 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]);
329 382 compressed_spec_mat[i*30+6] = compressed_spec_mat[i*30+6] / aux;
330 383 compressed_spec_mat[i*30+7] = compressed_spec_mat[i*30+7] / aux;
331 384 // S15
332 385 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+28]);
333 386 compressed_spec_mat[i*30+8] = compressed_spec_mat[i*30+8] / aux;
334 387 compressed_spec_mat[i*30+9] = compressed_spec_mat[i*30+9] / aux;
335 388 // S24
336 389 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+24]);
337 390 compressed_spec_mat[i*30+14] = compressed_spec_mat[i*30+14] / aux;
338 391 compressed_spec_mat[i*30+15] = compressed_spec_mat[i*30+15] / aux;
339 392 // S25
340 393 aux = sqrt(compressed_spec_mat[i*10]*compressed_spec_mat[i*30+28]);
341 394 compressed_spec_mat[i*30+16] = compressed_spec_mat[i*30+16] / aux;
342 395 compressed_spec_mat[i*30+17] = compressed_spec_mat[i*30+17] / aux;
343 396 // S34
344 397 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+24]);
345 398 compressed_spec_mat[i*30+20] = compressed_spec_mat[i*30+20] / aux;
346 399 compressed_spec_mat[i*30+21] = compressed_spec_mat[i*30+21] / aux;
347 400 // S35
348 401 aux = sqrt(compressed_spec_mat[i*18]*compressed_spec_mat[i*30+28]);
349 402 compressed_spec_mat[i*30+22] = compressed_spec_mat[i*30+22] / aux;
350 403 compressed_spec_mat[i*30+23] = compressed_spec_mat[i*30+23] / aux;
351 404 }
352 405 }
353
354 rtems_task avf0_task(rtems_task_argument argument){
355 int i;
356 static int nb_average;
357 rtems_event_set event_out;
358 rtems_status_code status;
359 406
360 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
361 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
362 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
363
364 nb_average = 0;
365
366 PRINTF("In AVFO *** \n")
367
368 while(1){
369 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
370 for(i=0; i<TOTAL_SIZE_SPEC_MAT; i++){
371 averaged_spec_mat_f0[i] = averaged_spec_mat_f0[i] + spec_mat_f0_a[i]
372 + spec_mat_f0_b[i]
373 + spec_mat_f0_c[i]
374 + spec_mat_f0_d[i]
375 + spec_mat_f0_e[i]
376 + spec_mat_f0_f[i]
377 + spec_mat_f0_g[i]
378 + spec_mat_f0_h[i];
379 }
380 spectral_matrices_regs->ctrl = spectral_matrices_regs->ctrl & 0xfffffffe; // reset the appropriate bit in the register
381 nb_average = nb_average + NB_SM_TO_RECEIVE_BEFORE_AVF0;
382 if (nb_average == NB_AVERAGE_NORMAL_f0) {
383 nb_average = 0;
384 status = rtems_event_send( Task_id[7], RTEMS_EVENT_0 ); // sending an event to the task 7, BPF0
385 if (status != RTEMS_SUCCESSFUL) printf("IN TASK AVF0 *** Error sending RTEMS_EVENT_0, code %d\n", status);
386 }
387 }
388 }
389
390 rtems_task bpf0_task(rtems_task_argument argument){
391 rtems_event_set event_out;
392
393 PRINTF("In BPFO *** \n")
394
395 while(1){
396 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
397 matrix_compression(averaged_spec_mat_f0, 0, compressed_spec_mat_f0);
398 BP1_set(compressed_spec_mat_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_F0);
399 //PRINTF("IN TASK BPF0 *** Matrix compressed, parameters calculated\n")
400 }
401 }
402
403 //*******
404 // UNUSED
405 rtems_task spw_bppr_task_rate_monotonic(rtems_task_argument argument)
406 {/*
407 rtems_status_code status;
408 //static int nb_average_f1 = 0;
409 //static int nb_average_f2 = 0;
410
411 rtems_name name;
412 rtems_id period;
413 name = rtems_build_name( 'P', 'E', 'R', 'D' );
414 status = rtems_rate_monotonic_create( name, &period );
415 if( status != RTEMS_SUCCESSFUL ) {
416 printf( "rtems_rate_monotonic_create failed with status of %d\n", status );
417 //exit( 1 );
418 }
419
420 spectral_matrices_regs = (struct spectral_matrices_regs_str *) REGS_ADDR_SPECTRAL_MATRICES;
421 spectral_matrices_regs->address0 = (volatile int) spec_mat_f0_a;
422 spectral_matrices_regs->address1 = (volatile int) spec_mat_f0_b;
423
424 printf("In BPPR BIS ***\n");
425
426 while(1){ // launch the rate monotonic task
427 if ( rtems_rate_monotonic_period( period, 8 ) == RTEMS_TIMEOUT ){
428 printf("TIMEOUT\n");
429 //break;
430 }
431 status = rtems_event_send( Task_id[6], RTEMS_EVENT_0 ); // sending an event to the task 6, AVF0
432 if (status != RTEMS_SUCCESSFUL) printf("IN TASK BPPR BIS *** Error sending RTEMS_EVENT_0 to AVF0, code %d\n", status);
433 }
434
435 status = rtems_rate_monotonic_delete( period );
436 if ( status != RTEMS_SUCCESSFUL ) {
437 printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
438 //exit( 1 );
439 }
440 status = rtems_task_delete( RTEMS_SELF ); // should not return
441 printf( "rtems_task_delete returned with status of %d.\n", status );
442 //exit( 1 );*/
443 }
444
445
446
447
@@ -1,531 +1,582
1 1 #include <tc_handler.h>
2 2 #include <fsw_params.h>
3 3
4 4 char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
5 5 "WRONG_LEN_PACKET 1",
6 6 "INCOR_CHECKSUM 2",
7 7 "ILL_TYPE 3",
8 8 "ILL_SUBTYPE 4",
9 9 "WRONG_APP_DATA 5",
10 10 "WRONG_CMD_CODE 6",
11 11 "CCSDS_TM_VALID 7"
12 12 };
13 13
14 14 //**********************
15 15 // GENERAL USE FUNCTIONS
16 16 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 17 {
18 18 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
19 19 }
20 20
21 21 void initLookUpTableForCRC()
22 22 {
23 23 unsigned int i, tmp;
24 24 for (i=0; i<256; i++)
25 25 {
26 26 tmp = 0;
27 27 if((i & 1) != 0) tmp = tmp ^ 0x1021;
28 28 if((i & 2) != 0) tmp = tmp ^ 0x2042;
29 29 if((i & 4) != 0) tmp = tmp ^ 0x4084;
30 30 if((i & 8) != 0) tmp = tmp ^ 0x8108;
31 31 if((i & 16) != 0) tmp = tmp ^ 0x1231;
32 32 if((i & 32) != 0) tmp = tmp ^ 0x2462;
33 33 if((i & 64) != 0) tmp = tmp ^ 0x48c4;
34 34 if((i & 128) != 0) tmp = tmp ^ 0x9188;
35 35 lookUpTableForCRC[i] = tmp;
36 36 }
37 37 }
38 38
39 39 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
40 40 {
41 41 unsigned int Chk;
42 42 int j;
43 43 Chk = 0xffff; // reset the syndrom to all ones
44 44 for (j=0; j<sizeOfData; j++) {
45 45 Chk = Crc_opt(data[j], Chk);
46 46 }
47 47 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
48 48 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
49 49 }
50 50
51
52 51 //*********************
53 52 // ACCEPTANCE FUNCTIONS
54 53 int TC_checker(ccsdsTelecommandPacket_t *TC, unsigned int tc_len_recv)
55 54 {
56 55 rtems_status_code status;
57 56 spw_ioctl_pkt_send spw_ioctl_send;
58 57 TMHeader_t TM_header;
59 58 unsigned int code = 0;
60 59 unsigned char computed_CRC[2];
61 60 char data[ TM_LEN_EXE_CORR + CCSDS_TC_TM_PACKET_OFFSET - TM_HEADER_LEN ];
62 61
63 62 GetCRCAsTwoBytes( (unsigned char*) TC->packetID, computed_CRC, tc_len_recv + 5 );
64 63 code = acceptTM( TC, tc_len_recv ) ;
65 64 if ( (code == 0) | (code == 1) | (code == 2)
66 65 | (code == 3) | (code == 4) | (code == 5) )
67 66 { // generate TM_LFR_TC_EXE_CORRUPTED
68 67 // BUILD HEADER
69 68 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_EXE_CORR, 0, 0, &TM_header);
70 69 // BUILD DATA
71 70 TM_build_data( TC, data, SID_EXE_CORR, computed_CRC);
72 71 // PREPARE TM SENDING
73 72 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
74 73 spw_ioctl_send.hdr = (char*) &TM_header;
75 74 spw_ioctl_send.dlen = 16;
76 75 spw_ioctl_send.data = data;
77 76 // SEND PACKET
78 77 write_spw(&spw_ioctl_send);
79 78 }
80 79 else { // send valid TC to the action launcher
81 80 status = rtems_message_queue_send( misc_id[0], TC, tc_len_recv + CCSDS_TC_TM_PACKET_OFFSET + 3);
82 81 return -1;
83 82 }
84 83 return -1;
85 84 }
86 85
87 86 unsigned char acceptTM(ccsdsTelecommandPacket_t * TMPacket, unsigned int TC_LEN_RCV)
88 87 {
89 88 unsigned char pid = 0;
90 89 unsigned char category = 0;
91 90 unsigned int length = 0;
92 91 unsigned char packetType = 0;
93 92 unsigned char packetSubtype = 0;
94 93 unsigned char * CCSDSContent;
95 94
96 95 // APID check *** APID on 2 bytes
97 96 pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
98 97 category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
99 98 if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
100 99 if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
101 100
102 101 // packet length check
103 102 length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
104 103 if (length != TC_LEN_RCV ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
105 104 if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
106 105
107 106 packetType = TMPacket->dataFieldHeader[1];
108 107 packetSubtype = TMPacket->dataFieldHeader[2];
109 108 // service type, subtype and packet length check
110 109 if (packetType == 181){
111 110 switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
112 111 case 3:
113 112 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
114 113 break;
115 114 case 20:
116 115 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
117 116 break;
118 117 case 21:
119 118 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
120 119 break;
121 120 case 24:
122 121 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
123 122 break;
124 123 case 27:
125 124 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
126 125 break;
127 126 case 28:
128 127 if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
129 128 break;
130 129 case 30:
131 130 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
132 131 break;
133 132 case 40:
134 133 if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
135 134 break;
136 135 case 50:
137 136 if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
138 137 break;
139 138 case 60:
140 139 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
141 140 break;
142 141 case 61:
143 142 if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
144 143 break;
145 144 default:
146 145 return ILL_SUBTYPE;
147 146 break;
148 147 }
149 148 }
150 149 else if (packetType == 9){
151 150 if (packetSubtype!=129) return ILL_SUBTYPE;
152 151 if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
153 152 }
154 153 else return ILL_TYPE;
155 154
156 155 // source ID check // Source ID not documented in the ICD
157 156
158 157 // packet error control, CRC check
159 158 CCSDSContent = (unsigned char*) TMPacket->packetID;
160 159 GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
161 160 if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
162 161 if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
163 162
164 163 return CCSDS_TM_VALID;
165 164 }
166 165
167 166 unsigned char TM_build_header( enum TM_TYPE tm_type, unsigned int packetLength,
168 167 unsigned int coarseTime, unsigned int fineTime, TMHeader_t *TMHeader)
169 168 {
170 169 TMHeader->targetLogicalAddress = CCSDS_DESTINATION_ID;
171 170 TMHeader->protocolIdentifier = 0x02;
172 171 TMHeader->reserved = 0x00;
173 172 TMHeader->userApplication = 0x00;
174 173 TMHeader->packetID[0] = 0x0c;
175 174 TMHeader->packetSequenceControl[0] = 0xc0;
176 175 TMHeader->packetSequenceControl[1] = 0x00;
177 176 TMHeader->packetLength[0] = (unsigned char) (packetLength>>8);
178 177 TMHeader->packetLength[1] = (unsigned char) packetLength;
179 178 TMHeader->dataFieldHeader[0] = 0x10;
180 179 TMHeader->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
181 180 switch (tm_type){
182 181 case(TM_LFR_TC_EXE_OK):
183 182 TMHeader->packetID[1] = 0xc1;
184 183 TMHeader->dataFieldHeader[1] = 1; // type
185 184 TMHeader->dataFieldHeader[2] = 7; // subtype
186 185 break;
187 186 case(TM_LFR_TC_EXE_ERR):
188 187 TMHeader->packetID[1] = 0xc1;
189 188 TMHeader->dataFieldHeader[1] = 1; // type
190 189 TMHeader->dataFieldHeader[2] = 8; // subtype
191 190 break;
192 191 case(TM_LFR_HK):
193 192 TMHeader->packetID[1] = 0xc4;
194 193 TMHeader->dataFieldHeader[1] = 3; // type
195 194 TMHeader->dataFieldHeader[2] = 25; // subtype
196 195 break;
197 196 case(TM_LFR_SCI):
198 197 TMHeader->packetID[1] = 0xcc;
199 198 TMHeader->dataFieldHeader[1] = 21; // type
200 199 TMHeader->dataFieldHeader[2] = 3; // subtype
201 200 break;
202 201 case(TM_LFR_SCI_SBM):
203 202 TMHeader->packetID[1] = 0xfc;
204 203 TMHeader->dataFieldHeader[1] = 21; // type
205 204 TMHeader->dataFieldHeader[2] = 3; // subtype
206 205 break;
207 206 case(TM_LFR_PAR_DUMP):
208 207 TMHeader->packetID[1] = 0xc9;
209 208 TMHeader->dataFieldHeader[1] = 181; // type
210 209 TMHeader->dataFieldHeader[2] = 31; // subtype
211 210 break;
212 211 default:
213 212 return 0;
214 213 }
215 214 TMHeader->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
216 215 TMHeader->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
217 216 TMHeader->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
218 217 TMHeader->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
219 218 TMHeader->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
220 219 TMHeader->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
221 220 return 1;
222 221 }
223 222
223 unsigned char TM_build_header_bis( enum TM_TYPE tm_type, unsigned int packetLength,
224 unsigned int coarseTime, unsigned int fineTime, Packet_TM_LFR_TC_EXE_t *packet)
225 {
226
227 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
228 packet->protocolIdentifier = 0x02;
229 packet->reserved = 0x00;
230 packet->userApplication = 0x00;
231 packet->packetID[0] = 0x0c;
232 packet->packetSequenceControl[0] = 0xc0;
233 packet->packetSequenceControl[1] = 0x00;
234 packet->packetLength[0] = (unsigned char) (packetLength>>8);
235 packet->packetLength[1] = (unsigned char) packetLength;
236 packet->dataFieldHeader[0] = 0x10;
237 packet->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
238 switch (tm_type){
239 case(TM_LFR_TC_EXE_OK):
240 packet->packetID[1] = 0xc1;
241 packet->dataFieldHeader[1] = 1; // type
242 packet->dataFieldHeader[2] = 7; // subtype
243 break;
244 case(TM_LFR_TC_EXE_ERR):
245 packet->packetID[1] = 0xc1;
246 packet->dataFieldHeader[1] = 1; // type
247 packet->dataFieldHeader[2] = 8; // subtype
248 break;
249 case(TM_LFR_HK):
250 packet->packetID[1] = 0xc4;
251 packet->dataFieldHeader[1] = 3; // type
252 packet->dataFieldHeader[2] = 25; // subtype
253 break;
254 case(TM_LFR_SCI):
255 packet->packetID[1] = 0xcc;
256 packet->dataFieldHeader[1] = 21; // type
257 packet->dataFieldHeader[2] = 3; // subtype
258 break;
259 case(TM_LFR_SCI_SBM):
260 packet->packetID[1] = 0xfc;
261 packet->dataFieldHeader[1] = 21; // type
262 packet->dataFieldHeader[2] = 3; // subtype
263 break;
264 case(TM_LFR_PAR_DUMP):
265 packet->packetID[1] = 0xc9;
266 packet->dataFieldHeader[1] = 181; // type
267 packet->dataFieldHeader[2] = 31; // subtype
268 break;
269 default:
270 return 0;
271 }
272 packet->dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
273 packet->dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
274 packet->dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
275 packet->dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
276 packet->dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
277 packet->dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
278 return 1;
279 }
280
224 281 unsigned char TM_build_data(ccsdsTelecommandPacket_t *TC, char* data, unsigned int SID, unsigned char *computed_CRC)
225 282 {
226 283 unsigned int packetLength;
227 284 packetLength = TC->packetLength[0] * 256 + TC->packetLength[1];
228 285 switch (SID){
229 286 case (SID_NOT_EXE):
230 287 break;
231 288 case (SID_NOT_IMP):
232 289 data[0] = 0x9c;
233 290 data[1] = 0x42;
234 291 data[2] = TC->packetID[0];
235 292 data[3] = TC->packetID[1];
236 293 data[4] = TC->packetSequenceControl[0];
237 294 data[5] = TC->packetSequenceControl[1];
238 295 data[6] = TC->dataFieldHeader[1]; // type
239 296 data[7] = TC->dataFieldHeader[2]; // subtype
240 297 break;
241 298 case (SID_EXE_ERR):
242 299 break;
243 300 case (SID_EXE_CORR):
244 301 data[0] = 0x9c;
245 302 data[1] = 0x45;
246 303 data[2] = TC->packetID[0];
247 304 data[3] = TC->packetID[1];
248 305 data[4] = TC->packetSequenceControl[0];
249 306 data[5] = TC->packetSequenceControl[1];
250 307 data[6] = TC->dataFieldHeader[1]; // type
251 308 data[7] = TC->dataFieldHeader[2]; // subtype
252 309 data[8] = currentTC_LEN_RCV[0];
253 310 data[9] = currentTC_LEN_RCV[1];
254 311 data[10] = TC->packetLength[0];
255 312 data[11] = TC->packetLength[1];
256 313 data[12] = TC->dataAndCRC[packetLength];
257 314 data[13] = TC->dataAndCRC[packetLength+1];
258 315 data[14] = computed_CRC[0];
259 316 data[15] = computed_CRC[1];
260 317 break;
261 318 default:
262 319 return 0;
263 320 }
264 321 return 1;
265 322 }
266 323
324 int create_message_queue()
325 {
326 rtems_status_code status;
327 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
328 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
329 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
330 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
331
332 return 0;
333 }
334
267 335 //***********
268 336 // RTEMS TASK
269 337 rtems_task recv_task( rtems_task_argument unused )
270 338 {
271 339 int len = 0;
272 340 unsigned int i = 0;
273 341 unsigned int data_length = 0;
274 342 ccsdsTelecommandPacket_t currentTC;
275 343 char data[100];
276 344
277 345 for(i=0; i<100; i++) data[i] = 0;
278 346
279 PRINTF("In RECV *** \n")
347 PRINTF("in RECV *** \n")
280 348
281 349 while(1)
282 350 {
283 351 len = read(fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE); // the call to read is blocking
284 352 if (len == -1){ // error during the read call
285 353 PRINTF("In RECV *** last read call returned -1\n")
286 354 if (rtems_event_send( Task_id[3], SPW_LINKERR_EVENT ) != RTEMS_SUCCESSFUL)
287 355 PRINTF("IN RECV *** Error: rtems_event_send SPW_LINKERR_EVENT\n")
288 356 if (rtems_task_suspend(RTEMS_SELF) != RTEMS_SUCCESSFUL)
289 357 PRINTF("In RECV *** Error: rtems_task_suspend(RTEMS_SELF)\n")
290 358 }
291 359 else {
292 360 PRINTF1("Got pck of length %d\n", len+1)
293 361 currentTC_LEN_RCV[0] = 0x00;
294 362 currentTC_LEN_RCV[1] = (unsigned char) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // build the corresponding packet size field
295 363 currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) len - CCSDS_TC_TM_PACKET_OFFSET - 3; // => -3 is for Prot ID, Reserved and User App bytes
296 364 // CHECK THE TC AND BUILD THE APPROPRIATE TM
297 365 data_length = TC_checker(&currentTC, currentTC_LEN_RCV_AsUnsignedInt);
298 366 if (data_length!=-1)
299 367 {
300 368 }
301 369 }
302 370 }
303 371 }
304 372
305 373 rtems_task actn_task( rtems_task_argument unused )
306 374 {
307 375 int result = 0;
308 376 rtems_status_code status; // RTEMS status code
309 377 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
310 378 size_t size; // size of the incoming TC packet
311 379 unsigned char subtype = 0; // subtype of the current TC packet
312 380
313 PRINTF("In ACTN *** \n")
381 PRINTF("in ACTN *** \n")
314 382
315 383 while(1)
316 384 {
317 385 status = rtems_message_queue_receive(misc_id[0], (char*) &TC, &size,
318 386 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
319 387 if (status!=RTEMS_SUCCESSFUL) PRINTF1("in task ACTN *** error receiving a message, code %d \n", status)
320 388 else
321 389 {
322 390 subtype = TC.dataFieldHeader[2];
323 391 switch(subtype)
324 392 {
325 393 case TC_SUBTYPE_RESET:
326 394 result = action_default( &TC );
327 395 break;
328 396 //
329 397 case TC_SUBTYPE_LOAD_COMM:
330 398 result = action_default( &TC );
331 399 break;
332 400 //
333 401 case TC_SUBTYPE_LOAD_NORM:
334 402 result = action_load_norm( &TC );
335 403 send_tm_lfr_tc_exe_success( &TC );
336 404 break;
337 405 //
338 406 case TC_SUBTYPE_LOAD_BURST:
339 407 result = action_default( &TC );
340 408 break;
341 409 //
342 410 case TC_SUBTYPE_LOAD_SBM1:
343 411 result = action_default( &TC );
344 412 break;
345 413 //
346 414 case TC_SUBTYPE_LOAD_SBM2:
347 415 result = action_default( &TC );
348 416 break;
349 417 //
350 418 case TC_SUBTYPE_DUMP:
351 419 result = action_default( &TC );
352 420 break;
353 421 //
354 422 case TC_SUBTYPE_ENTER:
355 423 result = action_enter( &TC );
356 424 send_tm_lfr_tc_exe_success( &TC );
357 425 break;
358 426 //
359 427 case TC_SUBTYPE_UPDT_INFO:
360 428 result = action_default( &TC );
361 429 break;
362 430 //
363 431 case TC_SUBTYPE_EN_CAL:
364 432 result = action_default( &TC );
365 433 break;
366 434 //
367 435 case TC_SUBTYPE_DIS_CAL:
368 436 result = action_default( &TC );
369 437 break;
370 438 //
371 439 case TC_SUBTYPE_UPDT_TIME:
372 440 result = action_updt_time( &TC );
373 441 send_tm_lfr_tc_exe_success( &TC );
374 442 break;
375 443 //
376 444 default:
377 445 break;
378 446 }
379 447 }
380 448 }
381 449 }
382 450
383 int create_message_queue()
451 rtems_task dumb_task( rtems_task_argument unused )
384 452 {
385 rtems_status_code status;
386 misc_name[0] = rtems_build_name( 'Q', 'U', 'E', 'U' );
387 status = rtems_message_queue_create( misc_name[0], ACTION_MSG_QUEUE_COUNT, CCSDS_TC_PKT_MAX_SIZE,
388 RTEMS_FIFO | RTEMS_LOCAL, &misc_id[0] );
389 if (status!=RTEMS_SUCCESSFUL) PRINTF("in create_message_queue *** error creating message queue\n")
453 unsigned int coarse_time;
454 unsigned int fine_time;
455 rtems_event_set event_out;
456
457 PRINTF("in DUMB *** \n")
390 458
391 return 0;
459 while(1){
460 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
461 coarse_time = time_management_regs->coarse_time;
462 fine_time = time_management_regs->fine_time;
463 printf("in DUMB *** coarse time = %x, fine time = %x\n", coarse_time, fine_time);
464 }
392 465 }
393 466
394 467 //***********
395 468 // TC ACTIONS
396 469
397 470 int action_default(ccsdsTelecommandPacket_t *TC)
398 471 {
399 TMHeader_t TM_header;
400 char data[8];
401 spw_ioctl_pkt_send spw_ioctl_send;
472 Packet_TM_LFR_TC_EXE_t packet;
402 473
403 TM_build_header( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
404 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
474 TM_build_header_bis( TM_LFR_TC_EXE_ERR, TM_LEN_NOT_IMP,
475 time_management_regs->coarse_time, time_management_regs->fine_time, &packet);
405 476
406 data[0] = 0x9c;
407 data[1] = 0x42;
408 data[2] = TC->packetID[0];
409 data[3] = TC->packetID[1];
410 data[4] = TC->packetSequenceControl[0];
411 data[5] = TC->packetSequenceControl[1];
412 data[6] = TC->dataFieldHeader[1]; // type
413 data[7] = TC->dataFieldHeader[2]; // subtype
414
415 // filling the structure for the spacewire transmission
416 spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header
417 spw_ioctl_send.hdr = (char*) &TM_header;
418 spw_ioctl_send.dlen = 8;
419 spw_ioctl_send.data = data;
477 packet.data[0] = 0x9c;
478 packet.data[1] = 0x42;
479 packet.data[2] = TC->packetID[0];
480 packet.data[3] = TC->packetID[1];
481 packet.data[4] = TC->packetSequenceControl[0];
482 packet.data[5] = TC->packetSequenceControl[1];
483 packet.data[6] = TC->dataFieldHeader[1]; // type
484 packet.data[7] = TC->dataFieldHeader[2]; // subtype
420 485
421 486 // SEND DATA
422 write_spw(&spw_ioctl_send);
487 if (write ( fdSPW, &packet, LEN_TM_LFR_TC_EXE_NOT_IMP)==-1)
488 PRINTF("ERR *** in action_default *** send TM packet\n");
423 489
424 490 return 0;
425 491 }
426 492
427 493 int action_enter(ccsdsTelecommandPacket_t *TC)
428 494 {
429 495 unsigned char lfr_mode = TC->dataAndCRC[1];
430 496 printf("enter mode %d\n", lfr_mode);
431 497 switch(lfr_mode)
432 498 {
433 499 case(LFR_MODE_STANDBY):
434 500 LEON_Mask_interrupt( IRQ_WF );
435 501 LEON_Mask_interrupt( IRQ_SM );
436 502 break;
437 503 case(LFR_MODE_NORMAL):
438 504 LEON_Unmask_interrupt( IRQ_WF );
439 505 LEON_Unmask_interrupt( IRQ_SM );
440 506 break;
441 507 case(LFR_MODE_BURST):
442 508 break;
443 509 case(LFR_MODE_SBM1):
444 510 break;
445 511 case(LFR_MODE_SBM2):
446 512 break;
447 513 }
448 514 return 0;
449 515 }
450 516
451 517 int action_load_norm(ccsdsTelecommandPacket_t *TC)
452 518 {
453 519 param_norm.sy_lfr_n_swf_l = TC->dataAndCRC[0] * 256 + TC->dataAndCRC[1];
454 520 param_norm.sy_lfr_n_swf_p = TC->dataAndCRC[2] * 256 + TC->dataAndCRC[3];
455 521 param_norm.sy_lfr_n_asm_p = TC->dataAndCRC[4] * 256 + TC->dataAndCRC[5];
456 522 param_norm.sy_lfr_n_bp_p0 = TC->dataAndCRC[6];
457 523 param_norm.sy_lfr_n_bp_p1 = TC->dataAndCRC[7];
458 524 /*printf("sy_lfr_n_ => swf_l %d, swf_p %d, asm_p %d, bsp_p0 %d, bsp_p1 %d\n",
459 525 param_norm.sy_lfr_n_swf_l, param_norm.sy_lfr_n_swf_p,
460 526 param_norm.sy_lfr_n_asm_p, param_norm.sy_lfr_n_bp_p0, param_norm.sy_lfr_n_bp_p1);*/
461 527 return 0;
462 528 }
463 529
464 530 int action_updt_time(ccsdsTelecommandPacket_t *TC)
465 531 {
466 532 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
467 533 + (TC->dataAndCRC[1] << 16)
468 534 + (TC->dataAndCRC[2] << 8)
469 535 + TC->dataAndCRC[3];
470 536 //time_management_regs->ctrl = time_management_regs->ctrl | 1;
471 537 return 0;
472 538 }
473 539
474 540 int send_tm_lfr_tc_exe_success(ccsdsTelecommandPacket_t *TC)
475 541 {
476 542 TMHeader_t TM_header;
477 543 char data[4];
478 544 spw_ioctl_pkt_send spw_ioctl_send;
479 545
480 546 TM_build_header( TM_LFR_TC_EXE_OK, TM_LEN_EXE,
481 547 time_management_regs->coarse_time, time_management_regs->fine_time, &TM_header);
482 548
483 549 data[0] = TC->packetID[0];
484 550 data[1] = TC->packetID[1];
485 551 data[2] = TC->packetSequenceControl[0];
486 552 data[3] = TC->packetSequenceControl[1];
487 553
488 554 // filling the structure for the spacewire transmission
489 555 spw_ioctl_send.hlen = TM_HEADER_LEN + 3; // + 4 is for the protocole extra header
490 556 spw_ioctl_send.hdr = (char*) &TM_header;
491 557 spw_ioctl_send.dlen = 3;
492 558 spw_ioctl_send.data = data;
493 559
494 560 // SEND DATA
495 561 write_spw(&spw_ioctl_send);
496 562
497 563 return 0;
498 564 }
499 565
500 566 //***************************
501 567 // Interrupt Service Routines
502 568 rtems_isr commutation_isr1( rtems_vector_number vector )
503 569 {
504 570 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
505 571 printf("In commutation_isr1 *** Error sending event to DUMB\n");
506 572 }
507 573
508 574 rtems_isr commutation_isr2( rtems_vector_number vector )
509 575 {
510 576 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
511 577 printf("In commutation_isr2 *** Error sending event to DUMB\n");
512 578 }
513 579
514 rtems_task dumb_task( rtems_task_argument unused )
515 {
516 unsigned int coarse_time;
517 unsigned int fine_time;
518 rtems_event_set event_out;
519
520 PRINTF("In DUMB *** \n")
521
522 while(1){
523 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
524 coarse_time = time_management_regs->coarse_time;
525 fine_time = time_management_regs->fine_time;
526 printf("commutation_isr*, coarse time = %x, fine time = %x\n", coarse_time, fine_time);
527 }
528 }
529 580
530 581
531 582
@@ -1,115 +1,176
1 1 #include <wf_handler.h>
2 2
3 3 rtems_isr waveforms_isr( rtems_vector_number vector )
4 4 {
5 5 if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
6 6 printf("In waveforms_isr *** Error sending event to WFRM\n");
7 7 }
8 8
9 9 rtems_task wfrm_task(rtems_task_argument argument)
10 10 {
11 11 unsigned int length;
12 12 unsigned int i = 0;
13 13 spw_ioctl_pkt_send spw_ioctl_send;
14 14 rtems_event_set event_out;
15 15 gptimer_regs_t *gptimer_regs;
16 16 gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
17 17 ExtendedTMHeader_t header;
18 18
19 19 header.targetLogicalAddress = CCSDS_DESTINATION_ID;
20 20 header.protocolIdentifier = CCSDS_PROTOCOLE_ID;
21 21 header.reserved = 0x00;
22 22 header.userApplication = CCSDS_USER_APP;
23 23 header.packetID[0] = 0x0c;
24 24 header.packetID[1] = 0xcc;
25 25 header.packetSequenceControl[0] = 0x00;
26 26 header.packetSequenceControl[1] = 0x00;
27 27 header.packetLength[0] = 0x00;
28 28 header.packetLength[1] = 0x00;
29 29 header.dataFieldHeader[0] = 0x10;
30 30 header.dataFieldHeader[1] = 0x15; // service type
31 31 header.dataFieldHeader[2] = 0x03; // service subtype
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID;
32 header.dataFieldHeader[3] = CCSDS_DESTINATION_ID_GROUND;
33 33
34 34 header.auxiliaryHeader[0] = 0x00;
35 35 header.auxiliaryHeader[1] = 0x1f;
36 36 header.auxiliaryHeader[2] = 0x07; // PKT_CNT
37 37 header.auxiliaryHeader[3] = 0x00; // PKT_NR
38 38 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
39 39 header.auxiliaryHeader[5] = 0x00; // BLK_NR LSB
40 40
41 41 // BUILD THE PACKET HEADER
42 42 spw_ioctl_send.hlen = TM_HEADER_LEN + 4 + 6; // + 4 is for the protocole extra header, + 6 is for the auxiliary header
43 43 spw_ioctl_send.hdr = (char*) &header;
44 44
45 PRINTF("In WFRM *** \n")
45 PRINTF("in WFRM *** \n")
46 46
47 47 while(1){
48 48 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
49 49 header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24);
50 50 header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16);
51 51 header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8);
52 52 header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time);
53 53 header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8);
54 54 header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time);
55 55 for (i=0; i<7; i++) // send F0
56 56 {
57 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
57 58 // BUILD THE DATA
58 59 if (i==6) {
59 60 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
60 length = TM_LEN_SCI_NORM_SWF_340;
61 }
61 length = TM_LEN_SCI_NORM_SWF_8;
62 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
63 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
64 }
62 65 else {
63 66 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
64 length = TM_LEN_SCI_NORM_SWF_8;
67 length = TM_LEN_SCI_NORM_SWF_340;
68 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
69 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
65 70 }
66 71 spw_ioctl_send.data = (char*) &wf_snap_f0[i * 340 * NB_BYTES_SWF_BLK];
67 72 // BUILD THE HEADER
68 73 header.packetLength[0] = (unsigned char) (length>>8);
69 74 header.packetLength[1] = (unsigned char) (length);
70 75 header.auxiliaryHeader[0] = SID_NORM_SWF_F0; // SID
71 76 // SEND PACKET
72 77 write_spw(&spw_ioctl_send);
73 78 }
74 79 for (i=0; i<7; i++) // send F1
75 80 {
81 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
76 82 // BUILD THE DATA
77 83 if (i==6) {
78 84 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
79 length = TM_LEN_SCI_NORM_SWF_340;
80 }
85 length = TM_LEN_SCI_NORM_SWF_8;
86 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
87 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
88 }
81 89 else {
82 90 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
83 length = TM_LEN_SCI_NORM_SWF_8;
91 length = TM_LEN_SCI_NORM_SWF_340;
92 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
93 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
84 94 }
85 95 spw_ioctl_send.data = (char*) &wf_snap_f1[i * 340 * NB_BYTES_SWF_BLK];
86 96 // BUILD THE HEADER
87 97 header.packetLength[0] = (unsigned char) (length>>8);
88 98 header.packetLength[1] = (unsigned char) (length);
89 99 header.auxiliaryHeader[0] = SID_NORM_SWF_F1; // SID
90 100 // SEND PACKET
91 101 write_spw(&spw_ioctl_send);
92 102 }
93 for (i=0; i<7; i++) // send F0
103 for (i=0; i<7; i++) // send F2
94 104 {
105 header.auxiliaryHeader[3] = (unsigned char) i+1; // PKT_NR
95 106 // BUILD THE DATA
96 107 if (i==6) {
97 108 spw_ioctl_send.dlen = 8 * NB_BYTES_SWF_BLK;
98 length = TM_LEN_SCI_NORM_SWF_340;
99 }
109 length = TM_LEN_SCI_NORM_SWF_8;
110 header.auxiliaryHeader[4] = 0x00; // BLK_NR MSB
111 header.auxiliaryHeader[5] = 0x08; // BLK_NR LSB
112 }
100 113 else {
101 114 spw_ioctl_send.dlen = 340 * NB_BYTES_SWF_BLK;
102 length = TM_LEN_SCI_NORM_SWF_8;
115 length = TM_LEN_SCI_NORM_SWF_340;
116 header.auxiliaryHeader[4] = 0x01; // BLK_NR MSB
117 header.auxiliaryHeader[5] = 0x54; // BLK_NR LSB
103 118 }
104 119 spw_ioctl_send.data = (char*) &wf_snap_f2[i * 340 * NB_BYTES_SWF_BLK];
105 120 // BUILD THE HEADER
106 121 header.packetLength[0] = (unsigned char) (length>>8);
107 122 header.packetLength[1] = (unsigned char) (length);
108 123 header.auxiliaryHeader[0] = SID_NORM_SWF_F2; // SID
109 124 // SEND PACKET
110 125 write_spw(&spw_ioctl_send);
111 126 }
112 127 // irq processed, reset the related register of the timer unit
113 128 gptimer_regs->timer[2].ctrl = gptimer_regs->timer[2].ctrl | 0x00000010;
114 129 }
115 130 }
131
132 //******************
133 // general functions
134 void init_waveforms()
135 {
136 int i = 0;
137
138 for (i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
139 {
140 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and e1
141 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( 3*i, 4*i ); // e2 and b1
142 wf_snap_f0[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
143 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
144 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
145 wf_snap_f1[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
146 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
147 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
148 wf_snap_f2[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
149 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 0 ] = buil_value( i, 2*i ); // v and 1
150 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 1 ] = buil_value( i, 2*i ); // e2 and b1
151 wf_cont_f3[ i* NB_WORDS_SWF_BLK + 2 ] = buil_value( i, 2*i ); // b2 and b3
152 }
153 }
154
155 int buil_value(int value1, int value0)
156 {
157 int aux = 0;
158 int aux1 = 0;
159 int aux0 = 0;
160 //******
161 // B3 B2
162 aux1 = ( (int) ( (char) (value1 >> 8) ) << 8 )
163 + ( (int) ( (char) (value1 ) ) );
164
165 //******
166 // B1 B0
167 aux0 = ( (int) ( (char) (value0 >> 8) ) << 8 )
168 + ( (int) ( (char) (value0 ) ) );
169
170 aux = (aux1 << 16) + aux0;
171
172 return aux;
173 }
174
175
176
General Comments 0
You need to be logged in to leave comments. Login now