⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsp_reg_access.c

📁 运行在Nios上的通过串行rapidio接口访问dsp的参考代码
💻 C
字号:
#include <stdio.h>
//#include <alt_types.h>
#include <io.h>
#include <string.h>

#include "sys/alt_dma.h"
#include "system.h"


#define CMD_LEN     128
#if 0
OUT_RTY_ENC   20  RW1C Output port has encountered a retry condition 1'b0
OUT_RETRIED   19  RO Output port has received a packet-retry control symbol
                  and cannot make forward progress.
OUT_RTY_STOP  18  RO Output port has been stopped due to a retry and is
                  trying to recover.
OUT_ERR_ENC   17  RW1C Output port has encountered (and possibly recovered
                  from) a transmission error.

OUT_ERR_STOP  16  RO Output port has been stopped due to a transmission
                  error and is trying to recover.

IN_RTY_STOP   10  RO Input port has been stopped due to a retry. 1'b0
IN_ERR_ENC    9   RW1C Input port has encountered (and possibly recovered
                  from) a transmission error.
IN_ERR_STOP   8   RO Input port has been stopped due to a transmission
                  error.
PWRITE_PEND   4   RO This register is not implemented and is reserved. It
                  is always set to zero.
PORT_ERR      2   RW1C Input or output port has encountered an unrecoverable
                  error and has shut down (turned off both port enables).
PORT_OK       1   RO Input and output ports a initialized and can
                  communicate with the adjacent device.
PORT_UNINIT   0   RO Input and output ports are not initialized and is in
                  training mode.

#endif

// SRIO Status Register Mask
#define SRIO_PORT_UNINT   0x00000001
#define SRIO_PORT_OK      0x00000002
#define SRIO_PORT_ERR     0x00000004
#define SRIO_PWRITE_PEND  0x00000010
#define SRIO_IN_ERR_STOP  0x00000100
#define SRIO_IN_ERR_ENC   0x00000200


#define IN_RTY_STOP       0x00000400
#define OUT_ERR_STOP      0x00010000
#define OUT_ERR_ENC       0x00020000
#define OUT_RTY_STOP      0x00040000
#define OUT_RETRIED       0x00080000
#define OUT_RTY_ENC       0x00100000


void get_cmd();
void parse_cmd(char *);
void parse_status(unsigned int s_val);
// refer to serial user manual page #142
// 
int main(void)
{
  unsigned int ret_val;
 ///////////////////////////////////////////////////////////////////////////////
 ////// **** Setting up the maintenance window address translation ***///////
 ///////////////////////////////////////////////////////////////////////////////
 ret_val = IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x158);
 printf("CSR : %x\n", ret_val);  //

 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x60, 0x00aa0000);  // write Source ID
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x13c, 0x60000000);  // 
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x1010c, 0x00abff00);  // write Tx Maintenance Control
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10104, 0xfffffffc);  //write Tx Maintenance Mask
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10088, 0x05000000);  //write Rx Maintanance Base Address
 
 printf("Source ID : %x\n", IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x60));  
 printf("Response Time : %x\n", IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x13c)); 
 printf("M Control : %x\n", IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x1010c));  
 printf("M Mask : %x\n", IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10104));  
 
 
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10300, 0x04040000);  // IO master base
 //IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10304, 0xfffffffc);  // IO Master window mask (enable)
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10304, 0x4);  // IO Master window mask (enable)
 IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10308, 0x00000000);  // IO Master window Offset

 printf("IO master base : %x\n", IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10300));  
 printf("Master window Offset : %x\n", IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10308)); 

// IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10400, 0x0);  // IO Slave base
// IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10404, 0x00fffffc);  // IO Slave window mask (enable)
// IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x10408, 0x04040000);  // IO Slave window Offset
// IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x1040c, 0x00AB0002);  // IO Slave window Control 
                                                          // nwrite_r, enable
 
  //Tx Port Write Buffer n : 0x10210 - 0x1024c
  //Rx Port Write Buffer n : 0x10260 - 0x1029c
  printf("\ndone...\n");

  while(1)
     get_cmd();
        
  
  return (0);
}


