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

📄 test_checksum.c

📁 altera 的示例ip
💻 C
字号:
/******************************************************************************
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA.           *
* All rights reserved. All use of this software and documentation is          *
* subject to the License Agreement located at the end of this file below.     *
*******************************************************************************/
/* Simple C program that exercises the altera_avalon_checksum component by 
 * filling a memory buffer with test data and then configuring the 
 * altera_avalon_checksum to read back the data using the IOWR and IORD 
 * to directly write to the register locations as defined in the _regs.h 
 * file
 * 
 * Version History
 * BR   04/01/2007  Created
 * ATJ  04/12/2007  Add additional comments 
 * 
*/

#include <stdio.h>
#include <stdlib.h>
#include "altera_avalon_checksum_regs.h"
#include "system.h"
#include <alt_types.h>


/* Simple function that sets all contents of a buffer to the specified value. */
int set_buf_val( alt_u8* buffer, int length, alt_u8 val )
{
  int ret_code = 0;
  
  /* Ok... one byte at a time is not efficient...C'est La Vie! */
  
  while (length >= 0)
  {
    *(buffer + length) = val;
    if( *(buffer+length) != val )
    {
      ret_code = -1;
    }
    length--;
  }
  return( ret_code );
}

/* This program points the checksum component at a small buffer and
 * computes the checksum.
 */
 
int main()
{
  /* Point the buffer at the base of the onchip ram.*/
  /* base of onchip ram defined in system.h file    */
  alt_u8* buf = (alt_u8*) ONCHIP_RAM_64_KBYTES_BASE;
  /* Set the length small, to start with. */
  int     len = 12;
  int status;
  int result;
  
  
  /* Set the buffer to all 0xF0's. */
  printf( "Writing to test memory.  \n");
  if( (set_buf_val( buf, len, 0xf0 )<0) )
  {
    printf( "Error:  Could not pre-set buffer at %d.\n", (int) buf );
    return( -1 );
  }
  
  /* Setup the checksum component. */
  /* IORD and IOWR macros setup in alter_avalon_checksum_regs.h and io.h */
  
  /* Store the address (must be 32-bit word aligned address). */
  printf( "Writing to address register.  \n");
  IOWR_ALTERA_AVALON_CHECKSUM_ADDR( ALTERA_AVALON_CHECKSUM_0_BASE, ONCHIP_RAM_64_KBYTES_BASE );
  /* Store the length in bytes (up to a 16-bit value). */
  printf( "Writing to length register.  \n");
  IOWR_ALTERA_AVALON_CHECKSUM_LENGTH( ALTERA_AVALON_CHECKSUM_0_BASE, len );
  /* Tell it to "go". */
  printf( "Writing to go bit in control register.  \n");
  IOWR_ALTERA_AVALON_CHECKSUM_CTRL( ALTERA_AVALON_CHECKSUM_0_BASE+ALTERA_AVALON_CHECKSUM_CTRL_GO_OFST, 
                                  ALTERA_AVALON_CHECKSUM_CTRL_GO_MSK);
  /* Polling loop waiting for the component to be done. */
  status = IORD_ALTERA_AVALON_CHECKSUM_STATUS( ALTERA_AVALON_CHECKSUM_0_BASE );

  printf( "Polling for DONE bit in status register. . .  \n");
  while( !(status & ALTERA_AVALON_CHECKSUM_STATUS_DONE_MSK) )
  {
    status = IORD_ALTERA_AVALON_CHECKSUM_STATUS( ALTERA_AVALON_CHECKSUM_0_BASE );
  }
  printf( "Done bit asserted, exiting polling loop.  \n");
    
  result = IORD_ALTERA_AVALON_CHECKSUM_RESULT( ALTERA_AVALON_CHECKSUM_0_BASE );
  
  printf( "Done...Result = 0x%x.\n", (int) result );
  
  return 0;
}

⌨️ 快捷键说明

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