I can tell

I can tell from your eye, i just can.

Can say nothing about that.

類別:Uncategorized

Transcript of Commencement Speech at Stanford given by Steve Jobs

Thank you. I’m honored to be with you today for your commencement from one of the finest universities in the world. Truth be told, I never graduated from college and this is the closest I’ve ever gotten to a college graduation.

Today I want to tell you three stories from my life. That’s it. No big deal. Just three stories. The first story is about connecting the dots.

I dropped out of Reed College after the first six months but then stayed around as a drop-in for another eighteen months or so before I really quit. So why did I drop out? It started before I was born. My biological mother was a young, unwed graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife, except that when I popped out, they decided at the last minute that they really wanted a girl. So my parents, who were on a waiting list, got a call in the middle of the night asking, 『We’ve got an unexpected baby boy. Do you want him?』 They said, 『Of course.』 My biological mother found out later that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would go to college.

This was the start in my life. And seventeen years later, I did go to college, but I naïvely chose a college that was almost as expensive as Stanford, and all of my working-class parents’ savings were being spent on my college tuition. After six months, I couldn’t see the value in it. I had no idea what I wanted to do with my life, and no idea of how college was going to help me figure it out, and here I was, spending all the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back, it was one of the best decisions I ever made. The minute I dropped out, I could stop taking the required classes that didn’t interest me and begin dropping in on the ones that looked far more interesting.

It wasn’t all romantic. I didn’t have a dorm room, so I slept on the floor in friends’ rooms. I returned Coke bottles for the five-cent deposits to buy food with, and I would walk the seven miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example.

Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer was beautifully hand-calligraphed. Because I had dropped out and didn’t have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and sans-serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can’t capture, and I found it fascinating.

None of this had even a hope of any practical application in my life. But ten years later when we were designing the first Macintosh computer, it all came back to me, and we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts, and since Windows just copied the Mac, it’s likely that no personal computer would have them.

If I had never dropped out, I would have never dropped in on that calligraphy class and personals computers might not have the wonderful typography that they do.

Of course it was impossible to connect the dots looking forward when I was in college, but it was very, very clear looking backwards 10 years later. Again, you can’t connect the dots looking forward. You can only connect them looking backwards, so you have to trust that the dots will somehow connect in your future. You have to trust in something–your gut, destiny, life, karma, whatever–because believing that the dots will connect down the road will give you the confidence to follow your heart, even when it leads you off the well-worn path, and that will make all the difference.

My second story is about love and loss. I was lucky. I found what I loved to do early in life. Woz and I started Apple in my parents’ garage when I was twenty. We worked hard and in ten years, Apple had grown from just the two of us in a garage into a $2 billion company with over 4,000 employees. We’d just released our finest creation, the Macintosh, a year earlier, and I’d just turned thirty, and then I got fired. How can you get fired from a company you started? Well, as Apple grew, we hired someone who I thought was very talented to run the company with me, and for the first year or so, things went well. But then our visions of the future began to diverge, and eventually we had a falling out. When we did, our board of directors sided with him, and so at thirty, I was out, and very publicly out. What had been the focus of my entire adult life was gone, and it was devastating. I really didn’t know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down, that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure and I even thought about running away from the Valley. But something slowly began to dawn on me. I still loved what I did. The turn of events at Apple had not changed that one bit. I’d been rejected but I was still in love. And so I decided to start over.

I didn’t see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods in my life. During the next five years I started a company named NeXT, another company named Pixar and fell in love with an amazing woman who would become my wife. Pixar went on to create the world’s first computer-animated feature film, 『Toy Story,』 and is now the most successful animation studio in the world.

In a remarkable turn of events, Apple bought NeXT and I returned to Apple and the technology we developed at NeXT is at the heart of Apple’s current renaissance, and Lorene and I have a wonderful family together.

