在msm800中启用硬件看门狗

发布于 2024-08-06 13:36:13 字数 905 浏览 12 评论 0原文

我需要启用 msm800 嵌入式计算机的硬件看门狗。

不幸的是我对使用汇编语言几乎一无所知。

该设备的文档是这样说的:

功能:看门狗

编号:EBh

描述:

启用闪光灯并禁用闪光灯 看门狗。上电后,看门狗 始终处于禁用状态。一旦看门狗 已启用,用户应用程序 必须至少每隔一次执行一次选通 800ms,否则看门狗执行 硬件重置

输入值:

AH:78h DLAG Int15 函数

AL:EBh 功能请求

BL:00h 禁用

BL:01h 启用

BL:FFh 频闪

01h-FFh 启用看门狗/重新触发

BH:00h=BL->秒数/ 01h = BL->分钟数。

输出值:AL 01h 看门狗定时器 发生超时

这就是我想到的:

#include <stdio.h>

int main() {

    asm(
        "movb       $0x78,      %ah\n\t"
        "movb       $0xEB,      %al\n\t"
        "movb       $0x01,      %bl\n\t"
        "movb       $0x00,      %bh\n\t"
        "int        $0x80"
    );

    return 0;
}

尽管这是错误的 - 运行会导致分段错误,我在寄存器中有正确的值,但不知道如何实际运行该函数。

有什么帮助吗?

I need to enable the hardware watchdog of an msm800 embedded computer.

Unfortunately I hardly know anything about using assembly languages.

This is what the documentation for the device says:

Function: WATCHDOG

Number: EBh

Description:

Enables strobes and disables the
Watchdog. After power-up, the Watchdog
is always disabled. Once the Watchdog
has been enabled, the user application
must perform a strobe at least every
800ms, otherwise the watchdog performs
a hardware reset

Input values:

AH: 78h DLAG Int15 function

AL: EBh Function request

BL: 00h Disable

BL: 01h Enable

BL: FFh Strobe

01h-FFh Enable Watchdog / retrigger

BH: 00h = BL -> number of sec. / 01h =
BL -> number of min.

Output value: AL 01h Watchdog timer
time-out occurred

And this is what i came up with:

#include <stdio.h>

int main() {

    asm(
        "movb       $0x78,      %ah\n\t"
        "movb       $0xEB,      %al\n\t"
        "movb       $0x01,      %bl\n\t"
        "movb       $0x00,      %bh\n\t"
        "int        $0x80"
    );

    return 0;
}

It's wrong though - running results in segmentation fault, I have the right values in registers, but don't know how to actually run the function.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我早已燃尽 2024-08-13 13:36:13

如果您使用 gcc,您需要告诉它哪些寄存器被破坏。

asm(
    "movb           $0x78,          %ah\n\t"
    "movb           $0xEB,          %al\n\t"
    "movb           $0x01,          %bl\n\t"
    "movb           $0x00,          %bh\n\t"
    "int            $0x80"
    :
    :
    : "ax", "bx", //... and what else may be clobbered by the int $80
);

If you are using gcc, you need to tell it which registers are clobbered.

asm(
    "movb           $0x78,          %ah\n\t"
    "movb           $0xEB,          %al\n\t"
    "movb           $0x01,          %bl\n\t"
    "movb           $0x00,          %bh\n\t"
    "int            $0x80"
    :
    :
    : "ax", "bx", //... and what else may be clobbered by the int $80
);
橘味果▽酱 2024-08-13 13:36:13

通常,您的编译器供应商会提供一种用 C 代码设置 CPU 外设的方法。我会尝试在您的手册中搜索“WDT”或“Watchdog”,看看它是否提供了一些方便的方法。

Usually your compiler vendor will provide a way of setting CPU peripherals in C code. I'd try searching your manual for "WDT" or "Watchdog" and see if it provides some convenience methods.

匿名的好友 2024-08-13 13:36:13

您面临的问题可能与上下文切换有关。您可以通过中断指令转移控制权,这意味着上下文切换部分需要由您的代码处理。简而言之,您必须编写一个中断服务例程并从主函数中调用它。

该例程应在实际中断处理器之前保存处理器的状态。这样做是因为中断处理可能会修改寄存器的内容。

退出时,例程应恢复处理器的状态。中断服务程序不会接受任何参数,也不会返回任何值。

The problem you are facing might be related to context switching. You transfer the control to via an interrupt instruction, which means the context switching part needs to be handled by your code. In short, you have to write a interrupt service routine and call it from your main function.

The routine should save the state of the processor before it actually interrupts the processor. This is done because the interrupt-processing might modify contents of registers.

On exit the routine should restore the state of the processor. The interrupt service routine will not take any argument and will not return any value.

寒尘 2024-08-13 13:36:13

这是我在 C 中设置特定地址或寄存器的代码(与 GCC 一起使用):

#define MICRO_PORT  (*(vuint8 *)(0x40100000))

这定义了地址 0x40100000 处的 8 位端口或寄存器,可以像任何其他变量一样读取/写入:

MICRO_PORT = 0xFF;
someval = MICRO_PORT;

Here's the code I have for setting a specific address or register in C (works with GCC):

#define MICRO_PORT  (*(vuint8 *)(0x40100000))

This defines an 8-bit port or register at address 0x40100000, can be read/written as any other variable:

MICRO_PORT = 0xFF;
someval = MICRO_PORT;

我在文档中找到了这个:

看门狗功能集成在 INT15 功能中

因此看来您应该调用 int 0x15,而不是 0x80。 0x80 是 Linux 系统调用。

还:

有一些可用的编程示例:产品 CD-Rom 或
客户下载区:\tools\SM855\int15dl\...

你看过那些例子吗?

I found this in the docs:

The watchdog feature is integrated in the INT15 function

So it seems you should call int 0x15, not 0x80. 0x80 is a Linux syscall.

Also:

There are some programming examples available: Product CD-Rom or
customer download area: \tools\SM855\int15dl\…

Have you looked at those examples?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文