c - 在内核空间上实现 timecounter_init (clocksource.h) 会出现无效的 ISA 状态错误

标签 c linux time linux-kernel embedded-linux

我正在使用 ARM Cortex-M4 在 stm32f429 上实现嵌入式 Linux 操作系统。在我的代码中,我需要出于个人目的实现clocksource.h 库来测量耗时。我的系统调用的代码是:

#include <linux/syscalls.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/time.h>
#include <linux/clocksource.h>


SYSCALL_DEFINE2(mycall, int*, arg1, char *, arg2) 
{
    struct timecounter *tc;
    struct cyclecounter *cc;
    long int value;

    local_irq_disable(); /*Disabling local interrupt*/


    spin_lock(&my_lock);

    timecounter_init(&tc,&cc,0);
    printk(KERN_INFO "PRINT\n");
    value = timecounter_read(&tc);

    local_irq_enable(); /*Enabling local interrupt*/


    return( value );
}

当我在板上加载测试应用程序并运行时,输出会给出:

KERNEL: fault at 0xd00877e0 [pc=0xd00877e0, sp=0xd0019f58]
Escalated to Hard Fault
Invalid ISA state


Pid: 17, comm:                 test
CPU: 0    Not tainted  (2.6.33-arm1 #594)
pc : [<d00877e0>]    lr : [<d009ec19>]    psr: 6000000b
sp : d0019f58  ip : 08060501  fp : 00000000
Code dump at pc [d00877e0]:
d0094a69 d009122f d0087dc5 d00b2231 
r10: 01000000  r9 : d0018000  r8 : d0257ec4
r7 : 00000000  r6 : 00000000  r5 : ffffffff  r4 : d0019f84
r3 : d00877e0  r2 : 00000000  r1 : d0019f80  r0 : d0019f80
Flags: nZCv  IRQs on  FIQs on  Mode UK11_26  ISA ARM  Segment kernel
Kernel panic - not syncing: 
Rebooting in 10 seconds..

如何解决?我必须初始化循环计数器 cc?如果是,怎么办?

最佳答案

如果您使用 Emcraft 的 SDK,则需要检查 CFLAGS 和 LDFLAGS 像这样

CFLAGS="-Os -mcpu=cortex-m3 -mthumb -I/opt/linux-cortexm-1-12/A2F/root/usr/include"

LDFLAGS="-mcpu=cortex-m3 -mthumb -L/opt/linux-cortexm-1-12/A2F/root/usr/lib"

关于c - 在内核空间上实现 timecounter_init (clocksource.h) 会出现无效的 ISA 状态错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27113367/

相关文章:

c - 在 C 或无限 sleep 中挂起主线程

linux - 编译后使用 gedit 打开 C 文件时出现意外警告

服务器上的 WCF 时间更改导致断开连接

c - 在 C 中,即使目录不存在,如何从文件路径创建文件?

c - 编译器大小

c - 如果在递归返回函数中不使用 return 会发生什么?

linux - 在 csv 命令输出的列后选择值

linux - 如何在linux下更改haskell进程的名称

javascript - javascript中动画之间的延迟

matlab - 自 "Jan 1, 0000": is this -1 BC or +1 CE? 起的序列日期号