Kinetis: Added FlexCAN driver with SocketCAN support

This commit is contained in:
Peter van der Perk 2020-06-15 10:25:46 +02:00 committed by patacongo
parent ff76ef0725
commit 5f73dc89be
5 changed files with 2098 additions and 31 deletions

View File

@ -317,6 +317,8 @@ config ARCH_FAMILY_K66
select KINETIS_HAVE_TPM1
select KINETIS_HAVE_TPM2
select KINETIS_HAVE_DMA
select KINETIS_HAVE_FLEXCAN0
select KINETIS_HAVE_FLEXCAN1
menu "Kinetis Peripheral Support"
@ -356,6 +358,14 @@ config KINETIS_HAVE_TPM2
bool
default n
config KINETIS_HAVE_FLEXCAN0
bool
default n
config KINETIS_HAVE_FLEXCAN1
bool
default n
config KINETIS_TRACE
bool "Trace"
default n
@ -502,15 +512,23 @@ config KINETIS_RNGB
select ARCH_HAVE_RNG
---help---
Support the random number generator(K6x only)
config KINETIS_FLEXCAN
bool
default n
config KINETIS_FLEXCAN0
bool "FlexCAN0"
bool "FLEXCAN0"
select KINETIS_FLEXCAN
select NET_CAN_HAVE_TX_DEADLINE
default n
---help---
Support FlexCAN0
config KINETIS_FLEXCAN1
bool "FlexCAN1"
bool "FLEXCAN1"
select KINETIS_FLEXCAN
select NET_CAN_HAVE_TX_DEADLINE
default n
---help---
Support FlexCAN1
@ -930,7 +948,7 @@ config KINETIS_ENET_NORXER
---help---
If selected, then the MII/RMII RXER output will be configured as a
GPIO and pulled low.
choice
prompt "RMII Clock Source"
default KINETIS_EMAC_RMIICLKEXTAL
@ -947,6 +965,76 @@ config KINETIS_EMAC_RMIICLK1588CLKIN
endchoice # RMII Clock Source
endmenu # Kinetis Ethernet Configuration
menu "Kinetis FLEXCAN0 Configuration"
depends on KINETIS_FLEXCAN0
config FLEXCAN0_BITRATE
int "CAN bitrate"
depends on !NET_CAN_CANFD
default 1000000
config FLEXCAN0_SAMPLEP
int "CAN sample point"
depends on !NET_CAN_CANFD
default 75
config FLEXCAN0_ARBI_BITRATE
int "CAN FD Arbitration phase bitrate"
depends on NET_CAN_CANFD
default 1000000
config FLEXCAN0_ARBI_SAMPLEP
int "CAN FD Arbitration phase sample point"
depends on NET_CAN_CANFD
default 80
config FLEXCAN0_DATA_BITRATE
int "CAN FD Arbitration phase bitrate"
depends on NET_CAN_CANFD
default 4000000
config FLEXCAN0_DATA_SAMPLEP
int "CAN FD Arbitration phase sample point"
depends on NET_CAN_CANFD
default 90
endmenu # KINETIS_FLEXCAN0
menu "Kinetis FLEXCAN1 Configuration"
depends on KINETIS_FLEXCAN1
config FLEXCAN1_BITRATE
int "CAN bitrate"
depends on !NET_CAN_CANFD
default 1000000
config FLEXCAN1_SAMPLEP
int "CAN sample point"
depends on !NET_CAN_CANFD
default 75
config FLEXCAN1_ARBI_BITRATE
int "CAN FD Arbitration phase bitrate"
depends on NET_CAN_CANFD
default 1000000
config FLEXCAN1_ARBI_SAMPLEP
int "CAN FD Arbitration phase sample point"
depends on NET_CAN_CANFD
default 80
config FLEXCAN1_DATA_BITRATE
int "CAN FD Arbitration phase bitrate"
depends on NET_CAN_CANFD
default 4000000
config FLEXCAN1_DATA_SAMPLEP
int "CAN FD Arbitration phase sample point"
depends on NET_CAN_CANFD
default 90
endmenu # KINETIS_FLEXCAN1
menu "Kinetis SDHC Configuration"
depends on KINETIS_SDHC

View File

@ -175,4 +175,11 @@ ifeq ($(CONFIG_NET),y)
ifeq ($(CONFIG_KINETIS_ENET),y)
CHIP_CSRCS += kinetis_enet.c
endif
ifeq ($(CONFIG_NET_CAN),y)
ifeq ($(CONFIG_KINETIS_FLEXCAN),y)
CHIP_CSRCS += kinetis_flexcan.c
endif
endif
endif

View File

