aesa: make "make clean" also remove output.txt
[jump.git] / aesa / src / Corner_Turn.c
1 #include "Corner_Turn.h"
2
3 /************************************************************************************/
4
5 void Corner_Turn_init(DOLProcess * p)
6 {       
7         int i,j;
8         
9         for (i=0; i<NUMBER_OF_RANGE_BINS; i=i+1) 
10         {
11                 for (j=0; j<NFFT; j=j+1) 
12                 {
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;
17                 }
18         }
19         
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;
27
28         p->local->hold_input = 0;
29         p->local->hold_output = 0;
30
31         p->local->excount = 0;
32
33 }
34
35 /************************************************************************************/
36
37 int Corner_Turn_fire(DOLProcess * p)
38 {
39         // ComplexNumber next_sample;
40         ComplexNumber samples_in[NFFT];
41         ComplexNumber samples_out[NUMBER_OF_RANGE_BINS];
42         p->local->excount++;
43
44         if(!p->local->hold_input){
45         DOL_read((void*)PORT_DATA_IN, &samples_in, NFFT*sizeof(ComplexNumber), p);
46         }
47
48         if (p->local->buffer_mode == 0)  // if buffer_mode = 0: input buffer is A, output buffer is B
49         {
50
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));
55                 }
56
57                 // next_sample = p->local->Channels_B[p->local->bin_counter_out][p->local->pulse_counter_out];
58                 if(!p->local->hold_output){
59                 int i;
60                 for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
61                 {
62                         samples_out[i]=p->local->Channels_B[i][p->local->pulse_counter_out];
63                 }
64                 // DOL_write((void*)PORT_DATA_OUT, &(next_sample), sizeof(ComplexNumber), p);
65                 
66                 DOL_write((void*)PORT_DATA_OUT, &(samples_out[0]), NUMBER_OF_RANGE_BINS*sizeof(ComplexNumber), p);
67                 }
68         }
69
70         else  // if buffer_mode = 1: input buffer is B, output buffer is A
71         {
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));
75                 }
76                 // next_sample = p->local->Channels_A[p->local->bin_counter_out][p->local->pulse_counter_out];
77                 if(!p->local->hold_output){
78                 int i;
79                 for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
80                 {
81                         samples_out[i]=p->local->Channels_A[i][p->local->pulse_counter_out];
82                 }
83
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);
86                 }
87         }
88
89         // // p->local->pulse_counter_in = p->local->pulse_counter_in + 1;
90
91         // // if (p->local->pulse_counter_in == NFFT) 
92         // // {
93  //    // p->local->pulse_counter_in = 0;
94
95         //      p->local->bin_counter_in = p->local->bin_counter_in + 1;
96         //      if (p->local->bin_counter_in == NUMBER_OF_RANGE_BINS) 
97         //      {
98         //              p->local->bin_counter_in = 0;
99         //      }
100         // // }
101
102         // // p->local->bin_counter_out = p->local->bin_counter_out + 1;
103         // // if (p->local->bin_counter_out == NUMBER_OF_RANGE_BINS)  
104         // // {
105  // //    p->local->bin_counter_out = 0;
106
107         //      p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
108         //      if (p->local->pulse_counter_out == NFFT) 
109         //      {
110  //                     p->local->pulse_counter_out = 0;
111         //              p->local->buffer_mode = p->local->buffer_mode ^ 0x01;     // Switch buffer mode
112
113         //         p->local->n_batches = p->local->n_batches + 1;
114                 
115         //         //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
116         //         // Probably this shouldn't be changed, but not sure. check it late!
117         //         if (p->local->n_batches == (NUMBER_OF_PULSES/NFFT))
118         //         {
119         //           p->local->n_batches = 0;
120         //                        p->local->n_iterations = p->local->n_iterations + 1;  
121         //         }
122         //      }
123         // // }
124
125                 #if NUMBER_OF_RANGE_BINS > NFFT  // this is the case that we have to hold the output
126
127
128                         if(!p->local->hold_output)
129                         {
130                         p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
131                         }
132
133                         p->local->bin_counter_in = p->local->bin_counter_in + 1;
134
135
136                         if (p->local->pulse_counter_out >= NFFT)
137                         {
138                                 if   (p->local->bin_counter_in < NUMBER_OF_RANGE_BINS )   // -1
139                                 {
140                                 p->local->hold_output = 1 ;
141                                 }
142                                 else
143                                 {
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;
148                                         
149
150                                         p->local->buffer_mode = p->local->buffer_mode ^ 0x01;
151                                         
152                                 }
153                         }
154
155
156                 #elif NUMBER_OF_RANGE_BINS < NFFT  // this is the case that we have to hold the input
157
158                         if (!p->local->hold_input)
159                         {
160                         p->local->bin_counter_in = p->local->bin_counter_in + 1;
161                         }
162
163                         p->local->pulse_counter_out = p->local->pulse_counter_out + 1;
164                         
165                         if (p->local->bin_counter_in == NUMBER_OF_RANGE_BINS)
166                         {
167                                 if(p->local->pulse_counter_out < NFFT)
168                                 {
169                                         p->local->hold_input = 1;
170                                 }
171                                 else  // pulse_counter_out == NUMBER OF RANGE BINS
172                                 {
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;
177
178                                         p->local->buffer_mode = p->local->buffer_mode ^ 0x01;
179                                         
180                                 }
181                         }
182
183
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;
187                         
188                         if (p->local->bin_counter_in == NFFT - 1) // not sure about the -1!! do test
189                         {
190                                 p->local->bin_counter_in = 0;
191                                 p->local->pulse_counter_out = 0;
192                                 p->local->n_batches = p->local->n_batches + 1;
193
194                                 p->local->buffer_mode = p->local->buffer_mode ^ 0x01;
195                         }
196
197                 #endif
198                 
199         if (p->local->n_batches == (NUMBER_OF_PULSES/NFFT))
200     {
201           p->local->n_batches = 0;
202                           p->local->n_iterations = p->local->n_iterations + 1;  
203     }
204         if (p->local->n_iterations == NUMBER_OF_ITERATIONS) 
205         {
206                 printf("\n\n:: Corner Turn process finished ::\n\n");
207     // printf("\ttotal number of executions:  %d",p->local->excount);   
208                 
209                 DOL_detach(p);
210         }
211         
212         return 0;
213 }