DM365 CMEM分配内存

 
#define ALIGN(x, y)          (((x + (y-1))/y)*y)     // 内存对齐数,不设可分配任意大小
struct buf_info {
    void *user_addr;
    unsigned long phy_addr;
};
struct buf_info dhavbuffer;
static int allocate_dhavbuffer(int size)  
{
    CMEM_AllocParams  alloc_params;

    alloc_params.type   = CMEM_POOL;
    alloc_params.flags   = CMEM_NONCACHED;
    alloc_params.alignment  = 32;

 if(size > 0 ){
  printf("Allocating input buffer :buf size = %d \n", size);
     dhavbuffer.user_addr = CMEM_alloc(ALIGN(size,4096), &alloc_params);
     if (dhavbuffer.user_addr) {
         dhavbuffer.phy_addr = CMEM_getPhys(dhavbuffer.user_addr);
         if (0 == dhavbuffer.phy_addr) {
             printf("Failed to get phy cmem buffer address\n");
             return -1;
         }
     } else {
         printf("Failed to allocate cmem buffer\n");
         return -1;
     }
     printf("Got %p from CMEM, phy = %p\n", dhavbuffer.user_addr, (void *)dhavbuffer.phy_addr);
 }

    return 1;
}
 

你可能感兴趣的:(struct,user,buffer,input)