示例#1
0
/******************************************************************************
 * Fifo_create
 ******************************************************************************/
Fifo_Handle Fifo_create(Fifo_Attrs *attrs)
{
    Fifo_Handle hFifo;
    BUF_Attrs bAttrs = BUF_ATTRS;

    if (attrs == NULL) {
        return NULL;
    }
    
    hFifo = MEM_calloc(Dmai_Bios_segid, sizeof(Fifo_Object), 0);

    if (hFifo == NULL) {
        Dmai_err0("Failed to allocate space for Fifo Object\n");
        return NULL;
    }
    
    /* Allocate a buffer pool for messages */
    bAttrs.segid = Dmai_Bios_segid;
    hFifo->hBufPool = BUF_create(attrs->maxElems, sizeof(Fifo_Elem), 0, &bAttrs);
    if (hFifo->hBufPool == NULL) {
        Dmai_err0("Failed to allocate space for buffer pool\n");
        MEM_free(Dmai_Bios_segid, hFifo, sizeof(Fifo_Object));
        return NULL;
    }
    
    /* initialize the object */
    QUE_new(&hFifo->queue);
    SEM_new(&hFifo->sem, 0);
    SEM_new(&hFifo->mutex, 1);

    return hFifo;
}
示例#2
0
Bool		bfqCreate			( BufferQueue_Handle queue, BufferQueue_Frame * frames, Int BufCount, Int BufSize, Int SegID)
{
	Int i;
	Ptr p;
	
	// Acquire the frames
	queue->Frames = frames;
	queue->bDynamicFrames = FALSE;
	
	// Init the QUE and SEM objects.
	SEM_new(&(queue->semFullBuffers), 0);
	SEM_new(&(queue->semEmptyBuffers), BufCount);
	
	QUE_new( &(queue->queFullBuffers) );
	QUE_new( &(queue->queEmptyBuffers) );
	QUE_new( &(queue->queEmptyFrames) );
	
	for (i=0; i<BufCount; i++)
	{
		// TODO: handle errors.
		
		// If the _BFQ_INIT_BUFFERS is defined, fill the buffers with 0xFF,
		// leave them uninitialized, otherwise.
#ifdef _BFQ_INIT_BUFFERS
		p = MEM_valloc( SegID, BufSize, 0, 0xFF );
		queue->Frames[i].Buffer = p;
		assertLog( p != MEM_ILLEGAL);
#else
		p = MEM_alloc( SegID, BufSize, 0 );
		queue->Frames[i].Buffer = p;
		assertLog( p != MEM_ILLEGAL);
#endif
		QUE_put(&(queue->queEmptyBuffers), &(queue->Frames[i]));
	}
		
	queue->BufSize = BufSize;
	queue->BufCount = BufCount;
	queue->SegId   = SegID;
	
	return TRUE;
}
示例#3
0
/*
 *  ======== QUE_create ========
 */
QUE_Handle QUE_create(QUE_Attrs *attrs)
{
    QUE_Handle  queue;

    if ((queue = MEM_alloc(0, sizeof(QUE_Elem), 0)) == MEM_ILLEGAL) {
        return(NULL);
    }

    QUE_new(queue);

    return (queue);
}
示例#4
0
/*
 *  ======== MSGQ_open ========
 *  Opens a MSG queue under given name. If the attrs variable is NULL,
 *  the default MSGQ_Attrs values will be used.
 * 
 *  The queueName string must be persistent for the life of the message queue.
 *  Note: the queueName can be NULL, but then it cannot be located.
 */
Int MSGQ_open(String      queueName,
              MSGQ_Queue *msgqQueue,
              MSGQ_Attrs *attrs)
{     
    MSGQ_Id i;    
    MSGQ_Handle msgqHandle;
    
    /* assert(msgqQueue != NULL); */
    
    *msgqQueue = MSGQ_INVALIDMSGQ;
    
    /* Use the default attributes if none are supplied */
    if (attrs == NULL) {
        attrs = (MSGQ_Attrs *)&MSGQ_ATTRS; 
    }

    /*  Search the local message queue array to find a free slot in it. */ 
    for (i = 0; i < MSGQ->numMsgqQueues; i++) {
        
        /* 
         *  The following is atomic to allow multiple MSGQ_open()'s at once.
         *  If ATM_setu() returns MSGQ_EMPTY, use that slot.
         *  If ATM_setu() returns !MSGQ_EMPTY, continue looking...
         */
        if (ATM_setu((Uns *)&(MSGQ->msgqQueues[i].status), MSGQ_INUSE) ==
                MSGQ_EMPTY) {           
            /* 
             *  Found empty slot...
             *  1. Create the MSGQ_Queue value 
             *  2. break of this loop.
             */
            *msgqQueue = ((Uint32)GBL_getProcId() << 16) | i;
            break;
        }
    }

    /* See if we found a free slot */
    if (*msgqQueue == MSGQ_INVALIDMSGQ) {
        return (SYS_ENOTFOUND);
    }
    
    msgqHandle = &(MSGQ->msgqQueues[i]);
    
    /* Initialize the fields in the returned MSGQ_Obj */
    QUE_new(&(msgqHandle->queue));
    msgqHandle->name         = queueName;
    msgqHandle->notifyHandle = attrs->notifyHandle;
    msgqHandle->pend         = attrs->pend;
    msgqHandle->post         = attrs->post;
        
    return (SYS_OK);
}
示例#5
0
文件: gio.c 项目: CheredHerry/ti-bios
/*
 *  ======== GIO_new ========
 */
GIO_Handle GIO_new(GIO_Handle gioChan, String name, Int mode, Int *status, Ptr optArgs,
        IOM_Packet packetBuf[], Ptr syncObject, GIO_Attrs *attrs)
{
    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);
    }

    /* initialize queue structures */
    QUE_new(&gioChan->freeList);

    /* zero out the packet buffers */
    memset(packetBuf, 0, attrs->nPackets * sizeof(IOM_Packet));

    /* Put packets into freeList. */
    for (i=0; i < attrs->nPackets; i++) {
        QUE_put(&gioChan->freeList, &packetBuf[i]);
    }

    /*
     * Plug 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 = syncObject;

    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) {
        return (NULL);
    }

    return (gioChan);
}
示例#6
0
文件: gio.c 项目: CheredHerry/ti-bios
/*
 *  ======== 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);
}