2 programming examples, Pitx-sp software guide, 1 watchdog example – Kontron pITX-SP User Manual

Page 23

Advertising
background image

KTD-S0003-C

Page 19

CPLD Interface


p

ITX-SP Software Guide

6.2

Programming Examples

The following examples (DOS programs) show the access to the CPLD features (C compiler: BORLAND C++).
Note: These programs cannot be run on Linux and Windows

®

.

6.2.1 Watchdog

Example

#include <stdio.h>
#include <dos.h>

#define CPLD_BASE_ADDR

0xA80

#define WDT_INDEX

0xA2

#define WDT_ENABLE

0x40

#define WDT_TRIGGER

0x80

#define WDT_1SEC

0x00

#define WDT_5SEC

0x01

#define WDT_10SEC

0x02

#define WDT_30SEC

0x03

#define WDT_1MIN

0x10

#define WDT_5MIN

0x11

#define WDT_10MIN

0x12


void ActivateWatchdog (void)
{

outp (CPLD_BASE_ADDR, WDT_INDEX);

outp

(CPLD_BASE_ADDR+1,

WDT_10SEC);

delay (1);

// wait one millisecond

outp

(CPLD_BASE_ADDR+1,

WDT_ENABLE);

}

void TriggerWatchdog (void)
{

outp (CPLD_BASE_ADDR, WDT_INDEX);

outp (CPLD_BASE_ADDR+1, WDT_TRIGGER | WDT_ENABLE);

delay (1);

// wait one millisecond

outp

(CPLD_BASE_ADDR+1,

WDT_ENABLE);

}

void main (void)
{
int

i;

ActivateWatchdog

();

for (i = 0; i < 5; i++)

// wait half of expiry time (= 5 seconds)

delay (1000);

// wait 1 second

TriggerWatchdog ();

// trigger the watchdog - total expiry time now 15 seconds

}

Advertising