Altera DE1-SoC Manual Download Page 13

DE1-S

O

C C

OMPUTER

S

YSTEM WITH

N

IOS

II

For Quartus II 15.0

/********************************************************************************

* Subroutine to read a character from the JTAG UART
* Returns

\

0 if no character, otherwise returns the character

********************************************************************************/

char

get_jtag(

void

)

{

volatile int

* JTAG_UART_ptr = (

int

*) 0xFF201000; // JTAG UART address

int

data;

data = *(JTAG_UART_ptr);

// read the JTAG_UART data register

if

(data & 0x00008000)

// check RVALID to see if there is new data

return

((

char

) data & 0xFF);

else

return

(’

\

0’);

}

Figure 13. An example of C code that uses the JTAG UART (Part

b

).

2.6

Interval Timers

The DE1-SoC Computer includes a timer module implemented in the FPGA that can be used by the Nios II pro-
cessor. This timer can be loaded with a preset value, and then counts down to zero using a 100-MHz clock. The
programming interface for the timer includes six 16-bit registers, as illustrated in Figure

14

. The 16-bit register at

address

0xFF202000

provides status information about the timer, and the register at address

0xFF202004

allows

control settings to be made. The bit fields in these registers are described below:

TO

provides a timeout signal which is set to 1 by the timer when it has reached a count value of zero. The

TO

bit can be reset by writing a 0 into it.

RUN

is set to 1 by the timer whenever it is currently counting.

ITO

is used for generating interrupts, which are discussed in section

3

.

CONT

affects the continuous operation of the timer. When the timer reaches a count value of zero it auto-

matically reloads the specified starting count value. If

CONT

is set to 1, then the timer will continue counting

down automatically. But if

CONT

=

0

, then the timer will stop after it has reached a count value of 0.

• (

START

/

STOP

) is used to commence/suspend the operation of the timer by writing a 1 into the respective bit.

The two 16-bit registers at addresses

0xFF202008

and

0xFF20200C

allow the period of the timer to be changed

by setting the starting count value. The default setting provided in the DE1-SoC Computer gives a timer period
of 125 msec. To achieve this period, the starting value of the count is 100 MHz

×

125 msec

=

12.5

×

10

6

. It is

possible to capture a snapshot of the counter value at any time by performing a write to address

0xFF202010

. This

write operation causes the current 32-bit counter value to be stored into the two 16-bit timer registers at addresses

0xFF202010

and

0xFF202014

. These registers can then be read to obtain the count value.

A second interval timer, which has an identical interface to the one described above, is also available in the FPGA,
starting at the base address

0xFF202020

. Each Nios II processor has exclusive access to two interval timers.

Altera Corporation - University Program

2015

13

Summary of Contents for DE1-SoC

Page 1: ...tions for using the HPS and ARM processor are provided in a separate document called DE1 SoC Computer System with ARM Cortex A9 2 1 FPGA Components As shown in Figure 1 many of the components in the D...

Page 2: ...includes the DE1 SoC Computer as a predesigned system that can be downloaded onto the DE1 SoC board as well as several sample programs in assembly language and C that show how to use the DE1 SoC Comp...

Page 3: ...mplemented inside the FPGA that is used as a character buffer for the video out port which is described in Section 4 2 The character buffer memory is organized as 8K x 8 bits and spans the address ran...

Page 4: ...o parallel ports connected to the 7 segment displays on the DE1 SoC board each of which comprises a 32 bit write only Data register As indicated in Figure 4 the register at address 0xFF200020 drives d...

Page 5: ...nused KEY3 0 Edge bits Mask bits Unused Unused Unused Data register Interruptmask register Edgecapture register Unused Figure 6 Registers used in the pushbutton parallel port 2 4 5 Expansion Parallel...

Page 6: ...rograms perform the same operations and illustrate the use of parallel ports by using either assembly language or C code The code in the figures displays the values of the SW switches on the red light...

Page 7: ...movia r20 0xFF200020 HEX3_HEX0 base address movia r19 HEX_bits ldwio r6 0 r19 load pattern for HEX displays DO_DISPLAY ldwio r4 0 r15 load input from slider switches stwio r4 0 r16 write to red LEDs l...

