Skip to content

Commit ee307d4

Browse files
committed
Fix read/write for multiple ports
1 parent 12999ac commit ee307d4

File tree

9 files changed

+172
-146
lines changed

9 files changed

+172
-146
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ set(PNET_MAX_CR 2
6060
set(PNET_MAX_SLOTS 5
6161
CACHE STRING "Per API. Should be > 1 to allow at least one I/O module")
6262
set(PNET_MAX_SUBSLOTS 3
63-
CACHE STRING "Per slot (3 needed for DAP)")
63+
CACHE STRING "Per slot (DAP requires 2 + PNET_MAX_PORT)")
6464
set(PNET_MAX_CHANNELS 1
6565
CACHE STRING "Per sub-slot. Used for diagnosis")
6666
set(PNET_MAX_DFP_IOCR 2
6767
CACHE STRING "Allowed values are 0 (zero) or 2")
6868
set(PNET_MAX_PORT 1
69-
CACHE STRING "2 for media redundancy. Currently only 1 is supported")
69+
CACHE STRING "Number of physical ports")
7070
set(PNET_MAX_LOG_BOOK_ENTRIES 16
7171
CACHE STRING "")
7272
set(PNET_MAX_ALARMS 3

doc/multiple_ports.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ Run ``ifconfig`` to check that the bridge is up and its network interfaces are a
9696
Configuration of p-net stack and sample application
9797
---------------------------------------------------------
9898
To run p-net and the sample application with multiple ports a couple
99-
of things need to be done:
99+
of things need to be done. Note that the settings described in the
100+
following sections are changed by running ``ccmake .`` in the build folder.
101+
``options.h`` will be regenerated. Another way to set the options is to
102+
set them on the cmake command line (-DPNET_MAX_PORTS=2 -DPNET_MAX_SUBSLOTS=4).
100103

101104
Reconfigure setting ``PNET_MAX_PORT`` to the actual number of physical ports available in the system.
102105
For this example ``PNET_MAX_PORT`` shall be set to 2.
103106

107+
Reconfigure setting ``PNET_MAX_SUBSLOTS``. Each additional port will require an additional subslot.
108+
For this example the ``PNET_MAX_SUBSLOTS`` should be be set to 4.
109+
104110
Example of initial log when starting the demo application with a multi port configuration::
105111

106112
pi@pndevice-pi:~/profinet/build $ sudo ./pn_dev -v

sample_app/GSDML-V2.4-rtlabs-IODevice-20201211.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,25 @@
5656
</InterfaceSubmoduleItem>
5757
<PortSubmoduleItem ID="IDS_P1" SubmoduleIdentNumber="0x00008001" SubslotNumber="32769" TextId="IDT_NAME_PS1" MaxPortRxDelay="350" MaxPortTxDelay="160">
5858
<MAUTypeList>
59+
<!--
60+
MAUTypeItems shall match the actual network interfaces of the device.
61+
Current list works for Raspberry Pi, Linksys usb/ethernet dongle and xmc sample targets
62+
-->
63+
<MAUTypeItem Value="30"/>
5964
<MAUTypeItem Value="16"/>
65+
<MAUTypeItem Value="5"/>
6066
</MAUTypeList>
6167
</PortSubmoduleItem>
62-
<!-- Enable to support additional port. (PNET_MAX_PORT == 2) -->
63-
<!-- Add additional PortSubmoduleItems to support additional ports -->
68+
<!--
69+
Enable to support additional port. (PNET_MAX_PORT == 2)
70+
Add additional PortSubmoduleItems to support additional ports
71+
-->
6472
<!--
6573
<PortSubmoduleItem ID="IDS_P2" SubmoduleIdentNumber="0x00008002" SubslotNumber="32770" TextId="IDT_NAME_PS2" MaxPortRxDelay="350" MaxPortTxDelay="160">
6674
<MAUTypeList>
75+
<MAUTypeItem Value="30"/>
6776
<MAUTypeItem Value="16"/>
77+
<MAUTypeItem Value="5"/>
6878
</MAUTypeList>
6979
</PortSubmoduleItem>
7080
-->

src/device/pf_block_writer.c

Lines changed: 71 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,16 +3572,23 @@ void pf_put_pdport_data_real (
35723572
{
35733573
uint16_t block_pos = *p_pos;
35743574
uint16_t block_len = 0;
3575-
uint8_t numPeers = 0;
3575+
uint8_t num_peers = 0;
3576+
uint16_t link_state = 0;
35763577
pf_lldp_station_name_t station_name;
35773578
pf_lldp_port_name_t port_name;
3579+
pnal_eth_status_t eth_status;
35783580
const uint16_t subslot = pf_port_loc_port_num_to_dap_subslot (loc_port_num);
35793581
const pnet_port_cfg_t * p_port_config =
35803582
pf_port_get_config (net, loc_port_num);
35813583
const pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);
35823584
const pf_lldp_peer_info_t * p_peer_info = &p_port_data->lldp.peer_info;
35833585

3584-
numPeers = p_peer_info->ttl ? 1 : 0;
3586+
num_peers = p_peer_info->ttl ? 1 : 0;
3587+
3588+
if (pnal_eth_get_status (p_port_config->phy_port.if_name, &eth_status) != 0)
3589+
{
3590+
memset (&eth_status, 0, sizeof (eth_status));
3591+
}
35853592

35863593
/* Block header first */
35873594
pf_put_block_header (
@@ -3612,13 +3619,13 @@ void pf_put_pdport_data_real (
36123619
p_pos);
36133620

36143621
/* Number of Peers */
3615-
pf_put_byte (numPeers, res_len, p_bytes, p_pos);
3622+
pf_put_byte (num_peers, res_len, p_bytes, p_pos);
36163623

3617-
/*Input only the number if it's there */
3618-
if (numPeers > 0)
3619-
{
3620-
pf_put_padding (2, res_len, p_bytes, p_pos);
3624+
pf_put_padding (2, res_len, p_bytes, p_pos);
36213625

3626+
/* Peer info */
3627+
if (num_peers > 0)
3628+
{
36223629
/* Peer port name */
36233630
pf_lldp_get_peer_port_name (net, loc_port_num, &port_name);
36243631
pf_put_byte (port_name.len, res_len, p_bytes, p_pos);
@@ -3653,92 +3660,50 @@ void pf_put_pdport_data_real (
36533660
p_pos);
36543661

36553662
pf_put_padding (2, res_len, p_bytes, p_pos);
3663+
} /* Peer info */
36563664

3657-
/* MAUType */
3658-
pf_put_uint16 (
3659-
is_big_endian,
3660-
p_peer_info->phy_config.operational_mau_type,
3661-
res_len,
3662-
p_bytes,
3663-
p_pos);
3665+
/* MAUType */
3666+
pf_put_uint16 (
3667+
is_big_endian,
3668+
eth_status.operational_mau_type,
3669+
res_len,
3670+
p_bytes,
3671+
p_pos);
36643672

3665-
pf_put_padding (2, res_len, p_bytes, p_pos);
3673+
pf_put_padding (2, res_len, p_bytes, p_pos);
36663674

3667-
/* Domain Boundary */
3668-
pf_put_uint32 (
3669-
is_big_endian,
3670-
p_peer_info->domain_boundary,
3671-
res_len,
3672-
p_bytes,
3673-
p_pos);
3675+
/* Domain Boundary */
3676+
/* Todo- hardcoded value*/
3677+
pf_put_uint32 (is_big_endian, 0, res_len, p_bytes, p_pos);
36743678

3675-
/* Multicast Boundary */
3676-
pf_put_uint32 (
3677-
is_big_endian,
3678-
p_peer_info->multicast_boundary,
3679-
res_len,
3680-
p_bytes,
3681-
p_pos);
3679+
/* Multicast Boundary */
3680+
/* Todo- hardcoded value*/
3681+
pf_put_uint32 (is_big_endian, 0, res_len, p_bytes, p_pos);
36823682

3683-
/* LinkState.Port */
3684-
pf_put_byte (p_peer_info->link_state_port, res_len, p_bytes, p_pos);
3683+
/* PN-AL-protocol (Mar20) section 5.2.13.23 for LinkState encoding */
3684+
/* LinkState.Link */
3685+
if (eth_status.running)
3686+
{
3687+
link_state = PF_PD_LINK_STATE_LINK_UP;
3688+
}
3689+
else
3690+
{
3691+
link_state = PF_PD_LINK_STATE_LINK_DOWN;
3692+
}
36853693

3686-
/* LinkState.Link */
3687-
/* TODO currently always set to up */
3688-
pf_put_byte (1, res_len, p_bytes, p_pos);
3694+
/* LinkState.Port */
3695+
link_state |= (PF_PD_LINK_STATE_PORT_UNKNOWN << 8);
36893696

3690-
pf_put_padding (2, res_len, p_bytes, p_pos);
3697+
pf_put_uint16 (is_big_endian, link_state, res_len, p_bytes, p_pos);
36913698

3692-
/* MediaType (Decode what type it is and report it out per
3693-
* PROFINET AL Protocol Table 717
3694-
*/
3695-
switch (p_peer_info->phy_config.operational_mau_type)
3696-
{
3697-
case PNAL_ETH_MAU_RADIO:
3698-
/* Radio */
3699-
pf_put_uint32 (
3700-
is_big_endian,
3701-
PF_PD_MEDIATYPE_RADIO,
3702-
res_len,
3703-
p_bytes,
3704-
p_pos);
3705-
break;
3706-
case PNAL_ETH_MAU_COPPER_10BaseT:
3707-
case PNAL_ETH_MAU_COPPER_100BaseTX_HALF_DUPLEX:
3708-
case PNAL_ETH_MAU_COPPER_100BaseTX_FULL_DUPLEX:
3709-
case PNAL_ETH_MAU_COPPER_1000BaseT_HALF_DUPLEX:
3710-
case PNAL_ETH_MAU_COPPER_1000BaseT_FULL_DUPLEX:
3711-
/* Copper */
3712-
pf_put_uint32 (
3713-
is_big_endian,
3714-
PF_PD_MEDIATYPE_COPPER,
3715-
res_len,
3716-
p_bytes,
3717-
p_pos);
3718-
break;
3719-
case PNAL_ETH_MAU_FIBER_100BaseFX_HALF_DUPLEX:
3720-
case PNAL_ETH_MAU_FIBER_100BaseFX_FULL_DUPLEX:
3721-
case PNAL_ETH_MAU_FIBER_1000BaseX_HALF_DUPLEX:
3722-
case PNAL_ETH_MAU_FIBER_1000BaseX_FULL_DUPLEX:
3723-
/* Fiber */
3724-
pf_put_uint32 (
3725-
is_big_endian,
3726-
PF_PD_MEDIATYPE_FIBER,
3727-
res_len,
3728-
p_bytes,
3729-
p_pos);
3730-
break;
3731-
default:
3732-
/* Unknown */
3733-
pf_put_uint32 (
3734-
is_big_endian,
3735-
PF_PD_MEDIATYPE_UNKNOWN,
3736-
res_len,
3737-
p_bytes,
3738-
p_pos);
3739-
break;
3740-
}
3741-
}
3699+
pf_put_padding (2, res_len, p_bytes, p_pos);
3700+
3701+
pf_put_uint32 (
3702+
is_big_endian,
3703+
pf_port_get_media_type (eth_status.operational_mau_type),
3704+
res_len,
3705+
p_bytes,
3706+
p_pos);
37423707

37433708
/* Finally insert the block length into the block header */
37443709
block_len = *p_pos - (block_pos + 4);
@@ -3896,10 +3861,8 @@ static void pf_put_pd_multiblock_interface_and_statistics (
38963861
{
38973862
uint16_t block_pos = *p_pos;
38983863
uint16_t block_len = 0;
3899-
39003864
pnal_port_stats_t port_stats;
39013865

3902-
/* TODO get correct interface/port name */
39033866
if (
39043867
pnal_get_port_statistics (
39053868
net->fspm_cfg.if_cfg.main_port.if_name,
@@ -3960,9 +3923,7 @@ static void pf_put_pd_multiblock_interface_and_statistics (
39603923

39613924
/**
39623925
* @internal
3963-
* Insert multiblock port and statistics
3964-
*
3965-
* TODO - Add multiport feature - current version only list port 1
3926+
* Insert multiblock port and statistics for one port
39663927
*
39673928
* @param net InOut: The p-net stack instance
39683929
* @param is_big_endian In: Endianness of the destination buffer.
@@ -4042,33 +4003,38 @@ static void pf_put_pd_multiblock_port_and_statistics (
40424003
void pf_put_pd_real_data (
40434004
pnet_t * net,
40444005
bool is_big_endian,
4045-
int loc_port_num,
40464006
const pf_iod_read_result_t * p_res,
40474007
uint16_t res_len,
40484008
uint8_t * p_bytes,
40494009
uint16_t * p_pos)
40504010
{
4051-
/* Add Interface Data with the interface (port) statistics */
4011+
int port;
4012+
pf_port_iterator_t port_iterator;
4013+
40524014
pf_put_pd_multiblock_interface_and_statistics (
40534015
net,
40544016
is_big_endian,
40554017
p_res,
40564018
res_len,
40574019
p_bytes,
40584020
p_pos);
4059-
/* Added Port Data and Port Statistics
4060-
* ToDo: Probably should have a loop that knows how
4061-
* how many interfaces are on the device so this
4062-
* routine correctly reports out the information
4063-
*/
4064-
pf_put_pd_multiblock_port_and_statistics (
4065-
net,
4066-
is_big_endian,
4067-
loc_port_num,
4068-
p_res,
4069-
res_len,
4070-
p_bytes,
4071-
p_pos);
4021+
4022+
pf_port_init_iterator_over_ports (net, &port_iterator);
4023+
port = pf_port_get_next (&port_iterator);
4024+
4025+
while (port != 0)
4026+
{
4027+
pf_put_pd_multiblock_port_and_statistics (
4028+
net,
4029+
is_big_endian,
4030+
port,
4031+
p_res,
4032+
res_len,
4033+
p_bytes,
4034+
p_pos);
4035+
4036+
port = pf_port_get_next (&port_iterator);
4037+
}
40724038
}
40734039

40744040
/**

src/device/pf_block_writer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,6 @@ void pf_put_pdinterface_data_real (
823823
* Insert dp real data block into a buffer.
824824
* @param net InOut: The p-net stack instance
825825
* @param is_big_endian In: Endianness of the destination buffer.
826-
* @param loc_port_num In: Local port number.
827-
* Valid range: 1 .. PNET_MAX_PORT
828826
* @param p_res In: Read result
829827
* @param res_len In: Size of destination buffer.
830828
* @param p_bytes Out: Destination buffer.
@@ -833,7 +831,6 @@ void pf_put_pdinterface_data_real (
833831
void pf_put_pd_real_data (
834832
pnet_t * net,
835833
bool is_big_endian,
836-
int loc_port_num,
837834
const pf_iod_read_result_t * p_res,
838835
uint16_t res_len,
839836
uint8_t * p_bytes,

0 commit comments

Comments
 (0)