I’m pretty sure none of this would have happened if I hadn’t been fired from Apple. It was awful-tasting medicine but I guess the patient needed it. Sometimes life’s going to hit you in the head with a brick. Don’t lose faith. I’m convinced that the only thing that kept me going was that I loved what I did. You’ve got to find what you love, and that is as true for work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work, and the only way to do great work is to love what you do. If you haven’t found it yet, keep looking, and don’t settle. As with all matters of the heart, you’ll know when you find it, and like any great relationship it just gets better and better as the years roll on. So keep looking. Don’t settle.

My third story is about death. When I was 17 I read a quote that went something like 『If you live each day as if it was your last, someday you’ll most certainly be right.』 It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself, 『If today were the last day of my life, would I want to do what I am about to do today?』 And whenever the answer has been 『no』 for too many days in a row, I know I need to change something. Remembering that I’ll be dead soon is the most important thing I’ve ever encountered to help me make the big choices in life, because almost everything–all external expectations, all pride, all fear of embarrassment or failure–these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.

About a year ago, I was diagnosed with cancer. I had a scan at 7:30 in the morning and it clearly showed a tumor on my pancreas. I didn’t even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctors’ code for 『prepare to die.』 It means to try and tell your kids everything you thought you’d have the next ten years to tell them, in just a few months. It means to make sure that everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.

I lived with that diagnosis all day. Later that evening I had a biopsy where they stuck an endoscope down my throat, through my stomach into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated but my wife, who was there, told me that when they viewed the cells under a microscope, the doctor started crying, because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and, thankfully, I am fine now.

This was the closest I’ve been to facing death, and I hope it’s the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept. No one wants to die, even people who want to go to Heaven don’t want to die to get there, and yet, death is the destination we all share. No one has ever escaped it. And that is as it should be, because death is very likely the single best invention of life. It’s life’s change agent; it clears out the old to make way for the new. right now, the new is you. But someday, not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it’s quite true. Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma, which is living with the results of other people’s thinking. Don’t let the noise of others’ opinions drown out your own inner voice, heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.

When I was young, there was an amazing publication called The Whole Earth Catalogue, which was one of the bibles of my generation. It was created by a fellow named Stuart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late Sixties, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and Polaroid cameras. it was sort of like Google in paperback form thirty-five years before Google came along. I was idealistic, overflowing with neat tools and great notions. Stuart and his team put out several issues of the The Whole Earth Catalogue, and then when it had run its course, they put out a final issue. It was the mid-Seventies and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath were the words, 『Stay hungry, stay foolish.』 It was their farewell message as they signed off. 『Stay hungry, stay foolish.』 And I have always wished that for myself, and now, as you graduate to begin anew, I wish that for you. Stay hungry, stay foolish.

Thank you all, very much.

 

類別:Uncategorized

Time goes by

Time goes by, you knew that, it’s life.

I am not sure, maybe today is the day i was preparing the oral defense in NTUST.

Never can forget that days, i grew up in that time. If you want to learn something, you learn from yourself.

In company, in society now, there are a lot of thing  that i am not ready to accept.

There are kinds of people, some you like, some you even hate them.

Some positive, some negative, which you want to be? You need to think of that, do not be affected from anybody, it’s really important.

As a mankind, I have to say, eff off. I am on my own side.

類別:Uncategorized

Initial data for behavioral memory

module rom_32_16k( clka, addra, douta );
input                                clka;
input               [13:0]    addra;
output reg    [31:0]    douta;
reg                   [31:0]    rom [16383:0];
integer i;
always@(posedge clka)
begin

douta <= rom[addra];
end
initial
$readmemb(『rom_32_16k.mif』,rom);

endmodule

可以在ISE, Modelsim下做 behavioral、Post xxx simulation

類別:IC, Uncategorized

Weakness

我所缺少的 就是一個夢想

類別:Uncategorized

Artisan Memory Generator

1. source memgen.csh

2. Instance Name
Number of Words -> depth
Number of Bits -> width
Frequency<MHz> -> 200
Ring Width<um> -> 10

3. Utilities -> Write Spec
//For second time use
ra1sh -spec xxx.spec

