qipp
2025-09-16 e7ac407a6aa40e94a34a772dee14e8d5fb55c45b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * 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;    
}