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.

1574 lines
60 KiB

  1. --
  2. -- File Name: ScoreBoardGenericPkg.vhd
  3. -- Design Unit Name: ScoreBoardGenericPkg
  4. -- Revision: STANDARD VERSION
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis email: jim@synthworks.com
  9. --
  10. --
  11. -- Description:
  12. -- Defines types and methods to implement a FIFO based Scoreboard
  13. -- Defines type ScoreBoardPType
  14. -- Defines methods for putting values the scoreboard
  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. -- Latest standard version available at:
  23. -- http://www.SynthWorks.com/downloads
  24. --
  25. -- Revision History:
  26. -- Date Version Description
  27. -- 12/2006: 2006.12 Initial revision
  28. -- 08/2010 2010.08 Added Tailpointer
  29. -- 05/2012 2012.05 Changed FIFO to store pointers to ExpectedType
  30. -- Allows usage of unconstrained arrays
  31. -- 08/2012 2012.08 Added Type and Subprogram Generics
  32. -- 08/2013 2013.08 Generics: to_string replaced write, Match replaced check
  33. -- Added Tags - Experimental
  34. -- Added Array of Scoreboards
  35. -- 09/2013 2013.09 Added file handling, Check Count, Finish Status
  36. -- Find, Flush
  37. -- 06/2015 2015.06 Added Alerts, SetAlertLogID, Revised LocalPush, GetDropCount,
  38. -- Deprecated SetFinish and ReportMode - REPORT_NONE, FileOpen
  39. -- Deallocate, Initialized, Function SetName
  40. -- 11/2016 2016.11 Released as part of OSVVM
  41. -- 05/2017 2017.05 First print Actual then only print Expected if mis-match
  42. --
  43. --
  44. -- Copyright (c) 2006 - 2016 by SynthWorks Design Inc. All rights reserved.
  45. --
  46. -- Verbatim copies of this source file may be used and
  47. -- distributed without restriction.
  48. --
  49. -- This source file is free software; you can redistribute it
  50. -- and/or modify it under the terms of the ARTISTIC License
  51. -- as published by The Perl Foundation; either version 2.0 of
  52. -- the License, or (at your option) any later version.
  53. --
  54. -- This source is distributed in the hope that it will be
  55. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  56. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  57. -- PURPOSE. See the Artistic License for details.
  58. --
  59. -- You should have received a copy of the license with this source.
  60. -- If not download it from,
  61. -- http://www.perlfoundation.org/artistic_license_2_0
  62. --
  63. --
  64. use std.textio.all ;
  65. library ieee ;
  66. use ieee.std_logic_1164.all ;
  67. use ieee.numeric_std.all ;
  68. use work.TranscriptPkg.all ;
  69. use work.AlertLogPkg.all ;
  70. use work.NamePkg.all ;
  71. package ScoreboardGenericPkg is
  72. generic (
  73. type ExpectedType ;
  74. type ActualType ;
  75. function Match(Actual : ActualType ; -- defaults
  76. Expected : ExpectedType) return boolean ; -- is "=" ;
  77. function expected_to_string(A : ExpectedType) return string ; -- is to_string ;
  78. function actual_to_string (A : ActualType) return string -- is to_string ;
  79. ) ;
  80. -- -- For a VHDL-2002 package, comment out the generics and
  81. -- -- uncomment the following, it replaces a generic instance of the package.
  82. -- -- As a result, you will have multiple copies of the entire package.
  83. -- -- Inconvenient, but ok as it still works the same.
  84. -- subtype ExpectedType is std_logic_vector ;
  85. -- subtype ActualType is std_logic_vector ;
  86. -- alias Match is std_match [ActualType, ExpectedType return boolean] ; -- for std_logic_vector
  87. -- alias expected_to_string is to_hstring [ExpectedType return string]; -- VHDL-2008
  88. -- alias actual_to_string is to_hstring [ActualType return string]; -- VHDL-2008
  89. -- ScoreboardReportType is deprecated
  90. -- Replaced by Affirmations. ERROR is the default. ALL turns on PASSED flag
  91. type ScoreboardReportType is (REPORT_ERROR, REPORT_ALL, REPORT_NONE) ; -- replaced by affirmations
  92. type ScoreBoardPType is protected
  93. ------------------------------------------------------------
  94. -- Emulate arrays of scoreboards
  95. procedure SetArrayIndex(L, R : integer) ; -- supports integer indices
  96. procedure SetArrayIndex(R : natural) ; -- indicies 1 to R
  97. impure function GetArrayIndex return integer_vector ;
  98. impure function GetArrayLength return natural ;
  99. ------------------------------------------------------------
  100. -- Push items into the scoreboard/FIFO
  101. -- Simple Scoreboard, no tag
  102. procedure Push (Item : in ExpectedType) ;
  103. -- Simple Tagged Scoreboard
  104. procedure Push (
  105. constant Tag : in string ;
  106. constant Item : in ExpectedType
  107. ) ;
  108. -- Array of Scoreboards, no tag
  109. procedure Push (
  110. constant Index : in integer ;
  111. constant Item : in ExpectedType
  112. ) ;
  113. -- Array of Tagged Scoreboards
  114. procedure Push (
  115. constant Index : in integer ;
  116. constant Tag : in string ;
  117. constant Item : in ExpectedType
  118. ) ;
  119. -- ------------------------------------------------------------
  120. -- -- Push items into the scoreboard/FIFO
  121. -- -- Function form supports chaining of operations
  122. -- -- In 2013, this caused overloading issues in some simulators, will retest later
  123. --
  124. -- -- Simple Scoreboard, no tag
  125. -- impure function Push (Item : ExpectedType) return ExpectedType ;
  126. --
  127. -- -- Simple Tagged Scoreboard
  128. -- impure function Push (
  129. -- constant Tag : in string ;
  130. -- constant Item : in ExpectedType
  131. -- ) return ExpectedType ;
  132. --
  133. -- -- Array of Scoreboards, no tag
  134. -- impure function Push (
  135. -- constant Index : in integer ;
  136. -- constant Item : in ExpectedType
  137. -- ) return ExpectedType ;
  138. --
  139. -- -- Array of Tagged Scoreboards
  140. -- impure function Push (
  141. -- constant Index : in integer ;
  142. -- constant Tag : in string ;
  143. -- constant Item : in ExpectedType
  144. -- ) return ExpectedType ; -- for chaining of operations
  145. ------------------------------------------------------------
  146. -- Check received item with item in the scoreboard/FIFO
  147. -- Simple Scoreboard, no tag
  148. procedure Check (ActualData : ActualType) ;
  149. -- Simple Tagged Scoreboard
  150. procedure Check (
  151. constant Tag : in string ;
  152. constant ActualData : in ActualType
  153. ) ;
  154. -- Array of Scoreboards, no tag
  155. procedure Check (
  156. constant Index : in integer ;
  157. constant ActualData : in ActualType
  158. ) ;
  159. -- Array of Tagged Scoreboards
  160. procedure Check (
  161. constant Index : in integer ;
  162. constant Tag : in string ;
  163. constant ActualData : in ActualType
  164. ) ;
  165. ------------------------------------------------------------
  166. -- Pop the top item (FIFO) from the scoreboard/FIFO
  167. -- Simple Scoreboard, no tag
  168. procedure Pop (variable Item : out ExpectedType) ;
  169. -- Simple Tagged Scoreboard
  170. procedure Pop (
  171. constant Tag : in string ;
  172. variable Item : out ExpectedType
  173. ) ;
  174. -- Array of Scoreboards, no tag
  175. procedure Pop (
  176. constant Index : in integer ;
  177. variable Item : out ExpectedType
  178. ) ;
  179. -- Array of Tagged Scoreboards
  180. procedure Pop (
  181. constant Index : in integer ;
  182. constant Tag : in string ;
  183. variable Item : out ExpectedType
  184. ) ;
  185. -- ------------------------------------------------------------
  186. -- -- Pop the top item (FIFO) from the scoreboard/FIFO
  187. -- -- Function form supports chaining of operations
  188. -- -- In 2013, this caused overloading issues in some simulators, will retest later
  189. --
  190. -- -- Simple Scoreboard, no tag
  191. -- impure function Pop return ExpectedType ;
  192. --
  193. -- -- Simple Tagged Scoreboard
  194. -- impure function Pop (
  195. -- constant Tag : in string
  196. -- ) return ExpectedType ;
  197. --
  198. -- -- Array of Scoreboards, no tag
  199. -- impure function Pop (Index : integer) return ExpectedType ;
  200. --
  201. -- -- Array of Tagged Scoreboards
  202. -- impure function Pop (
  203. -- constant Index : in integer ;
  204. -- constant Tag : in string
  205. -- ) return ExpectedType ;
  206. ------------------------------------------------------------
  207. -- Empty - check to see if scoreboard is empty
  208. impure function Empty return boolean ; -- Simple
  209. impure function Empty (Tag : String) return boolean ; -- Simple, Tagged
  210. impure function Empty (Index : integer) return boolean ; -- Array
  211. impure function Empty (Index : integer; Tag : String) return boolean ; -- Array, Tagged
  212. ------------------------------------------------------------
  213. -- SetAlertLogID - associate an AlertLogID with a scoreboard to allow integrated error reporting
  214. procedure SetAlertLogID(Index : Integer ; Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) ;
  215. procedure SetAlertLogID(Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) ;
  216. -- Use when an AlertLogID is used by multiple items (Model or other Scoreboards). See also AlertLogPkg.GetAlertLogID
  217. procedure SetAlertLogID (Index : Integer ; A : AlertLogIDType) ;
  218. procedure SetAlertLogID (A : AlertLogIDType) ;
  219. impure function GetAlertLogID(Index : Integer) return AlertLogIDType ;
  220. impure function GetAlertLogID return AlertLogIDType ;
  221. ------------------------------------------------------------
  222. -- Set a scoreboard name.
  223. -- Used when scoreboard AlertLogID is shared between different sources.
  224. procedure SetName (Name : String) ;
  225. impure function SetName (Name : String) return string ;
  226. impure function GetName (DefaultName : string := "Scoreboard") return string ;
  227. ------------------------------------------------------------
  228. -- Scoreboard Introspection
  229. -- Number of items put into scoreboard
  230. impure function GetItemCount return integer ; -- Simple, with or without tags
  231. impure function GetItemCount (Index : integer) return integer ; -- Arrays, with or without tags
  232. -- Number of items checked by scoreboard
  233. impure function GetCheckCount return integer ; -- Simple, with or without tags
  234. impure function GetCheckCount (Index : integer) return integer ; -- Arrays, with or without tags
  235. -- Number of items dropped by scoreboard. See Find/Flush
  236. impure function GetDropCount return integer ; -- Simple, with or without tags
  237. impure function GetDropCount (Index : integer) return integer ; -- Arrays, with or without tags
  238. ------------------------------------------------------------
  239. -- Find - Returns the ItemNumber for a value and tag (if applicable) in a scoreboard.
  240. -- Find returns integer'left if no match found
  241. -- Also See Flush. Flush will drop items up through the ItemNumber
  242. -- Simple Scoreboard
  243. impure function Find (
  244. constant ActualData : in ActualType
  245. ) return integer ;
  246. -- Tagged Scoreboard
  247. impure function Find (
  248. constant Tag : in string;
  249. constant ActualData : in ActualType
  250. ) return integer ;
  251. -- Array of Simple Scoreboards
  252. impure function Find (
  253. constant Index : in integer ;
  254. constant ActualData : in ActualType
  255. ) return integer ;
  256. -- Array of Tagged Scoreboards
  257. impure function Find (
  258. constant Index : in integer ;
  259. constant Tag : in string;
  260. constant ActualData : in ActualType
  261. ) return integer ;
  262. ------------------------------------------------------------
  263. -- Flush - Remove elements in the scoreboard upto and including the one with ItemNumber
  264. -- See Find to identify an ItemNumber of a particular value and tag (if applicable)
  265. -- Simple Scoreboard
  266. procedure Flush (
  267. constant ItemNumber : in integer
  268. ) ;
  269. -- Tagged Scoreboard - only removes items that also match the tag
  270. procedure Flush (
  271. constant Tag : in string ;
  272. constant ItemNumber : in integer
  273. ) ;
  274. -- Array of Simple Scoreboards
  275. procedure Flush (
  276. constant Index : in integer ;
  277. constant ItemNumber : in integer
  278. ) ;
  279. -- Array of Tagged Scoreboards - only removes items that also match the tag
  280. procedure Flush (
  281. constant Index : in integer ;
  282. constant Tag : in string ;
  283. constant ItemNumber : in integer
  284. ) ;
  285. ------------------------------------------------------------
  286. -- Generally these are not required. When a simulation ends and
  287. -- another simulation is started, a simulator will release all allocated items.
  288. procedure Deallocate ; -- Deletes all allocated items
  289. procedure Initialize ; -- Creates initial data structure if it was destroyed with Deallocate
  290. ------------------------------------------------------------
  291. ------------------------------------------------------------
  292. -- Deprecated. Use alerts directly instead.
  293. -- AlertIF(SB.GetCheckCount < 10, ....) ;
  294. -- AlertIf(Not SB.Empty, ...) ;
  295. ------------------------------------------------------------
  296. -- Set alerts if scoreboard not empty or if CheckCount <
  297. -- Use if need to check empty or CheckCount for a specific scoreboard.
  298. -- Simple Scoreboards, with or without tag
  299. procedure CheckFinish (
  300. FinishCheckCount : integer ;
  301. FinishEmpty : boolean
  302. ) ;
  303. -- Array of Scoreboards, with or without tag
  304. procedure CheckFinish (
  305. Index : integer ;
  306. FinishCheckCount : integer ;
  307. FinishEmpty : boolean
  308. ) ;
  309. ------------------------------------------------------------
  310. -- Get error count
  311. -- Deprecated, replaced by usage of Alerts
  312. -- AlertFLow: Instead use AlertLogPkg.ReportAlerts or AlertLogPkg.GetAlertCount
  313. -- Not AlertFlow: use GetErrorCount to get total error count
  314. -- Simple Scoreboards, with or without tag
  315. impure function GetErrorCount return integer ;
  316. -- Array of Scoreboards, with or without tag
  317. impure function GetErrorCount(Index : integer) return integer ;
  318. ------------------------------------------------------------
  319. -- Error count manipulation
  320. -- IncErrorCount - not recommended, use alerts instead - may be deprecated in the future
  321. procedure IncErrorCount ; -- Simple, with or without tags
  322. procedure IncErrorCount (Index : integer) ; -- Arrays, with or without tags
  323. -- Clear error counter. Caution does not change AlertCounts, must also use AlertLogPkg.ClearAlerts
  324. procedure SetErrorCountZero ; -- Simple, with or without tags
  325. procedure SetErrorCountZero (Index : integer) ; -- Arrays, with or without tags
  326. ------------------------------------------------------------
  327. ------------------------------------------------------------
  328. -- Deprecated. Names changed. Maintained for backward compatibility - would prefer an alias
  329. ------------------------------------------------------------
  330. procedure FileOpen (FileName : string; OpenKind : File_Open_Kind ) ; -- Replaced by TranscriptPkg.TranscriptOpen
  331. procedure PutExpectedData (ExpectedData : ExpectedType) ; -- Replaced by push
  332. procedure CheckActualData (ActualData : ActualType) ; -- Replaced by Check
  333. impure function GetItemNumber return integer ; -- Replaced by GetItemCount
  334. procedure SetMessage (MessageIn : String) ; -- Replaced by SetName
  335. impure function GetMessage return string ; -- Replaced by GetName
  336. -- Deprecated and may be deleted in a future revision
  337. procedure SetFinish ( -- Replaced by CheckFinish
  338. Index : integer ;
  339. FCheckCount : integer ;
  340. FEmpty : boolean := TRUE;
  341. FStatus : boolean := TRUE
  342. ) ;
  343. procedure SetFinish ( -- Replaced by CheckFinish
  344. FCheckCount : integer ;
  345. FEmpty : boolean := TRUE;
  346. FStatus : boolean := TRUE
  347. ) ;
  348. ------------------------------------------------------------
  349. -- SetReportMode
  350. -- Not AlertFlow
  351. -- REPORT_ALL: Replaced by AlertLogPkg.SetLogEnable(PASSED, TRUE)
  352. -- REPORT_ERROR: Replaced by AlertLogPkg.SetLogEnable(PASSED, FALSE)
  353. -- REPORT_NONE: Deprecated, do not use.
  354. -- AlertFlow:
  355. -- REPORT_ALL: Replaced by AlertLogPkg.SetLogEnable(AlertLogID, PASSED, TRUE)
  356. -- REPORT_ERROR: Replaced by AlertLogPkg.SetLogEnable(AlertLogID, PASSED, FALSE)
  357. -- REPORT_NONE: Replaced by AlertLogPkg.SetAlertEnable(AlertLogID, ERROR, FALSE)
  358. procedure SetReportMode (ReportModeIn : ScoreboardReportType) ;
  359. impure function GetReportMode return ScoreboardReportType ;
  360. end protected ScoreBoardPType ;
  361. end ScoreboardGenericPkg ;
  362. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  363. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  364. package body ScoreboardGenericPkg is
  365. type ScoreBoardPType is protected body
  366. type ExpectedPointerType is access ExpectedType ;
  367. type ListType ;
  368. type ListPointerType is access ListType ;
  369. type ListType is record
  370. ItemNumber : integer ;
  371. TagPtr : line ;
  372. ExpectedPtr : ExpectedPointerType ;
  373. NextPtr : ListPointerType ;
  374. end record ;
  375. type ListArrayType is array (integer range <>) of ListPointerType ;
  376. type ListArrayPointerType is access ListArrayType ;
  377. variable ArrayLengthVar : integer := 1 ;
  378. variable HeadPointer : ListArrayPointerType := new ListArrayType(1 to 1) ;
  379. variable TailPointer : ListArrayPointerType := new ListArrayType(1 to 1) ;
  380. variable PopListPointer : ListArrayPointerType := new ListArrayType(1 to 1) ;
  381. type IntegerArrayType is array (integer range <>) of Integer ;
  382. type IntegerArrayPointerType is access IntegerArrayType ;
  383. variable ErrCntVar : IntegerArrayPointerType := new IntegerArrayType'(1 => 0) ;
  384. variable DropCountVar : IntegerArrayPointerType := new IntegerArrayType'(1 => 0) ;
  385. variable ItemNumberVar : IntegerArrayPointerType := new IntegerArrayType'(1 => 0) ;
  386. variable CheckCountVar : IntegerArrayPointerType := new IntegerArrayType'(1 => 0) ;
  387. variable AlertLogIDVar : IntegerArrayPointerType := new IntegerArrayType'(1 => OSVVM_SCOREBOARD_ALERTLOG_ID) ;
  388. variable NameVar : NamePType ;
  389. variable ReportModeVar : ScoreboardReportType ;
  390. variable FirstIndexVar : integer := 1 ;
  391. ------------------------------------------------------------
  392. procedure SetName (Name : String) is
  393. ------------------------------------------------------------
  394. begin
  395. NameVar.Set(Name) ;
  396. end procedure SetName ;
  397. ------------------------------------------------------------
  398. impure function SetName (Name : String) return string is
  399. ------------------------------------------------------------
  400. begin
  401. NameVar.Set(Name) ;
  402. return Name ;
  403. end function SetName ;
  404. ------------------------------------------------------------
  405. impure function GetName (DefaultName : string := "Scoreboard") return string is
  406. ------------------------------------------------------------
  407. begin
  408. return NameVar.Get(DefaultName) ;
  409. end function GetName ;
  410. ------------------------------------------------------------
  411. procedure SetReportMode (ReportModeIn : ScoreboardReportType) is
  412. ------------------------------------------------------------
  413. begin
  414. ReportModeVar := ReportModeIn ;
  415. if ReportModeVar = REPORT_ALL then
  416. Alert(OSVVM_SCOREBOARD_ALERTLOG_ID, "ScoreboardGenericPkg.SetReportMode: To turn off REPORT_ALL, use osvvm.AlertLogPkg.SetLogEnable(PASSED, FALSE)", WARNING) ;
  417. for i in AlertLogIDVar'range loop
  418. SetLogEnable(AlertLogIDVar(i), PASSED, TRUE) ;
  419. end loop ;
  420. end if ;
  421. if ReportModeVar = REPORT_NONE then
  422. Alert(OSVVM_SCOREBOARD_ALERTLOG_ID, "ScoreboardGenericPkg.SetReportMode: ReportMode REPORT_NONE has been deprecated and will be removed in next revision. Please contact OSVVM architect Jim Lewis if you need this capability.", WARNING) ;
  423. end if ;
  424. end procedure SetReportMode ;
  425. ------------------------------------------------------------
  426. impure function GetReportMode return ScoreboardReportType is
  427. ------------------------------------------------------------
  428. begin
  429. return ReportModeVar ;
  430. end function GetReportMode ;
  431. ------------------------------------------------------------
  432. procedure SetArrayIndex(L, R : integer) is
  433. ------------------------------------------------------------
  434. variable OldHeadPointer, OldTailPointer, OldPopListPointer : ListArrayPointerType ;
  435. variable OldErrCnt, OldDropCount, OldItemNumber, OldCheckCount, OldAlertLogIDVar : IntegerArrayPointerType ;
  436. variable Min, Max, Len, OldLen, OldMax : integer ;
  437. begin
  438. Min := minimum(L, R) ;
  439. Max := maximum(L, R) ;
  440. OldLen := ArrayLengthVar ;
  441. OldMax := Min + ArrayLengthVar - 1 ;
  442. Len := Max - Min + 1 ;
  443. ArrayLengthVar := Len ;
  444. if Len >= OldLen then
  445. FirstIndexVar := Min ;
  446. OldHeadPointer := HeadPointer ;
  447. HeadPointer := new ListArrayType(Min to Max) ;
  448. if OldHeadPointer /= NULL then
  449. HeadPointer(Min to OldMax) := OldHeadPointer.all ; -- (OldHeadPointer'range) ;
  450. Deallocate(OldHeadPointer) ;
  451. end if ;
  452. OldTailPointer := TailPointer ;
  453. TailPointer := new ListArrayType(Min to Max) ;
  454. if OldTailPointer /= NULL then
  455. TailPointer(Min to OldMax) := OldTailPointer.all ;
  456. Deallocate(OldTailPointer) ;
  457. end if ;
  458. OldPopListPointer := PopListPointer ;
  459. PopListPointer := new ListArrayType(Min to Max) ;
  460. if OldPopListPointer /= NULL then
  461. PopListPointer(Min to OldMax) := OldPopListPointer.all ;
  462. Deallocate(OldPopListPointer) ;
  463. end if ;
  464. OldErrCnt := ErrCntVar ;
  465. ErrCntVar := new IntegerArrayType'(Min to Max => 0) ;
  466. if OldErrCnt /= NULL then
  467. ErrCntVar(Min to OldMax) := OldErrCnt.all ;
  468. Deallocate(OldErrCnt) ;
  469. end if ;
  470. OldDropCount := DropCountVar ;
  471. DropCountVar := new IntegerArrayType'(Min to Max => 0) ;
  472. if OldDropCount /= NULL then
  473. DropCountVar(Min to OldMax) := OldDropCount.all ;
  474. Deallocate(OldDropCount) ;
  475. end if ;
  476. OldItemNumber := ItemNumberVar ;
  477. ItemNumberVar := new IntegerArrayType'(Min to Max => 0) ;
  478. if OldItemNumber /= NULL then
  479. ItemNumberVar(Min to OldMax) := OldItemNumber.all ;
  480. Deallocate(OldItemNumber) ;
  481. end if ;
  482. OldCheckCount := CheckCountVar ;
  483. CheckCountVar := new IntegerArrayType'(Min to Max => 0) ;
  484. if OldCheckCount /= NULL then
  485. CheckCountVar(Min to OldMax) := OldCheckCount.all ;
  486. Deallocate(OldCheckCount) ;
  487. end if ;
  488. OldAlertLogIDVar := AlertLogIDVar ;
  489. AlertLogIDVar := new IntegerArrayType'(Min to Max => OSVVM_SCOREBOARD_ALERTLOG_ID) ;
  490. if OldAlertLogIDVar /= NULL then
  491. AlertLogIDVar(Min to OldMax) := OldAlertLogIDVar.all ;
  492. Deallocate(OldAlertLogIDVar) ;
  493. end if ;
  494. elsif Len < OldLen then
  495. report "ScoreboardGenericPkg: SetArrayIndex, new array Length <= current array length"
  496. severity failure ;
  497. end if ;
  498. end procedure SetArrayIndex ;
  499. ------------------------------------------------------------
  500. procedure SetArrayIndex(R : natural) is
  501. ------------------------------------------------------------
  502. begin
  503. SetArrayIndex(1, R) ;
  504. end procedure SetArrayIndex ;
  505. ------------------------------------------------------------
  506. procedure Deallocate is
  507. ------------------------------------------------------------
  508. variable CurListPtr, LastListPtr : ListPointerType ;
  509. begin
  510. for Index in HeadPointer'range loop
  511. -- Deallocate contents in the scoreboards
  512. CurListPtr := HeadPointer(Index) ;
  513. while CurListPtr /= Null loop
  514. deallocate(CurListPtr.TagPtr) ;
  515. deallocate(CurListPtr.ExpectedPtr) ;
  516. LastListPtr := CurListPtr ;
  517. CurListPtr := CurListPtr.NextPtr ;
  518. Deallocate(LastListPtr) ;
  519. end loop ;
  520. end loop ;
  521. for Index in PopListPointer'range loop
  522. -- Deallocate PopListPointer - only has single element
  523. CurListPtr := PopListPointer(Index) ;
  524. if CurListPtr /= NULL then
  525. deallocate(CurListPtr.TagPtr) ;
  526. deallocate(CurListPtr.ExpectedPtr) ;
  527. deallocate(CurListPtr) ;
  528. end if ;
  529. end loop ;
  530. -- Deallocate arrays of pointers
  531. Deallocate(HeadPointer) ;
  532. Deallocate(TailPointer) ;
  533. Deallocate(PopListPointer) ;
  534. -- Deallocate supporting arrays
  535. Deallocate(ErrCntVar) ;
  536. Deallocate(DropCountVar) ;
  537. Deallocate(ItemNumberVar) ;
  538. Deallocate(CheckCountVar) ;
  539. Deallocate(AlertLogIDVar) ;
  540. -- Deallocate NameVar - NamePType
  541. NameVar.Deallocate ;
  542. ArrayLengthVar := 0 ;
  543. end procedure Deallocate ;
  544. ------------------------------------------------------------
  545. -- Construct initial data structure
  546. procedure Initialize is
  547. ------------------------------------------------------------
  548. begin
  549. SetArrayIndex(1, 1) ;
  550. end procedure Initialize ;
  551. ------------------------------------------------------------
  552. impure function GetArrayIndex return integer_vector is
  553. ------------------------------------------------------------
  554. begin
  555. return (1 => HeadPointer'left, 2 => HeadPointer'right) ;
  556. end function GetArrayIndex ;
  557. ------------------------------------------------------------
  558. impure function GetArrayLength return natural is
  559. ------------------------------------------------------------
  560. begin
  561. return ArrayLengthVar ; -- HeadPointer'length ;
  562. end function GetArrayLength ;
  563. ------------------------------------------------------------
  564. procedure SetAlertLogID (Index : Integer ; A : AlertLogIDType) is
  565. ------------------------------------------------------------
  566. begin
  567. AlertLogIDVar(Index) := A ;
  568. end procedure SetAlertLogID ;
  569. ------------------------------------------------------------
  570. procedure SetAlertLogID (A : AlertLogIDType) is
  571. ------------------------------------------------------------
  572. begin
  573. AlertLogIDVar(FirstIndexVar) := A ;
  574. end procedure SetAlertLogID ;
  575. ------------------------------------------------------------
  576. procedure SetAlertLogID(Index : Integer ; Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) is
  577. ------------------------------------------------------------
  578. begin
  579. AlertLogIDVar(Index) := GetAlertLogID(Name, ParentID, CreateHierarchy) ;
  580. end procedure SetAlertLogID ;
  581. ------------------------------------------------------------
  582. procedure SetAlertLogID(Name : string ; ParentID : AlertLogIDType := ALERTLOG_BASE_ID ; CreateHierarchy : Boolean := TRUE) is
  583. ------------------------------------------------------------
  584. begin
  585. AlertLogIDVar(FirstIndexVar) := GetAlertLogID(Name, ParentID, CreateHierarchy) ;
  586. end procedure SetAlertLogID ;
  587. ------------------------------------------------------------
  588. impure function GetAlertLogID(Index : Integer) return AlertLogIDType is
  589. ------------------------------------------------------------
  590. begin
  591. return AlertLogIDVar(Index) ;
  592. end function GetAlertLogID ;
  593. ------------------------------------------------------------
  594. impure function GetAlertLogID return AlertLogIDType is
  595. ------------------------------------------------------------
  596. begin
  597. return AlertLogIDVar(FirstIndexVar) ;
  598. end function GetAlertLogID ;
  599. ------------------------------------------------------------
  600. impure function LocalOutOfRange(
  601. ------------------------------------------------------------
  602. constant Index : in integer ;
  603. constant Name : in string
  604. ) return boolean is
  605. begin
  606. return AlertIf(OSVVM_SCOREBOARD_ALERTLOG_ID, Index < HeadPointer'Low or Index > HeadPointer'High,
  607. GetName & " " & Name & " Index: " & to_string(Index) &
  608. "is not in the range (" & to_string(HeadPointer'Low) &
  609. "to " & to_string(HeadPointer'High) & ")",
  610. FAILURE ) ;
  611. end function LocalOutOfRange ;
  612. ------------------------------------------------------------
  613. procedure LocalPush (
  614. ------------------------------------------------------------
  615. constant Index : in integer ;
  616. constant Tag : in string ;
  617. constant Item : in ExpectedType
  618. ) is
  619. variable ExpectedPtr : ExpectedPointerType ;
  620. variable TagPtr : line ;
  621. begin
  622. if LocalOutOfRange(Index, "Push") then
  623. return ; -- error reporting in LocalOutOfRange
  624. end if ;
  625. ItemNumberVar(Index) := ItemNumberVar(Index) + 1 ;
  626. ExpectedPtr := new ExpectedType'(Item) ;
  627. TagPtr := new string'(Tag) ;
  628. if HeadPointer(Index) = NULL then
  629. -- 2015.05: allocation using ListTtype'(...) in a protected type does not work in some simulators
  630. -- HeadPointer(Index) := new ListType'(ItemNumberVar(Index), TagPtr, ExpectedPtr, NULL) ;
  631. HeadPointer(Index) := new ListType ;
  632. HeadPointer(Index).ItemNumber := ItemNumberVar(Index) ;
  633. HeadPointer(Index).TagPtr := TagPtr ;
  634. HeadPointer(Index).ExpectedPtr := ExpectedPtr ;
  635. HeadPointer(Index).NextPtr := NULL ;
  636. TailPointer(Index) := HeadPointer(Index) ;
  637. else
  638. -- 2015.05: allocation using ListTtype'(...) in a protected type does not work in some simulators
  639. -- TailPointer(Index).NextPtr := new ListType'(ItemNumberVar(Index), TagPtr, ExpectedPtr, NULL) ;
  640. TailPointer(Index).NextPtr := new ListType ;
  641. TailPointer(Index).NextPtr.ItemNumber := ItemNumberVar(Index) ;
  642. TailPointer(Index).NextPtr.TagPtr := TagPtr ;
  643. TailPointer(Index).NextPtr.ExpectedPtr := ExpectedPtr ;
  644. TailPointer(Index).NextPtr.NextPtr := NULL ;
  645. TailPointer(Index) := TailPointer(Index).NextPtr ;
  646. end if ;
  647. end procedure LocalPush ;
  648. ------------------------------------------------------------
  649. -- Array of Tagged Scoreboards
  650. procedure Push (
  651. ------------------------------------------------------------
  652. constant Index : in integer ;
  653. constant Tag : in string ;
  654. constant Item : in ExpectedType
  655. ) is
  656. variable ExpectedPtr : ExpectedPointerType ;
  657. variable TagPtr : line ;
  658. begin
  659. if LocalOutOfRange(Index, "Push") then
  660. return ; -- error reporting in LocalOutOfRange
  661. end if ;
  662. LocalPush(Index, Tag, Item) ;
  663. end procedure Push ;
  664. ------------------------------------------------------------
  665. -- Array of Scoreboards, no tag
  666. procedure Push (
  667. ------------------------------------------------------------
  668. constant Index : in integer ;
  669. constant Item : in ExpectedType
  670. ) is
  671. begin
  672. if LocalOutOfRange(Index, "Push") then
  673. return ; -- error reporting in LocalOutOfRange
  674. end if ;
  675. LocalPush(Index, "", Item) ;
  676. end procedure Push ;
  677. ------------------------------------------------------------
  678. -- Simple Tagged Scoreboard
  679. procedure Push (
  680. ------------------------------------------------------------
  681. constant Tag : in string ;
  682. constant Item : in ExpectedType
  683. ) is
  684. begin
  685. LocalPush(FirstIndexVar, Tag, Item) ;
  686. end procedure Push ;
  687. ------------------------------------------------------------
  688. -- Simple Scoreboard, no tag
  689. procedure Push (Item : in ExpectedType) is
  690. ------------------------------------------------------------
  691. begin
  692. LocalPush(FirstIndexVar, "", Item) ;
  693. end procedure Push ;
  694. ------------------------------------------------------------
  695. -- Array of Tagged Scoreboards
  696. impure function Push (
  697. ------------------------------------------------------------
  698. constant Index : in integer ;
  699. constant Tag : in string ;
  700. constant Item : in ExpectedType
  701. ) return ExpectedType is
  702. begin
  703. if LocalOutOfRange(Index, "Push") then
  704. return Item ; -- error reporting in LocalOutOfRange
  705. end if ;
  706. LocalPush(Index, Tag, Item) ;
  707. return Item ;
  708. end function Push ;
  709. ------------------------------------------------------------
  710. -- Array of Scoreboards, no tag
  711. impure function Push (
  712. ------------------------------------------------------------
  713. constant Index : in integer ;
  714. constant Item : in ExpectedType
  715. ) return ExpectedType is
  716. begin
  717. if LocalOutOfRange(Index, "Push") then
  718. return Item ; -- error reporting in LocalOutOfRange
  719. end if ;
  720. LocalPush(Index, "", Item) ;
  721. return Item ;
  722. end function Push ;
  723. ------------------------------------------------------------
  724. -- Simple Tagged Scoreboard
  725. impure function Push (
  726. ------------------------------------------------------------
  727. constant Tag : in string ;
  728. constant Item : in ExpectedType
  729. ) return ExpectedType is
  730. begin
  731. LocalPush(FirstIndexVar, Tag, Item) ;
  732. return Item ;
  733. end function Push ;
  734. ------------------------------------------------------------
  735. -- Simple Scoreboard, no tag
  736. impure function Push (Item : ExpectedType) return ExpectedType is
  737. ------------------------------------------------------------
  738. begin
  739. LocalPush(FirstIndexVar, "", Item) ;
  740. return Item ;
  741. end function Push ;
  742. ------------------------------------------------------------
  743. -- Local Only
  744. -- Pops highest element matching Tag into PopListPointer(Index)
  745. procedure LocalPop (Index : integer ; Tag : string; Name : string) is
  746. ------------------------------------------------------------
  747. variable CurPtr : ListPointerType ;
  748. begin
  749. if LocalOutOfRange(Index, "Pop/Check") then
  750. return ; -- error reporting in LocalOutOfRange
  751. end if ;
  752. if HeadPointer(Index) = NULL then
  753. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  754. Alert(AlertLogIDVar(Index), GetName & " Empty during " & Name, FAILURE) ;
  755. return ;
  756. end if ;
  757. -- deallocate previous pointer
  758. if PopListPointer(Index) /= NULL then
  759. deallocate(PopListPointer(Index).TagPtr) ;
  760. deallocate(PopListPointer(Index).ExpectedPtr) ;
  761. deallocate(PopListPointer(Index)) ;
  762. end if ;
  763. -- Descend to find Tag field and extract
  764. CurPtr := HeadPointer(Index) ;
  765. if CurPtr.TagPtr.all = Tag then
  766. -- Non-tagged scoreboards find this one.
  767. PopListPointer(Index) := HeadPointer(Index) ;
  768. HeadPointer(Index) := HeadPointer(Index).NextPtr ;
  769. else
  770. loop
  771. if CurPtr.NextPtr = NULL then
  772. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  773. Alert(AlertLogIDVar(Index), GetName & " Pop/Check (" & Name & "), tag: " & Tag & " not found", FAILURE) ;
  774. exit ;
  775. elsif CurPtr.NextPtr.TagPtr.all = Tag then
  776. PopListPointer(Index) := CurPtr.NextPtr ;
  777. CurPtr.NextPtr := CurPtr.NextPtr.NextPtr ;
  778. if CurPtr.NextPtr = NULL then
  779. TailPointer(Index) := CurPtr ;
  780. end if ;
  781. exit ;
  782. else
  783. CurPtr := CurPtr.NextPtr ;
  784. end if ;
  785. end loop ;
  786. end if ;
  787. end procedure LocalPop ;
  788. ------------------------------------------------------------
  789. -- Local Only
  790. procedure LocalCheck (
  791. ------------------------------------------------------------
  792. constant Index : in integer ;
  793. constant ActualData : in ActualType
  794. ) is
  795. variable ExpectedPtr : ExpectedPointerType ;
  796. variable CurrentItem : integer ;
  797. variable WriteBuf : line ;
  798. variable FoundError : boolean ;
  799. begin
  800. CheckCountVar(Index) := CheckCountVar(Index) + 1 ;
  801. ExpectedPtr := PopListPointer(Index).ExpectedPtr ;
  802. CurrentItem := PopListPointer(Index).ItemNumber ;
  803. if not Match(ActualData, ExpectedPtr.all) then
  804. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  805. FoundError := TRUE ;
  806. else
  807. FoundError := FALSE ;
  808. end if ;
  809. IncAffirmCount ;
  810. -- if FoundError or ReportModeVar = REPORT_ALL then
  811. if FoundError or GetLogEnable(AlertLogIDVar(Index), PASSED) then
  812. if AlertLogIDVar(Index) = OSVVM_SCOREBOARD_ALERTLOG_ID then
  813. write(WriteBuf, GetName(DefaultName => "Scoreboard")) ;
  814. else
  815. write(WriteBuf, GetName(DefaultName => "")) ;
  816. end if ;
  817. if ArrayLengthVar > 1 then
  818. write(WriteBuf, " (" & to_string(Index) & ") ") ;
  819. end if ;
  820. write(WriteBuf, " Received: " & actual_to_string(ActualData)) ;
  821. if FoundError then
  822. write(WriteBuf, " Expected: " & expected_to_string(ExpectedPtr.all)) ;
  823. end if ;
  824. if PopListPointer(Index).TagPtr.all /= "" then
  825. write(WriteBuf, " Tag: " & PopListPointer(Index).TagPtr.all) ;
  826. end if;
  827. write(WriteBuf, " Item Number: " & to_string(CurrentItem)) ;
  828. if FoundError then
  829. if ReportModeVar /= REPORT_NONE then
  830. -- Affirmation Failed
  831. Alert(AlertLogIDVar(Index), WriteBuf.all, ERROR) ;
  832. else
  833. -- Affirmation Failed, but silent, unless in DEBUG mode
  834. Log(AlertLogIDVar(Index), "ERROR " & WriteBuf.all, DEBUG) ;
  835. IncAlertCount(AlertLogIDVar(Index)) ; -- Silent Counted Alert
  836. end if ;
  837. else
  838. -- Affirmation passed
  839. Log(AlertLogIDVar(Index), WriteBuf.all, PASSED) ;
  840. end if ;
  841. deallocate(WriteBuf) ;
  842. end if ;
  843. end procedure LocalCheck ;
  844. ------------------------------------------------------------
  845. -- Array of Tagged Scoreboards
  846. procedure Check (
  847. ------------------------------------------------------------
  848. constant Index : in integer ;
  849. constant Tag : in string ;
  850. constant ActualData : in ActualType
  851. ) is
  852. begin
  853. if LocalOutOfRange(Index, "Check") then
  854. return ; -- error reporting in LocalOutOfRange
  855. end if ;
  856. LocalPop(Index, Tag, "Check") ;
  857. LocalCheck(Index, ActualData) ;
  858. end procedure Check ;
  859. ------------------------------------------------------------
  860. -- Array of Scoreboards, no tag
  861. procedure Check (
  862. ------------------------------------------------------------
  863. constant Index : in integer ;
  864. constant ActualData : in ActualType
  865. ) is
  866. begin
  867. if LocalOutOfRange(Index, "Check") then
  868. return ; -- error reporting in LocalOutOfRange
  869. end if ;
  870. LocalPop(Index, "", "Check") ;
  871. LocalCheck(Index, ActualData) ;
  872. end procedure Check ;
  873. ------------------------------------------------------------
  874. -- Simple Tagged Scoreboard
  875. procedure Check (
  876. ------------------------------------------------------------
  877. constant Tag : in string ;
  878. constant ActualData : in ActualType
  879. ) is
  880. begin
  881. LocalPop(FirstIndexVar, Tag, "Check") ;
  882. LocalCheck(FirstIndexVar, ActualData) ;
  883. end procedure Check ;
  884. ------------------------------------------------------------
  885. -- Simple Scoreboard, no tag
  886. procedure Check (ActualData : ActualType) is
  887. ------------------------------------------------------------
  888. begin
  889. LocalPop(FirstIndexVar, "", "Check") ;
  890. LocalCheck(FirstIndexVar, ActualData) ;
  891. end procedure Check ;
  892. ------------------------------------------------------------
  893. -- Array of Tagged Scoreboards
  894. procedure Pop (
  895. ------------------------------------------------------------
  896. constant Index : in integer ;
  897. constant Tag : in string ;
  898. variable Item : out ExpectedType
  899. ) is
  900. begin
  901. if LocalOutOfRange(Index, "Pop") then
  902. return ; -- error reporting in LocalOutOfRange
  903. end if ;
  904. LocalPop(Index, Tag, "Pop") ;
  905. Item := PopListPointer(Index).ExpectedPtr.all ;
  906. end procedure Pop ;
  907. ------------------------------------------------------------
  908. -- Array of Scoreboards, no tag
  909. procedure Pop (
  910. ------------------------------------------------------------
  911. constant Index : in integer ;
  912. variable Item : out ExpectedType
  913. ) is
  914. begin
  915. if LocalOutOfRange(Index, "Pop") then
  916. return ; -- error reporting in LocalOutOfRange
  917. end if ;
  918. LocalPop(Index, "", "Pop") ;
  919. Item := PopListPointer(Index).ExpectedPtr.all ;
  920. end procedure Pop ;
  921. ------------------------------------------------------------
  922. -- Simple Tagged Scoreboard
  923. procedure Pop (
  924. ------------------------------------------------------------
  925. constant Tag : in string ;
  926. variable Item : out ExpectedType
  927. ) is
  928. begin
  929. LocalPop(FirstIndexVar, Tag, "Pop") ;
  930. Item := PopListPointer(FirstIndexVar).ExpectedPtr.all ;
  931. end procedure Pop ;
  932. ------------------------------------------------------------
  933. -- Simple Scoreboard, no tag
  934. procedure Pop (variable Item : out ExpectedType) is
  935. ------------------------------------------------------------
  936. begin
  937. LocalPop(FirstIndexVar, "", "Pop") ;
  938. Item := PopListPointer(FirstIndexVar).ExpectedPtr.all ;
  939. end procedure Pop ;
  940. ------------------------------------------------------------
  941. -- Array of Tagged Scoreboards
  942. impure function Pop (
  943. ------------------------------------------------------------
  944. constant Index : in integer ;
  945. constant Tag : in string
  946. ) return ExpectedType is
  947. begin
  948. if LocalOutOfRange(Index, "Pop") then
  949. -- error reporting in LocalOutOfRange
  950. return PopListPointer(FirstIndexVar).ExpectedPtr.all ;
  951. end if ;
  952. LocalPop(Index, Tag, "Pop") ;
  953. return PopListPointer(Index).ExpectedPtr.all ;
  954. end function Pop ;
  955. ------------------------------------------------------------
  956. -- Array of Scoreboards, no tag
  957. impure function Pop (Index : integer) return ExpectedType is
  958. ------------------------------------------------------------
  959. begin
  960. if LocalOutOfRange(Index, "Pop") then
  961. -- error reporting in LocalOutOfRange
  962. return PopListPointer(FirstIndexVar).ExpectedPtr.all ;
  963. end if ;
  964. LocalPop(Index, "", "Pop") ;
  965. return PopListPointer(Index).ExpectedPtr.all ;
  966. end function Pop ;
  967. ------------------------------------------------------------
  968. -- Simple Tagged Scoreboard
  969. impure function Pop (
  970. ------------------------------------------------------------
  971. constant Tag : in string
  972. ) return ExpectedType is
  973. begin
  974. LocalPop(FirstIndexVar, Tag, "Pop") ;
  975. return PopListPointer(FirstIndexVar).ExpectedPtr.all ;
  976. end function Pop ;
  977. ------------------------------------------------------------
  978. -- Simple Scoreboard, no tag
  979. impure function Pop return ExpectedType is
  980. ------------------------------------------------------------
  981. begin
  982. LocalPop(FirstIndexVar, "", "Pop") ;
  983. return PopListPointer(FirstIndexVar).ExpectedPtr.all ;
  984. end function Pop ;
  985. ------------------------------------------------------------
  986. -- Array of Tagged Scoreboards
  987. impure function Empty (Index : integer; Tag : String) return boolean is
  988. ------------------------------------------------------------
  989. variable CurPtr : ListPointerType ;
  990. begin
  991. CurPtr := HeadPointer(Index) ;
  992. while CurPtr /= NULL loop
  993. if CurPtr.TagPtr.all = Tag then
  994. return FALSE ; -- Found Tag
  995. end if ;
  996. CurPtr := CurPtr.NextPtr ;
  997. end loop ;
  998. return TRUE ; -- Tag not found
  999. end function Empty ;
  1000. ------------------------------------------------------------
  1001. -- Array of Scoreboards, no tag
  1002. impure function Empty (Index : integer) return boolean is
  1003. ------------------------------------------------------------
  1004. begin
  1005. return HeadPointer(Index) = NULL ;
  1006. end function Empty ;
  1007. ------------------------------------------------------------
  1008. -- Simple Tagged Scoreboard
  1009. impure function Empty (Tag : String) return boolean is
  1010. ------------------------------------------------------------
  1011. variable CurPtr : ListPointerType ;
  1012. begin
  1013. return Empty(FirstIndexVar, Tag) ;
  1014. end function Empty ;
  1015. ------------------------------------------------------------
  1016. -- Simple Scoreboard, no tag
  1017. impure function Empty return boolean is
  1018. ------------------------------------------------------------
  1019. begin
  1020. return HeadPointer(FirstIndexVar) = NULL ;
  1021. end function Empty ;
  1022. ------------------------------------------------------------
  1023. procedure CheckFinish (
  1024. ------------------------------------------------------------
  1025. Index : integer ;
  1026. FinishCheckCount : integer ;
  1027. FinishEmpty : boolean
  1028. ) is
  1029. variable EmptyError : Boolean ;
  1030. variable WriteBuf : line ;
  1031. begin
  1032. if AlertLogIDVar(Index) = OSVVM_SCOREBOARD_ALERTLOG_ID then
  1033. write(WriteBuf, GetName(DefaultName => "Scoreboard")) ;
  1034. else
  1035. write(WriteBuf, GetName(DefaultName => "")) ;
  1036. end if ;
  1037. if ArrayLengthVar > 1 then
  1038. if WriteBuf.all /= "" then
  1039. swrite(WriteBuf, " ") ;
  1040. end if ;
  1041. write(WriteBuf, "Index(" & to_string(Index) & "), ") ;
  1042. else
  1043. if WriteBuf.all /= "" then
  1044. swrite(WriteBuf, ", ") ;
  1045. end if ;
  1046. end if ;
  1047. if FinishEmpty then
  1048. AffirmIf(AlertLogIDVar(Index), Empty(Index), WriteBuf.all & "Checking Empty: " & to_string(Empty(Index)) &
  1049. " FinishEmpty: " & to_string(FinishEmpty)) ;
  1050. if not Empty(Index) then
  1051. -- Increment internal count on FinishEmpty Error
  1052. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  1053. end if ;
  1054. end if ;
  1055. AffirmIf(AlertLogIDVar(Index), CheckCountVar(Index) >= FinishCheckCount, WriteBuf.all &
  1056. "Checking CheckCount: " & to_string(CheckCountVar(Index)) &
  1057. " >= Expected: " & to_string(FinishCheckCount)) ;
  1058. if not (CheckCountVar(Index) >= FinishCheckCount) then
  1059. -- Increment internal count on FinishCheckCount Error
  1060. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  1061. end if ;
  1062. deallocate(WriteBuf) ;
  1063. end procedure CheckFinish ;
  1064. ------------------------------------------------------------
  1065. procedure CheckFinish (
  1066. ------------------------------------------------------------
  1067. FinishCheckCount : integer ;
  1068. FinishEmpty : boolean
  1069. ) is
  1070. begin
  1071. for AlertLogID in AlertLogIDVar'range loop
  1072. CheckFinish(AlertLogID, FinishCheckCount, FinishEmpty) ;
  1073. end loop ;
  1074. end procedure CheckFinish ;
  1075. ------------------------------------------------------------
  1076. impure function GetErrorCount (Index : integer) return integer is
  1077. ------------------------------------------------------------
  1078. begin
  1079. return ErrCntVar(Index) ;
  1080. end function GetErrorCount ;
  1081. ------------------------------------------------------------
  1082. impure function GetErrorCount return integer is
  1083. ------------------------------------------------------------
  1084. variable TotalErrorCount : integer := 0 ;
  1085. begin
  1086. for Index in AlertLogIDVar'range loop
  1087. TotalErrorCount := TotalErrorCount + GetErrorCount(Index) ;
  1088. end loop ;
  1089. return TotalErrorCount ;
  1090. end function GetErrorCount ;
  1091. ------------------------------------------------------------
  1092. procedure IncErrorCount (Index : integer) is
  1093. ------------------------------------------------------------
  1094. begin
  1095. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  1096. IncAlertCount(AlertLogIDVar(Index), ERROR) ;
  1097. end IncErrorCount ;
  1098. ------------------------------------------------------------
  1099. procedure IncErrorCount is
  1100. ------------------------------------------------------------
  1101. begin
  1102. ErrCntVar(FirstIndexVar) := ErrCntVar(FirstIndexVar) + 1 ;
  1103. IncAlertCount(AlertLogIDVar(FirstIndexVar), ERROR) ;
  1104. end IncErrorCount ;
  1105. ------------------------------------------------------------
  1106. procedure SetErrorCountZero (Index : integer) is
  1107. ------------------------------------------------------------
  1108. begin
  1109. ErrCntVar(Index) := 0;
  1110. end procedure SetErrorCountZero ;
  1111. ------------------------------------------------------------
  1112. procedure SetErrorCountZero is
  1113. ------------------------------------------------------------
  1114. begin
  1115. ErrCntVar(FirstIndexVar) := 0 ;
  1116. end procedure SetErrorCountZero ;
  1117. ------------------------------------------------------------
  1118. impure function GetItemCount (Index : integer) return integer is
  1119. ------------------------------------------------------------
  1120. begin
  1121. return ItemNumberVar(Index) ;
  1122. end function GetItemCount ;
  1123. ------------------------------------------------------------
  1124. impure function GetItemCount return integer is
  1125. ------------------------------------------------------------
  1126. begin
  1127. return ItemNumberVar(FirstIndexVar) ;
  1128. end function GetItemCount ;
  1129. ------------------------------------------------------------
  1130. impure function GetCheckCount (Index : integer) return integer is
  1131. ------------------------------------------------------------
  1132. begin
  1133. return CheckCountVar(Index) ;
  1134. end function GetCheckCount ;
  1135. ------------------------------------------------------------
  1136. impure function GetCheckCount return integer is
  1137. ------------------------------------------------------------
  1138. begin
  1139. return CheckCountVar(FirstIndexVar) ;
  1140. end function GetCheckCount ;
  1141. ------------------------------------------------------------
  1142. impure function GetDropCount (Index : integer) return integer is
  1143. ------------------------------------------------------------
  1144. begin
  1145. return DropCountVar(Index) ;
  1146. end function GetDropCount ;
  1147. ------------------------------------------------------------
  1148. impure function GetDropCount return integer is
  1149. ------------------------------------------------------------
  1150. begin
  1151. return DropCountVar(FirstIndexVar) ;
  1152. end function GetDropCount ;
  1153. ------------------------------------------------------------
  1154. procedure SetFinish (
  1155. ------------------------------------------------------------
  1156. Index : integer ;
  1157. FCheckCount : integer ;
  1158. FEmpty : boolean := TRUE;
  1159. FStatus : boolean := TRUE
  1160. ) is
  1161. begin
  1162. Alert(AlertLogIDVar(Index), "OSVVM.ScoreboardGenericPkg.SetFinish: Deprecated and removed. See CheckFinish", ERROR) ;
  1163. end procedure SetFinish ;
  1164. ------------------------------------------------------------
  1165. procedure SetFinish (
  1166. ------------------------------------------------------------
  1167. FCheckCount : integer ;
  1168. FEmpty : boolean := TRUE;
  1169. FStatus : boolean := TRUE
  1170. ) is
  1171. begin
  1172. SetFinish(FirstIndexVar, FCheckCount, FEmpty, FStatus) ;
  1173. end procedure SetFinish ;
  1174. ------------------------------------------------------------
  1175. -- Array of Tagged Scoreboards
  1176. -- Find Element with Matching Tag and ActualData
  1177. -- Returns integer'left if no match found
  1178. impure function Find (
  1179. ------------------------------------------------------------
  1180. constant Index : in integer ;
  1181. constant Tag : in string;
  1182. constant ActualData : in ActualType
  1183. ) return integer is
  1184. variable CurPtr : ListPointerType ;
  1185. begin
  1186. if LocalOutOfRange(Index, "Find") then
  1187. return integer'left ; -- error reporting in LocalOutOfRange
  1188. end if ;
  1189. CurPtr := HeadPointer(Index) ;
  1190. loop
  1191. if CurPtr = NULL then
  1192. -- Failed to find it
  1193. ErrCntVar(Index) := ErrCntVar(Index) + 1 ;
  1194. if Tag /= "" then
  1195. Alert(AlertLogIDVar(Index),
  1196. GetName & " Did not find Tag: " & Tag & " and Actual Data: " & actual_to_string(ActualData),
  1197. FAILURE ) ;
  1198. else
  1199. Alert(AlertLogIDVar(Index),
  1200. GetName & " Did not find Actual Data: " & actual_to_string(ActualData),
  1201. FAILURE ) ;
  1202. end if ;
  1203. return integer'left ;
  1204. elsif CurPtr.TagPtr.all = Tag and
  1205. Match(ActualData, CurPtr.ExpectedPtr.all) then
  1206. -- Found it. Return Index.
  1207. return CurPtr.ItemNumber ;
  1208. else -- Descend
  1209. CurPtr := CurPtr.NextPtr ;
  1210. end if ;
  1211. end loop ;
  1212. end function Find ;
  1213. ------------------------------------------------------------
  1214. -- Array of Simple Scoreboards
  1215. -- Find Element with Matching ActualData
  1216. impure function Find (
  1217. ------------------------------------------------------------
  1218. constant Index : in integer ;
  1219. constant ActualData : in ActualType
  1220. ) return integer is
  1221. begin
  1222. return Find(Index, "", ActualData) ;
  1223. end function Find ;
  1224. ------------------------------------------------------------
  1225. -- Tagged Scoreboard
  1226. -- Find Element with Matching ActualData
  1227. impure function Find (
  1228. ------------------------------------------------------------
  1229. constant Tag : in string;
  1230. constant ActualData : in ActualType
  1231. ) return integer is
  1232. begin
  1233. return Find(FirstIndexVar, Tag, ActualData) ;
  1234. end function Find ;
  1235. ------------------------------------------------------------
  1236. -- Simple Scoreboard
  1237. -- Find Element with Matching ActualData
  1238. impure function Find (
  1239. ------------------------------------------------------------
  1240. constant ActualData : in ActualType
  1241. ) return integer is
  1242. begin
  1243. return Find(FirstIndexVar, "", ActualData) ;
  1244. end function Find ;
  1245. ------------------------------------------------------------
  1246. -- Array of Tagged Scoreboards
  1247. -- Flush Remove elements with tag whose itemNumber is <= ItemNumber parameter
  1248. procedure Flush (
  1249. ------------------------------------------------------------
  1250. constant Index : in integer ;
  1251. constant Tag : in string ;
  1252. constant ItemNumber : in integer
  1253. ) is
  1254. variable CurPtr, RemovePtr, LastPtr : ListPointerType ;
  1255. begin
  1256. if LocalOutOfRange(Index, "Find") then
  1257. return ; -- error reporting in LocalOutOfRange
  1258. end if ;
  1259. CurPtr := HeadPointer(Index) ;
  1260. LastPtr := NULL ;
  1261. loop
  1262. if CurPtr = NULL then
  1263. -- Done
  1264. return ;
  1265. elsif CurPtr.TagPtr.all = Tag then
  1266. if ItemNumber >= CurPtr.ItemNumber then
  1267. -- remove it
  1268. RemovePtr := CurPtr ;
  1269. if CurPtr = TailPointer(Index) then
  1270. TailPointer(Index) := LastPtr ;
  1271. end if ;
  1272. if CurPtr = HeadPointer(Index) then
  1273. HeadPointer(Index) := CurPtr.NextPtr ;
  1274. else -- if LastPtr /= NULL then
  1275. LastPtr.NextPtr := LastPtr.NextPtr.NextPtr ;
  1276. end if ;
  1277. CurPtr := CurPtr.NextPtr ;
  1278. -- LastPtr := LastPtr ; -- no change
  1279. DropCountVar(Index) := DropCountVar(Index) + 1 ;
  1280. deallocate(RemovePtr.TagPtr) ;
  1281. deallocate(RemovePtr.ExpectedPtr) ;
  1282. deallocate(RemovePtr) ;
  1283. else
  1284. -- Done
  1285. return ;
  1286. end if ;
  1287. else
  1288. -- Descend
  1289. LastPtr := CurPtr ;
  1290. CurPtr := CurPtr.NextPtr ;
  1291. end if ;
  1292. end loop ;
  1293. end procedure Flush ;
  1294. ------------------------------------------------------------
  1295. -- Tagged Scoreboard
  1296. -- Flush Remove elements with tag whose itemNumber is <= ItemNumber parameter
  1297. procedure Flush (
  1298. ------------------------------------------------------------
  1299. constant Tag : in string ;
  1300. constant ItemNumber : in integer
  1301. ) is
  1302. begin
  1303. Flush(FirstIndexVar, Tag, ItemNumber) ;
  1304. end procedure Flush ;
  1305. ------------------------------------------------------------
  1306. -- Array of Simple Scoreboards
  1307. -- Flush - Remove Elements upto and including the one with ItemNumber
  1308. procedure Flush (
  1309. ------------------------------------------------------------
  1310. constant Index : in integer ;
  1311. constant ItemNumber : in integer
  1312. ) is
  1313. variable CurPtr : ListPointerType ;
  1314. begin
  1315. if LocalOutOfRange(Index, "Find") then
  1316. return ; -- error reporting in LocalOutOfRange
  1317. end if ;
  1318. CurPtr := HeadPointer(Index) ;
  1319. loop
  1320. if CurPtr = NULL then
  1321. -- Done
  1322. return ;
  1323. elsif ItemNumber >= CurPtr.ItemNumber then
  1324. -- Descend, Check Tail, Deallocate
  1325. HeadPointer(Index) := HeadPointer(Index).NextPtr ;
  1326. if CurPtr = TailPointer(Index) then
  1327. TailPointer(Index) := NULL ;
  1328. end if ;
  1329. DropCountVar(Index) := DropCountVar(Index) + 1 ;
  1330. deallocate(CurPtr.TagPtr) ;
  1331. deallocate(CurPtr.ExpectedPtr) ;
  1332. deallocate(CurPtr) ;
  1333. CurPtr := HeadPointer(Index) ;
  1334. else
  1335. -- Done
  1336. return ;
  1337. end if ;
  1338. end loop ;
  1339. end procedure Flush ;
  1340. ------------------------------------------------------------
  1341. -- Simple Scoreboard
  1342. -- Flush - Remove Elements upto and including the one with ItemNumber
  1343. procedure Flush (
  1344. ------------------------------------------------------------
  1345. constant ItemNumber : in integer
  1346. ) is
  1347. begin
  1348. Flush(FirstIndexVar, ItemNumber) ;
  1349. end procedure Flush ;
  1350. ------------------------------------------------------------
  1351. ------------------------------------------------------------
  1352. -- Remaining Deprecated.
  1353. ------------------------------------------------------------
  1354. ------------------------------------------------------------
  1355. ------------------------------------------------------------
  1356. -- Deprecated. Maintained for backward compatibility.
  1357. -- Use TranscriptPkg.TranscriptOpen
  1358. procedure FileOpen (FileName : string; OpenKind : File_Open_Kind ) is
  1359. ------------------------------------------------------------
  1360. begin
  1361. -- WriteFileInit := TRUE ;
  1362. -- file_open( WriteFile , FileName , OpenKind );
  1363. TranscriptOpen(FileName, OpenKind) ;
  1364. end procedure FileOpen ;
  1365. ------------------------------------------------------------
  1366. -- Deprecated. Maintained for backward compatibility.
  1367. procedure PutExpectedData (ExpectedData : ExpectedType) is
  1368. ------------------------------------------------------------
  1369. begin
  1370. Push(ExpectedData) ;
  1371. end procedure PutExpectedData ;
  1372. ------------------------------------------------------------
  1373. -- Deprecated. Maintained for backward compatibility.
  1374. procedure CheckActualData (ActualData : ActualType) is
  1375. ------------------------------------------------------------
  1376. begin
  1377. Check(ActualData) ;
  1378. end procedure CheckActualData ;
  1379. ------------------------------------------------------------
  1380. -- Deprecated. Maintained for backward compatibility.
  1381. impure function GetItemNumber return integer is
  1382. ------------------------------------------------------------
  1383. begin
  1384. return GetItemCount(FirstIndexVar) ;
  1385. end GetItemNumber ;
  1386. ------------------------------------------------------------
  1387. -- Deprecated. Maintained for backward compatibility.
  1388. procedure SetMessage (MessageIn : String) is
  1389. ------------------------------------------------------------
  1390. begin
  1391. -- deallocate(Message) ;
  1392. -- Message := new string'(MessageIn) ;
  1393. SetName(MessageIn) ;
  1394. end procedure SetMessage ;
  1395. ------------------------------------------------------------
  1396. -- Deprecated. Maintained for backward compatibility.
  1397. impure function GetMessage return string is
  1398. ------------------------------------------------------------
  1399. begin
  1400. -- return Message.all ;
  1401. return GetName("Scoreboard") ;
  1402. end function GetMessage ;
  1403. end protected body ScoreBoardPType ;
  1404. end ScoreboardGenericPkg ;