4. Utilities -> Generate Menu
PostScript Datasheet -> 操作說明書
Verilog Model -> Only for Behavioral Simulation
Synopsys Model -> For Design Compiler
VCLEF Footprint -> For APR, fake layout
GDSII Layout -> Real layout, but we can’t use

5. Translate *.lib to *.db for Design Compiler
dc_shell-t> read_lib xxx.lib
dc_shell-t> write_lib xxx -output xxx.db

6. Setting .synopsys_dc.setup
set search_path 『$memory_path』
set link_library 『xxx.db』
set target_library 『xxx.db』

7.Using Memory Module
modeule y();
sram_xxx yyy(,,,);
endmodule;
//No need sram_xxx.v in design compiler project
//it’s a module in library

類別:IC, Uncategorized

Reading and writing files from Verilog models

Introduction

This describes how you can read and write files in a Verilog model using a set of user functions, based on the C stdio package. With these functions you can perform file input and output directly in Verilog models without having to learn C or the PLI. This code works with VCS, MTI, Verilog-XL, and NC-Verilog (see $fread for one restriction).

Overview

This application note describes how your Verilog model or testbench can read text and binary files to load memories, apply stimulus, and control simulation. Files can also be written. The format of the file I/O functions is based on the C stdio routines, such as fopen, fgetc, fprintf, and fscanf.

The Verilog language has a rich set of system functions to write files ($fdisplay, $fwrite, etc.) but only reads files with a single, fixed format ($readmem). In the past if you wanted to read a file that was not in $readmem format, you would have to learn the Programming Language Interface (PLI) and the C language, write C code to read the file and pass values into Verilog, then debug the combined C and Verilog code. In addition, the Verilog is limited to 32 open files at a time.

However, using the new file I/O system functions you can perform your file I/O directly from Verilog. You can write Verilog HDL to:

  • read stimulus files to apply patterns to the inputs of a model
  • read a file of expected values for comparison with your model
  • read a script of commands to drive a simulation
  • read either ASCII or binary files into Verilog registers and memories
  • have hundreds of log files open simultaneously (though they are written to one at a time)

Code for all the examples in this file is included in the examples directory for the file I/O functions.

Note that these system tasks behave the same as the equivalent stdio routines. For example, $fscanf will skip over white-space, including blank lines, just like fscanf(). You can prototype code in C then convert it to Verilog.


Differences between fileio and IEEE-1364 Verilog-2001 (V2K) standard

The following list describes the differences between my file I/O package (fileio) and the IEEE-1364 Verilog-2001 standard (V2K).

1) In fileio $fopen has read, write, append variants:
file = $fopenr("filename");
file = $fopenw("filename");
file = $fopena("filename");

In V2K, there is a single $fopen for both multi-channel descriptors (MCD) and file descriptors (FD).  Whether an FD or MCD is produced is indicated by the presence of a mode string added to $fopen in V2K:
file = $fopen("filename", "w");    // FD
file = $fopen("filename");         // MCD

Fileio supports the V2K $fopen format under a package compilation switch but that then blocks any use of MCDs since it hides the builtin $fopen.

2) Fileio $fclose has read and write variants that return a status:
r = $fcloser(file);
r = $fclosew(file);

In V2K, there is a single $fclose for both MCDs and FDs.  It does not return a status.  Errors can be determined by using $ferror.

Fileio supports the V2K $fclose format under a package compilation switch but that then blocks any use of MCDs since it hides the builtin $fclose.

3) Fileio $getchar is not directly supported in Verilog-2001.  The operation can be done by using $fgetc(‘h8000_0000) which makes use of the reserved FD for stdin.

4) Fileio defines $fgets as:
r = $fgets(string, n, file);

V2K does not support a maximum count 『n』 of characters to read. Input in V2K always terminates at end of line and then string assignment to the target is done.

