Commit 93679d5b authored by Claes Sjofors's avatar Claes Sjofors

Event arg added to swap IO method, new event for emergency break

parent ed0522fc
......@@ -107,7 +107,8 @@ static pwr_tStatus IoAgentClose (
);
static pwr_tStatus IoAgentSwap (
io_tCtx ctx,
io_sAgent *ap
io_sAgent *ap,
io_eEvent event
);
......@@ -784,9 +785,14 @@ static pwr_tStatus IoAgentInit (
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoAgentSwap (
io_tCtx ctx,
io_sAgent *ap
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;
......@@ -813,6 +819,14 @@ static pwr_tStatus IoAgentSwap (
return IO__ERRINIDEVICE;
}
}
break;
}
case io_eEvent_EmergencyBreak:
case io_eEvent_IoCommEmergencyBreak:
IoAgentClose( ctx, ap);
break;
}
return IO__SUCCESS;
}
......
......@@ -405,6 +405,7 @@ struct sLocal {
sNodeInfo nodeDb[cNodes];
pwr_tBoolean outunitServer;
pwr_sClass_IOHandler *iohp;
pwr_sNode *nodep;
};
/* Global variables */
......@@ -1253,6 +1254,7 @@ cSup_exec (
o->DelayNoted = TRUE;
if (o->DelayAction == 2) {
l.iohp->IOReadWriteFlag = FALSE;
l.nodep->EmergBreakTrue = TRUE;
errh_SetStatus( MH__IOSTALLED);
}
}
......@@ -1996,6 +1998,7 @@ getHandlerObject ()
pwr_sAttrRef aref;
pwr_tDlid dlid;
pwr_tBoolean created = FALSE;
pwr_tOid node_oid;
sts = gdh_GetClassList(pwr_eClass_Node, &nodeOid);
if (EVEN(sts)) {
......@@ -2100,6 +2103,13 @@ getHandlerObject ()
l.iohp = NULL;
gdh_ObjidToPointer(oid, (void *) &l.iohp);
sts = gdh_GetNodeObject( 0, &node_oid);
if (ODD(sts))
sts = gdh_ObjidToPointer( node_oid, (void **)&l.nodep);
if (EVEN(sts)) {
errh_Fatal("No node object found\n%m", sts);
exit(sts);
}
}
static mh_eAgent
......
......@@ -70,7 +70,7 @@
EVENT io_comm_terminate;
#endif
static pwr_sClass_IOHandler* init(qcom_sQid*, lst_sEntry**);
static pwr_sClass_IOHandler* init(qcom_sQid*, lst_sEntry**, pwr_sNode**);
static void usage()
{
......@@ -100,6 +100,8 @@ int main (int argc, char **argv)
pwr_tDeltaTime cycle;
lst_sEntry *csup_lh;
int delay_action = 0;
pwr_sNode *nodep;
pwr_tBoolean old_emergency_break = 0;
if ( argc > 1) {
if ( strcmp( argv[1], "-m") == 0) {
......@@ -112,7 +114,7 @@ int main (int argc, char **argv)
}
}
ihp = init(&qid, &csup_lh);
ihp = init(&qid, &csup_lh, &nodep);
plc_UtlWaitForPlc();
......@@ -147,12 +149,27 @@ int main (int argc, char **argv)
qcom_Get(&sts,&qid, &get, tmo);
if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
if ( nodep->EmergBreakTrue && !old_emergency_break)
sts = io_swap(io_ctx_swap, io_eEvent_IoCommEmergencyBreak);
sts = io_read(io_ctx);
if (EVEN(sts)) {
ihp->IOReadWriteFlag = FALSE;
errh_Error("IO read, %m", sts);
}
sts = io_write(io_ctx);
if (EVEN(sts)) {
ihp->IOReadWriteFlag = FALSE;
errh_Error("IO write, %m", sts);
}
if ( nodep->EmergBreakTrue && !old_emergency_break)
sts = io_swap(io_ctx, io_eEvent_EmergencyBreak);
old_emergency_break = nodep->EmergBreakTrue;
if (swap_io)
{
sts = io_swap(io_ctx_swap);
sts = io_swap(io_ctx_swap, io_eEvent_IoCommSwap);
}
io_ScanSupLst( io_ctx->SupCtx);
......@@ -193,13 +210,14 @@ int main (int argc, char **argv)
}
static pwr_sClass_IOHandler *
init (qcom_sQid *qid, lst_sEntry **csup_lh)
init (qcom_sQid *qid, lst_sEntry **csup_lh, pwr_sNode **nodep)
{
pwr_tStatus sts = 1;
pwr_sClass_IOHandler *ihp;
qcom_sQattr qAttr;
qcom_sQid qini;
pwr_tObjid oid;
pwr_tOid oid;
pwr_tOid node_oid;
errh_Init("pwr_io", errh_eAnix_io);
......@@ -238,6 +256,18 @@ init (qcom_sQid *qid, lst_sEntry **csup_lh)
exit(sts);
}
sts = gdh_GetNodeObject( 0, &node_oid);
if (EVEN(sts)) {
errh_Fatal("rt_io_comm aborted, no node object found\n%m", sts);
exit(sts);
}
sts = gdh_ObjidToPointer( node_oid, (void **)nodep);
if (EVEN(sts)) {
errh_Fatal("rt_io_comm aborted, no node object found\n%m", sts);
exit(sts);
}
aproc_RegisterObject( oid);
*csup_lh = csup_Init(&sts, oid, ihp->CycleTimeBus);
......
......@@ -2143,7 +2143,7 @@ static pwr_tStatus io_init_agent(
io_tCtx ctx,
void *dummy,
int agent_type,
int swap)
int iocomm_swap)
{
pwr_tStatus sts;
pwr_tClassId class;
......@@ -2181,7 +2181,7 @@ static pwr_tStatus io_init_agent(
strcat( attrname, ".Process");
sts = gdh_GetObjectInfo( attrname, &process, sizeof(process));
if (( EVEN(sts) ||
(ODD(sts) && ctx->Process & process)) && !swap) {
(ODD(sts) && ctx->Process & process)) && !iocomm_swap) {
if ( EVEN(sts))
process = io_mProcess_All;
if ( ctx->Process == io_mProcess_Profibus)
......@@ -2199,7 +2199,7 @@ static pwr_tStatus io_init_agent(
else
ok = 1;
}
else if (ODD(sts) && swap && AgentSwap != NULL) {
else if (ODD(sts) && iocomm_swap && AgentSwap != NULL) {
/* IoComm-process should always handle the Swap-method */
ok = 1;
}
......@@ -2213,11 +2213,13 @@ static pwr_tStatus io_init_agent(
ap->Objid = objid;
strcpy( ap->Name, aname);
ap->Process = process;
if (!swap) {
if (!iocomm_swap) {
if ( AgentRead != NULL)
ap->Action |= io_mAction_Read;
if ( AgentWrite != NULL)
ap->Action |= io_mAction_Write;
if ( AgentSwap != NULL)
ap->Action |= io_mAction_Swap;
ap->Init = AgentInit;
ap->Close = AgentClose;
ap->Read = AgentRead;
......@@ -2252,7 +2254,7 @@ static pwr_tStatus io_init_agent(
alp->next = ap;
}
sts = io_trv_child( objid, 0, io_init_rack, ctx, ap, agent_type, swap);
sts = io_trv_child( objid, 0, io_init_rack, ctx, ap, agent_type, iocomm_swap);
}
}
}
......@@ -2646,7 +2648,7 @@ pwr_tStatus io_init_swap (
{
if (ap->Action & io_mAction_Swap)
{
sts = (ap->Swap) ( *ctx, ap);
sts = (ap->Swap) ( *ctx, ap, io_eEvent_IoCommSwapInit);
if ( EVEN(sts)) return sts;
}
}
......@@ -2798,59 +2800,42 @@ pwr_tStatus io_write(
Swap io racks and cards.
\*----------------------------------------------------------------------------*/
pwr_tStatus io_swap(
io_tCtx ctx)
io_tCtx ctx,
io_eEvent event)
{
pwr_tStatus sts;
io_sAgent *ap;
io_sRack *rp;
io_sCard *cp;
switch ( event) {
case io_eEvent_EmergencyBreak:
case io_eEvent_IoCommEmergencyBreak:
break;
default:
if ( ctx->Node->EmergBreakTrue || !ctx->IOHandler->IOReadWriteFlag)
return IO__IS_STOPPED;
}
/* Call the read methods for agents, racks and cards */
for ( ap = ctx->agentlist; ap != NULL; ap = ap->next)
{
if (ap->Action & io_mAction_Swap)
{
if ( ap->scan_interval_cnt <= 1)
{
sts = (ap->Swap) ( ctx, ap);
for ( ap = ctx->agentlist; ap != NULL; ap = ap->next) {
if (ap->Action & io_mAction_Swap) {
sts = (ap->Swap) ( ctx, ap, event);
if ( EVEN(sts)) return sts;
ap->scan_interval_cnt = ap->scan_interval;
}
else
ap->scan_interval_cnt--;
}
for ( rp = ap->racklist; rp != NULL; rp = rp->next)
{
for ( rp = ap->racklist; rp != NULL; rp = rp->next) {
if (rp->Action & io_mAction_Swap &&
!rp->MethodDisabled)
{
if ( rp->scan_interval_cnt <= 1)
{
sts = (rp->Swap) ( ctx, ap, rp);
!rp->MethodDisabled) {
sts = (rp->Swap) ( ctx, ap, rp, event);
if ( EVEN(sts)) return sts;
rp->scan_interval_cnt = rp->scan_interval;
}
else
rp->scan_interval_cnt--;
}
for ( cp = rp->cardlist; cp != NULL; cp = cp->next)
{
for ( cp = rp->cardlist; cp != NULL; cp = cp->next) {
if (cp->Action & io_mAction_Swap &&
!cp->MethodDisabled)
{
if ( cp->scan_interval_cnt <= 1)
{
sts = (cp->Swap) ( ctx, ap, rp, cp);
!cp->MethodDisabled) {
sts = (cp->Swap) ( ctx, ap, rp, cp, event);
if ( EVEN(sts)) return sts;
cp->scan_interval_cnt = cp->scan_interval;
}
else
cp->scan_interval_cnt--;
}
}
}
......
......@@ -105,6 +105,13 @@ typedef enum {
io_mProcess_All = ~0
} io_mProcess;
typedef enum {
io_eEvent_EmergencyBreak,
io_eEvent_IoCommEmergencyBreak,
io_eEvent_IoCommSwapInit,
io_eEvent_IoCommSwap
} io_eEvent;
typedef struct {
void *cop; /* Pointer to channel object */
pwr_tDlid ChanDlid; /* Dlid for pointer to channel */
......@@ -245,7 +252,8 @@ pwr_tStatus io_write(
);
pwr_tStatus io_swap(
io_tCtx ctx
io_tCtx ctx,
io_eEvent event
);
pwr_tStatus io_close(
......
......@@ -172,6 +172,7 @@ struct plc_sThread {
io_tCtx plc_io_ctx;
pwr_tBoolean first_scan;
int skip_count;
pwr_tBoolean emergency_break_old;
};
struct plc_sProcess {
......
......@@ -250,6 +250,9 @@ scan (
errh_SetStatus( PLC__IOREAD);
}
}
if ( pp->Node->EmergBreakTrue && !tp->emergency_break_old)
io_swap(tp->plc_io_ctx, io_eEvent_EmergencyBreak);
tp->emergency_break_old = pp->Node->EmergBreakTrue;
thread_MutexLock(&pp->io_copy_mutex);
......@@ -307,6 +310,7 @@ scan (
delay_action = csup_Exec(&sts, tp->csup_lh, (pwr_tDeltaTime *) &tp->sync_time, (pwr_tDeltaTime *) &tp->after_scan, &now);
if (delay_action == 2) {
pp->IOHandler->IOReadWriteFlag = FALSE;
pp->Node->EmergBreakTrue = TRUE;
errh_SetStatus( PLC__IOSTALLED);
}
}
......
......@@ -84,11 +84,16 @@ static pwr_tStatus IoRackInit (
static pwr_tStatus IoRackSwap (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp
io_sRack *rp,
io_eEvent event
)
{
io_sRackLocal *local;
switch ( event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap:
if (!rp->Local) {
/* Open Qbus driver */
local = calloc( 1, sizeof(*local));
......@@ -103,6 +108,9 @@ static pwr_tStatus IoRackSwap (
errh_Info( "Swap init of IO rack %s", rp->Name);
}
default: ;
}
return 1;
}
......
......@@ -278,7 +278,8 @@ static pwr_tStatus IoCardSwap (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
io_sCard *cp,
io_eEvent event
)
{
io_sLocal *local;
......@@ -289,6 +290,9 @@ static pwr_tStatus IoCardSwap (
qbus_io_read rb;
int sts;
switch ( event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap:
op = (pwr_sClass_Ssab_BaseDoCard *) cp->op;
if (!cp->Local) {
......@@ -300,8 +304,7 @@ static pwr_tStatus IoCardSwap (
local->Qbus_fp = ((io_sRackLocal *)(rp->Local))->Qbus_fp;
}
for ( i = 0; i < 2; i++)
{
for ( i = 0; i < 2; i++) {
if (r_local->Qbus_fp != 0 && r_local->s == 0) {
/* Write to local Q-bus */
rb.Address = local->Address[i];
......@@ -315,6 +318,9 @@ static pwr_tStatus IoCardSwap (
sts = 1;
}
}
break;
default: ;
}
return 1;
}
......
......@@ -209,7 +209,9 @@ static pwr_tStatus IoRackInit (
static pwr_tStatus IoRackSwap (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp
io_sRack *rp,
io_eEvent event
)
{
io_sRackLocal *local;
......@@ -220,6 +222,10 @@ static pwr_tStatus IoRackSwap (
struct bfb_buf rbuf;
int size;
switch ( event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap:
if (!rp->Local) {
sts = IoRackInitSwap(ctx, ap, rp);
......@@ -258,6 +264,9 @@ static pwr_tStatus IoRackSwap (
op->RX_packets++;
}
}
break;
default: ;
}
return IO__SUCCESS;
......
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