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.

199 lines
7.5 KiB

  1. --
  2. -- File Name: TranscriptPkg.vhd
  3. -- Design Unit Name: TranscriptPkg
  4. -- Revision: STANDARD VERSION
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis jim@synthworks.com
  9. --
  10. --
  11. -- Description:
  12. -- Define file identifier TranscriptFile
  13. -- provide subprograms to open, close, and print to it.
  14. --
  15. --
  16. -- Developed for:
  17. -- SynthWorks Design Inc.
  18. -- VHDL Training Classes
  19. -- 11898 SW 128th Ave. Tigard, Or 97223
  20. -- http://www.SynthWorks.com
  21. --
  22. -- Revision History:
  23. -- Date Version Description
  24. -- 01/2015: 2015.01 Initial revision
  25. -- 01/2016: 2016.01 TranscriptOpen function now calls procedure of same name
  26. -- 11/2016: 2016.l1 Added procedure BlankLine
  27. --
  28. --
  29. -- Copyright (c) 2015-2016 by SynthWorks Design Inc. All rights reserved.
  30. --
  31. -- Verbatim copies of this source file may be used and
  32. -- distributed without restriction.
  33. --
  34. -- This source file is free software; you can redistribute it
  35. -- and/or modify it under the terms of the ARTISTIC License
  36. -- as published by The Perl Foundation; either version 2.0 of
  37. -- the License, or (at your option) any later version.
  38. --
  39. -- This source is distributed in the hope that it will be
  40. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  41. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  42. -- PURPOSE. See the Artistic License for details.
  43. --
  44. -- You should have received a copy of the license with this source.
  45. -- If not download it from,
  46. -- http://www.perlfoundation.org/artistic_license_2_0
  47. --
  48. use std.textio.all ;
  49. package TranscriptPkg is
  50. -- File Identifier to facilitate usage of one transcript file
  51. file TranscriptFile : text ;
  52. -- Cause compile errors if READ_MODE is passed to TranscriptOpen
  53. subtype WRITE_APPEND_OPEN_KIND is FILE_OPEN_KIND range WRITE_MODE to APPEND_MODE ;
  54. -- Open and close TranscriptFile. Function allows declarative opens
  55. procedure TranscriptOpen (Status: out FILE_OPEN_STATUS; ExternalName: STRING; OpenKind: WRITE_APPEND_OPEN_KIND := WRITE_MODE) ;
  56. procedure TranscriptOpen (ExternalName: STRING; OpenKind: WRITE_APPEND_OPEN_KIND := WRITE_MODE) ;
  57. impure function TranscriptOpen (ExternalName: STRING; OpenKind: WRITE_APPEND_OPEN_KIND := WRITE_MODE) return FILE_OPEN_STATUS ;
  58. procedure TranscriptClose ;
  59. impure function IsTranscriptOpen return boolean ;
  60. alias IsTranscriptEnabled is IsTranscriptOpen [return boolean] ;
  61. -- Mirroring. When using TranscriptPkw WriteLine and Print, uses both TranscriptFile and OUTPUT
  62. procedure SetTranscriptMirror (A : boolean := TRUE) ;
  63. impure function IsTranscriptMirrored return boolean ;
  64. alias GetTranscriptMirror is IsTranscriptMirrored [return boolean] ;
  65. -- Write to TranscriptFile when open. Write to OUTPUT when not open or IsTranscriptMirrored
  66. procedure WriteLine(buf : inout line) ;
  67. procedure Print(s : string) ;
  68. -- Create "count" number of blank lines
  69. procedure BlankLine (count : integer := 1) ;
  70. end TranscriptPkg ;
  71. --- ///////////////////////////////////////////////////////////////////////////
  72. --- ///////////////////////////////////////////////////////////////////////////
  73. --- ///////////////////////////////////////////////////////////////////////////
  74. package body TranscriptPkg is
  75. ------------------------------------------------------------
  76. type LocalBooleanPType is protected
  77. procedure Set (A : boolean) ;
  78. impure function get return boolean ;
  79. end protected LocalBooleanPType ;
  80. type LocalBooleanPType is protected body
  81. variable GlobalVar : boolean := FALSE ;
  82. procedure Set (A : boolean) is
  83. begin
  84. GlobalVar := A ;
  85. end procedure Set ;
  86. impure function get return boolean is
  87. begin
  88. return GlobalVar ;
  89. end function get ;
  90. end protected body LocalBooleanPType ;
  91. ------------------------------------------------------------
  92. shared variable TranscriptEnable : LocalBooleanPType ;
  93. shared variable TranscriptMirror : LocalBooleanPType ;
  94. ------------------------------------------------------------
  95. procedure TranscriptOpen (Status: out FILE_OPEN_STATUS; ExternalName: STRING; OpenKind: WRITE_APPEND_OPEN_KIND := WRITE_MODE) is
  96. ------------------------------------------------------------
  97. begin
  98. file_open(Status, TranscriptFile, ExternalName, OpenKind) ;
  99. if Status = OPEN_OK then
  100. TranscriptEnable.Set(TRUE) ;
  101. end if ;
  102. end procedure TranscriptOpen ;
  103. ------------------------------------------------------------
  104. procedure TranscriptOpen (ExternalName: STRING; OpenKind: WRITE_APPEND_OPEN_KIND := WRITE_MODE) is
  105. ------------------------------------------------------------
  106. variable Status : FILE_OPEN_STATUS ;
  107. begin
  108. TranscriptOpen(Status, ExternalName, OpenKind) ;
  109. if Status /= OPEN_OK then
  110. report "TranscriptPkg.TranscriptOpen file: " &
  111. ExternalName & " status is: " & to_string(status) & " and is not OPEN_OK" severity FAILURE ;
  112. end if ;
  113. end procedure TranscriptOpen ;
  114. ------------------------------------------------------------
  115. impure function TranscriptOpen (ExternalName: STRING; OpenKind: WRITE_APPEND_OPEN_KIND := WRITE_MODE) return FILE_OPEN_STATUS is
  116. ------------------------------------------------------------
  117. variable Status : FILE_OPEN_STATUS ;
  118. begin
  119. TranscriptOpen(Status, ExternalName, OpenKind) ;
  120. return Status ;
  121. end function TranscriptOpen ;
  122. ------------------------------------------------------------
  123. procedure TranscriptClose is
  124. ------------------------------------------------------------
  125. begin
  126. if TranscriptEnable.Get then
  127. file_close(TranscriptFile) ;
  128. end if ;
  129. TranscriptEnable.Set(FALSE) ;
  130. end procedure TranscriptClose ;
  131. ------------------------------------------------------------
  132. impure function IsTranscriptOpen return boolean is
  133. ------------------------------------------------------------
  134. begin
  135. return TranscriptEnable.Get ;
  136. end function IsTranscriptOpen ;
  137. ------------------------------------------------------------
  138. procedure SetTranscriptMirror (A : boolean := TRUE) is
  139. ------------------------------------------------------------
  140. begin
  141. TranscriptMirror.Set(A) ;
  142. end procedure SetTranscriptMirror ;
  143. ------------------------------------------------------------
  144. impure function IsTranscriptMirrored return boolean is
  145. ------------------------------------------------------------
  146. begin
  147. return TranscriptMirror.Get ;
  148. end function IsTranscriptMirrored ;
  149. ------------------------------------------------------------
  150. procedure WriteLine(buf : inout line) is
  151. ------------------------------------------------------------
  152. begin
  153. if not TranscriptEnable.Get then
  154. WriteLine(OUTPUT, buf) ;
  155. elsif TranscriptMirror.Get then
  156. TEE(TranscriptFile, buf) ;
  157. else
  158. WriteLine(TranscriptFile, buf) ;
  159. end if ;
  160. end procedure WriteLine ;
  161. ------------------------------------------------------------
  162. procedure Print(s : string) is
  163. ------------------------------------------------------------
  164. variable buf : line ;
  165. begin
  166. write(buf, s) ;
  167. WriteLine(buf) ;
  168. end procedure Print ;
  169. ------------------------------------------------------------
  170. procedure BlankLine (count : integer := 1) is
  171. ------------------------------------------------------------
  172. begin
  173. for i in 1 to count loop
  174. print("") ;
  175. end loop ;
  176. end procedure Blankline ;
  177. end package body TranscriptPkg ;