Commit 60f6ed3d authored by Claes Sjöfors's avatar Claes Sjöfors

Profibus merged

parent b12b2d08
...@@ -831,7 +831,7 @@ typedef struct T_SET_CONFIGURATION_REQ ...@@ -831,7 +831,7 @@ typedef struct T_SET_CONFIGURATION_REQ
max_nr_of_sap_buffers; /* max # of SAP-Buffers (all CR) */ max_nr_of_sap_buffers; /* max # of SAP-Buffers (all CR) */
USIGN16 max_nr_of_poll_list_entries; /* max # of Poll-List-Entries USIGN16 max_nr_of_poll_list_entries; /* max # of Poll-List-Entries
(all CR) */ (all CR) */
USIGN16 max_data_buffer_size; /* max size of FMS-/FMA7-PDU-Buffer */ USIGN16 max_data_buffer_size; /* max size of FMS-/FMA7-PDU-Buffer */
} T_SET_CONFIGURATION_REQ; } T_SET_CONFIGURATION_REQ;
#endif #endif
......
...@@ -108,7 +108,7 @@ extern "C" { ...@@ -108,7 +108,7 @@ extern "C" {
#define MODE_MODUL_MCL 13 /* Command: B_SYSFKT */ #define MODE_MODUL_MCL 13 /* Command: B_SYSFKT */
#define MODE_DISTRIBUTOR_DRIVER \ #define MODE_DISTRIBUTOR_DRIVER \
14 /* Command: B_SYSFKT ->function 1 = insert \ 14 /* Command: B_SYSFKT ->function 1 = insert \
*/ */
#define MODE_PRINT_DRIVER 15 /* Command: B_SYSFKT */ #define MODE_PRINT_DRIVER 15 /* Command: B_SYSFKT */
#define MODE_GET_RCS_ERROR 16 /* Command: B_SYSFKT */ #define MODE_GET_RCS_ERROR 16 /* Command: B_SYSFKT */
......
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8, void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8,
pwr_tUInt16 rawvalue16, pwr_tUInt32 rawvalue32, pwr_tFloat32* actvalue_p, pwr_tUInt16 rawvalue16, pwr_tUInt32 rawvalue32,
pwr_tEnum representation) pwr_tFloat32* actvalue_p, pwr_tEnum representation)
{ {
pwr_tFloat32 sigvalue; pwr_tFloat32 sigvalue;
...@@ -66,24 +66,30 @@ void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8, ...@@ -66,24 +66,30 @@ void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8,
pwr_tFloat32 f_raw = 0.0; pwr_tFloat32 f_raw = 0.0;
int i; int i;
if (nobits == 32) { if (nobits == 32)
{
if (representation == PB_NUMREP_SIGNEDINT) if (representation == PB_NUMREP_SIGNEDINT)
f_raw = (float)((int)rawvalue32); f_raw = (float)((int)rawvalue32);
else else
f_raw = (float)rawvalue32; f_raw = (float)rawvalue32;
} else if (nobits == 16) { }
else if (nobits == 16)
{
if (representation == PB_NUMREP_SIGNEDINT) if (representation == PB_NUMREP_SIGNEDINT)
f_raw = (float)((short)rawvalue16); f_raw = (float)((short)rawvalue16);
else else
f_raw = (float)rawvalue16; f_raw = (float)rawvalue16;
} else if (nobits == 8) { }
else if (nobits == 8)
{
if (representation == PB_NUMREP_SIGNEDINT) if (representation == PB_NUMREP_SIGNEDINT)
f_raw = (float)((char)rawvalue8); f_raw = (float)((char)rawvalue8);
else else
f_raw = (float)rawvalue8; f_raw = (float)rawvalue8;
} }
switch (cop->SensorPolyType) { switch (cop->SensorPolyType)
{
case 0: case 0:
*actvalue_p = cop->SigValPolyCoef0 + cop->SigValPolyCoef1 * f_raw; *actvalue_p = cop->SigValPolyCoef0 + cop->SigValPolyCoef1 * f_raw;
break; break;
...@@ -94,7 +100,8 @@ void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8, ...@@ -94,7 +100,8 @@ void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8,
sigvalue = cop->SigValPolyCoef0 + cop->SigValPolyCoef1 * f_raw; sigvalue = cop->SigValPolyCoef0 + cop->SigValPolyCoef1 * f_raw;
polycoef_p = &cop->SensorPolyCoef2; polycoef_p = &cop->SensorPolyCoef2;
actvalue = 0; actvalue = 0;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++)
{
actvalue = sigvalue * actvalue + *polycoef_p; actvalue = sigvalue * actvalue + *polycoef_p;
polycoef_p--; polycoef_p--;
} }
...@@ -124,8 +131,9 @@ void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8, ...@@ -124,8 +131,9 @@ void ConvertAi(pwr_sClass_ChanAi* cop, pwr_tInt16 nobits, pwr_tUInt8 rawvalue8,
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits, void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits,
pwr_tUInt16 rawvalue8, pwr_tUInt16 rawvalue16, pwr_tUInt32 rawvalue32, pwr_tUInt16 rawvalue8, pwr_tUInt16 rawvalue16,
pwr_tFloat32* actvalue_p, pwr_tEnum representation) pwr_tUInt32 rawvalue32, pwr_tFloat32* actvalue_p,
pwr_tEnum representation)
{ {
pwr_tFloat32 Slope; pwr_tFloat32 Slope;
pwr_tFloat32 Intercept; pwr_tFloat32 Intercept;
...@@ -136,17 +144,22 @@ void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits, ...@@ -136,17 +144,22 @@ void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits,
pwr_tFloat32 sigvalue; pwr_tFloat32 sigvalue;
pwr_tFloat32 f_raw = 0.0; pwr_tFloat32 f_raw = 0.0;
if (nobits == 32) { if (nobits == 32)
{
if (representation == PB_NUMREP_SIGNEDINT) if (representation == PB_NUMREP_SIGNEDINT)
f_raw = (float)((int)rawvalue32); f_raw = (float)((int)rawvalue32);
else else
f_raw = (float)rawvalue32; f_raw = (float)rawvalue32;
} else if (nobits == 16) { }
else if (nobits == 16)
{
if (representation == PB_NUMREP_SIGNEDINT) if (representation == PB_NUMREP_SIGNEDINT)
f_raw = (float)((short)rawvalue16); f_raw = (float)((short)rawvalue16);
else else
f_raw = (float)rawvalue16; f_raw = (float)rawvalue16;
} else if (nobits == 8) { }
else if (nobits == 8)
{
if (representation == PB_NUMREP_SIGNEDINT) if (representation == PB_NUMREP_SIGNEDINT)
f_raw = (float)((char)rawvalue8); f_raw = (float)((char)rawvalue8);
else else
...@@ -157,7 +170,8 @@ void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits, ...@@ -157,7 +170,8 @@ void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits,
Last = cop->NoOfCoordinates; Last = cop->NoOfCoordinates;
while ((Last - First) > 1) { while ((Last - First) > 1)
{
Middle = (First + Last) / 2; Middle = (First + Last) / 2;
TransTabValue = cop->InValue[Middle]; TransTabValue = cop->InValue[Middle];
if (sigvalue < TransTabValue) if (sigvalue < TransTabValue)
...@@ -174,8 +188,8 @@ void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits, ...@@ -174,8 +188,8 @@ void ConvertAit(pwr_sClass_ChanAit* cop, pwr_tInt16 nobits,
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Ai Init method for the Pb module Ai
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Ai* op; pwr_sClass_Pb_Ai* op;
...@@ -185,23 +199,28 @@ static pwr_tStatus IoCardInit( ...@@ -185,23 +199,28 @@ static pwr_tStatus IoCardInit(
op = (pwr_sClass_Pb_Ai*)cp->op; op = (pwr_sClass_Pb_Ai*)cp->op;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) { if (rp->Class != pwr_cClass_Pb_DP_Slave)
{
errh_Info("Illegal object type %s", cp->Name); errh_Info("Illegal object type %s", cp->Name);
return 1; return 1;
} }
if (op->Status >= PB_MODULE_STATE_OPERATE) { if (op->Status >= PB_MODULE_STATE_OPERATE)
for (i = 0; i < IO_MAXCHAN; i++) { {
for (i = 0; i < IO_MAXCHAN; i++)
{
local->scancount[i] = 0; local->scancount[i] = 0;
} }
// Calculate polycoeff // Calculate polycoeff
for (i = 0; i < cp->ChanListSize; i++) { for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (!chanp->cop) if (!chanp->cop)
continue; continue;
io_AiRangeToCoef(chanp); io_AiRangeToCoef(chanp);
} }
} else }
else
errh_Info("Error initializing Pb module Ai %s", cp->Name); errh_Info("Error initializing Pb module Ai %s", cp->Name);
return IO__SUCCESS; return IO__SUCCESS;
...@@ -210,8 +229,8 @@ static pwr_tStatus IoCardInit( ...@@ -210,8 +229,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Read method for the Pb Ai card Read method for the Pb Ai card
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead( static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Ai* op; pwr_sClass_Pb_Ai* op;
...@@ -232,8 +251,10 @@ static pwr_tStatus IoCardRead( ...@@ -232,8 +251,10 @@ static pwr_tStatus IoCardRead(
op = (pwr_sClass_Pb_Ai*)cp->op; op = (pwr_sClass_Pb_Ai*)cp->op;
slave = (pwr_sClass_Pb_DP_Slave*)rp->op; slave = (pwr_sClass_Pb_DP_Slave*)rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) { if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1)
for (i = 0; i < cp->ChanListSize; i++) { {
for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (!chanp->cop || !chanp->sop) if (!chanp->cop || !chanp->sop)
continue; continue;
...@@ -244,107 +265,121 @@ static pwr_tStatus IoCardRead( ...@@ -244,107 +265,121 @@ static pwr_tStatus IoCardRead(
if (cop->CalculateNewCoef) if (cop->CalculateNewCoef)
io_AiRangeToCoef(chanp); io_AiRangeToCoef(chanp);
if (cop->ConversionOn) { if (cop->ConversionOn)
if (local->scancount[i] <= 1) { {
if (op->BytesPerChannel == 4) { if (local->scancount[i] <= 1)
{
if (op->BytesPerChannel == 4)
{
memcpy(&udata32, local->input_area + op->OffsetInputs + 4 * i, 4); memcpy(&udata32, local->input_area + op->OffsetInputs + 4 * i, 4);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata32 = swap32(udata32); udata32 = swap32(udata32);
data32 = (pwr_tInt32)udata32; data32 = (pwr_tInt32)udata32;
sop->RawValue = 0; sop->RawValue = 0;
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
sop->SigValue sop->SigValue =
= udata32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; udata32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
else else
sop->SigValue sop->SigValue =
= data32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; data32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanAi: case pwr_cClass_ChanAi:
ConvertAi( ConvertAi(cop, 32, 0, 0, udata32, &actvalue,
cop, 32, 0, 0, udata32, &actvalue, op->NumberRepresentation); op->NumberRepresentation);
break; break;
case pwr_cClass_ChanAit: case pwr_cClass_ChanAit:
ConvertAit((pwr_sClass_ChanAit*)cop, 32, 0, 0, udata32, &actvalue, ConvertAit((pwr_sClass_ChanAit*)cop, 32, 0, 0, udata32, &actvalue,
op->NumberRepresentation); op->NumberRepresentation);
break; break;
} }
} else if (op->BytesPerChannel == 3) { }
else if (op->BytesPerChannel == 3)
{
udata32 = 0; udata32 = 0;
memcpy(&udata32, local->input_area + op->OffsetInputs + 3 * i, 3); memcpy(&udata32, local->input_area + op->OffsetInputs + 3 * i, 3);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) { if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
{
udata32 = swap32(udata32); udata32 = swap32(udata32);
udata32 = udata32 >> 8; udata32 = udata32 >> 8;
} }
data32 = (pwr_tInt32)udata32; data32 = (pwr_tInt32)udata32;
sop->RawValue = 0; sop->RawValue = 0;
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
sop->SigValue sop->SigValue =
= udata32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; udata32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
else else
sop->SigValue sop->SigValue =
= data32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; data32 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanAi: case pwr_cClass_ChanAi:
ConvertAi( ConvertAi(cop, 32, 0, 0, udata32, &actvalue,
cop, 32, 0, 0, udata32, &actvalue, op->NumberRepresentation); op->NumberRepresentation);
break; break;
case pwr_cClass_ChanAit: case pwr_cClass_ChanAit:
ConvertAit((pwr_sClass_ChanAit*)cop, 32, 0, 0, udata32, &actvalue, ConvertAit((pwr_sClass_ChanAit*)cop, 32, 0, 0, udata32, &actvalue,
op->NumberRepresentation); op->NumberRepresentation);
break; break;
} }
} else if (op->BytesPerChannel == 2) { }
else if (op->BytesPerChannel == 2)
{
memcpy(&udata16, local->input_area + op->OffsetInputs + 2 * i, 2); memcpy(&udata16, local->input_area + op->OffsetInputs + 2 * i, 2);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata16 = swap16(udata16); udata16 = swap16(udata16);
data16 = (pwr_tInt16)udata16; data16 = (pwr_tInt16)udata16;
sop->RawValue = udata16; sop->RawValue = udata16;
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
sop->SigValue sop->SigValue =
= udata16 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; udata16 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
else else
sop->SigValue sop->SigValue =
= data16 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; data16 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanAi: case pwr_cClass_ChanAi:
ConvertAi( ConvertAi(cop, 16, 0, udata16, 0, &actvalue,
cop, 16, 0, udata16, 0, &actvalue, op->NumberRepresentation); op->NumberRepresentation);
break; break;
case pwr_cClass_ChanAit: case pwr_cClass_ChanAit:
ConvertAit((pwr_sClass_ChanAit*)cop, 16, 0, udata16, 0, &actvalue, ConvertAit((pwr_sClass_ChanAit*)cop, 16, 0, udata16, 0, &actvalue,
op->NumberRepresentation); op->NumberRepresentation);
break; break;
} }
} }
else if (op->BytesPerChannel == 1) { else if (op->BytesPerChannel == 1)
{
memcpy(&udata8, local->input_area + op->OffsetInputs + i, 1); memcpy(&udata8, local->input_area + op->OffsetInputs + i, 1);
data8 = (pwr_tInt8)udata8; data8 = (pwr_tInt8)udata8;
sop->RawValue = udata8; sop->RawValue = udata8;
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
sop->SigValue sop->SigValue =
= udata8 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; udata8 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
else else
sop->SigValue sop->SigValue =
= data8 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; data8 * cop->SigValPolyCoef1 + cop->SigValPolyCoef0;
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanAi: case pwr_cClass_ChanAi:
ConvertAi( ConvertAi(cop, 8, udata8, 0, 0, &actvalue,
cop, 8, udata8, 0, 0, &actvalue, op->NumberRepresentation); op->NumberRepresentation);
break; break;
case pwr_cClass_ChanAit: case pwr_cClass_ChanAit:
ConvertAit((pwr_sClass_ChanAit*)cop, 8, udata8, 0, 0, &actvalue, ConvertAit((pwr_sClass_ChanAit*)cop, 8, udata8, 0, 0, &actvalue,
op->NumberRepresentation); op->NumberRepresentation);
break; break;
} }
} }
// Filter // Filter
if (sop->FilterType == 1 && sop->FilterAttribute[0] > 0 if (sop->FilterType == 1 && sop->FilterAttribute[0] > 0 &&
&& sop->FilterAttribute[0] > ctx->ScanTime) { sop->FilterAttribute[0] > ctx->ScanTime)
actvalue = *(pwr_tFloat32*)chanp->vbp {
+ ctx->ScanTime / sop->FilterAttribute[0] actvalue = *(pwr_tFloat32*)chanp->vbp +
* (actvalue - *(pwr_tFloat32*)chanp->vbp); ctx->ScanTime / sop->FilterAttribute[0] *
(actvalue - *(pwr_tFloat32*)chanp->vbp);
} }
*(pwr_tFloat32*)chanp->vbp = actvalue; *(pwr_tFloat32*)chanp->vbp = actvalue;
...@@ -353,8 +388,8 @@ static pwr_tStatus IoCardRead( ...@@ -353,8 +388,8 @@ static pwr_tStatus IoCardRead(
local->scancount[i]--; local->scancount[i]--;
} // if ...ConversionOn } // if ...ConversionOn
} // for } // for
} // if ...op->Status } // if ...op->Status
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -362,8 +397,8 @@ static pwr_tStatus IoCardRead( ...@@ -362,8 +397,8 @@ static pwr_tStatus IoCardRead(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Close method for the Pb Ai card Close method for the Pb Ai card
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -377,5 +412,6 @@ static pwr_tStatus IoCardClose( ...@@ -377,5 +412,6 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Ai) = { pwr_BindIoMethod(IoCardInit), pwr_dExport pwr_BindIoMethods(Pb_Ai) = {
pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod};
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Ao Init method for the Pb module Ao
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Ao* op; pwr_sClass_Pb_Ao* op;
...@@ -63,20 +63,24 @@ static pwr_tStatus IoCardInit( ...@@ -63,20 +63,24 @@ static pwr_tStatus IoCardInit(
op = (pwr_sClass_Pb_Ao*)cp->op; op = (pwr_sClass_Pb_Ao*)cp->op;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) { if (rp->Class != pwr_cClass_Pb_DP_Slave)
{
errh_Info("Illegal object type %s", cp->Name); errh_Info("Illegal object type %s", cp->Name);
return IO__SUCCESS; return IO__SUCCESS;
} }
if (op->Status >= PB_MODULE_STATE_OPERATE) { if (op->Status >= PB_MODULE_STATE_OPERATE)
{
// Calculate polycoeff // Calculate polycoeff
for (i = 0; i < cp->ChanListSize; i++) { for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (!chanp->cop) if (!chanp->cop)
continue; continue;
io_AoRangeToCoef(chanp); io_AoRangeToCoef(chanp);
} }
} else }
else
errh_Info("Error initializing Pb module Ao %s", cp->Name); errh_Info("Error initializing Pb module Ao %s", cp->Name);
return IO__SUCCESS; return IO__SUCCESS;
...@@ -85,8 +89,8 @@ static pwr_tStatus IoCardInit( ...@@ -85,8 +89,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Write method for the Pb module Ao Write method for the Pb module Ao
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite( static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Ao* op; pwr_sClass_Pb_Ao* op;
...@@ -109,10 +113,12 @@ static pwr_tStatus IoCardWrite( ...@@ -109,10 +113,12 @@ static pwr_tStatus IoCardWrite(
op = (pwr_sClass_Pb_Ao*)cp->op; op = (pwr_sClass_Pb_Ao*)cp->op;
slave = (pwr_sClass_Pb_DP_Slave*)rp->op; slave = (pwr_sClass_Pb_DP_Slave*)rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) { if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1)
{
fixout = ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT; fixout = ctx->Node->EmergBreakTrue && ctx->Node->EmergBreakSelect == FIXOUT;
for (i = 0; i < cp->ChanListSize; i++) { for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (!chanp->cop || !chanp->sop) if (!chanp->cop || !chanp->sop)
continue; continue;
...@@ -125,7 +131,8 @@ static pwr_tStatus IoCardWrite( ...@@ -125,7 +131,8 @@ static pwr_tStatus IoCardWrite(
value = cop->FixedOutValue; value = cop->FixedOutValue;
else if (cop->TestOn) else if (cop->TestOn)
value = cop->TestValue; value = cop->TestValue;
else { else
{
value = *(pwr_tFloat32*)chanp->vbp; value = *(pwr_tFloat32*)chanp->vbp;
} }
...@@ -152,50 +159,66 @@ static pwr_tStatus IoCardWrite( ...@@ -152,50 +159,66 @@ static pwr_tStatus IoCardWrite(
// Calculate signal value // Calculate signal value
sop->SigValue = cop->SigValPolyCoef1 * value + cop->SigValPolyCoef0; sop->SigValue = cop->SigValPolyCoef1 * value + cop->SigValPolyCoef0;
if (op->BytesPerChannel == 4) { if (op->BytesPerChannel == 4)
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
udata32 = (pwr_tUInt32)rawvalue; udata32 = (pwr_tUInt32)rawvalue;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata32 = swap32(udata32); udata32 = swap32(udata32);
memcpy(local->output_area + op->OffsetOutputs + 4 * i, &udata32, 4); memcpy(local->output_area + op->OffsetOutputs + 4 * i, &udata32, 4);
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
data32 = (pwr_tInt32)rawvalue; data32 = (pwr_tInt32)rawvalue;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data32 = swap32(data32); data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 4 * i, &data32, 4); memcpy(local->output_area + op->OffsetOutputs + 4 * i, &data32, 4);
} }
}
} else if (op->BytesPerChannel == 3) { else if (op->BytesPerChannel == 3)
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
udata32 = (pwr_tUInt32)rawvalue; udata32 = (pwr_tUInt32)rawvalue;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata32 = swap32(udata32); udata32 = swap32(udata32);
memcpy(local->output_area + op->OffsetOutputs + 3 * i, &udata32, 3); memcpy(local->output_area + op->OffsetOutputs + 3 * i, &udata32, 3);
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
data32 = (pwr_tInt32)rawvalue; data32 = (pwr_tInt32)rawvalue;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data32 = swap32(data32); data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 3 * i, &data32, 3); memcpy(local->output_area + op->OffsetOutputs + 3 * i, &data32, 3);
} }
}
} else if (op->BytesPerChannel == 2) { else if (op->BytesPerChannel == 2)
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
udata16 = (pwr_tUInt16)rawvalue; udata16 = (pwr_tUInt16)rawvalue;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata16 = swap16(udata16); udata16 = swap16(udata16);
memcpy(local->output_area + op->OffsetOutputs + 2 * i, &udata16, 2); memcpy(local->output_area + op->OffsetOutputs + 2 * i, &udata16, 2);
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
data16 = (pwr_tInt16)rawvalue; data16 = (pwr_tInt16)rawvalue;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data16 = swap16(data16); data16 = swap16(data16);
memcpy(local->output_area + op->OffsetOutputs + 2 * i, &data16, 2); memcpy(local->output_area + op->OffsetOutputs + 2 * i, &data16, 2);
} }
}
} else if (op->BytesPerChannel == 1) { else if (op->BytesPerChannel == 1)
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
udata8 = (pwr_tUInt8)rawvalue; udata8 = (pwr_tUInt8)rawvalue;
memcpy(local->output_area + op->OffsetOutputs + i, &udata8, 1); memcpy(local->output_area + op->OffsetOutputs + i, &udata8, 1);
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
data8 = (pwr_tInt8)rawvalue; data8 = (pwr_tInt8)rawvalue;
memcpy(local->output_area + op->OffsetOutputs + i, &data8, 1); memcpy(local->output_area + op->OffsetOutputs + i, &data8, 1);
} }
...@@ -209,8 +232,8 @@ static pwr_tStatus IoCardWrite( ...@@ -209,8 +232,8 @@ static pwr_tStatus IoCardWrite(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -224,6 +247,6 @@ static pwr_tStatus IoCardClose( ...@@ -224,6 +247,6 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Ao) pwr_dExport pwr_BindIoMethods(Pb_Ao) = {
= { pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardClose), pwr_NullMethod};
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Move di data word to valuebase. Move di data word to valuebase.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
void pbio_DiUnpackWord( void pbio_DiUnpackWord(io_sCard* cp, pwr_tUInt16 data, pwr_tUInt16 mask,
io_sCard* cp, pwr_tUInt16 data, pwr_tUInt16 mask, int index) int index)
{ {
io_sChannel* chanp; io_sChannel* chanp;
...@@ -64,7 +64,8 @@ void pbio_DiUnpackWord( ...@@ -64,7 +64,8 @@ void pbio_DiUnpackWord(
else else
chanp = &cp->chanlist[16]; chanp = &cp->chanlist[16];
if (mask == IO_CONVMASK_ALL) { if (mask == IO_CONVMASK_ALL)
{
/* No conversion test */ /* No conversion test */
if (chanp->cop && chanp->sop) if (chanp->cop && chanp->sop)
*(pwr_tUInt16*)(chanp->vbp) = ((data & 1) != 0); *(pwr_tUInt16*)(chanp->vbp) = ((data & 1) != 0);
...@@ -114,7 +115,9 @@ void pbio_DiUnpackWord( ...@@ -114,7 +115,9 @@ void pbio_DiUnpackWord(
if (chanp->cop && chanp->sop) if (chanp->cop && chanp->sop)
*(pwr_tUInt16*)(chanp->vbp) = ((data & 32768) != 0); *(pwr_tUInt16*)(chanp->vbp) = ((data & 32768) != 0);
chanp++; chanp++;
} else { }
else
{
if (chanp->cop && chanp->sop && mask & 1) if (chanp->cop && chanp->sop && mask & 1)
*(pwr_tUInt16*)(chanp->vbp) = ((data & 1) != 0); *(pwr_tUInt16*)(chanp->vbp) = ((data & 1) != 0);
chanp++; chanp++;
...@@ -169,8 +172,8 @@ void pbio_DiUnpackWord( ...@@ -169,8 +172,8 @@ void pbio_DiUnpackWord(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Di Init method for the Pb module Di
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Di* op; pwr_sClass_Pb_Di* op;
...@@ -180,8 +183,8 @@ static pwr_tStatus IoCardInit( ...@@ -180,8 +183,8 @@ static pwr_tStatus IoCardInit(
// Check configuration // Check configuration
if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 &&
&& op->NumberOfChannels != 32) op->NumberOfChannels != 32)
op->Status = PB_MODULE_STATE_NOTINIT; op->Status = PB_MODULE_STATE_NOTINIT;
if (op->Orientation > op->NumberOfChannels) if (op->Orientation > op->NumberOfChannels)
...@@ -196,8 +199,8 @@ static pwr_tStatus IoCardInit( ...@@ -196,8 +199,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Read method for the Pb module Di Read method for the Pb module Di
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead( static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Di* op; pwr_sClass_Pb_Di* op;
...@@ -208,22 +211,27 @@ static pwr_tStatus IoCardRead( ...@@ -208,22 +211,27 @@ static pwr_tStatus IoCardRead(
pwr_sClass_Di* sig_di; pwr_sClass_Di* sig_di;
pwr_tUInt32 mask = 0; pwr_tUInt32 mask = 0;
pwr_tUInt16 data[2] = { 0, 0 }; pwr_tUInt16 data[2] = {0, 0};
pwr_tUInt32* data32; pwr_tUInt32* data32;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
op = (pwr_sClass_Pb_Di*)cp->op; op = (pwr_sClass_Pb_Di*)cp->op;
slave = (pwr_sClass_Pb_DP_Slave*)rp->op; slave = (pwr_sClass_Pb_DP_Slave*)rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) { if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1)
{
memcpy(&data, local->input_area + op->OffsetInputs, op->BytesOfInput); memcpy(&data, local->input_area + op->OffsetInputs, op->BytesOfInput);
data32 = (pwr_tUInt32*)&data; data32 = (pwr_tUInt32*)&data;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) { if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
if (op->Orientation == PB_ORIENTATION_WORD) { {
if (op->Orientation == PB_ORIENTATION_WORD)
{
data[0] = swap16(data[0]); data[0] = swap16(data[0]);
data[1] = swap16(data[1]); data[1] = swap16(data[1]);
} else if (op->Orientation == PB_ORIENTATION_DWORD) { }
else if (op->Orientation == PB_ORIENTATION_DWORD)
{
*data32 = swap32(*data32); *data32 = swap32(*data32);
} }
} }
...@@ -233,11 +241,13 @@ static pwr_tStatus IoCardRead( ...@@ -233,11 +241,13 @@ static pwr_tStatus IoCardRead(
data[1] = data[1] ^ op->InvMask2; data[1] = data[1] ^ op->InvMask2;
// Packa upp // Packa upp
for (i = 0; i < cp->ChanListSize; i++) { for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
chan_di = (pwr_sClass_ChanDi*)chanp->cop; chan_di = (pwr_sClass_ChanDi*)chanp->cop;
sig_di = (pwr_sClass_Di*)chanp->sop; sig_di = (pwr_sClass_Di*)chanp->sop;
if (chan_di && sig_di) { if (chan_di && sig_di)
{
mask = 1 << chan_di->Number; mask = 1 << chan_di->Number;
*(pwr_tUInt16*)(chanp->vbp) = ((*data32 & mask) != 0); *(pwr_tUInt16*)(chanp->vbp) = ((*data32 & mask) != 0);
} }
...@@ -258,8 +268,8 @@ static pwr_tStatus IoCardRead( ...@@ -258,8 +268,8 @@ static pwr_tStatus IoCardRead(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -273,5 +283,6 @@ static pwr_tStatus IoCardClose( ...@@ -273,5 +283,6 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Di) = { pwr_BindIoMethod(IoCardInit), pwr_dExport pwr_BindIoMethods(Pb_Di) = {
pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod};
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Do Init method for the Pb module Do
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Do* op; pwr_sClass_Pb_Do* op;
...@@ -61,8 +61,8 @@ static pwr_tStatus IoCardInit( ...@@ -61,8 +61,8 @@ static pwr_tStatus IoCardInit(
op = (pwr_sClass_Pb_Do*)cp->op; op = (pwr_sClass_Pb_Do*)cp->op;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 if (op->NumberOfChannels != 8 && op->NumberOfChannels != 16 &&
&& op->NumberOfChannels != 32) op->NumberOfChannels != 32)
op->Status = PB_MODULE_STATE_NOTINIT; op->Status = PB_MODULE_STATE_NOTINIT;
if (op->Orientation > op->NumberOfChannels) if (op->Orientation > op->NumberOfChannels)
...@@ -77,8 +77,8 @@ static pwr_tStatus IoCardInit( ...@@ -77,8 +77,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Write method for the Pb module Do Write method for the Pb module Do
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite( static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Do* op; pwr_sClass_Pb_Do* op;
...@@ -90,22 +90,25 @@ static pwr_tStatus IoCardWrite( ...@@ -90,22 +90,25 @@ static pwr_tStatus IoCardWrite(
pwr_tUInt32 mask = 0; pwr_tUInt32 mask = 0;
pwr_tInt32 do_actval; pwr_tInt32 do_actval;
pwr_tUInt16 data[2] = { 0, 0 }; pwr_tUInt16 data[2] = {0, 0};
pwr_tUInt32* data32; pwr_tUInt32* data32;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
op = (pwr_sClass_Pb_Do*)cp->op; op = (pwr_sClass_Pb_Do*)cp->op;
slave = (pwr_sClass_Pb_DP_Slave*)rp->op; slave = (pwr_sClass_Pb_DP_Slave*)rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) { if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1)
{
data32 = (pwr_tUInt32*)&data; data32 = (pwr_tUInt32*)&data;
// Packa ner // Packa ner
for (i = 0; i < cp->ChanListSize; i++) { for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
chan_do = (pwr_sClass_ChanDo*)chanp->cop; chan_do = (pwr_sClass_ChanDo*)chanp->cop;
sig_do = (pwr_sClass_Do*)chanp->sop; sig_do = (pwr_sClass_Do*)chanp->sop;
if (chan_do && sig_do) { if (chan_do && sig_do)
{
mask = 1 << chan_do->Number; mask = 1 << chan_do->Number;
do_actval = *(pwr_tInt32*)chanp->vbp; do_actval = *(pwr_tInt32*)chanp->vbp;
if (do_actval != 0) if (do_actval != 0)
...@@ -118,11 +121,15 @@ static pwr_tStatus IoCardWrite( ...@@ -118,11 +121,15 @@ static pwr_tStatus IoCardWrite(
io_DoPackWord(cp, &data[0], 0); io_DoPackWord(cp, &data[0], 0);
if (op->NumberOfChannels > 16) io_DoPackWord(cp, &data[1], 1); if (op->NumberOfChannels > 16) io_DoPackWord(cp, &data[1], 1);
*/ */
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) { if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
if (op->Orientation == PB_ORIENTATION_WORD) { {
if (op->Orientation == PB_ORIENTATION_WORD)
{
data[0] = swap16(data[0]); data[0] = swap16(data[0]);
data[1] = swap16(data[1]); data[1] = swap16(data[1]);
} else if (op->Orientation == PB_ORIENTATION_DWORD) { }
else if (op->Orientation == PB_ORIENTATION_DWORD)
{
*data32 = swap32(*data32); *data32 = swap32(*data32);
} }
} }
...@@ -135,8 +142,8 @@ static pwr_tStatus IoCardWrite( ...@@ -135,8 +142,8 @@ static pwr_tStatus IoCardWrite(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -150,6 +157,6 @@ static pwr_tStatus IoCardClose( ...@@ -150,6 +157,6 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Do) pwr_dExport pwr_BindIoMethods(Pb_Do) = {
= { pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardClose), pwr_NullMethod};
...@@ -112,7 +112,8 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -112,7 +112,8 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
latent_input_count = 0; latent_input_count = 0;
latent_output_count = 0; latent_output_count = 0;
while (cardp) { while (cardp)
{
local_card = calloc(1, sizeof(*local_card)); local_card = calloc(1, sizeof(*local_card));
cardp->Local = local_card; cardp->Local = local_card;
local_card->input_area = (void*)&(op->Inputs); local_card->input_area = (void*)&(op->Inputs);
...@@ -124,7 +125,8 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -124,7 +125,8 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
while (ODD(gdh_GetSuperClass(cid, &cid, cardp->Objid))) while (ODD(gdh_GetSuperClass(cid, &cid, cardp->Objid)))
; ;
switch (cid) { switch (cid)
{
/* Old style configuring with Pb_xx objects. Still here for combatibility /* Old style configuring with Pb_xx objects. Still here for combatibility
reasons. reasons.
New systems (from v4.1.3) should be build with Pb_Module objects or New systems (from v4.1.3) should be build with Pb_Module objects or
...@@ -186,16 +188,19 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -186,16 +188,19 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
mp = (pwr_sClass_Pb_Module*)cardp->op; mp = (pwr_sClass_Pb_Module*)cardp->op;
mp->Status = PB__INITFAIL; mp->Status = PB__INITFAIL;
cardp->offset = 0; cardp->offset = 0;
for (i = 0; i < cardp->ChanListSize; i++) { for (i = 0; i < cardp->ChanListSize; i++)
{
chanp = &cardp->chanlist[i]; chanp = &cardp->chanlist[i];
if (is_diag(&chanp->ChanAref)) { if (is_diag(&chanp->ChanAref))
{
chanp->udata |= PB_UDATA_DIAG; chanp->udata |= PB_UDATA_DIAG;
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanIi: case pwr_cClass_ChanIi:
chanp->offset = ((pwr_sClass_ChanIi*)chanp->cop)->Number; chanp->offset = ((pwr_sClass_ChanIi*)chanp->cop)->Number;
chanp->size chanp->size =
= GetChanSize(((pwr_sClass_ChanIi*)chanp->cop)->Representation); GetChanSize(((pwr_sClass_ChanIi*)chanp->cop)->Representation);
break; break;
default: default:
errh_Error("Diagnostic channel class, card %s", cardp->Name); errh_Error("Diagnostic channel class, card %s", cardp->Name);
...@@ -203,30 +208,34 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -203,30 +208,34 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
continue; continue;
} }
if (chanp->ChanClass != pwr_cClass_ChanDi) { if (chanp->ChanClass != pwr_cClass_ChanDi)
{
input_counter += latent_input_count; input_counter += latent_input_count;
latent_input_count = 0; latent_input_count = 0;
} }
if (chanp->ChanClass != pwr_cClass_ChanDo) { if (chanp->ChanClass != pwr_cClass_ChanDo)
{
output_counter += latent_output_count; output_counter += latent_output_count;
latent_output_count = 0; latent_output_count = 0;
} }
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanDi: case pwr_cClass_ChanDi:
chan_di = (pwr_sClass_ChanDi*)chanp->cop; chan_di = (pwr_sClass_ChanDi*)chanp->cop;
if (chan_di->Number == 0) { if (chan_di->Number == 0)
{
input_counter += latent_input_count; input_counter += latent_input_count;
latent_input_count = 0; latent_input_count = 0;
} }
chanp->offset = input_counter; chanp->offset = input_counter;
chanp->mask = 1 << chan_di->Number; chanp->mask = 1 << chan_di->Number;
if (chan_di->Representation == pwr_eDataRepEnum_Bit16 if (chan_di->Representation == pwr_eDataRepEnum_Bit16 &&
&& op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap16(chanp->mask); chanp->mask = swap16(chanp->mask);
if (chan_di->Representation == pwr_eDataRepEnum_Bit32 if (chan_di->Representation == pwr_eDataRepEnum_Bit32 &&
&& op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap32(chanp->mask); chanp->mask = swap32(chanp->mask);
if (chan_di->Number == 0) if (chan_di->Number == 0)
latent_input_count = GetChanSize(chan_di->Representation); latent_input_count = GetChanSize(chan_di->Representation);
...@@ -269,18 +278,19 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -269,18 +278,19 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
case pwr_cClass_ChanDo: case pwr_cClass_ChanDo:
chan_do = (pwr_sClass_ChanDo*)chanp->cop; chan_do = (pwr_sClass_ChanDo*)chanp->cop;
if (chan_do->Number == 0) { if (chan_do->Number == 0)
{
output_counter += latent_output_count; output_counter += latent_output_count;
latent_output_count = 0; latent_output_count = 0;
} }
chanp->offset = output_counter; chanp->offset = output_counter;
chan_size = GetChanSize(chan_do->Representation); chan_size = GetChanSize(chan_do->Representation);
chanp->mask = 1 << chan_do->Number; chanp->mask = 1 << chan_do->Number;
if (chan_do->Representation == pwr_eDataRepEnum_Bit16 if (chan_do->Representation == pwr_eDataRepEnum_Bit16 &&
&& op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap16(chanp->mask); chanp->mask = swap16(chanp->mask);
if (chan_do->Representation == pwr_eDataRepEnum_Bit32 if (chan_do->Representation == pwr_eDataRepEnum_Bit32 &&
&& op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap32(chanp->mask); chanp->mask = swap32(chanp->mask);
if (chan_do->Number == 0) if (chan_do->Number == 0)
latent_output_count = GetChanSize(chan_do->Representation); latent_output_count = GetChanSize(chan_do->Representation);
...@@ -342,35 +352,45 @@ static pwr_tStatus IoRackRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -342,35 +352,45 @@ static pwr_tStatus IoRackRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
/* The reading of the process image is now performed at the agent level, /* 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. */ this eliminates the need for board specific code at the rack level. */
if (sp->DisableSlave != 1 && mp->DisableBus != 1) { if (sp->DisableSlave != 1 && mp->DisableBus != 1)
if (sp->Status == PB__NORMAL) { {
if (sp->Status == PB__NORMAL)
{
sp->ErrorCount = 0; sp->ErrorCount = 0;
} else { }
else
{
if (local->start_cnt >= local->start_time) if (local->start_cnt >= local->start_time)
sp->ErrorCount++; sp->ErrorCount++;
} }
if (sp->ErrorCount == sp->ErrorSoftLimit) { if (sp->ErrorCount == sp->ErrorSoftLimit)
{
errh_Error("IO Error soft limit reached on card '%s'", rp->Name); errh_Error("IO Error soft limit reached on card '%s'", rp->Name);
ctx->IOHandler->CardErrorSoftLimit = 1; ctx->IOHandler->CardErrorSoftLimit = 1;
ctx->IOHandler->ErrorSoftLimitObject = cdh_ObjidToAref(rp->Objid); ctx->IOHandler->ErrorSoftLimitObject = cdh_ObjidToAref(rp->Objid);
} }
if (sp->ErrorCount == sp->ErrorHardLimit) { if (sp->ErrorCount == sp->ErrorHardLimit)
{
errh_Error("IO Error hard limit reached on card '%s', stall action %d", errh_Error("IO Error hard limit reached on card '%s', stall action %d",
rp->Name, sp->StallAction); rp->Name, sp->StallAction);
ctx->IOHandler->CardErrorHardLimit = 1; ctx->IOHandler->CardErrorHardLimit = 1;
ctx->IOHandler->ErrorHardLimitObject = cdh_ObjidToAref(rp->Objid); ctx->IOHandler->ErrorHardLimitObject = cdh_ObjidToAref(rp->Objid);
} }
if (sp->ErrorCount > sp->ErrorHardLimit if (sp->ErrorCount > sp->ErrorHardLimit &&
&& sp->StallAction == pwr_ePbStallAction_ResetInputs) { sp->StallAction == pwr_ePbStallAction_ResetInputs)
{
memset(&sp->Inputs, 0, sp->BytesOfInput); memset(&sp->Inputs, 0, sp->BytesOfInput);
} }
if (sp->ErrorCount > sp->ErrorHardLimit if (sp->ErrorCount > sp->ErrorHardLimit &&
&& sp->StallAction == pwr_ePbStallAction_EmergencyBreak) { sp->StallAction == pwr_ePbStallAction_EmergencyBreak)
{
ctx->Node->EmergBreakTrue = 1; ctx->Node->EmergBreakTrue = 1;
} }
} else { }
else
{
sp->ErrorCount = 0; sp->ErrorCount = 0;
sp->Status = PB__DISABLED; sp->Status = PB__DISABLED;
} }
...@@ -410,6 +430,7 @@ static pwr_tStatus IoRackClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -410,6 +430,7 @@ static pwr_tStatus IoRackClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_DP_Slave) = { pwr_BindIoMethod(IoRackInit), pwr_dExport pwr_BindIoMethods(Pb_DP_Slave) = {
pwr_BindIoMethod(IoRackRead), pwr_BindIoMethod(IoRackWrite), pwr_BindIoMethod(IoRackInit), pwr_BindIoMethod(IoRackRead),
pwr_BindIoMethod(IoRackClose), pwr_NullMethod }; pwr_BindIoMethod(IoRackWrite), pwr_BindIoMethod(IoRackClose),
pwr_NullMethod};
...@@ -65,8 +65,9 @@ ...@@ -65,8 +65,9 @@
static unsigned char req_res_buffer[512]; static unsigned char req_res_buffer[512];
static short fdlif_sda_sdn_sdr_req(io_sAgentLocal* local_agent, static short fdlif_sda_sdn_sdr_req(io_sAgentLocal* local_agent,
pwr_sClass_Pb_FDL_SAP* sap, pwr_sClass_Pb_FDL_DataTransfer* op, pwr_sClass_Pb_FDL_SAP* sap,
io_sFDLCardLocal* local) pwr_sClass_Pb_FDL_DataTransfer* op,
io_sFDLCardLocal* local)
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
FUNCTIONAL_DESCRIPTION FUNCTIONAL_DESCRIPTION
...@@ -106,16 +107,20 @@ possible return values: ...@@ -106,16 +107,20 @@ possible return values:
*/ */
sdb.comm_ref = 0; sdb.comm_ref = 0;
sdb.layer = FDLIF; sdb.layer = FDLIF;
switch (op->Type) { switch (op->Type)
case pwr_ePbFDLDataTransferTypeEnum_FDLIF_SDA: { {
case pwr_ePbFDLDataTransferTypeEnum_FDLIF_SDA:
{
sdb.service = FDLIF_SDA; sdb.service = FDLIF_SDA;
break; break;
} }
case pwr_ePbFDLDataTransferTypeEnum_FDLIF_SDN: { case pwr_ePbFDLDataTransferTypeEnum_FDLIF_SDN:
{
sdb.service = FDLIF_SDN; sdb.service = FDLIF_SDN;
break; break;
} }
case pwr_ePbFDLDataTransferTypeEnum_FDLIF_SRD: { case pwr_ePbFDLDataTransferTypeEnum_FDLIF_SRD:
{
sdb.service = FDLIF_SRD; sdb.service = FDLIF_SRD;
break; break;
} }
...@@ -128,15 +133,17 @@ possible return values: ...@@ -128,15 +133,17 @@ possible return values:
sdb.invoke_id = local->invoke_id = local_agent->invoke_id; sdb.invoke_id = local->invoke_id = local_agent->invoke_id;
local_agent->invoke_id = (local_agent->invoke_id + 1) % 128; local_agent->invoke_id = (local_agent->invoke_id + 1) % 128;
result = profi_snd_req_res( // result = profi_snd_req_res(
(T_PROFI_DEVICE_HANDLE*)local_agent, &sdb, (void*)req, PB_FALSE); // (T_PROFI_DEVICE_HANDLE*)local_agent, &sdb, (void*)req, PB_FALSE);
result = profi_snd_req_res(&sdb, (void*)req, PB_FALSE);
return ((pwr_tBoolean)(result == E_OK)); return ((pwr_tBoolean)(result == E_OK));
} }
static short fdlif_reply_update_mult_req(io_sAgentLocal* local_agent, static short fdlif_reply_update_mult_req(io_sAgentLocal* local_agent,
pwr_sClass_Pb_FDL_SAP* sap, pwr_sClass_Pb_FDL_DataTransfer* op, pwr_sClass_Pb_FDL_SAP* sap,
io_sFDLCardLocal* local) pwr_sClass_Pb_FDL_DataTransfer* op,
io_sFDLCardLocal* local)
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
FUNCTIONAL_DESCRIPTION FUNCTIONAL_DESCRIPTION
...@@ -179,8 +186,9 @@ possible return values: ...@@ -179,8 +186,9 @@ possible return values:
sdb.invoke_id = local->invoke_id = local_agent->invoke_id; sdb.invoke_id = local->invoke_id = local_agent->invoke_id;
local_agent->invoke_id = (local_agent->invoke_id + 1) % 128; local_agent->invoke_id = (local_agent->invoke_id + 1) % 128;
result = profi_snd_req_res( // result = profi_snd_req_res((T_PROFI_DEVICE_HANDLE*)local_agent, &sdb,
(T_PROFI_DEVICE_HANDLE*)local_agent, &sdb, (void*)req, PB_FALSE); // (void*)req, PB_FALSE);
result = profi_snd_req_res(&sdb, (void*)req, PB_FALSE);
return ((pwr_tBoolean)(result == E_OK)); return ((pwr_tBoolean)(result == E_OK));
} }
...@@ -188,8 +196,8 @@ possible return values: ...@@ -188,8 +196,8 @@ possible return values:
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Init method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sFDLCardLocal* local; io_sFDLCardLocal* local;
pwr_sClass_Pb_FDL_DataTransfer* op = (pwr_sClass_Pb_FDL_DataTransfer*)cp->op; pwr_sClass_Pb_FDL_DataTransfer* op = (pwr_sClass_Pb_FDL_DataTransfer*)cp->op;
...@@ -206,8 +214,8 @@ static pwr_tStatus IoCardInit( ...@@ -206,8 +214,8 @@ static pwr_tStatus IoCardInit(
local->byte_ordering = ((pwr_sClass_Pb_FDL_SAP*)rp->op)->ByteOrdering; local->byte_ordering = ((pwr_sClass_Pb_FDL_SAP*)rp->op)->ByteOrdering;
io_bus_card_init(ctx, cp, &input_area_offset, &input_area_chansize, io_bus_card_init(ctx, cp, &input_area_offset, &input_area_chansize,
&output_area_offset, &output_area_chansize, local->byte_ordering, &output_area_offset, &output_area_chansize,
io_eAlignment_Packed); local->byte_ordering, io_eAlignment_Packed);
local->input_area_size = input_area_offset + input_area_chansize; local->input_area_size = input_area_offset + input_area_chansize;
local->output_area_size = output_area_offset + output_area_chansize; local->output_area_size = output_area_offset + output_area_chansize;
...@@ -227,13 +235,13 @@ static pwr_tStatus IoCardInit( ...@@ -227,13 +235,13 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Read method for the Pb FDL Data transfer module Read method for the Pb FDL Data transfer module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead( static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sFDLCardLocal* local = (io_sFDLCardLocal*)cp->Local; io_sFDLCardLocal* local = (io_sFDLCardLocal*)cp->Local;
io_bus_card_read(ctx, rp, cp, local->input_area, 0, local->byte_ordering, io_bus_card_read(ctx, rp, cp, local->input_area, 0, local->byte_ordering,
local->float_representation); local->float_representation);
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -241,8 +249,8 @@ static pwr_tStatus IoCardRead( ...@@ -241,8 +249,8 @@ static pwr_tStatus IoCardRead(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Write method for the Pb FDL Data transfer module Write method for the Pb FDL Data transfer module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite( static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sAgentLocal* local_agent = (io_sAgentLocal*)ap->Local; io_sAgentLocal* local_agent = (io_sAgentLocal*)ap->Local;
pwr_sClass_Pb_FDL_DataTransfer* op = (pwr_sClass_Pb_FDL_DataTransfer*)cp->op; pwr_sClass_Pb_FDL_DataTransfer* op = (pwr_sClass_Pb_FDL_DataTransfer*)cp->op;
...@@ -251,16 +259,21 @@ static pwr_tStatus IoCardWrite( ...@@ -251,16 +259,21 @@ static pwr_tStatus IoCardWrite(
op->Status = sap->Status; op->Status = sap->Status;
if (op->Status == PB__NORMAL) { if (op->Status == PB__NORMAL)
{
io_bus_card_write(ctx, cp, local->output_area, local->byte_ordering, io_bus_card_write(ctx, cp, local->output_area, local->byte_ordering,
local->float_representation); local->float_representation);
if (op->SendReq) { if (op->SendReq)
{
pthread_mutex_lock(&local_agent->mutex); pthread_mutex_lock(&local_agent->mutex);
if (sap->Responder) { if (sap->Responder)
{
fdlif_reply_update_mult_req(local_agent, sap, op, local); fdlif_reply_update_mult_req(local_agent, sap, op, local);
} else { }
else
{
fdlif_sda_sdn_sdr_req(local_agent, sap, op, local); fdlif_sda_sdn_sdr_req(local_agent, sap, op, local);
} }
op->SendReq = 0; op->SendReq = 0;
...@@ -274,8 +287,8 @@ static pwr_tStatus IoCardWrite( ...@@ -274,8 +287,8 @@ static pwr_tStatus IoCardWrite(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Close method for the Pb module Close method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -290,7 +303,7 @@ static pwr_tStatus IoCardClose( ...@@ -290,7 +303,7 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_FDL_DataTransfer) pwr_dExport pwr_BindIoMethods(Pb_FDL_DataTransfer) = {
= { pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardClose), pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardClose),
pwr_NullMethod }; pwr_NullMethod};
...@@ -85,5 +85,6 @@ static pwr_tStatus IoRackClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -85,5 +85,6 @@ static pwr_tStatus IoRackClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_FDL_SAP) = { pwr_BindIoMethod(IoRackInit), pwr_dExport pwr_BindIoMethods(Pb_FDL_SAP) = {pwr_BindIoMethod(IoRackInit),
pwr_BindIoMethod(IoRackClose), pwr_NullMethod }; pwr_BindIoMethod(IoRackClose),
pwr_NullMethod};
...@@ -86,7 +86,8 @@ board. ...@@ -86,7 +86,8 @@ board.
#include "rt_io_pb_locals.h" #include "rt_io_pb_locals.h"
typedef struct { typedef struct
{
/* Board number. */ /* Board number. */
unsigned short dev_number; unsigned short dev_number;
/* Number of occupied bytes in the input area of the dual port ram. */ /* Number of occupied bytes in the input area of the dual port ram. */
...@@ -114,7 +115,8 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap); ...@@ -114,7 +115,8 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap);
/* Start segment of the database, shall be 8 for /* Start segment of the database, shall be 8 for
CIF30-DPM, CIF104-DPM, COM-DPM, COM-PB, CIF104-PB and CIF 50-PB. 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. */ Shall be 0 for CIF 30-PB and CIF 60-PB. */
typedef struct { typedef struct
{
/* Used to terminate the table, se to 1 for every entry but the /* Used to terminate the table, se to 1 for every entry but the
last (dummy entry), which should be 0. */ last (dummy entry), which should be 0. */
unsigned char entry; unsigned char entry;
...@@ -129,15 +131,14 @@ typedef struct { ...@@ -129,15 +131,14 @@ typedef struct {
/* Table of known boards, consists of four fields according to the board type. /* Table of known boards, consists of four fields according to the board type.
The last entry must be a null termination (entry == 0). The last entry must be a null termination (entry == 0).
*/ */
boards known_boards[] boards known_boards[] = {
= { { 1, { 8, 50, 66, { 'C', 'I', 'F' } }, 8, "Hilscher CIF 50-PB" }, {1, {8, 50, 66, {'C', 'I', 'F'}}, 8, "Hilscher CIF 50-PB"}, {0, {}, 0, ""}};
{ 0, {}, 0, "" } };
#endif /* FLASH_WRITE_ENABLE */ #endif /* FLASH_WRITE_ENABLE */
/* Initializes Profibus DP interface on the CIF board referred to by local. /* Initializes Profibus DP interface on the CIF board referred to by local.
DRV_NO_ERROR is returned upon success. */ DRV_NO_ERROR is returned upon success. */
static short dpm_init_master( static short dpm_init_master(io_sAgentLocalHilscher* local,
io_sAgentLocalHilscher* local, pwr_sClass_Pb_Hilscher* op, io_sAgent* ap) pwr_sClass_Pb_Hilscher* op, io_sAgent* ap)
{ {
short rv; short rv;
DPM_PLC_PARAMETER prm; DPM_PLC_PARAMETER prm;
...@@ -166,19 +167,21 @@ static short dpm_init_master( ...@@ -166,19 +167,21 @@ static short dpm_init_master(
/* Writes parameters to the board local->dev_number, task 2, size is /* Writes parameters to the board local->dev_number, task 2, size is
* hardcoded to 16 as specified in dpm_pie.pdf, page 9. */ * hardcoded to 16 as specified in dpm_pie.pdf, page 9. */
if ((rv = DevPutTaskParameter(local->dev_number, 2, 16, &prm)) if ((rv = DevPutTaskParameter(local->dev_number, 2, 16, &prm)) !=
!= DRV_NO_ERROR) { DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" DevPutTaskParameter() failed with return code %d", " DevPutTaskParameter() failed with return code %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
/* Resets board to put new master parameters into effect. */ /* Resets board to put new master parameters into effect. */
if ((rv = DevReset(local->dev_number, WARMSTART, 8000)) != DRV_NO_ERROR) { if ((rv = DevReset(local->dev_number, WARMSTART, 8000)) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" DevReset() failed with return code %d", " DevReset() failed with return code %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
...@@ -191,15 +194,18 @@ static short dpm_init(io_sAgentLocalHilscher* local, io_sAgent* ap) ...@@ -191,15 +194,18 @@ static short dpm_init(io_sAgentLocalHilscher* local, io_sAgent* ap)
{ {
short rv; short rv;
if ((rv = DevOpenDriver()) != DRV_NO_ERROR) { if ((rv = DevOpenDriver()) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" DevOpenDriver() failed with return code %d", " DevOpenDriver() failed with return code %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} else if ((rv = DevInitBoard(local->dev_number)) != DRV_NO_ERROR) { }
else if ((rv = DevInitBoard(local->dev_number)) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" DevInitBoard() failed with return code %d", " DevInitBoard() failed with return code %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
...@@ -213,16 +219,18 @@ static short dpm_exit(io_sAgentLocalHilscher* local, io_sAgent* ap) ...@@ -213,16 +219,18 @@ static short dpm_exit(io_sAgentLocalHilscher* local, io_sAgent* ap)
short rv; short rv;
short rv_ret = DRV_NO_ERROR; short rv_ret = DRV_NO_ERROR;
if ((rv = DevExitBoard(local->dev_number)) != DRV_NO_ERROR) { if ((rv = DevExitBoard(local->dev_number)) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" DevExitBoard() failed with return code %d", " DevExitBoard() failed with return code %d",
ap->Name, rv); ap->Name, rv);
rv_ret = rv; rv_ret = rv;
} }
if ((rv = DevCloseDriver()) != DRV_NO_ERROR) { if ((rv = DevCloseDriver()) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" DevCloseDriver() failed with return code %d", " DevCloseDriver() failed with return code %d",
ap->Name, rv); ap->Name, rv);
rv_ret = rv; rv_ret = rv;
} }
...@@ -251,29 +259,35 @@ static short module_cnt_inputs(io_sCard* cp) ...@@ -251,29 +259,35 @@ static short module_cnt_inputs(io_sCard* cp)
for (cid = cp->Class; ODD(gdh_GetSuperClass(cid, &cid, cp->Objid));) for (cid = cp->Class; ODD(gdh_GetSuperClass(cid, &cid, cp->Objid));)
; ;
if (cid == pwr_cClass_Pb_Module) { if (cid == pwr_cClass_Pb_Module)
{
/* New style configuring (from v4.1.3) with Pb_Module objects or /* New style configuring (from v4.1.3) with Pb_Module objects or
subclass. Loop all channels in the module and set channel size and subclass. Loop all channels in the module and set channel size and
offset. */ offset. */
for (i = 0; i < cp->ChanListSize; ++i) { for (i = 0; i < cp->ChanListSize; ++i)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (is_diag(&chanp->ChanAref)) { if (is_diag(&chanp->ChanAref))
{
chanp->udata |= PB_UDATA_DIAG; chanp->udata |= PB_UDATA_DIAG;
if (chanp->ChanClass != pwr_cClass_ChanIi) if (chanp->ChanClass != pwr_cClass_ChanIi)
errh_Error("Diagnostic channel class, card %s", cp->Name); errh_Error("Diagnostic channel class, card %s", cp->Name);
continue; continue;
} }
if (chanp->ChanClass != pwr_cClass_ChanDi) { if (chanp->ChanClass != pwr_cClass_ChanDi)
{
input_counter += latent_input_count; input_counter += latent_input_count;
latent_input_count = 0; latent_input_count = 0;
} }
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanDi: case pwr_cClass_ChanDi:
chan_di = (pwr_sClass_ChanDi*)chanp->cop; chan_di = (pwr_sClass_ChanDi*)chanp->cop;
if (chan_di->Number == 0) { if (chan_di->Number == 0)
{
input_counter += latent_input_count; input_counter += latent_input_count;
latent_input_count = 0; latent_input_count = 0;
} }
...@@ -326,29 +340,35 @@ static short module_cnt_outputs(io_sCard* cp) ...@@ -326,29 +340,35 @@ static short module_cnt_outputs(io_sCard* cp)
for (cid = cp->Class; ODD(gdh_GetSuperClass(cid, &cid, cp->Objid));) for (cid = cp->Class; ODD(gdh_GetSuperClass(cid, &cid, cp->Objid));)
; ;
if (cid == pwr_cClass_Pb_Module) { if (cid == pwr_cClass_Pb_Module)
{
/* New style configuring (from v4.1.3) with Pb_Module objects or /* New style configuring (from v4.1.3) with Pb_Module objects or
subclass. Loop all channels in the module and set channel size and subclass. Loop all channels in the module and set channel size and
offset. */ offset. */
for (i = 0; i < cp->ChanListSize; i++) { for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (is_diag(&chanp->ChanAref)) { if (is_diag(&chanp->ChanAref))
{
chanp->udata |= PB_UDATA_DIAG; chanp->udata |= PB_UDATA_DIAG;
if (chanp->ChanClass != pwr_cClass_ChanIi) if (chanp->ChanClass != pwr_cClass_ChanIi)
errh_Error("Diagnostic channel class, card %s", cp->Name); errh_Error("Diagnostic channel class, card %s", cp->Name);
continue; continue;
} }
if (chanp->ChanClass != pwr_cClass_ChanDo) { if (chanp->ChanClass != pwr_cClass_ChanDo)
{
output_counter += latent_output_count; output_counter += latent_output_count;
latent_output_count = 0; latent_output_count = 0;
} }
switch (chanp->ChanClass) { switch (chanp->ChanClass)
{
case pwr_cClass_ChanDo: case pwr_cClass_ChanDo:
chan_do = (pwr_sClass_ChanDo*)chanp->cop; chan_do = (pwr_sClass_ChanDo*)chanp->cop;
if (chan_do->Number == 0) { if (chan_do->Number == 0)
{
output_counter += latent_output_count; output_counter += latent_output_count;
latent_output_count = 0; latent_output_count = 0;
} }
...@@ -385,7 +405,8 @@ The function will also set up the required fields in op so that Proview ...@@ -385,7 +405,8 @@ The function will also set up the required fields in op so that Proview
may perform IO operations using the IoAgentRead() and IoAgentWrite() functions may perform IO operations using the IoAgentRead() and IoAgentWrite() functions
in this module. */ in this module. */
static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, 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_sRack* rp, DPM_SL_PRM_ADD_TAB* add_tab,
int add_tab_len)
{ {
io_sCard* cardp; io_sCard* cardp;
short input_counter; short input_counter;
...@@ -400,10 +421,10 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, ...@@ -400,10 +421,10 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap,
slaves/modules have occupied so far. */ slaves/modules have occupied so far. */
unsigned short* input_size; unsigned short* input_size;
unsigned short* output_size; unsigned short* output_size;
input_size input_size =
= (unsigned short*)&((io_sAgentLocalHilscher*)ap->Local)->input_size; (unsigned short*)&((io_sAgentLocalHilscher*)ap->Local)->input_size;
output_size output_size =
= (unsigned short*)&((io_sAgentLocalHilscher*)ap->Local)->output_size; (unsigned short*)&((io_sAgentLocalHilscher*)ap->Local)->output_size;
/* This lets Proview find the IO-area for this module (in this case it is /* 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 actually handled at the agent level, thus in this file). The offsets
...@@ -415,21 +436,24 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, ...@@ -415,21 +436,24 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap,
op->BytesOfOutput = 0; op->BytesOfOutput = 0;
/* Finds our rack (slave). */ /* Finds our rack (slave). */
for (sl = rp; sl != NULL for (sl = rp;
&& ((pwr_sClass_Pb_DP_Slave*)sl->op)->SlaveAddress != op->SlaveAddress; sl != NULL &&
((pwr_sClass_Pb_DP_Slave*)sl->op)->SlaveAddress != op->SlaveAddress;
sl = sl->next) sl = sl->next)
; ;
if (sl == NULL if (sl == NULL ||
|| ((pwr_sClass_Pb_DP_Slave*)sl->op)->SlaveAddress != op->SlaveAddress) { ((pwr_sClass_Pb_DP_Slave*)sl->op)->SlaveAddress != op->SlaveAddress)
{
errh_Error("Profibus DP Master %s - " errh_Error("Profibus DP Master %s - "
" Can't find rack for slave %d", " Can't find rack for slave %d",
ap->Name, op->SlaveAddress); ap->Name, op->SlaveAddress);
return; return;
} }
/* Iterates through the cards (modules in Profibus terminology) of /* Iterates through the cards (modules in Profibus terminology) of
the current rack, counting the length of the input area as we go. */ the current rack, counting the length of the input area as we go. */
for (cardp = sl->cardlist; cardp; cardp = cardp->next) { for (cardp = sl->cardlist; cardp; cardp = cardp->next)
{
/* Gets the size of the input area for this module. */ /* Gets the size of the input area for this module. */
input_counter = module_cnt_inputs(cardp); input_counter = module_cnt_inputs(cardp);
...@@ -438,19 +462,21 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, ...@@ -438,19 +462,21 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap,
/* Only modules with and input or output area are required to /* Only modules with and input or output area are required to
have an entry in the add tab. */ have an entry in the add tab. */
if (input_counter > 0) { if (input_counter > 0)
{
assert(add_tab->bInput_Count + 4 < add_tab_len); assert(add_tab->bInput_Count + 4 < add_tab_len);
/* The MSB tells the Hilscher board whether to treat the address /* The MSB tells the Hilscher board whether to treat the address
as a byte (set) or word (unset) offset as a byte (set) or word (unset) offset
(see dpm_pie.pdf, page 45). */ (see dpm_pie.pdf, page 45). */
add_tab->ausEA_Offset[add_tab->bInput_Count++] add_tab->ausEA_Offset[add_tab->bInput_Count++] =
= *input_size | EA_OFFSET_BYTE; *input_size | EA_OFFSET_BYTE;
*input_size += input_counter; *input_size += input_counter;
} }
} }
/* Now process the output areas. */ /* Now process the output areas. */
for (cardp = sl->cardlist; cardp; cardp = cardp->next) { for (cardp = sl->cardlist; cardp; cardp = cardp->next)
{
/* Gets the size of the output area for this module. */ /* Gets the size of the output area for this module. */
output_counter = module_cnt_outputs(cardp); output_counter = module_cnt_outputs(cardp);
...@@ -459,14 +485,15 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, ...@@ -459,14 +485,15 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap,
/* Only modules with and input or output area are required to /* Only modules with and input or output area are required to
have an entry in the add tab. */ have an entry in the add tab. */
if (output_counter > 0) { if (output_counter > 0)
{
assert(add_tab->bInput_Count + add_tab->bOutput_Count + 4 < add_tab_len); assert(add_tab->bInput_Count + add_tab->bOutput_Count + 4 < add_tab_len);
/* The MSB tells the Hilscher board whether to treat the address /* The MSB tells the Hilscher board whether to treat the address
as a byte (set) or word (unset) offset as a byte (set) or word (unset) offset
(see dpm_pie.pdf, page 45). */ (see dpm_pie.pdf, page 45). */
/* The input offsets precedes the output offsets. */ /* The input offsets precedes the output offsets. */
add_tab->ausEA_Offset[add_tab->bInput_Count + add_tab->bOutput_Count++] add_tab->ausEA_Offset[add_tab->bInput_Count + add_tab->bOutput_Count++] =
= *output_size | EA_OFFSET_BYTE; *output_size | EA_OFFSET_BYTE;
*output_size += output_counter; *output_size += output_counter;
} }
} }
...@@ -474,9 +501,10 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, ...@@ -474,9 +501,10 @@ static void dpm_set_add_tab(pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap,
assert(add_tab->bInput_Count + add_tab->bOutput_Count <= MAX_EA_OFFSET_LEN); assert(add_tab->bInput_Count + add_tab->bOutput_Count <= MAX_EA_OFFSET_LEN);
/* Updates the length of the add_tab struct. */ /* Updates the length of the add_tab struct. */
add_tab->usAdd_Tab_Len = sizeof(add_tab->usAdd_Tab_Len) add_tab->usAdd_Tab_Len =
+ sizeof(add_tab->bInput_Count) + sizeof(add_tab->bOutput_Count) sizeof(add_tab->usAdd_Tab_Len) + sizeof(add_tab->bInput_Count) +
+ 2 * add_tab->bInput_Count + 2 * add_tab->bOutput_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. */ /* Writes instructions for reflashing the board to the error log. */
...@@ -499,9 +527,11 @@ static void dpm_ddlm_answer_msg_print_error(RCS_MESSAGE* msg, io_sAgent* ap) ...@@ -499,9 +527,11 @@ static void dpm_ddlm_answer_msg_print_error(RCS_MESSAGE* msg, io_sAgent* ap)
if (msg == NULL) if (msg == NULL)
return; return;
switch (msg->a) { switch (msg->a)
{
case DDLM_Download: case DDLM_Download:
switch (msg->f) { switch (msg->f)
{
case 0: case 0:
return; return;
case CON_NO: case CON_NO:
...@@ -551,7 +581,8 @@ static void dpm_ddlm_answer_msg_print_error(RCS_MESSAGE* msg, io_sAgent* ap) ...@@ -551,7 +581,8 @@ static void dpm_ddlm_answer_msg_print_error(RCS_MESSAGE* msg, io_sAgent* ap)
break; break;
case DDLM_Slave_Diag: case DDLM_Slave_Diag:
switch (msg->f) { switch (msg->f)
{
case 0: case 0:
return; return;
case CON_NA: case CON_NA:
...@@ -567,7 +598,7 @@ static void dpm_ddlm_answer_msg_print_error(RCS_MESSAGE* msg, io_sAgent* ap) ...@@ -567,7 +598,7 @@ static void dpm_ddlm_answer_msg_print_error(RCS_MESSAGE* msg, io_sAgent* ap)
return; return;
} }
errh_Info("Profibus DP Master %s - Station %d - DDLM Slave Diag: %s", errh_Info("Profibus DP Master %s - Station %d - DDLM Slave Diag: %s",
ap->Name, ((RCS_MESSAGETELEGRAM_10*)msg)->device_adr, s); ap->Name, ((RCS_MESSAGETELEGRAM_10*)msg)->device_adr, s);
break; break;
default: default:
...@@ -582,7 +613,8 @@ or 127 to set master bus parameters. The bus parameters are read from ...@@ -582,7 +613,8 @@ 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 the buffer prmdata and shall be of length prmlen. DRV_NO_ERROR is returned
if successful. */ if successful. */
static short dpm_ddlm_download(io_sAgentLocalHilscher* local, static short dpm_ddlm_download(io_sAgentLocalHilscher* local,
unsigned char address, unsigned int prmlen, void* prmdata, io_sAgent* ap) unsigned char address, unsigned int prmlen,
void* prmdata, io_sAgent* ap)
{ {
short rv; short rv;
int got_response = 0; int got_response = 0;
...@@ -613,32 +645,40 @@ static short dpm_ddlm_download(io_sAgentLocalHilscher* local, ...@@ -613,32 +645,40 @@ static short dpm_ddlm_download(io_sAgentLocalHilscher* local,
assert(prmlen <= 240); assert(prmlen <= 240);
memcpy(&(msg.d[4]), prmdata, prmlen); memcpy(&(msg.d[4]), prmdata, prmlen);
if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC*)&msg, 5000)) if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC*)&msg, 5000)) !=
!= DRV_NO_ERROR) { DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - DDLM_Download - DevPutMessage()" errh_Error("Profibus DP Master %s - DDLM_Download - DevPutMessage()"
" returned %d", " returned %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
/* Checks confirmation message. */ /* Checks confirmation message. */
while (!got_response) { while (!got_response)
if ((rv = DevGetMessage( {
local->dev_number, sizeof(rcv_msg), (MSG_STRUC*)&rcv_msg, 5000)) if ((rv = DevGetMessage(local->dev_number, sizeof(rcv_msg),
!= DRV_NO_ERROR) { (MSG_STRUC*)&rcv_msg, 5000)) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - DDLM_Download - DevGetMessage()" errh_Error("Profibus DP Master %s - DDLM_Download - DevGetMessage()"
" returned %d", " returned %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} else if (rcv_msg.nr != local->cif_msgcnt || rcv_msg.rx != 16 }
|| rcv_msg.tx != 3 || rcv_msg.a != DDLM_Download) { 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. */ /* Discards all messages prior to our response. */
memset(&rcv_msg, 0, sizeof(rcv_msg)); memset(&rcv_msg, 0, sizeof(rcv_msg));
continue; continue;
} else if (rcv_msg.f != 0) { }
else if (rcv_msg.f != 0)
{
dpm_ddlm_answer_msg_print_error(&rcv_msg, ap); dpm_ddlm_answer_msg_print_error(&rcv_msg, ap);
return rcv_msg.f; return rcv_msg.f;
} else { }
else
{
got_response = 1; got_response = 1;
} }
} }
...@@ -648,8 +688,8 @@ static short dpm_ddlm_download(io_sAgentLocalHilscher* local, ...@@ -648,8 +688,8 @@ static short dpm_ddlm_download(io_sAgentLocalHilscher* local,
/* Configures the master bus parameters of the board referred to by /* Configures the master bus parameters of the board referred to by
local, the struct containing the parameters should be passed in op. */ local, the struct containing the parameters should be passed in op. */
static short dpm_download_master_prm( static short dpm_download_master_prm(io_sAgentLocalHilscher* local,
io_sAgentLocalHilscher* local, pwr_sClass_Pb_Hilscher* op, io_sAgent* ap) pwr_sClass_Pb_Hilscher* op, io_sAgent* ap)
{ {
DPM_BUS_DP prm; DPM_BUS_DP prm;
...@@ -661,14 +701,17 @@ static short dpm_download_master_prm( ...@@ -661,14 +701,17 @@ static short dpm_download_master_prm(
prm.usBus_Para_Len = 32; prm.usBus_Para_Len = 32;
/* The master's address is hardcoded to 0. */ /* The master's address is hardcoded to 0. */
prm.bFDL_Add = 0; prm.bFDL_Add = 0;
prm.bBaudrate = ((op->BaudRate == 500) ? (DP_BAUD_500) prm.bBaudrate =
: (op->BaudRate == 1500) ((op->BaudRate == 500)
? (DP_BAUD_1500) ? (DP_BAUD_500)
: (op->BaudRate == 3000) ? (DP_BAUD_3000) : (op->BaudRate == 1500)
: (op->BaudRate == 6000) ? (DP_BAUD_1500)
? (DP_BAUD_6000) : (op->BaudRate == 3000)
: (op->BaudRate == 12000) ? (DP_BAUD_12000) ? (DP_BAUD_3000)
: (DP_BAUD_1500)); : (op->BaudRate == 6000)
? (DP_BAUD_6000)
: (op->BaudRate == 12000) ? (DP_BAUD_12000)
: (DP_BAUD_1500));
prm.usTSL = op->Tsl; prm.usTSL = op->Tsl;
prm.usMin_TSDR = op->MinTsdr; prm.usMin_TSDR = op->MinTsdr;
prm.usMax_TSDR = op->MaxTsdr; prm.usMax_TSDR = op->MaxTsdr;
...@@ -696,7 +739,8 @@ is passed in local. op holds the slave to configure, the corresponding ...@@ -696,7 +739,8 @@ 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. agent pointer and rack pointer must be passed in ap and rp respectively.
DRV_NO_ERROR will be returned upon success. */ DRV_NO_ERROR will be returned upon success. */
static short dpm_download_slave_prm(io_sAgentLocalHilscher* local, static short dpm_download_slave_prm(io_sAgentLocalHilscher* local,
pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap, io_sRack* rp) pwr_sClass_Pb_DP_Slave* op, io_sAgent* ap,
io_sRack* rp)
{ {
unsigned char buf[DPM_MAX_LEN_DATA_UNIT]; unsigned char buf[DPM_MAX_LEN_DATA_UNIT];
unsigned int bufcnt = 0; unsigned int bufcnt = 0;
...@@ -790,8 +834,8 @@ static short dpm_download_slave_prm(io_sAgentLocalHilscher* local, ...@@ -790,8 +834,8 @@ static short dpm_download_slave_prm(io_sAgentLocalHilscher* local,
board referred to by local. The function will return DRV_NO_ERROR if board referred to by local. The function will return DRV_NO_ERROR if
the request was sent without error, however, it tells us nothing the request was sent without error, however, it tells us nothing
about whether any diagnostics data was sent back. */ about whether any diagnostics data was sent back. */
static short dpm_req_slave_diag( static short dpm_req_slave_diag(io_sAgentLocalHilscher* local,
io_sAgentLocalHilscher* local, unsigned char address, io_sAgent* ap) unsigned char address, io_sAgent* ap)
{ {
short rv; short rv;
RCS_MESSAGETELEGRAM_10 msg; RCS_MESSAGETELEGRAM_10 msg;
...@@ -819,11 +863,12 @@ static short dpm_req_slave_diag( ...@@ -819,11 +863,12 @@ static short dpm_req_slave_diag(
msg.function = TASK_TFC_READ; msg.function = TASK_TFC_READ;
/* Requests diagnostic data from slave. */ /* Requests diagnostic data from slave. */
if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC*)&msg, 0)) if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC*)&msg, 0)) !=
!= DRV_NO_ERROR) { DRV_NO_ERROR)
{
errh_Info("Profibus DP Master %s - DDLM_Slave_Diag - DevPutMessage()" errh_Info("Profibus DP Master %s - DDLM_Slave_Diag - DevPutMessage()"
" returned %d", " returned %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
...@@ -834,8 +879,8 @@ static short dpm_req_slave_diag( ...@@ -834,8 +879,8 @@ static short dpm_req_slave_diag(
to gather diagnostics data asynchronously. The desired agent's local to gather diagnostics data asynchronously. The desired agent's local
struct is passed via local and the associated rack list (Profibus slaves) is struct is passed via local and the associated rack list (Profibus slaves) is
passed in slave_list. */ passed in slave_list. */
static void dpm_update_slave_diag( static void dpm_update_slave_diag(io_sAgentLocalHilscher* local,
io_sAgentLocalHilscher* local, io_sRack* slave_list, io_sAgent* ap) io_sRack* slave_list, io_sAgent* ap)
{ {
short rv; short rv;
RCS_MESSAGETELEGRAM_10 rcv_msg; RCS_MESSAGETELEGRAM_10 rcv_msg;
...@@ -846,33 +891,40 @@ static void dpm_update_slave_diag( ...@@ -846,33 +891,40 @@ static void dpm_update_slave_diag(
memset(&rcv_msg, 0, sizeof(rcv_msg)); memset(&rcv_msg, 0, sizeof(rcv_msg));
/* Gets pending diagnostic messages, discards all other messages. */ /* Gets pending diagnostic messages, discards all other messages. */
while ((rv = DevGetMessage( while ((rv = DevGetMessage(local->dev_number, sizeof(rcv_msg),
local->dev_number, sizeof(rcv_msg), (MSG_STRUC*)&rcv_msg, 0)) (MSG_STRUC*)&rcv_msg, 0)) == DRV_NO_ERROR)
== DRV_NO_ERROR) { {
if (rcv_msg.rx != 16 || rcv_msg.tx != 3 || rcv_msg.a != DDLM_Slave_Diag) { if (rcv_msg.rx != 16 || rcv_msg.tx != 3 || rcv_msg.a != DDLM_Slave_Diag)
{
/* Discards received message. */ /* Discards received message. */
memset(&rcv_msg, 0, sizeof(rcv_msg)); memset(&rcv_msg, 0, sizeof(rcv_msg));
continue; continue;
} else if (rcv_msg.f != 0) { }
else if (rcv_msg.f != 0)
{
dpm_ddlm_answer_msg_print_error((RCS_MESSAGE*)&rcv_msg, ap); dpm_ddlm_answer_msg_print_error((RCS_MESSAGE*)&rcv_msg, ap);
/* Discards received message. */ /* Discards received message. */
memset(&rcv_msg, 0, sizeof(rcv_msg)); memset(&rcv_msg, 0, sizeof(rcv_msg));
continue; continue;
} else { }
else
{
/*** Updates Proview's structs with the acquired diagnostics. ***/ /*** Updates Proview's structs with the acquired diagnostics. ***/
/* Finds our slave. */ /* Finds our slave. */
for (sl = slave_list; sl != NULL; sl = sl->next) { for (sl = slave_list; sl != NULL; sl = sl->next)
{
sp = (pwr_sClass_Pb_DP_Slave*)sl->op; sp = (pwr_sClass_Pb_DP_Slave*)sl->op;
if (sp->SlaveAddress == rcv_msg.device_adr) if (sp->SlaveAddress == rcv_msg.device_adr)
break; break;
} }
/* The slave from which we were to read diagnostic data could not /* The slave from which we were to read diagnostic data could not
be found -- abort. */ be found -- abort. */
if (sp->SlaveAddress != rcv_msg.device_adr) { if (sp->SlaveAddress != rcv_msg.device_adr)
{
errh_Error("Profibus DP Master %s - Received diagnostic message" errh_Error("Profibus DP Master %s - Received diagnostic message"
" from unknown slave %d", " from unknown slave %d",
ap->Name, rcv_msg.device_adr); ap->Name, rcv_msg.device_adr);
return; return;
} }
...@@ -888,23 +940,31 @@ static void dpm_update_slave_diag( ...@@ -888,23 +940,31 @@ static void dpm_update_slave_diag(
/* Updates the slave's status */ /* Updates the slave's status */
if (!(sp->StationStatus1 & ~pwr_mPbStationStatus1Mask_ExternalDiag) if (!(sp->StationStatus1 & ~pwr_mPbStationStatus1Mask_ExternalDiag) &&
&& !(sp->StationStatus2 !(sp->StationStatus2 &
& ~(pwr_mPbStationStatus2Mask_Default ~(pwr_mPbStationStatus2Mask_Default |
| pwr_mPbStationStatus2Mask_ResponseMonitoringOn))) { pwr_mPbStationStatus2Mask_ResponseMonitoringOn)))
{
sp->Status = PB__NORMAL; sp->Status = PB__NORMAL;
} else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent) { }
else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent)
{
sp->Status = PB__NOCONN; sp->Status = PB__NOCONN;
} else if ((sp->StationStatus1 }
& (pwr_mPbStationStatus1Mask_ConfigFault else if ((sp->StationStatus1 & (pwr_mPbStationStatus1Mask_ConfigFault |
| pwr_mPbStationStatus1Mask_ParamFault)) pwr_mPbStationStatus1Mask_ParamFault)) ||
|| (sp->StationStatus2 (sp->StationStatus2 &
& pwr_mPbStationStatus2Mask_NewParamsRequested)) { pwr_mPbStationStatus2Mask_NewParamsRequested))
{
sp->Status = PB__CONFIGERR; sp->Status = PB__CONFIGERR;
} else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_MasterLock) { }
else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_MasterLock)
{
sp->Status = PB__MASTERLOCK; sp->Status = PB__MASTERLOCK;
} else { /* if (sp->StationStatus1 }
& pwr_mPbStationStatus1Mask_NotReady) */ else
{ /* if (sp->StationStatus1
& pwr_mPbStationStatus1Mask_NotReady) */
sp->Status = PB__NOTREADY; sp->Status = PB__NOTREADY;
} }
} }
...@@ -917,10 +977,14 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag) ...@@ -917,10 +977,14 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag)
{ {
char* s; char* s;
if (diag->tError.bErr_Event == 0) { if (diag->tError.bErr_Event == 0)
{
return; return;
} else if (diag->tError.bErr_Rem_Adr == 255) { }
switch (diag->tError.bErr_Event) { else if (diag->tError.bErr_Rem_Adr == 255)
{
switch (diag->tError.bErr_Event)
{
case TASK_F_NO_USR_TASK: case TASK_F_NO_USR_TASK:
s = "usr task not found"; s = "usr task not found";
break; break;
...@@ -993,8 +1057,11 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag) ...@@ -993,8 +1057,11 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag)
errh_Info("Profibus DP Master %s - %s", ap->Name, s); errh_Info("Profibus DP Master %s - %s", ap->Name, s);
return; return;
} else { }
switch (diag->tError.bErr_Event) { else
{
switch (diag->tError.bErr_Event)
{
case CON_NA: case CON_NA:
s = "no reaction of the remote station"; s = "no reaction of the remote station";
break; break;
...@@ -1013,7 +1080,7 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag) ...@@ -1013,7 +1080,7 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag)
#ifdef SLAVE_DIAG_VERBOSE #ifdef SLAVE_DIAG_VERBOSE
errh_Info("Profibus DP Master %s - Station %d - %s", ap->Name, errh_Info("Profibus DP Master %s - Station %d - %s", ap->Name,
diag->tError.bErr_Rem_Adr, s); diag->tError.bErr_Rem_Adr, s);
#endif /* SLAVE_DIAG_VERBOSE */ #endif /* SLAVE_DIAG_VERBOSE */
return; return;
} }
...@@ -1026,7 +1093,7 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag) ...@@ -1026,7 +1093,7 @@ static void dpm_print_diag(io_sAgent* ap, DPM_DIAGNOSTICS* diag)
If the board was found in the database, the function returns DRV_NO_ERROR 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. */ and the startsegment will be written to what db_startsegment points to. */
static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap, static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap,
unsigned char* db_startsegment) unsigned char* db_startsegment)
{ {
short rv; short rv;
DEVINFO info; DEVINFO info;
...@@ -1035,16 +1102,17 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap, ...@@ -1035,16 +1102,17 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap,
assert(DRV_NO_ERROR == 0); assert(DRV_NO_ERROR == 0);
/* Gets device information from the board. */ /* Gets device information from the board. */
if ((rv = DevGetInfo(local->dev_number, GET_DEV_INFO, sizeof(info), &info)) if ((rv = DevGetInfo(local->dev_number, GET_DEV_INFO, sizeof(info), &info)) !=
!= DRV_NO_ERROR) { DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s - Error %d while checking board type.", errh_Error("Profibus DP Master %s - Error %d while checking board type.",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
errh_Info("Profibus DP Master %s -" errh_Info("Profibus DP Master %s -"
" Selected board %d has the following device info:", " Selected board %d has the following device info:",
ap->Name, local->dev_number); ap->Name, local->dev_number);
errh_Info("Device DPM size: %d", info.bDpmSize); errh_Info("Device DPM size: %d", info.bDpmSize);
errh_Info("Device type: %d", info.bDevType); errh_Info("Device type: %d", info.bDevType);
errh_Info("Device model: %d", info.bDevModel); errh_Info("Device model: %d", info.bDevModel);
...@@ -1055,7 +1123,8 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap, ...@@ -1055,7 +1123,8 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap,
if (memcmp(&known_boards[i].info, &info, sizeof(info)) == 0) if (memcmp(&known_boards[i].info, &info, sizeof(info)) == 0)
break; break;
if (known_boards[i].entry == 0) { if (known_boards[i].entry == 0)
{
/* Board was not found in table. */ /* Board was not found in table. */
errh_Error("Profibus DP Master %s - Unknown board.", ap->Name); 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("To add support for this board, look up its database start");
...@@ -1067,8 +1136,9 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap, ...@@ -1067,8 +1136,9 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap,
errh_Error("in the above mentioned documentation."); errh_Error("in the above mentioned documentation.");
errh_Error("{ 1, { %d, %d, %d, { '%c', '%c', '%c'} }, " errh_Error("{ 1, { %d, %d, %d, { '%c', '%c', '%c'} }, "
"<db start segment>, \"<board name>\" },", "<db start segment>, \"<board name>\" },",
info.bDpmSize, info.bDevType, info.bDevModel, info.abDevIdentifier[0], info.bDpmSize, info.bDevType, info.bDevModel,
info.abDevIdentifier[1], info.abDevIdentifier[2]); info.abDevIdentifier[0], info.abDevIdentifier[1],
info.abDevIdentifier[2]);
return BOARD_INIT_ERROR; return BOARD_INIT_ERROR;
} }
...@@ -1084,8 +1154,8 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap, ...@@ -1084,8 +1154,8 @@ static short dpm_check_board_type(io_sAgentLocalHilscher* local, io_sAgent* ap,
/* Deletes the "PROFIBUS" protocol settings database from the card referred /* 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. */ to by local, this procedure is described on page 32 -- 33 in dpm_pie.pdf. */
static short dpm_delete_flash_prmdb( static short dpm_delete_flash_prmdb(io_sAgentLocalHilscher* local,
io_sAgentLocalHilscher* local, io_sAgent* ap) io_sAgent* ap)
{ {
unsigned char db_startsegment; unsigned char db_startsegment;
int s = 3; int s = 3;
...@@ -1101,7 +1171,7 @@ static short dpm_delete_flash_prmdb( ...@@ -1101,7 +1171,7 @@ static short dpm_delete_flash_prmdb(
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
/* Defines message header. */ /* Defines message header. */
msg.rx = 0; /* receiver = RCS-Task */ msg.rx = 0; /* receiver = RCS-Task */
msg.tx = 16; /* transmitter = user at HOST */ msg.tx = 16; /* transmitter = user at HOST */
msg.ln = 2; msg.ln = 2;
msg.nr = ++local->cif_msgcnt; msg.nr = ++local->cif_msgcnt;
...@@ -1114,21 +1184,22 @@ static short dpm_delete_flash_prmdb( ...@@ -1114,21 +1184,22 @@ static short dpm_delete_flash_prmdb(
msg.d[0] = 4; /* mode = delete data base */ msg.d[0] = 4; /* mode = delete data base */
msg.d[1] = db_startsegment; msg.d[1] = db_startsegment;
errh_Info( errh_Info("Profibus DP Master %s - Sending delete database request...",
"Profibus DP Master %s - Sending delete database request...", ap->Name); ap->Name);
/* Sends delete database request. */ /* Sends delete database request. */
if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC*)&msg, 5000)) if ((rv = DevPutMessage(local->dev_number, (MSG_STRUC*)&msg, 5000)) !=
!= DRV_NO_ERROR) { DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s -" errh_Error("Profibus DP Master %s -"
" DevPutMessage failed with return code %d", " DevPutMessage failed with return code %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} }
/* Waits for controller to update flash. */ /* Waits for controller to update flash. */
errh_Info("Profibus DP Master %s -" errh_Info("Profibus DP Master %s -"
" Delete db request sent. Waiting %d seconds...", " Delete db request sent. Waiting %d seconds...",
ap->Name, s); ap->Name, s);
while ((s = sleep(s))) while ((s = sleep(s)))
; ;
...@@ -1136,28 +1207,33 @@ static short dpm_delete_flash_prmdb( ...@@ -1136,28 +1207,33 @@ static short dpm_delete_flash_prmdb(
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
/* Gets response message. */ /* Gets response message. */
while (!got_response) { while (!got_response)
if ((rv = DevGetMessage( {
local->dev_number, sizeof(msg), (MSG_STRUC*)&msg, 10000)) if ((rv = DevGetMessage(local->dev_number, sizeof(msg), (MSG_STRUC*)&msg,
!= DRV_NO_ERROR) { 10000)) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s -" errh_Error("Profibus DP Master %s -"
" DevGetMessage failed with return code %d\n", " DevGetMessage failed with return code %d\n",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} else if (msg.nr != local->cif_msgcnt || msg.rx != 16 || msg.tx != 0 }
|| msg.a != 6) { else if (msg.nr != local->cif_msgcnt || msg.rx != 16 || msg.tx != 0 ||
msg.a != 6)
{
/* Discards all messages prior to our response. */ /* Discards all messages prior to our response. */
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
continue; continue;
} else { }
else
{
if (msg.f != 0) if (msg.f != 0)
errh_Error("Profibus DP Master %s -" errh_Error("Profibus DP Master %s -"
" Delete db confirmation message f-flag set to %d", " Delete db confirmation message f-flag set to %d",
ap->Name, msg.f); ap->Name, msg.f);
else else
errh_Info("Profibus DP Master %s -" errh_Info("Profibus DP Master %s -"
" Delete database confirmation message received.", " Delete database confirmation message received.",
ap->Name); ap->Name);
got_response = 1; got_response = 1;
} }
} }
...@@ -1173,8 +1249,9 @@ static short dpm_delete_flash_prmdb( ...@@ -1173,8 +1249,9 @@ static short dpm_delete_flash_prmdb(
/* Wrapper for dpm_init_master(), takes care of checking for (and optionally /* Wrapper for dpm_init_master(), takes care of checking for (and optionally
removing) the sycon database if present. */ removing) the sycon database if present. */
static short dpm_init_master_check_sycon_db( static short dpm_init_master_check_sycon_db(io_sAgentLocalHilscher* local,
io_sAgentLocalHilscher* local, pwr_sClass_Pb_Hilscher* op, io_sAgent* ap) pwr_sClass_Pb_Hilscher* op,
io_sAgent* ap)
{ {
short rv; short rv;
DRIVERINFO di; DRIVERINFO di;
...@@ -1182,30 +1259,36 @@ static short dpm_init_master_check_sycon_db( ...@@ -1182,30 +1259,36 @@ static short dpm_init_master_check_sycon_db(
assert(DRV_NO_ERROR == 0); assert(DRV_NO_ERROR == 0);
/* Initializes DP Master. */ /* Initializes DP Master. */
if ((rv = dpm_init_master(local, op, ap)) != DRV_NO_ERROR) { if ((rv = dpm_init_master(local, op, ap)) != DRV_NO_ERROR)
{
return rv; return rv;
} else if ((rv = DevGetInfo( }
local->dev_number, GET_DRIVER_INFO, sizeof(di), &di)) else if ((rv = DevGetInfo(local->dev_number, GET_DRIVER_INFO, sizeof(di),
!= DRV_NO_ERROR) { &di)) != DRV_NO_ERROR)
{
errh_Error("Profibus DP Master %s -" errh_Error("Profibus DP Master %s -"
" DevGetInfo failed with return code %d", " DevGetInfo failed with return code %d",
ap->Name, rv); ap->Name, rv);
return rv; return rv;
} else if ((di.bHostFlags & (READY_FLAG | RUN_FLAG)) }
== (READY_FLAG | RUN_FLAG)) { else if ((di.bHostFlags & (READY_FLAG | RUN_FLAG)) == (READY_FLAG | RUN_FLAG))
{
/* RUN and RDY bits set */ /* RUN and RDY bits set */
errh_Info( errh_Info("Profibus DP Master %s - Hostflags: 0x%X", ap->Name,
"Profibus DP Master %s - Hostflags: 0x%X", ap->Name, di.bHostFlags); di.bHostFlags);
errh_Info("Device is configured by SyCon."); errh_Info("Device is configured by SyCon.");
#ifdef FLASH_WRITE_ENABLE #ifdef FLASH_WRITE_ENABLE
errh_Info("Deleting SyCon database from board's flash."); errh_Info("Deleting SyCon database from board's flash.");
if ((rv = dpm_delete_flash_prmdb(local, ap)) != DRV_NO_ERROR) { if ((rv = dpm_delete_flash_prmdb(local, ap)) != DRV_NO_ERROR)
{
return rv; return rv;
} else { }
else
{
/* Reinitializes DP Master. */ /* Reinitializes DP Master. */
rv = dpm_init_master(local, op, ap); rv = dpm_init_master(local, op, ap);
} }
#else /* FLASH_WRITE_ENABLE */ #else /* FLASH_WRITE_ENABLE */
errh_Info("Flash writing is not enabled, "); errh_Info("Flash writing is not enabled, ");
flashing_disabled_warning(ap); flashing_disabled_warning(ap);
return BOARD_INIT_ERROR; return BOARD_INIT_ERROR;
...@@ -1231,13 +1314,14 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1231,13 +1314,14 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
pwr_sClass_Pb_DP_Slave* sop; pwr_sClass_Pb_DP_Slave* sop;
char name[196]; char name[196];
struct timespec rqtp = { 0, 20000000 }; /* 20 ms */ struct timespec rqtp = {0, 20000000}; /* 20 ms */
int retry; int retry;
/* Allocates area for local data structure */ /* Allocates area for local data structure */
ap->Local = calloc(1, sizeof(io_sAgentLocalHilscher)); ap->Local = calloc(1, sizeof(io_sAgentLocalHilscher));
if (!ap->Local) { if (!ap->Local)
{
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, "calloc"); errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, "calloc");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
...@@ -1249,7 +1333,8 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1249,7 +1333,8 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
/* Initializes interface. */ /* Initializes interface. */
if (ctx->Node->Restarts > 0) { if (ctx->Node->Restarts > 0)
{
nanosleep(&rqtp, NULL); nanosleep(&rqtp, NULL);
} }
...@@ -1263,45 +1348,52 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1263,45 +1348,52 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
local->watchdog = 0; local->watchdog = 0;
/* Initializes Profibus driver API. */ /* Initializes Profibus driver API. */
if (dpm_init(local, ap) != DRV_NO_ERROR) { if (dpm_init(local, ap) != DRV_NO_ERROR)
{
/* Cannot open driver */ /* Cannot open driver */
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error( errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"ERROR config Profibus DP Master %s - %s", ap->Name, "open device"); "open device");
ctx->Node->EmergBreakTrue = 1; ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE; return IO__ERRDEVICE;
} }
/* If this is not the Profibus I/O process, return */ /* If this is not the Profibus I/O process, return */
if ((op->Process & io_mProcess_Profibus) if ((op->Process & io_mProcess_Profibus) &&
&& (ctx->Process != io_mProcess_Profibus)) { (ctx->Process != io_mProcess_Profibus))
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
errh_Info("Init template I/O agent for Profibus DP Master %s, %d", ap->Name, errh_Info("Init template I/O agent for Profibus DP Master %s, %d", ap->Name,
ctx->Process); ctx->Process);
return IO__SUCCESS; return IO__SUCCESS;
} }
if (ctx->Node->Restarts > 0) { if (ctx->Node->Restarts > 0)
errh_Info( {
"Warm restart - Skipping config of Profibus DP Master %s", ap->Name); errh_Info("Warm restart - Skipping config of Profibus DP Master %s",
ap->Name);
op->Status = PB__NORMAL; op->Status = PB__NORMAL;
return IO__SUCCESS; return IO__SUCCESS;
} }
errh_Info("Config of Profibus DP Master %s", ap->Name); errh_Info("Config of Profibus DP Master %s", ap->Name);
if (op->DisableBus != 1) { if (op->DisableBus != 1)
{
ok = FALSE; ok = FALSE;
if (ctx->Node->Restarts == 0) { if (ctx->Node->Restarts == 0)
{
retry = 0; retry = 0;
while (!ok) { while (!ok)
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
/* Sets DP master parameters and checks for sycon database. */ /* Sets DP master parameters and checks for sycon database. */
if (dpm_init_master_check_sycon_db(local, op, ap) != DRV_NO_ERROR) { if (dpm_init_master_check_sycon_db(local, op, ap) != DRV_NO_ERROR)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"dp init master"); "dp init master");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
...@@ -1309,42 +1401,46 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1309,42 +1401,46 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
and initializes them. */ and initializes them. */
op->NumberSlaves = 0; op->NumberSlaves = 0;
status = gdh_GetChild(ap->Objid, &slave_objid); status = gdh_GetChild(ap->Objid, &slave_objid);
while (ODD(status)) { while (ODD(status))
{
status = gdh_GetObjectClass(slave_objid, &slave_class); status = gdh_GetObjectClass(slave_objid, &slave_class);
status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress*)&sop); status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress*)&sop);
status = gdh_ObjidToName( status = gdh_ObjidToName(slave_objid, (char*)&name, sizeof(name),
slave_objid, (char*)&name, sizeof(name), cdh_mNName); cdh_mNName);
errh_Info("Download Profibus DP Slave config - %s", name); errh_Info("Download Profibus DP Slave config - %s", name);
/* Calculates IO offsets and configures the slave. */ /* Calculates IO offsets and configures the slave. */
if (dpm_download_slave_prm(local, sop, ap, ap->racklist) if (dpm_download_slave_prm(local, sop, ap, ap->racklist) !=
!= DRV_NO_ERROR) { DRV_NO_ERROR)
{
errh_Error("ERROR Init Profibus DP slave %s", name); errh_Error("ERROR Init Profibus DP slave %s", name);
} }
errh_Info("Profibus DP slave %d: in offs %d, input size %d," errh_Info("Profibus DP slave %d: in offs %d, input size %d,"
" out offs %d, out size %d", " out offs %d, out size %d",
sop->SlaveAddress, sop->OffsetInputs, sop->BytesOfInput, sop->SlaveAddress, sop->OffsetInputs, sop->BytesOfInput,
sop->OffsetOutputs, sop->BytesOfOutput); sop->OffsetOutputs, sop->BytesOfOutput);
op->NumberSlaves++; op->NumberSlaves++;
status = gdh_GetNextSibling(slave_objid, &slave_objid); status = gdh_GetNextSibling(slave_objid, &slave_objid);
} }
/* Downloads the DP bus parameters -- this initiates the /* Downloads the DP bus parameters -- this initiates the
cyclic data exchange. */ cyclic data exchange. */
if (dpm_download_master_prm(local, op, ap) != DRV_NO_ERROR) { if (dpm_download_master_prm(local, op, ap) != DRV_NO_ERROR)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"dp download bus"); "dp download bus");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
ok = TRUE; ok = TRUE;
} /* End - While !ok */ } /* End - While !ok */
} /* End - Initialization only if not restart */ } /* End - Initialization only if not restart */
} else }
else
op->Status = PB__DISABLED; op->Status = PB__DISABLED;
return IO__SUCCESS; return IO__SUCCESS;
...@@ -1376,17 +1472,19 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1376,17 +1472,19 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
however, keeping this code here enables us to confine all the Profibus however, keeping this code here enables us to confine all the Profibus
board specific code at the agent level. */ board specific code at the agent level. */
for (slave_list = ap->racklist; slave_list != NULL; for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) { slave_list = slave_list->next)
{
sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op; sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op;
mp = (pwr_sClass_Pb_Hilscher*)ap->op; mp = (pwr_sClass_Pb_Hilscher*)ap->op;
if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL &&
&& sp->DisableSlave != 1 && mp->DisableBus != 1) { sp->DisableSlave != 1 && mp->DisableBus != 1)
{
/* Triggers the board's watchdog. */ /* Triggers the board's watchdog. */
DevTriggerWatchDog(local->dev_number, WATCHDOG_START, &local->watchdog); DevTriggerWatchDog(local->dev_number, WATCHDOG_START, &local->watchdog);
/* Reads process image from the slave. */ /* Reads process image from the slave. */
rv = DevExchangeIO(local->dev_number, 0, 0, NULL, sp->OffsetInputs, rv = DevExchangeIO(local->dev_number, 0, 0, NULL, sp->OffsetInputs,
sp->BytesOfInput, sp->Inputs, 100); sp->BytesOfInput, sp->Inputs, 100);
} }
} }
...@@ -1399,8 +1497,8 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1399,8 +1497,8 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
Make a poll to see if there are diagnostics, the answer also tells us Make a poll to see if there are diagnostics, the answer also tells us
if there are any hardware faults. */ if there are any hardware faults. */
if ((op->Process & io_mProcess_Profibus) if ((op->Process & io_mProcess_Profibus) &&
&& (ctx->Process != io_mProcess_Profibus)) (ctx->Process != io_mProcess_Profibus))
return IO__SUCCESS; return IO__SUCCESS;
if (op->DisableBus == 1) if (op->DisableBus == 1)
...@@ -1409,27 +1507,32 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1409,27 +1507,32 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
/* Reads the protocol states and checks for errors. */ /* Reads the protocol states and checks for errors. */
DevGetTaskState(local->dev_number, 2, 64, &diag); DevGetTaskState(local->dev_number, 2, 64, &diag);
/* Checks if master is in state OPERATE. */ /* Checks if master is in state OPERATE. */
switch (diag.bDPM_state) { switch (diag.bDPM_state)
{
case OPERATE: case OPERATE:
if (op->Status != PB__NORMAL) { if (op->Status != PB__NORMAL)
{
op->Status = PB__NORMAL; op->Status = PB__NORMAL;
errh_Info("Profibus DP Master %s - Mode changed to OPERATE", ap->Name); errh_Info("Profibus DP Master %s - Mode changed to OPERATE", ap->Name);
} }
break; break;
case CLEAR: case CLEAR:
if (op->Status != PB__CLEARED) { if (op->Status != PB__CLEARED)
{
op->Status = PB__CLEARED; op->Status = PB__CLEARED;
errh_Info("Profibus DP Master %s - Mode changed to CLEAR", ap->Name); errh_Info("Profibus DP Master %s - Mode changed to CLEAR", ap->Name);
} }
break; break;
case STOP: case STOP:
if (op->Status != PB__STOPPED) { if (op->Status != PB__STOPPED)
{
op->Status = PB__STOPPED; op->Status = PB__STOPPED;
errh_Info("Profibus DP Master %s - Mode changed to STOP", ap->Name); errh_Info("Profibus DP Master %s - Mode changed to STOP", ap->Name);
} }
break; break;
case OFFLINE: case OFFLINE:
if (op->Status != PB__NOTINIT) { if (op->Status != PB__NOTINIT)
{
errh_Info("Profibus DP Master %s - Mode changed to OFFLINE", ap->Name); errh_Info("Profibus DP Master %s - Mode changed to OFFLINE", ap->Name);
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
} }
...@@ -1443,10 +1546,12 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1443,10 +1546,12 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
/* Checks if there are any new diagnostics data that we should read from /* Checks if there are any new diagnostics data that we should read from
any of our slaves. */ any of our slaves. */
for (i = 0; i <= 127; ++i) { for (i = 0; i <= 127; ++i)
{
/* The abSl_diag data structure is described on page 22 in /* The abSl_diag data structure is described on page 22 in
dpm_pie.pdf. */ dpm_pie.pdf. */
if (diag.abSl_diag[i >> 3] & (1 << (i & 7))) { if (diag.abSl_diag[i >> 3] & (1 << (i & 7)))
{
/* Request diagnostics from slaves with unread diagnostic data. */ /* Request diagnostics from slaves with unread diagnostic data. */
dpm_req_slave_diag(local, i, ap); dpm_req_slave_diag(local, i, ap);
} }
...@@ -1457,12 +1562,12 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1457,12 +1562,12 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
before its watchdog times out the diagnostics would not be updated. The before its watchdog times out the diagnostics would not be updated. The
following code covers that case, it is a bit ugly, but works. */ following code covers that case, it is a bit ugly, but works. */
for (slave_list = ap->racklist; slave_list != NULL; for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) { slave_list = slave_list->next)
{
sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op; sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op;
/* The abSl_state has the same layout as the abSl_diag bitmap. */ /* The abSl_state has the same layout as the abSl_diag bitmap. */
if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent &&
&& diag.abSl_state[sp->SlaveAddress >> 3] diag.abSl_state[sp->SlaveAddress >> 3] & (1 << (sp->SlaveAddress & 7)))
& (1 << (sp->SlaveAddress & 7)))
dpm_req_slave_diag(local, sp->SlaveAddress, ap); dpm_req_slave_diag(local, sp->SlaveAddress, ap);
} }
/* Collects requested slave diagnostics. */ /* Collects requested slave diagnostics. */
...@@ -1489,20 +1594,23 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap) ...@@ -1489,20 +1594,23 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap)
however, keeping this code here enables us to confine all the Profibus however, keeping this code here enables us to confine all the Profibus
board specific code at the agent level. */ board specific code at the agent level. */
for (slave_list = ap->racklist; slave_list != NULL; for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) { slave_list = slave_list->next)
{
sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op; sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op;
mp = (pwr_sClass_Pb_Hilscher*)ap->op; mp = (pwr_sClass_Pb_Hilscher*)ap->op;
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) &&
&& mp->Status == PB__NORMAL && (sp->DisableSlave != 1) mp->Status == PB__NORMAL && (sp->DisableSlave != 1) &&
&& (mp->DisableBus != 1)) { (mp->DisableBus != 1))
if (sp->BytesOfOutput > 0) { {
if (sp->BytesOfOutput > 0)
{
/* Trigger the board's watchdog. */ /* Trigger the board's watchdog. */
DevTriggerWatchDog(local->dev_number, WATCHDOG_START, &local->watchdog); DevTriggerWatchDog(local->dev_number, WATCHDOG_START, &local->watchdog);
/* Writes process image to the slave. */ /* Writes process image to the slave. */
if (DevExchangeIO(local->dev_number, sp->OffsetOutputs, if (DevExchangeIO(local->dev_number, sp->OffsetOutputs,
sp->BytesOfOutput, sp->Outputs, 0, 0, NULL, 100) sp->BytesOfOutput, sp->Outputs, 0, 0, NULL,
!= DRV_NO_ERROR) 100) != DRV_NO_ERROR)
sp->ErrorCount++; sp->ErrorCount++;
} }
} }
...@@ -1530,6 +1638,7 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap) ...@@ -1530,6 +1638,7 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap)
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Hilscher) = { pwr_BindIoMethod(IoAgentInit), pwr_dExport pwr_BindIoMethods(Pb_Hilscher) = {
pwr_BindIoMethod(IoAgentRead), pwr_BindIoMethod(IoAgentWrite), pwr_BindIoMethod(IoAgentInit), pwr_BindIoMethod(IoAgentRead),
pwr_BindIoMethod(IoAgentClose), pwr_NullMethod }; pwr_BindIoMethod(IoAgentWrite), pwr_BindIoMethod(IoAgentClose),
pwr_NullMethod};
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Ii Init method for the Pb module Ii
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Ii* op; pwr_sClass_Pb_Ii* op;
...@@ -60,7 +60,8 @@ static pwr_tStatus IoCardInit( ...@@ -60,7 +60,8 @@ static pwr_tStatus IoCardInit(
op = (pwr_sClass_Pb_Ii*)cp->op; op = (pwr_sClass_Pb_Ii*)cp->op;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) { if (rp->Class != pwr_cClass_Pb_DP_Slave)
{
errh_Info("Illegal object type %s", cp->Name); errh_Info("Illegal object type %s", cp->Name);
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -74,8 +75,8 @@ static pwr_tStatus IoCardInit( ...@@ -74,8 +75,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Read method for the Pb Ii card Read method for the Pb Ii card
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead( static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Ii* op; pwr_sClass_Pb_Ii* op;
...@@ -95,8 +96,10 @@ static pwr_tStatus IoCardRead( ...@@ -95,8 +96,10 @@ static pwr_tStatus IoCardRead(
op = (pwr_sClass_Pb_Ii*)cp->op; op = (pwr_sClass_Pb_Ii*)cp->op;
slave = (pwr_sClass_Pb_DP_Slave*)rp->op; slave = (pwr_sClass_Pb_DP_Slave*)rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) { if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1)
for (i = 0; i < cp->ChanListSize; i++) { {
for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (!chanp->cop || !chanp->sop) if (!chanp->cop || !chanp->sop)
continue; continue;
...@@ -104,54 +107,76 @@ static pwr_tStatus IoCardRead( ...@@ -104,54 +107,76 @@ static pwr_tStatus IoCardRead(
cop = (pwr_sClass_ChanIi*)chanp->cop; cop = (pwr_sClass_ChanIi*)chanp->cop;
sop = (pwr_sClass_Ii*)chanp->sop; sop = (pwr_sClass_Ii*)chanp->sop;
if (cop->ConversionOn) { if (cop->ConversionOn)
if (op->BytesPerChannel == 4) { {
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { if (op->BytesPerChannel == 4)
{
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
memcpy(&udata32, local->input_area + op->OffsetInputs + 4 * i, 4); memcpy(&udata32, local->input_area + op->OffsetInputs + 4 * i, 4);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata32 = swap32(udata32); udata32 = swap32(udata32);
*(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata32; *(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata32;
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
memcpy(&data32, local->input_area + op->OffsetInputs + 4 * i, 4); memcpy(&data32, local->input_area + op->OffsetInputs + 4 * i, 4);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data32 = swap32(data32); data32 = swap32(data32);
*(pwr_tInt32*)chanp->vbp = data32; *(pwr_tInt32*)chanp->vbp = data32;
} }
} else if (op->BytesPerChannel == 3) { }
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { else if (op->BytesPerChannel == 3)
{
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
udata32 = 0; udata32 = 0;
memcpy(&udata32, local->input_area + op->OffsetInputs + 3 * i, 3); memcpy(&udata32, local->input_area + op->OffsetInputs + 3 * i, 3);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) { if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
{
udata32 = swap32(udata32); udata32 = swap32(udata32);
udata32 = udata32 >> 8; udata32 = udata32 >> 8;
} }
*(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata32; *(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata32;
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
data32 = 0; data32 = 0;
memcpy(&data32, local->input_area + op->OffsetInputs + 3 * i, 3); memcpy(&data32, local->input_area + op->OffsetInputs + 3 * i, 3);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) { if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
{
data32 = swap32(data32); data32 = swap32(data32);
data32 = data32 >> 8; data32 = data32 >> 8;
} }
*(pwr_tInt32*)chanp->vbp = data32; *(pwr_tInt32*)chanp->vbp = data32;
} }
} else if (op->BytesPerChannel == 2) { }
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { else if (op->BytesPerChannel == 2)
{
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
memcpy(&udata16, local->input_area + op->OffsetInputs + 2 * i, 2); memcpy(&udata16, local->input_area + op->OffsetInputs + 2 * i, 2);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
udata16 = swap16(udata16); udata16 = swap16(udata16);
*(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata16; *(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata16;
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
memcpy(&data16, local->input_area + op->OffsetInputs + 2 * i, 2); memcpy(&data16, local->input_area + op->OffsetInputs + 2 * i, 2);
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data16 = swap16(data16); data16 = swap16(data16);
*(pwr_tInt32*)chanp->vbp = (pwr_tInt32)data16; *(pwr_tInt32*)chanp->vbp = (pwr_tInt32)data16;
} }
} else if (op->BytesPerChannel == 1) { }
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT) { else if (op->BytesPerChannel == 1)
{
if (op->NumberRepresentation == PB_NUMREP_UNSIGNEDINT)
{
memcpy(&udata8, local->input_area + op->OffsetInputs + i, 1); memcpy(&udata8, local->input_area + op->OffsetInputs + i, 1);
*(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata8; *(pwr_tInt32*)chanp->vbp = (pwr_tInt32)udata8;
} else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT) { }
else if (op->NumberRepresentation == PB_NUMREP_SIGNEDINT)
{
memcpy(&data8, local->input_area + op->OffsetInputs + i, 1); memcpy(&data8, local->input_area + op->OffsetInputs + i, 1);
*(pwr_tInt32*)chanp->vbp = (pwr_tInt32)data8; *(pwr_tInt32*)chanp->vbp = (pwr_tInt32)data8;
} }
...@@ -166,8 +191,8 @@ static pwr_tStatus IoCardRead( ...@@ -166,8 +191,8 @@ static pwr_tStatus IoCardRead(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Close method for the Pb Ii card Close method for the Pb Ii card
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -181,5 +206,6 @@ static pwr_tStatus IoCardClose( ...@@ -181,5 +206,6 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Ii) = { pwr_BindIoMethod(IoCardInit), pwr_dExport pwr_BindIoMethods(Pb_Ii) = {
pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod};
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Io Init method for the Pb module Io
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Io* op; pwr_sClass_Pb_Io* op;
...@@ -58,12 +58,14 @@ static pwr_tStatus IoCardInit( ...@@ -58,12 +58,14 @@ static pwr_tStatus IoCardInit(
op = (pwr_sClass_Pb_Io*)cp->op; op = (pwr_sClass_Pb_Io*)cp->op;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
if (rp->Class != pwr_cClass_Pb_DP_Slave) { if (rp->Class != pwr_cClass_Pb_DP_Slave)
{
errh_Info("Illegal object type %s", cp->Name); errh_Info("Illegal object type %s", cp->Name);
return IO__SUCCESS; return IO__SUCCESS;
} }
if (op->Status < PB_MODULE_STATE_OPERATE) { if (op->Status < PB_MODULE_STATE_OPERATE)
{
errh_Info("Error initializing Pb module Io %s", cp->Name); errh_Info("Error initializing Pb module Io %s", cp->Name);
} }
...@@ -73,8 +75,8 @@ static pwr_tStatus IoCardInit( ...@@ -73,8 +75,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Write method for the Pb module Io Write method for the Pb module Io
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite( static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Io* op; pwr_sClass_Pb_Io* op;
...@@ -91,8 +93,10 @@ static pwr_tStatus IoCardWrite( ...@@ -91,8 +93,10 @@ static pwr_tStatus IoCardWrite(
op = (pwr_sClass_Pb_Io*)cp->op; op = (pwr_sClass_Pb_Io*)cp->op;
slave = (pwr_sClass_Pb_DP_Slave*)rp->op; slave = (pwr_sClass_Pb_DP_Slave*)rp->op;
if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1) { if (op->Status >= PB_MODULE_STATE_OPERATE && slave->DisableSlave != 1)
for (i = 0; i < cp->ChanListSize; i++) { {
for (i = 0; i < cp->ChanListSize; i++)
{
chanp = &cp->chanlist[i]; chanp = &cp->chanlist[i];
if (!chanp->cop || !chanp->sop) if (!chanp->cop || !chanp->sop)
continue; continue;
...@@ -105,20 +109,27 @@ static pwr_tStatus IoCardWrite( ...@@ -105,20 +109,27 @@ static pwr_tStatus IoCardWrite(
data32 = *(pwr_tInt32*)chanp->vbp; data32 = *(pwr_tInt32*)chanp->vbp;
if (op->BytesPerChannel == 4) { if (op->BytesPerChannel == 4)
{
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data32 = swap32(data32); data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 4 * i, &data32, 4); memcpy(local->output_area + op->OffsetOutputs + 4 * i, &data32, 4);
} else if (op->BytesPerChannel == 3) { }
else if (op->BytesPerChannel == 3)
{
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data32 = swap32(data32); data32 = swap32(data32);
memcpy(local->output_area + op->OffsetOutputs + 3 * i, &data32, 3); memcpy(local->output_area + op->OffsetOutputs + 3 * i, &data32, 3);
} else if (op->BytesPerChannel == 2) { }
else if (op->BytesPerChannel == 2)
{
data16 = (pwr_tInt16)data32; data16 = (pwr_tInt16)data32;
if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) if (slave->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
data16 = swap16(data16); data16 = swap16(data16);
memcpy(local->output_area + op->OffsetOutputs + 2 * i, &data16, 2); memcpy(local->output_area + op->OffsetOutputs + 2 * i, &data16, 2);
} else if (op->BytesPerChannel == 1) { }
else if (op->BytesPerChannel == 1)
{
data8 = (pwr_tInt8)data32; data8 = (pwr_tInt8)data32;
memcpy(local->output_area + op->OffsetOutputs + i, &data8, 1); memcpy(local->output_area + op->OffsetOutputs + i, &data8, 1);
} }
...@@ -130,8 +141,8 @@ static pwr_tStatus IoCardWrite( ...@@ -130,8 +141,8 @@ static pwr_tStatus IoCardWrite(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -145,6 +156,6 @@ static pwr_tStatus IoCardClose( ...@@ -145,6 +156,6 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Io) pwr_dExport pwr_BindIoMethods(Pb_Io) = {
= { pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardClose), pwr_NullMethod};
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pb module Init method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit( static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Module* op; pwr_sClass_Pb_Module* op;
...@@ -62,7 +62,8 @@ static pwr_tStatus IoCardInit( ...@@ -62,7 +62,8 @@ static pwr_tStatus IoCardInit(
op = (pwr_sClass_Pb_Module*)cp->op; op = (pwr_sClass_Pb_Module*)cp->op;
local = (io_sCardLocal*)cp->Local; local = (io_sCardLocal*)cp->Local;
for (i = 0; i < IO_MAXCHAN; i++) { for (i = 0; i < IO_MAXCHAN; i++)
{
local->scancount[i] = 0; local->scancount[i] = 0;
} }
...@@ -74,8 +75,8 @@ static pwr_tStatus IoCardInit( ...@@ -74,8 +75,8 @@ static pwr_tStatus IoCardInit(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Read method for the Pb module Read method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead( static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Module* op; pwr_sClass_Pb_Module* op;
...@@ -92,7 +93,7 @@ static pwr_tStatus IoCardRead( ...@@ -92,7 +93,7 @@ static pwr_tStatus IoCardRead(
/* all inputs will be zeroed */ /* all inputs will be zeroed */
io_bus_card_read(ctx, rp, cp, local->input_area, slave->Diag, io_bus_card_read(ctx, rp, cp, local->input_area, slave->Diag,
slave->ByteOrdering, slave->FloatRepresentation); slave->ByteOrdering, slave->FloatRepresentation);
// printf("Method Pb_Module-IoCardRead\n"); // printf("Method Pb_Module-IoCardRead\n");
return IO__SUCCESS; return IO__SUCCESS;
...@@ -101,8 +102,8 @@ static pwr_tStatus IoCardRead( ...@@ -101,8 +102,8 @@ static pwr_tStatus IoCardRead(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Write method for the Pb module Write method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite( static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
pwr_sClass_Pb_Module* op; pwr_sClass_Pb_Module* op;
...@@ -114,9 +115,10 @@ static pwr_tStatus IoCardWrite( ...@@ -114,9 +115,10 @@ static pwr_tStatus IoCardWrite(
op->Status = slave->Status; op->Status = slave->Status;
if (op->Status == PB__NORMAL) { if (op->Status == PB__NORMAL)
{
io_bus_card_write(ctx, cp, local->output_area, slave->ByteOrdering, io_bus_card_write(ctx, cp, local->output_area, slave->ByteOrdering,
slave->FloatRepresentation); slave->FloatRepresentation);
} }
// printf("Method Pb_Module-IoCardWrite\n"); // printf("Method Pb_Module-IoCardWrite\n");
return IO__SUCCESS; return IO__SUCCESS;
...@@ -125,8 +127,8 @@ static pwr_tStatus IoCardWrite( ...@@ -125,8 +127,8 @@ static pwr_tStatus IoCardWrite(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Close method for the Pb module Close method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose( static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp) io_sCard* cp)
{ {
io_sCardLocal* local; io_sCardLocal* local;
local = cp->Local; local = cp->Local;
...@@ -141,6 +143,7 @@ static pwr_tStatus IoCardClose( ...@@ -141,6 +143,7 @@ static pwr_tStatus IoCardClose(
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Module) = { pwr_BindIoMethod(IoCardInit), pwr_dExport pwr_BindIoMethods(Pb_Module) = {
pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardClose), pwr_NullMethod }; pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardClose),
pwr_NullMethod};
...@@ -78,23 +78,23 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap); ...@@ -78,23 +78,23 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap);
static pwr_tStatus IoAgentRead(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 IoAgentWrite(io_tCtx ctx, io_sAgent* ap);
static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap); static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap);
static pwr_tStatus IoAgentSwap(io_tCtx ctx, io_sAgent* ap, io_eEvent event);
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Sends request to Profiboard for setting FMB parameters Sends request to Profiboard for setting FMB parameters
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static short try_profi_rcv_con_ind(T_PROFI_DEVICE_HANDLE* hDevice, static short try_profi_rcv_con_ind(T_PROFI_SERVICE_DESCR* con_ind_sdb,
T_PROFI_SERVICE_DESCR* con_ind_sdb, USIGN8* con_ind_buffer, USIGN8* con_ind_buffer,
USIGN16* con_ind_buffer_len, INT16* result) USIGN16* con_ind_buffer_len, INT16* result)
{ {
int retry_counter; int retry_counter;
struct timespec rqtp = { 0, 10000000 }; // 10 ms struct timespec rqtp = {0, 10000000}; // 10 ms
retry_counter = DP_MAX_SERVICE_RETRY; retry_counter = DP_MAX_SERVICE_RETRY;
do { do
{
nanosleep(&rqtp, NULL); nanosleep(&rqtp, NULL);
*result = profi_rcv_con_ind( *result =
hDevice, con_ind_sdb, con_ind_buffer, con_ind_buffer_len); profi_rcv_con_ind(con_ind_sdb, con_ind_buffer, con_ind_buffer_len);
} while ((*result == NO_CON_IND_RECEIVED) && (retry_counter-- > 0)); } while ((*result == NO_CON_IND_RECEIVED) && (retry_counter-- > 0));
if (*result == E_IF_FATAL_ERROR) if (*result == E_IF_FATAL_ERROR)
...@@ -105,8 +105,7 @@ static short try_profi_rcv_con_ind(T_PROFI_DEVICE_HANDLE* hDevice, ...@@ -105,8 +105,7 @@ static short try_profi_rcv_con_ind(T_PROFI_DEVICE_HANDLE* hDevice,
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Sends request to Profiboard for setting FMB parameters Sends request to Profiboard for setting FMB parameters
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static short fmb_set_configuration( static short fmb_set_configuration(io_sAgent* ap)
T_PROFI_DEVICE_HANDLE* hDevice, io_sAgent* ap)
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
T_FMB_SET_CONFIGURATION_REQ data; T_FMB_SET_CONFIGURATION_REQ data;
...@@ -126,7 +125,8 @@ static short fmb_set_configuration( ...@@ -126,7 +125,8 @@ static short fmb_set_configuration(
/* Iterate over the slaves. */ /* Iterate over the slaves. */
for (slave_list = ap->racklist; slave_list != NULL; for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) { slave_list = slave_list->next)
{
cid = slave_list->Class; cid = slave_list->Class;
while (ODD(gdh_GetSuperClass(cid, &cid, pwr_cNOid))) while (ODD(gdh_GetSuperClass(cid, &cid, pwr_cNOid)))
...@@ -167,13 +167,14 @@ static short fmb_set_configuration( ...@@ -167,13 +167,14 @@ static short fmb_set_configuration(
data.fdlif.receive_credits = 20; data.fdlif.receive_credits = 20;
data.fdlif.max_no_resp_saps = 20; data.fdlif.max_no_resp_saps = 20;
profi_snd_req_res(hDevice, &sdb, &data, PB_FALSE); profi_snd_req_res(&sdb, &data, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == FMB_SET_CONFIGURATION) if ((con_ind_sdb.service == FMB_SET_CONFIGURATION) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -183,7 +184,7 @@ static short fmb_set_configuration( ...@@ -183,7 +184,7 @@ static short fmb_set_configuration(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Sends request to Profiboard for setting DP master parameters Sends request to Profiboard for setting DP master parameters
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static short dp_init_master(T_PROFI_DEVICE_HANDLE* hDevice) static short dp_init_master()
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
T_DP_INIT_MASTER_REQ data; T_DP_INIT_MASTER_REQ data;
...@@ -203,19 +204,20 @@ static short dp_init_master(T_PROFI_DEVICE_HANDLE* hDevice) ...@@ -203,19 +204,20 @@ static short dp_init_master(T_PROFI_DEVICE_HANDLE* hDevice)
data.master_default_address = 0; data.master_default_address = 0;
data.master_class2 = PB_FALSE; data.master_class2 = PB_FALSE;
data.lowest_slave_address = 2; data.lowest_slave_address = 2;
data.slave_io_address_mode data.slave_io_address_mode =
= DP_AAM_IO_BLOCKS; // only mode possible with Linux-driver DP_AAM_ARRAY; DP_AAM_IO_BLOCKS; // only mode possible with Linux-driver DP_AAM_ARRAY;
data.clear_outputs = PB_TRUE; data.clear_outputs = PB_TRUE;
data.auto_remote_services = DP_AUTO_REMOTE_SERVICES; data.auto_remote_services = DP_AUTO_REMOTE_SERVICES;
data.cyclic_data_transfer = PB_TRUE; data.cyclic_data_transfer = PB_TRUE;
profi_snd_req_res(hDevice, &sdb, &data, PB_FALSE); profi_snd_req_res(&sdb, &data, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == DP_INIT_MASTER) && (con_ind_sdb.primitive == CON) if ((con_ind_sdb.service == DP_INIT_MASTER) &&
&& (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -225,11 +227,11 @@ static short dp_init_master(T_PROFI_DEVICE_HANDLE* hDevice) ...@@ -225,11 +227,11 @@ static short dp_init_master(T_PROFI_DEVICE_HANDLE* hDevice)
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Sends request to Profiboard for setting DP bus parameters Sends request to Profiboard for setting DP bus parameters
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static short dp_download_bus( static short dp_download_bus(pwr_sClass_Pb_Profiboard* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_Profiboard* op)
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
struct { struct
{
T_DP_DOWNLOAD_REQ drp; T_DP_DOWNLOAD_REQ drp;
T_DP_BUS_PARA_SET dbp; T_DP_BUS_PARA_SET dbp;
} data; } data;
...@@ -255,7 +257,8 @@ static short dp_download_bus( ...@@ -255,7 +257,8 @@ static short dp_download_bus(
data.dbp.bus_para_len = swap16(66); data.dbp.bus_para_len = swap16(66);
data.dbp.fdl_add = 0; data.dbp.fdl_add = 0;
switch (op->BaudRate) { switch (op->BaudRate)
{
case 500: case 500:
data.dbp.baud_rate = DP_KBAUD_500; data.dbp.baud_rate = DP_KBAUD_500;
break; break;
...@@ -298,13 +301,14 @@ static short dp_download_bus( ...@@ -298,13 +301,14 @@ static short dp_download_bus(
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
data.dbp.master_class2_name[i] = 0; data.dbp.master_class2_name[i] = 0;
profi_snd_req_res(hDevice, &sdb, &data, PB_FALSE); profi_snd_req_res(&sdb, &data, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == DP_DOWNLOAD_LOC) && (con_ind_sdb.primitive == CON) if ((con_ind_sdb.service == DP_DOWNLOAD_LOC) &&
&& (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -313,8 +317,7 @@ static short dp_download_bus( ...@@ -313,8 +317,7 @@ static short dp_download_bus(
/*********************** FMB_SET_BUSPARAMETER ******************************/ /*********************** FMB_SET_BUSPARAMETER ******************************/
static short fmb_set_busparameter( static short fmb_set_busparameter(pwr_sClass_Pb_Profiboard* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_Profiboard* op)
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* FUNCTIONAL_DESCRIPTION: */ /* FUNCTIONAL_DESCRIPTION: */
/* */ /* */
...@@ -337,7 +340,8 @@ static short fmb_set_busparameter( ...@@ -337,7 +340,8 @@ static short fmb_set_busparameter(
bus_par_req.loc_segm = 255; bus_par_req.loc_segm = 255;
bus_par_req.medium_red = 0; bus_par_req.medium_red = 0;
switch (op->BaudRate) { switch (op->BaudRate)
{
case 500: case 500:
bus_par_req.baud_rate = DP_KBAUD_500; bus_par_req.baud_rate = DP_KBAUD_500;
break; break;
...@@ -381,13 +385,14 @@ static short fmb_set_busparameter( ...@@ -381,13 +385,14 @@ static short fmb_set_busparameter(
/* Send Request */ /* Send Request */
profi_snd_req_res(hDevice, &sdb, &bus_par_req, PB_FALSE); profi_snd_req_res(&sdb, &bus_par_req, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == FMB_SET_BUSPARAMETER) if ((con_ind_sdb.service == FMB_SET_BUSPARAMETER) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -397,8 +402,7 @@ static short fmb_set_busparameter( ...@@ -397,8 +402,7 @@ static short fmb_set_busparameter(
/*********************** DP_SET_BUSPARAMETER ******************************/ /*********************** DP_SET_BUSPARAMETER ******************************/
static short dp_set_busparameter( static short dp_set_busparameter(pwr_sClass_Pb_Profiboard* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_Profiboard* op)
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* FUNCTIONAL_DESCRIPTION: */ /* FUNCTIONAL_DESCRIPTION: */
/* */ /* */
...@@ -432,15 +436,16 @@ static short dp_set_busparameter( ...@@ -432,15 +436,16 @@ static short dp_set_busparameter(
/* Send Request */ /* Send Request */
profi_snd_req_res(hDevice, &sdb, &bus_par_req, PB_FALSE); profi_snd_req_res(&sdb, &bus_par_req, PB_FALSE);
con_ind_sdb.service = 0; con_ind_sdb.service = 0;
while (con_ind_sdb.service != DP_SET_BUSPARAMETER) while (con_ind_sdb.service != DP_SET_BUSPARAMETER)
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == DP_SET_BUSPARAMETER) if ((con_ind_sdb.service == DP_SET_BUSPARAMETER) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -448,8 +453,7 @@ static short dp_set_busparameter( ...@@ -448,8 +453,7 @@ static short dp_set_busparameter(
} /* dp_set_busparameter */ } /* dp_set_busparameter */
static short fdlif_sap_activate_req( static short fdlif_sap_activate_req(pwr_sClass_Pb_FDL_SAP* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_FDL_SAP* op)
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
FUNCTIONAL_DESCRIPTION FUNCTIONAL_DESCRIPTION
...@@ -498,24 +502,24 @@ possible return values: ...@@ -498,24 +502,24 @@ possible return values:
/* Send Request */ /* Send Request */
profi_snd_req_res(hDevice, &sdb, &sap, PB_FALSE); profi_snd_req_res(&sdb, &sap, PB_FALSE);
con_ind_sdb.service = 0; con_ind_sdb.service = 0;
while (con_ind_sdb.service != FDLIF_SAP_ACTIVATE) while (con_ind_sdb.service != FDLIF_SAP_ACTIVATE)
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == FDLIF_SAP_ACTIVATE) if ((con_ind_sdb.service == FDLIF_SAP_ACTIVATE) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
return (PB_FALSE); return (PB_FALSE);
} }
static short fdlif_rsap_activate_req( static short fdlif_rsap_activate_req(pwr_sClass_Pb_FDL_SAP* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_FDL_SAP* op)
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
FUNCTIONAL_DESCRIPTION FUNCTIONAL_DESCRIPTION
...@@ -560,16 +564,17 @@ possible return values: ...@@ -560,16 +564,17 @@ possible return values:
/* Send Request */ /* Send Request */
profi_snd_req_res(hDevice, &sdb, &rsap, PB_FALSE); profi_snd_req_res(&sdb, &rsap, PB_FALSE);
con_ind_sdb.service = 0; con_ind_sdb.service = 0;
while (con_ind_sdb.service != FDLIF_RSAP_ACTIVATE) while (con_ind_sdb.service != FDLIF_RSAP_ACTIVATE)
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == FDLIF_RSAP_ACTIVATE) if ((con_ind_sdb.service == FDLIF_RSAP_ACTIVATE) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -579,7 +584,7 @@ possible return values: ...@@ -579,7 +584,7 @@ possible return values:
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Sends request for selecting operation mode to the Profiboard Sends request for selecting operation mode to the Profiboard
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static short dp_act_param_loc(T_PROFI_DEVICE_HANDLE* hDevice, short arg) static short dp_act_param_loc(short arg)
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
T_DP_ACT_PARAM_REQ apr; T_DP_ACT_PARAM_REQ apr;
...@@ -598,7 +603,7 @@ static short dp_act_param_loc(T_PROFI_DEVICE_HANDLE* hDevice, short arg) ...@@ -598,7 +603,7 @@ static short dp_act_param_loc(T_PROFI_DEVICE_HANDLE* hDevice, short arg)
apr.activate = arg; apr.activate = arg;
apr.dummy = 0; apr.dummy = 0;
retval = profi_snd_req_res(hDevice, &sdb, &apr, PB_FALSE); retval = profi_snd_req_res(&sdb, &apr, PB_FALSE);
return retval; return retval;
} }
...@@ -606,7 +611,7 @@ static short dp_act_param_loc(T_PROFI_DEVICE_HANDLE* hDevice, short arg) ...@@ -606,7 +611,7 @@ static short dp_act_param_loc(T_PROFI_DEVICE_HANDLE* hDevice, short arg)
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Sends request for getting slave diagnostics Sends request for getting slave diagnostics
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tBoolean dp_get_slave_diag(T_PROFI_DEVICE_HANDLE* hDevice) static pwr_tBoolean dp_get_slave_diag()
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
pwr_tUInt16 retval; pwr_tUInt16 retval;
...@@ -619,7 +624,7 @@ static pwr_tBoolean dp_get_slave_diag(T_PROFI_DEVICE_HANDLE* hDevice) ...@@ -619,7 +624,7 @@ static pwr_tBoolean dp_get_slave_diag(T_PROFI_DEVICE_HANDLE* hDevice)
sdb.invoke_id = 0; sdb.invoke_id = 0;
sdb.result = 0; sdb.result = 0;
retval = profi_snd_req_res(hDevice, &sdb, &sdb, PB_FALSE); retval = profi_snd_req_res(&sdb, &sdb, PB_FALSE);
return ((pwr_tBoolean)(retval == E_OK)); return ((pwr_tBoolean)(retval == E_OK));
} }
...@@ -627,50 +632,62 @@ static pwr_tBoolean dp_get_slave_diag(T_PROFI_DEVICE_HANDLE* hDevice) ...@@ -627,50 +632,62 @@ static pwr_tBoolean dp_get_slave_diag(T_PROFI_DEVICE_HANDLE* hDevice)
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Get slave diagnostics Get slave diagnostics
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static void dp_get_slave_diag_con( static void
T_DP_GET_SLAVE_DIAG_CON* get_slave_diag_con_ptr, io_sRack* slave_list, dp_get_slave_diag_con(T_DP_GET_SLAVE_DIAG_CON* get_slave_diag_con_ptr,
char log) io_sRack* slave_list, char log)
{ {
T_DP_DIAG_DATA FAR* diag_data_ptr; T_DP_DIAG_DATA FAR* diag_data_ptr;
char s[128]; char s[128];
pwr_sClass_Pb_DP_Slave* sp; pwr_sClass_Pb_DP_Slave* sp;
if (get_slave_diag_con_ptr->diag_data_len >= DP_MIN_SLAVE_DIAG_LEN) { if (get_slave_diag_con_ptr->diag_data_len >= DP_MIN_SLAVE_DIAG_LEN)
{
diag_data_ptr = (T_DP_DIAG_DATA FAR*)(get_slave_diag_con_ptr + 1); diag_data_ptr = (T_DP_DIAG_DATA FAR*)(get_slave_diag_con_ptr + 1);
while (slave_list != NULL) { while (slave_list != NULL)
{
sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op; sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op;
if (sp->SlaveAddress == get_slave_diag_con_ptr->rem_add) { if (sp->SlaveAddress == get_slave_diag_con_ptr->rem_add)
{
sp->StationStatus1 = diag_data_ptr->station_status_1; sp->StationStatus1 = diag_data_ptr->station_status_1;
sp->StationStatus2 = diag_data_ptr->station_status_2; sp->StationStatus2 = diag_data_ptr->station_status_2;
sp->StationStatus3 = diag_data_ptr->station_status_3; sp->StationStatus3 = diag_data_ptr->station_status_3;
sp->BytesOfDiag sp->BytesOfDiag =
= get_slave_diag_con_ptr->diag_data_len - DP_MIN_SLAVE_DIAG_LEN; get_slave_diag_con_ptr->diag_data_len - DP_MIN_SLAVE_DIAG_LEN;
memcpy(sp->Diag, diag_data_ptr + 1, memcpy(
sp->Diag, diag_data_ptr + 1,
MIN(get_slave_diag_con_ptr->diag_data_len - DP_MIN_SLAVE_DIAG_LEN, MIN(get_slave_diag_con_ptr->diag_data_len - DP_MIN_SLAVE_DIAG_LEN,
DP_MAX_EXT_DIAG_DATA_LEN)); DP_MAX_EXT_DIAG_DATA_LEN));
/* Update slave status */ /* Update slave status */
if (!(sp->StationStatus1 & ~pwr_mPbStationStatus1Mask_ExternalDiag) if (!(sp->StationStatus1 & ~pwr_mPbStationStatus1Mask_ExternalDiag) &&
&& !(sp->StationStatus2 !(sp->StationStatus2 &
& ~(pwr_mPbStationStatus2Mask_Default ~(pwr_mPbStationStatus2Mask_Default |
| pwr_mPbStationStatus2Mask_ResponseMonitoringOn))) { pwr_mPbStationStatus2Mask_ResponseMonitoringOn)))
{
sp->Status = PB__NORMAL; sp->Status = PB__NORMAL;
} else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent) { }
else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NonExistent)
{
sp->Status = PB__NOCONN; sp->Status = PB__NOCONN;
} else if ((sp->StationStatus1 }
& (pwr_mPbStationStatus1Mask_ConfigFault else if ((sp->StationStatus1 &
| pwr_mPbStationStatus1Mask_ParamFault)) (pwr_mPbStationStatus1Mask_ConfigFault |
|| (sp->StationStatus2 pwr_mPbStationStatus1Mask_ParamFault)) ||
& pwr_mPbStationStatus2Mask_NewParamsRequested)) { (sp->StationStatus2 &
pwr_mPbStationStatus2Mask_NewParamsRequested))
{
sp->Status = PB__CONFIGERR; sp->Status = PB__CONFIGERR;
} else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_MasterLock) { }
else if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_MasterLock)
{
sp->Status = PB__MASTERLOCK; sp->Status = PB__MASTERLOCK;
} else // if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NotReady) }
else // if (sp->StationStatus1 & pwr_mPbStationStatus1Mask_NotReady)
{ {
sp->Status = PB__NOTREADY; sp->Status = PB__NOTREADY;
} }
...@@ -681,9 +698,11 @@ static void dp_get_slave_diag_con( ...@@ -681,9 +698,11 @@ static void dp_get_slave_diag_con(
slave_list = slave_list->next; slave_list = slave_list->next;
} }
if (log) { if (log)
sprintf(s, "Slave [%3hhu] [0x%04hX]: Status = 0x%02hhX 0x%02hhX 0x%02hhX, " {
"Master = %3hhu, Ext = %u, Diags = %hu", sprintf(
s, "Slave [%3hhu] [0x%04hX]: Status = 0x%02hhX 0x%02hhX 0x%02hhX, "
"Master = %3hhu, Ext = %u, Diags = %hu",
get_slave_diag_con_ptr->rem_add, swap16(diag_data_ptr->ident_number), get_slave_diag_con_ptr->rem_add, swap16(diag_data_ptr->ident_number),
diag_data_ptr->station_status_1, diag_data_ptr->station_status_2, diag_data_ptr->station_status_1, diag_data_ptr->station_status_2,
diag_data_ptr->station_status_3, diag_data_ptr->master_add, diag_data_ptr->station_status_3, diag_data_ptr->master_add,
...@@ -696,8 +715,9 @@ static void dp_get_slave_diag_con( ...@@ -696,8 +715,9 @@ static void dp_get_slave_diag_con(
} /* diag_data_len */ } /* diag_data_len */
} }
static void fdlif_sda_sdn_srd_ind( static void fdlif_sda_sdn_srd_ind(INT8 invoke_id,
INT8 invoke_id, T_FDLIF_SDN_SDA_SRD_REQ* ind_ptr, io_sRack* slave_list) T_FDLIF_SDN_SDA_SRD_REQ* ind_ptr,
io_sRack* slave_list)
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
FUNCTIONAL_DESCRIPTION FUNCTIONAL_DESCRIPTION
...@@ -712,26 +732,31 @@ possible return values: ...@@ -712,26 +732,31 @@ possible return values:
USIGN8* data_ptr; USIGN8* data_ptr;
pwr_sClass_Pb_FDL_SAP* sp; pwr_sClass_Pb_FDL_SAP* sp;
if (ind_ptr->length > 0) { if (ind_ptr->length > 0)
{
data_ptr = (USIGN8*)(ind_ptr + 1); data_ptr = (USIGN8*)(ind_ptr + 1);
// print_data (data_ptr, cnf_ptr->length); // print_data (data_ptr, cnf_ptr->length);
while (slave_list != NULL) { while (slave_list != NULL)
if (((io_sRackLocal*)slave_list->Local)->fdl) { {
if (((io_sRackLocal*)slave_list->Local)->fdl)
{
sp = (pwr_sClass_Pb_FDL_SAP*)slave_list->op; sp = (pwr_sClass_Pb_FDL_SAP*)slave_list->op;
if (sp->SAP_Nr == ind_ptr->ssap) { if (sp->SAP_Nr == ind_ptr->ssap)
{
io_sCard* card_list = slave_list->cardlist; io_sCard* card_list = slave_list->cardlist;
pwr_sClass_Pb_FDL_DataTransfer* cp; pwr_sClass_Pb_FDL_DataTransfer* cp;
io_sFDLCardLocal* local_card; io_sFDLCardLocal* local_card;
if (card_list != NULL) { if (card_list != NULL)
{
cp = (pwr_sClass_Pb_FDL_DataTransfer*)card_list->op; cp = (pwr_sClass_Pb_FDL_DataTransfer*)card_list->op;
local_card = (io_sFDLCardLocal*)card_list->Local; local_card = (io_sFDLCardLocal*)card_list->Local;
if (local_card->input_area_size > 0) if (local_card->input_area_size > 0)
memcpy(local_card->input_area, data_ptr, memcpy(local_card->input_area, data_ptr,
MIN(local_card->input_area_size, ind_ptr->length)); MIN(local_card->input_area_size, ind_ptr->length));
} }
break; break;
...@@ -745,7 +770,7 @@ possible return values: ...@@ -745,7 +770,7 @@ possible return values:
} }
static void fdlif_srd_con(INT16 result, INT8 invoke_id, static void fdlif_srd_con(INT16 result, INT8 invoke_id,
T_FDLIF_SRD_CNF* cnf_ptr, io_sRack* slave_list) T_FDLIF_SRD_CNF* cnf_ptr, io_sRack* slave_list)
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
FUNCTIONAL_DESCRIPTION FUNCTIONAL_DESCRIPTION
...@@ -763,33 +788,41 @@ possible return values: ...@@ -763,33 +788,41 @@ possible return values:
pwr_sClass_Pb_FDL_SAP* sp; pwr_sClass_Pb_FDL_SAP* sp;
USIGN8 res; USIGN8 res;
if (result == POS) { if (result == POS)
{
res = 0; res = 0;
} else { }
else
{
res = cnf_ptr->status; res = cnf_ptr->status;
} }
data_ptr = (USIGN8*)(cnf_ptr + 1); data_ptr = (USIGN8*)(cnf_ptr + 1);
while (slave_list != NULL) { while (slave_list != NULL)
if (((io_sRackLocal*)slave_list->Local)->fdl) { {
if (((io_sRackLocal*)slave_list->Local)->fdl)
{
sp = (pwr_sClass_Pb_FDL_SAP*)slave_list->op; sp = (pwr_sClass_Pb_FDL_SAP*)slave_list->op;
if (!sp->Responder) { if (!sp->Responder)
{
io_sCard* card_list = slave_list->cardlist; io_sCard* card_list = slave_list->cardlist;
pwr_sClass_Pb_FDL_DataTransfer* cp; pwr_sClass_Pb_FDL_DataTransfer* cp;
io_sFDLCardLocal* local_card; io_sFDLCardLocal* local_card;
while (card_list != NULL) { while (card_list != NULL)
{
cp = (pwr_sClass_Pb_FDL_DataTransfer*)card_list->op; cp = (pwr_sClass_Pb_FDL_DataTransfer*)card_list->op;
local_card = (io_sFDLCardLocal*)card_list->Local; local_card = (io_sFDLCardLocal*)card_list->Local;
if ((local_card->invoke_id == invoke_id) if ((local_card->invoke_id == invoke_id) &&
&& (cp->Type == pwr_ePbFDLDataTransferTypeEnum_FDLIF_SRD)) { (cp->Type == pwr_ePbFDLDataTransferTypeEnum_FDLIF_SRD))
{
cp->Result = res; cp->Result = res;
if (cnf_ptr->length > 0) if (cnf_ptr->length > 0)
memcpy(local_card->input_area, data_ptr, memcpy(local_card->input_area, data_ptr,
MIN(local_card->input_area_size, cnf_ptr->length)); MIN(local_card->input_area_size, cnf_ptr->length));
break; break;
} }
card_list = card_list->next; card_list = card_list->next;
...@@ -805,33 +838,41 @@ possible return values: ...@@ -805,33 +838,41 @@ possible return values:
return; return;
} }
static void fdlif_sda_sdn_con( static void fdlif_sda_sdn_con(INT8 invoke_id, INT16 result,
INT8 invoke_id, INT16 result, T_FDLIF_ERROR* err_ptr, io_sRack* slave_list) T_FDLIF_ERROR* err_ptr, io_sRack* slave_list)
{ {
pwr_sClass_Pb_FDL_SAP* sp; pwr_sClass_Pb_FDL_SAP* sp;
USIGN8 res; USIGN8 res;
if (result == POS) { if (result == POS)
{
res = 0; res = 0;
} else { }
else
{
res = err_ptr->result; res = err_ptr->result;
} }
// print_data (data_ptr, cnf_ptr->length); // print_data (data_ptr, cnf_ptr->length);
while (slave_list != NULL) { while (slave_list != NULL)
if (((io_sRackLocal*)slave_list->Local)->fdl) { {
if (((io_sRackLocal*)slave_list->Local)->fdl)
{
sp = (pwr_sClass_Pb_FDL_SAP*)slave_list->op; sp = (pwr_sClass_Pb_FDL_SAP*)slave_list->op;
if (!sp->Responder) { if (!sp->Responder)
{
io_sCard* card_list = slave_list->cardlist; io_sCard* card_list = slave_list->cardlist;
pwr_sClass_Pb_FDL_DataTransfer* cp; pwr_sClass_Pb_FDL_DataTransfer* cp;
io_sFDLCardLocal* local_card; io_sFDLCardLocal* local_card;
while (card_list != NULL) { while (card_list != NULL)
{
cp = (pwr_sClass_Pb_FDL_DataTransfer*)card_list->op; cp = (pwr_sClass_Pb_FDL_DataTransfer*)card_list->op;
local_card = (io_sFDLCardLocal*)card_list->Local; local_card = (io_sFDLCardLocal*)card_list->Local;
if (local_card->invoke_id == invoke_id) { if (local_card->invoke_id == invoke_id)
{
cp->Result = res; cp->Result = res;
break; break;
} }
...@@ -851,8 +892,7 @@ static void fdlif_sda_sdn_con( ...@@ -851,8 +892,7 @@ static void fdlif_sda_sdn_con(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Starts download sequence of prm data to one slave Starts download sequence of prm data to one slave
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus start_download_seq( static pwr_tStatus start_download_seq(pwr_sClass_Pb_DP_Slave* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_DP_Slave* op)
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
T_DP_START_SEQ_REQ ssrp; T_DP_START_SEQ_REQ ssrp;
...@@ -874,13 +914,14 @@ static pwr_tStatus start_download_seq( ...@@ -874,13 +914,14 @@ static pwr_tStatus start_download_seq(
ssrp.area_code = op->SlaveAddress; ssrp.area_code = op->SlaveAddress;
ssrp.timeout = timeout; ssrp.timeout = timeout;
profi_snd_req_res(hDevice, &sdb, &ssrp, PB_FALSE); profi_snd_req_res(&sdb, &ssrp, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == DP_START_SEQ_LOC) if ((con_ind_sdb.service == DP_START_SEQ_LOC) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
op->Status = PB__NOCONN; op->Status = PB__NOCONN;
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -893,8 +934,7 @@ static pwr_tStatus start_download_seq( ...@@ -893,8 +934,7 @@ static pwr_tStatus start_download_seq(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Starts download sequence of prm data to one slave Starts download sequence of prm data to one slave
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus end_download_seq( static pwr_tStatus end_download_seq(pwr_sClass_Pb_DP_Slave* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_DP_Slave* op)
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
T_DP_END_SEQ_REQ esrp; T_DP_END_SEQ_REQ esrp;
...@@ -914,13 +954,14 @@ static pwr_tStatus end_download_seq( ...@@ -914,13 +954,14 @@ static pwr_tStatus end_download_seq(
esrp.rem_add = 0; esrp.rem_add = 0;
esrp.dummy = 0; esrp.dummy = 0;
profi_snd_req_res(hDevice, &sdb, &esrp, PB_FALSE); profi_snd_req_res(&sdb, &esrp, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == DP_END_SEQ_LOC) && (con_ind_sdb.primitive == CON) if ((con_ind_sdb.service == DP_END_SEQ_LOC) &&
&& (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
op->Status = PB__NOCONN; op->Status = PB__NOCONN;
return (PB_TRUE); return (PB_TRUE);
} }
...@@ -933,12 +974,12 @@ static pwr_tStatus end_download_seq( ...@@ -933,12 +974,12 @@ static pwr_tStatus end_download_seq(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Initializes one DP slave in the master card Initializes one DP slave in the master card
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus dp_download_slave( static pwr_tStatus dp_download_slave(pwr_sClass_Pb_DP_Slave* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_DP_Slave* op)
{ {
int i; int i;
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
struct { struct
{
T_DP_DOWNLOAD_REQ drp; T_DP_DOWNLOAD_REQ drp;
unsigned char param[512]; unsigned char param[512];
} slave_data; } slave_data;
...@@ -960,8 +1001,9 @@ static pwr_tStatus dp_download_slave( ...@@ -960,8 +1001,9 @@ static pwr_tStatus dp_download_slave(
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
download_data_size = sizeof(prm_head) + sizeof(prm_data) + op->PrmUserDataLen download_data_size = sizeof(prm_head) + sizeof(prm_data) +
+ op->ConfigDataLen + sizeof(aat_data) + sizeof(user_data); op->PrmUserDataLen + op->ConfigDataLen +
sizeof(aat_data) + sizeof(user_data);
data_len = download_data_size; data_len = download_data_size;
...@@ -1019,42 +1061,53 @@ static pwr_tStatus dp_download_slave( ...@@ -1019,42 +1061,53 @@ static pwr_tStatus dp_download_slave(
send_buf = (char*)slave_data.param; send_buf = (char*)slave_data.param;
if (data_len > DP_MAX_DOWNLOAD_DATA_LEN) { if (data_len > DP_MAX_DOWNLOAD_DATA_LEN)
if (!start_download_seq(hDevice, op)) { {
if (!start_download_seq(op))
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
return (PB_FALSE); return (PB_FALSE);
} }
} }
while (download_data_size > 0) { while (download_data_size > 0)
{
slave_data.drp.data_len = MIN(download_data_size, DP_MAX_DOWNLOAD_DATA_LEN); slave_data.drp.data_len = MIN(download_data_size, DP_MAX_DOWNLOAD_DATA_LEN);
profi_snd_req_res(hDevice, &sdb, &slave_data, PB_FALSE); profi_snd_req_res(&sdb, &slave_data, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if (con_ind_sdb.service == DP_DOWNLOAD_LOC) { if (con_ind_sdb.service == DP_DOWNLOAD_LOC)
if ((con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { {
if ((con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
op->Status = PB__NOCONN; op->Status = PB__NOCONN;
} else { }
else
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
failure = TRUE; failure = TRUE;
break; break;
} }
} }
if (download_data_size > DP_MAX_DOWNLOAD_DATA_LEN) { if (download_data_size > DP_MAX_DOWNLOAD_DATA_LEN)
{
download_data_size -= DP_MAX_DOWNLOAD_DATA_LEN; download_data_size -= DP_MAX_DOWNLOAD_DATA_LEN;
slave_data.drp.add_offset += DP_MAX_DOWNLOAD_DATA_LEN; slave_data.drp.add_offset += DP_MAX_DOWNLOAD_DATA_LEN;
send_buf += DP_MAX_DOWNLOAD_DATA_LEN; send_buf += DP_MAX_DOWNLOAD_DATA_LEN;
memcpy(slave_data.param, send_buf, memcpy(slave_data.param, send_buf,
MIN(download_data_size, DP_MAX_DOWNLOAD_DATA_LEN)); MIN(download_data_size, DP_MAX_DOWNLOAD_DATA_LEN));
} else }
else
download_data_size = 0; download_data_size = 0;
} }
if (data_len > DP_MAX_DOWNLOAD_DATA_LEN) { if (data_len > DP_MAX_DOWNLOAD_DATA_LEN)
if (!end_download_seq(hDevice, op)) { {
if (!end_download_seq(op))
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
return (PB_FALSE); return (PB_FALSE);
} }
...@@ -1069,8 +1122,7 @@ static pwr_tStatus dp_download_slave( ...@@ -1069,8 +1122,7 @@ static pwr_tStatus dp_download_slave(
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Calculate offsets of inputs and outputs for a slave Calculate offsets of inputs and outputs for a slave
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus dp_io_offsets( static pwr_tStatus dp_io_offsets(pwr_sClass_Pb_DP_Slave* op)
T_PROFI_DEVICE_HANDLE* hDevice, pwr_sClass_Pb_DP_Slave* op)
{ {
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
T_DP_GET_SLAVE_PARAM_REQ get_slave_param_req; T_DP_GET_SLAVE_PARAM_REQ get_slave_param_req;
...@@ -1092,20 +1144,21 @@ static pwr_tStatus dp_io_offsets( ...@@ -1092,20 +1144,21 @@ static pwr_tStatus dp_io_offsets(
get_slave_param_req.identifier = DP_SLAVE_PARAM_SLAVE_INFO; get_slave_param_req.identifier = DP_SLAVE_PARAM_SLAVE_INFO;
get_slave_param_req.rem_add = op->SlaveAddress; get_slave_param_req.rem_add = op->SlaveAddress;
result = profi_snd_req_res(hDevice, &sdb, &get_slave_param_req, PB_FALSE); result = profi_snd_req_res(&sdb, &get_slave_param_req, PB_FALSE);
if (result != E_OK) if (result != E_OK)
return (result); return (result);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
get_slave_param_con_ptr = (T_DP_GET_SLAVE_PARAM_CON FAR*)con_ind_buffer; get_slave_param_con_ptr = (T_DP_GET_SLAVE_PARAM_CON FAR*)con_ind_buffer;
if ((con_ind_sdb.service == DP_GET_SLAVE_PARAM) if ((con_ind_sdb.service == DP_GET_SLAVE_PARAM) &&
&& (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
slave_info_ptr {
= (T_DP_SLAVE_PARAM_SLAVE_INFO FAR*)(get_slave_param_con_ptr + 1); slave_info_ptr =
(T_DP_SLAVE_PARAM_SLAVE_INFO FAR*)(get_slave_param_con_ptr + 1);
op->BytesOfInput = slave_info_ptr->number_inputs; op->BytesOfInput = slave_info_ptr->number_inputs;
op->BytesOfOutput = slave_info_ptr->number_outputs; op->BytesOfOutput = slave_info_ptr->number_outputs;
...@@ -1126,7 +1179,6 @@ void* handle_events(void* ptr) ...@@ -1126,7 +1179,6 @@ void* handle_events(void* ptr)
io_sAgentLocal* local; io_sAgentLocal* local;
io_sAgent* ap; io_sAgent* ap;
short sts; short sts;
T_PROFI_DEVICE_HANDLE* hDevice;
pwr_sClass_Pb_Profiboard* op; pwr_sClass_Pb_Profiboard* op;
char s[128]; char s[128];
...@@ -1134,13 +1186,12 @@ void* handle_events(void* ptr) ...@@ -1134,13 +1186,12 @@ void* handle_events(void* ptr)
USIGN16 con_ind_buffer_len = 256; USIGN16 con_ind_buffer_len = 256;
T_PROFI_SERVICE_DESCR con_ind_sdb; T_PROFI_SERVICE_DESCR con_ind_sdb;
T_DP_GET_SLAVE_DIAG_CON* get_slave_diag_con_ptr; T_DP_GET_SLAVE_DIAG_CON* get_slave_diag_con_ptr;
struct timespec rqtp = { 0, 10000000 }; // 10 ms struct timespec rqtp = {0, 10000000}; // 10 ms
args = (agent_args*)ptr; args = (agent_args*)ptr;
local = (io_sAgentLocal*)args->local; local = (io_sAgentLocal*)args->local;
ap = args->ap; ap = args->ap;
hDevice = (T_PROFI_DEVICE_HANDLE*)ap->Local;
op = (pwr_sClass_Pb_Profiboard*)ap->op; op = (pwr_sClass_Pb_Profiboard*)ap->op;
/* If everything is fine we should be in state OPERATE /* If everything is fine we should be in state OPERATE
...@@ -1148,39 +1199,53 @@ void* handle_events(void* ptr) ...@@ -1148,39 +1199,53 @@ void* handle_events(void* ptr)
if there are any hardware faults. In that case, make a reset and a new if there are any hardware faults. In that case, make a reset and a new
init. */ init. */
while (1) { while (1)
{
if (op->DisableBus) if (op->DisableBus)
exit(0); exit(0);
pthread_mutex_lock(&local->mutex); pthread_mutex_lock(&local->mutex);
con_ind_buffer_len = 256; con_ind_buffer_len = 256;
sts = profi_rcv_con_ind( sts = profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len);
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len);
if (sts == CON_IND_RECEIVED)
if (sts == CON_IND_RECEIVED) { {
switch (con_ind_sdb.layer) { switch (con_ind_sdb.layer)
case DP_USR: { {
if (con_ind_sdb.primitive == CON) { case DP_USR:
if (con_ind_sdb.result == POS) { {
switch (con_ind_sdb.service) { if (con_ind_sdb.primitive == CON)
{
if (con_ind_sdb.result == POS)
{
switch (con_ind_sdb.service)
{
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
case DP_ACT_PARAM_LOC: { case DP_ACT_PARAM_LOC:
if (op->Status == PB__NOTINIT) { {
if (op->Status == PB__NOTINIT)
{
op->Status = PB__STOPPED; op->Status = PB__STOPPED;
errh_Info("Profibus DP Master %s to state STOPPED", ap->Name); errh_Info("Profibus DP Master %s to state STOPPED", ap->Name);
dp_act_param_loc(hDevice, DP_OP_MODE_CLEAR); dp_act_param_loc(DP_OP_MODE_CLEAR);
} else if (op->Status == PB__STOPPED) { }
else if (op->Status == PB__STOPPED)
{
op->Status = PB__CLEARED; op->Status = PB__CLEARED;
errh_Info("Profibus DP Master %s to state CLEARED", ap->Name); errh_Info("Profibus DP Master %s to state CLEARED", ap->Name);
dp_act_param_loc(hDevice, DP_OP_MODE_OPERATE); dp_act_param_loc(DP_OP_MODE_OPERATE);
} else if (op->Status == PB__CLEARED) { }
else if (op->Status == PB__CLEARED)
{
errh_Info("Profibus DP Master %s to state OPERATE", ap->Name); errh_Info("Profibus DP Master %s to state OPERATE", ap->Name);
op->Status = PB__NORMAL; op->Status = PB__NORMAL;
if (!local->slave_diag_requested && local->parallel_service) { if (!local->slave_diag_requested && local->parallel_service)
if (dp_get_slave_diag(hDevice)) { {
if (dp_get_slave_diag())
{
local->slave_diag_requested = op->Diag[3] = PB_TRUE; local->slave_diag_requested = op->Diag[3] = PB_TRUE;
local->parallel_service = PB_FALSE; local->parallel_service = PB_FALSE;
} }
...@@ -1192,61 +1257,74 @@ void* handle_events(void* ptr) ...@@ -1192,61 +1257,74 @@ void* handle_events(void* ptr)
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
case DP_GET_SLAVE_DIAG: { case DP_GET_SLAVE_DIAG:
get_slave_diag_con_ptr {
= (T_DP_GET_SLAVE_DIAG_CON FAR*)con_ind_buffer; get_slave_diag_con_ptr =
(T_DP_GET_SLAVE_DIAG_CON FAR*)con_ind_buffer;
dp_get_slave_diag_con( dp_get_slave_diag_con(get_slave_diag_con_ptr, ap->racklist,
get_slave_diag_con_ptr, ap->racklist, op->Diag[1]); op->Diag[1]);
op->Diag[2]++; op->Diag[2]++;
local->slave_diag_requested = op->Diag[3] = PB_FALSE; local->slave_diag_requested = op->Diag[3] = PB_FALSE;
if (get_slave_diag_con_ptr->diag_entries < 0) { if (get_slave_diag_con_ptr->diag_entries < 0)
{
errh_Warning("Profibus - diagnostic circular buffer owerflow."); errh_Warning("Profibus - diagnostic circular buffer owerflow.");
} }
if (get_slave_diag_con_ptr->diag_entries) { if (get_slave_diag_con_ptr->diag_entries)
{
local->slave_diag_requested = op->Diag[3] = PB_TRUE; local->slave_diag_requested = op->Diag[3] = PB_TRUE;
dp_get_slave_diag(hDevice); dp_get_slave_diag();
} }
break; break;
} /* case DP_GET_SLAVE_DIAG */ } /* case DP_GET_SLAVE_DIAG */
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
default: { default:
{
break; break;
} /* deafult service */ } /* deafult service */
} /* switch */ } /* switch */
} /* if POS */ } /* if POS */
else { else
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
errh_Error("Profibus DP Master %s - %x neg con rec", ap->Name, errh_Error("Profibus DP Master %s - %x neg con rec", ap->Name,
*((unsigned short*)con_ind_buffer)); *((unsigned short*)con_ind_buffer));
} /* else POS */ } /* else POS */
} /* if CON */ } /* if CON */
else if (con_ind_sdb.primitive == IND) { else if (con_ind_sdb.primitive == IND)
if (con_ind_sdb.result == POS) { {
switch (con_ind_sdb.service) { if (con_ind_sdb.result == POS)
{
switch (con_ind_sdb.service)
{
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
case DP_ACT_PARAM_LOC: { case DP_ACT_PARAM_LOC:
{
USIGN8 usif_state; USIGN8 usif_state;
usif_state = ((T_DP_ACT_PARAM_IND FAR*)con_ind_buffer)->activate; usif_state = ((T_DP_ACT_PARAM_IND FAR*)con_ind_buffer)->activate;
switch (usif_state) { switch (usif_state)
case DP_OP_MODE_STOP: { {
case DP_OP_MODE_STOP:
{
op->Status = PB__STOPPED; op->Status = PB__STOPPED;
sprintf(s, "Mode changed to STOP"); sprintf(s, "Mode changed to STOP");
break; break;
} }
case DP_OP_MODE_CLEAR: { case DP_OP_MODE_CLEAR:
{
op->Status = PB__CLEARED; op->Status = PB__CLEARED;
sprintf(s, "Mode changed to CLEAR"); sprintf(s, "Mode changed to CLEAR");
break; break;
} }
case DP_OP_MODE_OPERATE: { case DP_OP_MODE_OPERATE:
{
op->Status = PB__NORMAL; op->Status = PB__NORMAL;
sprintf(s, "Mode changed to OPERATE"); sprintf(s, "Mode changed to OPERATE");
break; break;
...@@ -1255,14 +1333,17 @@ void* handle_events(void* ptr) ...@@ -1255,14 +1333,17 @@ void* handle_events(void* ptr)
errh_Info("Profibus DP Master %s - %s", ap->Name, s); errh_Info("Profibus DP Master %s - %s", ap->Name, s);
if (usif_state == DP_OP_MODE_STOP) { if (usif_state == DP_OP_MODE_STOP)
{
usif_state = DP_OP_MODE_CLEAR; usif_state = DP_OP_MODE_CLEAR;
dp_act_param_loc(hDevice, DP_OP_MODE_CLEAR); dp_act_param_loc(DP_OP_MODE_CLEAR);
} else if (usif_state == DP_OP_MODE_CLEAR) { }
else if (usif_state == DP_OP_MODE_CLEAR)
{
usif_state = DP_OP_MODE_OPERATE; usif_state = DP_OP_MODE_OPERATE;
dp_act_param_loc(hDevice, DP_OP_MODE_OPERATE); dp_act_param_loc(DP_OP_MODE_OPERATE);
} }
break; break;
...@@ -1270,28 +1351,37 @@ void* handle_events(void* ptr) ...@@ -1270,28 +1351,37 @@ void* handle_events(void* ptr)
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
case DP_GET_SLAVE_DIAG: { case DP_GET_SLAVE_DIAG:
get_slave_diag_con_ptr {
= (T_DP_GET_SLAVE_DIAG_CON FAR*)con_ind_buffer; get_slave_diag_con_ptr =
(T_DP_GET_SLAVE_DIAG_CON FAR*)con_ind_buffer;
dp_get_slave_diag_con( dp_get_slave_diag_con(get_slave_diag_con_ptr, ap->racklist,
get_slave_diag_con_ptr, ap->racklist, op->Diag[1]); op->Diag[1]);
op->Diag[0]++; op->Diag[0]++;
if (get_slave_diag_con_ptr->diag_entries < 0) { if (get_slave_diag_con_ptr->diag_entries < 0)
{
errh_Warning("Profibus - diagnostic circular buffer owerflow."); errh_Warning("Profibus - diagnostic circular buffer owerflow.");
} }
if ((get_slave_diag_con_ptr->diag_entries) if ((get_slave_diag_con_ptr->diag_entries) &&
&& (!local->slave_diag_requested)) { (!local->slave_diag_requested))
if (op->Status == PB__NORMAL) { {
if (dp_get_slave_diag(hDevice)) { if (op->Status == PB__NORMAL)
{
if (dp_get_slave_diag())
{
local->slave_diag_requested = op->Diag[3] = PB_TRUE; local->slave_diag_requested = op->Diag[3] = PB_TRUE;
} else { }
else
{
errh_Warning("Profibus - Request for diag failed."); errh_Warning("Profibus - Request for diag failed.");
} }
} else { }
else
{
local->parallel_service = PB_TRUE; local->parallel_service = PB_TRUE;
} }
} }
...@@ -1301,31 +1391,38 @@ void* handle_events(void* ptr) ...@@ -1301,31 +1391,38 @@ void* handle_events(void* ptr)
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
default: { default:
{
break; break;
} /* deafult service */ } /* deafult service */
} /* switch */ } /* switch */
} /* if POS */ } /* if POS */
else { else
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
errh_Error("Profibus DP Master %s - %x neg ind rec", ap->Name, errh_Error("Profibus DP Master %s - %x neg ind rec", ap->Name,
*((unsigned short*)con_ind_buffer)); *((unsigned short*)con_ind_buffer));
} /* else POS */ } /* else POS */
} /* if IND */ } /* if IND */
break; break;
} }
case FMB_USR: { case FMB_USR:
switch (con_ind_sdb.service) { {
switch (con_ind_sdb.service)
{
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
case FMB_SET_CONFIGURATION: case FMB_SET_CONFIGURATION:
case FMB_EXIT: case FMB_EXIT:
case FMB_RESET: { case FMB_RESET:
{
break; break;
} }
case FMB_FM2_EVENT: { case FMB_FM2_EVENT:
switch (((T_FMB_FM2_EVENT_IND FAR*)con_ind_buffer)->reason) { {
switch (((T_FMB_FM2_EVENT_IND FAR*)con_ind_buffer)->reason)
{
case FM2_FAULT_ADDRESS: case FM2_FAULT_ADDRESS:
sprintf(s, "Duplicate address recognized"); sprintf(s, "Duplicate address recognized");
break; break;
...@@ -1355,17 +1452,20 @@ void* handle_events(void* ptr) ...@@ -1355,17 +1452,20 @@ void* handle_events(void* ptr)
break; break;
} /* case FMB_FM2_EVENT */ } /* case FMB_FM2_EVENT */
default: { default:
{
printf("\nnot supported FMB service received\n"); printf("\nnot supported FMB service received\n");
printf("service: %d primitive: %d\n", con_ind_sdb.service, printf("service: %d primitive: %d\n", con_ind_sdb.service,
con_ind_sdb.primitive); con_ind_sdb.primitive);
break; break;
} /* deafult service */ } /* deafult service */
} /* switch */ } /* switch */
break; break;
} }
case FDLIF_USR: { case FDLIF_USR:
switch (con_ind_sdb.service) { {
switch (con_ind_sdb.service)
{
case FDLIF_EVENT: case FDLIF_EVENT:
case FDLIF_SET_BUSPARAMETER: case FDLIF_SET_BUSPARAMETER:
case FDLIF_READ_BUSPARAMETER: case FDLIF_READ_BUSPARAMETER:
...@@ -1379,39 +1479,51 @@ void* handle_events(void* ptr) ...@@ -1379,39 +1479,51 @@ void* handle_events(void* ptr)
break; break;
case FDLIF_SDN: case FDLIF_SDN:
if (con_ind_sdb.primitive == IND) { if (con_ind_sdb.primitive == IND)
{
fdlif_sda_sdn_srd_ind(con_ind_sdb.invoke_id, fdlif_sda_sdn_srd_ind(con_ind_sdb.invoke_id,
(T_FDLIF_SDN_SDA_SRD_REQ FAR*)con_ind_buffer, ap->racklist); (T_FDLIF_SDN_SDA_SRD_REQ FAR*)con_ind_buffer,
} else { ap->racklist);
}
else
{
fdlif_sda_sdn_con(con_ind_sdb.invoke_id, con_ind_sdb.result, fdlif_sda_sdn_con(con_ind_sdb.invoke_id, con_ind_sdb.result,
(T_FDLIF_ERROR*)con_ind_buffer, ap->racklist); (T_FDLIF_ERROR*)con_ind_buffer, ap->racklist);
} }
break; break;
case FDLIF_SDA: case FDLIF_SDA:
if (con_ind_sdb.primitive == IND) { if (con_ind_sdb.primitive == IND)
{
fdlif_sda_sdn_srd_ind(con_ind_sdb.invoke_id, fdlif_sda_sdn_srd_ind(con_ind_sdb.invoke_id,
(T_FDLIF_SDN_SDA_SRD_REQ FAR*)con_ind_buffer, ap->racklist); (T_FDLIF_SDN_SDA_SRD_REQ FAR*)con_ind_buffer,
} else { ap->racklist);
}
else
{
fdlif_sda_sdn_con(con_ind_sdb.invoke_id, con_ind_sdb.result, fdlif_sda_sdn_con(con_ind_sdb.invoke_id, con_ind_sdb.result,
(T_FDLIF_ERROR*)con_ind_buffer, ap->racklist); (T_FDLIF_ERROR*)con_ind_buffer, ap->racklist);
} }
break; break;
case FDLIF_SRD: case FDLIF_SRD:
if (con_ind_sdb.primitive == IND) { if (con_ind_sdb.primitive == IND)
{
fdlif_sda_sdn_srd_ind(con_ind_sdb.invoke_id, fdlif_sda_sdn_srd_ind(con_ind_sdb.invoke_id,
(T_FDLIF_SDN_SDA_SRD_REQ FAR*)con_ind_buffer, ap->racklist); (T_FDLIF_SDN_SDA_SRD_REQ FAR*)con_ind_buffer,
} else { ap->racklist);
}
else
{
fdlif_srd_con(con_ind_sdb.result, con_ind_sdb.invoke_id, fdlif_srd_con(con_ind_sdb.result, con_ind_sdb.invoke_id,
(T_FDLIF_SRD_CNF*)con_ind_buffer, ap->racklist); (T_FDLIF_SRD_CNF*)con_ind_buffer, ap->racklist);
} }
break; break;
default: default:
printf("\nnot supported FDLIF service received\n"); printf("\nnot supported FDLIF service received\n");
printf("service: %d primitive: %d\n", con_ind_sdb.service, printf("service: %d primitive: %d\n", con_ind_sdb.service,
con_ind_sdb.primitive); con_ind_sdb.primitive);
} }
break; break;
} }
...@@ -1419,14 +1531,18 @@ void* handle_events(void* ptr) ...@@ -1419,14 +1531,18 @@ void* handle_events(void* ptr)
default: default:
printf("\nnot supported layer service received\n"); printf("\nnot supported layer service received\n");
printf("layer: %d service: %d primitive: %d\n", con_ind_sdb.layer, printf("layer: %d service: %d primitive: %d\n", con_ind_sdb.layer,
con_ind_sdb.service, con_ind_sdb.primitive); con_ind_sdb.service, con_ind_sdb.primitive);
break; break;
} }
}
} else if (sts != NO_CON_IND_RECEIVED) { else if (sts != NO_CON_IND_RECEIVED)
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
} else { }
if (local->slave_diag_requested) { else
{
if (local->slave_diag_requested)
{
// errh_Info( "Profibus - Diag re-request"); // errh_Info( "Profibus - Diag re-request");
// dp_get_slave_diag(hDevice); // dp_get_slave_diag(hDevice);
} }
...@@ -1444,7 +1560,6 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1444,7 +1560,6 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
pwr_sClass_Pb_Profiboard* op; pwr_sClass_Pb_Profiboard* op;
pwr_tUInt16 sts; pwr_tUInt16 sts;
pwr_tStatus status; pwr_tStatus status;
T_PROFI_DEVICE_HANDLE* hDevice;
io_sAgentLocal* local; io_sAgentLocal* local;
pwr_tCid cid; pwr_tCid cid;
...@@ -1458,7 +1573,7 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1458,7 +1573,7 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
char name[196]; char name[196];
struct timespec rqtp = { 0, 20000000 }; // 20 ms struct timespec rqtp = {0, 20000000}; // 20 ms
int retry; int retry;
...@@ -1466,13 +1581,12 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1466,13 +1581,12 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
/* Allocate area for local data structure */ /* Allocate area for local data structure */
ap->Local = calloc(1, sizeof(io_sAgentLocal)); ap->Local = calloc(1, sizeof(io_sAgentLocal));
if (!ap->Local) { if (!ap->Local)
{
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, "calloc"); errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, "calloc");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
hDevice = (T_PROFI_DEVICE_HANDLE*)ap->Local;
local = (io_sAgentLocal*)ap->Local; local = (io_sAgentLocal*)ap->Local;
op = (pwr_sClass_Pb_Profiboard*)ap->op; op = (pwr_sClass_Pb_Profiboard*)ap->op;
...@@ -1481,58 +1595,67 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1481,58 +1595,67 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
/* Initialize interface */ /* Initialize interface */
if (ctx->Node->Restarts > 0) { if (ctx->Node->Restarts > 0)
{
nanosleep(&rqtp, NULL); nanosleep(&rqtp, NULL);
} }
errh_Info("Initializing interface for Profibus DP Master %s", ap->Name); errh_Info("Initializing interface for Profibus DP Master %s", ap->Name);
sts = profi_init(hDevice, (unsigned char)op->BusNumber - 1, 0, 0); sts = profi_init((unsigned char)op->BusNumber - 1, 0, 0);
if (sts != E_OK) { if (sts != E_OK)
{
/* Can't open driver */ /* Can't open driver */
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error( errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"ERROR config Profibus DP Master %s - %s", ap->Name, "open device"); "open device");
ctx->Node->EmergBreakTrue = 1; ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE; return IO__ERRDEVICE;
} }
/* If this is not the Profibus I/O process, return */ /* If this is not the Profibus I/O process, return */
if ((op->Process & io_mProcess_Profibus) if ((op->Process & io_mProcess_Profibus) &&
&& (ctx->Process != io_mProcess_Profibus)) { (ctx->Process != io_mProcess_Profibus))
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
errh_Info("Init template I/O agent for Profibus DP Master %s, %d", ap->Name, errh_Info("Init template I/O agent for Profibus DP Master %s, %d", ap->Name,
ctx->Process); ctx->Process);
return IO__SUCCESS; return IO__SUCCESS;
} }
if (ctx->Node->Restarts > 0) { if (ctx->Node->Restarts > 0)
errh_Info( {
"Warm restart - Skipping config of Profibus DP Master %s", ap->Name); errh_Info("Warm restart - Skipping config of Profibus DP Master %s",
ap->Name);
op->Status = PB__NORMAL; op->Status = PB__NORMAL;
// return IO__SUCCESS; // return IO__SUCCESS;
} }
errh_Info("Config of Profibus DP Master %s", ap->Name); errh_Info("Config of Profibus DP Master %s", ap->Name);
if (op->DisableBus != 1) { if (op->DisableBus != 1)
{
ok = FALSE; ok = FALSE;
if (ctx->Node->Restarts == 0) { if (ctx->Node->Restarts == 0)
{
retry = 0; retry = 0;
while (!ok) { while (!ok)
{
op->Status = PB__NOTINIT; op->Status = PB__NOTINIT;
/* Set FMB configuration */ /* Set FMB configuration */
sts = fmb_set_configuration(hDevice, ap); sts = fmb_set_configuration(ap);
if (!sts) { if (!sts)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"fmb set configuration"); "fmb set configuration");
retry++; retry++;
if (retry < 2) { if (retry < 2)
{
nanosleep(&rqtp, NULL); nanosleep(&rqtp, NULL);
continue; continue;
} }
...@@ -1541,48 +1664,60 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1541,48 +1664,60 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
/* Set DP master parameters */ /* Set DP master parameters */
if (local->dp) { if (local->dp)
sts = dp_init_master(hDevice); {
if (!sts) { sts = dp_init_master();
if (!sts)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"dp init master"); "dp init master");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
} }
/* Download DP bus parameters */ /* Download DP bus parameters */
if (local->dp && !local->fdl) { if (local->dp && !local->fdl)
sts = dp_download_bus(hDevice, op); {
if (!sts) { sts = dp_download_bus(op);
if (!sts)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"dp download bus"); "dp download bus");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
} else if (!local->dp && local->fdl) { }
sts = fmb_set_busparameter(hDevice, op); else if (!local->dp && local->fdl)
if (!sts) { {
sts = fmb_set_busparameter(op);
if (!sts)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus FDL Master %s - %s", ap->Name, errh_Error("ERROR config Profibus FDL Master %s - %s", ap->Name,
"fmb set busparam"); "fmb set busparam");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} else }
else
op->Status = PB__NORMAL; op->Status = PB__NORMAL;
} else { }
sts = fmb_set_busparameter(hDevice, op); else
if (!sts) { {
sts = fmb_set_busparameter(op);
if (!sts)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus Master %s - %s", ap->Name, errh_Error("ERROR config Profibus Master %s - %s", ap->Name,
"fmb set busparam"); "fmb set busparam");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
sts = dp_set_busparameter(hDevice, op); sts = dp_set_busparameter(op);
if (!sts) { if (!sts)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"dp set busparam"); "dp set busparam");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
} }
...@@ -1593,7 +1728,8 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1593,7 +1728,8 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
op->NumberSlaves = 0; op->NumberSlaves = 0;
status = gdh_GetChild(ap->Objid, &slave_objid); status = gdh_GetChild(ap->Objid, &slave_objid);
while (ODD(status)) { while (ODD(status))
{
status = gdh_GetObjectClass(slave_objid, &slave_class); status = gdh_GetObjectClass(slave_objid, &slave_class);
cid = slave_class; cid = slave_class;
...@@ -1602,35 +1738,38 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1602,35 +1738,38 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
; ;
status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress*)&sop); status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress*)&sop);
status = gdh_ObjidToName( status = gdh_ObjidToName(slave_objid, (char*)&name, sizeof(name),
slave_objid, (char*)&name, sizeof(name), cdh_mNName); cdh_mNName);
if (cid == pwr_cClass_Pb_DP_Slave) { if (cid == pwr_cClass_Pb_DP_Slave)
{
errh_Info("Download Profibus DP Slave config - %s", name); errh_Info("Download Profibus DP Slave config - %s", name);
status = dp_download_slave(hDevice, (pwr_sClass_Pb_DP_Slave*)sop); status = dp_download_slave((pwr_sClass_Pb_DP_Slave*)sop);
if (!status) { if (!status)
{
errh_Error("ERROR Init Profibus DP slave %s", name); errh_Error("ERROR Init Profibus DP slave %s", name);
} }
op->NumberSlaves++; op->NumberSlaves++;
} }
if (cid == pwr_cClass_Pb_FDL_SAP) { if (cid == pwr_cClass_Pb_FDL_SAP)
{
errh_Info("Download Profibus FDL SAP config - %s", name); errh_Info("Download Profibus FDL SAP config - %s", name);
if (!((pwr_sClass_Pb_FDL_SAP*)sop)->Responder) if (!((pwr_sClass_Pb_FDL_SAP*)sop)->Responder)
status = fdlif_sap_activate_req( status = fdlif_sap_activate_req((pwr_sClass_Pb_FDL_SAP*)sop);
hDevice, (pwr_sClass_Pb_FDL_SAP*)sop);
else else
status = fdlif_rsap_activate_req( status = fdlif_rsap_activate_req((pwr_sClass_Pb_FDL_SAP*)sop);
hDevice, (pwr_sClass_Pb_FDL_SAP*)sop);
if (!status) { if (!status)
{
((pwr_sClass_Pb_FDL_SAP*)sop)->Status = PB__INITFAIL; ((pwr_sClass_Pb_FDL_SAP*)sop)->Status = PB__INITFAIL;
errh_Error("ERROR Init Profibus FDL SAP %s", name); errh_Error("ERROR Init Profibus FDL SAP %s", name);
} else }
else
((pwr_sClass_Pb_FDL_SAP*)sop)->Status = PB__NORMAL; ((pwr_sClass_Pb_FDL_SAP*)sop)->Status = PB__NORMAL;
} }
...@@ -1641,7 +1780,8 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1641,7 +1780,8 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
status = gdh_GetChild(ap->Objid, &slave_objid); status = gdh_GetChild(ap->Objid, &slave_objid);
while (ODD(status)) { while (ODD(status))
{
status = gdh_GetObjectClass(slave_objid, &slave_class); status = gdh_GetObjectClass(slave_objid, &slave_class);
cid = slave_class; cid = slave_class;
...@@ -1649,21 +1789,24 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1649,21 +1789,24 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
while (ODD(gdh_GetSuperClass(cid, &cid, pwr_cNOid))) while (ODD(gdh_GetSuperClass(cid, &cid, pwr_cNOid)))
; ;
if (cid == pwr_cClass_Pb_DP_Slave) { if (cid == pwr_cClass_Pb_DP_Slave)
{
status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress*)&sop); status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress*)&sop);
status = dp_io_offsets(hDevice, sop); status = dp_io_offsets(sop);
} }
status = gdh_GetNextSibling(slave_objid, &slave_objid); status = gdh_GetNextSibling(slave_objid, &slave_objid);
} }
/* Move to STOP mode, this will fix the DPRAM layout */ /* Move to STOP mode, this will fix the DPRAM layout */
if (local->dp) { if (local->dp)
sts = dp_act_param_loc(hDevice, DP_OP_MODE_STOP); {
if (sts != E_OK) { sts = dp_act_param_loc(DP_OP_MODE_STOP);
if (sts != E_OK)
{
op->Status = PB__INITFAIL; op->Status = PB__INITFAIL;
errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name, errh_Error("ERROR config Profibus DP Master %s - %s", ap->Name,
"act param loc to STOPPED"); "act param loc to STOPPED");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
} }
...@@ -1671,7 +1814,7 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1671,7 +1814,7 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
ok = TRUE; ok = TRUE;
} /* End - While !ok */ } /* End - While !ok */
} /* End - Initialization only if not restart */ } /* End - Initialization only if not restart */
/* else { /* else {
Move to STOP mode, this will fix the DPRAM layout Move to STOP mode, this will fix the DPRAM layout
...@@ -1683,55 +1826,9 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -1683,55 +1826,9 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
} }
} */ } */
} else
op->Status = PB__DISABLED;
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Swap method for the Pb_profiboard agent
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoAgentSwap(io_tCtx ctx, io_sAgent* ap, io_eEvent event)
{
switch (event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap: {
pwr_sClass_Pb_Profiboard* op;
char DeviceName[64];
io_sAgentLocal* local;
if (ap->Local == NULL) {
/* Allocate area for local data structure */
ap->Local = calloc(1, sizeof(io_sAgentLocal));
if (!ap->Local) {
errh_Error(
"ERROR swap init Profibus DP Master %s - %s", ap->Name, "calloc");
return IO__ERRINIDEVICE;
}
local = (io_sAgentLocal*)ap->Local;
errh_Info("Swap init interface for Profibus DP Master %s", ap->Name);
op = (pwr_sClass_Pb_Profiboard*)ap->op;
sprintf(DeviceName, "/dev/pbboard%u", op->BusNumber - 1);
local->hDpsBoardDevice = open(DeviceName, O_RDONLY | O_NONBLOCK);
if (local->hDpsBoardDevice == -1) {
errh_Error(
"ERROR swap init Profibus DP Master %s - %s", ap->Name, "open");
return IO__ERRINIDEVICE;
}
}
break;
}
case io_eEvent_EmergencyBreak:
case io_eEvent_IoCommEmergencyBreak:
IoAgentClose(ctx, ap);
break;
} }
else
op->Status = PB__DISABLED;
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -1742,7 +1839,6 @@ static pwr_tStatus IoAgentSwap(io_tCtx ctx, io_sAgent* ap, io_eEvent event) ...@@ -1742,7 +1839,6 @@ static pwr_tStatus IoAgentSwap(io_tCtx ctx, io_sAgent* ap, io_eEvent event)
static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
{ {
io_sAgentLocal* local; io_sAgentLocal* local;
T_PROFI_DEVICE_HANDLE* hDevice;
pwr_sClass_Pb_Profiboard* op; pwr_sClass_Pb_Profiboard* op;
pwr_tUInt16 sts; pwr_tUInt16 sts;
...@@ -1751,18 +1847,19 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1751,18 +1847,19 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
pwr_tUInt16 data_len; pwr_tUInt16 data_len;
io_sRack* slave_list; io_sRack* slave_list;
hDevice = (T_PROFI_DEVICE_HANDLE*)ap->Local;
local = (io_sAgentLocal*)ap->Local; local = (io_sAgentLocal*)ap->Local;
op = (pwr_sClass_Pb_Profiboard*)ap->op; op = (pwr_sClass_Pb_Profiboard*)ap->op;
/* Activate supervision thread, first cycle */ /* Activate supervision thread, first cycle */
if (!local->args.local) { if (!local->args.local)
{
pthread_attr_t attr; pthread_attr_t attr;
pthread_mutexattr_t mutexattr; pthread_mutexattr_t mutexattr;
local->args.local = local; local->args.local = local;
local->args.ap = ap; local->args.ap = ap;
local->args.ctx = ctx;
pthread_mutexattr_init(&mutexattr); pthread_mutexattr_init(&mutexattr);
pthread_mutex_init(&local->mutex, &mutexattr); pthread_mutex_init(&local->mutex, &mutexattr);
...@@ -1776,17 +1873,20 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1776,17 +1873,20 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
/* Iterate over the slaves. */ /* Iterate over the slaves. */
for (slave_list = ap->racklist; slave_list != NULL; for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) { slave_list = slave_list->next)
if (((io_sRackLocal*)slave_list->Local)->dp) { {
if (((io_sRackLocal*)slave_list->Local)->dp)
{
sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op; sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op;
mp = (pwr_sClass_Pb_Profiboard*)ap->op; mp = (pwr_sClass_Pb_Profiboard*)ap->op;
/* Read process data. */ /* Read process data. */
if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL if (sp->Status == PB__NORMAL && mp->Status == PB__NORMAL &&
&& sp->DisableSlave != 1 && mp->DisableBus != 1) { sp->DisableSlave != 1 && mp->DisableBus != 1)
{
data_len = sp->BytesOfInput; data_len = sp->BytesOfInput;
sts = profi_get_data(hDevice, ID_DP_SLAVE_IO_IMAGE, sp->OffsetInputs, sts = profi_get_data(ID_DP_SLAVE_IO_IMAGE, sp->OffsetInputs, &data_len,
&data_len, &sp->Inputs); &sp->Inputs);
} }
} }
} }
...@@ -1802,33 +1902,35 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -1802,33 +1902,35 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap) static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap)
{ {
io_sAgentLocal* local; io_sAgentLocal* local;
T_PROFI_DEVICE_HANDLE* hDevice;
pwr_tUInt16 sts; pwr_tUInt16 sts;
pwr_sClass_Pb_Profiboard* mp; pwr_sClass_Pb_Profiboard* mp;
pwr_sClass_Pb_DP_Slave* sp; pwr_sClass_Pb_DP_Slave* sp;
io_sRack* slave_list; io_sRack* slave_list;
hDevice = (T_PROFI_DEVICE_HANDLE*)ap->Local;
local = (io_sAgentLocal*)ap->Local; local = (io_sAgentLocal*)ap->Local;
pthread_mutex_lock(&local->mutex); pthread_mutex_lock(&local->mutex);
/* Iterate over the slaves. */ /* Iterate over the slaves. */
for (slave_list = ap->racklist; slave_list != NULL; for (slave_list = ap->racklist; slave_list != NULL;
slave_list = slave_list->next) { slave_list = slave_list->next)
if (((io_sRackLocal*)slave_list->Local)->dp) { {
if (((io_sRackLocal*)slave_list->Local)->dp)
{
sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op; sp = (pwr_sClass_Pb_DP_Slave*)slave_list->op;
mp = (pwr_sClass_Pb_Profiboard*)ap->op; mp = (pwr_sClass_Pb_Profiboard*)ap->op;
// Write the whole I/O output area from local area // Write the whole I/O output area from local area
if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) if ((sp->Status == PB__NORMAL || sp->Status == PB__NOCONN) &&
&& mp->Status == PB__NORMAL && (sp->DisableSlave != 1) mp->Status == PB__NORMAL && (sp->DisableSlave != 1) &&
&& (mp->DisableBus != 1)) { (mp->DisableBus != 1))
if (sp->BytesOfOutput > 0) { {
sts = profi_set_data(hDevice, ID_DP_SLAVE_IO_IMAGE, sp->OffsetOutputs, if (sp->BytesOfOutput > 0)
sp->BytesOfOutput, &sp->Outputs); {
sts = profi_set_data(ID_DP_SLAVE_IO_IMAGE, sp->OffsetOutputs,
sp->BytesOfOutput, &sp->Outputs);
if (sts != E_OK) if (sts != E_OK)
sp->ErrorCount++; sp->ErrorCount++;
...@@ -1848,7 +1950,6 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap) ...@@ -1848,7 +1950,6 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap)
static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap) static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap)
{ {
io_sAgentLocal* local; io_sAgentLocal* local;
T_PROFI_DEVICE_HANDLE* hDevice;
pwr_tStatus sts = PB_FALSE; pwr_tStatus sts = PB_FALSE;
T_PROFI_SERVICE_DESCR sdb; T_PROFI_SERVICE_DESCR sdb;
...@@ -1866,7 +1967,6 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap) ...@@ -1866,7 +1967,6 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap)
pthread_mutex_lock(&local->mutex); pthread_mutex_lock(&local->mutex);
hDevice = (T_PROFI_DEVICE_HANDLE*)ap->Local;
sdb.comm_ref = 0; sdb.comm_ref = 0;
sdb.layer = DP; sdb.layer = DP;
sdb.service = DP_EXIT_MASTER; sdb.service = DP_EXIT_MASTER;
...@@ -1874,35 +1974,49 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap) ...@@ -1874,35 +1974,49 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap)
sdb.invoke_id = 0; sdb.invoke_id = 0;
sdb.result = 0; sdb.result = 0;
profi_snd_req_res(hDevice, &sdb, &sdb, PB_FALSE); profi_snd_req_res(&sdb, &sdb, PB_FALSE);
try_profi_rcv_con_ind( try_profi_rcv_con_ind(&con_ind_sdb, con_ind_buffer, &con_ind_buffer_len,
hDevice, &con_ind_sdb, con_ind_buffer, &con_ind_buffer_len, &result); &result);
if ((con_ind_sdb.service == DP_EXIT_MASTER) && (con_ind_sdb.primitive == CON) if ((con_ind_sdb.service == DP_EXIT_MASTER) &&
&& (con_ind_sdb.result == POS)) { (con_ind_sdb.primitive == CON) && (con_ind_sdb.result == POS))
{
sts = PB_TRUE; sts = PB_TRUE;
} }
close(local->hServiceReadDevice); profi_end();
close(local->hServiceWriteDevice);
close(local->hDpDataDevice);
close(local->hDpsInputDataDevice);
close(local->hDpsOutputDataDevice);
close(local->hDpsBoardDevice);
pthread_mutex_unlock(&local->mutex); pthread_mutex_unlock(&local->mutex);
free((char*)local); free((char*)local);
if (ctx->Node->EmergBreakTrue == 1)
errh_Fatal("Emergency break detected shutting down profibus");
return sts; return sts;
} }
static pwr_tStatus IoAgentSwap(io_tCtx ctx, io_sAgent* ap, io_eEvent event)
{
switch (event) {
case io_eEvent_EmergencyBreak:
case io_eEvent_IoCommEmergencyBreak:
IoAgentClose(ctx, ap);
break;
default:
break;
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Pb_Profiboard) pwr_dExport pwr_BindIoMethods(Pb_Profiboard) = {
= { pwr_BindIoMethod(IoAgentInit), pwr_BindIoMethod(IoAgentRead), pwr_BindIoMethod(IoAgentInit), pwr_BindIoMethod(IoAgentRead),
pwr_BindIoMethod(IoAgentWrite), pwr_BindIoMethod(IoAgentClose), pwr_BindIoMethod(IoAgentWrite), pwr_BindIoMethod(IoAgentClose),
pwr_BindIoMethod(IoAgentSwap), pwr_NullMethod }; pwr_BindIoMethod(IoAgentSwap), pwr_NullMethod};
...@@ -80,8 +80,7 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap) ...@@ -80,8 +80,7 @@ static pwr_tStatus IoAgentInit(io_tCtx ctx, io_sAgent* ap)
/* Allocate area for local data structure */ /* Allocate area for local data structure */
ap->Local = (io_sAgentLocal*)new io_sAgentLocal; ap->Local = (io_sAgentLocal*)new io_sAgentLocal;
if (!ap->Local) if (!ap->Local) {
{
// errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, // errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name,
// "calloc"); // "calloc");
return IO__ERRINIDEVICE; return IO__ERRINIDEVICE;
...@@ -148,48 +147,39 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) ...@@ -148,48 +147,39 @@ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap)
// pthread_mutex_lock(&local->mutex); // pthread_mutex_lock(&local->mutex);
for (ii = 1; ii < local->device_data.size(); ii++) for (ii = 1; ii < local->device_data.size(); ii++) {
{ if (local->device_data[ii]->device_state == PNAK_DEVICE_STATE_CONNECTED) {
if (local->device_data[ii]->device_state == PNAK_DEVICE_STATE_CONNECTED) for (jj = 0; jj < local->device_data[ii]->iocr_data.size(); jj++) {
{
for (jj = 0; jj < local->device_data[ii]->iocr_data.size(); jj++)
{
pn_iocr_data = local->device_data[ii]->iocr_data[jj]; pn_iocr_data = local->device_data[ii]->iocr_data[jj];
if (pn_iocr_data->type == PROFINET_IO_CR_TYPE_INPUT) if (pn_iocr_data->type == PROFINET_IO_CR_TYPE_INPUT) {
{
data_length = pn_iocr_data->io_data_length; data_length = pn_iocr_data->io_data_length;
sts = pnak_get_iocr_data(0, pn_iocr_data->identifier, sts = pnak_get_iocr_data(0, pn_iocr_data->identifier,
pn_iocr_data->io_data, &data_length, &ioxs, pn_iocr_data->io_data, &data_length, &ioxs, &status_data);
&status_data);
if (sts == PNAK_OK) if (sts == PNAK_OK) {
{ for (kk = 0; kk < local->device_data[ii]->module_data.size();
for (kk = 0; kk < local->device_data[ii]->module_data.size(); kk++) kk++) {
{
for (ll = 0; ll < local->device_data[ii] for (ll = 0; ll < local->device_data[ii]
->module_data[kk] ->module_data[kk]
->submodule_data.size(); ->submodule_data.size();
ll++) ll++) {
{ submodule = local->device_data[ii]
submodule = ->module_data[kk]
local->device_data[ii]->module_data[kk]->submodule_data[ll]; ->submodule_data[ll];
if ((submodule->type == PROFINET_IO_SUBMODULE_TYPE_INPUT) || if ((submodule->type == PROFINET_IO_SUBMODULE_TYPE_INPUT)
(submodule->type == || (submodule->type
PROFINET_IO_SUBMODULE_TYPE_INPUT_AND_OUTPUT)) == PROFINET_IO_SUBMODULE_TYPE_INPUT_AND_OUTPUT)) {
{
io_datap = (pn_iocr_data->io_data + submodule->offset_io_in); io_datap = (pn_iocr_data->io_data + submodule->offset_io_in);
clean_io_datap = (pn_iocr_data->clean_io_data + clean_io_datap = (pn_iocr_data->clean_io_data
submodule->offset_clean_io_in); + submodule->offset_clean_io_in);
memcpy(clean_io_datap, io_datap, memcpy(
submodule->io_in_data_length); clean_io_datap, io_datap, submodule->io_in_data_length);
} }
} }
} }
} } else {
else
{
printf("pnak_get_iocr_data failed!\n"); printf("pnak_get_iocr_data failed!\n");
} }
} }
...@@ -228,45 +218,37 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap) ...@@ -228,45 +218,37 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap)
// pthread_mutex_lock(&local->mutex); // pthread_mutex_lock(&local->mutex);
for (ii = 1; ii < local->device_data.size(); ii++) for (ii = 1; ii < local->device_data.size(); ii++) {
{ if (slave_list != NULL) {
if (slave_list != NULL)
{
sp = (pwr_sClass_PnDevice*)slave_list->op; sp = (pwr_sClass_PnDevice*)slave_list->op;
slave_list = slave_list->next; slave_list = slave_list->next;
} }
if (local->device_data[ii]->device_state == PNAK_DEVICE_STATE_CONNECTED) if (local->device_data[ii]->device_state == PNAK_DEVICE_STATE_CONNECTED) {
{ for (jj = 0; jj < local->device_data[ii]->iocr_data.size(); jj++) {
for (jj = 0; jj < local->device_data[ii]->iocr_data.size(); jj++)
{
pn_iocr_data = local->device_data[ii]->iocr_data[jj]; pn_iocr_data = local->device_data[ii]->iocr_data[jj];
if (pn_iocr_data->type == PROFINET_IO_CR_TYPE_OUTPUT) if (pn_iocr_data->type == PROFINET_IO_CR_TYPE_OUTPUT) {
{
data_length = pn_iocr_data->io_data_length; data_length = pn_iocr_data->io_data_length;
/* Set io status to good */ /* Set io status to good */
memset(pn_iocr_data->io_data, 0x80, memset(pn_iocr_data->io_data, 0x80,
data_length); // 0x80 is PNAK_IOXS_STATUS_DATA_GOOD data_length); // 0x80 is PNAK_IOXS_STATUS_DATA_GOOD
for (kk = 0; kk < local->device_data[ii]->module_data.size(); kk++) for (kk = 0; kk < local->device_data[ii]->module_data.size(); kk++) {
{ for (ll = 0; ll < local->device_data[ii]
for (ll = 0; ->module_data[kk]
ll < ->submodule_data.size();
local->device_data[ii]->module_data[kk]->submodule_data.size(); ll++) {
ll++) submodule
{ = local->device_data[ii]->module_data[kk]->submodule_data[ll];
submodule = if ((submodule->type == PROFINET_IO_SUBMODULE_TYPE_OUTPUT)
local->device_data[ii]->module_data[kk]->submodule_data[ll]; || (submodule->type
if ((submodule->type == PROFINET_IO_SUBMODULE_TYPE_OUTPUT) || == PROFINET_IO_SUBMODULE_TYPE_INPUT_AND_OUTPUT)) {
(submodule->type ==
PROFINET_IO_SUBMODULE_TYPE_INPUT_AND_OUTPUT))
{
io_datap = (pn_iocr_data->io_data + submodule->offset_io_out); io_datap = (pn_iocr_data->io_data + submodule->offset_io_out);
clean_io_datap = (pn_iocr_data->clean_io_data + clean_io_datap = (pn_iocr_data->clean_io_data
submodule->offset_clean_io_out); + submodule->offset_clean_io_out);
memcpy(io_datap, clean_io_datap, submodule->io_out_data_length); memcpy(io_datap, clean_io_datap, submodule->io_out_data_length);
/*status_datap = io_datap + submodule->io_out_data_length; /*status_datap = io_datap + submodule->io_out_data_length;
...@@ -276,60 +258,51 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap) ...@@ -276,60 +258,51 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap)
} }
} }
} }
char ioxs = CYCLIC_DATA_STATUS_DATA_VALID | char ioxs = CYCLIC_DATA_STATUS_DATA_VALID
CYCLIC_DATA_STATUS_STATE_PRIMARY | | CYCLIC_DATA_STATUS_STATE_PRIMARY | CYCLIC_DATA_STATUS_STATE_RUN
CYCLIC_DATA_STATUS_STATE_RUN | | CYCLIC_DATA_STATUS_NORMAL_OPERATION;
CYCLIC_DATA_STATUS_NORMAL_OPERATION;
sts = pnak_set_iocr_data(0, pn_iocr_data->identifier, sts = pnak_set_iocr_data(0, pn_iocr_data->identifier,
pn_iocr_data->io_data, pn_iocr_data->io_data, pn_iocr_data->io_data_length, ioxs);
pn_iocr_data->io_data_length, ioxs); if (sts != PNAK_OK) {
if (sts != PNAK_OK)
{
printf("pnak_set_iocr_data failed!\n"); printf("pnak_set_iocr_data failed!\n");
} }
} }
} }
if (slave_list != NULL) if (slave_list != NULL) {
{
/* Check if there is a write request pending ?? */ /* Check if there is a write request pending ?? */
if (sp->WriteReq.SendReq) if (sp->WriteReq.SendReq) {
{ if ((sp->WriteReq.Length > 0)
if ((sp->WriteReq.Length > 0) && && (sp->WriteReq.Length <= sizeof(sp->WriteReq.Data))) {
(sp->WriteReq.Length <= sizeof(sp->WriteReq.Data))) for (jj = 0; jj < local->device_data[ii]->module_data.size();
{ jj++) {
for (jj = 0; jj < local->device_data[ii]->module_data.size(); jj++) if (local->device_data[ii]->module_data[jj]->slot_number
{ == sp->WriteReq.SlotNumber) {
if (local->device_data[ii]->module_data[jj]->slot_number ==
sp->WriteReq.SlotNumber)
{
for (kk = 0; kk < local->device_data[ii] for (kk = 0; kk < local->device_data[ii]
->module_data[jj] ->module_data[jj]
->submodule_data.size(); ->submodule_data.size();
kk++) kk++) {
{
if (local->device_data[ii] if (local->device_data[ii]
->module_data[jj] ->module_data[jj]
->submodule_data[kk] ->submodule_data[kk]
->subslot_number == sp->WriteReq.SubslotNumber) ->subslot_number
{ == sp->WriteReq.SubslotNumber) {
if (local->device_data[ii] if (local->device_data[ii]
->module_data[jj] ->module_data[jj]
->submodule_data[kk] ->submodule_data[kk]
->api > 0) ->api
{ > 0) {
sp->WriteReq.Api = local->device_data[ii] sp->WriteReq.Api = local->device_data[ii]
->module_data[jj] ->module_data[jj]
->submodule_data[kk] ->submodule_data[kk]
->api; ->api;
} }
pack_write_req(&local->service_req_res, pack_write_req(&local->service_req_res,
local->device_data[ii]->device_ref, local->device_data[ii]->device_ref, &sp->WriteReq);
&sp->WriteReq);
sts = pnak_send_service_req_res(0, &local->service_req_res); sts = pnak_send_service_req_res(0, &local->service_req_res);
errh_Info("Profinet - Asynch write, dev: %d", errh_Info("Profinet - Asynch write, dev: %d",
local->device_data[ii]->device_ref); local->device_data[ii]->device_ref);
break; break;
} }
} }
......
...@@ -80,8 +80,7 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -80,8 +80,7 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
latent_input_count = 0; latent_input_count = 0;
latent_output_count = 0; latent_output_count = 0;
while (cardp) while (cardp) {
{
local_card = (io_sPnCardLocal*)calloc(1, sizeof(*local_card)); local_card = (io_sPnCardLocal*)calloc(1, sizeof(*local_card));
cardp->Local = local_card; cardp->Local = local_card;
local_card->input_area = ((io_sPnRackLocal*)(rp->Local))->inputs; local_card->input_area = ((io_sPnRackLocal*)(rp->Local))->inputs;
...@@ -93,38 +92,32 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -93,38 +92,32 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
while (ODD(gdh_GetSuperClass(cid, &cid, cardp->Objid))) while (ODD(gdh_GetSuperClass(cid, &cid, cardp->Objid)))
; ;
switch (cid) switch (cid) {
{ /* New style configuring (from v4.1.3) with Pb_Module objects or subclass.
/* New style configuring (from v4.1.3) with Pb_Module objects or subclass. Loop all channels
Loop all channels in the module and set channel size and offset. */
in the module and set channel size and offset. */
case pwr_cClass_PnModule: case pwr_cClass_PnModule:
mp = (pwr_sClass_PnModule*)cardp->op; mp = (pwr_sClass_PnModule*)cardp->op;
mp->Status = PB__INITFAIL; mp->Status = PB__INITFAIL;
cardp->offset = 0; cardp->offset = 0;
for (i = 0; i < cardp->ChanListSize; i++) for (i = 0; i < cardp->ChanListSize; i++) {
{
chanp = &cardp->chanlist[i]; chanp = &cardp->chanlist[i];
if (chanp->ChanClass != pwr_cClass_ChanDi) if (chanp->ChanClass != pwr_cClass_ChanDi) {
{
input_counter += latent_input_count; input_counter += latent_input_count;
latent_input_count = 0; latent_input_count = 0;
} }
if (chanp->ChanClass != pwr_cClass_ChanDo) if (chanp->ChanClass != pwr_cClass_ChanDo) {
{
output_counter += latent_output_count; output_counter += latent_output_count;
latent_output_count = 0; latent_output_count = 0;
} }
switch (chanp->ChanClass) switch (chanp->ChanClass) {
{
case pwr_cClass_ChanDi: case pwr_cClass_ChanDi:
chan_di = (pwr_sClass_ChanDi*)chanp->cop; chan_di = (pwr_sClass_ChanDi*)chanp->cop;
if (chan_di->Number == 0) if (chan_di->Number == 0) {
{
input_counter += latent_input_count; input_counter += latent_input_count;
latent_input_count = 0; latent_input_count = 0;
} }
...@@ -138,15 +131,15 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -138,15 +131,15 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
// byte order. Maybe booleans can be // byte order. Maybe booleans can be
// considered Little Endian... // considered Little Endian...
// More TODO: Check host endianess aswell and take action accordingly // More TODO: Check host endianess aswell and take action accordingly
if (chan_di->Representation == pwr_eDataRepEnum_Bit16 && if (chan_di->Representation == pwr_eDataRepEnum_Bit16
op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap16(chanp->mask); chanp->mask = swap16(chanp->mask);
if (chan_di->Representation == pwr_eDataRepEnum_Bit32 && if (chan_di->Representation == pwr_eDataRepEnum_Bit32
op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap32(chanp->mask); chanp->mask = swap32(chanp->mask);
if (chan_di->Number == 0) if (chan_di->Number == 0)
latent_input_count = latent_input_count
GetChanSize((pwr_eDataRepEnum)chan_di->Representation); = GetChanSize((pwr_eDataRepEnum)chan_di->Representation);
// printf("Di channel found in %s, Number %d, Offset %d\n", // printf("Di channel found in %s, Number %d, Offset %d\n",
// cardp->Name, chan_di->Number, chanp->offset); // cardp->Name, chan_di->Number, chanp->offset);
break; break;
...@@ -186,23 +179,22 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -186,23 +179,22 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
case pwr_cClass_ChanDo: case pwr_cClass_ChanDo:
chan_do = (pwr_sClass_ChanDo*)chanp->cop; chan_do = (pwr_sClass_ChanDo*)chanp->cop;
if (chan_do->Number == 0) if (chan_do->Number == 0) {
{
output_counter += latent_output_count; output_counter += latent_output_count;
latent_output_count = 0; latent_output_count = 0;
} }
chanp->offset = output_counter; chanp->offset = output_counter;
chan_size = GetChanSize((pwr_eDataRepEnum)chan_do->Representation); chan_size = GetChanSize((pwr_eDataRepEnum)chan_do->Representation);
chanp->mask = 1 << chan_do->Number; chanp->mask = 1 << chan_do->Number;
if (chan_do->Representation == pwr_eDataRepEnum_Bit16 && if (chan_do->Representation == pwr_eDataRepEnum_Bit16
op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap16(chanp->mask); chanp->mask = swap16(chanp->mask);
if (chan_do->Representation == pwr_eDataRepEnum_Bit32 && if (chan_do->Representation == pwr_eDataRepEnum_Bit32
op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian) && op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap32(chanp->mask); chanp->mask = swap32(chanp->mask);
if (chan_do->Number == 0) if (chan_do->Number == 0)
latent_output_count = latent_output_count
GetChanSize((pwr_eDataRepEnum)chan_do->Representation); = GetChanSize((pwr_eDataRepEnum)chan_do->Representation);
// printf("Do channel found in %s, Number %d, Offset %d\n", // printf("Do channel found in %s, Number %d, Offset %d\n",
// cardp->Name, chan_do->Number, chanp->offset); // cardp->Name, chan_do->Number, chanp->offset);
break; break;
...@@ -256,40 +248,31 @@ static pwr_tStatus IoRackRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -256,40 +248,31 @@ static pwr_tStatus IoRackRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
/* The reading of the process image is now performed at the agent level, /* 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. */ this eliminates the need for board specific code at the rack level. */
if (sp->Status == PB__NORMAL) if (sp->Status == PB__NORMAL) {
{
sp->ErrorCount = 0; sp->ErrorCount = 0;
} } else {
else
{
if (local->start_cnt >= local->start_time) if (local->start_cnt >= local->start_time)
sp->ErrorCount++; sp->ErrorCount++;
} }
if (sp->ErrorCount == sp->ErrorHardLimit) if (sp->ErrorCount == sp->ErrorHardLimit) {
{
errh_Error("IO Error hard limit reached on card '%s', stall action %d", errh_Error("IO Error hard limit reached on card '%s', stall action %d",
rp->Name, sp->StallAction); rp->Name, sp->StallAction);
ctx->IOHandler->CardErrorHardLimit = 1; ctx->IOHandler->CardErrorHardLimit = 1;
ctx->IOHandler->ErrorHardLimitObject = cdh_ObjidToAref(rp->Objid); ctx->IOHandler->ErrorHardLimitObject = cdh_ObjidToAref(rp->Objid);
sp->ErrorCount++; sp->ErrorCount++;
} } else if (sp->ErrorCount == sp->ErrorSoftLimit) {
else if (sp->ErrorCount == sp->ErrorSoftLimit)
{
errh_Error("IO Error soft limit reached on card '%s'", rp->Name); errh_Error("IO Error soft limit reached on card '%s'", rp->Name);
ctx->IOHandler->CardErrorSoftLimit = 1; ctx->IOHandler->CardErrorSoftLimit = 1;
ctx->IOHandler->ErrorSoftLimitObject = cdh_ObjidToAref(rp->Objid); ctx->IOHandler->ErrorSoftLimitObject = cdh_ObjidToAref(rp->Objid);
sp->ErrorCount++; sp->ErrorCount++;
} }
if (sp->ErrorCount > sp->ErrorHardLimit) if (sp->ErrorCount > sp->ErrorHardLimit) {
{ if (sp->StallAction == pwr_ePbStallAction_ResetInputs) {
if (sp->StallAction == pwr_ePbStallAction_ResetInputs)
{
if (((io_sPnRackLocal*)(rp->Local))->bytes_of_input > 0) if (((io_sPnRackLocal*)(rp->Local))->bytes_of_input > 0)
memset(((io_sPnRackLocal*)(rp->Local))->inputs, 0, memset(((io_sPnRackLocal*)(rp->Local))->inputs, 0,
((io_sPnRackLocal*)(rp->Local))->bytes_of_input); ((io_sPnRackLocal*)(rp->Local))->bytes_of_input);
} } else if (sp->StallAction == pwr_ePbStallAction_EmergencyBreak)
else if (sp->StallAction == pwr_ePbStallAction_EmergencyBreak)
ctx->Node->EmergBreakTrue = 1; ctx->Node->EmergBreakTrue = 1;
} }
...@@ -307,33 +290,26 @@ static pwr_tStatus IoRackWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -307,33 +290,26 @@ static pwr_tStatus IoRackWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
/* The writing of the process image is now performed at the agent level, /* 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. */ this eliminates the need for board specific code at the rack level. */
if (sp->Status == PB__NORMAL) if (sp->Status == PB__NORMAL) {
{
sp->ErrorCount = 0; sp->ErrorCount = 0;
} } else {
else
{
if (local->start_cnt >= local->start_time) if (local->start_cnt >= local->start_time)
sp->ErrorCount++; sp->ErrorCount++;
} }
if (sp->ErrorCount == sp->ErrorHardLimit) if (sp->ErrorCount == sp->ErrorHardLimit) {
{
errh_Error("IO Error hard limit reached on card '%s', stall action %d", errh_Error("IO Error hard limit reached on card '%s', stall action %d",
rp->Name, sp->StallAction); rp->Name, sp->StallAction);
ctx->IOHandler->CardErrorHardLimit = 1; ctx->IOHandler->CardErrorHardLimit = 1;
ctx->IOHandler->ErrorHardLimitObject = cdh_ObjidToAref(rp->Objid); ctx->IOHandler->ErrorHardLimitObject = cdh_ObjidToAref(rp->Objid);
sp->ErrorCount++; sp->ErrorCount++;
} } else if (sp->ErrorCount == sp->ErrorSoftLimit) {
else if (sp->ErrorCount == sp->ErrorSoftLimit)
{
errh_Error("IO Error soft limit reached on card '%s'", rp->Name); errh_Error("IO Error soft limit reached on card '%s'", rp->Name);
ctx->IOHandler->CardErrorSoftLimit = 1; ctx->IOHandler->CardErrorSoftLimit = 1;
ctx->IOHandler->ErrorSoftLimitObject = cdh_ObjidToAref(rp->Objid); ctx->IOHandler->ErrorSoftLimitObject = cdh_ObjidToAref(rp->Objid);
sp->ErrorCount++; sp->ErrorCount++;
} }
if (sp->ErrorCount > sp->ErrorHardLimit) if (sp->ErrorCount > sp->ErrorHardLimit) {
{
if (sp->StallAction == pwr_ePbStallAction_EmergencyBreak) if (sp->StallAction == pwr_ePbStallAction_EmergencyBreak)
ctx->Node->EmergBreakTrue = 1; ctx->Node->EmergBreakTrue = 1;
} }
...@@ -353,7 +329,6 @@ static pwr_tStatus IoRackClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp) ...@@ -353,7 +329,6 @@ static pwr_tStatus IoRackClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(PnDevice) = { pwr_dExport pwr_BindIoMethods(PnDevice) = { pwr_BindIoMethod(IoRackInit),
pwr_BindIoMethod(IoRackInit), pwr_BindIoMethod(IoRackRead), pwr_BindIoMethod(IoRackRead), pwr_BindIoMethod(IoRackWrite),
pwr_BindIoMethod(IoRackWrite), pwr_BindIoMethod(IoRackClose), pwr_BindIoMethod(IoRackClose), pwr_NullMethod };
pwr_NullMethod};
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Init method for the Pnmodule Init method for the Pnmodule
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, static pwr_tStatus IoCardInit(
io_sCard* cp) io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp)
{ {
io_sPnCardLocal* local; io_sPnCardLocal* local;
pwr_sClass_PnModule* op; pwr_sClass_PnModule* op;
...@@ -57,8 +57,8 @@ static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, ...@@ -57,8 +57,8 @@ static pwr_tStatus IoCardInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Read method for the Pn module Read method for the Pn module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, static pwr_tStatus IoCardRead(
io_sCard* cp) io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp)
{ {
io_sPnCardLocal* local; io_sPnCardLocal* local;
pwr_sClass_PnModule* op; pwr_sClass_PnModule* op;
...@@ -75,7 +75,7 @@ static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, ...@@ -75,7 +75,7 @@ static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
/* all inputs will be zeroed */ /* all inputs will be zeroed */
io_bus_card_read(ctx, rp, cp, local->input_area, 0, slave->ByteOrdering, io_bus_card_read(ctx, rp, cp, local->input_area, 0, slave->ByteOrdering,
slave->FloatRepresentation); slave->FloatRepresentation);
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -83,8 +83,8 @@ static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, ...@@ -83,8 +83,8 @@ static pwr_tStatus IoCardRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Write method for the Pn module Write method for the Pn module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, static pwr_tStatus IoCardWrite(
io_sCard* cp) io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp)
{ {
io_sPnCardLocal* local; io_sPnCardLocal* local;
pwr_sClass_PnModule* op; pwr_sClass_PnModule* op;
...@@ -96,10 +96,9 @@ static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, ...@@ -96,10 +96,9 @@ static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
op->Status = slave->Status; op->Status = slave->Status;
if (op->Status == PB__NORMAL) if (op->Status == PB__NORMAL) {
{
io_bus_card_write(ctx, cp, local->output_area, slave->ByteOrdering, io_bus_card_write(ctx, cp, local->output_area, slave->ByteOrdering,
slave->FloatRepresentation); slave->FloatRepresentation);
} }
// printf("Method Pb_Module-IoCardWrite\n"); // printf("Method Pb_Module-IoCardWrite\n");
return IO__SUCCESS; return IO__SUCCESS;
...@@ -108,8 +107,8 @@ static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, ...@@ -108,8 +107,8 @@ static pwr_tStatus IoCardWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
/*----------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------*\
Close method for the Pb module Close method for the Pb module
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, static pwr_tStatus IoCardClose(
io_sCard* cp) io_tCtx ctx, io_sAgent* ap, io_sRack* rp, io_sCard* cp)
{ {
io_sPnCardLocal* local; io_sPnCardLocal* local;
local = (io_sPnCardLocal*)cp->Local; local = (io_sPnCardLocal*)cp->Local;
...@@ -124,7 +123,6 @@ static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp, ...@@ -124,7 +123,6 @@ static pwr_tStatus IoCardClose(io_tCtx ctx, io_sAgent* ap, io_sRack* rp,
Every method to be exported to the workbench should be registred here. Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(PnModule) = { pwr_dExport pwr_BindIoMethods(PnModule) = { pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardInit), pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardRead), pwr_BindIoMethod(IoCardWrite),
pwr_BindIoMethod(IoCardWrite), pwr_BindIoMethod(IoCardClose), pwr_BindIoMethod(IoCardClose), pwr_NullMethod };
pwr_NullMethod};
...@@ -102,6 +102,7 @@ typedef struct _agent_args ...@@ -102,6 +102,7 @@ typedef struct _agent_args
{ {
void* local; void* local;
io_sAgent* ap; io_sAgent* ap;
io_tCtx ctx;
} agent_args; } agent_args;
typedef struct typedef struct
......
...@@ -60,7 +60,8 @@ typedef enum { ...@@ -60,7 +60,8 @@ typedef enum {
GsdmlSlotData* GsdmlDeviceData::paste_slotdata = 0; GsdmlSlotData* GsdmlDeviceData::paste_slotdata = 0;
GsdmlChannelDiag::GsdmlChannelDiag() : error_type(0) GsdmlChannelDiag::GsdmlChannelDiag()
: error_type(0)
{ {
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
memset(help, 0, sizeof(help)); memset(help, 0, sizeof(help));
...@@ -76,11 +77,13 @@ int GsdmlChannelDiag::print(std::ofstream& fp) ...@@ -76,11 +77,13 @@ int GsdmlChannelDiag::print(std::ofstream& fp)
} }
GsdmlDataRecord::GsdmlDataRecord(const GsdmlDataRecord& x) GsdmlDataRecord::GsdmlDataRecord(const GsdmlDataRecord& x)
: record_idx(x.record_idx), data(x.data), data_length(x.data_length), : record_idx(x.record_idx)
index(x.index), transfer_sequence(x.transfer_sequence) , data(x.data)
, data_length(x.data_length)
, index(x.index)
, transfer_sequence(x.transfer_sequence)
{ {
if (data) if (data) {
{
data = (unsigned char*)malloc(data_length); data = (unsigned char*)malloc(data_length);
memcpy(data, x.data, data_length); memcpy(data, x.data, data_length);
} }
...@@ -91,14 +94,13 @@ int GsdmlDataRecord::print(std::ofstream& fp, bool reverse_endianess) ...@@ -91,14 +94,13 @@ int GsdmlDataRecord::print(std::ofstream& fp, bool reverse_endianess)
char str[1024]; char str[1024];
unsigned char* data; unsigned char* data;
// If we have allocated memory for reversed endianess we come from the pn configurator otherwise we use the data as is. // If we have allocated memory for reversed endianess we come from the pn
// The method SetIoDeviceData for instance reads the raw data and then recreates the pn configuration file. // configurator otherwise we use the data as is. The method SetIoDeviceData
if (data_reversed_endianess) // for instance reads the raw data and then recreates the pn configuration
{ // file.
if (data_reversed_endianess) {
data = (reverse_endianess ? this->data_reversed_endianess : this->data); data = (reverse_endianess ? this->data_reversed_endianess : this->data);
} } else {
else
{
data = this->data; data = this->data;
} }
...@@ -121,8 +123,7 @@ int GsdmlSubslotData::print(std::ofstream& fp, bool reverse_endianess) ...@@ -121,8 +123,7 @@ int GsdmlSubslotData::print(std::ofstream& fp, bool reverse_endianess)
<< " IOInputLength=\"" << io_input_length << "\"\n" << " IOInputLength=\"" << io_input_length << "\"\n"
<< " IOOutputLength=\"" << io_output_length << "\" >\n"; << " IOOutputLength=\"" << io_output_length << "\" >\n";
for (unsigned int i = 0; i < data_record.size(); i++) for (unsigned int i = 0; i < data_record.size(); i++) {
{
data_record[i]->print(fp, reverse_endianess); data_record[i]->print(fp, reverse_endianess);
} }
...@@ -139,8 +140,7 @@ int GsdmlSlotData::print(std::ofstream& fp, bool reverse_endianess) ...@@ -139,8 +140,7 @@ int GsdmlSlotData::print(std::ofstream& fp, bool reverse_endianess)
<< " SlotNumber=\"" << slot_number << "\"\n" << " SlotNumber=\"" << slot_number << "\"\n"
<< " DapFixedInSlot=\"" << dap_fixed_slot << "\" >\n"; << " DapFixedInSlot=\"" << dap_fixed_slot << "\" >\n";
for (unsigned int i = 0; i < subslot_data.size(); i++) for (unsigned int i = 0; i < subslot_data.size(); i++) {
{
subslot_data[i]->print(fp, reverse_endianess); subslot_data[i]->print(fp, reverse_endianess);
} }
...@@ -193,36 +193,27 @@ int GsdmlDeviceData::print(const char* filename) ...@@ -193,36 +193,27 @@ int GsdmlDeviceData::print(const char* filename)
// Save in accordance to the chosen endianess // Save in accordance to the chosen endianess
#if (pwr_dHost_byteOrder == pwr_dLittleEndian) #if (pwr_dHost_byteOrder == pwr_dLittleEndian)
if (byte_order == pwr_eByteOrderingEnum_LittleEndian) if (byte_order == pwr_eByteOrderingEnum_LittleEndian) {
{
reverse_endianess = false; reverse_endianess = false;
} } else {
else
{
// We use the data saved as the reversed endianess // We use the data saved as the reversed endianess
reverse_endianess = true; reverse_endianess = true;
} }
#elif (pwr_dHost_byteOrder == pwr_dBigEndian) #elif (pwr_dHost_byteOrder == pwr_dBigEndian)
if (byte_order == pwr_eByteOrderingEnum_LittleEndian) if (byte_order == pwr_eByteOrderingEnum_LittleEndian) {
{
reverse_endianess = true; reverse_endianess = true;
} } else {
else
{
reverse_endianess = false; reverse_endianess = false;
} }
#endif #endif
for (unsigned int i = 0; i < slot_data.size(); i++) for (unsigned int i = 0; i < slot_data.size(); i++) {
{
slot_data[i]->print(fp, reverse_endianess); slot_data[i]->print(fp, reverse_endianess);
} }
for (unsigned int i = 0; i < iocr_data.size(); i++) for (unsigned int i = 0; i < iocr_data.size(); i++) {
{
iocr_data[i]->print(fp); iocr_data[i]->print(fp);
} }
for (unsigned int i = 0; i < channel_diag.size(); i++) for (unsigned int i = 0; i < channel_diag.size(); i++) {
{
channel_diag[i]->print(fp); channel_diag[i]->print(fp);
} }
...@@ -271,8 +262,7 @@ int GsdmlDeviceData::cut_slot(unsigned int slot_idx) ...@@ -271,8 +262,7 @@ int GsdmlDeviceData::cut_slot(unsigned int slot_idx)
delete slot_data[slot_idx]; delete slot_data[slot_idx];
for (unsigned int i = slot_idx; i < slot_data.size() - 1; i++) for (unsigned int i = slot_idx; i < slot_data.size() - 1; i++) {
{
tmp_slot_idx = slot_data[i + 1]->slot_idx; tmp_slot_idx = slot_data[i + 1]->slot_idx;
tmp_slot_number = slot_data[i + 1]->slot_number; tmp_slot_number = slot_data[i + 1]->slot_number;
...@@ -304,8 +294,7 @@ int GsdmlDeviceData::paste_slot(unsigned int slot_idx) ...@@ -304,8 +294,7 @@ int GsdmlDeviceData::paste_slot(unsigned int slot_idx)
delete slot_data[slot_data.size() - 1]; delete slot_data[slot_data.size() - 1];
for (unsigned int i = slot_data.size() - 1; i > slot_idx; i--) for (unsigned int i = slot_data.size() - 1; i > slot_idx; i--) {
{
tmp_slot_idx = slot_data[i - 1]->slot_idx; tmp_slot_idx = slot_data[i - 1]->slot_idx;
tmp_slot_number = slot_data[i - 1]->slot_number; tmp_slot_number = slot_data[i - 1]->slot_number;
...@@ -329,11 +318,9 @@ int GsdmlDeviceData::modify_value(const char* attr, const char* value) ...@@ -329,11 +318,9 @@ int GsdmlDeviceData::modify_value(const char* attr, const char* value)
int ival, num2; int ival, num2;
num = dcli_parse(attr, "-", "", (char*)attrvect, num = dcli_parse(attr, "-", "", (char*)attrvect,
sizeof(attrvect) / sizeof(attrvect[0]), sizeof(attrvect[0]), sizeof(attrvect) / sizeof(attrvect[0]), sizeof(attrvect[0]), 0);
0);
if (streq(attrvect[0], "NetworkSettings")) if (streq(attrvect[0], "NetworkSettings")) {
{
if (num < 2) if (num < 2)
return 0; return 0;
if (streq(attrvect[1], "DeviceName")) if (streq(attrvect[1], "DeviceName"))
...@@ -344,42 +331,33 @@ int GsdmlDeviceData::modify_value(const char* attr, const char* value) ...@@ -344,42 +331,33 @@ int GsdmlDeviceData::modify_value(const char* attr, const char* value)
strncpy(subnet_mask, value, sizeof(subnet_mask)); strncpy(subnet_mask, value, sizeof(subnet_mask));
else if (streq(attrvect[1], "MAC Address")) else if (streq(attrvect[1], "MAC Address"))
strncpy(mac_address, value, sizeof(mac_address)); strncpy(mac_address, value, sizeof(mac_address));
else if (streq(attrvect[1], "SendClock")) else if (streq(attrvect[1], "SendClock")) {
{
num2 = sscanf(value, "%d", &ival); num2 = sscanf(value, "%d", &ival);
if (num2 != 1) if (num2 != 1)
return 0; return 0;
for (unsigned int i = 0; i < iocr_data.size(); i++) for (unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->send_clock_factor = ival; iocr_data[i]->send_clock_factor = ival;
} } else if (streq(attrvect[1], "ReductionRatio")) {
else if (streq(attrvect[1], "ReductionRatio"))
{
num2 = sscanf(value, "%d", &ival); num2 = sscanf(value, "%d", &ival);
if (num2 != 1) if (num2 != 1)
return 0; return 0;
for (unsigned int i = 0; i < iocr_data.size(); i++) for (unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->reduction_ratio = ival; iocr_data[i]->reduction_ratio = ival;
} } else if (streq(attrvect[1], "Phase")) {
else if (streq(attrvect[1], "Phase"))
{
num2 = sscanf(value, "%d", &ival); num2 = sscanf(value, "%d", &ival);
if (num2 != 1) if (num2 != 1)
return 0; return 0;
for (unsigned int i = 0; i < iocr_data.size(); i++) for (unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->phase = ival; iocr_data[i]->phase = ival;
} } else if (streq(attrvect[1], "API")) {
else if (streq(attrvect[1], "API"))
{
num2 = sscanf(value, "%d", &ival); num2 = sscanf(value, "%d", &ival);
if (num2 != 1) if (num2 != 1)
return 0; return 0;
for (unsigned int i = 0; i < iocr_data.size(); i++) for (unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->api = ival; iocr_data[i]->api = ival;
} } else
else
return 0; return 0;
} } else
else
return 0; return 0;
return 1; return 1;
} }
...@@ -390,11 +368,9 @@ int GsdmlDeviceData::get_value(const char* attr, char* buf, int bufsize) ...@@ -390,11 +368,9 @@ int GsdmlDeviceData::get_value(const char* attr, char* buf, int bufsize)
int num; int num;
num = dcli_parse(attr, "-", "", (char*)attrvect, num = dcli_parse(attr, "-", "", (char*)attrvect,
sizeof(attrvect) / sizeof(attrvect[0]), sizeof(attrvect[0]), sizeof(attrvect) / sizeof(attrvect[0]), sizeof(attrvect[0]), 0);
0);
if (streq(attrvect[0], "NetworkSettings")) if (streq(attrvect[0], "NetworkSettings")) {
{
if (num < 2) if (num < 2)
return 0; return 0;
if (streq(attrvect[1], "DeviceName")) if (streq(attrvect[1], "DeviceName"))
...@@ -415,8 +391,7 @@ int GsdmlDeviceData::get_value(const char* attr, char* buf, int bufsize) ...@@ -415,8 +391,7 @@ int GsdmlDeviceData::get_value(const char* attr, char* buf, int bufsize)
snprintf(buf, bufsize, "%d", iocr_data[0]->api); snprintf(buf, bufsize, "%d", iocr_data[0]->api);
else else
return 0; return 0;
} } else
else
return 0; return 0;
return 1; return 1;
} }
...@@ -447,27 +422,22 @@ int GsdmlDataReader::tag(const char* name) ...@@ -447,27 +422,22 @@ int GsdmlDataReader::tag(const char* name)
{ {
if (tag_name_to_id(name, &current_tag)) if (tag_name_to_id(name, &current_tag))
tag_stack_push(current_tag); tag_stack_push(current_tag);
else else {
{
printf("XML-Parser: Unknown tag: %s\n", name); printf("XML-Parser: Unknown tag: %s\n", name);
return 0; return 0;
} }
switch (current_tag) switch (current_tag) {
{ case gsdmldata_eTag_Slot: {
case gsdmldata_eTag_Slot:
{
GsdmlSlotData* sd = new GsdmlSlotData(); GsdmlSlotData* sd = new GsdmlSlotData();
data->slot_data.push_back(sd); data->slot_data.push_back(sd);
object_stack_push(sd, current_tag); object_stack_push(sd, current_tag);
break; break;
} }
case gsdmldata_eTag_Subslot: case gsdmldata_eTag_Subslot: {
{
GsdmlSlotData* sd = (GsdmlSlotData*)get_object_stack(gsdmldata_eTag_Slot); GsdmlSlotData* sd = (GsdmlSlotData*)get_object_stack(gsdmldata_eTag_Slot);
if (!sd) if (!sd) {
{
printf("XML-Parser: Subslot outside slot"); printf("XML-Parser: Subslot outside slot");
break; break;
} }
...@@ -478,12 +448,10 @@ int GsdmlDataReader::tag(const char* name) ...@@ -478,12 +448,10 @@ int GsdmlDataReader::tag(const char* name)
object_stack_push(ssd, current_tag); object_stack_push(ssd, current_tag);
break; break;
} }
case gsdmldata_eTag_DataRecord: case gsdmldata_eTag_DataRecord: {
{ GsdmlSubslotData* ssd
GsdmlSubslotData* ssd = = (GsdmlSubslotData*)get_object_stack(gsdmldata_eTag_Subslot);
(GsdmlSubslotData*)get_object_stack(gsdmldata_eTag_Subslot); if (!ssd) {
if (!ssd)
{
printf("XML-Parser: RecordData outside subslot"); printf("XML-Parser: RecordData outside subslot");
break; break;
} }
...@@ -494,16 +462,14 @@ int GsdmlDataReader::tag(const char* name) ...@@ -494,16 +462,14 @@ int GsdmlDataReader::tag(const char* name)
object_stack_push(dr, current_tag); object_stack_push(dr, current_tag);
break; break;
} }
case gsdmldata_eTag_IOCR: case gsdmldata_eTag_IOCR: {
{
GsdmlIOCRData* iod = new GsdmlIOCRData(); GsdmlIOCRData* iod = new GsdmlIOCRData();
data->iocr_data.push_back(iod); data->iocr_data.push_back(iod);
object_stack_push(iod, current_tag); object_stack_push(iod, current_tag);
break; break;
} }
case gsdmldata_eTag_ChannelDiag: case gsdmldata_eTag_ChannelDiag: {
{
GsdmlChannelDiag* cd = new GsdmlChannelDiag(); GsdmlChannelDiag* cd = new GsdmlChannelDiag();
data->channel_diag.push_back(cd); data->channel_diag.push_back(cd);
...@@ -515,21 +481,22 @@ int GsdmlDataReader::tag(const char* name) ...@@ -515,21 +481,22 @@ int GsdmlDataReader::tag(const char* name)
return 1; return 1;
} }
int GsdmlDataReader::metatag(const char* name) { return 1; } int GsdmlDataReader::metatag(const char* name)
{
return 1;
}
int GsdmlDataReader::tag_end(const char* name) int GsdmlDataReader::tag_end(const char* name)
{ {
unsigned int id; unsigned int id;
if (tag_name_to_id(name, &id)) if (tag_name_to_id(name, &id))
tag_stack_pull(id); tag_stack_pull(id);
else else {
{
printf("XML-Parser: Tag/EndTag mismach: %s\n", name); printf("XML-Parser: Tag/EndTag mismach: %s\n", name);
return 0; return 0;
} }
switch (id) switch (id) {
{
case gsdmldata_eTag_Slot: case gsdmldata_eTag_Slot:
object_stack_pull(id); object_stack_pull(id);
break; break;
...@@ -546,17 +513,20 @@ int GsdmlDataReader::tag_end(const char* name) ...@@ -546,17 +513,20 @@ int GsdmlDataReader::tag_end(const char* name)
} }
return 1; return 1;
} }
int GsdmlDataReader::metatag_end(const char* name) { return 1; } int GsdmlDataReader::metatag_end(const char* name)
int GsdmlDataReader::tag_value(const char* name) { return 1; } {
return 1;
}
int GsdmlDataReader::tag_value(const char* name)
{
return 1;
}
int GsdmlDataReader::tag_attribute(const char* name, const char* value) int GsdmlDataReader::tag_attribute(const char* name, const char* value)
{ {
switch (current_tag) switch (current_tag) {
{
case gsdmldata_eTag_PnDevice: case gsdmldata_eTag_PnDevice:
if (streq(name, "GsdmlFile")) if (streq(name, "GsdmlFile")) {
{ if (!streq(data->gsdmlfile, "")) {
if (!streq(data->gsdmlfile, ""))
{
// Check that the GSDML file is not changed // Check that the GSDML file is not changed
char* gsdmlfile_p; char* gsdmlfile_p;
...@@ -568,11 +538,9 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value) ...@@ -568,11 +538,9 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value)
if (!streq(value, gsdmlfile_p) && !new_filename) if (!streq(value, gsdmlfile_p) && !new_filename)
return PB__GSDMLFILEMISMATCH; return PB__GSDMLFILEMISMATCH;
} } else
else
strncpy(data->gsdmlfile, value, sizeof(data->gsdmlfile)); strncpy(data->gsdmlfile, value, sizeof(data->gsdmlfile));
} } else if (streq(name, "DeviceText"))
else if (streq(name, "DeviceText"))
strncpy(data->device_text, value, sizeof(data->device_text)); strncpy(data->device_text, value, sizeof(data->device_text));
else if (streq(name, "DeviceNumber")) else if (streq(name, "DeviceNumber"))
sscanf(value, "%d", &data->device_num); sscanf(value, "%d", &data->device_num);
...@@ -597,8 +565,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value) ...@@ -597,8 +565,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value)
else if (streq(name, "MAC_Address")) else if (streq(name, "MAC_Address"))
strncpy(data->mac_address, value, sizeof(data->mac_address)); strncpy(data->mac_address, value, sizeof(data->mac_address));
break; break;
case gsdmldata_eTag_Slot: case gsdmldata_eTag_Slot: {
{
GsdmlSlotData* sd = (GsdmlSlotData*)get_object_stack(current_tag); GsdmlSlotData* sd = (GsdmlSlotData*)get_object_stack(current_tag);
if (streq(name, "ModuleEnumNumber")) if (streq(name, "ModuleEnumNumber"))
...@@ -615,8 +582,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value) ...@@ -615,8 +582,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value)
sscanf(value, "%u", &sd->dap_fixed_slot); sscanf(value, "%u", &sd->dap_fixed_slot);
break; break;
} }
case gsdmldata_eTag_Subslot: case gsdmldata_eTag_Subslot: {
{
GsdmlSubslotData* sd = (GsdmlSubslotData*)get_object_stack(current_tag); GsdmlSubslotData* sd = (GsdmlSubslotData*)get_object_stack(current_tag);
if (streq(name, "SubslotNumber")) if (streq(name, "SubslotNumber"))
...@@ -633,8 +599,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value) ...@@ -633,8 +599,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value)
sscanf(value, "%u", &sd->io_output_length); sscanf(value, "%u", &sd->io_output_length);
break; break;
} }
case gsdmldata_eTag_DataRecord: case gsdmldata_eTag_DataRecord: {
{
GsdmlDataRecord* dr = (GsdmlDataRecord*)get_object_stack(current_tag); GsdmlDataRecord* dr = (GsdmlDataRecord*)get_object_stack(current_tag);
if (streq(name, "DataLength")) if (streq(name, "DataLength"))
...@@ -643,15 +608,13 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value) ...@@ -643,15 +608,13 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value)
sscanf(value, "%hu", &dr->index); sscanf(value, "%hu", &dr->index);
else if (streq(name, "TransferSequence")) else if (streq(name, "TransferSequence"))
sscanf(value, "%hu", &dr->transfer_sequence); sscanf(value, "%hu", &dr->transfer_sequence);
else if (streq(name, "Data")) else if (streq(name, "Data")) {
{
int len; int len;
co_xml_parser::ostring_to_data(&dr->data, value, dr->data_length, &len); co_xml_parser::ostring_to_data(&dr->data, value, dr->data_length, &len);
} }
break; break;
} }
case gsdmldata_eTag_IOCR: case gsdmldata_eTag_IOCR: {
{
GsdmlIOCRData* iod = (GsdmlIOCRData*)get_object_stack(current_tag); GsdmlIOCRData* iod = (GsdmlIOCRData*)get_object_stack(current_tag);
if (streq(name, "Type")) if (streq(name, "Type"))
...@@ -668,8 +631,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value) ...@@ -668,8 +631,7 @@ int GsdmlDataReader::tag_attribute(const char* name, const char* value)
sscanf(value, "%u", &iod->api); sscanf(value, "%u", &iod->api);
break; break;
} }
case gsdmldata_eTag_ChannelDiag: case gsdmldata_eTag_ChannelDiag: {
{
GsdmlChannelDiag* cd = (GsdmlChannelDiag*)get_object_stack(current_tag); GsdmlChannelDiag* cd = (GsdmlChannelDiag*)get_object_stack(current_tag);
if (streq(name, "ErrorType")) if (streq(name, "ErrorType"))
......
...@@ -175,7 +175,8 @@ public: ...@@ -175,7 +175,8 @@ public:
GsdmlChannelDiag(); GsdmlChannelDiag();
unsigned short error_type; unsigned short error_type;
char name[200]; char name[200];
char help[4096]; // We need a large buffer for most of the help text in the diagnostics... char help[4096]; // We need a large buffer for most of the help text in the
// diagnostics...
int print(std::ofstream& fp); int print(std::ofstream& fp);
}; };
...@@ -213,7 +214,8 @@ public: ...@@ -213,7 +214,8 @@ public:
static GsdmlSlotData* paste_slotdata; static GsdmlSlotData* paste_slotdata;
std::vector<GsdmlChannelDiag*> channel_diag; std::vector<GsdmlChannelDiag*> channel_diag;
~GsdmlDeviceData() { ~GsdmlDeviceData()
{
device_reset(); device_reset();
channel_diag_reset(); channel_diag_reset();
} }
......
...@@ -23,66 +23,71 @@ Version: 2.22.00 ...@@ -23,66 +23,71 @@ Version: 2.22.00
/*****************************************************************************/ /*****************************************************************************/
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
#pragma warning (disable : 4103) /* used #pragma pack to change alignment */ #pragma warning(disable : 4103) /* used #pragma pack to change alignment */
#pragma pack (push, 2) #pragma pack(push, 2)
#pragma warning (default : 4103) #pragma warning(default : 4103)
#ifndef PACK_WORD_ALIGNMENT #ifndef PACK_WORD_ALIGNMENT
#define PACK_WORD_ALIGNMENT(Struct) Struct #define PACK_WORD_ALIGNMENT(Struct) Struct
#endif #endif
#ifndef PACK_BYTE_ALIGNMENT #ifndef PACK_BYTE_ALIGNMENT
#define PACK_BYTE_ALIGNMENT(Struct) Struct #define PACK_BYTE_ALIGNMENT(Struct) Struct
#endif #endif
#elif defined __GNUC__ #elif defined __GNUC__
#ifndef PACK_WORD_ALIGNMENT #ifndef PACK_WORD_ALIGNMENT
#define PACK_WORD_ALIGNMENT(Struct) __attribute__ ((packed, aligned (2))) Struct #define PACK_WORD_ALIGNMENT(Struct) __attribute__((packed, aligned(2))) Struct
#endif #endif
#ifndef PACK_BYTE_ALIGNMENT #ifndef PACK_BYTE_ALIGNMENT
#define PACK_BYTE_ALIGNMENT(Struct) __attribute__ ((packed, aligned (1))) Struct #define PACK_BYTE_ALIGNMENT(Struct) __attribute__((packed, aligned(1))) Struct
#endif #endif
#elif defined _OS9000 #elif defined _OS9000
#ifndef PACK_WORD_ALIGNMENT #ifndef PACK_WORD_ALIGNMENT
#define PACK_WORD_ALIGNMENT(Struct) Struct #define PACK_WORD_ALIGNMENT(Struct) Struct
#endif #endif
#ifndef PACK_BYTE_ALIGNMENT #ifndef PACK_BYTE_ALIGNMENT
#define PACK_BYTE_ALIGNMENT(Struct) Struct #define PACK_BYTE_ALIGNMENT(Struct) Struct
#endif #endif
#else #else
#error CAUTION: set word structure alignment #error CAUTION: set word structure alignment
#endif #endif
/****************************************************************************** /******************************************************************************
ACCESS KIT USER INTERFACE ACCESS KIT USER INTERFACE
******************************************************************************/ ******************************************************************************/
#define _BITSET256_RESET_BIT(pBS,BitNr) (((pBS)) [(BitNr) >> 3] &= ~(1u << ((BitNr) & 7u))) #define _BITSET256_RESET_BIT(pBS, BitNr) \
#define _BITSET256_SET_BIT(pBS,BitNr) (((pBS)) [(BitNr) >> 3] |= 1u << ((BitNr) & 7u) ) (((pBS))[(BitNr) >> 3] &= ~(1u << ((BitNr)&7u)))
#define _BITSET256_IS_BIT_SET(pBS,BitNr) ((((pBS)) [(BitNr) >> 3]) & (1u << ((BitNr) & 7u) )) #define _BITSET256_SET_BIT(pBS, BitNr) \
(((pBS))[(BitNr) >> 3] |= 1u << ((BitNr)&7u))
#define _BITSET256_IS_BIT_SET(pBS, BitNr) \
((((pBS))[(BitNr) >> 3]) & (1u << ((BitNr)&7u)))
#define _BITSET64_RESET_BIT(pBS,BitNr) (((pBS)) [(BitNr) >> 3] &= ~(1u << ((BitNr) & 7u))) #define _BITSET64_RESET_BIT(pBS, BitNr) \
#define _BITSET64_SET_BIT(pBS,BitNr) (((pBS)) [(BitNr) >> 3] |= 1u << ((BitNr) & 7u) ) (((pBS))[(BitNr) >> 3] &= ~(1u << ((BitNr)&7u)))
#define _BITSET64_IS_BIT_SET(pBS,BitNr) ((((pBS)) [(BitNr) >> 3]) & (1u << ((BitNr) & 7u) )) #define _BITSET64_SET_BIT(pBS, BitNr) \
(((pBS))[(BitNr) >> 3] |= 1u << ((BitNr)&7u))
#define _BITSET64_IS_BIT_SET(pBS, BitNr) \
((((pBS))[(BitNr) >> 3]) & (1u << ((BitNr)&7u)))
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifndef _MAX #ifndef _MAX
#define _MAX(A,B) ((A) > (B) ? (A) : (B)) #define _MAX(A, B) ((A) > (B) ? (A) : (B))
#endif #endif
#ifndef _MIN #ifndef _MIN
#define _MIN(A,B) ((A) < (B) ? (A) : (B)) #define _MIN(A, B) ((A) < (B) ? (A) : (B))
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef enum _T_PNAK_RESULT typedef enum _T_PNAK_RESULT {
{ PNAK_OK = 0,
PNAK_OK = 0,
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -154,142 +159,139 @@ typedef enum _T_PNAK_RESULT ...@@ -154,142 +159,139 @@ typedef enum _T_PNAK_RESULT
/*--- errors loading library -------------------------------------------*/ /*--- errors loading library -------------------------------------------*/
PNAK_ERR_LIBRARY_NOT_LOADED, PNAK_ERR_LIBRARY_NOT_LOADED,
} T_PNAK_RESULT; } T_PNAK_RESULT;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef unsigned char T_BITSET_256 [32]; typedef unsigned char T_BITSET_256[32];
typedef unsigned char T_BITSET_64 [8]; typedef unsigned char T_BITSET_64[8];
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef unsigned short T_PNAK_EXCEPTION_SOURCE; typedef unsigned short T_PNAK_EXCEPTION_SOURCE;
#define PNAK_EXCEPTION_SOURCE_IS_STACK 0u #define PNAK_EXCEPTION_SOURCE_IS_STACK 0u
#define PNAK_EXCEPTION_SOURCE_IS_PNAK 1u #define PNAK_EXCEPTION_SOURCE_IS_PNAK 1u
#define PNAK_EXCEPTION_SOURCE_IS_APPL 2u #define PNAK_EXCEPTION_SOURCE_IS_APPL 2u
typedef struct _T_PNAK_EXCEPTION typedef struct _T_PNAK_EXCEPTION
{ {
T_PNAK_EXCEPTION_SOURCE Source; T_PNAK_EXCEPTION_SOURCE Source;
unsigned short ChannelId; unsigned short ChannelId;
unsigned short ModuleId; unsigned short ModuleId;
unsigned short FileId; unsigned short FileId;
unsigned short ErrorId; unsigned short ErrorId;
PN_U32 UserSpecificParameter; PN_U32 UserSpecificParameter;
char UserString [22]; char UserString[22];
} PACK_WORD_ALIGNMENT (T_PNAK_EXCEPTION); } PACK_WORD_ALIGNMENT(T_PNAK_EXCEPTION);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef unsigned long T_PNAK_OID; typedef unsigned long T_PNAK_OID;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef unsigned short T_PNAK_MODE_ID; typedef unsigned short T_PNAK_MODE_ID;
#define PNAK_UNINITIALIZED_MODE 0 #define PNAK_UNINITIALIZED_MODE 0
#define PNAK_CONTROLLER_MODE 1 #define PNAK_CONTROLLER_MODE 1
#define PNAK_DEVICE_MODE 2 #define PNAK_DEVICE_MODE 2
#define PNAK_SUPERVISOR_MODE 3 #define PNAK_SUPERVISOR_MODE 3
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_VERSION_STRING_LENGTH 42 #define PNAK_VERSION_STRING_LENGTH 42
typedef struct _T_PNAK_VERSION typedef struct _T_PNAK_VERSION
{ {
unsigned short IfId; unsigned short IfId;
unsigned short HostIfId; unsigned short HostIfId;
unsigned short HostConfigIfId; unsigned short HostConfigIfId;
unsigned short ExceptionIfId; unsigned short ExceptionIfId;
unsigned short ServiceIfId; unsigned short ServiceIfId;
unsigned short EventIfId; unsigned short EventIfId;
unsigned short StatisticIfId; unsigned short StatisticIfId;
unsigned short DataIfId; unsigned short DataIfId;
char VersionString [PNAK_VERSION_STRING_LENGTH]; char VersionString[PNAK_VERSION_STRING_LENGTH];
} PACK_WORD_ALIGNMENT (T_PNAK_VERSION); } PACK_WORD_ALIGNMENT(T_PNAK_VERSION);
typedef struct _T_PNAK_VERSIONS typedef struct _T_PNAK_VERSIONS
{ {
T_PNAK_VERSION Firmware; T_PNAK_VERSION Firmware;
T_PNAK_VERSION Pnak; T_PNAK_VERSION Pnak;
} PACK_WORD_ALIGNMENT (T_PNAK_VERSIONS); } PACK_WORD_ALIGNMENT(T_PNAK_VERSIONS);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_INFINITE_TIMEOUT 0xFFFFFFFFuL #define PNAK_INFINITE_TIMEOUT 0xFFFFFFFFuL
#define PNAK_MAX_NUMBER_WAIT_OBJECTS 32uL #define PNAK_MAX_NUMBER_WAIT_OBJECTS 32uL
typedef PN_U32 T_PNAK_TIMEOUT; typedef PN_U32 T_PNAK_TIMEOUT;
typedef PN_U32 T_PNAK_WAIT_OBJECT; typedef PN_U32 T_PNAK_WAIT_OBJECT;
#define PNAK_WAIT_OBJECT_EXCEPTION ((T_PNAK_WAIT_OBJECT) 0x00000001uL) #define PNAK_WAIT_OBJECT_EXCEPTION ((T_PNAK_WAIT_OBJECT)0x00000001uL)
#define PNAK_WAIT_OBJECT_STATE_CHANGED ((T_PNAK_WAIT_OBJECT) 0x00000002uL) #define PNAK_WAIT_OBJECT_STATE_CHANGED ((T_PNAK_WAIT_OBJECT)0x00000002uL)
#define PNAK_WAIT_OBJECT_ALARM ((T_PNAK_WAIT_OBJECT) 0x00000004uL) #define PNAK_WAIT_OBJECT_ALARM ((T_PNAK_WAIT_OBJECT)0x00000004uL)
#define PNAK_WAIT_OBJECT_ALARM_ACK ((T_PNAK_WAIT_OBJECT) 0x00000008uL) #define PNAK_WAIT_OBJECT_ALARM_ACK ((T_PNAK_WAIT_OBJECT)0x00000008uL)
#define PNAK_WAIT_OBJECT_DEVICE_STATE_CHANGED ((T_PNAK_WAIT_OBJECT) 0x00000010uL) #define PNAK_WAIT_OBJECT_DEVICE_STATE_CHANGED ((T_PNAK_WAIT_OBJECT)0x00000010uL)
#define PNAK_WAIT_OBJECT_ETHERNET_STATE_CHANGED ((T_PNAK_WAIT_OBJECT) 0x00000020uL) #define PNAK_WAIT_OBJECT_ETHERNET_STATE_CHANGED \
#define PNAK_WAIT_OBJECT_PROVIDER_DATA_UPDATED ((T_PNAK_WAIT_OBJECT) 0x00000040uL) ((T_PNAK_WAIT_OBJECT)0x00000020uL)
#define PNAK_WAIT_OBJECT_CONSUMER_DATA_CHANGED ((T_PNAK_WAIT_OBJECT) 0x00000080uL) #define PNAK_WAIT_OBJECT_PROVIDER_DATA_UPDATED \
#define PNAK_WAIT_OBJECT_SERVICE_IND ((T_PNAK_WAIT_OBJECT) 0x00000100uL) ((T_PNAK_WAIT_OBJECT)0x00000040uL)
#define PNAK_WAIT_OBJECT_SERVICE_CON ((T_PNAK_WAIT_OBJECT) 0x00000200uL) #define PNAK_WAIT_OBJECT_CONSUMER_DATA_CHANGED \
#define PNAK_WAIT_OBJECT_SERVICE_REQ_RES_HANDLED ((T_PNAK_WAIT_OBJECT) 0x00000400uL) ((T_PNAK_WAIT_OBJECT)0x00000080uL)
#define PNAK_WAIT_OBJECT_PTCP ((T_PNAK_WAIT_OBJECT) 0x00000800uL) #define PNAK_WAIT_OBJECT_SERVICE_IND ((T_PNAK_WAIT_OBJECT)0x00000100uL)
#define PNAK_WAIT_OBJECT_SOCKET_STATE_CHANGED ((T_PNAK_WAIT_OBJECT) 0x00001000uL) #define PNAK_WAIT_OBJECT_SERVICE_CON ((T_PNAK_WAIT_OBJECT)0x00000200uL)
#define PNAK_WAIT_OBJECT_SOCKET_DATA_RECEIVED ((T_PNAK_WAIT_OBJECT) 0x00002000uL) #define PNAK_WAIT_OBJECT_SERVICE_REQ_RES_HANDLED \
#define PNAK_WAIT_OBJECT_MRPD ((T_PNAK_WAIT_OBJECT) 0x00004000uL) ((T_PNAK_WAIT_OBJECT)0x00000400uL)
#define PNAK_WAIT_OBJECT_CHANNEL_CLOSED ((T_PNAK_WAIT_OBJECT) 0x00200000uL) #define PNAK_WAIT_OBJECT_PTCP ((T_PNAK_WAIT_OBJECT)0x00000800uL)
#define PNAK_WAIT_OBJECT_INTERRUPTED ((T_PNAK_WAIT_OBJECT) 0x00400000uL) #define PNAK_WAIT_OBJECT_SOCKET_STATE_CHANGED ((T_PNAK_WAIT_OBJECT)0x00001000uL)
#define PNAK_USER_WAIT_OBJECT_1 ((T_PNAK_WAIT_OBJECT) 0x00800000uL) #define PNAK_WAIT_OBJECT_SOCKET_DATA_RECEIVED ((T_PNAK_WAIT_OBJECT)0x00002000uL)
#define PNAK_USER_WAIT_OBJECT_2 ((T_PNAK_WAIT_OBJECT) 0x01000000uL) #define PNAK_WAIT_OBJECT_MRPD ((T_PNAK_WAIT_OBJECT)0x00004000uL)
#define PNAK_USER_WAIT_OBJECT_3 ((T_PNAK_WAIT_OBJECT) 0x02000000uL) #define PNAK_WAIT_OBJECT_CHANNEL_CLOSED ((T_PNAK_WAIT_OBJECT)0x00200000uL)
#define PNAK_USER_WAIT_OBJECT_4 ((T_PNAK_WAIT_OBJECT) 0x04000000uL) #define PNAK_WAIT_OBJECT_INTERRUPTED ((T_PNAK_WAIT_OBJECT)0x00400000uL)
#define PNAK_USER_WAIT_OBJECT_5 ((T_PNAK_WAIT_OBJECT) 0x08000000uL) #define PNAK_USER_WAIT_OBJECT_1 ((T_PNAK_WAIT_OBJECT)0x00800000uL)
#define PNAK_USER_WAIT_OBJECT_6 ((T_PNAK_WAIT_OBJECT) 0x10000000uL) #define PNAK_USER_WAIT_OBJECT_2 ((T_PNAK_WAIT_OBJECT)0x01000000uL)
#define PNAK_USER_WAIT_OBJECT_7 ((T_PNAK_WAIT_OBJECT) 0x20000000uL) #define PNAK_USER_WAIT_OBJECT_3 ((T_PNAK_WAIT_OBJECT)0x02000000uL)
#define PNAK_USER_WAIT_OBJECT_8 ((T_PNAK_WAIT_OBJECT) 0x40000000uL) #define PNAK_USER_WAIT_OBJECT_4 ((T_PNAK_WAIT_OBJECT)0x04000000uL)
#define PNAK_WAIT_TIMEOUT ((T_PNAK_WAIT_OBJECT) 0x80000000uL) #define PNAK_USER_WAIT_OBJECT_5 ((T_PNAK_WAIT_OBJECT)0x08000000uL)
#define PNAK_USER_WAIT_OBJECT_6 ((T_PNAK_WAIT_OBJECT)0x10000000uL)
#define PNAK_WAIT_OBJECTS_SERVICE (PNAK_WAIT_OBJECT_SERVICE_CON | \ #define PNAK_USER_WAIT_OBJECT_7 ((T_PNAK_WAIT_OBJECT)0x20000000uL)
PNAK_WAIT_OBJECT_SERVICE_IND | \ #define PNAK_USER_WAIT_OBJECT_8 ((T_PNAK_WAIT_OBJECT)0x40000000uL)
PNAK_WAIT_OBJECT_SERVICE_REQ_RES_HANDLED) #define PNAK_WAIT_TIMEOUT ((T_PNAK_WAIT_OBJECT)0x80000000uL)
#define PNAK_WAIT_OBJECTS_EVENT_IND (PNAK_WAIT_OBJECT_STATE_CHANGED | \
PNAK_WAIT_OBJECT_ALARM | \ #define PNAK_WAIT_OBJECTS_SERVICE \
PNAK_WAIT_OBJECT_ALARM_ACK | \ (PNAK_WAIT_OBJECT_SERVICE_CON | PNAK_WAIT_OBJECT_SERVICE_IND | \
PNAK_WAIT_OBJECT_DEVICE_STATE_CHANGED | \ PNAK_WAIT_OBJECT_SERVICE_REQ_RES_HANDLED)
PNAK_WAIT_OBJECT_ETHERNET_STATE_CHANGED | \ #define PNAK_WAIT_OBJECTS_EVENT_IND \
PNAK_WAIT_OBJECT_PTCP | \ (PNAK_WAIT_OBJECT_STATE_CHANGED | PNAK_WAIT_OBJECT_ALARM | \
PNAK_WAIT_OBJECT_MRPD) PNAK_WAIT_OBJECT_ALARM_ACK | PNAK_WAIT_OBJECT_DEVICE_STATE_CHANGED | \
#define PNAK_WAIT_OBJECTS_DATA_IND (PNAK_WAIT_OBJECT_PROVIDER_DATA_UPDATED |\ PNAK_WAIT_OBJECT_ETHERNET_STATE_CHANGED | PNAK_WAIT_OBJECT_PTCP | \
PNAK_WAIT_OBJECT_CONSUMER_DATA_CHANGED) PNAK_WAIT_OBJECT_MRPD)
#define PNAK_WAIT_OBJECTS_SOCKET_IND (PNAK_WAIT_OBJECT_SOCKET_STATE_CHANGED | \ #define PNAK_WAIT_OBJECTS_DATA_IND \
PNAK_WAIT_OBJECT_SOCKET_DATA_RECEIVED) (PNAK_WAIT_OBJECT_PROVIDER_DATA_UPDATED | \
#define PNAK_WAIT_OBJECTS_OTHER (PNAK_WAIT_OBJECT_EXCEPTION | \ PNAK_WAIT_OBJECT_CONSUMER_DATA_CHANGED)
PNAK_WAIT_OBJECT_CHANNEL_CLOSED | \ #define PNAK_WAIT_OBJECTS_SOCKET_IND \
PNAK_WAIT_OBJECT_INTERRUPTED) (PNAK_WAIT_OBJECT_SOCKET_STATE_CHANGED | \
#define PNAK_WAIT_OBJECTS_USER (PNAK_USER_WAIT_OBJECT_1 | \ PNAK_WAIT_OBJECT_SOCKET_DATA_RECEIVED)
PNAK_USER_WAIT_OBJECT_2 | \ #define PNAK_WAIT_OBJECTS_OTHER \
PNAK_USER_WAIT_OBJECT_3 | \ (PNAK_WAIT_OBJECT_EXCEPTION | PNAK_WAIT_OBJECT_CHANNEL_CLOSED | \
PNAK_USER_WAIT_OBJECT_4 | \ PNAK_WAIT_OBJECT_INTERRUPTED)
PNAK_USER_WAIT_OBJECT_5 | \ #define PNAK_WAIT_OBJECTS_USER \
PNAK_USER_WAIT_OBJECT_6 | \ (PNAK_USER_WAIT_OBJECT_1 | PNAK_USER_WAIT_OBJECT_2 | \
PNAK_USER_WAIT_OBJECT_7 | \ PNAK_USER_WAIT_OBJECT_3 | PNAK_USER_WAIT_OBJECT_4 | \
PNAK_USER_WAIT_OBJECT_8) PNAK_USER_WAIT_OBJECT_5 | PNAK_USER_WAIT_OBJECT_6 | \
#define PNAK_WAIT_OBJECTS_ALL (PNAK_WAIT_OBJECTS_OTHER | \ PNAK_USER_WAIT_OBJECT_7 | PNAK_USER_WAIT_OBJECT_8)
PNAK_WAIT_OBJECTS_EVENT_IND | \ #define PNAK_WAIT_OBJECTS_ALL \
PNAK_WAIT_OBJECTS_DATA_IND | \ (PNAK_WAIT_OBJECTS_OTHER | PNAK_WAIT_OBJECTS_EVENT_IND | \
PNAK_WAIT_OBJECTS_SERVICE | \ PNAK_WAIT_OBJECTS_DATA_IND | PNAK_WAIT_OBJECTS_SERVICE | \
PNAK_WAIT_OBJECTS_SOCKET_IND | \ PNAK_WAIT_OBJECTS_SOCKET_IND | PNAK_WAIT_OBJECTS_USER | PNAK_WAIT_TIMEOUT)
PNAK_WAIT_OBJECTS_USER | \
PNAK_WAIT_TIMEOUT)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
...@@ -299,147 +301,145 @@ typedef PN_U32 T_PNAK_WAIT_OBJECT; ...@@ -299,147 +301,145 @@ typedef PN_U32 T_PNAK_WAIT_OBJECT;
* the max number and add specific statemachines in the * the max number and add specific statemachines in the
* object data structure * object data structure
*/ */
#define MAX_NUMBER_CMDEV_CONNECTIONS 4u #define MAX_NUMBER_CMDEV_CONNECTIONS 4u
/*============================================================================= /*=============================================================================
SERVICE INTERFACE SERVICE INTERFACE
=============================================================================*/ =============================================================================*/
typedef unsigned char T_PNAK_SERVICE_PRIMITIVE; typedef unsigned char T_PNAK_SERVICE_PRIMITIVE;
#define PNAK_SERVICE_REQ (T_PNAK_SERVICE_PRIMITIVE) 0x01u #define PNAK_SERVICE_REQ (T_PNAK_SERVICE_PRIMITIVE)0x01u
#define PNAK_SERVICE_RES (T_PNAK_SERVICE_PRIMITIVE) 0x02u #define PNAK_SERVICE_RES (T_PNAK_SERVICE_PRIMITIVE)0x02u
#define PNAK_SERVICE_CON (T_PNAK_SERVICE_PRIMITIVE) 0x03u #define PNAK_SERVICE_CON (T_PNAK_SERVICE_PRIMITIVE)0x03u
#define PNAK_SERVICE_IND (T_PNAK_SERVICE_PRIMITIVE) 0x04u #define PNAK_SERVICE_IND (T_PNAK_SERVICE_PRIMITIVE)0x04u
typedef unsigned char T_PNAK_SERVICE_RESULT; typedef unsigned char T_PNAK_SERVICE_RESULT;
#define PNAK_RESULT_POS (T_PNAK_SERVICE_RESULT) 0x00u #define PNAK_RESULT_POS (T_PNAK_SERVICE_RESULT)0x00u
#define PNAK_RESULT_NEG (T_PNAK_SERVICE_RESULT) 0x01u #define PNAK_RESULT_NEG (T_PNAK_SERVICE_RESULT)0x01u
typedef struct _T_PNAK_SERVICE_DESCRIPTION typedef struct _T_PNAK_SERVICE_DESCRIPTION
{ {
unsigned short DeviceRef; unsigned short DeviceRef;
unsigned char Instance; unsigned char Instance;
unsigned char Service; unsigned char Service;
T_PNAK_SERVICE_PRIMITIVE Primitive; T_PNAK_SERVICE_PRIMITIVE Primitive;
T_PNAK_SERVICE_RESULT Result; T_PNAK_SERVICE_RESULT Result;
unsigned short ClientId; unsigned short ClientId;
unsigned short InvokeId; unsigned short InvokeId;
unsigned short DataLength; unsigned short DataLength;
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_DESCRIPTION);
} PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_DESCRIPTION);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_MAX_NUMBER_REQ_SERVICES 52u #define PNAK_MAX_NUMBER_REQ_SERVICES 52u
#define PNAK_MAX_NUMBER_CON_SERVICES 52u #define PNAK_MAX_NUMBER_CON_SERVICES 52u
#define PNAK_MAX_NUMBER_IND_SERVICES 52u #define PNAK_MAX_NUMBER_IND_SERVICES 52u
#ifndef PNAK_SERVICE_REQ_CHANNEL_SIZE #ifndef PNAK_SERVICE_REQ_CHANNEL_SIZE
#define PNAK_SERVICE_REQ_CHANNEL_SIZE (PN_U16) 8086u #define PNAK_SERVICE_REQ_CHANNEL_SIZE (PN_U16)8086u
#endif #endif
#ifndef PNAK_SERVICE_CON_CHANNEL_SIZE #ifndef PNAK_SERVICE_CON_CHANNEL_SIZE
#define PNAK_SERVICE_CON_CHANNEL_SIZE (PN_U16) 8086u #define PNAK_SERVICE_CON_CHANNEL_SIZE (PN_U16)8086u
#endif #endif
#ifndef PNAK_SERVICE_IND_CHANNEL_SIZE #ifndef PNAK_SERVICE_IND_CHANNEL_SIZE
#define PNAK_SERVICE_IND_CHANNEL_SIZE (PN_U16) 8086u #define PNAK_SERVICE_IND_CHANNEL_SIZE (PN_U16)8086u
#endif #endif
/*=== SERVICE REQUEST/RESPONSE ==============================================*/ /*=== SERVICE REQUEST/RESPONSE ==============================================*/
typedef struct _T_PNAK_SERVICE_REQ_RES_ENTRY typedef struct _T_PNAK_SERVICE_REQ_RES_ENTRY
{ {
unsigned short ServiceOffset; unsigned short ServiceOffset;
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_REQ_RES_ENTRY); } PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_REQ_RES_ENTRY);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_SERVICE_REQ_RES typedef struct _T_PNAK_SERVICE_REQ_RES
{ {
unsigned short NumberEntries; unsigned short NumberEntries;
T_PNAK_SERVICE_REQ_RES_ENTRY ServiceEntry [PNAK_MAX_NUMBER_REQ_SERVICES]; T_PNAK_SERVICE_REQ_RES_ENTRY ServiceEntry[PNAK_MAX_NUMBER_REQ_SERVICES];
unsigned char ServiceChannel [PNAK_SERVICE_REQ_CHANNEL_SIZE]; unsigned char ServiceChannel[PNAK_SERVICE_REQ_CHANNEL_SIZE];
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_REQ_RES); } PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_REQ_RES);
/*=== SERVICE CONFIRMATION ==================================================*/ /*=== SERVICE CONFIRMATION ==================================================*/
typedef struct _T_PNAK_SERVICE_CON_ENTRY typedef struct _T_PNAK_SERVICE_CON_ENTRY
{ {
unsigned short ServiceOffset; unsigned short ServiceOffset;
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_CON_ENTRY); } PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_CON_ENTRY);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_SERVICE_CON typedef struct _T_PNAK_SERVICE_CON
{ {
unsigned short NumberEntries; unsigned short NumberEntries;
T_PNAK_SERVICE_CON_ENTRY ServiceEntry [PNAK_MAX_NUMBER_CON_SERVICES]; T_PNAK_SERVICE_CON_ENTRY ServiceEntry[PNAK_MAX_NUMBER_CON_SERVICES];
unsigned char ServiceChannel [PNAK_SERVICE_CON_CHANNEL_SIZE]; unsigned char ServiceChannel[PNAK_SERVICE_CON_CHANNEL_SIZE];
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_CON); } PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_CON);
/*=== SERVICE INDICATION ====================================================*/ /*=== SERVICE INDICATION ====================================================*/
typedef struct _T_PNAK_SERVICE_IND_ENTRY typedef struct _T_PNAK_SERVICE_IND_ENTRY
{ {
unsigned short ServiceOffset; unsigned short ServiceOffset;
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_IND_ENTRY); } PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_IND_ENTRY);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_SERVICE_IND typedef struct _T_PNAK_SERVICE_IND
{ {
unsigned short NumberEntries; unsigned short NumberEntries;
T_PNAK_SERVICE_IND_ENTRY ServiceEntry [PNAK_MAX_NUMBER_IND_SERVICES]; T_PNAK_SERVICE_IND_ENTRY ServiceEntry[PNAK_MAX_NUMBER_IND_SERVICES];
unsigned char ServiceChannel [PNAK_SERVICE_IND_CHANNEL_SIZE]; unsigned char ServiceChannel[PNAK_SERVICE_IND_CHANNEL_SIZE];
} PACK_WORD_ALIGNMENT (T_PNAK_SERVICE_IND); } PACK_WORD_ALIGNMENT(T_PNAK_SERVICE_IND);
/*============================================================================= /*=============================================================================
EVENT INTERFACE EVENT INTERFACE
=============================================================================*/ =============================================================================*/
typedef unsigned short T_PNAK_MODE; typedef unsigned short T_PNAK_MODE;
#define PNAK_MODE_OFFLINE (T_PNAK_MODE) 0u #define PNAK_MODE_OFFLINE (T_PNAK_MODE)0u
#define PNAK_MODE_ONLINE (T_PNAK_MODE) 1u #define PNAK_MODE_ONLINE (T_PNAK_MODE)1u
/*=== EVENT REQUEST ==========================================================*/ /*=== EVENT REQUEST ==========================================================*/
typedef struct _T_PNAK_EVENT_SET_MODE typedef struct _T_PNAK_EVENT_SET_MODE
{ {
T_PNAK_MODE Mode; T_PNAK_MODE Mode;
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_SET_MODE); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_SET_MODE);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_EVENT_SET_DEVICE_STATE typedef struct _T_PNAK_EVENT_SET_DEVICE_STATE
{ {
T_BITSET_256 ActivateDeviceReference; T_BITSET_256 ActivateDeviceReference;
T_BITSET_256 DeactivateDeviceReference; T_BITSET_256 DeactivateDeviceReference;
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_SET_DEVICE_STATE); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_SET_DEVICE_STATE);
/*=== EVENT INDICATION ======================================================*/ /*=== EVENT INDICATION ======================================================*/
typedef enum _T_PNAK_STATE typedef enum _T_PNAK_STATE {
{
PNAK_STATE_OK = 0, PNAK_STATE_OK = 0,
PNAK_STATE_NO_PARAMETER, PNAK_STATE_NO_PARAMETER,
PNAK_STATE_DOUBLE_ADDRESS_ERROR, PNAK_STATE_DOUBLE_ADDRESS_ERROR,
...@@ -457,142 +457,139 @@ typedef enum _T_PNAK_STATE ...@@ -457,142 +457,139 @@ typedef enum _T_PNAK_STATE
typedef struct _T_PNAK_EVENT_STATE typedef struct _T_PNAK_EVENT_STATE
{ {
T_PNAK_MODE Mode; T_PNAK_MODE Mode;
T_PNAK_STATE State; T_PNAK_STATE State;
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_STATE); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_STATE);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_EVENT_ALARM typedef struct _T_PNAK_EVENT_ALARM
{ {
T_BITSET_256 DeviceReference; T_BITSET_256 DeviceReference;
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_ALARM); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_ALARM);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_EVENT_ALARM_ACK typedef struct _T_PNAK_EVENT_ALARM_ACK
{ {
T_BITSET_256 DeviceReference; T_BITSET_256 DeviceReference;
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_ALARM_ACK); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_ALARM_ACK);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_DEVICE_STATE_DEACTIVATED 0x00u #define PNAK_DEVICE_STATE_DEACTIVATED 0x00u
#define PNAK_DEVICE_STATE_FIND_DEVICE 0x01u #define PNAK_DEVICE_STATE_FIND_DEVICE 0x01u
#define PNAK_DEVICE_STATE_CONNECTION_ESTABLISHMENT 0x02u #define PNAK_DEVICE_STATE_CONNECTION_ESTABLISHMENT 0x02u
#define PNAK_DEVICE_STATE_CONNECTED 0x04u #define PNAK_DEVICE_STATE_CONNECTED 0x04u
#define PNAK_DEVICE_STATE_CONNECT_ERROR 0x10u #define PNAK_DEVICE_STATE_CONNECT_ERROR 0x10u
#define PNAK_DEVICE_STATE_WRITE_ERROR 0x20u #define PNAK_DEVICE_STATE_WRITE_ERROR 0x20u
#define PNAK_DEVICE_STATE_CONTROL_ERROR 0x40u #define PNAK_DEVICE_STATE_CONTROL_ERROR 0x40u
#define PNAK_DEVICE_STATE_CLOSE_PENDING 0x80u #define PNAK_DEVICE_STATE_CLOSE_PENDING 0x80u
#define PNAK_DEVICE_STATE_MASK (PNAK_DEVICE_STATE_DEACTIVATED | \ #define PNAK_DEVICE_STATE_MASK \
PNAK_DEVICE_STATE_FIND_DEVICE | \ (PNAK_DEVICE_STATE_DEACTIVATED | PNAK_DEVICE_STATE_FIND_DEVICE | \
PNAK_DEVICE_STATE_CONNECTION_ESTABLISHMENT | \ PNAK_DEVICE_STATE_CONNECTION_ESTABLISHMENT | PNAK_DEVICE_STATE_CONNECTED)
PNAK_DEVICE_STATE_CONNECTED) #define PNAK_DEVICE_STATE_MASK_CONNECTING \
#define PNAK_DEVICE_STATE_MASK_CONNECTING (PNAK_DEVICE_STATE_FIND_DEVICE | \ (PNAK_DEVICE_STATE_FIND_DEVICE | PNAK_DEVICE_STATE_CONNECTION_ESTABLISHMENT)
PNAK_DEVICE_STATE_CONNECTION_ESTABLISHMENT) #define PNAK_DEVICE_STATE_ERROR_MASK \
#define PNAK_DEVICE_STATE_ERROR_MASK (PNAK_DEVICE_STATE_CONNECT_ERROR | \ (PNAK_DEVICE_STATE_CONNECT_ERROR | PNAK_DEVICE_STATE_WRITE_ERROR | \
PNAK_DEVICE_STATE_WRITE_ERROR | \ PNAK_DEVICE_STATE_CONTROL_ERROR)
PNAK_DEVICE_STATE_CONTROL_ERROR)
typedef struct _T_PNAK_EVENT_DEVICE_STATE typedef struct _T_PNAK_EVENT_DEVICE_STATE
{ {
unsigned char State [MAX_NUMBER_SUPPORTED_DEVICES]; unsigned char State[MAX_NUMBER_SUPPORTED_DEVICES];
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_DEVICE_STATE); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_DEVICE_STATE);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_PTCP_IN_SNYC 0x00000001uL #define PNAK_PTCP_IN_SNYC 0x00000001uL
#define PNAK_PTCP_NO_SYNC_MESSAGE 0x00000002uL #define PNAK_PTCP_NO_SYNC_MESSAGE 0x00000002uL
#define PNAK_PTCP_JITTER_OUT_OF_BOUNDARY 0x00000004uL #define PNAK_PTCP_JITTER_OUT_OF_BOUNDARY 0x00000004uL
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_MRPD_MISSING_APPEARS 0x8000u #define PNAK_MRPD_MISSING_APPEARS 0x8000u
#define PNAK_MRPD_MISSING_DISAPPEARS 0x0000u #define PNAK_MRPD_MISSING_DISAPPEARS 0x0000u
typedef struct _T_PNAK_EVENT_MRPD_IOCR typedef struct _T_PNAK_EVENT_MRPD_IOCR
{ {
PN_U16 FrameId [PN_SERVICE_DOWNLOAD_MAX_NUMBER_IOCRS]; PN_U16 FrameId[PN_SERVICE_DOWNLOAD_MAX_NUMBER_IOCRS];
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_MRPD_IOCR); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_MRPD_IOCR);
typedef struct _T_PNAK_EVENT_MRPD typedef struct _T_PNAK_EVENT_MRPD
{ {
T_PNAK_EVENT_MRPD_IOCR AR [MAX_NUMBER_CMDEV_CONNECTIONS]; T_PNAK_EVENT_MRPD_IOCR AR[MAX_NUMBER_CMDEV_CONNECTIONS];
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_MRPD); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_MRPD);
/*=== EVENT INDICATION MASK =================================================*/ /*=== EVENT INDICATION MASK =================================================*/
#define PNAK_EVENT_STATE_CHANGED 0x00000001uL #define PNAK_EVENT_STATE_CHANGED 0x00000001uL
#define PNAK_EVENT_DEVICE_STATE_CHANGED 0x00000002uL #define PNAK_EVENT_DEVICE_STATE_CHANGED 0x00000002uL
#define PNAK_EVENT_ALARM 0x00000004uL #define PNAK_EVENT_ALARM 0x00000004uL
#define PNAK_EVENT_ALARM_ACK 0x00000008uL #define PNAK_EVENT_ALARM_ACK 0x00000008uL
#define PNAK_EVENT_ETHERNET_STATE_CHANGED 0x00000010uL #define PNAK_EVENT_ETHERNET_STATE_CHANGED 0x00000010uL
#define PNAK_EVENT_PTCP 0x00000020uL #define PNAK_EVENT_PTCP 0x00000020uL
#define PNAK_EVENT_MRPD 0x00000040uL #define PNAK_EVENT_MRPD 0x00000040uL
#define PNAK_EVENT_MASK (PNAK_EVENT_STATE_CHANGED | \ #define PNAK_EVENT_MASK \
PNAK_EVENT_DEVICE_STATE_CHANGED | \ (PNAK_EVENT_STATE_CHANGED | PNAK_EVENT_DEVICE_STATE_CHANGED | \
PNAK_EVENT_ALARM | \ PNAK_EVENT_ALARM | PNAK_EVENT_ALARM_ACK | \
PNAK_EVENT_ALARM_ACK | \ PNAK_EVENT_ETHERNET_STATE_CHANGED | PNAK_EVENT_PTCP | PNAK_EVENT_MRPD)
PNAK_EVENT_ETHERNET_STATE_CHANGED | \
PNAK_EVENT_PTCP | \ typedef PN_U32 T_PNAK_EVENT_REG;
PNAK_EVENT_MRPD)
typedef PN_U32 T_PNAK_EVENT_REG;
typedef struct _T_PNAK_EVENT_IND_MASK typedef struct _T_PNAK_EVENT_IND_MASK
{ {
T_PNAK_EVENT_REG EventMaskReg; T_PNAK_EVENT_REG EventMaskReg;
} PACK_WORD_ALIGNMENT (T_PNAK_EVENT_IND_MASK); } PACK_WORD_ALIGNMENT(T_PNAK_EVENT_IND_MASK);
/*============================================================================= /*=============================================================================
STATISTIC INTERFACE STATISTIC INTERFACE
=============================================================================*/ =============================================================================*/
/* Attention: keep in sync with data provided by stack, see controller/device context management */ /* Attention: keep in sync with data provided by stack, see controller/device
#define PNAK_CMCTL_VENDOR_ID_MISMATCH 0x00000001uL * context management */
#define PNAK_CMCTL_DEVICE_ID_MISMATCH 0x00000002uL #define PNAK_CMCTL_VENDOR_ID_MISMATCH 0x00000001uL
#define PNAK_CMCTL_DUPLICATE_NAME 0x00000004uL #define PNAK_CMCTL_DEVICE_ID_MISMATCH 0x00000002uL
#define PNAK_CMCTL_DUPLICATE_IP_ADDRESS 0x00000008uL #define PNAK_CMCTL_DUPLICATE_NAME 0x00000004uL
#define PNAK_CMCTL_NO_EMPTY_NAME 0x00000010uL #define PNAK_CMCTL_DUPLICATE_IP_ADDRESS 0x00000008uL
#define PNAK_CMCTL_RPC_RESPONSE_MISSING 0x00000020uL #define PNAK_CMCTL_NO_EMPTY_NAME 0x00000010uL
#define PNAK_CMCTL_MODULE_MISMATCH 0x00000040uL #define PNAK_CMCTL_RPC_RESPONSE_MISSING 0x00000020uL
#define PNAK_CMCTL_MODULE_MISMATCH 0x00000040uL
#define PNIO_STATUS_CODING_RPC 0x00000001uL #define PNIO_STATUS_CODING_RPC 0x00000001uL
#define PNIO_STATUS_CODING_NDR 0x00000002uL #define PNIO_STATUS_CODING_NDR 0x00000002uL
#define PNIO_STATUS_CODING_PROFINET 0x00000003uL #define PNIO_STATUS_CODING_PROFINET 0x00000003uL
#define PNIO_STATUS_ENCODING_BIG_ENDIAN 0x00u #define PNIO_STATUS_ENCODING_BIG_ENDIAN 0x00u
#define PNIO_STATUS_ENCODING_LITTLE_ENDIAN 0x10u #define PNIO_STATUS_ENCODING_LITTLE_ENDIAN 0x10u
#define PNIO_STATUS_ENCODING_MASK 0xF0u #define PNIO_STATUS_ENCODING_MASK 0xF0u
typedef struct _T_PNAK_CONNECTION_STATISTIC typedef struct _T_PNAK_CONNECTION_STATISTIC
{ {
PN_U32 Coding; PN_U32 Coding;
PN_U8 Encoding; PN_U8 Encoding;
PN_U8 Reserved [3]; PN_U8 Reserved[3];
T_PROFINET_STATUS PNIOStatus; T_PROFINET_STATUS PNIOStatus;
} T_PNAK_CONNECTION_STATISTIC; } T_PNAK_CONNECTION_STATISTIC;
typedef struct _T_PNAK_CMCTL_STATISTIC typedef struct _T_PNAK_CMCTL_STATISTIC
{ {
PN_U32 NumberDevicesInStartup; PN_U32 NumberDevicesInStartup;
PN_U32 NumberDevicesConnected; PN_U32 NumberDevicesConnected;
T_PN_MAC_ADDRESS MacAddress [MAX_NUMBER_SUPPORTED_DEVICES]; T_PN_MAC_ADDRESS MacAddress[MAX_NUMBER_SUPPORTED_DEVICES];
T_PNAK_CONNECTION_STATISTIC Cmctl [MAX_NUMBER_SUPPORTED_DEVICES]; T_PNAK_CONNECTION_STATISTIC Cmctl[MAX_NUMBER_SUPPORTED_DEVICES];
PN_U32 Status [MAX_NUMBER_SUPPORTED_DEVICES]; PN_U32 Status[MAX_NUMBER_SUPPORTED_DEVICES];
} T_PNAK_CMCTL_STATISTIC; } T_PNAK_CMCTL_STATISTIC;
...@@ -600,7 +597,7 @@ typedef struct _T_PNAK_CMCTL_STATISTIC ...@@ -600,7 +597,7 @@ typedef struct _T_PNAK_CMCTL_STATISTIC
typedef struct _T_PNAK_CMDEV_STATISTIC typedef struct _T_PNAK_CMDEV_STATISTIC
{ {
T_PNAK_CONNECTION_STATISTIC Cmdev [MAX_NUMBER_CMDEV_CONNECTIONS]; T_PNAK_CONNECTION_STATISTIC Cmdev[MAX_NUMBER_CMDEV_CONNECTIONS];
} T_PNAK_CMDEV_STATISTIC; } T_PNAK_CMDEV_STATISTIC;
...@@ -612,141 +609,177 @@ DATA INTERFACE ...@@ -612,141 +609,177 @@ DATA INTERFACE
typedef struct _T_PNAK_DATA_CONSUMER_DATA_CHANGED typedef struct _T_PNAK_DATA_CONSUMER_DATA_CHANGED
{ {
T_BITSET_256 DeviceReference; T_BITSET_256 DeviceReference;
} PACK_WORD_ALIGNMENT (T_PNAK_DATA_CONSUMER_DATA_CHANGED); } PACK_WORD_ALIGNMENT(T_PNAK_DATA_CONSUMER_DATA_CHANGED);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct _T_PNAK_DATA_PROVIDER_DATA_UPDATED typedef struct _T_PNAK_DATA_PROVIDER_DATA_UPDATED
{ {
T_BITSET_256 DeviceReference; T_BITSET_256 DeviceReference;
} PACK_WORD_ALIGNMENT (T_PNAK_DATA_PROVIDER_DATA_UPDATED); } PACK_WORD_ALIGNMENT(T_PNAK_DATA_PROVIDER_DATA_UPDATED);
/*=== DATA INDICATION MASK ==================================================*/ /*=== DATA INDICATION MASK ==================================================*/
#define PNAK_DATA_EVENT_CYCLIC_TRANSFER_FINISHED 0x00000001uL #define PNAK_DATA_EVENT_CYCLIC_TRANSFER_FINISHED 0x00000001uL
#define PNAK_DATA_EVENT_CONSUMER_DATA_CHANGED 0x00000002uL #define PNAK_DATA_EVENT_CONSUMER_DATA_CHANGED 0x00000002uL
#define PNAK_DATA_EVENT_PROVIDER_DATA_UPDATED 0x00000004uL #define PNAK_DATA_EVENT_PROVIDER_DATA_UPDATED 0x00000004uL
typedef PN_U32 T_PNAK_DATA_EVENT_REG; typedef PN_U32 T_PNAK_DATA_EVENT_REG;
typedef struct _T_PNAK_DATA_IND_MASK typedef struct _T_PNAK_DATA_IND_MASK
{ {
T_PNAK_DATA_EVENT_REG EventMaskReg; T_PNAK_DATA_EVENT_REG EventMaskReg;
} PACK_WORD_ALIGNMENT (T_PNAK_DATA_IND_MASK); } PACK_WORD_ALIGNMENT(T_PNAK_DATA_IND_MASK);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define PNAK_IOXS_STATUS_NO_EXTENTION_FOLLOWS 0x00u #define PNAK_IOXS_STATUS_NO_EXTENTION_FOLLOWS 0x00u
#define PNAK_IOXS_STATUS_DETECTED_BY_SUBSLOT 0x00u #define PNAK_IOXS_STATUS_DETECTED_BY_SUBSLOT 0x00u
#define PNAK_IOXS_STATUS_DETECTED_BY_SLOT 0x20u #define PNAK_IOXS_STATUS_DETECTED_BY_SLOT 0x20u
#define PNAK_IOXS_STATUS_DETECTED_BY_DEVICE 0x40u #define PNAK_IOXS_STATUS_DETECTED_BY_DEVICE 0x40u
#define PNAK_IOXS_STATUS_DETECTED_BY_CONTROLLER 0x60u #define PNAK_IOXS_STATUS_DETECTED_BY_CONTROLLER 0x60u
#define PNAK_IOXS_STATUS_DATA_BAD 0x00u #define PNAK_IOXS_STATUS_DATA_BAD 0x00u
#define PNAK_IOXS_STATUS_DATA_GOOD 0x80u #define PNAK_IOXS_STATUS_DATA_GOOD 0x80u
/****************************************************************************** /******************************************************************************
FUNCTION DECLARATION FUNCTION DECLARATION
******************************************************************************/ ******************************************************************************/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef __DOXYGEN__ #ifndef __DOXYGEN__
/*--- initialization/termination functions ----------------------------------*/ /*--- initialization/termination functions ----------------------------------*/
extern void pnak_init (void); extern void pnak_init(void);
extern void pnak_term (void); extern void pnak_term(void);
#define pnak_start_profistack pnak_start_stack #define pnak_start_profistack pnak_start_stack
#define pnak_stop_profistack pnak_stop_stack #define pnak_stop_profistack pnak_stop_stack
extern T_PNAK_RESULT pnak_start_stack (unsigned short, const T_PNAK_MODE_ID); extern T_PNAK_RESULT pnak_start_stack(unsigned short, const T_PNAK_MODE_ID);
extern T_PNAK_RESULT pnak_stop_stack (unsigned short); extern T_PNAK_RESULT pnak_stop_stack(unsigned short);
/*--- General interface functions -------------------------------------------*/ /*--- General interface functions -------------------------------------------*/
extern T_PNAK_RESULT pnak_wait_for_multiple_objects (unsigned short, T_PNAK_WAIT_OBJECT*, T_PNAK_TIMEOUT); extern T_PNAK_RESULT pnak_wait_for_multiple_objects(unsigned short,
extern T_PNAK_RESULT pnak_set_multiple_objects (unsigned short, const T_PNAK_WAIT_OBJECT); T_PNAK_WAIT_OBJECT*,
extern T_PNAK_RESULT pnak_mask_multiple_objects (unsigned short, const T_PNAK_WAIT_OBJECT); T_PNAK_TIMEOUT);
extern T_PNAK_RESULT pnak_set_multiple_objects(unsigned short,
const T_PNAK_WAIT_OBJECT);
extern T_PNAK_RESULT pnak_mask_multiple_objects(unsigned short,
const T_PNAK_WAIT_OBJECT);
extern T_PNAK_RESULT pnak_get_exception (unsigned short, T_PNAK_EXCEPTION*); extern T_PNAK_RESULT pnak_get_exception(unsigned short, T_PNAK_EXCEPTION*);
extern T_PNAK_RESULT pnak_get_version (unsigned short, T_PNAK_VERSIONS*); extern T_PNAK_RESULT pnak_get_version(unsigned short, T_PNAK_VERSIONS*);
extern T_PNAK_RESULT pnak_snmp_get_data (unsigned short, T_PNAK_OID*, void*, PN_U32*, PN_U32*, unsigned char, PN_BOOL); extern T_PNAK_RESULT pnak_snmp_get_data(unsigned short, T_PNAK_OID*, void*,
extern T_PNAK_RESULT pnak_snmp_check_data (unsigned short, T_PNAK_OID*, void*, PN_U32, PN_U32, unsigned char); PN_U32*, PN_U32*, unsigned char,
extern T_PNAK_RESULT pnak_snmp_set_data (unsigned short, T_PNAK_OID*, void*, PN_U32, PN_U32); PN_BOOL);
extern T_PNAK_RESULT pnak_snmp_check_data(unsigned short, T_PNAK_OID*, void*,
PN_U32, PN_U32, unsigned char);
extern T_PNAK_RESULT pnak_snmp_set_data(unsigned short, T_PNAK_OID*, void*,
PN_U32, PN_U32);
extern T_PNAK_RESULT pnak_retrigger_watchdog (unsigned short, PN_U32); extern T_PNAK_RESULT pnak_retrigger_watchdog(unsigned short, PN_U32);
/*--- Service interface functions -------------------------------------------*/ /*--- Service interface functions -------------------------------------------*/
extern T_PNAK_RESULT pnak_limit_number_parallel_services (unsigned short, unsigned short, unsigned short); extern T_PNAK_RESULT pnak_limit_number_parallel_services(unsigned short,
unsigned short,
unsigned short);
extern T_PNAK_RESULT pnak_send_service_req_res (unsigned short, const T_PNAK_SERVICE_REQ_RES*); extern T_PNAK_RESULT pnak_send_service_req_res(unsigned short,
extern T_PNAK_RESULT pnak_get_service_ind (unsigned short, T_PNAK_SERVICE_IND*); const T_PNAK_SERVICE_REQ_RES*);
extern T_PNAK_RESULT pnak_get_service_con (unsigned short, T_PNAK_SERVICE_CON*); extern T_PNAK_RESULT pnak_get_service_ind(unsigned short, T_PNAK_SERVICE_IND*);
extern T_PNAK_RESULT pnak_get_service_con(unsigned short, T_PNAK_SERVICE_CON*);
/*--- Event interface functions ---------------------------------------------*/ /*--- Event interface functions ---------------------------------------------*/
extern T_PNAK_RESULT pnak_set_mode (unsigned short, const T_PNAK_EVENT_SET_MODE*); extern T_PNAK_RESULT pnak_set_mode(unsigned short,
extern T_PNAK_RESULT pnak_set_device_state (unsigned short, const T_PNAK_EVENT_SET_DEVICE_STATE*); const T_PNAK_EVENT_SET_MODE*);
extern T_PNAK_RESULT
pnak_set_device_state(unsigned short, const T_PNAK_EVENT_SET_DEVICE_STATE*);
extern T_PNAK_RESULT pnak_get_state (unsigned short, T_PNAK_EVENT_STATE*); extern T_PNAK_RESULT pnak_get_state(unsigned short, T_PNAK_EVENT_STATE*);
extern T_PNAK_RESULT pnak_get_device_state_ind (unsigned short, T_PNAK_EVENT_DEVICE_STATE*); extern T_PNAK_RESULT pnak_get_device_state_ind(unsigned short,
extern T_PNAK_RESULT pnak_get_alarm_ind (unsigned short, T_PNAK_EVENT_ALARM*); T_PNAK_EVENT_DEVICE_STATE*);
extern T_PNAK_RESULT pnak_get_alarm_ack_ind (unsigned short, T_PNAK_EVENT_ALARM_ACK*); extern T_PNAK_RESULT pnak_get_alarm_ind(unsigned short, T_PNAK_EVENT_ALARM*);
extern T_PNAK_RESULT pnak_get_ptcp_ind (unsigned short, PN_U32*); extern T_PNAK_RESULT pnak_get_alarm_ack_ind(unsigned short,
extern T_PNAK_RESULT pnak_get_mrpd_ind (unsigned short, T_PNAK_EVENT_MRPD*); T_PNAK_EVENT_ALARM_ACK*);
extern T_PNAK_RESULT pnak_get_ptcp_ind(unsigned short, PN_U32*);
extern T_PNAK_RESULT pnak_get_mrpd_ind(unsigned short, T_PNAK_EVENT_MRPD*);
/*--- Data interface functions ----------------------------------------------*/ /*--- Data interface functions ----------------------------------------------*/
extern T_PNAK_RESULT pnak_set_iocr_data (unsigned short, unsigned short, const unsigned char*, unsigned short, unsigned char); extern T_PNAK_RESULT pnak_set_iocr_data(unsigned short, unsigned short,
const unsigned char*, unsigned short,
unsigned char);
extern T_PNAK_RESULT pnak_get_iocr_data (unsigned short, unsigned short, unsigned char*, unsigned short*, unsigned char*, unsigned char*); extern T_PNAK_RESULT pnak_get_iocr_data(unsigned short, unsigned short,
extern T_PNAK_RESULT pnak_get_consumer_data_changed_ind (unsigned short, T_PNAK_DATA_CONSUMER_DATA_CHANGED*); unsigned char*, unsigned short*,
extern T_PNAK_RESULT pnak_get_provider_data_updated (unsigned short, T_PNAK_DATA_PROVIDER_DATA_UPDATED*); unsigned char*, unsigned char*);
extern T_PNAK_RESULT
pnak_get_consumer_data_changed_ind(unsigned short,
T_PNAK_DATA_CONSUMER_DATA_CHANGED*);
extern T_PNAK_RESULT
pnak_get_provider_data_updated(unsigned short,
T_PNAK_DATA_PROVIDER_DATA_UPDATED*);
/*============================================================================= /*=============================================================================
CALLBACK INTERFACE CALLBACK INTERFACE
=============================================================================*/ =============================================================================*/
typedef int (*T_PNAK_WAIT_OBJECT_CALLBACK) (unsigned short, T_PNAK_WAIT_OBJECT); typedef int (*T_PNAK_WAIT_OBJECT_CALLBACK)(unsigned short, T_PNAK_WAIT_OBJECT);
typedef int (*T_PNAK_HW_START_CALLBACK) (unsigned short, T_PNAK_MODE_ID, void*); typedef int (*T_PNAK_HW_START_CALLBACK)(unsigned short, T_PNAK_MODE_ID, void*);
typedef void (*T_PROVIDER_CALLBACK) (unsigned short, unsigned short, unsigned char*, unsigned short, unsigned char*); typedef void (*T_PROVIDER_CALLBACK)(unsigned short, unsigned short,
typedef void (*T_CONSUMER_CALLBACK) (unsigned short, unsigned short, const unsigned char*, unsigned short, unsigned char, unsigned char); unsigned char*, unsigned short,
unsigned char*);
typedef void (*T_CONSUMER_CALLBACK)(unsigned short, unsigned short,
const unsigned char*, unsigned short,
unsigned char, unsigned char);
extern T_PNAK_RESULT pnak_register_provider_callback (unsigned short, T_PROVIDER_CALLBACK); extern T_PNAK_RESULT pnak_register_provider_callback(unsigned short,
extern T_PNAK_RESULT pnak_unregister_provider_callback (unsigned short); T_PROVIDER_CALLBACK);
extern T_PNAK_RESULT pnak_unregister_provider_callback(unsigned short);
extern T_PNAK_RESULT pnak_register_consumer_callback (unsigned short, T_CONSUMER_CALLBACK); extern T_PNAK_RESULT pnak_register_consumer_callback(unsigned short,
extern T_PNAK_RESULT pnak_unregister_consumer_callback (unsigned short); T_CONSUMER_CALLBACK);
extern T_PNAK_RESULT pnak_unregister_consumer_callback(unsigned short);
extern T_PNAK_RESULT pnak_register_ethernet_provider_hook (unsigned short, T_PROVIDER_CALLBACK); extern T_PNAK_RESULT pnak_register_ethernet_provider_hook(unsigned short,
extern T_PNAK_RESULT pnak_unregister_ethernet_provider_hook (unsigned short); T_PROVIDER_CALLBACK);
extern T_PNAK_RESULT pnak_unregister_ethernet_provider_hook(unsigned short);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef void (*T_PNAK_CMCTL_STATISTIC_CALLBACK) (unsigned short, T_PNAK_CMCTL_STATISTIC*); typedef void (*T_PNAK_CMCTL_STATISTIC_CALLBACK)(unsigned short,
T_PNAK_CMCTL_STATISTIC*);
extern T_PNAK_RESULT pnak_register_cmctl_statistic_callback (unsigned short, T_PNAK_CMCTL_STATISTIC_CALLBACK); extern T_PNAK_RESULT
extern T_PNAK_RESULT pnak_unregister_cmctl_statistic_callback (unsigned short); pnak_register_cmctl_statistic_callback(unsigned short,
T_PNAK_CMCTL_STATISTIC_CALLBACK);
extern T_PNAK_RESULT pnak_unregister_cmctl_statistic_callback(unsigned short);
typedef void (*T_PNAK_CMDEV_STATISTIC_CALLBACK) (unsigned short, T_PNAK_CMDEV_STATISTIC*); typedef void (*T_PNAK_CMDEV_STATISTIC_CALLBACK)(unsigned short,
T_PNAK_CMDEV_STATISTIC*);
extern T_PNAK_RESULT pnak_register_cmdev_statistic_callback (unsigned short, T_PNAK_CMDEV_STATISTIC_CALLBACK); extern T_PNAK_RESULT
extern T_PNAK_RESULT pnak_unregister_cmdev_statistic_callback (unsigned short); pnak_register_cmdev_statistic_callback(unsigned short,
T_PNAK_CMDEV_STATISTIC_CALLBACK);
extern T_PNAK_RESULT pnak_unregister_cmdev_statistic_callback(unsigned short);
#endif /* __DOXYGEN__ */ #endif /* __DOXYGEN__ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/* the scai/sdai socket functions are derived from the basic implementation of /* the scai/sdai socket functions are derived from the basic implementation of
...@@ -754,7 +787,7 @@ extern T_PNAK_RESULT pnak_unregister_cmdev_statistic_callback (unsigned shor ...@@ -754,7 +787,7 @@ extern T_PNAK_RESULT pnak_unregister_cmdev_statistic_callback (unsigned shor
* so we have to disable the original definitions * so we have to disable the original definitions
*/ */
#if !defined (SCAI_INCLUDE_SOCKET) && !defined(SDAI_INCLUDE_SOCKET) #if !defined(SCAI_INCLUDE_SOCKET) && !defined(SDAI_INCLUDE_SOCKET)
/****************************************************************************** /******************************************************************************
SOCKET USER INTERFACE SOCKET USER INTERFACE
...@@ -764,9 +797,10 @@ SOCKET USER INTERFACE ...@@ -764,9 +797,10 @@ SOCKET USER INTERFACE
* @socketmainpage * @socketmainpage
* *
* @section Introduction * @section Introduction
* In addition to the realtime ethernet communication via the PROFINET Application Interface (PNAK) * In addition to the realtime ethernet communication via the PROFINET
* Softing offers a universal Socket Interface for implementation of any TCP or UDP based protocol. It * Application Interface (PNAK) Softing offers a universal Socket Interface for
* enables the integration of various industrial IT functions into the device: * implementation of any TCP or UDP based protocol. It enables the integration
* of various industrial IT functions into the device:
* *
* - Embedded Webserver for freely designed websites * - Embedded Webserver for freely designed websites
* - FTP-Server for updating the device firmware or for file downloads * - FTP-Server for updating the device firmware or for file downloads
...@@ -774,24 +808,31 @@ SOCKET USER INTERFACE ...@@ -774,24 +808,31 @@ SOCKET USER INTERFACE
* - Telnet for virtual terminal connections * - Telnet for virtual terminal connections
* - Implementation of manufacturer specific application protocols * - Implementation of manufacturer specific application protocols
* *
* The Socket Interface offers a comfortable application interface which disburdens the user from a lot of * The Socket Interface offers a comfortable application interface which
* tasks and provides a lot of automatisms. The special characteristics of each TCP/IP stack will be hidden * disburdens the user from a lot of tasks and provides a lot of automatisms.
* from the user. Establishment and management of TCP connections are handled completely by the socket interface. * The special characteristics of each TCP/IP stack will be hidden from the
* The user can focus on the implementation of the desired IT functionality. This allows an easy implementation * user. Establishment and management of TCP connections are handled completely
* of the socket application. The resources needed by the socket interface (see also \ref SocketResources) can be * by the socket interface. The user can focus on the implementation of the
* easily adpated to the available memory provided by the used the hardware platform. * desired IT functionality. This allows an easy implementation of the socket
* application. The resources needed by the socket interface (see also \ref
* SocketResources) can be easily adpated to the available memory provided by
* the used the hardware platform.
* *
* The communication via the Socket Interface can be used in parallel and without influencing the realtime * The communication via the Socket Interface can be used in parallel and
* communication via the used realtime ethernet protocol. Therefore the realtime ethernet communication * without influencing the realtime communication via the used realtime ethernet
* will be processed with a higher priority than the communication via the Socket Interface. The network interface * protocol. Therefore the realtime ethernet communication will be processed
* is shared between the Socket Interface and the realtime ethernet protocol. Thus a high communication load * with a higher priority than the communication via the Socket Interface. The
* to be processed by the realtime ethernet protocol limits the available bandwith and the performance of the * network interface is shared between the Socket Interface and the realtime
* Socket Interface communication. * ethernet protocol. Thus a high communication load to be processed by the
* realtime ethernet protocol limits the available bandwith and the performance
* of the Socket Interface communication.
* *
* @section Application Interface Description * @section Application Interface Description
* The following figure shows the structure of Softings Socket Interface implementation. * The following figure shows the structure of Softings Socket Interface
* implementation.
* @image html Socket_Structure.png * @image html Socket_Structure.png
* A detailed description of the Socket Application Interface can be found in the following chapters: * A detailed description of the Socket Application Interface can be found in
* the following chapters:
* - \ref sock_defines * - \ref sock_defines
* - \ref sock_structures * - \ref sock_structures
* - \ref sock_functions * - \ref sock_functions
...@@ -816,7 +857,7 @@ SOCKET USER INTERFACE ...@@ -816,7 +857,7 @@ SOCKET USER INTERFACE
* @{ * @{
*/ */
#define MAX_NUMBER_SUPPORTED_SOCKETS (PN_U16) 64u #define MAX_NUMBER_SUPPORTED_SOCKETS (PN_U16)64u
/*--- Socket options --------------------------------------------------------*/ /*--- Socket options --------------------------------------------------------*/
...@@ -825,12 +866,22 @@ SOCKET USER INTERFACE ...@@ -825,12 +866,22 @@ SOCKET USER INTERFACE
* @{ * @{
*/ */
#define SOCK_FLAG_TYPE_UDP 0x00000000uL /**< Socket type TCP */ #define SOCK_FLAG_TYPE_UDP 0x00000000uL /**< Socket type TCP */
#define SOCK_FLAG_TYPE_TCP 0x00008000uL /**< Socket type UDP */ #define SOCK_FLAG_TYPE_TCP 0x00008000uL /**< Socket type UDP */
#define SOCK_FLAG_ENABLE_KEEPALIVE (SOCK_FLAG_TYPE_TCP | 0x00000001uL) /**< Enables keep-alive packets to supervise a TCP connection */ #define SOCK_FLAG_ENABLE_KEEPALIVE \
#define SOCK_FLAG_ENABLE_BROADCAST (SOCK_FLAG_TYPE_UDP | 0x00000002uL) /**< Enables the transmission of broadcast messages over a UDP socket */ (SOCK_FLAG_TYPE_TCP | 0x00000001uL) /**< Enables keep-alive packets to \
#define SOCK_FLAG_ENABLE_MULTICAST (SOCK_FLAG_TYPE_UDP | 0x00000004uL) /**< Enables the transmission of multicast messages over a UDP socket */ supervise a TCP connection */
#define SOCK_FLAG_USER_MASK 0x0000FFFFuL /**< Specifies the bits wich are valid for the socket application */ #define SOCK_FLAG_ENABLE_BROADCAST \
(SOCK_FLAG_TYPE_UDP | \
0x00000002uL) /**< Enables the transmission of broadcast messages over \
a UDP socket */
#define SOCK_FLAG_ENABLE_MULTICAST \
(SOCK_FLAG_TYPE_UDP | \
0x00000004uL) /**< Enables the transmission of multicast messages over \
a UDP socket */
#define SOCK_FLAG_USER_MASK \
0x0000FFFFuL /**< Specifies the bits wich are valid for the socket \
application */
/** @} */ /** @} */
...@@ -841,39 +892,68 @@ SOCKET USER INTERFACE ...@@ -841,39 +892,68 @@ SOCKET USER INTERFACE
* @{ * @{
*/ */
typedef enum _T_SOCKET_RESULT typedef enum _T_SOCKET_RESULT {
{ SOCK_SUCCESS = 0u, /**< General success return value */
SOCK_SUCCESS = 0u, /**< General success return value */ SOCK_ERR_INVALID_ARGUMENT, /**< Passed argument is invalid */
SOCK_ERR_INVALID_ARGUMENT, /**< Passed argument is invalid */ SOCK_ERR_API_ALREADY_INITIALIZED, /**< Socket Interface already initialized */
SOCK_ERR_API_ALREADY_INITIALIZED, /**< Socket Interface already initialized */ SOCK_ERR_API_NOT_INITIALIZED, /**< Socket Interface not initialized */
SOCK_ERR_API_NOT_INITIALIZED, /**< Socket Interface not initialized */ SOCK_ERR_INVALID_SOCKET_ID, /**< The passed socket ID is invalid */
SOCK_ERR_INVALID_SOCKET_ID, /**< The passed socket ID is invalid */ SOCK_ERR_OUT_OF_SOCKETS, /**< No free socket available */
SOCK_ERR_OUT_OF_SOCKETS, /**< No free socket available */ SOCK_ERR_SOCKET_NOT_CREATED, /**< The specified socket has not been created.
SOCK_ERR_SOCKET_NOT_CREATED, /**< The specified socket has not been created. */ */
SOCK_ERR_SOCKET_OFFLINE, /**< The local port associated with the socket is not open. Sending/Receiving of messages is not possible. */ SOCK_ERR_SOCKET_OFFLINE, /**< The local port associated with the socket is not
SOCK_ERR_SOCKET_BUSY, /**< A send request is rejected because a previous send request on the specified socket is not completed */ open. Sending/Receiving of messages is not
SOCK_ERR_SOCKET_NOT_CONNECTED, /**< The request is rejected because the specified TCP connection or no TCP connection has been established for the specified socket. */ possible. */
SOCK_ERR_SOCKET_CONNECTED, /**< The request is rejected because the specified TCP connection has established a connection before the filter was activated. */ SOCK_ERR_SOCKET_BUSY, /**< A send request is rejected because a previous send
SOCK_ERR_ADDR_IN_USE, /**< The passed local address is already in use by another socket. */ request on the specified socket is not completed */
SOCK_ERR_INVALID_LOCAL_ADDR, /**< The passed local IP address is invalid. It is not possible to bind the socket to this address. Which IP addresses are allowed depends SOCK_ERR_SOCKET_NOT_CONNECTED, /**< The request is rejected because the
on the socket configuration (e.g. socket type UDP or TCP) and the network settings adjusted by calling the function sock_init(). */ specified TCP connection or no TCP
SOCK_ERR_INVALID_REMOTE_ADDR, /**< The passed remote IP address is invalid. It is not possible to send or connect to this address. Which IP addresses are allowed depends connection has been established for the
on the socket configuration (e.g. socket type UDP or TCP) and the network settings adjusted by calling the function sock_init(). */ specified socket. */
SOCK_ERR_NO_DATA_RECEIVED, /**< No data has been received on the specfied socket or TCP connection. */ SOCK_ERR_SOCKET_CONNECTED, /**< The request is rejected because the specified
SOCK_ERR_NOT_SUPPORTED, /**< The requested action is not supported on the specified socket. */ TCP connection has established a connection
SOCK_ERR_TEMPORARY_NOT_EXECUTABLE, /**< The requested action is temporary not executable on the specified socket due a concurrent pending request. */ before the filter was activated. */
SOCK_ERR_FATAL_ERROR, /**< A fatal error is reported during execution of function. */ SOCK_ERR_ADDR_IN_USE, /**< The passed local address is already in use by
SOCK_ERR_LIBRARY_NOT_LOADED /**< Can not load socket library */ another socket. */
SOCK_ERR_INVALID_LOCAL_ADDR, /**< The passed local IP address is invalid. It
is not possible to bind the socket to this
address. Which IP addresses are allowed
depends on the socket configuration (e.g.
socket type UDP or TCP) and the network
settings adjusted by calling the function
sock_init(). */
SOCK_ERR_INVALID_REMOTE_ADDR, /**< The passed remote IP address is invalid. It
is not possible to send or connect to this
address. Which IP addresses are allowed
depends on the socket configuration (e.g.
socket type UDP or TCP) and the network
settings adjusted by calling the function
sock_init(). */
SOCK_ERR_NO_DATA_RECEIVED, /**< No data has been received on the specfied
socket or TCP connection. */
SOCK_ERR_NOT_SUPPORTED, /**< The requested action is not supported on the
specified socket. */
SOCK_ERR_TEMPORARY_NOT_EXECUTABLE, /**< The requested action is temporary not
executable on the specified socket due a
concurrent pending request. */
SOCK_ERR_FATAL_ERROR, /**< A fatal error is reported during execution of
function. */
SOCK_ERR_LIBRARY_NOT_LOADED /**< Can not load socket library */
} T_SOCKET_RESULT; } T_SOCKET_RESULT;
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define SOCK_IP_ADDR_ANY 0x00000000uL /**< Can be used as local IP address when creating a socket to bind the socket to all the IP addresses (If the system has #define SOCK_IP_ADDR_ANY \
multiple IP addresses) or if the local IP address is unknown. */ 0x00000000uL /**< Can be used as local IP address when creating a socket to \
#define SOCK_PORT_ANY 0u /**< Can be used as local port when creating a TCP Client socket to let the TCP/IP stack select a unique local port from the bind the socket to all the IP addresses (If the system has \
dynamic client port range. */ multiple IP addresses) or if the local IP address is \
unknown. */
#define SOCK_PORT_ANY \
0u /**< Can be used as local port when creating a TCP Client socket to let \
the TCP/IP stack select a unique local port from the dynamic client \
port range. */
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/
...@@ -881,18 +961,19 @@ typedef enum _T_SOCKET_RESULT ...@@ -881,18 +961,19 @@ typedef enum _T_SOCKET_RESULT
/** \addtogroup sock_structures Data Structures /** \addtogroup sock_structures Data Structures
* @{ * @{
* \brief Specifies a transport IP address and port. * \brief Specifies a transport IP address and port.
* All of the structure data must be specified in network-byte-order (big-endian). * All of the structure data must be specified in network-byte-order
* (big-endian).
*/ */
typedef struct _T_PNAK_SOCK_ADDR typedef struct _T_PNAK_SOCK_ADDR
{ {
PN_U32 IpAddress; /**< IP address */ PN_U32 IpAddress; /**< IP address */
unsigned short Port; /**< port number */ unsigned short Port; /**< port number */
unsigned char Alignment [2]; unsigned char Alignment[2];
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_ADDR); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_ADDR);
/** @} */ /** @} */
...@@ -904,12 +985,19 @@ typedef struct _T_PNAK_SOCK_ADDR ...@@ -904,12 +985,19 @@ typedef struct _T_PNAK_SOCK_ADDR
*/ */
typedef struct _T_PNAK_SOCK_CONFIG_OPTIONS typedef struct _T_PNAK_SOCK_CONFIG_OPTIONS
{ {
PN_U32 Timeout; /**< Keep-Alive Timeout in milliseconds. The Keep-Alive Timeout will be used for the supervision of TCP connections. The connection will be aborted if the PN_U32
remote connection partner did not show activity within this timeout. The supervision of TCP connections can be enabled/disabled socket-specific when Timeout; /**< Keep-Alive Timeout in milliseconds. The Keep-Alive Timeout
creating the socket by calling sock_create(). For UDP sockets the application needs to perform a supervision if necessary. If the timeout value is set to 0 will be used for the supervision of TCP connections. The
and #SOCK_FLAG_ENABLE_KEEPALIVE is set when creating a socket, a default value for the Keep-Alive Timeout will be used. */ connection will be aborted if the remote connection partner
did not show activity within this timeout. The supervision of
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_CONFIG_OPTIONS); TCP connections can be enabled/disabled socket-specific when
creating the socket by calling sock_create(). For UDP
sockets the application needs to perform a supervision if
necessary. If the timeout value is set to 0 and
#SOCK_FLAG_ENABLE_KEEPALIVE is set when creating a socket, a
default value for the Keep-Alive Timeout will be used. */
} PACK_WORD_ALIGNMENT(T_PNAK_SOCK_CONFIG_OPTIONS);
/** @} */ /** @} */
...@@ -918,18 +1006,20 @@ typedef struct _T_PNAK_SOCK_CONFIG_OPTIONS ...@@ -918,18 +1006,20 @@ typedef struct _T_PNAK_SOCK_CONFIG_OPTIONS
/** \addtogroup sock_structures Data Structures /** \addtogroup sock_structures Data Structures
* @{ * @{
* \brief Network specific parameter * \brief Network specific parameter
* All of the structure data must be specified in network-byte-order (big-endian). * All of the structure data must be specified in network-byte-order
* (big-endian).
*/ */
typedef struct _T_PNAK_SOCK_NETWORK_SETTINGS typedef struct _T_PNAK_SOCK_NETWORK_SETTINGS
{ {
PN_U32 IpAddress; /**< The IP-Address of the Device. For future use only. */ PN_U32 IpAddress; /**< The IP-Address of the Device. For future use only. */
PN_U32 SubnetMask; /**< The Netmask of the Device. For future use only. */ PN_U32 SubnetMask; /**< The Netmask of the Device. For future use only. */
PN_U32 GatewayAddress; /**< The Gateway of the Device. For future use only. */ PN_U32 GatewayAddress; /**< The Gateway of the Device. For future use only. */
unsigned char MacAddress [6]; /**< The MAC address of the device. For future use only. */ unsigned char
unsigned char Alignment [2]; MacAddress[6]; /**< The MAC address of the device. For future use only. */
unsigned char Alignment[2];
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_NETWORK_SETTINGS); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_NETWORK_SETTINGS);
/** @} */ /** @} */
...@@ -941,10 +1031,12 @@ typedef struct _T_PNAK_SOCK_NETWORK_SETTINGS ...@@ -941,10 +1031,12 @@ typedef struct _T_PNAK_SOCK_NETWORK_SETTINGS
*/ */
typedef struct _T_PNAK_SOCK_INIT typedef struct _T_PNAK_SOCK_INIT
{ {
T_PNAK_SOCK_NETWORK_SETTINGS NetworkSettings; /**< Network specific parameter */ T_PNAK_SOCK_NETWORK_SETTINGS
T_PNAK_SOCK_CONFIG_OPTIONS ConfigOptions; /**< Configurable Options for the socket interface */ NetworkSettings; /**< Network specific parameter */
T_PNAK_SOCK_CONFIG_OPTIONS
ConfigOptions; /**< Configurable Options for the socket interface */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_INIT); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_INIT);
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
...@@ -955,25 +1047,44 @@ typedef struct _T_PNAK_SOCK_INIT ...@@ -955,25 +1047,44 @@ typedef struct _T_PNAK_SOCK_INIT
* Status of a TCP connection * Status of a TCP connection
* @{ * @{
*/ */
#define SOCK_TCP_CONNECTION_STATUS_UNCONNECTED 0x00000001uL /**< TCP connection not established */ #define SOCK_TCP_CONNECTION_STATUS_UNCONNECTED \
#define SOCK_TCP_CONNECTION_STATUS_CONNECTING 0x00000002uL /**< A TCP connection establishment is in progress. This status is only possible for a TCP client socket. */ 0x00000001uL /**< TCP connection not established */
#define SOCK_TCP_CONNECTION_STATUS_CONNECTED 0x00000003uL /**< TCP connection established */ #define SOCK_TCP_CONNECTION_STATUS_CONNECTING \
0x00000002uL /**< A TCP connection establishment is in progress. This status \
is only possible for a TCP client socket. */
#define SOCK_TCP_CONNECTION_STATUS_CONNECTED \
0x00000003uL /**< TCP connection established */
/** @} */ /** @} */
/** \anchor ConnectionStatusCode @name TCP Connection Status Codes /** \anchor ConnectionStatusCode @name TCP Connection Status Codes
* Error Codes of a TCP connection * Error Codes of a TCP connection
* @{ * @{
*/ */
#define SOCK_TCP_CONNECTION_STATUS_CODE_NO_ERROR 0x00000000uL /**< No error detected */ #define SOCK_TCP_CONNECTION_STATUS_CODE_NO_ERROR \
#define SOCK_TCP_CONNECTION_STATUS_CODE_INTERNAL_ERROR 0x00000001uL /**< An internal error occurred in the socket interface causing the connection to abort. */ 0x00000000uL /**< No error detected */
#define SOCK_TCP_CONNECTION_STATUS_CODE_CLOSED_REMOTELY 0x00000002uL /**< The connection has been orderly closed by the remote connection partner (TCP FIN received). */ #define SOCK_TCP_CONNECTION_STATUS_CODE_INTERNAL_ERROR \
#define SOCK_TCP_CONNECTION_STATUS_CODE_ABORTED_REMOTELY 0x00000003uL /**< The connection has been aborted by the remote connection partner (TCP RST received), e.g. because 0x00000001uL /**< An internal error occurred in the socket interface causing \
the remote partner has detected an error or temporarily crashed. */ the connection to abort. */
#define SOCK_TCP_CONNECTION_STATUS_CODE_TIMEOUT 0x00000004uL /**< The connection has been aborted because of a network failure or because the remote connection partner failed #define SOCK_TCP_CONNECTION_STATUS_CODE_CLOSED_REMOTELY \
to respond within the configured supervision timeout (see also T_PNAK_SOCK_CONFIG_OPTIONS). */ 0x00000002uL /**< The connection has been orderly closed by the remote \
#define SOCK_TCP_CONNECTION_STATUS_CODE_CONNECT_REJECTED 0x00000005uL /**< It was not possible to establish a connection because the destination host rejected the connect request, connection partner (TCP FIN received). */
e.g. because the remote port is closed. This error only occurs for a TCP client socket. To retry connection #define SOCK_TCP_CONNECTION_STATUS_CODE_ABORTED_REMOTELY \
establishment the application has to close the socket and re-create the socket again. */ 0x00000003uL /**< The connection has been aborted by the remote connection \
partner (TCP RST received), e.g. because \
the remote partner has detected an error or temporarily \
crashed. */
#define SOCK_TCP_CONNECTION_STATUS_CODE_TIMEOUT \
0x00000004uL /**< The connection has been aborted because of a network \
failure or because the remote connection partner failed to \
respond within the configured supervision timeout (see also \
T_PNAK_SOCK_CONFIG_OPTIONS). */
#define SOCK_TCP_CONNECTION_STATUS_CODE_CONNECT_REJECTED \
0x00000005uL /**< It was not possible to establish a connection because the \
destination host rejected the connect request, e.g. because \
the remote port is closed. This error only occurs for a TCP \
client socket. To retry connection establishment the \
application has to close the socket and re-create the socket \
again. */
/** @} */ /** @} */
/** @} */ /** @} */
...@@ -983,26 +1094,31 @@ typedef struct _T_PNAK_SOCK_INIT ...@@ -983,26 +1094,31 @@ typedef struct _T_PNAK_SOCK_INIT
*/ */
typedef struct _T_PNAK_SOCK_TCP_CONNECTION_LOCAL_STATUS typedef struct _T_PNAK_SOCK_TCP_CONNECTION_LOCAL_STATUS
{ {
PN_U32 Status; /**< Local status of the TCP connection. Valid values: \ref ConnectionStatus */ PN_U32 Status; /**< Local status of the TCP connection. Valid values: \ref
PN_U32 StatusCode; /**< Indicates the last error of the TCP connection. Valid values: \ref ConnectionStatusCode */ ConnectionStatus */
PN_U32 StatusCode; /**< Indicates the last error of the TCP connection. Valid
values: \ref ConnectionStatusCode */
T_PNAK_SOCK_ADDR RemoteAddr; /**< Address information of the remote connection partner */ T_PNAK_SOCK_ADDR
RemoteAddr; /**< Address information of the remote connection partner */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_TCP_CONNECTION_LOCAL_STATUS); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_TCP_CONNECTION_LOCAL_STATUS);
/** @} */ /** @} */
/** \addtogroup sock_structures Data Structures /** \addtogroup sock_structures Data Structures
* @{ * @{
* \brief This structure holds status informations about all TCP connections of a socket * \brief This structure holds status informations about all TCP connections of
* a socket
*/ */
typedef struct _T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA typedef struct _T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA
{ {
PN_U32 NumberConnections; /**< Number of TCP connection for which status info is provided */ PN_U32 NumberConnections; /**< Number of TCP connection for which status info
is provided */
/*T_PNAK_SOCK_TCP_CONNECTION_LOCAL_STATUS Connection [NumberConnections];*/ /**< TCP connection status information */ /*T_PNAK_SOCK_TCP_CONNECTION_LOCAL_STATUS Connection [NumberConnections];*/ /**< TCP connection status information */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA);
/** @} */ /** @} */
...@@ -1012,18 +1128,28 @@ typedef struct _T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA ...@@ -1012,18 +1128,28 @@ typedef struct _T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA
* Status of a socket * Status of a socket
* @{ * @{
*/ */
#define SOCK_LOCAL_STATUS_CLOSED 0x00000001uL /**< The local socket is closed */ #define SOCK_LOCAL_STATUS_CLOSED \
#define SOCK_LOCAL_STATUS_OFFLINE 0x00000002uL /**< The local port associated with the socket is not open. Sending/Receiving of messages is not possible. */ 0x00000001uL /**< The local socket is closed \
#define SOCK_LOCAL_STATUS_ONLINE 0x00000003uL /**< The local port associated with the socket is open. Sending/Receiving of messages is possible. */ */
#define SOCK_LOCAL_STATUS_OFFLINE \
0x00000002uL /**< The local port associated with the socket is not open. \
Sending/Receiving of messages is not possible. */
#define SOCK_LOCAL_STATUS_ONLINE \
0x00000003uL /**< The local port associated with the socket is open. \
Sending/Receiving of messages is possible. */
/** @} */ /** @} */
/** \anchor SocketStatusCode @name Socket Status Codes /** \anchor SocketStatusCode @name Socket Status Codes
* Error Codes of a socket * Error Codes of a socket
* @{ * @{
*/ */
#define SOCK_LOCAL_STATUS_CODE_NO_ERROR 0x00000000uL /**< No error detected */ #define SOCK_LOCAL_STATUS_CODE_NO_ERROR 0x00000000uL /**< No error detected */
#define SOCK_LOCAL_STATUS_CODE_ADDR_IN_USE 0x00000001uL /**< The local address passed with sock_create() is already in use by another socket. */ #define SOCK_LOCAL_STATUS_CODE_ADDR_IN_USE \
#define SOCK_LOCAL_STATUS_CODE_INTERNAL_ERROR 0x00000002uL /**< An internal error occurred in the socket interface causing the socket to close. */ 0x00000001uL /**< The local address passed with sock_create() is already in \
use by another socket. */
#define SOCK_LOCAL_STATUS_CODE_INTERNAL_ERROR \
0x00000002uL /**< An internal error occurred in the socket interface causing \
the socket to close. */
/** @} */ /** @} */
/** @} */ /** @} */
...@@ -1033,17 +1159,19 @@ typedef struct _T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA ...@@ -1033,17 +1159,19 @@ typedef struct _T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA
*/ */
typedef struct _T_PNAK_SOCK_IOC_GET_LOCAL_STATUS typedef struct _T_PNAK_SOCK_IOC_GET_LOCAL_STATUS
{ {
PN_U32 Status; /**< Common socket status information. Valid values: \ref SocketStatus */ PN_U32 Status; /**< Common socket status information. Valid values: \ref
PN_U32 StatusCode; /**< Common socket error code. Valid values: \ref SocketStatusCode */ SocketStatus */
PN_U32 StatusCode; /**< Common socket error code. Valid values: \ref
union SocketStatusCode */
{
T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA Tcp; /**< TCP specific socket status information */ union {
T_PNAK_SOCK_TCP_LOCAL_STATUS_DATA
Tcp; /**< TCP specific socket status information */
/* UDP specific socket status information not existing */ /* UDP specific socket status information not existing */
} UseAs; } UseAs;
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IOC_GET_LOCAL_STATUS); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IOC_GET_LOCAL_STATUS);
/** @} */ /** @} */
...@@ -1055,20 +1183,30 @@ typedef struct _T_PNAK_SOCK_IOC_GET_LOCAL_STATUS ...@@ -1055,20 +1183,30 @@ typedef struct _T_PNAK_SOCK_IOC_GET_LOCAL_STATUS
* Send Status of a socket * Send Status of a socket
* @{ * @{
*/ */
#define SOCK_SEND_STATUS_NOT_BUSY 0x00000001uL /**< No send request produced by the application */ #define SOCK_SEND_STATUS_NOT_BUSY \
#define SOCK_SEND_STATUS_BUSY 0x00000002uL /**< The send request is in progress. */ 0x00000001uL /**< No send request produced by the application */
#define SOCK_SEND_STATUS_BUSY \
0x00000002uL /**< The send request is in progress. */
/** @} */ /** @} */
/** \anchor SendStatusCode @name Send Status Codes /** \anchor SendStatusCode @name Send Status Codes
* Send Error Codes * Send Error Codes
* @{ * @{
*/ */
#define SOCK_SEND_STATUS_CODE_NO_ERROR 0x00000000uL /**< No error detected */ #define SOCK_SEND_STATUS_CODE_NO_ERROR 0x00000000uL /**< No error detected */
#define SOCK_SEND_STATUS_CODE_NO_BUFFERS 0x00000001uL /**< The TCP/IP stack was unable to allocate an internal buffer or the output queue is full. */ #define SOCK_SEND_STATUS_CODE_NO_BUFFERS \
#define SOCK_SEND_STATUS_CODE_HOST_UNREACHABLE 0x00000002uL /**< The destination host is unreachable, e.g. the destination host is down */ 0x00000001uL /**< The TCP/IP stack was unable to allocate an internal buffer \
#define SOCK_SEND_STATUS_CODE_REJECTED 0x00000003uL /**< The destination host rejected the message, e.g. remote port is closed. or the output queue is full. */
This error can only be returned by TCP sockets. */ #define SOCK_SEND_STATUS_CODE_HOST_UNREACHABLE \
#define SOCK_SEND_STATUS_CODE_SEND_ERROR 0x00000004uL /**< The TCP/IP stack reported a general problem sending the message. */ 0x00000002uL /**< The destination host is unreachable, e.g. the destination \
host is down */
#define SOCK_SEND_STATUS_CODE_REJECTED \
0x00000003uL /**< The destination host rejected the message, e.g. remote \
port is closed. This error can only be returned by TCP \
sockets. */
#define SOCK_SEND_STATUS_CODE_SEND_ERROR \
0x00000004uL /**< The TCP/IP stack reported a general problem sending the \
message. */
/** @} */ /** @} */
/** @} */ /** @} */
...@@ -1078,9 +1216,10 @@ typedef struct _T_PNAK_SOCK_IOC_GET_LOCAL_STATUS ...@@ -1078,9 +1216,10 @@ typedef struct _T_PNAK_SOCK_IOC_GET_LOCAL_STATUS
*/ */
typedef struct _T_PNAK_SOCK_TCP_SEND_STATUS_DATA typedef struct _T_PNAK_SOCK_TCP_SEND_STATUS_DATA
{ {
T_PNAK_SOCK_ADDR RemoteAddr; /**< Address information of the remote connection partner */ T_PNAK_SOCK_ADDR
RemoteAddr; /**< Address information of the remote connection partner */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_TCP_SEND_STATUS_DATA); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_TCP_SEND_STATUS_DATA);
/** @} */ /** @} */
...@@ -1090,17 +1229,19 @@ typedef struct _T_PNAK_SOCK_TCP_SEND_STATUS_DATA ...@@ -1090,17 +1229,19 @@ typedef struct _T_PNAK_SOCK_TCP_SEND_STATUS_DATA
*/ */
typedef struct _T_PNAK_SOCK_IOC_GET_SEND_STATUS typedef struct _T_PNAK_SOCK_IOC_GET_SEND_STATUS
{ {
PN_U32 Status; /**< Common send status information. Valid values: \ref SendStatus */ PN_U32 Status; /**< Common send status information. Valid values: \ref
PN_U32 StatusCode; /**< Common send error code. Valid values: \ref SendStatusCode */ SendStatus */
PN_U32 StatusCode; /**< Common send error code. Valid values: \ref
union SendStatusCode */
{
T_PNAK_SOCK_TCP_SEND_STATUS_DATA Tcp; /**< TCP specific send status information */ union {
T_PNAK_SOCK_TCP_SEND_STATUS_DATA
Tcp; /**< TCP specific send status information */
/* UDP specific send status information not existing */ /* UDP specific send status information not existing */
} UseAs; } UseAs;
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IOC_GET_SEND_STATUS); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IOC_GET_SEND_STATUS);
/** @} */ /** @} */
...@@ -1112,15 +1253,21 @@ typedef struct _T_PNAK_SOCK_IOC_GET_SEND_STATUS ...@@ -1112,15 +1253,21 @@ typedef struct _T_PNAK_SOCK_IOC_GET_SEND_STATUS
* Receive Status of a socket * Receive Status of a socket
* @{ * @{
*/ */
#define SOCK_RECEIVE_STATUS_NO_DATA_RECEIVED 0x00000000uL /**< No data on the specfied socket or TCP connection has been received. */ #define SOCK_RECEIVE_STATUS_NO_DATA_RECEIVED \
#define SOCK_RECEIVE_STATUS_DATA_RECEIVED 0x00000001uL /**< New data has been received on the specfied socket or TCP connection. */ 0x00000000uL /**< No data on the specfied socket or TCP connection has been \
received. */
#define SOCK_RECEIVE_STATUS_DATA_RECEIVED \
0x00000001uL /**< New data has been received on the specfied socket or TCP \
connection. */
/** @} */ /** @} */
/** \anchor ReceiveStatusCode @name Receive Status Codes /** \anchor ReceiveStatusCode @name Receive Status Codes
* Receive Error Codes * Receive Error Codes
* @{ * @{
*/ */
#define SOCK_RECEIVE_STATUS_CODE_NO_ERROR 0x00000000uL /**< No error detected */ #define SOCK_RECEIVE_STATUS_CODE_NO_ERROR \
0x00000000uL /**< No error detected \
*/
/** @} */ /** @} */
/** @} */ /** @} */
...@@ -1130,9 +1277,10 @@ typedef struct _T_PNAK_SOCK_IOC_GET_SEND_STATUS ...@@ -1130,9 +1277,10 @@ typedef struct _T_PNAK_SOCK_IOC_GET_SEND_STATUS
*/ */
typedef struct _T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA typedef struct _T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA
{ {
T_PNAK_SOCK_ADDR RemoteAddr; /**< Address information of the remote connection partner */ T_PNAK_SOCK_ADDR
RemoteAddr; /**< Address information of the remote connection partner */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA);
/** @} */ /** @} */
...@@ -1142,17 +1290,19 @@ typedef struct _T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA ...@@ -1142,17 +1290,19 @@ typedef struct _T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA
*/ */
typedef struct _T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS typedef struct _T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS
{ {
PN_U32 Status; /**< Common receive status information. Valid values: \ref ReceiveStatus */ PN_U32 Status; /**< Common receive status information. Valid values: \ref
PN_U32 StatusCode; /**< Common receive error code. Valid values: \ref ReceiveStatusCode */ ReceiveStatus */
PN_U32 StatusCode; /**< Common receive error code. Valid values: \ref
union ReceiveStatusCode */
{
T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA Tcp; /**< TCP specific receive status information */ union {
T_PNAK_SOCK_TCP_RECEIVE_STATUS_DATA
Tcp; /**< TCP specific receive status information */
/* UDP specific send status information not existing */ /* UDP specific send status information not existing */
} UseAs; } UseAs;
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS);
/** @} */ /** @} */
...@@ -1164,28 +1314,30 @@ typedef struct _T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS ...@@ -1164,28 +1314,30 @@ typedef struct _T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS
*/ */
typedef struct _T_PNAK_SOCK_IOC_CLOSE_TCP_CONNECTION typedef struct _T_PNAK_SOCK_IOC_CLOSE_TCP_CONNECTION
{ {
T_PNAK_SOCK_ADDR RemoteAddr; /**< Address information of the remote connection partner */ T_PNAK_SOCK_ADDR
RemoteAddr; /**< Address information of the remote connection partner */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IOC_CLOSE_TCP_CONNECTION); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IOC_CLOSE_TCP_CONNECTION);
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define SOCK_MAX_NUMBER_FILTER_ENTRIES 4u #define SOCK_MAX_NUMBER_FILTER_ENTRIES 4u
/** \addtogroup sock_structures Data Structures /** \addtogroup sock_structures Data Structures
* @{ * @{
* \brief This structure specifies the IP addresses from which a connection establishment shall be accepted * \brief This structure specifies the IP addresses from which a connection
* establishment shall be accepted
*/ */
typedef struct _T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER typedef struct _T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER
{ {
PN_U16 NumberEntries; /**< number of filter entries */ PN_U16 NumberEntries; /**< number of filter entries */
PN_U16 Alignment; PN_U16 Alignment;
PN_U32 Filter [SOCK_MAX_NUMBER_FILTER_ENTRIES]; /**< IP address */ PN_U32 Filter[SOCK_MAX_NUMBER_FILTER_ENTRIES]; /**< IP address */
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER);
/** @} */ /** @} */
...@@ -1193,13 +1345,14 @@ typedef struct _T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER ...@@ -1193,13 +1345,14 @@ typedef struct _T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER
/** \addtogroup sock_structures Data Structures /** \addtogroup sock_structures Data Structures
* @{ * @{
* \brief This structure specifies the IP addresses of the multicast group the application wants to join or leave * \brief This structure specifies the IP addresses of the multicast group the
* application wants to join or leave
*/ */
typedef struct _T_PNAK_SOCK_IOC_MULTICAST typedef struct _T_PNAK_SOCK_IOC_MULTICAST
{ {
PN_U32 IpAddress; PN_U32 IpAddress;
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IOC_MULTICAST); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IOC_MULTICAST);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
...@@ -1209,13 +1362,20 @@ typedef struct _T_PNAK_SOCK_IOC_MULTICAST ...@@ -1209,13 +1362,20 @@ typedef struct _T_PNAK_SOCK_IOC_MULTICAST
* IO Control Commands for a socket * IO Control Commands for a socket
* @{ * @{
*/ */
#define SOCK_IOC_GET_LOCAL_STATUS 0x00000001uL /**< Get the local socket status */ #define SOCK_IOC_GET_LOCAL_STATUS \
#define SOCK_IOC_GET_SEND_STATUS 0x00000002uL /**< Get the status of a send request */ 0x00000001uL /**< Get the local socket status */
#define SOCK_IOC_GET_RECEIVE_STATUS 0x00000003uL /**< Checks if new data has been received */ #define SOCK_IOC_GET_SEND_STATUS \
#define SOCK_IOC_CLOSE_TCP_CONNECTION 0x00000004uL /**< Closes a TCP connection */ 0x00000002uL /**< Get the status of a send request */
#define SOCK_IOC_TCP_ACCEPT_FILTER 0x00000005uL /**< Defines which IP Addresses are accepted by the socket */ #define SOCK_IOC_GET_RECEIVE_STATUS \
#define SOCK_IOC_UDP_ADD_MULTICAST 0x00000006uL /**< Join a multicast group */ 0x00000003uL /**< Checks if new data has been received */
#define SOCK_IOC_UDP_DEL_MULTICAST 0x00000007uL /**< Leave a multicast group */ #define SOCK_IOC_CLOSE_TCP_CONNECTION \
0x00000004uL /**< Closes a TCP connection */
#define SOCK_IOC_TCP_ACCEPT_FILTER \
0x00000005uL /**< Defines which IP Addresses are accepted by the socket */
#define SOCK_IOC_UDP_ADD_MULTICAST 0x00000006uL /**< Join a multicast group */
#define SOCK_IOC_UDP_DEL_MULTICAST \
0x00000007uL /**< Leave a multicast group \
*/
/** @} */ /** @} */
/** @} */ /** @} */
...@@ -1225,21 +1385,27 @@ typedef struct _T_PNAK_SOCK_IOC_MULTICAST ...@@ -1225,21 +1385,27 @@ typedef struct _T_PNAK_SOCK_IOC_MULTICAST
*/ */
typedef struct _T_PNAK_SOCK_IO_CONTROL typedef struct _T_PNAK_SOCK_IO_CONTROL
{ {
PN_U32 Command; /**< Specifies the IO Control Command. Valid values: \ref IoctlCommand */ PN_U32 Command; /**< Specifies the IO Control Command. Valid values: \ref
IoctlCommand */
union
{ union {
T_PNAK_SOCK_IOC_GET_LOCAL_STATUS GetLocalStatus; /**< Local Socket Status informations */ T_PNAK_SOCK_IOC_GET_LOCAL_STATUS
T_PNAK_SOCK_IOC_GET_SEND_STATUS GetSendStatus; /**< Send Status informations */ GetLocalStatus; /**< Local Socket Status informations */
T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS GetReceiveStatus; /**< Receive Status informations */ T_PNAK_SOCK_IOC_GET_SEND_STATUS
T_PNAK_SOCK_IOC_CLOSE_TCP_CONNECTION CloseTcpConnection; /**< TCP connection which shall be closed */ GetSendStatus; /**< Send Status informations */
T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER TcpAcceptFilter; /**< IP Address which shall be able to connect to the server */ T_PNAK_SOCK_IOC_GET_RECEIVE_STATUS
T_PNAK_SOCK_IOC_MULTICAST AddMulticast; /**< Multicast group to join */ GetReceiveStatus; /**< Receive Status informations */
T_PNAK_SOCK_IOC_MULTICAST DelMulticast; /**< Multicast group to leave */ T_PNAK_SOCK_IOC_CLOSE_TCP_CONNECTION
CloseTcpConnection; /**< TCP connection which shall be closed */
T_PNAK_SOCK_IOC_TCP_ACCEPT_FILTER
TcpAcceptFilter; /**< IP Address which shall be able to connect to the
server */
T_PNAK_SOCK_IOC_MULTICAST AddMulticast; /**< Multicast group to join */
T_PNAK_SOCK_IOC_MULTICAST DelMulticast; /**< Multicast group to leave */
} UseAs; } UseAs;
} PACK_WORD_ALIGNMENT (T_PNAK_SOCK_IO_CONTROL); } PACK_WORD_ALIGNMENT(T_PNAK_SOCK_IO_CONTROL);
/** @} */ /** @} */
...@@ -1248,32 +1414,40 @@ FUNCTION DECLARATION ...@@ -1248,32 +1414,40 @@ FUNCTION DECLARATION
******************************************************************************/ ******************************************************************************/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef __DOXYGEN__ #ifndef __DOXYGEN__
/*--- initialization/termination functions ----------------------------------*/ /*--- initialization/termination functions ----------------------------------*/
extern T_SOCKET_RESULT pnak_sock_init (unsigned short, T_PNAK_SOCK_INIT*); extern T_SOCKET_RESULT pnak_sock_init(unsigned short, T_PNAK_SOCK_INIT*);
extern T_SOCKET_RESULT pnak_sock_term (unsigned short); extern T_SOCKET_RESULT pnak_sock_term(unsigned short);
/*--- socket interface functions --------------------------------------------*/ /*--- socket interface functions --------------------------------------------*/
extern T_SOCKET_RESULT pnak_sock_create (unsigned short, PN_U32, T_PNAK_SOCK_ADDR*, T_PNAK_SOCK_ADDR*, unsigned short*); extern T_SOCKET_RESULT pnak_sock_create(unsigned short, PN_U32,
extern T_SOCKET_RESULT pnak_sock_close (unsigned short, unsigned short); T_PNAK_SOCK_ADDR*, T_PNAK_SOCK_ADDR*,
extern T_SOCKET_RESULT pnak_sock_send (unsigned short, unsigned short, T_PNAK_SOCK_ADDR*, PN_U16, const unsigned char*); unsigned short*);
extern T_SOCKET_RESULT pnak_sock_receive (unsigned short, unsigned short, T_PNAK_SOCK_ADDR*, PN_U16*, unsigned char*); extern T_SOCKET_RESULT pnak_sock_close(unsigned short, unsigned short);
extern T_SOCKET_RESULT pnak_sock_ioctl (unsigned short, unsigned short, T_PNAK_SOCK_IO_CONTROL*); extern T_SOCKET_RESULT pnak_sock_send(unsigned short, unsigned short,
T_PNAK_SOCK_ADDR*, PN_U16,
const unsigned char*);
extern T_SOCKET_RESULT pnak_sock_receive(unsigned short, unsigned short,
T_PNAK_SOCK_ADDR*, PN_U16*,
unsigned char*);
extern T_SOCKET_RESULT pnak_sock_ioctl(unsigned short, unsigned short,
T_PNAK_SOCK_IO_CONTROL*);
/*--- socket interface helper functions -------------------------------------*/ /*--- socket interface helper functions -------------------------------------*/
extern T_SOCKET_RESULT pnak_sock_get_receive_status (unsigned short, T_BITSET_64*); extern T_SOCKET_RESULT pnak_sock_get_receive_status(unsigned short,
T_BITSET_64*);
#endif /* __DOXYGEN__ */ #endif /* __DOXYGEN__ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* SCAI_INCLUDE_SOCKET || SDAI_INCLUDE_SOCKET */ #endif /* SCAI_INCLUDE_SOCKET || SDAI_INCLUDE_SOCKET */
...@@ -1281,18 +1455,18 @@ extern T_SOCKET_RESULT pnak_sock_get_receive_status (unsigned shor ...@@ -1281,18 +1455,18 @@ extern T_SOCKET_RESULT pnak_sock_get_receive_status (unsigned shor
/*****************************************************************************/ /*****************************************************************************/
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
#pragma warning (disable : 4103) /* used #pragma pack to reset alignment */ #pragma warning(disable : 4103) /* used #pragma pack to reset alignment */
#pragma pack(pop) #pragma pack(pop)
#pragma warning (default : 4103) #pragma warning(default : 4103)
#elif defined __GNUC__ #elif defined __GNUC__
/* nothing to do */ /* nothing to do */
#elif defined _OS9000 #elif defined _OS9000
/* nothing to do */ /* nothing to do */
#else #else
#error CAUTION: set default structure alignment #error CAUTION: set default structure alignment
#endif #endif
/*****************************************************************************/ /*****************************************************************************/
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2019 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* SOFTING AG */ /* SOFTING AG */
......
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