Bladeren bron

Change the QoS module to provide access to a global QoS object instance

The QoS module was changed to provide access to a global QoS object
to allow the Non Volatile Data code to access the needed data.

In NetworkHandlerInitialize() we call CipQosUpdateUsedSetQosValues() to
activate the current DSCP values for use with CipQosGetDscpPriority().

Between the call of CipStackInit() and NetworkHandlerInitialize() the
NV data shall be loaded.

Some internal renaming to make the names a little shorter was done also.

Signed-off-by: Stefan Mätje <stefan.maetje@esd.eu>
Stefan Mätje 6 jaren geleden
bovenliggende
commit
4be10c8ee2
3 gewijzigde bestanden met toevoegingen van 80 en 65 verwijderingen
  1. 48 59
      source/src/cip/cipqos.c
  2. 30 6
      source/src/cip/cipqos.h
  3. 2 0
      source/src/ports/generic_networkhandler.c

+ 48 - 59
source/src/cip/cipqos.c

@@ -23,47 +23,35 @@
 #define DEFAULT_DSCP_LOW 31u
 #define DEFAULT_DSCP_EXPLICIT 27u
 
-typedef struct cip_qos_dscp_values {
-  CipUsint dscp_event; /**< DSCP value for event messages*/
-  CipUsint dscp_general; /**< DSCP value for general messages*/
-  CipUsint dscp_urgent; /**< DSCP value for CIP transport class 0/1 Urgent priority messages */
-  CipUsint dscp_scheduled; /**< DSCP value for CIP transport class 0/1 Scheduled priority messages*/
-  CipUsint dscp_high; /**< DSCP value for CIP transport class 0/1 High priority messages */
-  CipUsint dscp_low; /**< DSCP value for CIP transport class 0/1 low priority messages */
-  CipUsint dscp_explicit; /**< DSCP value for CIP explicit messages (transport class 2/3 and UCMM)
-                                        and all other EtherNet/IP encapsulation messages */
-} CipQosDscpValues;
-
-typedef struct {
-  CipUsint q_frames_enable; /**< Enables or disable sending 802.1Q frames on CIP and IEEE 1588 messages */
-  CipQosDscpValues dscp_values; /**< Attribute set of DSCP values - beware! must not be the used set */
-} CipQosInstanceAttributes;
-
-static CipQosInstanceAttributes s_instance_1_attributes = {
+/** @brief The QoS object
+ *
+ *  The global instance of the QoS object
+ */
+CipQosObject g_qos = {
   .q_frames_enable = false,
-  .dscp_values.dscp_event = DEFAULT_DSCP_EVENT,
-  .dscp_values.dscp_general = DEFAULT_DSCP_GENERAL,
-  .dscp_values.dscp_urgent = DEFAULT_DSCP_URGENT,
-  .dscp_values.dscp_scheduled = DEFAULT_DSCP_SCHEDULED,
-  .dscp_values.dscp_high = DEFAULT_DSCP_HIGH,
-  .dscp_values.dscp_low = DEFAULT_DSCP_LOW,
-  .dscp_values.dscp_explicit = DEFAULT_DSCP_EXPLICIT
+  .dscp.event = DEFAULT_DSCP_EVENT,
+  .dscp.general = DEFAULT_DSCP_GENERAL,
+  .dscp.urgent = DEFAULT_DSCP_URGENT,
+  .dscp.scheduled = DEFAULT_DSCP_SCHEDULED,
+  .dscp.high = DEFAULT_DSCP_HIGH,
+  .dscp.low = DEFAULT_DSCP_LOW,
+  .dscp.explicit = DEFAULT_DSCP_EXPLICIT
 };
 
-/** @brief Hidden copy of data that need to be frozen on boot-up
+/** @brief Active set of DSCP data inherits its data from the QoS object on boot-up
  *
  *  The QoS DSCP values can be changed from the EIP network but the changes should come
  *  into effect only after a restart. Values are initialized with the default values.
  *  Changes are activated via the Identity Reset function
  */
-static CipQosDscpValues s_currently_used_dscp_values = {
-  .dscp_event = DEFAULT_DSCP_EVENT,
-  .dscp_general = DEFAULT_DSCP_GENERAL,
-  .dscp_urgent = DEFAULT_DSCP_URGENT,
-  .dscp_scheduled = DEFAULT_DSCP_SCHEDULED,
-  .dscp_high = DEFAULT_DSCP_HIGH,
-  .dscp_low = DEFAULT_DSCP_LOW,
-  .dscp_explicit = DEFAULT_DSCP_EXPLICIT
+static CipQosDscpValues s_active_dscp = {
+  .event = DEFAULT_DSCP_EVENT,
+  .general = DEFAULT_DSCP_GENERAL,
+  .urgent = DEFAULT_DSCP_URGENT,
+  .scheduled = DEFAULT_DSCP_SCHEDULED,
+  .high = DEFAULT_DSCP_HIGH,
+  .low = DEFAULT_DSCP_LOW,
+  .explicit = DEFAULT_DSCP_EXPLICIT
 };
 
 /************** Functions ****************************************/
@@ -131,23 +119,23 @@ EipStatus SetAttributeSingleQoS(
 
 CipUsint CipQosGetDscpPriority(ConnectionObjectPriority priority) {
 
-  CipUsint priority_value = s_currently_used_dscp_values.dscp_explicit;
+  CipUsint priority_value = s_active_dscp.explicit;
   switch (priority) {
     case kConnectionObjectPriorityLow:
-      priority_value = s_currently_used_dscp_values.dscp_low;
+      priority_value = s_active_dscp.low;
       break;
     case kConnectionObjectPriorityHigh:
-      priority_value = s_currently_used_dscp_values.dscp_high;
+      priority_value = s_active_dscp.high;
       break;
     case kConnectionObjectPriorityScheduled:
-      priority_value = s_currently_used_dscp_values.dscp_scheduled;
+      priority_value = s_active_dscp.scheduled;
       break;
     case kConnectionObjectPriorityUrgent:
-      priority_value = s_currently_used_dscp_values.dscp_urgent;
+      priority_value = s_active_dscp.urgent;
       break;
     case kConnectionObjectPriorityExplicit: /* Fall-through wanted here */
     default:
-      priority_value = s_currently_used_dscp_values.dscp_explicit;
+      priority_value = s_active_dscp.explicit;
       break;
   }
   return priority_value;
@@ -181,42 +169,42 @@ EipStatus CipQoSInit() {
   InsertAttribute(instance,
                   1,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.q_frames_enable,
+                  (void *) &g_qos.q_frames_enable,
                   kNotSetOrGetable);
   InsertAttribute(instance,
                   2,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_event,
+                  (void *) &g_qos.dscp.event,
                   kNotSetOrGetable);
   InsertAttribute(instance,
                   3,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_general,
+                  (void *) &g_qos.dscp.general,
                   kNotSetOrGetable);
   InsertAttribute(instance,
                   4,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_urgent,
+                  (void *) &g_qos.dscp.urgent,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   5,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_scheduled,
+                  (void *) &g_qos.dscp.scheduled,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   6,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_high,
+                  (void *) &g_qos.dscp.high,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   7,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_low,
+                  (void *) &g_qos.dscp.low,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   8,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_explicit,
+                  (void *) &g_qos.dscp.explicit,
                   kGetableSingle | kSetable);
 
   InsertService(qos_class, kGetAttributeSingle, &GetAttributeSingleQoS,
@@ -227,19 +215,20 @@ EipStatus CipQoSInit() {
   return kEipStatusOk;
 }
 
-void CipQosUpdateUsedSetQosValues() {
-  s_currently_used_dscp_values = s_instance_1_attributes.dscp_values;
+void CipQosUpdateUsedSetQosValues(void) {
+  s_active_dscp = g_qos.dscp;
 }
 
-void CipQosResetAttributesToDefaultValues() {
-  const CipQosDscpValues kDefaultValues = {
-    .dscp_event = DEFAULT_DSCP_EVENT,
-    .dscp_general = DEFAULT_DSCP_GENERAL,
-    .dscp_urgent = DEFAULT_DSCP_URGENT,
-    .dscp_scheduled = DEFAULT_DSCP_SCHEDULED,
-    .dscp_high = DEFAULT_DSCP_HIGH,
-    .dscp_low = DEFAULT_DSCP_LOW,
-    .dscp_explicit = DEFAULT_DSCP_EXPLICIT
+void CipQosResetAttributesToDefaultValues(void) {
+  static const CipQosDscpValues kDefaultValues = {
+    .event = DEFAULT_DSCP_EVENT,
+    .general = DEFAULT_DSCP_GENERAL,
+    .urgent = DEFAULT_DSCP_URGENT,
+    .scheduled = DEFAULT_DSCP_SCHEDULED,
+    .high = DEFAULT_DSCP_HIGH,
+    .low = DEFAULT_DSCP_LOW,
+    .explicit = DEFAULT_DSCP_EXPLICIT
   };
-  s_instance_1_attributes.dscp_values = kDefaultValues;
+  g_qos.q_frames_enable = false;
+  g_qos.dscp = kDefaultValues;
 }

+ 30 - 6
source/src/cip/cipqos.h

@@ -19,21 +19,45 @@
 /** @brief QoS Object class code */
 static const CipUint kCipQoSClassCode = 0x48u;
 
+/* public types */
+
+/** This type represents the group of DSCP values of the QoS object. */
+typedef struct cip_qos_dscp_values {
+  CipUsint event; /**< Attr. #2: DSCP value for event messages */
+  CipUsint general; /**< Attr. #3: DSCP value for general messages */
+  CipUsint urgent; /**< Attr. #4: DSCP value for CIP transport class 0/1 Urgent priority messages */
+  CipUsint scheduled; /**< Attr. #5: DSCP value for CIP transport class 0/1 Scheduled priority messages */
+  CipUsint high; /**< Attr. #6: DSCP value for CIP transport class 0/1 High priority messages */
+  CipUsint low; /**< Attr. #7: DSCP value for CIP transport class 0/1 low priority messages */
+  CipUsint explicit; /**< Attr. #8: DSCP value for CIP explicit messages (transport class 2/3 and UCMM)
+                                        and all other EtherNet/IP encapsulation messages */
+} CipQosDscpValues;
+
+/** This type represents the QoS object */
+typedef struct {
+  CipUsint q_frames_enable; /**< Attr. #1: Enables or disable sending 802.1Q frames on CIP and IEEE 1588 messages */
+  CipQosDscpValues dscp; /**< Attributes #2 ... #8 of DSCP values - beware! must not be the used set */
+} CipQosObject;
+
+
+/* public data */
+extern CipQosObject g_qos;
+
+
 /* public functions */
-/** @brief Initializing the data structures of the TCP/IP interface object
+/** @brief Provide the matching DSCP value for a given connection object priority level
  */
 CipUsint CipQosGetDscpPriority(ConnectionObjectPriority priority);
 
+/** @brief Create and initialize the QoS object
+ */
 EipStatus CipQoSInit(void);
 
 /** @brief Updates the currently used set of DSCP priority values
- *
  */
-void CipQosUpdateUsedSetQosValues(
-  );
+void CipQosUpdateUsedSetQosValues(void);
 
 /** @brief Reset attribute values to default. Does not update currently used set */
-void CipQosResetAttributesToDefaultValues(
-  );
+void CipQosResetAttributesToDefaultValues(void);
 
 #endif  /* OPENER_CIPQOS_H_*/

+ 2 - 0
source/src/ports/generic_networkhandler.c

@@ -71,6 +71,8 @@ EipStatus NetworkHandlerInitialize(void) {
   }
 
   SocketTimerArrayInitialize(g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
+  /* Activate the current DSCP values to become the used set of values. */
+  CipQosUpdateUsedSetQosValues();
 
   /* clear the master an temp sets */
   FD_ZERO(&master_socket);