200 lines
4.2 KiB
C
200 lines
4.2 KiB
C
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/relay.c,v 1.3 2003/01/15 14:04:34 josh Exp $ */
|
|
|
|
/*
|
|
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
|
* All rights reserved. Provided under license only.
|
|
* Distribution or other use of this software is only
|
|
* permitted pursuant to the terms of a license agreement
|
|
* from Wind River Systems (and is otherwise prohibited).
|
|
* Refer to that license agreement for terms of use.
|
|
*/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
* Copyright 1990-1997 Epilogue Technology Corporation.
|
|
* Copyright 1998 Integrated Systems, Inc.
|
|
* All rights reserved.
|
|
****************************************************************************/
|
|
|
|
/*
|
|
* $Log: relay.c,v $
|
|
* Revision 1.3 2003/01/15 14:04:34 josh
|
|
* directory structure shifting
|
|
*
|
|
* Revision 1.2 2001/11/08 15:56:26 tneale
|
|
* Updated for newest file layout
|
|
*
|
|
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
|
* Tornado shuffle
|
|
*
|
|
* Revision 2.7 2001/01/19 22:23:51 paul
|
|
* Update copyright.
|
|
*
|
|
* Revision 2.6 2000/03/17 00:12:44 meister
|
|
* Update copyright message
|
|
*
|
|
* Revision 2.5 1998/09/18 19:56:24 meister
|
|
* timer call renaming tm_ --> etc_tm_
|
|
*
|
|
* Revision 2.4 1998/06/03 21:24:47 sar
|
|
* Updated code to use common string macros
|
|
*
|
|
* Revision 2.3 1998/02/25 15:21:49 sra
|
|
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
|
*
|
|
* Revision 2.2 1998/02/25 04:57:37 sra
|
|
* Update copyrights.
|
|
*
|
|
* Revision 2.1 1997/04/25 05:43:23 sra
|
|
* Still hacking PCL-725 relay boards after all these years.
|
|
*
|
|
*/
|
|
|
|
/* [clearcase]
|
|
modification history
|
|
-------------------
|
|
01a,19apr05,job update copyright notices
|
|
*/
|
|
|
|
|
|
/*
|
|
* Control code for PCL-725 relay board (of "Internet Toaster" fame).
|
|
*
|
|
* To build a standalone control program for the relay board,
|
|
* compile with -DRELAY_STANDALONE
|
|
*
|
|
* Yes, the conditional compilation in this file is ugly. This is
|
|
* code that we use at trade shows, we don't really expect our
|
|
* customers to ever try to turn this on.
|
|
*/
|
|
|
|
#ifndef RELAY_PORT
|
|
#define RELAY_PORT 0x2a8
|
|
#endif
|
|
|
|
#if defined(RELAY_STANDALONE)
|
|
|
|
typedef unsigned char bits8_t;
|
|
|
|
#else /* RELAY_STANDALONE */
|
|
|
|
#include <wrn/wm/common/install.h>
|
|
#include <wrn/wm/common/types.h>
|
|
#include <wrn/wm/demo/snarklib.h>
|
|
|
|
#include <wrn/wm/demo/relay.h>
|
|
|
|
#endif /* RELAY_STANDALONE */
|
|
|
|
#if defined(INSTALL_on_msdos) || defined(MSDOS)
|
|
|
|
/*
|
|
* DOS, I forget which compiler, probably BCC.
|
|
*/
|
|
|
|
#include <dos.h>
|
|
|
|
#define PORT_READ __inportb__
|
|
#define PORT_WRITE __outportb__
|
|
#define PORT_INIT()
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
/*
|
|
* FreeBSD. Yes, this really does open a file descriptor which is
|
|
* never used again, that's how raw hardware I/O works on FreeBSD.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <sys/file.h>
|
|
#include <machine/pio.h>
|
|
|
|
static int relay_fd = -1;
|
|
|
|
#define PORT_READ inb
|
|
#define PORT_WRITE outb
|
|
#define PORT_INIT() \
|
|
do { \
|
|
if (relay_fd < 0 && (relay_fd = open("/dev/io", O_RDONLY, 0666)) < 0) \
|
|
abort(); \
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#error Sorry, no PCL-725 support for this platform yet.
|
|
|
|
#endif
|
|
|
|
|
|
/*
|
|
* Read relay state, one bit per relay.
|
|
*/
|
|
bits8_t relay_read(void)
|
|
{
|
|
PORT_INIT();
|
|
return PORT_READ(RELAY_PORT);
|
|
}
|
|
|
|
/*
|
|
* Write relay state, one bit per relay.
|
|
*/
|
|
void relay_write(bits8_t bits)
|
|
{
|
|
PORT_INIT();
|
|
PORT_WRITE(RELAY_PORT, bits);
|
|
}
|
|
|
|
|
|
|
|
#if defined(RELAY_STANDALONE)
|
|
|
|
/*
|
|
* Standalone program to twiddle the relays.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
int main (int argc, char *argv[])
|
|
{
|
|
if (argc > 1)
|
|
relay_write(STRTOUL(argv[1], 0, 16));
|
|
else
|
|
printf("Relay state %02x\n", relay_read());
|
|
return 0;
|
|
}
|
|
|
|
#else /* RELAY_STANDALONE */
|
|
|
|
/*
|
|
* Attache timer based routines for demos.
|
|
* Could trivially add Envoy timers here if we ever need that.
|
|
*/
|
|
|
|
#if defined(INSTALL_ATTACHE) && INSTALL_ATTACHE
|
|
|
|
#include <wrn/wm/attache/timer.h>
|
|
|
|
static struct timer relay_timer;
|
|
static bits8_t relay_reset_state;
|
|
|
|
static void relay_handler(struct timer *tm, void *cookie)
|
|
{
|
|
relay_write(relay_reset_state);
|
|
}
|
|
|
|
void relay_start(bits8_t state1, bits32_t delay, bits8_t state2)
|
|
{
|
|
if (!relay_timer.handler) {
|
|
etc_tm_init(&relay_timer);
|
|
relay_timer.handler = relay_handler;
|
|
}
|
|
relay_reset_state = state2;
|
|
relay_write(state1);
|
|
etc_tm_set(&relay_timer, delay);
|
|
}
|
|
|
|
#endif /* INSTALL_ATTACHE */
|
|
|
|
#endif /* RELAY_STANDALONE */
|