diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-12-22 15:59:50 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-12-22 15:59:50 +0000 |
commit | 5b038d28629472894c07f4efc604c992c9d8264d (patch) | |
tree | 63468d1d6ac45b29fbd91bfc9b9e1d7d6d7b17c0 /nuttx/arch/arm/src/stm32 | |
parent | 0404da840332858afad5ecbfcba1290c191f0078 (diff) | |
download | px4-nuttx-5b038d28629472894c07f4efc604c992c9d8264d.tar.gz px4-nuttx-5b038d28629472894c07f4efc604c992c9d8264d.tar.bz2 px4-nuttx-5b038d28629472894c07f4efc604c992c9d8264d.zip |
Add loopback support to STM32 CAN driver; Add apps/examples/can loopback test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4213 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/stm32')
-rwxr-xr-x | nuttx/arch/arm/src/stm32/stm32_can.c | 46 | ||||
-rw-r--r-- | nuttx/arch/arm/src/stm32/stm32_can.h | 56 |
2 files changed, 71 insertions, 31 deletions
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 */ |