エンベデッド・ペリフェラルIPユーザーガイド

ID 683130
日付 9/21/2020
Public
ドキュメント目次
1. 概要 2. Avalon® -ST Multi-Channel Shared Memory FIFOコア 3. Avalon® -STシングルクロックFIFOコアおよびデュアルクロックFIFOコア 4. Avalon® -STシリアル・ペリフェラル・インターフェイス・コア 5. SPIコア 6. SPI Slave to Avalon® Master Bridgeコア/JTAG to Avalon® Master Bridgeコア 7. インテル eSPIスレーブコア 8. eSPI to LPCブリッジコア 9. イーサネットMDIOコア 10. インテルFPGA 16550互換UARTコア 11. UARTコア 12. JTAG UARTコア 13. インテル FPGA Avalon® Mailboxコア 14. インテル FPGA Avalon® ミューテックス・コア 15. インテル FPGA Avalon® I2C (Master) コア 16. インテル FPGA I2C Slave to Avalon® -MM Master Bridgeコア 17. インテルFPGA Avalon® コンパクト・フラッシュ・コア 18. EPCS/EPCQAシリアル・フラッシュ・コントローラー・コア 19. インテルFPGAシリアル・フラッシュ・コントローラー・コア 20. インテルFPGAシリアル・フラッシュ・コントローラーIIコア 21. インテルFPGA汎用クアッドSPIコントローラー・コア 22. インテルFPGA汎用クアッドSPIコントローラーIIコア 23. インターバル・タイマー・コア 24. インテルFPGA Avalon FIFOメモリーコア 25. オンチップメモリー (RAMおよびROM) コア 26. Optrex 16207 LCDコントローラー・コア 27. PIOコア 28. PLLコア 29. DMAコントローラー・コア 30. Modular Scatter-Gather DMAコア 31. Scatter-Gather DMAコントローラー・コア 32. SDRAMコントローラー・コア 33. トライステートSDRAMコア 34. Video Sync GeneratorコアとPixel Converterコア 35. インテル FPGA Interrupt Latency Counterコア 36. パフォーマンス・カウンター・ユニット・コア 37. ベクトル割り込みコントローラー・コア 38. Avalon® -STデータ・パターン・ジェネレーター・コアとデータ・パターン・チェッカー・コア 39. Avalon® -STテスト・パターン・ジェネレーター・コアとテスト・パターン・チェッカー・コア 40. システムIDペリフェラル・コア 41. Avalon® Packets to Transactions Converterコア 42. Avalon® -STマルチプレクサー・コアとデマルチプレクサー・コア 43. Avalon® -ST Bytes to Packets ConverterコアとPackets to Bytes Converterコア 44. Avalon® -ST Delayコア 45. Avalon® -STラウンド・ロビン・スケジューラー・コア 46. Avalon® -ST Splitterコア 47. Avalon® -MM DDR Memory Half Rate Bridgeコア 48. インテル FPGA GMII to RGMIIコンバーター・コア 49. インテル FPGA MII to RMIIコンバーター・コア 50. インテルFPGA HPS GMII to TSE 1000BASE-X/SGMII PCSブリッジコア 51. インテル FPGA HPS EMAC to Multi-rate PHY GMIIアダプターコア 52. インテル FPGA MSI to GICジェネレーター・コア

5.5. テストコード例

#include "alt_types.h"
#include "sys/alt_stdio.h"
#include "io.h"
#include "system.h"
#include "sys/alt_cache.h"
#include "altera_avalon_spi.h"
#include "altera_avalon_spi_regs.h"
#include "sys/alt_irq.h"

//This is the ISR that runs when the SPI Slave receives data

static void spi_rx_isr(void* isr_context){

        alt_printf("ISR :) %x \n" ,  IORD_ALTERA_AVALON_SPI_RXDATA(SPI_SLAVE_BASE));

        //This resets the IRQ flag. Otherwise the IRQ will continuously run.
        IOWR_ALTERA_AVALON_SPI_STATUS(SPI_SLAVE_BASE, 0x0);
}

int main()
{
  alt_printf("Hello from Nios II!\n");

  int return_code,ret;
  char spi_command_string_tx[10] = "$HELLOABC*";

  char spi_command_string_rx[10] = "$HELLOABC*";

  //This registers the Slave IRQ with NIOS

  ret = alt_ic_isr_register(SPI_SLAVE_IRQ_INTERRUPT_CONTROLLER_ID,SPI_SLAVE_IRQ,spi_rx_isr,(void *)spi_command_string_tx,0x0);
  alt_printf("IRQ register return %x \n", ret);

  //You need to enable the IRQ in the IP core control register as well.
  IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_SLAVE_BASE,ALTERA_AVALON_SPI_CONTROL_SSO_MSK | ALTERA_AVALON_SPI_CONTROL_IRRDY_MSK);

  //Just calling the ISR to see if the function is OK.
  spi_rx_isr(NULL);

  return_code = alt_avalon_spi_command(SPI_MASTER_BASE,0 ,
                              1, spi_command_string_tx,
                              0, spi_command_string_rx,
                              0);

  return_code = alt_avalon_spi_command(SPI_MASTER_BASE,0 ,
                                1, &spi_command_string_tx[1],
                                0, spi_command_string_rx,
                                0);

  return_code = alt_avalon_spi_command(SPI_MASTER_BASE,0 ,
                                1, &spi_command_string_tx[2],
                                0, spi_command_string_rx,
                                0);

  return_code = alt_avalon_spi_command(SPI_MASTER_BASE,0 ,
                                1, &spi_command_string_tx[3],
                                0, spi_command_string_rx,
                                0);

  if(return_code < 0)
                 alt_printf("ERROR SPI TX RET = %x \n" , return_code);

  alt_printf("Transmit done. RET = %x spi_rx %x\n",return_code,spi_command_string_rx[0]);

  //RX is done via interrupts.
  alt_printf("Rx done \n");
  return 0;

}