Sunteți pe pagina 1din 4

Introduction to Digital Systems ELEC245

Session 10 K. Joseph Hass


Electrical Engineering Bucknell University

Basic Verilog File IO


$fopen(lename,[accesstype ]); $fscanf (lehandle,format spec,[value ],[value ],. . . ); $fdisplay(lehandle,[format spec ],[value ],[value ],. . . ); $fwrite(lehandle,[format spec ],[value ],[value ],. . . ); $fmonitor(lehandle,[format spec ],[value ],[value ],. . . ); $fclose([lehandle ]);

Basic Verilog File IO


Opening and Closing Files

integer MyFileHandle; MyFileHandle = $fopen(MyFileName,MyAccessType); $fclose(MyFileHandle); Access Type r or rb w or wb a or ab Meaning Open text or binary le for reading Open text or binary le for write Open text or binary le for appending

Basic Verilog File IO


Reading From Text Files

r e a l MyNumber ; integer i ; i = 1; w h i l e ( i > 0) begin @( posedge C h a n g e I n p u t s ) ; i=$ f s c a n f ( M y I n p u t F i l e , %f , MyNumber ) ; end %b %h %t %m %v binary hexadecimal time module name strength %d %s %c %f %e decimal string character real exponential

The $fscanf should return 1 at end-of-le. . . this is broken in Xilinx ISE Version 11. . . use $feof instead.

Basic Verilog File IO


Writing To A Text File

integer MyFileDescriptor ; r e a l MyNumber ; M y F i l e D e s c r i p t o r = $ fopen ( MyFileName , w ) ; always @( posedge O u t p u t S t r o b e ) $ f d i s p l a y ( M y F i l e D e s c r i p t o r , %f , MyNumber ) ; $fwrite is similar to $fdisplay but does not append an end-of-line.

Basic Verilog File IO


Writing To Multiple Text Streams

parameter STDOUT = 1 ; i n t e g e r MyMCD; // A m u l t i c h a n n e l d e s c r i p t o r r e a l MyNumber ; MyMCD = $ fopen ( MyFileName ) ; // no a c c e s s t y p e always @( posedge O u t p u t S t r o b e ) ; $ f d i s p l a y ( (MyMCD | STDOUT) , %f , MyNumber ) ; end Note that $fdisplay (STDOUT, %f, MyNumber); is equivalent to $display(%f, MyNumber); and similar equivalents exist for $fwrite and $fmonitor.

Basic Verilog File IO


Monitors

initial $ monitor ( A= %h t i m e= %t , MySig , $ r e a l t i m e ) ; A monitor prints whenever one of the specied variables changes. Only one monitor can be active at any time. Using $fmonitor with a le handle writes to a le

Other Verilog File IO


Other verilog commands for le IO include Read and write binary (rather than text les)
Command syntax is OS dependent File format (big endian or little endian) is OS dependent

Write when signal becomes stable ($fstrobe) Read, write, and display without format string
Default format is decimal Final character of command is default format (e.g. $writeb for binary)

Access by characters rather than lines Arbitrary positioning of read/write pointers

S-ar putea să vă placă și