Page 8: ...FF200040 SW slider switch address volatile int KEY_ptr int 0xFF200050 pushbutton KEY address int HEX_bits 0x0000000F initial pattern for HEX displays int SW_value volatile int delay_count volatile so...

Page 9: ...h is provided in bits 7 0 decrements the value of RAVAIL by one and returns this decremented value as part of the read operation If no data is present in the receive FIFO then RVALID will be set to 0...

Page 10: ...cter data back to the JTAG UART text executable code follows global _start _start set up stack pointer movia sp 0x03FFFFFC put stack at top of SDRAM movia r6 0xFF201000 JTAG UART base address print a...

Page 11: ...stw r4 0 sp save register ldwio r4 4 r6 read the JTAG UART Control register andhi r4 r4 0xffff check for write space beq r4 r0 END_PUT if no space ignore the character stwio r5 0 r6 send the character...

Page 12: ...TAG UART example code n 0 char str c print a text string for str text_string str 0 str put_jtag str read and echo characters while 1 c get_jtag if c 0 put_jtag c Subroutine to send a character to the...

Page 13: ...ly counting ITO is used for generating interrupts which are discussed in section 3 CONT affects the continuous operation of the timer When the timer reaches a count value of zero it auto matically rel...

Page 14: ...SoC Computer is set to 0x00000000 The address used for all other general exceptions such as divide by zero and hardware IRQ interrupts is 0x00000020 Since the Nios II processor uses the same address...

Page 15: ...hbutton parallel port The Interruptmask register allows inter rupts to be generated when a key is pressed Each bit in the Edgecapture register is set to 1 by the parallel port when the corresponding k...

Page 16: ...in the interval timer that causes an interrupt to occur every 33 msec equ KEY2 1 This program demonstrates use of interrupts in the DE1 SoC Computer It first starts the interval timer with 33 msec tim...

Page 17: ...show on the HEX displays global KEY_PRESSED KEY_PRESSED word KEY2 stores code representing pushbutton key pressed global SHIFT_DIR SHIFT_DIR word 2 default shift direction 2 right end Figure 16 An exa...

Page 18: ...xecutable section exceptions ax global EXCEPTION_HANDLER EXCEPTION_HANDLER subi sp sp 16 make room on the stack stw et 0 sp rdctl et ctl4 beq et r0 SKIP_EA_DEC interrupt is not external subi ea ea 4 m...

Page 19: ...ldw r22 12 sp addi sp sp 16 eret end Figure 17 Reset and exception handler assembly language code Part b include key_codes s includes equ for KEY0 KEY1 extern PATTERN externally defined variables exte...

Page 20: ...6 0 r21 load pattern for HEX displays stwio r6 0 r20 store to HEX3 HEX0 ldw r4 0 r22 check which key has been pressed CHK_KEY0 movi r8 KEY0 code to check for KEY1 bne r4 r8 CHK_KEY1 movia r20 SLIDER_S...

Page 21: ...e the displayed pattern right br END_INTERVAL_TIMER_ISR SHIFT_L movi r8 LEFT bne r5 r8 END_INTERVAL_TIMER_ISR movi r5 1 set r5 to the constant value 1 rol r6 r6 r5 shift left END_INTERVAL_TIMER_ISR st...

Page 22: ...of pushbutton KEY parallel port ldwio r11 0xC r10 read edge capture register stwio r0 0xC r10 clear the interrupt movia r10 KEY_PRESSED global variable to return the result CHECK_KEY0 andi r13 r11 0b0...

Page 23: ...tion called the_reset provides a simple reset mechanism by performing a branch to the main program The function named the_exception represents a general exception handler that can be used with any C p...

Page 24: ...e displayed pattern to the right KEY 2 rotates the displayed pattern to the left KEY 3 stops the rotation int main void Declare volatile pointers to I O registers volatile means that IO load and store...

Page 25: ...NIOS2_READ_ESTATUS dest do dest __builtin_rdctl 1 while 0 define NIOS2_READ_BSTATUS dest do dest __builtin_rdctl 2 while 0 define NIOS2_READ_IENABLE dest do dest __builtin_rdctl 3 while 0 define NIOS2...

Page 26: ...handles Nios II exception processing This code should not be modified instead the C language code in the function interrupt_handler can be modified as needed for a given application void the_exceptio...

