Texas Instruments TMS320 User Manual page 266

Dsp/bios v5.40
Hide thumbs Also See for TMS320:
Table of Contents

Advertisement

Opening Devices
Example 7-28. Typical Features for a Terminating Device
7-36
Int Dxx_open(DEV_Handle device, String name)
{
Dxx_Handle objptr;
/* check mode of device to be opened */
if ( `device->mode is invalid` ) {
return (SYS_EMODE);
}
/* check device id */
if ( `device->devid is invalid` ) {
return (SYS_ENODEV);
}
/* if device is already open, return error */
if ( `device is in use` ) {
return (SYS_EBUSY);
}
/* allocate device-specific object */
objptr = MEM_alloc(0, sizeof (Dxx_Obj), 0);
`fill in device-specific fields`
/*
* create synchronization semaphore ... */
objptr->sync = SEM_create( 0 , NULL);
/* initialize ready semaphore for
SIO_select()/Dxx_ready() */
objptr->ready = NULL;
`do any other device-specific initialization required`
/* assign initialized object */
device->object = (Ptr)objptr;
return (SYS_OK);
}
The first two steps take care of error checking. For example, a request to
open an output-only device for input should generate an error message. A
request to open channel ten on a five-channel system should also generate
an error message.
The next step is to determine if the device is already opened. In many cases,
an opened device cannot be re-opened, so a request to do so generates an
error message.
If the device can be opened, the rest of Dxx_open consists of two major
operations. First, the device-specific object is initialized, based in part on the
device
params settings passed by SIO_create. Second, this object is
attached to device
object. Dxx_open returns SYS_OK to SIO_create, which
now has a properly initialized device object.

Advertisement

Table of Contents
loading

Table of Contents