
3.7. HOW TO GET STARTED WRITING/EXECUTING C PROGRAMS
41
• synthdir/foo.syr: Synthesis report
• synthdir/foo_map.mrp: Map report
• synthdir/foo.par: Place and Route report
• synthdir/foo.twr: Timing analyzer report
(Where foo is the name of the top level file you compiled, as in dafk or lab1).
3.7 How to get Start ed Writing/Executing C Programs
A good starting point is the program simpleprog situated in the directory firmware.
It can be compiled with make in Linux.
The executable file is simpleprog.hex which can be downloaded with the com-
mand l in the monitor and File->Send Raw File in gtkterm. You run the program
with g 2000 or just g.
The size of the DRAM is 64 MB, so there is plenty of room for your program.
You can check the length of the program by looking inside the file simpleprog.txt,
which is a disassembled version of simpleprog. The length of simpleprog is 2800
bytes.
3.7.1 A Note on Volatile
Normally, the compiler assumes that memory locations will not change unless the pro-
gram itself changes it. This assumption does not hold when the program tries to access
I/O memory. For example, in the following code shown in Listing 3.3, the programmer
wants the program to wait until pin 1 of the parallel port is set to 1. The problem is
that an optimizing compiler will generate assembler code doing approximately what is
shown in Listing 3.4.
Listing 3.3: Volatile is not used for memory mapped I/O.
unsigned i n t ∗p a r p o r t = 0 x91000000 ;
w h i l e ( ( ∗ p a r p o r t & 0 x1 ) ! = 1 ) ; / ∗ Busy w a i t ∗/
Listing 3.4: Resulting assembler from code in Listing 3.3.
LOAD R0 , [ 0 x91000000 ] ; Load v a l u e fr o m memory
AND R0 , R0 , 0 x1 ; And R0 w i t h 1
CMP R0 , 0 x1 ; Compare R0 w i t h 1
lo o p :
BNEQ lo op ; Jump t o l o o p i f R0 was n o t e q u a l t o 1
This is certainly not what the programmer had in mind. This kind of error is even
more insidious because in some cases it might work ok and in some cases it will fail
sporadically and in some cases it might not work at all. It will also depend on the
optimization level of the compiler. The correct way to deal with this situation is to tell
the C compiler that the memory location can change at any time. This will force the
compiler to generate code that reloads the memory location every time it is referenced.
This can be done using the volatile keyword. We recommend that you use the
Komentarze do niniejszej Instrukcji