Custom Logic Tutorial - Creating the C Code Symbols

Frozen Content

Now we have our C source files, we can create corresponding C Code Symbols for each, directly from them.

  1. Open the design schematic (CHC_Accumulator.SchDoc).
     
  2. 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.
     
  3. 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 and PulseGenerator.C respectively. Notice also that two C Code Entries have been added to the symbol, corresponding to the parameters of the underlying C function.
     

    Figure 1. Initial C Code Symbol, generated
    from the C source file PulseGenerator.C.

     
  4. Double-click on the symbol to access its properties dialog and activate the Signature tab (Figure 2).
     

    Figure 2. Accessing properties for hooking the exported C function to the referencing C Code Symbol.
     

    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 of RETVAL.
     
    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.

     
  5. 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 entry GeneratePulse. 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 and Multi-cycle. This is specified using the Interface field, which is set to Combinatorial 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 and RESET_DONE.
     
  6. Our clock pulse circuit is multi-cycle in nature, so select Multi-cycle in the Interface field.
     

    Figure 3. Switch over to have the CHC generate
    a Multi-cycle circuit.

     
  7. 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.
     

    Figure 4. Final C Code Symbol for the
    custom clock pulse circuit.

     
  8. 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 to U_Accumulate and Accumulator.C respectively. Notice also that two C Code Entries have been added to the symbol, corresponding to the parameters of the underlying C function.
     

    Figure 5. Initial C Code Symbol, generated from
    the C source file Accumulator.C.

     
  9. 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.
     
  10. 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.
     

    Figure 6. Final C Code Symbol for the custom
    accumulation circuit.
You are reporting an issue with the following selected text and/or image within the active document: