@@ -801,31 +801,47 @@ static int app_state_ind (
801
801
}
802
802
else if (state == PNET_EVENT_PRMEND )
803
803
{
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 )
811
807
{
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 ++ )
813
814
{
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 ++ )
817
816
{
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
+ }
822
826
}
823
827
}
828
+ (void )pnet_set_provider_state (net , true);
824
829
}
825
- (void )pnet_set_provider_state (net , true);
826
830
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
+ }
829
845
}
830
846
831
847
return 0 ;
@@ -1571,38 +1587,6 @@ void app_copy_ip_to_struct (
1571
1587
destination_struct -> d = (ip & 0xFF );
1572
1588
}
1573
1589
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
-
1606
1590
/**
1607
1591
* Send alarm ACK to the controller
1608
1592
*
@@ -2082,8 +2066,7 @@ static void app_handle_send_alarm (
2082
2066
2083
2067
void app_loop_forever (pnet_t * net , app_data_t * p_appdata )
2084
2068
{
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 ;
2087
2070
uint32_t flags = 0 ;
2088
2071
bool button1_pressed = false;
2089
2072
bool button2_pressed = false;
@@ -2106,16 +2089,7 @@ void app_loop_forever (pnet_t * net, app_data_t * p_appdata)
2106
2089
for (;;)
2107
2090
{
2108
2091
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 )
2119
2093
{
2120
2094
os_event_clr (p_appdata -> main_events , APP_EVENT_ALARM ); /* Re-arm */
2121
2095
0 commit comments