dio_cb.c

来自「DM642的一些基本功能例程。包括一些图像处理例子」· C语言 代码 · 共 118 行

C
118
字号
/*
 *  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.10.00.23 07-02-03 (ddk-b12)" */
/*
 *  ======== dio_cb.c ========
 *  Callback based functions of DIO.
 *
 */

#include <std.h>

#include <dev.h>
#include <que.h>
#include <sem.h>
#include <sys.h>

#include <iom.h>
#include <dio.h>

Int     DIO_cbIdle(DEV_Handle device, Bool flush);
Int     DIO_cbIssue(DEV_Handle device);
Bool    DIO_cbReady(DEV_Handle device, SEM_Handle sem);
Int     DIO_cbReclaim(DEV_Handle device);
Void    DIO_cbCallback(Ptr devp, DEV_Frame *frame);

/*
 *  ======== DIO_cbCallback ========
 */
Void DIO_cbCallback(Ptr devp, DEV_Frame *frame)
{
    DEV_Handle  device = (DEV_Handle)devp;
    DIO_Handle  dio = (DIO_Handle)device->object;

    if (frame->cmd == IOM_READ || frame->cmd == IOM_WRITE) {
        QUE_put(device->fromdevice, frame); 
        dio->context.cb.fxn(dio->context.cb.arg0,
            dio->context.cb.arg1);
    }
}

/*
 *  ======== DIO_cbIdle ========
 *  DIO_cbIdle() simply return SYS_OK
 *  which means it really is a NOP.
 */
Int DIO_cbIdle(DEV_Handle device, Bool flush)
{
    return (SYS_OK);
}

/*
 *  ======== DIO_cbIssue ========
 */
Int DIO_cbIssue(DEV_Handle device)
{
    DIO_Handle dio = (DIO_Handle)device->object;
    DEV_Frame   *frame;
    Int         status;

    frame = QUE_get(device->todevice);

    frame->cmd = (device->mode == DEV_INPUT) ? IOM_READ : IOM_WRITE;
    frame->status = IOM_PENDING;

    status = dio->fxns->mdSubmitChan(dio->chanp, frame);

    if (status < 0) {
        return (SYS_EBADIO);
    }
    else {
        if (status == IOM_COMPLETED) {
            DIO_cbCallback(device, frame);
        }
    
        return (SYS_OK);
    }

}

/*
 *  ======== DIO_cbReady ========
 */
Bool DIO_cbReady(DEV_Handle device, SEM_Handle sem)
{
    return (!(QUE_empty(device->fromdevice)));
}

/*
 *  ======== DIO_cbReclaim ========
 *  This function is expecting at least one buffer ready to be
 *  processed from the fromdevice queue.
 *  If there are no buffers ready then it will return an error.
 *  If more than one buffer is ready, it will call the callback function.
 */
Int DIO_cbReclaim(DEV_Handle device)
{
    DIO_Handle  dio = (DIO_Handle)device->object;
    QUE_Handle  queElem;

    queElem = device->fromdevice->next;

    if (queElem == device->fromdevice) {
        return (SYS_EBADIO);
    }

    if (queElem->next != device->fromdevice) {
        dio->context.cb.fxn(dio->context.cb.arg0,
            dio->context.cb.arg1);
    }

    return (SYS_OK);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?