innovate asia 2008 sopc builder and nios ii · 2008. 7. 28. · © 2008 terasic corporation 1...

67
© 2008 Terasic Corporation 1 Innovate Asia 2008 Innovate Asia 2008 Innovate Asia 2008 Innovate Asia 2008 SOPC Builder and NIOS II SOPC Builder and NIOS II SOPC Builder and NIOS II SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example: SDCARD Music Player

Upload: others

Post on 07-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

© 2008 Terasic Corporation

1

Innovate Asia 2008Innovate Asia 2008Innovate Asia 2008Innovate Asia 2008SOPC Builder and NIOS IISOPC Builder and NIOS IISOPC Builder and NIOS IISOPC Builder and NIOS II

�Build SOPC for DE1�NIOS II Programming

�Example: SDCARD Music Player

Page 2: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

© 2008 Terasic Corporation

2

Build SOPC for DE1Build SOPC for DE1Build SOPC for DE1Build SOPC for DE1

�New SOPC System�Add CPU/Component�Clock Setting�Specify Connection�Adjust Base Address/Interrupt Number�Adjust Arbitration�Generate Code

Page 3: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

3

© 2008 Terasic Corporation

3

New SOPC System

• Click SOPC Builder ICON under Quartus II

• Input Project Name

Page 4: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

4

© 2008 Terasic Corporation

4

Add CPU

Page 5: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

5

© 2008 Terasic Corporation

5

Add GPIO Controller for LED/7SEG/SWITCH/BUTTON

LED Switch

Page 6: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

6

© 2008 Terasic Corporation

6

Enable Interrupt for Input GPIO

Page 7: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

7

© 2008 Terasic Corporation

7

ADD SDRAM

Page 8: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

8

© 2008 Terasic Corporation

8

Add SRAM/EPCS

Page 9: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

9

© 2008 Terasic Corporation

9

Add FLASH

Page 10: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

10

© 2008 Terasic Corporation

10

Add Tristate Bridge for Flash

• Bridge and Adapters�Memory Mapped->Avalon-MM Tristate Bridge

Page 11: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

11

© 2008 Terasic Corporation

11

JTAG-UART/UART

Page 12: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

12

© 2008 Terasic Corporation

12

Timer/Time-Stamp/sysid

Page 13: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

13

© 2008 Terasic Corporation

13

Add PLL

Page 14: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

14

© 2008 Terasic Corporation

14

Add PLL (2)

SDRAMClock

CPUClock

Phase

Page 15: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

15

© 2008 Terasic Corporation

15

Clock Setting

Page 16: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

16

© 2008 Terasic Corporation

16

Connection

• Master Port �Slave Port

Page 17: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

17

© 2008 Terasic Corporation

17

Adjust Base Addressand Interrupt Number

• Apply Auto• Adjust in manual• Lock Address

Page 18: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

18

© 2008 Terasic Corporation

18

Adjust Arbitration

1~100

Page 19: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

19

© 2008 Terasic Corporation

19

Generate Code

Page 20: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

20

© 2008 Terasic Corporation

20

Instantiate SOPC in Quartus Top

Page 21: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

© 2008 Terasic Corporation

21

NIOS II ProgrammingNIOS II ProgrammingNIOS II ProgrammingNIOS II Programming

�New NIOS II Project�NIOS II System API

Page 22: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

22

© 2008 Terasic Corporation

22

Start NIOS II IDE 7.2

• Windows選單“開始�所有程式�Altera�NIOS II EDS 7.2�NIOS II IDE 7.2”

Page 23: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

23

© 2008 Terasic Corporation

23

Setup Workspace

• 選單“File�Switch Workspace…”

D:\NIOS_II\DE1\software\project_hello

Page 24: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

24

© 2008 Terasic Corporation

24

New Nios Project

• 選單“File�New�Nios II C/C++ Application”

Page 25: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

25

© 2008 Terasic Corporation

25

Hello Project

Editor

Project Management

Page 26: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

26

© 2008 Terasic Corporation

26

Project Configuration

Page 27: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

27

© 2008 Terasic Corporation

27

• Menu “Project�Build All”

• Sytem.h

Compile

Page 28: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

