ECE 368 CAD-Based Logic Design Shantanu Dutt Lecture 11 File I/O and Textio in VHDL (courtesy of Karam Chatha, ASU)

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

Introduction to C Programming
Lectures 10 & 11.
VHDL in digital circuit synthesis (tutorial) dr inż. Miron Kłosowski EA 309
INTRO TO VHDL Appendix A: page page VHDL is an IEEE and ANSI standard. VHDL stands for Very High Speed IC hardware description language.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Digital Design with VHDL Presented by: Amir Masoud Gharehbaghi
1 Lecture 13 VHDL 3/16/09. 2 VHDL VHDL is a hardware description language. The behavior of a digital system can be described (specified) by writing a.
Test Bench Un test bench es una entidad que no tiene declaraciones de puertos. Consiste en una arquitectura que contiene una instancia del componente a.
1 H ardware D escription L anguages Basic Input/Output.
Signals vs. Variables Workshop Fri/Sat Test bench creation Misc IP Cores Chipscope Pro When Demos due.
CIS 101: Computer Programming and Problem Solving Lecture10 Usman Roshan Department of Computer Science NJIT.
Data Types. Composite Date Types n Arrays –Single and multi-dimensional –Arrays are single Type n Records –Records are mixed types.
SubprogramsSubprograms. SubprogramsSubprograms ä Similar to subprograms found in other languages ä Allow repeatedly used code to be referenced multiple.
ELEN 468 Lecture 191 ELEN 468 Advanced Logic Design Lecture 19 VHDL.
Topics of Lecture Structural Model Procedures Functions Overloading.
ECE C03 Lecture 141 Lecture 14 VHDL Modeling of Sequential Machines Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
(1) Basic Input and Output © Sudhakar Yalamanchili, Georgia Institute of Technology, 2006.
Concordia University 1 Lecture #8 In this lecture we will cover the following material: The standard package, The std_logic_1164  Objects & data Types.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
10/17/2015DSD, USIT, GGSIPU1 Data Types Each data object has a type associated with it. The type defines the set of values that the object can have and.
IAY 0600 Digital Systems Design
VHDL Project I: Introduction to Testbench Design Matthew Murach Slides Available at:
VHDL FLI. FLI Definition FLI routines are C programming language functions that provide procedural access to information within the HDL simulator.
VHDL Files & Text IO ECE4623/5623 Computer Hardware Design.
RTL Hardware Design by P. Chu Chapter Basic VHDL program 2. Lexical elements and program format 3. Objects 4. Data type and operators RTL Hardware.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHDL – Basic Language Elements  Identifiers: –basic identifier: composed of a sequence of one or more.
George Mason University ECE 545 – Introduction to VHDL Variables, Functions, Memory, File I/O ECE 545 Lecture 7.
Lecture #8 Page 1 Lecture #8 Agenda 1.VHDL : Operators 2.VHDL : Signal Assignments Announcements 1.HW #4 assigned ECE 4110– Digital Logic Design.
Copyright(c) 1996 W. B. Ligon III1 Getting Started with VHDL VHDL code is composed of a number of entities Entities describe the interface of the component.
VHDL Very High Speed Integrated Circuit Hardware Description Language Shiraz University of shiraz spring 2011.
INTRO TO VLSI DESIGN (CPE 448) (VHDL Tutorial ) Prof: Asuif Mahmood.
Topics AliasesSubprograms Generics & Configurations.
1 VLSI Design & Reconfigurable Computing ENG*6090(3) Advanced Topics in VHDL Stephen Coe Guangfa Lu Friday, March 07, 2003.
EE694v-Verification-Lect6-1- Lecture 6 - Writing Tests A difference if treating the design as a black box or if you have access to internal signals EE762.
VHDL Basics. VHDL BASICS 2 OUTLINE –Component model –Code model –Entity –Architecture –Identifiers and objects –Operations for relations VHDL ET062G &
L13 – VHDL Language Elements. VHDL Language Elements  Elements needed for FPGA design Types  Basic Types  Resolved Types – special attributes of resolved.
Lecture #7 Page 1 Lecture #7 Agenda 1.VHDL Data Types Announcements 1.n/a ECE 4110– Digital Logic Design.
Aliases Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.
04/26/20031 ECE 551: Digital System Design & Synthesis Lecture Set : Introduction to VHDL 12.2: VHDL versus Verilog (Separate File)
VHDL Discussion Subprograms IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
ECOM 4311—Digital System Design with VHDL
Subprograms Lecture 6. Subprograms A subprogram defines a sequential algorithm that performs some computations. Subprograms can be: –1. functions –2.
EE694v-Verification-Lect6-1- Lecture 6 - Writing Tests A difference if treating the design as a black box or if you have access to internal signals EE762.
Advanced FPGA Based System Design Lecture-6 & 7 VHDL Data Types By: Dr Imtiaz Hussain 1.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Modern Digital System Design Using VHDL: A Practical Introduction Subprograms & Packages Dr. Aiman H. El-Maleh Computer Engineering Department King Fahd.
Files A collection of related data treated as a unit. Two types Text
Case Study: Xilinx Synthesis Tool (XST). Arrays & Records 2.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
1/20/ L8 Language Overview III Copyright Joanne DeGroat, ECE, OSU1 Language Overview III The finish of a grand tour of the language.
George Mason University Advanced Testbenches Lecture 4.
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
Chapter 8. Additional Topics in VHDL 권동혁.
ECE 448 – FPGA and ASIC Design with VHDL George Mason University ECE 448 Lab 2 Implementing Combinational Logic in VHDL.
Introduction To VHDL 홍 원 의.
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
CPE 528: Session #7 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
ECE 434 Advanced Digital System L17
CPE/EE 422/522 Advanced Logic Design L15
ECE 434 Advanced Digital System L9
ECE 434 Advanced Digital System L10
VHDL Discussion Subprograms
CPE 528: Lecture #3 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
VHDL Discussion Subprograms
Design units Lecture 2.
Data Types Each data object has a type associated with it.
EEL4712 Digital Design (VHDL Tutorial).
Presentation transcript:

