📄 osal_memory.s51
字号:
// 55 #define OSALMEM_ALOC 'A'
// 56 #define OSALMEM_REIN 'F'
// 57 #endif
// 58
// 59 /*********************************************************************
// 60 * MACROS
// 61 */
// 62
// 63 /*
// 64 * The MAC_ASSERT macro is for use during debugging.
// 65 * The given expression must evaluate as "true" or else fatal error occurs.
// 66 * At that point, the call stack feature of the debugger can pinpoint where
// 67 * the problem occurred.
// 68 *
// 69 * To disable this feature and save code size, the project should define
// 70 * OSALMEM_NODEBUG to TRUE.
// 71 */
// 72 #if ( OSALMEM_NODEBUG )
// 73 #define OSALMEM_ASSERT( expr )
// 74 #define OSALMEM_DEBUG( statement )
// 75 #else
// 76 #define OSALMEM_ASSERT( expr) HAL_ASSERT( expr )
// 77 #define OSALMEM_DEBUG( statement) st( statement )
// 78 #endif
// 79
// 80 /*********************************************************************
// 81 * TYPEDEFS
// 82 */
// 83
// 84 typedef uint16 osalMemHdr_t;
// 85
// 86 /*********************************************************************
// 87 * CONSTANTS
// 88 */
// 89
// 90 #define OSALMEM_IN_USE 0x8000
// 91
// 92 /* This number sets the size of the small-block bucket. Although profiling
// 93 * shows max simultaneous alloc of 16x18, timing without profiling overhead
// 94 * shows that the best worst case is achieved with the following.
// 95 */
// 96 #define SMALLBLKHEAP 232
// 97
// 98 // To maintain data alignment of the pointer returned, reserve the greater
// 99 // space for the memory block header.
// 100 #define HDRSZ ( (sizeof ( halDataAlign_t ) > sizeof( osalMemHdr_t )) ? \
// 101 sizeof ( halDataAlign_t ) : sizeof( osalMemHdr_t ) )
// 102
// 103 /*********************************************************************
// 104 * GLOBAL VARIABLES
// 105 */
// 106
// 107 /*********************************************************************
// 108 * EXTERNAL VARIABLES
// 109 */
// 110
// 111 /*********************************************************************
// 112 * EXTERNAL FUNCTIONS
// 113 */
// 114
// 115 /*********************************************************************
// 116 * LOCAL VARIABLES
// 117 */
// 118
// 119 #if ( OSALMEM_GUARD )
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 120 static byte ready = 0;
??ready:
DS 1
// 121 #endif
// 122
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 123 static osalMemHdr_t *ff1; // First free block in the small-block bucket.
??ff1:
DS 2
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 124 static osalMemHdr_t *ff2; // First free block after the small-block bucket.
??ff2:
DS 2
// 125
// 126 #if ( OSALMEM_METRICS )
// 127 static uint16 blkMax; // Max cnt of all blocks ever seen at once.
// 128 static uint16 blkCnt; // Current cnt of all blocks.
// 129 static uint16 blkFree; // Current cnt of free blocks.
// 130 static uint16 memAlo; // Current total memory allocated.
// 131 static uint16 memMax; // Max total memory ever allocated at once.
// 132 #endif
// 133
// 134 #if ( OSALMEM_PROFILER )
// 135 #define OSALMEM_PROMAX 8
// 136 /* The profiling buckets must differ by at least OSALMEM_MIN_BLKSZ; the
// 137 * last bucket must equal the max alloc size. Set the bucket sizes to
// 138 * whatever sizes necessary to show how your application is using memory.
// 139 */
// 140 static uint16 proCnt[OSALMEM_PROMAX] = {
// 141 OSALMEM_SMALL_BLKSZ, 48, 112, 176, 192, 224, 256, 65535 };
// 142 static uint16 proCur[OSALMEM_PROMAX] = { 0 };
// 143 static uint16 proMax[OSALMEM_PROMAX] = { 0 };
// 144 static uint16 proTot[OSALMEM_PROMAX] = { 0 };
// 145 static uint16 proSmallBlkMiss;
// 146 #endif
// 147
// 148 // Memory Allocation Heap.
// 149 #if defined( EXTERNAL_RAM )
// 150 static byte *theHeap = (byte *)EXT_RAM_BEG;
// 151 #else
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 152 static halDataAlign_t _theHeap[ MAXMEMHEAP / sizeof( halDataAlign_t ) ];
??_theHeap:
DS 4096
RSEG XDATA_I:XDATA:NOROOT(0)
// 153 static byte *theHeap = (byte *)_theHeap;
??theHeap:
DS 2
REQUIRE `?<Initializer for theHeap>`
REQUIRE __INIT_XDATA_I
// 154 #endif
// 155
// 156 /*********************************************************************
// 157 * LOCAL FUNCTIONS
// 158 */
// 159
// 160 /*********************************************************************
// 161 * @fn osal_mem_init
// 162 *
// 163 * @brief Initialize the heap memory management system.
// 164 *
// 165 * @param void
// 166 *
// 167 * @return void
// 168 */
RSEG BANKED_CODE:CODE:NOROOT(0)
// 169 void osal_mem_init( void )
osal_mem_init:
CFI Block cfiBlock0 Using cfiCommon0
CFI Function osal_mem_init
// 170 {
FUNCALL osal_mem_init, osal_mem_alloc
LOCFRAME ISTACK, 2, STACK
ARGFRAME ISTACK, 2, STACK
PUSH DPL
CFI DPL0 Frame(CFA_SP, 4)
CFI CFA_SP SP+-4
PUSH DPH
CFI DPH0 Frame(CFA_SP, 5)
CFI CFA_SP SP+-5
; Saved register size: 2
; Auto size: 0
// 171 osalMemHdr_t *tmp;
// 172
// 173 #if ( OSALMEM_PROFILER )
// 174 osal_memset( theHeap, OSALMEM_INIT, MAXMEMHEAP );
// 175 #endif
// 176
// 177 // Setup a NULL block at the end of the heap for fast comparisons with zero.
// 178 tmp = (osalMemHdr_t *)theHeap + (MAXMEMHEAP / HDRSZ) - 1;
// 179 *tmp = 0;
MOV DPTR,#??theHeap
MOVX A,@DPTR
ADD A,#-0x2
MOV R0,A
INC DPTR
MOVX A,@DPTR
ADDC A,#0xf
MOV R1,A
MOV DPL,R0
MOV DPH,R1
CLR A
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
// 180
// 181 // Setup a small-block bucket.
// 182 tmp = (osalMemHdr_t *)theHeap;
// 183 *tmp = SMALLBLKHEAP;
MOV DPTR,#??theHeap
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
MOV DPH,A
MOV DPL,R0
MOV A,#-0x18
MOVX @DPTR,A
INC DPTR
CLR A
MOVX @DPTR,A
// 184
// 185 // Setup the wilderness.
// 186 tmp = (osalMemHdr_t *)theHeap + (SMALLBLKHEAP / HDRSZ);
MOV DPTR,#??theHeap
MOVX A,@DPTR
ADD A,#-0x18
MOV R0,A
INC DPTR
MOVX A,@DPTR
ADDC A,#0x0
MOV R1,A
// 187 *tmp = ((MAXMEMHEAP / HDRSZ) * HDRSZ) - SMALLBLKHEAP - HDRSZ;
MOV DPL,R0
MOV DPH,R1
MOV A,#0x16
MOVX @DPTR,A
INC DPTR
MOV A,#0xf
MOVX @DPTR,A
// 188
// 189 #if ( OSALMEM_GUARD )
// 190 ready = OSALMEM_READY;
MOV A,#-0x1e
MOV DPTR,#??ready
MOVX @DPTR,A
// 191 #endif
// 192
// 193 // Setup a NULL block that is never freed so that the small-block bucket
// 194 // is never coalesced with the wilderness.
// 195 ff1 = tmp;
MOV DPTR,#??ff1
MOV A,R0
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
// 196 ff2 = osal_mem_alloc( 0 );
; Setup parameters for call to function osal_mem_alloc
MOV R2,#0x0
MOV R3,#0x0
MOV DPTR,#(osal_mem_alloc & 0xffff)
MOV A,#((osal_mem_alloc >> 16) & 0xff)
LCALL ?BCALL ; Banked call to: DPTR()
MOV DPTR,#??ff2
MOV A,R2
MOVX @DPTR,A
INC DPTR
MOV A,R3
MOVX @DPTR,A
// 197 ff1 = (osalMemHdr_t *)theHeap;
MOV DPTR,#??theHeap
LCALL ?Subroutine0 & 0xFFFF
CFI EndBlock cfiBlock0
// 198
// 199 #if ( OSALMEM_METRICS )
// 200 /* Start with the small-block bucket and the wilderness - don't count the
// 201 * end-of-heap NULL block nor the end-of-small-block NULL block.
// 202 */
// 203 blkCnt = blkFree = 2;
// 204 #endif
// 205 }
??CrossCallReturnLabel_0:
REQUIRE ?Subroutine2
; // Fall through to label ?Subroutine2
RSEG BANKED_CODE:CODE:NOROOT(0)
?Subroutine2:
CFI Block cfiBlock1 Using cfiCommon0
CFI NoFunction
CFI CFA_SP SP+-5
CFI DPL0 Frame(CFA_SP, 4)
CFI DPH0 Frame(CFA_SP, 5)
POP DPH
CFI CFA_SP SP+-4
CFI DPH0 SameValue
POP DPL
CFI CFA_SP SP+-3
CFI DPL0 SameValue
LJMP ?BRET
CFI EndBlock cfiBlock1
// 206
// 207 /*********************************************************************
// 208 * @fn osal_mem_kick
// 209 *
// 210 * @brief Kick the ff1 pointer out past the long-lived OSAL Task blocks.
// 211 * Invoke this once after all long-lived blocks have been allocated -
// 212 * presently at the end of osal_init_system().
// 213 *
// 214 * @param void
// 215 *
// 216 * @return void
// 217 */
RSEG BANKED_CODE:CODE:NOROOT(0)
// 218 void osal_mem_kick( void )
osal_mem_kick:
CFI Block cfiBlock2 Using cfiCommon0
CFI Function osal_mem_kick
// 219 {
PUSH DPL
CFI DPL0 Frame(CFA_SP, 4)
CFI CFA_SP SP+-4
PUSH DPH
CFI DPH0 Frame(CFA_SP, 5)
CFI CFA_SP SP+-5
; Saved register size: 2
; Auto size: 0
// 220 halIntState_t intState;
// 221
// 222 HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
MOV C,0xa8.7
CLR A
MOV 0xE0 /* A */.0,C
CLR 0xa8.7
// 223
// 224 /* Logic in osal_mem_free() will ratchet ff1 back down to the first free
// 225 * block in the small-block bucket.
// 226 */
// 227 ff1 = ff2;
MOV DPTR,#??ff2
LCALL ?Subroutine0 & 0xFFFF
// 228
// 229 HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
??CrossCallReturnLabel_1:
MOV 0xa8.7,C
// 230 }
SJMP ?Subroutine2
CFI EndBlock cfiBlock2
RSEG BANKED_CODE:CODE:NOROOT(0)
?Subroutine0:
CFI Block cfiCond3 Using cfiCommon0
CFI NoFunction
CFI Conditional ??CrossCallReturnLabel_0
CFI DPL0 Frame(CFA_SP, 4)
CFI DPH0 Frame(CFA_SP, 5)
CFI CFA_SP SP+-5
CFI Block cfiCond4 Using cfiCommon0
CFI (cfiCond4) NoFunction
CFI (cfiCond4) Conditional ??CrossCallReturnLabel_1
CFI (cfiCond4) DPL0 Frame(CFA_SP, 4)
CFI (cfiCond4) DPH0 Frame(CFA_SP, 5)
CFI (cfiCond4) CFA_SP SP+-5
CFI Block cfiPicker5 Using cfiCommon1
CFI (cfiPicker5) NoFunction
CFI (cfiPicker5) Picker
LCALL ??Subroutine1_0 & 0xFFFF
??CrossCallReturnLabel_5:
MOV DPTR,#??ff1
MOV A,R0
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
RET
CFI EndBlock cfiCond3
CFI EndBlock cfiCond4
CFI EndBlock cfiPicker5
// 231
// 232 /*********************************************************************
// 233 * @fn osal_mem_alloc
// 234 *
// 235 * @brief Implementation of the allocator functionality.
// 236 *
// 237 * @param size - number of bytes to allocate from the heap.
// 238 *
// 239 * @return void * - pointer to the heap allocation; NULL if error or failure.
// 240 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -