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