ECE 368 CAD-Based Logic Design Shantanu Dutt Lecture 11 File I/O and Textio in VHDL (courtesy of Karam Chatha, ASU)

Files In all the testbenches we created so far, the test stimuli were coded inside each testbench. Hence, if we need to change the test stimuli we need to modify the model or create a new model. Input and output files can be used to get around this problem.

File Definition and Declaration file_type_defn <= type file_type_name is file of type_mark ; A file class needs to be defined before it can be used. Once defined, a file object can be declared. type integer _file is file of integer ; file_decl <= file id {, …} : subtype_indication [ [ open file_open_kind ] is string_expr ; file table: integer _file open read_mode is “table.dat” ; type file_open_kind is (read_mode, write_mode, append_mode);

File reading Given a file definition, VHDL implicitly provides the following subprograms: type file_type is file of element_type; procedure read ( file f: file_type; value : out element_type; length : out natural); function endfile ( file f: file_type ) return boolean; If the length of the element is greater than the length of the actual data on the file, it is placed left justified in the element.

Example p1: process is type bit_vector_file is file of bit_vectors; file vectors: bit_vector_file open read_mode is “vec.dat”; variable next_vector : bit_vector (63 downto 0); variable actual_len: natural; begin while not endfile(vectors) loop read (vectors,next_vector,actual_len); if actual_len > next_vector’length then report “vector too long”; else for bit_index in 1 to actual_len loop …. end loop; end if; end loop; wait; end process;

File writing Given a file definition, VHDL implicitly provides the following subprograms: type file_type is file of element_type; procedure write ( file f: file_type; value : in element_type);

Problem Description Write a process description that writes the data of integer type from an input signal to a file. Assume that the input signal “s1” is an “in” port of the top level entity. Assume the file name to be “out.dat”.

Example P1: process (s1) is type integer_file is file of integer; file out_file: integer_file open write_mode is “out.dat”; begin write (out_file,s1); end;

Files in Subprograms In all the examples of file I/O thus far, files are opened at the start of simulation, and automatically closed at end of simulation. However, for files declared in subprograms, files are opened and closed at each invocation of the subprogram.

Example function read_array (file_name: string; len: natural) return integer_vector is type integer_file is file of integer; file data_file: integer_file open read_mode is file_name; variable result: integer_vector(1 to len); variable index: integer := 1; begin while not endfile(data_file) and index <= len loop read(data_file, result(index)); index:= index + 1; end loop; return result; end;

File open and close In the examples discussed thus far: we have opened the files at definition. we have implicitly closed the files. VHDL permits explicit opening and closing of files.

File open and close procedure file_open (status : out file_open_status; file f: file_type; extern_name: in string; open_kind : in file_open_mode := read_mode); type file_open_status is (open_ok, status_error, name_error, mode_error); VHDL provides two implicit procedures: procedure file_close (file f: file_type);

Open errors status_error: file object previously open and associated with a physical file. name_error: in read mode indicates file does not exist. in write mode indicates file cannot be created. in append mode indicates both. mode_error: indicates file cannot be opened in the specified mode.

File procedure parameters procedure read_transform (file f: transform_file; variable transform : out transform_array) is begin for i in transform’range(1) loop for j in transform’range(2) loop if endfile(f) then report “unexpected end of file” severity error; return end if; read (f,transform(i,j)); end loop; end; VHDL does not permit reading or writing of 2-D arrays.

Package textio The file that we have created can read only one type of objects. The package textio provides useful functions for reading general text files. The package is part of the standard library “std”.

Package textio type line is access string; type text is file of string; type side is (right,left); subtype width is natural; file input: text open read_mode is “std_input”; file output: text open write_mode is “std_output”; procedure readline (file f: text; L: inout line); procedure writeline (file f: text; L: inout line);

Using textio procedures The type “access” denotes a pointer in VHDL. textio works with a pointer to a line of text or string. A pointer is an object that has the starting address of the line of text. Pointer String “readline” and “writeline” read and write an entire string that is pointed to by the pointer.

textio read procedures procedure read (L : inout line; value: out bit; good: out boolean); procedure read (L : inout line; value: out bit_vector; good: out boolean); procedure read (L : inout line; value: out boolean; good: out boolean); procedure read (L : inout line; value: out character; good: out boolean); procedure read (L : inout line; value: out integer; good: out boolean); procedure read (L : inout line; value: out real; good: out boolean); procedure read (L : inout line; value: out string; good: out boolean); procedure read (L : inout line; value: out time; good: out boolean);

textio read operation Every read operation that reads a data type other than “character” skips whitespace (ws) characters: Space, Tab. Reading a character does not skip ws chars since they are legitimate characters; if they need to be skipped, then that does need to be done explicitly at the point of the ws character w/ a read: read(L,c), where “c” is of type character. If the line contains the following items: fred “cat” a 10 ns readline(file_id,L); read (L,s); -- L is a string, s is a string read (L,s); read (L,bv); -- bv is a bit_vector read (L,i); -- i is an integer read (L,r); -- r is a real read (L,c); read(L,c); -- c is a character read (L,t); -- t is a time

textio write procedures procedure write (L : inout line; value: in bit; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in bit_vector; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in boolean; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in character; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in integer; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in real; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in string; justified: in side := right; field: in width := 0); procedure write (L : inout line; value: in time; justified: in side := right; field: in width; unit: in time:= ns);

textio write operation write (L,i,left,5); -- L is a line, i = 45 write (L,’ ‘); write (L,i,right,5); write (L,’ ‘); write (L,”fred”); write (L,’ ‘); write (L,”101”); write (L,’ ‘); write (L,r,left,3); -- r = write (L,’ ‘); write (L,t,left,0,ms); -- t = 23 micro secs writeline(file_id,L); 45bbb bbb45 fred ms