Commit 2d22681d authored by Claes Sjofors's avatar Claes Sjofors

Added Hilscher CIF 50-PB agent code as well as the Hilscher API.

Updated guide to io systems, both english and swedish version.
parent 428c1cf5
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
========================================================================
cif_api.c
-------------------------------------------------------------------------
CREATETED : D. Tsaava, Hilscher GmbH
DATE : 18.07.2000
PROJEKT : CIF device driver
=========================================================================
DISCRIPTION
CIF device driver api
=========================================================================
CHANGES
version name date Discription
V2.620 Oktober '06
******************************************************************** <En> */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
/* Paths modified to fit in Proview's build tree. */
#include "cif_types.h"
#include "cif_dev_i.h"
#include "rcsdef.h"
#define INVALID_HANDLE_VALUE -1
int hDevDrv = INVALID_HANDLE_VALUE; // handle to cifDevDrv
static unsigned short DrvOpenCount = 0; // no Application is logged in
typedef struct DEV_DPM_SIZEtag {
unsigned int ulDpmSize;
unsigned int ulDpmIOSize;
} DEV_DPM_SIZE;
DEV_DPM_SIZE tDevDPMSize[MAX_DEV_BOARDS] = { {0L,0L},
{0L,0L},
{0L,0L},
{0L,0L} }; // DPM size of each board
/* <ST> =================================================================================
Function: DevOpenDriver
opens a connection to the device driver
---------------------------------------------------------------------------------------
Input :
Output : -
Return : DRV_NO_ERROR - driver opens successfully
DRV_USR_OPEN_DRV_ERROR - open error
================================================================================= <En> */
short DevOpenDriver()
{
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
// first application, search CIF device driver
if( (hDevDrv = open("/dev/cif",O_RDONLY) ) == -1 ) { // handle of file with attributes to copy
// error open CIF driver
sRet = DRV_USR_OPEN_ERROR;
} else {
// driver is opend for the 1st. time, store application in DrvOpencount
DrvOpenCount = 1;
}
} else {
// driver is already opend, store application in DrvOpencount
DrvOpenCount++;
}
//printf("*** DevOpenDriver(): OpenCount = %d, hDevDrv = %d\n\n", DrvOpenCount, hDevDrv);
return sRet;
}
/* <ST> =================================================================================
Function: DevCloseDriver
closes the connection to the DEV driver
---------------------------------------------------------------------------------------
Input : usDevNumber - not asigned
Output : -
Return : DRV_NO_ERROR - driver closed successfully
DRV_USR_NOT_INITIALIZED - driver not initialized
================================================================================= <En> */
short DevCloseDriver()
{
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else {
// test if other applications are logged in
if( DrvOpenCount > 1) {
// there are more applications logged in, do not close the driver
DrvOpenCount--;
} else {
// no more application are logged in, close File Handle
close( hDevDrv); // handle of object to close
DrvOpenCount = 0;
hDevDrv = INVALID_HANDLE_VALUE;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetBoardInfo
reads special board informations from the driver
---------------------------------------------------------------------------------------
Input : usDevNumber - not asigned
usSize - length
*pvData - data pointer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetBoardInfo( BOARD_INFO *pvData)
{
DEVIO_GETBOARDINFOCMD *ptBuffer = NULL;
BOARD_INFO *ptBoardInfo = NULL;
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else {
if( (ptBuffer = (DEVIO_GETBOARDINFOCMD *)malloc(sizeof(DEVIO_GETBOARDINFOCMD))) == NULL)
return DRV_USR_SENDBUF_PTR_NULL;
if( (ptBuffer->ptBoardInfo = (BOARD_INFO *)malloc(sizeof(BOARD_INFO))) == NULL) {
free( ptBuffer);
return DRV_USR_SENDBUF_PTR_NULL;
}
ptBuffer->sError = sRet;
ptBuffer->usInfoLen = sizeof( BOARD_INFO);
ptBoardInfo = ptBuffer->ptBoardInfo;
if( !ioctl( hDevDrv, CIF_IOCTLBOARDINFO, (unsigned long)ptBuffer) ) {
//fprintf(stderr, "CIF_IOCTLBOARDINFO: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
ptBuffer->ptBoardInfo = ptBoardInfo;
//printf("sRet=%X, &tBuffer=%lX, ->ptBI=%lX\n",sRet,(unsigned long)tBuffer,(unsigned long)ptBoardInfo);
//printf("BufferLen = %X\n", tBuffer->usInfoLen);
//printf("Vers = %s\n", ptBoardInfo->abDriverVersion);
//printf("Add = %lX\n", ptBoardInfo->tBoard[0].ulPhysicalAddress);
//printf("IRQ = %d\n", ptBoardInfo->tBoard[0].usIrq);
memcpy( pvData, ptBoardInfo, sizeof( BOARD_INFO));
sRet = ptBuffer->sError;
}
free( ptBoardInfo);
free( ptBuffer);
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetBoardInfoEx
reads special board informations from the driver
---------------------------------------------------------------------------------------
Input : usDevNumber - not asigned
usSize - length
*pvData - data pointer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetBoardInfoEx ( BOARD_INFOEX *pvData)
{
DEVIO_GETBOARDINFOEXCMD *ptBuffer = NULL;
BOARD_INFOEX *ptBoardInfoEx = NULL;
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else {
if( (ptBuffer = (DEVIO_GETBOARDINFOEXCMD *)malloc(sizeof(DEVIO_GETBOARDINFOEXCMD))) == NULL)
return DRV_USR_SENDBUF_PTR_NULL;
ptBuffer->usInfoLen = sizeof( BOARD_INFOEX);
if( (ptBuffer->ptBoard = (BOARD_INFOEX *)malloc(sizeof(BOARD_INFOEX))) == NULL) {
free( ptBuffer);
return DRV_USR_SENDBUF_PTR_NULL;
}
ptBoardInfoEx = ptBuffer->ptBoard;
ptBuffer->usInfoLen = sizeof( BOARD_INFOEX);
ptBuffer->sError = sRet;
if( !ioctl( hDevDrv, CIF_IOCTLBOARDINFOEX, (unsigned long)ptBuffer) ) {
//fprintf(stderr, "CIF_IOCTLBOARDINFOEX: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
sRet = ptBuffer->sError;
ptBuffer->ptBoard = ptBoardInfoEx;
memcpy( pvData, ptBoardInfoEx, sizeof( BOARD_INFOEX));
}
free( ptBoardInfoEx);
free( ptBuffer);
}
return sRet;
}
/* <ST> =================================================================================
Function: DevSetOpMode
set polling || interrupt operation mode
---------------------------------------------------------------------------------------
Input : usBoard - number of the DEV board (0..3)
usMode - INTERRUPT_MODE || POLLING_MODE
Return : DRV_NO_ERROR - function successfull
DRV_DEV_IRQ_REQUEST_FAILED - function failed
================================================================================= <En> */
short DevSetOpMode( unsigned short usBoard,
unsigned short usMode,
unsigned short *usIrq)
{
DEVIO_SETOPMODE tBuffer;
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if(usBoard >= MAX_DEV_BOARDS) {
// number is invalid
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else {
// clear all data buffers
tBuffer.usBoard = usBoard;
tBuffer.usMode = usMode;
tBuffer.sError = sRet;
if( !ioctl( hDevDrv, CIF_IOCTL_IRQ_POLL, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIFAPI (CIF_IOCTL_IRQ_POLL): %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
sRet = tBuffer.sError;
*usIrq = tBuffer.usIrq;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevInitBoard
initializes a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
*pDevAddress - not used
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevInitBoard( unsigned short usDevNumber)
{
DEVIO_RESETCMD tBuffer;
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
// number is invalid
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else {
// clear all data buffers
tBuffer.usBoard = usDevNumber;
tBuffer.sError = sRet;
if( !ioctl( hDevDrv, CIF_IOCTLINITDRV, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIFAPI (CIF_IOCTLINITDRV): %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
sRet = tBuffer.sError;
//printf("CIFAPI (CIF_IOCTLINITDRV): sRet = %d\n", sRet);
if( sRet == DRV_NO_ERROR) {
// Save the DPM size for further function calls and calculate the length
// of the DPM-IO data area
tDevDPMSize[usDevNumber].ulDpmSize = tBuffer.ulDpmSize;
tDevDPMSize[usDevNumber].ulDpmIOSize = ((tBuffer.ulDpmSize * 1024) - 1024) /2;
}
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevReset
reset a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - reset mode (2,3)
ulTimeout - function timeout in milliseconds
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevReset ( unsigned char usDevNumber,
unsigned short usMode,
unsigned long ulTimeout)
{
DEVIO_RESETCMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if((usMode != COLDSTART) &&
(usMode != WARMSTART) &&
(usMode != BOOTSTART) ) {
sRet = DRV_USR_MODE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
tBuffer.ulTimeout = ulTimeout;
tBuffer.sError
= sRet;
//printf("CIF_IOCTLRESETDEV: BOARD = %d, mode = %d, tout = %ld\n",
// tBuffer.ucBoard, tBuffer.usMode, tBuffer.ulTimeout);
if( !ioctl( hDevDrv, CIF_IOCTLRESETDEV, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLRESETDEV: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetInfo
read the differnt information areas from a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usInfoArea - 1..n
usSize - size of the users data buffer
pvData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetInfo( unsigned short usDevNumber,
unsigned short usInfoArea,
unsigned short usSize,
void *pvData)
{
DEVIO_GETDEVINFOCMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if ( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if ( usSize == 0) {
sRet = DRV_USR_SIZE_ZERO;
} else {
// test area spezific data
switch ( usInfoArea) {
case GET_VERSION_INFO:
if ( usSize > sizeof(VERSIONINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_DRIVER_INFO:
if ( usSize > sizeof(DRIVERINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_FIRMWARE_INFO:
if ( usSize > sizeof(FIRMWAREINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_RCS_INFO:
if ( usSize > sizeof(RCSINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_DEV_INFO:
if ( usSize > sizeof(DEVINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_TASK_INFO:
if ( usSize > sizeof(TASKINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_IO_INFO:
if ( usSize > sizeof(IOINFO) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
case GET_IO_SEND_DATA:
if ( usSize > tDevDPMSize[usDevNumber].ulDpmIOSize) {
sRet = DRV_USR_SIZE_TOO_LONG;
}
break;
default:
sRet = DRV_USR_INFO_AREA_INVALID;
} /* end switch */
if ( sRet == DRV_NO_ERROR) {
// complete buffer length with return data
// usDataBufferLen = usSize;
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usInfoArea = usInfoArea;
tBuffer.usInfoLen = usSize;
tBuffer.pabInfoData = pvData; // needed in kernel-space to copy data back to it!
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLGETINFO, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "(CIFAPI: (CIF_IOCTLGETINFO): %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
// memcpy(pvData, tBuffer.pabInfoData, usSize); already copied by driver direct !!!
sRet = tBuffer.sError;
}
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevPutTaskParameter
write communication parameters
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usNumber - number of the parameter area (1..7)
usSize - size of the parameter area ( >0, <= max.Size)
pvData - pointer to task parameter buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevPutTaskParameter( unsigned short usDevNumber,
unsigned short usNumber,
unsigned short usSize,
void *pvData)
{
DEVIO_PUTPARAMETERCMD tBuffer;
unsigned int lBytesReturned ;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if ( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if (usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if ( (usNumber < 1) ||
(usNumber > 7) ) { // 3...7 wird in MailBox memory area geschrieben
sRet = DRV_USR_NUMBER_INVALID;
} else if (usSize == 0) {
sRet = DRV_USR_SIZE_ZERO;
} else if ( usSize > sizeof(TASKPARAM)) {
sRet = DRV_USR_SIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
// set command buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usTaskParamNum = usNumber;
tBuffer.usTaskParamLen = usSize;
memcpy ( (unsigned char *)&(tBuffer.TaskParameter), (unsigned char *)pvData, usSize);
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLPARAMETER, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLRESETDEV: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetTaskState
read a task state field form a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usNumber - number of the status field (1,2)
usSize - size of the users data buffer (>0..<= 64)
pvData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetTaskState( unsigned short usDevNumber,
unsigned short usNumber,
unsigned short usSize,
void *pvData)
{
DEVIO_GETTASKSTATECMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if ( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if ( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if ( usNumber < 1 ||
usNumber > 2 ) {
sRet = DRV_USR_NUMBER_INVALID;
} else if (usSize == 0) {
sRet = DRV_USR_SIZE_ZERO;
} else if (usSize > sizeof(TASKSTATE) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
// set command buffer
tBuffer.ucBoard = usDevNumber;
tBuffer.usStateNum = usNumber;
tBuffer.usStateLen = usSize;
//memcpy( tBuffer.TaskState, pvData, usSize);
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLTASKSTATE, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLTASKSTATE: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
memcpy( pvData, tBuffer.TaskState, usSize);
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetMBXState
Test send and receive MBX
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0)
*pusDevMbxState - 0 = empty, 1 = full
*pusHostMBXState - 0 = empty, 1 = full
Output : -
Return : DRV_NO_ERROR - function successfull
================================================================================= <En> */
short DevGetMBXState( unsigned short usDevNumber,
unsigned short *pusDevMbxState,
unsigned short *pusHostMbxState)
{
DEVIO_MBXINFOCMD tBuffer;
unsigned int lBytesReturned ;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if ( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if ( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.ucBoard = usDevNumber;
tBuffer.usDevMbxState = 0x00;//*pusDevMbxState;
tBuffer.usHostMbxState = 0x00;//*pusHostMbxState;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLMBXINFO, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLMBXINFO: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
}
else {
*pusDevMbxState = tBuffer.usDevMbxState;
*pusHostMbxState = tBuffer.usHostMbxState;
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetMBXData
reads the device and the host mailbox
---------------------------------------------------------------------------------------
Input : usDevNumber - not asigned
usHostSize - length of the host data to be read
*pvHostData - buffer for host data pointer
usDevSize - length of the device data to be read
*pvHostData - buffer for device data pointer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetMBXData( unsigned short usDevNumber,
unsigned short usHostSize,
void *pvHostData,
unsigned short usDevSize,
void *pvDevData)
{
DEVIO_GETMBXCMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if((usHostSize == 0) ||
(usDevSize == 0) ) {
sRet = DRV_USR_SIZE_ZERO;
} else if((usHostSize > sizeof(MSG_STRUC)) ||
(usDevSize > sizeof(MSG_STRUC)) ){
sRet = DRV_USR_SIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
tBuffer.usBoard = usDevNumber;
tBuffer.usHostLen = usHostSize;
tBuffer.usDevLen = usDevSize;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, // handle of the device
CIF_IOCTLGETMBX, // control code of operation to perform
(unsigned long)(&tBuffer) ))
/*, // address of buffer for input data
sizeof(tBuffer), // size of input buffer
NULL, // address of output buffer
0, // size of output buffer
(unsigned int *)&lBytesReturned, // address of actual bytes of output
NULL) ) // address of overlapped structure*/
{
//fprintf(stderr, "CIF_IOCTLGETMBX: %s\n", strerror(errno));
// function error
sRet = DRV_USR_COMM_ERR;
} else {
printf("cif_api::DevGetMBXData: after CIF_IOCTLGETMBX ...\n");
memcpy( pvDevData, tBuffer.abDevMbx, usDevSize);
printf("cif_api::DevGetMBXData: after memcpy ...\n");
memcpy( pvHostData, tBuffer.abHostMbx, usHostSize);
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevExitBoard
closes the connection to a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevExitBoard( unsigned short usDevNumber)
{
DEVIO_EXITCMD tBuffer;
unsigned int lBytesReturned;
unsigned short usDrvOpenCount;
short sRet = DRV_NO_ERROR;
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
// number is invalid
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else {
// valid handle available, driver is open
// clear all data buffers
lBytesReturned = 0;
tBuffer.usBoard = usDevNumber; // [in]
//tBuffer.usDrvOpenCount = usDrvOpenCount; // [out]
//tBuffer.sError = sRet; // [out]
if( !ioctl( hDevDrv, CIF_IOCTLEXITDRV, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLEXITDRV: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
tBuffer.usDrvOpenCount = usDrvOpenCount; // [out]
sRet = tBuffer.sError; // [out]
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevReadSendData
reads the send data from the send area
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usReadOffset -
usReadSize - size of the users data buffer
pvReadData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevReadSendData( unsigned short usDevNumber,
unsigned short usOffset,
unsigned short usSize,
void *pvData)
{
DEVIO_READSENDCMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usSize != 0) &&
((usSize + usOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usReadOffset = usOffset;
tBuffer.usReadLen = usSize;
tBuffer.pabReadData = pvData;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLREADSEND, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLREADSEND: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevTriggerWatchDog
triggers the PC watchdog an delivers the actual DEV watchdog
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - 0 = start, 1 = stop
*pusDevWatchDog - size of the users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevTriggerWatchDog( unsigned short usDevNumber,
unsigned short usMode,
unsigned short *pusDevWatchDog)
{
DEVIO_TRIGGERCMD tBuffer;
unsigned int lBytesReturned ;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( usMode > WATCHDOG_START) {
sRet = DRV_USR_MODE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
//tBuffer.pusTriggerValue = pusDevWatchDog;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLTRIGGERWD, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLREADSEND: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
*pusDevWatchDog = tBuffer.usTriggerValue;
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevSpecialControl
Change the special control value in DevFlags
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - 0 = SPC_CTRL_CLEAR, 1 = SPC_CTRL_SET
*pusDevWatchDog - size of the users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevSpecialControl( unsigned short usDevNumber,
unsigned short usMode,
unsigned short *pusCtrlAck)
{
DEVIO_TRIGGERCMD tBuffer;
unsigned int lBytesReturned ;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if ( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( pusCtrlAck == NULL) {
sRet = DRV_USR_BUF_PTR_NULL;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLSPCONTROL, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLREADSEND: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
*pusCtrlAck = tBuffer.usTriggerValue;
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevExtendedData
extended data function
---------------------------------------------------------------------------------------
Input : usDevNumber - not asigned
usMode - 1 ...n
usSize - length of user data
*pvData - data pointer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevExtendedData( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usSize,
void *pvData)
{
DEVIO_EXTDATACMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( usSize == 0) {
sRet = DRV_USR_SIZE_ZERO;
} else if( usSize > EXTDATASIZE) {
sRet = DRV_USR_SIZE_TOO_LONG;
} else if( (usMode == 0) ||
(usMode > 100) ) {
sRet = DRV_USR_MODE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
tBuffer.pabExtData = pvData;
tBuffer.sError = sRet;
// insert error for older driver versions, because function which are not included
// in the driver returns always DeviceIoControl success without setting an
// error into the tDataBuffer.
sRet = DRV_USR_COMM_ERR;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLEXTDATA, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLEXTDATA: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetTaskParameter
reads the task parameters from task 1 and 2
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usArea - 1,2
usSize - size of the users data buffer
pvData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetTaskParameter( unsigned short usDevNumber,
unsigned short usNumber,
unsigned short usSize,
void *pvData)
{
DEVIO_GETPARAMETERCMD tBuffer;
unsigned int lBytesReturned ;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if(usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usNumber < 1) ||
(usNumber > 2) ) {
sRet = DRV_USR_NUMBER_INVALID;
} else if(usSize == 0) {
sRet = DRV_USR_SIZE_ZERO;
} else if( usSize > sizeof(TASKPARAM)) {
sRet = DRV_USR_SIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
// set command buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usTaskParamNum = usNumber;
tBuffer.usTaskParamLen = usSize;
//tBuffer.ptTaskParam = pvData;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLGETPARAMETER, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLGETPARAMETER: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
memcpy ( (unsigned char *)pvData, (unsigned char *)&(tBuffer.TaskParameter), usSize);
sRet = tBuffer.sError;
}
}
return sRet;
}
/* <ST> =================================================================================
Function: DevReadWriteDPMData
Function to access the whole DPM
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
*pusBytes - Amount of bytes sended
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevReadWriteDPMData( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usOffset,
unsigned short usSize,
void *pvData)
{
DEVIO_RWDPMDATACMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if(usDevNumber >= MAX_DEV_BOARDS ) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usMode != PARAMETER_READ) &&
(usMode != PARAMETER_WRITE) ) {
sRet = DRV_USR_MODE_INVALID;
} else if( ( usSize != 0) &&
( (usSize + usOffset) > (unsigned short)(tDevDPMSize[usDevNumber].ulDpmSize * 1024))) {
sRet = DRV_USR_SIZE_TOO_LONG;;
} else {
// fill in parameter data
lBytesReturned = 0;
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
tBuffer.usOffset = usOffset;
tBuffer.usLen = usSize;
tBuffer.pabData = pvData;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLRWDPMDATA, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLRWDPMDATA: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
} /* endif */
return sRet;
} /* end funktion */
/* <ST> =================================================================================
Function: DevReadWriteDPMRaw
reads and writes bytes from the DPM, last KByte
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0)
usMode - function read = 1, write = 2
usOffset - offset in the RAW data area
usSize - number of bytes to read or write
pvData - pointer to the user data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevReadWriteDPMRaw( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usOffset,
unsigned short usSize,
void *pvData)
{
DEVIO_RWRAWDATACMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if(usDevNumber >= MAX_DEV_BOARDS ) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usSize + usOffset) > sizeof(RAWDATA) ) {
sRet = DRV_USR_SIZE_TOO_LONG;
} else if( (usMode != PARAMETER_READ) &&
(usMode != PARAMETER_WRITE) ) {
sRet = DRV_USR_MODE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
tBuffer.usOffset = usOffset;
tBuffer.usLen = usSize;
tBuffer.pabData = pvData;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLRWRAW, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLRWRAW: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
} /* endif */
return sRet;
} /* end funktion */
/* <ST> =================================================================================
Function: DevExchangeIO
reads and writes IO datas
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usInfoArea - 1..n
usSize - size of the users data buffer
pvData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevExchangeIO( unsigned short usDevNumber,
unsigned short usSendOffset,
unsigned short usSendSize,
void *pvSendData,
unsigned short usReceiveOffset,
unsigned short usReceiveSize,
void *pvReceiveData,
unsigned long ulTimeout)
{
DEVIO_EXIOCMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
int lRet = 0;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usSendSize != 0) &&
((usSendSize + usSendOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_SENDSIZE_TOO_LONG;
} else if( (usReceiveSize != 0) &&
((usReceiveSize + usReceiveOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_RECVSIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usReceiveOffset = usReceiveOffset;
tBuffer.usReceiveLen = usReceiveSize;
tBuffer.usSendOffset = usSendOffset;
tBuffer.usSendLen = usSendSize;
tBuffer.pabSendData = pvSendData;
tBuffer.pabReceiveData = pvReceiveData;
tBuffer.sError = sRet;
tBuffer.ulTimeout = ulTimeout;
// activate function
lRet = ioctl( hDevDrv, CIF_IOCTLEXIO, (unsigned long)(&tBuffer));
if( lRet <= 0) {
//fprintf(stderr, "CIF_IOCTLEXIO: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevExchangeIOEx
reads and writes IO datas
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - Exchange mode
usInfoArea - 1..n
usSize - size of the users data buffer
pvData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevExchangeIOEx( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usSendOffset,
unsigned short usSendSize,
void *pvSendData,
unsigned short usReceiveOffset,
unsigned short usReceiveSize,
void *pvReceiveData,
unsigned long ulTimeout)
{
DEVIO_EXIOCMDEX tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
int lRet = 0;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usSendSize != 0) &&
((usSendSize + usSendOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_SENDSIZE_TOO_LONG;
} else if( (usReceiveSize != 0) &&
((usReceiveSize + usReceiveOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_RECVSIZE_TOO_LONG;
} else if( usMode > 4) {
sRet = DRV_USR_MODE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usReceiveOffset = usReceiveOffset;
tBuffer.usReceiveLen = usReceiveSize;
tBuffer.usSendOffset = usSendOffset;
tBuffer.usSendLen = usSendSize;
tBuffer.pabSendData = pvSendData;
tBuffer.pabReceiveData = pvReceiveData;
tBuffer.ulTimeout = ulTimeout;
tBuffer.sError = sRet;
tBuffer.usMode = (unsigned short)(usMode + 1); // Driver uses 1..5
// activate function
lRet = ioctl (hDevDrv, CIF_IOCTLEXIOEX, (unsigned long)(&tBuffer));
if( lRet <= 0) {
//fprintf(stderr, "CIF_IOCTLEXIO: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevExchangeIOErr
reads and writes IO datas with state field information
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - Exchange mode
usInfoArea - 1..n
usSize - size of the users data buffer
pvData - pointer to users data buffer
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevExchangeIOErr( unsigned short usDevNumber,
unsigned short usSendOffset,
unsigned short usSendSize,
void *pvSendData,
unsigned short usReceiveOffset,
unsigned short usReceiveSize,
void *pvReceiveData,
COMSTATE *ptState,
unsigned long ulTimeout)
{
DEVIO_EXIOCMDERR tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
int lRet = 0;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (usSendSize != 0) &&
((usSendSize + usSendOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_SENDSIZE_TOO_LONG;
} else if( (usReceiveSize != 0) &&
((usReceiveSize + usReceiveOffset) > (unsigned short)tDevDPMSize[usDevNumber].ulDpmIOSize) ) {
sRet = DRV_USR_RECVSIZE_TOO_LONG;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usReceiveOffset = usReceiveOffset;
tBuffer.usReceiveLen = usReceiveSize;
tBuffer.usSendOffset = usSendOffset;
tBuffer.usSendLen = usSendSize;
tBuffer.pabSendData = pvSendData;
tBuffer.pabReceiveData = pvReceiveData;
tBuffer.ptStateData = ptState;
tBuffer.sError = sRet;
tBuffer.ulTimeout = ulTimeout;
// activate function
lRet = ioctl (hDevDrv, CIF_IOCTLEXIOERR, (unsigned long)(&tBuffer));
if( lRet <= 0) {
//fprintf(stderr, "CIF_IOCTLEXIO: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevSetHostState
set the host state
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - 0 = Host not ready, 1 = Host ready
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevSetHostState( unsigned short usDevNumber,
unsigned short usMode,
unsigned long ulTimeout)
{
DEVIO_TRIGGERCMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( usMode > HOST_READY) {
sRet = DRV_USR_MODE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.usMode = usMode;
tBuffer.ulTimeout = ulTimeout;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLSETHOST, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLSETHOST: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevPutMessage
send a message to a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
ptMessage - pointer to users message
ulTimeout - function timeout in milliseconds
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevPutMessage( unsigned short usDevNumber,
MSG_STRUC *ptMessage,
unsigned long ulTimeout)
{
DEVIO_PUTMESSAGECMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.ulTimeout = ulTimeout;
memcpy( &tBuffer.tMsg, ptMessage, sizeof(MSG_STRUC));
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLPUTMSG, (unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLPUTMSG: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else
sRet = tBuffer.sError;
}
return sRet;
}
/* <ST> =================================================================================
Function: DevGetMessage
read a message from a DEV board
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usSize - size of the users data area (>0..<= sizeof(MSG_STRUC))
ptMessage - pointer to the users data buffer
ulTimeout - function timeout in milliseconds
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevGetMessage( unsigned short usDevNumber,
unsigned short usSize,
MSG_STRUC *ptMessage,
unsigned long ulTimeout)
{
DEVIO_GETMESSAGECMD tBuffer;
unsigned int lBytesReturned;
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if(usSize == 0 ||
usSize > sizeof(MSG_STRUC)) {
sRet = DRV_USR_SIZE_INVALID;
} else {
// fill in parameter data
lBytesReturned = 0;
// set output buffer
tBuffer.usBoard = usDevNumber;
tBuffer.ulTimeout = ulTimeout;
tBuffer.sError = sRet;
// activate function
if( !ioctl( hDevDrv, CIF_IOCTLGETMSG,(unsigned long)(&tBuffer)) ) {
//fprintf(stderr, "CIF_IOCTLGETMSG: %s\n", strerror(errno));
sRet = DRV_USR_COMM_ERR;
} else {
memcpy( ptMessage, &tBuffer.tMsg, sizeof(MSG_STRUC));
sRet = tBuffer.sError;
}
}
return sRet;
}
/* ======================================================================================
DOWNLOAD part
=================================================================================== */
/* ------------------------------------------------------------------------------------ */
/* Locale variables */
/* ------------------------------------------------------------------------------------ */
#define MAX_DOWNLOAD_MSG_LENGTH 240
#define TO_COLDSTART 10000L
#define TO_SEND_MSG 500L
#define TO_1ST_MSG 10000L
#define TO_CONT_MSG 1000L
#define TO_LAST_MSG 15000L
// File data structure
typedef struct tagFILEDATA {
int fd;
//struct stat *Info;//struct _stat *Info;
char *pabBuffer;
int lSize;
} FILEDATA;
typedef struct tagDEVICE_TYPE_INFO {
unsigned char bHerstellerkennung;
unsigned char bDeviceType;
unsigned char bDeviceModel;
unsigned char bReserve3;
} DEVICE_TYPE_INFO;
/* <ST> =================================================================================
Function: CloseFile
Close a previously opened file by OpenFile(), free all memory and handles
---------------------------------------------------------------------------------------
Input : ptFile - File data structure
Output : -
Return : -
================================================================================= <En> */
void closeFile ( FILEDATA *ptFile)
{
if ( ptFile->fd >= 0) {
if ( ptFile->pabBuffer != NULL) {
free( ptFile->pabBuffer);
}
close( ptFile->fd);
// Clear file structure
memset ( ptFile, 0, sizeof(FILEDATA));
}
}
/* <ST> =================================================================================
Function: openFile
Open a file and load the file into memory
---------------------------------------------------------------------------------------
Input : pwFileName - Filename including a path
ptFile - File data structure
Output : -
Return : DRV_NO_ERROR - File successfully opened and loaded into memory
================================================================================= <En> */
short openFile ( const char *fileName, FILEDATA *ptFile)
{
unsigned int lNumberOfBytesRead;
short sRet = DRV_NO_ERROR;
// Clear file structure
memset ( ptFile, 0, sizeof(FILEDATA));
// open the existing file
ptFile->fd = open( fileName, O_RDONLY);
if ( ptFile->fd < 0 ) {
// File not opend
sRet = DRV_USR_FILE_OPEN_FAILED;
} else {
// Get the file size
ptFile->lSize = lseek( ptFile->fd, 0, SEEK_END);
if ( ptFile->lSize <= 0) {
// File size is zero
sRet = DRV_USR_FILE_SIZE_ZERO;
} else {
if( lseek( ptFile->fd, 0, SEEK_SET) < 0)
sRet = DRV_USR_FILE_READ_FAILED;
else {
// Allocate memory for file data
if ( (ptFile->pabBuffer = (char*)malloc( ptFile->lSize)) == NULL) {
// Error by memory allocation
sRet = DRV_USR_FILE_NO_MEMORY;
closeFile( ptFile);
} else {
// Read file data into memory
if ( ( lNumberOfBytesRead = read( ptFile->fd, // handle of file to read
ptFile->pabBuffer, // address of buffer that receives data
ptFile->lSize) ) < 0) { // number of bytes to read
// File read into memory failed
sRet = DRV_USR_FILE_READ_FAILED;
closeFile( ptFile);
}
}
}
}
}
return sRet;
}
//----------------------------------------------------------------------------------------
// Free receive mailbox
//----------------------------------------------------------------------------------------
short FreeRecvMailbox( unsigned short usDevNumber)
{
// Read all messages from the device
MSG_STRUC tRecvMsg;
unsigned short usDevState, usHostState, usIdx;
short sRet;
// Read until no msg available
usIdx = 0;
do {
if( (sRet = DevGetMBXState( usDevNumber,
&usDevState,
&usHostState)) != DRV_NO_ERROR) {
// Something wrong, end function
break;
} else {
// Check if message available
if( usHostState == HOST_MBX_FULL) {
// Read message and throw away
DevGetMessage(usDevNumber,
sizeof(MSG_STRUC),
&tRecvMsg,
100L);
} else {
break;
}
}
usIdx++;
} while( usIdx < 150); // A maximum of 150 times
return sRet;
}
//----------------------------------------------------------------------------------------
// Create checksum
//----------------------------------------------------------------------------------------
unsigned short CreateChecksum( unsigned char *pabData,
int lDataLen,
MSG_STRUC *ptSendMsg)
{
int lIdx, lTempLen;
unsigned short usCheckSum, usTemp;
unsigned char *pByte;
// Create length for checksum calculating
usCheckSum = 0; // Clear checksum
lTempLen = lDataLen - 16384 - 64;
pByte = &ptSendMsg->data[3];
// Calculate the Checksum, start with the first message Msg.d[3] up to Msg.d[64]
for ( lIdx = 0; lIdx < 31; lIdx++) {
usTemp = (*(pByte+1));
usTemp = (unsigned short)((usTemp << 8) | (*pByte));
usCheckSum = (unsigned short)(usCheckSum + usTemp);
pByte +=2; // Next short value
}
pByte = &pabData[64];
// Create cheksum for the rest of the file
do {
usTemp = (*(pByte+1));
usTemp = (unsigned short)((usTemp << 8) | (*pByte));
usCheckSum = (unsigned short)(usCheckSum + usTemp);
pByte += 2; // Next short value
lTempLen-=2;
} while (lTempLen > 0);
// Return
return usCheckSum;
}
//----------------------------------------------------------------------------------------
// Transfer messages
//----------------------------------------------------------------------------------------
short TransferMessage( unsigned short usDevNumber,
MSG_STRUC *ptSendMsg,
MSG_STRUC *ptRecvMsg,
long lTimeout)
{
int lCount = 0;
short sRet = DRV_NO_ERROR;
if( (sRet = DevPutMessage(usDevNumber,
ptSendMsg,
TO_SEND_MSG)) == DRV_NO_ERROR) {
do {
if( (sRet = DevGetMessage(usDevNumber,
sizeof(MSG_STRUC),
ptRecvMsg,
lTimeout)) == DRV_NO_ERROR) {
// Check on message errors
if( (ptRecvMsg->tx == ptSendMsg->rx) &&
(ptRecvMsg->rx == ptSendMsg->tx) &&
(ptRecvMsg->a == ptSendMsg->b) &&
(ptRecvMsg->b == 0) &&
(ptRecvMsg->nr == ptSendMsg->nr) ) {
// Check on message error
if( ptRecvMsg->f != 0) {
sRet = (short)(ptRecvMsg->f + DRV_RCS_ERROR_OFFSET);
break;
} else {
break;
}
}
}
// else
lCount++;
} while( lCount < 10);
}
return sRet;
}
//----------------------------------------------------------------------------------------
// Read device information
//----------------------------------------------------------------------------------------
short ReadDeviceInformation( unsigned short usDevNumber,
const char *fileName)
{
int dwStrLen;
short sRet;
MSG_STRUC tSendMsg, tRecvMsg;
DEVICE_TYPE_INFO *pInfo;
memset( &tSendMsg, 0, sizeof( MSG_STRUC));
memset( &tRecvMsg, 0, sizeof( MSG_STRUC));
if ( (sRet = FreeRecvMailbox( usDevNumber)) == DRV_NO_ERROR) {
// Insert data into message
tSendMsg.rx = RCS_TASK;
tSendMsg.tx = MSG_SYSTEM_TX;
tSendMsg.ln = 1;
tSendMsg.nr = 0;
tSendMsg.a = 0;
tSendMsg.f = 0;
tSendMsg.b = RCS_B_SYSFKT;
tSendMsg.e = 0;
// Insert data
tSendMsg.data[0] = MODE_GET_PROJ_WERTE_HW;
if ( (sRet = TransferMessage ( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_SEND_MSG)) == DRV_NO_ERROR) {
// Check entry
dwStrLen = strlen( fileName);
pInfo = (DEVICE_TYPE_INFO*)&tRecvMsg.data[0];
if ( (pInfo->bHerstellerkennung != (char)(toupper( fileName[dwStrLen-3]))) ||
(pInfo->bDeviceType != (char)(toupper( fileName[dwStrLen-2]))) ||
(pInfo->bDeviceModel != (char)(toupper( fileName[dwStrLen-1]))) ) {
sRet = DRV_USR_INVALID_FILETYPE;
}
}
}
return sRet;
}
/* <ST> =================================================================================
Function: RunFirmwareDownload
Download a firmware to a device
---------------------------------------------------------------------------------------
Input : usDevNumber - Device number
pwFile - File name including a path
*pdwBytes - Already loaded bytes
Output : -
Return : DRV_NO_ERROR - Download successfully
================================================================================= <En> */
short RunFirmwareDownload( unsigned short usDevNumber,
FILEDATA *ptFile,
unsigned long *pdwByte)
{
int lFileLength, lSendLen, lActIdx;
unsigned short usCheckSum, usTemp;
unsigned char *pabData;
MSG_STRUC tSendMsg, tRecvMsg;
BOOL fRet;
short sRet;
unsigned int dwState = RCS_FIRST_MSK;
// Load pointer to data
pabData = (unsigned char*)ptFile->pabBuffer;
lActIdx = 0; // Clear actual index
*pdwByte = lActIdx;
// Clear messages
memset( &tSendMsg, 0, sizeof(MSG_STRUC));
memset( &tRecvMsg, 0, sizeof(MSG_STRUC));
// Set data length
lFileLength = ptFile->lSize;
// Set maximum message length
if ( lFileLength > MAX_DOWNLOAD_MSG_LENGTH) lSendLen = MAX_DOWNLOAD_MSG_LENGTH;
else lSendLen = lFileLength;
// Set program state
dwState = RCS_FIRST_MSK;
fRet = TRUE;
// Run download
do {
switch ( dwState) {
//--------------------------
// Send first message
//--------------------------
case RCS_FIRST_MSK:
// Set HOST_READY for download, maybe it is disabled
sRet = DevSetHostState( usDevNumber,
HOST_READY,
0L);
// Insert data into message
tSendMsg.rx = RCS_TASK;
tSendMsg.tx = MSG_SYSTEM_TX;
tSendMsg.ln = 65;
tSendMsg.nr = 1;
tSendMsg.a = 0;
tSendMsg.f = 0;
tSendMsg.b = RCS_B_LOADFKT;
tSendMsg.e = RCS_FIRST_MSK;
// Insert data
tSendMsg.data[0] = 6;
memcpy( &tSendMsg.data[3], "RCSCODE", 7);
usTemp = (unsigned short)( lFileLength / 16);
tSendMsg.data[13] = (unsigned char)(usTemp & 0x00FF);
tSendMsg.data[14] = (unsigned char)((usTemp >> 8) & 0x00FF);
tSendMsg.data[15] = 6;
memcpy( &tSendMsg.data[17], "RCSCODE", 7);
tSendMsg.data[27] = 255;
tSendMsg.data[49] = 255;
// Create check sum
usCheckSum = CreateChecksum( pabData,
lFileLength,
&tSendMsg);
// Insert check sum
tSendMsg.data[1] = (unsigned char)(usCheckSum & 0x00FF);
tSendMsg.data[2] = (unsigned char)((usCheckSum >> 8) & 0x00FF);
// Process message
if ( (sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_1ST_MSG)) != DRV_NO_ERROR ) {
// Could not process this message
fRet = FALSE;
} else {
// ----------------------------
// Message send second message
// ----------------------------
// Save fimware length given in this RCS message
// Set download length to this size
lFileLength = *(int*)(&tRecvMsg.data[0]);
// Send next message
tSendMsg.rx = RCS_TASK;
tSendMsg.tx = MSG_SYSTEM_TX;
tSendMsg.ln = (unsigned char)lSendLen;
tSendMsg.nr = ++tSendMsg.nr;
tSendMsg.a = 0;
tSendMsg.f = 0;
tSendMsg.b = RCS_B_LOADFKT;
tSendMsg.e = RCS_CONT_MSK;
// Set byte 0 to 63 to byte 1 to 65 of the 1st message
memcpy ( &tSendMsg.data[0], &tSendMsg.data[1], 64);
// Insert byte 64 to 239 from the abData[64]
memcpy ( &tSendMsg.data[64], &pabData[64], (unsigned char)(lSendLen - 64));
// Process message
if ( (sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_1ST_MSG)) != DRV_NO_ERROR ) {
// Could not process this message
fRet = FALSE;
} else {
// No error, send next message
lActIdx += lSendLen; // Add send size to actual index
*pdwByte = lActIdx;
// Calculate next message length
if ( lFileLength <= (lSendLen + lActIdx)) {
lSendLen = lFileLength - lActIdx; // Set length to rest of data
dwState = RCS_LAST_MSK;
} else {
dwState = RCS_CONT_MSK;
}
}
}
break;
//--------------------------
// Send continue message
//--------------------------
case RCS_CONT_MSK:
tSendMsg.e = RCS_CONT_MSK;
tSendMsg.ln = (unsigned char)lSendLen;
tSendMsg.nr = ++tSendMsg.nr;
// Send next message
memcpy ( &tSendMsg.data[0], &pabData[lActIdx], lSendLen);
// Process message
if ( (sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_CONT_MSG)) != DRV_NO_ERROR ) {
// Could not process this message
fRet = FALSE;
} else {
//printf("(A)===========================flen = %ld, Sndlen = %ld, ActIdx = %ld\n", lFileLength, lSendLen, lActIdx);
// No error, send next message
lActIdx += lSendLen; // Add send size to actual index
*pdwByte = lActIdx;
// Calculate next message length
if ( lFileLength <= (lSendLen + lActIdx)) {
lSendLen = lFileLength - lActIdx; // Set length to rest of data
dwState = RCS_LAST_MSK;
} else {
dwState = RCS_CONT_MSK;
}
}
break;
//--------------------------
// Send last message
//--------------------------
case RCS_LAST_MSK:
tSendMsg.ln = (unsigned char)lSendLen;
tSendMsg.nr = ++tSendMsg.nr;
tSendMsg.e = RCS_LAST_MSK;
memcpy ( &tSendMsg.data[0], &pabData[lActIdx] , lSendLen);
// Process message
sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_LAST_MSG);
*pdwByte = (lActIdx + lSendLen);
fRet = FALSE; // END after last message
break;
default:
// unkonwn, leave command
sRet = DRV_DEV_FUNCTION_FAILED;
fRet = FALSE;
break;
}
} while ( fRet == TRUE);
return sRet;
}
/* <ST> =================================================================================
Function: RunConfigDownload
Download a configuration to a device
---------------------------------------------------------------------------------------
Input : usDevNumber - Device number
pwFile - File name including a path
*pdwBytes - Already loaded bytes
Output : -
Return : DRV_NO_ERROR - Download successfully
================================================================================= <En> */
short RunConfigDownload( unsigned short usDevNumber,
FILEDATA *ptFile,
unsigned long *pdwByte)
{
unsigned int dwState;
int lSendLen, lActIdx, lOffset, lFileLength;
unsigned char *pabData;
MSG_STRUC tSendMsg, tRecvMsg;
BOOL fRet;
short sRet = DRV_NO_ERROR;
unsigned char ab1StMsgBuf1[16];
unsigned char ab1StMsgBuf2[60];
// Load pointer to data
pabData = (unsigned char*)ptFile->pabBuffer;
// Clear messages
memset( &tSendMsg, 0, sizeof(MSG_STRUC));
memset( &tRecvMsg, 0, sizeof(MSG_STRUC));
// Craete 1st data buffer from DBM file
memcpy( &ab1StMsgBuf1[0], &pabData[44], 16);
// Craete 2nd data buffer from DBM file
lOffset = (*((int*)(&pabData[40]))) + ((*((short*)(&pabData[60]))) * 2) + 14 ;
lOffset = (*(int*)(&pabData[40])) + ((*(short*)(&pabData[lOffset])) *2) + 12 ;
memcpy( &ab1StMsgBuf2[0], &pabData[lOffset], sizeof(ab1StMsgBuf2));
// Set data length
lFileLength = ptFile->lSize;
// Set maximum message length
if ( lFileLength > MAX_DOWNLOAD_MSG_LENGTH) lSendLen = MAX_DOWNLOAD_MSG_LENGTH;
else lSendLen = lFileLength;
lActIdx = 0;
*pdwByte = lActIdx;
// Set program state
dwState = RCS_FIRST_MSK;
fRet = TRUE;
do {
switch( dwState) {
//--------------------------
// Send first message
//--------------------------
case RCS_FIRST_MSK: // Send first message
// Set HOST_READY for download, maybe it is disabled
sRet = DevSetHostState( usDevNumber, HOST_READY, 0L);
// Insert data into message
tSendMsg.rx = RCS_TASK; // Receiver task number
tSendMsg.tx = MSG_SYSTEM_TX; // Transmitter task number
tSendMsg.ln = 51; // Message length first message
tSendMsg.nr = 1; // Message number
tSendMsg.a = 0; // Answer byte cleared
tSendMsg.f = 0; // Error byte cleared
tSendMsg.b = RCS_B_LOADFKT; // Function code
tSendMsg.e = RCS_FIRST_MSK; // First message
tSendMsg.data[0] = MODE_DOWNLOAD_DBM; // Download a configuration file
// Copy buffer 1st to message
memcpy ( &tSendMsg.data[1], &ab1StMsgBuf1[0], sizeof(ab1StMsgBuf1));
// Copy buffer 2nd to message, 34 Byte
memcpy ( &tSendMsg.data[17], &ab1StMsgBuf2[0], 34);
//printf("cifAPI: %ld\n", dwState);
// Process message
if ( (sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_1ST_MSG)) != DRV_NO_ERROR ) {
// Could not process this message
fRet = FALSE;
} else {
// Set Index for next message, start at offset 44
lActIdx = 44;
*pdwByte = lActIdx;
// Message send, goto next message
*pdwByte = lFileLength;
dwState = RCS_CONT_MSK;
}
break;
//--------------------------
// Send continue message
//--------------------------
case RCS_CONT_MSK:
//printf("cifAPI: (case RCS_CONT_MSK:) %ld\n", lActIdx);
// Insert data into message
tSendMsg.rx = RCS_TASK;
tSendMsg.tx = MSG_SYSTEM_TX;
tSendMsg.ln = (unsigned char)lSendLen;
tSendMsg.nr = ++tSendMsg.nr;
tSendMsg.a = 0;
tSendMsg.f = 0;
tSendMsg.b = RCS_B_LOADFKT;
tSendMsg.e = RCS_CONT_MSK;
memcpy ( &tSendMsg.data[0], &pabData[lActIdx] , lSendLen);
// Process message
if ( (sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_CONT_MSG)) != DRV_NO_ERROR ) {
// Could not process this message
fRet = FALSE;
} else {
// No error, send next message
lActIdx += lSendLen; // Add send size to actual index
*pdwByte = lActIdx;
// Calculate next message length
if ( lFileLength <= (lSendLen + lActIdx)) {
lSendLen = lFileLength - lActIdx; // Set length to rest of data
dwState = RCS_LAST_MSK; // Set to last mask
} else {
// Continue message
dwState = RCS_CONT_MSK;
}
}
break;
//--------------------------
// Send last message
//--------------------------
case RCS_LAST_MSK:
// Insert message data
tSendMsg.rx = RCS_TASK;
tSendMsg.tx = MSG_SYSTEM_TX;
tSendMsg.ln = (unsigned char)lSendLen;
tSendMsg.nr = ++tSendMsg.nr;
tSendMsg.a = 0;
tSendMsg.f = 0;
tSendMsg.b = RCS_B_LOADFKT;
tSendMsg.e = RCS_LAST_MSK;
memcpy ( &tSendMsg.data[0], &pabData[lActIdx] , lSendLen);
// Process message
sRet = TransferMessage( usDevNumber,
&tSendMsg,
&tRecvMsg,
TO_LAST_MSG);
*pdwByte = (lActIdx + lSendLen);
fRet = FALSE; // END after last message
break;
default:
// unkonwn, leave command
sRet = DRV_DEV_FUNCTION_FAILED;
fRet = FALSE;
break;
}
} while (fRet == TRUE);
return sRet;
}
/* <ST> =================================================================================
Function: FirmwareDownload
Download a firmware file to a device
---------------------------------------------------------------------------------------
Input : usDevNumber - Device number
pwFile - File name including a path
*pdwBytes - Already loaded bytes
Output : -
Return : DRV_NO_ERROR - Download successfully
================================================================================= <En> */
short FirmwareDownload ( unsigned short usDevNumber,
const char *fileName,
unsigned long *pdwByte)
{
short sRet = DRV_NO_ERROR;
FILEDATA tFileData;
// Read Device Information
if ( (sRet = ReadDeviceInformation( usDevNumber, fileName)) == DRV_NO_ERROR) {
// Firmware name is OK
if ( (sRet = openFile ( fileName, &tFileData)) == DRV_NO_ERROR) {
// Firmware file opened and loaded into RAM
sRet = RunFirmwareDownload( usDevNumber, &tFileData, pdwByte);
closeFile ( &tFileData);
}
}
return sRet;
}
/* <ST> =================================================================================
Function: ConfigDownload
Download a configuration file created by SyCon to a device
---------------------------------------------------------------------------------------
Input : usDevNumber - Device number
pwFile - File name including a path
*pdwBytes - Already loaded bytes
Output : -
Return : DRV_NO_ERROR - Download successfully
================================================================================= <En> */
short ConfigDownload( unsigned short usDevNumber,
const char *fileName,
unsigned long *pdwByte)
{
unsigned short sRet = DRV_NO_ERROR;
FILEDATA tFileData;
if ( (sRet = openFile ( fileName, &tFileData)) == DRV_NO_ERROR) {
// Configuration file opened and loaded into RAM
sRet = RunConfigDownload( usDevNumber, &tFileData, pdwByte);
closeFile ( &tFileData);
}
return sRet;
}
/* <ST> =================================================================================
Function: DevDownload
Download a firmware or configuration file
---------------------------------------------------------------------------------------
Input : usDevNumber - number of the DEV board (0..3)
usMode - 1 = FIRMWARE_DOWNLOAD, 2 = CONFIGURATION_DOWNLOAD
*pdwBytes - Amount of bytes sended
Output : -
Return : DRV_NO_ERROR - function successfull
!= DRV_NO_ERROR - function failed
================================================================================= <En> */
short DevDownload( unsigned short usDevNumber,
unsigned short usMode,
unsigned char *pszFileName,
unsigned long *pdwBytes)
{
short sRet = DRV_NO_ERROR;
// valid handle available, driver is open
if( hDevDrv == INVALID_HANDLE_VALUE) {
sRet = DRV_USR_NOT_INITIALIZED;
} else if( usDevNumber >= MAX_DEV_BOARDS) {
sRet = DRV_USR_DEV_NUMBER_INVALID;
} else if( (pdwBytes == NULL) ||
(pszFileName == NULL) ||
(pdwBytes == NULL) ) {
sRet = DRV_USR_BUF_PTR_NULL;
} else if( strlen( (const char*)pszFileName) == 0) {
sRet = DRV_USR_FILENAME_INVALID;
} else {
switch( usMode) {
case FIRMWARE_DOWNLOAD:
sRet = FirmwareDownload( usDevNumber,
(const char*)pszFileName,
pdwBytes);
break;
case CONFIGURATION_DOWNLOAD:
sRet = ConfigDownload( usDevNumber,
(const char*)pszFileName,
pdwBytes);
break;
default:
sRet = DRV_USR_MODE_INVALID;
} // end switch
}
return sRet;
}
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
========================================================================
cifdev_i.h
-------------------------------------------------------------------------
CREATETED : D. Tsaava, Hilscher GmbH
DATE : 18.07.2000
PROJEKT : CIF device driver
=========================================================================
DISCRIPTION
Internal driver interface definition
=========================================================================
CHANGES
version name date Discription
March 2001
Juli 2004 Redesigned for the 2.6 Kernel
Copyright changed to GNU Lesser GPL
-------------------------------------------------------------------------
V2.602
NOTE: as groundwork for this header served Windows version of
the CIF device driver
******************************************************************** <En> */
#ifndef CIFDEV_I_H
# define CIFDEV_I_H
#ifdef _cplusplus
extern "C" {
#endif /* _cplusplus */
/* ------------------------------------------------------------------------------------ */
/* global definitions */
/* ------------------------------------------------------------------------------------ */
#define MAX_DEV_BOARDS 4 // maximum numbers of boards
/* ------------------------------------------------------------------------------------ */
/* driver errors */
/* ------------------------------------------------------------------------------------ */
#define DRV_NO_ERROR 0 // no error
#define DRV_BOARD_NOT_INITIALIZED -1 // DRIVER board not initialized
#define DRV_INIT_STATE_ERROR -2 // DRIVER error in internal init state
#define DRV_READ_STATE_ERROR -3 // DRIVER error in internal read state
#define DRV_CMD_ACTIVE -4 // DRIVER command on this chanal is activ
#define DRV_PARAMETER_UNKNOWN -5 // DRIVER unknown parameter in function occured
#define DRV_WRONG_DRIVER_VERSION -6 // DRIVER driver version is incompatible with DLL
#define DRV_PCI_SET_CONFIG_MODE -7 // DRIVER error during PCI set config mode
#define DRV_PCI_READ_DPM_LENGTH -8 // DRIVER could not read PCI DPM length
#define DRV_PCI_SET_RUN_MODE -9 // DRIVER error during PCI set run mode
#define DRV_DEV_DPM_ACCESS_ERROR -10 // DEVICE dual port ram not accessable
#define DRV_DEV_NOT_READY -11 // DEVICE not ready (ready flag failed)
#define DRV_DEV_NOT_RUNNING -12 // DEVICE not running (running flag failed)
#define DRV_DEV_WATCHDOG_FAILED -13 // DEVICE watch dog test failed
#define DRV_DEV_OS_VERSION_ERROR -14 // DEVICE signals wrong OS version
#define DRV_DEV_SYSERR -15 // DEVICE error in dual port flags
#define DRV_DEV_MAILBOX_FULL -16 // DEVICE send mailbox is full
#define DRV_DEV_PUT_TIMEOUT -17 // DEVICE PutMessage timeout
#define DRV_DEV_GET_TIMEOUT -18 // DEVICE GetMessage timeout
#define DRV_DEV_GET_NO_MESSAGE -19 // DEVICE no message available
#define DRV_DEV_RESET_TIMEOUT -20 // DEVICE RESET command timeout
#define DRV_DEV_NO_COM_FLAG -21 // DEVICE COM-flag not set
#define DRV_DEV_EXCHANGE_FAILED -22 // DEVICE IO data exchange failed
#define DRV_DEV_EXCHANGE_TIMEOUT -23 // DEVICE IO data exchange timeout
#define DRV_DEV_COM_MODE_UNKNOWN -24 // DEVICE IO data mode unknown
#define DRV_DEV_FUNCTION_FAILED -25 // DEVICE Function call failed
#define DRV_DEV_DPMSIZE_MISMATCH -26 // DEVICE DPM size differs from configuration
#define DRV_DEV_STATE_MODE_UNKNOWN -27 // DEVICE State mode unknown
// Error from Interface functions
#define DRV_USR_OPEN_ERROR -30 // USER driver not opened
#define DRV_USR_INIT_DRV_ERROR -31 // USER can't connect with DEV board
#define DRV_USR_NOT_INITIALIZED -32 // USER board not initialized
#define DRV_USR_COMM_ERR -33 // USER IOCTRL function faild
#define DRV_USR_DEV_NUMBER_INVALID -34 // USER parameter for DEV number invalid
#define DRV_USR_INFO_AREA_INVALID -35 // USER parameter InfoArea unknown
#define DRV_USR_NUMBER_INVALID -36 // USER parameter Number invalid
#define DRV_USR_MODE_INVALID -37 // USER parameter Mode invalid
#define DRV_USR_MSG_BUF_NULL_PTR -38 // USER NULL pointer assignment
#define DRV_USR_MSG_BUF_TOO_SHORT -39 // USER Messagebuffer too short
#define DRV_USR_SIZE_INVALID -40 // USER size parameter invalid
#define DRV_USR_SIZE_ZERO -42 // USER size parameter with zero length
#define DRV_USR_SIZE_TOO_LONG -43 // USER size parameter too long
#define DRV_USR_DEV_PTR_NULL -44 // USER device address null pointer
#define DRV_USR_BUF_PTR_NULL -45 // USER pointer to buffer is a null pointer
#define DRV_USR_SENDSIZE_TOO_LONG -46 // USER SendSize parameter too long
#define DRV_USR_RECVSIZE_TOO_LONG -47 // USER ReceiveSize parameter too long
#define DRV_USR_SENDBUF_PTR_NULL -48 // USER pointer to buffer is a null pointer
#define DRV_USR_RECVBUF_PTR_NULL -49 // USER pointer to buffer is a null pointer
#define DRV_DEV_NO_VIRTUAL_MEM -60 // DEVICE Virtual memory not available
#define DRV_DEV_UNMAP_VIRTUAL_MEM -61 // DEVICE Unmap virtual memory failed
#define DRV_DEV_REQUEST_IRQ_FAILED -62 // DEVICE Request irq failed
#define DRV_USR_FILE_OPEN_FAILED -100 // USER file not opend
#define DRV_USR_FILE_SIZE_ZERO -101 // USER file size zero
#define DRV_USR_FILE_NO_MEMORY -102 // USER not enough memory to load file
#define DRV_USR_FILE_READ_FAILED -103 // USER file read failed
#define DRV_USR_INVALID_FILETYPE -104 // USER file type invalid
#define DRV_USR_FILENAME_INVALID -105 // USER file name not valid
#define DRV_RCS_ERROR_OFFSET 1000 // RCS error number start
/* ------------------------------------------------------------------------------------ */
/* message definition */
/* ------------------------------------------------------------------------------------ */
#ifndef PACKED
# define PACKED __attribute__( (aligned(1)))
#endif /* PACKED */
// max. length is 255 + 8 Bytes
typedef struct tagMSG_STRUC {
unsigned char rx PACKED;
unsigned char tx PACKED;
unsigned char ln PACKED;
unsigned char nr PACKED;
unsigned char a PACKED;
unsigned char f PACKED;
unsigned char b PACKED;
unsigned char e PACKED;
unsigned char data[255] PACKED;
unsigned char dummy[25] PACKED;
} MSG_STRUC;
/* ------------------------------------------------------------------------------------ */
/* DEV DPM DATA structures */
/* ------------------------------------------------------------------------------------ */
typedef struct tagIOINFO {
unsigned char bComBit PACKED;
unsigned char bIOExchangeMode PACKED;
unsigned int ulIOExchangeCnt PACKED;
} IOINFO;
typedef struct tagVERSIONINFO { /* DEV serial number and OS versions */
unsigned int ulDate PACKED PACKED;
unsigned int ulDeviceNo PACKED;
unsigned int ulSerialNo PACKED;
unsigned int ulReserved PACKED;
unsigned char PcOsName0[4] PACKED;
unsigned char PcOsName1[4] PACKED;
unsigned char PcOsName2[4] PACKED;
unsigned char OemIdentifier[4] PACKED;
} VERSIONINFO;
typedef struct tagFIRMWAREINFO {
unsigned char FirmwareName[16] PACKED;
unsigned char FirmwareVersion[16] PACKED;
} FIRMWAREINFO;
typedef struct tagTASKSTATE {
unsigned char TaskState[64] PACKED;
} TASKSTATE;
typedef struct tagTASKPARAM {
unsigned char TaskParameter[64] PACKED;
} TASKPARAM;
typedef struct tagRAWDATA {
unsigned char abRawData[1022] PACKED;
} RAWDATA;
typedef struct tagTASKINFO {
struct {
char TaskName[8] PACKED; /* Task name */
unsigned short Version PACKED; /* Task version */
unsigned char TaskCondition PACKED;
unsigned char reserved[5] PACKED; /* n.c. */
} tInfo [7];
} TASKINFO;
typedef struct tagRCSINFO {
unsigned short RcsVersion PACKED; /* Operationsystem Version */
unsigned char RcsError PACKED;
unsigned char HostWatchDog PACKED;
unsigned char DevWatchDog PACKED;
unsigned char SegmentCount PACKED;
unsigned char DeviceAdress PACKED;
unsigned char DriverType PACKED;
} RCSINFO;
typedef struct tagDEVINFO {
unsigned char DpmSize PACKED;
unsigned char DevType PACKED;
unsigned char DevModel PACKED;
unsigned char DevIdentifier[3] PACKED;
} DEVINFO;
/* ------------------------------------------------------------------------------------ */
/* driver info structure definitions */
/* ------------------------------------------------------------------------------------ */
// Board information structure
typedef struct tagBOARD_INFO{
unsigned char abDriverVersion[16] PACKED; // DRV driver information string
struct {
unsigned short usBoard PACKED; // DRV board number
unsigned short usAvailable PACKED; // DRV board is available
unsigned long ulPhysicalAddress PACKED; // DRV physical DPM address
unsigned short usIrq PACKED; // DRV irq number
} tBoard [MAX_DEV_BOARDS];
unsigned short usBoards_detected PACKED;
} BOARD_INFO;
// Driver information structure
typedef struct tagDRIVERINFO{
unsigned long OpenCnt PACKED; // number of driver open
unsigned long CloseCnt PACKED; // number of driver close
unsigned long ReadCnt PACKED; // number of DevGetMessage commands
unsigned long WriteCnt PACKED; // number of DevPutMessage commands
unsigned long IRQCnt PACKED; // number of IRQs
unsigned char InitMsgFlag PACKED; // DPM state init
unsigned char ReadMsgFlag PACKED; // DPM state read message
unsigned char WriteMsgFlag PACKED; // DPM state write message
unsigned char LastFunction PACKED; // DRV last function in driver
unsigned char WriteState PACKED; // DRV actual write state
unsigned char ReadState PACKED; // DRV actual read state
unsigned char HostFlags PACKED; // DPM HostFlags (PcFlags)
unsigned char MyDevFlags PACKED; // DPM (internal) DevFlags
unsigned char ExComBit PACKED; // COM bit
unsigned long ExIOCnt PACKED; // IO data exchange count
} DRIVERINFO;
// Extended board information structure
typedef struct tagBOARD_INFOEX{
unsigned char abDriverVersion[16] PACKED; // DRV driver information string
struct {
unsigned short usBoard PACKED; // DRV board number
unsigned short usAvailable PACKED; // DRV board is available
unsigned long ulPhysicalAddress PACKED; // DRV physical DPM address
unsigned short usIrq PACKED; // DRV irq number
DRIVERINFO tDriverInfo PACKED; // Driver information
FIRMWAREINFO tFirmware PACKED;
DEVINFO tDeviceInfo PACKED;
RCSINFO tRcsInfo PACKED;
VERSIONINFO tVersion PACKED;
} tBoard [MAX_DEV_BOARDS];
} BOARD_INFOEX;
// State field structure
typedef struct tagCOMSTATE {
unsigned short usMode PACKED; // Actual STATE mode
unsigned short usStateFlag PACKED; // State flag
unsigned char abState[64] PACKED; // State area
} COMSTATE;
// state information in bLastFunction
#define FKT_OPEN 1;
#define FKT_CLOSE 2;
#define FKT_READ 3;
#define FKT_WRITE 4;
#define FKT_IO 5;
// state information in bWriteState and bReadState
#define STATE_IN 0x01;
#define STATE_WAIT 0x02;
#define STATE_OUT 0x03;
#define STATE_IN_IRQ 0x04;
/* ------------------------------------------------------------------------------------ */
/* IOCTRL data structures */
/* ------------------------------------------------------------------------------------ */
// IOCTRL funktion defines, always step 8
/*
* Ioctl definitions
*/
/* Use 'c' as magic number */
#define CIF_IOC_MAGIC 'c'
#define CIF_IOCRESET _IO(CIF_IOC_MAGIC, 0)
#define CIF_IOCTLNOFUNCTION _IO (CIF_IOC_MAGIC, 0)
#define CIF_IOCTLBOARDINFO _IOWR(CIF_IOC_MAGIC, 1, char[256])
#define CIF_IOCTLINITDRV _IOWR(CIF_IOC_MAGIC, 2, char[13])
#define CIF_IOCTLPARAMETER _IOW (CIF_IOC_MAGIC, 3, char[71])
#define CIF_IOCTLRESETDEV _IOW (CIF_IOC_MAGIC, 4, char[13])
#define CIF_IOCTLPUTMSG _IO (CIF_IOC_MAGIC, 5)
#define CIF_IOCTLGETMSG _IO (CIF_IOC_MAGIC, 6)
#define CIF_IOCTLTASKSTATE _IO (CIF_IOC_MAGIC, 7)
#define CIF_IOCTLMBXINFO _IO (CIF_IOC_MAGIC, 8)
#define CIF_IOCTLTRIGGERWD _IO (CIF_IOC_MAGIC, 9)
#define CIF_IOCTLGETINFO _IO (CIF_IOC_MAGIC, 10)
#define CIF_IOCTLEXITDRV _IO (CIF_IOC_MAGIC, 11)
#define CIF_IOCTLGETPARAMETER _IO (CIF_IOC_MAGIC, 12)
#define CIF_IOCTLEXIO _IO (CIF_IOC_MAGIC, 13)
#define CIF_IOCTLSETHOST _IO (CIF_IOC_MAGIC, 14)
#define CIF_IOCTLREADSEND _IO (CIF_IOC_MAGIC, 15)
#define CIF_IOCTLEXTDATA _IO (CIF_IOC_MAGIC, 16)
#define CIF_IOCTLGETMBX _IO (CIF_IOC_MAGIC, 17)
#define CIF_IOCTLBOARDINFOEX _IO (CIF_IOC_MAGIC, 18)
#define CIF_IOCTLEXIOEX _IO (CIF_IOC_MAGIC, 19)
#define CIF_IOCTLEXIOERR _IO (CIF_IOC_MAGIC, 20)
#define CIF_IOCTLRWRAW _IO (CIF_IOC_MAGIC, 21)
#define CIF_IOCTLSPCONTROL _IO (CIF_IOC_MAGIC, 22)
#define CIF_IOCTLGETDPMPTR _IO (CIF_IOC_MAGIC, 23)
#define CIF_IOCTLRWDPMDATA _IO (CIF_IOC_MAGIC, 24)
#define CIF_IOCTL_IRQ_POLL _IOWR(CIF_IOC_MAGIC, 25, char[13])
#define CIF_IOC_MAXNR 25
// interface structure for ioctl's
typedef struct cif_ioctl_data {
unsigned long lInpBuffLen PACKED;
unsigned long lOutBuffLen PACKED;
unsigned char *pInpBuff PACKED;
unsigned char *pOutBuff PACKED;
} cif_ioctl_data;
// SET BOARD OPERATION MODE
typedef struct tagDEVIO_SETOPMODE {
unsigned short usBoard PACKED;
unsigned short usMode PACKED; // Interrupt/polling mode
unsigned short usIrq PACKED;
short sError PACKED;
} DEVIO_SETOPMODE;
// GETBOARDINFORMATION
typedef struct tagDEVIO_GETBOARDINFOCMD {
unsigned short usDevNumber PACKED; // n.a.
unsigned short usInfoLen PACKED; // Information length
BOARD_INFO *ptBoardInfo PACKED;
short sError PACKED;
} DEVIO_GETBOARDINFOCMD;
// Extnded GETBOARDINFORMATION
typedef struct tagDEVIO_GETBOARDINFOEXCMD {
unsigned short usDevNumber PACKED; // n.a.
unsigned short usInfoLen PACKED; // Information length
BOARD_INFOEX * ptBoard PACKED;
short sError PACKED;
} DEVIO_GETBOARDINFOEXCMD;
// RESETDEV
#define COLDSTART 2
#define WARMSTART 3
#define BOOTSTART 4
typedef struct tagDEVIO_RESETCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usMode PACKED; // DEV function
unsigned long ulTimeout PACKED; // Service timeout
unsigned long ulDpmSize PACKED;
short sError PACKED;
} DEVIO_RESETCMD;
// PUTTASKPARAMETER
typedef struct tagDEVIO_PUTPARAMETERCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usTaskParamNum PACKED; // Number of the parameter area
unsigned short usTaskParamLen PACKED; // Lenght of parameter data
unsigned char TaskParameter[64] PACKED;
short sError PACKED;
} DEVIO_PUTPARAMETERCMD;
// PUTMESSAGE
typedef struct tagDEVIO_PUTMESSAGECMD {
unsigned short usBoard PACKED; // DEV board number
MSG_STRUC tMsg PACKED; // Message data
unsigned long ulTimeout PACKED; // Service timeout
short sError PACKED;
} DEVIO_PUTMESSAGECMD;
// GETMESSAGE
typedef struct tagDEVIO_GETMESSAGECMD {
unsigned short usBoard PACKED; // DEV board number
unsigned long ulTimeout PACKED; // Service timeout
unsigned long ulMsgSize PACKED; // User message buffer size
MSG_STRUC tMsg PACKED; // Message data
short sError PACKED;
} DEVIO_GETMESSAGECMD;
// GETTASKSTATE
typedef struct tagDEVIO_GETTASKSTATECMD {
unsigned char ucBoard PACKED; // DEV board number
unsigned short usStateNum PACKED; // Task state field number
unsigned short usStateLen PACKED; // Lenght of state data
unsigned char TaskState[64] PACKED;
short sError PACKED;
} DEVIO_GETTASKSTATECMD;
// DEVMBXINFO
#define DEVICE_MBX_EMPTY 0
#define DEVICE_MBX_FULL 1
#define HOST_MBX_EMPTY 0
#define HOST_MBX_FULL 1
#define HOST_MBX_SYSERR 2
typedef struct tagDEVIO_MBXINFOCMD {
unsigned char ucBoard PACKED; // DEV board number
unsigned short usDevMbxState PACKED; // State of the device mailbox
unsigned short usHostMbxState PACKED; // State of the host mailbox
short sError PACKED;
} DEVIO_MBXINFOCMD;
// Board operation mode
#define POLLING_MODE 0
#define INTERRUPT_MODE 1
// TRIGGERWATCHDOG and SETHOSTSTATE
#define WATCHDOG_STOP 0
#define WATCHDOG_START 1
#define HOST_NOT_READY 0
#define HOST_READY 1
#define SPECIAL_CONTROL_CLEAR 0
#define SPECIAL_CONTROL_SET 1
typedef struct tagDEVIO_TRIGGERCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usMode PACKED; // DEV function
unsigned long ulTimeout PACKED; // DEV timeout
unsigned short usTriggerValue PACKED; // DEV trigger value
short sError PACKED;
} DEVIO_TRIGGERCMD;
// GETINFO
// InfoArea definitions
#define GET_DRIVER_INFO 1
#define GET_VERSION_INFO 2
#define GET_FIRMWARE_INFO 3
#define GET_TASK_INFO 4
#define GET_RCS_INFO 5
#define GET_DEV_INFO 6
#define GET_IO_INFO 7
#define GET_IO_SEND_DATA 8
typedef struct tagDEVIO_GETDEVINFOCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usInfoArea PACKED; // Number of info area
unsigned short usInfoLen PACKED; // Lenght of info data
unsigned char * pabInfoData PACKED; // Pointer to info data area
short sError PACKED;
} DEVIO_GETDEVINFOCMD;
// EXITDRV
typedef struct tagDEVIO_EXITCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usDrvOpenCount PACKED; // dr�er opencount
short sError PACKED;
} DEVIO_EXITCMD;
// GETTASKPARAMETER
typedef struct tagDEVIO_GETPARAMETERCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usTaskParamNum PACKED; // Number of the parameter area
unsigned short usTaskParamLen PACKED; // Lenght of parameter data
unsigned char TaskParameter[64] PACKED;
short sError PACKED;
} DEVIO_GETPARAMETERCMD;
// EXIO
typedef struct tagDEVIO_EXIOCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usSendOffset PACKED; // Byte offset send data
unsigned short usSendLen PACKED; // Length of send data
unsigned char *pabSendData PACKED; // Send data buffer
unsigned short usReceiveOffset PACKED; // Byte offset receive data
unsigned short usReceiveLen PACKED; // Length of receive data
unsigned char *pabReceiveData PACKED; // Receive data buffer
unsigned long ulTimeout PACKED; // Service timeout
short sError PACKED;
} DEVIO_EXIOCMD;
// EXIOEX
typedef struct tagDEVIO_EXIOCMDEX {
unsigned short usBoard PACKED; // DEV board number
unsigned short usSendOffset PACKED; // Byte offset send data
unsigned short usSendLen PACKED; // Length of send data
unsigned char * pabSendData PACKED; // Send data buffer
unsigned short usReceiveOffset PACKED; // Byte offset receive data
unsigned short usReceiveLen PACKED; // Length of receive data
unsigned char * pabReceiveData PACKED; // Receive data buffer
unsigned long ulTimeout PACKED; // Service timeout
short sError PACKED; // --- Equal to "ExcahangeIOCmd"
unsigned short usMode PACKED; // External exchange mode
} DEVIO_EXIOCMDEX;
// EXIOERR
#define STATE_ERR_NON 0
#define STATE_ERR 1
#define STATE_MODE_2 2
#define STATE_MODE_3 3
#define STATE_MODE_4 4
typedef struct tagDEVIO_EXIOCMDERR {
unsigned short usBoard PACKED; // DEV board number
unsigned short usSendOffset PACKED; // Byte offset send data
unsigned short usSendLen PACKED; // Length of send data
unsigned char *pabSendData PACKED; // Send data buffer
unsigned short usReceiveOffset PACKED; // Byte offset receive data
unsigned short usReceiveLen PACKED; // Length of receive data
unsigned char *pabReceiveData PACKED; // Receive data buffer
unsigned long ulTimeout PACKED; // Service timeout
short sError PACKED; // --- Equal to "ExcahangeIOCmd"
COMSTATE *ptStateData PACKED; // State data buffer
} DEVIO_EXIOCMDERR;
// READIO
typedef struct tagDEVIO_READSENDCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usReadOffset PACKED; // Byte offset send/receive data
unsigned short usReadLen PACKED; // Length of send/receive data
unsigned char * pabReadData PACKED; // Read send data buffer
short sError PACKED;
} DEVIO_READSENDCMD;
// ExtData
#define EXTDATASIZE 20
typedef struct tagDEVIO_EXTDATACMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usMode PACKED; // DEV mode
unsigned char *pabExtData PACKED; // DEV Extended data
short sError PACKED;
} DEVIO_EXTDATACMD;
// GetMbxData
typedef struct tagDEVIO_GETMBXCMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usDevLen PACKED; // DEV length of dev data
unsigned short usHostLen PACKED; // DEV length of host data
unsigned char abHostMbx[288] PACKED; // DEV pointer to host data buffer
unsigned char abDevMbx[288] PACKED; // DEV pointer to device data buffer
short sError PACKED;
} DEVIO_GETMBXCMD;
// ReadWriteRawData
#define PARAMETER_READ 1
#define PARAMETER_WRITE 2
typedef struct tagDEVIO_RWRAWDATACMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usMode PACKED; // DEV read or write
unsigned short usOffset PACKED; // DEV offset in the DPM last kByte
unsigned short usLen PACKED; // DEV length of data
unsigned char *pabData PACKED; // DEV pointer to data buffer
short sError PACKED;
} DEVIO_RWRAWDATACMD;
// ReadWriteDPMData
typedef struct tagDEVIO_RWDPMDATACMD {
unsigned short usBoard PACKED; // DEV board number
unsigned short usMode PACKED; // DEV read or write
unsigned short usOffset PACKED; // DEV offset in the DPM last kByte
unsigned short usLen PACKED; // DEV length of data
unsigned char *pabData PACKED; // DEV pointer to data buffer
short sError PACKED;
} DEVIO_RWDPMDATACMD;
// GetDPMPtr
#define DPM_PTR_OPEN_DRV 1
#define DPM_PTR_OPEN_USR 2
#define DPM_PTR_CLOSE 3
typedef struct tagDEVIO_GETDPMPTR {
unsigned short usMode PACKED; // DEV mode
unsigned short usBoard PACKED; // DEV board number
void *pvUserData PACKED; // DEV user data for pmi
unsigned long *pulDPMSize PACKED; // DEV DPM size in bytes
unsigned char **pDPMBase PACKED; // DEV pointer to data buffer
unsigned long lError PACKED; // DEV system error
short sError PACKED; // DEV driver error
} DEVIO_GETDPMPTR;
#ifdef _cplusplus
}
#endif
#endif /* CIFDEV_I_H */
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
=========================================================================
cif_types.h
-------------------------------------------------------------------------
CREATETED : D. Tsaava, Hilscher GmbH
DATE : 18.07.2000
PROJEKT : CIF device driver
=========================================================================
DISCRIPTION
Includefile for CIF device driver, DPM layout .
=========================================================================
CHANGES
version name date Discription
March 2001
Juli 2004 Redesigned for the 2.6 Kernel
Copyright changed to GNU Lesser GPL
-------------------------------------------------------------------------
V2.602
******************************************************************** <En> */
#ifndef CIF_TYPES_H
# define CIF_TYPES_H
/* Macros for debugging */
#undef DBG_PRN /* undef it, just in case */
#ifdef CIF_DEBUG
# define CIF_PRN(function, lineno,fmt,args...) printk(fmt,function,lineno,##args)
# define DBG_PRN(fmt,args...) CIF_PRN((__FUNCTION__),(__LINE__),KERN_INFO __FILE__"::%s(L%.4d): "fmt,##args)
#else
# define DBG_PRN(fmt, args...) /* not debugging: nothing */
#endif
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifndef BOOL
# define BOOL int
#endif
#endif /* CIF_TYPES_H */
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
========================================================================
cif_user.h
-------------------------------------------------------------------------
CREATETED : D. Tsaava, Hilscher GmbH
DATE : 18.07.2000
PROJEKT : CIF device driver
=========================================================================
DISCRIPTION
User interface definition.
=========================================================================
CHANGES
version name date Discription
Juli 2004 Copyright changed to GNU Lesser GPL
-------------------------------------------------------------------------
V2.000
NOTE: The Code from the Windows version of the driver related to
driver API was taken over for the most part unchanged
******************************************************************** <En> */
/* prevent multiple inclusion */
#ifndef CIFUSER_H_INCLUDED
#define CIFUSER_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif /* _cplusplus */
#ifndef _GNUC_
# define _GNUC_
#endif /* _GNUC_ */
/* ------------------------------------------------------------------------------------ */
/* global definitions */
/* ------------------------------------------------------------------------------------ */
#define MAX_DEV_BOARDS 4 // maximum numbers of boards
/* ------------------------------------------------------------------------------------ */
/* driver errors */
/* ------------------------------------------------------------------------------------ */
#define DRV_NO_ERROR 0 // no error
#define DRV_BOARD_NOT_INITIALIZED -1 // DRIVER Board not initialized
#define DRV_INIT_STATE_ERROR -2 // DRIVER Error in internal init state
#define DRV_READ_STATE_ERROR -3 // DRIVER Error in internal read state
#define DRV_CMD_ACTIVE -4 // DRIVER Command on this channel is activ
#define DRV_PARAMETER_UNKNOWN -5 // DRIVER Unknown parameter in function occured
#define DRV_WRONG_DRIVER_VERSION -6 // DRIVER Version is incompatible with DLL
#define DRV_PCI_SET_CONFIG_MODE -7 // DRIVER Error during PCI set run mode
#define DRV_PCI_READ_DPM_LENGTH -8 // DRIVER Could not read PCI dual port memory length
#define DRV_PCI_SET_RUN_MODE -9 // DRIVER Error during PCI set run mode
#define DRV_DEV_DPM_ACCESS_ERROR -10 // DEVICE Dual port ram not accessable(board not found)
#define DRV_DEV_NOT_READY -11 // DEVICE Not ready (ready flag failed)
#define DRV_DEV_NOT_RUNNING -12 // DEVICE Not running (running flag failed)
#define DRV_DEV_WATCHDOG_FAILED -13 // DEVICE Watchdog test failed
#define DRV_DEV_OS_VERSION_ERROR -14 // DEVICE Signals wrong OS version
#define DRV_DEV_SYSERR -15 // DEVICE Error in dual port flags
#define DRV_DEV_MAILBOX_FULL -16 // DEVICE Send mailbox is full
#define DRV_DEV_PUT_TIMEOUT -17 // DEVICE PutMessage timeout
#define DRV_DEV_GET_TIMEOUT -18 // DEVICE GetMessage timeout
#define DRV_DEV_GET_NO_MESSAGE -19 // DEVICE No message available
#define DRV_DEV_RESET_TIMEOUT -20 // DEVICE RESET command timeout
#define DRV_DEV_NO_COM_FLAG -21 // DEVICE COM-flag not set
#define DRV_DEV_EXCHANGE_FAILED -22 // DEVICE IO data exchange failed
#define DRV_DEV_EXCHANGE_TIMEOUT -23 // DEVICE IO data exchange timeout
#define DRV_DEV_COM_MODE_UNKNOWN -24 // DEVICE IO data mode unknown
#define DRV_DEV_FUNCTION_FAILED -25 // DEVICE Function call failed
#define DRV_DEV_DPMSIZE_MISMATCH -26 // DEVICE DPM size differs from configuration
#define DRV_DEV_STATE_MODE_UNKNOWN -27 // DEVICE State mode unknown
// Error from Interface functions
#define DRV_USR_OPEN_ERROR -30 // USER Driver not opened (device driver not loaded)
#define DRV_USR_INIT_DRV_ERROR -31 // USER Can't connect with device
#define DRV_USR_NOT_INITIALIZED -32 // USER Board not initialized (DevInitBoard not called)
#define DRV_USR_COMM_ERR -33 // USER IOCTRL function failed
#define DRV_USR_DEV_NUMBER_INVALID -34 // USER Parameter DeviceNumber invalid
#define DRV_USR_INFO_AREA_INVALID -35 // USER Parameter InfoArea unknown
#define DRV_USR_NUMBER_INVALID -36 // USER Parameter Number invalid
#define DRV_USR_MODE_INVALID -37 // USER Parameter Mode invalid
#define DRV_USR_MSG_BUF_NULL_PTR -38 // USER NULL pointer assignment
#define DRV_USR_MSG_BUF_TOO_SHORT -39 // USER Message buffer too short
#define DRV_USR_SIZE_INVALID -40 // USER Parameter Size invalid
#define DRV_USR_SIZE_ZERO -42 // USER Parameter Size with zero length
#define DRV_USR_SIZE_TOO_LONG -43 // USER Parameter Size too long
#define DRV_USR_DEV_PTR_NULL -44 // USER Device address null pointer
#define DRV_USR_BUF_PTR_NULL -45 // USER Pointer to buffer is a null pointer
#define DRV_USR_SENDSIZE_TOO_LONG -46 // USER Parameter SendSize too long
#define DRV_USR_RECVSIZE_TOO_LONG -47 // USER Parameter ReceiveSize too long
#define DRV_USR_SENDBUF_PTR_NULL -48 // USER Pointer to send buffer is a null pointer
#define DRV_USR_RECVBUF_PTR_NULL -49 // USER Pointer to receive buffer is a null pointer
#define DRV_DEV_NO_VIRTUAL_MEM -60 // DEVICE Virtual memory not available
#define DRV_DEV_UNMAP_VIRTUAL_MEM -61 // DEVICE Unmap virtual memory failed
#define DRV_DEV_REQUEST_IRQ_FAILED -62 // DEVICE Request irq failed
#define DRV_USR_FILE_OPEN_FAILED -100 // USER file not opend
#define DRV_USR_FILE_SIZE_ZERO -101 // USER file size zero
#define DRV_USR_FILE_NO_MEMORY -102 // USER not enough memory to load file
#define DRV_USR_FILE_READ_FAILED -103 // USER file read failed
#define DRV_USR_INVALID_FILETYPE -104 // USER file type invalid
#define DRV_USR_FILENAME_INVALID -105 // USER file name not valid
#define DRV_RCS_ERROR_OFFSET 1000 // RCS error number start
#ifndef PACKED
# define PACKED __attribute__( (aligned(1)))
#endif /* PACKED */
/* ------------------------------------------------------------------------------------ */
/* message definition */
/* ------------------------------------------------------------------------------------ */
// max. length is 288 Bytes, max message length is 255 + 8 Bytes
typedef struct tagMSG_STRUC {
unsigned char rx PACKED;
unsigned char tx PACKED;
unsigned char ln PACKED;
unsigned char nr PACKED;
unsigned char a PACKED;
unsigned char f PACKED;
unsigned char b PACKED;
unsigned char e PACKED;
unsigned char data[255] PACKED;
unsigned char dummy[25] PACKED; // for compatibility with older definitions (288 Bytes)
} MSG_STRUC;
/* ------------------------------------------------------------------------------------ */
/* INFO structure definitions */
/* ------------------------------------------------------------------------------------ */
// Board operation mode
#define POLLING_MODE 0
#define INTERRUPT_MODE 1
// DEVRESET
#define COLDSTART 2
#define WARMSTART 3
#define BOOTSTART 4
// DEVMBXINFO
#define DEVICE_MBX_EMPTY 0
#define DEVICE_MBX_FULL 1
#define HOST_MBX_EMPTY 0
#define HOST_MBX_FULL 1
// TRIGGERWATCHDOG
#define WATCHDOG_STOP 0
#define WATCHDOG_START 1
// GETINFO InfoArea definitions
#define GET_DRIVER_INFO 1
#define GET_VERSION_INFO 2
#define GET_FIRMWARE_INFO 3
#define GET_TASK_INFO 4
#define GET_RCS_INFO 5
#define GET_DEV_INFO 6
#define GET_IO_INFO 7
#define GET_IO_SEND_DATA 8
// HOST mode definition
#define HOST_NOT_READY 0
#define HOST_READY 1
// DEVREADWRITERAW
#define PARAMETER_READ 1
#define PARAMETER_WRITE 2
// STATE definition
#define STATE_ERR_NON 0
#define STATE_ERR 1
#define STATE_MODE_2 2
#define STATE_MODE_3 3
#define STATE_MODE_4 4
// DEVSPECIALCONTROL
#define SPECIAL_CONTROL_CLEAR 0
#define SPECIAL_CONTROL_SET 1
// DEVDOWNLOAD
#define FIRMWARE_DOWNLOAD 1
#define CONFIGURATION_DOWNLOAD 2
// Device exchange IO information
typedef struct tagIOINFO {
unsigned char bComBit PACKED; /* Actual state of the COM bit */
unsigned char bIOExchangeMode PACKED; /* Actual data exchange mode (0..5) */
unsigned int ulIOExchangeCnt PACKED; /* Exchange IO counter */
} IOINFO;
// Device version information
typedef struct tagVERSIONINFO { /* DEV serial number and OS versions */
unsigned int ulDate PACKED;
unsigned int ulDeviceNo PACKED;
unsigned int ulSerialNo PACKED;
unsigned int ulReserved PACKED;
unsigned char abPcOsName0[4] PACKED;
unsigned char abPcOsName1[4] PACKED;
unsigned char abPcOsName2[4] PACKED;
unsigned char abOemIdentifier[4] PACKED;
} VERSIONINFO;
// Device firmware information
typedef struct tagFIRMWAREINFO {
unsigned char abFirmwareName[16] PACKED; /* Firmware name */
unsigned char abFirmwareVersion[16] PACKED; /* Firmware version */
} FIRMWAREINFO;
// Device task state information
typedef struct tagTASKSTATE {
unsigned char abTaskState[64] PACKED; /* Task state field */
} TASKSTATE;
// Device task paramater data
typedef struct tagTASKPARAM {
unsigned char abTaskParameter[64] PACKED; /* Task parameter field */
} TASKPARAM;
// Device raw data structure
typedef struct tagRAWDATA {
unsigned char abRawData[1022] PACKED; /* Definition of the last kByte */
} RAWDATA;
// Device task information
typedef struct tagTASKINFO {
struct {
unsigned char abTaskName[8] PACKED; /* Task name */
unsigned short usTaskVersion PACKED; /* Task version */
unsigned char bTaskCondition PACKED; /* Actual task condition */
unsigned char abreserved[5] PACKED; /* n.c. */
} tTaskInfo [7];
} TASKINFO;
// Device operating system (RCS) information
typedef struct tagRCSINFO {
unsigned short usRcsVersion PACKED; /* Device operating system (RCS) version */
unsigned char bRcsError PACKED; /* Operating system errors */
unsigned char bHostWatchDog PACKED; /* Host watchdog value */
unsigned char bDevWatchDog PACKED; /* Device watchdog value */
unsigned char bSegmentCount PACKED; /* RCS segment free counter */
unsigned char bDeviceAdress PACKED; /* RCS device base address */
unsigned char bDriverType PACKED; /* RCS driver type */
} RCSINFO;
// Device description
typedef struct tagDEVINFO {
unsigned char bDpmSize PACKED; /* Device dpm size (2,8...) */
unsigned char bDevType PACKED; /* Device type (manufactor code) */
unsigned char bDevModel PACKED; /* Device model (manufactor code) */
unsigned char abDevIdentifier[3] PACKED; /* Device identification characters */
} DEVINFO;
/* ------------------------------------------------------------------------------------ */
/* driver info structure definitions */
/* ------------------------------------------------------------------------------------ */
// Board information structure
typedef struct tagBOARD_INFO{
unsigned char abDriverVersion[16] PACKED; // DRV driver information string
struct {
unsigned short usBoard PACKED; // DRV board number
unsigned short usAvailable PACKED; // DRV board is available
unsigned long ulPhysicalAddress PACKED; // DRV physical DPM address
unsigned short usIrq PACKED; // DRV irq number
} tBoard [MAX_DEV_BOARDS];
unsigned short usBoards_detected PACKED;
} BOARD_INFO;
// Internal driver state information structure
typedef struct tagDRIVERINFO {
unsigned long ulOpenCnt PACKED; // DevOpen() counter
unsigned long CloseCnt PACKED; // number of driver close
unsigned long ulReadCnt PACKED; // Number of DevGetMessage commands
unsigned long ulWriteCnt PACKED; // Number of DevPutMessage commands
unsigned long ulIRQCnt PACKED; // Number of board interrupts
unsigned char bInitMsgFlag PACKED; // Actual init sate
unsigned char bReadMsgFlag PACKED; // Actual read mailbox state
unsigned char bWriteMsgFlag PACKED; // Actual write mailbox state
unsigned char bLastFunction PACKED; // Last driver function
unsigned char bWriteState PACKED; // Actual write command state
unsigned char bReadState PACKED; // Actual read command state
unsigned char bHostFlags PACKED; // Actual host flags
unsigned char bMyDevFlags PACKED; // Actual device falgs
unsigned char bExIOFlag PACKED; // Actual IO flags
unsigned long ulExIOCnt PACKED; // DevExchangeIO() counter
} DRIVERINFO;
// Extended board information structure
typedef struct tagBOARD_INFOEX{
unsigned char abDriverVersion[16] PACKED; // DRV driver information string
struct {
unsigned short usBoard PACKED; // DRV board number
unsigned short usAvailable PACKED; // DRV board is available
unsigned long ulPhysicalAddress PACKED; // DRV physical DPM address
unsigned short usIrq PACKED; // DRV irq number
DRIVERINFO tDriverInfo PACKED; // Driver information
FIRMWAREINFO tFirmware PACKED;
DEVINFO tDeviceInfo PACKED;
RCSINFO tRcsInfo PACKED;
VERSIONINFO tVersion PACKED;
} tBoard [MAX_DEV_BOARDS];
} BOARD_INFOEX;
// changes made for 64-bit architecture
// 64-bit Linux machine & 32-bit Windows machine
// #ifdef CONFIG_64BIT
// Extended board information structure
typedef struct tagBOARD_INFOEX_32 {
unsigned char abDriverVersion[16] PACKED; // DRV driver information string
unsigned char abCatchall[484] PACKED; // catchall
/*struct {
unsigned short usBoard PACKED; // DRV board number
unsigned short usAvailable PACKED; // DRV board is available
unsigned long ulPhysicalAddress PACKED; // DRV physical DPM address
unsigned short usIrq PACKED; // DRV irq number
DRIVERINFO tDriverInfo PACKED; // Driver information
FIRMWAREINFO tFirmware PACKED;
DEVINFO tDeviceInfo PACKED;
RCSINFO tRcsInfo PACKED;
VERSIONINFO tVersion PACKED;
} tBoard [MAX_DEV_BOARDS];*/
} BOARD_INFOEX_32;
// Communication state field structure
typedef struct tagCOMSTATE {
unsigned short usMode PACKED; // Actual STATE mode
unsigned short usStateFlag PACKED; // State flag
unsigned char abState[64] PACKED; // State area
} COMSTATE;
// state information in bLastFunction
#define FKT_OPEN 1;
#define FKT_CLOSE 2;
#define FKT_READ 3;
#define FKT_WRITE 4;
#define FKT_IO 5;
// state information in bWriteState and bReadState
#define STATE_IN 0x01;
#define STATE_WAIT 0x02;
#define STATE_OUT 0x03;
#define STATE_IN_IRQ 0x04;
/* ------------------------------------------------------------------------------------ */
/* funcion prototypes */
/* ------------------------------------------------------------------------------------ */
extern short DevOpenDriver ( void);
extern short DevCloseDriver ( void);
extern short DevGetBoardInfo ( BOARD_INFO *pvData);
extern short DevInitBoard ( unsigned short usDevNumber);
extern short DevExitBoard ( unsigned short usDevNumber);
extern short DevPutTaskParameter ( unsigned short usDevNumber,
unsigned short usNumber,
unsigned short usSize,
void *pvData);
extern short DevReset ( unsigned short usDevNumber,
unsigned short usMode,
unsigned long ulTimeout);
extern short DevPutMessage ( unsigned short usDevNumber,
MSG_STRUC *ptMessage,
unsigned long ulTimeout);
extern short DevGetMessage ( unsigned short usDevNumber,
unsigned short usSize,
MSG_STRUC *ptMessage,
unsigned long ulTimeout);
extern short DevGetTaskState ( unsigned short usDevNumber,
unsigned short usNumber,
unsigned short usSize,
void *pvData);
extern short DevGetMBXState ( unsigned short usDevNumber,
unsigned short *pusDevMBXState,
unsigned short *pusHostMBXState);
extern short DevTriggerWatchDog ( unsigned short usDevNumber,
unsigned short usFunction,
unsigned short *usDevWatchDog);
extern short DevGetInfo ( unsigned short usDevNumber,
unsigned short usFunction,
unsigned short usSize,
void *pvData);
extern short DevGetTaskParameter ( unsigned short usDevNumber,
unsigned short usNumber,
unsigned short usSize,
void *pvData);
extern short DevExchangeIO ( unsigned short usDevNumber,
unsigned short usSendOffset,
unsigned short usSendSize,
void *pvSendData,
unsigned short usReceiveOffset,
unsigned short usReceiveSize,
void *pvReceiveData,
unsigned long ulTimeout);
extern short DevReadSendData ( unsigned short usDevNumber,
unsigned short usOffset,
unsigned short usSize,
void *pvData);
extern short DevSetHostState ( unsigned short usDevNumber,
unsigned short usMode,
unsigned long ulTimeout);
extern short DevExtendedData ( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usSize,
void *pvData);
extern short DevGetMBXData ( unsigned short usDevNumber,
unsigned short usHostSize,
void *pvHostData,
unsigned short usDevSize,
void *pvDevData);
extern short DevGetBoardInfoEx ( void *pvData);
extern short DevExchangeIOEx ( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usSendOffset,
unsigned short usSendSize,
void *pvSendData,
unsigned short usReceiveOffset,
unsigned short usReceiveSize,
void *pvReceiveData,
unsigned long ulTimeout);
extern short DevExchangeIOErr ( unsigned short usDevNumber,
unsigned short usSendOffset,
unsigned short usSendSize,
void *pvSendData,
unsigned short usReceiveOffset,
unsigned short usReceiveSize,
void *pvReceiveData,
COMSTATE *ptState,
unsigned long ulTimeout);
extern short DevReadWriteDPMRaw ( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usOffset,
unsigned short usSize,
void *pvData);
extern short DevSpecialControl ( unsigned short usDevNumber,
unsigned short usMode,
unsigned short *pusCtrlAck);
extern short DevDownload( unsigned short usDevNumber,
unsigned short usMode,
unsigned char *pszFileName,
unsigned long *pdwBytes);
extern short DevReadWriteDPMData ( unsigned short usDevNumber,
unsigned short usMode,
unsigned short usOffset,
unsigned short usSize,
void *pvData);
extern short DevSetOpMode ( unsigned short usBoard,
unsigned short usMode ,
unsigned short *usIrq );
#ifdef __cplusplus
}
#endif
#endif // ifndef CIFUSER_H_INCLUDED
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
========================================================================
FILENAME : DPM_USER.H
-------------------------------------------------------------------------
CREATED BY : Armin Beck, Hilscher GmbH
CREATED AT : 10.05.96
PROJECT :
=========================================================================
FUNCTION :
User-Interface to PROFIBUS DP-master
=========================================================================
CHANGES OF REVISIONS :
Version Name Date Change
-------------------------------------------------------------------------
V1.711 SW 16.02.04 - GNUC_PACKED added again
RH 24.09.03 - new bit at structure sl_flag
V1.710 AB 16.10.02 - new service FDL_Sap_Deactivate
- replacing FMA_ primitives by FDL_ primitves in
defined structures
V1.700 AB 03.07.02 - changing the value DPM_FORMAT_INTEL/MOTOROLA
to value DPM_FORMAT_SWAP/NO_SWAP
V1.600 AB 14.08.01 - changing order of bDsap und bSSsap
in structure FDL_DATA_ACK_IND_STU
and structure FDL_DATA_REPLY_IND_STU
- correction of definition FDL_Send_Data_Ack_Ind
- new indication command FDL_Send_Data_No_Ack_Ind
inserted
- corretion of FDL_DATA_ACK_IND_STU structure
V1.501 AB 23.05.01 definition EA_OFFSET_BYTE inserted
definition DDLM_RD_Input, DDLM_RD_Output
DDLM_Set_Slave_Add inserted
insert define __DPM_USER_H
09.05.01 new MPI primitives included
V1.500 AB 04.05.01 defining the DPV1_USR_PRM structure in the slave
parameter data set as union, to distinguish
slave with DPV1 capability and non capability
V1.404 AB 17.04.01 documentation of structure FDL_DATA_REPLY_IND_STU
V1.403 AB 19.11.01 new message FDL_Send_Data_Ack and
FDL_Send_Data_No_Ack and FDL_Reply_Update
V1.402 AB 17.12.00 new define DPM_MAX_NUM_DEVICES
new command DDLM_Life_List
V1.401 AB 19.10.00 New Message command MPI_Read_Write_DB and
disconnect
V1.400 AB 22.11.99 Extention of struct DPM_PLC_PARAMETER.(Identnumber)
V1.304 AB 27.06.99 Definition of FDL_Send_Data_Reply Service
V1.303 AB 16.06.99 Extention of FDL-error table. CON_AD, CON_NP
included
V1.302 AB 30.04.99 change the order of bAlarm_Mode and bAdd_Sl_Flag
in the structure DPM_SL_PRM_HEADER in accordance
to the DPV1-specification
V1.301 AB 23.02.99 Extention of the DPM_SL_PRM_PRM_DATA structure
for DPV1 usage
Extention of DPM_BUS_DP structure
new parameter bRedundancy and bSlStateMethod
in structure DPM_PLC_PARAMETER
new DPV1 message command definitions
V1.300 AB 22.01.99 Changing nomenclatura of service definitions
from DPM_... to DDLM_...
Insert new service DDLM_Upload
inser new command DDLM_Get_Cfg
V1.202 AB 02.04.98 correction of the definition
of CLEAR_DATA,SYNC...
bTout inserted in global statusfield
V1.201 AB 16.03.98 WatchDogTime extention in warmstart parameter
V1.200 AB 09.11.97 extended errors; extended diagnostic structure
V1.102 AB 09.09.97 extended errors; extended diagnostic structure
V1.101 AB 04.12.96 new #defines included
V1.100 AB 29.11.96 revision of all structures
V1.000 Mayer 29.05.96 changed
V1.000 AB 10.05.96 created
******************************************************************** <En> */
#ifndef __DPM_USER_H
#define __DPM_USER_H
#if _MSC_VER >= 1000
#pragma once
#endif /* _MSC_VER >= 1000 */
/* support for GNU compiler */
#ifdef __GNUC__
#define GNUC_PACKED __attribute__((__packed__))
#else
#define GNUC_PACKED
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined( _MSC_VER) /* Microsoft C */
#pragma pack(1) /* Byte Alignment */
#endif
/* ------------------------------------------------------------------------------------ */
/* process image transfer mode definitions */
/* ------------------------------------------------------------------------------------ */
#define DPM_GET_MODE_MASK 0xf0
#define DPM_GET_MODE_NOT_SUPPORTED 0x00
#define DPM_GET_MODE_BUSSYNC_DEVICE_CONTROLLED 0x10
#define DPM_GET_MODE_BUFFERED_DEVICE_CONTROLLED 0x20
#define DPM_GET_MODE_UNCONTROLLED 0x30
#define DPM_GET_MODE_BUFFERED_HOST_CONTROLLED 0x40
#define DPM_GET_MODE_BUSSYNC_HOST_CONTROLLED 0x50
/* ======================================================================== */
/* Protocol parameter structure */
/* ======================================================================== */
/* --------------------------- */
/* device warm start parameter */
/* --------------------------- */
typedef struct DPM_PLC_PARAMETERtag {
unsigned char bMode; /* handshake of process data */
#define DPM_SET_MODE_BUSSYNC_DEVICE_CONTROLLED 0
#define DPM_SET_MODE_BUFFERED_DEVICE_CONTROLLED 1
#define DPM_SET_MODE_UNCONTROLLED 2
#define DPM_SET_MODE_BUFFERED_HOST_CONTROLLED 3
#define DPM_SET_MODE_BUSSYNC_HOST_CONTROLLED 4
unsigned char bCycleTime; /* replace the min_slave_intervall */
unsigned char bFormat; /* storage format of word data */
#define DPM_FORMAT_NO_SWAP 0
#define DPM_FORMAT_SWAP 1
unsigned short usWatchDogTime; /* watchdog time in msec. for HOST-supervision */
unsigned char bRedundancy; /* enables or disables the redundancy logic */
unsigned char bSlStateMethod; /* defines the update method od Sl_State field */
#define DPM_SL_STATE_NOT_SYCHRONOUS 0
#define DPM_SL_STATE_SYCHRONOUS 1
struct
{
unsigned char biIdentNumberActive : 1;
unsigned char biHighPriorHandshake : 1;
unsigned char biReserved : 6;
} GNUC_PACKED bEnableBits;
unsigned short usIdentNumber;
unsigned char abReserved[6];
} GNUC_PACKED DPM_PLC_PARAMETER;
/* -------------------------------- */
/* structures to set slave data set */
/* -------------------------------- */
#define DPM_MAX_NUM_DEVICES 126
/* parameter data header structure of a slave station,
described in norm EN 50170 page 101 */
typedef struct DPM_SL_PRM_HEADERtag {
unsigned short usSlaveParaLen; /* length of whole parameter data set */
struct
{
unsigned char biReserved1 : 1;
unsigned char biExtra_Alarm_SAP : 1;
unsigned char biDPV1_Data_Types : 1;
unsigned char biDPV1_Supported : 1;
unsigned char biPublisher_Enable : 1;
unsigned char biFail_Safe : 1;
unsigned char biNew_Prm : 1;
unsigned char biActive : 1;
} GNUC_PACKED Sl_Flag; /* slave related flags */
unsigned char bSlave_Typ; /* type of slave */
unsigned char bMax_Diag_Data_Len;
unsigned char bMax_Alarm_Len;
unsigned char bMax_Channel_Data_Length;
unsigned char bDiag_Upd_Delay;
unsigned char bAlarm_Mode;
struct
{
unsigned char biNA_to_Abort : 1;
unsigned char biIgnore_Aclr : 1;
unsigned char abiReserved : 6;
} GNUC_PACKED bAdd_Sl_Flag;
unsigned char abOctet_String[6];
} GNUC_PACKED DPM_SL_PRM_HEADER;
/* parameter data 'Prm_Data' structure of a slave station,
described in norm EN 50170 page 51 */
#define MAX_USR_PRM_LEN 237
typedef struct DPV0_PRMtag {
unsigned char abUsr_Prm_Data[MAX_USR_PRM_LEN]; /* user parameter data without DPV1-bytes */
} GNUC_PACKED DPV0_PRM;
typedef struct DPV1_USR_PRMtag {
struct
{
unsigned char bReserved1 : 2;
unsigned char bWD_Base_1ms : 1;
unsigned char bReserved2 : 2;
unsigned char bPublisher_Enable : 1;
unsigned char bFail_Safe : 1;
unsigned char bDPV1_Enable : 1;
} GNUC_PACKED DPV1_Status_1;
struct
{
unsigned char bRun_On_Cfg_Fault : 1;
unsigned char bReserved1 : 1;
unsigned char bEnable_Update_Alarm : 1;
unsigned char bEnable_Status_Alarm : 1;
unsigned char bEnable_Manufacture_Alarm : 1;
unsigned char bEnable_Diagnostic_Alarm : 1;
unsigned char bEnable_Process_Alarm : 1;
unsigned char bEnable_Pull_plug_Alarm : 1;
} GNUC_PACKED DPV1_Status_2;
struct
{
unsigned char bAlarm_Mode : 3;
unsigned char bIsoM_Req : 1;
unsigned char bReserved1 : 4;
} GNUC_PACKED DPV1_Status_3;
} GNUC_PACKED DPV1_USR_PRM;
typedef struct DPV1_PRMtag {
DPV1_USR_PRM tDpv1;
unsigned char abUsr_Prm_Data[MAX_USR_PRM_LEN-sizeof(DPV1_USR_PRM)];
} GNUC_PACKED DPV1_PRM;
typedef struct DPV2_HEADERtag {
unsigned char bStructure_Length;
unsigned char bStructure_Type;
unsigned char bSlot_Number;
unsigned char bReserved;
} GNUC_PACKED DPV2_HEADER;
typedef struct DPV2_ISOM_PRMtag {
DPV2_HEADER tDpv2Header;
unsigned char bVersion;
unsigned long bTBase_Dp;
unsigned short bTDp;
unsigned char bTMapc;
unsigned long bTBase_Io;
unsigned short bTI;
unsigned short bTO;
unsigned long bTDx;
unsigned short bTPll_W;
unsigned short bTPll_D;
} GNUC_PACKED DPV2_ISOM_PRM;
typedef struct DPV2_DBX_LINK_FILTERtag {
unsigned char bPublisher_Addr;
unsigned char bPublisher_Length;
unsigned char bSample_Offset;
unsigned char bSample_Length;
} GNUC_PACKED DPV2_DBX_LINK_FILTER;
typedef struct DPV2_DBX_LINKtag {
DPV2_HEADER tDpv2Header;
unsigned char bVersion;
DPV2_DBX_LINK_FILTER tDbxLinkFilter;
} GNUC_PACKED DPV2_DBX_LINK;
typedef struct DPV2_PRMtag {
DPV1_USR_PRM tDpv1;
DPV2_ISOM_PRM tDpv2Iso;
unsigned char abUsr_Prm_Data[MAX_USR_PRM_LEN-
sizeof(DPV1_USR_PRM)-
sizeof(DPV2_ISOM_PRM)];
} GNUC_PACKED DPV2_PRM;
typedef struct DPM_SL_PRM_PRM_DATAtag {
unsigned short usPrmDataLen; /* length of PRM_PRM_DATA */
struct
{
unsigned char bReserved : 3;
unsigned char bWD_On : 1;
unsigned char bFreeze_Req : 1;
unsigned char bSync_Req : 1;
unsigned char bUnLock_Req : 1;
unsigned char bLock_Req : 1;
} GNUC_PACKED Station_Status; /* status of supported functions */
unsigned char bWD_Fact_1; /* watchdog factor 1 */
unsigned char bWD_Fact_2; /* watchdog factor 2 */
unsigned char bMin_Tsdr; /* min. station delay reponder */
unsigned short usIdent_Number; /* ident number of the station, motorola format */
unsigned char bGroup_Ident; /* configures group number */
union
{
DPV0_PRM tDpv0; /* standard parameter , or */
DPV1_PRM tDpv1Only; /* parameter data with DPV1 */
DPV2_PRM tDpv1Dpv2; /* parameter data with DPV1,DPV2 */
} GNUC_PACKED u;
} GNUC_PACKED DPM_SL_PRM_PRM_DATA;
/* configuration data 'Cfg_Data' structure of a slave station,
described in norm EN 50170 page 55 */
#define MAX_CFG_DATA_LEN 244
typedef struct DPM_SL_PRM_CFG_DATAtag {
unsigned short usCfg_Data_Len; /* length of CFG_DATA */
unsigned char abCfg_Data[MAX_CFG_DATA_LEN]; /* configuration data of the
slave station */
} GNUC_PACKED DPM_SL_PRM_CFG_DATA;
/* i/o offset table 'Add_Tab' structure of a slave station,
described in norm EN 50170 page 103 */
#define MAX_EA_OFFSET_LEN 244
typedef struct DPM_SL_PRM_ADD_TABtag {
unsigned short usAdd_Tab_Len; /* length of ADD_TAB */
unsigned char bInput_Count; /* counter of following input offsets */
unsigned char bOutput_Count; /* counter of following ouput offsets */
#define EA_OFFSET_BYTE 0x8000
unsigned short ausEA_Offset[MAX_EA_OFFSET_LEN]; /* user defined offsets */
} GNUC_PACKED DPM_SL_PRM_ADD_TAB;
/* extented data 'Slave_User_Data' structure of a slave station,
described in norm EN 50170 page 103 */
#define MAX_SL_PRM_LEN 100
typedef struct DPM_SL_PRM_USR_DATAtag {
unsigned short usSlave_Usr_Data_Len; /* length of USR_DATA */
unsigned char abSlave_Usr_Data[MAX_SL_PRM_LEN]; /* user paramteres */
} GNUC_PACKED DPM_SL_PRM_USR_DATA;
/* --------------------------------- */
/* structure to set master parameter */
/* --------------------------------- */
/* master parameter 'DPM_Bus_Dp' data set
described in norm DIN 19245-T3 page 98 */
typedef struct DPM_BUS_DPtag {
unsigned short usBus_Para_Len; /* length of BUS_DP */
unsigned char bFDL_Add; /* master address */
unsigned char bBaudrate; /* baudrate, see. #defines */
#define DP_BAUD_96 0
#define DP_BAUD_19_2 1
#define DP_BAUD_93_75 2
#define DP_BAUD_187_5 3
#define DP_BAUD_500 4
#define DP_BAUD_1500 6
#define DP_BAUD_3000 7
#define DP_BAUD_6000 8
#define DP_BAUD_12000 9
#define DP_BAUD_31_25 10
#define DP_BAUD_45_45 11
unsigned short usTSL; /* slot-time */
unsigned short usMin_TSDR; /* min. station delay responder */
unsigned short usMax_TSDR; /* max. station delay responder */
unsigned char bTQUI; /* quite time */
unsigned char bTSET; /* setup time */
unsigned long ulTTR; /* target rotation time */
unsigned char bG; /* gap update */
unsigned char bHSA; /* highest active station address */
unsigned char bMax_Retry_Limit; /* retries if error occurs */
struct
{
unsigned char bReserved : 7;
unsigned char bError_Action_Flag : 1;
} GNUC_PACKED Bp_Flag; /* auto_clear on/off */
unsigned short usMin_Slave_Intervall; /* min. slave intervall time */
unsigned short usPoll_Timeout; /* poll timeout */
unsigned short usData_Control_Time; /* data control time */
unsigned char bAlarm_Max; /* maximum alarms the master supports = 32 */
unsigned char bMax_User_Global_Control; /* maximum parallel Global-
Controls the master supports = 1*/
unsigned char abOctet[4];
} GNUC_PACKED DPM_BUS_DP;
/* ======================================================================== */
/* Protocol slave specific single diagnostic structure */
/* ======================================================================== */
#define MAX_EXT_DIAG_LEN 100
/* slave specific diagnostic structure
described in norm DIN 19245-T3 page 41 */
typedef struct DPM_SLAVE_SINGLE_DIAGNOTICStag {
struct
{
unsigned char bStation_Non_Existent : 1; /* no response */
unsigned char bStation_Not_Ready : 1; /* station not ready */
unsigned char bCfg_Fault : 1; /* configuration fault */
unsigned char bExt_Diag : 1; /* extended diagnostic */
unsigned char bNot_Supported : 1; /* sync, freeze not supported */
unsigned char bInvalid_Response : 1; /* response faulty */
unsigned char bPrm_Fault : 1; /* parameters faulty */
unsigned char bMaster_Lock : 1; /* locked by a master */
} GNUC_PACKED Stationstatus_1;
struct
{
unsigned char bPrm_Req : 1; /* request new parameters */
unsigned char bStat_Diag : 1; /* static diagnostic */
unsigned char bTrue : 1; /* set to 1 by a slave */
unsigned char bWd_On : 1; /* watchdog function on/off */
unsigned char bFreeze_Mode : 1; /* freeze mode active */
unsigned char bSync_Mode : 1; /* sync mode active */
unsigned char bReserved : 1; /* reserved */
unsigned char bDeactivated : 1; /* slave deactivated */
} GNUC_PACKED Stationstatus_2;
struct
{
unsigned char bReserved : 7;
unsigned char bExt_Diag_Overflow : 1; /* ext. diagnostic overflow */
} GNUC_PACKED Stationstatus_3;
unsigned char bMaster_Add; /* corresponding master address */
unsigned short usIdent_Number; /* ident number, motorola format */
unsigned char abExt_Diag_Data[MAX_EXT_DIAG_LEN];
/* extended diagnostic field */
} GNUC_PACKED DPM_SLAVE_SINGLE_DIAGNOSTICS;
/* ======================================================================== */
/* Protocol master state structure */
/* ======================================================================== */
typedef struct DPM_DIAGNOSTICStag {
/* unsigned char field to show bus and master main errors */
struct
{
unsigned char bCtrl : 1; /* wrong parameterization */
unsigned char bAClr : 1; /* auto_clear activated */
unsigned char bNonExch : 1; /* no data exchange to at least on station */
unsigned char bFatal : 1; /* fatal error occured */
unsigned char bEvent : 1; /* bus error events occured */
unsigned char bNRdy : 1; /* host program not ready */
unsigned char bTout : 1; /* PROFIBUS timeout event detected */
unsigned char bReserved : 1;
} GNUC_PACKED bGlobalBits;
/* global state for the different master main states */
unsigned char bDPM_state;
#define OFFLINE 0x00
#define STOP 0x40
#define CLEAR 0x80
#define OPERATE 0xC0
/* location of error and error code */
struct
{
unsigned char bErr_Rem_Adr; /* 0-125, 255 */
#define MST_ERR 0xFF
unsigned char bErr_Event; /* see #defines */
#define TASK_F_NO_USR_TASK 50 /* usr task not found */
#define TASK_F_NO_GLOBAL_DATA 51 /* no global entry in data base */
#define TASK_F_NO_FDL 52 /* fdl task not found */
#define TASK_F_NO_PLC 53 /* plc task not found */
#define TASK_F_NO_BUS_DP 54 /* no bus parameters */
#define TASK_F_INVALID_BUS_DP 55 /* bus parameters faulty */
#define TASK_F_NO_SL_TAB 56 /* no slave data sets */
#define TASK_F_INVALID_SL_TAB 57 /* slave data set faulty */
#define TASK_F_REM_ADR_DOUBLE 58 /* double station adress detected */
#define TASK_F_A_OFFSET_MAX 59 /* maximum output offset reached */
#define TASK_F_E_OFFSET_MAX 60 /* maximum input offset reached */
#define TASK_F_A_OVERLAP 61 /* overlap in output area */
#define TASK_F_E_OVERLAP 62 /* overlap in input area */
#define TASK_F_DPM_UNKNOWN_MODE 63 /* warm start with unknown mode */
#define TASK_F_RAM_OVERRUN 64 /* extended ram exeeded */
#define TASK_F_SL_PRM_FAULT 65 /* slave data set faulty */
#define TASK_F_WATCHDOG 220 /* user watchdog failure */
#define TASK_F_NO_DATA_ACK 221 /* mode0 no acknowledge */
#define TASK_F_AUTO_CLEAR 222 /* auto clear activated */
#define TASK_F_FATAL_ASIC_ERROR 223 /* fatal error occured */
#define TASK_F_UNKNOWN_EVENT 224 /* unknown event detected */
#define TASK_F_SEGMENT_CNT 225 /* no segments to communicate */
#define CON_NA 0x11 /* no reaction of the remote station */
#define CON_DS 0x12 /* cocal-FDL/PHY not in logical token ring */
#define CON_RS 0x03 /* master request not supported by the slave */
#define CON_NR 0x09 /* no response data */
#define CON_DS 0x12 /* local FDL not in logical token ring */
} GNUC_PACKED tError;
/* counter for the bus error events */
unsigned short usBus_Error_Cnt;
/* Zhler fr die BusTimeouts */
unsigned short usTime_Out_Cnt;
/* reserved area */
unsigned char abReserved[8];
/* Bit-Ready, Cfg-Ready and diagnostic display of slave devices */
unsigned char abSl_cfg [16]; /* Slave configuration area */
unsigned char abSl_state[16]; /* Slave state information area */
unsigned char abSl_diag [16]; /* Slave diagnostic area */
} GNUC_PACKED DPM_DIAGNOSTICS;
/* ======================================================================== */
/* Master Class2 definitions */
/* ======================================================================== */
#define UNDEFINED 1
typedef struct
{
unsigned char abNetwork_Address[6]; /* network address according ISO/OSI */
unsigned char abMAC_Address[UNDEFINED];/* MAC_Address */
} GNUC_PACKED ADDR_EXTENTION;
typedef struct
{
unsigned char bAPI; /* application process instance */
unsigned char bSCL; /* access level */
} GNUC_PACKED ADDR;
#define MAX_ADD_TABLE_LEN 235
typedef struct
{
#define TYPE_EXT_OFF 0 /* no optional Network/MAC address */
#define TYPE_EXT_ON 1 /* optional Network/MAC address available */
unsigned char bS_Type;
unsigned char bS_Len; /* length of S_Addr subparameter */
unsigned char bD_Type;
unsigned char bD_Len; /* length of D_Addr subparameter */
unsigned char abAddParam[ MAX_ADD_TABLE_LEN ];
} GNUC_PACKED ADD_ADDR_PARAM;
typedef struct
{
unsigned short usSend_Timeout; /* control time for supervision */
struct
{
unsigned char biDPV1_RW : 1; /* support of MSAC2_READ and WRITE */
unsigned char abiReserved : 7;
} GNUC_PACKED bFeatures_Supported_1;
struct
{
unsigned char abiReserved : 8;
} GNUC_PACKED bFeatures_Supported_2;
unsigned char bProfile_Features_Supported_1;
unsigned char bProfile_Features_Supported_2;
unsigned short usProfile_Ident_Number; /* 0 to 65535 */
#define NO_PROFILE 0
ADD_ADDR_PARAM tAdd_Addr_Param;
} GNUC_PACKED DPM_MSAC2M_INITIATE_REQ;
typedef struct
{
struct
{
unsigned char biDPV1_RW : 1; /* support of MSAC2_READ and WRITE */
unsigned char abiReserved : 7;
} GNUC_PACKED bFeatures_Supported_1;
struct
{
unsigned char abiReserved : 8;
} GNUC_PACKED bFeatures_Supported_2;
unsigned char bProfile_Features_Supported_1;
unsigned char bProfile_Features_Supported_2;
unsigned short usProfile_Ident_Number; /* 0 to 65535 */
#define NO_PROFILE 0
ADD_ADDR_PARAM tAdd_Addr_Param;
} GNUC_PACKED DPM_MSAC2M_INITIATE_CON;
/* ======================================================================== */
/* Protocol definition */
/* ======================================================================== */
/* DPV1 Class1 primitives */
#define MSAC1M_Read_Write 0x11
#define MSAL1M_Alarm 0x12
#define MSAC1M_Abort 0x1f
/* DPV1 Class2 primitives */
#define MSAC2M_Initiate 0x20
#define MSAC2M_Read_Write_Data 0x21
#define MSAC2M_Fault 0x2d
#define MSAC2M_Close 0x2e
#define MSAC2M_Abort 0x2f
/* MPI primitives */
#define MPI_Read_Write_DB 0x31
#define MPI_Get_OP_Status 0x32
#define MPI_Read_Write_M 0x33
#define MPI_Read_Write_IO 0x34
#define MPI_Read_Write_Cnt 0x35
#define MPI_Read_Write_Tim 0x36
#define MPI_Disconnect 0x3f
#define DPM_MAX_LEN_DATA_UNIT 240
/* ------------------------------- */
/* message: shared_memory */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DPM_Shared_Memory 0x11
/* ------------------------------- */
/* message: slave_diag */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Slave_Diag 0x42
typedef struct DDLM_SLAVE_DIAG_CONFIRMtag {
DPM_SLAVE_SINGLE_DIAGNOSTICS tDiagData;
} GNUC_PACKED DDLM_SLAVE_DIAG_CONFIRM;
/* ------------------------------- */
/* message: set_prm */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Set_Prm 0x4a
typedef struct DDLM_SET_PRM_REQUESTtag {
unsigned char bRem_Add;
unsigned char abUsr_Prm_Data[DPM_MAX_LEN_DATA_UNIT];
} GNUC_PACKED DDLM_SET_PRM_REQUEST;
typedef struct DDLM_SET_PRM_CONFIRMtag {
unsigned char bRem_Add;
} GNUC_PACKED DDLM_SET_PRM_CONFIRM;
/* ------------------------------- */
/* message: get_cfg */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Get_Cfg 0xe8
/* ------------------------------- */
/* message: start_seq */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Start_Seq 0x43
typedef struct DDLM_START_SEQ_REQUESTtag {
unsigned char bReq_Add; /* 0 */
unsigned char bArea_Code; /* 0 - 125 */
unsigned short usTimeout; /* 0 - 65535 */
} GNUC_PACKED DDLM_START_SEQ_REQUEST;
typedef struct DDLM_START_SEQ_CONFIRMtag {
unsigned char bMax_Len_Data_Unit; /* 240 */
} GNUC_PACKED DDLM_START_SEQ_CONFIRM;
/* ------------------------------- */
/* message: download */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Download 0x44
#define DPM_DEVICE_PRM 127
/* message data structure */
typedef struct DDLM_DOWNLOAD_REQUESTtag {
unsigned char bReq_Add; /* 0 */
unsigned char bArea_Code; /* 0 - 125, 127 */
unsigned short usAdd_Offset; /* 0 - 760 */
unsigned char abData[DPM_MAX_LEN_DATA_UNIT];
} GNUC_PACKED DDLM_DOWNLOAD_REQUEST;
/* ------------------------------- */
/* message: upload */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Upload 0x50
/* message data structure */
typedef struct DDLM_UPLOAD_REQUESTtag {
unsigned char bReq_Add; /* 0 */
unsigned char bArea_Code; /* 0 - 125, 127 */
unsigned short usAdd_Offset; /* 0 - 760 */
unsigned char bData_Len; /* 1-240 */
} GNUC_PACKED DDLM_UPLOAD_REQUEST;
/* ------------------------------- */
/* message: end_sequence */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_End_Seq 0x45
/* message data structure */
typedef struct DDLM_END_SEQ_REQUESTtag {
unsigned char bReq_Add; /* 0 */
} GNUC_PACKED DDLM_END_SEQ_REQUEST;
/* ------------------------------- */
/* message: global_control */
/* ------------------------------- */
/* message command msg.b msg.a */
#define DDLM_Global_Control 0x46
/* message data structure */
typedef struct DDLM_GLOBAL_CONTROL_REQUESTtag {
unsigned char bRem_Add; /* 0 - 127 */
unsigned char bControl_Command;
#define CLEAR_DATA 0x02
#define UNFREEZE 0x04
#define FREEZE 0x08
#define UNSYNC 0x10
#define SYNC 0x20 /* unsigned chars can be combined with an 'or' command */
unsigned char bGroup_Select;
} GNUC_PACKED DDLM_GLOBAL_CONTROL_REQUEST;
typedef struct DDLM_GLOBAL_CONTROL_CONFIRMtag {
unsigned char bRem_Add; /* 0 - 127 */
} GNUC_PACKED DDLM_GLOBAL_CONTROL_CONFIRM;
/* ------------------------------- */
/* message: life_list */
/* ------------------------------- */
#define DDLM_Life_List 0x96
/* ------------------------------- */
/* message: Read_Input */
/* ------------------------------- */
#define DDLM_RD_Input 0xE9
/* ------------------------------- */
/* message: Read_Output */
/* ------------------------------- */
#define DDLM_RD_Output 0xEA
/* ------------------------------- */
/* message: Set-Slaveadress */
/* ------------------------------- */
#define DDLM_Set_Slave_Add 0xEB
/* --------------------------------- */
/* message: FDL_Send_Data_Ack */
/* --------------------------------- */
#define FDL_Send_Data_Ack_Req 0x80
#define FDL_Send_Data_Ack_Con 0x80
#define FDL_Send_Data_Ack_Ind 0xC0
#define FDL_Send_Data_No_Ack_Ind 0xC1
#define DATA_STU_SIZE 244
typedef struct octet_strtag {
unsigned char bLen; /* length of data field 0 to 244 */
unsigned char bValue[ DATA_STU_SIZE ]; /* data field */
} GNUC_PACKED octet_str;
typedef struct FDL_DATA_ACK_REQ_STUtag {
unsigned char bSsap; /* Src.Serv.Acc.Point0-62,255 */
unsigned char bDsap; /* Dest.Serv.Acc.Point0-63,255 */
unsigned char bRem_add_da; /* Remote Address 0-126 */
unsigned char bServ_class; /* Prio Low=0,high=1*/
octet_str tL_sdu; /* data field structure */
} GNUC_PACKED FDL_DATA_ACK_REQ_STU;
typedef struct FDL_DATA_ACK_IND_STUtag {
unsigned char bDsap; /* Dest.Serv.Acc.Point0-63,255 */
unsigned char bSsap; /* Src.Serv.Acc.Point0-62,255 */
unsigned char bRem_add_da; /* Remote Address 0-126 */
unsigned char bLoc_add_da; /* local Address in PROFIBUS 0 to 127 */
unsigned char bServ_class; /* Prio Low=0,high=1*/
octet_str tL_sdu; /* data field structure */
} GNUC_PACKED FDL_DATA_ACK_IND_STU;
/* --------------------------------- */
/* message: */
/* --------------------------------- */
#define FDL_Send_Data_No_Ack_Req 0x81
#define FDL_Send_Data_No_Ack_Con 0x81
/* --------------------------------- */
/* message: FDL_Send_Data_With_Reply */
/* --------------------------------- */
#define FDL_Send_Data_Reply_Req 0x82
#define FDL_Send_Data_Reply_Con 0x82
#define FDL_Send_Data_Reply_Ind 0xC2
typedef struct FDL_DATA_REPLY_REQ_STUtag {
unsigned char bSsap; /* Source Service Access Point 0 to 126 */
unsigned char bDsap; /* Destination Service Access Point 0 to 127 */
unsigned char bRem_add_da;/* Remote Address in PROFIBUS 0 to 127 */
unsigned char bServ_class;/* Priority of service = 0 Low */
octet_str tL_sdu; /* data field structure */
} GNUC_PACKED FDL_DATA_REPLY_REQ_STU;
typedef struct FDL_DATA_REPLY_CON_STUtag {
unsigned char bSsap; /* Source Service Access Point 0 to 126 */
unsigned char bDsap; /* Destination Service Access Point 0 to 127 */
unsigned char bRem_add_da;/* Remote Address in PROFIBUS 0 to 127 */
unsigned char bServ_class;/* Priority of service = 0 Low */
unsigned char bL_status; /* Error code */
octet_str tL_sdu; /* data field structure */
} GNUC_PACKED FDL_DATA_REPLY_CON_STU;
typedef struct FDL_DATA_REPLY_IND_STUtag {
unsigned char bDsap; /* Destination Service Access Point 0 to 127 */
unsigned char bSsap; /* Source Service Access Point 0 to 126 */
unsigned char bRem_add_da; /* Remote Address in PROFIBUS 0 to 127 */
unsigned char bLoc_add_da; /* local Address in PROFIBUS 0 to 127 */
unsigned char bServ_class; /* Priority of service = 0 Low */
unsigned char bUpdate_status; /* reply data sent, or not */
octet_str tL_sdu; /* data field structure */
} GNUC_PACKED FDL_DATA_REPLY_IND_STU;
/* definition for bUpdate_status */
#define CON_LO 0x20 /* low priority data transmitted in response */
#define CON_HI 0x21 /* high priority data transmitted in response */
#define CON_NO_DATA 0x22 /* no data transmitted in response */
/* --------------------------------- */
/* message: FDL_Reply_Update */
/* --------------------------------- */
#define FDL_Reply_Update_Req 0x83
typedef struct FDL_REPLY_UPDATE_REQ_STUtag {
unsigned char bSsap; /* Src.Serv.Acc.Point 0-62 */
unsigned char bDsap; /* not used */
unsigned char bRem_add_da; /* not used */
unsigned char bServ_class; /* Prio Low=0,high=1*/
unsigned char bTransmit; /* Single=1/Multiple=2*/
octet_str tL_sdu; /* data field structure */
} GNUC_PACKED FDL_REPLY_UPDATE_REQ_STU;
typedef struct FDL_REPLY_UPDATE_CON_STUtag {
unsigned char bSsap; /* Src.Serv.Acc.Point 0-62 */
unsigned char bDsap; /* Dest.Serv.Acc.Point 0-63 */
unsigned char bRem_add_da; /* Remote Address 0-126 */
unsigned char bServ_class; /* Prio Low=0,high=1*/
unsigned char bL_status; /* error code */
} GNUC_PACKED FDL_REPLY_UPDATE_CON_STU;
/* --------------------------------- */
/* message: FDL_Activate_SSap */
/* --------------------------------- */
#define FDL_SSap_Activate_req 0x97
#define FDL_SSap_Activate_con 0x97
typedef struct FDL_SAP_ACTIVATE_REQ_STUtag {
unsigned char bSsap; /* Source Service Access Point 0-63,65 */
unsigned char bAccess; /* Accessright = 255 */
unsigned char bService_list_length; /* Length of followed list = 4 */
#define SERVICE_SDA 0
#define SERVICE_SDN 1
#define SERVICE_SRD 2
unsigned char abService_activate[4]; /* Service that shall be activated*/
#define ROLE_IN_BOTH 1 /* Role_IN-Service Both */
#define ROLE_IN_RESPONDER 2
#define ROLE_IN_INITIATOR 3
unsigned char abRole_in_service [4]; /* Configuration for the service */
struct {
unsigned char bReq_low; /* Maximum length of buffer = 240 */
unsigned char bReq_high; /* Maximum length of buffer = 240 */
unsigned char bInd_low; /* Maximum length of buffer = 240 */
unsigned char bInd_high; /* Maximum length of buffer = 240 */
} GNUC_PACKED tNon_cyclic_L_sdu_length_list[3];
} GNUC_PACKED FDL_SAP_ACTIVATE_REQ_STU;
typedef struct FDL_SAP_ACTIVATE_CON_STUtag {
unsigned char bSsap; /* Src. Service Access Pnt */
unsigned char bM_status;
} GNUC_PACKED FDL_SAP_ACTIVATE_CON_STU;
/* --------------------------------- */
/* message: FDL_Activate_RSap */
/* --------------------------------- */
#define FDL_RSap_Activate_Req 0x98
#define FDL_RSap_Activate_Con 0x98
typedef struct FDL_RSAP_ACTIVATE_REQ_STUtag {
unsigned char bSsap; /* Source Service Access Point 0-63,65 */
unsigned char bAccess; /* Accessright = 255 */
unsigned char bIndication_mode;
unsigned char bReq_low; /* Maximum length of buffer = 240 */
unsigned char bReq_high; /* Maximum length of buffer = 240 */
unsigned char bInd_low; /* Maximum length of buffer = 240 */
unsigned char bInd_high; /* Maximum length of buffer = 240 */
} GNUC_PACKED FDL_RSAP_ACTIVATE_REQ_STU;
typedef struct FDL_RSAP_ACTIVATE_CON_STUtag {
unsigned char bSsap; /* Src. Service Access Pnt */
unsigned char bM_status;
} GNUC_PACKED FDL_RSAP_ACTIVATE_CON_STU;
/* --------------------------------- */
/* message: FDL_Deactivate_Sap */
/* --------------------------------- */
#define FDL_Sap_Deactivate_Req 0x9A
#define FDL_Sap_Deactivate_Con 0x9A
typedef struct
{
unsigned char bSsap; /* Source Serv. Access Pnt 0-63,255 */
} GNUC_PACKED FDL_SAP_DEACTIVATE_REQ_STU;
typedef struct
{
unsigned char bSsap; /* Src. Service Access Pnt 0-63,255 */
unsigned char bM_status;
} GNUC_PACKED FDL_SAP_DEACTIVATE_CON_STU;
/* ======================================================================== */
/* message error numbers */
/* ======================================================================== */
#define CON_OK 0x00 /* no error */
#define CON_RS 0x03 /* Profibus-DP service not accessible */
#define CON_NO 0x13 /* no access in current master mode */
#define CON_IV 0x15 /* parameter fault in request */
#define CON_NP 0x19 /* no plausible reaction from remote station*/
#define CON_TO 0x30 /* function timeout */
#define CON_NI 0x34 /* function not available on responder */
#define CON_EA 0x35 /* area overflow */
#define CON_AD 0x36 /* access denied */
#define CON_IP 0x37 /* parameter error */
#define CON_SE 0x39 /* sequence fault */
#define CON_NE 0x3A /* requested data not available */
#define CON_DI 0x3B /* data fault or not complete */
#if defined( _MSC_VER) /* Microsoft C */
#pragma pack() /* Byte Alignment */
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/* === eof 'DPM_USER.H' === */
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
========================================================================
FILENAME : RCS_USER.H
-------------------------------------------------------------------------
CREATED BY : R.Mayer, Hilscher GmbH
CREATED AT : 10.05.96
PROJECT : global
=========================================================================
FUNCTION :
General RCS definitions
=========================================================================
CHANGES OF REVISIONS :
Version Name Date Change
-------------------------------------------------------------------------
V1.002 Mayer 14.05.98 RCS_TELEGRAMHEADERDATA_10 structure included
V1.001 Mayer 29.05.96 Task errors included
V1.000 Mayer 10.05.96 created from the file rc090203.h
******************************************************************** <En> */
#ifdef __cplusplus
}
#endif
#if defined( _MSC_VER) /* Microsoft C */
#pragma pack(1) /* Byte Alignment */
#endif
/* ======================================================================== */
/* General task errors */
/* ======================================================================== */
#define TASK_F_OK 0
#define TASK_F_NO_COMMUNICATION 1
#define TASK_F_IDLE 2
#define TASK_F_INIT_BASE 50
#define TASK_F_PARITY 100
#define TASK_F_FRAMING 101
#define TASK_F_OVERRUN 102
#define TASK_F_DATACOUNT 103
#define TASK_F_CHECKSUM 104
#define TASK_F_TIMEOUT 105
#define TASK_F_PROTOCOL 106
#define TASK_F_DATA 107
#define TASK_F_NACK 108
#define TASK_F_PROTOCOL_BASE 110
#define TASK_F_MESSAGEHEADER 150
#define TASK_F_MESSAGESIZE 151
#define TASK_F_MESSAGECOMMAND 152
#define TASK_F_MESSAGESTRUCTURE 153
#define TASK_F_MESSAGEERROR 154
#define TASK_F_MESSAGETIMEOUT 155
#define TASK_F_TELEGRAMHEADER 160
#define TASK_F_DEVICE_ADR 161
#define TASK_F_DATA_AREA 162
#define TASK_F_DATA_ADR 163
#define TASK_F_DATA_IDX 164
#define TASK_F_DATA_CNT 165
#define TASK_F_DATA_TYPE 166
#define TASK_F_FUNCTION 167
#define TASK_F_MESSAGE_BASE 170
#define TASK_F_NOT_INITIALIZED 200
#define TASK_F_BUSY 201
#define TASK_F_SEGMENT 202
#define TASK_F_USER 203
#define TASK_F_DATABASE 210
#define TASK_F_DATABASE_WRITE 211
#define TASK_F_DATABASE_READ 212
#define TASK_F_STRUCTURE 213
#define TASK_F_PARAMETER 214
#define TASK_F_CONFIGURATION 215
#define TASK_F_FUNCTIONLIST 216
#define TASK_F_SYSTEM 217
#define TASK_F_SYSTEM_BASE 220
/* ======================================================================== */
/* Task commands */
/* ======================================================================== */
#define TASK_B_10 16 /* RCS_TELEGRAMHEADER_10 */
#define TASK_B_11 17 /* Task specific */
/* ======================================================================== */
/* Message definitions */
/* ======================================================================== */
/* ----------------- Definition of the standard telegram header ----------- */
/* Keyword: MESSAGE ---------------------------------------------------- */
/* TelegramFunCtion */
#define TASK_TFC_UNUSED 0
#define TASK_TFC_READ 1
#define TASK_TFC_WRITE 2
#define TASK_TFC_QUERRY 3
/* TelegramDataArea */
/* 'data_area' */
#define TASK_TDA_UNUSED 0
#define TASK_TDA_BIT 1
#define TASK_TDA_BYTE 2
#define TASK_TDA_WORD 3
#define TASK_TDA_DWORD 4
#define TASK_TDA_FLOAT 5
/* TelegramDataType */
/* 'data_type' for MOTOROLA data types ! */
/* For INTEL data types, the 'RCS_TDT_IDF_MASK' flag must be set */
#define TASK_TDT_UNUSED 0
#define TASK_TDT_BOOLEAN 1
#define TASK_TDT_INT8 2
#define TASK_TDT_INT16 3
#define TASK_TDT_INT32 4
#define TASK_TDT_UINT8 5
#define TASK_TDT_UINT16 6
#define TASK_TDT_UINT32 7
#define TASK_TDT_FLOAT 8
#define TASK_TDT_ASCII 9
#define TASK_TDT_STRING 10
#define TASK_TDT_BIT 14
#define TASK_TDT_IDF_MSK 0X80
/* ======================================================================== */
/* Message structure definitions */
/* ======================================================================== */
/* -------------------- General RCS definitions -------------------------- */
/* Keyword: MESSAGE ------------------------------------------------------ */
#define RCS_SEGMENT_LEN 288
#define RCS_MESSAGEHEADER_LEN 8
#define RCS_TELEGRAMHEADER_LEN 8
/* ------------------------ RCS message definition ------------------------ */
typedef struct RCS_MESSAGEHEADERtag {
unsigned char rx; /* receiver */
unsigned char tx; /* transmitter */
unsigned char ln; /* lenght */
unsigned char nr; /* number */
unsigned char a; /* answer */
unsigned char f; /* fault */
unsigned char b; /* command */
unsigned char e; /* extension */
} RCS_MESSAGEHEADER;
typedef struct RCS_MESSAGEtag {
unsigned char rx; /* receiver */
unsigned char tx; /* transmitter */
unsigned char ln; /* lenght */
unsigned char nr; /* number */
unsigned char a; /* answer */
unsigned char f; /* fault */
unsigned char b; /* command */
unsigned char e; /* extension */
unsigned char d[ RCS_SEGMENT_LEN-RCS_MESSAGEHEADER_LEN ]; /* data */
} RCS_MESSAGE;
/* ----------------- Standard telegram header ----------------------------- */
/* Keyword: MESSAGE, TASK_B_10 --------------------------------------------*/
typedef struct RCS_TELEGRAMHEADER_10tag {
unsigned char device_adr; /* device address */
unsigned char data_area; /* data area */
unsigned short data_adr; /* data address */
unsigned char data_idx; /* data index */
unsigned char data_cnt; /* data count */
unsigned char data_type; /* data type */
unsigned char function; /* function */
} RCS_TELEGRAMHEADER_10;
typedef struct RCS_MESSAGETELEGRAMHEADER_10_tag {
unsigned char rx; /* receiver */
unsigned char tx; /* transmitter */
unsigned char ln; /* lenght */
unsigned char nr; /* number */
unsigned char a; /* answer */
unsigned char f; /* fault */
unsigned char b; /* command */
unsigned char e; /* extension */
unsigned char device_adr; /* device address */
unsigned char data_area; /* data area */
unsigned short data_adr; /* data address */
unsigned char data_idx; /* data index */
unsigned char data_cnt; /* data count */
unsigned char data_type; /* data type */
unsigned char function; /* function */
} RCS_MESSAGETELEGRAMHEADER_10;
typedef struct RCS_TELEGRAMHEADERDATA_10tag {
unsigned char device_adr;
unsigned char data_area;
unsigned short data_adr;
unsigned char data_idx;
unsigned char data_cnt;
unsigned char data_type;
unsigned char function;
unsigned char d[ RCS_SEGMENT_LEN-RCS_MESSAGEHEADER_LEN-RCS_TELEGRAMHEADER_LEN];
} RCS_TELEGRAMHEADERDATA_10;
typedef struct RCS_MESSAGETELEGRAM_10tag {
unsigned char rx; /* receiver */
unsigned char tx; /* transmitter */
unsigned char ln; /* lenght */
unsigned char nr; /* number */
unsigned char a; /* answer */
unsigned char f; /* fault */
unsigned char b; /* command */
unsigned char e; /* extension */
unsigned char device_adr; /* device address */
unsigned char data_area; /* data area */
unsigned short data_adr; /* data address */
unsigned char data_idx; /* data index */
unsigned char data_cnt; /* data count */
unsigned char data_type; /* data type */
unsigned char function; /* function */
unsigned char d[ RCS_SEGMENT_LEN-RCS_MESSAGEHEADER_LEN-RCS_TELEGRAMHEADER_LEN];
} RCS_MESSAGETELEGRAM_10;
#if defined( _MSC_VER) /* Microsoft C */
#pragma pack() /* Byte Alignment */
#endif
#ifdef __cplusplus
}
#endif
/* === eof 'RCS_USER.H' === */
/* <St> *******************************************************************
======================== Copyright =====================================
Copyright (C) 2004 Hilscher GmbH
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.
========================================================================
FILENAME : RcsDef.h
-------------------------------------------------------------------------
CREATED BY : R.Mayer, Hilscher GmbH
CREATED AT : 10.03.97
PROJECT :
=========================================================================
FUNCTION / CLASSDESCRIPTION:
=========================================================================
CHANGES OF REVISIONS :
Version Name Date Change
-------------------------------------------------------------------------
1.000 RM 10.03.97 Created
******************************************************************** <En> */
// Prevent multiple inclusion
#ifndef __RCSDEF_H__
#define __RCSDEF_H__
#ifdef _cplusplus
extern "C" {
#endif /* _cplusplus */
#define FIRMWARE_DOWNLOAD 1
#define CONFIGURATION_DOWNLOAD 2
/* ======================================================================== */
/* Message definitions */
/* ======================================================================== */
#define RCS_TASK 0x00 /* Number of RCS */
#define PLC_TASK 0x02 /* Number for PLC_TASK */
#define MSG_SYSTEM_TX 0xFF /* Transmitter for system functions number */
#define RCS_B_TASK_STATE 4 // Task state
/************************************************************************** */
/* Genaral RCS commands */
/************************************************************************** */
#define RCS_B_SYSFKT 1
#define RCS_B_TASKFKT 2
#define RCS_B_DIAGNOSE 3
#define RCS_B_STRUCTFNC 4
#define RCS_B_TRACE 5
#define RCS_B_LOADFKT 6
#define RCS_B_DBMFKT 10
/* ----------------------- */
/* Message extension masks */
/* ----------------------- */
#define RCS_FIFO_MSK 0
#define RCS_LIFO_MSK 1
#define RCS_NAK_MSK 2
#define RCS_NORM_MSK 0
#define RCS_FIRST_MSK 4
#define RCS_CONT_MSK 8
#define RCS_LAST_MSK 0x0C
#define RCS_SEQ_MSK 0x0C
/* ------------------ */
/* Mode definitions */
/* ------------------ */
#define MODE_NEUSTART 0 /* Command: B_SYSFKT */
#define MODE_KALTSTART 1 /* Command: B_SYSFKT */
#define MODE_WARMSTART 2 /* Command: B_SYSFKT */
#define MODE_ZYKL_STATUS_STOP 3 /* Command: B_SYSFKT */
#define MODE_FWVERSION 4 /* Command: B_SYSFKT */
#define MODE_GET_PROJ_WERTE_HW 5 /* Command: B_SYSFKT */
#define MODE_GET_PROJ_WERTE_SW 6 /* Command: B_SYSFKT */
#define MODE_SHOW_DYN_SYSSTAT 7 /* Command: B_SYSFKT */
#define MODE_SETTIME 9 /* not implemented yet */
#define MODE_SET_DEVICE_DATA 9 /* not implemented yet */
#define MODE_MODUL_RCS 11 /* Command: B_SYSFKT */
#define MODE_MODUL_LIB 12 /* Command: B_SYSFKT */
#define MODE_MODUL_MCL 13 /* Command: B_SYSFKT */
#define MODE_MODUL_LIB 12 /* Command: B_SYSFKT */
#define MODE_MODUL_MCL 13 /* Command: B_SYSFKT */
#define MODE_DISTRIBUTOR_DRIVER 14 /* Command: B_SYSFKT ->function 1 = insert */
#define MODE_PRINT_DRIVER 15 /* Command: B_SYSFKT */
#define MODE_GET_RCS_ERROR 16 /* Command: B_SYSFKT */
#define MODE_PRINT_DEVICE 1 /* NO mode, only for MENU.H */
#define MODE_PRINT_DEVICE_DRIVER 2 /* NO mode, only for MENU.H */
#define MODE_START_STOP_STAT 0 /* Command: B_TASKFKT */
#define MODE_START_STOP 1 /* Command: B_TASKFKT */
#define MODE_TASK_VERSION 2 /* Command: B_TASKFKT */
#define MODE_ZYKL_STATUS 3 /* Command: B_TASKFKT */
#define MODE_SHOW_FUELLST 4 /* Command: B_TASKFKT */
#define MODE_SHOW_TIMER 5 /* Command: B_TASKFKT */
#define MODE_DIAG_MEM_READ_SINGLE 0x0 /* Command: B_DIAGNOSE */
#define MODE_DIAG_MEM_WRITE_SINGLE 0x1 /* Command: B_DIAGNOSE */
#define MODE_DIAG_IO_READ_SINGLE 0x2 /* Command: B_STRUKTFKT */
#define MODE_DIAG_IO_WRITE_SINGLE 0x3 /* Command: B_STRUKTFKT */
#define MODE_DIAG_ZYKL 0x10 /* Command: B_STRUKTFKT */
#define MODE_DIAG_MEM_READ_ZYKL 0x10 /* Command: B_STRUKTFKT */
#define MODE_DIAG_MEM_WRITE_ZYKL 0x11 /* Command: B_STRUKTFKT */
#define MODE_DIAG_IO_READ_ZYKL 0x12 /* Command: B_STRUKTFKT */
#define MODE_DIAG_IO_WRITE_ZYKL 0x13 /* Command: B_STRUKTFKT */
#define MODE_ZYKL_TASK_STRUK 0 /* Command: B_STRUKTFKT */
#define MODE_INIT_INFO_STRUK 1 /* Command: B_STRUKTFKT */
#define MODE_WRITE_STRUK 2 /* Command: B_STRUKTFKT */
#define MODE_START_TRACE 0 /* Command: B_TRACE */
#define MODE_DEL_TRACE_PUF 1 /* Command: B_TRACE */
#define MODE_UPLOAD_BINAER 0 /* Command: B_LOADFKT */
#define MODE_DOWNLOAD_BINAER 1 /* Command: B_LOADFKT */
#define MODE_UPLOAD_DBM 2 /* Command: B_LOADFKT */
#define MODE_DOWNLOAD_DBM 3 /* Command: B_LOADFKT */
#define MODE_DEL_FLASH 4 /* Command: B_LOADFKT */
#define MODE_GET_FLASH_DIR 5 /* Command: B_LOADFKT */
#define MODE_URLADEN 6 /* Command: B_LOADFKT */
#define MODE_LONG_BINLOAD 7 /* Command: B_LOADFKT */
#define MODE_FREE_DRIVER 8 /* Command: B_LOADFKT */
#define MODE_RESET_DEVICE 10 /* Command: B_LOADFKT */
/* ------------------------------------------------------------------------------------ */
#ifdef _cplusplus
}
#endif
#endif
// ======== eof 'RcsDef.h' ========
......@@ -30,14 +30,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -47,7 +39,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
Convert ai from rawvalue to actualvalue.
......
......@@ -28,15 +28,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -46,7 +37,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
......
......@@ -28,15 +28,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -46,7 +37,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
#define IO_CONVMASK_ALL 0xFFFF
......
......@@ -28,15 +28,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -46,7 +37,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
......
......@@ -27,15 +27,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -316,21 +307,13 @@ static pwr_tStatus IoRackRead (
{
pwr_sClass_Pb_Profiboard *mp;
pwr_sClass_Pb_DP_Slave *sp;
T_PROFI_DEVICE_HANDLE *hDevice;
pwr_tUInt16 sts;
pwr_tUInt16 data_len;
hDevice = (T_PROFI_DEVICE_HANDLE *) ap->Local;
sp = (pwr_sClass_Pb_DP_Slave *) rp->op;
mp = (pwr_sClass_Pb_Profiboard *) ap->op;
if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL && sp->DisableSlave != 1 && mp->DisableBus != 1) {
/* The reading of the process image is now performed at the agent level,
this eliminates the need for board specific code at the rack level. */
data_len = sp->BytesOfInput;
sts = profi_get_data(hDevice, ID_DP_SLAVE_IO_IMAGE, sp->OffsetInputs, &data_len, &sp->Inputs );
}
if (sp->DisableSlave != 1 && mp->DisableBus != 1) {
if (sp->Status == PB__NORMAL) {
......@@ -368,26 +351,12 @@ static pwr_tStatus IoRackWrite (
{
pwr_sClass_Pb_Profiboard *mp;
pwr_sClass_Pb_DP_Slave *sp;
T_PROFI_DEVICE_HANDLE *hDevice;
pwr_tUInt16 sts;
hDevice = (T_PROFI_DEVICE_HANDLE *) ap->Local;
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__NORMAL || sp->Status == PB__NOCONN) &&
mp->Status == PB__NORMAL && (sp->DisableSlave != 1) && (mp->DisableBus != 1)) {
if (sp->BytesOfOutput > 0) {
sts = profi_set_data(hDevice, ID_DP_SLAVE_IO_IMAGE, sp->OffsetOutputs, sp->BytesOfOutput, &sp->Outputs);
if (sts != E_OK) sp->ErrorCount++;
}
}
/* The writing of the process image is now performed at the agent level,
this eliminates the need for board specific code at the rack level. */
if (sp->DisableSlave == 1 || mp->DisableBus == 1) sp->Status = PB__DISABLED;
......
/*
* Proview $Id$
* Copyright (C) 2008 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_hilscher.c -- Proview agent for the Hilscher CIF 50-PB
* Profibus DP board.
*/
/* Enable this define to spam the Proview log with diagnostic messages
from the slaves (this is probably a bad idea). */
/* #define SLAVE_DIAG_VERBOSE */
/* Enable this define to permit the agent to write to the board's flash in
order to remove the SyCon database. */
#define FLASH_WRITE_ENABLE
/* A note on assertions: There are some asserts in the code, most of these
are only used during initialization to verify that we do not write outside
our buffers or provide the Hilscher API with messages that would be too long.
The asserts may be disabled completely by using the NDEBUG macro, defined
in assert.h (man assert(3)). I would, however, recommend against that. */
/*
The code refers to some documents provided by Hilscher, the documents are:
CIFLinux_en.pdf: found in cif2620.tbz, the Linux version of the Hilscher
driver and API.
dpm_pie.pdf: found on the system software disc that comes with the board.
*/
#define BOARD_INIT_ERROR -1
#pragma pack(1)
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include "cif_user.h"
#include "rcs_user.h"
#include "dpm_user.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
#include "co_cdh.h"
#include "pwr_baseclasses.h"
#include "pwr_profibusclasses.h"
#include "rt_io_base.h"
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_agent_init.h"
#include "rt_pb_msg.h"
typedef struct {
/* Board number. */
unsigned short dev_number;
/* Number of occupied bytes in the input area of the dual port ram. */
unsigned short input_size;
/* Number of occupied bytes in the output area of the dual port ram. */
unsigned short output_size;
/* Message counter for communicating with the Profibus board,
(pre-)incremented before sending each message, the value is then
sent with the message. This message counter is optional. */
unsigned char cif_msgcnt;
/* Watchdog counter, used by DevTriggerWatchDog() as explained on page
58 of CIFLinux_en.pdf. */
unsigned short watchdog;
} io_sAgentLocal;
/* Prototypes for functions exported to Proview. */
static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent *ap);
static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent *ap);
static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent *ap);
static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent *ap);
#ifdef FLASH_WRITE_ENABLE
/*** Structures for board flashing. ***/
/* Start segment of the database, shall be 8 for
CIF30-DPM, CIF104-DPM, COM-DPM, COM-PB, CIF104-PB and CIF 50-PB.
Shall be 0 for CIF 30-PB and CIF 60-PB. */
typedef struct {
/* Used to terminate the table, se to 1 for every entry but the
last (dummy entry), which should be 0. */
unsigned char entry;
/* The DEVINFO struct for this board. */
DEVINFO info;
/* Start segment of the database for this board. */
unsigned char db_startsegment;
/* A human readable name for this board. Max 99 characters! */
unsigned char board_name[100];
} boards;
/* Table of known boards, consists of four fields according to the board type.
The last entry must be a null termination (entry == 0).
*/
boards known_boards[] = {
{ 1, { 8, 50, 66, { 'C', 'I', 'F'} }, 8, "Hilscher CIF 50-PB" },
{ 0 }
};
#endif /* FLASH_WRITE_ENABLE */
/* Initializes Profibus DP interface on the CIF board referred to by local.
DRV_NO_ERROR is returned upon success. */
static short
dpm_init_master(io_sAgentLocal *local, pwr_sClass_Pb_Hilscher *op,
io_sAgent *ap)
{
short rv;
DPM_PLC_PARAMETER prm;
/* Clears struct. */
memset(&prm, 0, sizeof(prm));
/* Defines standard parameters. */
prm.bMode = DPM_SET_MODE_BUFFERED_HOST_CONTROLLED;
prm.bCycleTime = 0;
prm.bFormat = DPM_FORMAT_SWAP;
/* Sets the timeout (in milliseconds) for the watchdog supervising the
Profibus DP board. After this amount of time has passed without
any data exchange with the host, the board will be reset which will
eventually make the watchdogs in the slaves time out (normally resulting
in all outputs being cleared). A zero value will disable the watchdog
functionality altogether. */
prm.usWatchDogTime = op->StallTime;
prm.bRedundancy = 0;
prm.bSlStateMethod = DPM_SL_STATE_NOT_SYCHRONOUS;
prm.bEnableBits.biIdentNumberActive = 0;
prm.bEnableBits.biHighPriorHandshake = 0;
/* 0x7505 in LE */
*((unsigned char *) &(prm.usIdentNumber)) = 0x75;
*(((unsigned char *) &(prm.usIdentNumber)) + 1) = 0x05;
/* Writes parameters to the board local->dev_number, task 2, size is
* hardcoded to 16 as specified in dpm_pie.pdf, page 9. */
if ((rv = DevPutTaskParameter(local->dev_number, 2,
16, &prm)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - "
" DevPutTaskParameter() failed with return code %d",
ap->Name, rv);
return rv;
}
/* Resets board to put new master parameters into effect. */
if ((rv = DevReset(local->dev_number, WARMSTART, 8000)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - "
" DevReset() failed with return code %d",
ap->Name, rv);
return rv;
}
return rv;
}
/* Opens and initializes the board referred to by local. Upon success
* DRV_NO_ERROR will be returned. */
static short
dpm_init(io_sAgentLocal *local, io_sAgent *ap)
{
short rv;
if ((rv = DevOpenDriver()) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - "
" DevOpenDriver() failed with return code %d",
ap->Name, rv);
return rv;
} else if ((rv = DevInitBoard(local->dev_number)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - "
" DevInitBoard() failed with return code %d",
ap->Name, rv);
return rv;
}
return DRV_NO_ERROR;
}
/* Closes the board referred to by local. Upon success DRV_NO_ERROR will
be returned. */
static short
dpm_exit(io_sAgentLocal *local, io_sAgent *ap)
{
short rv;
short rv_ret = DRV_NO_ERROR;
if ((rv = DevExitBoard(local->dev_number)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - "
" DevExitBoard() failed with return code %d",
ap->Name, rv);
rv_ret = rv;
}
if ((rv = DevCloseDriver()) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - "
" DevCloseDriver() failed with return code %d",
ap->Name, rv);
rv_ret = rv;
}
return rv_ret;
}
/* Returns the number of bytes required to represent the inputs of card
(Profibus module) cp. Based on the IoRackInit() method of
rt_io_m_pb_dp_slave.c. */
static short
module_cnt_inputs(io_sCard *cp)
{
short input_counter = 0;
int latent_input_count = 0;
pwr_tCid cid;
io_sChannel *chanp;
int i;
pwr_tInt32 chan_size;
pwr_sClass_ChanDi *chan_di;
pwr_sClass_ChanAi *chan_ai;
pwr_sClass_ChanAit *chan_ait;
pwr_sClass_ChanIi *chan_ii;
/* From v4.1.3 we can have subclasses, find the super class */
for (cid = cp->Class; ODD(gdh_GetSuperClass(cid, &cid, cp->Objid));)
;
if (cid == pwr_cClass_Pb_Module) {
/* New style configuring (from v4.1.3) with Pb_Module objects or
subclass. Loop all channels in the module and set channel size and
offset. */
for (i = 0; i < cp->ChanListSize; ++i) {
chanp = &cp->chanlist[i];
if (is_diag(&chanp->ChanAref)) {
chanp->udata |= PB_UDATA_DIAG;
if (chanp->ChanClass != pwr_cClass_ChanIi)
errh_Error("Diagnostic channel class, card %s", cp->Name);
continue;
}
if (chanp->ChanClass != pwr_cClass_ChanDi) {
input_counter += latent_input_count;
latent_input_count = 0;
}
switch (chanp->ChanClass) {
case pwr_cClass_ChanDi:
chan_di = (pwr_sClass_ChanDi *) chanp->cop;
if (chan_di->Number == 0) {
input_counter += latent_input_count;
latent_input_count = 0;
}
if (chan_di->Number == 0)
latent_input_count = GetChanSize(chan_di->Representation);
break;
case pwr_cClass_ChanAi:
chan_ai = (pwr_sClass_ChanAi *) chanp->cop;
chan_size = GetChanSize(chan_ai->Representation);
input_counter += chan_size;
break;
case pwr_cClass_ChanAit:
chan_ait = (pwr_sClass_ChanAit *) chanp->cop;
chan_size = GetChanSize(chan_ait->Representation);
input_counter += chan_size;
break;
case pwr_cClass_ChanIi:
chan_ii = (pwr_sClass_ChanIi *) chanp->cop;
chan_size = GetChanSize(chan_ii->Representation);
input_counter += chan_size;
break;
}
}
}
return (input_counter + latent_input_count);
}
/* Returns the number of bytes required to represent the outputs of card
(Profibus module) cp. Based on the IoRackInit() method of
rt_io_m_pb_dp_slave.c. */
static short
module_cnt_outputs(io_sCard *cp)
{
short output_counter = 0;
int latent_output_count = 0;
pwr_tCid cid;
io_sChannel *chanp;
int i;
pwr_tInt32 chan_size;
pwr_sClass_ChanDo *chan_do;
pwr_sClass_ChanAo *chan_ao;
pwr_sClass_ChanIo *chan_io;
/* From v4.1.3 we can have subclasses, find the super class */
for (cid = cp->Class; ODD(gdh_GetSuperClass(cid, &cid, cp->Objid));)
;
if (cid == pwr_cClass_Pb_Module) {
/* New style configuring (from v4.1.3) with Pb_Module objects or
subclass. Loop all channels in the module and set channel size and
offset. */
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
if(is_diag(&chanp->ChanAref)) {
chanp->udata |= PB_UDATA_DIAG;
if (chanp->ChanClass != pwr_cClass_ChanIi)
errh_Error("Diagnostic channel class, card %s", cp->Name);
continue;
}
if (chanp->ChanClass != pwr_cClass_ChanDo) {
output_counter += latent_output_count;
latent_output_count = 0;
}
switch (chanp->ChanClass) {
case pwr_cClass_ChanDo:
chan_do = (pwr_sClass_ChanDo *) chanp->cop;
if (chan_do->Number == 0) {
output_counter += latent_output_count;
latent_output_count = 0;
}
chan_size = GetChanSize(chan_do->Representation);
if (chan_do->Number == 0)
latent_output_count = GetChanSize(chan_do->Representation);
break;
case pwr_cClass_ChanAo:
chan_ao = (pwr_sClass_ChanAo *) chanp->cop;
chan_size = GetChanSize(chan_ao->Representation);
output_counter += chan_size;
break;
case pwr_cClass_ChanIo:
chan_io = (pwr_sClass_ChanIo *) chanp->cop;
chan_size = GetChanSize(chan_io->Representation);
output_counter += chan_size;
break;
}
}
}
return (output_counter + latent_output_count);
}
/* Builds a struct for IO area allocation for the modules attached
to the slave op. The starting offset is derived from the local struct of
ap. The address table will be written to the buffer provided in add_tab.
add_tab will also have its length field updated. Not more than add_tab_len
bytes will be written to add_tab.
The function will also set up the required fields in op so that Proview
may perform IO operations using the IoAgentRead() and IoAgentWrite() functions
in this module. */
static void
dpm_set_add_tab(pwr_sClass_Pb_DP_Slave *op, io_sAgent *ap, io_sRack *rp,
DPM_SL_PRM_ADD_TAB *add_tab, int add_tab_len)
{
io_sCard *cardp;
short input_counter;
short output_counter;
io_sRack *sl;
/* A minimal address table consists of one word of length counter + two
bytes of input and output counters. */
assert(add_tab_len >= 4);
/* Handles for the number of bytes in the board's dual port memory that the
slaves/modules have occupied so far. */
unsigned short *input_size;
unsigned short *output_size;
input_size = (unsigned short *) &((io_sAgentLocal *) ap->Local)->input_size;
output_size =
(unsigned short *) &((io_sAgentLocal *) ap->Local)->output_size;
/* This lets Proview find the IO-area for this module (in this case it is
actually handled at the agent level, thus in this file). The offsets
are known at this time, while the number of IO-bytes are calculated below,
the latter still needs to be initialized to zero. */
op->OffsetInputs = *input_size;
op->OffsetOutputs = *output_size;
op->BytesOfInput = 0;
op->BytesOfOutput = 0;
/* Finds our rack (slave). */
for (sl = rp;
sl != NULL && ((pwr_sClass_Pb_DP_Slave *) sl->op)->SlaveAddress
!= op->SlaveAddress;
sl = sl->next)
;
if (sl == NULL
|| ((pwr_sClass_Pb_DP_Slave *) sl->op)->SlaveAddress
!= op->SlaveAddress) {
errh_Error("Profibus DP Master %s - "
" Can't find rack for slave %d",
ap->Name, op->SlaveAddress);
return;
}
/* Iterates through the cards (modules in Profibus terminology) of
the current rack, counting the length of the input area as we go. */
for (cardp = sl->cardlist; cardp; cardp = cardp->next) {
/* Gets the size of the input area for this module. */
input_counter = module_cnt_inputs(cardp);
/* Saves the length of this module's input area. */
op->BytesOfInput += input_counter;
/* Only modules with and input or output area are required to
have an entry in the add tab. */
if (input_counter > 0) {
assert(add_tab->bInput_Count + 4 < add_tab_len);
/* The MSB tells the Hilscher board whether to treat the address
as a byte (set) or word (unset) offset
(see dpm_pie.pdf, page 45). */
add_tab->ausEA_Offset[add_tab->bInput_Count++]
= *input_size | EA_OFFSET_BYTE;
*input_size += input_counter;
}
}
/* Now process the output areas. */
for (cardp = sl->cardlist; cardp; cardp = cardp->next) {
/* Gets the size of the output area for this module. */
output_counter = module_cnt_outputs(cardp);
/* Saves the length of this module's input area. */
op->BytesOfOutput += output_counter;
/* Only modules with and input or output area are required to
have an entry in the add tab. */
if (output_counter > 0) {
assert(add_tab->bInput_Count + add_tab->bOutput_Count + 4
< add_tab_len);
/* The MSB tells the Hilscher board whether to treat the address
as a byte (set) or word (unset) offset
(see dpm_pie.pdf, page 45). */
/* The input offsets precedes the output offsets. */
add_tab->ausEA_Offset[
add_tab->bInput_Count + add_tab->bOutput_Count++]
= *output_size | EA_OFFSET_BYTE;
*output_size += output_counter;
}
}
assert(add_tab->bInput_Count + add_tab->bOutput_Count <= MAX_EA_OFFSET_LEN);
/* Updates the length of the add_tab struct. */
add_tab->usAdd_Tab_Len = sizeof(add_tab->usAdd_Tab_Len)
+ sizeof(add_tab->bInput_Count) + sizeof(add_tab->bOutput_Count)
+ 2 * add_tab->bInput_Count + 2 * add_tab->bOutput_Count;
}
/* Writes instructions for reflashing the board to the error log. */
static void
flashing_disabled_warning(io_sAgent *ap)
{
errh_Error("Profibus DP Master %s - DDLM Download: this board",
ap->Name);
errh_Error("appears to be set for offline configuration. To make");
errh_Error("the board usable in Proview, delete the configuration");
errh_Error("database from the board's flash. This can be done");
errh_Error("with the tool cif50_rmdb, alternatively the profibus");
errh_Error("agent may be recompiled with flashing support.");
}
/* Produces human readable log entries based on the f-flag (error state) of the
message passed in msg. */
static void
dpm_ddlm_answer_msg_print_error(RCS_MESSAGE *msg, io_sAgent *ap)
{
char *s;
if (msg == NULL)
return;
switch (msg->a) {
case DDLM_Download:
switch (msg->f) {
case 0:
return;
case CON_NO:
s = "master not in offline configuration mode. Delete"
" the data base within the DEVICE, else the DEVICE is not"
" able to execute the download of the dataset file";
break;
case CON_IV:
s = "parameter fault in request. Please check the"
" downloaded parameter in your request message. The"
" Siemens master chip has denied the bus parameter data"
" set.";
break;
case CON_TO:
s = "timeout. If Start and End_Seq messaging is used a"
" message timeout occurred during the sequenced download.";
break;
case CON_NI:
s = "area_code unknown. Please check the area code"
" of the message in its limits.";
break;
case CON_EA:
s = "overstep of the maximum buffer length of 1000"
" bytes per dataset file.";
break;
case CON_IP:
s = "faulty parameter detected. The configured"
" data_control time is set to zero. This is not allowed.";
break;
case CON_SE:
s = "sequence error. End_seq was called without"
" Start_seq or the area_code is different in the download"
" message in comparison to the Start_seq area_code";
break;
case CON_DI:
s = "data incomplete or faulty. The check routine for the"
" downloaded parameter file detected inconsistencies";
break;
default:
return;
}
errh_Info("Profibus DP Master %s - DDLM Download: %s", ap->Name, s);
/* Provides extended instructions if the board's flash is configured for
offline configuration. */
if (msg->f == CON_NO)
flashing_disabled_warning(ap);
break;
case DDLM_Slave_Diag:
switch (msg->f) {
case 0:
return;
case CON_NA:
s = "no response of the station";
break;
case CON_DS:
s = "master not into the logical network in token ring";
break;
case TASK_F_DEVICE_ADR:
s = "Remote Address in request service out of range";
break;
default:
return;
}
errh_Info("Profibus DP Master %s - Station %d - DDLM Slave Diag: %s",
ap->Name, ((RCS_MESSAGETELEGRAM_10 *) msg)->device_adr, s);
break;
default:
return;
}
}
/* Performs a DDLM download, used to configure the master or
slave bus parameters. The agent's local struct is passed in local, the
destination address is passed in address, 0-125 to set slave bus parameters
or 127 to set master bus parameters. The bus parameters are read from
the buffer prmdata and shall be of length prmlen. DRV_NO_ERROR is returned
if successful. */
static short
dpm_ddlm_download(io_sAgentLocal *local, unsigned char address,
unsigned int prmlen, void *prmdata, io_sAgent *ap)
{
short rv;
int got_response = 0;
RCS_MESSAGE msg, rcv_msg;
DDLM_DOWNLOAD_REQUEST *download = (DDLM_DOWNLOAD_REQUEST *) &(msg.d[0]);
/* Clears struct. */
memset(&msg, 0, sizeof(msg));
memset(&rcv_msg, 0, sizeof(rcv_msg));
/* Defines message header. */
msg.rx = 3;
msg.tx = 16;
msg.ln = prmlen + 4;
msg.nr = ++local->cif_msgcnt;
msg.a = 0;
msg.f = 0;
msg.b = DDLM_Download;
msg.e = 0;
/* Defines service header. */
download->bReq_Add = 0;
download->bArea_Code = address;
download->usAdd_Offset = 0;
/* PRM data starts at d[4] in the message according to
dpm_pie.pdf, page 43. */
assert(prmlen <= 240);
memcpy(&(msg.d[4]), prmdata, prmlen);
if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC *) &msg, 5000))
!= DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - DDLM_Download - DevPutMessage()"
" returned %d", ap->Name, rv);
return rv;
}
/* Checks confirmation message. */
while (!got_response) {
if ((rv = DevGetMessage(local->dev_number, sizeof(rcv_msg),
(MSG_STRUC *) &rcv_msg, 5000)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s - DDLM_Download - DevGetMessage()"
" returned %d", ap->Name, rv);
return rv;
} else if (rcv_msg.nr != local->cif_msgcnt
|| rcv_msg.rx != 16
|| rcv_msg.tx != 3
|| rcv_msg.a != DDLM_Download) {
/* Discards all messages prior to our response. */
memset(&rcv_msg, 0, sizeof(rcv_msg));
continue;
} else if (rcv_msg.f != 0) {
dpm_ddlm_answer_msg_print_error(&rcv_msg, ap);
return rcv_msg.f;
} else {
got_response = 1;
}
}
return rv;
}
/* Configures the master bus parameters of the board referred to by
local, the struct containing the parameters should be passed in op. */
static short
dpm_download_master_prm(io_sAgentLocal *local, pwr_sClass_Pb_Hilscher *op,
io_sAgent *ap)
{
DPM_BUS_DP prm;
/* Clears struct. */
memset(&prm, 0, sizeof(prm));
/* Defines Profibus DP bus parameters, these are described briefly
in dpm_pie.pdf, page 41. */
prm.usBus_Para_Len = 32;
/* The master's address is hardcoded to 0. */
prm.bFDL_Add = 0;
prm.bBaudrate = ((op->BaudRate == 500) ? (DP_BAUD_500)
: (op->BaudRate == 1500) ? (DP_BAUD_1500)
: (op->BaudRate == 3000) ? (DP_BAUD_3000)
: (op->BaudRate == 6000) ? (DP_BAUD_6000)
: (op->BaudRate == 12000) ? (DP_BAUD_12000)
: (DP_BAUD_1500));
prm.usTSL = op->Tsl;
prm.usMin_TSDR = op->MinTsdr;
prm.usMax_TSDR = op->MaxTsdr;
prm.bTQUI = op->Tqui;
prm.bTSET = op->Tset;
prm.ulTTR = op->Ttr;
prm.bG = op->G;
prm.bHSA = op->Hsa;
prm.bMax_Retry_Limit = op->MaxRetryLimit;
prm.Bp_Flag.bError_Action_Flag = ((op->BpFlag) ? (1) : (0));
prm.usMin_Slave_Intervall = op->MinSlaveInterval;
prm.usPoll_Timeout = op->PollTimeout;
prm.usData_Control_Time = op->DataControlTime;
prm.bAlarm_Max = 0;
prm.bMax_User_Global_Control = 1;
/* The length of the total message is 35 according to dpm_pie.pdf,
page 43. The service header accounts for 4 of these, thus we set
the length to 31 here. */
return dpm_ddlm_download(local, 127, 31, &prm, ap);
}
/* Configures the bus parameters for one slave. The agent's local struct
is passed in local. op holds the slave to configure, the corresponding
agent pointer and rack pointer must be passed in ap and rp respectively.
DRV_NO_ERROR will be returned upon success. */
static short
dpm_download_slave_prm(io_sAgentLocal *local, pwr_sClass_Pb_DP_Slave *op,
io_sAgent *ap, io_sRack *rp)
{
unsigned char buf[DPM_MAX_LEN_DATA_UNIT];
unsigned int bufcnt = 0;
/* DPM_SL_PRM_HEADER starts at offset 4 in the data buffer according
to dpm_pie.pdf, page 45 -- however, since the first 4 bytes are
occupied by the service header, which we'll fill in later, we'll
define the offset to be 0. */
DPM_SL_PRM_HEADER *hdr = (DPM_SL_PRM_HEADER *) &buf[0];
DPM_SL_PRM_PRM_DATA *prm = (DPM_SL_PRM_PRM_DATA *) &buf[16];
DPM_SL_PRM_CFG_DATA *cfg;
DPM_SL_PRM_ADD_TAB *add_tab;
DPM_SL_PRM_USR_DATA *usr;
/* Clears buffer. */
memset(&buf, 0, sizeof(buf));
/* Defines prm header. */
hdr->Sl_Flag.biExtra_Alarm_SAP = 0;
hdr->Sl_Flag.biDPV1_Data_Types = 0;
hdr->Sl_Flag.biDPV1_Supported = 0;
hdr->Sl_Flag.biPublisher_Enable = 0;
hdr->Sl_Flag.biFail_Safe = 0;
hdr->Sl_Flag.biNew_Prm = 0;
hdr->Sl_Flag.biActive = 1;
hdr->bSlave_Typ = 0;
bufcnt = 16;
/* Defines prm data */
prm->usPrmDataLen = 7 + sizeof(prm->usPrmDataLen);
prm->Station_Status.bWD_On = 1;
prm->Station_Status.bFreeze_Req = 0;
prm->Station_Status.bSync_Req = 0;
prm->Station_Status.bUnLock_Req = 0;
prm->Station_Status.bLock_Req = 1;
prm->bWD_Fact_1 = op->WdFact1;
prm->bWD_Fact_2 = op->WdFact2;
prm->bMin_Tsdr = 0;
/* Ident number in LE */
prm->usIdent_Number = swap16(op->PNOIdent);
prm->bGroup_Ident = op->GroupIdent;
bufcnt += prm->usPrmDataLen;
/* Defines user prm data. */
prm->usPrmDataLen += op->PrmUserDataLen;
assert(bufcnt + op->PrmUserDataLen + 2 <= DPM_MAX_LEN_DATA_UNIT);
memcpy(&buf[bufcnt], op->PrmUserData, op->PrmUserDataLen);
bufcnt += op->PrmUserDataLen;
/* Defines cfg data */
cfg = (DPM_SL_PRM_CFG_DATA *) &buf[bufcnt];
/* Note that the cfg data length is part of the cfg data in Proview,
by skipping these two bytes and writing the op->ConfigDataLen
field to the usCfg_Data_Len of DPM_SL_PRM_CFG_DATA we avoid some
endianness issues. */
cfg->usCfg_Data_Len = op->ConfigDataLen - 2 + sizeof(cfg->usCfg_Data_Len);
assert(bufcnt + cfg->usCfg_Data_Len + 2 <= DPM_MAX_LEN_DATA_UNIT);
memcpy(cfg->abCfg_Data, op->ConfigData + 2, op->ConfigDataLen - 2);
bufcnt += cfg->usCfg_Data_Len;
/* Defines address table. */
add_tab = (DPM_SL_PRM_ADD_TAB *) &buf[bufcnt];
/* dpm_set_add_tab is also responsible for updating the length of the
table, so no need to worry about it here :). */
dpm_set_add_tab(op, ap, rp, add_tab, DPM_MAX_LEN_DATA_UNIT - bufcnt);
/* Take the length of the address table into account when filling our
local buffer. */
bufcnt += add_tab->usAdd_Tab_Len;
assert(bufcnt + 2 <= DPM_MAX_LEN_DATA_UNIT);
/* We will leave the slave user data empty. */
usr = (DPM_SL_PRM_USR_DATA *) &buf[bufcnt];
usr->usSlave_Usr_Data_Len = sizeof(usr->usSlave_Usr_Data_Len);
bufcnt += usr->usSlave_Usr_Data_Len;
/* The length of the whole PRM set is now known, so we can
fill in that field in the header. */
hdr->usSlaveParaLen = bufcnt;
assert(bufcnt <= DPM_MAX_LEN_DATA_UNIT);
return dpm_ddlm_download(local, op->SlaveAddress, bufcnt, buf, ap);
}
/* Requests diagnostics from the slave address, attached to the
board referred to by local. The function will return DRV_NO_ERROR if
the request was sent without error, however, it tells us nothing
about whether any diagnostics data was sent back. */
static short
dpm_req_slave_diag(io_sAgentLocal *local, unsigned char address, io_sAgent *ap)
{
short rv;
RCS_MESSAGETELEGRAM_10 msg;
/* Clears struct. */
memset(&msg, 0, sizeof(msg));
/* Defines message header. */
msg.rx = 3;
msg.tx = 16;
msg.ln = 8;
msg.nr = ++local->cif_msgcnt;
msg.a = 0;
msg.f = 0;
msg.b = DDLM_Slave_Diag;
msg.e = 0;
/* Defines extended message header. */
msg.device_adr = address;
msg.data_area = 0;
msg.data_adr = 0;
msg.data_idx = 0;
msg.data_cnt = 0;
msg.data_type = TASK_TDT_STRING;
msg.function = TASK_TFC_READ;
/* Requests diagnostic data from slave. */
if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC *) &msg, 0))
!= DRV_NO_ERROR) {
errh_Info("Profibus DP Master %s - DDLM_Slave_Diag - DevPutMessage()"
" returned %d", ap->Name, rv);
return rv;
}
return DRV_NO_ERROR;
}
/* Checks if we have any pending messages and processes them. This allows us
to gather diagnostics data asynchronously. The desired agent's local
struct is passed via local and the associated rack list (Profibus slaves) is
passed in slave_list. */
static void
dpm_update_slave_diag(io_sAgentLocal *local, io_sRack *slave_list,
io_sAgent *ap)
{
short rv;
RCS_MESSAGETELEGRAM_10 rcv_msg;
pwr_sClass_Pb_DP_Slave *sp;
io_sRack *sl;
/* Clears struct. */
memset(&rcv_msg, 0, sizeof(rcv_msg));
/* Gets pending diagnostic messages, discards all other messages. */
while ((rv = DevGetMessage(local->dev_number, sizeof(rcv_msg),
(MSG_STRUC *) &rcv_msg, 0)) == DRV_NO_ERROR) {
if (rcv_msg.rx != 16 || rcv_msg.tx != 3
|| rcv_msg.a != DDLM_Slave_Diag) {
/* Discards received message. */
memset(&rcv_msg, 0, sizeof(rcv_msg));
continue;
} else if (rcv_msg.f != 0) {
dpm_ddlm_answer_msg_print_error((RCS_MESSAGE *) &rcv_msg, ap);
/* Discards received message. */
memset(&rcv_msg, 0, sizeof(rcv_msg));
continue;
} else {
/*** Updates Proview's structs with the acquired diagnostics. ***/
/* Finds our slave. */
for (sl = slave_list; sl != NULL; sl = sl->next) {
sp = (pwr_sClass_Pb_DP_Slave *) sl->op;
if (sp->SlaveAddress == rcv_msg.device_adr)
break;
}
/* The slave from which we were to read diagnostic data could not
be found -- abort. */
if (sp->SlaveAddress != rcv_msg.device_adr) {
errh_Error("Profibus DP Master %s - Received diagnostic message"
" from unknown slave %d", ap->Name, rcv_msg.device_adr);
return;
}
/* Copies the diagnostic data into slave struct. */
sp->StationStatus1 = rcv_msg.d[0];
sp->StationStatus2 = rcv_msg.d[1];
sp->StationStatus3 = rcv_msg.d[2];
sp->BytesOfDiag = rcv_msg.data_cnt - 6;
/* Makes sure we don't overflow the slave's diagnostics buffer. */
if (sp->BytesOfDiag > sizeof(sp->Diag))
sp->BytesOfDiag = sizeof(sp->Diag);
memcpy(sp->Diag, rcv_msg.d + 6, sp->BytesOfDiag);
/* Updates the slave's status */
if (!(sp->StationStatus1 & ~pwr_mPbStationStatus1Mask_ExternalDiag)
&& !(sp->StationStatus2
& ~(pwr_mPbStationStatus2Mask_Default |
pwr_mPbStationStatus2Mask_ResponseMonitoringOn))) {
sp->Status = PB__NORMAL;
} else if (sp->StationStatus1
& pwr_mPbStationStatus1Mask_NonExistent) {
sp->Status = PB__NOCONN;
} else if ((sp->StationStatus1
& (pwr_mPbStationStatus1Mask_ConfigFault
| pwr_mPbStationStatus1Mask_ParamFault))
|| (sp->StationStatus2
& pwr_mPbStationStatus2Mask_NewParamsRequested)) {
sp->Status = PB__CONFIGERR;
} else if (sp->StationStatus1
& pwr_mPbStationStatus1Mask_MasterLock) {
sp->Status = PB__MASTERLOCK;
} else { /* if (sp->StationStatus1
& pwr_mPbStationStatus1Mask_NotReady) */
sp->Status = PB__NOTREADY;
}
}
}
}
/* Prints diagnostics info diag in human readable form if the macro
SLAVE_DIAG_VERBOSE is defined. */
static void
dpm_print_diag(io_sAgent *ap, DPM_DIAGNOSTICS *diag)
{
char *s;
if (diag->tError.bErr_Event == 0) {
return;
} else if (diag->tError.bErr_Rem_Adr == 255) {
switch (diag->tError.bErr_Event) {
case TASK_F_NO_USR_TASK: s = "usr task not found"; break;
case TASK_F_NO_GLOBAL_DATA: s = "no global entry in data base"; break;
case TASK_F_NO_FDL: s = "fdl task not found"; break;
case TASK_F_NO_PLC: s = "plc task not found"; break;
case TASK_F_NO_BUS_DP: s = "no bus parameters"; break;
case TASK_F_INVALID_BUS_DP: s = "bus parameters faulty"; break;
case TASK_F_NO_SL_TAB: s = "no slave data sets"; break;
case TASK_F_INVALID_SL_TAB: s = "slave data set faulty"; break;
case TASK_F_REM_ADR_DOUBLE: s = "double station addr detected"; break;
case TASK_F_A_OFFSET_MAX: s = "maximum output offset reached"; break;
case TASK_F_E_OFFSET_MAX: s = "maximum input offset reached"; break;
case TASK_F_A_OVERLAP: s = "overlap in output area"; break;
case TASK_F_E_OVERLAP: s = "overlap in input area"; break;
case TASK_F_DPM_UNKNOWN_MODE: s = "warmstart with unknown mode"; break;
case TASK_F_RAM_OVERRUN: s = "extended ram exceeded"; break;
case TASK_F_SL_PRM_FAULT: s = "slave data set faulty"; break;
case TASK_F_WATCHDOG: s = "user watchdog failure"; break;
case TASK_F_NO_DATA_ACK: s = "mode0 no acknowledge"; break;
case TASK_F_AUTO_CLEAR: s = "auto clear activated"; break;
case TASK_F_FATAL_ASIC_ERROR: s = "fatal error occurred"; break;
case TASK_F_UNKNOWN_EVENT: s = "unknown event detected"; break;
case TASK_F_SEGMENT_CNT: s = "no segments to communicate"; break;
default: return;
}
errh_Info("Profibus DP Master %s - %s", ap->Name, s);
return;
} else {
switch (diag->tError.bErr_Event) {
case CON_NA: s = "no reaction of the remote station"; break;
case CON_DS: s = "local FDL not in logical token ring"; break;
case CON_RS: s = "master request not supported by the slave"; break;
case CON_NR: s = "no response data"; break;
default: return;
}
#ifdef SLAVE_DIAG_VERBOSE
errh_Info("Profibus DP Master %s - Station %d - %s",
ap->Name, diag->tError.bErr_Rem_Adr, s);
#endif /* SLAVE_DIAG_VERBOSE */
return;
}
}
#ifdef FLASH_WRITE_ENABLE
/*** Functions for board flashing. ***/
/* Tries to find the db_startsegment for the board referred to by local.
If the board was found in the database, the function returns DRV_NO_ERROR
and the startsegment will be written to what db_startsegment points to. */
static short
dpm_check_board_type(io_sAgentLocal *local, io_sAgent *ap,
unsigned char *db_startsegment)
{
short rv;
DEVINFO info;
int i;
assert(DRV_NO_ERROR == 0);
/* Gets device information from the board. */
if ((rv = DevGetInfo(local->dev_number, GET_DEV_INFO, sizeof(info), &info))
!= DRV_NO_ERROR) {
errh_Error(
"Profibus DP Master %s - Error %d while checking board type.",
ap->Name, rv);
return rv;
}
errh_Info("Profibus DP Master %s -"
" Selected board %d has the following device info:",
ap->Name, local->dev_number);
errh_Info("Device DPM size: %d", info.bDpmSize);
errh_Info("Device type: %d", info.bDevType);
errh_Info("Device model: %d", info.bDevModel);
errh_Info("Device identification: %.3s", info.abDevIdentifier);
/* Looks for an entry matching our board. */
for (i = 0; known_boards[i].entry != 0; ++i)
if (memcmp(&known_boards[i].info, &info, sizeof(info)) == 0)
break;
if (known_boards[i].entry == 0) {
/* Board was not found in table. */
errh_Error("Profibus DP Master %s - Unknown board.", ap->Name);
errh_Error("To add support for this board, look up its database start");
errh_Error("segment in DPM_PIE.PDF, page 33 and add an entry to the");
errh_Error("known_boards table in rt_io_m_pb_hilscher.c.");
errh_Error("The following entry may be inserted into the known_boards");
errh_Error("table to enable flashing for this board. Replace");
errh_Error("<db start segment> and <board name> with data found");
errh_Error("in the above mentioned documentation.");
errh_Error("{ 1, { %d, %d, %d, { '%c', '%c', '%c'} }, "
"<db start segment>, \"<board name>\" },",
info.bDpmSize, info.bDevType, info.bDevModel,
info.abDevIdentifier[0],
info.abDevIdentifier[1],
info.abDevIdentifier[2]);
return BOARD_INIT_ERROR;
}
/* Board was found in table. */
errh_Info("Board known:");
errh_Info("Name: %s", known_boards[i].board_name);
errh_Info("Start segment of database: %d",
known_boards[i].db_startsegment);
*db_startsegment = known_boards[i].db_startsegment;
return DRV_NO_ERROR;
}
/* Deletes the "PROFIBUS" protocol settings database from the card referred
to by local, this procedure is described on page 32 -- 33 in dpm_pie.pdf. */
static short
dpm_delete_flash_prmdb(io_sAgentLocal *local, io_sAgent *ap)
{
unsigned char db_startsegment;
int s = 3;
int got_response = 0;
short rv;
RCS_MESSAGE msg;
/* Gets start segment of database. */
if ((rv = dpm_check_board_type(local, ap, &db_startsegment))
!= DRV_NO_ERROR)
return rv;
/* Clears struct. */
memset(&msg, 0, sizeof(msg));
/* Defines message header. */
msg.rx = 0; /* receiver = RCS-Task */
msg.tx = 16; /* transmitter = user at HOST */
msg.ln = 2;
msg.nr = ++local->cif_msgcnt;
msg.a = 0; /* no answer */
msg.f = 0; /* no error */
msg.b = 6; /* command = data base access */
msg.e = 0; /* extension, not used */
/* Defines delete database request. */
msg.d[0] = 4; /* mode = delete data base */
msg.d[1] = db_startsegment;
errh_Info("Profibus DP Master %s - Sending delete database request...",
ap->Name);
/* Sends delete database request. */
if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC *) &msg, 5000))
!= DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s -"
" DevPutMessage failed with return code %d", ap->Name, rv);
return rv;
}
/* Waits for controller to update flash. */
errh_Info("Profibus DP Master %s -"
" Delete db request sent. Waiting %d seconds...", ap->Name, s);
while ((s = sleep(s)))
;
/* Clears struct. */
memset(&msg, 0, sizeof(msg));
/* Gets response message. */
while (!got_response) {
if ((rv = DevGetMessage(local->dev_number, sizeof(msg),
(MSG_STRUC *) &msg, 10000)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s -"
" DevGetMessage failed with return code %d\n",
ap->Name, rv);
return rv;
} else if (msg.nr != local->cif_msgcnt || msg.rx != 16 || msg.tx != 0
|| msg.a != 6) {
/* Discards all messages prior to our response. */
memset(&msg, 0, sizeof(msg));
continue;
} else {
if (msg.f != 0)
errh_Error("Profibus DP Master %s -"
" Delete db confirmation message f-flag set to %d",
ap->Name, msg.f);
else
errh_Info("Profibus DP Master %s -"
" Delete database confirmation message received.",
ap->Name);
got_response = 1;
}
}
return rv;
}
#endif /* FLASH_WRITE_ENABLE */
/* From cif_dev.h in the linux driver package. */
#define RUN_FLAG 0x40
#define READY_FLAG 0x80
/* Wrapper for dpm_init_master(), takes care of checking for (and optionally
removing) the sycon database if present. */
static short
dpm_init_master_check_sycon_db(io_sAgentLocal *local,
pwr_sClass_Pb_Hilscher *op, io_sAgent *ap)
{
short rv;
DRIVERINFO di;
assert(DRV_NO_ERROR == 0);
/* Initializes DP Master. */
if ((rv = dpm_init_master(local, op, ap)) != DRV_NO_ERROR) {
return rv;
} else if ((rv = DevGetInfo(local->dev_number, GET_DRIVER_INFO,
sizeof(di), &di)) != DRV_NO_ERROR) {
errh_Error("Profibus DP Master %s -"
" DevGetInfo failed with return code %d", ap->Name, rv);
return rv;
} else if ((di.bHostFlags & (READY_FLAG | RUN_FLAG))
== (READY_FLAG | RUN_FLAG)) {
/* RUN and RDY bits set */
errh_Info("Profibus DP Master %s - Hostflags: 0x%X",
ap->Name, di.bHostFlags);
errh_Info("Device is configured by SyCon.");
#ifdef FLASH_WRITE_ENABLE
errh_Info("Deleting SyCon database from board's flash.");
if ((rv = dpm_delete_flash_prmdb(local, ap)) != DRV_NO_ERROR) {
return rv;
} else {
/* Reinitializes DP Master. */
rv = dpm_init_master(local, op, ap);
}
#else /* FLASH_WRITE_ENABLE */
errh_Info("Flash writing is not enabled, ");
flashing_disabled_warning(ap);
return BOARD_INIT_ERROR;
#endif /* FLASH_WRITE_ENABLE */
}
return rv;
}
/*----------------------------------------------------------------------------*\
Init method for the Pb_Hilscher agent
\*----------------------------------------------------------------------------*/
static pwr_tStatus
IoAgentInit(io_tCtx ctx, io_sAgent *ap)
{
pwr_sClass_Pb_Hilscher *op;
pwr_tStatus status;
io_sAgentLocal *local;
char ok;
pwr_tObjid slave_objid;
pwr_tClassId slave_class;
pwr_sClass_Pb_DP_Slave *sop;
char name[196];
struct timespec rqtp = {0, 20000000}; /* 20 ms */
int retry;
/* Allocates area for local data structure */
ap->Local = calloc(1, sizeof(io_sAgentLocal));
if (!ap->Local) {
errh_Error("ERROR config Profibus DP Master %s - %s",
ap->Name, "calloc");
return IO__ERRINIDEVICE;
}
/* Handles for easy access to local variables. */
local = (io_sAgentLocal *) ap->Local;
op = (pwr_sClass_Pb_Hilscher *) ap->op;
op->Status = PB__NOTINIT;
/* Initializes interface. */
if (ctx->Node->Restarts > 0) {
nanosleep(&rqtp, NULL);
}
errh_Info("Initializing interface for Profibus DP Master %s", ap->Name);
/* Initializes local struct. */
local->dev_number = op->BusNumber - 1;
local->input_size = 0;
local->output_size = 0;
local->cif_msgcnt = 0;
local->watchdog = 0;
/* Initializes Profibus driver API. */
if (dpm_init(local, ap) != DRV_NO_ERROR) {
/* Cannot open driver */
op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s",
ap->Name, "open device");
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
/* If this is not the Profibus I/O process, return */
if ((op->Process & io_mProcess_Profibus)
&& (ctx->Process != io_mProcess_Profibus)) {
op->Status = PB__NOTINIT;
errh_Info("Init template I/O agent for Profibus DP Master %s, %d",
ap->Name, ctx->Process );
return IO__SUCCESS;
}
if (ctx->Node->Restarts > 0) {
errh_Info("Warm restart - Skipping config of Profibus DP Master %s",
ap->Name);
op->Status = PB__NORMAL;
return IO__SUCCESS;
}
errh_Info("Config of Profibus DP Master %s", ap->Name);
if (op->DisableBus != 1) {
ok = FALSE;
if (ctx->Node->Restarts == 0) {
retry = 0;
while (!ok) {
op->Status = PB__NOTINIT;
/* Sets DP master parameters and checks for sycon database. */
if (dpm_init_master_check_sycon_db(local, op, ap)
!= DRV_NO_ERROR) {
op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s",
ap->Name, "dp init master");
return IO__ERRINIDEVICE;
}
/* Loops through all slaves (traverse agent's children)
and initializes them. */
op->NumberSlaves = 0;
status = gdh_GetChild(ap->Objid, &slave_objid);
while (ODD(status)) {
status = gdh_GetObjectClass(slave_objid, &slave_class);
status = gdh_ObjidToPointer(slave_objid,
(pwr_tAddress *) &sop);
status = gdh_ObjidToName(slave_objid, (char *) &name,
sizeof(name), cdh_mNName);
errh_Info("Download Profibus DP Slave config - %s", name);
/* Calculates IO offsets and configures the slave. */
if (dpm_download_slave_prm(local, sop, ap, ap->racklist)
!= DRV_NO_ERROR) {
errh_Error("ERROR Init Profibus DP slave %s", name);
}
errh_Info("Profibus DP slave %d: in offs %d, input size %d,"
" out offs %d, out size %d",
sop->SlaveAddress,
sop->OffsetInputs, sop->BytesOfInput,
sop->OffsetOutputs, sop->BytesOfOutput);
op->NumberSlaves++;
status = gdh_GetNextSibling(slave_objid, &slave_objid);
}
/* Downloads the DP bus parameters -- this initiates the
cyclic data exchange. */
if (dpm_download_master_prm(local, op, ap) != DRV_NO_ERROR) {
op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s",
ap->Name, "dp download bus");
return IO__ERRINIDEVICE;
}
ok = TRUE;
} /* End - While !ok */
} /* End - Initialization only if not restart */
} else
op->Status = PB__DISABLED;
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Read method for the Pb_Hilscher agent
\*----------------------------------------------------------------------------*/
static pwr_tStatus
IoAgentRead(io_tCtx ctx, io_sAgent *ap)
{
pwr_sClass_Pb_Hilscher *mp;
pwr_sClass_Pb_DP_Slave *sp;
io_sAgentLocal *local;
io_sRack *slave_list;
pwr_sClass_Pb_Hilscher *op;
unsigned short rv;
int i;
DPM_DIAGNOSTICS diag;
/* Handle for local data structure. */
local = (io_sAgentLocal *) ap->Local;
/*** Data exchange code goes here: ***/
/* Iterates over the slaves on the bus and reads process data from their
respective addresses. This is really the responsibility of the rack level,
however, keeping this code here enables us to confine all the Profibus
board specific code at the agent level. */
for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) {
sp = (pwr_sClass_Pb_DP_Slave *) slave_list->op;
mp = (pwr_sClass_Pb_Hilscher *) ap->op;
if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL
&& sp->DisableSlave != 1 && mp->DisableBus != 1) {
/* Triggers the board's watchdog. */
DevTriggerWatchDog(local->dev_number, WATCHDOG_START,
&local->watchdog);
/* Reads process image from the slave. */
rv = DevExchangeIO(local->dev_number,
0, 0, NULL,
sp->OffsetInputs, sp->BytesOfInput, sp->Inputs,
100);
}
}
/*** Diagnostics collecting code goes here: ***/
local = (io_sAgentLocal *) ap->Local;
op = (pwr_sClass_Pb_Hilscher *) ap->op;
/* If everything is fine we should be in state OPERATE.
Make a poll to see if there are diagnostics, the answer also tells us
if there are any hardware faults. */
if ((op->Process & io_mProcess_Profibus)
&& (ctx->Process != io_mProcess_Profibus))
return IO__SUCCESS;
if (op->DisableBus == 1)
return IO__SUCCESS;
/* Reads the protocol states and checks for errors. */
DevGetTaskState(local->dev_number, 2, 64, &diag);
/* Checks if master is in state OPERATE. */
switch (diag.bDPM_state) {
case OPERATE:
if (op->Status != PB__NORMAL) {
op->Status = PB__NORMAL;
errh_Info("Profibus DP Master %s - Mode changed to OPERATE",
ap->Name);
}
break;
case CLEAR:
if (op->Status != PB__CLEARED) {
op->Status = PB__CLEARED;
errh_Info("Profibus DP Master %s - Mode changed to CLEAR",
ap->Name);
}
break;
case STOP:
if (op->Status != PB__STOPPED) {
op->Status = PB__STOPPED;
errh_Info("Profibus DP Master %s - Mode changed to STOP", ap->Name);
}
break;
case OFFLINE:
if (op->Status != PB__NOTINIT) {
errh_Info("Profibus DP Master %s - Mode changed to OFFLINE",
ap->Name);
op->Status = PB__NOTINIT;
}
break;
default:
errh_Info("Profibus DP Master %s - Unknown mode", ap->Name);
}
/* Outputs some bus related diagnostics (using errh_Info()). */
dpm_print_diag(ap, &diag);
/* Checks if there are any new diagnostics data that we should read from
any of our slaves. */
for (i = 0; i <= 127; ++i) {
/* The abSl_diag data structure is described on page 22 in
dpm_pie.pdf. */
if (diag.abSl_diag[i >> 3] & (1 << (i & 7))) {
/* Request diagnostics from slaves with unread diagnostic data. */
dpm_req_slave_diag(local, i, ap);
}
}
/* The above code requests diagnostics from the slaves
with new diagnostic data. It does not seem to work reliably in
some circumstances though. E.g. if a slave is disconnected and reconnected
before its watchdog times out the diagnostics would not be updated. The
following code covers that case, it is a bit ugly, but works. */
for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) {
sp = (pwr_sClass_Pb_DP_Slave *) slave_list->op;
/* The abSl_state has the same layout as the abSl_diag bitmap. */
if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent &&
diag.abSl_state[sp->SlaveAddress >> 3]
& (1 << (sp->SlaveAddress & 7)))
dpm_req_slave_diag(local, sp->SlaveAddress, ap);
}
/* Collects requested slave diagnostics. */
dpm_update_slave_diag(local, ap->racklist, ap);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb_Hilscher agent
\*----------------------------------------------------------------------------*/
static pwr_tStatus
IoAgentWrite(io_tCtx ctx, io_sAgent *ap)
{
pwr_sClass_Pb_Hilscher *mp;
pwr_sClass_Pb_DP_Slave *sp;
io_sAgentLocal *local;
io_sRack *slave_list;
/* Handle for local data structure. */
local = (io_sAgentLocal *) ap->Local;
/* Iterates over the slaves on the bus and writes process data to their
respective addresses. This is really the rack level's responsibility,
however, keeping this code here enables us to confine all the Profibus
board specific code at the agent level. */
for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) {
sp = (pwr_sClass_Pb_DP_Slave *) slave_list->op;
mp = (pwr_sClass_Pb_Hilscher *) ap->op;
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN)
&& mp->Status == PB__NORMAL
&& (sp->DisableSlave != 1) && (mp->DisableBus != 1)) {
if (sp->BytesOfOutput > 0) {
/* Trigger the board's watchdog. */
DevTriggerWatchDog(local->dev_number, WATCHDOG_START,
&local->watchdog);
/* Writes process image to the slave. */
if (DevExchangeIO(local->dev_number,
sp->OffsetOutputs, sp->BytesOfOutput, sp->Outputs,
0, 0, NULL,
100)
!= DRV_NO_ERROR)
sp->ErrorCount++;
}
}
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/
static pwr_tStatus
IoAgentClose(io_tCtx ctx, io_sAgent *ap)
{
io_sAgentLocal *local;
local = (io_sAgentLocal *) ap->Local;
dpm_exit(local, ap);
free(local);
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Hilscher) = {
pwr_BindIoMethod(IoAgentInit),
pwr_BindIoMethod(IoAgentRead),
pwr_BindIoMethod(IoAgentWrite),
pwr_BindIoMethod(IoAgentClose),
pwr_NullMethod
};
......@@ -27,16 +27,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -46,7 +36,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
......
......@@ -25,15 +25,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -43,7 +34,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
/*----------------------------------------------------------------------------*\
......
......@@ -27,15 +27,6 @@
#include <sys/file.h>
#include <sys/ioctl.h>
#include "keywords.h"
#include "pb_type.h"
#include "pb_conf.h"
#include "pb_if.h"
#include "pb_err.h"
#include "pb_fmb.h"
#include "pb_dp.h"
#include "rt_io_pb_locals.h"
#include "pwr.h"
......@@ -45,7 +36,6 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_profiboard.h"
#include "rt_pb_msg.h"
/*----------------------------------------------------------------------------*\
......
......@@ -54,6 +54,17 @@
#include "rt_io_profiboard.h"
typedef struct {
int hServiceReadDevice; // Handle for Service device
int hServiceWriteDevice; // Handle for Service device
int hDpDataDevice; // Handle for DP-Data device
int hDpsInputDataDevice; // Handle for DP-Slave Input-Data device
int hDpsOutputDataDevice; // Handle for DP-Slave Output-Data device
unsigned char CurrentBoardNumber;
int slave_diag_requested;
int hDpsBoardDevice; // Handle for DP-Slave Output-Data device
} io_sAgentLocal;
#define DP_MAX_SERVICE_RETRY 10
......@@ -807,10 +818,32 @@ static pwr_tStatus IoAgentRead (
T_PROFI_SERVICE_DESCR con_ind_sdb;
T_DP_GET_SLAVE_DIAG_CON FAR *get_slave_diag_con_ptr;
pwr_sClass_Pb_Profiboard *mp;
pwr_sClass_Pb_DP_Slave *sp;
pwr_tUInt16 data_len;
io_sRack *slave_list;
hDevice = (T_PROFI_DEVICE_HANDLE *) ap->Local;
local = (io_sAgentLocal *) ap->Local;
op = (pwr_sClass_Pb_Profiboard *) ap->op;
/* Iterate over the slaves. */
for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) {
sp = (pwr_sClass_Pb_DP_Slave *) slave_list->op;
mp = (pwr_sClass_Pb_Profiboard *) ap->op;
/* Read process data. */
if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL && sp->DisableSlave != 1 && mp->DisableBus != 1) {
data_len = sp->BytesOfInput;
sts = profi_get_data(hDevice, ID_DP_SLAVE_IO_IMAGE, sp->OffsetInputs, &data_len, &sp->Inputs );
}
}
/* If everything is fine we should be in state OPERATE
Make a poll to see if there are diagnostics, the answer also tell us
if there are any hardware faults. In that case, make a reset and a new init. */
......@@ -1003,6 +1036,37 @@ static pwr_tStatus IoAgentWrite (
io_sAgent *ap
)
{
T_PROFI_DEVICE_HANDLE *hDevice;
pwr_tUInt16 sts;
pwr_sClass_Pb_Profiboard *mp;
pwr_sClass_Pb_DP_Slave *sp;
io_sRack *slave_list;
hDevice = (T_PROFI_DEVICE_HANDLE *) ap->Local;
/* Iterate over the slaves. */
for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) {
sp = (pwr_sClass_Pb_DP_Slave *) slave_list->op;
mp = (pwr_sClass_Pb_Profiboard *) ap->op;
// Write the whole I/O output area from local area
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) &&
mp->Status == PB__NORMAL && (sp->DisableSlave != 1) && (mp->DisableBus != 1)) {
if (sp->BytesOfOutput > 0) {
sts = profi_set_data(hDevice, ID_DP_SLAVE_IO_IMAGE, sp->OffsetOutputs, sp->BytesOfOutput, &sp->Outputs);
if (sts != E_OK) sp->ErrorCount++;
}
}
}
return IO__SUCCESS;
}
......
......@@ -53,16 +53,7 @@
#define PB_UDATA_DIAG 1
typedef struct {
int hServiceReadDevice; // Handle for Service device
int hServiceWriteDevice; // Handle for Service device
int hDpDataDevice; // Handle for DP-Data device
int hDpsInputDataDevice; // Handle for DP-Slave Input-Data device
int hDpsOutputDataDevice; // Handle for DP-Slave Output-Data device
unsigned char CurrentBoardNumber;
int slave_diag_requested;
int hDpsBoardDevice; // Handle for DP-Slave Output-Data device
} io_sAgentLocal;
/* io_sAgentLocal now lives in the respective agent modules. */
typedef struct {
int initialized;
......
Pb_Profiboard
Pb_Hilscher
Pb_DP_Slave
Pb_Module
Pb_Di
......
Volume Profibus $ClassVolume 0.0.250.7
Body SysBody 05-SEP-2005 17:51:40.00
Attr NextOix = "_X109"
Attr NextCix = "_X14"
Attr NextOix = "_X115"
Attr NextCix = "_X15"
Attr NextTix[0] = "_X7"
EndBody
Object Type $TypeHier 55 16-JAN-2006 10:07:43.21
......@@ -1969,5 +1969,354 @@ Volume Profibus $ClassVolume 0.0.250.7
EndObject
EndObject
EndObject
!/**
! @Author Ferdinand Hauck
! @Version 1.0
! @Group IO
! @Summary Configures a Hilscher CIF 50-PB (Profibus DP master board)
! Configuresa Hilscher CIF 50-PB (Profibus DP master board).
! Available on GNU/Linux. The object should be named Px, where x is
! the number of the device, e.g. P1. It should in theory be possible
! to run up to four Hilscher Profibus DP master boards in parallel per
! system.
! This class is based on the Softing Profiboard class by Claes Jurstrand.
!*/
Object Pb_Hilscher $ClassDef 14 09-DEC-2008 13:19:56.59
Body SysBody 09-DEC-2008 13:19:32.10
Attr Editor = 0
Attr Method = 1
Attr Flags = 4176
EndBody
Object RtBody $ObjBodyDef 1 09-DEC-2008 13:20:25.79
Body SysBody 09-DEC-2008 13:26:35.55
Attr StructName = "Pb_Hilscher"
Attr NextAix = "_X53"
EndBody
!/**
! Text description of the object (comment).
!*/
Object Description $Attribute 27 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Description"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
! Defines the Proview process that will handle I/O for the bus.
! 1 for the PLC process (default).
!*/
Object Process $Attribute 28 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Process"
Attr TypeRef = "pwrb:Type-IoProcessMask"
EndBody
EndObject
!/**
! Defines which of the PLC threads that will handle I/O for the bus (if Process = 1).
!*/
Object ThreadObject $Attribute 29 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "ThreadObject"
Attr TypeRef = "pwrs:Type-$Objid"
EndBody
EndObject
!/**
! Indicates the current state of the bus in runtime. Updated by the I/O-handler.
! PB__NOTINIT : Bus is not initialized.
! PB__INITFAIL : Bus failed to be initialized.
! PB__DISABLED : Bus is disabled, no I/O-handling will be performed.
! PB__STOPPED : Bus is in stopped mode.
! PB__CLEARED : Bus is in cleared mode.
! PB__NORMAL : Bus is in operating mode (this should be the normal state when running).
!*/
Object Status $Attribute 30 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Status"
Attr Flags = 3072
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
!/**
! Flag that disables the initialization of the bus, if initialized turns off I/O-handling.
!*/
Object DisableBus $Attribute 31 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "DisableBus"
Attr Flags = 3072
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Number of configured slaves in the bus. Updated by the I/O-handler.
!*/
Object NumberSlaves $Attribute 32 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "NumberSlaves"
Attr Flags = 3072
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Number of the bus. This value is independent for different agent
! classes, so if you mix boards from different vendors, the agent
! objects for the cards will share BusNumber in some cases.
! It should be possible to attach up to four Hilscher Profibus DP
! master boards to each system.
!*/
Object BusNumber $Attribute 33 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "BusNumber"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Baud rate for the bus in Kbit/s. Possible values are 500, 1500, 3000, 6000, 12000.
! Note that the values for some of the following attributes are depending on the
! baud rate.
!*/
Object BaudRate $Attribute 37 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "BaudRate"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Watchdog timer for write supervision in the master card. This watchdog is
! activated at the first write operation after initialization. If the timer later
! elapses without a write operation, the master card will reset itself, and the bus
! will stop, leaving all slaves to stall when their own stall time elapses.
! A value of 0 will disable the board's watchdog functionality altogether.
! Range 0..65535 ms
!*/
Object StallTime $Attribute 38 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "StallTime"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Slot time, the maximum time a master station must wait for a transaction response.
! Range 37..16383 Bit Times.
! Recommended values for each baud rate:
! 500 kbit/s - 200
! 1500 kbit/s - 300
! 3000 kbit/s - 400
! 6000 kbit/s - 600
! 12000 kbit/s - 1000
!*/
Object Tsl $Attribute 39 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Tsl"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Minimum station delay time for responder, the period of time which may elapse before
! the responder can send the response frame. Range 11..1023 Bit Times.
! Recommended values for each baud rate:
! 500 kbit/s - 11
! 1500 kbit/s - 11
! 3000 kbit/s - 11
! 6000 kbit/s - 11
! 12000 kbit/s - 11
!*/
Object MinTsdr $Attribute 40 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "MinTsdr"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Maximum station delay time for responder, the responder has to send the response frame
! before this time is elapsed. Range 37..2^16-1 Bit Times.
! Recommended values for each baud rate:
! 500 kbit/s - 100
! 1500 kbit/s - 150
! 3000 kbit/s - 250
! 6000 kbit/s - 450
! 12000 kbit/s - 800
!*/
Object MaxTsdr $Attribute 41 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "MaxTsdr"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Quiet time, the period of time which a transmitting station must wait after the end of a frame
! before enabling its receiver. It is significant when using repeaters. Range 0..493 Bit Times.
! Recommended values for each baud rate:
! 500 kbit/s - 0
! 1500 kbit/s - 0
! 3000 kbit/s - 3
! 6000 kbit/s - 6
! 12000 kbit/s - 9
!*/
Object Tqui $Attribute 42 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Tqui"
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Setup time, the time between the occurrence of an interrupt request and the necessary request
! action is performed. Range 1..494-Tqui BitTimes.
! Recommended values for each baud rate:
! 500 kbit/s - 1
! 1500 kbit/s - 1
! 3000 kbit/s - 4
! 6000 kbit/s - 8
! 12000 kbit/s - 16
!*/
Object Tset $Attribute 43 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Tset"
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Target rotation time, the anticipated time for one token rotation on the bus, including
! allowances for high and low priority transactions and GAP maintenance.
! Range 256..2^24-1 Bit Times.
! The value is irrelevant in Profibus DP operations.
!*/
Object Ttr $Attribute 44 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Ttr"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
!/**
! Gap update factor, defines the number of token rotations between GAP maintenance cycles.
! Range 1..100.
! Recommended values for each baud rate:
! 500 kbit/s - 1
! 1500 kbit/s - 10
! 3000 kbit/s - 10
! 6000 kbit/s - 10
! 12000 kbit/s - 10
!*/
Object G $Attribute 45 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "G"
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Highest station address. Range 1..126.
!*/
Object Hsa $Attribute 46 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Hsa"
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Maximum retry limit, indicates how often FDL has to repeat the request frame when no response
! or acknowledge frame is receive from the recognized station within the slot time. Range 0..7.
! Recommended values for each baud rate:
! 500 kbit/s - 1
! 1500 kbit/s - 1
! 3000 kbit/s - 2
! 6000 kbit/s - 3
! 12000 kbit/s - 4
!*/
Object MaxRetryLimit $Attribute 47 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "MaxRetryLimit"
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Bus parameter flag. Should not be changed from the default value.
!*/
Object BpFlag $Attribute 48 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "BpFlag"
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
!/**
! Data exchange cycle time in 100 us. Should not be changed from the default value.
!*/
Object MinSlaveInterval $Attribute 49 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "MinSlaveInterval"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Watchdog timer for Master to Master communication.
!*/
Object PollTimeout $Attribute 50 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "PollTimeout"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Control interval for global control status reports of the DP master.
!*/
Object DataControlTime $Attribute 51 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "DataControlTime"
Attr TypeRef = "pwrs:Type-$UInt16"
EndBody
EndObject
!/**
! Area for receiving diagnostic data from the master. Not implemented yet.
!*/
Object Diag $Attribute 52 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:19:32.10
Attr PgmName = "Diag"
Attr Flags = 3074
Attr Elements = 256
Attr TypeRef = "pwrs:Type-$UInt8"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 110 09-DEC-2008 13:19:32.10
Object IoAgentInit $Method 111 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:20:59.19
Attr MethodName = "Pb_Hilscher-IoAgentInit"
EndBody
EndObject
Object IoAgentClose $Method 112 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:21:12.28
Attr MethodName = "Pb_Hilscher-IoAgentClose"
EndBody
EndObject
Object IoAgentRead $Method 113 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:21:25.05
Attr MethodName = "Pb_Hilscher-IoAgentRead"
EndBody
EndObject
Object IoAgentWrite $Method 114 09-DEC-2008 13:19:32.10
Body SysBody 09-DEC-2008 13:21:42.78
Attr MethodName = "Pb_Hilscher-IoAgentWrite"
EndBody
EndObject
EndObject
Object Template Pb_Hilscher 2151383040 01-JAN-1970 01:00:00.00
Body RtBody 09-DEC-2008 13:24:06.12
Attr Process = 1
Attr BusNumber = 1
Attr BaudRate = 12000
Attr StallTime = 3000
Attr Tsl = 1000
Attr MinTsdr = 11
Attr MaxTsdr = 800
Attr Tqui = 9
Attr Tset = 16
Attr Ttr = 300000
Attr G = 10
Attr Hsa = 126
Attr MaxRetryLimit = 4
Attr MinSlaveInterval = 1
Attr PollTimeout = 1000
Attr DataControlTime = 100
EndBody
EndObject
EndObject
EndObject
EndVolume
......@@ -264,6 +264,7 @@ palette NavigatorPalette
menu Masters
{
class Pb_Profiboard
class Pb_Hilscher
}
menu Slaves
{
......
......@@ -460,7 +460,7 @@ menu Components
subgraph FlowSensor pwr_exe:bcomp_flowsensor.pwsg 16
subgraph FcPPO3MotorAggr pwr_exe:bcomp_basefcppo3motoraggr.pwsg 23
subgraph FcPPO3FanAggr pwr_exe:bcomp_basefcppo3fanaggr.pwsg 71
subgraph FcPPO3umpAggr pwr_exe:bcomp_basefcppo3pumpaggr.pwsg 72
subgraph FcPPO3PumpAggr pwr_exe:bcomp_basefcppo3pumpaggr.pwsg 72
subgraph FcPPO5MotorAggr pwr_exe:bcomp_basefcppo5motoraggr.pwsg 23
subgraph FcPPO5FanAggr pwr_exe:bcomp_basefcppo5fanaggr.pwsg 71
subgraph FcPPO5umpAggr pwr_exe:bcomp_basefcppo5pumpaggr.pwsg 72
......
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