barry
Advanced Member level 7
- Joined
- Mar 31, 2005
- Messages
- 6,579
- Helped
- 1,208
- Reputation
- 2,428
- Reaction score
- 1,438
- Trophy points
- 1,393
- Location
- California, USA
- Activity points
- 35,777
And then when you end up with 256 types of SPI modules you start generalizing again ?
makes it extremely painful to deal with code that is hidden behind all those submodules
Well the fact that most people write code like this:
Code Verilog - [expand] 1 2 3 a a_i (xyz, abc, nmo, pqr, c, r); b b_i (c, r, abc, xyz, hij); add add_i (hij, xyz, add_out);
makes it extremely painful to deal with code that is hidden behind all those submodules without even named port mappings and names that s**k on top of everything else. Oh and two lines of comments at the top of the file...name of file (duh I know the file name), and their name (like I would ever put my name in a file full of cr*p ;-))
The whole point of having a component (sorry, I only speak VHDL) is that you don't have to worry about any of the lower-level stuff-it's already been vetted. I don't need to know anything about the piston rods in my car in order to drive it.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 module parity (data, parity); parameter N = 32; input wire [N-1:0] data; output wire parity; integer i; reg psum = 0; for (i=0;i<N;i=i+1) begin assign psum = data[i] ^ psum; end assign parity = psum; endmodule
Code Verilog - [expand] 1 assign parity = ^data;
Not really.Do you have a very specific example of SPI thingy for which you want to see the component breakdown?
To me having a file full of tiny instantiated modules makes for less readable code and a larger maintenance burden.
I respectfully totally disagree.
I'd rather see an instantiation of INPUT.VHD which has 3 ports: SERIAL IN, PARALLEL OUT, DATA_READY, READ, than a bunch of registers, state machines, etc. The four lines or so instantiating the module is going to be a lot clearer than 100 lines of stuff implementing the INPUT function. This is even more important if you've got multiple instances of the same component.
If it is something as trivial as a shift register or an adder, it's probably better to write the code directly.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 module nreg (in_d, out_d, enable, reset, clk) parameter N = 8; input [N-1:0] in_d; output [N-1:0] out_d; input enable; input reset; input clk; wire [N-1:0] in_d; reg [N-1:0] out_d; wire enable, reset, clk; always @ (posedge clk or posedge reset) begin if (reset) begin out_d <= {N{1'b0}}; end else if (enable) begin out_d <= in_d; end end endmodule
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 nreg #(16) a_reg_i (a_signal, a, 1'b1, 1'b0, clk); nreg #(16) b_reg_i (b_signal, b, 1'b1, 1'b0, clk); // of course this mux is actually in a separate module too. :P always @* begin mux = sel ? a : b; end nreg #(16) mux_reg_i (mux, mux_reg, enable, reset, clk); // Note: I've written the code like they did, not following any reasonable coding readability guidelines or 2001 port declarations.
Have you ever picked up code written by someone who did this?
Code VHDL - [expand] 1--I know this file looks a mess, but it's been bodged together over the years, theres never any time to make it good. It really needed making into a single process/state machine, not the 30 or so single register processes it is now!
-- this seems to work, Im now quite sure why though
--25.12.08 I tried to rewrite the component so it won't use the external SPI clock as a system clock - but ISIM simulation didn't show good results
I think you've misinterpreted what I've said. The keyword in my statement was tiny. If you have a individual shift register module, data ready module, parallel output module, register module, read module, fsm module (with each state decide in it's own module, yes I had to fix a design like that :shock, etc to implement the 100 lines of stuff, then I have a problem with that. To me any module that is 100-300 lines of code without counting comments is fine with me. Going to the extreme of having every possible register, AND gate, parity, etc as instances in anything is overkill and you might as well go back to designing with schematics and 7400 series components.
You're INPUT.VHD makes perfect sense and is what I would typically do.
TrickyDicky,
What do you think about the subject ?
What are your rules when in comes to splitting your design into small pieces ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?