C 用微晶玻璃设置计时器?

C 用微晶玻璃设置计时器?,c,timer,fpga,xilinx,microblaze,C,Timer,Fpga,Xilinx,Microblaze,使用Microblaze创建计时器的最佳方法是什么,它可以让我的工作方式更类似于更传统脚本中的delay\u ms()或sleep() 很容易,我就可以创建这样一个愚蠢的函数: void delay_ms(int i) { //mind that I am doing this on the top of my head for(delays=0; delay<(i*((1/frequency of the device)/2)); delays++) { } }

使用Microblaze创建计时器的最佳方法是什么,它可以让我的工作方式更类似于更传统脚本中的
delay\u ms()
sleep()

很容易,我就可以创建这样一个愚蠢的函数:

void delay_ms(int i) {
    //mind that I am doing this on the top of my head
    for(delays=0; delay<(i*((1/frequency of the device)/2)); delays++) {
    }
}
void delay_ms(int i){
//请注意,我是在头顶上做这件事的
对于(延迟=0;延迟TL;DR

使用微型操作系统,比如

回答不好

如果你没有操作系统,没有任务转换,但是有一个外部定时器,你可以 使用以下方法:

为硬件计时器启用中断,并管理由该中断驱动的计数器:

你应该吃点类似的东西

/**timer.c**/

/* The internal counters
 * each task have its counter
 */
static int s_timers[NUMBER_OF_TASKS] = {0,0};

/* on each time tick, decrease timers */
void timer_interrupt()
{
    int i;
    for (i = 0; i < NUMBER_OF_TASKS; ++i)
    {
        if (s_timer[i] > 0)
        {
            s_timer[i]--;
        }
    }
}

/* set wait counter:
 * each task says how tick it want to wait
 */
void timer_set_wait(int task_num, int tick_to_wait)
{
    s_timer[task_num] = tick_to_wait;
}

/**
 * each task can ask if its time went out
 */
int timer_timeout(int task_num)
{
    return (0 == s_timer[task_num]);
}
并计划(这里有一个大字)任务:

/** main.c **/

int main()
{
    /* init the program, like set up the timer interruption */
    init() 

    /* do tasks, for ever*/
    while(1)
    {
        task_1();
        task_2();
    }
    return 0;
}
我认为我所描述的是一个蹩脚的解决方案,不应该认真使用

我给出的代码充满了问题,比如如果任务执行变慢会发生什么


相反,你——可以——应该使用一些RT操作系统,比如对这类问题非常有帮助的RT操作系统。

你可以通过中断或信号来执行操作……但这取决于你如何对处理器进行编程。你使用任何操作系统吗?一点也不。我正在尽可能轻松地完成所有操作。你如何运行几个进程呢?我正在尝试这样做配置硬件xps定时器。解决方案实际上非常智能。唯一的问题是,我可能在其中执行无限量的任务,我需要对其进行大量修补。OSs(OSi?)对于我正在做的事情来说实际上相当繁重,所以最好忽略它们,尽管这样做会容易得多。“解决方案真的很聪明。”谢谢“OSs对我正在做的事情来说确实很重,所以最好忽略它们”,所以我说……5年前,现在我还没有操作系统,我经常会想念它。我理解你的痛苦。但对于我目前的项目,最好不要使用它。
/** main.c **/

int main()
{
    /* init the program, like set up the timer interruption */
    init() 

    /* do tasks, for ever*/
    while(1)
    {
        task_1();
        task_2();
    }
    return 0;
}