Owner's manual

KTD-S0003-C Page 31 CPLD Interface
pITX-SP Software Guide
6.2.6 Fan Speed Example
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define CPLD_BASE_ADDR 0xA80
#define FAN_CTRL_INDEX 0xF4
#define FAN_SPEED_INDEX 0xF5
#define CTRL_MASK 0x3F
#define DIVISOR_SHIFT 6
#define SPEED_OVERFLOW 255
#define MAX_DIVISOR 3
#define ESC_CHAR 0x1B
#define UPDATE_TIME 1000 // 1 second
#define REFRESH_TIME 500 // 0.5 seconds
#define TRUE 1
unsigned char ReadFanSpeed (unsigned char divisor)
{
unsigned char value;
outp (CPLD_BASE_ADDR, FAN_CTRL_INDEX);
value = inp (CPLD_BASE_ADDR+1);
value &= CTRL_MASK;
divisor = divisor << DIVISOR_SHIFT;
value |= divisor;
outp (CPLD_BASE_ADDR+1, value);
outp (CPLD_BASE_ADDR, FAN_SPEED_INDEX);
value = inp (CPLD_BASE_ADDR+1);
return value;
}
void main (void)
{
unsigned char divisor = 0;
int speed, key;
clrscr ();
while (TRUE)
{
speed = (int) ReadFanSpeed (divisor);
if (speed < SPEED_OVERFLOW)
break;
divisor++;
if (divisor > MAX_DIVISOR)
break;
delay (UPDATE_TIME);
}