EasyManua.ls Logo

Texas Instruments TMS320 - Page 266

Texas Instruments TMS320
288 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Opening Devices
7-36
Example 7-28. Typical Features for a Terminating Device
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.
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);
}

Table of Contents

Other manuals for Texas Instruments TMS320

Related product manuals