aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/python-console/modified/pyinterpreter.cc
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/python-console/modified/pyinterpreter.cc')
0 files changed, 0 insertions, 0 deletions
n54'>54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
------------------------------------------------------------
-- Copyright (c) 2019 by Paul Scherrer Institute, Switzerland
-- All rights reserved.
------------------------------------------------------------

------------------------------------------------------------
-- Testbench generated by TbGen.py
------------------------------------------------------------
-- see Library/Python/TbGenerator

------------------------------------------------------------
-- Libraries
------------------------------------------------------------
library ieee;
	use ieee.std_logic_1164.all;
	use ieee.numeric_std.all;
	use ieee.math_real.all;

library work;
	use work.psi_common_math_pkg.all;
	use work.psi_common_logic_pkg.all;
	use work.psi_common_i2c_master_pkg.all;

library work;
	use work.psi_tb_compare_pkg.all;
	use work.psi_tb_activity_pkg.all;
	use work.psi_tb_txt_util.all;
	use work.psi_tb_i2c_pkg.all;

------------------------------------------------------------
-- Entity Declaration
------------------------------------------------------------
entity psi_common_i2c_master_tb is
	generic (
		InternalTriState_g : boolean := true
	);
end entity;

------------------------------------------------------------
-- Architecture
------------------------------------------------------------
architecture sim of psi_common_i2c_master_tb is
	-- *** Fixed Generics ***
	constant ClockFrequency_g : real := 125.0e6;
	constant I2cFrequency_g : real := 1.0e6;
	constant BusBusyTimeout_g : real := 50.0e-6;
	constant CmdTimeout_g : real := 10.0e-6;
	
	-- *** Not Assigned Generics (default values) ***
	
	-- *** TB Control ***
	signal TbRunning : boolean := True;
	signal NextCase : integer := -1;
	signal ProcessDone : std_logic_vector(0 to 1) := (others => '0');
	constant AllProcessesDone_c : std_logic_vector(0 to 1) := (others => '1');
	constant TbProcNr_stim_c : integer := 0;
	constant TbProcNr_i2c_c : integer := 1;
	signal StimCase : integer := -1;
	signal I2cCase : integer := -1;
	
	-- *** DUT Signals ***
	signal Clk : std_logic := '1';
	signal Rst : std_logic := '1';
	signal CmdRdy : std_logic := '0';
	signal CmdVld : std_logic := '0';
	signal CmdType : std_logic_vector(2 downto 0) := (others => '0');
	signal CmdData : std_logic_vector(7 downto 0) := (others => '0');
	signal CmdAck : std_logic := '0';
	signal RspVld : std_logic := '0';
	signal RspData : std_logic_vector(7 downto 0) := (others => '0');
	signal RspType : std_logic_vector(2 downto 0) := (others => '0');
	signal RspArbLost : std_logic := '0';
	signal RspAck : std_logic := '0';
	signal RspSeq : std_logic := '0';
	signal BusBusy : std_logic := '0';
	signal TimeoutCmd : std_logic := '0';
	signal I2cScl : std_logic := '0';
	signal I2cSda : std_logic := '0';
	signal I2cScl_I : std_logic := '0';
	signal I2cScl_O : std_logic := '0';
	signal I2cScl_T : std_logic := '0';
	signal I2cSda_I : std_logic := '0';
	signal I2cSda_O : std_logic := '0';
	signal I2cSda_T : std_logic := '0';
	
	-- *** Helper Functions ***
	procedure WaitForCase(	signal TestCase : in integer;
							Value 			: in integer) is
	begin
		if TestCase /= Value then
			wait until TestCase = Value;
		end if;
	end procedure;
	
	procedure ApplyCmd(	Command			: in	std_logic_vector(2 downto 0);
						Data			: in	std_logic_vector(7 downto 0);
						Ack				: in	std_logic;
						signal CmdVld	: out	std_logic;
						signal CmdRdy	: in	std_logic;
						signal CmdType	: out	std_logic_vector(2 downto 0);
						signal CmdData	: out	std_logic_vector(7 downto 0);
						signal CmdAck	: out	std_logic) is
	begin
		wait until rising_edge(Clk);
		CmdVld <= '1';
		CmdType <= Command;
		CmdData <= Data;
		CmdAck  <= Ack;
		wait until rising_edge(Clk) and CmdRdy = '1';
		CmdVld <= '0';
		CmdType	<= (others => '0');
		CmdData <= (others => '0');
		CmdAck  <= '0';
	end procedure;
	
	procedure CheckRsp(	Command				: in	std_logic_vector(2 downto 0);
						Data				: in	std_logic_vector;
						Ack					: in	std_logic;
						ArbLost				: in	std_logic;						
						signal RspVld		: in	std_logic;
						signal RspData		: in	std_logic_vector(7 downto 0);
						signal RspType		: in	std_logic_vector(2 downto 0);
						signal RspArbLost	: in	std_logic;
						signal RspAck		: in	std_logic;
						signal RspSeq		: in	std_logic;
						Msg					: in	string := "No Msg";
						Err					: in	std_logic := '0') is
	begin
		wait until rising_edge(Clk) and RspVld = '1';
		StdlvCompareStdlv(Command, RspType, "Response: Wrong Type - " & Msg);
		if Data /= "X" then
			StdlvCompareStdlv(Data, RspData, "Response: Wrong Data - " & Msg);
		end if;
		if Ack /= 'X' then
			StdlCompare(choose(Ack = '1', 1, 0), RspAck, "Response: Wrong Ack - " & Msg);
		end if;
		if ArbLost /= 'X' then
			StdlCompare(choose(ArbLost = '1', 1, 0), RspArbLost, "Response: Wrong ArbLost - " & Msg);
		end if;		
		StdlCompare(choose(Err = '1', 1, 0), RspSeq, "Response: Wrong Err - " & Msg);
	end procedure;

