Premier commit suite au crash du repo le 10 juillet 2017

This commit is contained in:
zonetest
2017-07-11 09:18:32 -04:00
commit d08fe76884
267 changed files with 43069 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#
# $Id: Makefile,v 1.6 2007/01/12 20:20:05 thomasw Exp $
#
# General build makefile. (Includes)
INCLUDEDIR ?= /usr/local/include
CP ?= /bin/cp
RM ?= /bin/rm
## ============================================================================
FILES = seamaxlin.h cethernet.h
## ============================================================================
all: $(FILES)
@echo " *Include dir is prepared."
@echo
objs: $(FILES)
@echo " *Include dir is prepared."
@echo
install: $(FILES)
@echo " *Installing header files to $(INCLUDEDIR)"
@for n in $(FILES); do $(CP) -r $$n $(INCLUDEDIR) || exit 1; done
@echo " Done installing header files."
@echo
uninstall:
@echo " *Uninstalling header files from $(INCLUDEDIR)"
@for n in $(FILES); do $(RM) -rf ${INCLUDEDIR}/$$n || exit 1; done
@echo " Header files removed."
@echo
clean: $(FILES)
@echo " *Nothing to clean in Include dir."
@echo
+122
View File
@@ -0,0 +1,122 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2008, Sealevel Systems
//
// For help please contact us by email at support@sealevel.com.
//
// $Id: cethernet.h,v 1.6 2008/09/24 13:47:40 thomasw Exp $
// ----------------------------------------------------------------------------
#ifndef CETHERNET_H__
#define CETHERNET_H__
// This is for inclusion by the C++ wrapper.
#ifdef __cplusplus
extern "C" {
#endif
// ----------------------------------------------------------------------------
// | Structs used in this library. |
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/// \ingroup group_cethernet_all
/// \brief The device type -- SeaIO_Ethernet or SeaLink_Dev.
/// In the windows version of this library, this function can find both types
/// of devices. To make things simpler, this version of CEthernet only works
/// with SeaIO_Ethernet devices.
// ----------------------------------------------------------------------------
typedef enum ceth_device_type
{
SeaIO_Ethernet = 1, ///< Ethernet enabled SeaIO devices.
SeaLink_Dev = 2, ///< Skeletal SeaLink device support.
Sealevel_All_Devices = 99 ///< Any type.
} ceth_device_type;
// ----------------------------------------------------------------------------
/// \ingroup group_cethernet_all
/// \brief The type of information to set with the set_information function.
/// You may optionally OR two of the commands together. You cannot OR SetDHCP
/// and SetIPAddress. If you do OR one of the IP related functions with
/// SetName, the name parameter should be the last parameter.
// ----------------------------------------------------------------------------
typedef enum ceth_set_types
{
SetIPAddress = 1, ///< Option to set a device's IP address.
SetName = 4, ///< Option to set the device's name.
SetDHCP = 2 ///< Option to enable DHCP mode.
} ceth_set_types;
// ----------------------------------------------------------------------------
/// \ingroup group_cethernet_all
/// \brief An IP, NetMask, or GateWay Address.
/// This is a union which will allow you to access the data in one of three
/// data type methods -- long (all 4 bytes at once), short (2 bytes at a time),
/// or char (1 byte at a time). If you access the data 1 byte at a time, through
/// the c array, each octet is the same as the human readable ip address. ie the
/// first octet (0) in the IP 192.168.0.1 can be accessed through
/// ceth_ip_addr.c[2].
// ----------------------------------------------------------------------------
typedef union ceth_ip_addr
{
unsigned long i; ///< Access all 4 bytes at once.
unsigned short s[2]; ///< Access to two bytes at a time.
unsigned char c[4]; ///< Access to each individual byte.
} ceth_ip_addr;
// ----------------------------------------------------------------------------
/// \ingroup group_cethernet_all
/// \brief This is a MAC address storage struct.
/// This struct can only be accessed one byte at a time.
// ----------------------------------------------------------------------------
typedef struct ceth_addr_info
{
unsigned char c[6]; ///< The six byte of the MAC address.
} ceth_addr_info;
// ----------------------------------------------------------------------------
/// \ingroup group_cethernet_all
/// \brief This is the device info struct.
/// find_devices() expects a list of this structs. The data fields of this
/// struct are filled in in find_device(). Please note that the MAC address can
/// only be retrieved as a privileged user (RAW Sockets).
// ----------------------------------------------------------------------------
typedef struct ceth_device
{
ceth_device_type type; ///< SeaLink or SeaIO.
ceth_addr_info mac_address; ///< Device MAC address.
ceth_ip_addr ip_address; ///< IP address.
ceth_ip_addr net_mask; ///< Device Netmask.
ceth_ip_addr gateway; ///< Device Gateway.
char name[20]; ///< Device name (max 8 bytes).
unsigned char dhcp_enabled; ///< Is DHCP mode enabled?
struct ceth_device *next; ///< Pointer to next device.
void *prop_data; ///< Skeleton. Unused.
} ceth_device, *ceth_device_p;
// ----------------------------------------------------------------------------
// | The C library function prototypes. |
// ----------------------------------------------------------------------------
ceth_device *CEthernet_Alloc(int number);
void CEthernet_Free(ceth_device *list);
int CEthernet_find_devices(ceth_device_type type, int num, ceth_device *list);
int CEthernet_set_information(ceth_device *device, ceth_set_types command, ...);
int CEthernet_recover_module(ceth_device *device);
// ----------------------------------------------------------------------------
// | The C++ class! |
// ----------------------------------------------------------------------------
#ifdef __cplusplus
}
class CCEthernet {
public:
ceth_device *Alloc(int number);
void Free(ceth_device *list);
int find_devices(ceth_device_type type, int number, ceth_device *list);
int set_information(ceth_device *device, ceth_set_types command, ...);
int recover_module(ceth_device *device);
};
#endif //__cplusplus
#endif //CETHERNET_H__
+586
View File
@@ -0,0 +1,586 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2008, Sealevel Systems
//
// For help please contact us by email at support@sealevel.com.
//
// $Id: seamaxlin.h,v 1.11 2009/07/13 19:49:55 kmoody Exp $
// ----------------------------------------------------------------------------
#ifndef PUBLIC_DOCUMENTATION
/*! \mainpage Linux SeaMax API Documentation
* \section warning Internal Disclaimer
*
* <b>WARNING! This document is intended for internal use only.</b>
*/
#else
/*! \mainpage Linux SeaMAX API Documentation
*
* \section intro_sec Introduction
*
* Sealevel digital and analog I/O modules supported by the SeaMAX software
* suite are designed to work with third party applications via the SeaMAX API.
* To help simplify application development, the following documentation
* details the functions of the SeaMAX API. To help you get started, example
* C and C++ source code is provided.
*
* \section start Getting Started
*
* There are three modules that are included in the SeaMAX API:
*
* \li <b>\ref group_seamax_all</b><br>
* The foundation of SeaMAX with functions for configuring, interfacing,
* and modifying supported Sealevel digital I/O modules and devices.
* \li <b>\ref group_cethernet_all</b><br>
* The Ethernet module contains functions related to the discovery and
* configuration of Sealevel I/O devices with an Ethernet interface.
* \li <b>\ref modbusbreakdown</b><br>
* The Modbus Specification contains detailed descriptions of all RTU
* and TCP Modbus commands applicable to SeaIO and SeaDAC modules.
*
* The 'Modules' tab above lists all SeaMAX modules and their functions. For
* additional information regarding legacy products and technical
* specifications, please refer to the 'Related Pages' tab above.
*
* \section questions Questions & Comments
*
* Send your questions and comments to Sealevel Systems. For technical
* assistance, please include your model or part number and any device
* settings that may apply. Technical support is available Monday to
* Friday from 8:00AM to 5:00PM (US Eastern Time Zone, UTC-6 hours) by
* email (support@sealevel.com) or by phone at +1 (864) 843.4343.
*/
/// \defgroup group_seamax_all SeaMAX API
/// The SeaMAX API consists of the functions outline below, and provides an
/// interface for construction, transmission, and reception of Modbus RTU and
/// TCP commands. For more information, click a function name below for
/// detailed information on function use, parameter types, and return codes.
///
/// \note Not every function below may apply to your specific Sealevel I/O
/// device. Refer to the \ref modbusbreakdown "modbus breakdown".
/// \defgroup group_cethernet_all SeaMAX Ethernet Discovery/Configuration API
///
/// The SeaMAX Ethernet Discover API includes functions used for configuration
/// and discovery of Ethernet enabled Sealevel I/O devices. For specifics,
/// click any of the function names below to view function use, parameters, and
/// return code information.
/// \ingroup group_seamax_all
/// \defgroup group_seamax_oop Object-Oriented SeaMAX Modbus Interface
/// This is a C++ wrapper for the standard SeaMAX Modbus interface library.
/// This library is designed to aid in the construction, transmission, and
/// reception of Modbus RTU and TCP commands. This library is designed for use
/// with Sealevel SeaIO modules.
///
/// \ingroup group_seamax_all
/// \defgroup group_seamax_fun Functional SeaMAX Modbus Interface
/// This is a simple C library to aid in the construction, transmission, and
/// reception of Modbus RTU and TCP commands. This library is designed for use
/// with Sealevel SeaIO modules.
///
/// \ingroup group_cethernet_all
/// \defgroup group_cethernet_oop Object Oriented CEthernet Interface
/// This is a C++ wrapper for the standard CEthernet library. This library is
/// designed to aid in the discovery and configuration of Ethernet enabled
/// SeaIO modules.
///
/// \ingroup group_cethernet_all
/// \defgroup group_cethernet_fun Functional CEthernet Interface
/// This is a simple C library to aid in the discovery and configuration
/// of Ethernet enabled SeaIO modules.
///
#endif
#ifndef SEAMAXLIN_H__
#define SEAMAXLIN_H__
#include "thirdparty/ftdi.h"
// Sealevel vendor ID number
#define VENDOR 0x0c52
// This is used for proper inclusion when used with C++
#ifdef __cplusplus
extern "C" {
#endif
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \typedef SeaMaxLin
/// Pointer to a SeaMax object. The data structure this points to is private
/// and should not be accessed directly, but through the function calls instead.
// ----------------------------------------------------------------------------
typedef long SeaMaxLin;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \typedef HANDLE
/// A handle or pointer to another data structure.
/// This particular pointer is used to pass the serial communications struct.
// ----------------------------------------------------------------------------
typedef int HANDLE;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \typedef slave_address_t
/// The slave ID of a device. This value can be from 1 to 247.
// ----------------------------------------------------------------------------
typedef unsigned char slave_address_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \typedef address_loc_t
/// An address specific to your device. Check read/write functions for
/// specific use.
// ----------------------------------------------------------------------------
typedef unsigned short address_loc_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \typedef address_range_t
/// The range of address to be used. Check read/write functions for specific
/// use.
// ----------------------------------------------------------------------------
typedef unsigned short address_range_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief The module connection type.
/// Currently there is only support for RTU and TCP type connections.
// ----------------------------------------------------------------------------
typedef enum
{
NO_CONNECT = 0, ///< Connection not open.
MODBUS_RTU = 1, ///< An RTU type connection. 232, 485, USB.
MODBUS_TCP = 2, ///< An ethernet connection.
FTDI_DIRECT = 3 ///< An ethernet connection.
} seaio_mode_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief The current baud rate used by a RTU type module.
/// If the module is TCP type, then BR9600, the default, will be used.
/// Note these are not the same values used by the termios library.
// ----------------------------------------------------------------------------
typedef enum
{
BRNONE = 0, ///< Default value, no connection, or unkown baud rate.
BR1200 = 1, ///< 1200 baud.
BR2400 = 2, ///< 2400 baud.
BR4800 = 3, ///< 4800 baud.
BR9600 = 4, ///< 9600 baud.
BR14400 = 5, ///< 14400 baud.
BR19200 = 6, ///< 19200 baud.
BR28800 = 7, ///< 28800 baud.
BR38400 = 8, ///< 38400 baud.
BR57600 = 9, ///< 57600 baud.
BR115200 = 10 ///< 115200 baud.
} baud_rates_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief The currently used parity.
/// Parity is a quick and simple method of checking for errors. It doesn't
/// work all the time, but it is very simple to implement.
// ----------------------------------------------------------------------------
typedef enum
{
P_NONE = 0, ///< No parity (Default).
P_ODD = 1, ///< Odd parity.
P_EVEN = 2 ///< Even parity.
} parity_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief The type of read / write to preform.
/// Note that not all types can be written. For example an attempt to write to
/// D_INPUTS or INPUTREG would cause an EINVAL error. Also you can not directly
/// write to SETUPREGS, you must use an appropriate Ioctl.
// ----------------------------------------------------------------------------
typedef enum
{
COILS = 1, ///< Coils are any relay type outputs.
D_INPUTS = 2, ///< Digitial inputs. Single bit inputs.
HOLDINGREG = 3, ///< Configuration registers.
INPUTREG = 4, ///< Registers only used on A/D type devices.
SETUPREG = 5, ///< Advanced device configuration registers.
SEAMAXPIO = 6 ///< Programmable type I/O.
} seaio_type_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \ingroup group_seamax_all
/// \brief The type of IOCTL operation desired.
/// Read the manual carefully when using these. There are some specific
/// methods that must be followed to use correctly.
// ----------------------------------------------------------------------------
typedef enum
{
IOCTL_READ_COMM_PARAM = 1, ///< Read communication parameters.
IOCTL_SET_ADDRESS = 2, ///< Set device slave ID.
IOCTL_SET_COMM_PARAM = 3, ///< Set communication parameters.
IOCTL_GET_PIO = 4, ///< Get direction of programmable I/O.
IOCTL_SET_PIO = 5, ///< Set direction of programmable I/O.
IOCTL_GET_ADDA_CONFIG = 6, ///< Get A/D configuration information.
IOCTL_SET_ADDA_CONFIG = 7, ///< Set the A/D configuration.
IOCTL_GET_EXT_CONFIG = 8, ///< Extended module id (SeaDAC).
IOCTL_GET_ADDA_EXT_CONFIG = 9, ///< Information about D/A jumpers.
} IOCTL_t;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief 48 Bit pio configuration.
/// This struct is contained within the \a SeaMAX_PIO_ioctl_s struct. It is
/// used whenever retrieving or setting port direction on a PIO device with
/// 48 bits of I/O.
// ----------------------------------------------------------------------------
typedef struct PIO48_config_s
{
unsigned char channel1; ///< Bits 0-5 map ports 1-6. (0:O, 1:I)
} PIO48_config_s;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief 96 Bit pio configuration.
/// This struct is contained within the \a SeaMAX_PIO_ioctl_s struct. It is
/// used whenever retrieving or setting port direction on a PIO device with
/// 96 bits of I/O.
// ----------------------------------------------------------------------------
typedef struct PIO96_config_s
{
unsigned char channel1; ///< Bits 0-5 map ports 1-6. (0:O, 1:I)
unsigned char channel2; ///< Bits 0-5 map ports 7-12. (0:O, 1:I)
} PIO96_config_s;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief This struct is used to set the address of a particular device.
/// In this way, it becomes unnecessary to manually turn the screw terminal to
/// configure a particular SeaIO device. It also allows for more devices than
/// the physically selectable 15 addresses.
// ----------------------------------------------------------------------------
typedef struct seaio_ioctl_address_s
{
unsigned char new_address; ///< Address value from 1 to 247.
} seaio_ioctl_address_s;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief Communication parameters (desired) struct.
/// This struct can be used to set a desired communication configuration.
/// Note that you must first call get params before you attempt to set params,
/// or it will fail.
// ----------------------------------------------------------------------------
typedef struct seaio_ioctl_comms_s
{
baud_rates_t new_baud_rate; ///< Desire baud rate (/a baud_rates_t).
parity_t new_parity; ///< Desire parity (/a parity_t).
} seaio_ioctl_comms_s;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief Communication parameters (current) struct.
/// This struct can be used to store the current communication parameters.
/// Note that you will have call get params before you may set a configuration,
/// or it will fail.
// ----------------------------------------------------------------------------
typedef struct seaio_ioctl_get_params_s
{
unsigned short model; ///< Device model number (410, 462, ...)
unsigned char bridge_type; ///< Bridge type (M, E, U, S, or N).
baud_rates_t baud_rate; ///< The device's communication baud rate.
parity_t parity; ///< The device's communication parity.
unsigned char magic_cookie; ///< \internal Multithread saftey.
} seaio_ioctl_get_params_s;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief PIO data/setup struct.
/// This struct can be used to read data from a PIO device, or configure a PIO
/// device.
// ----------------------------------------------------------------------------
typedef struct SeaMAX_PIO_ioctl_s
{
unsigned short model; ///< Device model number (462, 463, ...)
union
{
PIO48_config_s PIO48; ///< PIO directions /a PIO48_config_s
PIO96_config_s PIO96; ///< PIO directions /a PIO96_config_s
} config_state;
} SeaMAX_PIO_ioctl_s;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief PIO data/setup struct.
/// This struct can be used to read data from a PIO device, or configure a PIO
/// device.
// ----------------------------------------------------------------------------
typedef struct seaio_ioctl_ext_config
{
unsigned short model; ///< Device model number (SeaDAC)
} seaio_ioctl_ext_config;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief The IOCTL struct used in the majority of the IOCTL calls.
/// Every call except the three involving A/D and D/A converters use this
/// struct. This struct is actually the union of several smaller structs, so
/// that it can be used multiple times.
// ----------------------------------------------------------------------------
typedef struct seaio_ioctl_s
{
union
{
seaio_ioctl_address_s address; ///< IOCTL_SET_ADDRESS
seaio_ioctl_comms_s comms; ///< IOCTL_READ_COMM_PARAM
seaio_ioctl_get_params_s params; ///< IOCTL_SET_COMM_PARAM
SeaMAX_PIO_ioctl_s pio; ///< IOCTL_GET/SET_PIO
seaio_ioctl_ext_config config; ///< IOCTL_GET_EXT_CONFIG
} u; ///< Keep size down to largest struct inside.
} seaio_ioctl_s;
// ----------------------------------------------------------------------------
// | ADDA structs and types. |
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief ADDA conversion range configuration type.
/// This is the range of voltages that the A/D will convert into values from
/// 0x000 to 0xFFF (0-4095). Plus to minus conversions do use a sign bit, so
/// 4095 is not necessarily the highest value.
// ----------------------------------------------------------------------------
typedef enum
{
ZERO_TO_FIVE = 0, ///< 0-5V (0x000-0xFFF)
PLS_MIN_FIVE = 1, ///< -5-5V (0x800-0x7FF)
ZERO_TO_TEN = 2, ///< 0-10V (0x000-0xFFF)
PLS_MIN_TEN = 3 ///< -10-10V (0x800-0x7FF)
} channel_range_type;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// ADDA mode configuration type.
/// This is how the board is physically configured to read Analog signals. The
/// way to measure. You can either measure 16 signals with a single common
/// ground, 8 isolated signals, or the current pulled through internal resistors
/// from 8 separate signals.
// ----------------------------------------------------------------------------
typedef enum
{
SINGLE_ENDED = 0, ///< 16 common ground channels.
DIFFERENTIAL = 1, ///< 8 differential channels.
CURRENT_LOOP = 2 ///< 8 current loop measurements.
} channel_mode_type;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief ADDA reference type configuration.
/// This controls the mux that is in charge of input to the single A/D chip on
/// an A/D capable device. This provides some small A/D diagnostics if you
/// desire to use them.
// ----------------------------------------------------------------------------
typedef enum
{
ANALOG_OFFSET = 0, ///< The A/D inputs available on the device.
GND_OFFSET = 1, ///< A ground value. Should always read 0V.
AD_REF_OFFSET = 2, ///< A/D reference value. Should always read 0V.
DA_CHANNEL_1 = 4, ///< D/A channel one as input.
DA_CHANNEL_2 = 8 ///< D/A channel two as input.
} ad_reference_type;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief The ADDA data struct used in the ADDA ioctl calls.
/// Contains information about device configuration.
// ----------------------------------------------------------------------------
typedef struct adda_config
{
/// Overall device settings.
struct
{
unsigned char reference_offset; ///< A/D Mux address.
unsigned char channel_mode; ///< Measurement mode.
} device;
/// Each channel uses 2 bits for configuration.
/// Each of the bytes in this struct uses the lowest
/// two bits for each channel configuration.
struct
{
unsigned char ch_1;
unsigned char ch_2;
unsigned char ch_3;
unsigned char ch_4;
unsigned char ch_5;
unsigned char ch_6;
unsigned char ch_7;
unsigned char ch_8;
unsigned char ch_9;
unsigned char ch_10;
unsigned char ch_11;
unsigned char ch_12;
unsigned char ch_13;
unsigned char ch_14;
unsigned char ch_15;
unsigned char ch_16;
} channels;
} adda_config;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief Data struct returned by get ext adda ioctl.
/// Contains information about the physical jumper configuration of the device.
// ----------------------------------------------------------------------------
typedef struct adda_ext_config
{
unsigned char ad_multiplier_enabled; ///< A/D amplifier.
channel_range_type da_channel_1_range; ///< D/A1 range.
channel_range_type da_channel_2_range; ///< D/A2 range
} adda_ext_config;
// ----------------------------------------------------------------------------
/// \ingroup group_seamax_all
/// \brief SeaDAC Lite range configuration type.
/// This is the range of available SeaDAC products
// ----------------------------------------------------------------------------
typedef enum
{
SDL_8111 = 0x8111, ///< 4 inputs and 4 reed outputs
SDL_8112, ///< 4 inputs and 4 form-c outputs
SDL_8113, ///< 4 inputs
SDL_8114, ///< 4 reed outputs
SDL_8115, ///< 4 form-c outputs
SDL_8126 = 0x8126 ///< 32 TTL I/O
} sdl_range_type;
typedef enum
{
SCL = 0x01, SDA = 0x02, TDO = 0x04, CS = 0x08,
GPIO_0 = 0x01, GPIO_1 = 0x02, GPIO_2 = 0x04, GPIO_3 = 0x08,
GPIO_4 = 0x10, GPIO_5 = 0x20, GPIO_6 = 0x40, GPIO_7 = 0x80
} sdl_i2c_type;
// ----------------------------------------------------------------------------
// SeaMaxModule struct.
// This structure is used internally to keep track of a module that open() has
// been called on.
// ----------------------------------------------------------------------------
typedef struct seaMaxModule
{
int throttle; //Throttling delay for RTU mode.
seaio_mode_t commMode; //Communication medium (RTU or TCP).
HANDLE hDevice; //Device comm interface.
int mutex; //Multithread (force sequential).
struct termios *initalConfig; //Original serial configuration.
struct ftdi_context ftdic; //For SeaDAC Lite modules
int deviceType;
} seaMaxModule;
// ----------------------------------------------------------------------------
// | private prototypes |
// ----------------------------------------------------------------------------
int InitializeI2C(seaMaxModule*);
void ExecuteQueue(seaMaxModule*);
void InitializeQueue(void);
void ExecuteQueue(seaMaxModule*);
void ReadRegister(unsigned char, unsigned char, unsigned char*);
void WriteRegister(unsigned char, unsigned char, unsigned char);
void SetGPIO(unsigned char, unsigned char);
// ----------------------------------------------------------------------------
// | API prototypes |
// ----------------------------------------------------------------------------
SeaMaxLin *SeaMaxLinCreate(void);
int SeaMaxLinDestroy(SeaMaxLin *SeaMaxPointer);
int SeaMaxLinOpen(SeaMaxLin *SeaMaxPointer, char *filename);
int SeaMaxLinClose(SeaMaxLin *SeaMaxPointer);
int SeaMaxLinRead(SeaMaxLin *SeaMaxPointer, slave_address_t slaveId,
seaio_type_t type, address_loc_t starting_address,
address_range_t range, void *data);
int SeaDacLinRead(SeaMaxLin *SeaMaxPointer, unsigned char *data,
int numBytes);
int SeaMaxLinWrite(SeaMaxLin *SeaMaxPointer, slave_address_t slaveId,
seaio_type_t type, address_loc_t starting_address,
address_range_t range, unsigned char *data);
int SeaDacLinWrite(SeaMaxLin *SeaMaxPointer, unsigned char *data,
int numBytes);
int SeaMaxLinIoctl(SeaMaxLin *SeaMaxPointer, slave_address_t slaveId,
IOCTL_t which, void *data);
int SeaMaxLinSetIMDelay(SeaMaxLin *SeaMaxPointer, int delay);
int SeaDacGetPIO(SeaMaxLin *SeaMaxPointer, unsigned char* data);
int SeaDacSetPIO(SeaMaxLin *SeaMaxPointer, unsigned char* data);
int SeaDacSetPIODirection(SeaMaxLin *SeaMaxPointer, unsigned char* data);
int SeaDacGetPIODirection(SeaMaxLin *SeaMaxPointer, unsigned char* data);
HANDLE SeaMaxLinGetCommHandle(SeaMaxLin *SeaMaxPointer);
// ----------------------------------------------------------------------------
// | End of C library function calls. |
// ----------------------------------------------------------------------------
#ifdef __cplusplus
}
class CSeaMaxLin {
public:
CSeaMaxLin(void);
~CSeaMaxLin(void);
int Open(char *filename);
int Close(void);
int Read(slave_address_t slaveId, seaio_type_t type,
address_loc_t starting_address, address_range_t range,
void *data);
int Read(unsigned char *data, int length);
int Write(slave_address_t slaveId, seaio_type_t type,
address_loc_t starting_address,
address_range_t range, unsigned char *data);
int Write(unsigned char *data, int length);
int Ioctl(slave_address_t slaveId, IOCTL_t which, void *data);
int set_intermessage_delay(int delay);
int GetPIO(unsigned char* data);
int SetPIO(unsigned char* data);
int SetPIODirection(unsigned char* data);
int GetPIODirection(unsigned char* data);
HANDLE getCommHandle(void);
private:
SeaMaxLin *SeaMaxPointer;
};
#endif //__cplusplus
#endif //SEAMAXLIN_H__
+356
View File
@@ -0,0 +1,356 @@
/***************************************************************************
ftdi.h - description
-------------------
begin : Fri Apr 4 2003
copyright : (C) 2003 by Intra2net AG
email : opensource@intra2net.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License *
* version 2.1 as published by the Free Software Foundation; *
* *
***************************************************************************/
#ifndef __libftdi_h__
#define __libftdi_h__
#include <usb.h>
#define FTDI_DEFAULT_EEPROM_SIZE 128
/** FTDI chip type */
enum ftdi_chip_type { TYPE_AM=0, TYPE_BM=1, TYPE_2232C=2, TYPE_R=3, TYPE_2232H=4, TYPE_4232H=5 };
/** Parity mode for ftdi_set_line_property() */
enum ftdi_parity_type { NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4 };
/** Number of stop bits for ftdi_set_line_property() */
enum ftdi_stopbits_type { STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 };
/** Number of bits for ftdi_set_line_property() */
enum ftdi_bits_type { BITS_7=7, BITS_8=8 };
/** Break type for ftdi_set_line_property2() */
enum ftdi_break_type { BREAK_OFF=0, BREAK_ON=1 };
/** MPSSE bitbang modes */
enum ftdi_mpsse_mode
{
BITMODE_RESET = 0x00,
BITMODE_BITBANG= 0x01,
BITMODE_MPSSE = 0x02,
BITMODE_SYNCBB = 0x04,
BITMODE_MCU = 0x08,
/* CPU-style fifo mode gets set via EEPROM */
BITMODE_OPTO = 0x10,
BITMODE_CBUS = 0x20
};
/** Port interface for FT2232C */
enum ftdi_interface
{
INTERFACE_ANY = 0,
INTERFACE_A = 1,
INTERFACE_B = 2,
INTERFACE_C = 3,
INTERFACE_D = 4
};
/* Shifting commands IN MPSSE Mode*/
#define MPSSE_WRITE_NEG 0x01 /* Write TDI/DO on negative TCK/SK edge*/
#define MPSSE_BITMODE 0x02 /* Write bits, not bytes */
#define MPSSE_READ_NEG 0x04 /* Sample TDO/DI on negative TCK/SK edge */
#define MPSSE_LSB 0x08 /* LSB first */
#define MPSSE_DO_WRITE 0x10 /* Write TDI/DO */
#define MPSSE_DO_READ 0x20 /* Read TDO/DI */
#define MPSSE_WRITE_TMS 0x40 /* Write TMS/CS */
/* FTDI MPSSE commands */
#define SET_BITS_LOW 0x80
/*BYTE DATA*/
/*BYTE Direction*/
#define SET_BITS_HIGH 0x82
/*BYTE DATA*/
/*BYTE Direction*/
#define GET_BITS_LOW 0x81
#define GET_BITS_HIGH 0x83
#define LOOPBACK_START 0x84
#define LOOPBACK_END 0x85
#define TCK_DIVISOR 0x86
/* Value Low */
/* Value HIGH */ /*rate is 12000000/((1+value)*2) */
#define DIV_VALUE(rate) (rate > 6000000)?0:((6000000/rate -1) > 0xffff)? 0xffff: (6000000/rate -1)
/* Commands in MPSSE and Host Emulation Mode */
#define SEND_IMMEDIATE 0x87
#define WAIT_ON_HIGH 0x88
#define WAIT_ON_LOW 0x89
/* Commands in Host Emulation Mode */
#define READ_SHORT 0x90
/* Address_Low */
#define READ_EXTENDED 0x91
/* Address High */
/* Address Low */
#define WRITE_SHORT 0x92
/* Address_Low */
#define WRITE_EXTENDED 0x93
/* Address High */
/* Address Low */
/* Definitions for flow control */
#define SIO_RESET 0 /* Reset the port */
#define SIO_MODEM_CTRL 1 /* Set the modem control register */
#define SIO_SET_FLOW_CTRL 2 /* Set flow control register */
#define SIO_SET_BAUD_RATE 3 /* Set baud rate */
#define SIO_SET_DATA 4 /* Set the data characteristics of the port */
#define FTDI_DEVICE_OUT_REQTYPE (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT)
#define FTDI_DEVICE_IN_REQTYPE (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN)
/* Requests */
#define SIO_RESET_REQUEST SIO_RESET
#define SIO_SET_BAUDRATE_REQUEST SIO_SET_BAUD_RATE
#define SIO_SET_DATA_REQUEST SIO_SET_DATA
#define SIO_SET_FLOW_CTRL_REQUEST SIO_SET_FLOW_CTRL
#define SIO_SET_MODEM_CTRL_REQUEST SIO_MODEM_CTRL
#define SIO_POLL_MODEM_STATUS_REQUEST 0x05
#define SIO_SET_EVENT_CHAR_REQUEST 0x06
#define SIO_SET_ERROR_CHAR_REQUEST 0x07
#define SIO_SET_LATENCY_TIMER_REQUEST 0x09
#define SIO_GET_LATENCY_TIMER_REQUEST 0x0A
#define SIO_SET_BITMODE_REQUEST 0x0B
#define SIO_READ_PINS_REQUEST 0x0C
#define SIO_READ_EEPROM_REQUEST 0x90
#define SIO_WRITE_EEPROM_REQUEST 0x91
#define SIO_ERASE_EEPROM_REQUEST 0x92
#define SIO_RESET_SIO 0
#define SIO_RESET_PURGE_RX 1
#define SIO_RESET_PURGE_TX 2
#define SIO_DISABLE_FLOW_CTRL 0x0
#define SIO_RTS_CTS_HS (0x1 << 8)
#define SIO_DTR_DSR_HS (0x2 << 8)
#define SIO_XON_XOFF_HS (0x4 << 8)
#define SIO_SET_DTR_MASK 0x1
#define SIO_SET_DTR_HIGH ( 1 | ( SIO_SET_DTR_MASK << 8))
#define SIO_SET_DTR_LOW ( 0 | ( SIO_SET_DTR_MASK << 8))
#define SIO_SET_RTS_MASK 0x2
#define SIO_SET_RTS_HIGH ( 2 | ( SIO_SET_RTS_MASK << 8 ))
#define SIO_SET_RTS_LOW ( 0 | ( SIO_SET_RTS_MASK << 8 ))
#define SIO_RTS_CTS_HS (0x1 << 8)
/* marker for unused usb urb structures
(taken from libusb) */
#define FTDI_URB_USERCONTEXT_COOKIE ((void *)0x1)
/**
\brief Main context structure for all libftdi functions.
Do not access directly if possible.
*/
struct ftdi_context
{
/* USB specific */
/** libusb's usb_dev_handle */
struct usb_dev_handle *usb_dev;
/** usb read timeout */
int usb_read_timeout;
/** usb write timeout */
int usb_write_timeout;
/* FTDI specific */
/** FTDI chip type */
enum ftdi_chip_type type;
/** baudrate */
int baudrate;
/** bitbang mode state */
unsigned char bitbang_enabled;
/** pointer to read buffer for ftdi_read_data */
unsigned char *readbuffer;
/** read buffer offset */
unsigned int readbuffer_offset;
/** number of remaining data in internal read buffer */
unsigned int readbuffer_remaining;
/** read buffer chunk size */
unsigned int readbuffer_chunksize;
/** write buffer chunk size */
unsigned int writebuffer_chunksize;
/* FTDI FT2232C requirecments */
/** FT2232C interface number: 0 or 1 */
int interface; /* 0 or 1 */
/** FT2232C index number: 1 or 2 */
int index; /* 1 or 2 */
/* Endpoints */
/** FT2232C end points: 1 or 2 */
int in_ep;
int out_ep; /* 1 or 2 */
/** Bitbang mode. 1: (default) Normal bitbang mode, 2: FT2232C SPI bitbang mode */
unsigned char bitbang_mode;
/** EEPROM size. Default is 128 bytes for 232BM and 245BM chips */
int eeprom_size;
/** String representation of last error */
char *error_str;
/** Buffer needed for async communication */
char *async_usb_buffer;
/** Number of URB-structures we can buffer */
unsigned int async_usb_buffer_size;
};
/**
\brief list of usb devices created by ftdi_usb_find_all()
*/
struct ftdi_device_list
{
/** pointer to next entry */
struct ftdi_device_list *next;
/** pointer to libusb's usb_device */
struct usb_device *dev;
};
/**
\brief FTDI eeprom structure
*/
struct ftdi_eeprom
{
/** vendor id */
int vendor_id;
/** product id */
int product_id;
/** self powered */
int self_powered;
/** remote wakeup */
int remote_wakeup;
/** chip type */
int BM_type_chip;
/** input in isochronous transfer mode */
int in_is_isochronous;
/** output in isochronous transfer mode */
int out_is_isochronous;
/** suspend pull downs */
int suspend_pull_downs;
/** use serial */
int use_serial;
/** fake usb version */
int change_usb_version;
/** usb version */
int usb_version;
/** maximum power */
int max_power;
/** manufacturer name */
char *manufacturer;
/** product name */
char *product;
/** serial number */
char *serial;
/** eeprom size in bytes. This doesn't get stored in the eeprom
but is the only way to pass it to ftdi_eeprom_build. */
int size;
};
#ifdef __cplusplus
extern "C"
{
#endif
int ftdi_init(struct ftdi_context *ftdi);
struct ftdi_context *ftdi_new();
int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface);
void ftdi_deinit(struct ftdi_context *ftdi);
void ftdi_free(struct ftdi_context *ftdi);
void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev);
int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
int vendor, int product);
void ftdi_list_free(struct ftdi_device_list **devlist);
void ftdi_list_free2(struct ftdi_device_list *devlist);
int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct usb_device *dev,
char * manufacturer, int mnf_len,
char * description, int desc_len,
char * serial, int serial_len);
int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
const char* description, const char* serial);
int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev);
int ftdi_usb_close(struct ftdi_context *ftdi);
int ftdi_usb_reset(struct ftdi_context *ftdi);
int ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi);
int ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi);
int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
int ftdi_set_line_property2(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity,
enum ftdi_break_type break_type);
int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
int ftdi_write_data_async(struct ftdi_context *ftdi, unsigned char *buf, int size);
void ftdi_async_complete(struct ftdi_context *ftdi, int wait_for_more);
int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask);
int ftdi_disable_bitbang(struct ftdi_context *ftdi);
int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode);
int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status);
/* flow control */
int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
int ftdi_setdtr_rts(struct ftdi_context *ftdi, int dtr, int rts);
int ftdi_setdtr(struct ftdi_context *ftdi, int state);
int ftdi_setrts(struct ftdi_context *ftdi, int state);
int ftdi_set_event_char(struct ftdi_context *ftdi, unsigned char eventch, unsigned char enable);
int ftdi_set_error_char(struct ftdi_context *ftdi, unsigned char errorch, unsigned char enable);
/* set eeprom size */
void ftdi_eeprom_setsize(struct ftdi_context *ftdi, struct ftdi_eeprom *eeprom, int size);
/* init and build eeprom from ftdi_eeprom structure */
void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
int ftdi_eeprom_decode(struct ftdi_eeprom *eeprom, unsigned char *output, int size);
/* "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator)
the checksum of the eeprom is valided */
int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
int ftdi_read_eeprom_getsize(struct ftdi_context *ftdi, unsigned char *eeprom, int maxsize);
int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
int ftdi_erase_eeprom(struct ftdi_context *ftdi);
char *ftdi_get_error_string(struct ftdi_context *ftdi);
#ifdef __cplusplus
}
#endif
#endif /* __libftdi_h__ */