在msm800中启用硬件看门狗
我需要启用 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 resetInput 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用 gcc,您需要告诉它哪些寄存器被破坏。
If you are using gcc, you need to tell it which registers are clobbered.
通常,您的编译器供应商会提供一种用 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.
您面临的问题可能与上下文切换有关。您可以通过中断指令转移控制权,这意味着上下文切换部分需要由您的代码处理。简而言之,您必须编写一个中断服务例程并从主函数中调用它。
该例程应在实际中断处理器之前保存处理器的状态。这样做是因为中断处理可能会修改寄存器的内容。
退出时,例程应恢复处理器的状态。中断服务程序不会接受任何参数,也不会返回任何值。
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.
这是我在 C 中设置特定地址或寄存器的代码(与 GCC 一起使用):
这定义了地址 0x40100000 处的 8 位端口或寄存器,可以像任何其他变量一样读取/写入:
Here's the code I have for setting a specific address or register in C (works with GCC):
This defines an 8-bit port or register at address 0x40100000, can be read/written as any other variable:
我在文档中找到了这个:
因此看来您应该调用 int 0x15,而不是 0x80。 0x80 是 Linux 系统调用。
还:
你看过那些例子吗?
I found this in the docs:
So it seems you should call int 0x15, not 0x80. 0x80 is a Linux syscall.
Also:
Have you looked at those examples?