Software Platform Builder Tutorial - Write the Application Code

Frozen Content

Tutorial - Getting Started with the Software Platform Builder
  First Steps
  Create the Software Platform
  Write the Application Code
  Build and Download
  Simplify the Application Code
 
Now we are ready to write the C source application. Thanks to the Generic Device I/O service, we can simply use the C library to access the keyboard and the Terminal instrument.

  1. From the File menu, select New » C Source Document.
    A new C source document is added to the Projects panel named "Source1.C".
    This new document is part of the embedded project.

     
  2. Double click on the C source document in the embedded project to open it, and enter the following code:

#include <stdio.h>

int main(void)

 {

        int ch;
        FILE *fp_kb = fopen("KEYBOARD_1", "r");
        FILE *fp_ti = fopen("SERIAL_1", "w");

        setbuf(fp_kb, NULL); /* Disable buffering */
        setbuf(fp_ti, NULL); /* Disable buffering */

        fprintf(fp_ti, "FIRST APPLICATION\n\n");
        fprintf(fp_ti, "Type your message and press ESC to exit...\n\n");

        while ((ch = fgetc(fp_kb)) != 27) /* 27 = ESC */

    {

            if (ch != EOF)
      {

                    fputc(ch, fp_ti);
      }

    }

        fprintf(fp_ti, "\n\nThat's it!\n");

        fclose(fp_kb);
        fclose(fp_ti);

        return 0;

 }

Note that we use simple standard C library functions like fopen(), fprintf(), fgetc(), fputc() and fclose() to access our peripherals. Thanks to the Software Platform Builder we created a library that provides the proper implementation for these functions. To prevent our input and/or output from being buffered, we need the two lines that disable buffering.

  1. To save the new project, click the Workspace button and select Save All.
    The Save [...] As dialog appears.
     
  2. Save the new C source file and give it a proper name, for example PS2_Echo.c.

That's it - we've finished the embedded software project. The whole project is ready to be built now. Proceed with the next section Build and Download in which we will build the design and download it to the FPGA device on the daughter board.

You are reporting an issue with the following selected text and/or image within the active document: