Nut/OS  4.10.3
API Reference
Generic Character Device

Character Device Driver Template. More...

Collaboration diagram for Generic Character Device:

Data Structures

struct  DEVDCB
 Device driver's private data structure. More...

Defines

#define GENDEV_SPORT   0x100
#define GENDEV_DPORT   0x104
#define GENDEV_SIGNAL   sig_INTERRUPT1

Functions

int GenCharWrite_P (NUTFILE *fp, PGM_P buffer, int len)
 Write program data to the device.
long GenCharSize (NUTFILE *fp)
 Retrieves the number of characters in input buffer.

Variables

NUTDEVICE devGenChar
 Device information structure.

Detailed Description

Character Device Driver Template.

Extensively commented source code of a Nut/OS character device driver. It doesn't drive any specific device, but can be used as a template when adding new device drivers.


Define Documentation

#define GENDEV_SPORT   0x100

Definition at line 67 of file genchar.c.

#define GENDEV_DPORT   0x104

Definition at line 72 of file genchar.c.

#define GENDEV_SIGNAL   sig_INTERRUPT1

Definition at line 77 of file genchar.c.

Referenced by GenCharSize().


Function Documentation

int GenCharWrite_P ( NUTFILE fp,
PGM_P  buffer,
int  len 
)

Write program data to the device.

Similar to GenCharWrite() except that the data is located in program memory.

This function is called by the low level output routines of the C runtime library, using the _NUTDEVICE::dev_write_P entry, which is available on Harvard architectures only.

The function may block the calling thread.

Parameters:
fpPointer to a NUTFILE structure, obtained by a previous call to UsartOpen().
bufferPointer to the data in program space to be written.
lenNumber of bytes to write.
Returns:
The number of bytes written. With some devices this may be less than the number of bytes specified if a timeout occured. A return value of -1 indicates an error.

Definition at line 380 of file genchar.c.

long GenCharSize ( NUTFILE fp)

Retrieves the number of characters in input buffer.

This function is called by the low level size routine of the C runtime library, using the _NUTDEVICE::dev_size entry.

Parameters:
fpPointer to a _NUTFILE structure, obtained by a previous call to UsartOpen().
Returns:
The number of bytes currently stored in input buffer.

Definition at line 452 of file genchar.c.

References DEVDCB::dcb_rcnt, _NUTDEVICE::dev_dcb, GENDEV_SIGNAL, _NUTFILE::nf_dev, NutIrqDisable(), and NutIrqEnable().

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
    
    0,

    
    {'g', 'e', 'n', 'c', 'h', 'a', 'r', 0, 0},

    
    IFTYP_CHAR,

    
    0,

    
    0,

    
    0,

    
    &devdcb,

    
    GenCharInit,

    
    GenCharIOCtl,

    
    GenCharRead,

    
    GenCharWrite,


    
    GenCharWrite_P,


    
    GenCharOpen,

    
    GenCharClose,

    
    GenCharSize
}

Device information structure.

Definition at line 469 of file genchar.c.