zbigh
zbigh

Reputation: 467

Enabling hardware watchdog in msm800

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?

Upvotes: 1

Views: 283

Answers (5)

Igor Skochinsky
Igor Skochinsky

Reputation: 25318

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?

Upvotes: 0

John U
John U

Reputation: 2993

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;

Upvotes: 0

Ganesh Gopalasubramanian
Ganesh Gopalasubramanian

Reputation: 1589

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.

Upvotes: 0

blak3r
blak3r

Reputation: 16546

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.

Upvotes: 0

Gunther Piez
Gunther Piez

Reputation: 30449

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
);

Upvotes: 1

Related Questions