28

© 2008 Terasic Corporation

28

Download Hardware .SOF• Menu “Tools�Quartus II Progammer”

Page 29: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

29

© 2008 Terasic Corporation

29

Run

Page 30: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

30

© 2008 Terasic Corporation

30

Run Configuration

Page 31: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

31

© 2008 Terasic Corporation

31

• “Hello from Nios II!” appears in Consol Window

Result

Page 32: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

32

© 2008 Terasic Corporation

32

Debug

F6: Step OverF5: Step Into

Page 33: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

© 2008 Terasic Corporation

33

NIOS II System APINIOS II System APINIOS II System APINIOS II System API

Page 34: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

34

© 2008 Terasic Corporation

34

Altera Data Type• alt_32: singed 32-bit integer• alt_u32: unsigned 32-bit integer• alt_16: singed 16-bit integer• alt_u16: unsigned 16-bit integer• alt_8: singed 8-bit integer• alt_u8: unsigned 8-bit integer• defined in “alt_types.h”

Page 35: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

35

© 2008 Terasic Corporation

35

Access Hardware

• Access Memory: – Pointer (Data Cache Enabled)

• Access Device Register: – IORD, IOWR (Data Cache Disabled)

• Access by HAL API:– open, write, read, close (and fcntl)

– alt_xxx

Page 36: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

36

© 2008 Terasic Corporation

36

PIO-LED Example

void test1_led(void ){alt_u32 led_mask=0;while(1){

// green led controlIOWR_ALTERA_AVALON_PIO_DATA(

PIO_GREEN_LED_BASE, led_mask);// red led controlIOWR_ALTERA_AVALON_PIO_DATA(

PIO_RED_LED_BASE, led_mask);// toggle ledled_mask ^= 0xFFFFFFFF;

// sleep 0.2 secondusleep(200*1000);

} // while}// PIO_GREEN_LED_BASE & PIO_RED_LED_BASE defined in system.h

LED閃爍

Page 37: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

37

© 2008 Terasic Corporation

37

PIO-SWITCH Example

void test2_switch(void ){alt_u32 mask;while (1){

// (switch up) active-highmask = IORD_ALTERA_AVALON_PIO_DATA(PIO_SWITCH_BASE);

// high-active IOWR_ALTERA_AVALON_PIO_DATA(PIO_RED_LED_BASE, mask);

}}

Switch狀態顯示

Page 38: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

38

© 2008 Terasic Corporation

38

PIO-IRQ Example (1)

void test3_irq_pushbutton(void ){static alt_u8 led_indicate=0x00;// init led indicatorIOWR_ALTERA_AVALON_PIO_DATA(PIO_GREEN_LED_BASE, led_indicate);

// enable interrupt, 4-buttonIOWR_ALTERA_AVALON_PIO_IRQ_MASK(PIO_BUTTON_BASE, 0x0F);

// Reset the edge capture registerIOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_BUTTON_BASE,0);

// register ISRif ((alt_irq_register(PIO_BUTTON_IRQ, (void *)&led_indicate, pushbutton_isr) != 0))

printf("[pushbutton]register button IRQ fail\n");else

printf("[pushbutton]register button IRQ success\n");}

Pushbutton IRQ Enable

Page 39: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

39

© 2008 Terasic Corporation

39

PIO-IRQ Example (2)

void pushbutton_isr(void * context, alt_u32 id){alt_u8 pushbutton_mask;alt_u8 *pled_indicate = (alt_u8*)context;

// get the edge capture maskpushbutton_mask = IORD_ALTERA_AVALON_PIO_EDGE_CAP(

PIO_BUTTON_BASE) & 0x0F; // 4-button

// Reset the edge capture registerIOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_BUTTON_BASE,0);

// update led indicator*pled_indicate ^= pushbutton_mask;IOWR_ALTERA_AVALON_PIO_DATA(

PIO_GREEN_LED_BASE, *pled_indicate);}

Pushbutton ISR

Page 40: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

40

© 2008 Terasic Corporation

40

Timer Example

void test_timer(void){alt_u32 time_start, time_elapsed, ticks_per_second;

// check hardwareticks_per_second = alt_ticks_per_second();if (ticks_per_second == 0){

printf("timer hardware not works well\n");return;

}

// measure timetime_start = alt_nticks();usleep(1*1000*1000); // sleep 1 secondtime_elapsed = alt_nticks() - time_start;printf("[timer test]time elapsed:%.3f seconds\n",

(float)time_elapsed/(float)ticks_per_second);

}

Time Measurement

Page 41: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

41

© 2008 Terasic Corporation

41

Alarm Example

#define ALRAM_DUR (alt_ticks_per_second()/2)

alt_u32 alarm_callback(void *context){static alt_u8 led_mask = 0xFF;IOWR_ALTERA_AVALON_PIO_DATA(PIO_GREEN_LED_BASE, led_mask);led_mask ^= 0xFF;return ALRAM_DUR;

}

void test_alarm(void){int result;static alt_alarm alarm;result = alt_alarm_start (&alarm, ALRAM_DUR, alarm_callback, NULL);if (result != 0)

printf("[alarm test] failed to start alarm\n");

// call alt_alram_stop(&alarm) to stop it.}

LED Blink

Page 42: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

42

© 2008 Terasic Corporation

42

Timestamp Example

void test_timestamp(void){alt_u32 timestamp_freq;timestamp_freq = alt_timestamp_freq();if (timestamp_freq == 0){

printf("timestamp hardware not works well\n");return;

}printf("[timestamp]timestamp_freq = %ld\n", timestamp_freq);//alt_timestamp_start();usleep(1*1000*1000); // sleep 1 secondprintf("[timestamp]timestamp 1:%.3f seconds\n",

(float)alt_timestamp()/(float)timestamp_freq);usleep(500*1000); // sleep 0.5 secondprintf("[timestamp]timestamp 2:%.3f seconds\n",

(float)alt_timestamp()/(float)timestamp_freq);

}

Time Measure

Page 43: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

43

© 2008 Terasic Corporation

43

UART Example (1)

void test8_uart(void ){int uart, result;char szHello[] = "\r\nHello from Nios II Uart, please input:\r\n";char szRead[1];

// open uartuart = open(UART_NAME, O_ACCMODE); // UART_NAME defined in system.hif (!uart){

printf("failed to open uart\n");return ;

}

// write uartif (write(uart, szHello, strlen(szHello)) != strlen(szHello)){

printf("failed to write uart");close(uart);return ;

}

UART Write & None-Blocking Read

Page 44: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

44

© 2008 Terasic Corporation

44

UART Example (2)

// none-blocking readfcntl(uart, F_SETFL, O_ACCMODE | O_NONBLOCK);while (result >= 0){

result = read(uart, szRead, sizeof (szRead));if (result == -1){

printf("failed to read uart");}else if (result > 0){

printf("%c", szRead[0]);}

}fcntl(uart, F_SETFL, O_ACCMODE);close(uart);

}

UART Write & None-Blocking Read

Page 45: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

45

© 2008 Terasic Corporation

45

Memory Access Example

void test8_memory(void ){int i;const int test_num = 8;alt_u32 data32;volatile alt_u32 *pSDRAM = (alt_u32 *)SDRAM_U1_BASE;

for (i=0;i<test_num;i++){*(pSDRAM+i) = i;

}

for (i=0;i<test_num;i++){data32 = *(pSDRAM+i);printf("*(pSDRAM+%d)=%08lXh\n", i, data32);

}}

Write & Read

Page 46: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

46

© 2008 Terasic Corporation

46

Flash Erase Example (1)

