Introduction
There are several steps involved in setting up Celoxica’s DK GUI for doing projects in the lab. Some of them need to be done just once, while others need to be done for each project -- but many of the per-project settings can be copied over from other projects, saving some overhead.
The purpose of this web page is to run through the settings you will need to manage, hopefully in a form so they will be easy to refer back to as necessary.
Directory and Workspace Setup
When we set up your account we put a directory named My Projects under your My Documents directory. You will need to create one DK workspace for the semester, and you will be doing several projects during the semester. You will tell DK to create the workspace in your My Projects directory, and then will create each project there.
Start DK, and click the menu, and click on the Workspace tab. Set the Location to your My Documents folder (you can browse to it using the “...” button), and type My Projects as the Workspace name. If you were to exit DK now, you would see that DK creates two files in your My Projects directory: My Projects.hw and My Projects.pref The .hw file where DK keeps information about the workspace, basically just a text list of the projects in the workspace. The other file is where it will record the preferences, some of which you will need to adjust.
Before making the preference changes you need, create your first project. Bring up the Project tab. On the left side, click on Library (the fifth icon down), and in the Project Name text box, put DelayProcs. I suggest not putting spaces in project names to make things easier later. Be sure the “Add to current workspace” radio button is checked. If it is grayed out, you need to go back and make sure the workspace you set up above is open.
panel again, and this time, click on theNow create a source code file for your DelayProcs project. Open the panel again, and this time select Source File, select “Handel-C Source File,” and enter msec_delay as the File Name. When you click OK, an editor window will open up: type a comment line with the file name at the beginning:
// msec_delay.hcc
Save your source code file (Control-S) and exit DK. Verify that the .hp and .pref files mentioned above are in your My Projects directory, and that there is now a subdirectory named DelayProcs. In the DelayProcs directory there should be two files: DelayProcs.hp holds the housekeeping information DK needs for the project, and msec_delay.hcc is your source code file. Like the .hw file, .hp files are just text files that you could look at with a program editor if you wanted to.
Be sure your workspace and first project are set up as described here before proceeding! If they are not, delete everything under your My Projects directory and repeat the above steps.
Start DK and open your workspace again.
Go to
and Remove all the build configurations for this project except “Generic.”Add the code for macro proc msecDelay() to msec_delay.hcc. Be sure the Active Build Configuration at the top of the screen says “Generic” rather than “Debug” (or anything else) and build the project. There should be no warnings or errors. If you look at your project directory (DelayProcs) you should see a subdirectory named Generic, and inside that you should see an object file named msec_delay.hco and a library file named DelayProcs.hcl.
Set Default Preferences
Click on
to bring up a big panels for setting options. Once you set these up, you won’t have to change them again.- On the Tabs tab, set the tab
size to either 2 (the value I personally like) or 4 (another
popular value), but make sure it is not anything larger than 4 to
avoid code that gets so wide it can’t be read without
horizontal scrolling.
Click the “Insert spaces” radio button: tab characters in your code lead to mixed up indendation (or even none at all) depending how particular programs or printers interpret tab characters. What your code looks like matters in this course!. - On the Format tab, change the font for the Output Window category to a fixed-width font, such as Monaco.
- On the Directories tab, select “Show directories for Include files,” and add your DelayProcs directory to the list. You will be putting a header file here shortly. Select “Show directories for Library files” and add the pathname to the Generic you created for your library file above.
Create and Configure a Simple Project
To complete the setup process, you will need to configure your first application. We will use an application that turns a LED on and off once a second as an example.
-
Add a header file to DelayProcs
First, construct a header file that guarantees that the definitions of the macro procs in your DelayProcs library agree with your use of these procedures in your applications. To do this, add the following Handel-C header file to your DelayProcs project:
// delayProcs.hch #ifndef __DELAY_PROCS_HCH__ #define __DELAY_PROCS_HCH__ extern macro proc msecDelay(clock_rate, msec); #endif
The preprocessor directives are a conventional mechanism for making sure that cpp doesn’t accidentally get put into an endless loop inserting one header file that includes another one that includes the first one again. (Current versions of cpp check for this and won’t actually loop, but the convention of testing for and defining a preprocessor symbol based on the file name remains.)
Add this directive to your msec_delay.hcc and make sure you can re-build the library without warnings or errors:
#include <delayProcs.hch>
By enclosing the header file name in angle brackets (< >) instead of quotes, you are telling the preprocessor to look for it in one of its “standard places,” namely the directory you added to the
tab above. -
Add a project to the workspace.
Create a new project called Flash_A_LED. Be sure DK adds it to your workspace. Note that the name follows the convention of not having any spaces in the project name.
You will configure the project for two target platforms: Simulation (Debug) and FPGA implementation (EDIF). To avoid accidentally using some other configuration, remove all but these two configurations from the project using the
menu item.There are several settings you need to set up for each project. The good news is that once you set them up for one project, you can copy many of them over to new projects somewhat mindlessly. You get to the settings panel from the
menu item.There is a table of configuration settings for various platforms for you to refer to for the values you will need to enter.
Enter all the values for the Debug and EDIF settings for this project.
-
Write the code and build the two configuration.
Add a Handel-C source file named flash_a_led.hcc to the project, and enter the following code:
// flash_a_led.hcc /* Turns a LED on and off once per second. */ #include <stdlib.hch> #include <pal_master.hch> #include <delay_procs.hch> // main() // ------------------------------------------------------------------ /* * Turns a LED on, waits half a second, turns it off, and waits * another half a second. Repeats forever. */ void main(void) { while (1) { PalLEDWrite(PalLEDCT(0), 1); msecDelay(PAL_ACTUAL_CLOCK_RATE, 500); PalLEDWrite(PalLEDCT(0), 0); msecDelay(PAL_ACTUAL_CLOCK_RATE, 500); } }Note that including the same delay_procs.hch header here as you used in msec_delay.hcc makes the compiler check that you use the same number of parameters when invoking the macro as you used when you defined it. However, because msecDelay() is a macro rather than a function, there is no checking of the parameter types.
Use the “Active Build Configuration” box at the top of the DK window to select the Debug configuration, and build the simulation using the F7 key or by clicking on the blue toolbar button that is supposed to look like a building (but doesn’t really). Do the same for the EDIF configuration. Be sure there are no errors, and be sure the EDIF process goes all the way through the “Bitstream generation complete” stage successfully.
-
Test both project configurations.
With Debug selected as the active configuration, press F5 to start simulation. Two windows should come up: a black Command Line window from Windows and a “Pal Virtual Console Window.” There should be a flashing LED on the Pal Virtual Console. The exact rate at which the LED flashes will depend on the PC’s clock speed and the target clock rate you chose in the project settings. To stop the simulation you can either close the Windows Command Line window or click the DK toolbar button with a red X in it.
To test the FPGA configuration, launch one of the File Transfer Utility programs provided by Celoxica: FTU2 for the RC200E (parallel port), or FTU3 for the RC10 or RC300 (USB port). Make sure the FTU detects the kit you have attached to the PC, browse to and select the bit file, flash_a_led.bit in your Flash_A_LED/EDIF directory, and then click the Configure button or just double-click on the file name in the FTU’s list to download the bitfile to the FPGA. A LED should flash exactly once per second.