Page 27: ...asm stw r21 84 sp asm stw r22 88 sp asm stw r23 92 sp asm stw r25 100 sp r25 bt skip r24 et because it was saved above asm stw r26 104 sp r26 gp skip r27 because it is sp and there is no point in savi...

Page 28: ...7 because it is sp and we did not save this on the stack asm ldw r28 112 sp r28 fp asm ldw r29 116 sp r29 ea asm ldw r30 120 sp r30 ba asm ldw r31 124 sp r31 ra asm addi sp sp 128 asm eret Interrupt S...

Page 29: ...0020 HEX3_HEX0 address interval_timer_ptr 0 clear the interrupt HEX3_HEX0_ptr pattern display pattern on HEX3 HEX0 rotate the pattern shown on the HEX displays if key_pressed KEY0 for KEY0 load a new...

Page 30: ...variable KEY_PRESSED void pushbutton_ISR void volatile int KEY_ptr int 0xFF200050 int press press KEY_ptr 3 read the pushbutton interrupt register KEY_ptr 3 press clear the interrupt if press 0x1 KEY0...

Page 31: ...by removing data from the Read FIFOs until both are less than 75 full Bit WE gives an interrupt enable capability for outgoing data Setting this bit to 1 allows the audio core to generate an interrupt...

Page 32: ...a VGA controller that can be connected to a standard VGA monitor The VGA controller supports a screen resolution of 640 480 The image that is displayed by the VGA controller is derived from two sourc...

Page 33: ...ory for display on the VGA screen You can modify the pixel data at any time simply by writing to the pixel addresses Thus an image can be changed even when it is in the process of being displayed Howe...

Page 34: ...ddress 0 15 31 0xFF203020 0xFF203024 A S 1 X Y 16 2 23 front buffer address 0xFF203028 back buffer address 0xFF20302C 3 B 7 m n 4 8 24 Backbuffer register Resolution register Status register Buffer re...

Page 35: ...of Figure 30 shows that characters are addressed in the memory by using the combination of a base address which has the value 09000000 16 and an x y offset Using this scheme the character at location...

Page 36: ...be displayed on a VGA monitor by using the video out port described in Section 4 2 The video in port writes each frame of the video in data into the pixel buffer described in Section 4 2 1 The video...

Page 37: ...e 33 The PS2_Data register is both readable and writable When bit 15 RVALID is 1 reading from this register provides the data at the head of the FIFO in the Data field and the number of entries in the...

Page 38: ...port shown in Figure 34 except that the base address of its PS2_Data register is 0xFF200108 and the base address of its PS2_Control register is 0xFF20010C 4 6 IrDA Infrared Serial Port The IrDA port...

Page 39: ...ding interrupts are indicated in the Control register s RI and WI bits and can be cleared by writing or reading data to from the UART 4 7 Analog to Digital Conversion Port The Analog to Digital Conver...

Page 40: ...s Quartus II software and Qsys tool Tutorials that introduce this software are provided in the University Program section of Altera s web site To modify the system it is first necessary to make an edi...

Page 41: ...results on Terminal window int main void float x y add sub mult div while 1 printf Enter FP values X Y n scanf f x printf f x echo the typed data to the Terminal window scanf f y printf f n y echo the...

Page 42: ...004F Slider Switches 0xFF200050 0xFF20005F Pushbutton KEYs 0xFF200060 0xFF20006F JP1 Expansion 0xFF200070 0xFF20007F JP2 Expansion 0xFF200100 0xFF200107 PS 2 0xFF200108 0xFF20010F PS 2 Dual 0xFF201000...

Page 43: ...ing used Pressing Next opens the window in Figure 40 Here the user can select the DE1 SoC Computer as a predesigned system The Monitor Program then fills in the relevant information in the System deta...

Page 44: ...ns of the Monitor Program Figure 42 gives the final screen that is used to create a new project in the Monitor Program This screen shows the default addresses of compiler and linker sections that will...

Page 45: ...DE1 SOC COMPUTER SYSTEM WITH NIOS II For Quartus II 15 0 Figure 41 Selecting sample programs Figure 42 Setting offsets for text and data Altera Corporation University Program 2015 45...

Reviews: