【问题标题】:C - How to use Timers Interrupts in Nios IIC - 如何在 Nios II 中使用定时器中断
【发布时间】:2024-01-19 14:54:01
【问题描述】:

在我的项目中,我在 Quartus 的 Qsys 设计中使用了一个简单的周期性中断。下面我需要创建一个可以从用户定义的值(以秒为单位)计数的计数器,但我不确定如何开始编写代码。我已经在线查看了 Atera 手册以了解如何开始,但我仍然有点困惑。以下是我目前所拥有的

//*****************************************************************************
//*****************************************************************************
#include "nios_std_types.h"
#include "system.h"
#include <stdio.h>
#include "sys/alt_stdio.h"

//*****************************************************************************
//                  Define symbolic constants
//*****************************************************************************
// define the PIO register offsets
#define TIMER_START_OFFSET 2
#define TIMER_CNTRL_MASK //Not sure what to write yet.


//*****************************************************************************
//                            Define private data
//*****************************************************************************
uint32 *timer_ptr = (uint32 *)TIMER_0_BASE;




//*****************************************************************************
//                             private functions
//*****************************************************************************

void Timer_StartTimer();
void Timer_StopTimer();
void Timer_SetTimeLimit();

【问题讨论】:

    标签: c timer interrupt nios


    【解决方案1】:
    1. 在项目 BSP(板支持文件)中配置时间戳计时器
    2. 生成 BSP(右键单击项目并生成)
    3. 如下注册ISR

       retVal = alt_ic_isr_register(HIGH_RES_TIMER_IRQ_INTERRUPT_CONTROLLER_ID,
                                HIGH_RES_TIMER_IRQ,
                                handle_timer_interrupts,
                                timer_ptr, 0x0);
      

    那么它应该可以工作,同样必须存在于其中一个文档中 http://www.altera.com/support/ip/processors/nios2/ips-nios2_support.html

    【讨论】: