Commit 29fb1c0e authored by claes's avatar claes

Module profibus created

parent f9e7f984
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************/
/* */
/* SOFTING GmbH */
/* Richard-Reitzner-Allee 6 */
/* D-85540 Haar */
/* Phone: (++49)-(0)89-45656-0 */
/* Fax: (++49)-(0)89-45656-399 */
/* */
/* Copyright (C) SOFTING GmbH 1995-1999 */
/* All Rights Reserved */
/* */
/*****************************************************************************/
/*****************************************************************************/
/* PROFIBoard SPECIFIC DEFINES */
/* Filename : PB_HW.H */
/* Version : 5.22.0.00.release */
/* Date : 26-February-1999 */
/* Author : SOFTING-BG2 */
/* */
/* Description : This file contains the PROFIboard specific defines */
/* */
/* CHANGE_NOTES */
/* */
/* date name change */
/* ----------------------------------------------------------------------- */
/* 03.03.98 BOE new/modify #defines for DPRAM SIZES and IRQ-VAL */
/* offset in DPR */
/* */
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#ifndef __PB_HW__
#define __PB_HW__
/* --- macros to access DPR ----------------------------------------------- */
#define _GET_DPR_BYTE(var) var
#define _SET_DPR_BYTE(out_var,in_var) out_var = in_var
#define _GET_DPR_WORD(var) var
#define _SET_DPR_WORD(out_var,in_var) out_var = in_var
#define _SET_CHIP_SELECT_ADDR(addr)
/* --- DPRAM SIZES / IRQ-VAL offset in DPR --------------------------------- */
#define DPRAM_SIZE_PROFIBOARD 0x4000 /* 16 KB DPRAM */
#define DPRAM_SIZE_PROFI_104 0x4000 /* 16 KB DPRAM */
#define DPRAM_H_TO_C_IRQ_OFFSET 0x2 /* IRQ memory cells at DPRAM end */
#define DPRAM_C_TO_H_IRQ_OFFSET 0x4
/* --- IRQ-VALUE ----------------------------------------------------------- */
#define RST_IRQ_VALUE 0xAA /* Reset */
#define REQ_IRQ_VALUE 0xF0 /* SND/RCV Request */
#define ACK_IRQ_VALUE 0x0F /* SND/RCV Acknowledge */
#define DP_SLAVE_IO_REQ_IRQ_VALUE 0xE0 /* DP-SLAVE-IO Request */
#define DP_SLAVE_IO_ACK_IRQ_VALUE 0x0E /* DP-SLAVE-IO Acknowldege */
#define DP_DATA_STOP_REQ_IRQ_VALUE 0xD0 /* data transfer stop Request */
#define DP_DATA_STOP_ACK_IRQ_VALUE 0x0D /* data transfer stop Acknowldege */
/* --- Read Registers in the I/O Area of the PC ---------------------------- */
#define IDENT_1 (IO_BASE_ADD + 0) /* Identification Byte 1 */
#define IDENT_2 (IO_BASE_ADD + 1) /* Identification Byte 2 */
#define IDENT_3 (IO_BASE_ADD + 2) /* Identification Byte 3 */
#define IDENT_4 (IO_BASE_ADD + 3) /* Identification Byte 4 */
/* --- Write Registers in the I/O Area of the PC --------------------------- */
#define BOARD_CTRL (IO_BASE_ADD + 0) /* Board Control Register */
#define BASE_ADD (IO_BASE_ADD + 1) /* DPRAM Base Address Register */
#define PAGE_SEL (IO_BASE_ADD + 2) /* Page Select Register */
#define CP_IRQ (IO_BASE_ADD + 3) /* Interrupt Register */
/* -- Pindefinition of the Board Control Register -------------------------- */
#define C165_RESET 0x01 /* Reset of the C165 (low active)*/
#define EN_DPRAM 0x02 /* Enable DPRAM for PC (high active)*/
#define SIZE_16_64 0x04 /* DPRAM size 1:16 kByte 0:64kByte*/
/* 64 kByte (low) */
#define BASE_A14 0x08 /* Address low within the 64 kByte */
#define BASE_A15 0x10 /* Address high within the 64 kByte */
#define DPR_WIDTH_8_16 0x20 /* DPRAM width 0:16Bit 1:8Bit */
#define MEMCS16_LA_SA 0x40 /* MEMCS16 generation 0:LA 1:SA */
/* --- Pindefinition of the DPRAM Base Adress Register --------------------- */
/* Bit 7: Base Address 23 (MSB) to */
/* Bit 0: Base Address 16 (LSB) */
/* --- Pindefinition of the Page Select Register --------------------------- */
#define PAGE_A0 0x01 /* Page Address low within the 64 kByte window */
#define PAGE_A1 0x02 /* Page Address high within the 64 kByte window */
#define PAGE_0 0x00 /* Page 0 0KB - 16KB */
#define PAGE_1 0x01 /* Page 1 16KB - 32KB */
#define PAGE_2 0x02 /* Page 2 32KB - 48KB */
#define PAGE_3 0x03 /* Page 3 48KB - 64KB */
/* --- Macros to Set or Clear Page ----------------------------------------- */
#define CLEAR_PAGE(reg) \
((reg) & ~(PAGE_A0 | PAGE_A1))
#define SET_PAGE(reg, page) \
(CLEAR_PAGE(reg) | page)
/* --- Board I/O identifier ------------------------------------------------ */
#define HW_IO_ID_PROFIBOARD_0 0x96
#define HW_IO_ID_PROFIBOARD_1 0x26
#define HW_IO_ID_PROFIBOARD_2 0x6B
#define HW_IO_ID_PROFI104_0 0x2C
#define HW_IO_ID_PROFI104_1 0x12
#define HW_IO_ID_PROFI104_2 0x41
#endif
/**********************************************************************************/
/* */
/* SOFTING GmbH */
/* Richard-Reitzner-Allee 6 */
/* D-85540 Haar */
/* Phone: (++49)-(0)89-45656-0 */
/* Fax: (++49)-(0)89-45656-399 */
/* */
/* Copyright (C) SOFTING GmbH 1995-1999 */
/* All Rights Reserved */
/* */
/**********************************************************************************/
/**********************************************************************************/
/* PROFIBUS APPLICATION PROGRAM INTERFACE */
/* */
/* Filename : PB_IF.H */
/* Version : 5.22.0.00.release */
/* Date : 26-February-1999 */
/* Author : SOFTING-BG2 */
/* */
/* Description : This file contains the global function declarations, */
/* defines and types of the PROFIBUS Communication Interface */
/* */
/* CHANGE_NOTES */
/* */
/* date name change */
/* ------------------------------------------------------------------------ */
/* 18.03.97 BG2-BOE use compiler switch PB_API_FUNC_NOT_USED */
/* to switch off PAPI-functions */
/* 22.07.97 BG2-BOE remove layer identifier SM7 and SM7_USR */
/* 22.07.97 BG2-BOE set #pragma pack(2) and reset to #pragma pack() */
/* 24.09.97 BG2-BOE add new identifiers for data description interface */
/* - ID_SERIAL_DEVICE_NUMBER */
/* 24.07.97 BG2-BOE add new function prototypes */
/* - profi_get_serial_device_number() */
/* - profi_get_add_error() */
/* 10.02.99 BG2-BOE remove WIN32 function prototypes */
/**********************************************************************************/
/**********************************************************************************/
/**********************************************************************************/
#ifndef __PB_IF__
#define __PB_IF__
/*
#pragma warning (disable : 4103)
#ifdef WIN32
#pragma pack(push,2)
#else
#pragma pack(2)
#endif
#pragma warning (default : 4103)
*/
/**********************************************************************************/
/* INTERFACE DEFINES */
/**********************************************************************************/
/* --- contants for IRQ values -(only used for 16BIT-Interface) */
#define REQ_IRQ 0xF0 /* IND/CON IRQ is received */
#define ACK_IRQ 0x0F /* acknowledge REQ/RES */
#define DP_SLAVE_IO_REQ_IRQ 0xE0 /* MASTER: DP-SLAVE-IO IND/REQ */
#define DP_SLAVE_IO_ACK_IRQ 0x0E /* MASTER: DP-SLAVE-IO acknowldege IND/REQ */
#define DP_DATA_STOP_REQ_IRQ 0xD0 /* MASTER: data transfer stop REQ received */
#define DP_DATA_STOP_ACK_IRQ 0x0D /* MASTER: data transfer stop Acknowldege */
#define EXCEPTION_REQ_IRQ 0xB0 /* Exception Request */
#define EXCEPTION_ACK_IRQ 0x0B /* Exception Acknowledge */
/* --- contants to receive an indication or confirmation ------------------------ */
#define CON_IND_RECEIVED 0x0001 /* ind. or con. has been received */
#define NO_CON_IND_RECEIVED 0x0000 /* nothing has been received */
/* --- values > CON_IND_RECEIVED are error returns (see pb_err.h) -------------- */
/* --- OK return value ---------------------------------------------------------- */
#define E_OK 0 /* no errors */
/* --- values != E_OK are error returns (see pb_err.h) -------------------------- */
/* --- service result ----------------------------------------------------------- */
#define NEG 0x01 /* result for negative response */
#define POS 0x00 /* result for positive response */
/* --- service priority --------------------------------------------------------- */
#define LOW 0x00 /* high priority */
#define HIGH 0x01 /* low priority */
/* --- service primitives ------------------------------------------------------- */
#define REQ 0x00 /* request primitive */
#define CON 0x01 /* confirmation primitive */
#define IND 0x02 /* indication primitive */
#define RES 0x03 /* response primitive */
#define RET 0x04 /* return primitive not used by application */
/* --- layer identifiers -------------------------------------------------------- */
#define USR 0x00 /* identifier USER */
#define FMS 0x01 /* identifier FMS */
#define LLI 0x02 /* identifier LLI */
#define FDL 0x03 /* identifier FDL */
#define FM7 0x04 /* identifier FM7 */
#define FMB 0x05 /* identifier FMB */
#define FMS_USR 0x06 /* identifier FMS-USER */
#define FM7_USR 0x07 /* identifier FM7-USER */
#define FMB_USR 0x08 /* identifier FMB-USER */
#define DP 0x0B /* identifier DP */
#define DP_USR 0x0C /* identifier DP-USER */
#define FDLIF 0x0D /* identifier FDLIF */
#define FDLIF_USR 0x0E /* identifier FDLIF-USER */
#define PAPI 0xF0 /* identifier Application-Layer-IF */
#if (PB_VER < 500)
#define FMA7 FM7 /* identifier FMA7 */
#define FMA2 FMB /* identifier FMA2 */
#define FMA7_USR FM7_USR /* identifier FMA7-USER */
#endif
/* --- identifiers for data description interface ------------------------------- */
/* --- 0x00 - 0x3F used by FMS -- (no identifiers defined) ---------------------- */
/* --- 0x40 - 0x7F reserved by management -- (no identifiers defined) ----------- */
/* --- 0x80 - 0x9F reserved by DP ----------------------------------------------- */
/* --- DP-MASTER ---------------------------------------------------------------- */
#define ID_DP_SLAVE_IO_IMAGE 0x80 /* MASTER: image for slave io datas */
#define ID_DP_STATUS_IMAGE 0x81 /* MASTER: image for status datas */
/* --- 0xA0 - 0xEF reserved for future use --- (no identifiers defined) --------- */
/* --- 0xF0 - 0xFF reserved for diagonsis -------------------------------------- */
#define ID_EXCEPTION_IMAGE 0xF0 /* image for exeption datas */
#define ID_FW_VERS_IMAGE 0xF1 /* image for firmware version */
#define ID_SERIAL_DEVICE_NUMBER 0xF2 /* image for serial device number */
/* --- idebtifier for end of data description list ------------------------------ */
#define EOF_DATA_DESCR_LIST 0x00 /* end of data description list */
/**********************************************************************************/
/* PROFI SERVICE DESCRIPTION BLOCK */
/**********************************************************************************/
typedef struct _T_PROFI_SERVICE_DESCR
{
USIGN16 comm_ref; /* communication reference */
USIGN8 layer; /* layer identifier */
USIGN8 service; /* service identifier */
USIGN8 primitive; /* service primitive */
INT8 invoke_id; /* invoke id */
INT16 result; /* service result (POS or NEG) */
} T_PROFI_SERVICE_DESCR;
#endif
/*****************************************************************************/
/* */
/* SOFTING GmbH */
/* Richard-Reitzner-Allee 6 */
/* D-85540 Haar */
/* Phone: (++49)-(0)89-45656-0 */
/* Fax: (++49)-(0)89-45656-399 */
/* */
/* Copyright (C) SOFTING GmbH 1995-1999 */
/* All Rights Reserved */
/* */
/*****************************************************************************/
/*****************************************************************************/
/* PROFIBUS BASIC TYPES */
/* */
/* Filename : PB_TYPE.H */
/* Version : 5.22.0.00.release */
/* Date : 26-February-1999 */
/* Author : SOFTING-BG2 */
/* */
/* Description : This file contains the PROFIBUS basic types */
/* */
/* CHANGE_NOTES */
/* */
/* date name change */
/* ----------------------------------------------------------------------- */
/* 18.03.97 BG2-BOE include header file 'pb_conf.h' */
/* 18.03.97 BG2-BOE remove #define FAR and #define HUGE */
/* 02.02.99 BG2-BOE define INT32 as int using WIN32 */
/* (compatibility to MSVC60) */
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
#ifndef __PB_TYPE__
#define __PB_TYPE__
#include "pb_conf.h" /* PAPI configuration parameters */
/* --- global type definitions --------------------------------------------- */
#ifndef VOID
#define VOID void
#endif
#define PB_BOOL unsigned char
#if (PB_VER < 500)
#undef BOOL
#define BOOL PB_BOOL
#endif
#define OCTET unsigned char
#define USIGN8 unsigned char
#define USIGN16 unsigned short
#define USIGN32 unsigned int
#define INT8 signed char
#define INT16 signed short
#define INT32 signed int
#define FLOAT float
#define DOUBLE double
#define STRINGV char
#define CSTRING char
/* --- PROFIBUS true and false definitions --------------------------------- */
#define PB_TRUE 0xFF
#define PB_FALSE 0x00
#if (PB_VER < 500)
#undef TRUE
#undef FALSE
#define TRUE PB_TRUE
#define FALSE PB_FALSE
#endif
/* --- PROFIBUS function declarations -------------------------------------- */
#define LOCAL static
#define PUBLIC
#define GLOBAL
#endif
/*
* Proview $Id: pbus.h,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PBDRVR__
#define __PBDRVR__
#define INIT_MODE 0x00
#define CONFIG_MODE 0x05
#define COMM_MODE 0x08
#define H_READY_MASK 0x874B2D1E
#define C_READY_MASK 0x78B4D2E1
#define IDLE 0x00
#define BUSY 0x01
#define D_DATA_IDLE 0x00
#define D_DATA_APPLY 0xF0
#define D_DATA_BUSY 0x0F
// Macros for defining ioctl commands
#define PB_IOCTL_MAGIC 'c'
#define PB_IOCTL_READCMIDESC _IO(PB_IOCTL_MAGIC, 1)
#define PB_IOCTL_READLOCALREG _IO(PB_IOCTL_MAGIC, 2)
#define PB_IOCTL_WRITECMIDESC _IO(PB_IOCTL_MAGIC, 3)
#define PB_IOCTL_HWRESET _IO(PB_IOCTL_MAGIC, 4)
#define PB_IOCTL_CMI_INIT _IO(PB_IOCTL_MAGIC, 5)
#define PB_IOCTL_READDATADESC _IO(PB_IOCTL_MAGIC, 6)
#define PB_IOCTL_CMI_WRITE _IO(PB_IOCTL_MAGIC, 7)
#define PB_IOCTL_READ_SDB _IO(PB_IOCTL_MAGIC, 8)
#define PB_IOCTL_READ_DB _IO(PB_IOCTL_MAGIC, 9)
#define PB_IOCTL_CMI_READ _IO(PB_IOCTL_MAGIC, 10)
#define PB_IOCTL_READ_IRQ_VALUES _IO(PB_IOCTL_MAGIC, 11)
#define PB_IOCTL_READ_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 12)
#define PB_IOCTL_WRITE_FIRST_SLAVE _IO(PB_IOCTL_MAGIC, 13)
#define PB_IOCTL_READVERSION _IO(PB_IOCTL_MAGIC, 14)
#define PB_IOCTL_READSERIAL _IO(PB_IOCTL_MAGIC, 15)
#define PB_IOCTL_SET_STALLTIME _IO(PB_IOCTL_MAGIC, 16)
#define ERROR_DESCR_LENGTH 32
typedef struct {
unsigned int h_ready_mask;
unsigned int h_base_address;
unsigned char h_id;
unsigned char h_int_enable;
unsigned char h_address_swap_mode;
unsigned char h_state;
unsigned int h_param_addr;
unsigned int h_data_addr;
unsigned short h_param_size;
unsigned short h_data_size;
unsigned char h_sema;
unsigned char h_ret_val;
unsigned char h_head;
unsigned char h_tail;
unsigned int h_data_descr_addr;
unsigned int c_ready_mask;
unsigned int c_base_address;
unsigned char c_id;
unsigned char c_int_enable;
unsigned char c_address_swap_mode;
unsigned char c_state;
unsigned int c_param_addr;
unsigned int c_data_addr;
unsigned short c_param_size;
unsigned short c_data_size;
unsigned char c_sema;
unsigned char c_ret_val;
unsigned char c_head;
unsigned char c_tail;
unsigned int c_data_descr_addr;
}T_CMI_DESCRIPTOR;
typedef struct {
unsigned int reg[21];
} T_LOCALREG;
typedef struct {
unsigned char d_id;
unsigned char dummy;
unsigned char d_sema_c;
unsigned char d_sema_h;
unsigned short d_data_size;
unsigned int d_data_addr;
} T_DATA_DESCR;
typedef struct {
T_PROFI_SERVICE_DESCR *sdb_ptr;
USIGN8 *data_ptr;
USIGN16 *data_len_ptr;
USIGN16 *retval_ptr;
} cmi_request_access_struct;
typedef struct {
USIGN8 data_id; // Id of data structure
USIGN16 offset; // Offset in data area
USIGN8 *data_ptr; // Pointer to data to write/to be read
USIGN16 *retval_ptr; // Pointer to return value
} cmi_data_access_struct;
#endif
This diff is collapsed.
/*
* Proview $Id: rt_io_m_pb_ao.c,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_pb_ao.c
PROVIEW/R */
#pragma pack(1)
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include "pb_type.h"
#include "pb_if.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
Init method for the Pb module Ao
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Ao *op;
io_sChannel *chanp;
int i;
op = (pwr_sClass_Pb_Ao *) cp->op;
local = (io_sCardLocal *) cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) {
errh_Info( "Illegal object type %s", cp->Name );
return IO__SUCCESS;
}
if (op->Status >= PB_MODULE_STATE_OPERATE) {
// Calculate polycoeff
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
if (!chanp->cop) continue;
io_AoRangeToCoef(chanp);
}
}
else
errh_Info( "Error initializing Pb module Ao %s", cp->Name );
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb module Ao
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Ao *op;
pwr_sClass_Pb_DP_Slave *slave;
int i;
pwr_tInt8 data8 = 0;
pwr_tInt16 data16 = 0;
pwr_tInt32 data32 = 0;
pwr_tUInt8 udata8 = 0;
pwr_tUInt16 udata16 = 0;
pwr_tUInt32 udata32 = 0;
pwr_sClass_ChanAo *cop;
pwr_sClass_Ao *sop;
io_sChannel *chanp;
int fixout;
pwr_tFloat32 value;
pwr_tFloat32 rawvalue;
local = (io_sCardLocal *) cp->Local;
op = (pwr_sClass_Pb_Ao *) cp->op;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) {
fixout = ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT;
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
if (!chanp->cop) continue;
cop = (pwr_sClass_ChanAo *) chanp->cop;
sop = (pwr_sClass_Ao *) chanp->sop;
// Determine what actual value we actually want!
if (fixout)
value = cop->FixedOutValue;
else if (cop->TestOn)
value = cop->TestValue;
else
value = *(pwr_tFloat32 *) chanp->vbp;
// Make new coeff.. if necessary
if (cop->CalculateNewCoef)
io_AoRangeToCoef(chanp);
// Convert to rawvalue
if (value > cop->ActValRangeHigh)
value = cop->ActValRangeHigh;
else if ( value < cop->ActValRangeLow)
value = cop->ActValRangeLow;
rawvalue = cop->OutPolyCoef1 * value + cop->OutPolyCoef0;
if ( rawvalue > 0)
rawvalue = rawvalue + 0.5;
else
rawvalue = rawvalue - 0.5;
// We dont use RawValue in Profibus I/O
sop->RawValue = 0;
// Calculate signal value
sop->SigValue = cop->SigValPolyCoef1 * value + cop->SigValPolyCoef0;
if (op->BytesPerChannel == 4) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
udata32 = (pwr_tUInt32) rawvalue;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) udata32 = swap32(udata32);
memcpy(local->output_area + op->OffsetOutputs + 4*i, &udata32, 4);
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
data32 = (pwr_tInt32) rawvalue;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 4*i, &data32, 4);
}
}
else if (op->BytesPerChannel == 3) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
udata32 = (pwr_tUInt32) rawvalue;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) udata32 = swap32(udata32);
memcpy(local->output_area + op->OffsetOutputs + 3*i, &udata32, 3);
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
data32 = (pwr_tInt32) rawvalue;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 3*i, &data32, 3);
}
}
else if (op->BytesPerChannel == 2) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
udata16 = (pwr_tUInt16) rawvalue;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) udata16 = swap16(udata16);
memcpy(local->output_area + op->OffsetOutputs + 2*i, &udata16, 2);
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
data16 = (pwr_tInt16) rawvalue;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data16 = swap16(data16);
memcpy(local->output_area + op->OffsetOutputs + 2*i, &data16, 2);
}
}
else if (op->BytesPerChannel == 1) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
udata8 = (pwr_tUInt8) rawvalue;
memcpy(local->output_area + op->OffsetOutputs + i, &udata8, 1);
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
data8 = (pwr_tInt8) rawvalue;
memcpy(local->output_area + op->OffsetOutputs + i, &data8, 1);
}
}
}
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
local = cp->Local;
free ((char *) local);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Ao) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardClose),
pwr_NullMethod
};
/*
* Proview $Id: rt_io_m_pb_di.c,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_pb_di.c
PROVIEW/R */
#pragma pack(1)
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include "pb_type.h"
#include "pb_if.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
Init method for the Pb module Di
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Di *op;
op = (pwr_sClass_Pb_Di *) cp->op;
local = (io_sCardLocal *) cp->Local;
// Check configuration
if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 && op->NumberOfChannels != 32)
op->Status = PB_MODULE_STATE_NOTINIT;
if (op->Orientation > op->NumberOfChannels)
op->Status = PB_MODULE_STATE_NOTINIT;
if (op->Status < PB_MODULE_STATE_OPERATE) errh_Info( "Error initializing Pb module Di %s", cp->Name );
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Read method for the Pb module Di
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Di *op;
pwr_sClass_Pb_DP_Slave *slave;
pwr_tUInt16 data[2] = {0, 0};
pwr_tUInt32 *data32;
local = (io_sCardLocal *) cp->Local;
op = (pwr_sClass_Pb_Di *) cp->op;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) {
memcpy(&data, local->input_area + op->OffsetInputs, op->BytesOfInput);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) {
if (op->Orientation == PB_ORIENTATION_WORD) {
data[0] = swap16(data[0]);
data[1] = swap16(data[1]);
}
else if (op->Orientation == PB_ORIENTATION_DWORD) {
data32 = (pwr_tUInt32 *) &data;
*data32 = swap32(*data32);
}
}
// Packa upp
data[0] = data[0] ^ op->InvMask1;
io_DiUnpackWord(cp, data[0], op->ConvMask1, 0);
if (op->NumberOfChannels > 16) {
data[1] = data[1] ^ op->InvMask2;
io_DiUnpackWord(cp, data[1], op->ConvMask2, 1);
}
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
local = cp->Local;
free ((char *) local);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Di) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardClose),
pwr_NullMethod
};
/*
* Proview $Id: rt_io_m_pb_do.c,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_pb_do.c
PROVIEW/R */
#pragma pack(1)
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include "pb_type.h"
#include "pb_if.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
Init method for the Pb module Do
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Do *op;
op = (pwr_sClass_Pb_Do *) cp->op;
local = (io_sCardLocal *) cp->Local;
if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 && op->NumberOfChannels != 32)
op->Status = PB_MODULE_STATE_NOTINIT;
if (op->Orientation > op->NumberOfChannels)
op->Status = PB_MODULE_STATE_NOTINIT;
if (op->Status < PB_MODULE_STATE_OPERATE) errh_Info( "Error initializing Pb module Do %s", cp->Name );
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb module Do
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Do *op;
pwr_sClass_Pb_DP_Slave *slave;
pwr_tUInt16 data[2] = {0, 0};
pwr_tUInt32 *data32;
local = (io_sCardLocal *) cp->Local;
op = (pwr_sClass_Pb_Do *) cp->op;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) {
io_DoPackWord(cp, &data[0], 0);
if (op->NumberOfChannels > 16) io_DoPackWord(cp, &data[1], 1);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) {
if (op->Orientation == PB_ORIENTATION_WORD) {
data[0] = swap16(data[0]);
data[1] = swap16(data[1]);
}
else if (op->Orientation == PB_ORIENTATION_DWORD) {
data32 = (pwr_tUInt32 *) &data;
*data32 = swap32(*data32);
}
}
memcpy(local->output_area + op->OffsetOutputs, &data, op->BytesOfOutput);
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
local = cp->Local;
free ((char *) local);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Do) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardClose),
pwr_NullMethod
};
/*
* Proview $Id: rt_io_m_pb_dp_slave.c,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_pb_dp_slave.c -- io methods for a profibus DP slave */
#pragma pack(1)
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include "pb_type.h"
#include "pb_if.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "co_cdh.h"
#include "pwr_baseclasses.h"
#include "rt_gdh.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "co_cdh.h"
#include "rt_io_profiboard.h"
#include "rt_pb_msg.h"
/*----------------------------------------------------------------------------*\
Init method for the Pb DP slave
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoRackInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp
)
{
io_sCardLocal *local_card;
io_sCard *cardp;
short input_counter;
short output_counter;
pwr_sClass_Pb_DP_Slave *op;
pwr_sClass_Pb_Di *dip;
pwr_sClass_Pb_Do *dop;
pwr_sClass_Pb_Ai *aip;
pwr_sClass_Pb_Ao *aop;
pwr_sClass_Pb_Ii *iip;
pwr_sClass_Pb_Io *iop;
pwr_sClass_Pb_Module *mp;
char name[196];
pwr_tStatus sts;
pwr_tCid cid;
sts = gdh_ObjidToName(rp->Objid, (char *) &name, sizeof(name), cdh_mNName);
errh_Info( "Init of Profibus DP Slave and modules %s", name);
op = (pwr_sClass_Pb_DP_Slave *) rp->op;
// Do configuration check and initialize modules.
cardp = rp->cardlist;
input_counter = 0;
output_counter = 0;
op->NumberModules = 0;
while(cardp) {
local_card = calloc(1, sizeof(*local_card));
cardp->Local = local_card;
local_card->input_area = (void *) &(op->Inputs);
local_card->output_area = (void *) &(op->Outputs);
cid = cardp->Class;
while ( ODD( gdh_GetSuperClass( cid, &cid, cardp->Objid))) ;
switch (cid) {
case pwr_cClass_Pb_Di:
dip = (pwr_sClass_Pb_Di *) cardp->op;
dip->OffsetInputs = input_counter;
dip->BytesOfInput = dip->NumberOfChannels / 8;
input_counter += dip->BytesOfInput;
dip->Status = PB_MODULE_STATE_OPERATE;
break;
case pwr_cClass_Pb_Do:
dop = (pwr_sClass_Pb_Do *) cardp->op;
dop->OffsetOutputs = output_counter;
dop->BytesOfOutput = dop->NumberOfChannels / 8;
output_counter += dop->BytesOfOutput;
dop->Status = PB_MODULE_STATE_OPERATE;
break;
case pwr_cClass_Pb_Ai:
aip = (pwr_sClass_Pb_Ai *) cardp->op;
aip->OffsetInputs = input_counter;
aip->BytesOfInput = aip->NumberOfChannels * aip->BytesPerChannel;
input_counter += aip->BytesOfInput;
aip->Status = PB_MODULE_STATE_OPERATE;
break;
case pwr_cClass_Pb_Ao:
aop = (pwr_sClass_Pb_Ao *) cardp->op;
aop->OffsetOutputs = output_counter;
aop->BytesOfOutput = aop->NumberOfChannels * aop->BytesPerChannel;
output_counter += aop->BytesOfOutput;
aop->Status = PB_MODULE_STATE_OPERATE;
break;
case pwr_cClass_Pb_Ii:
iip = (pwr_sClass_Pb_Ii *) cardp->op;
iip->OffsetInputs = input_counter;
iip->BytesOfInput = iip->NumberOfChannels * iip->BytesPerChannel;
input_counter += iip->BytesOfInput;
iip->Status = PB_MODULE_STATE_OPERATE;
break;
case pwr_cClass_Pb_Io:
iop = (pwr_sClass_Pb_Io *) cardp->op;
iop->OffsetOutputs = output_counter;
iop->BytesOfOutput = iop->NumberOfChannels * iop->BytesPerChannel;
output_counter += iop->BytesOfOutput;
iop->Status = PB_MODULE_STATE_OPERATE;
break;
case pwr_cClass_Pb_Module:
mp = (pwr_sClass_Pb_Module *) cardp->op;
// iop->OffsetOutputs = output_counter;
// iop->BytesOfOutput = iop->NumberOfChannels * iop->BytesPerChannel;
// output_counter += iop->BytesOfOutput;
mp->Status = PB__SUCCESS;
break;
}
op->NumberModules++;
cardp = cardp->next;
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Read method for the Pb DP slave
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoRackRead (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp
)
{
pwr_sClass_Pb_Profiboard *mp;
pwr_sClass_Pb_DP_Slave *sp;
int fp;
unsigned char diag;
pwr_tUInt16 sts;
fp = ((io_sAgentLocal *) (ap->Local))->Pb_fp;
sp = (pwr_sClass_Pb_DP_Slave *) rp->op;
mp = (pwr_sClass_Pb_Profiboard *) ap->op;
if (sp->Status > PB_SLAVE_STATE_NOTINIT && mp->Status == PB_MASTER_STATE_OPERATE && sp->DisableSlave != 1 && mp->DisableBus != 1) {
sts = pb_cmi_get_data(fp, ID_DP_STATUS_IMAGE, sp->SlaveAddress, 1, &diag);
if ((sts != PB_OK) || (diag & 1)) {
sp->Status = PB_SLAVE_STATE_STOPPED;
sp->ErrorCount++;
if (sp->ErrorCount > sp->ErrorSoftLimit && sp->StallAction >= PB_STALLACTION_RESET) {
memset(&sp->Inputs, 0, sp->BytesOfInput);
}
}
else {
sp->Status = PB_SLAVE_STATE_OPERATE;
}
if ((sp->Status > PB_SLAVE_STATE_STOPPED) && sp->BytesOfInput > 0) {
sts = pb_cmi_get_data(fp,
ID_DP_SLAVE_IO_IMAGE,
sp->OffsetInputs,
sp->BytesOfInput,
&sp->Inputs);
if (sts != PB_OK)
sp->ErrorCount++;
else
sp->ErrorCount = 0;
}
if (sp->ErrorCount > sp->ErrorHardLimit && sp->StallAction >= PB_STALLACTION_BREAK)
ctx->Node->EmergBreakTrue = 1;
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb DP slave
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoRackWrite (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp
)
{
pwr_sClass_Pb_Profiboard *mp;
pwr_sClass_Pb_DP_Slave *sp;
int fp;
pwr_tUInt16 sts;
fp = ((io_sAgentLocal *) (ap->Local))->Pb_fp;
sp = (pwr_sClass_Pb_DP_Slave *) rp->op;
mp = (pwr_sClass_Pb_Profiboard *) ap->op;
// Write the whole I/O output area from local area
if (sp->Status > PB_SLAVE_STATE_NOTINIT && mp->Status == PB_MASTER_STATE_OPERATE && sp->DisableSlave != 1 && mp->DisableBus != 1) {
if (sp->BytesOfOutput > 0) {
sts = pb_cmi_set_data(fp,
ID_DP_SLAVE_IO_IMAGE,
sp->OffsetOutputs,
sp->BytesOfOutput,
&sp->Outputs);
if (sts != PB_OK) sp->ErrorCount++;
}
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoRackClose (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp
)
{
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_DP_Slave) = {
pwr_BindIoMethod(IoRackInit),
pwr_BindIoMethod(IoRackRead),
pwr_BindIoMethod(IoRackWrite),
pwr_BindIoMethod(IoRackClose),
pwr_NullMethod
};
/*
* Proview $Id: rt_io_m_pb_ii.c,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#pragma pack(1)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include "pb_type.h"
#include "pb_if.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
Init method for the Pb module Ii
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Ii *op;
op = (pwr_sClass_Pb_Ii *) cp->op;
local = (io_sCardLocal *) cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) {
errh_Info( "Illegal object type %s", cp->Name );
return IO__SUCCESS;
}
if (op->Status < PB_MODULE_STATE_OPERATE) errh_Info( "Error initializing Pb module Ii %s", cp->Name );
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Read method for the Pb Ii card
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Ii *op;
pwr_sClass_Pb_DP_Slave *slave;
io_sChannel *chanp;
pwr_sClass_ChanIi *cop;
pwr_sClass_Ii *sop;
pwr_tUInt8 udata8 = 0;
pwr_tUInt16 udata16 = 0;
pwr_tUInt32 udata32 = 0;
pwr_tInt8 data8 = 0;
pwr_tInt16 data16 = 0;
pwr_tInt32 data32 = 0;
int i;
local = (io_sCardLocal *) cp->Local;
op = (pwr_sClass_Pb_Ii *) cp->op;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) {
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
if (!chanp->cop) continue;
cop = (pwr_sClass_ChanIi *) chanp->cop;
sop = (pwr_sClass_Ii *) chanp->sop;
if (cop->ConversionOn) {
if (op->BytesPerChannel == 4) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
memcpy(&udata32, local->input_area + op->OffsetInputs + 4*i, 4);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) udata32 = swap32(udata32);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata32;
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
memcpy(&data32, local->input_area + op->OffsetInputs + 4*i, 4);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data32 = swap32(data32);
*(pwr_tInt32 *) chanp->vbp = data32;
}
}
else if (op->BytesPerChannel == 3) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
udata32 = 0;
memcpy(&udata32, local->input_area + op->OffsetInputs + 3*i, 3);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) udata32 = swap32(udata32);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata32;
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
data32 = 0;
memcpy(&data32, local->input_area + op->OffsetInputs + 3*i, 3);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data32 = swap32(data32);
*(pwr_tInt32 *) chanp->vbp = data32;
}
}
else if (op->BytesPerChannel == 2) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
memcpy(&udata16, local->input_area + op->OffsetInputs + 2*i, 2);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) udata16 = swap16(udata16);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata16;
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
memcpy(&data16, local->input_area + op->OffsetInputs + 2*i, 2);
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data16 = swap16(data16);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) data16;
}
}
else if (op->BytesPerChannel == 1) {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) {
memcpy(&udata8, local->input_area + op->OffsetInputs + i, 1);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) udata8;
}
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) {
memcpy(&data8, local->input_area + op->OffsetInputs + i, 1);
*(pwr_tInt32 *) chanp->vbp = (pwr_tInt32) data8;
}
}
}
}
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Close method for the Pb Ii card
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
local = cp->Local;
free ((char *) local);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Ii) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardClose),
pwr_NullMethod
};
/*
* Proview $Id: rt_io_m_pb_io.c,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#pragma pack(1)
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include "pb_type.h"
#include "pb_if.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
Init method for the Pb module Io
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Io *op;
op = (pwr_sClass_Pb_Io *) cp->op;
local = (io_sCardLocal *) cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) {
errh_Info( "Illegal object type %s", cp->Name );
return IO__SUCCESS;
}
if (op->Status < PB_MODULE_STATE_OPERATE) {
errh_Info( "Error initializing Pb module Io %s", cp->Name );
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb module Io
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Pb_Io *op;
pwr_sClass_Pb_DP_Slave *slave;
int i;
pwr_tInt8 data8 = 0;
pwr_tInt16 data16 = 0;
pwr_tInt32 data32 = 0;
pwr_sClass_ChanIo *cop;
pwr_sClass_Io *sop;
io_sChannel *chanp;
local = (io_sCardLocal *) cp->Local;
op = (pwr_sClass_Pb_Io *) cp->op;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) {
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
if (!chanp->cop) continue;
cop = (pwr_sClass_ChanIo *) chanp->cop;
sop = (pwr_sClass_Io *) chanp->sop;
if (cop->TestOn != 0) continue;
data32 = *(pwr_tInt32 *) chanp->vbp;
if (op->BytesPerChannel == 4) {
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 4*i, &data32, 4);
}
else if (op->BytesPerChannel == 3) {
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 3*i, &data32, 3);
}
else if (op->BytesPerChannel == 2) {
data16 = (pwr_tInt16) data32;
if (slave->ByteOrdering == PB_BYTEORDERING_BE) data16 = swap16(data16);
memcpy(local->output_area + op->OffsetOutputs + 2*i, &data16, 2);
}
else if (op->BytesPerChannel == 1) {
data8 = (pwr_tInt8) data32;
memcpy(local->output_area + op->OffsetOutputs + i, &data8, 1);
}
}
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
local = cp->Local;
free ((char *) local);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Io) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardClose),
pwr_NullMethod
};
This diff is collapsed.
This diff is collapsed.
/*
* Proview $Id: rt_io_pb_locals.h,v 1.1 2006-01-16 10:55:42 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define IO_MAXCHAN 96
#define PB_MODULE_STATE_NOTINIT 0
#define PB_MODULE_STATE_OPERATE 1
#define PB_SLAVE_STATE_NOTINIT 0
#define PB_SLAVE_STATE_STOPPED 1
#define PB_SLAVE_STATE_OPERATE 2
#define PB_MASTER_STATE_NOTINIT 0
#define PB_MASTER_STATE_STOPPED 1
#define PB_MASTER_STATE_CLEARED 2
#define PB_MASTER_STATE_OPERATE 3
#define PB_STALLACTION_NONE 0
#define PB_STALLACTION_RESET 1
#define PB_STALLACTION_BREAK 2
#define PB_NUMREP_UNSIGNEDINT 0
#define PB_NUMREP_SIGNEDINT 1
#define PB_NUMREP_FLOATIEEE 2
#define PB_NUMREP_FLOATVAX 3
#define PB_NUMREP_FLOATINTEL 4
#define PB_BYTEORDERING_LE 0
#define PB_BYTEORDERING_BE 1
#define PB_ORIENTATION_BYTE 8
#define PB_ORIENTATION_WORD 16
#define PB_ORIENTATION_DWORD 32
typedef struct {
int Pb_fp;
} io_sAgentLocal;
typedef struct {
int initialized;
} io_sRackLocal;
typedef struct {
void *input_area;
void *output_area;
int scancount[IO_MAXCHAN];
} io_sCardLocal;
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment