├── compile.f ├── .github └── FUNDING.yml ├── compile.rb ├── src ├── tvip_apb_status.svh ├── tvip_apb_master_ral_predictor.svh ├── tvip_apb_master_sequencer.svh ├── tvip_apb_macros.svh ├── tvip_apb_master_monitor.svh ├── tvip_apb_master_agent.svh ├── tvip_apb_pkg.sv ├── tvip_apb_types.svh ├── tvip_apb_configuration.svh ├── tvip_apb_master_ral_adapter.svh ├── tvip_apb_if.sv ├── tvip_apb_monitor_base.svh ├── tvip_apb_master_driver.svh └── tvip_apb_item.svh └── LICENSE /compile.f: -------------------------------------------------------------------------------- 1 | +incdir+${TVIP_APB_HOME}/src 2 | ${TVIP_APB_HOME}/src/tvip_apb_pkg.sv 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [taichi-ishitani] 4 | -------------------------------------------------------------------------------- /compile.rb: -------------------------------------------------------------------------------- 1 | if ENV.key?('TVIP_COMMON_HOME') 2 | file_list File.join(ENV['TVIP_COMMON_HOME'], 'compile.f') 3 | elsif Dir.exist?(File.join(__dir__, 'tvip-common')) 4 | file_list 'tvip-common/compile.rb', from: :current 5 | end 6 | 7 | include_directory 'src' 8 | source_file 'src/tvip_apb_pkg.sv' 9 | -------------------------------------------------------------------------------- /src/tvip_apb_status.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_STATUS_SVH 17 | `define TVIP_APB_STATUS_SVH 18 | typedef tue_status_dummy tvip_apb_status; 19 | `endif 20 | -------------------------------------------------------------------------------- /src/tvip_apb_master_ral_predictor.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MASTER_RAL_PREDICTOR_SVH 17 | `define TVIP_APB_MASTER_RAL_PREDICTOR_SVH 18 | typedef tue_reg_predictor #(tvip_apb_master_item) tvip_apb_master_ral_predictor; 19 | `endif 20 | -------------------------------------------------------------------------------- /src/tvip_apb_master_sequencer.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MASTER_SEQUENCER_SVH 17 | `define TVIP_APB_MASTER_SEQUENCER_SVH 18 | typedef tue_sequencer #( 19 | tvip_apb_configuration, tvip_apb_status, tvip_apb_master_item 20 | ) tvip_apb_master_sequencer; 21 | `endif 22 | -------------------------------------------------------------------------------- /src/tvip_apb_macros.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MACROS_SVH 17 | `define TVIP_APB_MACROS_SVH 18 | 19 | `ifndef TVIP_APB_MAX_ADDRESS_WIDTH 20 | `define TVIP_APB_MAX_ADDRESS_WIDTH 16 21 | `endif 22 | 23 | `ifndef TVIP_APB_MAX_DATA_WIDTH 24 | `define TVIP_APB_MAX_DATA_WIDTH 32 25 | `endif 26 | 27 | `endif 28 | -------------------------------------------------------------------------------- /src/tvip_apb_master_monitor.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MASTER_MONITOR_SVH 17 | `define TVIP_APB_MASTER_MONITOR_SVH 18 | class tvip_apb_master_monitor extends tvip_apb_monitor_base #(tvip_apb_master_item); 19 | `tue_component_default_constructor (tvip_apb_master_monitor) 20 | `uvm_component_utils(tvip_apb_master_monitor) 21 | endclass 22 | `endif 23 | -------------------------------------------------------------------------------- /src/tvip_apb_master_agent.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MASTER_AGENT_SVH 17 | `define TVIP_APB_MASTER_AGENT_SVH 18 | class tvip_apb_master_agent extends tue_param_agent #( 19 | tvip_apb_configuration , tvip_apb_status , tvip_apb_master_item, 20 | tvip_apb_master_monitor, tvip_apb_master_sequencer, tvip_apb_master_driver 21 | ); 22 | `tue_component_default_constructor(tvip_apb_master_agent) 23 | `uvm_component_utils(tvip_apb_master_agent) 24 | endclass 25 | `endif 26 | -------------------------------------------------------------------------------- /src/tvip_apb_pkg.sv: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_PKG_SV 17 | `define TVIP_APB_PKG_SV 18 | 19 | `include "tvip_apb_macros.svh" 20 | `include "tvip_apb_if.sv" 21 | 22 | package tvip_apb_pkg; 23 | import uvm_pkg::*; 24 | import tue_pkg::*; 25 | 26 | `include "uvm_macros.svh" 27 | `include "tue_macros.svh" 28 | 29 | `include "tvip_apb_types.svh" 30 | `include "tvip_apb_configuration.svh" 31 | `include "tvip_apb_status.svh" 32 | `include "tvip_apb_item.svh" 33 | `include "tvip_apb_monitor_base.svh" 34 | 35 | `include "tvip_apb_master_monitor.svh" 36 | `include "tvip_apb_master_sequencer.svh" 37 | `include "tvip_apb_master_driver.svh" 38 | `include "tvip_apb_master_agent.svh" 39 | 40 | `include "tvip_apb_master_ral_adapter.svh" 41 | `include "tvip_apb_master_ral_predictor.svh" 42 | endpackage 43 | `endif 44 | -------------------------------------------------------------------------------- /src/tvip_apb_types.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_TYPES_SVH 17 | `define TVIP_APB_TYPES_SVH 18 | 19 | typedef bit [`TVIP_APB_MAX_ADDRESS_WIDTH-1:0] tvip_apb_address; 20 | typedef bit [`TVIP_APB_MAX_DATA_WIDTH-1:0] tvip_apb_data; 21 | typedef bit [`TVIP_APB_MAX_DATA_WIDTH/8-1:0] tvip_apb_strobe; 22 | 23 | typedef enum bit { 24 | TVIP_APB_READ = 0, 25 | TVIP_APB_WRITE = 1 26 | } tvip_apb_direction; 27 | 28 | typedef enum bit { 29 | TVIP_APB_NORMAL_ACCESS = 0, 30 | TVIP_APB_PRIVILEGED_ACCESS = 1 31 | } tvip_apb_privileged_access; 32 | 33 | typedef enum bit { 34 | TVIP_APB_SECURE_ACCESS = 0, 35 | TVIP_APB_NON_SECURE_ACCESS = 1 36 | } tvip_apb_secure_access; 37 | 38 | typedef enum bit { 39 | TVIP_APB_DATA_ACCESS = 0, 40 | TVIP_APB_INSTRACTION_ACCESS = 1 41 | } tvip_apb_access_type; 42 | 43 | typedef virtual tvip_apb_if tvip_apb_vif; 44 | 45 | `endif 46 | -------------------------------------------------------------------------------- /src/tvip_apb_configuration.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_CONFIGURATION_SVH 17 | `define TVIP_APB_CONFIGURATION_SVH 18 | class tvip_apb_configuration extends tue_configuration; 19 | tvip_apb_vif vif; 20 | rand int address_width; 21 | rand int data_width; 22 | 23 | constraint c_valid_address_width { 24 | address_width inside {[1:32]}; 25 | address_width <= `TVIP_APB_MAX_ADDRESS_WIDTH; 26 | } 27 | 28 | constraint c_valid_data_width { 29 | data_width inside {8, 16, 32}; 30 | data_width <= `TVIP_APB_MAX_DATA_WIDTH; 31 | } 32 | 33 | virtual function bit apply_config_db( 34 | uvm_component context_component, string instance_name 35 | ); 36 | if (!uvm_config_db #(tvip_apb_vif)::get( 37 | context_component, instance_name, "vif", vif) 38 | ) begin 39 | return 0; 40 | end 41 | return 1; 42 | endfunction 43 | 44 | `tue_object_default_constructor(tvip_apb_configuration) 45 | `uvm_object_utils(tvip_apb_configuration) 46 | endclass 47 | `endif 48 | -------------------------------------------------------------------------------- /src/tvip_apb_master_ral_adapter.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MASTER_RAL_ADAPTER_SVH 17 | `define TVIP_APB_MASTER_RAL_ADAPTER_SVH 18 | class tvip_apb_master_ral_adapter extends uvm_reg_adapter; 19 | function new(string name = "tvip_apb_master_ral_adapter"); 20 | super.new(name); 21 | supports_byte_enable = 1; 22 | provides_responses = 0; 23 | endfunction 24 | 25 | virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw); 26 | tvip_apb_master_item apb_item = tvip_apb_master_item::type_id::create("apb_item"); 27 | apb_item.address = rw.addr; 28 | apb_item.direction = (rw.kind == UVM_WRITE) ? TVIP_APB_WRITE : TVIP_APB_READ; 29 | apb_item.set_protection(0); 30 | if (apb_item.is_write()) begin 31 | apb_item.data = rw.data; 32 | apb_item.strobe = rw.byte_en; 33 | end 34 | else begin 35 | apb_item.data = '0; 36 | apb_item.strobe = '0; 37 | end 38 | return apb_item; 39 | endfunction 40 | 41 | virtual function void bus2reg(uvm_sequence_item bus_item, ref uvm_reg_bus_op rw); 42 | tvip_apb_master_item apb_item; 43 | $cast(apb_item, bus_item); 44 | rw.addr = apb_item.address; 45 | rw.kind = (apb_item.is_write()) ? UVM_WRITE : UVM_READ; 46 | rw.byte_en = (apb_item.is_write()) ? apb_item.strobe : rw.byte_en; 47 | rw.data = apb_item.data; 48 | rw.status = (apb_item.slave_error) ? UVM_NOT_OK : UVM_IS_OK; 49 | endfunction 50 | 51 | `uvm_object_utils(tvip_apb_master_ral_adapter) 52 | endclass 53 | `endif 54 | -------------------------------------------------------------------------------- /src/tvip_apb_if.sv: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_IF_SV 17 | `define TVIP_APB_IF_SV 18 | 19 | `include "tvip_apb_macros.svh" 20 | 21 | interface tvip_apb_if ( 22 | input logic pclk, 23 | input logic preset_n 24 | ); 25 | localparam int AW = `TVIP_APB_MAX_ADDRESS_WIDTH; 26 | localparam int DW = `TVIP_APB_MAX_DATA_WIDTH; 27 | 28 | logic psel; 29 | logic penable; 30 | logic [AW-1:0] paddr; 31 | logic [2:0] pprot; 32 | logic pwrite; 33 | logic [DW-1:0] pwdata; 34 | logic [DW/8-1:0] pstrb; 35 | logic pready; 36 | logic [DW-1:0] prdata; 37 | logic pslverr; 38 | logic pack; 39 | 40 | assign pack = (psel && penable && pready) ? 1 : 0; 41 | 42 | clocking master_cb @(posedge pclk); 43 | output psel; 44 | output penable; 45 | output paddr; 46 | output pprot; 47 | output pwrite; 48 | output pwdata; 49 | output pstrb; 50 | input pready; 51 | input prdata; 52 | input pslverr; 53 | input pack; 54 | endclocking 55 | 56 | clocking slave_cb @(posedge pclk); 57 | input psel; 58 | input penable; 59 | input paddr; 60 | input pprot; 61 | input pwrite; 62 | input pwdata; 63 | input pstrb; 64 | output pready; 65 | output prdata; 66 | output pslverr; 67 | input pack; 68 | endclocking 69 | 70 | clocking monitor_cb @(posedge pclk); 71 | input psel; 72 | input penable; 73 | input paddr; 74 | input pprot; 75 | input pwrite; 76 | input pwdata; 77 | input pstrb; 78 | input pready; 79 | input prdata; 80 | input pslverr; 81 | input pack; 82 | endclocking 83 | 84 | function automatic void reset_master(); 85 | psel = '0; 86 | penable = '0; 87 | paddr = '0; 88 | pprot = '0; 89 | pwrite = '0; 90 | pwdata = '0; 91 | pstrb = '0; 92 | endfunction 93 | 94 | event master_cb_edge; 95 | event slave_cb_edge; 96 | event monitor_cb_edge; 97 | 98 | always @(master_cb) begin 99 | ->master_cb_edge; 100 | end 101 | 102 | always @(slave_cb) begin 103 | ->slave_cb_edge; 104 | end 105 | 106 | always @(monitor_cb) begin 107 | ->monitor_cb_edge; 108 | end 109 | endinterface 110 | 111 | `endif 112 | -------------------------------------------------------------------------------- /src/tvip_apb_monitor_base.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MONITOR_BASE_SVH 17 | `define TVIP_APB_MONITOR_BASE_SVH 18 | class tvip_apb_monitor_base #( 19 | type ITEM = tvip_apb_master_item 20 | ) extends tue_param_monitor #( 21 | tvip_apb_configuration, tvip_apb_status, ITEM 22 | ); 23 | protected tvip_apb_vif vif; 24 | 25 | function void build_phase(uvm_phase phase); 26 | super.build_phase(phase); 27 | vif = configuration.vif; 28 | endfunction 29 | 30 | task run_phase(uvm_phase phase); 31 | forever begin 32 | do_reset(); 33 | fork 34 | monitor_thread(); 35 | @(negedge vif.preset_n); 36 | join_any 37 | disable fork; 38 | end 39 | endtask 40 | 41 | virtual protected task do_reset(); 42 | wait (vif.preset_n === 1); 43 | endtask 44 | 45 | virtual protected task monitor_thread(); 46 | ITEM item; 47 | 48 | forever begin 49 | wait_for_psel(); 50 | item = create_item("item"); 51 | 52 | wait_for_penable(); 53 | sample_request(item); 54 | 55 | wait_for_pready(); 56 | sample_response(item); 57 | write_item(item); 58 | end 59 | endtask 60 | 61 | virtual protected task wait_for_psel(); 62 | do begin 63 | @(vif.monitor_cb); 64 | end while (!vif.monitor_cb.psel); 65 | endtask 66 | 67 | virtual protected task wait_for_penable(); 68 | @(vif.master_cb); 69 | endtask 70 | 71 | virtual protected function void sample_request(ITEM item); 72 | item.address = vif.monitor_cb.paddr; 73 | item.direction = tvip_apb_direction'(vif.monitor_cb.pwrite); 74 | item.privileged_access = tvip_apb_privileged_access'(vif.monitor_cb.pprot[0]); 75 | item.secure_access = tvip_apb_secure_access'(vif.monitor_cb.pprot[1]); 76 | item.access_type = tvip_apb_access_type'(vif.monitor_cb.pprot[2]); 77 | if (item.is_write()) begin 78 | item.data = vif.monitor_cb.pwdata; 79 | item.strobe = vif.monitor_cb.pstrb; 80 | end 81 | endfunction 82 | 83 | virtual protected task wait_for_pready(); 84 | while (!vif.monitor_cb.pready) begin 85 | @(vif.monitor_cb); 86 | end 87 | endtask 88 | 89 | virtual protected function void sample_response(ITEM item); 90 | item.slave_error = vif.monitor_cb.pslverr; 91 | if (item.is_read()) begin 92 | item.data = vif.monitor_cb.prdata; 93 | end 94 | endfunction 95 | 96 | `tue_component_default_constructor(tvip_apb_monitor_base) 97 | endclass 98 | `endif 99 | -------------------------------------------------------------------------------- /src/tvip_apb_master_driver.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_MASTER_DRIVER_SVH 17 | `define TVIP_APB_MASTER_DRIVER_SVH 18 | class tvip_apb_master_driver extends tue_driver #( 19 | tvip_apb_configuration, tvip_apb_status, tvip_apb_master_item 20 | ); 21 | protected tvip_apb_vif vif; 22 | protected tvip_apb_master_item current_item; 23 | 24 | function void build_phase(uvm_phase phase); 25 | super.build_phase(phase); 26 | vif = configuration.vif; 27 | endfunction 28 | 29 | task run_phase(uvm_phase phase); 30 | forever begin 31 | do_reset(); 32 | fork 33 | driver_thread(); 34 | @(negedge vif.preset_n); 35 | join_any 36 | disable fork; 37 | end 38 | endtask 39 | 40 | protected virtual task do_reset(); 41 | if (current_item != null) begin 42 | finish_item(); 43 | end 44 | 45 | vif.reset_master(); 46 | wait (vif.preset_n); 47 | endtask 48 | 49 | protected virtual task driver_thread(); 50 | int ipg; 51 | 52 | forever begin 53 | wait_for_next_item(); 54 | drive_request(); 55 | wait_for_done(); 56 | sample_response(); 57 | drive_idle(); 58 | 59 | ipg = current_item.get_ipg(); 60 | finish_item(); 61 | 62 | repeat (ipg) begin 63 | @(vif.master_cb_edge); 64 | end 65 | end 66 | endtask 67 | 68 | protected virtual task wait_for_next_item(); 69 | seq_item_port.get_next_item(current_item); 70 | void'(begin_tr(current_item)); 71 | if (!vif.master_cb_edge.triggered) begin 72 | @(vif.master_cb_edge); 73 | end 74 | endtask 75 | 76 | protected virtual task drive_request(); 77 | vif.master_cb.psel <= '1; 78 | vif.master_cb.paddr <= current_item.address; 79 | vif.master_cb.pwrite <= current_item.is_write(); 80 | vif.master_cb.pprot <= current_item.get_protection(); 81 | if (current_item.is_write()) begin 82 | vif.master_cb.pwdata <= current_item.data; 83 | vif.master_cb.pstrb <= current_item.strobe; 84 | end 85 | 86 | @(vif.master_cb_edge); 87 | vif.master_cb.penable <= '1; 88 | endtask 89 | 90 | protected virtual task wait_for_done(); 91 | do begin 92 | @(vif.master_cb_edge); 93 | end while (!vif.master_cb.pready); 94 | endtask 95 | 96 | protected virtual task sample_response(); 97 | current_item.slave_error = vif.master_cb.pslverr; 98 | if (current_item.is_read()) begin 99 | current_item.data = vif.master_cb.prdata; 100 | end 101 | endtask 102 | 103 | protected virtual task drive_idle(); 104 | vif.master_cb.psel <= '0; 105 | vif.master_cb.penable <= '0; 106 | endtask 107 | 108 | protected virtual function void finish_item(); 109 | end_tr(current_item); 110 | seq_item_port.item_done(); 111 | current_item = null; 112 | endfunction 113 | 114 | `tue_component_default_constructor(tvip_apb_master_driver) 115 | `uvm_component_utils(tvip_apb_master_driver) 116 | endclass 117 | `endif 118 | -------------------------------------------------------------------------------- /src/tvip_apb_item.svh: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2017 Taichi Ishitani 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //------------------------------------------------------------------------------ 16 | `ifndef TVIP_APB_ITEM_SVH 17 | `define TVIP_APB_ITEM_SVH 18 | class tvip_apb_item extends tue_sequence_item #( 19 | .CONFIGURATION (tvip_apb_configuration ), 20 | .STATUS (tvip_apb_status ) 21 | ); 22 | rand tvip_apb_address address; 23 | rand tvip_apb_direction direction; 24 | rand tvip_apb_data data; 25 | rand tvip_apb_strobe strobe; 26 | rand tvip_apb_privileged_access privileged_access; 27 | rand tvip_apb_secure_access secure_access; 28 | rand tvip_apb_access_type access_type; 29 | rand bit slave_error; 30 | rand int ipg; 31 | 32 | constraint c_valid_ipg { 33 | ipg >= -1; 34 | } 35 | 36 | constraint c_default_ipg { 37 | soft ipg == -1; 38 | } 39 | 40 | constraint c_valid_address { 41 | (address >> this.configuration.address_width) == '0; 42 | } 43 | 44 | constraint c_valid_write_data { 45 | if (direction == TVIP_APB_WRITE) { 46 | (data >> this.configuration.data_width) == '0; 47 | } 48 | else { 49 | data == 0; 50 | } 51 | } 52 | 53 | constraint c_valid_strobe { 54 | if (direction == TVIP_APB_WRITE) { 55 | (strobe >> (this.configuration.data_width / 8)) == 0; 56 | } 57 | else { 58 | strobe == 0; 59 | } 60 | } 61 | 62 | constraint c_valid_read_data { 63 | if (direction == TVIP_APB_READ) { 64 | (data >> this.configuration.data_width) == 0; 65 | } 66 | } 67 | 68 | function bit is_read(); 69 | return (direction == TVIP_APB_READ) ? 1 : 0; 70 | endfunction 71 | 72 | function bit is_write(); 73 | return (direction == TVIP_APB_WRITE) ? 1 : 0; 74 | endfunction 75 | 76 | function bit [2:0] get_protection(); 77 | bit [2:0] protection; 78 | protection[0] = privileged_access; 79 | protection[1] = secure_access; 80 | protection[2] = access_type; 81 | return protection; 82 | endfunction 83 | 84 | function void set_protection(bit [2:0] protection); 85 | privileged_access = tvip_apb_privileged_access'(protection[0]); 86 | secure_access = tvip_apb_secure_access'(protection[1]); 87 | access_type = tvip_apb_access_type'(protection[0]); 88 | endfunction 89 | 90 | function int get_ipg(); 91 | return (ipg >= 0) ? ipg : 0; 92 | endfunction 93 | 94 | `tue_object_default_constructor(tvip_apb_item) 95 | `uvm_object_utils_begin(tvip_apb_item) 96 | `uvm_field_int(address, UVM_DEFAULT | UVM_HEX) 97 | `uvm_field_enum(tvip_apb_direction, direction, UVM_DEFAULT) 98 | `uvm_field_int(data , UVM_DEFAULT | UVM_HEX) 99 | `uvm_field_int(strobe, UVM_DEFAULT | UVM_BIN) 100 | `uvm_field_enum(tvip_apb_privileged_access, privileged_access, UVM_DEFAULT) 101 | `uvm_field_enum(tvip_apb_secure_access , secure_access , UVM_DEFAULT) 102 | `uvm_field_enum(tvip_apb_access_type , access_type , UVM_DEFAULT) 103 | `uvm_field_int(slave_error, UVM_DEFAULT | UVM_BIN) 104 | `uvm_field_int(ipg, UVM_DEFAULT | UVM_DEC | UVM_NOCOMPARE) 105 | `uvm_object_utils_end 106 | endclass 107 | 108 | class tvip_apb_master_item extends tvip_apb_item; 109 | function void pre_randomize(); 110 | slave_error.rand_mode(0); 111 | c_valid_read_data.constraint_mode(0); 112 | endfunction 113 | 114 | `tue_object_default_constructor(tvip_apb_master_item) 115 | `uvm_object_utils(tvip_apb_master_item) 116 | endclass 117 | 118 | class tvip_apb_slave_item extends tvip_apb_item; 119 | function void pre_randomize(); 120 | direction.rand_mode(0); 121 | address.rand_mode(0); 122 | c_valid_address.constraint_mode(0); 123 | data.rand_mode(is_read()); 124 | c_valid_write_data.constraint_mode(0); 125 | c_valid_read_data.constraint_mode(is_read()); 126 | strobe.rand_mode(0); 127 | c_valid_strobe.constraint_mode(0); 128 | privileged_access.rand_mode(0); 129 | secure_access.rand_mode(0); 130 | access_type.rand_mode(0); 131 | endfunction 132 | 133 | `tue_object_default_constructor(tvip_apb_slave_item) 134 | `uvm_object_utils(tvip_apb_slave_item) 135 | endclass 136 | `endif 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------