Nut/OS  5.0.5
API Reference
XgDevDebugLpc

Functions

NUTFILELpcDevDebugOpen (NUTDEVICE *dev, const char *name, int mode, int acc)
 Open debug device.
int LpcDevDebugClose (NUTFILE *fp)
 Close debug device.
int LpcDevDebugIOCtl (NUTDEVICE *dev, int req, void *conf)
 Handle I/O controls for debug device 2.
int LpcDevDebugWrite (NUTFILE *fp, const void *buffer, int len)
 Send characters to debug device 0.

Variables

NUTDEVICE devDebug0
 Debug device 0 information structure.

Function Documentation

NUTFILE* LpcDevDebugOpen ( NUTDEVICE dev,
const char *  name,
int  mode,
int  acc 
)

Open debug device.

Parameters:
devPointer to a previously registered NUTDEVICE structure.
nameIgnored, typically points to an empty string.
modeIgnored, operation mode.
accIgnored, should be zero.
Returns:
Pointer to a static NUTFILE structure.

References _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, and NULL.

int LpcDevDebugClose ( NUTFILE fp)

Close debug device.

Parameters:
fpPointer to a _NUTFILE structure, obtained by a previous call to LpcDevDebugOpen().
Returns:
Always 0.
int LpcDevDebugIOCtl ( NUTDEVICE dev,
int  req,
void *  conf 
)

Handle I/O controls for debug device 2.

The debug device supports UART_SETSPEED only.

Parameters:
devIdentifies the device that receives the device-control function.
reqRequested control function. May be set to one of the following constants:
  • UART_SETSPEED, conf points to an uint32_t value containing the baudrate.
confPoints to a variable that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.
int LpcDevDebugWrite ( NUTFILE fp,
const void *  buffer,
int  len 
)

Send characters to debug device 0.

This function is called by the low level input routines of the C runtime library, using the _NUTDEVICE::dev_write entry.

A newline character will be automatically prepended by a carriage return.

Parameters:
fpPointer to a _NUTFILE structure, obtained by a previous call to LpcDevDebugOpen().
Returns:
Number of characters sent.

References _NUTFILE::nf_dev.


Variable Documentation

Initial value:
 {
    NULL,               
    {'u', 'a', 'r', 't', '0', 0, 0, 0, 0}
    ,                   
    0,                  
    LPC_UART0_BASE,     
    0,                  
    NULL,               
    &dbg0file,          
    Debug0Init,         
    LpcDevDebugIOCtl,   



    NULL,               

    LpcDevDebugWrite,   
    LpcDevDebugOpen,    
    LpcDevDebugClose,   



    NULL                

}

Debug device 0 information structure.

Debug device 0 information structure.

Usually, the device structure is the only public symbol that may be referenced by the application code using

 #include <dev/debug.h>

 {
     ...
     NutRegisterDevice(&devDebug0, 0, 0);
     ...
 }

If not referenced, the driver code (and this structure) will not be included in the final binary.

The name of the structure may differ among platforms. Portable applications should avoid it and instead make use of dev/board.h.

 #include <dev/board.h>

 {
     ...
     NutRegisterDevice(&DEV_DEBUG, 0, 0);
     ...
 }

While output is supported by default, input may be not. If input is required, applications may replace DEV_DEBUG by DEV_CONSOLE. In this case the debug driver is selected only, if it has input capability (see NUT_DEV_DEBUG_READ). Otherwise an interrupt driven UART driver will be used.

Note, that this polling driver has certain advantages

  • very low memory usage
  • allows stdio output functions in interrupt context
  • allows stdio output functions in early system stage
  • no internal buffering, output is synchronous
  • atomic output with multiple threads

but also some disadvantages

  • concurrent threads are blocked during output
  • most or all UART settings are hard coded
  • may not work with non-ASCII (binary) data
  • often only output is supported, not input
  • only one instance (open) is allowed

When used with Harvard architectures, additional functions may be offered to access data in program space.