Commit 8493264f authored by claes's avatar claes

Di and Do in module design

parent 5c82d04c
/*
* Proview $Id: rt_io_m_pb_dp_slave.c,v 1.2 2006-01-16 13:56:52 claes Exp $
* Proview $Id: rt_io_m_pb_dp_slave.c,v 1.3 2006-04-12 12:16:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -45,7 +45,31 @@
#include "rt_io_profiboard.h"
#include "rt_pb_msg.h"
pwr_tInt32 GetChanSize(pwr_eDataRepEnum rep)
{
switch (rep) {
case pwr_eDataRepEnum_Int64:
case pwr_eDataRepEnum_UInt64:
case pwr_eDataRepEnum_Float64:
return 8;
break;
case pwr_eDataRepEnum_Bit32:
case pwr_eDataRepEnum_Int32:
case pwr_eDataRepEnum_UInt32:
case pwr_eDataRepEnum_Float32:
return 4;
break;
case pwr_eDataRepEnum_Bit16:
case pwr_eDataRepEnum_Int16:
case pwr_eDataRepEnum_UInt16:
return 2;
break;
default:
return 1;
break;
}
}
/*----------------------------------------------------------------------------*\
Init method for the Pb DP slave
\*----------------------------------------------------------------------------*/
......@@ -70,6 +94,17 @@ static pwr_tStatus IoRackInit (
char name[196];
pwr_tStatus sts;
pwr_tCid cid;
io_sChannel *chanp;
int i, latent_input_count, latent_output_count;
pwr_tInt32 chan_size;
pwr_sClass_ChanDi *chan_di;
pwr_sClass_ChanDo *chan_do;
pwr_sClass_ChanAi *chan_ai;
pwr_sClass_ChanAit *chan_ait;
pwr_sClass_ChanIi *chan_ii;
pwr_sClass_ChanAo *chan_ao;
pwr_sClass_ChanIo *chan_io;
sts = gdh_ObjidToName(rp->Objid, (char *) &name, sizeof(name), cdh_mNName);
errh_Info( "Init of Profibus DP Slave and modules %s", name);
......@@ -144,10 +179,104 @@ static pwr_tStatus IoRackInit (
case pwr_cClass_Pb_Module:
mp = (pwr_sClass_Pb_Module *) cardp->op;
// iop->OffsetOutputs = output_counter;
// iop->BytesOfOutput = iop->NumberOfChannels * iop->BytesPerChannel;
// output_counter += iop->BytesOfOutput;
mp->Status = PB__SUCCESS;
mp->Status = PB__NOTINIT;
cardp->offset = 0;
latent_input_count = 0;
latent_output_count = 0;
for (i=0; i<cardp->ChanListSize; i++) {
chanp = &cardp->chanlist[i];
if (chanp->ChanClass != pwr_cClass_ChanDi) {
input_counter += latent_input_count;
latent_input_count = 0;
}
if (chanp->ChanClass != pwr_cClass_ChanDo) {
output_counter += latent_output_count;
latent_output_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;
}
chanp->offset = input_counter;
chanp->mask = 1<<chan_di->Number;
if (chan_di->Number == 0) latent_input_count = GetChanSize(chan_di->Representation);
printf("Di channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_di->Number, chanp->offset);
break;
case pwr_cClass_ChanAi:
chan_ai = (pwr_sClass_ChanAi *) chanp->cop;
chanp->offset = input_counter;
chan_size = GetChanSize(chan_ai->Representation);
chanp->size = chan_size;
chanp->mask = 0;
input_counter += chan_size;
io_AiRangeToCoef(chanp);
printf("Ai channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ai->Number, chanp->offset);
break;
case pwr_cClass_ChanAit:
chan_ait = (pwr_sClass_ChanAit *) chanp->cop;
chanp->offset = input_counter;
chan_size = GetChanSize(chan_ait->Representation);
chanp->size = chan_size;
chanp->mask = 0;
input_counter += chan_size;
io_AiRangeToCoef(chanp);
break;
case pwr_cClass_ChanIi:
chan_ii = (pwr_sClass_ChanIi *) chanp->cop;
chanp->offset = input_counter;
chan_size = GetChanSize(chan_ii->Representation);
chanp->size = chan_size;
chanp->mask = 0;
input_counter += chan_size;
break;
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;
}
chanp->offset = output_counter;
chan_size = GetChanSize(chan_do->Representation);
chanp->mask = 1<<chan_do->Number;
if (chan_do->Number == 0) latent_output_count = GetChanSize(chan_do->Representation);
printf("Do channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_do->Number, chanp->offset);
break;
case pwr_cClass_ChanAo:
chan_ao = (pwr_sClass_ChanAo *) chanp->cop;
chanp->offset = output_counter;
chan_size = GetChanSize(chan_ao->Representation);
chanp->size = chan_size;
chanp->mask = 0;
output_counter += chan_size;
io_AoRangeToCoef(chanp);
printf("Ao channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_ao->Number, chanp->offset);
break;
case pwr_cClass_ChanIo:
chan_io = (pwr_sClass_ChanIo *) chanp->cop;
chanp->offset = output_counter;
chan_size = GetChanSize(chan_io->Representation);
chanp->size = chan_size;
chanp->mask = 0;
output_counter += chan_size;
break;
}
}
mp->Status = PB__NOCONN;
break;
}
......@@ -179,22 +308,22 @@ static pwr_tStatus IoRackRead (
sp = (pwr_sClass_Pb_DP_Slave *) rp->op;
mp = (pwr_sClass_Pb_Profiboard *) ap->op;
if (sp->Status > PB_SLAVE_STATE_NOTINIT && mp->Status == PB_MASTER_STATE_OPERATE && sp->DisableSlave != 1 && mp->DisableBus != 1) {
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) && mp->Status == PB__NORMAL && sp->DisableSlave != 1 && mp->DisableBus != 1) {
sts = pb_cmi_get_data(fp, ID_DP_STATUS_IMAGE, sp->SlaveAddress, 1, &diag);
if ((sts != PB_OK) || (diag & 1)) {
sp->Status = PB_SLAVE_STATE_STOPPED;
sp->Status = PB__NOCONN;
sp->ErrorCount++;
if (sp->ErrorCount > sp->ErrorSoftLimit && sp->StallAction >= PB_STALLACTION_RESET) {
memset(&sp->Inputs, 0, sp->BytesOfInput);
}
}
else {
sp->Status = PB_SLAVE_STATE_OPERATE;
sp->Status = PB__NORMAL;
}
if ((sp->Status > PB_SLAVE_STATE_STOPPED) && sp->BytesOfInput > 0) {
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) && sp->BytesOfInput > 0) {
sts = pb_cmi_get_data(fp,
ID_DP_SLAVE_IO_IMAGE,
......@@ -211,6 +340,8 @@ static pwr_tStatus IoRackRead (
if (sp->ErrorCount > sp->ErrorHardLimit && sp->StallAction >= PB_STALLACTION_BREAK)
ctx->Node->EmergBreakTrue = 1;
}
if (sp->DisableSlave == 1 || mp->DisableBus == 1) sp->Status = PB__DISABLED;
return IO__SUCCESS;
}
......@@ -237,7 +368,7 @@ static pwr_tStatus IoRackWrite (
// Write the whole I/O output area from local area
if (sp->Status > PB_SLAVE_STATE_NOTINIT && mp->Status == PB_MASTER_STATE_OPERATE && sp->DisableSlave != 1 && mp->DisableBus != 1) {
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) && mp->Status == PB__NORMAL && sp->DisableSlave != 1 && mp->DisableBus != 1) {
if (sp->BytesOfOutput > 0) {
......@@ -251,6 +382,8 @@ static pwr_tStatus IoRackWrite (
}
}
if (sp->DisableSlave == 1 || mp->DisableBus == 1) sp->Status = PB__DISABLED;
return IO__SUCCESS;
}
......
/*
* Proview $Id: rt_io_m_pb_module.c,v 1.2 2006-01-16 13:56:52 claes Exp $
* Proview $Id: rt_io_m_pb_module.c,v 1.3 2006-04-12 12:16:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -42,29 +42,6 @@
#include "rt_io_profiboard.h"
#include "rt_pb_msg.h"
pwr_tInt32 GetChanSize(pwr_eDataRepEnum rep)
{
switch (rep) {
case pwr_eDataRepEnum_Int64:
case pwr_eDataRepEnum_UInt64:
case pwr_eDataRepEnum_Float64:
return 8;
break;
case pwr_eDataRepEnum_Int32:
case pwr_eDataRepEnum_UInt32:
case pwr_eDataRepEnum_Float32:
return 4;
break;
case pwr_eDataRepEnum_Int16:
case pwr_eDataRepEnum_UInt16:
return 2;
break;
default:
return 1;
break;
}
}
/*----------------------------------------------------------------------------*\
Convert ai from raw float value to signal value and actual value
\*----------------------------------------------------------------------------*/
......@@ -136,101 +113,16 @@ static pwr_tStatus IoCardInit (
{
io_sCardLocal *local;
pwr_sClass_Pb_Module *op;
int i, input_count, output_count, chan_size, bit_pos;
io_sChannel *chanp;
pwr_sClass_ChanAi *chan_ai;
pwr_sClass_ChanAit *chan_ait;
pwr_sClass_ChanIi *chan_ii;
pwr_sClass_ChanAo *chan_ao;
pwr_sClass_ChanIo *chan_io;
int i;
op = (pwr_sClass_Pb_Module *) cp->op;
local = (io_sCardLocal *) cp->Local;
if (op->Status == PB__SUCCESS) {
input_count = 0;
output_count = 0;
bit_pos = 0;
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
switch (chanp->ChanClass) {
/*
case pwr_cClass_ChanDi:
printf("Di channel found in %s\n", cp->Name);
chan_di = (pwr_sClass_ChanDi *) chanp->cop;
chanp->offset = byte_count;
chan_size = GetChanSize(chan_di->Representation);
chanp->mask = 1<<bit_pos;
bit_pos++;
if (bit_pos >= 8) {
byte_count++;
bit_pos = 0;
}
break;
*/
case pwr_cClass_ChanAi:
// printf("Ai channel found in %s\n", cp->Name);
chan_ai = (pwr_sClass_ChanAi *) chanp->cop;
chanp->offset = input_count;
chan_size = GetChanSize(chan_ai->Representation);
chanp->size = chan_size;
chanp->mask = 0;
input_count += chan_size;
io_AiRangeToCoef(chanp);
break;
case pwr_cClass_ChanAit:
// printf("Ait channel found in %s\n", cp->Name);
chan_ait = (pwr_sClass_ChanAit *) chanp->cop;
chanp->offset = input_count;
chan_size = GetChanSize(chan_ait->Representation);
chanp->size = chan_size;
chanp->mask = 0;
input_count += chan_size;
io_AiRangeToCoef(chanp);
break;
case pwr_cClass_ChanIi:
// printf("Ii channel found in %s\n", cp->Name);
chan_ii = (pwr_sClass_ChanIi *) chanp->cop;
chanp->offset = input_count;
chan_size = GetChanSize(chan_ii->Representation);
chanp->size = chan_size;
chanp->mask = 0;
input_count += chan_size;
break;
case pwr_cClass_ChanAo:
// printf("Ao channel found in %s\n", cp->Name);
chan_ao = (pwr_sClass_ChanAo *) chanp->cop;
chanp->offset = output_count;
chan_size = GetChanSize(chan_ao->Representation);
chanp->size = chan_size;
chanp->mask = 0;
output_count += chan_size;
io_AoRangeToCoef(chanp);
break;
case pwr_cClass_ChanIo:
// printf("Io channel found in %s\n", cp->Name);
chan_io = (pwr_sClass_ChanIo *) chanp->cop;
chanp->offset = output_count;
chan_size = GetChanSize(chan_io->Representation);
chanp->size = chan_size;
chanp->mask = 0;
output_count += chan_size;
break;
}
}
for (i=0; i<IO_MAXCHAN; i++) {
local->scancount[i] = 0;
}
}
else {
errh_Info( "Error initializing Pb module %s", cp->Name );
op->Status = PB__INITFAIL;
for (i=0; i<IO_MAXCHAN; i++) {
local->scancount[i] = 0;
}
printf("Method Pb_Module-IoCardInit\n");
printf("Module size: input %d, output %d\n", input_count, output_count);
op->Status = PB__NORMAL;
return IO__SUCCESS;
}
......@@ -249,7 +141,8 @@ static pwr_tStatus IoCardRead (
io_sCardLocal *local;
pwr_sClass_Pb_Module *op;
io_sChannel *chanp;
// pwr_sClass_ChanDi *chan_di;
pwr_sClass_ChanDi *chan_di;
pwr_sClass_Di *sig_di;
pwr_sClass_ChanAi *chan_ai;
pwr_sClass_Ai *sig_ai;
// pwr_sClass_ChanAit *chan_ait;
......@@ -268,26 +161,47 @@ static pwr_tStatus IoCardRead (
op = (pwr_sClass_Pb_Module *) cp->op;
local = (io_sCardLocal *) cp->Local;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (slave->Status == PB_SLAVE_STATE_NOTINIT) {
op->Status = PB__INITFAIL;
}
else if (slave->Status == PB_SLAVE_STATE_STOPPED) {
op->Status = PB__NOCONN;
}
else if (slave->Status == PB_SLAVE_STATE_OPERATE) {
op->Status = PB__NORMAL;
}
if (slave->DisableSlave == 1) {
op->Status = PB__DISABLED;
}
else {
op->Status = slave->Status;
if (op->Status == PB__NORMAL) {
for (i=0; i<cp->ChanListSize; i++) {
chanp = &cp->chanlist[i];
switch (chanp->ChanClass) {
// Channel type is Di (digital input)
case pwr_cClass_ChanDi:
chan_di = (pwr_sClass_ChanDi *) chanp->cop;
sig_di = (pwr_sClass_Di *) chanp->sop;
if (chan_di && sig_di && chan_di->ConversionOn) {
switch (chan_di->Representation) {
case pwr_eDataRepEnum_Bit8:
memcpy(&udata8, local->input_area + cp->offset + chanp->offset, 1);
* (pwr_tUInt16 *) (chanp->vbp) = ((udata8 & chanp->mask) != 0);
break;
case pwr_eDataRepEnum_Bit16:
memcpy(&udata16, local->input_area + cp->offset + chanp->offset, 2);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) udata16 = swap16(udata16);
* (pwr_tUInt16 *) (chanp->vbp) = ((udata16 & chanp->mask) != 0);
break;
case pwr_eDataRepEnum_Bit32:
memcpy(&udata32, local->input_area + cp->offset + chanp->offset, 4);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) udata32 = swap32(udata32);
* (pwr_tUInt16 *) (chanp->vbp) = ((udata32 & chanp->mask) != 0);
break;
}
// Invert ?
if (chan_di->InvertOn) * (pwr_tUInt16 *) (chanp->vbp) ^= 1;
}
break;
// Channel type is Ai (analog input)
......@@ -335,6 +249,13 @@ static pwr_tStatus IoCardRead (
f_raw = (float) udata32;
break;
case pwr_eDataRepEnum_Float32:
memcpy(&udata32, local->input_area + cp->offset + chanp->offset, 4);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian ||
slave->FloatRepresentation == pwr_ePbNumberRep_FloatIEEE) udata32 = swap32(udata32);
memcpy(&f_raw, &udata32, 4);
break;
}
sig_ai->RawValue = 0;
......@@ -416,8 +337,8 @@ static pwr_tStatus IoCardWrite (
pwr_sClass_Pb_Module *op;
io_sChannel *chanp;
// pwr_sClass_ChanDo *chan_do;
// pwr_sClass_Do *sig_do;
pwr_sClass_ChanDo *chan_do;
pwr_sClass_Do *sig_do;
pwr_sClass_ChanAo *chan_ao;
pwr_sClass_Ao *sig_ao;
pwr_sClass_ChanIo *chan_io;
......@@ -425,6 +346,7 @@ static pwr_tStatus IoCardWrite (
pwr_sClass_Pb_DP_Slave *slave;
pwr_tUInt8 udata8 = 0;
pwr_tUInt8 *udata8p;
pwr_tUInt16 udata16 = 0;
pwr_tUInt32 udata32 = 0;
pwr_tInt8 data8 = 0;
......@@ -438,20 +360,9 @@ static pwr_tStatus IoCardWrite (
local = (io_sCardLocal *) cp->Local;
slave = (pwr_sClass_Pb_DP_Slave *) rp->op;
if (slave->Status == PB_SLAVE_STATE_NOTINIT) {
op->Status = PB__INITFAIL;
}
else if (slave->Status == PB_SLAVE_STATE_STOPPED) {
op->Status = PB__NOCONN;
}
else if (slave->Status == PB_SLAVE_STATE_OPERATE) {
op->Status = PB__NORMAL;
}
if (slave->DisableSlave == 1) {
op->Status = PB__DISABLED;
}
else {
op->Status = slave->Status;
if (op->Status == PB__NORMAL) {
fixout = ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT;
......@@ -460,6 +371,38 @@ static pwr_tStatus IoCardWrite (
switch (chanp->ChanClass) {
case pwr_cClass_ChanDo:
chan_do = (pwr_sClass_ChanDo *) chanp->cop;
sig_do = (pwr_sClass_Do *) chanp->sop;
if (chan_do && sig_do) {
if (fixout) {}
switch (chan_do->Representation) {
case pwr_eDataRepEnum_Bit8:
udata8p = local->output_area + cp->offset + chanp->offset;
if (*(pwr_tInt32 *) chanp->vbp != 0)
*udata8p |= chanp->mask;
else
*udata8p &= ~chanp->mask;
break;
/*
case pwr_eDataRepEnum_Bit16:
memcpy(&udata16, local->input_area + cp->offset + chanp->offset, 2);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) udata16 = swap16(udata16);
* (pwr_tUInt16 *) (chanp->vbp) = ((udata16 & chanp->mask) != 0);
break;
case pwr_eDataRepEnum_Bit32:
memcpy(&udata32, local->input_area + cp->offset + chanp->offset, 4);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian) udata32 = swap32(udata32);
* (pwr_tUInt16 *) (chanp->vbp) = ((udata32 & chanp->mask) != 0);
break;
*/
}
}
break;
// Channel type is Ao (analog output)
......@@ -529,6 +472,13 @@ static pwr_tStatus IoCardWrite (
memcpy(local->output_area + cp->offset + chanp->offset, &udata32, 4);
break;
case pwr_eDataRepEnum_Float32:
memcpy(&udata32, &rawvalue, 4);
if (slave->ByteOrdering == pwr_eByteOrdering_BigEndian ||
slave->FloatRepresentation == pwr_ePbNumberRep_FloatIEEE) udata32 = swap32(udata32);
memcpy(local->output_area + cp->offset + chanp->offset, &udata32, 4);
break;
}
}
......
/*
* Proview $Id: rt_io_m_pb_profiboard.c,v 1.2 2006-01-16 13:56:52 claes Exp $
* Proview $Id: rt_io_m_pb_profiboard.c,v 1.3 2006-04-12 12:16:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -44,6 +44,7 @@
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_agent_init.h"
#include "rt_pb_msg.h"
#include "rt_io_profiboard.h"
......@@ -284,9 +285,9 @@ static pwr_tStatus init_dp_slave (
local_agent = (io_sAgentLocal *) (ap->Local);
op->Status = PB_SLAVE_STATE_NOTINIT;
op->Status = PB__NOTINIT;
errh_Info( "Config of Profibus DP Slave %s", name );
errh_Info( "Download Profibus DP Slave config - %s", name );
// Try to initialize slave, make three attempts before we give up
......@@ -327,11 +328,12 @@ static pwr_tStatus init_dp_slave (
nanosleep(&rqtp, &rmtp);
}
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR Init Profibus DP slave %s", name);
return IO__ERRINIDEVICE;
}
op->Status = PB_SLAVE_STATE_STOPPED;
op->Status = PB__NOCONN;
return IO__SUCCESS;
}
......@@ -368,6 +370,8 @@ static pwr_tStatus IoAgentInit (
local = (io_sAgentLocal *) ap->Local;
op = (pwr_sClass_Pb_Profiboard *) ap->op;
op->Status = PB__NOTINIT;
/* Open Pb driver */
sprintf(devname, "/dev/pbus%1d", (int)op->BusNumber);
local->Pb_fp = open(devname, O_RDWR);
......@@ -375,6 +379,7 @@ static pwr_tStatus IoAgentInit (
if (local->Pb_fp == -1)
{
/* Can't open driver */
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "open device");
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
......@@ -383,6 +388,7 @@ static pwr_tStatus IoAgentInit (
/* 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;
}
......@@ -395,10 +401,13 @@ static pwr_tStatus IoAgentInit (
while (!ok) {
op->Status = PB__NOTINIT;
/* Initialize CMI */
sts = pb_cmi_init(local->Pb_fp);
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "cmi init");
return IO__ERRINIDEVICE;
}
......@@ -407,6 +416,7 @@ static pwr_tStatus IoAgentInit (
sts = fmb_set_configuration(local->Pb_fp, op);
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "fmb set configuration");
return IO__ERRINIDEVICE;
}
......@@ -415,6 +425,7 @@ static pwr_tStatus IoAgentInit (
sts = dp_init_master(local->Pb_fp, op);
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "dp init master");
return IO__ERRINIDEVICE;
}
......@@ -422,6 +433,7 @@ static pwr_tStatus IoAgentInit (
/* Set DP bus parameters */
sts = dp_init_bus(local->Pb_fp, op);
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "dp init bus");
return IO__ERRINIDEVICE;
}
......@@ -430,6 +442,7 @@ static pwr_tStatus IoAgentInit (
sts = pb_set_stalltime(local->Pb_fp, op->StallTime);
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "set stalltime");
return IO__ERRINIDEVICE;
}
......@@ -437,11 +450,12 @@ static pwr_tStatus IoAgentInit (
/* Move to STOP mode */
sts = act_param_loc(local->Pb_fp, op, DP_OP_MODE_STOP);
if (sts != PB_OK) {
op->Status = PB__INITFAIL;
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to STOPPED");
return IO__ERRINIDEVICE;
}
op->Status = PB_MASTER_STATE_STOPPED;
op->Status = PB__STOPPED;
/* Loop through all slaves (traverse agent's children) and initialize them */
......@@ -450,10 +464,9 @@ static pwr_tStatus IoAgentInit (
while (ODD(status)) {
status = gdh_GetObjectClass(slave_objid, &slave_class);
if (slave_class == pwr_cClass_Pb_DP_Slave ) {
status = init_dp_slave(ap, slave_objid);
op->NumberSlaves++;
}
// printf("Found slave, class %d\n", slave_class);
status = init_dp_slave(ap, slave_objid);
op->NumberSlaves++;
status = gdh_GetNextSibling(slave_objid, &slave_objid);
}
......@@ -461,19 +474,19 @@ static pwr_tStatus IoAgentInit (
sts = act_param_loc(local->Pb_fp, op, DP_OP_MODE_CLEAR);
if (sts == PB_OK) {
op->Status = PB_MASTER_STATE_CLEARED;
op->Status = PB__CLEARED;
sts = act_param_loc(local->Pb_fp, op, DP_OP_MODE_OPERATE);
if (sts == PB_OK) {
op->Status = PB_MASTER_STATE_OPERATE;
op->Status = PB__NORMAL;
errh_Info( "Profibus DP Master %s to state OPERATE", ap->Name);
}
else {
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to OPERATE");
errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to OPERATE");
return IO__ERRINIDEVICE;
}
}
else {
errh_Info( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to CLEAR");
errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to CLEAR");
return IO__ERRINIDEVICE;
}
......@@ -494,6 +507,8 @@ static pwr_tStatus IoAgentInit (
}
}
else
op->Status = PB__DISABLED;
return IO__SUCCESS;
}
......@@ -528,12 +543,12 @@ static pwr_tStatus IoAgentRead (
switch (op->Status) {
case PB_MASTER_STATE_OPERATE:
case PB__NORMAL:
sts = pb_cmi_poll(local->Pb_fp, NULL, NULL, NULL);
/* In case of device error, move to state NOTINIT */
if (sts == PB_DEVICE_ERROR) {
op->Status = PB_MASTER_STATE_NOTINIT;
op->Status = PB__NOTINIT;
}
/* In case of diagnostic message, just mark it.
in the future, take care of it */
......@@ -543,7 +558,7 @@ static pwr_tStatus IoAgentRead (
break;
default:
op->Status = PB_MASTER_STATE_NOTINIT;
op->Status = PB__NOTINIT;
errh_Info( "Reconfig of Profibus DP Master %s - %d", ap->Name, count );
IoAgentClose(ctx, ap);
IoAgentInit(ctx, ap);
......
/*
* Proview $Id: rt_io_pb_locals.h,v 1.1 2006-01-16 10:55:42 claes Exp $
* Proview $Id: rt_io_pb_locals.h,v 1.2 2006-04-12 12:16:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -19,17 +19,20 @@
#define IO_MAXCHAN 96
// These status constants are obsolete from V4.1, except for the old style
// (Pb_Di, Pb_Do etc)
#define PB_MODULE_STATE_NOTINIT 0
#define PB_MODULE_STATE_OPERATE 1
#define PB_SLAVE_STATE_NOTINIT 0
#define PB_SLAVE_STATE_STOPPED 1
#define PB_SLAVE_STATE_OPERATE 2
//#define PB_SLAVE_STATE_NOTINIT 0
//#define PB_SLAVE_STATE_STOPPED 1
//#define PB_SLAVE_STATE_OPERATE 2
#define PB_MASTER_STATE_NOTINIT 0
#define PB_MASTER_STATE_STOPPED 1
#define PB_MASTER_STATE_CLEARED 2
#define PB_MASTER_STATE_OPERATE 3
//#define PB_MASTER_STATE_NOTINIT 0
//#define PB_MASTER_STATE_STOPPED 1
//#define PB_MASTER_STATE_CLEARED 2
//#define PB_MASTER_STATE_OPERATE 3
#define PB_STALLACTION_NONE 0
#define PB_STALLACTION_RESET 1
......
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