summaryrefslogtreecommitdiff
path: root/iotest/src/diasio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'iotest/src/diasio.cpp')
-rw-r--r--iotest/src/diasio.cpp123
1 files changed, 123 insertions, 0 deletions
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 <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);
+ }
+}
+
+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");
+}