@ -68,6 +68,8 @@
#define KINETIS_CAN_RXFGMASK_OFFSET 0x0048 /* Rx FIFO Global Mask Register */
#define KINETIS_CAN_RXFIR_OFFSET 0x004c /* Rx FIFO Information Register */
#define KINETIS_CAN_MB_OFFSET 0x0080 /* CAN MB register */
#define KINETIS_CAN_RXIMR_OFFSET(n) (0x0880+((n)<<2)) /* Rn Individual Mask Registers */
#define KINETIS_CAN_RXIMR0_OFFSET 0x0880 /* R0 Individual Mask Registers */
#define KINETIS_CAN_RXIMR1_OFFSET 0x0884 /* R1 Individual Mask Registers */
@ -137,6 +139,7 @@
# define CAN_MCR_IDAM_FMTB (1 << CAN_MCR_IDAM_SHIFT) /* Format B: Two full (or partial) IDs */
# define CAN_MCR_IDAM_FMTC (2 << CAN_MCR_IDAM_SHIFT) /* Format C: Four partial IDs */
# define CAN_MCR_IDAM_FMTD (3 << CAN_MCR_IDAM_SHIFT) /* Format D: All frames rejected */
/* Bits 10-11: Reserved */
#define CAN_MCR_AEN (1 << 12) /* Bit 12: Abort Enable */
#define CAN_MCR_LPRIOEN (1 << 13) /* Bit 13: Local Priority Enable */
@ -162,6 +165,7 @@
#define CAN_CTRL1_ROPSEG_SHIFT (0) /* Bits 0-2: Propagation Segment */
#define CAN_CTRL1_ROPSEG_MASK (7 << CAN_CTRL1_ROPSEG_SHIFT)
#define CAN_CTRL1_PROPSEG(x) (((uint32_t)(((uint32_t)(x)) << 0)) & 0x7)
#define CAN_CTRL1_LOM (1 << 3) /* Bit 3: Listen-Only Mode */
#define CAN_CTRL1_LBUF (1 << 4) /* Bit 4: Lowest Buffer Transmitted First */
#define CAN_CTRL1_TSYN (1 << 5) /* Bit 5: Timer Sync */
@ -176,18 +180,23 @@
#define CAN_CTRL1_BOFFMSK (1 << 15) /* Bit 15: Bus Off Mask */
#define CAN_CTRL1_PSEG2_SHIFT (16) /* Bits 16-18: Phase Segment 2 */
#define CAN_CTRL1_PSEG2_MASK (7 << CAN_CTRL1_PSEG2_SHIFT)
#define CAN_CTRL1_PSEG2(x) (((uint32_t)(((uint32_t)(x)) << 16)) & 0x70000)
#define CAN_CTRL1_PSEG1_SHIFT (19) /* Bits 19-21: Phase Segment 1 */
#define CAN_CTRL1_PSEG1_MASK (7 << CAN_CTRL1_PSEG1_SHIFT)
#define CAN_CTRL1_PSEG1(x) (((uint32_t)(((uint32_t)(x)) << 19)) & 0x380000)
#define CAN_CTRL1_RJW_SHIFT (22) /* Bits 22-23: Resync Jump Width */
#define CAN_CTRL1_RJW_MASK (3 << CAN_CTRL1_RJW_SHIFT)
#define CAN_CTRL1_RJW(x) (((uint32_t)(((uint32_t)(x)) << 22)) & 0xC00000)
#define CAN_CTRL1_PRESDIV_SHIFT (24) /* Bits 24-31: Prescaler Division Factor */
#define CAN_CTRL1_PRESDIV_MASK (0xff << CAN_CTRL1_PRESDIV_SHIFT)
#define CAN_CTRL1_PRESDIV(x) (((uint32_t)(((uint32_t)(x)) << 24)) & 0xFF000000)
/* Free Running Timer */
#define CAN_TIMER_SHIFT (0) /* Bits 0-15: Timer value */
#define CAN_TIMER_MASK (0xffff << CAN_TIMER_SHIFT)
/* Bits 16-31: Reserved */
/* Rx Mailboxes Global Mask Register (32 Rx Mailboxes Global Mask Bits) */
#define CAN_RXMGMASK(n) (1 << (n)) /* Bit n: Rx Mailboxe n Global Mask Bit */
@ -207,6 +216,7 @@
#define CAN_ECR_RXERRCNT_SHIFT (8) /* Bits 8-15: Receive Error Counter */
#define CAN_ECR_RXERRCNT_MASK (0xff << CAN_ECR_RXERRCNT_SHIFT)
/* Bits 16-31: Reserved */
/* Error and Status 1 Register */
#define CAN_ESR1_WAKINT (1 << 0) /* Bit 0: Wake-Up Interrupt */
@ -231,7 +241,9 @@
#define CAN_ESR1_RWRNINT (1 << 16) /* Bit 16: Rx Warning Interrupt Flag */
#define CAN_ESR1_TWRNINT (1 << 17) /* Bit 17: Tx Warning Interrupt Flag */
#define CAN_ESR1_SYNCH (1 << 18) /* Bit 18: CAN Synchronization Status */
/* Bits 19-31: Reserved */
/* Interrupt Masks 2 Register */
#define CAN_IMASK2(n) (1 << (n)) /* Bit n: Buffer MBn Mask */
@ -249,6 +261,7 @@
#define CAN_IFLAG1(n) (1 << (n)) /* Bit n: Buffer MBn Interrupt, n=0..4,8..31 */
/* Control 2 Register */
/* Bits 0-15: Reserved */
#define CAN_CTRL2_EACEN (1 << 16) /* Bit 16: Entire Frame Arbitration Field Comparison Enable (Rx) */
#define CAN_CTRL2_RRS (1 << 17) /* Bit 17: Remote Request Storing */
@ -275,7 +288,9 @@
# define CAN_CTRL2_RFFN_128MB (15 << CAN_CTRL2_RFFN_SHIFT)
#define CAN_CTRL2_WRMFRZ (1 << 28) /* Bit 28: Write-Access to Memory in Freeze mode */
/* Bits 29-31: Reserved */
/* Error and Status 2 Register */
/* Bits 0-12: Reserved */
#define CAN_ESR2_IMB (1 << 13) /* Bit 13: Inactive Mailbox */
#define CAN_ESR2_VPS (1 << 14) /* Bit 14: Valid Priority Status */
@ -283,6 +298,7 @@
#define CAN_ESR2_LPTM_SHIFT (16) /* Bits 16-22: Lowest Priority Tx Mailbox */
#define CAN_ESR2_LPTM_MASK (0x7f << CAN_ESR2_LPTM_SHIFT)
/* Bits 23-31: Reserved */
/* CRC Register */
#define CAN_CRCR_TXCRC_SHIFT (0) /* Bits 0-14: CRC Transmitted */
@ -295,6 +311,7 @@
/* Rx FIFO Global Mask Register (32 Rx FIFO Global Mask Bits) */
/* Rx FIFO Information Register */
/* Bits 9-31: Reserved */
#define CAN_RXFIR_IDHIT_SHIFT (0) /* Bits 0-8: Identifier Acceptance Filter Hit Indicator */
#define CAN_RXFIR_IDHIT_MASK (0x1ff << CAN_RXFIR_IDHIT_SHIFT)
@ -303,6 +320,15 @@
#define CAN_RXIMR(n) (1 << (n)) /* Bit n: Individual Mask Bits */
/* CAN MB TX codes */
#define CAN_TXMB_INACTIVE 0x8 /* MB is not active. */
#define CAN_TXMB_ABORT 0x9 /* MB is aborted. */
#define CAN_TXMB_DATAORREMOTE 0xC /* MB is a TX Data Frame(when MB RTR = 0) or */
/* MB is a TX Remote Request Frame (when MB RTR = 1). */
#define CAN_TXMB_TANSWER 0xE /* MB is a TX Response Request Frame from */
/* an incoming Remote Request Frame. */
#define CAN_TXMB_NOTUSED 0xF /* Not used.*/
/****************************************************************************************************
* Public Types
****************************************************************************************************/
@ -311,8 +337,4 @@
* Public Data
****************************************************************************************************/
/****************************************************************************************************
* Public Functions
****************************************************************************************************/
#endif /* __ARCH_ARM_SRC_KINETIS_HARDWARE_KINETIS_FLEXCAN_H */

