?? memorylib.vhd
字號:
if (ins_pnt.endAddr - prev_pnt.endAddr = 1) then
insdel_num:= 1;
exit;
else
mypointer:= ins_pnt;
ins_pnt:= null;
mydata:= FF;
myadd:= myadd - 1;
insdel_num:= 2;
end if;
end if;
end loop;
end;
---------------------------------------------------------------------
-------- Insert a cell in the tail of the memory list -------------
---------------------------------------------------------------------
procedure AddCellToTail(variable tail: inout cell_pointer; variable data: in DataMem_type; variable insdel_num: inout integer) is
variable pnt: cell_pointer;
begin
pnt:= new memory_cell;
pnt.endAddr:= Last_Addr;
pnt.value:= data;
pnt.prev:= tail;
tail.nexto:= pnt;
tail:= pnt;
insdel_num:= 1;
end;
---------------------------------------------------------------
------------ Error Message during Add operation -------------
---------------------------------------------------------------
procedure AddressError is
begin
assert (false) report "The specified address is out of the memory range" severity note;
end;
---------------------------------------------------------------
----------- Error Message in writing operation --------------
---------------------------------------------------------------
procedure WriteError is
begin
assert (false) report "The specified location is not empty. It is not possible writing on it."
severity note;
end;
----------------------------------------------------------------
----------- Add a cell to the head of the memory list --------
----------------------------------------------------------------
procedure AddCellToHead(variable head: inout cell_pointer; variable add: in AddrMem_type; variable data: in DataMem_type; variable insdel_num: inout integer) is
variable pnt_one, pnt_two: cell_pointer;
begin
pnt_one:= new memory_cell;
pnt_one.endAddr:= add;
pnt_one.value:= data;
head.prev:= pnt_one;
if add /= 0 then
pnt_two:= new memory_cell;
pnt_one.prev:= pnt_two;
pnt_two.prev:= null;
pnt_two.nexto:= pnt_one;
pnt_one.nexto:= head;
head:= pnt_two;
head.value:= FF;
head.endAddr:= add - 1;
insdel_num:= 2;
else -- Write at the address 000000
pnt_one.prev:= null;
pnt_one.nexto:= head;
head:= pnt_one;
insdel_num:= 1;
end if;
end;
---------------------------------------------------------------
--------- Read the data in a memory cell --------------------
---------------------------------------------------------------
procedure getMemory(variable memory: in memory_rec; variable add: in AddrMem_type; variable data: out DataMem_type) is
variable pnt, pnt2, next_pnt: cell_pointer;
variable read_mode: modality;
variable writeError: boolean;
begin
pnt := memory.head;
pnt2:= memory.tail;
writeError:= false;
if add < 0 or add > Last_addr then AddressError;
elsif
add = pnt.endAddr then data:= pnt.value;
elsif
add < pnt.endAddr then data:= FF;
elsif
add = pnt2.endAddr then data:= pnt2.value;
else -- 0 < add < Last_Addr
read_mode:= reading;
SearchForRightPosition(memory.middle, pnt, next_pnt, add, read_mode, writeError);
if pnt /= null then data:= pnt.value;
else data:= FF;
end if;
end if;
end;
---------------------------------------------------------------
--------- Read a vector of data in the memory ----------------
---------------------------------------------------------------
procedure getMemoryBuffer(variable memory: in memory_rec; variable firstAdd: in AddrMem_type; variable numData: in natural; variable dataVector: out MemBuffer_type) is
variable pnt, pnt2, firstData_pnt, nextData_pnt, current_pnt: cell_pointer;
variable read_mode: modality;
variable writeError: boolean;
variable add : AddrMem_type;
variable index : natural;
begin
pnt := memory.head;
pnt2:= memory.tail;
writeError:= false;
nextData_pnt := null;
if firstAdd < 0 or firstAdd > Last_addr then AddressError;
--elsif firstAdd + numData > Memory_Dim - 1 then AddressError;
elsif firstAdd = pnt.endAddr then
firstData_pnt := pnt;
nextData_pnt := firstData_pnt.nexto;
elsif firstAdd = pnt2.endAddr then
firstData_pnt := pnt2;
nextData_pnt:= null; -- pnt2 point to the tail
elsif firstAdd < pnt.endAddr then
firstData_pnt := null;
nextData_pnt := pnt; -- head
else -- 0 < add < Last_Addr
read_mode:= reading;
SearchForRightPosition(memory.middle, firstData_pnt, nextData_pnt, firstAdd, read_mode, writeError);
end if;
add := firstAdd;
current_pnt:= firstData_pnt;
for index in 1 to numData loop
if current_pnt = null then
dataVector(index) := FF;
else -- current_pnt /= null
dataVector(index) := current_pnt.value;
end if;
if add + 1 > Memory_dim - 1 then
AddressError;
exit;
else
add := add + 1;
if nextData_pnt = null then exit;
elsif add < nextData_pnt.endAddr then current_pnt := null;
elsif add = nextData_pnt.endAddr then
current_pnt := nextData_pnt;
nextData_pnt := nextData_pnt.nexto;
else exit; -- add > nextData_pnt.endAddr => abbiamo finito !!!
end if;
end if;
end loop;
end;
---------------------------------------------------------------
------ Add or remove a cell to the memory list --------------
---------------------------------------------------------------
procedure putMemory(variable memory: inout memory_rec; variable add: in AddrMem_type; variable data: in DataMem_type) is
variable pointer: cell_pointer;
variable pnt, pnt2, nxpnt: cell_pointer;
variable mode: modality;
variable insdel_num: integer;
variable writeError: boolean; -- goes true if address is already in the list
begin
insdel_num:= 0;
pnt := memory.head;
pnt2:= memory.tail;
writeError:= false;
if (add > Last_Addr) or (add < 0) then AddressError;
else -- 0 <= add <= Last_Addr
if data = FF then
mode:= erasing;
-- if add < head.endAddr the cell is already to FF
if add = pnt.endAddr then
if pnt.value /= FF then EraseHead(memory.head, insdel_num);
end if;
elsif add = Last_Addr then EraseTail(memory.tail, insdel_num);
elsif add > pnt.endAddr then -- head.endAddr < add < Last_Addr
SearchForRightPosition(memory.middle, pointer, nxpnt, add, mode, writeError);
if pointer /= null then EraseCell(memory, pointer, insdel_num);
end if;
end if;
else -- data /= FF => mode = writing
mode:= writing;
--AddressInList(memory, add, addError);
if add = pnt.endAddr then
if pnt.value /= FF then pnt.value:= data; --WriteError;
else
if add = 0 then pnt.value:= data;
else
pnt.endAddr:= pnt.endAddr - 1;
InsertCell(pnt.nexto, add, data, insdel_num);
end if;
end if;
elsif add < pnt.endAddr then AddCellToHead(memory.head, add, data, insdel_num);
elsif add = Last_addr then
if pnt2.value /= FF then pnt2.value:= data; --WriteError;
else
pnt2.endAddr:= pnt2.endAddr - 1;
AddCellToTail(memory.tail, data, insdel_num);
end if;
else -- head.endAddr < add < Last_Addr
SearchForRightPosition(memory.middle, pointer, nxpnt, add, mode, writeError);
if writeError then pointer.value:= data; -- address is already written in the memory
else
if pointer /= null then InsertCell(pointer, add, data, insdel_num);
end if;
end if;
end if;
end if;
UpdateMiddle(memory, add, mode, insdel_num); -- Update the pointer to the middle of the list
end if;
end;
---------------------------------------------------------------------
---------------- Erase a cell in the memory list ------------------
---------------------------------------------------------------------
procedure EraseCell(variable memory: inout memory_rec; variable pointer: inout cell_pointer; variable insdel_num: inout integer) is
variable i: integer;
variable prev_pnt, next_pnt, other_pnt, double_prev: cell_pointer;
begin
-- erase the pointed cell and the previous cell only if its data is FF
prev_pnt:= pointer.prev;
next_pnt:= pointer.nexto;
double_prev := prev_pnt.prev;
if (prev_pnt.value = FF) and (next_pnt.value = FF) then -- remove prev and pointer
if (prev_pnt = memory.head) then
next_pnt.prev:= null;
pointer.nexto:= null;
pointer.prev:= null;
prev_pnt.nexto:= null;
memory.head:= next_pnt; -- change head
if (pointer = memory.middle) or (prev_pnt = memory.middle) then
memory.middle:= next_pnt;
if memory.bal_value = left then memory.bal_value := centre;
elsif memory.bal_value = centre then memory.bal_value := right;
end if;
end if;
else -- prev_pnt != head
other_pnt:= prev_pnt.prev;
other_pnt.nexto:= next_pnt;
next_pnt.prev:= other_pnt;
prev_pnt.prev:= null;
prev_pnt.nexto:= null;
pointer.nexto:= null;
pointer.prev:= null;
if (pointer = memory.middle) or (prev_pnt = memory.middle) then
memory.middle:= next_pnt;
if memory.bal_value = left then memory.bal_value := centre;
elsif memory.bal_value = centre then memory.bal_value := right;
end if;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -