Skip to content

Commit 9857aba

Browse files
Jonas Berghefloryd
Jonas Berg
authored andcommitted
Basic adaption of pnet to multiple connections
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
1 parent 45e531e commit 9857aba

12 files changed

+214
-142
lines changed

sample_app/sampleapp_common.c

+36-62
Original file line numberDiff line numberDiff line change
@@ -801,31 +801,47 @@ static int app_state_ind (
801801
}
802802
else if (state == PNET_EVENT_PRMEND)
803803
{
804-
/* Save the arep for later use */
805-
p_appdata->main_api.arep = arep;
806-
807-
/* Set initial data and IOPS for input modules, and IOCS for
808-
* output modules
809-
*/
810-
for (slot = 0; slot < PNET_MAX_SLOTS; slot++)
804+
/* To simplify sample applicataion, handle the subslot data
805+
properly just for first connection (AR) */
806+
if (p_appdata->main_api.arep == UINT32_MAX)
811807
{
812-
for (subslot_ix = 0; subslot_ix < PNET_MAX_SUBSLOTS; subslot_ix++)
808+
/* Save the arep for later use */
809+
p_appdata->main_api.arep = arep;
810+
811+
/* Set initial data and IOPS for input modules, and IOCS for
812+
* output modules */
813+
for (slot = 0; slot < PNET_MAX_SLOTS; slot++)
813814
{
814-
if (
815-
p_appdata->main_api.slots[slot].plugged &&
816-
p_appdata->main_api.slots[slot].subslots[subslot_ix].plugged)
815+
for (subslot_ix = 0; subslot_ix < PNET_MAX_SUBSLOTS; subslot_ix++)
817816
{
818-
app_set_initial_data_and_ioxs (
819-
net,
820-
p_appdata,
821-
&p_appdata->main_api.slots[slot].subslots[subslot_ix]);
817+
if (
818+
p_appdata->main_api.slots[slot].plugged &&
819+
p_appdata->main_api.slots[slot].subslots[subslot_ix].plugged)
820+
{
821+
app_set_initial_data_and_ioxs (
822+
net,
823+
p_appdata,
824+
&p_appdata->main_api.slots[slot].subslots[subslot_ix]);
825+
}
822826
}
823827
}
828+
(void)pnet_set_provider_state (net, true);
824829
}
825-
(void)pnet_set_provider_state (net, true);
826830

827-
/* Send application ready */
828-
os_event_set (p_appdata->main_events, APP_EVENT_READY_FOR_DATA);
831+
if (pnet_application_ready (net, arep) != 0)
832+
{
833+
printf (
834+
"AREP %u Error returned when application telling that it is "
835+
"ready for data. Have you set IOCS or IOPS for all subslots?\n",
836+
arep);
837+
}
838+
}
839+
else if (state == PNET_EVENT_DATA)
840+
{
841+
if (p_appdata->arguments.verbosity > 0)
842+
{
843+
printf ("Cyclic data transmission started\n\n");
844+
}
829845
}
830846

831847
return 0;
@@ -1571,38 +1587,6 @@ void app_copy_ip_to_struct (
15711587
destination_struct->d = (ip & 0xFF);
15721588
}
15731589

