timer是软核里的计时器。

1.添加nios ii系统

加入nios ii processor, ram, jtag, timer,,注意连线。图例中pio,spi都不用添加。


2.实例化qsys

module work(
	CLOCK_50
	,KEY
	);
input CLOCK_50;
input [3:0] KEY;

wire clk, rst;

assign clk = CLOCK_50;
assign rst = KEY[3];

nios_II u0 (
        .clk_clk        (clk),
        .reset_reset_n  (rst)
    );	 

endmodule

3.Eclipse

可见 http://blog.csdn.net/moon9999/article/details/69938526

在软核中写入如下代码

#include <stdio.h>
#include "stdlib.h"
#include "system.h"
#include "sys/alt_timestamp.h"
#include "alt_types.h"

void func1(void)
{
    int cnt=1000;
    while(cnt--);
}
void func2(void)
{
    int cnt=2000;
    while(cnt--);
}

int main()
{
  printf("step 1 is ok\n");
  alt_timestamp_start();
  alt_u32 time1, time2,time3;
  time1=alt_timestamp();
  printf("time is %ld\n",time1);
  func1();
  time2=alt_timestamp();
  printf("time is %ld\n",time2);
  func2();
  time3=alt_timestamp();
  printf("time is %ld\n",time3);
  printf("系统时钟频率是 %ld Hz\n", alt_timestamp_freq());
  return 0;
}
函数的作用:

alt_timestamp_start():开启计时器

alt_timestamp():戳取时间点

alt_timestamp_freq():获取系统频率

注意修改bsp


4.运行程序

运行结果如下