From 507481336146ca188a9a9d9d1548d5dc81539a60 Mon Sep 17 00:00:00 2001 From: guest Date: Tue, 23 Oct 2007 08:21:21 +0000 Subject: Initial import. git-svn-id: svn+ssh://mecka.net/home/svn/dds@15 c30cbac5-9f56-4f76-8ed5-5c34e48a65ae --- iotest/src/diasio.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 iotest/src/diasio.cpp (limited to 'iotest/src/diasio.cpp') diff --git a/iotest/src/diasio.cpp b/iotest/src/diasio.cpp new file mode 100644 index 0000000..6d791ba --- /dev/null +++ b/iotest/src/diasio.cpp @@ -0,0 +1,123 @@ +/* + ============================================================================ + Name : diasio.cpp + Author : Manuel Traut + Version : + Copyright : Your copyright notice + Description : DAIS IO Class + ============================================================================ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "diasio.h" + +unsigned int DIASIO::instance = 0; +bool DIASIO::stop_wd = false; +int DIASIO::m_Bereich1; +int DIASIO::m_Bereich2; +int DIASIO::m_Bereich3; + +static void* watchDogTriggern(void* arg) +{ + struct timespec req; + unsigned int out = 0; + + req.tv_sec = 0; + req.tv_nsec = 300000; + while(!DIASIO::stop_wd){ + outw( out, DIASIO::m_Bereich2 + 0x0c ); + nanosleep(&req, NULL); + } + return NULL; +} + + +DIASIO::DIASIO(){ + if(instance == 0){ + init(); + } + instance++; +} + +DIASIO::~DIASIO(){ + instance--; + if(instance == 0){ + stop_wd = true; + pthread_join(watchdog, NULL); + } +} + +void DIASIO::set(TyuInt16 value){ + fprintf(stderr, "writing: %d -> %x + %x\n", value, m_Bereich2, S_AdresseOut); + fflush(stderr); + outw( value, m_Bereich2 + S_AdresseOut ); + fprintf(stderr, "DONE\n"); fflush(stderr); +} + +TyuInt16 DIASIO::get(){ + return inw( m_Bereich2 + S_AdresseOut ); +} + +void DIASIO::init(){ + + char a_buffer[17]; + + pthread_attr_t watchdog_attr; + + iopl( 3 ); + + sprintf( a_buffer, "/dev/diasio_card%i", 0 ); + m_Deviceio = open( a_buffer, O_RDWR ); + + if( -1 == m_Deviceio ) { + fprintf(stderr, "Kein Zugriff auf IO-Karte %s", a_buffer); + fflush(stderr); + exit(0); + } + + //PCI-Kartenadressen holen + m_Bereich1 = 0; + if( 0 != ioctl( m_Deviceio, D_TCDIASIOC_IOADRESSELESEN, &m_Bereich1 ) ) + { + fprintf(stderr, "couldn't get bereich1\n"); + fflush(stderr); + close( m_Deviceio ); + m_Deviceio = -1; + exit(0); + } + + m_Bereich2 = 1; + if( 0 != ioctl( m_Deviceio, D_TCDIASIOC_IOADRESSELESEN, &m_Bereich2 ) ) + { + fprintf(stderr, "couldn't get bereich2\n"); + fflush(stderr); + close( m_Deviceio ); + m_Deviceio = -1; + exit(0); + } + + m_Bereich3 = 2; + if( 0 != ioctl( m_Deviceio, D_TCDIASIOC_IOADRESSELESEN, &m_Bereich3 ) ) + { + fprintf(stderr, "couldn't get bereich3\n"); + fflush(stderr); + close( m_Deviceio ); + m_Deviceio = -1; + exit(0); + } + + fprintf(stderr, "1: 0x%x, 2: 0x%x, 3: 0x%x\n", m_Bereich1, m_Bereich2, m_Bereich3); + fflush(stderr); + + pthread_attr_init(&watchdog_attr); + if ( pthread_create(&watchdog, &watchdog_attr, watchDogTriggern, NULL) ) + perror("watchdog thread creation failed"); +} -- cgit v1.2.3