Fileio’s $gets is not directly supported in Verilog 2001.  The operation can be done by using:
$fgets(string, 'h8000_0000);
that makes use of the reserved FD for stdin.

5) Fileio $scanf is not directly supported in Verilog 2001.  The operation can be done by using:
$fscanf('h8000_0000, format, args);
which makes use of the reserved FD for stdin.

6) Fileio does not support ? as an alias for X; V2K does.

7) Fileio does not support reading X or Z for %d format specification; V2K does.

8) Fileio supports %f, but not the synonyms %e and %g.  V2K supports all three.  Fileio does not support %f on in $sscanf; V2K supports all specifiers in $sscanf.

9) Fileio does not support %u, %z, %v, %t, or %m input format specifiers; V2K supports all of them.

10) Fileio supports special character input handling for \ (i.e. \\, \oNNN); V2K does not support this (not in LRM).

11) Fileio requires that $fread on a memory use 『mem[0]』 as the memory referend.  V2K requires 『mem』 since 『mem[0]』 will be taken as a register read.

12) Fileio defines $sprintf and $fprintf which are not defined in V2K.  V2K defines the $swrite family of tasks for string ouput and allows both MCDs and FDs in the $fwrite, $fdisplay, $fmonitor, and $fstrobe families of tasks.  V2K supports $sformat where the difference in $sformat and $swrite is in the management of format specification strings.  Fileio requires a single format string in $sprintf, etc; V2K follows the normal Verilog convention of treating any constant strings as format specifiers for $swrite.  In V2K, all output format specifications are consistent and produce the same result independent of whether the target is a string, file, or standard output.

13) Fileio $ferror only returns a status.  V2k $ferror takes a second parameter and stores the error string in that register.  Additionally, V2K $ferror accepts a file descriptor with the value 0 and simple produces the most recent system error status.

14) Fileio requires an argument to $fflush; V2K permits a parameterless call and flushes all files (including MCD files) in that case.  V2K $fflush supports either MCDs or FDs.

15) V2K supports $rewind which Fileio does not.

16) Fileio supports $fputc which V2K does not.

17) Fileio supports $feof which V2K does not.  Some functions such as $fgetc return EOF (-1) but this is not the same.


File Input Functions

The file I/O system functions and tasks are based on the C stdio routines. For more information on the stdio routines, consult a C manual. The major differences between these system tasks and C are caused by the lack of a pointer variable in the Verilog language. Strings in Verilog are stored in registers, with 8 bits needed to store a single character.

OPEN A FILE

integer file;
file = $fopenr("filename");
file = $fopenw("filename");
file = $fopena("filename");

The function $fopenr opens an existing file for reading. $fopenw opens a new file for writing, and $fopena opens a new file for writing where any data will be appended to the end of the file. The file name can be either a quoted string or a reg holding the file name. If the file was successfully opened, it returns an integer containing the file number (1..MAX_FILES) or NULL (0) if there was an error. Note that these functions are not the same as the built-in system function $fopen which opens a file for writing by $fdisplay. The files are opened in C with ‘rb’, ‘wb’, and ‘ab’ which allows reading and writing binary data on the PC. The ‘b’ is ignored on Unix.

CLOSE A FILE

integer file, r;
r = $fcloser(file);
r = $fclosew(file);

The function $fcloser closes a file for input. $fclosew closes a file for output. It returns EOF if there was an error, otherwise 0. Note that these are not the same as $fclose which closes files for writing.

TEST FOR END OF FILE

integer file;
reg eof;
eof = $feof(file);

The function $feof tests for end of file. If an end-of-file has been reached while reading from the file, a non-zero value is returned; otherwise, a 0 is returned.

RETURN FILE STATUS

integer file;
reg error;
error = $ferror(file);

The function $ferror returns the error status of a file. If an error has occurred while reading from a file, $ferror returns a non-zero value, else 0. The error value is returned once, then reset to 0.

READ A SINGLE CHARACTER

integer file, char;
char = $fgetc(file);
char = $getc();

The function $fgetc reads a single character from the specified file and returns it. If the end-of-file is reached, $fgetc returns EOF. You should use a 32-bit register to hold the result from $fgetc to tell the difference between the character with the value 255 and EOF. $getc reads from stdin.

