c - 加速Linux可执行程序-arm处理器。位切换

标签 c linux embedded toggle executable

我正在运行启动到终端的linux(没有gui)。 我有一 block 带有 ArmV7 处理器的 ZyBo 电路板。我编写了一个 C 程序来在 PMOD 上输出时钟和相应的数据序列。 PMOD 的开关速度高达 50MHz。然而,我的程序创建的时钟的最大频率只有 115 Hz。我需要这个程序尽可能快地输出,因为我使用的 PMOD 的频率为 50MHz。 我用以下代码行编译了我的程序: gcc -ofast (c_program)

#include <stdio.h>
#include <stdlib.h>

#define ARRAYSIZE 511
//________________________________________

//macro for the SIGNAL PMOD
//________________________________________
//DATA 
//ZYBO Use Pin JE1
#define INIT_SIGNAL system("echo 54 > /sys/class/gpio/export"); system("echo out > /sys/class/gpio/gpio54/direction");
#define SIGNAL_ON system("echo 1 > /sys/class/gpio/gpio54/value");
#define SIGNAL_OFF system("echo 0 > /sys/class/gpio/gpio54/value");
//________________________________________

//macro for the "CLOCK" PMOD
//________________________________________
//CLOCK 
//ZYBO Use Pin JE4
#define INIT_MYCLOCK system("echo 57 > /sys/class/gpio/export"); system("echo out > /sys/class/gpio/gpio57/direction");
#define MYCLOCK_ON system("echo 1 > /sys/class/gpio/gpio57/value");
#define MYCLOCK_OFF system("echo 0 > /sys/class/gpio/gpio57/value");

int main(void){

int myarray[ARRAYSIZE] = {//hard coded array for signal data
    1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,1,0,0,1,1,0,1,0,0,0,0,0,1,0,0,1,1,1,0,0,1,1,1,0,1,1,1,1,0,0,1,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,0,1,0,0,1,0,1,1,0,1,0,1,1,0,0,1,1,1,1,0,0,1,0,1,0,0,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,1,0,1,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,1,0,1,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,0,0,1,1,1,0,0,1,1,0,1,1,0,1,1,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1,1,0,1,0,0,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,1,1,0,1,1,1,0,0,1,1,1,0,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,0,0,1,0,1,1,0,1,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1,1,1,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,1,0,1,0,1,0,0,1,1,0,0,1,1,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0
    };

INIT_SIGNAL
INIT_MYCLOCK;
//infinite loop
int i;
do{
    i = 0;
    do{
        /*
        1020 is chosen because it is twice the size needed allowing for the changes in the clock.
        (511= 0-510, 510*2= 1020 ==> 0-1020 needed, so 1021 it is)
        */
        if((i%2)==0)
        {
            MYCLOCK_ON;
            if(myarray[i/2] == 1){
                SIGNAL_ON;
            }else{
                SIGNAL_OFF;
            }
        }
        else if((i%2)==1)
        {
            MYCLOCK_OFF;
            //dont need to change the signal since it will just stay at whatever it was.
        }
        ++i;
    } while(i < 1021);
} while(1);
return 0;
}

我该怎么做才能使我的可执行程序输出至少达到兆赫兹的量级?

最佳答案

您正在尝试使用 system 来控制您的时钟函数(即创建进程)来调用另一个可执行文件( /bin/echo ),其目标是将值写入 /sys 中的伪文件。文件系统。难怪您无法实现超过数百赫兹的速率。

至少您应该写入 /sys 中的伪文件。文件系统,通过直接打开它们并从程序中写入它们,而不是通过 system 。这可能不会让您进入 MHz 范围,但它的运行速度肯定会比您现有的速度快数百倍。

关于c - 加速Linux可执行程序-arm处理器。位切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23879512/

相关文章:

c - write() 不写入数据

linux - 查找超过 15 分钟的文件

c - 未对齐的内存访问

c - 如何在 C 中模拟 OO 风格的多态性?

python - 导入后无法进行 git pull

c - 开发板ARM汇编

c - 如何从带尾数的 double 值中获取浮点值?

ARM架构的Linux交叉编译

c - 在 C 中验证帮助

linux - DNS A记录和PTR记录删除