]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Fixed bug in CAN configuration, fiiltering settings
authorMichal Horn <hornmich@fel.cvut.cz>
Tue, 26 Aug 2014 08:40:36 +0000 (10:40 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Tue, 26 Aug 2014 08:40:36 +0000 (10:40 +0200)
This bug caused the message filtering malfunction when mask was defined.
Now the standart, extended and mixed message ID filtering with mask definition is supported.

When mixed is selected, only he higher bits of the Mask and ID registers are used.

rpp/src/rpp/can.c

index 0a1847a988287b87926e1421ca4316c53ec4b8c4..f1845698b539db29634923f324c9cb2b2ce82910 100644 (file)
@@ -184,7 +184,17 @@ static int8_t init_tx_box(struct rpp_can_tx_config cfg)
     /**
     * 31 Set whether use of std/ext ID should have effect on acceptance filtering
     */
-    controller->IF1MSK = ((cfg.type == RPP_CAN_MIXED ? 0 : 1) << 31);
+    switch (cfg.type) {
+               case RPP_CAN_STANDARD:
+                       controller->IF1MSK = 0 << 31;
+                       break;
+               case RPP_CAN_MIXED:
+                       controller->IF1MSK = 1 << 31;
+                       break;
+               case RPP_CAN_EXTENDED:
+                       controller->IF1MSK = 1 << 31;
+                       break;
+    }
 
     /**
     * 31 Message object is valid
@@ -233,8 +243,17 @@ static int8_t init_rx_box(struct rpp_can_rx_config cfg)
     * 31 Set whether use of std/ext ID should have effect on acceptance filtering
     * 28-1 Set mask
     */
-    controller->IF2MSK = ((cfg.type == RPP_CAN_MIXED ? 0 : 1U) << 31)
-                          | cfg.mask;
+    switch (cfg.type) {
+               case RPP_CAN_STANDARD:
+                       controller->IF2MSK = (1 << 31) | (cfg.mask << 18);
+                       break;
+               case RPP_CAN_MIXED:
+                       controller->IF2MSK = (0 << 31) | cfg.mask;
+                       break;
+               case RPP_CAN_EXTENDED:
+                       controller->IF2MSK = (1 << 31) | cfg.mask;
+                       break;
+    }
 
     /**
     * 31 Message object is valid
@@ -242,11 +261,10 @@ static int8_t init_rx_box(struct rpp_can_rx_config cfg)
     * 29 Direction is read
     * 28-18 / 28-1 Object ID
     */
-    controller->IF2ARB = (1U << 31)
+    controller->IF2ARB = (1U << 31)    // MsgVal
                           | ((cfg.type == RPP_CAN_STANDARD ? 0 : 1) << 30)
-                          | (0 << 29)
+                          | (0 << 29)  // Dir
                           | cfg.id << (cfg.type == RPP_CAN_STANDARD ? 18 : 0);
-
     /**
     * 12 Use mask for filtering
     *  7 End of buffer