PUSH BACK A CHARACTER

integer file;
reg [7:0] char, r;
r = $ungetc(char, file);

The function $ungetc pushes the character back into the file stream. That character will be the next read by $fgetc. It returns the character if it was successfully pushed back or EOF if it fails.

Note that since there is no $ungetc for stdin in C, there will not be one in the file I/O package.

WRITE A SINGLE CHARACTER

integer stream, r, char;
r = $fputc(stream, char);

The function $fputc writes a single character to the specified file. It returns EOF if there was an error, 0 otherwise.

READ A STRING

integer file, n, r;
reg [n*8-1:0] string;
r = $fgets(string, n, file);
r = $gets(string);

The function $fgets reads a string from the file. Characters are read from the file into string until a newline is seen, end-of-file is reached, or n-1 characters have been read. If the end-of-file is encountered, $fgets returns a 0 and string is unchanged; otherwise, $fgets returns a 1. $gets reads from stdin.

The function $gets is no longer supported by default in fileio v3.4. If you want to use it, you must compile fileio.c with -DGETS. This is because some C compilers will give an error message when compiling fileio.c:


fileio.o: In function `fileio_gets_call`:
fileio.o: the gets function is dangerous and should not be used

You can either ignore this message, or stop using -DGETS to remove the gets function call from fileio.c.

READ FORMATTED TEXT

integer file, count;
count = $fscanf(file, format, args);
count = $sscanf(string, format, args);
count = $scanf(format, args);

The function $fscanf parses formatted text from the file according to the format and writes the results to args. $sscanf parses formatted text from a string. $scanf parses formated text from stdin. See a C reference manual for detailed information on fscanf, plus examples later in this note.

The format can be either a string constant or a reg. It can contain:

  • Whitespace characters such as space, tab (\t), or newline (\n). One or more whitespace characters are treated as a single character, and can match zero or more whitespace characters from the input.
  • Conversion specifications which start with a %. Next is an optional *, which suppresses assignment. Then is an optional field width in decimal. Lastly is the operator character as follows:
  • b — Binary values 0, 1, X, x, Z, z, _
  • d — Decimal values 0-9, _, no X, x, Z, or z. Note that negative numbers are NOT supported because of a Verilog language limitation.
  • o — Octal values 0-7, _, X, x, Z, z
  • h or x — Hexadecimal values, 0-9, A-F, a-f, _, X, x, Z, z
  • c — A single character
  • f — A floating point number, no _, X, x, Z, or z
  • s — A string
  • % — The percent character
  • Other characters which must match the characters read from the file. Special characters are \』 for the 』 character, \\ for the \ character, \oNNN is a single character whose ASCII value is specified by the octal number NNN, and %% for the character %.

The args is an optional list of registers to be assigned by $fscanf, $sscanf, and $scanf. There must be a register for each conversion operator (except those with %*). Bit subscripts are ignored.

Formatting & padding is closer to Verilog than C. For example, %x of 16′h24 is ’0024′, not ’24′, and %0x returns ’24′, not ’0024′.

$fscanf, $sscanf, and $scanf return the number of successful assignments performed. If you do not want a return value from these routines, compile fileio.c (and veriuser.c for Cadence users) with -Dscanf_task. VCS users should switch from fileio.tab to fileio_task.tab

FIND THE FILE POSITION

integer file, position;
position = $ftell(file);

The function $ftell returns the position in the file for use by $fseek. If there is an error, it returns a -1.

POSITION A FILE

