IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit f61780d4 authored by Jim Lewis's avatar Jim Lewis
Browse files

Transfer of OSVVM utility library to IEEE Open Source servers

parent 9543dfaf
This diff is collapsed.
This diff is collapsed.
This is a local copy of the Apache License Version 2.0.
The original can be obtained here: [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
--------------------------------------------------------------------------------
# Apache License
Version 2.0, January 2004
## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
### 1. Definitions.
*"License"* shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
*"Licensor"* shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
*"Legal Entity"* shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
*"You"* (or *"Your"*) shall mean an individual or Legal Entity exercising permissions granted by this License.
*"Source"* form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
*"Object"* form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
*"Work"* shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
*"Derivative Works"* shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
*"Contribution"* shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, *"submitted"* means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as *"Not a Contribution."*
*"Contributor"* shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
### 2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
### 3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
### 4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
- You must give any other recipients of the Work or Derivative Works a copy of this License; and
- You must cause any modified files to carry prominent notices stating that You changed the files; and
- You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
- If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
### 5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
### 6. Trademarks.
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
### 7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
### 8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
### 9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
## Appendix: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--
-- File Name: MemoryPkg.vhd
-- Design Unit Name: MemoryPkg
-- Revision: STANDARD VERSION
--
-- Maintainer: Jim Lewis email: jim@synthworks.com
-- Contributor(s):
-- Jim Lewis email: jim@synthworks.com
--
-- Description
-- Package defines a protected type, MemoryPType, and methods
-- for efficiently implementing memory data structures
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Revision History:
-- Date Version Description
-- 05/2005 0.1 Initial revision
-- 06/2015 2015.06 Updated for Alerts, ...
-- Numerous revisions for VHDL Testbenches and Verification
-- 01/2016 2016.01 Update for buf.all(buf'left)
-- 11/2016 2016.11 Refinement to MemRead to return value, X (if X), U (if not initialized)
-- 01/2020 2020.01 Updated Licenses to Apache
--
--
-- This file is part of OSVVM.
--
-- Copyright (c) 2005 - 2020 by SynthWorks Design Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
use std.textio.all ;
library IEEE ;
use IEEE.std_logic_1164.all ;
use IEEE.numeric_std.all ;
use IEEE.numeric_std_unsigned.all ;
use IEEE.math_real.all ;
use work.TextUtilPkg.all ;
use work.TranscriptPkg.all ;
use work.AlertLogPkg.all ;
package MemoryPkg is
type MemoryPType is protected
------------------------------------------------------------
procedure MemInit ( AddrWidth, DataWidth : in integer ) ;
------------------------------------------------------------
procedure MemWrite ( Addr, Data : in std_logic_vector ) ;
------------------------------------------------------------
procedure MemRead (
Addr : in std_logic_vector ;
Data : out std_logic_vector
) ;
impure function MemRead ( Addr : std_logic_vector ) return std_logic_vector ;
------------------------------------------------------------
procedure MemErase ;
procedure deallocate ;
------------------------------------------------------------
procedure SetAlertLogID (A : AlertLogIDType) ;
procedure SetAlertLogID (Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) ;
impure function GetAlertLogID return AlertLogIDType ;
------------------------------------------------------------
procedure FileReadH ( -- Hexadecimal File Read
FileName : string ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) ;
procedure FileReadH (FileName : string ; StartAddr : std_logic_vector) ;
procedure FileReadH (FileName : string) ;
------------------------------------------------------------
procedure FileReadB ( -- Binary File Read
FileName : string ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) ;
procedure FileReadB (FileName : string ; StartAddr : std_logic_vector) ;
procedure FileReadB (FileName : string) ;
------------------------------------------------------------
procedure FileWriteH ( -- Hexadecimal File Write
FileName : string ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) ;
procedure FileWriteH (FileName : string ; StartAddr : std_logic_vector) ;
procedure FileWriteH (FileName : string) ;
------------------------------------------------------------
procedure FileWriteB ( -- Binary File Write
FileName : string ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) ;
procedure FileWriteB (FileName : string ; StartAddr : std_logic_vector) ;
procedure FileWriteB (FileName : string) ;
end protected MemoryPType ;
end MemoryPkg ;
package body MemoryPkg is
constant BLOCK_WIDTH : integer := 10 ;
type MemoryPType is protected body
type MemBlockType is array (integer range <>) of integer ;
type MemBlockPtrType is access MemBlockType ;
type MemArrayType is array (integer range <>) of MemBlockPtrType ;
type ArrayPtrVarType is access MemArrayType ;
variable ArrayPtrVar : ArrayPtrVarType := NULL ;
variable AddrWidthVar : integer := -1 ; -- set by MemInit - merges addr length and initialized checks.
variable DataWidthVar : natural := 1 ; -- set by MemInit
variable BlockkWidthVar : natural := 0 ; -- set by MemInit
variable AlertLogIDVar : AlertLogIDType := OSVVM_ALERTLOG_ID ;
type FileFormatType is (BINARY, HEX) ;
------------------------------------------------------------
procedure MemInit ( AddrWidth, DataWidth : In integer ) is
------------------------------------------------------------
begin
if AddrWidth <= 0 then
Alert(AlertLogIDVar, "MemoryPType.MemInit. AddrWidth = " & to_string(AddrWidth) & " must be > 0.", FAILURE) ;
return ;
end if ;
if DataWidth <= 0 then
Alert(AlertLogIDVar, "MemoryPType.MemInit. DataWidth = " & to_string(DataWidth) & " must be > 0.", FAILURE) ;
return ;
end if ;
AddrWidthVar := AddrWidth ;
DataWidthVar := DataWidth ;
BlockkWidthVar := minimum(BLOCK_WIDTH, AddrWidth) ;
ArrayPtrVar := new MemArrayType(0 to 2**(AddrWidth-BlockkWidthVar)-1) ;
end procedure MemInit ;
------------------------------------------------------------
procedure MemWrite ( Addr, Data : in std_logic_vector ) is
------------------------------------------------------------
variable BlockAddr, WordAddr : integer ;
alias aAddr : std_logic_vector (Addr'length-1 downto 0) is Addr ;
begin
-- Check Bounds of Address and if memory is initialized
if Addr'length /= AddrWidthVar then
if (ArrayPtrVar = NULL) then
Alert(AlertLogIDVar, "MemoryPType.MemWrite: Memory not initialized, Write Ignored.", FAILURE) ;
else
Alert(AlertLogIDVar, "MemoryPType.MemWrite: Addr'length: " & to_string(Addr'length) & " /= Memory Address Width: " & to_string(AddrWidthVar), FAILURE) ;
end if ;
return ;
end if ;
-- Check Bounds on Data
if Data'length /= DataWidthVar then
Alert(AlertLogIDVar, "MemoryPType.MemWrite: Data'length: " & to_string(Data'length) & " /= Memory Data Width: " & to_string(DataWidthVar), FAILURE) ;
return ;
end if ;
if is_X( Addr ) then
Alert(AlertLogIDVar, "MemoryPType.MemWrite: Address X, Write Ignored.") ;
return ;
end if ;
-- Slice out upper address to form block address
if aAddr'high >= BlockkWidthVar then
BlockAddr := to_integer(aAddr(aAddr'high downto BlockkWidthVar)) ;
else
BlockAddr := 0 ;
end if ;
-- If empty, allocate a memory block
if (ArrayPtrVar(BlockAddr) = NULL) then
ArrayPtrVar(BlockAddr) := new MemBlockType(0 to 2**BlockkWidthVar-1) ;
end if ;
-- Address of a word within a block
WordAddr := to_integer(aAddr(BlockkWidthVar -1 downto 0)) ;
-- Write to BlockAddr, WordAddr
if (Is_X(Data)) then
ArrayPtrVar(BlockAddr)(WordAddr) := -1 ;
else
ArrayPtrVar(BlockAddr)(WordAddr) := to_integer( Data ) ;
end if ;
end procedure MemWrite ;
------------------------------------------------------------
procedure MemRead (
------------------------------------------------------------
Addr : In std_logic_vector ;
Data : Out std_logic_vector
) is
variable BlockAddr, WordAddr : integer ;
alias aAddr : std_logic_vector (Addr'length-1 downto 0) is Addr ;
begin
-- Check Bounds of Address and if memory is initialized
if Addr'length /= AddrWidthVar then
if (ArrayPtrVar = NULL) then
Alert(AlertLogIDVar, "MemoryPType.MemRead: Memory not initialized. Returning U", FAILURE) ;
else
Alert(AlertLogIDVar, "MemoryPType.MemRead: Addr'length: " & to_string(Addr'length) & " /= Memory Address Width: " & to_string(AddrWidthVar), FAILURE) ;
end if ;
Data := (Data'range => 'U') ;
return ;
end if ;
-- Check Bounds on Data
if Data'length /= DataWidthVar then
Alert(AlertLogIDVar, "MemoryPType.MemRead: Data'length: " & to_string(Data'length) & " /= Memory Data Width: " & to_string(DataWidthVar), FAILURE) ;
Data := (Data'range => 'U') ;
return ;
end if ;
-- If Addr X, data = X
if is_X( aAddr ) then
Data := (Data'range => 'X') ;
return ;
end if ;
-- Slice out upper address to form block address
if aAddr'high >= BlockkWidthVar then
BlockAddr := to_integer(aAddr(aAddr'high downto BlockkWidthVar)) ;
else
BlockAddr := 0 ;
end if ;
-- Empty Block, return all U
if (ArrayPtrVar(BlockAddr) = NULL) then
Data := (Data'range => 'U') ;
return ;
end if ;
-- Address of a word within a block
WordAddr := to_integer(aAddr(BlockkWidthVar -1 downto 0)) ;
if ArrayPtrVar(BlockAddr)(WordAddr) >= 0 then
-- Get the Word from the Array
Data := to_slv(ArrayPtrVar(BlockAddr)(WordAddr), Data'length) ;
elsif ArrayPtrVar(BlockAddr)(WordAddr) = -1 then
-- X in Word, return all X
Data := (Data'range => 'X') ;
else
-- Location Uninitialized, return all X
Data := (Data'range => 'U') ;
end if ;
end procedure MemRead ;
------------------------------------------------------------
impure function MemRead ( Addr : std_logic_vector ) return std_logic_vector is
------------------------------------------------------------
variable BlockAddr, WordAddr : integer ;
alias aAddr : std_logic_vector (Addr'length-1 downto 0) is Addr ;
variable Data : std_logic_vector(DataWidthVar-1 downto 0) ;
begin
MemRead(Addr, Data) ;
return Data ;
end function MemRead ;
------------------------------------------------------------
procedure MemErase is
-- Deallocate the memory, but not the array of pointers
------------------------------------------------------------
begin
for BlockAddr in ArrayPtrVar'range loop
if (ArrayPtrVar(BlockAddr) /= NULL) then
deallocate (ArrayPtrVar(BlockAddr)) ;
end if ;
end loop ;
end procedure ;
------------------------------------------------------------
procedure deallocate is
-- Deallocate all allocated memory
------------------------------------------------------------
begin
MemErase ;
deallocate(ArrayPtrVar) ;
AddrWidthVar := -1 ;
DataWidthVar := 1 ;
BlockkWidthVar := 0 ;
end procedure ;
------------------------------------------------------------
procedure SetAlertLogID (A : AlertLogIDType) is
------------------------------------------------------------
begin
AlertLogIDVar := A ;
end procedure SetAlertLogID ;
------------------------------------------------------------
procedure SetAlertLogID(Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) is
------------------------------------------------------------
begin
AlertLogIDVar := GetAlertLogID(Name, ParentID, CreateHierarchy) ;
end procedure SetAlertLogID ;
------------------------------------------------------------
impure function GetAlertLogID return AlertLogIDType is
------------------------------------------------------------
begin
return AlertLogIDVar ;
end function GetAlertLogID ;
------------------------------------------------------------
-- PT Local
procedure FileReadX (
-- Hexadecimal or Binary File Read
------------------------------------------------------------
FileName : string ;
DataFormat : FileFormatType ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) is
-- Format:
-- @hh..h -- Address in hex
-- hhh_XX_ZZ -- data values in hex - space delimited
-- "--" or "//" -- comments
file MemFile : text open READ_MODE is FileName ;
variable Addr : std_logic_vector(AddrWidthVar - 1 downto 0) ;
variable SmallAddr : std_logic_vector(AddrWidthVar - 1 downto 0) ;
variable BigAddr : std_logic_vector(AddrWidthVar - 1 downto 0) ;
variable Data : std_logic_vector(DataWidthVar - 1 downto 0) ;
variable LineNum : natural ;
variable ItemNum : natural ;
variable AddrInc : std_logic_vector(AddrWidthVar - 1 downto 0) ;
variable buf : line ;
variable ReadValid : boolean ;
variable Empty : boolean ;
variable MultiLineComment : boolean ;
variable NextChar : character ;
variable StrLen : integer ;
begin
MultiLineComment := FALSE ;
if StartAddr'length /= AddrWidthVar and EndAddr'length /= AddrWidthVar then
if (ArrayPtrVar = NULL) then
Alert(AlertLogIDVar, "MemoryPType.FileReadX: Memory not initialized, FileRead Ignored.", FAILURE) ;
else
Alert(AlertLogIDVar, "MemoryPType.FileReadX: Addr'length: " & to_string(Addr'length) & " /= Memory Address Width: " & to_string(AddrWidthVar), FAILURE) ;
end if ;
return ;
end if ;
Addr := StartAddr ;
LineNum := 0 ;
if StartAddr <= EndAddr then
SmallAddr := StartAddr ;
BigAddr := EndAddr ;
AddrInc := (AddrWidthVar -1 downto 0 => '0') + 1 ;
else
SmallAddr := EndAddr ;
BigAddr := StartAddr ;
AddrInc := (others => '1') ; -- -1
end if;
ReadLineLoop : while not EndFile(MemFile) loop
ReadLine(MemFile, buf) ;
LineNum := LineNum + 1 ;
ItemNum := 0 ;
ItemLoop : loop
EmptyOrCommentLine(buf, Empty, MultiLineComment) ;
exit ItemLoop when Empty ;
ItemNum := ItemNum + 1 ;
NextChar := buf.all(buf'left) ;
if (NextChar = '@') then
-- Get Address
read(buf, NextChar) ;
ReadHexToken(buf, Addr, StrLen) ;
exit ReadLineLoop when AlertIf(AlertLogIDVar, StrLen = 0, "MemoryPType.FileReadX: Address length 0 on line: " & to_string(LineNum), FAILURE) ;
exit ItemLoop when AlertIf(AlertLogIDVar, Addr < SmallAddr,
"MemoryPType.FileReadX: Address in file: " & to_hstring(Addr) &
" < StartAddr: " & to_hstring(StartAddr) & " on line: " & to_string(LineNum)) ;
exit ItemLoop when AlertIf(AlertLogIDVar, Addr > BigAddr,
"MemoryPType.FileReadX: Address in file: " & to_hstring(Addr) &
" > EndAddr: " & to_hstring(BigAddr) & " on line: " & to_string(LineNum)) ;
elsif DataFormat = HEX and ishex(NextChar) then
-- Get Hex Data
ReadHexToken(buf, data, StrLen) ;
exit ReadLineLoop when AlertIfNot(AlertLogIDVar, StrLen > 0,
"MemoryPType.FileReadH: Error while reading data on line: " & to_string(LineNum) &
" Item number: " & to_string(ItemNum), FAILURE) ;
log("MemoryPType.FileReadX: MemWrite(Addr => " & to_hstring(Addr) & ", Data => " & to_hstring(Data) & ")", DEBUG) ;
MemWrite(Addr, data) ;
Addr := Addr + AddrInc ;
elsif DataFormat = BINARY and isstd_logic(NextChar) then
-- Get Binary Data
-- read(buf, data, ReadValid) ;
ReadBinaryToken(buf, data, StrLen) ;
-- exit ReadLineLoop when AlertIfNot(AlertLogIDVar, ReadValid,
exit ReadLineLoop when AlertIfNot(AlertLogIDVar, StrLen > 0,
"MemoryPType.FileReadB: Error while reading data on line: " & to_string(LineNum) &
" Item number: " & to_string(ItemNum), FAILURE) ;
log("MemoryPType.FileReadX: MemWrite(Addr => " & to_hstring(Addr) & ", Data => " & to_string(Data) & ")", DEBUG) ;
MemWrite(Addr, data) ;
Addr := Addr + AddrInc ;
else
-- Invalid Text, Issue Warning and skip it
Alert(AlertLogIDVar,
"MemoryPType.FileReadX: Invalid text on line: " & to_string(LineNum) &
" Item: " & to_string(ItemNum) & ". Skipping text: " & buf.all) ;
exit ItemLoop ;
end if ;
end loop ItemLoop ;
end loop ReadLineLoop ;
-- -- must read EndAddr-StartAddr number of words if both start and end specified
-- if (StartAddr /= 0 or (not EndAddr) /= 0) and (Addr /= EndAddr) then
-- Alert("MemoryPType.FileReadH: insufficient data values", WARNING) ;
-- end if ;
file_close(MemFile) ;
end FileReadX ;
------------------------------------------------------------
procedure FileReadH (
-- Hexadecimal File Read
------------------------------------------------------------
FileName : string ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) is
begin
FileReadX(FileName, HEX, StartAddr, EndAddr) ;
end FileReadH ;
------------------------------------------------------------
procedure FileReadH (FileName : string ; StartAddr : std_logic_vector) is
-- Hexadecimal File Read
------------------------------------------------------------
constant EndAddr : std_logic_vector(AddrWidthVar - 1 downto 0) := (others => '1') ;
begin
FileReadX(FileName, HEX, StartAddr, EndAddr) ;
end FileReadH ;
------------------------------------------------------------
procedure FileReadH (FileName : string) is
-- Hexadecimal File Read
------------------------------------------------------------
constant StartAddr : std_logic_vector(AddrWidthVar - 1 downto 0) := (others => '0') ;
constant EndAddr : std_logic_vector(AddrWidthVar - 1 downto 0) := (others => '1') ;
begin
FileReadX(FileName, HEX, StartAddr, EndAddr) ;
end FileReadH ;
------------------------------------------------------------
procedure FileReadB (
-- Binary File Read
------------------------------------------------------------
FileName : string ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) is
begin
FileReadX(FileName, BINARY, StartAddr, EndAddr) ;
end FileReadB ;
------------------------------------------------------------
procedure FileReadB (FileName : string ; StartAddr : std_logic_vector) is
-- Binary File Read
------------------------------------------------------------
constant EndAddr : std_logic_vector(AddrWidthVar - 1 downto 0) := (others => '1') ;
begin
FileReadX(FileName, BINARY, StartAddr, EndAddr) ;
end FileReadB ;
------------------------------------------------------------
procedure FileReadB (FileName : string) is
-- Binary File Read
------------------------------------------------------------
constant StartAddr : std_logic_vector(AddrWidthVar - 1 downto 0) := (others => '0') ;
constant EndAddr : std_logic_vector(AddrWidthVar - 1 downto 0) := (others => '1') ;
begin
FileReadX(FileName, BINARY, StartAddr, EndAddr) ;
end FileReadB ;
------------------------------------------------------------
-- PT Local
procedure FileWriteX (
-- Hexadecimal or Binary File Write
------------------------------------------------------------
FileName : string ;
DataFormat : FileFormatType ;
StartAddr : std_logic_vector ;
EndAddr : std_logic_vector
) is
-- Format:
-- @hh..h -- Address in hex
-- hhhhh -- data one per line in either hex or binary as specified
file MemFile : text open WRITE_MODE is FileName ;
alias normStartAddr : std_logic_vector(StartAddr'length-1 downto 0) is StartAddr ;
alias normEndAddr : std_logic_vector(EndAddr'length-1 downto 0) is EndAddr ;
variable StartBlockAddr : natural ;
variable EndBlockAddr : natural ;
variable StartWordAddr : natural ;
variable EndWordAddr : natural ;
variable Data : std_logic_vector(DataWidthVar - 1 downto 0) ;
variable FoundData : boolean ;
variable buf : line ;
begin
if StartAddr'length /= AddrWidthVar and EndAddr'length /= AddrWidthVar then
-- Check StartAddr and EndAddr Widths and Memory not initialized
if (ArrayPtrVar = NULL) then
Alert(AlertLogIDVar, "MemoryPType.FileWriteX: Memory not initialized, FileRead Ignored.", FAILURE) ;
else
AlertIf(AlertLogIDVar, StartAddr'length /= AddrWidthVar, "MemoryPType.FileWriteX: StartAddr'length: "