Skip to content

Commit

Permalink
Basic adaption of pnet to multiple connections
Browse files Browse the repository at this point in the history
CMSU and CMWRR should be per AR instead of per device.

Implement modulediff when another AR owns a submodule.

Verify that PPM data have been set for a submodule, regardless of owning AR.

The output data frame ID from the PLC should be unique per device, not per AR.

Adapt sample application to be able to handle multiple connections.

Future work is needed for one input subslot to be able to send data to multiple PLCs.

Closes #131
Closes #169
  • Loading branch information
Jonas Berg authored and hefloryd committed Mar 26, 2021
1 parent 45e531e commit 9857aba
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 142 deletions.
98 changes: 36 additions & 62 deletions sample_app/sampleapp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,31 +801,47 @@ static int app_state_ind (
}
else if (state == PNET_EVENT_PRMEND)
{
/* Save the arep for later use */
p_appdata->main_api.arep = arep;

/* Set initial data and IOPS for input modules, and IOCS for
* output modules
*/
for (slot = 0; slot < PNET_MAX_SLOTS; slot++)
/* To simplify sample applicataion, handle the subslot data
properly just for first connection (AR) */
if (p_appdata->main_api.arep == UINT32_MAX)
{
for (subslot_ix = 0; subslot_ix < PNET_MAX_SUBSLOTS; subslot_ix++)
/* Save the arep for later use */
p_appdata->main_api.arep = arep;

/* Set initial data and IOPS for input modules, and IOCS for
* output modules */
for (slot = 0; slot < PNET_MAX_SLOTS; slot++)
{
if (
p_appdata->main_api.slots[slot].plugged &&
p_appdata->main_api.slots[slot].subslots[subslot_ix].plugged)
for (subslot_ix = 0; subslot_ix < PNET_MAX_SUBSLOTS; subslot_ix++)
{
app_set_initial_data_and_ioxs (
net,
p_appdata,
&p_appdata->main_api.slots[slot].subslots[subslot_ix]);
if (
p_appdata->main_api.slots[slot].plugged &&
p_appdata->main_api.slots[slot].subslots[subslot_ix].plugged)
{
app_set_initial_data_and_ioxs (
net,
p_appdata,
&p_appdata->main_api.slots[slot].subslots[subslot_ix]);
}
}
}
(void)pnet_set_provider_state (net, true);
}
(void)pnet_set_provider_state (net, true);

/* Send application ready */
os_event_set (p_appdata->main_events, APP_EVENT_READY_FOR_DATA);
if (pnet_application_ready (net, arep) != 0)
{
printf (
"AREP %u Error returned when application telling that it is "
"ready for data. Have you set IOCS or IOPS for all subslots?\n",
arep);
}
}
else if (state == PNET_EVENT_DATA)
{
if (p_appdata->arguments.verbosity > 0)
{
printf ("Cyclic data transmission started\n\n");
}
}

return 0;
Expand Down Expand Up @@ -1571,38 +1587,6 @@ void app_copy_ip_to_struct (
destination_struct->d = (ip & 0xFF);
}

/**
* Send application ready to the controller
*
* @param net InOut: p-net stack instance
* @param arep In: Arep
* @param verbosity In: Verbosity
*/
static void app_handle_send_application_ready (
pnet_t * net,
uint32_t arep,
int verbosity)
{
int ret = -1;

if (verbosity > 0)
{
printf ("Application will signal that it is ready for data.\n");
}

ret = pnet_application_ready (net, arep);
if (ret != 0)
{
printf ("Error returned when application telling that it is ready for "
"data. Have you set IOCS or IOPS for all subslots?\n");
}

/*
* cm_ccontrol_cnf(+/-) is indicated later (app_state_ind(DATA)), when the
* confirmation arrives from the controller.
*/
}

/**
* Send alarm ACK to the controller
*
Expand Down Expand Up @@ -2082,8 +2066,7 @@ static void app_handle_send_alarm (

void app_loop_forever (pnet_t * net, app_data_t * p_appdata)
{
uint32_t mask = APP_EVENT_READY_FOR_DATA | APP_EVENT_TIMER |
APP_EVENT_ALARM | APP_EVENT_ABORT;
uint32_t mask = APP_EVENT_TIMER | APP_EVENT_ALARM | APP_EVENT_ABORT;
uint32_t flags = 0;
bool button1_pressed = false;
bool button2_pressed = false;
Expand All @@ -2106,16 +2089,7 @@ void app_loop_forever (pnet_t * net, app_data_t * p_appdata)
for (;;)
{
os_event_wait (p_appdata->main_events, mask, &flags, OS_WAIT_FOREVER);
if (flags & APP_EVENT_READY_FOR_DATA)
{
os_event_clr (p_appdata->main_events, APP_EVENT_READY_FOR_DATA);

app_handle_send_application_ready (
net,
p_appdata->main_api.arep,
p_appdata->arguments.verbosity);
}
else if (flags & APP_EVENT_ALARM)
if (flags & APP_EVENT_ALARM)
{
os_event_clr (p_appdata->main_events, APP_EVENT_ALARM); /* Re-arm */

Expand Down
1 change: 0 additions & 1 deletion sample_app/sampleapp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern "C" {

#define APP_DATA_LED_ID 1
#define APP_PROFINET_SIGNAL_LED_ID 2
#define APP_EVENT_READY_FOR_DATA BIT (0)
#define APP_EVENT_TIMER BIT (1)
#define APP_EVENT_ALARM BIT (2)
#define APP_EVENT_ABORT BIT (15)
Expand Down
16 changes: 1 addition & 15 deletions src/common/pf_ppm.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,21 +441,7 @@ int pf_ppm_close_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)
return 0;
}

/**
* @internal
* Find the AR, input IOCR and IODATA object instances for the specified
* sub-slot.
* @param net InOut: The p-net stack instance
* @param api_id In: The API id.
* @param slot_nbr In: The slot number.
* @param subslot_nbr In: The sub-slot number.
* @param pp_ar Out: The AR instance.
* @param pp_iocr Out: The IOCR instance.
* @param pp_iodata Out: The IODATA object instance.
* @return 0 If the information has been found.
* -1 If the information was not found.
*/
static int pf_ppm_get_ar_iocr_desc (
int pf_ppm_get_ar_iocr_desc (
pnet_t * net,
uint32_t api_id,
uint16_t slot_nbr,
Expand Down
22 changes: 22 additions & 0 deletions src/common/pf_ppm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ int pf_ppm_activate_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep);
*/
int pf_ppm_close_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep);

/**
* Find the AR, input IOCR and IODATA object instances for the specified
* sub-slot.
* @param net InOut: The p-net stack instance
* @param api_id In: The API id.
* @param slot_nbr In: The slot number.
* @param subslot_nbr In: The sub-slot number.
* @param pp_ar Out: The AR instance.
* @param pp_iocr Out: The IOCR instance.
* @param pp_iodata Out: The IODATA object instance.
* @return 0 If the information has been found.
* -1 If the information was not found.
*/
int pf_ppm_get_ar_iocr_desc (
pnet_t * net,
uint32_t api_id,
uint16_t slot_nbr,
uint16_t subslot_nbr,
pf_ar_t ** pp_ar,
pf_iocr_t ** pp_iocr,
pf_iodata_object_t ** pp_iodata);

/**
* Set the data and IOPS for a sub-module.
* @param net InOut: The p-net stack instance
Expand Down
Loading

0 comments on commit 9857aba

Please sign in to comment.