void parse_status(unsigned int s_val)
{
    if ((s_val & SRIO_PORT_UNINT) == SRIO_PORT_UNINT) printf("SRIO_PORT_UNINT|");
    if ((s_val & SRIO_PORT_OK) == SRIO_PORT_OK) printf("SRIO_PORT_OK|");
    if ((s_val & SRIO_PORT_ERR) == SRIO_PORT_ERR) printf("SRIO_PORT_ERR|");
    if ((s_val & SRIO_PWRITE_PEND) == SRIO_PWRITE_PEND) printf("SRIO_PWRITE_PEND|");
    if ((s_val & SRIO_IN_ERR_STOP) == SRIO_IN_ERR_STOP) printf("SRIO_IN_ERR_STOP|");
    if ((s_val & SRIO_IN_ERR_ENC) == SRIO_IN_ERR_ENC) printf("SRIO_IN_ERR_ENC|");
    if ((s_val & IN_RTY_STOP) == IN_RTY_STOP) printf("IN_RTY_STOP|");
    if ((s_val & OUT_ERR_STOP) == OUT_ERR_STOP) printf("OUT_ERR_STOP|");
    if ((s_val & OUT_ERR_ENC) == OUT_ERR_ENC) printf("OUT_ERR_ENC|");
    if ((s_val & OUT_RTY_STOP) == OUT_RTY_STOP) printf("OUT_RTY_STOP|");
    if ((s_val & OUT_RETRIED) == OUT_RETRIED) printf("OUT_RETRIED|");
    if ((s_val & OUT_RTY_ENC) == OUT_RTY_ENC) printf("OUT_RTY_ENC|");
    printf("\n");
}



void get_cmd()
{
  char cmd_buffer[CMD_LEN];
  unsigned i = 0;
  printf("cmd > ");

  for(i=0; i<CMD_LEN; i++)
  {
    scanf("%c", &cmd_buffer[i]);
    if (cmd_buffer[i] == '\n')
      break;
  }
  
  cmd_buffer[i]= '\0';
  parse_cmd(cmd_buffer);
  
  // command parsing.
  
}

void parse_cmd(char *cmd_buffer)
{
  char cmd[2];
  unsigned int val1, val2, offset, ret_val;
  unsigned int temp;
  
  sscanf(cmd_buffer, "%s %x %x\n", cmd, &val1, &val2);
  //printf("cmd : %c\n", cmd);
  //printf("val1 : %x\n", val1);
  //printf("val2 : %x\n", val2);
  
  switch(cmd[0])
  {
  case 'c' :
        ret_val = IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x158);
        printf("CSR : %x\n", ret_val);  //
        parse_status(ret_val);
        break;
  case 'p' :
        ret_val = IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, 0x15c); // Port 0 Control CSR
        printf("PCtrl : %x\n", ret_val);  //
        break;
  case 'w' :
        if (cmd[1] == 'r')
        {
          IOWR_32DIRECT(RIO_MNT_SLAVE_BASE, val1, val2); // read ti address at     ti id addr : 0x2d01060
          printf("remote write 0x%x=0x%x\n", val1, val2);
        }
        else if (cmd[1] == 's')
        {
          IOWR_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, val1, val2); // read ti address at     ti id addr : 0x2d01060
          printf("sys write 0x%x=0x%x\n", val1, val2);
        }
        else if (cmd[1] == 'b')
        {
          IOWR_32DIRECT(SRIO_BUF_BASE, val1, val2); // read ti address at     ti id addr : 0x2d01060
          printf("sys write 0x%x=0x%x\n", val1, val2);
        }
        else
          printf("unknow write\n");        
        //IOWR_32DIRECT(RIO_MNT_SLAVE_BASE, 0x60, (ret_val & 0x0000ffff) | 0x00AB0000); // read ti address at     
        break;

  case 'd' :
         printf("Dumping the RapidIO Registers of the DSP ....\n");
         for(offset=0; offset < 0x200; offset = offset + 4)
          printf("%8x : %8X\n", offset, IORD_32DIRECT(RIO_MNT_SLAVE_BASE, offset));
         printf("------- read compeleted\n");
         break;
        
  case 'r' :
        if (cmd[1] == 'r')
        {
          ret_val = IORD_32DIRECT(RIO_MNT_SLAVE_BASE, val1); // read ti address at     ti id addr : 0x2d01060
          printf("Remote Read 0x%x : 0x%x\n", val1, ret_val);  //
        }
        else if (cmd[1] == 's')
        {
          ret_val = IORD_32DIRECT(RIO_SYS_MNT_SLAVE_BASE, val1);// read ti address at     ti id addr : 0x2d01060
          printf("Sys Read 0x%x : 0x%x\n", val1, ret_val);  //
        }
        else if (cmd[1] == 'b')
        {
         for(temp=0; temp < 0x200; temp = temp + 4)
            {
         // ret_val = IORD_32DIRECT(SRIO_BUF_BASE, offset);// read ti address at     ti id addr : 0x2d01060
          printf("Sys Read 0x%x : 0x%x\n", temp, ret_val);  //
          }
        }
        else
          printf("unknow read\n");        


         // Port 0 Control CSR
        
        break;
  case 'h' :
      printf("--------- help -----------\n");
      printf(" c           : show current RIO port status\n");
      printf(" w[r/s] add value : write value into add (eg. w 0x60 0x1234) r:remote, s:sys\n");
      printf(" r[r/s] add       : read value from add(eg. r 0x60) r:remote, s:sys\n");
      printf("----- register address -----\n");
      printf("CSR register       : 0x158\n");
      printf("BASE ID register   : 0x60\n");
      break;       
  default:
    printf("unknow command\n");
    break;
  }
        
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -