diff options
Diffstat (limited to 'nuttx/arch/arm')
-rw-r--r-- | nuttx/arch/arm/src/common/up_internal.h | 6 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/lpc17xx/lpc17_can.c | 4 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/lpc17xx/lpc17_internal.h | 19 | ||||
-rwxr-xr-x | nuttx/arch/arm/src/stm32/stm32_can.c | 46 | ||||
-rw-r--r-- | nuttx/arch/arm/src/stm32/stm32_can.h | 56 |
5 files changed, 92 insertions, 39 deletions
diff --git a/nuttx/arch/arm/src/common/up_internal.h b/nuttx/arch/arm/src/common/up_internal.h index c90f49a3d..306a44b49 100644 --- a/nuttx/arch/arm/src/common/up_internal.h +++ b/nuttx/arch/arm/src/common/up_internal.h @@ -340,11 +340,6 @@ extern void up_usbuninitialize(void); # define up_usbuninitialize() #endif -/* CAN **********************************************************************/ - -struct can_dev_s; /* Forward reference */ -extern FAR struct can_dev_s *up_caninitialize(int port); - /**************************************************************************** * Name: up_check_stack * @@ -361,7 +356,6 @@ extern FAR struct can_dev_s *up_caninitialize(int port); * ****************************************************************************/ - #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) extern size_t up_check_stack(void); extern size_t up_check_tcbstack(FAR _TCB); diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_can.c b/nuttx/arch/arm/src/lpc17xx/lpc17_can.c index f714b5715..dfcd1f0e7 100755 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_can.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_can.c @@ -354,7 +354,7 @@ static int can_interrupt(int irq, void *context) ****************************************************************************/ /**************************************************************************** - * Name: up_caninitialize + * Name: lpc17_caninitialize * * Description: * Initialize the selected can port @@ -367,7 +367,7 @@ static int can_interrupt(int irq, void *context) * ****************************************************************************/ -FAR struct can_dev_s *up_caninitialize(int port) +FAR struct can_dev_s *lpc17_caninitialize(int port) { uint32_t regval; irqstate_t flags; diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_internal.h b/nuttx/arch/arm/src/lpc17xx/lpc17_internal.h index c33ed21b2..06ac7b47a 100755 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_internal.h +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_internal.h @@ -786,6 +786,25 @@ FAR struct adc_dev_s *stm32_adcinitialize(void); EXTERN FAR struct dac_dev_s *lpc17_dacinitialize(void); #endif +/**************************************************************************** + * Name: lpc17_caninitialize + * + * Description: + * Initialize the selected can port + * + * Input Parameter: + * Port number (for hardware that has mutiple can interfaces) + * + * Returned Value: + * Valid can device structure reference on succcess; a NULL on failure + * + ****************************************************************************/ + +#if defined(CONFIG_CAN) && (defined(CONFIG_LPC17_CAN1) || defined(CONFIG_LPC17_CAN2)) +struct can_dev_s; +EXTERN FAR struct can_dev_s *lpc17_caninitialize(int port); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/arch/arm/src/stm32/stm32_can.c b/nuttx/arch/arm/src/stm32/stm32_can.c index 46e01797b..fc5a4f4ab 100755 --- a/nuttx/arch/arm/src/stm32/stm32_can.c +++ b/nuttx/arch/arm/src/stm32/stm32_can.c @@ -60,34 +60,11 @@ #include "stm32_internal.h" #include "stm32_can.h" -#ifdef CONFIG_CAN +#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)) /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* Configuration ************************************************************/ -/* Up to 2 CAN interfaces are supported */ - -#if STM32_NCAN < 2 -# undef CONFIG_STM32_CAN2 -#endif - -#if STM32_NCAN < 1 -# undef CONFIG_STM32_CAN1 -#endif - -#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2) - -/* CAN BAUD */ - -#if defined(CONFIG_STM32_CAN1) && !defined(CONFIG_CAN1_BAUD) -# error "CONFIG_CAN1_BAUD is not defined" -#endif - -#if defined(CONFIG_STM32_CAN2) && !defined(CONFIG_CAN2_BAUD) -# error "CONFIG_CAN2_BAUD is not defined" -#endif - /* Delays *******************************************************************/ /* Time out for INAK bit */ @@ -762,7 +739,7 @@ static int can_rx0interrupt(int irq, void *context) /* Provide the data to the upper half driver */ - ret = can_receive(dev, (uint16_t)CAN_MSG(id, rtr, dlc), data); + ret = can_receive(dev, (uint16_t)CAN_HDR(id, rtr, dlc), data); /* Release the FIFO0 */ @@ -925,7 +902,7 @@ static int can_bittiming(struct stm32_can_s *priv) canvdbg("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp); /* Configure bit timing. This also does the the following, less obvious - * things: + * things. Unless loopback mode is enabled, it: * * - Disables silent mode. * - Disables loopback mode. @@ -936,6 +913,10 @@ static int can_bittiming(struct stm32_can_s *priv) tmp = ((brp - 1) << CAN_BTR_BRP_SHIFT) | ((ts1 - 1) << CAN_BTR_TS1_SHIFT) | ((ts2 - 1) << CAN_BTR_TS2_SHIFT) | ((1 - 1) << CAN_BTR_SJW_SHIFT); +#ifdef CONFIG_CAN_LOOPBACK + tmp |= (CAN_BTR_LBKM | CAN_BTR_SILM); +#endif + can_putreg(priv, STM32_CAN_BTR_OFFSET, tmp); return OK; } @@ -1126,7 +1107,7 @@ static int can_filterinit(struct stm32_can_s *priv) ****************************************************************************/ /**************************************************************************** - * Name: up_caninitialize + * Name: stm32_caninitialize * * Description: * Initialize the selected CAN port @@ -1139,7 +1120,7 @@ static int can_filterinit(struct stm32_can_s *priv) * ****************************************************************************/ -FAR struct can_dev_s *up_caninitialize(int port) +FAR struct can_dev_s *stm32_caninitialize(int port) { struct can_dev_s *dev = NULL; @@ -1158,8 +1139,10 @@ FAR struct can_dev_s *up_caninitialize(int port) * file must have been disambiguated in the board.h file. */ +#ifndef CONFIG_CAN_LOOPBACK stm32_configgpio(GPIO_CAN1_RX); stm32_configgpio(GPIO_CAN1_TX); +#endif } else #endif @@ -1174,19 +1157,20 @@ FAR struct can_dev_s *up_caninitialize(int port) * file must have been disambiguated in the board.h file. */ +#ifndef CONFIG_CAN_LOOPBACK stm32_configgpio(GPIO_CAN2_RX); stm32_configgpio(GPIO_CAN2_TX); +#endif } else #endif { - candbg("Unsupported port %d\n", priv->port); + candbg("Unsupported port %d\n", port); return NULL; } return dev; } -#endif /* CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2 */ -#endif /* CONFIG_CAN */ +#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */ diff --git a/nuttx/arch/arm/src/stm32/stm32_can.h b/nuttx/arch/arm/src/stm32/stm32_can.h index 8d9dccadd..b842627b8 100644 --- a/nuttx/arch/arm/src/stm32/stm32_can.h +++ b/nuttx/arch/arm/src/stm32/stm32_can.h @@ -50,17 +50,73 @@ /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ +/* Configuration ********************************************************************/ +/* Up to 2 CAN interfaces are supported */ + +#if STM32_NCAN < 2 +# undef CONFIG_STM32_CAN2 +#endif + +#if STM32_NCAN < 1 +# undef CONFIG_STM32_CAN1 +#endif + +#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)) + +/* CAN BAUD */ + +#if defined(CONFIG_STM32_CAN1) && !defined(CONFIG_CAN1_BAUD) +# error "CONFIG_CAN1_BAUD is not defined" +#endif + +#if defined(CONFIG_STM32_CAN2) && !defined(CONFIG_CAN2_BAUD) +# error "CONFIG_CAN2_BAUD is not defined" +#endif /************************************************************************************ * Public Types ************************************************************************************/ +#ifndef __ASSEMBLY__ + /************************************************************************************ * Public Data ************************************************************************************/ +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + /************************************************************************************ * Public Functions ************************************************************************************/ +/**************************************************************************** + * Name: stm32_caninitialize + * + * Description: + * Initialize the selected CAN port + * + * Input Parameter: + * Port number (for hardware that has mutiple CAN interfaces) + * + * Returned Value: + * Valid CAN device structure reference on succcess; a NULL on failure + * + ****************************************************************************/ + +struct can_dev_s; +EXTERN FAR struct can_dev_s *stm32_caninitialize(int port); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */ #endif /* __ARCH_ARM_SRC_STM32_STM32_CAN_H */ |