ACKSession allocACK(ushort session_id, int size) { MMU_Tab mmu = null; if (session_id > 0 && session_id < 32) { if (ACKSessionTab[session_id - 1].mmu != null) { freeACK(ACKSessionTab[session_id - 1]); } mmu = allocMemory(size); if (mmu == null) { API_LOG(serialDevice, ERROR_LOG, "there is not enough memory"); return(null); } else { ACKSessionTab[session_id - 1].mmu = mmu; return(ACKSessionTab[session_id - 1]); } } API_LOG(serialDevice, ERROR_LOG, "wrong Ack session ID: 0x{0:X}", session_id); return(null); }
void freeMemory(MMU_Tab mmu_tab) { if (mmu_tab == null) { return; } if (mmu_tab.tabIndex == 0 || mmu_tab.tabIndex == (MMU_TABLE_NUM - 1)) { return; } mmu_tab.usageFlag = false; }
/*! @note Alloc a cmd session for sending cmd data * when arg session_id = 0/1, it means select session 0/1 to send cmd * otherwise set arg session_id = CMD_SESSION_AUTO (32), which means auto * select a idle session id is between 2~31. */ CMDSession allocSession(ushort session_id, int size) { uint i; API_LOG(serialDevice, DEBUG_LOG, "Allocation size {0}", size); MMU_Tab mmu = null; if (session_id == 0 || session_id == 1) { if (CMDSessionTab[session_id].usageFlag == false) { i = session_id; } else { /* session is busy */ API_LOG(serialDevice, ERROR_LOG, "session {0} is busy", session_id); return(null); } } else { for (i = 2; i < SESSION_TABLE_NUM; i++) { if (CMDSessionTab[i].usageFlag == false) { break; } } } if (i < 32 && CMDSessionTab[i].usageFlag == false) { CMDSessionTab[i].usageFlag = true; mmu = allocMemory(size); if (mmu == null) { CMDSessionTab[i].usageFlag = false; } else { CMDSessionTab[i].mmu = mmu; return(CMDSessionTab[i]); } } return(null); }
void setupMMU() { for (int i = 0; i < MMU.Length; i++) { MMU[i] = new MMU_Tab(); } MMU[0].tabIndex = 0; MMU[0].usageFlag = true; MMU[0].pmem = (Ptr)memory; MMU[0].memSize = 0; for (var i = 1; i < (MMU_TABLE_NUM - 1); i++) { MMU[i].tabIndex = i; MMU[i].usageFlag = false; } MMU[MMU_TABLE_NUM - 1].tabIndex = MMU_TABLE_NUM - 1; MMU[MMU_TABLE_NUM - 1].usageFlag = true; MMU[MMU_TABLE_NUM - 1].pmem = (Ptr)memory + MEMORY_SIZE; MMU[MMU_TABLE_NUM - 1].memSize = 0; }