@@ -654,17 +654,17 @@ int can_write(can_t *obj, CAN_Message msg, int cc) {
654
654
__NOP ();
655
655
}
656
656
657
- if (((msg .format == CANStandard ) && (msg .id <= 0x07FF )) || ((msg .format == CANExtended ) && (msg .id <= 0x03FFFF ))) {
657
+ if (((msg .format == CANStandard ) && (msg .id <= 0x07FF )) || ((msg .format == CANExtended ) && (msg .id <= 0x1FFFFFFF ))) {
658
658
/* send/receive FIFO buffer isn't full */
659
659
dmy_cfsts = CFSTS_TBL [obj -> ch ][CAN_SEND ];
660
660
if ((* dmy_cfsts & 0x02 ) != 0x02 ) {
661
- /* set format, frame type and send/receive FIFO buffer ID(b10-0 or b28-11 ) */
661
+ /* set format, frame type and send/receive FIFO buffer ID(b10-0 or b28-0 ) */
662
662
dmy_cfid = CFID_TBL [obj -> ch ][CAN_SEND ];
663
663
* dmy_cfid = ((msg .format << 31 ) | (msg .type << 30 ));
664
664
if (msg .format == CANStandard ) {
665
665
* dmy_cfid |= (msg .id & 0x07FF );
666
666
} else {
667
- * dmy_cfid |= (( msg .id & 0x03FFFF ) << 11 );
667
+ * dmy_cfid |= (msg .id & 0x1FFFFFFF );
668
668
}
669
669
/* set length */
670
670
dmy_cfptr = CFPTR_TBL [obj -> ch ][CAN_SEND ];
@@ -703,14 +703,14 @@ int can_read(can_t *obj, CAN_Message *msg, int handle) {
703
703
/* send/receive FIFO buffer isn't empty */
704
704
dmy_cfsts = CFSTS_TBL [obj -> ch ][CAN_RECV ];
705
705
while ((* dmy_cfsts & 0x01 ) != 0x01 ) {
706
- /* get format, frame type and send/receive FIFO buffer ID(b10-0 or b28-11 ) */
706
+ /* get format, frame type and send/receive FIFO buffer ID(b10-0 or b28-0 ) */
707
707
dmy_cfid = CFID_TBL [obj -> ch ][CAN_RECV ];
708
708
msg -> format = (CANFormat )(* dmy_cfid >> 31 );
709
- msg -> type = (CANType )(* dmy_cfid >> 30 );
709
+ msg -> type = (CANType )(( * dmy_cfid >> 30 ) & 0x1 );
710
710
if (msg -> format == CANStandard ) {
711
711
msg -> id = (* dmy_cfid & 0x07FF );
712
712
} else {
713
- msg -> id = (( * dmy_cfid >> 11 ) & 0x03FFFF );
713
+ msg -> id = (* dmy_cfid & 0x1FFFFFFF );
714
714
}
715
715
/* get length */
716
716
dmy_cfptr = CFPTR_TBL [obj -> ch ][CAN_RECV ];
@@ -830,7 +830,7 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
830
830
int retval = 0 ;
831
831
832
832
if ((format == CANStandard ) || (format == CANExtended )) {
833
- if (((format == CANStandard ) && (id <= 0x07FF )) || ((format == CANExtended ) && (id <= 0x03FFFF ))) {
833
+ if (((format == CANStandard ) && (id <= 0x07FF )) || ((format == CANExtended ) && (id <= 0x1FFFFFFF ))) {
834
834
/* set Global Reset mode and Channel Reset mode */
835
835
can_set_global_mode (GL_RESET );
836
836
can_set_channel_mode (obj -> ch , CH_RESET );
@@ -841,11 +841,11 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
841
841
/* set IDE format */
842
842
* dmy_gaflid = (format << 31 );
843
843
if (format == CANExtended ) {
844
- /* set receive rule ID for bit28-11 */
845
- * dmy_gaflid |= (id << 11 );
844
+ /* set receive rule ID for bit28-0 */
845
+ * dmy_gaflid |= (id & 0x1FFFFFFF );
846
846
} else {
847
847
/* set receive rule ID for bit10-0 */
848
- * dmy_gaflid |= id ;
848
+ * dmy_gaflid |= ( id & 0x07FF ) ;
849
849
}
850
850
/* set ID mask bit */
851
851
* dmy_gaflm = (0xC0000000 | mask );
@@ -988,6 +988,7 @@ static void can_set_frequency(can_t *obj, int f) {
988
988
uint8_t brp = 0 ;
989
989
uint8_t tseg1 = 0 ;
990
990
uint8_t tseg2 = 0 ;
991
+ uint8_t sjw = 0 ;
991
992
992
993
/* set clkc */
993
994
if (RZ_A1_IsClockMode0 () == false) {
@@ -1010,9 +1011,10 @@ static void can_set_frequency(can_t *obj, int f) {
1010
1011
/* calculate TSEG1 bit and TSEG2 bit */
1011
1012
tseg1 = (tq - 1 ) * 0.666666667 ;
1012
1013
tseg2 = (tq - 1 ) - tseg1 ;
1014
+ sjw = (tseg2 > 4 )? 4 : tseg2 ;
1013
1015
/* set RSCAN0CmCFG register */
1014
1016
dmy_cfg = CFG_MATCH [obj -> ch ];
1015
- * dmy_cfg = ((tseg2 - 1 ) << 20 ) | ((tseg1 - 1 ) << 16 ) | brp ;
1017
+ * dmy_cfg = ((sjw - 1 ) << 24 ) | (( tseg2 - 1 ) << 20 ) | ((tseg1 - 1 ) << 16 ) | brp ;
1016
1018
}
1017
1019
1018
1020
static void can_set_global_mode (int mode ) {
0 commit comments