`define SEEK_SET 0
`define SEEK_CUR 1
`define SEEK_END 2
integer file, offset, position, r;
r = $fseek(file, 0, `SEEK_SET); /* Beginning */
r = $fseek(file, 0, `SEEK_CUR); /* No effect */
r = $fseek(file, 0, `SEEK_END); /* End of file */
r = $fseek(file, position, `SEEK_SET); /* Previous loc */

The function $fseek allows random access in a file. You can position at the beginning or end of a file, or use the position returned from $ftell.

READ BINARY DATA

integer r, file, start, count;
reg [15:0] mem[0:10], r16;
r = $fread(file, mem[0], start, count);
r = $fread(file, r16);

The function $fread reads a binary file into a Verilog memory. The first argument is either a register or a memory name, which must have a subscript, though the value of the subscript is ignored. start and count are optional.

By default $fread will store data in the first data location through the final location. For the memory up[10:20], the first location loaded would be up[10], then up[11]. For down[20:10], the first location would be down[10], then down[11].

start and count are ignored if $fread storing data in a reg instead of a memory. No warning is printed if the file contains more data than will fit in the memory.

start is the word offset from the lowest element in the memory. For start = 2 and the memory up[10:20], the first data would be loaded at up[12]. For the memory down[20:10] , the first location loaded would be down[12], then down[13].

$fread returns the number of elements read from the file, If $fread terminates early because of an error, it will return the number of elements successfully read. $feof can be used to determine whether the end-of-file was reached during $fread.

The data in the file is broken into bytes according to the width of the memory. An 8-bit wide memory takes one byte per location, while a 9-bit wide memory takes 2 bytes. Care should be taken when using memories with widths not evenly divisible by 8 as there may be gaps in the data in the memory vs. data in the file.

The $fread system task only works with NC-Verilog if you use the -MEMPACK switch as in:

ncverilog +ncvlogargs+-NOMEMPACK foo.v

WRITING A FORMATTED STRING

integer file, r, a, b;
reg [80*8:1] string;
file = $fopenw("output.log");
r = $sformat(string, "Formatted %d %x", a, b);
r = $sprintf(string, "Formatted %d %x", a, b);
r = $fprintf(file, "Formatted %d %x", a, b);

The functions $sformat and $sprintf writes a formatted string into a Verilog register.  The two functions are identical. $fprintf writes a formatted string to a file.  It has most, but not the formatting capabilites of C stdio package.  The first argument is a register to receive the formatted data, and the second is a format string.  Additional arguments may be included.

The supported formats include b, c, d, e, f, g, h, m, o, r, s, and x. %t for printing formatted time is NOT supported yet.

FLUSHING THE FILE STREAM

integer file, r;
file = $fopenw("output.log");
r = $fflush(file);

The function $fflush(stream) causes any buffered data waiting to be written for the named stream to be written to that file. If the stream is 0, all files open for writing are flushed.


Restrictions and Caveats

You should be aware of following restrictions in using these Verilog functions vs. the stdio functions in C, which are imposed by the Verilog language :

  • Because these are Verilog system functions, you must always use the return value as in:

r = $fscanf(...)

  • Verilog does not allow assignments inside a conditional. Thus the C code fragment:
while (c=fgetc(stream) != EOF) {
    <process input>
    }

turns into the Verilog code:

c = $fgetc(file);
while (c !== `EOF)
    begin
    <process input>
    c = $fgetc(file);
    end
  • $fgets and $gets return only a single bit, 0 = error, 1 = no error, unlike fgets / gets in C, which return a string pointer.
  • $fread is very different from fread in C. The order of arguments is different, and the arguments are oriented towards writing to a Verilog memory instead of a C character string. See page 5 for more info.
  • $fscanf can not be used to read binary files, or any files with null characters. $fprintf can not be used to write binary files with null characters. Because of the string processing that $fscanf uses, a null in the middle of an ASCII field will prematurely terminate the field.

In addition, $save / $restart are loosely supported with VCS on SunOS. In a test, $feof never returned EOF when running from a save file, but $fgetc did. On other simulators and hardware platforms you can mimic these functions using $ftell and $fseek to find the position in a file and later jump to that location.

The maximum number of files (MAX_FILES) is set in the C code to 12. The maximum string size is 1000 characters. There is no known limit to the number of conversion operators in $fscanf or $sscanf.


Reading pattern files

This first example shows how to read input stimulus from a text file.

This is the pattern file – read_pattern.pat , included in the examples directory:

