Examples/ehw4/logic/ehw.v |
12 | 12 | // synchronize signals |
13 | 13 | reg sncs, snwe; |
14 | 14 | reg [12:0] buffer_addr; |
15 | | reg [B:0] buffer_data; |
16 | | wire led; |
| 15 | reg [B:0] buffer_data; |
17 | 16 | |
18 | 17 | // bram-cpu interfaz |
19 | 18 | reg we; |
20 | 19 | reg w_st=0; |
21 | 20 | reg [B:0] wdBus; |
22 | | reg [B:0] rdBus; |
| 21 | wire [B:0] rdBus; |
23 | 22 | wire [12:0] addr; |
24 | 23 | reg [7:0] bae; |
25 | 24 | |
... | ... | |
45 | 44 | wire [3:0] max_lev; |
46 | 45 | wire [7:0] control; |
47 | 46 | |
48 | | reg [7:0] reg_bank [31:0]; |
49 | | wire enReg; |
50 | | wire [4:0] address; |
51 | | |
52 | | // Test : LED blinking |
| 47 | // Test : LED blinking |
53 | 48 | reg [25:0] counter; |
54 | 49 | always @(posedge clk) begin |
55 | 50 | if (~reset) |
... | ... | |
59 | 54 | end |
60 | 55 | assign led = counter[24]; |
61 | 56 | |
62 | | // Data Bus direction control |
| 57 | // Data Bus direction control |
63 | 58 | wire T = ~noe | ncs; |
64 | 59 | assign sram_data = T?8'bZ:rdBus; |
65 | 60 | |
66 | | // synchronize assignment |
| 61 | // synchronize assignment |
67 | 62 | always @(negedge clk) |
68 | 63 | begin |
69 | 64 | sncs <= ncs; |
... | ... | |
72 | 67 | buffer_addr <= addr; |
73 | 68 | end |
74 | 69 | |
75 | | // write access cpu to bram |
| 70 | // write access cpu to bram |
76 | 71 | always @(posedge clk) |
77 | 72 | if(~reset) {w_st, we, wdBus} <= 0; |
78 | 73 | else begin |
... | ... | |
115 | 110 | else |
116 | 111 | bae <= 8'h00; |
117 | 112 | end |
118 | | wire en1, en2; // enable memory signals |
119 | | assign en0 = bae[0] | bae[1] | bae[2] | bae[3]; |
120 | | assign en1 = bae[4] | bae[5] | bae[6] | bae[7]; |
121 | 113 | |
122 | | reg[31:0] DIA_Aux; |
123 | | always @ (posedge clk) begin |
124 | | if (bae[0]) DIA_Aux[7:0] = wdBus[7:0]; |
125 | | if (bae[1]) DIA_Aux[15:8] = wdBus[7:0]; |
126 | | if (bae[2]) DIA_Aux[23:16] = wdBus[7:0]; |
127 | | if (bae[3]) DIA_Aux[31:24] = wdBus[7:0]; |
128 | | if (bae[4]) DIA_Aux[7:0] = wdBus[7:0]; |
129 | | if (bae[5]) DIA_Aux[15:8] = wdBus[7:0]; |
130 | | if (bae[6]) DIA_Aux[23:16] = wdBus[7:0]; |
131 | | if (bae[7]) DIA_Aux[31:24] = wdBus[7:0]; |
132 | | end |
133 | 114 | |
134 | | reg [2:0] state, nextstate; //FSM for write in 32bit mode to memory |
135 | | wire we0, we1; |
136 | | wire nreset; |
137 | | assign nreset = ~reset; |
138 | | parameter S0 = 3'b000; |
139 | | parameter S1 = 3'b001; |
140 | | parameter S2 = 3'b010; |
141 | | |
142 | | always @ (posedge clk, posedge nreset) |
143 | | if (nreset) state <= S0; |
144 | | else state <= nextstate; |
145 | | // next state logic |
146 | | always@(*) |
147 | | case (state) |
148 | | S0:if (bae[3]&we) nextstate = S1; |
149 | | else |
150 | | if (bae[7]&we) nextstate = S2; |
151 | | else nextstate = S0; |
152 | | S1: nextstate = S0; |
153 | | S2: nextstate = S0; |
154 | | default: nextstate = S0; |
155 | | endcase |
156 | | // output logic |
157 | | assign we0 = (state == S1); |
158 | | assign we1 = (state == S2); |
| 115 | // Memories |
159 | 116 | |
160 | | // Read control |
161 | | reg [7:0] MemDOA; |
162 | | wire [63:0] DOA_Aux; |
163 | | |
164 | | always @(posedge clk) |
165 | | if(~reset)begin |
166 | | rdBus = 8'h00; |
167 | | end |
168 | | else begin |
169 | | if(enReg) |
170 | | rdBus = reg_bank[address]; |
171 | | else |
172 | | rdBus = MemDOA[7:0]; |
173 | | end |
174 | | // memory output mux |
175 | | always @(buffer_addr[2:0]) |
176 | | case (buffer_addr[2:0]) |
177 | | 0 : MemDOA = DOA_Aux[7:0]; |
178 | | 1 : MemDOA = DOA_Aux[15:8]; |
179 | | 2 : MemDOA = DOA_Aux[23:16]; |
180 | | 3 : MemDOA = DOA_Aux[31:24]; |
181 | | 4 : MemDOA = DOA_Aux[39:32]; |
182 | | 5 : MemDOA = DOA_Aux[47:40]; |
183 | | 6 : MemDOA = DOA_Aux[55:48]; |
184 | | 7 : MemDOA = DOA_Aux[63:56]; |
185 | | default: MemDOA = 8'h00; |
186 | | endcase |
187 | | |
188 | | // Store Inputs |
189 | | always @(posedge clk) |
190 | | begin |
191 | | if(enReg) begin |
192 | | reg_bank[20] = error[7:0]; |
193 | | reg_bank[21] = error[15:8]; |
194 | | reg_bank[22] = status[7:0]; |
195 | | reg_bank[24] = mt_rnd[7:0]; |
196 | | reg_bank[25] = mt_rnd[15:8]; |
197 | | reg_bank[26] = mt_rnd[23:16]; |
198 | | reg_bank[27] = mt_rnd[31:24]; |
199 | | end |
200 | | end |
| 117 | RAMB16_S4_S4 ba0( .CLKA(~clk), .ENA(bae[0]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 118 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[3:0]), .DOB(ev_di[3:0])); //D3-D0 |
| 119 | RAMB16_S4_S4 ba1( .CLKA(~clk), .ENA(bae[0]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 120 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[7:4]), .DOB(ev_di[7:4])); //D7-D4 |
| 121 | |
| 122 | RAMB16_S4_S4 ba2( .CLKA(~clk), .ENA(bae[1]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 123 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[11:8]), .DOB(ev_di[11:8])); //D11-D8 |
| 124 | RAMB16_S4_S4 ba3( .CLKA(~clk), .ENA(bae[1]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 125 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[15:12]), .DOB(ev_di[15:12]));//D15-D12 |
| 126 | |
| 127 | RAMB16_S4_S4 ba4( .CLKA(~clk), .ENA(bae[2]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 128 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[19:16]), .DOB(ev_di[19:16])); //D19-D16 |
| 129 | RAMB16_S4_S4 ba5( .CLKA(~clk), .ENA(bae[2]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 130 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[23:20]), .DOB(ev_di[23:20])); //D23-D20 |
201 | 131 | |
202 | | assign address[4:0] = buffer_addr[4:0]; |
203 | | assign enReg = buffer_addr[12]; |
| 132 | RAMB16_S4_S4 ba6( .CLKA(~clk), .ENA(bae[3]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 133 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[27:24]), .DOB(ev_di[27:24])); //D27-D24 |
| 134 | RAMB16_S4_S4 ba7( .CLKA(~clk), .ENA(bae[3]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 135 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[31:28]), .DOB(ev_di[31:28])); //D31-D28 |
204 | 136 | |
205 | | assign reg0[7:0] = reg_bank[0]; |
206 | | assign reg0[15:8] = reg_bank[1]; |
207 | | assign reg0[23:16] = reg_bank[2]; |
208 | | assign reg0[31:24] = reg_bank[3]; |
209 | | assign reg1[7:0] = reg_bank[4]; |
210 | | assign reg1[15:8] = reg_bank[5]; |
211 | | assign reg1[23:16] = reg_bank[6]; |
212 | | assign reg1[31:24] = reg_bank[7]; |
213 | | assign reg2[7:0] = reg_bank[8]; |
214 | | assign reg2[15:8] = reg_bank[9]; |
215 | | assign reg2[23:16] = reg_bank[10]; |
216 | | assign reg2[31:24] = reg_bank[11]; |
217 | | assign reg3[7:0] = reg_bank[12]; |
218 | | assign reg3[15:8] = reg_bank[13]; |
219 | | assign reg3[23:16] = reg_bank[14]; |
220 | | assign reg3[31:24] = reg_bank[15]; |
221 | | assign reg4[7:0] = reg_bank[16]; |
222 | | assign reg4[15:8] = reg_bank[17]; |
223 | | assign reg4[23:16] = reg_bank[18]; |
224 | | assign reg4[31:24] = reg_bank[19]; |
| 137 | RAMB16_S4_S4 ba8( .CLKA(~clk), .ENA(bae[4]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 138 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[35:32]), .DOB(ev_di[35:32])); //D35-D32 |
| 139 | RAMB16_S4_S4 ba9( .CLKA(~clk), .ENA(bae[4]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 140 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[39:36]), .DOB(ev_di[39:36])); //D39-D36 |
225 | 141 | |
226 | | assign max_lev = reg_bank[28]; |
227 | | assign control = reg_bank[29]; |
228 | | assign max_com[7:0] = reg_bank[30]; |
229 | | assign max_com[15:8] = reg_bank[31]; |
230 | | // Write control |
231 | | always @(negedge clk) |
232 | | if(we & enReg) begin |
233 | | case (address) |
234 | | 0: reg_bank[0] = wdBus; |
235 | | 1: reg_bank[1] = wdBus; |
236 | | 2: reg_bank[2] = wdBus; |
237 | | 3: reg_bank[3] = wdBus; |
238 | | 4: reg_bank[4] = wdBus; |
239 | | 5: reg_bank[5] = wdBus; |
240 | | 6: reg_bank[6] = wdBus; |
241 | | 7: reg_bank[7] = wdBus; |
242 | | 8: reg_bank[8] = wdBus; |
243 | | 9: reg_bank[9] = wdBus; |
244 | | 10: reg_bank[10] = wdBus; |
245 | | 11: reg_bank[11] = wdBus; |
246 | | 12: reg_bank[12] = wdBus; |
247 | | 13: reg_bank[13] = wdBus; |
248 | | 14: reg_bank[14] = wdBus; |
249 | | 15: reg_bank[15] = wdBus; |
250 | | 16: reg_bank[16] = wdBus; |
251 | | 17: reg_bank[17] = wdBus; |
252 | | 18: reg_bank[18] = wdBus; |
253 | | 19: reg_bank[19] = wdBus; |
254 | | 28: reg_bank[28] = wdBus; |
255 | | 29: reg_bank[29] = wdBus; |
256 | | 30: reg_bank[30] = wdBus; |
257 | | 31: reg_bank[31] = wdBus; |
258 | | endcase |
259 | | end |
| 142 | RAMB16_S4_S4 ba10(.CLKA(~clk), .ENA(bae[5]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 143 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[43:40]), .DOB(ev_di[43:40])); //D43-D40 |
| 144 | RAMB16_S4_S4 ba11(.CLKA(~clk), .ENA(bae[5]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 145 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[47:44]), .DOB(ev_di[47:44])); //D47-D44 |
260 | 146 | |
261 | | RAMB16_S36_S36 #(.INIT_00(256'hABCDEF00_00000000_00000000_00000000_00000000_00000000_00000000_76543210) ) |
262 | | mem0 ( .CLKA(~clk), .ENA(en0), .SSRA(1'b0), .ADDRA(buffer_addr[11:3]), .WEA(we0), .DIA(DIA_Aux[31:0]), .DIPA(0'b0), .DOA(DOA_Aux[31:0]), |
263 | | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval), .DIB(ev_do[31:0]), .DIPB(0'b0), .DOB(ev_di[31:0])); |
264 | | |
265 | | RAMB16_S36_S36 mem1( .CLKA(~clk), .ENA(en1), .SSRA(1'b0), .ADDRA(buffer_addr[11:3]), .WEA(we1), .DIA(DIA_Aux[31:0]), .DIPA(0'b0), .DOA(DOA_Aux[63:32]), |
266 | | .CLKB(~clk), .ENB(en_ev),.SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval), .DIB(ev_do[63:32]), .DIPB(0'b0), .DOB(ev_di[63:32])); |
| 147 | RAMB16_S4_S4 ba12(.CLKA(~clk), .ENA(bae[6]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 148 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[51:48]), .DOB(ev_di[51:48])); //D51-D48 |
| 149 | RAMB16_S4_S4 ba13(.CLKA(~clk), .ENA(bae[6]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 150 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[55:52]), .DOB(ev_di[55:52])); //D55-D52 |
267 | 151 | |
268 | | // evalfit_peripheral |
269 | | evalfit_peripheral evalfit( .clk(clk), .reset(~reset), .habilita(control[0]), .maxcombs(max_com), .nivel_max(max_lev), |
| 152 | RAMB16_S4_S4 ba14(.CLKA(~clk), .ENA(bae[7]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[3:0]), |
| 153 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[59:56]), .DOB(ev_di[59:56])); //D59-D56 |
| 154 | RAMB16_S4_S4 ba15(.CLKA(~clk), .ENA(bae[7]), .SSRA(1'b0), .ADDRA(buffer_addr[12:3]), .WEA(we), .DIA(wdBus[7:4]), |
| 155 | .CLKB(~clk), .ENB(en_ev), .SSRB(1'b0), .ADDRB(evalfit_addr), .WEB(we_eval),.DIB(ev_do[63:60]), .DOB(ev_di[63:60])); //D63-D60 |
| 156 | |
| 157 | // evalfit_peripheral |
| 158 | evalfit_peripheral evalfit( .clk(clk), .reset(reset), .habilita(control[0]), .maxcombs(max_com), .nivel_max(max_lev), |
270 | 159 | .peripheral_mem_in(ev_di), .peripheral_mem_en(en_eval), .peripheral_mem_out(ev_do), .peripheral_mem_we(we_eval), |
271 | 160 | .peripheral_mem_addr(evalfit_addr), .evalfit3_estado(status), .errores(error), |
272 | 161 | .fin_ack(irq_pin), .reg0_s(reg0), .reg1_s(reg1), .reg2_s(reg2), .reg3_s(reg3), .reg4_s(reg4)); |
273 | 162 | |
274 | | // MersenneTwister |
275 | | mt_mem random( .clk(clk), .ena(1'b1), .resetn(reset), .random(mt_rnd)); |
| 163 | reg_bank RegBank( .clk(clk), .reset(reset), .en(buffer_addr[12]), .we(we), .wdBus(wdBus), .rdBus(rdBus), .address(buffer_addr[4:0]), |
| 164 | .reg0(reg0), .reg1(reg1), .reg2(reg2), .reg3(reg3), .reg4(reg4), .error(error), .status(status), |
| 165 | .max_com(max_com), .max_lev(max_lev), .control(control)); |
| 166 | |
| 167 | // mt_mem |
| 168 | mt_mem random( .clk(clk), .ena(1'b1), .resetn(~reset), .random(mt_rnd)); |
276 | 169 | |
| 170 | |
277 | 171 | endmodule |
278 | 172 | |
Examples/ehw4/src/genetic.c |
14 | 14 | #include "errno.h" |
15 | 15 | #include "sys/un.h" |
16 | 16 | #include "genetic.h" |
| 17 | #include "jz47xx_gpio.h" |
| 18 | #include <jz47xx_mmap.h> |
| 19 | |
| 20 | #define CS2_PORT JZ_GPIO_PORT_B |
| 21 | #define CS2_PIN 26 |
17 | 22 | |
18 | 23 | /************************************************************************************************************************************** |
19 | 24 | imprime un cromosoma completo */ |
... | ... | |
87 | 92 | mascara = (mascara << 1) + 1; |
88 | 93 | }while(max > mascara); |
89 | 94 | |
90 | | if(HW_ENABLE == 1) variable = (*(int *)(evalfit_ptr1 + EVALFIT_RDREG8)) & mascara; |
| 95 | if(HW_ENABLE == 1) variable = (*(int *)(evalfit_ptr1 + EVALFIT_RANDOM)) & mascara; |
91 | 96 | else variable = random() & mascara; |
92 | 97 | |
93 | 98 | while(variable > max) |
... | ... | |
442 | 447 | |
443 | 448 | /** insertar cromosoma en periferico **/ |
444 | 449 | for(i = 0; i < ARBOLES_INDIV; i++) |
445 | | { |
446 | | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i)) = *(char *)(cromo +(LONG_ARBOL*i)+7); |
447 | | // printf("\n%i: %0x",i,*(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i))); |
448 | | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 4) = *(int *)(cromo +(LONG_ARBOL*i)); |
449 | | // printf(": %0x",*(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i)+4)); |
450 | | } |
451 | | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i)) = 0xF; //para terminar |
452 | | i++; |
453 | | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i)) = 0xF; //para terminar |
454 | | |
| 450 | { |
| 451 | *(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0) =*(char *)(cromo +(LONG_ARBOL*i)+7); |
| 452 | //printf("\n%04hhu: Level:%X ", *(cromo+(i*LONG_ARBOL) + 6), *(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0)); |
| 453 | *(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 4) = *(int *)(cromo +(LONG_ARBOL*i)); |
| 454 | //printf("LUT-VARS: %08x",*(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 4)); |
| 455 | } |
| 456 | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0) = 0xF; //para terminar |
| 457 | i++; |
| 458 | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0) = 0xF; //para terminar |
455 | 459 | /** Iniciar **/ |
456 | 460 | *(int *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = CONTROL_START_MASK; |
457 | 461 | } |
... | ... | |
463 | 467 | int errores, puertas, i; |
464 | 468 | |
465 | 469 | // tiempo1 = get_timestamp(); |
466 | | do{ }while((*(int *)(evalfit_ptr + EVALFIT_RDREG1) & DONE_MASK) != 1); |
467 | | // tiempo2 = get_timestamp(); |
468 | | errores = *(int *)(evalfit_ptr + EVALFIT_RDREG2) & ERRORS_MASK; //errores |
469 | | *(int *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = 0; //terminar, bajar habilita |
470 | | |
471 | | puertas = 0; |
| 470 | do{ |
| 471 | //printf("\nSTATUS: %0x",*(short *)(evalfit_ptr + EVALFIT_STATUS)); |
| 472 | //usleep(100); |
| 473 | }while((*(short *)(evalfit_ptr + EVALFIT_STATUS) & DONE_MASK) != 0x8000); //wait for DONE |
| 474 | //tiempo2 = get_timestamp(); |
| 475 | //printf("\n\nErrors calculated HW: %0x",(*(int *)(evalfit_ptr + EVALFIT_ERRORS) & ERRORS_MASK)); //errores |
| 476 | errores = (*(int *)(evalfit_ptr + EVALFIT_ERRORS) & ERRORS_MASK); //errores |
| 477 | *(int *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = 0; //end , disable |
| 478 | puertas = 0; |
472 | 479 | for(i = 0; i < ARBOLES_INDIV; i++) |
473 | 480 | { |
474 | 481 | puertas = puertas + *(puertas_ap + *(char *)(cromo +(LONG_ARBOL*i)+6)); |
475 | 482 | } |
476 | | |
477 | | return ((errores * PESO_SALIDA) + (PESO_PUERTAS * puertas) + (PESO_NIVELES * nivel_max)); |
| 483 | return ((errores * PESO_SALIDA) + (PESO_PUERTAS * puertas) + (PESO_NIVELES * nivel_max)); |
478 | 484 | } |
479 | 485 | |
480 | 486 | /************************************************************************************************************************************** |
... | ... | |
579 | 585 | } |
580 | 586 | } |
581 | 587 | |
| 588 | |
| 589 | /************************************************************************************************************************************** |
| 590 | map peripheral **/ |
| 591 | int periph_map(off_t offset) |
| 592 | { |
| 593 | int basemem, baseperiph; |
| 594 | basemem = open("/dev/mem", (O_RDWR | O_SYNC)); //abrir dispositivo memoria para mapear dir del periferico |
| 595 | if(basemem == -1) |
| 596 | { |
| 597 | printf("Error to open /dev/mem \n"); |
| 598 | return -1; |
| 599 | } |
| 600 | baseperiph = (int )mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, basemem, offset);// & ~MAP_MASK); |
| 601 | if (baseperiph == -1) |
| 602 | { |
| 603 | printf ("Cannot mmap.\n"); |
| 604 | return -1; |
| 605 | } |
| 606 | return baseperiph; |
| 607 | } |
| 608 | |
582 | 609 | /************************************************************************************************************************************** |
583 | 610 | inicializar periferico **/ |
584 | 611 | int init_peripheral(int offset_int, int basemem) |
585 | 612 | { |
586 | 613 | /* Variables para periferico*/ |
587 | | int *aux, base_periferico, *evalfit_ptr; |
588 | | off_t offset = offset_int; //Direccion base del periferico |
589 | | base_periferico = (int *)mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, basemem, offset & ~MAP_MASK); |
590 | | evalfit_ptr = base_periferico + (offset & MAP_MASK); |
591 | | printf("\r\nPeripheral_ptr: %0x", evalfit_ptr); |
592 | | if( (int *)evalfit_ptr == (int *)MAP_FAILED) |
593 | | { printf("error mmap!\n"); |
594 | | fflush(stdout); |
595 | | return -1; |
596 | | } |
597 | | *(int *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = CONTROL_RESET_MASK; //reset |
598 | | *(int *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = 0; |
599 | | printf("\nDate + Status: %0x\n", *(int *)(evalfit_ptr + EVALFIT_STATUS_OFFSET)); |
600 | | return evalfit_ptr; |
| 614 | int *aux, base_periferico, *ConfigRegsBase_ptr, maxcombs, nivel_max; |
| 615 | void *pio, *evalfit_ptr; |
| 616 | basemem = open("/dev/mem", (O_RDWR | O_SYNC)); //abrir dispositivo memoria para mapear dir del periferico |
| 617 | if(basemem == -1) |
| 618 | { |
| 619 | printf("Error al abrir /dev/mem \n"); |
| 620 | return -1; |
| 621 | } |
| 622 | pio = jz_gpio_map(CS2_PORT); |
| 623 | jz_gpio_as_func (pio, CS2_PIN, 0); |
| 624 | ConfigRegsBase_ptr = (int *)periph_map(CONFIG_REGS_BASE);// + SACR2_OFFSET/sizeof(int);//SMCR2_OFFSET/sizeof(int); |
| 625 | printf("\n%0x ", *(ConfigRegsBase_ptr + SMCR2_OFFSET/sizeof(int))); |
| 626 | munmap(ConfigRegsBase_ptr, MAP_SIZE); |
| 627 | evalfit_ptr = (int *)periph_map(EVALFIT_PHYSBASE1); |
| 628 | |
| 629 | printf("\r\nevalfit_ptr: %0x", evalfit_ptr); |
| 630 | if( evalfit_ptr == (int *)MAP_FAILED) |
| 631 | { printf("error mmap!\n"); |
| 632 | fflush(stdout); |
| 633 | return -1; |
| 634 | } |
| 635 | *(char *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = CONTROL_RESET_MASK; //reset |
| 636 | //sleep(1); |
| 637 | *(char *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = 0; |
| 638 | printf("\nDate + Status: %0x\n", *(char *)(evalfit_ptr + EVALFIT_STATUS)); |
| 639 | return evalfit_ptr; |
601 | 640 | } |
602 | 641 | |
603 | 642 | /************************************************************************************************************************************** |
... | ... | |
643 | 682 | /* datos = malloc(sizeof(datos)*maxgeneraciones*2); if(datos==0) printf("Error en malloc");*/ |
644 | 683 | /* x=0;*/ |
645 | 684 | |
646 | | objetivo = gen_datos -> objetivo; |
647 | | tamaobj = gen_datos -> tamaobj; |
648 | | pentarboles = gen_datos -> pentarboles; |
649 | | tamacromo = gen_datos -> tamacrom; |
650 | | cromo_sal = gen_datos -> cromo_sal; |
651 | | fitness_sal = gen_datos -> fitness; |
652 | | cromo_entrada = gen_datos -> cromo_entrada; |
653 | | fitness_entrada = gen_datos -> fitness_entrada; |
654 | | nivel_max = gen_datos -> nivel_max; |
655 | | vars = gen_datos -> vars; |
656 | | generacion = gen_datos->generacion; |
657 | | aux = gen_datos->aux; |
658 | | aux_sal = gen_datos->aux_sal; |
659 | | |
660 | | cromo = malloc(sizeof(cromo) * (poblacion + 2) * LONG_INDIV); if(cromo==0) printf("Error en malloc"); |
661 | | fitness = malloc(sizeof(fitness) * (poblacion+1)); if(fitness==0) printf("Error en malloc"); |
662 | | fitness2 = malloc(sizeof(fitness2) * (poblacion+1)); if(fitness2==0) printf("Error en malloc"); |
663 | | ordenpoblacion = malloc(sizeof(ordenpoblacion) * (poblacion+1)); if(ordenpoblacion==0) printf("Error en malloc"); |
| 685 | objetivo = gen_datos -> objetivo; |
| 686 | tamaobj = gen_datos -> tamaobj; |
| 687 | pentarboles = gen_datos -> pentarboles; |
| 688 | tamacromo = gen_datos -> tamacrom; |
| 689 | cromo_sal = gen_datos -> cromo_sal; |
| 690 | fitness_sal = gen_datos -> fitness; |
| 691 | cromo_entrada = gen_datos -> cromo_entrada; |
| 692 | fitness_entrada = gen_datos -> fitness_entrada; |
| 693 | nivel_max = gen_datos -> nivel_max; |
| 694 | vars = gen_datos -> vars; |
| 695 | generacion = gen_datos->generacion; |
| 696 | aux = gen_datos->aux; |
| 697 | aux_sal = gen_datos->aux_sal; |
| 698 | |
| 699 | cromo = malloc(sizeof(cromo) * (poblacion + 2) * LONG_INDIV); if(cromo==0) printf("Error en malloc"); |
| 700 | fitness = malloc(sizeof(fitness) * (poblacion+1)); if(fitness==0) printf("Error en malloc"); |
| 701 | fitness2 = malloc(sizeof(fitness2) * (poblacion+1)); if(fitness2==0) printf("Error en malloc"); |
| 702 | ordenpoblacion = malloc(sizeof(ordenpoblacion) * (poblacion+1)); if(ordenpoblacion==0) printf("Error en malloc"); |
664 | 703 | |
665 | 704 | if(gen_datos->en_cromo_entrada == 1) |
666 | | { |
| 705 | { |
667 | 706 | for(i = 0; i < LONG_INDIV; i++ ) |
668 | 707 | { |
669 | 708 | *(char *)(cromo + i) = *(char *)(cromo_entrada + i); |
670 | 709 | } |
671 | | } |
| 710 | } |
672 | 711 | |
673 | | if(gen_datos->en_cromo_entrada==0) gen_poblacion(cromo, pentarboles, vars, poblacion); |
674 | | else gen_poblacion(cromo + LONG_INDIV, pentarboles, vars, poblacion-1); |
| 712 | if(gen_datos->en_cromo_entrada == 0) |
| 713 | gen_poblacion(cromo, pentarboles, vars, poblacion); //generate chromosome |
| 714 | else |
| 715 | gen_poblacion(cromo + LONG_INDIV, pentarboles, vars, poblacion-1); |
675 | 716 | |
676 | | for(i = 0; i < poblacion; i++) |
677 | | { |
678 | | *(ordenpoblacion + i) = i; //se inicializa el stream para el orden poblacional |
679 | | *(fitness + i) = 100000; |
680 | | *(fitness2 + i) = 100000; |
681 | | } |
| 717 | for(i = 0; i < poblacion; i++) |
| 718 | { |
| 719 | *(ordenpoblacion + i) = i; //se inicializa el stream para el orden poblacional |
| 720 | *(fitness + i) = 100000; |
| 721 | *(fitness2 + i) = 100000; |
| 722 | } |
682 | 723 | |
683 | 724 | /** copiar miniterminos a periferico **/ |
684 | 725 | if(HW_ENABLE == 1) { |
685 | 726 | minterm2peripheral(objetivo, tamaobj, (int *)(evalfit_ptr1)); |
| 727 | /* |
686 | 728 | minterm2peripheral(objetivo, tamaobj, (int *)(evalfit_ptr2)); |
687 | 729 | minterm2peripheral(objetivo, tamaobj, (int *)(evalfit_ptr3)); |
688 | 730 | minterm2peripheral(objetivo, tamaobj, (int *)(evalfit_ptr4)); |
| 731 | */ |
689 | 732 | } |
690 | 733 | |
691 | 734 | /** Insertar maxcombs y nivel_max **/ |
692 | 735 | if(HW_ENABLE == 1) { |
693 | 736 | *(int *)(evalfit_ptr1 + EVALFIT_WREG4) = (COMBS-1) + (nivel_max << 16); |
| 737 | /* |
694 | 738 | *(int *)(evalfit_ptr2 + EVALFIT_WREG4) = (COMBS-1) + (nivel_max << 16); |
695 | 739 | *(int *)(evalfit_ptr3 + EVALFIT_WREG4) = (COMBS-1) + (nivel_max << 16); |
696 | 740 | *(int *)(evalfit_ptr4 + EVALFIT_WREG4) = (COMBS-1) + (nivel_max << 16); |
| 741 | */ |
697 | 742 | } |
698 | 743 | o=0; |
699 | 744 | *generacion = 0; |
... | ... | |
726 | 771 | // evaluar cromosomas de poblacion |
727 | 772 | o=0; |
728 | 773 | // tiempo1 = get_timestamp(); |
729 | | for(i = 0; i < poblacion; i=i+4) |
| 774 | for(i = 0; i < poblacion; i=i+1) |
730 | 775 | { |
731 | 776 | if(HW_ENABLE == 1) |
732 | 777 | { |
733 | 778 | evalfit_hw_init((cromo + (i * LONG_INDIV)), pentarboles, nivel_max, (int *)evalfit_ptr1); |
| 779 | /* |
734 | 780 | evalfit_hw_init((cromo + ((i+1) * LONG_INDIV)), pentarboles, nivel_max, (int *)evalfit_ptr2); |
735 | 781 | evalfit_hw_init((cromo + ((i+2) * LONG_INDIV)), pentarboles, nivel_max, (int *)evalfit_ptr3); |
736 | 782 | evalfit_hw_init((cromo + ((i+3) * LONG_INDIV)), pentarboles, nivel_max, (int *)evalfit_ptr4); |
| 783 | */ |
737 | 784 | *(fitness + i) = evalfit_hw_wait((cromo + (i * LONG_INDIV)), pentarboles, nivel_max, (int *)evalfit_ptr1); |
| 785 | /* |
738 | 786 | *(fitness + i+1) = evalfit_hw_wait((cromo + ((i+1) * LONG_INDIV)), pentarboles,nivel_max, (int *)evalfit_ptr2); |
739 | 787 | *(fitness + i+2) = evalfit_hw_wait((cromo + ((i+2) * LONG_INDIV)), pentarboles,nivel_max, (int *)evalfit_ptr3); |
740 | 788 | *(fitness + i+3) = evalfit_hw_wait((cromo + ((i+3) * LONG_INDIV)), pentarboles, nivel_max, (int *)evalfit_ptr4); |
| 789 | */ |
741 | 790 | }else{ |
742 | 791 | *(fitness + i) = eval_fit_sw((cromo + (i * LONG_INDIV)), objetivo, tamaobj, pentarboles, vars); |
| 792 | /* |
743 | 793 | *(fitness + i+1) = eval_fit_sw((cromo + ((i+1) * LONG_INDIV)), objetivo, tamaobj, pentarboles, vars); |
744 | 794 | *(fitness + i+2) = eval_fit_sw((cromo + ((i+2) * LONG_INDIV)), objetivo, tamaobj, pentarboles, vars); |
745 | 795 | *(fitness + i+3) = eval_fit_sw((cromo + ((i+3) * LONG_INDIV)), objetivo, tamaobj, pentarboles, vars); |
| 796 | */ |
746 | 797 | } |
747 | 798 | *(fitness2 + i) = *(fitness + i); |
| 799 | /* |
748 | 800 | *(fitness2 + i+1) = *(fitness + i+1); |
749 | 801 | *(fitness2 + i+2) = *(fitness + i+2); |
750 | 802 | *(fitness2 + i+3) = *(fitness + i+3); |
| 803 | */ |
751 | 804 | |
752 | 805 | if(*(fitness + i) < PESO_SALIDA) |
753 | 806 | { |
Examples/ehw4/src/sintesishw_client.c |
244 | 244 | |
245 | 245 | int main( int argc, char** argv ) |
246 | 246 | { |
247 | | int *generacion, k, a, b, z, i, j= 0, error, nivel_max, vars, *tiempo, poblacion_total, m, p, iteraciones, T; |
248 | | int conta=0, aux1, aux2, pentarboles, *fitness1, *fitness2, *entrada, *orderesult, aux, *aux_sal; |
249 | | char o, *ap, *valor_devuelto;; |
250 | | char *cromo_sal1, *cromo_sal2, *cromo_entrada; |
251 | | int tamaobj, objetivo[8192], obj_combs;//= {0,254,123,16,87,56,34,76,89,155,199}; |
252 | | long int tiempo1, tiempo2; |
253 | | float tiempof, tiempof2, Tfloat, float1, float2; |
| 247 | int *generacion, k, a, b, z, i, j= 0, error, nivel_max, vars, *tiempo, poblacion_total, m, p, iteraciones, T; |
| 248 | int conta=0, aux1, aux2, pentarboles, *fitness1, *fitness2, *entrada, *orderesult, aux, *aux_sal; |
| 249 | char o, *ap, *valor_devuelto;; |
| 250 | char *cromo_sal1, *cromo_sal2, *cromo_entrada; |
| 251 | int tamaobj, objetivo[8192], obj_combs;//= {0,254,123,16,87,56,34,76,89,155,199}; |
| 252 | long int tiempo1, tiempo2; |
| 253 | float tiempof, tiempof2, Tfloat, float1, float2; |
254 | 254 | |
255 | 255 | int nivel2[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; |
256 | 256 | int nivel3[]={0,0,1,1,1,2,2,2,2,3,3, 3, 3, 4, 4, 4}; |
... | ... | |
258 | 258 | int nivel5[]={0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0}; |
259 | 259 | |
260 | 260 | /* Estructuras para datos de cromosomas*/ |
261 | | struct gen_datos_tipo data_struct1, data_struct2; |
262 | | struct gen_datos_tipo *data_struct_ap1, *data_struct_ap2; |
263 | | data_struct_ap1 = &data_struct1; |
264 | | data_struct_ap2 = &data_struct2; |
| 261 | struct gen_datos_tipo data_struct1, data_struct2; |
| 262 | struct gen_datos_tipo *data_struct_ap1, *data_struct_ap2; |
| 263 | data_struct_ap1 = &data_struct1; |
| 264 | data_struct_ap2 = &data_struct2; |
265 | 265 | |
266 | 266 | /* Variables para tablas de lut*/ |
267 | | FILE *f1; |
268 | | int size1; |
269 | | srand ( (time(NULL)) ); |
| 267 | FILE *f1; |
| 268 | int size1; |
| 269 | srand ( (time(NULL)) ); |
270 | 270 | |
271 | 271 | /* Variables para almacenar datos para graficar*/ |
272 | | int *datos, *datos2, x, media=4, puntos; |
273 | | FILE *fich, *fich2; |
| 272 | int *datos, *datos2, x, media=4, puntos; |
| 273 | FILE *fich, *fich2; |
274 | 274 | |
275 | 275 | char output_file_name[128], output_file_fitness_name[128]; |
276 | 276 | sscanf(argv[1], "%i",&vars); |
... | ... | |
279 | 279 | sscanf(argv[4], "%i", &nodos); |
280 | 280 | sscanf(argv[5], "%s", output_file_name); |
281 | 281 | sscanf(argv[6], "%s", output_file_fitness_name); |
282 | | // printf("\nvars: %i indivs:%i generations:%i nodos:%i ", vars, poblacion_total, maxgeneraciones, nodos); |
| 282 | printf("\nvars: %i indivs:%i generations:%i nodos:%i ", vars, poblacion_total, maxgeneraciones, nodos); |
283 | 283 | fflush(stdout); |
284 | 284 | |
285 | | pentarboles = 1; //MODIFIQUE NIVEL_MAX |
286 | | nivel_max = 2; |
287 | | poblacion = poblacion_total/nodos; |
| 285 | pentarboles = 1; //MODIFIQUE NIVEL_MAX |
| 286 | nivel_max = 2; |
| 287 | poblacion = poblacion_total/nodos; |
288 | 288 | m = 1; //datos a migrar |
289 | | p = 8; //frecuencia de migracion |
| 289 | p = maxgeneraciones;//8; //frecuencia de migracion |
290 | 290 | T = 4; //temperatura para crear nuevos indiv. A mayor T menor temperatura |
291 | 291 | i=0; |
292 | 292 | tamaobj=0; |
... | ... | |
297 | 297 | obj_combs = pow(2, (vars/2)); |
298 | 298 | |
299 | 299 | /*Armar funcion objetivo comparador*/ /* OJO, SE ESTÁN METIENDO VALORES DE 1EXX EN LAS LUT Y ESOS INDIVIDUOS AL PARECER QUEDAN MAL */ |
300 | | for(a=0; a < obj_combs ;a++) |
301 | | { |
302 | | for(b=0; b < obj_combs ;b++) |
303 | | { |
304 | | if(a > b)z=1; if(a < b)z=2; if(a == b)z=4; |
305 | | if((z & 0x4) != 0 ) |
306 | | { |
307 | | objetivo[tamaobj] = i; |
308 | | printf("%i ",objetivo[tamaobj]); |
309 | | tamaobj++; |
310 | | } |
311 | | i++; |
312 | | } |
313 | | } |
| 300 | for(a=0; a < obj_combs ;a++) |
| 301 | { |
| 302 | for(b=0; b < obj_combs ;b++) |
| 303 | { |
| 304 | if(a > b)z=1; if(a < b)z=2; if(a == b)z=4; |
| 305 | if((z & 0x4) != 0 ) |
| 306 | { |
| 307 | objetivo[tamaobj] = i; |
| 308 | printf("%i ",objetivo[tamaobj]); |
| 309 | tamaobj++; |
| 310 | } |
| 311 | i++; |
| 312 | } |
| 313 | } |
314 | 314 | // printf("Tama:%i ",tamaobj); |
315 | 315 | |
316 | 316 | /* Tabla para las LUT*/ |
317 | | f1 = fopen("funlut.dat","r"); |
318 | | if(f1 == NULL){ |
319 | | printf("\nError de lectura de archivo!"); |
320 | | return 0;} |
321 | | |
322 | | fseek (f1, 0, SEEK_END); |
323 | | size1 = ftell(f1); |
324 | | funlut_ap = malloc(size1); if(funlut_ap==0) printf("Error en malloc"); |
325 | | rewind (f1); |
326 | | fread(funlut_ap,1,size1,f1); |
327 | | fclose(f1); |
328 | | |
329 | | puntos = 16; /*numero de puntos para la grafica*/ |
330 | | datos = malloc(sizeof(datos)*puntos*3); if(datos==0) printf("Error en malloc"); |
331 | | fich=fopen(output_file_name,"wb"); |
332 | | datos2 = malloc(sizeof(datos2) * maxgeneraciones * p * nodos); if(datos2==0) printf("Error en malloc"); |
333 | | fich2=fopen(output_file_fitness_name,"wb"); |
| 317 | f1 = fopen("funlut.dat","r"); |
| 318 | if(f1 == NULL){ |
| 319 | printf("\nError de lectura de archivo!"); |
| 320 | return 0;} |
| 321 | |
| 322 | fseek (f1, 0, SEEK_END); |
| 323 | size1 = ftell(f1); |
| 324 | funlut_ap = malloc(size1); if(funlut_ap==0) printf("Error en malloc"); |
| 325 | rewind (f1); |
| 326 | fread(funlut_ap,1,size1,f1); |
| 327 | fclose(f1); |
| 328 | |
| 329 | puntos = 16; /*numero de puntos para la grafica*/ |
| 330 | datos = malloc(sizeof(datos)*puntos*3); if(datos==0) printf("Error en malloc"); |
| 331 | fich=fopen(output_file_name,"wb"); |
| 332 | datos2 = malloc(sizeof(datos2) * maxgeneraciones * p * nodos); if(datos2==0) printf("Error en malloc"); |
| 333 | fich2=fopen(output_file_fitness_name,"wb"); |
334 | 334 | |
335 | 335 | cromo_sal1 = malloc(sizeof(cromo_sal1) * RESULTADOS * LONG_INDIV * nodos); if(cromo_sal1==0) printf("Error en malloc"); |
336 | | fitness1 = malloc(sizeof(fitness1) * RESULTADOS * nodos); if(fitness1==0) printf("Error en malloc"); |
337 | | cromo_sal2 = malloc(sizeof(cromo_sal2) * RESULTADOS * LONG_INDIV * nodos); if(cromo_sal2==0) printf("Error en malloc"); |
338 | | fitness2 = malloc(sizeof(fitness2) * RESULTADOS * nodos); if(fitness2==0) printf("Error en malloc"); |
339 | | cromo_sal2 = malloc(sizeof(cromo_sal2) * RESULTADOS * LONG_INDIV * nodos); if(cromo_sal2==0) printf("Error en malloc"); |
340 | | generacion = malloc(sizeof(generacion)* RESULTADOS * nodos); if(generacion==0) printf("Error en malloc"); |
341 | | tiempo = malloc(sizeof(tiempo)* RESULTADOS * nodos); if(tiempo==0) printf("Error en malloc"); |
342 | | cromo_entrada = malloc(sizeof(cromo_entrada)* LONG_INDIV * m); if(cromo_entrada==0) printf("Error en malloc"); |
| 336 | fitness1 = malloc(sizeof(fitness1) * RESULTADOS * nodos); if(fitness1==0) printf("Error en malloc"); |
| 337 | cromo_sal2 = malloc(sizeof(cromo_sal2) * RESULTADOS * LONG_INDIV * nodos); if(cromo_sal2==0) printf("Error en malloc"); |
| 338 | fitness2 = malloc(sizeof(fitness2) * RESULTADOS * nodos); if(fitness2==0) printf("Error en malloc"); |
| 339 | cromo_sal2 = malloc(sizeof(cromo_sal2) * RESULTADOS * LONG_INDIV * nodos); if(cromo_sal2==0) printf("Error en malloc"); |
| 340 | generacion = malloc(sizeof(generacion)* RESULTADOS * nodos); if(generacion==0) printf("Error en malloc"); |
| 341 | tiempo = malloc(sizeof(tiempo)* RESULTADOS * nodos); if(tiempo==0) printf("Error en malloc"); |
| 342 | cromo_entrada = malloc(sizeof(cromo_entrada)* LONG_INDIV * m); if(cromo_entrada==0) printf("Error en malloc"); |
343 | 343 | orderesult = malloc(sizeof(orderesult) * nodos*RESULTADOS); if(orderesult==0) printf("Error en malloc"); |
344 | 344 | aux_sal = malloc(sizeof(aux_sal) * nodos * maxgeneraciones * 2); if(aux_sal==0) printf("Error en malloc"); |
345 | 345 | |
346 | | data_struct_ap1->objetivo = objetivo; |
347 | | data_struct_ap1->tamaobj = tamaobj; |
348 | | data_struct_ap1->pentarboles = pentarboles; |
349 | | data_struct_ap1->maxgen = maxgeneraciones; |
350 | | data_struct_ap1->cromo_sal = cromo_sal1; |
351 | | data_struct_ap1->fitness = fitness1; |
352 | | data_struct_ap1->cromo_entrada = cromo_entrada; |
353 | | data_struct_ap1->fitness_entrada = 0; |
354 | | data_struct_ap1->nivel_max = nivel_max; |
355 | | data_struct_ap1->vars= vars; |
356 | | data_struct_ap1->en_cromo_entrada = 0; |
357 | | data_struct_ap1->generacion = generacion; |
358 | | data_struct_ap1->tiempo = tiempo; |
359 | | data_struct_ap1->aux = aux; |
360 | | data_struct_ap1->aux_sal = aux_sal; |
| 346 | data_struct_ap1->objetivo = objetivo; |
| 347 | data_struct_ap1->tamaobj = tamaobj; |
| 348 | data_struct_ap1->pentarboles = pentarboles; |
| 349 | data_struct_ap1->maxgen = maxgeneraciones; |
| 350 | data_struct_ap1->cromo_sal = cromo_sal1; |
| 351 | data_struct_ap1->fitness = fitness1; |
| 352 | data_struct_ap1->cromo_entrada = cromo_entrada; |
| 353 | data_struct_ap1->fitness_entrada = 0; |
| 354 | data_struct_ap1->nivel_max = nivel_max; |
| 355 | data_struct_ap1->vars= vars; |
| 356 | data_struct_ap1->en_cromo_entrada = 0; |
| 357 | data_struct_ap1->generacion = generacion; |
| 358 | data_struct_ap1->tiempo = tiempo; |
| 359 | data_struct_ap1->aux = aux; |
| 360 | data_struct_ap1->aux_sal = aux_sal; |
361 | 361 | |
362 | 362 | /* printf("\npentarboles:%i nivel_max%i ", pentarboles ,nivel_max);*/ |
363 | 363 | /* fflush(stdout); */ |
364 | 364 | |
365 | | /* Iniciar evolucion */ |
366 | | |
367 | | x = 0; |
368 | | fflush(stdout); |
| 365 | /* Iniciar evolucion */ |
| 366 | x = 0; |
369 | 367 | for(k = 0; k < iteraciones ; k++) |
370 | 368 | { |
371 | 369 | tiempo1 = get_timestamp(); |
372 | | iniciar_evol(data_struct_ap1); |
| 370 | iniciar_evol(data_struct_ap1); //evolution |
373 | 371 | tiempo2 = get_timestamp(); |
374 | 372 | *tiempo = tiempo2 - tiempo1; |
375 | 373 | tiempof2 = *tiempo; |
376 | 374 | tiempof = tiempof2/(1000000); |
377 | | // printf("\n%i %i %i %5f",nodos, vars, poblacion_total, tiempof); |
378 | | fprintf(fich, "\n%i %i %i %5f",nodos, vars, poblacion_total, tiempof); |
| 375 | printf("\n%i %i %i %5f",nodos, vars, poblacion_total, tiempof); |
| 376 | //fprintf(fich, "\n%i %i %i %5f",nodos, vars, poblacion_total, tiempof); |
379 | 377 | |
380 | 378 | for(i = 0; i < nodos*RESULTADOS; i++) //Organizar lo q llego, ¡solo se indexa orderesult, que dice en q orden estan los cromosomas! |
381 | 379 | { |
Examples/ehw4/src/test/EvalfitTest.c |
| 1 | /*********************************************************************************************************** |
| 2 | * programa para hacer test perifericos evalfit del proyecto ehw4, con mersenne twister incorporado |
| 3 | * |
| 4 | * Funciona con HW evalfit hasta con 14 vars. Evalfit funciona para 5 arboles. nivel max de 4. |
| 5 | * |
| 6 | ************************************************************************************************************/ |
| 7 | |
| 8 | // clk => PLB_Clk, |
| 9 | // reset => regs_wr(0)(0), |
| 10 | // habilita => regs_wr(0)(1), |
| 11 | // maxcombs => regs_wr(4)(16 to 31), |
| 12 | // nivel_max => regs_wr(4)(12 to 15), |
| 13 | // peripheral_mem_in => do_mem_usr,-- 64 bits |
| 14 | // peripheral_mem_en => en_mem_usr, |
| 15 | // peripheral_mem_out => di_mem_usr, -- 64 bits |
| 16 | // peripheral_mem_we => we_mem_usr, |
| 17 | // peripheral_mem_addr => addr_mem_usr, --9 bits |
| 18 | // evalfit3_estado => regs_rd(1)(8 to 15), |
| 19 | // errores => regs_rd(2)(16 to 31), |
| 20 | // fin_ack => regs_rd(1)(31) ); |
| 21 | |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <termios.h> |
| 25 | #include <sys/mman.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <time.h> |
| 31 | #include <evalfit.h> |
| 32 | #include "jz47xx_gpio.h" |
| 33 | #include <jz47xx_mmap.h> |
| 34 | |
| 35 | #define CS2_PORT JZ_GPIO_PORT_B |
| 36 | #define CS2_PIN 26 |
| 37 | |
| 38 | typedef long long timestamp_t; |
| 39 | static timestamp_t |
| 40 | get_timestamp () |
| 41 | { |
| 42 | struct timeval now; |
| 43 | gettimeofday (&now, NULL); |
| 44 | return now.tv_usec + (timestamp_t)now.tv_sec *1000000 ; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | int nivel2(int pentarboles) |
| 49 | { |
| 50 | int x; |
| 51 | if(nivel1 > 1) |
| 52 | x = (int)ceil((float)nivel1 / 4); |
| 53 | else |
| 54 | x = 0; |
| 55 | return x; |
| 56 | |
| 57 | } |
| 58 | int nivel3(int pentarboles) |
| 59 | { |
| 60 | int x; |
| 61 | if(nivel2(pentarboles) > 1) |
| 62 | x = (int)ceil((float)nivel1 / 16); |
| 63 | else |
| 64 | x = 0; |
| 65 | return x; |
| 66 | } |
| 67 | int nivel4(int pentarboles) |
| 68 | { |
| 69 | int x; |
| 70 | if(nivel3(pentarboles) > 1) |
| 71 | x = (int)ceil((float)nivel1/ 64); |
| 72 | else |
| 73 | x = 0; |
| 74 | return x; |
| 75 | } |
| 76 | int nivel5(int pentarboles) |
| 77 | { |
| 78 | int x; |
| 79 | if(nivel4(pentarboles) > 1) |
| 80 | x = (int)ceil((float)nivel1 / 256); |
| 81 | else |
| 82 | x = 0; |
| 83 | return x; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /************************************************************************************************************************************** |
| 88 | genera un numero de forma aleatoria*/ |
| 89 | char random_var(int max) |
| 90 | { |
| 91 | char variable, mascara; |
| 92 | int i; |
| 93 | mascara = 1; |
| 94 | do |
| 95 | { |
| 96 | mascara = (mascara << 1) + 1; |
| 97 | }while(max > mascara); |
| 98 | variable = random() & mascara; |
| 99 | |
| 100 | while(variable > max) |
| 101 | { |
| 102 | variable = variable - max; |
| 103 | } |
| 104 | return variable; |
| 105 | } |
| 106 | |
| 107 | /************************************************************************************************************************************** |
| 108 | imprime un cromosoma completo */ |
| 109 | void mostrar_indiv_lut(char *cromo, int pentarboles) |
| 110 | { |
| 111 | char *ap, i, fn[8] = {'!', '&', '^', '|', '_'}; //NOT, AND, XOR, OR, NADA o YES |
| 112 | char vn[] = {'A', 'B', 'C', 'D', 'E' , 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', '.'}; |
| 113 | ap = cromo; |
| 114 | |
| 115 | if(*(cromo + 7) == 1) |
| 116 | { |
| 117 | vn[VARS] = '.'; |
| 118 | printf(": %0x%c%c%c%c", *(unsigned short int *)ap, vn[*(ap+2) >> 4], vn[*(ap+2) & 0xF], vn[*(ap+3) >> 4], vn[*(ap+3) & 0xF]); |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | vn[4] = '.'; |
| 123 | printf(": %0x%c%c%c%c", *(unsigned short int *)ap, vn[*(ap+2) >> 4], vn[*(ap+2) & 0xF], vn[*(ap+3) >> 4], vn[*(ap+3) & 0xF]); |
| 124 | } |
| 125 | printf("\t %0x %0x ", *(short int *)(ap+2), *(ap+6) ); |
| 126 | for(i = 0; i < LONG_ARBOL; i++) |
| 127 | { |
| 128 | printf("%0x,",*(cromo+i)); |
| 129 | } |
| 130 | // printf("\n"); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /************************************************************************************************************************************** |
| 135 | imprime un cromosoma completo */ |
| 136 | void mostrar_indiv(char *cromo, int pentarboles) |
| 137 | { |
| 138 | char *ap, i, fn[8] = {'!', '&', '^', '|', '_'}; //NOT, AND, XOR, OR, NADA o YES |
| 139 | char vn[] = {'A', 'B', 'C', 'D', 'E' , 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', '.'}; |
| 140 | |
| 141 | ap = cromo; |
| 142 | for(i = 0; i < ARBOLES_INDIV; i++){ |
| 143 | if(*(cromo + (i * LONG_ARBOL) + 7) == 1) |
| 144 | { |
| 145 | vn[VARS] = '.'; |
| 146 | printf(" %c%c%c%c%c%c%c", fn[*ap], fn[*(ap+1)], vn[*(ap+2)], vn[*(ap+3)], fn[*(ap+4)], vn[*(ap+5)], vn[*(ap+6)]); |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | vn[4] = '.'; |
| 151 | printf(" %c%c%c%c%c%c%c", fn[*ap], fn[*(ap+1)], vn[*(ap+2)], vn[*(ap+3)], fn[*(ap+4)], vn[*(ap+5)], vn[*(ap+6)]); |
| 152 | } |
| 153 | ap = ap + LONG_ARBOL; |
| 154 | } |
| 155 | printf("\t"); |
| 156 | //for(i = 0; i < LONG_INDIV; i++) |
| 157 | //{ |
| 158 | // printf("%i,",*(cromo+i)); |
| 159 | //} |
| 160 | printf("\n"); |
| 161 | } |
| 162 | |
| 163 | /************************************************************************************************************************************** |
| 164 | imprime un cromosoma completo */ |
| 165 | void mostrar_indiv2(char *cromo, int pentarboles) |
| 166 | { |
| 167 | char *ap, i, fn[8] = {'!', '&', '^', '|', '_'}; //NOT, AND, XOR, OR, NADA o YES |
| 168 | char vn[] = {'A', 'B', 'C', 'D', 'E' , 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', '.'}; |
| 169 | |
| 170 | ap = cromo; |
| 171 | |
| 172 | if(*(cromo + (i * LONG_ARBOL) + 7) == 1) |
| 173 | { |
| 174 | vn[VARS] = '.'; |
| 175 | printf(" %c%c%c%c%c%c%c", fn[*ap], fn[*(ap+1)], vn[*(ap+2)], vn[*(ap+3)], fn[*(ap+4)], vn[*(ap+5)], vn[*(ap+6)]); |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | vn[4] = '.'; |
| 180 | printf(" %c%c%c%c%c%c%c", fn[*ap], fn[*(ap+1)], vn[*(ap+2)], vn[*(ap+3)], fn[*(ap+4)], vn[*(ap+5)], vn[*(ap+6)]); |
| 181 | } |
| 182 | |
| 183 | printf("\n"); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /************************************************************************************************************************************** |
| 188 | Genera un arbol de forma aleatoria |
| 189 | Las funciones y variables son representadas por enteros del 0 al 3 o mas... |
| 190 | - el arbol se encuentra compuesto de tres funciones, dos de entrada y una de salida. |
| 191 | */ |
| 192 | void gen_arbol_lut(char *ap, int variables) |
| 193 | { |
| 194 | int lut; |
| 195 | short int dato_lut; |
| 196 | lut = random_var(FUNCOMBS-1); |
| 197 | dato_lut = (*(funlut_ap+(lut*2)) << 8) + (*(funlut_ap+(lut*2)+1)); |
| 198 | *(short int *)ap = dato_lut; |
| 199 | *(ap+2) = *(ap+3) = 0; |
| 200 | *(ap+2) = random_var(variables-1) + (random_var(variables-1) << 4); |
| 201 | *(ap+3) = random_var(variables-1) + (random_var(variables-1) << 4); |
| 202 | *(ap+6) = lut;(ap); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /************************************************************************************************************************************** |
| 207 | Genera un arbol de forma aleatoria |
| 208 | - estructura de un arbol: FFVVFVV F = funcion V = variable |
| 209 | Las funciones y variables son representadas por enteros del 0 al 3 o mas... |
| 210 | - el arbol se encuentra compuesto de tres funciones, dos de entrada y una de salida. |
| 211 | */ |
| 212 | void gen_arbol(char *ap, int variables) |
| 213 | { |
| 214 | *ap = random_var((FUNCIONES)); //funcion de salida, no YES |
| 215 | *(ap+1) = random_var(FUNCIONES); //PRIMER ARBOL |
| 216 | *(ap+2) = random_var(variables); |
| 217 | *(ap+3) = random_var(variables); |
| 218 | *(ap+4) = random_var(FUNCIONES); //SEGUNDO ARBOL |
| 219 | *(ap+5) = random_var(variables); |
| 220 | *(ap+6) = random_var(variables); |
| 221 | |
| 222 | } |
| 223 | |
| 224 | |
| 225 | /************************************************************************************************************************************** |
| 226 | genera un individuo de forma aleatoria */ |
| 227 | void gen_indiv(char *cromo, int pentarboles) |
| 228 | { |
| 229 | char i=0; |
| 230 | int n1, n2, n3, n4, n5, c1, c2, c3, c4, c5, sig, indice; |
| 231 | n1 = n2 = n3 = n4 = n5 = 0; |
| 232 | c1 = c2 = c3 = c4 = c5 = 0; |
| 233 | indice = 0; |
| 234 | |
| 235 | sig=1; |
| 236 | |
| 237 | |
| 238 | do |
| 239 | { |
| 240 | |
| 241 | if((sig == 1) && (c1 < nivel1)) |
| 242 | { |
| 243 | gen_arbol(cromo + (indice * LONG_ARBOL), VARS-1); |
| 244 | *(cromo +(indice*LONG_ARBOL) + 7) = 1; |
| 245 | n1 ++; |
| 246 | c1 ++; |
| 247 | indice ++; |
| 248 | if(n1 < 4) |
| 249 | sig = 1; |
| 250 | else |
| 251 | { |
| 252 | sig = 2; |
| 253 | n1 = 0; |
| 254 | }//printf("1"); |
| 255 | } |
| 256 | else |
| 257 | { |
| 258 | if((sig == 2) && (c2 < nivel2(pentarboles))) |
| 259 | { |
| 260 | gen_arbol(cromo + (indice*LONG_ARBOL), 3); |
| 261 | *(cromo +(indice*LONG_ARBOL) + 7) = 2; |
| 262 | n2++; |
| 263 | c2 ++; |
| 264 | indice ++; |
| 265 | if(c2 == nivel2(pentarboles)) |
| 266 | sig = 3; |
| 267 | else |
| 268 | { |
| 269 | if(n2 < 4) |
| 270 | sig = 1; |
| 271 | else |
| 272 | { |
| 273 | sig = 3; |
| 274 | n2 = 0; |
| 275 | } |
| 276 | }//printf("2"); |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | if((sig == 3) && (c3 < nivel3(pentarboles))) |
| 281 | { |
| 282 | gen_arbol(cromo + (indice*LONG_ARBOL), 3); |
| 283 | *(cromo +(indice*LONG_ARBOL) + 7) = 3; |
| 284 | n3++; |
| 285 | c3++; |
| 286 | indice++; |
| 287 | if(c3 == nivel3(pentarboles)) |
| 288 | sig = 4; |
| 289 | else |
| 290 | { |
| 291 | if(n3 < 4) |
| 292 | sig = 1; |
| 293 | else |
| 294 | { |
| 295 | sig = 4; |
| 296 | n3 = 0; |
| 297 | } |
| 298 | }//printf("3"); |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | if((sig == 4) && (c4 < nivel4(pentarboles))) |
| 303 | { |
| 304 | gen_arbol(cromo + (indice*LONG_ARBOL), 3); |
| 305 | *(cromo +(indice*LONG_ARBOL) + 7) = 4; |
| 306 | n4++; |
| 307 | c4++; |
| 308 | indice++; |
| 309 | if(c4 == nivel4(pentarboles)) |
| 310 | sig = 5; |
| 311 | else |
| 312 | { |
| 313 | if(n4 < 4) |
| 314 | sig = 1; |
| 315 | else |
| 316 | { |
| 317 | sig = 5; |
| 318 | n4 = 0; |
| 319 | } |
| 320 | }//printf("4"); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | if((sig == 5) && (c5 < nivel5(pentarboles))) |
| 325 | { |
| 326 | gen_arbol(cromo + (indice*LONG_ARBOL), 3); |
| 327 | *(cromo +(indice*LONG_ARBOL) + 7) = 5; |
| 328 | c5++; |
| 329 | indice++; |
| 330 | if(c5 == nivel5(pentarboles)) |
| 331 | sig = 1; |
| 332 | else |
| 333 | sig = 1; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | } |
| 341 | |
| 342 | }while(indice < ARBOLES_INDIV); |
| 343 | |
| 344 | } |
| 345 | |
| 346 | /************************************************************************************************************************************** |
| 347 | halla la salida de un arbol para una entrada de x de un cromo basado en LUT*/ |
| 348 | int eval_func_lut(char *ap, int x ) //var apunta al valor de las variables |
| 349 | { |
| 350 | char Y; |
| 351 | char var[VARS], i, a, b, c, d; |
| 352 | int lut; |
| 353 | |
| 354 | for(i=0;i <= VARS-1;i++) |
| 355 | { |
| 356 | var[i] = (x >> i) & 0x1; |
| 357 | // printf("-%i",var[i]); |
| 358 | } |
| 359 | var[VARS] = 0; |
| 360 | |
| 361 | a = *(ap + 3) & 0xF; |
| 362 | b = (*(ap + 3) >> 4) & 0xF; |
| 363 | c = *(ap + 2) & 0xF; |
| 364 | d = (*(ap + 2) >> 4) & 0xF; |
| 365 | i = var[a] + (var[b]*2) + (var[c]*4) + (var[d]*8); |
| 366 | lut = *(short int *)ap; |
| 367 | Y = (lut >> i) & 0x1; |
| 368 | return Y; |
| 369 | } |
| 370 | |
| 371 | /************************************************************************************************************************************** |
| 372 | halla la salida de un arbol para una entrada de x */ |
| 373 | int eval_func(char *ap, int x ) //var apunta al valor de las variables |
| 374 | { |
| 375 | char apfun[32] = {0, 0x1, 0x1,0x0,0x0, 0x0,0x0,0x0,0x1, 0x0,0x1,0x1,0x0, 0x0,0x1,0x1,0x1, 0x0,0x0,0x1,0x1}; //0=NOT,1=AND,2=XOR,3=OR,4=YES |
| 376 | char apl0, apl11, apl12; |
| 377 | char Y, f1, f2; |
| 378 | char var[VARS], i; |
| 379 | |
| 380 | |
| 381 | for(i=0;i <= VARS-1;i++) |
| 382 | { |
| 383 | var[i] = (x >> i) & 0x1; |
| 384 | // printf("-%i",var[i]); |
| 385 | } |
| 386 | var[VARS] = 0; |
| 387 | |
| 388 | f1 = 2*apfun[((*(ap+1))*4) + (2* (*(var+(*(ap+2))))) + *(var+(*(ap+3))) + 1]; |
| 389 | // ^2da funcion ^1ra variable ^2da variable |
| 390 | f2 = apfun[((*(ap+4))*4) + (2* (*(var+(*(ap+5))))) + *(var+(*(ap+6))) + 1]; |
| 391 | // ^3ra funcion ^3ra variable ^4da variable |
| 392 | Y = apfun[((*(ap))*4) + f1 + f2 + 1]; |
| 393 | // ^1ra funcion |
| 394 | // printf("\n"); |
| 395 | |
| 396 | return Y; |
| 397 | } |
| 398 | |
| 399 | |
| 400 | |
| 401 | /************************************************************************************************************************************** |
| 402 | retorna las salidas de un cromosoma de 5 arboles*/ |
| 403 | void eval_pentarbol_sw(char *ap, int *salida, int *entrada) |
| 404 | { |
| 405 | int i, k ; |
| 406 | char salidas[ARBOLES][COMBS], aux[COMBS]; |
| 407 | for(i=0; i <= ARBOLES-2; i++){ //se evaluan las salidas de los primeros arboles y se almacenan en salidas |
| 408 | for(k=0; k<= (COMBS-1); k++) |
| 409 | { |
| 410 | salidas[i][k] = eval_func_lut((ap+(i*LONG_ARBOL)), k); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | //se calculan los minterminos para el arbol de salida |
| 415 | for(k=0; k <= (COMBS-1); k++) |
| 416 | { |
| 417 | aux[k] = ((salidas[0][k])*1) + ((salidas[1][k])*2) + ((salidas[2][k])*4) + ((salidas[3][k])*8); |
| 418 | } |
| 419 | |
| 420 | for(i=0; i <= (COMBS-1); i++) |
| 421 | { |
| 422 | *(salida + i) = eval_func_lut(ap + ((ARBOLES-1) * LONG_ARBOL), aux[i]); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | |
| 427 | /************************************************************************************************************************************** |
| 428 | retorna el numero de errores y las salidas de un cromosoma de 1 o mas pentarboles*/ |
| 429 | int eval_fit_sw(char *ap, int *objetivo, int num_min, int pentarboles ) |
| 430 | { |
| 431 | int *obj_min, *med_min2, *med_min3, *med_min4, *med_min5, *entrada, i, j, errores, puertas; |
| 432 | int *salida, n2, n3, n4, n5, x; |
| 433 | |
| 434 | obj_min = malloc(sizeof(obj_min)*COMBS); |
| 435 | med_min2 = malloc(sizeof(med_min2)*COMBS); |
| 436 | med_min3 = malloc(sizeof(med_min3)*COMBS); |
| 437 | med_min4 = malloc(sizeof(med_min4)*COMBS); |
| 438 | med_min5 = malloc(sizeof(med_min5)*COMBS); |
| 439 | entrada = malloc(sizeof(entrada)*COMBS); |
| 440 | salida = malloc(sizeof(salida)*COMBS); |
| 441 | errores = 0; |
| 442 | |
| 443 | for(i=0; i < COMBS; i++) |
| 444 | { |
| 445 | *(obj_min+i) = 0; |
| 446 | *(entrada+i) = i; |
| 447 | *(med_min2 + i) = 0; |
| 448 | *(med_min3 + i) = 0; |
| 449 | *(med_min4 + i) = 0; |
| 450 | *(med_min5 + i) = 0; |
| 451 | } |
| 452 | |
| 453 | for(i = 0; i < num_min; i++) |
| 454 | { |
| 455 | *(obj_min + (*(objetivo + i))) = 1; //se convierte el objetivo a un arreglo |
| 456 | } |
| 457 | |
| 458 | i = 0; |
| 459 | n2 = 0; |
| 460 | n3 = 0; |
| 461 | n4 = 0; |
| 462 | n5 = 0; |
| 463 | |
| 464 | do |
| 465 | { |
| 466 | if(*(ap + (i * LONG_ARBOL) + 7) == 1) |
| 467 | { |
| 468 | eval_pentarbol_sw(ap + (i * LONG_ARBOL), salida, entrada); |
| 469 | for(j = 0; j < COMBS; j++) |
| 470 | { |
| 471 | *(med_min2 + j) = *(med_min2 + j) + (*(salida + j) << n2); |
| 472 | // printf("%i ",*(med_min2 + j));////////quitar |
| 473 | } |
| 474 | if(n2 == 3) n2 = 0; else n2++; |
| 475 | i = i + 5; |
| 476 | // printf(" ");////////quitar |
| 477 | } |
| 478 | else |
| 479 | { |
| 480 | if(*(ap + (i * LONG_ARBOL) + 7) == 3) |
| 481 | { |
| 482 | for(j = 0; j < COMBS; j++) |
| 483 | { |
| 484 | *(salida + j) = eval_func_lut(ap + (i * LONG_ARBOL), *(med_min2 + j)); |
| 485 | } |
| 486 | for(j = 0; j < COMBS; j++) |
| 487 | { |
| 488 | *(med_min3 + j) = *(med_min3 + j) + (*(salida + j) << n3); |
| 489 | // printf("%i ",*(med_min3 + j));////////quitar |
| 490 | } |
| 491 | if(n3 == 3) n3 = 0; else n3++; |
| 492 | i++; |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | |
| 497 | if(*(ap + (i * LONG_ARBOL) + 7) == 4) |
| 498 | { |
| 499 | for(j = 0; j < COMBS; j++) |
| 500 | { |
| 501 | *(salida + j) = eval_func_lut(ap + (i * LONG_ARBOL), *(med_min3 + j)); |
| 502 | } |
| 503 | for(j = 0; j < COMBS; j++) |
| 504 | { |
| 505 | *(med_min4 + j) = *(med_min4 + j) + (*(salida + j) << n4); |
| 506 | } |
| 507 | if(n4 == 3) n4 = 0; else n4++; |
| 508 | i++; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | }while(i <= (ARBOLES_INDIV-1)); |
| 513 | |
| 514 | if(*(ap + ((ARBOLES_INDIV-1) * LONG_ARBOL) + 7) == 2) |
| 515 | { |
| 516 | for(j = 0; j < COMBS; j++) //se evalua el arbol de salida |
| 517 | { |
| 518 | errores = errores + abs(*(med_min2 + j) - *(obj_min + j)); //errores |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | if(*(ap + ((ARBOLES_INDIV-1) * LONG_ARBOL) + 7) == 3) |
| 523 | { |
| 524 | for(j = 0; j < COMBS; j++) //se evalua el arbol de salida |
| 525 | { |
| 526 | errores = errores + abs(*(med_min3 + j) - *(obj_min + j)); //errores |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | if(*(ap + ((ARBOLES_INDIV-1) * LONG_ARBOL) + 7) == 4) |
| 531 | { |
| 532 | for(j = 0; j < COMBS; j++) //se evalua el arbol de salida |
| 533 | { |
| 534 | errores = errores + abs(*(med_min4 + j) - *(obj_min + j)); //errores |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | if(*(ap + ((ARBOLES_INDIV-1) * LONG_ARBOL) + 7) == 5) |
| 539 | { |
| 540 | for(j = 0; j < COMBS; j++) //se evalua el arbol de salida |
| 541 | { |
| 542 | errores = errores + abs(*(med_min5 + j) - *(obj_min + j)); //errores |
| 543 | } |
| 544 | } |
| 545 | free(obj_min); |
| 546 | free(med_min2); |
| 547 | free(med_min3); |
| 548 | free(med_min4); |
| 549 | free(med_min5); |
| 550 | free(entrada); |
| 551 | free(salida); |
| 552 | |
| 553 | puertas = 0; |
| 554 | |
| 555 | return ((errores * PESO_SALIDA) + puertas); |
| 556 | } |
| 557 | |
| 558 | /************************************************************************************************************************************** |
| 559 | Introducir minterminos **/ |
| 560 | void minterm2peripheral(int *fun_obj, int tamano) |
| 561 | { int i, j, a; |
| 562 | |
| 563 | for(i = 0; i < 512; i++) //rellenar con 0 |
| 564 | { |
| 565 | *(int *)(evalfit_ptr + EVALFIT_OBJOFFSET + (i*4)) = 0; |
| 566 | } |
| 567 | |
| 568 | for(i = 0; i < tamano; i++) //insertar 1's en segmento de mem objetivo |
| 569 | { |
| 570 | j=0; |
| 571 | a=fun_obj[i]; |
| 572 | while(a > 31) |
| 573 | { |
| 574 | a -= 32; |
| 575 | j++; |
| 576 | } |
| 577 | *(int *)(evalfit_ptr + EVALFIT_OBJOFFSET + (j*4)) += (1 << (31-a)); |
| 578 | } |
| 579 | } |
| 580 | /*************************************************************************************************************************************/ |
| 581 | |
| 582 | |
| 583 | /************************************************************************************************************************************** |
| 584 | map peripheral **/ |
| 585 | int periph_map(off_t offset) |
| 586 | { |
| 587 | int basemem, baseperiph; |
| 588 | basemem = open("/dev/mem", (O_RDWR | O_SYNC)); //abrir dispositivo memoria para mapear dir del periferico |
| 589 | if(basemem == -1) |
| 590 | { |
| 591 | printf("Error to open /dev/mem \n"); |
| 592 | return -1; |
| 593 | } |
| 594 | baseperiph = (int )mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, basemem, offset);// & ~MAP_MASK); |
| 595 | if (baseperiph == -1) |
| 596 | { |
| 597 | printf ("Cannot mmap.\n"); |
| 598 | return -1; |
| 599 | } |
| 600 | return baseperiph; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /************************************************************************************************************************************** |
| 605 | main **/ |
| 606 | int main() |
| 607 | { |
| 608 | int *aux, base_periferico, *ConfigRegsBase_ptr, basemem, maxcombs, nivel_max; |
| 609 | int a, b, c, i,j, pentarboles, sum1, sum2, sum3; |
| 610 | long int tiempo1, tiempo2; |
| 611 | char *cromo, *cromo2, *obj; |
| 612 | short int dato_lut; |
| 613 | int fun_obj[16]; |
| 614 | void *pio; |
| 615 | |
| 616 | for(i=0;i<16;i++) |
| 617 | { |
| 618 | fun_obj[i] = i; |
| 619 | } |
| 620 | |
| 621 | /** Variables para tablas de lut **/ |
| 622 | FILE *f1; |
| 623 | int size1; |
| 624 | |
| 625 | srand ( (time(NULL)) ); |
| 626 | |
| 627 | cromo = malloc(sizeof(char) * LONG_ARBOL*21); |
| 628 | if(cromo==0) printf("Error en malloc"); |
| 629 | cromo2 = malloc(sizeof(char) * LONG_ARBOL*21); |
| 630 | if(cromo2==0) printf("Error en malloc"); |
| 631 | obj = malloc(COMBS); |
| 632 | if(obj==0) printf("Error en malloc"); |
| 633 | a= sizeof(fun_obj)/4; |
| 634 | printf("{%0x %0x}",a,COMBS); |
| 635 | |
| 636 | for(i=0;i<a;i++) |
| 637 | { |
| 638 | *(obj + fun_obj[i]) = 1; |
| 639 | } |
| 640 | |
| 641 | /** Tabla para las LUT **/ |
| 642 | f1 = fopen("funlut.dat","r"); |
| 643 | if(f1 == NULL){ |
| 644 | printf("\nError de lectura de archivo!"); |
| 645 | return 0;} |
| 646 | fseek (f1, 0, SEEK_END); |
| 647 | size1 = ftell(f1); |
| 648 | funlut_ap = malloc(size1); |
| 649 | |
| 650 | if(funlut_ap==0) printf("Error en malloc"); |
| 651 | rewind (f1); |
| 652 | fread(funlut_ap,1,size1,f1); |
| 653 | fclose(f1); |
| 654 | |
| 655 | |
| 656 | /** periferico **/ |
| 657 | printf("Evalfit Test..."); |
| 658 | basemem = open("/dev/mem", (O_RDWR | O_SYNC)); //abrir dispositivo memoria para mapear dir del periferico |
| 659 | if(basemem == -1) |
| 660 | { |
| 661 | printf("Error al abrir /dev/mem \n"); |
| 662 | return -1; |
| 663 | } |
| 664 | pio = jz_gpio_map(CS2_PORT); |
| 665 | jz_gpio_as_func (pio, CS2_PIN, 0); |
| 666 | ConfigRegsBase_ptr = (int *)periph_map(CONFIG_REGS_BASE);// + SACR2_OFFSET/sizeof(int);//SMCR2_OFFSET/sizeof(int); |
| 667 | printf("\n%0x ", *(ConfigRegsBase_ptr + SMCR2_OFFSET/sizeof(int))); |
| 668 | munmap(ConfigRegsBase_ptr, MAP_SIZE); |
| 669 | evalfit_ptr = (int *)periph_map(EVALFIT_PHYSBASE1); |
| 670 | |
| 671 | printf("\r\nevalfit_ptr: %0x", evalfit_ptr); |
| 672 | if( evalfit_ptr == (int *)MAP_FAILED) |
| 673 | { printf("error mmap!\n"); |
| 674 | fflush(stdout); |
| 675 | return -1; |
| 676 | } |
| 677 | *(char *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = CONTROL_RESET_MASK; //reset |
| 678 | //sleep(1); |
| 679 | *(char *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = 0; |
| 680 | printf("\nDate + Status: %0x\n", *(char *)(evalfit_ptr + EVALFIT_STATUS)); |
| 681 | |
| 682 | /* pentarboles */ |
| 683 | maxcombs = COMBS; |
| 684 | pentarboles = 4; |
| 685 | nivel_max = 0x3; |
| 686 | printf("\nVars:%i COMBS: %0xH LONG_ARBOL:%0xH LONG_INDIV:%0xH ARBOLES_INDIV:%i\n", VARS, maxcombs, LONG_ARBOL , LONG_INDIV, ARBOLES_INDIV); |
| 687 | |
| 688 | gen_indiv(cromo2, pentarboles); |
| 689 | mostrar_indiv(cromo2, pentarboles); |
| 690 | |
| 691 | /******* convertir a formato de luts ******/ |
| 692 | for(i = 0; i < ARBOLES_INDIV; i++) |
| 693 | { |
| 694 | *(short int *)(cromo+(i*LONG_ARBOL)) = *(short int *)(funlut_ap + ( (*(cromo2 + (i*LONG_ARBOL)) * 25) + |
| 695 | (*(cromo2+(i*LONG_ARBOL)+1)*5) + *(cromo2+(i*LONG_ARBOL)+4) ) *2 ); |
| 696 | *(cromo+(i*LONG_ARBOL) + 3) = *(cromo2+(i*LONG_ARBOL) + 2) + (*(cromo2+(i*LONG_ARBOL) + 3) << 4); |
| 697 | *(cromo+(i*LONG_ARBOL) + 2) = *(cromo2+(i*LONG_ARBOL) + 5) + (*(cromo2+(i*LONG_ARBOL) + 6) << 4); |
| 698 | *(cromo+(i*LONG_ARBOL) + 6) = (*(cromo2+(i*LONG_ARBOL)) * 25) + (*(cromo2+(i*LONG_ARBOL)+1)*5) + *(cromo2+(i*LONG_ARBOL)+4); |
| 699 | *(cromo+(i*LONG_ARBOL) + 7) = *(cromo2+(i*LONG_ARBOL) + 7); |
| 700 | } |
| 701 | |
| 702 | /** copiar miniterminos a periferico **/ |
| 703 | minterm2peripheral(fun_obj, sizeof(fun_obj)/4); |
| 704 | |
| 705 | /** Insertar maxcombs y nivel_max **/ |
| 706 | *(short *)(evalfit_ptr + EVALFIT_MAX_COMBS) = maxcombs-1; |
| 707 | *(char *)(evalfit_ptr + EVALFIT_MAX_LEVEL) = nivel_max; |
| 708 | |
| 709 | /** insertar cromosoma en periferico **/ |
| 710 | printf("\nInserting chromosome in peripheral..."); fflush(stdout); |
| 711 | for(i = 0; i < ARBOLES_INDIV; i++) |
| 712 | { |
| 713 | *(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0) =*(char *)(cromo +(LONG_ARBOL*i)+7); |
| 714 | printf("\n%04hhu: Level:%X ", *(cromo+(i*LONG_ARBOL) + 6), *(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0)); |
| 715 | *(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 4) = *(int *)(cromo +(LONG_ARBOL*i)); |
| 716 | printf("LUT-VARS: %08x",*(int *)(evalfit_ptr + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 4)); |
| 717 | } |
| 718 | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0) = 0xF; //para terminar |
| 719 | i++; |
| 720 | *(int *)((evalfit_ptr) + EVALFIT_MEMOFFSET + (LONG_ARBOL*i) + 0) = 0xF; //para terminar |
| 721 | |
| 722 | /** Iniciar HW **/ |
| 723 | *(char *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = CONTROL_START_MASK; |
| 724 | tiempo1 = get_timestamp(); |
| 725 | |
| 726 | do{ |
| 727 | //printf("\nSTATUS: %0x",*(short *)(evalfit_ptr + EVALFIT_STATUS)); |
| 728 | //usleep(100); |
| 729 | }while((*(short *)(evalfit_ptr + EVALFIT_STATUS) & DONE_MASK) != 0x8000); //wait for DONE |
| 730 | tiempo2 = get_timestamp(); |
| 731 | printf("\n\nErrors calculated HW: %0x",(*(int *)(evalfit_ptr + EVALFIT_ERRORS) & ERRORS_MASK)); //errores |
| 732 | *(char *)(evalfit_ptr + EVALFIT_CONTROL_OFFSET) = 0; //disable peripheral |
| 733 | printf("\ndt_hw:%i microsegs\n", tiempo2 - tiempo1); |
| 734 | |
| 735 | /** por SW **/ |
| 736 | tiempo1 = get_timestamp(); |
| 737 | a = eval_fit_sw(cromo, fun_obj, sizeof(fun_obj)/4, pentarboles); |
| 738 | tiempo2 = get_timestamp(); |
| 739 | printf("\nErrors calculated SW: %0x", a); |
| 740 | printf("\ndt_sw:%i microsegs\n", tiempo2 - tiempo1); |
| 741 | |
| 742 | /* Mersenne twister test */ |
| 743 | printf("\n\nnumero aleatorio: %0x",(*(int *)(evalfit_ptr + EVALFIT_RANDOM))); //random |
| 744 | free(funlut_ap); |
| 745 | free(cromo); |
| 746 | free(cromo2); |
| 747 | free(obj); |
| 748 | close(basemem); |
| 749 | munmap(base_periferico, MAP_SIZE); |
| 750 | exit(0); |
| 751 | return 0; |
| 752 | } |
Examples/ehw4/src/test/gen_fun_lut.c |
| 1 | /********************************************************************************************************* |
| 2 | ** Programa para generar los posibles datos que van en una LUT |
| 3 | ** - Son 3 funciones por LUT |
| 4 | ** - Son 5 posibles funciones. 0 NOT, 1 AND, 2 XOR, 3 OR, 4 YES |
| 5 | ** |
| 6 | ** |
| 7 | ** |
| 8 | ** |
| 9 | **********************************************************************************************************/ |
| 10 | #include <stdio.h> |
| 11 | #include <termios.h> |
| 12 | #include <sys/mman.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <sys/types.h> |
| 15 | #include <sys/stat.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <time.h> |
| 18 | #include <math.h> |
| 19 | #include <pthread.h> |
| 20 | #define FUNCIONES 5 |
| 21 | #define FUNCOMBS (int) pow(FUNCIONES, 3) |
| 22 | #define VARS 4 |
| 23 | #define COMBS (int) pow(2,VARS) |
| 24 | |
| 25 | #define POBLACION 64 |
| 26 | #define ARBOLES 5 |
| 27 | #define LONG_ARBOL 8 |
| 28 | |
| 29 | /************************************************************************************************************************************** |
| 30 | halla la salida de un arbol para una entrada de x */ |
| 31 | int eval_func(char *ap, int x ) //var apunta al valor de las variables |
| 32 | { |
| 33 | char apfun[32] = {0, 0x1, 0x1,0x0,0x0, 0x0,0x0,0x0,0x1, 0x0,0x1,0x1,0x0, 0x0,0x1,0x1,0x1, 0x0,0x0,0x1,0x1}; //0=NOT,1=AND,2=XOR,3=OR,4=YES |
| 34 | char apl0, apl11, apl12; |
| 35 | char Y, f1, f2; |
| 36 | char var[VARS], i; |
| 37 | |
| 38 | for(i=0;i <= VARS-1;i++) |
| 39 | { |
| 40 | var[i] = (x >> i) & 0x1; |
| 41 | //printf("-%i",var[i]); |
| 42 | } |
| 43 | var[VARS] = 0; |
| 44 | |
| 45 | f1 = 2*apfun[((*(ap+1))*4) + (2* (*(var+(*(ap+2))))) + *(var+(*(ap+3))) + 1]; |
| 46 | // ^2da funcion ^1ra variable ^2da variable |
| 47 | f2 = apfun[((*(ap+4))*4) + (2* (*(var+(*(ap+5))))) + *(var+(*(ap+6))) + 1]; |
| 48 | // ^3ra funcion ^3ra variable ^4da variable |
| 49 | Y = apfun[((*(ap))*4) + f1 + f2 + 1]; |
| 50 | // ^1ra funcion |
| 51 | // printf("f1:%i f2:%i Y:%i ",f1,f2,Y); |
| 52 | return Y; |
| 53 | } |
| 54 | |
| 55 | /************************************************************************************************************************************** |
| 56 | imprime un cromosoma completo */ |
| 57 | mostrar_indiv(char *cromo, int pentarboles) |
| 58 | { |
| 59 | char *ap, i, fn[8] = {'!', '&', '^', '|', '_'}; //NOT, AND, XOR, OR, NADA o YES |
| 60 | char vn[] = {'A', 'B', 'C', 'D', 'E' , 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', '.'}; |
| 61 | |
| 62 | ap = cromo; |
| 63 | for(i = 0; i < 1; i++){ |
| 64 | vn[VARS] = '.'; |
| 65 | printf(" %c%c%c%c%c%c%c", fn[*ap], fn[*(ap+1)], vn[*(ap+2)], vn[*(ap+3)], fn[*(ap+4)], vn[*(ap+5)], vn[*(ap+6)]); |
| 66 | } |
| 67 | printf("\n"); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | main() |
| 72 | { |
| 73 | char *cromo, *tabla,*puertas; |
| 74 | int i, j, k, l, salida,x; |
| 75 | char ruta[]="funlut.dat"; |
| 76 | char ruta2[]="puertas.dat"; |
| 77 | short int *funlut_ap; |
| 78 | int size1; |
| 79 | |
| 80 | tabla = malloc(sizeof(short int) * FUNCOMBS*4); |
| 81 | if(tabla==0) printf("Error en malloc"); |
| 82 | puertas = malloc(sizeof(short int) * FUNCOMBS*4); |
| 83 | if(tabla==0) printf("Error en malloc"); |
| 84 | cromo = malloc(sizeof(char) * FUNCOMBS); |
| 85 | if(cromo==0) printf("Error en malloc"); |
| 86 | |
| 87 | FILE *f1, *fich=fopen(ruta,"wb"); |
| 88 | FILE *f2, *fich2=fopen(ruta2,"wb"); |
| 89 | |
| 90 | printf("COMBS%i ", FUNCOMBS); |
| 91 | |
| 92 | for(i = 0; i < FUNCIONES; i++) |
| 93 | { |
| 94 | for(j = 0; j < FUNCIONES; j++) |
| 95 | { |
| 96 | for(k = 0; k < FUNCIONES; k++) |
| 97 | { |
| 98 | x = 0; |
| 99 | for(l = 0; l < COMBS; l++) |
| 100 | { |
| 101 | *(puertas + ((i*25) + (j*5) + k))=0; |
| 102 | *cromo = i; |
| 103 | *(cromo+1) = j; |
| 104 | *(cromo+2) = 0; |
| 105 | *(cromo+3) = 1; |
| 106 | *(cromo+4) = k; |
| 107 | *(cromo+5) = 2; |
| 108 | *(cromo+6) = 3; |
| 109 | salida = eval_func(cromo, l); |
| 110 | printf("%i", salida); |
| 111 | x = x + (salida << l); |
| 112 | if(*cromo != 4) |
| 113 | (*(puertas + ((i*25) + (j*5) + k) ))++; |
| 114 | if(*(cromo + 1) != 4) |
| 115 | (*(puertas + ((i*25) + (j*5) + k)))++; |
| 116 | if(*(cromo + 4) != 4 && *cromo != 4) |
| 117 | (*(puertas + ((i*25) + (j*5) + k)))++; |
| 118 | } |
| 119 | *(tabla + ((i*25) + (j*5) + k)*2 + 1 ) = 0xFF & (x>>8); // se guarda con little endian, para JZ e intel. |
| 120 | *(tabla + ((i*25) + (j*5) + k)*2 ) = 0xFF & x; // intercambia estos dos para cambiar endianismo |
| 121 | printf(" %i %04hX %4X", (i*25) + (j*5) + k, *(unsigned short *)(tabla + ((i*25) + (j*5) + k)*2), *(unsigned char *)(tabla + ((i*25) + (j*5) + k)*2 + 1)); |
| 122 | mostrar_indiv(cromo, 1); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | fwrite((short int *)tabla, FUNCOMBS, sizeof(short int),fich); |
| 128 | fclose(fich); |
| 129 | fwrite((char *)puertas, FUNCOMBS, sizeof(char),fich2); |
| 130 | fclose(fich2); |
| 131 | |
| 132 | f1 = fopen("funlut.dat","r"); |
| 133 | if(f1 == NULL){ |
| 134 | printf("\nError de lectura de archivo!"); |
| 135 | return 0;} |
| 136 | fseek (f1, 0, SEEK_END); |
| 137 | size1 = ftell(f1); |
| 138 | funlut_ap = malloc(size1); |
| 139 | if(funlut_ap==0) printf("Error en malloc"); |
| 140 | rewind (f1); |
| 141 | fread(funlut_ap,2,size1/(sizeof(short int)),f1); |
| 142 | fclose(f1); |
| 143 | for(i = 0; i < (size1/sizeof(short int)); i++) |
| 144 | printf("\n%0x : %0x ",i, *(unsigned short int*)(funlut_ap+i)); |
| 145 | free(funlut_ap); |
| 146 | |
| 147 | } |