Software Platform Builder Tutorial - Simplifying 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
In our example keyboard echo design, the C application has source lines to open and close the input and output devices. This is common for many situations. However, since we use only one input device and one output device, we can simplify the application even more by defining the keyboard as stdin and the Terminal instrument as stdout.

For this we just need to configure the standard devices in the Software Platform document and then modify the application.

Configure the Generic Device I/O Service

  1. In the Projects panel, double-click on the PS2_Echo_SP.SwPlatform document to open the Software Platform document.
  2. Click on the Generic Device I/O in the Software Services list. The configuration options for the Generic Device I/O service are displayed in the Configuration region of the document. Make the following changes to the service's configuration:
    • Enable the option Standard Input.
      • Click on stdin device name, then on the down-arrow next to it and select KEYBOARD_1
      • Leave the stdin buffering type set to None (remember that we did not want input and output buffering for our application).
    • Enable the option Standard Output
      • Click on stdout device name, then on the down-arrow next to it and select SERIAL_1
      • Set the stdout buffering type to None.

The Configuration for the Generic Device I/O service should now appear as shown in Figure 1.

Figure 1. Modified configuration for the Generic Device I/O service.

Rewrite and Rebuild the Application

Because we changed the configuration of the Generic Device I/O service, the library implementation will differ from the first build. This means that in our application we now can access the keyboard and Terminal Instrument as stdin and stdout. Instead of opening and closing our devices, we can simply use the printf(), getc() and putc() functions.

Check out the code below and compare the differences with the previous version:

#include <stdio.h>

int main(void)


        int ch;
        printf("SIMPLIFIED APPLICATION\n\n");
        printf("Type your message and press ESC to exit...\n\n");

        while ((ch = getc(stdin)) != 27) /* 27 = ESC */


            if (ch != EOF)

                     putc(ch, stdout);


        printf("\n\nThat's it!\n");

        return 0;


The following differences can be observed:

  • The calls to fopen() and fclose() are no longer necessary, stdin and stdout are used instead.
  • The calls to setbuf() are no longer necessary because we configured the buffering type in the Generic Device I/O service.
  • The fprintf(), fgetc() and fputc() functions are replaced respectively by printf(), getc() and putc().
  1. Double click on the C source document in the embedded project to open it, and enter the code above. Save your project.
  2. In the Devices view, click on the Compile button just below the TSK3000A symbol. Both the library and the application are rebuilt.
  3. Click on the Download button to load and start the application. The Terminal instrument's display should appear as shown in Figure 2.

    Figure 2. Terminal instrument display after rebuild.

Characters you type on the PS/2 keyboard connected to the NanoBoard are echoed on the Terminal instrument's display.

Now compare the final application to the software requirements we defined previously (see Write the Application Code). It's that simple with the Software Platform Builder to write software that accesses input and output devices!

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