-
Notifications
You must be signed in to change notification settings - Fork 1
OpenDevice
Cycl0ne edited this page Apr 20, 2013
·
3 revisions
NAME
OpenDevice - Gain access to a device
SYNOPSIS
err = OpenDevice(deviceName, unitNum, iORequest, flags);
INT32 OpenDevice(STRPTR, UINT32, struct IORequest *, UINT32);
FUNCTION
This function opens the named device/unit and initializes the given
I/O request block. Specific documentation on opening procedures
may come with certain devices.
All calls to OpenDevice should have matching calls to CloseDevice!
INPUTS
devName - requested device name
unitNumber - the unit number to open on that device. The format of
the unit number is device specific. If the device does
not have separate units, send a zero.
iORequest - the I/O request block to be returned with appropriate fields initialized.
flags - additional driver specific information. This is sometimes used to request opening a device with exclusive access.
SEE ALSO
[[CloseDevice]], [[AddDevice]], [[RemDevice]]
EXAMPLE
#include "exec_funcs.h"
void main(SysBase *SysBase)
{
// We need a proper MessagePort to get Messages
struct MsgPort *mp= CreateMsgPort();
struct TimeRequest *io;
// Now we need an IO Request Structure
io = CreateIORequest(mp, sizeof(struct TimeRequest));
if (io == NULL)
{
DPrintF("Couldnt create IORequest (no Memory?)\n");
DeleteMsgPort(mp);
}
//Get Unit UNIT_VBLANK from device, this runs at 1/100 sec
INT32 ret = OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)io, 0);
if (ret != 0)
{
DPrintF("OpenDevice Timer failed!\n");
// Please tidy up, close all !
DeleteIORequest((struct IORequest *)io);
DeleteMsgPort(mp);
return;
}
// Now we have everything setup.. Lets Proceed
io->tr_node.io_Command = TR_ADDREQUEST; /* add a new timer request */
io->tr_time.tv_micro = 0; // 0 micros to wait
io->tr_time.tv_secs = 5; // 5 secs to wait
// post request to the timer -- will go to sleep till done
DPrintF("We will go 5 Seconds to sleep\n");
DoIO((struct IORequest *) io );
DPrintF("Return after 5 Seconds\n");
CloseDevice(io);
DeleteIORequest((struct IORequest *)io);
DeleteMsgPort(mp);
}