wiki:Exercises/XPSIntro/GeneratingSW

Once bitstream generation is complete, a software project must be developed to utilize the generated hardware. From the Software menu at the top of the main XPS window, select "Add Software Application Project...".

Specify a name for the project, then click OK.

In the leftmost panel of the main XPS window, you will notice that an entry has been added for the new project. If a "+" symbol is visible to the left of this new project entry, click on the "+" symbol to expand the underlying project components. If a "-" symbol is visible to the left of the project entry, the underlying components have already ben expanded. Right click on the "Sources" label underneath the project name, then click on "Add New File...".

You will be adding a C source file to the project. Choose a name for this source file and click SAVE.

The new source file will appear below the Sources label. You may need to expand the source label (click on the "+" symbol) to see the source file. Open the source file for editing by double-clicking on the file name.

The source file (currently blank) will be opened in the rightmost panel of the XPS main window. Copy the following code into the blank source file, then save the file. Note that the addresses of various peripherals are simply defined as constants in the "xparameters.h" include file. This is a powerful feature of XPS! When a hardware system is generated, parameters needed by software to correctly access the system are written to a single include file.

#include "xbasic_types.h"
#include "xparameters.h"
#include "xgpio.h"

int main ()
{
   Xuint32       led_test_value      = 0;
   Xuint32       led_7seg_codes [16] = {
                                        0x7E,0x30,0x6D,0x79,
                                        0x33,0x5B,0x5F,0x70,
                                        0x7F,0x7B,0x77,0x1F,
                                        0x4E,0x3D,0x4F,0x47
                                       };
   unsigned char led_7seg_index_h;
   unsigned char led_7seg_index_l;

   xil_printf("\r\n\r\n");
   xil_printf("Starting test of discrete LEDs...\r\n");
   xil_printf("\r\n");

   while (1)
   {
      usleep(500000);

      xil_printf("LED test value = 0x%2x.\r\n",led_test_value);

      // The 4 low order 4 bits of the test value define the
      // value (0x0 - 0xF) to be displayed on the righthand
      // 7-segment LED.  The next 4 higher order bits define
      // the value (0x0 - 0xF) to be displayed on the lefthand
      // 7-segment LED.

      led_7seg_index_l = ((led_test_value >> 0) & 0x0000000F);
      led_7seg_index_h = ((led_test_value >> 4) & 0x0000000F);

      // Write registers to define the displayed values.  The
      // 7-segment LEDs require a value that defines which
      // individual segments are on or off.  Here, I simply
      // use the value I wish to display as an index into an
      // array of "on/off" codes.

      // First, the 4-bit discrete LEDs...

      XGpio_mSetDataReg(
                        XPAR_LEDS_4BIT_BASEADDR,
                        1,
                        led_test_value & 0x0000000F
                       );

      // Next, the low order 7-segment display...

       XGpio_mSetDataReg(
                        XPAR_LED_7SEGMENT_BASEADDR,
                        1,
                        led_7seg_codes[led_7seg_index_l]
                       );

      // Finally, the high order 7-segment display...

      XGpio_mSetDataReg(
                        XPAR_LED_7SEGMENT_1_BASEADDR,
                        1,
                        led_7seg_codes[led_7seg_index_h]
                       );

      // Increment the test value, and then clip it to a
      // maximum value of 0xFF.

      led_test_value += 1;
      led_test_value &= 0x000000FF;
   }

   return 0;
}

The following screen shot illustrates the contents of the new soure file after pasting the preceding source code into it.

In the left pane of the XPS main window, right click on the label corresponding to the ppc405_0_bootloop. In the resulting pop-up menu, click on MARK TO INITIALIZE BRAMs. The icon to the left of the ppc405_0_bootloop should change to a green arrow with a red "X" over it. This icon indicates that the bootloop project will not be selected for compilation.

Repat this process for your newly created project. The icon to the left of the project should change to a green arrow with no red "X", indicating that this project will be selected for compilation.

Icons located to the left of the project names in the Software Projects window should appear as shown in the following screen shot.

In the leftmost panel of the XPS main window, select the new software project (click on it). The project should be highlighted. Then, from the Software menu at the top of the XPS main window, select "Generate Linker Script".

Verify that every code section is mapped to either the instruction on-chip memory (iocm_cntlr) or the data on-chip memory (docm_cntlr). Click GENERATE.

From the Device Configuration menu at the top of the XPS main window, select "Update Bitstream". This process will compile your software project, and then insert the resulting object code into the previously generated hardware configuration file. The resulting file contains both the hardware and software configuration data for the WARP FPGA board.

Verify that the process (memory initialization) has been completed successfully.


Back: Generating Hardware | Top | Next: Download & Testing

Last modified 16 years ago Last modified on Oct 29, 2007, 10:09:52 PM