gio_crea.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:3k
- /*
- * Copyright 2003 by Texas Instruments Incorporated.
- * All rights reserved. Property of Texas Instruments Incorporated.
- * Restricted rights to use, duplicate or disclose this code are
- * granted through contract.
- *
- */
- /* "@(#) DDK 1.11.00.00 11-04-03 (ddk-b13)" */
- /*
- * ======== gio_crea.c ========
- *
- */
- #include <std.h>
- #include <dev.h>
- #include <mem.h>
- #include <que.h>
- #include <sys.h>
- #include <gio.h>
- #include <iom.h>
- #include <_gio.h>
- /*
- * ======== GIO_create ========
- */
- GIO_Handle GIO_create(String name, Int mode, Int *status, Ptr optArgs,
- GIO_Attrs *attrs)
- {
- GIO_Handle gioChan;
- IOM_Packet *packet;
- DEV_Device *entry;
- Int i;
- Int tmpStat;
- if (attrs == NULL) {
- attrs = &GIO_ATTRS;
- }
- /*
- * status param is used to pass additional device status back to caller.
- */
- if (status == NULL) {
- status = &tmpStat; /* no longer need to check if status valid ptr */
- }
- *status = IOM_COMPLETED;
-
- /*
- * Find device structure in device table for device with name 'name'.
- * DEV_match() returns the remaining name string for use by the
- * mini-driver's create() function.
- */
- name = DEV_match(name, &entry);
- if (entry == NULL) {
- SYS_error(name, SYS_ENODEV); /* sys error - no device found */
- return (NULL);
- }
-
- if (entry->type != DEV_IOMTYPE) {
- SYS_error("IOM", SYS_EINVAL); /* sys error - invalid device parameter */
- return (NULL);
- }
- /* allocate and 0-fill IOM object */
- gioChan = MEM_calloc(0, sizeof(GIO_Obj), 0);
- if (gioChan == NULL) {
- *status = IOM_EALLOC;
-
- return (NULL);
- }
- /* initialize queue structures */
- QUE_new(&gioChan->freeList);
- /*
- * Allocate packets for asynch I/O.
- */
- for (i=0; i < attrs->nPackets; i++) {
- packet = _GIO_mkPacket();
- if (packet == NULL) {
-
- *status = IOM_EALLOC;
- GIO_delete(gioChan);
- return (NULL);
- }
- QUE_put(&gioChan->freeList, packet);
- }
- /*
- * Create semaphore or other synchronization object. 'gioChan->syncObj' is
- * used to wait for I/O to complete when GIO_submit() is called with
- * NULL *appCallback parameter.
- */
- gioChan->syncObj = GIO->SEMCREATE(0, NULL);
- if (gioChan->syncObj == NULL) {
- *status = IOM_EALLOC;
-
- GIO_delete(gioChan);
- return (NULL);
- }
- gioChan->fxns = (IOM_Fxns *)entry->fxns;
- gioChan->mode = mode;
- gioChan->timeout = attrs->timeout;
- *status = gioChan->fxns->mdCreateChan(&gioChan->mdChan, entry->devp,
- name, mode, optArgs, _GIO_iomCallback, gioChan);
- if (gioChan->mdChan == NULL) {
-
- GIO_delete(gioChan);
- return (NULL);
- }
- return (gioChan);
- }