diff options
| author | guest <guest@c30cbac5-9f56-4f76-8ed5-5c34e48a65ae> | 2007-10-10 15:01:48 +0000 |
|---|---|---|
| committer | guest <guest@c30cbac5-9f56-4f76-8ed5-5c34e48a65ae> | 2007-10-10 15:01:48 +0000 |
| commit | e768f895bdd96b06761bea9a359580eb23997173 (patch) | |
| tree | b068f0d8424c57a915f74d3209c6c1943c9fc87d | |
| parent | 6b370d6a7ecdc7c144d3f29372f64deebaa8e582 (diff) | |
git-svn-id: svn+ssh://mecka.net/home/svn/dds@7 c30cbac5-9f56-4f76-8ed5-5c34e48a65ae
| -rw-r--r-- | dds_io_pub/Writer.cpp | 44 | ||||
| -rw-r--r-- | dds_io_pub/Writer.h | 4 | ||||
| -rw-r--r-- | dds_io_pub/diasio.cpp | 131 | ||||
| -rw-r--r-- | dds_io_pub/diasio.h | 75 | ||||
| -rw-r--r-- | dds_io_pub/tctypdef.h | 75 |
5 files changed, 309 insertions, 20 deletions
diff --git a/dds_io_pub/Writer.cpp b/dds_io_pub/Writer.cpp index 82d5173..f0b16f0 100644 --- a/dds_io_pub/Writer.cpp +++ b/dds_io_pub/Writer.cpp @@ -76,39 +76,43 @@ Writer::svc () cout<<"Writer thread, DataWriter Cast ok\n"; struct timespec t_sleep; - t_sleep.tv_sec = 1; - t_sleep.tv_nsec = 500000; + t_sleep.tv_sec = 0; + t_sleep.tv_nsec = 10000; IOTest::Port port_obj; ::DDS::InstanceHandle_t handle = port_dw->_cxx_register (port_obj); port_obj.no = 1; - port_obj.value = 0xff; ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Writer::svc starting to write.\n"))); + + int actval, lastval = 0; + while(1) { - ::DDS::ReturnCode_t ret = port_dw->write(port_obj, handle); - - if (ret != ::DDS::RETCODE_OK) { - ACE_ERROR ((LM_ERROR, - ACE_TEXT("(%P|%t)ERROR Writer::svc, ") - ACE_TEXT ("write() returned %d.\n"), - ret)); - if (ret == ::DDS::RETCODE_TIMEOUT) { - timeout_writes_ ++; - } - cout<<"?\n"; + + actval = io.get(); + + if ( lastval != actval ){ + + lastval = actval; + port_obj.value = actval; + + ::DDS::ReturnCode_t ret = port_dw->write(port_obj, handle); + + if (ret != ::DDS::RETCODE_OK) + ACE_ERROR ((LM_ERROR, + ACE_TEXT("(%P|%t)ERROR Writer::svc, ") + ACE_TEXT ("write() returned %d.\n"), + ret)); + + if (ret == ::DDS::RETCODE_TIMEOUT) + timeout_writes_ ++; } - if( port_obj.value == 0xff ) - port_obj.value = 0x00; - else - port_obj.value = 0xff; - nanosleep(&t_sleep, NULL); - cout<<".\n"; + //cout<<".\n"; } } catch (CORBA::Exception& e) { diff --git a/dds_io_pub/Writer.h b/dds_io_pub/Writer.h index 030211d..bfd603a 100644 --- a/dds_io_pub/Writer.h +++ b/dds_io_pub/Writer.h @@ -7,6 +7,7 @@ #include <dds/DdsDcpsPublicationC.h> #include <ace/Task.h> +#include "diasio.h" class Writer : public ACE_Task_Base { @@ -31,6 +32,9 @@ private: ::DDS::DataWriter_var writer_; ACE_Atomic_Op<ACE_SYNCH_MUTEX, int> finished_instances_; ACE_Atomic_Op<ACE_SYNCH_MUTEX, int> timeout_writes_; + + DIASIO io; + }; #endif /* WRITER_H */ diff --git a/dds_io_pub/diasio.cpp b/dds_io_pub/diasio.cpp new file mode 100644 index 0000000..3e2ca02 --- /dev/null +++ b/dds_io_pub/diasio.cpp @@ -0,0 +1,131 @@ +/* + ============================================================================ + 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--; + + fprintf(stderr, "DECONSTRUCTION OF DAIS\n"); fflush(stderr); + + if(instance == 0){ + stop_wd = true; + pthread_join(watchdog, NULL); + } +} + +void DIASIO::set(TyuInt16 value){ + iopl( 3 ); + //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(){ + iopl( 3 ); + return inw( m_Bereich2 + S_AdresseOut ); +} + +void DIASIO::init(){ + + fprintf(stderr, "INIT DAIS\n"); fflush(stderr); + + 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"); + +} diff --git a/dds_io_pub/diasio.h b/dds_io_pub/diasio.h new file mode 100644 index 0000000..d8a752f --- /dev/null +++ b/dds_io_pub/diasio.h @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// All rights reserved to Trumpf GmbH + Co., Germany +//------------------------------------------------------------------------------ + +#ifndef TCDIASUSER_H +#define TCDIASUSER_H + +// -- required headers --------------------------------------------------------- +#include <linux/ioctl.h> +#include "tctypdef.h" + +/* + * Ioctl definitions + */ + +/* Use 'j' as magic number */ +#define D_TCDIAS_IOC_MAGIC 'j' + +#define D_TCDIASIOC_IOADRESSELESEN _IOWR( D_TCDIAS_IOC_MAGIC, 0, TyuInt32 ) +#define D_TCDIASIOC_MEMLAENGE _IOR( D_TCDIAS_IOC_MAGIC, 1, TysInt32 ) +#define D_TCDIASIOC_MEMOFFSET _IOR( D_TCDIAS_IOC_MAGIC, 2, TyuInt32 ) +#define D_TCDIASIOC_AUTOSTART _IOWR( D_TCDIAS_IOC_MAGIC, 3, TyuInt32 ) +#define D_TCDIASIOC_INTERRUPTBETRIEB _IOWR( D_TCDIAS_IOC_MAGIC, 4, TyuInt32 ) +#define D_TCDIASIOC_BEENDEN _IO( D_TCDIAS_IOC_MAGIC, 5 ) +#define D_TCDIASIOC_BEENDENAUFHEBEN _IO( D_TCDIAS_IOC_MAGIC, 6 ) +#define D_TCDIAS_IOC_MAXNR 7 + + +static const TyuInt32 S_AdresseLS7166 = 0; +static const TyuInt32 S_AdresseLS7166Status = 1; +static const TyuInt32 S_Adresse7Seg1 = 2; +static const TyuInt32 S_Adresse7Seg2 = 3; +static const TyuInt32 S_AdresseOut = 4; +static const TyuInt32 S_AdresseIn = 5; +static const TyuInt32 S_AdresseWatchdog = 0x0c; + +static const TyuInt32 S_AdresseStatus = 6; +static const TyuInt32 S_AdresseADStart = 7; +static const TyuInt32 S_AdresseMultiplexer = 8; +static const TyuInt32 S_AdresseFreigabe = 9; +static const TyuInt32 S_AdresseRevisionLogik = 0x0e; +static const TyuInt32 S_AdresseRevisionKarte = 0x0f; + +//zweiter Adressblock +static const TyuInt32 S_AdresseFrequenzzaehlerLW = 0; +static const TyuInt32 S_AdresseFrequenzzaehlerHW = 2; +static const TyuInt32 S_AdresseIndexRevisionZaehler = 4; +static const TyuInt32 S_AdresseAD = 6; +static const TyuInt32 S_AdresseDA0 = 8; +static const TyuInt32 S_AdresseDA1 = 0x0a; +static const TyuInt32 S_AdresseDA2 = 0x0c; +static const TyuInt32 S_AdresseDA3 = 0x0e; +// -- exported global variables - declarations (should be empty)---------------- + +class DIASIO{ + +public: + DIASIO(); + ~DIASIO(); + void set(TyuInt16 value); + TyuInt16 get(); + static int m_Bereich1; + static int m_Bereich2; + static int m_Bereich3; + static bool stop_wd; + +private: + int m_Deviceio; + static unsigned int instance; + pthread_t watchdog; + + void init(); +}; + +#endif diff --git a/dds_io_pub/tctypdef.h b/dds_io_pub/tctypdef.h new file mode 100644 index 0000000..614771d --- /dev/null +++ b/dds_io_pub/tctypdef.h @@ -0,0 +1,75 @@ +// \HEADER\-------------------------------------------------------------------- +// +// $Archive: //pvcs_tw/data/archives/SensorSystems/Linuxprojekte/DIAS-Linux/rtsystem/src/rtsystem/lrt/treiber/dias4io/tctypdef.h-arc $ +// +// $Revision: 1.0 $ +// +// $Date: Mar 05 2007 12:07:38 $ +// +// $Author: kraussjo $ +// +// CONTENTS : +// +// DESCRIPTION : +// +// RESTRICTIONS : +// +// REQUIRES : +// +//------------------------------------------------------------------------------ +// All rights reserved to Trumpf GmbH + Co., Germany +//------------------------------------------------------------------------------ + +#ifndef tctypdef_H +#define tctypdef_H + + +// -- required headers --------------------------------------------------------- + +// -- forward declarations ----------------------------------------------------- + +// -- exported constants, types, classes --------------------------------------- + +// -- exported functions - declarations ---------------------------------------- + +/** +* Description of +* +* Design Pattern: +* +* @author krauss +* @version $Revision: 1.0 $ +*/ +#if defined DIASLINUX || WIN32 +typedef char TysChar; +typedef unsigned char TyuChar; +typedef signed short TysInt16; +typedef unsigned short TyuInt16; +typedef signed int TysInt32; +typedef unsigned int TyuInt32; +typedef signed long TysInt64; +typedef unsigned long TyuInt64; +typedef float TyReal32; +typedef double TyReal64; +#else +typedef char TysChar; +typedef unsigned char TyuChar; +typedef signed int TysInt16; +typedef unsigned int TyuInt16; +typedef signed long TysInt32; +typedef unsigned long TyuInt32; +typedef float TyReal32; +typedef double TyReal64; +/* +#define TysChar char +#define TyuChar unsigned char +#define TysInt16 int +#define TyuInt16 unsigned int +#define TysInt32 long +#define TyuInt32 unsigned long +#define TyReal32 float +#define TyReal64 double*/ +#endif +// -- exported global variables - declarations (should be empty)---------------- + +#endif |
