/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This software is Copyright  2011 Yuri Gonzaga Gonalves da Costa <yuriggc at gmail>, and it is hereby released to the general public under the following terms:*
 * Redistribution and use in source and binary forms, with or without modification, are permitted.                                                                 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 `timescale 1 ns/ 1 ns
 
module Manager(
	PicoRst, 
	PicoClk, 
	PicoWr,
	PicoAddr,
	PicoRd,  
	PicoDataIn, 
	PicoDataOut
);
	parameter N_MODULES  = 6;
	parameter UM    = 2'd0;
	parameter DOIS  = 2'd1;
	parameter TRES  = 2'd2;
	reg[1:0] state;

	input PicoRst;
	input PicoClk;
	input PicoWr;
	input PicoRd;
	input [31:0]PicoDataIn;
	input [31:0] PicoAddr;
	output [31:0] PicoDataOut;	
	reg [31:0] PicoDataOut_r;
	reg [N_MODULES-1:0] ACTIVES;

	wire [31:0] PicoDataOut0, PicoDataOut1, PicoDataOut2, PicoDataOut3, PicoDataOut4, PicoDataOut5;
	
	loop L_0(
	.PicoRst(PicoRst), 
	.PicoClk(PicoClk), 
	.PicoWr(PicoWr),
	.PicoAddr(PicoAddr),
	.PicoRd(PicoRd),  
	.PicoDataIn(PicoDataIn), 
	.PicoDataOut(PicoDataOut0),
	.active(ACTIVES[0])
	);
	
	loop L_1(
	.PicoRst(PicoRst), 
	.PicoClk(PicoClk), 
	.PicoWr(PicoWr),
	.PicoAddr(PicoAddr),
	.PicoRd(PicoRd),  
	.PicoDataIn(PicoDataIn), 
	.PicoDataOut(PicoDataOut1),
	.active(ACTIVES[1])
	);
	
	loop L_2(
	.PicoRst(PicoRst), 
	.PicoClk(PicoClk), 
	.PicoWr(PicoWr),
	.PicoAddr(PicoAddr),
	.PicoRd(PicoRd),  
	.PicoDataIn(PicoDataIn), 
	.PicoDataOut(PicoDataOut2),
	.active(ACTIVES[2])
	);
	
	loop L_3(
	.PicoRst(PicoRst), 
	.PicoClk(PicoClk), 
	.PicoWr(PicoWr),
	.PicoAddr(PicoAddr),
	.PicoRd(PicoRd),  
	.PicoDataIn(PicoDataIn), 
	.PicoDataOut(PicoDataOut3),
	.active(ACTIVES[3])
	);

	loop L_4(
	.PicoRst(PicoRst), 
	.PicoClk(PicoClk), 
	.PicoWr(PicoWr),
	.PicoAddr(PicoAddr),
	.PicoRd(PicoRd),  
	.PicoDataIn(PicoDataIn), 
	.PicoDataOut(PicoDataOut4),
	.active(ACTIVES[4])
	);

	loop L_5(
	.PicoRst(PicoRst), 
	.PicoClk(PicoClk), 
	.PicoWr(PicoWr),
	.PicoAddr(PicoAddr),
	.PicoRd(PicoRd),  
	.PicoDataIn(PicoDataIn), 
	.PicoDataOut(PicoDataOut5),
	.active(ACTIVES[5])
	);

	always@(posedge PicoClk) begin
		if(PicoRst==1'b0)begin
			if(PicoWr)begin
				if(PicoAddr[31:24] == 8'd255)begin
					ACTIVES <= PicoAddr[N_MODULES+3:4];
				end
			end
		end else begin
			ACTIVES <= {N_MODULES{1'b0}};
		end
	end	
	
	assign PicoDataOut = PicoDataOut0 | PicoDataOut1 | PicoDataOut2 | PicoDataOut3 | PicoDataOut4 | PicoDataOut5;
	
endmodule

