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.

349 lines
13 KiB

  1. --
  2. -- File Name: OsvvmGlobalPkg.vhd
  3. -- Design Unit Name: OsvvmGlobalPkg
  4. -- Revision: STANDARD VERSION, revision 2015.01
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis jim@synthworks.com
  9. --
  10. --
  11. -- Description:
  12. -- Global Settings for OSVVM packages
  13. --
  14. --
  15. -- Developed for:
  16. -- SynthWorks Design Inc.
  17. -- VHDL Training Classes
  18. -- 11898 SW 128th Ave. Tigard, Or 97223
  19. -- http://www.SynthWorks.com
  20. --
  21. -- Revision History:
  22. -- Date Version Description
  23. -- 01/2014: 2015.01 Initial revision
  24. --
  25. --
  26. -- Copyright (c) 2015 by SynthWorks Design Inc. All rights reserved.
  27. --
  28. -- Verbatim copies of this source file may be used and
  29. -- distributed without restriction.
  30. --
  31. -- This source file is free software; you can redistribute it
  32. -- and/or modify it under the terms of the ARTISTIC License
  33. -- as published by The Perl Foundation; either version 2.0 of
  34. -- the License, or (at your option) any later version.
  35. --
  36. -- This source is distributed in the hope that it will be
  37. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  38. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  39. -- PURPOSE. See the Artistic License for details.
  40. --
  41. -- You should have received a copy of the license with this source.
  42. -- If not download it from,
  43. -- http://www.perlfoundation.org/artistic_license_2_0
  44. --
  45. library ieee ;
  46. use std.textio.all ;
  47. use work.NamePkg.all ;
  48. package OsvvmGlobalPkg is
  49. -- FILE IO Global File Identifier -- Open using AlertLogPkg.TranscriptOpen
  50. -- file TranscriptFile : text ;
  51. -- Shared Options Type used in OSVVM
  52. type OsvvmOptionsType is (OPT_INIT_PARM_DETECT, OPT_USE_DEFAULT, DISABLED, FALSE, ENABLED, TRUE) ;
  53. function IsEnabled (A : OsvvmOptionsType) return boolean ; -- Requires that TRUE is last and ENABLED is 2nd to last
  54. function to_OsvvmOptionsType (A : boolean) return OsvvmOptionsType ;
  55. -- Defaults for String values
  56. constant OSVVM_DEFAULT_ALERT_PREFIX : string := "%% Alert" ;
  57. constant OSVVM_DEFAULT_LOG_PREFIX : string := "%% Log " ;
  58. constant OSVVM_DEFAULT_WRITE_PREFIX : string := "%% " ;
  59. constant OSVVM_DEFAULT_DONE_NAME : string := "DONE" ;
  60. constant OSVVM_DEFAULT_PASS_NAME : string := "PASSED" ;
  61. constant OSVVM_DEFAULT_FAIL_NAME : string := "FAILED" ;
  62. constant OSVVM_STRING_INIT_PARM_DETECT : string := NUL & NUL & NUL ;
  63. constant OSVVM_STRING_USE_DEFAULT : string := NUL & "" ;
  64. -- Coverage Settings
  65. constant OSVVM_DEFAULT_WRITE_PASS_FAIL : OsvvmOptionsType := FALSE ;
  66. constant OSVVM_DEFAULT_WRITE_BIN_INFO : OsvvmOptionsType := TRUE ;
  67. constant OSVVM_DEFAULT_WRITE_COUNT : OsvvmOptionsType := TRUE ;
  68. constant OSVVM_DEFAULT_WRITE_ANY_ILLEGAL : OsvvmOptionsType := FALSE ;
  69. ------------------------------------------------------------
  70. procedure SetOsvvmGlobalOptions (
  71. ------------------------------------------------------------
  72. WritePassFail : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  73. WriteBinInfo : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  74. WriteCount : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  75. WriteAnyIllegal : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  76. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  77. DoneName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  78. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  79. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  80. ) ;
  81. ------------------------------------------------------------
  82. -- Accessor Functions
  83. function ResolveOsvvmOption(A, B, C : OsvvmOptionsType) return OsvvmOptionsType ;
  84. function ResolveOsvvmOption(A, B, C, D : OsvvmOptionsType) return OsvvmOptionsType ;
  85. function IsOsvvmStringSet (A : string) return boolean ;
  86. function ResolveOsvvmOption(A, B : string) return string ;
  87. function ResolveOsvvmOption(A, B, C : string) return string ;
  88. function ResolveOsvvmOption(A, B, C, D : string) return string ;
  89. impure function ResolveOsvvmWritePrefix(A : String) return string ;
  90. impure function ResolveOsvvmWritePrefix(A, B : String) return string ;
  91. impure function ResolveOsvvmDoneName(A : String) return string ;
  92. impure function ResolveOsvvmDoneName(A, B : String) return string ;
  93. impure function ResolveOsvvmPassName(A : String) return string ;
  94. impure function ResolveOsvvmPassName(A, B : String) return string ;
  95. impure function ResolveOsvvmFailName(A : String) return string ;
  96. impure function ResolveOsvvmFailName(A, B : String) return string ;
  97. impure function ResolveCovWritePassFail(A, B : OsvvmOptionsType) return OsvvmOptionsType ; -- Cov
  98. impure function ResolveCovWriteBinInfo(A, B : OsvvmOptionsType) return OsvvmOptionsType ; -- Cov
  99. impure function ResolveCovWriteCount(A, B : OsvvmOptionsType) return OsvvmOptionsType ; -- Cov
  100. impure function ResolveCovWriteAnyIllegal(A, B : OsvvmOptionsType) return OsvvmOptionsType ; -- Cov
  101. procedure OsvvmDeallocate ;
  102. type OptionsPType is protected
  103. procedure Set (A: OsvvmOptionsType) ;
  104. impure function get return OsvvmOptionsType ;
  105. end protected OptionsPType ;
  106. end OsvvmGlobalPkg ;
  107. --- ///////////////////////////////////////////////////////////////////////////
  108. --- ///////////////////////////////////////////////////////////////////////////
  109. --- ///////////////////////////////////////////////////////////////////////////
  110. package body OsvvmGlobalPkg is
  111. type OptionsPType is protected body
  112. variable GlobalVar : OsvvmOptionsType ;
  113. procedure Set (A : OsvvmOptionsType) is
  114. begin
  115. GlobalVar := A ;
  116. end procedure Set ;
  117. impure function get return OsvvmOptionsType is
  118. begin
  119. return GlobalVar ;
  120. end function get ;
  121. end protected body OptionsPType ;
  122. shared variable WritePrefixVar : NamePType ;
  123. shared variable DoneNameVar : NamePType ;
  124. shared variable PassNameVar : NamePType ;
  125. shared variable FailNameVar : NamePType ;
  126. shared variable WritePassFailVar : OptionsPType ; -- := FALSE ;
  127. shared variable WriteBinInfoVar : OptionsPType ; -- := TRUE ;
  128. shared variable WriteCountVar : OptionsPType ; -- := TRUE ;
  129. shared variable WriteAnyIllegalVar : OptionsPType ; -- := FALSE ;
  130. function IsEnabled (A : OsvvmOptionsType) return boolean is
  131. begin
  132. return A >= ENABLED ;
  133. end function IsEnabled ;
  134. function to_OsvvmOptionsType (A : boolean) return OsvvmOptionsType is
  135. begin
  136. if A then
  137. return TRUE ;
  138. else
  139. return FALSE ;
  140. end if ;
  141. end function to_OsvvmOptionsType ;
  142. ------------------------------------------------------------
  143. procedure SetOsvvmGlobalOptions (
  144. ------------------------------------------------------------
  145. WritePassFail : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  146. WriteBinInfo : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  147. WriteCount : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  148. WriteAnyIllegal : OsvvmOptionsType := OPT_INIT_PARM_DETECT ;
  149. WritePrefix : string := OSVVM_STRING_INIT_PARM_DETECT ;
  150. DoneName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  151. PassName : string := OSVVM_STRING_INIT_PARM_DETECT ;
  152. FailName : string := OSVVM_STRING_INIT_PARM_DETECT
  153. ) is
  154. begin
  155. if WritePassFail /= OPT_INIT_PARM_DETECT then
  156. WritePassFailVar.Set(WritePassFail) ;
  157. end if ;
  158. if WriteBinInfo /= OPT_INIT_PARM_DETECT then
  159. WriteBinInfoVar.Set(WriteBinInfo) ;
  160. end if ;
  161. if WriteCount /= OPT_INIT_PARM_DETECT then
  162. WriteCountVar.Set(WriteCount) ;
  163. end if ;
  164. if WriteAnyIllegal /= OPT_INIT_PARM_DETECT then
  165. WriteAnyIllegalVar.Set(WriteAnyIllegal) ;
  166. end if ;
  167. if WritePrefix /= OSVVM_STRING_INIT_PARM_DETECT then
  168. WritePrefixVar.Set(WritePrefix) ;
  169. end if ;
  170. if DoneName /= OSVVM_STRING_INIT_PARM_DETECT then
  171. DoneNameVar.Set(DoneName) ;
  172. end if ;
  173. if PassName /= OSVVM_STRING_INIT_PARM_DETECT then
  174. PassNameVar.Set(PassName) ;
  175. end if ;
  176. if FailName /= OSVVM_STRING_INIT_PARM_DETECT then
  177. FailNameVar.Set(FailName) ;
  178. end if ;
  179. end procedure SetOsvvmGlobalOptions ;
  180. ------------------------------------------------------------
  181. -- Accessor Functions
  182. -- Local Function
  183. function IsOsvvmOptionSet (A : OsvvmOptionsType) return boolean is
  184. begin
  185. return A > OPT_USE_DEFAULT ;
  186. end function IsOsvvmOptionSet ;
  187. function ResolveOsvvmOption(A, B, C : OsvvmOptionsType) return OsvvmOptionsType is
  188. begin
  189. if IsOsvvmOptionSet(A) then
  190. return A ;
  191. elsif IsOsvvmOptionSet(B) then
  192. return B ;
  193. else
  194. return C ;
  195. end if ;
  196. end function ResolveOsvvmOption ;
  197. function ResolveOsvvmOption(A, B, C, D : OsvvmOptionsType) return OsvvmOptionsType is
  198. begin
  199. if IsOsvvmOptionSet(A) then
  200. return A ;
  201. elsif IsOsvvmOptionSet(B) then
  202. return B ;
  203. elsif IsOsvvmOptionSet(C) then
  204. return C ;
  205. else
  206. return D ;
  207. end if ;
  208. end function ResolveOsvvmOption ;
  209. -- Local Function
  210. function IsOsvvmStringSet (A : string) return boolean is
  211. begin
  212. if A'length = 0 then -- Null strings permitted
  213. return TRUE ;
  214. else
  215. return A(A'left) /= NUL ;
  216. end if;
  217. end function IsOsvvmStringSet ;
  218. function ResolveOsvvmOption(A, B : string) return string is
  219. begin
  220. if IsOsvvmStringSet(A) then
  221. return A ;
  222. else
  223. return B ;
  224. end if ;
  225. end function ResolveOsvvmOption ;
  226. function ResolveOsvvmOption(A, B, C : string) return string is
  227. begin
  228. if IsOsvvmStringSet(A) then
  229. return A ;
  230. elsif IsOsvvmStringSet(B) then
  231. return B ;
  232. else
  233. return C ;
  234. end if ;
  235. end function ResolveOsvvmOption ;
  236. function ResolveOsvvmOption(A, B, C, D : string) return string is
  237. begin
  238. if IsOsvvmStringSet(A) then
  239. return A ;
  240. elsif IsOsvvmStringSet(B) then
  241. return B ;
  242. elsif IsOsvvmStringSet(C) then
  243. return C ;
  244. else
  245. return D ;
  246. end if ;
  247. end function ResolveOsvvmOption ;
  248. impure function ResolveOsvvmWritePrefix(A : String) return string is
  249. begin
  250. return ResolveOsvvmOption(A, WritePrefixVar.GetOpt, OSVVM_DEFAULT_WRITE_PREFIX) ;
  251. end function ResolveOsvvmWritePrefix ;
  252. impure function ResolveOsvvmWritePrefix(A, B : String) return string is
  253. begin
  254. return ResolveOsvvmOption(A, B, WritePrefixVar.GetOpt, OSVVM_DEFAULT_WRITE_PREFIX) ;
  255. end function ResolveOsvvmWritePrefix ;
  256. impure function ResolveOsvvmDoneName(A : String) return string is
  257. begin
  258. return ResolveOsvvmOption(A, DoneNameVar.GetOpt, OSVVM_DEFAULT_DONE_NAME) ;
  259. end function ResolveOsvvmDoneName ;
  260. impure function ResolveOsvvmDoneName(A, B : String) return string is
  261. begin
  262. return ResolveOsvvmOption(A, DoneNameVar.GetOpt, OSVVM_DEFAULT_DONE_NAME) ;
  263. end function ResolveOsvvmDoneName ;
  264. impure function ResolveOsvvmPassName(A : String) return string is
  265. begin
  266. return ResolveOsvvmOption(A, PassNameVar.GetOpt, OSVVM_DEFAULT_PASS_NAME) ;
  267. end function ResolveOsvvmPassName ;
  268. impure function ResolveOsvvmPassName(A, B : String) return string is
  269. begin
  270. return ResolveOsvvmOption(A, B, PassNameVar.GetOpt, OSVVM_DEFAULT_PASS_NAME) ;
  271. end function ResolveOsvvmPassName ;
  272. impure function ResolveOsvvmFailName(A : String) return string is
  273. begin
  274. return ResolveOsvvmOption(A, FailNameVar.GetOpt, OSVVM_DEFAULT_FAIL_NAME) ;
  275. end function ResolveOsvvmFailName ;
  276. impure function ResolveOsvvmFailName(A, B : String) return string is
  277. begin
  278. return ResolveOsvvmOption(A, B, FailNameVar.GetOpt, OSVVM_DEFAULT_FAIL_NAME) ;
  279. end function ResolveOsvvmFailName ;
  280. impure function ResolveCovWritePassFail(A, B : OsvvmOptionsType) return OsvvmOptionsType is
  281. begin
  282. return ResolveOsvvmOption(A, B, WritePassFailVar.Get, OSVVM_DEFAULT_WRITE_PASS_FAIL) ;
  283. end function ResolveCovWritePassFail ; -- Cov
  284. impure function ResolveCovWriteBinInfo(A, B : OsvvmOptionsType) return OsvvmOptionsType is
  285. begin
  286. return ResolveOsvvmOption(A, B, WriteBinInfoVar.Get, OSVVM_DEFAULT_WRITE_BIN_INFO) ;
  287. end function ResolveCovWriteBinInfo ; -- Cov
  288. impure function ResolveCovWriteCount(A, B : OsvvmOptionsType) return OsvvmOptionsType is
  289. begin
  290. return ResolveOsvvmOption(A, B, WriteCountVar.Get, OSVVM_DEFAULT_WRITE_COUNT) ;
  291. end function ResolveCovWriteCount ; -- Cov
  292. impure function ResolveCovWriteAnyIllegal(A, B : OsvvmOptionsType) return OsvvmOptionsType is
  293. begin
  294. return ResolveOsvvmOption(A, B, WriteAnyIllegalVar.Get, OSVVM_DEFAULT_WRITE_ANY_ILLEGAL) ;
  295. end function ResolveCovWriteAnyIllegal ; -- Cov
  296. procedure OsvvmDeallocate is
  297. begin
  298. -- Free up space used by NamePType within OsvvmGlobalPkg
  299. WritePrefixVar.Deallocate ;
  300. DoneNameVar.Deallocate ;
  301. PassNameVar.Deallocate ;
  302. FailNameVar.Deallocate ;
  303. WritePassFailVar.Set(FALSE) ; -- := FALSE ;
  304. WriteBinInfoVar.Set(TRUE ) ; -- := TRUE ;
  305. WriteCountVar.Set(TRUE ) ; -- := TRUE ;
  306. WriteAnyIllegalVar.Set(FALSE) ; -- := FALSE ;
  307. end procedure OsvvmDeallocate ;
  308. end package body OsvvmGlobalPkg ;