Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
970b5281
Commit
970b5281
authored
Mar 16, 2020
by
Marcus Nordenberg
Committed by
Esteban Blanc
Dec 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
profinet: propagate state on stack shutdown
(cherry picked from commit 9497f8a92eed8c75f9c90d459a91ec693939b21f)
parent
e7b8508a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
82 deletions
+99
-82
profibus/lib/rt/src/rt_io_m_pncontrollersoftingpnak.cpp
profibus/lib/rt/src/rt_io_m_pncontrollersoftingpnak.cpp
+32
-21
profibus/lib/rt/src/rt_io_m_pndevice.cpp
profibus/lib/rt/src/rt_io_m_pndevice.cpp
+17
-11
profibus/lib/rt/src/rt_pn_iface.cpp
profibus/lib/rt/src/rt_pn_iface.cpp
+50
-50
No files found.
profibus/lib/rt/src/rt_io_m_pncontrollersoftingpnak.cpp
View file @
970b5281
...
...
@@ -301,8 +301,8 @@ static pwr_tStatus IoAgentWrite(io_tCtx ctx, io_sAgent* ap)
pack_write_req
(
&
local
->
service_req_res
,
local
->
device_data
[
ii
]
->
device_ref
,
&
sp
->
WriteReq
);
sts
=
pnak_send_service_req_res
(
0
,
&
local
->
service_req_res
);
errh_Info
(
"P
rofinet - Asynch
write, dev: %d"
,
local
->
device_data
[
ii
]
->
device_ref
);
errh_Info
(
"P
ROFINET: Async
write, dev: %d"
,
local
->
device_data
[
ii
]
->
device_ref
);
break
;
}
}
...
...
@@ -329,48 +329,59 @@ static pwr_tStatus IoAgentClose(io_tCtx ctx, io_sAgent* ap)
io_sAgentLocal
*
local
;
int
*
exitcodep
;
int
error
;
pwr_tStatus
sts
=
PB__NOTINIT
;
local
=
(
io_sAgentLocal
*
)
ap
->
Local
;
if
(
ctx
->
Node
->
EmergBreakTrue
==
1
)
errh_Fatal
(
"Emergency break detected shutting down PROFINET"
);
/* Stop profistack */
// Stop the supervision thread before shutting down PROFINET.
local
=
(
io_sAgentLocal
*
)
ap
->
Local
;
if
(
!
local
)
return
IO__SUCCESS
;
if
((
error
=
pthread_cancel
(
local
->
handle_events
)))
errh_Warning
(
"Unsuccessful cancelation of PROFINET supervision thread"
);
else
errh_Info
(
"Canceled PROFINET supervision thread"
);
// Start taking the stack down. A PNAK_WAIT_OBJECT_CHANNEL_CLOSED event will
// be emitted and the supervision thread will exit
pnak_stop_stack
(
0
);
// Wait for the thread to exit
if
((
error
=
pthread_join
(
local
->
handle_events
,
(
void
**
)
&
exitcodep
)))
errh_Warning
(
"
Unable to wait for PROFINET thread! Might cause undefined behaviour...
"
);
errh_Warning
(
"
PROFINET: Unable to wait for supervision thread!
"
);
else
errh_Info
(
"PROFINET supervision thread has exited. Stopping PROFINET..."
);
sts
=
pnak_stop_stack
(
0
);
pnak_term
();
errh_Info
(
"PROFINET: Supervision thread has exited. PROFINET stopped..."
);
free
(
local
);
local
=
NULL
;
/* Clean data areas .... */
return
sts
;
return
IO__SUCCESS
;
}
static
pwr_tStatus
IoAgentSwap
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_eEvent
event
)
{
switch
(
event
)
{
switch
(
event
)
{
// For now we just shut down regardless of what EmergBreakSelect says...safety
// first :)
case
io_eEvent_EmergencyBreak
:
case
io_eEvent_IoCommEmergencyBreak
:
errh_Fatal
(
"PROFINET: Emergency break detected! Shutting down PROFINET!"
);
IoAgentClose
(
ctx
,
ap
);
// TODO We need a complete overhaul of EmergencyBreakTrue / EmergBreakSelect
// / IOReadWriteFlag
// switch (ctx->Node->EmergBreakSelect)
// {
// case pwr_eEmergBreakSelectEnum_StopIO:
// case pwr_eEmergBreakSelectEnum_Reboot:
// errh_Fatal("PROFINET: Emergency break action (StopIO/Reboot) shutting
// down PROFINET"); IoAgentClose(ctx, ap); break;
// case pwr_eEmergBreakSelectEnum_NoAction:
// errh_Warning("PROFINET: Emergency break action (NoAction).
// Continuing..."); break;
// case pwr_eEmergBreakSelectEnum_FixedOutputValues:
// errh_Warning("PROFINET: Behaviour of FixedOutputValues should be
// configured on device level"); errh_Fatal("PROFINET: Emergency break
// action (Fixed Output Values)."); break;
// }
break
;
case
io_eEvent_IoCommEmergencyBreak
:
break
;
default:
break
;
...
...
profibus/lib/rt/src/rt_io_m_pndevice.cpp
View file @
970b5281
...
...
@@ -64,7 +64,7 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
pwr_sClass_ChanIo
*
chan_io
;
sts
=
gdh_ObjidToName
(
rp
->
Objid
,
(
char
*
)
&
name
,
sizeof
(
name
),
cdh_mNName
);
errh_Info
(
"
Init of Profinet Device and M
odules %s"
,
name
);
errh_Info
(
"
PROFINET: Init of device and m
odules %s"
,
name
);
op
=
(
pwr_sClass_PnDevice
*
)
rp
->
op
;
local
=
(
io_sPnRackLocal
*
)
rp
->
Local
;
...
...
@@ -255,14 +255,17 @@ static pwr_tStatus IoRackRead(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
sp
->
ErrorCount
++
;
}
if
(
sp
->
ErrorCount
==
sp
->
ErrorHardLimit
)
{
errh_Error
(
"IO Error hard limit reached on card '%s', stall action %d"
,
rp
->
Name
,
sp
->
StallAction
);
if
(
sp
->
ErrorCount
==
sp
->
ErrorHardLimit
)
{
errh_Error
(
"PROFINET: IO Error hard limit reached on device '%s', stall action %d"
,
rp
->
Name
,
sp
->
StallAction
);
ctx
->
IOHandler
->
CardErrorHardLimit
=
1
;
ctx
->
IOHandler
->
ErrorHardLimitObject
=
cdh_ObjidToAref
(
rp
->
Objid
);
sp
->
ErrorCount
++
;
}
else
if
(
sp
->
ErrorCount
==
sp
->
ErrorSoftLimit
)
{
errh_Error
(
"IO Error soft limit reached on card '%s'"
,
rp
->
Name
);
}
else
if
(
sp
->
ErrorCount
==
sp
->
ErrorSoftLimit
)
{
errh_Error
(
"PROFINET: IO Error soft limit reached on device '%s'"
,
rp
->
Name
);
ctx
->
IOHandler
->
CardErrorSoftLimit
=
1
;
ctx
->
IOHandler
->
ErrorSoftLimitObject
=
cdh_ObjidToAref
(
rp
->
Objid
);
sp
->
ErrorCount
++
;
...
...
@@ -297,14 +300,17 @@ static pwr_tStatus IoRackWrite(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
sp
->
ErrorCount
++
;
}
if
(
sp
->
ErrorCount
==
sp
->
ErrorHardLimit
)
{
errh_Error
(
"IO Error hard limit reached on card '%s', stall action %d"
,
rp
->
Name
,
sp
->
StallAction
);
if
(
sp
->
ErrorCount
==
sp
->
ErrorHardLimit
)
{
errh_Error
(
"PROFINET: IO Error hard limit reached on device '%s', stall action %d"
,
rp
->
Name
,
sp
->
StallAction
);
ctx
->
IOHandler
->
CardErrorHardLimit
=
1
;
ctx
->
IOHandler
->
ErrorHardLimitObject
=
cdh_ObjidToAref
(
rp
->
Objid
);
sp
->
ErrorCount
++
;
}
else
if
(
sp
->
ErrorCount
==
sp
->
ErrorSoftLimit
)
{
errh_Error
(
"IO Error soft limit reached on card '%s'"
,
rp
->
Name
);
}
else
if
(
sp
->
ErrorCount
==
sp
->
ErrorSoftLimit
)
{
errh_Error
(
"PROFINET: IO Error soft limit reached on device '%s'"
,
rp
->
Name
);
ctx
->
IOHandler
->
CardErrorSoftLimit
=
1
;
ctx
->
IOHandler
->
ErrorSoftLimitObject
=
cdh_ObjidToAref
(
rp
->
Objid
);
sp
->
ErrorCount
++
;
...
...
profibus/lib/rt/src/rt_pn_iface.cpp
View file @
970b5281
...
...
@@ -1852,7 +1852,7 @@ void handle_device_state_changed(io_sAgentLocal* local, io_sAgent* ap)
else
dev
->
Status
=
PB__NOCONN
;
errh_Info
(
"P
rofinet -
New device state, dev: %s, state: %d"
,
errh_Info
(
"P
ROFINET:
New device state, dev: %s, state: %d"
,
slave_list
->
Name
,
dev
->
State
);
}
}
...
...
@@ -1969,7 +1969,7 @@ void* handle_events(void* ptr)
/* Initialize interface */
errh_Info
(
"
Initializing interface for Profinet IO Mast
er %s"
,
ap
->
Name
);
errh_Info
(
"
PROFINET: Initializing interface for controll
er %s"
,
ap
->
Name
);
/* Add master as a device */
...
...
@@ -2092,7 +2092,7 @@ void* handle_events(void* ptr)
if
(
sts
!=
PNAK_OK
)
{
op
->
Status
=
PB__INITFAIL
;
errh_Error
(
"
Starting profi
stack returned with error code: %d"
,
sts
);
errh_Error
(
"
PROFINET: Start of
stack returned with error code: %d"
,
sts
);
// return IO__ERRINIDEVICE;
}
...
...
@@ -2156,7 +2156,7 @@ void* handle_events(void* ptr)
}
else
{
errh_Error
(
"
Download of Profinet D
evice configuration failed for: %s"
,
errh_Error
(
"
PROFINET: Download of d
evice configuration failed for: %s"
,
device_vect
[
ii
]
->
device_name
);
/* Setup a dummy i/o area. Depending on exisiting channels this area
* needs to exist */
...
...
@@ -2221,7 +2221,7 @@ void* handle_events(void* ptr)
if
(
sts
!=
PNAK_OK
)
{
op
->
Status
=
PB__INITFAIL
;
errh_Error
(
"P
rofistack unable to go online, err
code: %d"
,
sts
);
errh_Error
(
"P
ROFINET: Unable to go online, error
code: %d"
,
sts
);
// return IO__ERRINIDEVICE;
}
...
...
@@ -2242,7 +2242,7 @@ void* handle_events(void* ptr)
if
(
sts
!=
PNAK_OK
)
{
op
->
Status
=
PB__INITFAIL
;
errh_Error
(
"P
rofistack unable to set state online, err
code: %d"
,
sts
);
errh_Error
(
"P
ROFINET: Unable to set state online, error
code: %d"
,
sts
);
// return IO__ERRINIDEVICE;
}
}
...
...
@@ -2267,7 +2267,7 @@ void* handle_events(void* ptr)
if
(
sts
!=
PNAK_OK
)
{
op
->
Status
=
PB__INITFAIL
;
errh_Error
(
"P
rofistack unable to activate devices, err
code: %d"
,
sts
);
errh_Error
(
"P
ROFINET: Unable to activate devices, error
code: %d"
,
sts
);
// return IO__ERRINIDEVICE;
}
...
...
@@ -2290,83 +2290,83 @@ void* handle_events(void* ptr)
pthread_cond_signal
(
&
local
->
cond
);
pthread_mutex_unlock
(
&
local
->
mutex
);
/* Do forever ... */
/* Do until we close the channel and break out */
while
(
1
)
{
// wait_object = PNAK_WAIT_OBJECTS_EVENT_IND | PNAK_WAIT_OBJECTS_OTHER
// | PNAK_WAIT_OBJECT_SERVICE_CON;
wait_object
=
PNAK_WAIT_OBJECTS_ALL
&
~
(
PNAK_WAIT_OBJECT_PROVIDER_DATA_UPDATED
|
PNAK_WAIT_OBJECT_CONSUMER_DATA_CHANGED
);
// pthread_mutex_lock(&local->mutex);
/* Other states available:
PNAK_WAIT_OBJECT_ETHERNET_STATE_CHANGED
PNAK_WAIT_OBJECT_INTERRUPTED
PNAK_WAIT_OBJECTS_EVENT_IND
PNAK_WAIT_OBJECTS_OTHER
PNAK_WAIT_OBJECT_SERVICE_CON
*/
wait_object
=
PNAK_WAIT_OBJECTS_ALL
&
~
(
PNAK_WAIT_OBJECT_PROVIDER_DATA_UPDATED
|
PNAK_WAIT_OBJECT_CONSUMER_DATA_CHANGED
);
sts
=
pnak_wait_for_multiple_objects
(
0
,
&
wait_object
,
PNAK_INFINITE_TIMEOUT
);
if
(
sts
==
PNAK_OK
)
{
if
(
wait_object
&
PNAK_WAIT_OBJECT_EXCEPTION
)
if
(
wait_object
&
PNAK_WAIT_OBJECT_CHANNEL_CLOSED
)
{
errh_Info
(
"PROFINET: Stack received channel closed event!"
);
// Iterate through all devices and propagate stopped state to all children
if
(
ap
)
{
((
pwr_sClass_PnControllerSoftingPNAK
*
)
ap
->
op
)
->
Status
=
PB__STOPPED
;
io_sRack
*
device
;
io_sCard
*
module
;
pwr_sClass_PnDevice
*
dev
;
pwr_sClass_PnModule
*
mod
;
for
(
device
=
ap
->
racklist
;
device
!=
NULL
;
device
=
device
->
next
)
{
dev
=
(
pwr_sClass_PnDevice
*
)
device
->
op
;
dev
->
Status
=
PB__STOPPED
;
for
(
module
=
device
->
cardlist
;
module
!=
NULL
;
module
=
module
->
next
)
{
mod
=
(
pwr_sClass_PnModule
*
)
module
->
op
;
mod
->
Status
=
PB__STOPPED
;
}
}
}
break
;
}
else
if
(
wait_object
&
PNAK_WAIT_OBJECT_EXCEPTION
)
{
// printf("Exception !!\n");
handle_exception
(
local
);
}
else
if
(
wait_object
&
PNAK_WAIT_OBJECT_STATE_CHANGED
)
{
// printf("State changed !!\n");
handle_state_changed
(
local
);
}
else
if
(
wait_object
&
PNAK_WAIT_OBJECT_DEVICE_STATE_CHANGED
)
{
// printf("Device state changed !!\n");
handle_device_state_changed
(
local
,
ap
);
}
else
if
(
wait_object
&
PNAK_WAIT_OBJECT_ALARM
)
{
// printf("Alarm !!\n");
handle_alarm_indication
(
local
,
ap
);
}
// else if (wait_object & PNAK_WAIT_OBJECT_CHANNEL_CLOSED) {
// // printf("Channel closed !!");
// // What to do if channel closes ???;
// }
// else if (wait_object & PNAK_WAIT_OBJECT_ETHERNET_STATE_CHANGED) {
// // printf("Ethernet state changed !!");
// // What to do if ethernet state changes ???;
// }
// else if (wait_object & PNAK_WAIT_OBJECT_INTERRUPTED) {
// // printf("Interrupted !!");
// // What to do if interrupted ???;
// }
else
if
(
wait_object
&
PNAK_WAIT_OBJECT_SERVICE_CON
)
{
// printf("Service con !!\n");
sts
=
handle_service_con
(
local
,
ap
);
}
// else
// {
// printf("Unhandled status!! 0x%02X\n", wait_object);
// }
}
else
if
((
sts
==
PNAK_ERR_FATAL_ERROR
)
||
(
sts
==
PNAK_EXCEPTION_THROWN
))
{
printf
(
"Err Fatal / Exception !!
\n
"
);
// user_handle_exception (ChannelId);
}
else
{
printf
(
"Running == NOT !!
\n
"
);
// pThisSmObject->Running = PN_FALSE
;
errh_Fatal
(
"PROFINET: Fatal exception occured. Stopping PROFINET!
"
);
pnak_stop_stack
(
0
)
;
}
// pthread_mutex_unlock(&local->mutex);
}
pnak_term
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment