diff options
Diffstat (limited to 'dds_io_sub/diasio.cpp')
| -rw-r--r-- | dds_io_sub/diasio.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/dds_io_sub/diasio.cpp b/dds_io_sub/diasio.cpp new file mode 100644 index 0000000..9209fcb --- /dev/null +++ b/dds_io_sub/diasio.cpp @@ -0,0 +1,122 @@ +/* + ============================================================================ + Name : diasio.cpp + Author : Manuel Traut + Version : + Copyright : Your copyright notice + Description : DAIS IO Class + ============================================================================ + */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/io.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <pthread.h> +#include <time.h> + +#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); + S_AdresseOut -= m_Bereich2; + } +} + +void DIASIO::set(TyuInt16 value){ + outw( value, S_AdresseOut ); +} + +TyuInt16 DIASIO::get(){ + return inw( S_AdresseOut ); +} + +void DIASIO::init(){ + S_AdresseOut += m_Bereich2; + + 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"); +} |
