コード例 #1
0
ファイル: memPartLib.c プロジェクト: andy345/vxworks5
void *memPartAlloc 
    (
    FAST PART_ID partId,        /* memory partition to allocate from */
    unsigned nBytes             /* number of bytes to allocate */
    )
    {
    if (ID_IS_SHARED (partId))  /* partition is shared? */
        {
	if (smMemPartAllocRtn == NULL)
	    {
	    errno = S_smObjLib_NOT_INITIALIZED;
	    return (NULL);
	    }

        return ((void *) (*smMemPartAllocRtn) (SM_OBJ_ID_TO_ADRS (partId), 
					       nBytes));
	}

    /* partition is local */

    return (memPartAlignedAlloc (partId, nBytes, memDefaultAlignment));
    }
コード例 #2
0
ファイル: ossLib.c プロジェクト: andy345/vxworks5
void * ossPartMalloc 
    (
    UINT32 numBytes		    /* Size of buffer to allocate */
    )
    {
    void * pBfr;
    void * pMoreMemory;
    UINT32 growSize;

    /*  Create the USB memory partition from cache safe memory */ 

    if (ossPartInitFlag == TRUE)
	{

	/* on the first pass create 64k chunk of cache safe memory for usb */

	pUsbMemSpace = (char *) cacheDmaMalloc (usbMemPartSize);

	if (pUsbMemSpace == NULL)
	    {
	    printf ("ossLib.c: unable to allocate USB memory space.\n");
	    return NULL;
	    } 
	
	/* make this chunk a partition */
	
	usbMemPartId = memPartCreate (pUsbMemSpace, usbMemPartSize);
	
	if (usbMemPartId == NULL)
	    {
	    printf ("ossLib.c: unable to create USB memory partition.\n");
	    return NULL;
	    } 

	ossPartInitFlag = FALSE;

    	}

    /* 
     * If this call to ossMalloc is going to allocate more memory than is 
     * available in the partition, then grow the partition by 8k, or if
     * numBytes is larger than 4k, then grow the partition by numBytes + 4k.
     */

    if ((usbMemCount + numBytes) > (usbMemPartSize - 0x1000))
	{

	growSize = 0x2000;

	if (numBytes > 0x1000)
	    growSize += numBytes;

	pMoreMemory = cacheDmaMalloc (growSize);
	
	if (pMoreMemory == NULL)
	   {
	   printf ("ossLib.c: ossPartMalloc could not cacheDmaMalloc() new" \
		   " memory.\n");
	   return NULL;
	   }

	if (memPartAddToPool (usbMemPartId, pMoreMemory, growSize) == ERROR)
	   {
	   printf ("ossLib.c: ossPartMalloc could not add new memory to" \
		   " pool.\n");
	   return NULL;
	   }
	
	usbMemPartSize += growSize;	
	}

    /* From now on, use this partition for all USB mallocs */

    pBfr = memPartAlignedAlloc (usbMemPartId, 
				ROUND_UP(numBytes, _CACHE_ALIGN_SIZE), 
				_CACHE_ALIGN_SIZE);
	
    if (pBfr == NULL)
	{
	printf ("ossLib.c: unable to malloc USB memory.\n");
	return NULL;
	} 

    /* Update the amount of memory USB is currently using. */

    usbMemCount += ROUND_UP(numBytes, _CACHE_ALIGN_SIZE);

    return pBfr;

    }
コード例 #3
0
ファイル: memLib.c プロジェクト: rixrix/zafu
/*-------------------------------------------------------- */
void *
memalign(unsigned alignment, 
         unsigned size)
{
    return memPartAlignedAlloc(memSysPartId,size,alignment);
}