Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Verilog Help

Altera_Forum
Honored Contributor II
1,401 Views

Hey Guyz! 

 

I need some help with verilog coding. i got this code off opencore website that teaches us how to code a sd card controller.Below shows 2 of the verilog file.  

 

A) spiMaster_defines.v 

`ifdef SIM_COMPILE 

`define SD_INIT_START_SEQ_LEN 8'h03 

`define MAX_8_BIT 8'h08 

`else 

`define SD_INIT_START_SEQ_LEN 8'ha0 

`define MAX_8_BIT 8'hff 

`endif 

 

B) initSD.v  

`include "spiMaster_defines.v" 

`CLK_SEQ_CHK_FIN: 

begin 

next_txDataWen <= 1'b0; 

if (loopCnt == `SD_INIT_START_SEQ_LEN) 

begin 

NextState_initSDSt <= `CLK_SEQ_WT_DATA_EMPTY; 

end 

else 

begin 

NextState_initSDSt <= `CLK_SEQ_SEND_FF; 

end 

end 

 

My question is what is the value of `SD_INIT_START_SEQ_LEN ?? Also what is the verilog code in A trying to do? Hope someone can help me as i really need to understand this. Thank you. 

0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
676 Views

From the name, the first file appears to contain definitions for constants. The code you listed in 'A' defines two constants which are dependant on whether or not SIM_COMPILE is defined. If SIM_COMPILE is defined, SD_INIT_START_SEQ_LEN will be an 8 bit value of '3'. If SIM_COMPILE is not defined, SD_INIT_START_SEQ_LEN will be hex 'a0'.

0 Kudos
Altera_Forum
Honored Contributor II
676 Views

Are you a C programmer? If so, the equivalent code for A) in C would be: 

# ifdef SIM_COMPILE # define SD_INIT_START_SEQ_LEN 0x03 # define MAX_8_BIT 0x08 # else # define SD_INIT_START_SEQ_LEN 0xa0 # define MAX_8_BIT 0xff # endif 

 

So the value of SD_INIT_SEQ_LEN is either 3 or 160 depending on whether or not SIM_COMPILE is defined. 

 

Most likely the designer defines the macro "SIM_COMPILE" when he wants to run a simulation because it takes less time. 

 

Jake
0 Kudos
Altera_Forum
Honored Contributor II
676 Views

Hey ereeves and jakobjones, 

 

Thanks a lot for your advice and help. I understand now. Appreciate your advices and effort to help me. 

 

Cheers!
0 Kudos
Reply