View File

@ -62,6 +62,7 @@
/* Configuration ********************************************************************/
/* Bit-encoded input to kinetis_pinconfig() *****************************************/
/* General form (32-bits, only 22 bits are unused in the encoding):
*
* oooo mmmv iiii ifd- ---- -ppp ---b bbbb
@ -80,6 +81,7 @@
#define _PIN_OPTIONS_MASK (15 << _PIN_OPTIONS_SHIFT)
/* Port Modes */
/* Unshifted versions: */
#define PIN_MODE_ANALOG (0) /* 000 Pin Disabled (Analog) */
#define PIN_MODE_ALT1 (1) /* 001 Alternative 1 */
@ -354,7 +356,7 @@ extern "C"
void kinetis_clockconfig(void);
/****************************************************************************
/************************************************************************************
* Name: kinetis_earlyserialinit
*
* Description:
@ -362,13 +364,13 @@ void kinetis_clockconfig(void);
* the serial console will be available during bootup. This must be called
* before arm_serialinit.
*
****************************************************************************/
************************************************************************************/
#ifdef USE_EARLYSERIALINIT
void kinetis_earlyserialinit(void);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_uart_earlyserialinit
*
* Description:
@ -376,13 +378,13 @@ void kinetis_earlyserialinit(void);
* serial console will be available during bootup. This must be called
* before arm_serialinit.
*
****************************************************************************/
************************************************************************************/
#ifdef USE_EARLYSERIALINIT
void kinetis_uart_earlyserialinit(void);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_lpuart_earlyserialinit
*
* Description:
@ -390,7 +392,7 @@ void kinetis_uart_earlyserialinit(void);
* serial console will be available during bootup. This must be called
* before arm_serialinit.
*
****************************************************************************/
************************************************************************************/
#ifdef USE_EARLYSERIALINIT
void kinetis_lpuart_earlyserialinit(void);
@ -408,7 +410,7 @@ void kinetis_lpuart_earlyserialinit(void);
void kinetis_lowsetup(void);
/****************************************************************************
/************************************************************************************
* Name: kinetis_uart_serialinit
*
* Description:
@ -421,13 +423,13 @@ void kinetis_lowsetup(void);
* Returned Value:
* The next TTY number available for assignment
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_UART_DEVICE
unsigned int kinetis_uart_serialinit(unsigned int first);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_lpuart_serialinit
*
* Description:
@ -440,43 +442,43 @@ unsigned int kinetis_uart_serialinit(unsigned int first);
* Returned Value:
* The next TTY number available for assignment
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_LPUART_DEVICE
unsigned int kinetis_lpuart_serialinit(unsigned int first);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_uartreset
*
* Description:
* Reset a UART.
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_UART_DEVICE
void kinetis_uartreset(uintptr_t uart_base);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_lpuartreset
*
* Description:
* Reset a UART.
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_LPUART_DEVICE
void kinetis_lpuartreset(uintptr_t uart_base);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_uartconfigure
*
* Description:
* Configure a UART as a RS-232 UART.
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_UART_DEVICE
void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock,
@ -485,13 +487,13 @@ void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock,
bool iflow, bool oflow);
#endif
/****************************************************************************
/************************************************************************************
* Name: kinetis_lpuartconfigure
*
* Description:
* Configure a UART as a RS-232 UART.
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_LPUART_DEVICE
void kinetis_lpuartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock,
@ -672,7 +674,7 @@ void kinetis_pindump(uint32_t pinset, const char *msg);
void kinetis_clrpend(int irq);
/****************************************************************************
/************************************************************************************
* Name: sdhc_initialize
*
* Description:
@ -684,14 +686,14 @@ void kinetis_clrpend(int irq);
* Returned Value:
* A reference to an SDIO interface structure. NULL is returned on failures.
*
****************************************************************************/
************************************************************************************/
#ifdef CONFIG_KINETIS_SDHC
struct sdio_dev_s;
FAR struct sdio_dev_s *sdhc_initialize(int slotno);
#endif
/****************************************************************************
/************************************************************************************
* Name: sdhc_mediachange
*
* Description:
@ -708,13 +710,13 @@ FAR struct sdio_dev_s *sdhc_initialize(int slotno);
* Returned Value:
* None
*
****************************************************************************/
************************************************************************************/
#ifdef CONFIG_KINETIS_SDHC
void sdhc_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot);
#endif
/****************************************************************************
/************************************************************************************
* Name: sdio_wrprotect
*
* Description:
@ -728,7 +730,7 @@ void sdhc_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot);
* Returned Value:
* None
*
****************************************************************************/
************************************************************************************/
#ifdef CONFIG_KINETIS_SDHC
void sdhc_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect);
@ -738,5 +740,46 @@ void sdhc_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect);
}
#endif
/************************************************************************************
* Name: kinetis_netinitialize
*
* Description:
* Initialize the Ethernet controller and driver
*
* Input Parameters:
* intf - In the case where there are multiple EMACs, this value
* identifies which EMAC is to be initialized.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
************************************************************************************/
#ifdef CONFIG_KINETIS_ENET
int kinetis_netinitialize(int intf);
#endif
/************************************************************************************
* Function: kinetis_caninitialize
*
* Description:
* Initialize the CAN controller and driver
*
* Input Parameters:
* intf - In the case where there are multiple CAN, this value
* identifies which CAN is to be initialized.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
************************************************************************************/
#ifdef CONFIG_KINETIS_CAN
int kinetis_caninitialize(int intf)
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_KINETIS_KINETIS_H */

File diff suppressed because it is too large Load Diff