NiosII的范例
源代码在线查看: 7个范例程序的测试结果.txt
7个范例程序的测试结果
1、字符模式设备范例.txt
--上位机串口波特率115200,在硬件上全速运行程序后控制台收到:
This application will printf 'Hello world' to uart1!
串口上收到:
hello world
2、Alarm范例.txt
--在my_alarm_callback()函数return前,加入了一条printf("CallCounter's Value is %d!\n",CallCounter);,在硬件上全速运行程序后收到:
CallCounter's Value is 1!
3、ISR范例.txt
--在硬件上全速运行程序后收到:
ISR Demo!
Timer interrupt has occurred for: 0 times
Timer interrupt has occurred for: 1 times
Timer interrupt has occurred for: 2 times
Timer interrupt has occurred for: 3 times
…………
4、HighResTimer范例.txt
--在硬件上全速运行程序后收到:
Elapsed time in func1 = 993 us
Elapsed time in func1 = 4830 us
5、DMA范例.txt
--在SOPC Builder中建一个RAM型On-chip_memory命名为onchip_RAM_4K(也可取其它名),建一个DMA命名为dma,将dma的read_master、write_master与onchip_RAM_4K连接.在硬件上全速运行程序后收到:
DMA Demo(Memory to Memory)!
Create the transmit channel successfully!
Create the receive channel successfully!
Post the transmit request successfully!
Post the receive request successfully!
6、Simple Flash Access驱动范例.txt
--在硬件上全速运行程序后收到:
Simple Flash Access Demo.
Open Flash Device Successfully.
Write Flash Device Successfully.
Read Flash Device Successfully.
Verify Successfully!
7、Fine-gained Flash Access驱动范例.txt
--在硬件上全速运行程序后收到:
Fine-gained Flash Access Demo.
Open Flash Device Successfully.
Erase Flash Device Successfully.
Write Flash Device Successfully.
Read Flash Device Successfully.
Verify Successfully!
Alarm范例程序经过修改之后,可以看到重复进my_alarm_callback()函数了
控制台显示结果为:
my_alarm_callback has been called for: 0 times
my_alarm_callback has been called for: 1 times
my_alarm_callback has been called for: 2 times
my_alarm_callback has been called for: 3 times
my_alarm_callback has been called for: 4 times
…………
/*
* 一、功能: Alarm演示代码修改版.
*
* 二、相关说明:
* 由于NiosII IDE的ISS(Instruction Set Simulation)支持JTAG_UART和定时
* 器的仿真功能,所以该源码可以运行在ISS模式下,而无须任何硬件开发板的支持.
*
* 三、运行前提:
* 1. 选择包含JTAG_UART和具有周期中断功能的定时器的NiosII系统(ptf文件);
* 2. 在系统库属性中完成下面的配置:
* (1) 将stdout映射到JTAG_UART;
* (2) 将具有周期中断功能的定时器映射为系统时钟;
*
*/
#include
#include "sys/alt_alarm.h"
#include "alt_types.h"
//定义my_alarm_callback函数的重复调用周期
//INTEVAL_TICK不能太大,因为ISS对定时器的仿真需要很长的时间,这里取1即可
//在SOPC Builder中对定时器周期的设定也不要太大,1ms即可
#define INTEVAL_TICK 1 //单位:系统时钟周期
//定义全局静态变量对my_alarm_callback的被调用次数进行计数;
static int CalledCounter = 0;
/* 定义欲注册为Alarm的callback函数; */
alt_u32 my_alarm_callback (void* context)
{
CalledCounter++;
//返回值决定在返回后的多少个系统时钟周期后,my_alarm_callback函数再次被调用;
return INTEVAL_TICK;
}
int main()
{
//在注册alarm之前,必须先定义一个alt_alarm类型的变量(无须初始化),
//并将它作为alarm注册函数alt_alarm_start的输入参数;
static alt_alarm alarm;
//当alt_alarm_start注册成功时返回0,否则返回负数;
if(
alt_alarm_start(&alarm,
INTEVAL_TICK,
my_alarm_callback,
NULL
) < 0
)
{
printf ("No system clock available\n" ) ;
}
//将my_alarm_callback的被调用次数由stdout设备输出
printf("my_alarm_callback has been called for: %d times\n", CalledCounter) ;
int Old_Value = CalledCounter;
for( ; ; )
{
if(Old_Value != CalledCounter)
{
Old_Value = CalledCounter;
printf("my_alarm_callback has been called for: %d times\n", Old_Value);
}
}
}