/*
|
* sdram_hp.c
|
* Description:
|
*
|
* Created on: 2014-10-8
|
* Author: DELL
|
* Modify:
|
*/
|
#include <stdio.h>
|
#include <assert.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include "hmem.h"
|
|
//int _heap_install(void *base, size_t length, int userid, int pmdm /* -1 dm, 1 pm */);
|
|
#define BANKNUM 4
|
static const int banksize[BANKNUM] ={32*1024,0*1024,16*1024,1024*1024*8};
|
static const int bankbase[BANKNUM] ={0x000e0000, 0x000C7000, 0x000ba000, 0x00660000};
|
static const mymalloc_style banktype[BANKNUM] ={SRAM_DM,SRAM_DM,SRAM_PM,SRAM_DDR};
|
int memIndex[BANKNUM] ={0,0,0,0};
|
static unsigned short total_inner_mem = 0;//////////////////////////////////////
|
|
static uvoidptr memalloc(mymalloc_style type,int size)
|
{
|
int i;
|
uvoidptr ptr = NULL;
|
|
for(i =0 ;i<BANKNUM;i++) {
|
if(banktype[i] == type
|
&& memIndex[i]+size <= banksize[i]) {
|
ptr = (uvoidptr)(bankbase[i]+memIndex[i]);
|
memIndex[i] += size;
|
break;
|
}
|
}
|
return ptr;
|
}
|
|
uvoid hmem_init()
|
{
|
int i;/////////////////////////////////////////////////
|
|
memset(memIndex, 0, BANKNUM);
|
//////////////////////////////////////////////
|
for(i =0 ;i<BANKNUM-1;i++) {
|
total_inner_mem += banksize[i];
|
}
|
//////////////////////////////////////////////
|
}
|
|
uvoidptr mymalloc(mymalloc_style type, uint32_t size)
|
{
|
uvoidptr ptr = unull;
|
|
|
switch(type){
|
case SRAM_DM:
|
case SRAM_PM:
|
case SRAM_DDR:
|
ptr = memalloc(type , size);
|
break;
|
case SRAM_AUTO:
|
ptr = memalloc(SRAM_DM,size);
|
if(ptr == unull){
|
ptr = memalloc(SRAM_PM, size);
|
}
|
if(ptr == unull){
|
ptr = memalloc(SRAM_DDR, size);
|
}
|
break;
|
}
|
|
return ptr;
|
}
|
|
uvoid myfree(mymalloc_style type, uvoidptr ptr)
|
{
|
switch(type){
|
case SRAM_DM:
|
|
break;
|
case SRAM_PM:
|
|
break;
|
case SRAM_DDR:
|
break;
|
case SRAM_AUTO:
|
|
break;
|
}
|
}
|
|
short hmem_perused(mymalloc_style type)
|
{
|
unsigned short used =0;
|
//////////////////////////////////////////////////
|
float used_ratio = 0;
|
int i;
|
|
for(i =0 ;i<BANKNUM-1;i++) {
|
used += memIndex[i];
|
}
|
|
used_ratio = ((float)used)/((float)total_inner_mem);
|
used = used_ratio*10000;
|
/////////////////////////////////////////////////////
|
return used;
|
}
|
|
uvoid hmem_free()
|
{
|
memset(memIndex, 0, BANKNUM);
|
}
|
|
void* sram_malloc(int memtype , int size)
|
{
|
void* p = 0;
|
|
if(memtype == 2) {
|
p =mymalloc(SRAM_DDR, size);
|
}
|
else {
|
p = mymalloc(SRAM_AUTO, size);
|
}
|
|
return p;
|
}
|
|
void sram_free(int memtype ,void* ptr)
|
{
|
|
}
|
int sram_free_space(int memtype)
|
{
|
return 0;
|
}
|