1574-
/**
1575-
* Send application ready to the controller
1576-
*
1577-
* @param net InOut: p-net stack instance
1578-
* @param arep In: Arep
1579-
* @param verbosity In: Verbosity
1580-
*/
1581-
static void app_handle_send_application_ready (
1582-
pnet_t * net,
1583-
uint32_t arep,
1584-
int verbosity)
1585-
{
1586-
int ret = -1;
1587-
1588-
if (verbosity > 0)
1589-
{
1590-
printf ("Application will signal that it is ready for data.\n");
1591-
}
1592-
1593-
ret = pnet_application_ready (net, arep);
1594-
if (ret != 0)
1595-
{
1596-
printf ("Error returned when application telling that it is ready for "
1597-
"data. Have you set IOCS or IOPS for all subslots?\n");
1598-
}
1599-
1600-
/*
1601-
* cm_ccontrol_cnf(+/-) is indicated later (app_state_ind(DATA)), when the
1602-
* confirmation arrives from the controller.
1603-
*/
1604-
}
1605-
16061590
/**
16071591
* Send alarm ACK to the controller
16081592
*
@@ -2082,8 +2066,7 @@ static void app_handle_send_alarm (
20822066

20832067
void app_loop_forever (pnet_t * net, app_data_t * p_appdata)
20842068
{
2085-
uint32_t mask = APP_EVENT_READY_FOR_DATA | APP_EVENT_TIMER |
2086-
APP_EVENT_ALARM | APP_EVENT_ABORT;
2069+
uint32_t mask = APP_EVENT_TIMER | APP_EVENT_ALARM | APP_EVENT_ABORT;
20872070
uint32_t flags = 0;
20882071
bool button1_pressed = false;
20892072
bool button2_pressed = false;
@@ -2106,16 +2089,7 @@ void app_loop_forever (pnet_t * net, app_data_t * p_appdata)
21062089
for (;;)
21072090
{
21082091
os_event_wait (p_appdata->main_events, mask, &flags, OS_WAIT_FOREVER);
2109-
if (flags & APP_EVENT_READY_FOR_DATA)
2110-
{
2111-
os_event_clr (p_appdata->main_events, APP_EVENT_READY_FOR_DATA);
2112-
2113-
app_handle_send_application_ready (
2114-
net,
2115-
p_appdata->main_api.arep,
2116-
p_appdata->arguments.verbosity);
2117-
}
2118-
else if (flags & APP_EVENT_ALARM)
2092+
if (flags & APP_EVENT_ALARM)
21192093
{
21202094
os_event_clr (p_appdata->main_events, APP_EVENT_ALARM); /* Re-arm */
21212095

sample_app/sampleapp_common.h

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ extern "C" {
3636

3737
#define APP_DATA_LED_ID 1
3838
#define APP_PROFINET_SIGNAL_LED_ID 2
39-
#define APP_EVENT_READY_FOR_DATA BIT (0)
4039
#define APP_EVENT_TIMER BIT (1)
4140
#define APP_EVENT_ALARM BIT (2)
4241
#define APP_EVENT_ABORT BIT (15)

src/common/pf_ppm.c

+1-15
Original file line numberDiff line numberDiff line change
@@ -441,21 +441,7 @@ int pf_ppm_close_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)
441441
return 0;
442442
}
443443

444-
/**
445-
* @internal
446-
* Find the AR, input IOCR and IODATA object instances for the specified
447-
* sub-slot.
448-
* @param net InOut: The p-net stack instance
449-
* @param api_id In: The API id.
450-
* @param slot_nbr In: The slot number.
451-
* @param subslot_nbr In: The sub-slot number.
452-
* @param pp_ar Out: The AR instance.
453-
* @param pp_iocr Out: The IOCR instance.
454-
* @param pp_iodata Out: The IODATA object instance.
455-
* @return 0 If the information has been found.
456-
* -1 If the information was not found.
457-
*/
458-
static int pf_ppm_get_ar_iocr_desc (
444+
int pf_ppm_get_ar_iocr_desc (
459445
pnet_t * net,
460446
uint32_t api_id,
461447
uint16_t slot_nbr,

src/common/pf_ppm.h

+22
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ int pf_ppm_activate_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep);
4646
*/
4747
int pf_ppm_close_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep);
4848

49+
/**
50+
* Find the AR, input IOCR and IODATA object instances for the specified
51+
* sub-slot.
52+
* @param net InOut: The p-net stack instance
53+
* @param api_id In: The API id.
54+
* @param slot_nbr In: The slot number.
55+
* @param subslot_nbr In: The sub-slot number.
56+
* @param pp_ar Out: The AR instance.
57+
* @param pp_iocr Out: The IOCR instance.
58+
* @param pp_iodata Out: The IODATA object instance.
59+
* @return 0 If the information has been found.
60+
* -1 If the information was not found.
61+
*/
62+
int pf_ppm_get_ar_iocr_desc (
63+
pnet_t * net,
64+
uint32_t api_id,
65+
uint16_t slot_nbr,
66+
uint16_t subslot_nbr,
67+
pf_ar_t ** pp_ar,
68+
pf_iocr_t ** pp_iocr,
69+
pf_iodata_object_t ** pp_iodata);
70+
4971
/**
5072
* Set the data and IOPS for a sub-module.
5173
* @param net InOut: The p-net stack instance

0 commit comments

Comments
 (0)