Skip to content

Commit

Permalink
Fix read/write for multiple ports
Browse files Browse the repository at this point in the history
  • Loading branch information
olbjo committed Feb 4, 2021
1 parent 12999ac commit ee307d4
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 146 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ set(PNET_MAX_CR 2
set(PNET_MAX_SLOTS 5
CACHE STRING "Per API. Should be > 1 to allow at least one I/O module")
set(PNET_MAX_SUBSLOTS 3
CACHE STRING "Per slot (3 needed for DAP)")
CACHE STRING "Per slot (DAP requires 2 + PNET_MAX_PORT)")
set(PNET_MAX_CHANNELS 1
CACHE STRING "Per sub-slot. Used for diagnosis")
set(PNET_MAX_DFP_IOCR 2
CACHE STRING "Allowed values are 0 (zero) or 2")
set(PNET_MAX_PORT 1
CACHE STRING "2 for media redundancy. Currently only 1 is supported")
CACHE STRING "Number of physical ports")
set(PNET_MAX_LOG_BOOK_ENTRIES 16
CACHE STRING "")
set(PNET_MAX_ALARMS 3
Expand Down
8 changes: 7 additions & 1 deletion doc/multiple_ports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ Run ``ifconfig`` to check that the bridge is up and its network interfaces are a
Configuration of p-net stack and sample application
---------------------------------------------------------
To run p-net and the sample application with multiple ports a couple
of things need to be done:
of things need to be done. Note that the settings described in the
following sections are changed by running ``ccmake .`` in the build folder.
``options.h`` will be regenerated. Another way to set the options is to
set them on the cmake command line (-DPNET_MAX_PORTS=2 -DPNET_MAX_SUBSLOTS=4).

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

Reconfigure setting ``PNET_MAX_SUBSLOTS``. Each additional port will require an additional subslot.
For this example the ``PNET_MAX_SUBSLOTS`` should be be set to 4.

Example of initial log when starting the demo application with a multi port configuration::

pi@pndevice-pi:~/profinet/build $ sudo ./pn_dev -v
Expand Down
14 changes: 12 additions & 2 deletions sample_app/GSDML-V2.4-rtlabs-IODevice-20201211.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,25 @@
</InterfaceSubmoduleItem>
<PortSubmoduleItem ID="IDS_P1" SubmoduleIdentNumber="0x00008001" SubslotNumber="32769" TextId="IDT_NAME_PS1" MaxPortRxDelay="350" MaxPortTxDelay="160">
<MAUTypeList>
<!--
MAUTypeItems shall match the actual network interfaces of the device.
Current list works for Raspberry Pi, Linksys usb/ethernet dongle and xmc sample targets
-->
<MAUTypeItem Value="30"/>
<MAUTypeItem Value="16"/>
<MAUTypeItem Value="5"/>
</MAUTypeList>
</PortSubmoduleItem>
<!-- Enable to support additional port. (PNET_MAX_PORT == 2) -->
<!-- Add additional PortSubmoduleItems to support additional ports -->
<!--
Enable to support additional port. (PNET_MAX_PORT == 2)
Add additional PortSubmoduleItems to support additional ports
-->
<!--
<PortSubmoduleItem ID="IDS_P2" SubmoduleIdentNumber="0x00008002" SubslotNumber="32770" TextId="IDT_NAME_PS2" MaxPortRxDelay="350" MaxPortTxDelay="160">
<MAUTypeList>
<MAUTypeItem Value="30"/>
<MAUTypeItem Value="16"/>
<MAUTypeItem Value="5"/>
</MAUTypeList>
</PortSubmoduleItem>
-->
Expand Down
176 changes: 71 additions & 105 deletions src/device/pf_block_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3572,16 +3572,23 @@ void pf_put_pdport_data_real (
{
uint16_t block_pos = *p_pos;
uint16_t block_len = 0;
uint8_t numPeers = 0;
uint8_t num_peers = 0;
uint16_t link_state = 0;
pf_lldp_station_name_t station_name;
pf_lldp_port_name_t port_name;
pnal_eth_status_t eth_status;
const uint16_t subslot = pf_port_loc_port_num_to_dap_subslot (loc_port_num);
const pnet_port_cfg_t * p_port_config =
pf_port_get_config (net, loc_port_num);
const pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);
const pf_lldp_peer_info_t * p_peer_info = &p_port_data->lldp.peer_info;

numPeers = p_peer_info->ttl ? 1 : 0;
num_peers = p_peer_info->ttl ? 1 : 0;

if (pnal_eth_get_status (p_port_config->phy_port.if_name, &eth_status) != 0)
{
memset (&eth_status, 0, sizeof (eth_status));
}

/* Block header first */
pf_put_block_header (
Expand Down Expand Up @@ -3612,13 +3619,13 @@ void pf_put_pdport_data_real (
p_pos);

/* Number of Peers */
pf_put_byte (numPeers, res_len, p_bytes, p_pos);
pf_put_byte (num_peers, res_len, p_bytes, p_pos);

/*Input only the number if it's there */
if (numPeers > 0)
{
pf_put_padding (2, res_len, p_bytes, p_pos);
pf_put_padding (2, res_len, p_bytes, p_pos);

/* Peer info */
if (num_peers > 0)
{
/* Peer port name */
pf_lldp_get_peer_port_name (net, loc_port_num, &port_name);
pf_put_byte (port_name.len, res_len, p_bytes, p_pos);
Expand Down Expand Up @@ -3653,92 +3660,50 @@ void pf_put_pdport_data_real (
p_pos);

pf_put_padding (2, res_len, p_bytes, p_pos);
} /* Peer info */

/* MAUType */
pf_put_uint16 (
is_big_endian,
p_peer_info->phy_config.operational_mau_type,
res_len,
p_bytes,
p_pos);
/* MAUType */
pf_put_uint16 (
is_big_endian,
eth_status.operational_mau_type,
res_len,
p_bytes,
p_pos);

pf_put_padding (2, res_len, p_bytes, p_pos);
pf_put_padding (2, res_len, p_bytes, p_pos);

/* Domain Boundary */
pf_put_uint32 (
is_big_endian,
p_peer_info->domain_boundary,
res_len,
p_bytes,
p_pos);
/* Domain Boundary */
/* Todo- hardcoded value*/
pf_put_uint32 (is_big_endian, 0, res_len, p_bytes, p_pos);

/* Multicast Boundary */
pf_put_uint32 (
is_big_endian,
p_peer_info->multicast_boundary,
res_len,
p_bytes,
p_pos);
/* Multicast Boundary */
/* Todo- hardcoded value*/
pf_put_uint32 (is_big_endian, 0, res_len, p_bytes, p_pos);

/* LinkState.Port */
pf_put_byte (p_peer_info->link_state_port, res_len, p_bytes, p_pos);
/* PN-AL-protocol (Mar20) section 5.2.13.23 for LinkState encoding */
/* LinkState.Link */
if (eth_status.running)
{
link_state = PF_PD_LINK_STATE_LINK_UP;
}
else
{
link_state = PF_PD_LINK_STATE_LINK_DOWN;
}

/* LinkState.Link */
/* TODO currently always set to up */
pf_put_byte (1, res_len, p_bytes, p_pos);
/* LinkState.Port */
link_state |= (PF_PD_LINK_STATE_PORT_UNKNOWN << 8);

pf_put_padding (2, res_len, p_bytes, p_pos);
pf_put_uint16 (is_big_endian, link_state, res_len, p_bytes, p_pos);

/* MediaType (Decode what type it is and report it out per
* PROFINET AL Protocol Table 717
*/
switch (p_peer_info->phy_config.operational_mau_type)
{
case PNAL_ETH_MAU_RADIO:
/* Radio */
pf_put_uint32 (
is_big_endian,
PF_PD_MEDIATYPE_RADIO,
res_len,
p_bytes,
p_pos);
break;
case PNAL_ETH_MAU_COPPER_10BaseT:
case PNAL_ETH_MAU_COPPER_100BaseTX_HALF_DUPLEX:
case PNAL_ETH_MAU_COPPER_100BaseTX_FULL_DUPLEX:
case PNAL_ETH_MAU_COPPER_1000BaseT_HALF_DUPLEX:
case PNAL_ETH_MAU_COPPER_1000BaseT_FULL_DUPLEX:
/* Copper */
pf_put_uint32 (
is_big_endian,
PF_PD_MEDIATYPE_COPPER,
res_len,
p_bytes,
p_pos);
break;
case PNAL_ETH_MAU_FIBER_100BaseFX_HALF_DUPLEX:
case PNAL_ETH_MAU_FIBER_100BaseFX_FULL_DUPLEX:
case PNAL_ETH_MAU_FIBER_1000BaseX_HALF_DUPLEX:
case PNAL_ETH_MAU_FIBER_1000BaseX_FULL_DUPLEX:
/* Fiber */
pf_put_uint32 (
is_big_endian,
PF_PD_MEDIATYPE_FIBER,
res_len,
p_bytes,
p_pos);
break;
default:
/* Unknown */
pf_put_uint32 (
is_big_endian,
PF_PD_MEDIATYPE_UNKNOWN,
res_len,
p_bytes,
p_pos);
break;
}
}
pf_put_padding (2, res_len, p_bytes, p_pos);

pf_put_uint32 (
is_big_endian,
pf_port_get_media_type (eth_status.operational_mau_type),
res_len,
p_bytes,
p_pos);

/* Finally insert the block length into the block header */
block_len = *p_pos - (block_pos + 4);
Expand Down Expand Up @@ -3896,10 +3861,8 @@ static void pf_put_pd_multiblock_interface_and_statistics (
{
uint16_t block_pos = *p_pos;
uint16_t block_len = 0;

pnal_port_stats_t port_stats;

/* TODO get correct interface/port name */
if (
pnal_get_port_statistics (
net->fspm_cfg.if_cfg.main_port.if_name,
Expand Down Expand Up @@ -3960,9 +3923,7 @@ static void pf_put_pd_multiblock_interface_and_statistics (

/**
* @internal
* Insert multiblock port and statistics
*
* TODO - Add multiport feature - current version only list port 1
* Insert multiblock port and statistics for one port
*
* @param net InOut: The p-net stack instance
* @param is_big_endian In: Endianness of the destination buffer.
Expand Down Expand Up @@ -4042,33 +4003,38 @@ static void pf_put_pd_multiblock_port_and_statistics (
void pf_put_pd_real_data (
pnet_t * net,
bool is_big_endian,
int loc_port_num,
const pf_iod_read_result_t * p_res,
uint16_t res_len,
uint8_t * p_bytes,
uint16_t * p_pos)
{
/* Add Interface Data with the interface (port) statistics */
int port;
pf_port_iterator_t port_iterator;

pf_put_pd_multiblock_interface_and_statistics (
net,
is_big_endian,
p_res,
res_len,
p_bytes,
p_pos);
/* Added Port Data and Port Statistics
* ToDo: Probably should have a loop that knows how
* how many interfaces are on the device so this
* routine correctly reports out the information
*/
pf_put_pd_multiblock_port_and_statistics (
net,
is_big_endian,
loc_port_num,
p_res,
res_len,
p_bytes,
p_pos);

pf_port_init_iterator_over_ports (net, &port_iterator);
port = pf_port_get_next (&port_iterator);

while (port != 0)
{
pf_put_pd_multiblock_port_and_statistics (
net,
is_big_endian,
port,
p_res,
res_len,
p_bytes,
p_pos);

port = pf_port_get_next (&port_iterator);
}
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/device/pf_block_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,6 @@ void pf_put_pdinterface_data_real (
* Insert dp real data block into a buffer.
* @param net InOut: The p-net stack instance
* @param is_big_endian In: Endianness of the destination buffer.
* @param loc_port_num In: Local port number.
* Valid range: 1 .. PNET_MAX_PORT
* @param p_res In: Read result
* @param res_len In: Size of destination buffer.
* @param p_bytes Out: Destination buffer.
Expand All @@ -833,7 +831,6 @@ void pf_put_pdinterface_data_real (
void pf_put_pd_real_data (
pnet_t * net,
bool is_big_endian,
int loc_port_num,
const pf_iod_read_result_t * p_res,
uint16_t res_len,
uint8_t * p_bytes,
Expand Down
Loading

0 comments on commit ee307d4

Please sign in to comment.