Commit 39f8971d authored by claes's avatar claes

Merge branch 'master' of 62.20.65.89:/data1/git/pwr

parents 8135fea8 93679d5b
......@@ -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,36 +785,49 @@ static pwr_tStatus IoAgentInit (
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoAgentSwap (
io_tCtx ctx,
io_sAgent *ap
io_sAgent *ap,
io_eEvent event
)
{
pwr_sClass_Pb_Profiboard *op;
char DeviceName[64];
io_sAgentLocal *local;
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;
}
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);
local = (io_sAgentLocal *) ap->Local;
errh_Info( "Swap init interface for Profibus DP Master %s", ap->Name);
op = (pwr_sClass_Pb_Profiboard *) ap->op;
op = (pwr_sClass_Pb_Profiboard *) ap->op;
sprintf(DeviceName, "/dev/pbboard%u", op->BusNumber - 1);
local->hDpsBoardDevice = open(DeviceName, O_RDONLY | O_NONBLOCK);
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;
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;
}
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)) {
......@@ -2099,7 +2102,14 @@ 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();
......@@ -146,13 +148,28 @@ int main (int argc, char **argv)
get.data = mp;
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;
if ( ctx->Node->EmergBreakTrue || !ctx->IOHandler->IOReadWriteFlag)
return IO__IS_STOPPED;
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);
if ( EVEN(sts)) return sts;
ap->scan_interval_cnt = ap->scan_interval;
}
else
ap->scan_interval_cnt--;
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;
}
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);
if ( EVEN(sts)) return sts;
rp->scan_interval_cnt = rp->scan_interval;
}
else
rp->scan_interval_cnt--;
!rp->MethodDisabled) {
sts = (rp->Swap) ( ctx, ap, rp, event);
if ( EVEN(sts)) return sts;
}
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);
if ( EVEN(sts)) return sts;
cp->scan_interval_cnt = cp->scan_interval;
}
else
cp->scan_interval_cnt--;
!cp->MethodDisabled) {
sts = (cp->Swap) ( ctx, ap, rp, cp, event);
if ( EVEN(sts)) return sts;
}
}
}
......
......@@ -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,25 +84,33 @@ 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;
if (!rp->Local) {
/* Open Qbus driver */
local = calloc( 1, sizeof(*local));
rp->Local = local;
local->Qbus_fp = open("/dev/qbus", O_RDWR);
if ( local->Qbus_fp == -1)
{
errh_Error( "Qbus swap initialization error, IO rack %s", rp->Name);
return IO__ERRDEVICE;
switch ( event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap:
if (!rp->Local) {
/* Open Qbus driver */
local = calloc( 1, sizeof(*local));
rp->Local = local;
local->Qbus_fp = open("/dev/qbus", O_RDWR);
if ( local->Qbus_fp == -1)
{
errh_Error( "Qbus swap initialization error, IO rack %s", rp->Name);
return IO__ERRDEVICE;
}
errh_Info( "Swap init of IO rack %s", rp->Name);
}
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,32 +290,37 @@ static pwr_tStatus IoCardSwap (
qbus_io_read rb;
int sts;
op = (pwr_sClass_Ssab_BaseDoCard *) cp->op;
if (!cp->Local) {
local = calloc( 1, sizeof(*local));
cp->Local = local;
switch ( event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap:
op = (pwr_sClass_Ssab_BaseDoCard *) cp->op;
local->Address[0] = op->RegAddress;
local->Address[1] = op->RegAddress + 2;
local->Qbus_fp = ((io_sRackLocal *)(rp->Local))->Qbus_fp;
}
if (!cp->Local) {
local = calloc( 1, sizeof(*local));
cp->Local = local;
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];
sts = read( local->Qbus_fp, &rb, sizeof(rb));
}
else {
/* Ethernet I/O, Get data from current address */
data = bfbeth_get_data(r_local, (pwr_tUInt16) local->Address[i], &sts);
/* Yes, we want to read this address the next time aswell */
bfbeth_set_read_req(r_local, (pwr_tUInt16) local->Address[i]);
sts = 1;
local->Address[0] = op->RegAddress;
local->Address[1] = op->RegAddress + 2;
local->Qbus_fp = ((io_sRackLocal *)(rp->Local))->Qbus_fp;
}
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];
sts = read( local->Qbus_fp, &rb, sizeof(rb));
}
else {
/* Ethernet I/O, Get data from current address */
data = bfbeth_get_data(r_local, (pwr_tUInt16) local->Address[i], &sts);
/* Yes, we want to read this address the next time aswell */
bfbeth_set_read_req(r_local, (pwr_tUInt16) local->Address[i]);
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,44 +222,51 @@ static pwr_tStatus IoRackSwap (
struct bfb_buf rbuf;
int size;
if (!rp->Local) {
switch ( event) {
case io_eEvent_IoCommSwapInit:
case io_eEvent_IoCommSwap:
sts = IoRackInitSwap(ctx, ap, rp);
if (sts != IO__SUCCESS)
return IO__ERRINIDEVICE;
}
local = (io_sRackLocal *) rp->Local;
op = (pwr_sClass_Ssab_RemoteRack *) rp->op;
// Calc length and send read request
local->read_req.service = BFB_SERVICE_READ;
local->read_req.length = local->next_read_req_item*4 + 4;
sts = send(local->s, &local->read_req, local->read_req.length, 0);
op->TX_packets++;
local->next_read_req_item = 0;
bzero(&local->read_area, sizeof(local->read_area));
if (!rp->Local) {
sts = 1;
while (sts > 0) {
FD_ZERO(&fds);
FD_SET(local->s, &fds);
tv.tv_sec = 0;
tv.tv_usec = 0;
sts = select(32, &fds, NULL, NULL, &tv);
if (sts > 0) {
size = recv(local->s, &rbuf, sizeof(rbuf), 0);
if (rbuf.service == BFB_SERVICE_READ) {
bzero(&local->read_area, sizeof(local->read_area));
memcpy(&local->read_area, &rbuf, size);
}
else if (rbuf.service == BFB_SERVICE_WRITE) {
bzero(&local->write_area, sizeof(local->write_area));
memcpy(&local->write_area, &rbuf, size);
}
op->RX_packets++;
sts = IoRackInitSwap(ctx, ap, rp);
if (sts != IO__SUCCESS)
return IO__ERRINIDEVICE;
}
}
local = (io_sRackLocal *) rp->Local;
op = (pwr_sClass_Ssab_RemoteRack *) rp->op;
// Calc length and send read request
local->read_req.service = BFB_SERVICE_READ;
local->read_req.length = local->next_read_req_item*4 + 4;
sts = send(local->s, &local->read_req, local->read_req.length, 0);
op->TX_packets++;
local->next_read_req_item = 0;
bzero(&local->read_area, sizeof(local->read_area));
sts = 1;
while (sts > 0) {
FD_ZERO(&fds);
FD_SET(local->s, &fds);
tv.tv_sec = 0;
tv.tv_usec = 0;
sts = select(32, &fds, NULL, NULL, &tv);
if (sts > 0) {
size = recv(local->s, &rbuf, sizeof(rbuf), 0);
if (rbuf.service == BFB_SERVICE_READ) {
bzero(&local->read_area, sizeof(local->read_area));
memcpy(&local->read_area, &rbuf, size);
}
else if (rbuf.service == BFB_SERVICE_WRITE) {
bzero(&local->write_area, sizeof(local->write_area));
memcpy(&local->write_area, &rbuf, size);
}
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