@@ -1,1412 +1,1422 | |||||
1 | /** Functions related to the SpaceWire interface. |
|
1 | /** Functions related to the SpaceWire interface. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | * A group of functions to handle SpaceWire transmissions: |
|
6 | * A group of functions to handle SpaceWire transmissions: | |
7 | * - configuration of the SpaceWire link |
|
7 | * - configuration of the SpaceWire link | |
8 | * - SpaceWire related interruption requests processing |
|
8 | * - SpaceWire related interruption requests processing | |
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task |
|
9 | * - transmission of TeleMetry packets by a dedicated RTEMS task | |
10 | * - reception of TeleCommands by a dedicated RTEMS task |
|
10 | * - reception of TeleCommands by a dedicated RTEMS task | |
11 | * |
|
11 | * | |
12 | */ |
|
12 | */ | |
13 |
|
13 | |||
14 | #include "fsw_spacewire.h" |
|
14 | #include "fsw_spacewire.h" | |
15 |
|
15 | |||
16 | rtems_name semq_name; |
|
16 | rtems_name semq_name; | |
17 | rtems_id semq_id; |
|
17 | rtems_id semq_id; | |
18 |
|
18 | |||
19 | //***************** |
|
19 | //***************** | |
20 | // waveform headers |
|
20 | // waveform headers | |
21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF; |
|
21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF; | |
22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF; |
|
22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF; | |
23 | Header_TM_LFR_SCIENCE_ASM_t headerASM; |
|
23 | Header_TM_LFR_SCIENCE_ASM_t headerASM; | |
24 |
|
24 | |||
25 | unsigned char previousTimecodeCtr = 0; |
|
25 | unsigned char previousTimecodeCtr = 0; | |
26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); |
|
26 | unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); | |
27 |
|
27 | |||
28 | //*********** |
|
28 | //*********** | |
29 | // RTEMS TASK |
|
29 | // RTEMS TASK | |
30 | rtems_task spiq_task(rtems_task_argument unused) |
|
30 | rtems_task spiq_task(rtems_task_argument unused) | |
31 | { |
|
31 | { | |
32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. |
|
32 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. | |
33 | * |
|
33 | * | |
34 | * @param unused is the starting argument of the RTEMS task |
|
34 | * @param unused is the starting argument of the RTEMS task | |
35 | * |
|
35 | * | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | rtems_event_set event_out; |
|
38 | rtems_event_set event_out; | |
39 | rtems_status_code status; |
|
39 | rtems_status_code status; | |
40 | int linkStatus; |
|
40 | int linkStatus; | |
41 |
|
41 | |||
42 | BOOT_PRINTF("in SPIQ *** \n") |
|
42 | BOOT_PRINTF("in SPIQ *** \n") | |
43 |
|
43 | |||
44 | while(true){ |
|
44 | while(true){ | |
45 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
45 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT | |
46 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") |
|
46 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") | |
47 |
|
47 | |||
48 | // [0] SUSPEND RECV AND SEND TASKS |
|
48 | // [0] SUSPEND RECV AND SEND TASKS | |
49 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); |
|
49 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); | |
50 | if ( status != RTEMS_SUCCESSFUL ) { |
|
50 | if ( status != RTEMS_SUCCESSFUL ) { | |
51 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") |
|
51 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") | |
52 | } |
|
52 | } | |
53 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); |
|
53 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); | |
54 | if ( status != RTEMS_SUCCESSFUL ) { |
|
54 | if ( status != RTEMS_SUCCESSFUL ) { | |
55 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") |
|
55 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | // [1] CHECK THE LINK |
|
58 | // [1] CHECK THE LINK | |
59 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) |
|
59 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) | |
60 | if ( linkStatus != 5) { |
|
60 | if ( linkStatus != 5) { | |
61 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) |
|
61 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) | |
62 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
62 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT |
|
65 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT | |
66 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) |
|
66 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) | |
67 | if ( linkStatus != 5 ) // [2.a] not in run state, reset the link |
|
67 | if ( linkStatus != 5 ) // [2.a] not in run state, reset the link | |
68 | { |
|
68 | { | |
69 | spacewire_compute_stats_offsets(); |
|
69 | spacewire_compute_stats_offsets(); | |
70 | status = spacewire_reset_link( ); |
|
70 | status = spacewire_reset_link( ); | |
71 | } |
|
71 | } | |
72 | else // [2.b] in run state, start the link |
|
72 | else // [2.b] in run state, start the link | |
73 | { |
|
73 | { | |
74 | status = spacewire_stop_and_start_link( fdSPW ); // start the link |
|
74 | status = spacewire_stop_and_start_link( fdSPW ); // start the link | |
75 | if ( status != RTEMS_SUCCESSFUL) |
|
75 | if ( status != RTEMS_SUCCESSFUL) | |
76 | { |
|
76 | { | |
77 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) |
|
77 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS |
|
81 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS | |
82 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully |
|
82 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully | |
83 | { |
|
83 | { | |
84 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
84 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
85 | if ( status != RTEMS_SUCCESSFUL ) { |
|
85 | if ( status != RTEMS_SUCCESSFUL ) { | |
86 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") |
|
86 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") | |
87 | } |
|
87 | } | |
88 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
88 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
89 | if ( status != RTEMS_SUCCESSFUL ) { |
|
89 | if ( status != RTEMS_SUCCESSFUL ) { | |
90 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") |
|
90 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 | else // [3.b] the link is not in run state, go in STANDBY mode |
|
93 | else // [3.b] the link is not in run state, go in STANDBY mode | |
94 | { |
|
94 | { | |
95 | status = enter_mode_standby(); |
|
95 | status = enter_mode_standby(); | |
96 | if ( status != RTEMS_SUCCESSFUL ) { |
|
96 | if ( status != RTEMS_SUCCESSFUL ) { | |
97 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) |
|
97 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) | |
98 | } |
|
98 | } | |
99 | // wake the WTDG task up to wait for the link recovery |
|
99 | // wake the WTDG task up to wait for the link recovery | |
100 | status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); |
|
100 | status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); | |
101 | status = rtems_task_suspend( RTEMS_SELF ); |
|
101 | status = rtems_task_suspend( RTEMS_SELF ); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | rtems_task recv_task( rtems_task_argument unused ) |
|
106 | rtems_task recv_task( rtems_task_argument unused ) | |
107 | { |
|
107 | { | |
108 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. |
|
108 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. | |
109 | * |
|
109 | * | |
110 | * @param unused is the starting argument of the RTEMS task |
|
110 | * @param unused is the starting argument of the RTEMS task | |
111 | * |
|
111 | * | |
112 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: |
|
112 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: | |
113 | * 1. It reads the incoming data. |
|
113 | * 1. It reads the incoming data. | |
114 | * 2. Launches the acceptance procedure. |
|
114 | * 2. Launches the acceptance procedure. | |
115 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. |
|
115 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. | |
116 | * |
|
116 | * | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | int len; |
|
119 | int len; | |
120 | ccsdsTelecommandPacket_t currentTC; |
|
120 | ccsdsTelecommandPacket_t currentTC; | |
121 | unsigned char computed_CRC[ 2 ]; |
|
121 | unsigned char computed_CRC[ 2 ]; | |
122 | unsigned char currentTC_LEN_RCV[ 2 ]; |
|
122 | unsigned char currentTC_LEN_RCV[ 2 ]; | |
123 | unsigned char destinationID; |
|
123 | unsigned char destinationID; | |
124 | unsigned int estimatedPacketLength; |
|
124 | unsigned int estimatedPacketLength; | |
125 | unsigned int parserCode; |
|
125 | unsigned int parserCode; | |
126 | rtems_status_code status; |
|
126 | rtems_status_code status; | |
127 | rtems_id queue_recv_id; |
|
127 | rtems_id queue_recv_id; | |
128 | rtems_id queue_send_id; |
|
128 | rtems_id queue_send_id; | |
129 |
|
129 | |||
130 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes |
|
130 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes | |
131 |
|
131 | |||
132 | status = get_message_queue_id_recv( &queue_recv_id ); |
|
132 | status = get_message_queue_id_recv( &queue_recv_id ); | |
133 | if (status != RTEMS_SUCCESSFUL) |
|
133 | if (status != RTEMS_SUCCESSFUL) | |
134 | { |
|
134 | { | |
135 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) |
|
135 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | status = get_message_queue_id_send( &queue_send_id ); |
|
138 | status = get_message_queue_id_send( &queue_send_id ); | |
139 | if (status != RTEMS_SUCCESSFUL) |
|
139 | if (status != RTEMS_SUCCESSFUL) | |
140 | { |
|
140 | { | |
141 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) |
|
141 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | BOOT_PRINTF("in RECV *** \n") |
|
144 | BOOT_PRINTF("in RECV *** \n") | |
145 |
|
145 | |||
146 | while(1) |
|
146 | while(1) | |
147 | { |
|
147 | { | |
148 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking |
|
148 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking | |
149 | if (len == -1){ // error during the read call |
|
149 | if (len == -1){ // error during the read call | |
150 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) |
|
150 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) | |
151 | } |
|
151 | } | |
152 | else { |
|
152 | else { | |
153 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { |
|
153 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { | |
154 | PRINTF("in RECV *** packet lenght too short\n") |
|
154 | PRINTF("in RECV *** packet lenght too short\n") | |
155 | } |
|
155 | } | |
156 | else { |
|
156 | else { | |
157 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes |
|
157 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes | |
158 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); |
|
158 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); | |
159 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); |
|
159 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); | |
160 | // CHECK THE TC |
|
160 | // CHECK THE TC | |
161 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; |
|
161 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; | |
162 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) |
|
162 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) | |
163 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) |
|
163 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) | |
164 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) |
|
164 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) | |
165 | || (parserCode == WRONG_SRC_ID) ) |
|
165 | || (parserCode == WRONG_SRC_ID) ) | |
166 | { // send TM_LFR_TC_EXE_CORRUPTED |
|
166 | { // send TM_LFR_TC_EXE_CORRUPTED | |
167 | PRINTF1("TC corrupted received, with code: %d\n", parserCode) |
|
167 | PRINTF1("TC corrupted received, with code: %d\n", parserCode) | |
168 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
168 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
169 | && |
|
169 | && | |
170 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
170 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
171 | ) |
|
171 | ) | |
172 | { |
|
172 | { | |
173 | if ( parserCode == WRONG_SRC_ID ) |
|
173 | if ( parserCode == WRONG_SRC_ID ) | |
174 | { |
|
174 | { | |
175 | destinationID = SID_TC_GROUND; |
|
175 | destinationID = SID_TC_GROUND; | |
176 | } |
|
176 | } | |
177 | else |
|
177 | else | |
178 | { |
|
178 | { | |
179 | destinationID = currentTC.sourceID; |
|
179 | destinationID = currentTC.sourceID; | |
180 | } |
|
180 | } | |
181 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, |
|
181 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, | |
182 | computed_CRC, currentTC_LEN_RCV, |
|
182 | computed_CRC, currentTC_LEN_RCV, | |
183 | destinationID ); |
|
183 | destinationID ); | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 | else |
|
186 | else | |
187 | { // send valid TC to the action launcher |
|
187 | { // send valid TC to the action launcher | |
188 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, |
|
188 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, | |
189 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); |
|
189 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); |
|
194 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); | |
195 |
|
195 | |||
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | rtems_task send_task( rtems_task_argument argument) |
|
199 | rtems_task send_task( rtems_task_argument argument) | |
200 | { |
|
200 | { | |
201 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. |
|
201 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. | |
202 | * |
|
202 | * | |
203 | * @param unused is the starting argument of the RTEMS task |
|
203 | * @param unused is the starting argument of the RTEMS task | |
204 | * |
|
204 | * | |
205 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: |
|
205 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: | |
206 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. |
|
206 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. | |
207 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After |
|
207 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After | |
208 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the |
|
208 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the | |
209 | * data it contains. |
|
209 | * data it contains. | |
210 | * |
|
210 | * | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | rtems_status_code status; // RTEMS status code |
|
213 | rtems_status_code status; // RTEMS status code | |
214 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
214 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer | |
215 | ring_node *incomingRingNodePtr; |
|
215 | ring_node *incomingRingNodePtr; | |
216 | int ring_node_address; |
|
216 | int ring_node_address; | |
217 | char *charPtr; |
|
217 | char *charPtr; | |
218 | spw_ioctl_pkt_send *spw_ioctl_send; |
|
218 | spw_ioctl_pkt_send *spw_ioctl_send; | |
219 | size_t size; // size of the incoming TC packet |
|
219 | size_t size; // size of the incoming TC packet | |
220 | rtems_id queue_send_id; |
|
220 | rtems_id queue_send_id; | |
221 | unsigned int sid; |
|
221 | unsigned int sid; | |
222 | unsigned char sidAsUnsignedChar; |
|
222 | unsigned char sidAsUnsignedChar; | |
223 | unsigned char type; |
|
223 | unsigned char type; | |
224 |
|
224 | |||
225 | incomingRingNodePtr = NULL; |
|
225 | incomingRingNodePtr = NULL; | |
226 | ring_node_address = 0; |
|
226 | ring_node_address = 0; | |
227 | charPtr = (char *) &ring_node_address; |
|
227 | charPtr = (char *) &ring_node_address; | |
228 | sid = 0; |
|
228 | sid = 0; | |
229 | sidAsUnsignedChar = 0; |
|
229 | sidAsUnsignedChar = 0; | |
230 |
|
230 | |||
231 | init_header_cwf( &headerCWF ); |
|
231 | init_header_cwf( &headerCWF ); | |
232 | init_header_swf( &headerSWF ); |
|
232 | init_header_swf( &headerSWF ); | |
233 | init_header_asm( &headerASM ); |
|
233 | init_header_asm( &headerASM ); | |
234 |
|
234 | |||
235 | status = get_message_queue_id_send( &queue_send_id ); |
|
235 | status = get_message_queue_id_send( &queue_send_id ); | |
236 | if (status != RTEMS_SUCCESSFUL) |
|
236 | if (status != RTEMS_SUCCESSFUL) | |
237 | { |
|
237 | { | |
238 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
238 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | BOOT_PRINTF("in SEND *** \n") |
|
241 | BOOT_PRINTF("in SEND *** \n") | |
242 |
|
242 | |||
243 | while(1) |
|
243 | while(1) | |
244 | { |
|
244 | { | |
245 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, |
|
245 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, | |
246 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
|
246 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); | |
247 |
|
247 | |||
248 | if (status!=RTEMS_SUCCESSFUL) |
|
248 | if (status!=RTEMS_SUCCESSFUL) | |
249 | { |
|
249 | { | |
250 | PRINTF1("in SEND *** (1) ERR = %d\n", status) |
|
250 | PRINTF1("in SEND *** (1) ERR = %d\n", status) | |
251 | } |
|
251 | } | |
252 | else |
|
252 | else | |
253 | { |
|
253 | { | |
254 | if ( size == sizeof(ring_node*) ) |
|
254 | if ( size == sizeof(ring_node*) ) | |
255 | { |
|
255 | { | |
256 | charPtr[0] = incomingData[0]; |
|
256 | charPtr[0] = incomingData[0]; | |
257 | charPtr[1] = incomingData[1]; |
|
257 | charPtr[1] = incomingData[1]; | |
258 | charPtr[2] = incomingData[2]; |
|
258 | charPtr[2] = incomingData[2]; | |
259 | charPtr[3] = incomingData[3]; |
|
259 | charPtr[3] = incomingData[3]; | |
260 | incomingRingNodePtr = (ring_node*) ring_node_address; |
|
260 | incomingRingNodePtr = (ring_node*) ring_node_address; | |
261 | sid = incomingRingNodePtr->sid; |
|
261 | sid = incomingRingNodePtr->sid; | |
262 | if ( (sid==SID_NORM_CWF_LONG_F3) |
|
262 | if ( (sid==SID_NORM_CWF_LONG_F3) | |
263 | || (sid==SID_BURST_CWF_F2 ) |
|
263 | || (sid==SID_BURST_CWF_F2 ) | |
264 | || (sid==SID_SBM1_CWF_F1 ) |
|
264 | || (sid==SID_SBM1_CWF_F1 ) | |
265 | || (sid==SID_SBM2_CWF_F2 )) |
|
265 | || (sid==SID_SBM2_CWF_F2 )) | |
266 | { |
|
266 | { | |
267 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); |
|
267 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); | |
268 | } |
|
268 | } | |
269 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) |
|
269 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) | |
270 | { |
|
270 | { | |
271 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); |
|
271 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); | |
272 | } |
|
272 | } | |
273 | else if ( (sid==SID_NORM_CWF_F3) ) |
|
273 | else if ( (sid==SID_NORM_CWF_F3) ) | |
274 | { |
|
274 | { | |
275 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); |
|
275 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); | |
276 | } |
|
276 | } | |
277 | else if (sid==SID_NORM_ASM_F0) |
|
277 | else if (sid==SID_NORM_ASM_F0) | |
278 | { |
|
278 | { | |
279 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); |
|
279 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); | |
280 | } |
|
280 | } | |
281 | else if (sid==SID_NORM_ASM_F1) |
|
281 | else if (sid==SID_NORM_ASM_F1) | |
282 | { |
|
282 | { | |
283 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); |
|
283 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); | |
284 | } |
|
284 | } | |
285 | else if (sid==SID_NORM_ASM_F2) |
|
285 | else if (sid==SID_NORM_ASM_F2) | |
286 | { |
|
286 | { | |
287 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); |
|
287 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); | |
288 | } |
|
288 | } | |
289 | else if ( sid==TM_CODE_K_DUMP ) |
|
289 | else if ( sid==TM_CODE_K_DUMP ) | |
290 | { |
|
290 | { | |
291 | spw_send_k_dump( incomingRingNodePtr ); |
|
291 | spw_send_k_dump( incomingRingNodePtr ); | |
292 | } |
|
292 | } | |
293 | else |
|
293 | else | |
294 | { |
|
294 | { | |
295 | PRINTF1("unexpected sid = %d\n", sid); |
|
295 | PRINTF1("unexpected sid = %d\n", sid); | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet |
|
298 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet | |
299 | { |
|
299 | { | |
300 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; |
|
300 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; | |
301 | sid = sidAsUnsignedChar; |
|
301 | sid = sidAsUnsignedChar; | |
302 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; |
|
302 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; | |
303 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently |
|
303 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently | |
304 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS |
|
304 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS | |
305 | { |
|
305 | { | |
306 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); |
|
306 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | status = write( fdSPW, incomingData, size ); |
|
309 | status = write( fdSPW, incomingData, size ); | |
310 | if (status == -1){ |
|
310 | if (status == -1){ | |
311 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
311 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 | else // the incoming message is a spw_ioctl_pkt_send structure |
|
314 | else // the incoming message is a spw_ioctl_pkt_send structure | |
315 | { |
|
315 | { | |
316 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; |
|
316 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; | |
317 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); |
|
317 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); | |
318 | if (status == -1){ |
|
318 | if (status == -1){ | |
319 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) |
|
319 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) | |
320 | } |
|
320 | } | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); |
|
324 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); | |
325 |
|
325 | |||
326 | } |
|
326 | } | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | rtems_task wtdg_task( rtems_task_argument argument ) |
|
329 | rtems_task wtdg_task( rtems_task_argument argument ) | |
330 | { |
|
330 | { | |
331 | rtems_event_set event_out; |
|
331 | rtems_event_set event_out; | |
332 | rtems_status_code status; |
|
332 | rtems_status_code status; | |
333 | int linkStatus; |
|
333 | int linkStatus; | |
334 |
|
334 | |||
335 | BOOT_PRINTF("in WTDG ***\n") |
|
335 | BOOT_PRINTF("in WTDG ***\n") | |
336 |
|
336 | |||
337 | while(1) |
|
337 | while(1) | |
338 | { |
|
338 | { | |
339 | // wait for an RTEMS_EVENT |
|
339 | // wait for an RTEMS_EVENT | |
340 | rtems_event_receive( RTEMS_EVENT_0, |
|
340 | rtems_event_receive( RTEMS_EVENT_0, | |
341 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
341 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
342 | PRINTF("in WTDG *** wait for the link\n") |
|
342 | PRINTF("in WTDG *** wait for the link\n") | |
343 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
343 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
344 | while( linkStatus != 5) // wait for the link |
|
344 | while( linkStatus != 5) // wait for the link | |
345 | { |
|
345 | { | |
346 | status = rtems_task_wake_after( 10 ); // monitor the link each 100ms |
|
346 | status = rtems_task_wake_after( 10 ); // monitor the link each 100ms | |
347 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
347 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | status = spacewire_stop_and_start_link( fdSPW ); |
|
350 | status = spacewire_stop_and_start_link( fdSPW ); | |
351 |
|
351 | |||
352 | if (status != RTEMS_SUCCESSFUL) |
|
352 | if (status != RTEMS_SUCCESSFUL) | |
353 | { |
|
353 | { | |
354 | PRINTF1("in WTDG *** ERR link not started %d\n", status) |
|
354 | PRINTF1("in WTDG *** ERR link not started %d\n", status) | |
355 | } |
|
355 | } | |
356 | else |
|
356 | else | |
357 | { |
|
357 | { | |
358 | PRINTF("in WTDG *** OK link started\n") |
|
358 | PRINTF("in WTDG *** OK link started\n") | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | // restart the SPIQ task |
|
361 | // restart the SPIQ task | |
362 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); |
|
362 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); | |
363 | if ( status != RTEMS_SUCCESSFUL ) { |
|
363 | if ( status != RTEMS_SUCCESSFUL ) { | |
364 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") |
|
364 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | // restart RECV and SEND |
|
367 | // restart RECV and SEND | |
368 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
368 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); | |
369 | if ( status != RTEMS_SUCCESSFUL ) { |
|
369 | if ( status != RTEMS_SUCCESSFUL ) { | |
370 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") |
|
370 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") | |
371 | } |
|
371 | } | |
372 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
372 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); | |
373 | if ( status != RTEMS_SUCCESSFUL ) { |
|
373 | if ( status != RTEMS_SUCCESSFUL ) { | |
374 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") |
|
374 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") | |
375 | } |
|
375 | } | |
376 | } |
|
376 | } | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | //**************** |
|
379 | //**************** | |
380 | // OTHER FUNCTIONS |
|
380 | // OTHER FUNCTIONS | |
381 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] |
|
381 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] | |
382 | { |
|
382 | { | |
383 | /** This function opens the SpaceWire link. |
|
383 | /** This function opens the SpaceWire link. | |
384 | * |
|
384 | * | |
385 | * @return a valid file descriptor in case of success, -1 in case of a failure |
|
385 | * @return a valid file descriptor in case of success, -1 in case of a failure | |
386 | * |
|
386 | * | |
387 | */ |
|
387 | */ | |
388 | rtems_status_code status; |
|
388 | rtems_status_code status; | |
389 |
|
389 | |||
390 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware |
|
390 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware | |
391 | if ( fdSPW < 0 ) { |
|
391 | if ( fdSPW < 0 ) { | |
392 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) |
|
392 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) | |
393 | } |
|
393 | } | |
394 | else |
|
394 | else | |
395 | { |
|
395 | { | |
396 | status = RTEMS_SUCCESSFUL; |
|
396 | status = RTEMS_SUCCESSFUL; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return status; |
|
399 | return status; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | int spacewire_start_link( int fd ) |
|
402 | int spacewire_start_link( int fd ) | |
403 | { |
|
403 | { | |
404 | rtems_status_code status; |
|
404 | rtems_status_code status; | |
405 |
|
405 | |||
406 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
406 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started | |
407 | // -1 default hardcoded driver timeout |
|
407 | // -1 default hardcoded driver timeout | |
408 |
|
408 | |||
409 | return status; |
|
409 | return status; | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | int spacewire_stop_and_start_link( int fd ) |
|
412 | int spacewire_stop_and_start_link( int fd ) | |
413 | { |
|
413 | { | |
414 | rtems_status_code status; |
|
414 | rtems_status_code status; | |
415 |
|
415 | |||
416 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 |
|
416 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 | |
417 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
417 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started | |
418 | // -1 default hardcoded driver timeout |
|
418 | // -1 default hardcoded driver timeout | |
419 |
|
419 | |||
420 | return status; |
|
420 | return status; | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | int spacewire_configure_link( int fd ) |
|
423 | int spacewire_configure_link( int fd ) | |
424 | { |
|
424 | { | |
425 | /** This function configures the SpaceWire link. |
|
425 | /** This function configures the SpaceWire link. | |
426 | * |
|
426 | * | |
427 | * @return GR-RTEMS-DRIVER directive status codes: |
|
427 | * @return GR-RTEMS-DRIVER directive status codes: | |
428 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. |
|
428 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. | |
429 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. |
|
429 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. | |
430 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. |
|
430 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. | |
431 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. |
|
431 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. | |
432 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. |
|
432 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. | |
433 | * - 5 EIO - Error when writing to grswp hardware registers. |
|
433 | * - 5 EIO - Error when writing to grswp hardware registers. | |
434 | * - 2 ENOENT - No such file or directory |
|
434 | * - 2 ENOENT - No such file or directory | |
435 | */ |
|
435 | */ | |
436 |
|
436 | |||
437 | rtems_status_code status; |
|
437 | rtems_status_code status; | |
438 |
|
438 | |||
439 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force |
|
439 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force | |
440 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration |
|
440 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration | |
441 |
|
441 | |||
442 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
442 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception | |
443 | if (status!=RTEMS_SUCCESSFUL) { |
|
443 | if (status!=RTEMS_SUCCESSFUL) { | |
444 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
444 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") | |
445 | } |
|
445 | } | |
446 | // |
|
446 | // | |
447 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a |
|
447 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a | |
448 | if (status!=RTEMS_SUCCESSFUL) { |
|
448 | if (status!=RTEMS_SUCCESSFUL) { | |
449 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
449 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs | |
450 | } |
|
450 | } | |
451 | // |
|
451 | // | |
452 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts |
|
452 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts | |
453 | if (status!=RTEMS_SUCCESSFUL) { |
|
453 | if (status!=RTEMS_SUCCESSFUL) { | |
454 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") |
|
454 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") | |
455 | } |
|
455 | } | |
456 | // |
|
456 | // | |
457 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
457 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit | |
458 | if (status!=RTEMS_SUCCESSFUL) { |
|
458 | if (status!=RTEMS_SUCCESSFUL) { | |
459 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
459 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") | |
460 | } |
|
460 | } | |
461 | // |
|
461 | // | |
462 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks |
|
462 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks | |
463 | if (status!=RTEMS_SUCCESSFUL) { |
|
463 | if (status!=RTEMS_SUCCESSFUL) { | |
464 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") |
|
464 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") | |
465 | } |
|
465 | } | |
466 | // |
|
466 | // | |
467 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available |
|
467 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available | |
468 | if (status!=RTEMS_SUCCESSFUL) { |
|
468 | if (status!=RTEMS_SUCCESSFUL) { | |
469 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") |
|
469 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") | |
470 | } |
|
470 | } | |
471 | // |
|
471 | // | |
472 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] |
|
472 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] | |
473 | if (status!=RTEMS_SUCCESSFUL) { |
|
473 | if (status!=RTEMS_SUCCESSFUL) { | |
474 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") |
|
474 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | return status; |
|
477 | return status; | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | int spacewire_reset_link( void ) |
|
480 | int spacewire_reset_link( void ) | |
481 | { |
|
481 | { | |
482 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. |
|
482 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. | |
483 | * |
|
483 | * | |
484 | * @return RTEMS directive status code: |
|
484 | * @return RTEMS directive status code: | |
485 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. |
|
485 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. | |
486 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. |
|
486 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. | |
487 | * |
|
487 | * | |
488 | */ |
|
488 | */ | |
489 |
|
489 | |||
490 | rtems_status_code status_spw; |
|
490 | rtems_status_code status_spw; | |
491 | rtems_status_code status; |
|
491 | rtems_status_code status; | |
492 | int i; |
|
492 | int i; | |
493 |
|
493 | |||
494 | for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ ) |
|
494 | for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ ) | |
495 | { |
|
495 | { | |
496 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); |
|
496 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); | |
497 |
|
497 | |||
498 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM |
|
498 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM | |
499 |
|
499 | |||
500 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
500 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms | |
501 |
|
501 | |||
502 | status_spw = spacewire_stop_and_start_link( fdSPW ); |
|
502 | status_spw = spacewire_stop_and_start_link( fdSPW ); | |
503 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
503 | if ( status_spw != RTEMS_SUCCESSFUL ) | |
504 | { |
|
504 | { | |
505 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw) |
|
505 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw) | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | if ( status_spw == RTEMS_SUCCESSFUL) |
|
508 | if ( status_spw == RTEMS_SUCCESSFUL) | |
509 | { |
|
509 | { | |
510 | break; |
|
510 | break; | |
511 | } |
|
511 | } | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | return status_spw; |
|
514 | return status_spw; | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force |
|
517 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force | |
518 | { |
|
518 | { | |
519 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. |
|
519 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. | |
520 | * |
|
520 | * | |
521 | * @param val is the value, 0 or 1, used to set the value of the NP bit. |
|
521 | * @param val is the value, 0 or 1, used to set the value of the NP bit. | |
522 | * @param regAddr is the address of the GRSPW control register. |
|
522 | * @param regAddr is the address of the GRSPW control register. | |
523 | * |
|
523 | * | |
524 | * NP is the bit 20 of the GRSPW control register. |
|
524 | * NP is the bit 20 of the GRSPW control register. | |
525 | * |
|
525 | * | |
526 | */ |
|
526 | */ | |
527 |
|
527 | |||
528 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
528 | unsigned int *spwptr = (unsigned int*) regAddr; | |
529 |
|
529 | |||
530 | if (val == 1) { |
|
530 | if (val == 1) { | |
531 | *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit |
|
531 | *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit | |
532 | } |
|
532 | } | |
533 | if (val== 0) { |
|
533 | if (val== 0) { | |
534 | *spwptr = *spwptr & 0xffdfffff; |
|
534 | *spwptr = *spwptr & 0xffdfffff; | |
535 | } |
|
535 | } | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable |
|
538 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable | |
539 | { |
|
539 | { | |
540 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. |
|
540 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. | |
541 | * |
|
541 | * | |
542 | * @param val is the value, 0 or 1, used to set the value of the RE bit. |
|
542 | * @param val is the value, 0 or 1, used to set the value of the RE bit. | |
543 | * @param regAddr is the address of the GRSPW control register. |
|
543 | * @param regAddr is the address of the GRSPW control register. | |
544 | * |
|
544 | * | |
545 | * RE is the bit 16 of the GRSPW control register. |
|
545 | * RE is the bit 16 of the GRSPW control register. | |
546 | * |
|
546 | * | |
547 | */ |
|
547 | */ | |
548 |
|
548 | |||
549 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
549 | unsigned int *spwptr = (unsigned int*) regAddr; | |
550 |
|
550 | |||
551 | if (val == 1) |
|
551 | if (val == 1) | |
552 | { |
|
552 | { | |
553 | *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit |
|
553 | *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit | |
554 | } |
|
554 | } | |
555 | if (val== 0) |
|
555 | if (val== 0) | |
556 | { |
|
556 | { | |
557 | *spwptr = *spwptr & 0xfffdffff; |
|
557 | *spwptr = *spwptr & 0xfffdffff; | |
558 | } |
|
558 | } | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | void spacewire_compute_stats_offsets( void ) |
|
561 | void spacewire_compute_stats_offsets( void ) | |
562 | { |
|
562 | { | |
563 | /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising. |
|
563 | /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising. | |
564 | * |
|
564 | * | |
565 | * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics |
|
565 | * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics | |
566 | * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it |
|
566 | * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it | |
567 | * during the open systel call). |
|
567 | * during the open systel call). | |
568 | * |
|
568 | * | |
569 | */ |
|
569 | */ | |
570 |
|
570 | |||
571 | spw_stats spacewire_stats_grspw; |
|
571 | spw_stats spacewire_stats_grspw; | |
572 | rtems_status_code status; |
|
572 | rtems_status_code status; | |
573 |
|
573 | |||
574 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); |
|
574 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); | |
575 |
|
575 | |||
576 | spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received |
|
576 | spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received | |
577 | + spacewire_stats.packets_received; |
|
577 | + spacewire_stats.packets_received; | |
578 | spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent |
|
578 | spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent | |
579 | + spacewire_stats.packets_sent; |
|
579 | + spacewire_stats.packets_sent; | |
580 | spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err |
|
580 | spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err | |
581 | + spacewire_stats.parity_err; |
|
581 | + spacewire_stats.parity_err; | |
582 | spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err |
|
582 | spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err | |
583 | + spacewire_stats.disconnect_err; |
|
583 | + spacewire_stats.disconnect_err; | |
584 | spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err |
|
584 | spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err | |
585 | + spacewire_stats.escape_err; |
|
585 | + spacewire_stats.escape_err; | |
586 | spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err |
|
586 | spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err | |
587 | + spacewire_stats.credit_err; |
|
587 | + spacewire_stats.credit_err; | |
588 | spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err |
|
588 | spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err | |
589 | + spacewire_stats.write_sync_err; |
|
589 | + spacewire_stats.write_sync_err; | |
590 | spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err |
|
590 | spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err | |
591 | + spacewire_stats.rx_rmap_header_crc_err; |
|
591 | + spacewire_stats.rx_rmap_header_crc_err; | |
592 | spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err |
|
592 | spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err | |
593 | + spacewire_stats.rx_rmap_data_crc_err; |
|
593 | + spacewire_stats.rx_rmap_data_crc_err; | |
594 | spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep |
|
594 | spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep | |
595 | + spacewire_stats.early_ep; |
|
595 | + spacewire_stats.early_ep; | |
596 | spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address |
|
596 | spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address | |
597 | + spacewire_stats.invalid_address; |
|
597 | + spacewire_stats.invalid_address; | |
598 | spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err |
|
598 | spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err | |
599 | + spacewire_stats.rx_eep_err; |
|
599 | + spacewire_stats.rx_eep_err; | |
600 | spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated |
|
600 | spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated | |
601 | + spacewire_stats.rx_truncated; |
|
601 | + spacewire_stats.rx_truncated; | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | void spacewire_update_statistics( void ) |
|
604 | void spacewire_update_statistics( void ) | |
605 | { |
|
605 | { | |
606 | rtems_status_code status; |
|
606 | rtems_status_code status; | |
607 | spw_stats spacewire_stats_grspw; |
|
607 | spw_stats spacewire_stats_grspw; | |
608 |
|
608 | |||
609 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); |
|
609 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); | |
610 |
|
610 | |||
611 | spacewire_stats.packets_received = spacewire_stats_backup.packets_received |
|
611 | spacewire_stats.packets_received = spacewire_stats_backup.packets_received | |
612 | + spacewire_stats_grspw.packets_received; |
|
612 | + spacewire_stats_grspw.packets_received; | |
613 | spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent |
|
613 | spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent | |
614 | + spacewire_stats_grspw.packets_sent; |
|
614 | + spacewire_stats_grspw.packets_sent; | |
615 | spacewire_stats.parity_err = spacewire_stats_backup.parity_err |
|
615 | spacewire_stats.parity_err = spacewire_stats_backup.parity_err | |
616 | + spacewire_stats_grspw.parity_err; |
|
616 | + spacewire_stats_grspw.parity_err; | |
617 | spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err |
|
617 | spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err | |
618 | + spacewire_stats_grspw.disconnect_err; |
|
618 | + spacewire_stats_grspw.disconnect_err; | |
619 | spacewire_stats.escape_err = spacewire_stats_backup.escape_err |
|
619 | spacewire_stats.escape_err = spacewire_stats_backup.escape_err | |
620 | + spacewire_stats_grspw.escape_err; |
|
620 | + spacewire_stats_grspw.escape_err; | |
621 | spacewire_stats.credit_err = spacewire_stats_backup.credit_err |
|
621 | spacewire_stats.credit_err = spacewire_stats_backup.credit_err | |
622 | + spacewire_stats_grspw.credit_err; |
|
622 | + spacewire_stats_grspw.credit_err; | |
623 | spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err |
|
623 | spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err | |
624 | + spacewire_stats_grspw.write_sync_err; |
|
624 | + spacewire_stats_grspw.write_sync_err; | |
625 | spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err |
|
625 | spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err | |
626 | + spacewire_stats_grspw.rx_rmap_header_crc_err; |
|
626 | + spacewire_stats_grspw.rx_rmap_header_crc_err; | |
627 | spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err |
|
627 | spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err | |
628 | + spacewire_stats_grspw.rx_rmap_data_crc_err; |
|
628 | + spacewire_stats_grspw.rx_rmap_data_crc_err; | |
629 | spacewire_stats.early_ep = spacewire_stats_backup.early_ep |
|
629 | spacewire_stats.early_ep = spacewire_stats_backup.early_ep | |
630 | + spacewire_stats_grspw.early_ep; |
|
630 | + spacewire_stats_grspw.early_ep; | |
631 | spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address |
|
631 | spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address | |
632 | + spacewire_stats_grspw.invalid_address; |
|
632 | + spacewire_stats_grspw.invalid_address; | |
633 | spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err |
|
633 | spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err | |
634 | + spacewire_stats_grspw.rx_eep_err; |
|
634 | + spacewire_stats_grspw.rx_eep_err; | |
635 | spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated |
|
635 | spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated | |
636 | + spacewire_stats_grspw.rx_truncated; |
|
636 | + spacewire_stats_grspw.rx_truncated; | |
637 | //spacewire_stats.tx_link_err; |
|
637 | //spacewire_stats.tx_link_err; | |
638 |
|
638 | |||
639 | //**************************** |
|
639 | //**************************** | |
640 | // DPU_SPACEWIRE_IF_STATISTICS |
|
640 | // DPU_SPACEWIRE_IF_STATISTICS | |
641 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8); |
|
641 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8); | |
642 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); |
|
642 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); | |
643 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); |
|
643 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); | |
644 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); |
|
644 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); | |
645 | //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; |
|
645 | //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; | |
646 | //housekeeping_packet.hk_lfr_dpu_spw_last_timc; |
|
646 | //housekeeping_packet.hk_lfr_dpu_spw_last_timc; | |
647 |
|
647 | |||
648 | //****************************************** |
|
648 | //****************************************** | |
649 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY |
|
649 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY | |
650 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; |
|
650 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; | |
651 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; |
|
651 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; | |
652 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; |
|
652 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; | |
653 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; |
|
653 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; | |
654 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; |
|
654 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; | |
655 |
|
655 | |||
656 | //********************************************* |
|
656 | //********************************************* | |
657 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY |
|
657 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY | |
658 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; |
|
658 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; | |
659 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; |
|
659 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; | |
660 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; |
|
660 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; | |
661 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; |
|
661 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; | |
662 | } |
|
662 | } | |
663 |
|
663 | |||
664 | void increase_unsigned_char_counter( unsigned char *counter ) |
|
664 | void increase_unsigned_char_counter( unsigned char *counter ) | |
665 | { |
|
665 | { | |
666 | // update the number of valid timecodes that have been received |
|
666 | // update the number of valid timecodes that have been received | |
667 | if (*counter == 255) |
|
667 | if (*counter == 255) | |
668 | { |
|
668 | { | |
669 | *counter = 0; |
|
669 | *counter = 0; | |
670 | } |
|
670 | } | |
671 | else |
|
671 | else | |
672 | { |
|
672 | { | |
673 | *counter = *counter + 1; |
|
673 | *counter = *counter + 1; | |
674 | } |
|
674 | } | |
675 | } |
|
675 | } | |
676 |
|
676 | |||
677 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) |
|
677 | rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data ) | |
678 | { |
|
678 | { | |
679 |
|
679 | |||
680 | unsigned char currentTimecodeCtr; |
|
680 | unsigned char currentTimecodeCtr; | |
681 |
|
681 | |||
682 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
682 | currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); | |
683 |
|
683 | |||
684 | if (currentTimecodeCtr == previousTimecodeCtr) |
|
684 | if (currentTimecodeCtr == previousTimecodeCtr) | |
685 | { |
|
685 | { | |
686 | //************************ |
|
686 | //************************ | |
687 | // HK_LFR_TIMECODE_MISSING |
|
687 | // HK_LFR_TIMECODE_MISSING | |
688 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING |
|
688 | // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING | |
689 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); |
|
689 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing ); | |
690 | } |
|
690 | } | |
691 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) |
|
691 | else if (currentTimecodeCtr == (previousTimecodeCtr+1)) | |
692 | { |
|
692 | { | |
693 | // the timecode value has changed and the value is valid, this is unexpected because |
|
693 | // the timecode value has changed and the value is valid, this is unexpected because | |
694 | // the timer should not have fired, the timecode_irq_handler should have been raised |
|
694 | // the timer should not have fired, the timecode_irq_handler should have been raised | |
695 | } |
|
695 | } | |
696 | else |
|
696 | else | |
697 | { |
|
697 | { | |
698 | //************************ |
|
698 | //************************ | |
699 | // HK_LFR_TIMECODE_INVALID |
|
699 | // HK_LFR_TIMECODE_INVALID | |
700 | // the timecode value has changed and the value is not valid, no tickout has been generated |
|
700 | // the timecode value has changed and the value is not valid, no tickout has been generated | |
701 | // this is why the timer has fired |
|
701 | // this is why the timer has fired | |
702 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); |
|
702 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid ); | |
703 | } |
|
703 | } | |
704 |
|
704 | |||
705 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); |
|
705 | rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 ); | |
706 | } |
|
706 | } | |
707 |
|
707 | |||
708 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) |
|
708 | unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr) | |
709 | { |
|
709 | { | |
|
710 | /** This function checks the coherency between the incoming timecode and the last valid timecode. | |||
|
711 | * | |||
|
712 | * @param currentTimecodeCtr is the incoming timecode | |||
|
713 | * | |||
|
714 | * @return returned codes:: | |||
|
715 | * - LFR_DEFAULT | |||
|
716 | * - LFR_SUCCESSFUL | |||
|
717 | * | |||
|
718 | */ | |||
|
719 | ||||
710 | static unsigned char firstTickout = 1; |
|
720 | static unsigned char firstTickout = 1; | |
711 | unsigned char ret; |
|
721 | unsigned char ret; | |
712 |
|
722 | |||
713 | ret = LFR_DEFAULT; |
|
723 | ret = LFR_DEFAULT; | |
714 |
|
724 | |||
715 | if (firstTickout == 0) |
|
725 | if (firstTickout == 0) | |
716 | { |
|
726 | { | |
717 | if (currentTimecodeCtr == 0) |
|
727 | if (currentTimecodeCtr == 0) | |
718 | { |
|
728 | { | |
719 | if (previousTimecodeCtr == 63) |
|
729 | if (previousTimecodeCtr == 63) | |
720 | { |
|
730 | { | |
721 | ret = LFR_SUCCESSFUL; |
|
731 | ret = LFR_SUCCESSFUL; | |
722 | } |
|
732 | } | |
723 | else |
|
733 | else | |
724 | { |
|
734 | { | |
725 | ret = LFR_DEFAULT; |
|
735 | ret = LFR_DEFAULT; | |
726 | } |
|
736 | } | |
727 | } |
|
737 | } | |
728 | else |
|
738 | else | |
729 | { |
|
739 | { | |
730 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) |
|
740 | if (currentTimecodeCtr == (previousTimecodeCtr +1)) | |
731 | { |
|
741 | { | |
732 | ret = LFR_SUCCESSFUL; |
|
742 | ret = LFR_SUCCESSFUL; | |
733 | } |
|
743 | } | |
734 | else |
|
744 | else | |
735 | { |
|
745 | { | |
736 | ret = LFR_DEFAULT; |
|
746 | ret = LFR_DEFAULT; | |
737 | } |
|
747 | } | |
738 | } |
|
748 | } | |
739 | } |
|
749 | } | |
740 | else |
|
750 | else | |
741 | { |
|
751 | { | |
742 | firstTickout = 0; |
|
752 | firstTickout = 0; | |
743 | ret = LFR_SUCCESSFUL; |
|
753 | ret = LFR_SUCCESSFUL; | |
744 | } |
|
754 | } | |
745 |
|
755 | |||
746 | return ret; |
|
756 | return ret; | |
747 | } |
|
757 | } | |
748 |
|
758 | |||
749 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) |
|
759 | unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime) | |
750 | { |
|
760 | { | |
751 | unsigned int ret; |
|
761 | unsigned int ret; | |
752 |
|
762 | |||
753 | ret = LFR_DEFAULT; |
|
763 | ret = LFR_DEFAULT; | |
754 |
|
764 | |||
755 | if (timecode == internalTime) |
|
765 | if (timecode == internalTime) | |
756 | { |
|
766 | { | |
757 | ret = LFR_SUCCESSFUL; |
|
767 | ret = LFR_SUCCESSFUL; | |
758 | } |
|
768 | } | |
759 | else |
|
769 | else | |
760 | { |
|
770 | { | |
761 | ret = LFR_DEFAULT; |
|
771 | ret = LFR_DEFAULT; | |
762 | } |
|
772 | } | |
763 |
|
773 | |||
764 | return ret; |
|
774 | return ret; | |
765 | } |
|
775 | } | |
766 |
|
776 | |||
767 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) |
|
777 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) | |
768 | { |
|
778 | { | |
769 | // a tickout has been emitted, perform actions on the incoming timecode |
|
779 | // a tickout has been emitted, perform actions on the incoming timecode | |
770 |
|
780 | |||
771 | unsigned char incomingTimecode; |
|
781 | unsigned char incomingTimecode; | |
772 | unsigned char updateTime; |
|
782 | unsigned char updateTime; | |
773 | unsigned char internalTime; |
|
783 | unsigned char internalTime; | |
774 | rtems_status_code status; |
|
784 | rtems_status_code status; | |
775 |
|
785 | |||
776 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); |
|
786 | incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK); | |
777 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; |
|
787 | updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK; | |
778 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; |
|
788 | internalTime = time_management_regs->coarse_time & TIMECODE_MASK; | |
779 |
|
789 | |||
780 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; |
|
790 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode; | |
781 |
|
791 | |||
782 | // update the number of tickout that have been generated |
|
792 | // update the number of tickout that have been generated | |
783 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); |
|
793 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt ); | |
784 |
|
794 | |||
785 | //************************** |
|
795 | //************************** | |
786 | // HK_LFR_TIMECODE_ERRONEOUS |
|
796 | // HK_LFR_TIMECODE_ERRONEOUS | |
787 | // MISSING and INVALID are handled by the timecode_timer_routine service routine |
|
797 | // MISSING and INVALID are handled by the timecode_timer_routine service routine | |
788 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) |
|
798 | if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT) | |
789 | { |
|
799 | { | |
790 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous |
|
800 | // this is unexpected but a tickout could have been raised despite of the timecode being erroneous | |
791 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); |
|
801 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous ); | |
792 | } |
|
802 | } | |
793 |
|
803 | |||
794 | //************************ |
|
804 | //************************ | |
795 | // HK_LFR_TIME_TIMECODE_IT |
|
805 | // HK_LFR_TIME_TIMECODE_IT | |
796 | // check the coherency between the SpaceWire timecode and the Internal Time |
|
806 | // check the coherency between the SpaceWire timecode and the Internal Time | |
797 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) |
|
807 | if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT) | |
798 | { |
|
808 | { | |
799 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); |
|
809 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it ); | |
800 | } |
|
810 | } | |
801 |
|
811 | |||
802 | //******************** |
|
812 | //******************** | |
803 | // HK_LFR_TIMECODE_CTR |
|
813 | // HK_LFR_TIMECODE_CTR | |
804 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 |
|
814 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 | |
805 | if (incomingTimecode != updateTime) |
|
815 | if (incomingTimecode != updateTime) | |
806 | { |
|
816 | { | |
807 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); |
|
817 | increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr ); | |
808 | } |
|
818 | } | |
809 |
|
819 | |||
810 | // launch the timecode timer to detect missing or invalid timecodes |
|
820 | // launch the timecode timer to detect missing or invalid timecodes | |
811 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value |
|
821 | previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value | |
812 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); |
|
822 | status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL ); | |
813 | } |
|
823 | } | |
814 |
|
824 | |||
815 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
825 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) | |
816 | { |
|
826 | { | |
817 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
827 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
818 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
828 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
819 | header->reserved = DEFAULT_RESERVED; |
|
829 | header->reserved = DEFAULT_RESERVED; | |
820 | header->userApplication = CCSDS_USER_APP; |
|
830 | header->userApplication = CCSDS_USER_APP; | |
821 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; |
|
831 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; | |
822 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; |
|
832 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; | |
823 | header->packetLength[0] = 0x00; |
|
833 | header->packetLength[0] = 0x00; | |
824 | header->packetLength[1] = 0x00; |
|
834 | header->packetLength[1] = 0x00; | |
825 | // DATA FIELD HEADER |
|
835 | // DATA FIELD HEADER | |
826 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
836 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
827 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
837 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
828 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
838 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype | |
829 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
839 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
830 | header->time[0] = 0x00; |
|
840 | header->time[0] = 0x00; | |
831 | header->time[0] = 0x00; |
|
841 | header->time[0] = 0x00; | |
832 | header->time[0] = 0x00; |
|
842 | header->time[0] = 0x00; | |
833 | header->time[0] = 0x00; |
|
843 | header->time[0] = 0x00; | |
834 | header->time[0] = 0x00; |
|
844 | header->time[0] = 0x00; | |
835 | header->time[0] = 0x00; |
|
845 | header->time[0] = 0x00; | |
836 | // AUXILIARY DATA HEADER |
|
846 | // AUXILIARY DATA HEADER | |
837 | header->sid = 0x00; |
|
847 | header->sid = 0x00; | |
838 | header->hkBIA = DEFAULT_HKBIA; |
|
848 | header->hkBIA = DEFAULT_HKBIA; | |
839 | header->blkNr[0] = 0x00; |
|
849 | header->blkNr[0] = 0x00; | |
840 | header->blkNr[1] = 0x00; |
|
850 | header->blkNr[1] = 0x00; | |
841 | } |
|
851 | } | |
842 |
|
852 | |||
843 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
853 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) | |
844 | { |
|
854 | { | |
845 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
855 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
846 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
856 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
847 | header->reserved = DEFAULT_RESERVED; |
|
857 | header->reserved = DEFAULT_RESERVED; | |
848 | header->userApplication = CCSDS_USER_APP; |
|
858 | header->userApplication = CCSDS_USER_APP; | |
849 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
859 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
850 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
860 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
851 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
861 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
852 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
862 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
853 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); |
|
863 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); | |
854 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
864 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | |
855 | // DATA FIELD HEADER |
|
865 | // DATA FIELD HEADER | |
856 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
866 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
857 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
867 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
858 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
868 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype | |
859 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
869 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
860 | header->time[0] = 0x00; |
|
870 | header->time[0] = 0x00; | |
861 | header->time[0] = 0x00; |
|
871 | header->time[0] = 0x00; | |
862 | header->time[0] = 0x00; |
|
872 | header->time[0] = 0x00; | |
863 | header->time[0] = 0x00; |
|
873 | header->time[0] = 0x00; | |
864 | header->time[0] = 0x00; |
|
874 | header->time[0] = 0x00; | |
865 | header->time[0] = 0x00; |
|
875 | header->time[0] = 0x00; | |
866 | // AUXILIARY DATA HEADER |
|
876 | // AUXILIARY DATA HEADER | |
867 | header->sid = 0x00; |
|
877 | header->sid = 0x00; | |
868 | header->hkBIA = DEFAULT_HKBIA; |
|
878 | header->hkBIA = DEFAULT_HKBIA; | |
869 | header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT |
|
879 | header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT | |
870 | header->pktNr = 0x00; |
|
880 | header->pktNr = 0x00; | |
871 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); |
|
881 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); | |
872 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
882 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); | |
873 | } |
|
883 | } | |
874 |
|
884 | |||
875 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
885 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) | |
876 | { |
|
886 | { | |
877 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
887 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; | |
878 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
888 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
879 | header->reserved = DEFAULT_RESERVED; |
|
889 | header->reserved = DEFAULT_RESERVED; | |
880 | header->userApplication = CCSDS_USER_APP; |
|
890 | header->userApplication = CCSDS_USER_APP; | |
881 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
891 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
882 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
892 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
883 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
893 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
884 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
894 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
885 | header->packetLength[0] = 0x00; |
|
895 | header->packetLength[0] = 0x00; | |
886 | header->packetLength[1] = 0x00; |
|
896 | header->packetLength[1] = 0x00; | |
887 | // DATA FIELD HEADER |
|
897 | // DATA FIELD HEADER | |
888 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
898 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
889 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
899 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type | |
890 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype |
|
900 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype | |
891 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
901 | header->destinationID = TM_DESTINATION_ID_GROUND; | |
892 | header->time[0] = 0x00; |
|
902 | header->time[0] = 0x00; | |
893 | header->time[0] = 0x00; |
|
903 | header->time[0] = 0x00; | |
894 | header->time[0] = 0x00; |
|
904 | header->time[0] = 0x00; | |
895 | header->time[0] = 0x00; |
|
905 | header->time[0] = 0x00; | |
896 | header->time[0] = 0x00; |
|
906 | header->time[0] = 0x00; | |
897 | header->time[0] = 0x00; |
|
907 | header->time[0] = 0x00; | |
898 | // AUXILIARY DATA HEADER |
|
908 | // AUXILIARY DATA HEADER | |
899 | header->sid = 0x00; |
|
909 | header->sid = 0x00; | |
900 | header->biaStatusInfo = 0x00; |
|
910 | header->biaStatusInfo = 0x00; | |
901 | header->pa_lfr_pkt_cnt_asm = 0x00; |
|
911 | header->pa_lfr_pkt_cnt_asm = 0x00; | |
902 | header->pa_lfr_pkt_nr_asm = 0x00; |
|
912 | header->pa_lfr_pkt_nr_asm = 0x00; | |
903 | header->pa_lfr_asm_blk_nr[0] = 0x00; |
|
913 | header->pa_lfr_asm_blk_nr[0] = 0x00; | |
904 | header->pa_lfr_asm_blk_nr[1] = 0x00; |
|
914 | header->pa_lfr_asm_blk_nr[1] = 0x00; | |
905 | } |
|
915 | } | |
906 |
|
916 | |||
907 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, |
|
917 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, | |
908 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
918 | Header_TM_LFR_SCIENCE_CWF_t *header ) | |
909 | { |
|
919 | { | |
910 | /** This function sends CWF CCSDS packets (F2, F1 or F0). |
|
920 | /** This function sends CWF CCSDS packets (F2, F1 or F0). | |
911 | * |
|
921 | * | |
912 | * @param waveform points to the buffer containing the data that will be send. |
|
922 | * @param waveform points to the buffer containing the data that will be send. | |
913 | * @param sid is the source identifier of the data that will be sent. |
|
923 | * @param sid is the source identifier of the data that will be sent. | |
914 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
924 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
915 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
925 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
916 | * contain information to setup the transmission of the data packets. |
|
926 | * contain information to setup the transmission of the data packets. | |
917 | * |
|
927 | * | |
918 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
928 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | |
919 | * |
|
929 | * | |
920 | */ |
|
930 | */ | |
921 |
|
931 | |||
922 | unsigned int i; |
|
932 | unsigned int i; | |
923 | int ret; |
|
933 | int ret; | |
924 | unsigned int coarseTime; |
|
934 | unsigned int coarseTime; | |
925 | unsigned int fineTime; |
|
935 | unsigned int fineTime; | |
926 | rtems_status_code status; |
|
936 | rtems_status_code status; | |
927 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
937 | spw_ioctl_pkt_send spw_ioctl_send_CWF; | |
928 | int *dataPtr; |
|
938 | int *dataPtr; | |
929 | unsigned char sid; |
|
939 | unsigned char sid; | |
930 |
|
940 | |||
931 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
941 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; | |
932 | spw_ioctl_send_CWF.options = 0; |
|
942 | spw_ioctl_send_CWF.options = 0; | |
933 |
|
943 | |||
934 | ret = LFR_DEFAULT; |
|
944 | ret = LFR_DEFAULT; | |
935 | sid = (unsigned char) ring_node_to_send->sid; |
|
945 | sid = (unsigned char) ring_node_to_send->sid; | |
936 |
|
946 | |||
937 | coarseTime = ring_node_to_send->coarseTime; |
|
947 | coarseTime = ring_node_to_send->coarseTime; | |
938 | fineTime = ring_node_to_send->fineTime; |
|
948 | fineTime = ring_node_to_send->fineTime; | |
939 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
949 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
940 |
|
950 | |||
941 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); |
|
951 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); | |
942 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
952 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); | |
943 | header->hkBIA = pa_bia_status_info; |
|
953 | header->hkBIA = pa_bia_status_info; | |
944 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
954 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
945 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); |
|
955 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); | |
946 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
956 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); | |
947 |
|
957 | |||
948 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform |
|
958 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform | |
949 | { |
|
959 | { | |
950 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; |
|
960 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; | |
951 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
961 | spw_ioctl_send_CWF.hdr = (char*) header; | |
952 | // BUILD THE DATA |
|
962 | // BUILD THE DATA | |
953 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; |
|
963 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; | |
954 |
|
964 | |||
955 | // SET PACKET SEQUENCE CONTROL |
|
965 | // SET PACKET SEQUENCE CONTROL | |
956 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
966 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
957 |
|
967 | |||
958 | // SET SID |
|
968 | // SET SID | |
959 | header->sid = sid; |
|
969 | header->sid = sid; | |
960 |
|
970 | |||
961 | // SET PACKET TIME |
|
971 | // SET PACKET TIME | |
962 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); |
|
972 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); | |
963 | // |
|
973 | // | |
964 | header->time[0] = header->acquisitionTime[0]; |
|
974 | header->time[0] = header->acquisitionTime[0]; | |
965 | header->time[1] = header->acquisitionTime[1]; |
|
975 | header->time[1] = header->acquisitionTime[1]; | |
966 | header->time[2] = header->acquisitionTime[2]; |
|
976 | header->time[2] = header->acquisitionTime[2]; | |
967 | header->time[3] = header->acquisitionTime[3]; |
|
977 | header->time[3] = header->acquisitionTime[3]; | |
968 | header->time[4] = header->acquisitionTime[4]; |
|
978 | header->time[4] = header->acquisitionTime[4]; | |
969 | header->time[5] = header->acquisitionTime[5]; |
|
979 | header->time[5] = header->acquisitionTime[5]; | |
970 |
|
980 | |||
971 | // SET PACKET ID |
|
981 | // SET PACKET ID | |
972 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) |
|
982 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) | |
973 | { |
|
983 | { | |
974 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8); |
|
984 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8); | |
975 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); |
|
985 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); | |
976 | } |
|
986 | } | |
977 | else |
|
987 | else | |
978 | { |
|
988 | { | |
979 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
989 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
980 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
990 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
981 | } |
|
991 | } | |
982 |
|
992 | |||
983 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
993 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); | |
984 | if (status != RTEMS_SUCCESSFUL) { |
|
994 | if (status != RTEMS_SUCCESSFUL) { | |
985 | ret = LFR_DEFAULT; |
|
995 | ret = LFR_DEFAULT; | |
986 | } |
|
996 | } | |
987 | } |
|
997 | } | |
988 |
|
998 | |||
989 | return ret; |
|
999 | return ret; | |
990 | } |
|
1000 | } | |
991 |
|
1001 | |||
992 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, |
|
1002 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, | |
993 | Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
1003 | Header_TM_LFR_SCIENCE_SWF_t *header ) | |
994 | { |
|
1004 | { | |
995 | /** This function sends SWF CCSDS packets (F2, F1 or F0). |
|
1005 | /** This function sends SWF CCSDS packets (F2, F1 or F0). | |
996 | * |
|
1006 | * | |
997 | * @param waveform points to the buffer containing the data that will be send. |
|
1007 | * @param waveform points to the buffer containing the data that will be send. | |
998 | * @param sid is the source identifier of the data that will be sent. |
|
1008 | * @param sid is the source identifier of the data that will be sent. | |
999 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. |
|
1009 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. | |
1000 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1010 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1001 | * contain information to setup the transmission of the data packets. |
|
1011 | * contain information to setup the transmission of the data packets. | |
1002 | * |
|
1012 | * | |
1003 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
1013 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. | |
1004 | * |
|
1014 | * | |
1005 | */ |
|
1015 | */ | |
1006 |
|
1016 | |||
1007 | unsigned int i; |
|
1017 | unsigned int i; | |
1008 | int ret; |
|
1018 | int ret; | |
1009 | unsigned int coarseTime; |
|
1019 | unsigned int coarseTime; | |
1010 | unsigned int fineTime; |
|
1020 | unsigned int fineTime; | |
1011 | rtems_status_code status; |
|
1021 | rtems_status_code status; | |
1012 | spw_ioctl_pkt_send spw_ioctl_send_SWF; |
|
1022 | spw_ioctl_pkt_send spw_ioctl_send_SWF; | |
1013 | int *dataPtr; |
|
1023 | int *dataPtr; | |
1014 | unsigned char sid; |
|
1024 | unsigned char sid; | |
1015 |
|
1025 | |||
1016 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; |
|
1026 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; | |
1017 | spw_ioctl_send_SWF.options = 0; |
|
1027 | spw_ioctl_send_SWF.options = 0; | |
1018 |
|
1028 | |||
1019 | ret = LFR_DEFAULT; |
|
1029 | ret = LFR_DEFAULT; | |
1020 |
|
1030 | |||
1021 | coarseTime = ring_node_to_send->coarseTime; |
|
1031 | coarseTime = ring_node_to_send->coarseTime; | |
1022 | fineTime = ring_node_to_send->fineTime; |
|
1032 | fineTime = ring_node_to_send->fineTime; | |
1023 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
1033 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
1024 | sid = ring_node_to_send->sid; |
|
1034 | sid = ring_node_to_send->sid; | |
1025 |
|
1035 | |||
1026 | header->hkBIA = pa_bia_status_info; |
|
1036 | header->hkBIA = pa_bia_status_info; | |
1027 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1037 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1028 |
|
1038 | |||
1029 | for (i=0; i<7; i++) // send waveform |
|
1039 | for (i=0; i<7; i++) // send waveform | |
1030 | { |
|
1040 | { | |
1031 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; |
|
1041 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; | |
1032 | spw_ioctl_send_SWF.hdr = (char*) header; |
|
1042 | spw_ioctl_send_SWF.hdr = (char*) header; | |
1033 |
|
1043 | |||
1034 | // SET PACKET SEQUENCE CONTROL |
|
1044 | // SET PACKET SEQUENCE CONTROL | |
1035 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1045 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1036 |
|
1046 | |||
1037 | // SET PACKET LENGTH AND BLKNR |
|
1047 | // SET PACKET LENGTH AND BLKNR | |
1038 | if (i == 6) |
|
1048 | if (i == 6) | |
1039 | { |
|
1049 | { | |
1040 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; |
|
1050 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; | |
1041 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); |
|
1051 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); | |
1042 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); |
|
1052 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); | |
1043 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); |
|
1053 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); | |
1044 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); |
|
1054 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); | |
1045 | } |
|
1055 | } | |
1046 | else |
|
1056 | else | |
1047 | { |
|
1057 | { | |
1048 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; |
|
1058 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; | |
1049 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); |
|
1059 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); | |
1050 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); |
|
1060 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); | |
1051 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); |
|
1061 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); | |
1052 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); |
|
1062 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); | |
1053 | } |
|
1063 | } | |
1054 |
|
1064 | |||
1055 | // SET PACKET TIME |
|
1065 | // SET PACKET TIME | |
1056 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); |
|
1066 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); | |
1057 | // |
|
1067 | // | |
1058 | header->time[0] = header->acquisitionTime[0]; |
|
1068 | header->time[0] = header->acquisitionTime[0]; | |
1059 | header->time[1] = header->acquisitionTime[1]; |
|
1069 | header->time[1] = header->acquisitionTime[1]; | |
1060 | header->time[2] = header->acquisitionTime[2]; |
|
1070 | header->time[2] = header->acquisitionTime[2]; | |
1061 | header->time[3] = header->acquisitionTime[3]; |
|
1071 | header->time[3] = header->acquisitionTime[3]; | |
1062 | header->time[4] = header->acquisitionTime[4]; |
|
1072 | header->time[4] = header->acquisitionTime[4]; | |
1063 | header->time[5] = header->acquisitionTime[5]; |
|
1073 | header->time[5] = header->acquisitionTime[5]; | |
1064 |
|
1074 | |||
1065 | // SET SID |
|
1075 | // SET SID | |
1066 | header->sid = sid; |
|
1076 | header->sid = sid; | |
1067 |
|
1077 | |||
1068 | // SET PKTNR |
|
1078 | // SET PKTNR | |
1069 | header->pktNr = i+1; // PKT_NR |
|
1079 | header->pktNr = i+1; // PKT_NR | |
1070 |
|
1080 | |||
1071 | // SEND PACKET |
|
1081 | // SEND PACKET | |
1072 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); |
|
1082 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); | |
1073 | if (status != RTEMS_SUCCESSFUL) { |
|
1083 | if (status != RTEMS_SUCCESSFUL) { | |
1074 | ret = LFR_DEFAULT; |
|
1084 | ret = LFR_DEFAULT; | |
1075 | } |
|
1085 | } | |
1076 | } |
|
1086 | } | |
1077 |
|
1087 | |||
1078 | return ret; |
|
1088 | return ret; | |
1079 | } |
|
1089 | } | |
1080 |
|
1090 | |||
1081 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, |
|
1091 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, | |
1082 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
1092 | Header_TM_LFR_SCIENCE_CWF_t *header ) | |
1083 | { |
|
1093 | { | |
1084 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
1094 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. | |
1085 | * |
|
1095 | * | |
1086 | * @param waveform points to the buffer containing the data that will be send. |
|
1096 | * @param waveform points to the buffer containing the data that will be send. | |
1087 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
1097 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
1088 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
1098 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
1089 | * contain information to setup the transmission of the data packets. |
|
1099 | * contain information to setup the transmission of the data packets. | |
1090 | * |
|
1100 | * | |
1091 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
1101 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer | |
1092 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
1102 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. | |
1093 | * |
|
1103 | * | |
1094 | */ |
|
1104 | */ | |
1095 |
|
1105 | |||
1096 | unsigned int i; |
|
1106 | unsigned int i; | |
1097 | int ret; |
|
1107 | int ret; | |
1098 | unsigned int coarseTime; |
|
1108 | unsigned int coarseTime; | |
1099 | unsigned int fineTime; |
|
1109 | unsigned int fineTime; | |
1100 | rtems_status_code status; |
|
1110 | rtems_status_code status; | |
1101 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
1111 | spw_ioctl_pkt_send spw_ioctl_send_CWF; | |
1102 | char *dataPtr; |
|
1112 | char *dataPtr; | |
1103 | unsigned char sid; |
|
1113 | unsigned char sid; | |
1104 |
|
1114 | |||
1105 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1115 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; | |
1106 | spw_ioctl_send_CWF.options = 0; |
|
1116 | spw_ioctl_send_CWF.options = 0; | |
1107 |
|
1117 | |||
1108 | ret = LFR_DEFAULT; |
|
1118 | ret = LFR_DEFAULT; | |
1109 | sid = ring_node_to_send->sid; |
|
1119 | sid = ring_node_to_send->sid; | |
1110 |
|
1120 | |||
1111 | coarseTime = ring_node_to_send->coarseTime; |
|
1121 | coarseTime = ring_node_to_send->coarseTime; | |
1112 | fineTime = ring_node_to_send->fineTime; |
|
1122 | fineTime = ring_node_to_send->fineTime; | |
1113 | dataPtr = (char*) ring_node_to_send->buffer_address; |
|
1123 | dataPtr = (char*) ring_node_to_send->buffer_address; | |
1114 |
|
1124 | |||
1115 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); |
|
1125 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); | |
1116 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); |
|
1126 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); | |
1117 | header->hkBIA = pa_bia_status_info; |
|
1127 | header->hkBIA = pa_bia_status_info; | |
1118 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1128 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1119 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); |
|
1129 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); | |
1120 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); |
|
1130 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); | |
1121 |
|
1131 | |||
1122 | //********************* |
|
1132 | //********************* | |
1123 | // SEND CWF3_light DATA |
|
1133 | // SEND CWF3_light DATA | |
1124 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform |
|
1134 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform | |
1125 | { |
|
1135 | { | |
1126 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; |
|
1136 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; | |
1127 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1137 | spw_ioctl_send_CWF.hdr = (char*) header; | |
1128 | // BUILD THE DATA |
|
1138 | // BUILD THE DATA | |
1129 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; |
|
1139 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; | |
1130 |
|
1140 | |||
1131 | // SET PACKET SEQUENCE COUNTER |
|
1141 | // SET PACKET SEQUENCE COUNTER | |
1132 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1142 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1133 |
|
1143 | |||
1134 | // SET SID |
|
1144 | // SET SID | |
1135 | header->sid = sid; |
|
1145 | header->sid = sid; | |
1136 |
|
1146 | |||
1137 | // SET PACKET TIME |
|
1147 | // SET PACKET TIME | |
1138 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); |
|
1148 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); | |
1139 | // |
|
1149 | // | |
1140 | header->time[0] = header->acquisitionTime[0]; |
|
1150 | header->time[0] = header->acquisitionTime[0]; | |
1141 | header->time[1] = header->acquisitionTime[1]; |
|
1151 | header->time[1] = header->acquisitionTime[1]; | |
1142 | header->time[2] = header->acquisitionTime[2]; |
|
1152 | header->time[2] = header->acquisitionTime[2]; | |
1143 | header->time[3] = header->acquisitionTime[3]; |
|
1153 | header->time[3] = header->acquisitionTime[3]; | |
1144 | header->time[4] = header->acquisitionTime[4]; |
|
1154 | header->time[4] = header->acquisitionTime[4]; | |
1145 | header->time[5] = header->acquisitionTime[5]; |
|
1155 | header->time[5] = header->acquisitionTime[5]; | |
1146 |
|
1156 | |||
1147 | // SET PACKET ID |
|
1157 | // SET PACKET ID | |
1148 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
1158 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); | |
1149 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1159 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); | |
1150 |
|
1160 | |||
1151 | // SEND PACKET |
|
1161 | // SEND PACKET | |
1152 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1162 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); | |
1153 | if (status != RTEMS_SUCCESSFUL) { |
|
1163 | if (status != RTEMS_SUCCESSFUL) { | |
1154 | ret = LFR_DEFAULT; |
|
1164 | ret = LFR_DEFAULT; | |
1155 | } |
|
1165 | } | |
1156 | } |
|
1166 | } | |
1157 |
|
1167 | |||
1158 | return ret; |
|
1168 | return ret; | |
1159 | } |
|
1169 | } | |
1160 |
|
1170 | |||
1161 | void spw_send_asm_f0( ring_node *ring_node_to_send, |
|
1171 | void spw_send_asm_f0( ring_node *ring_node_to_send, | |
1162 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1172 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1163 | { |
|
1173 | { | |
1164 | unsigned int i; |
|
1174 | unsigned int i; | |
1165 | unsigned int length = 0; |
|
1175 | unsigned int length = 0; | |
1166 | rtems_status_code status; |
|
1176 | rtems_status_code status; | |
1167 | unsigned int sid; |
|
1177 | unsigned int sid; | |
1168 | float *spectral_matrix; |
|
1178 | float *spectral_matrix; | |
1169 | int coarseTime; |
|
1179 | int coarseTime; | |
1170 | int fineTime; |
|
1180 | int fineTime; | |
1171 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1181 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1172 |
|
1182 | |||
1173 | sid = ring_node_to_send->sid; |
|
1183 | sid = ring_node_to_send->sid; | |
1174 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1184 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1175 | coarseTime = ring_node_to_send->coarseTime; |
|
1185 | coarseTime = ring_node_to_send->coarseTime; | |
1176 | fineTime = ring_node_to_send->fineTime; |
|
1186 | fineTime = ring_node_to_send->fineTime; | |
1177 |
|
1187 | |||
1178 | header->biaStatusInfo = pa_bia_status_info; |
|
1188 | header->biaStatusInfo = pa_bia_status_info; | |
1179 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1189 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1180 |
|
1190 | |||
1181 | for (i=0; i<3; i++) |
|
1191 | for (i=0; i<3; i++) | |
1182 | { |
|
1192 | { | |
1183 | if ((i==0) || (i==1)) |
|
1193 | if ((i==0) || (i==1)) | |
1184 | { |
|
1194 | { | |
1185 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; |
|
1195 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; | |
1186 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1196 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1187 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1197 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) | |
1188 | ]; |
|
1198 | ]; | |
1189 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; |
|
1199 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; | |
1190 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1200 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1191 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB |
|
1201 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB | |
1192 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB |
|
1202 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB | |
1193 | } |
|
1203 | } | |
1194 | else |
|
1204 | else | |
1195 | { |
|
1205 | { | |
1196 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; |
|
1206 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; | |
1197 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1207 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ | |
1198 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1208 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) | |
1199 | ]; |
|
1209 | ]; | |
1200 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; |
|
1210 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; | |
1201 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1211 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1202 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB |
|
1212 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB | |
1203 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB |
|
1213 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB | |
1204 | } |
|
1214 | } | |
1205 |
|
1215 | |||
1206 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1216 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1207 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1217 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1208 | spw_ioctl_send_ASM.options = 0; |
|
1218 | spw_ioctl_send_ASM.options = 0; | |
1209 |
|
1219 | |||
1210 | // (2) BUILD THE HEADER |
|
1220 | // (2) BUILD THE HEADER | |
1211 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1221 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1212 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1222 | header->packetLength[0] = (unsigned char) (length>>8); | |
1213 | header->packetLength[1] = (unsigned char) (length); |
|
1223 | header->packetLength[1] = (unsigned char) (length); | |
1214 | header->sid = (unsigned char) sid; // SID |
|
1224 | header->sid = (unsigned char) sid; // SID | |
1215 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1225 | header->pa_lfr_pkt_cnt_asm = 3; | |
1216 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1226 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1217 |
|
1227 | |||
1218 | // (3) SET PACKET TIME |
|
1228 | // (3) SET PACKET TIME | |
1219 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1229 | header->time[0] = (unsigned char) (coarseTime>>24); | |
1220 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1230 | header->time[1] = (unsigned char) (coarseTime>>16); | |
1221 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1231 | header->time[2] = (unsigned char) (coarseTime>>8); | |
1222 | header->time[3] = (unsigned char) (coarseTime); |
|
1232 | header->time[3] = (unsigned char) (coarseTime); | |
1223 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1233 | header->time[4] = (unsigned char) (fineTime>>8); | |
1224 | header->time[5] = (unsigned char) (fineTime); |
|
1234 | header->time[5] = (unsigned char) (fineTime); | |
1225 | // |
|
1235 | // | |
1226 | header->acquisitionTime[0] = header->time[0]; |
|
1236 | header->acquisitionTime[0] = header->time[0]; | |
1227 | header->acquisitionTime[1] = header->time[1]; |
|
1237 | header->acquisitionTime[1] = header->time[1]; | |
1228 | header->acquisitionTime[2] = header->time[2]; |
|
1238 | header->acquisitionTime[2] = header->time[2]; | |
1229 | header->acquisitionTime[3] = header->time[3]; |
|
1239 | header->acquisitionTime[3] = header->time[3]; | |
1230 | header->acquisitionTime[4] = header->time[4]; |
|
1240 | header->acquisitionTime[4] = header->time[4]; | |
1231 | header->acquisitionTime[5] = header->time[5]; |
|
1241 | header->acquisitionTime[5] = header->time[5]; | |
1232 |
|
1242 | |||
1233 | // (4) SEND PACKET |
|
1243 | // (4) SEND PACKET | |
1234 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1244 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1235 | if (status != RTEMS_SUCCESSFUL) { |
|
1245 | if (status != RTEMS_SUCCESSFUL) { | |
1236 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1246 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1237 | } |
|
1247 | } | |
1238 | } |
|
1248 | } | |
1239 | } |
|
1249 | } | |
1240 |
|
1250 | |||
1241 | void spw_send_asm_f1( ring_node *ring_node_to_send, |
|
1251 | void spw_send_asm_f1( ring_node *ring_node_to_send, | |
1242 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1252 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1243 | { |
|
1253 | { | |
1244 | unsigned int i; |
|
1254 | unsigned int i; | |
1245 | unsigned int length = 0; |
|
1255 | unsigned int length = 0; | |
1246 | rtems_status_code status; |
|
1256 | rtems_status_code status; | |
1247 | unsigned int sid; |
|
1257 | unsigned int sid; | |
1248 | float *spectral_matrix; |
|
1258 | float *spectral_matrix; | |
1249 | int coarseTime; |
|
1259 | int coarseTime; | |
1250 | int fineTime; |
|
1260 | int fineTime; | |
1251 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1261 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1252 |
|
1262 | |||
1253 | sid = ring_node_to_send->sid; |
|
1263 | sid = ring_node_to_send->sid; | |
1254 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1264 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1255 | coarseTime = ring_node_to_send->coarseTime; |
|
1265 | coarseTime = ring_node_to_send->coarseTime; | |
1256 | fineTime = ring_node_to_send->fineTime; |
|
1266 | fineTime = ring_node_to_send->fineTime; | |
1257 |
|
1267 | |||
1258 | header->biaStatusInfo = pa_bia_status_info; |
|
1268 | header->biaStatusInfo = pa_bia_status_info; | |
1259 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1269 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1260 |
|
1270 | |||
1261 | for (i=0; i<3; i++) |
|
1271 | for (i=0; i<3; i++) | |
1262 | { |
|
1272 | { | |
1263 | if ((i==0) || (i==1)) |
|
1273 | if ((i==0) || (i==1)) | |
1264 | { |
|
1274 | { | |
1265 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; |
|
1275 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; | |
1266 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1276 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1267 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1277 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) | |
1268 | ]; |
|
1278 | ]; | |
1269 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; |
|
1279 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; | |
1270 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1280 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1271 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB |
|
1281 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB | |
1272 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB |
|
1282 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB | |
1273 | } |
|
1283 | } | |
1274 | else |
|
1284 | else | |
1275 | { |
|
1285 | { | |
1276 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; |
|
1286 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; | |
1277 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1287 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ | |
1278 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1288 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) | |
1279 | ]; |
|
1289 | ]; | |
1280 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; |
|
1290 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; | |
1281 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1291 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; | |
1282 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB |
|
1292 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB | |
1283 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB |
|
1293 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB | |
1284 | } |
|
1294 | } | |
1285 |
|
1295 | |||
1286 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1296 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1287 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1297 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1288 | spw_ioctl_send_ASM.options = 0; |
|
1298 | spw_ioctl_send_ASM.options = 0; | |
1289 |
|
1299 | |||
1290 | // (2) BUILD THE HEADER |
|
1300 | // (2) BUILD THE HEADER | |
1291 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1301 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1292 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1302 | header->packetLength[0] = (unsigned char) (length>>8); | |
1293 | header->packetLength[1] = (unsigned char) (length); |
|
1303 | header->packetLength[1] = (unsigned char) (length); | |
1294 | header->sid = (unsigned char) sid; // SID |
|
1304 | header->sid = (unsigned char) sid; // SID | |
1295 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1305 | header->pa_lfr_pkt_cnt_asm = 3; | |
1296 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1306 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1297 |
|
1307 | |||
1298 | // (3) SET PACKET TIME |
|
1308 | // (3) SET PACKET TIME | |
1299 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1309 | header->time[0] = (unsigned char) (coarseTime>>24); | |
1300 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1310 | header->time[1] = (unsigned char) (coarseTime>>16); | |
1301 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1311 | header->time[2] = (unsigned char) (coarseTime>>8); | |
1302 | header->time[3] = (unsigned char) (coarseTime); |
|
1312 | header->time[3] = (unsigned char) (coarseTime); | |
1303 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1313 | header->time[4] = (unsigned char) (fineTime>>8); | |
1304 | header->time[5] = (unsigned char) (fineTime); |
|
1314 | header->time[5] = (unsigned char) (fineTime); | |
1305 | // |
|
1315 | // | |
1306 | header->acquisitionTime[0] = header->time[0]; |
|
1316 | header->acquisitionTime[0] = header->time[0]; | |
1307 | header->acquisitionTime[1] = header->time[1]; |
|
1317 | header->acquisitionTime[1] = header->time[1]; | |
1308 | header->acquisitionTime[2] = header->time[2]; |
|
1318 | header->acquisitionTime[2] = header->time[2]; | |
1309 | header->acquisitionTime[3] = header->time[3]; |
|
1319 | header->acquisitionTime[3] = header->time[3]; | |
1310 | header->acquisitionTime[4] = header->time[4]; |
|
1320 | header->acquisitionTime[4] = header->time[4]; | |
1311 | header->acquisitionTime[5] = header->time[5]; |
|
1321 | header->acquisitionTime[5] = header->time[5]; | |
1312 |
|
1322 | |||
1313 | // (4) SEND PACKET |
|
1323 | // (4) SEND PACKET | |
1314 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1324 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1315 | if (status != RTEMS_SUCCESSFUL) { |
|
1325 | if (status != RTEMS_SUCCESSFUL) { | |
1316 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1326 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1317 | } |
|
1327 | } | |
1318 | } |
|
1328 | } | |
1319 | } |
|
1329 | } | |
1320 |
|
1330 | |||
1321 | void spw_send_asm_f2( ring_node *ring_node_to_send, |
|
1331 | void spw_send_asm_f2( ring_node *ring_node_to_send, | |
1322 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1332 | Header_TM_LFR_SCIENCE_ASM_t *header ) | |
1323 | { |
|
1333 | { | |
1324 | unsigned int i; |
|
1334 | unsigned int i; | |
1325 | unsigned int length = 0; |
|
1335 | unsigned int length = 0; | |
1326 | rtems_status_code status; |
|
1336 | rtems_status_code status; | |
1327 | unsigned int sid; |
|
1337 | unsigned int sid; | |
1328 | float *spectral_matrix; |
|
1338 | float *spectral_matrix; | |
1329 | int coarseTime; |
|
1339 | int coarseTime; | |
1330 | int fineTime; |
|
1340 | int fineTime; | |
1331 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1341 | spw_ioctl_pkt_send spw_ioctl_send_ASM; | |
1332 |
|
1342 | |||
1333 | sid = ring_node_to_send->sid; |
|
1343 | sid = ring_node_to_send->sid; | |
1334 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1344 | spectral_matrix = (float*) ring_node_to_send->buffer_address; | |
1335 | coarseTime = ring_node_to_send->coarseTime; |
|
1345 | coarseTime = ring_node_to_send->coarseTime; | |
1336 | fineTime = ring_node_to_send->fineTime; |
|
1346 | fineTime = ring_node_to_send->fineTime; | |
1337 |
|
1347 | |||
1338 | header->biaStatusInfo = pa_bia_status_info; |
|
1348 | header->biaStatusInfo = pa_bia_status_info; | |
1339 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1349 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
1340 |
|
1350 | |||
1341 | for (i=0; i<3; i++) |
|
1351 | for (i=0; i<3; i++) | |
1342 | { |
|
1352 | { | |
1343 |
|
1353 | |||
1344 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; |
|
1354 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; | |
1345 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1355 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ | |
1346 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) |
|
1356 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) | |
1347 | ]; |
|
1357 | ]; | |
1348 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; |
|
1358 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; | |
1349 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; |
|
1359 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; | |
1350 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB |
|
1360 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB | |
1351 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB |
|
1361 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB | |
1352 |
|
1362 | |||
1353 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1363 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; | |
1354 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1364 | spw_ioctl_send_ASM.hdr = (char *) header; | |
1355 | spw_ioctl_send_ASM.options = 0; |
|
1365 | spw_ioctl_send_ASM.options = 0; | |
1356 |
|
1366 | |||
1357 | // (2) BUILD THE HEADER |
|
1367 | // (2) BUILD THE HEADER | |
1358 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1368 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); | |
1359 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1369 | header->packetLength[0] = (unsigned char) (length>>8); | |
1360 | header->packetLength[1] = (unsigned char) (length); |
|
1370 | header->packetLength[1] = (unsigned char) (length); | |
1361 | header->sid = (unsigned char) sid; // SID |
|
1371 | header->sid = (unsigned char) sid; // SID | |
1362 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1372 | header->pa_lfr_pkt_cnt_asm = 3; | |
1363 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1373 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); | |
1364 |
|
1374 | |||
1365 | // (3) SET PACKET TIME |
|
1375 | // (3) SET PACKET TIME | |
1366 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1376 | header->time[0] = (unsigned char) (coarseTime>>24); | |
1367 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1377 | header->time[1] = (unsigned char) (coarseTime>>16); | |
1368 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1378 | header->time[2] = (unsigned char) (coarseTime>>8); | |
1369 | header->time[3] = (unsigned char) (coarseTime); |
|
1379 | header->time[3] = (unsigned char) (coarseTime); | |
1370 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1380 | header->time[4] = (unsigned char) (fineTime>>8); | |
1371 | header->time[5] = (unsigned char) (fineTime); |
|
1381 | header->time[5] = (unsigned char) (fineTime); | |
1372 | // |
|
1382 | // | |
1373 | header->acquisitionTime[0] = header->time[0]; |
|
1383 | header->acquisitionTime[0] = header->time[0]; | |
1374 | header->acquisitionTime[1] = header->time[1]; |
|
1384 | header->acquisitionTime[1] = header->time[1]; | |
1375 | header->acquisitionTime[2] = header->time[2]; |
|
1385 | header->acquisitionTime[2] = header->time[2]; | |
1376 | header->acquisitionTime[3] = header->time[3]; |
|
1386 | header->acquisitionTime[3] = header->time[3]; | |
1377 | header->acquisitionTime[4] = header->time[4]; |
|
1387 | header->acquisitionTime[4] = header->time[4]; | |
1378 | header->acquisitionTime[5] = header->time[5]; |
|
1388 | header->acquisitionTime[5] = header->time[5]; | |
1379 |
|
1389 | |||
1380 | // (4) SEND PACKET |
|
1390 | // (4) SEND PACKET | |
1381 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1391 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); | |
1382 | if (status != RTEMS_SUCCESSFUL) { |
|
1392 | if (status != RTEMS_SUCCESSFUL) { | |
1383 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1393 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) | |
1384 | } |
|
1394 | } | |
1385 | } |
|
1395 | } | |
1386 | } |
|
1396 | } | |
1387 |
|
1397 | |||
1388 | void spw_send_k_dump( ring_node *ring_node_to_send ) |
|
1398 | void spw_send_k_dump( ring_node *ring_node_to_send ) | |
1389 | { |
|
1399 | { | |
1390 | rtems_status_code status; |
|
1400 | rtems_status_code status; | |
1391 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; |
|
1401 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; | |
1392 | unsigned int packetLength; |
|
1402 | unsigned int packetLength; | |
1393 | unsigned int size; |
|
1403 | unsigned int size; | |
1394 |
|
1404 | |||
1395 | PRINTF("spw_send_k_dump\n") |
|
1405 | PRINTF("spw_send_k_dump\n") | |
1396 |
|
1406 | |||
1397 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; |
|
1407 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; | |
1398 |
|
1408 | |||
1399 | packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1]; |
|
1409 | packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1]; | |
1400 |
|
1410 | |||
1401 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
1411 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; | |
1402 |
|
1412 | |||
1403 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) |
|
1413 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) | |
1404 |
|
1414 | |||
1405 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); |
|
1415 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); | |
1406 |
|
1416 | |||
1407 | if (status == -1){ |
|
1417 | if (status == -1){ | |
1408 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
1418 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) | |
1409 | } |
|
1419 | } | |
1410 |
|
1420 | |||
1411 | ring_node_to_send->status = 0x00; |
|
1421 | ring_node_to_send->status = 0x00; | |
1412 | } |
|
1422 | } |
General Comments 0
You need to be logged in to leave comments.
Login now