Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

/*
   cc32lib.c -- a simple access library for the PCICC32 PCI to CAMAC Interface from ARW Elektronik

   (c) 2000 ARW Elektronik

   this source code is published under GPL (Open Source). You can use, redistrubute and
   modify it unless this header   is not modified or deleted. No warranty is given that
   this software will work like expected.
   This product is not authorized for use as critical component in life support systems
   wihout the express written approval of ARW Elektronik Germany.
 
   Please announce changes and hints to ARW Elektronik

   first steps derived from the LINUX pcicc32 library                   AR   16.03.2000
   new architecture - added WINNT to DLL                                AR   30.07.2000
   added buffer, UNTIL_NOT_Q and AUTOREAD functionality                 AR   17.03.2001
   added interrupt handling                                             AR   08.06.2002
*/

 
/*--- INCLUDES -----------------------------------------------------------------------------------*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "os_info.h"      /* to determine the underlaying OS                                      */
#include "libcc32_95.h"   /* the win95 + 98 parts                                                 */
#include "libcc32_NT.h"   /* the winnt part                                                       */
#include "libcc32.h"      /* shared header bewteen applictaion and library                        */

/*--- DEFINES ------------------------------------------------------------------------------------*/

/*--- EXTERNALS ----------------------------------------------------------------------------------*/

/*--- TYPEDEFS -----------------------------------------------------------------------------------*/
typedef struct
{
        int            (*cc32_open)(char *cszPath, int nModuleNumber, void **handle);
        int            (*cc32_close)(void *handle);
        unsigned short (*cc32_read_word)(void *handle, unsigned int N, unsigned int A, unsigned int F);
        unsigned long  (*cc32_read_long)(void *handle, unsigned int N, unsigned int A, unsigned int F, char *Q, char *X);
        unsigned long  (*cc32_read_long_all)(void *handle, unsigned int N, unsigned int A, unsigned int F);
        void           (*cc32_write_word)(void *handle, unsigned int N, unsigned int A, unsigned int F, unsigned short uwData);
        void           (*cc32_write_long)(void *handle, unsigned int N, unsigned int A, unsigned int F, unsigned long ulData);
        int            (*cc32_poll_error)(void *handle, char *nTimeout, char *nLam);
        int            (*cc32_read_word_buffer)(void * handle, unsigned int N, unsigned int A, unsigned int F, unsigned short *pwBuffer, unsigned long *pdwLen);
        int            (*cc32_read_long_buffer)(void * handle, unsigned int N, unsigned int A, unsigned int F, unsigned long *pdwBuffer, unsigned long *pdwLen);
        int            (*cc32_read_long_all_buffer)(void * handle, unsigned int N, unsigned int A, unsigned int F, unsigned long *pdwBuffer, unsigned long *pdwLen);
        int            (*cc32_access_switch)(void *handle, unsigned short uwSwitch);
        int            (*cc32_enable_interrupt)(void *handle);
        int            (*cc32_disable_interrupt)(void *handle);
        int            (*cc32_get_interrupt)(void *handle, unsigned long *dwStatus);
} MY_ACTIONS;

/*--- GLOBALS ------------------------------------------------------------------------------------*/
MY_ACTIONS  ma;
static BOOLEAN firstime = TRUE;

/*--- FUNCTIONS -----------------------------------------------------------------------*/

//--------------------------------------------------------------------------------------
// open the device
//
int __declspec(dllexport) cc32_open(char *cszPath, int nModuleNumber, CC32_HANDLE *handle)
{
        if (firstime)
        {
                if (IsWindowsNT())
                {
                        ma.cc32_open                                            = cc32_open_NT;
                        ma.cc32_close                                           = cc32_close_NT;
                        ma.cc32_read_word                                       = cc32_read_word_NT;
                        ma.cc32_read_long                                       = cc32_read_long_NT;
                        ma.cc32_read_long_all                           = cc32_read_long_all_NT;
                        ma.cc32_write_word                                      = cc32_write_word_NT;
                        ma.cc32_write_long                                      = cc32_write_long_NT;
                        ma.cc32_poll_error                                      = cc32_poll_error_NT;
                        ma.cc32_read_word_buffer                        = cc32_read_word_buffer_NT;
                        ma.cc32_read_long_buffer                        = cc32_read_long_buffer_NT;
                        ma.cc32_read_long_all_buffer            = cc32_read_long_all_buffer_NT;
                        ma.cc32_access_switch                           = cc32_access_switch_NT;
                        ma.cc32_enable_interrupt            = cc32_enable_interrupt_NT;
                        ma.cc32_disable_interrupt           = cc32_disable_interrupt_NT;
                        ma.cc32_get_interrupt               = cc32_get_interrupt_NT;
                }
                else
                        if (IsWindows95() || IsWindows98())
                        {
                                ma.cc32_open                                            = cc32_open_95;
                                ma.cc32_close                                           = cc32_close_95;
                                ma.cc32_read_word                                       = cc32_read_word_95;
                                ma.cc32_read_long                                       = cc32_read_long_95;
                                ma.cc32_read_long_all                           = cc32_read_long_all_95;
                                ma.cc32_write_word                                      = cc32_write_word_95;
                                ma.cc32_write_long                                      = cc32_write_long_95;
                                ma.cc32_poll_error                                      = cc32_poll_error_95;
                                ma.cc32_read_word_buffer                        = cc32_read_word_buffer_95;
                                ma.cc32_read_long_buffer                        = cc32_read_long_buffer_95;
                                ma.cc32_read_long_all_buffer            = cc32_read_long_all_buffer_95;
                                ma.cc32_access_switch                           = cc32_access_switch_95;
                                ma.cc32_enable_interrupt            = cc32_enable_interrupt_95;
                                ma.cc32_disable_interrupt           = cc32_disable_interrupt_95;
                                ma.cc32_get_interrupt               = cc32_get_interrupt_95;
                        }
                        else
                                return -1;

                firstime = FALSE;
        }

        return ma.cc32_open(cszPath, nModuleNumber, (CC32_HANDLE *)handle);
}

