|
| 1 | +-- This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +-- License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 3 | +-- You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | +-- |
| 5 | +-- Copyright (c) 2014-2019, Lars Asplund [email protected] |
| 6 | + |
| 7 | +library vunit_lib; |
| 8 | +context vunit_lib.vunit_context; |
| 9 | +context vunit_lib.com_context; |
| 10 | +context vunit_lib.vc_context; |
| 11 | + |
| 12 | +-- foo_bar_pkg defines the verification component interface (VCI) |
| 13 | +package foo_bar_pkg is |
| 14 | + -- The type of a VC instance handle. It contains the properties that can be |
| 15 | + -- configured when a new instance is created. p_* means that the content of |
| 16 | + -- the record is private and the user is not supposed to access these fields |
| 17 | + -- directly. It should be possible jto change the contents of the record |
| 18 | + -- without breaking backward compatibility. |
| 19 | + type foo_bar_handle_t is record |
| 20 | + p_actor : actor_t; |
| 21 | + p_logger : logger_t; |
| 22 | + p_checker : checker_t; |
| 23 | + p_fail_on_unexpected_msg_type : boolean; |
| 24 | + end record; |
| 25 | + |
| 26 | + -- Transaction messages used to control the VC. Not used directly by a user of the VC. |
| 27 | + -- Someone writing another VC reusing this VCI would know about these messages. |
| 28 | + constant transaction_1_msg : msg_type_t := new_msg_type("transaction 1"); |
| 29 | + constant transaction_2_msg : msg_type_t := new_msg_type("transaction 2"); |
| 30 | + |
| 31 | + -- Creates a new VC instance handle |
| 32 | + impure function new_foo_bar( |
| 33 | + logger : logger_t := null_logger; |
| 34 | + actor : actor_t := null_actor; |
| 35 | + checker : checker_t := null_checker; |
| 36 | + fail_on_unexpected_msg_type : boolean := true |
| 37 | + ) return foo_bar_handle_t; |
| 38 | + |
| 39 | + procedure transaction_1( |
| 40 | + signal net : inout network_t; |
| 41 | + foo_bar_h : foo_bar_handle_t; |
| 42 | + arg_1 : integer; |
| 43 | + arg_2 : boolean |
| 44 | + ); |
| 45 | + |
| 46 | + procedure transaction_2( |
| 47 | + signal net : inout network_t; |
| 48 | + foo_bar_h : foo_bar_handle_t; |
| 49 | + arg_1 : integer; |
| 50 | + arg_2 : boolean |
| 51 | + ); |
| 52 | + |
| 53 | + impure function as_sync( |
| 54 | + foo_bar_h : foo_bar_handle_t |
| 55 | + ) return sync_handle_t; |
| 56 | + |
| 57 | +end package; |
| 58 | + |
| 59 | +package body foo_bar_pkg is |
| 60 | + impure function new_foo_bar( |
| 61 | + logger : logger_t := null_logger; -- Enables full control of reporting |
| 62 | + actor : actor_t := null_actor; -- Enables full control over messaging |
| 63 | + checker : checker_t := null_checker; -- Enables separation between error reporting and other reporting |
| 64 | + fail_on_unexpected_msg_type : boolean := true -- The presence of unexpected messages depends on the VC |
| 65 | + -- context so whether or not this is an error must be under user control. |
| 66 | + ) return foo_bar_handle_t is |
| 67 | + variable p_logger : logger_t := logger; |
| 68 | + variable p_actor : actor_t := actor; |
| 69 | + variable p_checker : checker_t := checker; |
| 70 | + begin |
| 71 | + if logger = null_logger then |
| 72 | + p_logger := get_logger("foo_bar"); |
| 73 | + end if; |
| 74 | + |
| 75 | + if actor = null_actor then |
| 76 | + p_actor := new_actor; |
| 77 | + end if; |
| 78 | + |
| 79 | + if checker = null_checker then |
| 80 | + if logger = null_logger then |
| 81 | + p_checker := new_checker(p_logger); |
| 82 | + else |
| 83 | + p_checker := new_checker(logger); |
| 84 | + end if; |
| 85 | + end if; |
| 86 | + |
| 87 | + return ( |
| 88 | + p_logger => p_logger, |
| 89 | + p_actor => p_actor, |
| 90 | + p_checker => p_checker, |
| 91 | + p_fail_on_unexpected_msg_type => fail_on_unexpected_msg_type |
| 92 | + ); |
| 93 | + end; |
| 94 | + |
| 95 | + procedure transaction_1( |
| 96 | + signal net : inout network_t; |
| 97 | + foo_bar_h : foo_bar_handle_t; |
| 98 | + arg_1 : integer; |
| 99 | + arg_2 : boolean |
| 100 | + ) is |
| 101 | + variable msg : msg_t; |
| 102 | + begin |
| 103 | + msg := new_msg(transaction_1_msg); |
| 104 | + push(msg, arg_1); |
| 105 | + push(msg, arg_2); |
| 106 | + send(net, foo_bar_h.p_actor, msg); |
| 107 | + end procedure; |
| 108 | + |
| 109 | + procedure transaction_2( |
| 110 | + signal net : inout network_t; |
| 111 | + foo_bar_h : foo_bar_handle_t; |
| 112 | + arg_1 : integer; |
| 113 | + arg_2 : boolean |
| 114 | + ) is |
| 115 | + variable msg : msg_t; |
| 116 | + begin |
| 117 | + msg := new_msg(transaction_2_msg); |
| 118 | + push(msg, arg_1); |
| 119 | + push(msg, arg_2); |
| 120 | + send(net, foo_bar_h.p_actor, msg); |
| 121 | + end procedure; |
| 122 | + |
| 123 | + impure function as_sync(foo_bar_h : foo_bar_handle_t) return sync_handle_t is |
| 124 | + begin |
| 125 | + return foo_bar_h.p_actor; |
| 126 | + end; |
| 127 | + |
| 128 | +end package body; |
| 129 | + |
0 commit comments