Altera DE1-SoC Manual Download Page 9

DE1-S

O

C C

OMPUTER

S

YSTEM WITH

N

IOS

II

For Quartus II 15.0

2.5

JTAG Port

The JTAG port implements a communication link between the DE1-SoC board and its host computer. This link
can be used by the Altera Quartus II software to transfer FPGA programming files into the DE1-SoC board, and
by the Altera Monitor Program, discussed in Section

8

. The JTAG port also includes a UART, which can be used

to transfer character data between the host computer and programs that are executing on the Nios II processor. If
the Altera Monitor Program is used on the host computer, then this character data is sent and received through its

Terminal Window

. The programming interface of the JTAG UART consists of two 32-bit registers, as shown in

Figure

10

. The register mapped to address

0xFF201000

is called the

Data

register and the register mapped to

address

0xFF201004

is called the

Control

register.

Address

0

7

31

16

. . .

0

x

FF201000

 

0

x

FF201004

 

DATA

RAVAIL

14

8

. . .

. . .

WSPACE

Unused

WI RI

WE RE

1

RVALID

AC

10 9

11

Unused

15

Data register

Control register

Figure 10. JTAG UART registers.

When character data from the host computer is received by the JTAG UART it is stored in a 64-character FIFO.
The number of characters currently stored in this FIFO is indicated in the field

RAVAIL

, which are bits 31

16 of the

Data

register. If the receive FIFO overflows, then additional data is lost. When data is present in the receive FIFO,

then the value of

RAVAIL

will be greater than 0 and the value of bit 15,

RVALID

, will be 1. Reading the character

at the head of the FIFO, which 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 and the data in bits

7

0

is undefined.

The JTAG UART also includes a 64-character FIFO that stores data waiting to be transmitted to the host computer.
Character data is loaded into this FIFO by performing a write to bits 7

0 of the

Data

register in Figure

10

. Note

that writing into this register has no effect on received data. The amount of space,

WSPACE

, currently available in

the transmit FIFO is provided in bits 31

16 of the

Control

register. If the transmit FIFO is full, then any characters

written to the

Data

register will be lost.

Bit 10 in the

Control

register, called

AC

, has the value 1 if the JTAG UART has been accessed by the host computer.

This bit can be used to check if a working connection to the host computer has been established. The

AC

bit can be

cleared to 0 by writing a 1 into it.

The

Control

register bits

RE

,

WE

,

RI

, and

WI

are described in Section

3

.

2.5.1

Using the JTAG UART with Assembly Language Code and C Code

Figures

11

and

13

give simple examples of assembly language and C code, respectively, that use the JTAG UART.

Both versions of the code perform the same function, which is to first send an ASCII string to the JTAG UART, and
then enter an endless loop. In the loop, the code reads character data that has been received by the JTAG UART,
and echoes this data back to the UART for transmission. If the program is executed by using the Altera Monitor
Program, then any keyboard character that is typed into the

Terminal Window

of the Monitor Program will be echoed

Altera Corporation - University Program

2015

9

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: