Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
5.7 KiB

  1. --
  2. -- File Name: MessagePkg.vhd
  3. -- Design Unit Name: MessagePkg
  4. -- Revision: STANDARD VERSION, revision 2015.01
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis SynthWorks
  9. --
  10. --
  11. -- Package Defines
  12. -- Data structure for multi-line name/message to be associated with a data structure.
  13. --
  14. -- Developed for:
  15. -- SynthWorks Design Inc.
  16. -- VHDL Training Classes
  17. -- 11898 SW 128th Ave. Tigard, Or 97223
  18. -- http://www.SynthWorks.com
  19. --
  20. -- Latest standard version available at:
  21. -- http://www.SynthWorks.com/downloads
  22. --
  23. -- Revision History:
  24. -- Date Version Description
  25. -- 06/2010: 0.1 Initial revision
  26. -- 07/2014: 2014.07 Moved specialization required by CoveragePkg to CoveragePkg
  27. -- 07/2014: 2014.07a Removed initialized pointers which can lead to memory leaks.
  28. -- 01/2015: 2015.01 Removed initialized parameter from Get
  29. --
  30. --
  31. -- Copyright (c) 2010 - 2015 by SynthWorks Design Inc. All rights reserved.
  32. --
  33. -- Verbatim copies of this source file may be used and
  34. -- distributed without restriction.
  35. --
  36. -- This source file is free software; you can redistribute it
  37. -- and/or modify it under the terms of the ARTISTIC License
  38. -- as published by The Perl Foundation; either version 2.0 of
  39. -- the License, or (at your option) any later version.
  40. --
  41. -- This source is distributed in the hope that it will be
  42. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  43. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  44. -- PURPOSE. See the Artistic License for details.
  45. --
  46. -- You should have received a copy of the license with this source.
  47. -- If not download it from,
  48. -- http://www.perlfoundation.org/artistic_license_2_0
  49. --
  50. use work.OsvvmGlobalPkg.all ;
  51. use work.AlertLogPkg.all ;
  52. library ieee ;
  53. use ieee.std_logic_1164.all ;
  54. use ieee.numeric_std.all ;
  55. use ieee.math_real.all ;
  56. use std.textio.all ;
  57. package MessagePkg is
  58. type MessagePType is protected
  59. procedure Set (MessageIn : String) ;
  60. impure function Get (ItemNumber : integer) return string ;
  61. impure function GetCount return integer ;
  62. impure function IsSet return boolean ;
  63. procedure Clear ; -- clear message
  64. procedure Deallocate ; -- clear message
  65. end protected MessagePType ;
  66. end package MessagePkg ;
  67. --- ///////////////////////////////////////////////////////////////////////////
  68. --- ///////////////////////////////////////////////////////////////////////////
  69. --- ///////////////////////////////////////////////////////////////////////////
  70. package body MessagePkg is
  71. -- Local Data Structure Types
  72. type LineArrayType is array (natural range <>) of line ;
  73. type LineArrayPtrType is access LineArrayType ;
  74. type MessagePType is protected body
  75. variable MessageCount : integer := 0 ;
  76. constant INITIAL_ITEM_COUNT : integer := 16 ;
  77. variable MaxMessageCount : integer := 0 ;
  78. variable MessagePtr : LineArrayPtrType ;
  79. ------------------------------------------------------------
  80. procedure Set (MessageIn : String) is
  81. ------------------------------------------------------------
  82. variable NamePtr : line ;
  83. variable OldMaxMessageCount : integer ;
  84. variable OldMessagePtr : LineArrayPtrType ;
  85. begin
  86. MessageCount := MessageCount + 1 ;
  87. if MessageCount > MaxMessageCount then
  88. OldMaxMessageCount := MaxMessageCount ;
  89. MaxMessageCount := MaxMessageCount + INITIAL_ITEM_COUNT ;
  90. OldMessagePtr := MessagePtr ;
  91. MessagePtr := new LineArrayType(1 to MaxMessageCount) ;
  92. for i in 1 to OldMaxMessageCount loop
  93. MessagePtr(i) := OldMessagePtr(i) ;
  94. end loop ;
  95. Deallocate( OldMessagePtr ) ;
  96. end if ;
  97. MessagePtr(MessageCount) := new string'(MessageIn) ;
  98. end procedure Set ;
  99. ------------------------------------------------------------
  100. impure function Get (ItemNumber : integer) return string is
  101. ------------------------------------------------------------
  102. begin
  103. if MessageCount > 0 then
  104. if ItemNumber >= 1 and ItemNumber <= MessageCount then
  105. return MessagePtr(ItemNumber).all ;
  106. else
  107. Alert(OSVVM_ALERTLOG_ID, "%% MessagePkg.Get input value out of range", FAILURE) ;
  108. return "" ; -- error if this happens
  109. end if ;
  110. else
  111. Alert(OSVVM_ALERTLOG_ID, "%% MessagePkg.Get message is not set", FAILURE) ;
  112. return "" ; -- error if this happens
  113. end if ;
  114. end function Get ;
  115. ------------------------------------------------------------
  116. impure function GetCount return integer is
  117. ------------------------------------------------------------
  118. begin
  119. return MessageCount ;
  120. end function GetCount ;
  121. ------------------------------------------------------------
  122. impure function IsSet return boolean is
  123. ------------------------------------------------------------
  124. begin
  125. return MessageCount > 0 ;
  126. end function IsSet ;
  127. ------------------------------------------------------------
  128. procedure Deallocate is -- clear message
  129. ------------------------------------------------------------
  130. variable CurPtr : LineArrayPtrType ;
  131. begin
  132. for i in 1 to MessageCount loop
  133. deallocate( MessagePtr(i) ) ;
  134. end loop ;
  135. MessageCount := 0 ;
  136. MaxMessageCount := 0 ;
  137. deallocate( MessagePtr ) ;
  138. end procedure Deallocate ;
  139. ------------------------------------------------------------
  140. procedure Clear is -- clear
  141. ------------------------------------------------------------
  142. begin
  143. Deallocate ;
  144. end procedure Clear ;
  145. end protected body MessagePType ;
  146. end package body MessagePkg ;