Custom Logic Tutorial - Creating the C Code Symbols
Now we have our C source files, we can create corresponding C Code Symbols for each, directly from them.
- Open the design schematic (
CHC_Accumulator.SchDoc
).
- From the main menus, choose Design » Create Code Symbol From C File. In the Choose Document to Place dialog that appears, select the
PulseGenerator.C
entry and click OK.
- Place the new C Code Symbol into free space on the schematic for the time being. Notice that the Designator and Filename have been automatically set to
U_GeneratePulse
andPulseGenerator.C
respectively. Notice also that two C Code Entries have been added to the symbol, corresponding to the parameters of the underlying C function.
- Double-click on the symbol to access its properties dialog and activate the Signature tab (Figure 2).
Our C functions do not provide a return value. A return value would appear as a special C Code Entry, with an IO Type of
Output
and a Parameter Name ofRETVAL
.
It is also worth mentioning that the widths of integer-type C Code Entries can be in the range 1-64. You are not limited to using the widths of C data types only. - It is worth spending some time to look more closely at the information contained within this tab of the dialog.
Notice that the Function Name field has the entryGeneratePulse
. This corresponds to the name of the exported function in the underlying C source file,PulseGenerator.C
.
The Parameters region lists the parameters (and their properties) of the top-level exported function. The entries here are made available on the symbol as C Code Entries – allowing for data transfer to/from other logic in the design.
C functions allow only one return value, but it is possible to have more outputs by using pointer parameters. Output C Code Entries correspond to pointer parameters in the C function. Note that values must be assigned to output pointer parameters (and don't forget to dereference the pointer when assigning a value to it).
The C-to-Hardware Compiler can generate two types of circuit from the C source code for the exported function –Combinatorial
andMulti-cycle
. This is specified using the Interface field, which is set toCombinatorial
by default. For more information, see Combinatorial vs. Multi-Cycle Circuits.
The Variables region of the tab provides additional options, offering advanced functionality for the C Code Symbol. For the purposes of this tutorial, we will leave all three options enabled (their default state). One thing to note however, is that by enabling the Enable reset logic option, reset logic will be built into the symbol, and two additional Control-type C Code Entries will be added to the symbol –RESET
andRESET_DONE
.
- Our clock pulse circuit is multi-cycle in nature, so select
Multi-cycle
in the Interface field.
- Click OK to close out of the dialog. The C Code Symbol for the custom clock pulse circuit is now fully configured as required. We will reposition the Designator and Filename fields to enhance readability and also adjust the location of the Control-type C Code Entries to aid in wiring.
- Use the Design » Create Code Symbol From C File command to create and initially place a new C Code Symbol from the
Accumulator.C
source file. Notice that the Designator and Filename have been automatically set toU_Accumulate
andAccumulator.C
respectively. Notice also that two C Code Entries have been added to the symbol, corresponding to the parameters of the underlying C function.
- Our accumulation circuit is also multi-cycle in nature. Access the Signature tab of the symbol's properties dialog and set the Interface entry to
Multi-cycle
.
- Click OK to close the dialog. The C Code Symbol for the custom accumulation circuit is now fully configured. Again, we will reposition the Designator and Filename fields and adjust the location of the Control-type C Code Entries.