1 #include "Corner_Turn.h"
3 /************************************************************************************/
5 void Corner_Turn_init(DOLProcess * p)
9 for (i=0; i<NUMBER_OF_RANGE_BINS; i=i+1)
11 for (j=0; j<NFFT; j=j+1)
13 p->local->Channels_A[i][j].real = 0.0;
14 p->local->Channels_A[i][j].imag = 0.0;
15 p->local->Channels_B[i][j].real = 0.0;
16 p->local->Channels_B[i][j].imag = 0.0;
20 p->local->buffer_mode = 0;
21 // p->local->pulse_counter_in = 0;
22 p->local->pulse_counter_out = 0;
23 p->local->bin_counter_in = 0;
24 // p->local->bin_counter_out = 0;
25 p->local->n_batches = 0;
26 p->local->n_iterations = 0;
28 p->local->hold_input = 0;
29 p->local->hold_output = 0;
31 p->local->excount = 0;
35 /************************************************************************************/
37 int Corner_Turn_fire(DOLProcess * p)
39 // ComplexNumber next_sample;
40 ComplexNumber samples_in[NFFT];
41 ComplexNumber samples_out[NUMBER_OF_RANGE_BINS];
44 if(!p->local->hold_input){
45 DOL_read((void*)PORT_DATA_IN, &samples_in, NFFT*sizeof(ComplexNumber), p);
48 if (p->local->buffer_mode == 0) // if buffer_mode = 0: input buffer is A, output buffer is B
51 // !!!!!!!!!!!!!!!!!! Not sure about syntax. check the dest adrs and &
52 // p->local->Channels_A[p->local->bin_counter_in][p->local->pulse_counter_in] = next_sample;
53 if(!p->local->hold_input){
54 memcpy(&(p->local->Channels_A[p->local->bin_counter_in][0]) , &samples_in, NFFT*sizeof(int));
57 // next_sample = p->local->Channels_B[p->local->bin_counter_out][p->local->pulse_counter_out];
58 if(!p->local->hold_output){
60 for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
62 samples_out[i]=p->local->Channels_B[i][p->local->pulse_counter_out];
64 // DOL_write((void*)PORT_DATA_OUT, &(next_sample), sizeof(ComplexNumber), p);
66 DOL_write((void*)PORT_DATA_OUT, &(samples_out[0]), NUMBER_OF_RANGE_BINS*sizeof(ComplexNumber), p);
70 else // if buffer_mode = 1: input buffer is B, output buffer is A
72 // p->local->Channels_B[p->local->bin_counter_in][p->local->pulse_counter_in] = next_sample;
73 if(!p->local->hold_input){
74 memcpy(&(p->local->Channels_B[p->local->bin_counter_in][0]) , &samples_in, NFFT*sizeof(int));
76 // next_sample = p->local->Channels_A[p->local->bin_counter_out][p->local->pulse_counter_out];
77 if(!p->local->hold_output){
79 for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
81 samples_out[i]=p->local->Channels_A[i][p->local->pulse_counter_out];
84 // DOL_write((void*)PORT_DATA_OUT, &(next_sample), sizeof(ComplexNumber), p);
85 DOL_write((void*)PORT_DATA_OUT, &(samples_out[0]), NUMBER_OF_RANGE_BINS*sizeof(ComplexNumber), p);
89 // // p->local->pulse_counter_in = p->local->pulse_counter_in + 1;
91 // // if (p->local->pulse_counter_in == NFFT)
93 // // p->local->pulse_counter_in = 0;
95 // p->local->bin_counter_in = p->local->bin_counter_in + 1;
96 // if (p->local->bin_counter_in == NUMBER_OF_RANGE_BINS)
98 // p->local->bin_counter_in = 0;
102 // // p->local->bin_counter_out = p->local->bin_counter_out + 1;
103 // // if (p->local->bin_counter_out == NUMBER_OF_RANGE_BINS)
105 // // p->local->bin_counter_out = 0;
107 // p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
108 // if (p->local->pulse_counter_out == NFFT)
110 // p->local->pulse_counter_out = 0;
111 // p->local->buffer_mode = p->local->buffer_mode ^ 0x01; // Switch buffer mode
113 // p->local->n_batches = p->local->n_batches + 1;
115 // //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
116 // // Probably this shouldn't be changed, but not sure. check it late!
117 // if (p->local->n_batches == (NUMBER_OF_PULSES/NFFT))
119 // p->local->n_batches = 0;
120 // p->local->n_iterations = p->local->n_iterations + 1;
125 #if NUMBER_OF_RANGE_BINS > NFFT // this is the case that we have to hold the output
128 if(!p->local->hold_output)
130 p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
133 p->local->bin_counter_in = p->local->bin_counter_in + 1;
136 if (p->local->pulse_counter_out >= NFFT)
138 if (p->local->bin_counter_in < NUMBER_OF_RANGE_BINS ) // -1
140 p->local->hold_output = 1 ;
144 p->local->bin_counter_in = 0;
145 p->local->pulse_counter_out = 0;
146 p->local->hold_output = 0;
147 p->local->n_batches = p->local->n_batches + 1;
150 p->local->buffer_mode = p->local->buffer_mode ^ 0x01;
156 #elif NUMBER_OF_RANGE_BINS < NFFT // this is the case that we have to hold the input
158 if (!p->local->hold_input)
160 p->local->bin_counter_in = p->local->bin_counter_in + 1;
163 p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
165 if (p->local->bin_counter_in == NUMBER_OF_RANGE_BINS)
167 if(p->local->pulse_counter_out < NFFT)
169 p->local->hold_input = 1;
171 else // pulse_counter_out == NUMBER OF RANGE BINS
173 p->local->bin_counter_in = 0;
174 p->local->pulse_counter_out = 0;
175 p->local->hold_input = 0;
176 p->local->n_batches = p->local->n_batches + 1;
178 p->local->buffer_mode = p->local->buffer_mode ^ 0x01;
184 #else // in this case we have equal number of iterations over input and output
185 p->local->bin_counter_in = p->local->bin_counter_in + 1;
186 p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
188 if (p->local->bin_counter_in == NFFT - 1) // not sure about the -1!! do test
190 p->local->bin_counter_in = 0;
191 p->local->pulse_counter_out = 0;
192 p->local->n_batches = p->local->n_batches + 1;
194 p->local->buffer_mode = p->local->buffer_mode ^ 0x01;
199 if (p->local->n_batches == (NUMBER_OF_PULSES/NFFT))
201 p->local->n_batches = 0;
202 p->local->n_iterations = p->local->n_iterations + 1;
204 if (p->local->n_iterations == NUMBER_OF_ITERATIONS)
206 printf("\n\n:: Corner Turn process finished ::\n\n");
207 // printf("\ttotal number of executions: %d",p->local->excount);