void test10_flash_erase(void ){alt_flash_fd* fd_flash;flash_region *regions_flash=0,*nextreg;int number_of_regions_flash=0; int error_code, r, i, offset;alt_u32 length, block_index;

fd_flash = alt_flash_open_dev(CFI_FLASH_NAME);if (fd_flash){

error_code = alt_get_flash_info(fd_flash,&regions_flash, &number_of_regions_flash);if (error_code == 0){

block_index = 0;nextreg = regions_flash;for (r=0;r<number_of_regions_flash && !error_code;r++){

printf("=== region %d, size=%d, offset=%08lX, block_num=%d, block_size=%d\n", r, nextreg->region_size, (alt_u32)nextreg->offset, nextreg->number_of_blocks, nextreg->block_size);

offset = nextreg->offset;

Erase Flash

Page 47: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

47

© 2008 Terasic Corporation

47

Flash Erase Example (2)for (i=0;i<nextreg->number_of_blocks && !error_code;i++){

length = nextreg->block_size;error_code = alt_erase_flash_block(fd_flash, offset, length);if (error_code)

printf("faied to erase flash block %d\n", block_index);else

printf("erase block %d success\n", block_index);offset += length;block_index++;

} // for i nextreg++;

} // or rprintf("faied to get flash info\n");

}alt_flash_close_dev(fd_flash);

}else {printf("failed to open flash\n");

}}

Page 48: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

© 2008 Terasic Corporation

48

ExampleExampleExampleExampleSDCARD Music PlayerSDCARD Music PlayerSDCARD Music PlayerSDCARD Music Player

�SOPC Hardware Design�NIOS II C Program Design

Page 49: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

49

© 2008 Terasic Corporation

49

SDCARD Music Player - Function

Page 50: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

50

© 2008 Terasic Corporation

50

Music Player - SOPC

Page 51: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

51

© 2008 Terasic Corporation

51

Program Flow Chart

Page 52: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

52

© 2008 Terasic Corporation

52

Music Player - NIOS II Program

Page 53: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

53

© 2008 Terasic Corporation

53

I2C Protocol

• Start/Stop: Change at SCLK High• Data: Change at SCLK Low

Page 54: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

54

© 2008 Terasic Corporation

54

I2C Implementation

• NIOS Implement I2C protocol• Use two PIO controllers

– I2C Clock– I2C Data

• I2C Clock Implement (output pin)– IORD_ALTERA_AVALON_PIO_DATA

• I2C Data Implement: (inout pin)– IOWR_ALTERA_AVALON_PIO_DIRECTION– IORD_ALTERA_AVALON_PIO_DATA– IOWR_ALTERA_AVALON_PIO_DATA

Page 55: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

55

© 2008 Terasic Corporation

55

SDCARD Interface

• SD 1-Bit Protocol: CMD, DAT0, CLK

Page 56: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

56

© 2008 Terasic Corporation

56

SDCARD – Bus Protocol (1)

• No Data: 1).No response 2). Response

Page 57: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

57

© 2008 Terasic Corporation

57

SDCARD – Bus Protocol (2)

• Multiple Block Read

Page 58: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

58

© 2008 Terasic Corporation

58

SDCARD – Bus Protocol (3)

• Multiple Block Write

Page 59: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

59

© 2008 Terasic Corporation

59

SDCARD – Command Token Format

• Token Size: Fixed to 6 bytes

Page 60: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

60

© 2008 Terasic Corporation

60

SDCARD – Data Packet Format

• Size: 1~512 Bytes

Page 61: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

61

© 2008 Terasic Corporation

61

SDCARD – Response Token Format

Page 62: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

62

© 2008 Terasic Corporation

62

SDCAR Driver Implementation

• NIOS II Implement 1-bit SD mode protocol• Use three PIO controllers

– Clock– Command– Data

• Clock and Command Implement (output pin)– IORD_ALTERA_AVALON_PIO_DATA

• Data Implement: (inout pin)– IOWR_ALTERA_AVALON_PIO_DIRECTION– IORD_ALTERA_AVALON_PIO_DATA– IOWR_ALTERA_AVALON_PIO_DATA

Page 63: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

63

© 2008 Terasic Corporation

63

FAT System

Page 64: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

64

© 2008 Terasic Corporation

64

FAT - File

Page 65: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

65

© 2008 Terasic Corporation

65

.WAV - File Format

Page 66: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

66

© 2008 Terasic Corporation

66

.WAV - Example

Page 67: Innovate Asia 2008 SOPC Builder and NIOS II · 2008. 7. 28. · © 2008 Terasic Corporation 1 Innovate Asia 2008 SOPC Builder and NIOS II Build SOPC for DE1 NIOS II Programming Example:

© 2008 Terasic Corporation

67

THANK YOU!THANK YOU!THANK YOU!THANK YOU!