1 /* 2 * Copyright (c) 2022 Henrik Brix Andersen <henrik@brixandersen.dk> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_CAN_SJA1000_PRIV_H_ 8 #define ZEPHYR_DRIVERS_CAN_SJA1000_PRIV_H_ 9 10 #include <zephyr/sys/util.h> 11 12 /* SJA1000 register "CAN addresses", PeliCAN mode */ 13 #define CAN_SJA1000_MOD (0U) 14 #define CAN_SJA1000_CMR (1U) 15 #define CAN_SJA1000_SR (2U) 16 #define CAN_SJA1000_IR (3U) 17 #define CAN_SJA1000_IER (4U) 18 #define CAN_SJA1000_BTR0 (6U) 19 #define CAN_SJA1000_BTR1 (7U) 20 #define CAN_SJA1000_OCR (8U) 21 #define CAN_SJA1000_ALC (11U) 22 #define CAN_SJA1000_ECC (12U) 23 #define CAN_SJA1000_EWLR (13U) 24 #define CAN_SJA1000_RXERR (14U) 25 #define CAN_SJA1000_TXERR (15U) 26 27 /* Reset Mode access (acceptance codes/masks) */ 28 #define CAN_SJA1000_ACR0 (16U) 29 #define CAN_SJA1000_ACR1 (17U) 30 #define CAN_SJA1000_ACR2 (18U) 31 #define CAN_SJA1000_ACR3 (19U) 32 #define CAN_SJA1000_AMR0 (20U) 33 #define CAN_SJA1000_AMR1 (21U) 34 #define CAN_SJA1000_AMR2 (22U) 35 #define CAN_SJA1000_AMR3 (23U) 36 37 /* Operation Mode access (RX/TX SFF/EFF frame) */ 38 #define CAN_SJA1000_FRAME_INFO (16U) 39 #define CAN_SJA1000_XFF_ID1 (17U) 40 #define CAN_SJA1000_XFF_ID2 (18U) 41 #define CAN_SJA1000_EFF_ID3 (19U) 42 #define CAN_SJA1000_EFF_ID4 (20U) 43 #define CAN_SJA1000_SFF_DATA (19U) 44 #define CAN_SJA1000_EFF_DATA (21U) 45 46 #define CAN_SJA1000_RMC (29U) 47 #define CAN_SJA1000_RBSA (30U) 48 #define CAN_SJA1000_CDR (31U) 49 50 /* Mode register (MOD) bits */ 51 #define CAN_SJA1000_MOD_RM BIT(0) 52 #define CAN_SJA1000_MOD_LOM BIT(1) 53 #define CAN_SJA1000_MOD_STM BIT(2) 54 #define CAN_SJA1000_MOD_AFM BIT(3) 55 #define CAN_SJA1000_MOD_SM BIT(4) 56 57 /* Command Register (CMR) bits */ 58 #define CAN_SJA1000_CMR_TR BIT(0) 59 #define CAN_SJA1000_CMR_AT BIT(1) 60 #define CAN_SJA1000_CMR_RRB BIT(2) 61 #define CAN_SJA1000_CMR_CDO BIT(3) 62 #define CAN_SJA1000_CMR_SRR BIT(4) 63 64 /* Status Register (SR) bits */ 65 #define CAN_SJA1000_SR_RBS BIT(0) 66 #define CAN_SJA1000_SR_DOS BIT(1) 67 #define CAN_SJA1000_SR_TBS BIT(2) 68 #define CAN_SJA1000_SR_TCS BIT(3) 69 #define CAN_SJA1000_SR_RS BIT(4) 70 #define CAN_SJA1000_SR_TS BIT(5) 71 #define CAN_SJA1000_SR_ES BIT(6) 72 #define CAN_SJA1000_SR_BS BIT(7) 73 74 /* Interrupt Register (IR) bits */ 75 #define CAN_SJA1000_IR_RI BIT(0) 76 #define CAN_SJA1000_IR_TI BIT(1) 77 #define CAN_SJA1000_IR_EI BIT(2) 78 #define CAN_SJA1000_IR_DOI BIT(3) 79 #define CAN_SJA1000_IR_WUI BIT(4) 80 #define CAN_SJA1000_IR_EPI BIT(5) 81 #define CAN_SJA1000_IR_ALI BIT(6) 82 #define CAN_SJA1000_IR_BEI BIT(7) 83 84 /* Interrupt Enable Register (IER) bits */ 85 #define CAN_SJA1000_IER_RIE BIT(0) 86 #define CAN_SJA1000_IER_TIE BIT(1) 87 #define CAN_SJA1000_IER_EIE BIT(2) 88 #define CAN_SJA1000_IER_DOIE BIT(3) 89 #define CAN_SJA1000_IER_WUIE BIT(4) 90 #define CAN_SJA1000_IER_EPIE BIT(5) 91 #define CAN_SJA1000_IER_ALIE BIT(6) 92 #define CAN_SJA1000_IER_BEIE BIT(7) 93 94 /* Bus Timing Register 0 (BTR0) bits */ 95 #define CAN_SJA1000_BTR0_BRP_MASK GENMASK(5, 0) 96 #define CAN_SJA1000_BTR0_SJW_MASK GENMASK(7, 6) 97 98 #define CAN_SJA1000_BTR0_BRP_PREP(brp) FIELD_PREP(CAN_SJA1000_BTR0_BRP_MASK, brp) 99 #define CAN_SJA1000_BTR0_SJW_PREP(sjw) FIELD_PREP(CAN_SJA1000_BTR0_SJW_MASK, sjw) 100 101 /* Bus Timing Register 1 (BTR1) bits */ 102 #define CAN_SJA1000_BTR1_TSEG1_MASK GENMASK(3, 0) 103 #define CAN_SJA1000_BTR1_TSEG2_MASK GENMASK(6, 4) 104 #define CAN_SJA1000_BTR1_SAM BIT(7) 105 106 #define CAN_SJA1000_BTR1_TSEG1_PREP(tseg1) FIELD_PREP(CAN_SJA1000_BTR1_TSEG1_MASK, tseg1) 107 #define CAN_SJA1000_BTR1_TSEG2_PREP(tseg2) FIELD_PREP(CAN_SJA1000_BTR1_TSEG2_MASK, tseg2) 108 109 /* Error Code Capture register (ECC) bits */ 110 #define CAN_SJA1000_ECC_SEG_MASK GENMASK(4, 0) 111 #define CAN_SJA1000_ECC_DIR_MASK BIT(5) 112 #define CAN_SJA1000_ECC_ERRC_MASK GENMASK(7, 6) 113 114 #define CAN_SJA1000_ECC_SEG_SOF FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 3U) 115 #define CAN_SJA1000_ECC_SEG_ID28_TO_ID21 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 2U) 116 #define CAN_SJA1000_ECC_SEG_ID20_TO_ID18 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 6U) 117 #define CAN_SJA1000_ECC_SEG_SRTR FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 4U) 118 #define CAN_SJA1000_ECC_SEG_IDE FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 5U) 119 #define CAN_SJA1000_ECC_SEG_ID17_TO_ID13 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 7U) 120 #define CAN_SJA1000_ECC_SEG_ID12_TO_ID5 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 15U) 121 #define CAN_SJA1000_ECC_SEG_ID4_TO_ID0 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 14U) 122 #define CAN_SJA1000_ECC_SEG_RTR FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 12U) 123 #define CAN_SJA1000_ECC_SEG_RES1 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 13U) 124 #define CAN_SJA1000_ECC_SEG_RES0 FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 9U) 125 #define CAN_SJA1000_ECC_SEG_DLC FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 11U) 126 #define CAN_SJA1000_ECC_SEG_DATA FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 10U) 127 #define CAN_SJA1000_ECC_SEG_CRC_SEQ FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 8U) 128 #define CAN_SJA1000_ECC_SEG_CRC_DELIM FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 24U) 129 #define CAN_SJA1000_ECC_SEG_ACK_SLOT FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 25U) 130 #define CAN_SJA1000_ECC_SEG_ACK_DELIM FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 27U) 131 #define CAN_SJA1000_ECC_SEG_EOF FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 26U) 132 #define CAN_SJA1000_ECC_SEG_INTERMISSION FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 18U) 133 #define CAN_SJA1000_ECC_SEG_ACTIVE_ERROR_FLAG FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 17U) 134 #define CAN_SJA1000_ECC_SEG_PASSIVE_ERROR_FLAG FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 22U) 135 #define CAN_SJA1000_ECC_SEG_TOLERATE_DOM_BITS FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 19U) 136 #define CAN_SJA1000_ECC_SEG_ERROR_DELIM FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 23U) 137 #define CAN_SJA1000_ECC_SEG_OVERLOAD_FLAG FIELD_PREP(CAN_SJA1000_ECC_SEG_MASK, 28U) 138 139 #define CAN_SJA1000_ECC_DIR_TX FIELD_PREP(CAN_SJA1000_ECC_DIR_MASK, 0U) 140 #define CAN_SJA1000_ECC_DIR_RX FIELD_PREP(CAN_SJA1000_ECC_DIR_MASK, 1U) 141 142 #define CAN_SJA1000_ECC_ERRC_BIT_ERROR FIELD_PREP(CAN_SJA1000_ECC_ERRC_MASK, 0U) 143 #define CAN_SJA1000_ECC_ERRC_FORM_ERROR FIELD_PREP(CAN_SJA1000_ECC_ERRC_MASK, 1U) 144 #define CAN_SJA1000_ECC_ERRC_STUFF_ERROR FIELD_PREP(CAN_SJA1000_ECC_ERRC_MASK, 2U) 145 #define CAN_SJA1000_ECC_ERRC_OTHER_ERROR FIELD_PREP(CAN_SJA1000_ECC_ERRC_MASK, 3U) 146 147 /* RX/TX SFF/EFF Frame Information bits */ 148 #define CAN_SJA1000_FRAME_INFO_DLC_MASK GENMASK(3, 0) 149 #define CAN_SJA1000_FRAME_INFO_RTR BIT(6) 150 #define CAN_SJA1000_FRAME_INFO_FF BIT(7) 151 152 #define CAN_SJA1000_FRAME_INFO_DLC_PREP(dlc) FIELD_PREP(CAN_SJA1000_FRAME_INFO_DLC_MASK, dlc) 153 #define CAN_SJA1000_FRAME_INFO_DLC_GET(info) FIELD_GET(CAN_SJA1000_FRAME_INFO_DLC_MASK, info) 154 155 #endif /* ZEPHYR_DRIVERS_CAN_SJA1000_PRIV_H_ */ 156