begin
	------------------------------------------------------------
	-- DUT Instantiation
	------------------------------------------------------------
	i_dut : entity work.psi_common_i2c_master
		generic map (
			ClockFrequency_g => ClockFrequency_g,
			I2cFrequency_g => I2cFrequency_g,
			BusBusyTimeout_g => BusBusyTimeout_g,
			CmdTimeout_g => CmdTimeout_g,
			InternalTriState_g => InternalTriState_g,
			DisableAsserts_g => true
		)
		port map (
			Clk => Clk,
			Rst => Rst,
			CmdRdy => CmdRdy,
			CmdVld => CmdVld,
			CmdType => CmdType,
			CmdData => CmdData,
			CmdAck => CmdAck,
			RspVld => RspVld,
			RspType => RspType,
			RspArbLost => RspArbLost,
			RspData => RspData,
			RspAck => RspAck,
			RspSeq => RspSeq,
			BusBusy => BusBusy,
			TimeoutCmd => TimeoutCmd,
			I2cScl => I2cScl,
			I2cSda => I2cSda,
			I2cScl_I => I2cScl_I,
			I2cScl_O => I2cScl_O,
			I2cScl_T => I2cScl_T,
			I2cSda_I => I2cSda_I,
			I2cSda_O => I2cSda_O,
			I2cSda_T => I2cSda_T
		);
		
	------------------------------------------------------------
	-- I2C Emulation
	------------------------------------------------------------		
	I2cPullup(I2cScl, I2cSda);
	g_triState : if not InternalTriState_g generate
		I2cScl <= 'Z' when I2cScl_T = '1' else I2cScl_O;
		I2cScl_I <= To01X(I2cScl);
		I2cSda <= 'Z' when I2cSda_T = '1' else I2cSda_O;
		I2cSda_I <= To01X(I2cSda);
	end generate;
	
	------------------------------------------------------------
	-- Testbench Control !DO NOT EDIT!
	------------------------------------------------------------
	p_tb_control : process
	begin
		wait until Rst = '0';
		wait until ProcessDone = AllProcessesDone_c;
		TbRunning <= false;
		wait;
	end process;
	
	------------------------------------------------------------
	-- Clocks !DO NOT EDIT!
	------------------------------------------------------------
	p_clock_Clk : process
		constant Frequency_c : real := real(125e6);
	begin
		while TbRunning loop
			wait for 0.5*(1 sec)/Frequency_c;
			Clk <= not Clk;
		end loop;
		wait;
	end process;
	
	
	------------------------------------------------------------
	-- Resets
	------------------------------------------------------------
	p_rst_Rst : process
	begin
		wait for 1 us;
		-- Wait for two clk edges to ensure reset is active for at least one edge
		wait until rising_edge(Clk);
		wait until rising_edge(Clk);
		Rst <= '0';
		wait;
	end process;
	
	
	------------------------------------------------------------
	-- Processes
	------------------------------------------------------------
	-- *** stim ***
	p_stim : process
	begin
		I2cSetFrequency(I2cFrequency_g);
		-- start of process !DO NOT EDIT
		wait until Rst = '0';
		wait until rising_edge(Clk);
		
		-- *** Test Bus Busy ***
		print(">> Test Bus Busy");
		StimCase <= 0;	
		wait until rising_edge(Clk);		
		WaitForCase(I2cCase, 0);
		wait for 10 us;
		
		-- *** Test Start / Repeated-Start / Stop ***
		print(">> Test Start / Repeated-Start / Stop");
		StimCase <= 1;	
		wait until rising_edge(Clk);
		ApplyCmd(CMD_START, 	X"00", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_START, 	"X", 'X', '0', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Start");
		ApplyCmd(CMD_REPSTART, 	X"00", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_REPSTART, 	"X", 'X', '0', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Start");
		ApplyCmd(CMD_STOP, 		X"00", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_STOP, 		"X", 'X', '0', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Stop");		
		WaitForCase(I2cCase, 1);
		wait for 10 us;
		
		-- *** Test Write ***
		print(">> Test Write");
		StimCase <= 2;	
		wait until rising_edge(Clk);
		
		-- 1Byte ACK
		ApplyCmd(CMD_START, 	X"00", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_START, 	"X", 'X', 'X', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Start 1b ACK");
		ApplyCmd(CMD_SEND, 		X"A3", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_SEND, 		"X", '1', '0', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Start 1b ACK");
		ApplyCmd(CMD_STOP, 		X"00", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_STOP, 		"X", 'X', 'X', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Stop 1b ACK");			
		
		-- 2Byte ACK, then NACK
		ApplyCmd(CMD_START, 	X"00", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_START, 	"X", 'X', 'X', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Start 2b ACK -> NACK");
		ApplyCmd(CMD_SEND, 		X"12", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);
		CheckRsp(CMD_SEND, 		"X", '1', '0', RspVld, RspData, RspType, RspArbLost, RspAck, RspSeq, "Start 2b ACK -> NACK 1");
		ApplyCmd(CMD_SEND, 		X"34", 'X', CmdVld, CmdRdy, CmdType, CmdData, CmdAck);