//--------------------------------------------------------------------------------------
// close the device
//
int __declspec(dllexport) cc32_close(CC32_HANDLE handle)
{
        return ma.cc32_close((CC32_HANDLE)handle);
}

//--------------------------------------------------------------------------------------
// read a word
//
unsigned short __declspec(dllexport) cc32_read_word(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F)
{
        return ma.cc32_read_word((CC32_HANDLE) handle, N, A, F);
}

//--------------------------------------------------------------------------------------
// read a long
//
unsigned long __declspec(dllexport) cc32_read_long_all(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F)
{
        return ma.cc32_read_long_all((CC32_HANDLE) handle, N, A, F);
}

//--------------------------------------------------------------------------------------
// read a long and get Q and X
//
unsigned long __declspec(dllexport) cc32_read_long(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F, char *Q, char *X)
{
        return ma.cc32_read_long((CC32_HANDLE) handle, N, A, F, Q, X);
}

//--------------------------------------------------------------------------------------
// write a word
//
void __declspec(dllexport) cc32_write_word(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F, unsigned short uwData)
{
        ma.cc32_write_word((CC32_HANDLE) handle, N, A, F, uwData);
}

//--------------------------------------------------------------------------------------
// write a long
//
void __declspec(dllexport) cc32_write_long(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F, unsigned long ulData)
{
        ma.cc32_write_long((CC32_HANDLE) handle, N, A, F, ulData);
}

//--------------------------------------------------------------------------------------
// read and clear the PCIADA status
//
int __declspec(dllexport) cc32_poll_error(CC32_HANDLE handle, char *nTimeout, char *nLam)
{
        return ma.cc32_poll_error((CC32_HANDLE) handle, nTimeout, nLam);
}

//--------------------------------------------------------------------------------------
// read 'len' words or 'UNTIL_NOT_Q' from a address made out of N,A,F into a buffer
//
int __declspec(dllexport) cc32_read_word_buffer(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F,
                                                                                                                                unsigned short *pwBuffer, unsigned long *pdwLen)
{
        return ma.cc32_read_word_buffer(handle, N, A, F, pwBuffer, pdwLen);
}

//--------------------------------------------------------------------------------------
// read 'len' longs or 'UNTIL_NOT_Q' from a address made out of N,A,F into a buffer, mask 24 bits out
//
int __declspec(dllexport) cc32_read_long_buffer(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F,
                                                                                                                                unsigned long *pdwBuffer, unsigned long *pdwLen)
{
        return ma.cc32_read_long_buffer(handle, N, A, F, pdwBuffer, pdwLen);
}

//--------------------------------------------------------------------------------------
// read 'len' longs or 'UNTIL_NOT_Q' from a address made out of N,A,F into a buffer, without interpretation
//
int __declspec(dllexport) cc32_read_long_all_buffer(CC32_HANDLE handle, unsigned int N, unsigned int A, unsigned int F,
                                                                                                                                unsigned long *pdwBuffer, unsigned long *pdwLen)
{
        return ma.cc32_read_long_all_buffer(handle, N, A, F, pdwBuffer, pdwLen);
}

//--------------------------------------------------------------------------------------
// set the accessmode for the path, e.g. UNTIL_NOT_Q or AUTOREAD or ...
//
int __declspec(dllexport) cc32_access_switch(CC32_HANDLE handle, unsigned short uwSwitch)
{
        return ma.cc32_access_switch(handle, uwSwitch);
}

//--------------------------------------------------------------------------------------
// switch interrupts on
//
int __declspec(dllexport) cc32_enable_interrupt(CC32_HANDLE handle)
{
        return ma.cc32_enable_interrupt(handle);
}

//--------------------------------------------------------------------------------------
// switch interrupts off
//
int __declspec(dllexport) cc32_disable_interrupt(CC32_HANDLE handle)
{
        return ma.cc32_disable_interrupt(handle);
}

//--------------------------------------------------------------------------------------
// wait blocking for the next interrupt
//
int __declspec(dllexport) cc32_get_interrupt(CC32_HANDLE handle, unsigned long *dwStatus)
{
        return ma.cc32_get_interrupt(handle, dwStatus);
}