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

📄 crcci.c

📁 NIOSII 实验指导
💻 C
字号:


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include <time.h>
#include <unistd.h>
#include <sys/alt_timestamp.h>


unsigned short crcCompute(unsigned short *data_block, unsigned int nWords)
{
    unsigned short*  pointer;
    unsigned short   word;

    word = ALT_CI_CRC(0xFFFF, 1);  // initialise crc reg to 0xFFFF

    for (pointer = data_block; pointer < (data_block + nWords); pointer ++)
    {
		word = ALT_CI_CRC(*pointer, 0);  

	 }

    return (word);

}   /* crcCompute() */



/**********************************************************************
 *
 * Function:    sevenseg_set_hex()
 *
 * Description: Decode hex number to format for 7-seg display.
 *              Also: sends data to the 7-seg display PIO
 *
 * Notes:       
 *
 * Returns:     The 7-seg-decoded values of a hex digit input.
 *
 **********************************************************************/
static void sevenseg_set_hex(int hex)
{
  static alt_u8 segments[16] = {
    0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84, /* 0-9 */
    0x88, 0xE0, 0xF2, 0xC2, 0xB0, 0xB8 };                       /* a-f */

  unsigned int data = segments[hex & 15] | (segments[(hex >> 4) & 15] << 8);

  IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_PIO_BASE, data);
}




int main(void)
{
	#define data_block_begin 0x600000
	#define data_block_end   0x63ffff
	#define data_sram_copy   0x8a0000

   	unsigned short int crc_result;
	unsigned int hex_digits;
	unsigned int* read_data;
	unsigned int* write_data;
//	unsigned char * byte_pointer;
	unsigned int data_block_length;

        alt_u32 num_ticks = 0;
        alt_u32 time1, time2, timer_overhead;


	// copy data block to SRAM so that Flash access time does not effect results
	write_data = (int*)data_sram_copy;
	for (read_data = (int*)data_block_begin; (int*)read_data <= (int*)data_block_end; read_data++)
	{
		*write_data = *read_data;
		write_data++;
	}


	data_block_length = (short*)data_block_end - (short*)data_block_begin + 1;

	IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0);
  	// Start Timer:    
   	if(alt_timestamp_start() < 0)
   	{
    	  printf("Timer init failed \n");
   	  exit(0);
    	}

 	// Get the number of clocks it takes + record time stamp:
   	time1 = alt_timestamp();
    	time2 = alt_timestamp();
    	timer_overhead = time2 - time1;

   	time1 = alt_timestamp();

    	for (hex_digits = 0; hex_digits <= 0x80; hex_digits++)
    	{
    	    crc_result = crcCompute((char*)data_sram_copy, data_block_length);
     	    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,hex_digits>>3);
   	}

   	time2 = alt_timestamp();
    	num_ticks = time2 - time1 - timer_overhead;

   	printf ("\nCRC for Data Block = 0x%x.\n", crc_result);
   	 printf("CPU time(ms): %.*f\n", 2, ((float)num_ticks/(float)alt_timestamp_freq()) * (float)1000); 




}

⌨️ 快捷键说明

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