Exemplo n.º 1
0
/* This function shall be invoked by the API library 
 * and should not be explicitly invoked.
 */
void
CyU3PDmaBufferDeInit (
        void)
{
    uint32_t status;

    /* Get the mutex lock. */
    if (CyU3PThreadIdentify ())
    {
        status = CyU3PMutexGet (&glBufferManager.lock, CYU3P_WAIT_FOREVER);
    }
    else
    {
        status = CyU3PMutexGet (&glBufferManager.lock, CYU3P_NO_WAIT);
    }

    if (status != CY_U3P_SUCCESS)
    {
        return;
    }

    /* Free memory and zero out variables. */
    CyU3PMemFree (glBufferManager.usedStatus);
    glBufferManager.usedStatus = 0;
    glBufferManager.startAddr  = 0;
    glBufferManager.regionSize = 0;
    glBufferManager.statusSize = 0;

    /* Free up and destroy the mutex variable. */
    CyU3PMutexPut (&glBufferManager.lock);
    CyU3PMutexDestroy (&glBufferManager.lock);
}
/* This function shall be invoked by the API library 
 * and should not be explicitly invoked.
 * If other buffer sizes are required by the application code, this function must
 * be modified to create other block pools.
 */
void
CyU3PDmaBufferInit (
        void)
{
    uint32_t status, size;
    uint32_t tmp;

    /* If buffer manager has already been initialized, just return. */
    if ((glBufferManager.startAddr != 0) && (glBufferManager.regionSize != 0))
    {
        return;
    }

    /* Create a mutex variable for safe allocation. */
    status = CyU3PMutexCreate (&glBufferManager.lock, CYU3P_NO_INHERIT);
    if (status != CY_U3P_SUCCESS)
    {
        return;
    }

    /* No threads are running at this point in time. There is no need to
       get the mutex. */

    /* Allocate the memory buffer to be used to track memory status.
       We need one bit per 32 bytes of memory buffer space. Since a 32
       bit array is being used, round up to the necessary number of
       32 bit words. */
    size = ((CY_U3P_BUFFER_HEAP_SIZE / 32) + 31) / 32;
    glBufferManager.usedStatus = (uint32_t *)CyU3PMemAlloc (size * 4);
    if (glBufferManager.usedStatus == 0)
    {
        CyU3PMutexDestroy (&glBufferManager.lock);
        return;
    }

    /* Initially mark all memory as available. If there are any status bits
       beyond the valid memory range, mark these as unavailable. */
    CyU3PMemSet ((uint8_t *)glBufferManager.usedStatus, 0, (size * 4));
    if ((CY_U3P_BUFFER_HEAP_SIZE / 32) & 31)
    {
        tmp = 32 - ((CY_U3P_BUFFER_HEAP_SIZE / 32) & 31);
        glBufferManager.usedStatus[size - 1] = ~((1 << tmp) - 1);
    }

    /* Initialize the start address and region size variables. */
    glBufferManager.startAddr  = CY_U3P_BUFFER_HEAP_BASE;
    glBufferManager.regionSize = CY_U3P_BUFFER_HEAP_SIZE;
    glBufferManager.statusSize = size;
    glBufferManager.searchPos  = 0;
}
Exemplo n.º 3
0
/* Function    : CyU3PDmaBufferDeInit
 * Description : This function frees up the custom heap used for DMA buffer allocation.
 *               The function should not be explicitly invoked, and is called from the 
 *               API library.
 * Parameters  : None
 */
void
CyU3PDmaBufferDeInit (
        void)
{
    uint32_t status;

    /* Get the mutex lock. */
    if (CyU3PThreadIdentify ())
    {
        status = CyU3PMutexGet (&glBufferManager.lock, CYU3P_WAIT_FOREVER);
    }
    else
    {
        status = CyU3PMutexGet (&glBufferManager.lock, CYU3P_NO_WAIT);
    }

    if (status != CY_U3P_SUCCESS)
    {
        return;
    }

    /* Free memory and zero out variables. */
    CyU3PMemFree (glBufferManager.usedStatus);
    glBufferManager.usedStatus = 0;
    glBufferManager.startAddr  = 0;
    glBufferManager.regionSize = 0;
    glBufferManager.statusSize = 0;

#ifdef CYFXTX_ERRORDETECTION
    /* Clear status tracking variables. */
    glBufAllocCnt  = 0;
    glBufFreeCnt   = 0;
    glBufInUseList = 0;
#endif

    /* Free up and destroy the mutex variable. */
    CyU3PMutexPut (&glBufferManager.lock);
    CyU3PMutexDestroy (&glBufferManager.lock);
}