⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dstr_2d.c

📁 基于合众达公司开发的DM643实验平台的实验例程
💻 C
📖 第 1 页 / 共 2 页
字号:
    /*  Wait for the "ready" buffer to truly be ready.                      */
    /* -------------------------------------------------------------------- */
    DAT_wait(dstr->xfer_id);

    /* -------------------------------------------------------------------- */
    /*  Remember our dirty buffer's transfer ID.                            */
    /* -------------------------------------------------------------------- */
    dstr->xfer_id = id;

    /* -------------------------------------------------------------------- */
    /*  Return the pointer to the readied output buffer.                    */
    /* -------------------------------------------------------------------- */
    return (void *) ready;
} 


/* ======================================================================== */
/*  DSTR_GET     -- Get the next buffer from a stream.                      */
/* ======================================================================== */
void *dstr_get_2D(dstr_t *dstr)
{
    unsigned    id;
    char        *ready, *active;
    int         do_copy = 0;

    /* -------------------------------------------------------------------- */
    /*  Remember the pointer to the currently ready buffer, and generate    */
    /*  a pointer to the new active buffer.                                 */
    /*                                                                      */
    /*  The ready buffer is always 'w_size' quanta behind the active        */
    /*  buffer, modulo the total buffer size.  The conditional handles      */
    /*  the one wraparound case.  The input offset marches from 'w_size -   */
    /*  quantum' thru 'i_size - quantum'.                                   */
    /*                                                                      */
    /*  We also decide whether an extra 'copy' transfer is issued here,     */
    /*  based on the current value of i_ofs relative to the window size.    */
    /* -------------------------------------------------------------------- */
    active  = dstr->i_data + dstr->i_ofs;
    do_copy = dstr->i_ofs >= (dstr->w_size + (dstr->quantum * dstr->multiple));

    if (dstr->i_ofs >= dstr->w_size)
        ready = dstr->i_data + dstr->i_ofs - dstr->w_size;  /* Normal       */
    else
        ready = dstr->i_data + dstr->w_size;                /* Wraparound   */

    /* -------------------------------------------------------------------- */
    /*  Update our input offset for the next transfer, and handle its       */
    /*  wraparound case as well.                                            */
    /* -------------------------------------------------------------------- */
    dstr->i_ofs  += (dstr->quantum * dstr->multiple);
    if (dstr->i_ofs >= dstr->i_size)
        dstr->i_ofs = dstr->w_size - (dstr->quantum * dstr->multiple);

    dprintf(("ACTIVE: %3d  READY: %3d  COPY: %d  W_SIZE: %d\n", 
             active - i_data, ready - i_data, do_copy, w_size));

    /* -------------------------------------------------------------------- */
    /*  Fire off a new transfer for the next buffer.                        */
    /* -------------------------------------------------------------------- */
    if (dstr->x_ofs < dstr->x_size)
    {
        id = DAT_copy2d( DAT_2D1D,
                         (void *) (dstr->x_data + dstr->x_ofs), 
                         (void *) (active),
                         dstr->quantum,
                         dstr->multiple,
                         dstr->stride);
    }

    /* -------------------------------------------------------------------- */
    /*  Handle extra copy for sliding window.   We replace the previous     */
    /*  "ready" line with a copy of the new "active" line.   In the case    */
    /*  where we do this extra copy, we block on the extra copy only.       */
    /* -------------------------------------------------------------------- */
    if (do_copy)
    {
        id = DAT_copy((void *) (active), 
                      (void *) (ready - (dstr->quantum * dstr->multiple)), 
                      dstr->quantum * dstr->multiple);
    }

    /* -------------------------------------------------------------------- */
    /*  Actually wait the ready buffer, to be sure it's truly ready.        */
    /* -------------------------------------------------------------------- */
    DAT_wait(dstr->xfer_id);

    /* -------------------------------------------------------------------- */
    /*  Remember the new transfer ID, and update our external data pointer. */
    /* -------------------------------------------------------------------- */
    dstr->xfer_id = id;
    dstr->x_ofs  += (dstr->stride * dstr->multiple);

    /* -------------------------------------------------------------------- */
    /*  Return the pointer to the ready buffer.  We're done.                */
    /* -------------------------------------------------------------------- */
    return (void*) ready;
}