// This is a pattern file
// time bin dec hex
10: 001 1 1
20.0: 010 20 020
50.02: 111 5 FFF
62.345: 100 4 DEADBEEF
75.789: XXX 2 ZzZzZzZz

Note that the binary and hexadecimal values have X and Z values, but these are not allowed in the decimal values. You can use white space when formatting your file to make it more readable. Lastly, any line beginning with a / is treated as a comment.

The module read_pattern.v reads the time for the next pattern from an ASCII file. It then waits until the absolute time specified in the input file, and reads the new values for the input signals (bin, dec, hex). The time in the file is a real value and, when used in a delay, is rounded according to the timescale directive. Thus the time 75.789 is rounded to 75.79 ns.

`timescale 1ns / 10 ps
`define EOF 32'hFFFF_FFFF
`define NULL 0
`define MAX_LINE_LENGTH 1000

module read_pattern;
integer file, c, r;
reg [3:0] bin;
reg [31:0] dec, hex;
real real_time;
reg [8*`MAX_LINE_LENGTH:0] line; /* Line of text read from file */

initial
    begin : file_block
    $timeformat(-9, 3, "ns", 6);
    $display("time bin decimal hex");
    file = $fopenr("read_pattern.pat");
    if (file == `NULL) // If error opening file
        disable file_block; // Just quit

    c = $fgetc(file);
    while (c != `EOF)
        begin
        /* Check the first character for comment */
        if (c == "/")
            r = $fgets(line, `MAX_LINE_LENGTH, file);
        else
            begin
            // Push the character back to the file then read the next time
            r = $ungetc(c, file);
            r = $fscanf(file," %f:\n", real_time);

            // Wait until the absolute time in the file, then read stimulus
            if ($realtime > real_time)
                $display("Error - absolute time in file is out of order - %t",
                        real_time);
                else
                    #(real_time - $realtime)
                        r = $fscanf(file," %b %d %h\n",bin,dec,hex);
                end // if c else
            c = $fgetc(file);
        end // while not EOF

    r = $fcloser(file);
    end // initial

// Display changes to the signals
always @(bin or dec or hex)
    $display("%t %b %d %h", $realtime, bin, dec, hex);

endmodule // read_pattern

Comparing outputs with expected results

The following model, compare.v, reads a file containing both
stimulus and expected results. The input signals are toggled at the
beginning of a clock cycle and the output is compared just before the
end of the cycle.
`define EOF 32'hFFFF_FFFF
`define NULL 0
`define MAX_LINE_LENGTH 1000
module compare;
integer file, r;
reg a, b, expect, clock;
wire out;
reg [`MAX_LINE_LENGTH*8:1];
parameter cycle = 20;

initial
    begin : file_block
    $display("Time Stim Expect Output");
    clock = 0;

    file = $fopenr("compare.pat");
    if (file == `NULL)
        disable file_block;

    r = $fgets(line, MAX_LINE_LENGTH, file); // Skip comments
    r = $fgets(line, MAX_LINE_LENGTH, file);

    while (!$feof(file))
        begin
        // Wait until rising clock, read stimulus
        @(posedge clock)
        r = $fscanf(file, " %b %b %b\n", a, b, expect);

        // Wait just before the end of cycle to do compare
        #(cycle - 1)
        $display("%d %b %b %b %b", $stime, a, b, expect, out);
        $strobe_compare(expect, out);
        end // while not EOF

    r = $fcloser(file);
    $stop;
    end // initial

always #(cycle / 2) clock = !clock; // Clock generator

and #4 (out, a, b); // Circuit under test
endmodule // compare

Reading script files

Sometimes a detailed simulation model for a device is not available, such as a microprocessor. As a substitute, you can write a bus-functional model which reads a script of bus transactions and performs these actions. The following, script.v, reads a file with commands plus data values.

`define EOF 32'hFFFF_FFFF
`define NULL 0
module script;
integer file, r;
reg [80*8:1] command;
reg [31:0] addr, data;

initial
    begin : file_block
    clock = 0;

    file = $fopenr("script.txt");
    if (file == `NULL)
        disable file_block;

    while (!$feof(file))
        begin
        r = $fscanf(file, " %s %h %h \n", command, addr, data);
        case (command)
        "read":
            $display("READ mem[%h], expect = %h", addr, data);
        "write":
            $display("WRITE mem[%h] = %h", addr, data);
        default:
            $display("Unknown command '%0s'", command);
        endcase
        end // while not EOF

    r = $fcloser(file);
    end // initial
