/* 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);
}
Exemplo n.º 2
0
/* Function     : CyU3PMemAlloc
 * Description  : This function allocates memory required for various OS objects in the
 *                firmware application. This function is used by the SDK internal drivers
 *                in addition to the application code itself.
 *                The default implementation makes use of the ThreadX byte pool services.
 *                If memory leak and corruption checking is enabled, the implementation
 *                adds a 20 byte header and a 4 byte footer around the memory block.
 * Parameters   :
 *                size : Size of memory required in bytes.
 * Return Value : Pointer to the allocated memory block.
 */
void *
CyU3PMemAlloc (
        uint32_t size)
{
    void         *ret_p;
    uint32_t      status;

#ifdef CYFXTX_ERRORDETECTION
    MemBlockInfo *block_p;
#endif

    /* Round size up to a multiple of 4 bytes. */
    size = ROUND_UP (size, 4);

#ifdef CYFXTX_ERRORDETECTION
    /* If memory checks are enabled, add memory for the header and footer. */
    if (glMemEnableChecks)
        size += sizeof (MemBlockInfo) + sizeof (uint32_t);
#endif

    /* Cannot wait in interrupt context */
    if (CyU3PThreadIdentify ())
    {
        status = CyU3PByteAlloc (&glMemBytePool, (void **)&ret_p, size, CY_U3P_MEM_ALLOC_TIMEOUT);
    }
    else
    {
        status = CyU3PByteAlloc (&glMemBytePool, (void **)&ret_p, size, CYU3P_NO_WAIT);
    }

    if (status == CY_U3P_SUCCESS)
    {
#ifdef CYFXTX_ERRORDETECTION
        if (glMemEnableChecks)
        {
            /* Store the header information used for leak and corruption checks. */
            block_p = (MemBlockInfo *)ret_p;
            block_p->alloc_id        = glMemAllocCnt++;
            block_p->alloc_size      = size;
            block_p->prev_blk        = glMemInUseList;
            block_p->next_blk        = 0;
            block_p->start_sig       = CY_U3P_MEM_START_SIG;
            if (glMemInUseList != 0)
                glMemInUseList->next_blk = block_p;
            glMemInUseList           = block_p;

            /* Add the end block signature as a footer. */
            ((uint32_t *)block_p)[BYTE_TO_DWORD (size) - 1] = CY_U3P_MEM_END_SIG;

            /* Update the return pointer to skip the header created. */
            ret_p = (void *)((uint8_t *)block_p + sizeof (MemBlockInfo));
        }
#endif

        return ret_p;
    }

    return (NULL);
}
Exemplo n.º 3
0
void *CyU3PMemAlloc(uint32_t size) {
	void *ret_p;
	uint32_t status;

	// Cannot wait in interrupt context
	if (CyU3PThreadIdentify()) {
		status = CyU3PByteAlloc(&glMemBytePool, (void **)&ret_p, size, CY_U3P_MEM_ALLOC_TIMEOUT);
	} else {
		status = CyU3PByteAlloc(&glMemBytePool, (void **)&ret_p, size, CYU3P_NO_WAIT);
	}

	if (status == CY_U3P_SUCCESS) {
		return ret_p;
	}

	return (NULL);
}
Exemplo n.º 4
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);
}