/* ======================================================================== */
/*  DSTR_PUT     -- Write out the next buffer in a double-buffer.           */
/* ======================================================================== */
void *dstr_put_2D(dstr_t *dstr)
{
    unsigned id;
    char *ready;

    /* -------------------------------------------------------------------- */
    /*  If x_ofs < 0, then we haven't started yet.  Return the initial      */
    /*  buffer pointer for the user to start writing data.                  */
    /* -------------------------------------------------------------------- */
    if (dstr->x_ofs < 0)
    {
        dstr->x_ofs = 0;
        dstr->i_ofs = 0;
        id = DAT_copy((void *) (dstr->i_data + dstr->i_ofs),
                      (void *) (dstr->x_data + dstr->x_ofs),
                      1);
        dstr->xfer_id = id;
        return (void *) dstr->i_data;
    }

    /* -------------------------------------------------------------------- */
    /*  Otherwise, fire off the copy for the dirty buffer.                  */
    /* -------------------------------------------------------------------- */
    if (dstr->x_ofs < dstr->x_size)
    {
        id = DAT_copy2d(  DAT_1D2D,
                          (void *) (dstr->i_data + dstr->i_ofs),
                          (void *) (dstr->x_data + dstr->x_ofs),
                          dstr->quantum,
                          dstr->multiple,
                          dstr->stride);
    }

    /* -------------------------------------------------------------------- */
    /*  Generate the pointer to the newly ready buffer, and move our        */
    /*  output's data pointer.                                              */
    /* -------------------------------------------------------------------- */
    dstr->x_ofs += dstr->stride * dstr->multiple;
    dstr->i_ofs ^= (dstr->quantum * dstr->multiple);
    ready        = dstr->i_data + dstr->i_ofs;

    /* -------------------------------------------------------------------- */
    /*  Wait for the "ready" buffer to truly be ready.                      */
    /* -------------------------------------------------------------------- */
    DAT_wait(dstr->xfer_id);

    /* -------------------------------------------------------------------- */
    /*  Remember our dirty buffer's transfer ID.                            */
    /* -------------------------------------------------------------------- */
    dstr->xfer_id = id;

    /* -------------------------------------------------------------------- */
    /*  Return the pointer to the readied output buffer.                    */
    /* -------------------------------------------------------------------- */
    return (void *) ready;
} 

/* ======================================================================== */
/*  DSTR_REWUIND    -- Initialize a new DMA Stream object.                  */
/* ======================================================================== */
int dstr_rewind
(
    dstr_t         *dstr,       /* DMA Stream structure.                    */
    void           *x_data,     /* "External" data buffer.                  */
    dstr_dir_t      dir,        /* Direction (Input or Output)              */             
    unsigned short  w_size      /* Window size.  Set to 1 for double buf.   */  
)
{
  
     

    /* -------------------------------------------------------------------- */
    /*  Poke all the appropriate values into the structure.                 */
    /*  Make sure our external and internal sizes are rounded to multiples  */
    /*  of our transfer quantum.                                            */
    /* -------------------------------------------------------------------- */
    dstr->x_data   = (char *) x_data;   
    dstr->i_ofs    = 0;
    dstr->x_ofs    = 0;
    
     
    
    if (dir == DSTR_OUTPUT)
    {
        dstr->x_ofs = -1;
        DAT_wait(dstr->xfer_id);
    }   
  
    /* -------------------------------------------------------------------- */
    /*  If this is an external-to-internal transfer, start off the initial  */
    /*  transfers to pipe up the stream.                                    */
    /* -------------------------------------------------------------------- */
    if (dir == DSTR_INPUT)
    {
        
        unsigned id; 
                        
        dprintf(("PREFETCH: ACTIVE = %d\n", dstr->x_ofs));

        id = DAT_copy2d( DAT_2D1D,
                         (void*) (dstr->x_data), 
                         (void*) (dstr->i_data),
                         dstr->quantum,
                         w_size * dstr->multiple,
                         dstr->stride);

        dstr->x_ofs   += (dstr->stride  * dstr->multiple * w_size);
        dstr->i_ofs   += (dstr->quantum * dstr->multiple * w_size);
        dstr->xfer_id = id;
    }    
    
    return 0;
} 



/*--------------------------------------------------------------------------*/
/* Function obtains transfer id and makes sure that DAT_wait completes.     */
/*--------------------------------------------------------------------------*/

void dstr_close(dstr_t *dstr)
{
    unsigned id;
    
    id = dstr->xfer_id;
    
  //  DAT_wait(id);
}

/* ======================================================================== */
/*  End of file:  dstr.c                                                    */
/* ------------------------------------------------------------------------ */
/*            Copyright (c) 2000 Texas Instruments, Incorporated.           */
/*                           All Rights Reserved.                           */
/* ======================================================================== */

⌨️ 快捷键说明

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