C H A P T E R  4

Programming the User LED

This chapter describes how to use the Alarm/User LED. The Alarm/User LED is located on the front panel of the Netra CP2300 cPSB board. The bi-colored LED is red and green in color (see FIGURE 4-1 for the location of the Alarm/User LED on the board front panel).

In order to use the LED function, a SPARC V9 64-bit C library and the led.h file are required. The library and the file are available in the SUNWcp23u package. The Application Programming Interface (API) for the user is documented in the led.h file. See Files and Packages Required to Support the Alarm/User LED for more information.

 

FIGURE 4-1 Illustration of a Typical Netra CP2300 cPSB Board Front Panel Showing the Alarm/User LED

A typical Netra CP2300 cPSB board front panel in which the Alarm/User LED is the third from the bottom when PMC slots are at the top.


Files and Packages Required to Support the Alarm/User LED

To use the Alarm/User LED feature, the user should update the firmware with the appropriate firmware version that supports this feature on the Netra board.



Note - To check the current firmware version and for instructions on how to update the firmware, refer to the technical reference manual of the Netra board that you are using.



The list of packages that are required are as follows:

  • SUNWcp23u: SPARC V9 64-bit C library libcp2300.so.1 available at:
/usr/platform/${PLATFORM}/lib
  • SUNWcp23u: LED include file available at:
/usr/platform/${PLATFORM}/include/sys/

Ensure that the following driver is also there, as needed:

  • SUNWcp23x.u: 64-bit sc_nct driver available at:
/platform/${PLATFORM}/kernel/drv/sparcv9/sc_nct

A typical example of ${PLATFORM} is SUNW,Netra-CP2300 for the Netra CP2300 board. An example for the library directory is:

/usr/platform/SUNW,Netra-CP2300 /lib


Applications

This section provides the application programming interface (API) to control the command combination of the Alarm/User LED, and instructions on how to compile and link the information.



Note - Since the LED interface installs and then removes the sc_nct streams module, an error can occur when multiple applications attempt to use this interface at the same time. If the user desires more than one application to use this interface, application software should incorporate a synchronization method such that only one access to the interface exists at any time.



Application Programming Interface (API)

 

CODE EXAMPLE 4-1 Application Programming Interface for the Netra CP2300 Board
extern   int   led(int led, int cmd);
 
/* LEDS */
#define BLUE_LED          0x0
#define HOTSWAP_LED       BLUE_LED
#define PLD_GREEN_LED     0x04
#define GREEN_LED         PLD_GREEN_LED
#define AMBER_LED         0x08
 
/* LED COMMANDS */
#define LED_OFF        0x00
#define LED_ON         0x01
#define LED_BLINK_SLOW 0x02
#define LED_BLINK_FAST 0x03
 
/* ERROR CODES */
#define ESEQUENCE      200  /* portnum mismatch */
#define ECMDCOMP       201  /* non-zero command completion */
#define ECMDCODE       202  /* smc command mismatch */

The supported LED and command combinations are shown in TABLE 4-1.

TABLE 4-1 Supported LED and Command Combinations for the Netra CP2300 Board

Color of LED

LED_OFF

LED_ON

LED_BLINK_SLOW

LED_BLINK_FAST

BLUE_LED

Yes

Yes

No

No

GREEN_LED

Yes

Yes

Yes

Yes

AMBER_LED

Yes

Yes

No

No


Compile

As you compile your application, you need to use the compiler command (cc) flag
-I, to include the sys/led.h file named in Files and Packages Required to Support the Alarm/User LED. Specify 64-bit binaries by setting the
-xarch=v9 and -D__sparcv9 compiler flags.

For example:

-xCC -xarch=v9 -D__sparcv9 -I/usr/platform/SUNW,Netra-CP2300/include/



Note - Type the above command all on one line.



Link

To create a link to the library named (libcp2300.so.1) listed in Files and Packages Required to Support the Alarm/User LED, use the linker flag -L command.

For example:

-L /usr/platform/SUNW,Netra-CP2300/lib

Sample Application Program

This section presents a sample test.c application to turn the LED on, off, and blink.

CODE EXAMPLE 4-2 Sample LED Application Program
#include       <stdio.h>
#include       <sys/led.h>
 
main()
{
      /* blue on, rest off */
      printf("\n\nTesting Blue led ON, rest off\n");
      fflush(stdout);
      printf("BLUE_LED on returned %d\n", led(BLUE_LED, LED_ON));
      fflush(stdout);
      sleep(4);
      printf("GREEN_LED off returned %d\n", led(GREEN_LED, LED_OFF));
      fflush(stdout);
      sleep(4);
      printf("AMBER_LED off returned %d\n", led(AMBER_LED, LED_OFF));
      fflush(stdout);
      sleep(4);
 
      /* all lights on, and green blinking fast */
      printf("\n\nTesting all led's on and green blinking fast\n");
      fflush(std out);
      printf("BLUE_LED on returned %d\n", led(BLUE_LED, LED_ON));
      fflush(stdout);
      sleep(4);
      printf("AMBER_LED on returned %d\n", led(AMBER_LED, LED_ON));
      fflush(stdout);
      sleep(4);
      printf("GREEN_LED blink returned %d\n", led(GREEN_LED, LED_BLINK_FAST));
      fflush(stdout);
      sleep(4);
}
 
cc -xCC -xarch=v9 -D__sparcv9 \
        -I /usr/platform/SUNW,Netra-CP2300/include \
        -L /usr/platform/SUNW,Netra-CP2300/lib
        -l cp2300 \
        -o test \
        test.c