endmodule // script

The file script.txt is the script read by the above model:

read 9 0
write 300a feedface
read 2FF xxxxxxxx
bad

Reading data files into memories

Reading a formatted ASCII file is easy with the system tasks. The following
is an example of reading a binary file into a Verilog memory. $fread can
also read a file one word at a time and copy the word into memory, but
this is about 100 times slower than using $fread to read the entire array
directly.
This is the file load_mem.v

`define EOF 32'HFFFF_FFFF
`define MEM_SIZE 200_000

module load_mem;

integer file, i;
reg [7:0] mem[0:`MEM_SIZE];
reg [80*8:1] file_name;

initial
    begin
    file_name = "data.bin";
    file = $fopenr(file_name);
    i = $fread(file, mem[0]);
    $display("Loaded %0d entries \n", i);
    i = $fcloser(file);
    $stop;
    end

endmodule // load_mem

The file data.bin contains the 200 binary values 0 to 199. You can
look at the program data.c which generated the file. To dump out the binary
file in Unix use the command od data.bin

類別:IC, Uncategorized

The Blower’s Daughter

Artist(Band):Damien Rice

And so it is
Just like you said it would be
Life goes easy on me
Most of the time
And so it is
The shorter story
No love, no glory
No hero in her skies

I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes…

And so it is
Just like you said it should be
We’ll both forget the breeze
Most of the time
And so it is
The colder water
The blower’s daughter
The pupil in denial

I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes off you
I can’t take my eyes…

Did I say that I loathe you?
Did I say that I want to
Leave it all behind?

I can’t take my mind off you
I can’t take my mind off you…
I can’t take my mind off you
I can’t take my mind off you
I can’t take my mind off you
I can’t take my mind…
My mind…my mind…
‘Til I find somebody new

類別:Uncategorized

投機珠璣集, by Andre’ Kostolany

人不必有資本, 但要有零用錢, 有些人甚至認為零用錢比財富更重要.
作多傻瓜能承受股市下跌的損失, 卻無法承受股市上漲而錯過的獲利.
任何沒有自己見解的人, 就不能投入股市.
對猶豫不決的人來說, 行情不是太高就是太低; 而決定不是太晚就是太早.
對行情發展重要的不是今天發生的事, 而是明天和後天將發生的事. 因為今天發生的事已經被行情吸收.
多數擁有賺大錢特質的人, 卻不具備享受金錢的特質.
股市上人人皆知的東西不會令我坐立不安.

節錄: 一個投機者的告白之 金錢遊戲

類別:Uncategorized

About ADS: the 『tracer』, handle trace file

Using AXD
In ADS, press Debug into AXD,
Select System Views -> Debugger Internals -> Internal Variables,
and then double-click on the $rdi_log value to edit it:
To enable tracing, set $rdi_log to 0×00000010
To disable tracing, set $rdi_log to 0×00000000.

Configuring Tracer
File: peripherals.ami
What I need is to trace instruciotns,
Setting:
TraceInstructions= True
OpcodeFetch =Ture
If you need to trace OpcodeFetch, you need to trace instructions first.
————————————————————–
AXD ‘s configure target -> ARMUL -> Configure
Variant : ARM9TDMI
Clock : Real-time
Floating Point Emulation : None
Debug Endian : Little
Start target Endian : Debug Endian
Memory Map File : No Map File
FPU : NO_FPU
Pagetab : Default

類別:IC, Uncategorized
Follow

Get every new post delivered to your Inbox.