From 4750867a34ebfc4e79a62ea39dbe19a74a0aa18c Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 1 Apr 2013 14:10:54 +0000 Subject: [PATCH] Add support for CAN1 and CAN2 to zkit-arm-1769. From M. Kannan git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5808 42af7a65-404d-4744-a932-0658087f49c3 --- configs/zkit-arm-1769/include/board.h | 2 ++ configs/zkit-arm-1769/src/up_can.c | 50 ++++++++++++++++----------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/configs/zkit-arm-1769/include/board.h b/configs/zkit-arm-1769/include/board.h index 54362fc034..63dd4d914c 100644 --- a/configs/zkit-arm-1769/include/board.h +++ b/configs/zkit-arm-1769/include/board.h @@ -231,6 +231,8 @@ #define GPIO_CAN1_RD GPIO_CAN1_RD_1 #define GPIO_CAN1_TD GPIO_CAN1_TD_1 +#define GPIO_CAN2_RD GPIO_CAN2_RD_2 +#define GPIO_CAN2_TD GPIO_CAN2_TD_2 #define GPIO_I2C1_SDA GPIO_I2C0_SDA #define GPIO_I2C1_SCL GPIO_I2C0_SCL #define GPIO_SSP1_SCK GPIO_SSP1_SCK_1 diff --git a/configs/zkit-arm-1769/src/up_can.c b/configs/zkit-arm-1769/src/up_can.c index 0f50cd146d..eaec05696b 100644 --- a/configs/zkit-arm-1769/src/up_can.c +++ b/configs/zkit-arm-1769/src/up_can.c @@ -5,7 +5,7 @@ * Copyright (C) 2013 Zilogic Systems. All rights reserved. * Author: Raashid Muhammed * - * Based on configs/olimex-lpc1766stk/src/up_can.c + * Based on configs/olimex-lpc1766stk/src/up_can.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -63,21 +63,9 @@ * Pre-processor Definitions ************************************************************************************/ /* Configuration ********************************************************************/ +#define CAN_PORT1 1 +#define CAN_PORT2 2 -#if defined(CONFIG_LPC17_CAN1) && defined(CONFIG_LPC17_CAN2) -# warning "Both CAN1 and CAN2 are enabled. Assuming only CAN1." -# undef CONFIG_LPC17_CAN2 -#endif - -#ifdef CONFIG_LPC17_CAN2 -# warning "CAN2 is not connected on the ZKIT-ARM-1769" -#endif - -#ifdef CONFIG_LPC17_CAN1 -# define CAN_PORT 1 -#else -# define CAN_PORT 2 -#endif /* Debug ***************************************************************************/ /* Non-standard debug that may be enabled just for testing CAN */ @@ -121,23 +109,45 @@ int can_devinit(void) if (!initialized) { - /* Call lpc17_caninitialize() to get an instance of the CAN interface */ +#ifdef CONFIG_LPC17_CAN1 + /* Call lpc17_caninitialize() to get an instance of the CAN1 interface */ - can = lpc17_caninitialize(CAN_PORT); + can = lpc17_caninitialize(CAN_PORT1); if (can == NULL) { - candbg("ERROR: Failed to get CAN interface\n"); + candbg("ERROR: Failed to get CAN1 interface\n"); return -ENODEV; } - /* Register the CAN driver at "/dev/can0" */ + /* Register the CAN1 driver at "/dev/can0" */ ret = can_register("/dev/can0", can); if (ret < 0) { - candbg("ERROR: can_register failed: %d\n", ret); + candbg("ERROR: CAN1 register failed: %d\n", ret); return ret; } +#endif + +#ifdef CONFIG_LPC17_CAN2 + /* Call lpc17_caninitialize() to get an instance of the CAN2 interface */ + + can = lpc17_caninitialize(CAN_PORT2); + if (can == NULL) + { + candbg("ERROR: Failed to get CAN2 interface\n"); + return -ENODEV; + } + + /* Register the CAN2 driver at "/dev/can1" */ + + ret = can_register("/dev/can1", can); + if (ret < 0) + { + candbg("ERROR: CAN2 register failed: %d\n", ret); + return ret; + } +#endif /* Now we are initialized */