diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html
index e6d3134dee2..c1db0c7eebb 100644
--- a/Documentation/NuttxPortingGuide.html
+++ b/Documentation/NuttxPortingGuide.html
@@ -4545,7 +4545,7 @@ void board_autoled_off(int led);
- Interface Definition.
- The header file for the NuttX CAN driver resides at
include/nuttx/drivers/can.h.
+ The header file for the NuttX CAN driver resides at include/nuttx/can/can.h.
This header file includes both the application level interface to the CAN driver as well as the interface between the "upper half" and "lower half" drivers.
The CAN module uses a standard character driver framework.
diff --git a/arch/arm/src/lpc17xx/lpc17_can.c b/arch/arm/src/lpc17xx/lpc17_can.c
index 11ac88cc04d..94f1987280c 100644
--- a/arch/arm/src/lpc17xx/lpc17_can.c
+++ b/arch/arm/src/lpc17xx/lpc17_can.c
@@ -57,7 +57,7 @@
#include
#include
#include
-#include
+#include
#include "up_internal.h"
#include "up_arch.h"
diff --git a/arch/arm/src/sama5/sam_can.c b/arch/arm/src/sama5/sam_can.c
index 4020055e89a..029a4df1c6b 100644
--- a/arch/arm/src/sama5/sam_can.c
+++ b/arch/arm/src/sama5/sam_can.c
@@ -60,7 +60,7 @@
#include
#include
-#include
+#include
#include "up_internal.h"
#include "up_arch.h"
diff --git a/arch/arm/src/sama5/sam_can.h b/arch/arm/src/sama5/sam_can.h
index 5a26fe83143..83a08f756bb 100644
--- a/arch/arm/src/sama5/sam_can.h
+++ b/arch/arm/src/sama5/sam_can.h
@@ -45,7 +45,7 @@
#include "chip.h"
#include "chip/sam_can.h"
-#include
+#include
#if defined(CONFIG_CAN) && (defined(CONFIG_SAMA5_CAN0) || defined(CONFIG_SAMA5_CAN1))
diff --git a/arch/arm/src/samv7/sam_mcan.c b/arch/arm/src/samv7/sam_mcan.c
index 7d16f0898df..d4807941a4c 100644
--- a/arch/arm/src/samv7/sam_mcan.c
+++ b/arch/arm/src/samv7/sam_mcan.c
@@ -56,7 +56,7 @@
#include
#include
#include
-#include
+#include
#include "cache.h"
#include "up_internal.h"
diff --git a/arch/arm/src/samv7/sam_mcan.h b/arch/arm/src/samv7/sam_mcan.h
index 07ecdd71ad3..3672547788a 100644
--- a/arch/arm/src/samv7/sam_mcan.h
+++ b/arch/arm/src/samv7/sam_mcan.h
@@ -45,7 +45,7 @@
#include "chip.h"
#include "chip/sam_mcan.h"
-#include
+#include
#if defined(CONFIG_CAN) && (defined(CONFIG_SAMV7_MCAN0) || \
defined(CONFIG_SAMV7_MCAN1))
diff --git a/arch/arm/src/stm32/stm32_can.c b/arch/arm/src/stm32/stm32_can.c
index d90e5cd06da..4497dd97662 100644
--- a/arch/arm/src/stm32/stm32_can.c
+++ b/arch/arm/src/stm32/stm32_can.c
@@ -53,7 +53,7 @@
#include
#include
#include
-#include
+#include
#include "up_internal.h"
#include "up_arch.h"
diff --git a/arch/arm/src/stm32/stm32_can.h b/arch/arm/src/stm32/stm32_can.h
index 765dc95c0ca..f06231ab60a 100644
--- a/arch/arm/src/stm32/stm32_can.h
+++ b/arch/arm/src/stm32/stm32_can.h
@@ -45,7 +45,7 @@
#include "chip.h"
#include "chip/stm32_can.h"
-#include
+#include
/************************************************************************************
* Pre-processor Definitions
diff --git a/arch/arm/src/stm32l4/stm32l4_can.c b/arch/arm/src/stm32l4/stm32l4_can.c
index ed14ca43609..7667481c6cd 100644
--- a/arch/arm/src/stm32l4/stm32l4_can.c
+++ b/arch/arm/src/stm32l4/stm32l4_can.c
@@ -57,7 +57,7 @@
#include
#include
#include
-#include
+#include
#include "up_internal.h"
#include "up_arch.h"
diff --git a/arch/arm/src/stm32l4/stm32l4_can.h b/arch/arm/src/stm32l4/stm32l4_can.h
index 86eb26fb659..b5db2c42865 100644
--- a/arch/arm/src/stm32l4/stm32l4_can.h
+++ b/arch/arm/src/stm32l4/stm32l4_can.h
@@ -49,7 +49,7 @@
#include "chip.h"
#include "chip/stm32l4_can.h"
-#include
+#include
/************************************************************************************
* Pre-processor Definitions
diff --git a/configs/clicker2-stm32/src/stm32_can.c b/configs/clicker2-stm32/src/stm32_can.c
index 2c3b98ea6f1..003c0fd3909 100644
--- a/configs/clicker2-stm32/src/stm32_can.c
+++ b/configs/clicker2-stm32/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "stm32.h"
diff --git a/configs/nucleo-f303re/src/stm32_can.c b/configs/nucleo-f303re/src/stm32_can.c
index e1f1a2d7135..1541c8b2acc 100644
--- a/configs/nucleo-f303re/src/stm32_can.c
+++ b/configs/nucleo-f303re/src/stm32_can.c
@@ -45,7 +45,7 @@
#include
#include
-#include
+#include
#include "stm32.h"
diff --git a/configs/olimex-lpc1766stk/src/lpc17_can.c b/configs/olimex-lpc1766stk/src/lpc17_can.c
index a9e1b68c883..fcc99e54dd4 100644
--- a/configs/olimex-lpc1766stk/src/lpc17_can.c
+++ b/configs/olimex-lpc1766stk/src/lpc17_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/olimex-stm32-e407/src/stm32_can.c b/configs/olimex-stm32-e407/src/stm32_can.c
index b5c7bce8bcb..f4e941bf5a1 100644
--- a/configs/olimex-stm32-e407/src/stm32_can.c
+++ b/configs/olimex-stm32-e407/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "stm32.h"
diff --git a/configs/olimex-stm32-h405/src/stm32_can.c b/configs/olimex-stm32-h405/src/stm32_can.c
index 6f361af9406..42164d8959a 100644
--- a/configs/olimex-stm32-h405/src/stm32_can.c
+++ b/configs/olimex-stm32-h405/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
diff --git a/configs/olimex-stm32-h407/src/stm32_can.c b/configs/olimex-stm32-h407/src/stm32_can.c
index b482342e617..a14d0f3f50a 100644
--- a/configs/olimex-stm32-h407/src/stm32_can.c
+++ b/configs/olimex-stm32-h407/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "stm32.h"
diff --git a/configs/olimex-stm32-p107/src/stm32_can.c b/configs/olimex-stm32-p107/src/stm32_can.c
index 9889f836b22..85d36cf5156 100644
--- a/configs/olimex-stm32-p107/src/stm32_can.c
+++ b/configs/olimex-stm32-p107/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/olimex-stm32-p207/src/stm32_can.c b/configs/olimex-stm32-p207/src/stm32_can.c
index ab20e9fcb90..0f9e2dffe2e 100644
--- a/configs/olimex-stm32-p207/src/stm32_can.c
+++ b/configs/olimex-stm32-p207/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "stm32.h"
diff --git a/configs/olimex-stm32-p407/src/stm32_can.c b/configs/olimex-stm32-p407/src/stm32_can.c
index 763df54e78a..373d15e9694 100644
--- a/configs/olimex-stm32-p407/src/stm32_can.c
+++ b/configs/olimex-stm32-p407/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "stm32.h"
diff --git a/configs/olimexino-stm32/src/stm32_can.c b/configs/olimexino-stm32/src/stm32_can.c
index 862def8094d..5e942ea6fca 100644
--- a/configs/olimexino-stm32/src/stm32_can.c
+++ b/configs/olimexino-stm32/src/stm32_can.c
@@ -43,7 +43,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/sama5d3-xplained/src/sam_can.c b/configs/sama5d3-xplained/src/sam_can.c
index cbd76837d8b..f9e39e86126 100644
--- a/configs/sama5d3-xplained/src/sam_can.c
+++ b/configs/sama5d3-xplained/src/sam_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/sama5d3x-ek/src/sam_can.c b/configs/sama5d3x-ek/src/sam_can.c
index 4fc441f1101..3c083a9ff15 100644
--- a/configs/sama5d3x-ek/src/sam_can.c
+++ b/configs/sama5d3x-ek/src/sam_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/same70-xplained/src/sam_mcan.c b/configs/same70-xplained/src/sam_mcan.c
index 5a96930a639..f09f8504c7f 100644
--- a/configs/same70-xplained/src/sam_mcan.c
+++ b/configs/same70-xplained/src/sam_mcan.c
@@ -43,7 +43,7 @@
#include
#include
-#include
+#include
#include
#include "sam_mcan.h"
diff --git a/configs/samv71-xult/src/sam_mcan.c b/configs/samv71-xult/src/sam_mcan.c
index f17d9ccb20e..d977e8f16df 100644
--- a/configs/samv71-xult/src/sam_mcan.c
+++ b/configs/samv71-xult/src/sam_mcan.c
@@ -43,7 +43,7 @@
#include
#include
-#include
+#include
#include
#include "sam_mcan.h"
diff --git a/configs/shenzhou/src/stm32_can.c b/configs/shenzhou/src/stm32_can.c
index 6a08cc1fc0f..34b1c9e7c3f 100644
--- a/configs/shenzhou/src/stm32_can.c
+++ b/configs/shenzhou/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/stm3210e-eval/src/stm32_can.c b/configs/stm3210e-eval/src/stm32_can.c
index 06e24930ea6..6da4ee58d6f 100644
--- a/configs/stm3210e-eval/src/stm32_can.c
+++ b/configs/stm3210e-eval/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/stm3220g-eval/src/stm32_can.c b/configs/stm3220g-eval/src/stm32_can.c
index e362ad95c5b..e1264c9e524 100644
--- a/configs/stm3220g-eval/src/stm32_can.c
+++ b/configs/stm3220g-eval/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/stm3240g-eval/src/stm32_can.c b/configs/stm3240g-eval/src/stm32_can.c
index 3ebae0dfa34..82697c7ed57 100644
--- a/configs/stm3240g-eval/src/stm32_can.c
+++ b/configs/stm3240g-eval/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/stm32f4discovery/src/stm32_can.c b/configs/stm32f4discovery/src/stm32_can.c
index 702dff902f3..5464205b66b 100644
--- a/configs/stm32f4discovery/src/stm32_can.c
+++ b/configs/stm32f4discovery/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/viewtool-stm32f107/src/stm32_can.c b/configs/viewtool-stm32f107/src/stm32_can.c
index 462e5a72ba8..0ddfaa074d4 100644
--- a/configs/viewtool-stm32f107/src/stm32_can.c
+++ b/configs/viewtool-stm32f107/src/stm32_can.c
@@ -42,7 +42,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/configs/zkit-arm-1769/src/lpc17_can.c b/configs/zkit-arm-1769/src/lpc17_can.c
index 6b4a1021f8c..3815c7f1ef8 100644
--- a/configs/zkit-arm-1769/src/lpc17_can.c
+++ b/configs/zkit-arm-1769/src/lpc17_can.c
@@ -47,7 +47,7 @@
#include
#include
-#include
+#include
#include
#include "chip.h"
diff --git a/drivers/Kconfig b/drivers/Kconfig
index d7bc2653746..937a5e13fea 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -157,130 +157,11 @@ menuconfig CAN
default n
---help---
This selection enables building of the "upper-half" CAN driver.
- See include/nuttx/drivers/can.h for further CAN driver information.
+ See include/nuttx/can/can.h for further CAN driver information.
if CAN
-
-config CAN_EXTID
- bool "CAN extended IDs"
- default n
- ---help---
- Enables support for the 28-bit extended ID. Default Standard 11-bit
- IDs.
-
-config ARCH_HAVE_CAN_ERRORS
- bool
- default n
-
-config CAN_ERRORS
- bool "CAN error reporting"
- default n
- depends on ARCH_HAVE_CAN_ERRORS
- ---help---
- Support CAN error reporting. If this option is selected then CAN
- error reporting is enabled. In the event of an error, the ch_error
- bit will be set in the CAN message and the following message payload
- will include a more detailed description of certain errors.
-
-config CAN_FD
- bool "CAN FD"
- default n
- ---help---
- Enables support for the CAN_FD mode.
-
-config CAN_FIFOSIZE
- int "CAN driver I/O buffer size"
- default 8
- ---help---
- The size of the circular buffer of CAN messages. Default: 8
-
-config CAN_NPENDINGRTR
- int "Number of pending RTRs"
- default 4
- ---help---
- The size of the list of pending RTR requests. Default: 4
-
-config CAN_TXREADY
- bool "can_txready interface"
- default n
- select SCHED_WORKQUEUE
- ---help---
- This selection enables the can_txready() interface. This interface
- is needed only for CAN hardware that supports queing of outgoing
- messages in a H/W FIFO.
-
- The CAN upper half driver also supports a queue of output messages
- in a S/W FIFO. Messages are added to that queue when when
- can_write() is called and removed from the queue in can_txdone()
- when each TX message is complete.
-
- After each message is added to the S/W FIFO, the CAN upper half
- driver will attempt to send the message by calling into the lower
- half driver. That send will not be performed if the lower half
- driver is busy, i.e., if dev_txready() returns false. In that
- case, the number of messages in the S/W FIFO can grow. If the
- S/W FIFO becomes full, then can_write() will wait for space in
- the S/W FIFO.
-
- If the CAN hardware does not support a H/W FIFO then busy means
- that the hardware is actively sending the message and is
- guaranteed to become non busy (i.e, dev_txready()) when the
- send transfer completes and can_txdone() is called. So the call
- to can_txdone() means that the transfer has completed and also
- that the hardware is ready to accept another transfer.
-
- If the CAN hardware supports a H/W FIFO, can_txdone() is not
- called when the tranfer is complete, but rather when the
- transfer is queued in the H/W FIFO. When the H/W FIFO becomes
- full, then dev_txready() will report false and the number of
- queued messages in the S/W FIFO will grow.
-
- There is no mechanism in this case to inform the upper half
- driver when the hardware is again available, when there is
- again space in the H/W FIFO. can_txdone() will not be called
- again. If the S/W FIFO becomes full, then the upper half
- driver will wait for space to become available, but there is
- no event to awaken it and the driver will hang.
-
- Enabling this feature adds support for the can_txready()
- interface. This function is called from the lower half
- driver's CAN interrupt handler each time a TX transfer
- completes. This is a sure indication that the H/W FIFO is
- no longer full. can_txready() will then awaken the
- can_write() logic and the hang condition is avoided.
-
-choice
- prompt "TX Ready Work Queue"
- default CAN_TXREADY_HIPRI
- depends on CAN_TXREADY
-
-config CAN_TXREADY_LOPRI
- bool "Low-priority work queue"
- select SCHED_LPWORK
-
-config CAN_TXREADY_HIPRI
- bool "High-priority work queue"
- select SCHED_HPWORK
-
-endchoice # TX Ready Work Queue
-
-config CAN_LOOPBACK
- bool "CAN loopback mode"
- default n
- ---help---
- A CAN driver may or may not support a loopback mode for testing. If the
- driver does support loopback mode, the setting will enable it. (If the
- driver does not, this setting will have no effect).
-
-config CAN_NPOLLWAITERS
- int "Number of poll waiters"
- default 2
- depends on !DISABLE_POLL
- ---help---
- The maximum number of threads that may be waiting on the
- poll method.
-
-endif # CAN
+source drivers/can/Kconfig
+endif
config ARCH_HAVE_PWM_PULSECOUNT
bool
diff --git a/drivers/Makefile b/drivers/Makefile
index 5946cc123a7..83d830c8abb 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -52,6 +52,7 @@ VPATH = .
include analog$(DELIM)Make.defs
include audio$(DELIM)Make.defs
include bch$(DELIM)Make.defs
+include can$(DELIM)Make.defs
include i2c$(DELIM)Make.defs
include input$(DELIM)Make.defs
include ioexpander$(DELIM)Make.defs
diff --git a/drivers/README.txt b/drivers/README.txt
index f9f23af06f2..ec65ccbe8eb 100644
--- a/drivers/README.txt
+++ b/drivers/README.txt
@@ -12,10 +12,6 @@ Contents:
Files in this directory
^^^^^^^^^^^^^^^^^^^^^^^
-can.c
- This is a CAN driver. See include/nuttx/drivers/can.h for usage
- information.
-
dev_null.c and dev_zero.c
These files provide the standard /dev/null and /dev/zero devices.
See include/nuttx/fs/fs.h for functions that should be called if you
@@ -55,6 +51,10 @@ bch/
performed by loop.c. See include/nuttx/fs/fs.h for registration
information.
+can/
+ This is the CAN drivers and logic support. See include/nuttx/can/can.h
+ for usage information.
+
contactless/
Contactless devices are related to wireless devices. They are not
communication devices with other similar peers, but couplers/interfaces
diff --git a/drivers/can/Kconfig b/drivers/can/Kconfig
new file mode 100644
index 00000000000..577dbea8d15
--- /dev/null
+++ b/drivers/can/Kconfig
@@ -0,0 +1,127 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+if CAN
+
+config CAN_EXTID
+ bool "CAN extended IDs"
+ default n
+ ---help---
+ Enables support for the 29-bit extended ID. Default Standard 11-bit
+ IDs.
+
+config ARCH_HAVE_CAN_ERRORS
+ bool
+ default n
+
+config CAN_ERRORS
+ bool "CAN error reporting"
+ default n
+ depends on ARCH_HAVE_CAN_ERRORS
+ ---help---
+ Support CAN error reporting. If this option is selected then CAN
+ error reporting is enabled. In the event of an error, the ch_error
+ bit will be set in the CAN message and the following message payload
+ will include a more detailed description of certain errors.
+
+config CAN_FD
+ bool "CAN FD"
+ default n
+ ---help---
+ Enables support for the CAN_FD mode.
+
+config CAN_FIFOSIZE
+ int "CAN driver I/O buffer size"
+ default 8
+ ---help---
+ The size of the circular buffer of CAN messages. Default: 8
+
+config CAN_NPENDINGRTR
+ int "Number of pending RTRs"
+ default 4
+ ---help---
+ The size of the list of pending RTR requests. Default: 4
+
+config CAN_TXREADY
+ bool "can_txready interface"
+ default n
+ select SCHED_WORKQUEUE
+ ---help---
+ This selection enables the can_txready() interface. This interface
+ is needed only for CAN hardware that supports queing of outgoing
+ messages in a H/W FIFO.
+
+ The CAN upper half driver also supports a queue of output messages
+ in a S/W FIFO. Messages are added to that queue when when
+ can_write() is called and removed from the queue in can_txdone()
+ when each TX message is complete.
+
+ After each message is added to the S/W FIFO, the CAN upper half
+ driver will attempt to send the message by calling into the lower
+ half driver. That send will not be performed if the lower half
+ driver is busy, i.e., if dev_txready() returns false. In that
+ case, the number of messages in the S/W FIFO can grow. If the
+ S/W FIFO becomes full, then can_write() will wait for space in
+ the S/W FIFO.
+
+ If the CAN hardware does not support a H/W FIFO then busy means
+ that the hardware is actively sending the message and is
+ guaranteed to become non busy (i.e, dev_txready()) when the
+ send transfer completes and can_txdone() is called. So the call
+ to can_txdone() means that the transfer has completed and also
+ that the hardware is ready to accept another transfer.
+
+ If the CAN hardware supports a H/W FIFO, can_txdone() is not
+ called when the tranfer is complete, but rather when the
+ transfer is queued in the H/W FIFO. When the H/W FIFO becomes
+ full, then dev_txready() will report false and the number of
+ queued messages in the S/W FIFO will grow.
+
+ There is no mechanism in this case to inform the upper half
+ driver when the hardware is again available, when there is
+ again space in the H/W FIFO. can_txdone() will not be called
+ again. If the S/W FIFO becomes full, then the upper half
+ driver will wait for space to become available, but there is
+ no event to awaken it and the driver will hang.
+
+ Enabling this feature adds support for the can_txready()
+ interface. This function is called from the lower half
+ driver's CAN interrupt handler each time a TX transfer
+ completes. This is a sure indication that the H/W FIFO is
+ no longer full. can_txready() will then awaken the
+ can_write() logic and the hang condition is avoided.
+
+choice
+ prompt "TX Ready Work Queue"
+ default CAN_TXREADY_HIPRI
+ depends on CAN_TXREADY
+
+config CAN_TXREADY_LOPRI
+ bool "Low-priority work queue"
+ select SCHED_LPWORK
+
+config CAN_TXREADY_HIPRI
+ bool "High-priority work queue"
+ select SCHED_HPWORK
+
+endchoice # TX Ready Work Queue
+
+config CAN_LOOPBACK
+ bool "CAN loopback mode"
+ default n
+ ---help---
+ A CAN driver may or may not support a loopback mode for testing. If the
+ driver does support loopback mode, the setting will enable it. (If the
+ driver does not, this setting will have no effect).
+
+config CAN_NPOLLWAITERS
+ int "Number of poll waiters"
+ default 2
+ depends on !DISABLE_POLL
+ ---help---
+ The maximum number of threads that may be waiting on the
+ poll method.
+
+endif # CAN
diff --git a/drivers/can/Make.defs b/drivers/can/Make.defs
new file mode 100644
index 00000000000..9a1504664cd
--- /dev/null
+++ b/drivers/can/Make.defs
@@ -0,0 +1,52 @@
+############################################################################
+# drivers/can/Make.defs
+#
+# Copyright (C) 2017 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+# Don't build anything if there is no CAN support
+
+ifeq ($(CONFIG_CAN),y)
+
+CSRCS += can.c
+
+ifeq ($(CONFIG_CAN_MCP2515),y)
+CSRCS += mcp2515.c
+endif
+
+# Include CAN device driver build support
+
+DEPPATH += --dep-path can
+VPATH += :can
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)can}
+endif
+
diff --git a/drivers/can.c b/drivers/can/can.c
similarity index 99%
rename from drivers/can.c
rename to drivers/can/can.c
index dd810ebcd18..730d7e84b55 100644
--- a/drivers/can.c
+++ b/drivers/can/can.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * drivers/can.c
+ * drivers/can/can.c
*
* Copyright (C) 2008-2009, 2011-2012, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
@@ -57,7 +57,7 @@
#include
#include
#include
-#include
+#include
#ifdef CONFIG_CAN_TXREADY
# include
diff --git a/include/nuttx/analog/adc.h b/include/nuttx/analog/adc.h
index 214143357a6..73d839b0038 100644
--- a/include/nuttx/analog/adc.h
+++ b/include/nuttx/analog/adc.h
@@ -6,7 +6,7 @@
* Author: Li Zhuoyi
* Gregory Nutt
*
- * Derived from include/nuttx/drivers/can.h
+ * Derived from include/nuttx/can/can.h
*
* Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
diff --git a/include/nuttx/analog/dac.h b/include/nuttx/analog/dac.h
index 249100d89b4..93f1282ef57 100644
--- a/include/nuttx/analog/dac.h
+++ b/include/nuttx/analog/dac.h
@@ -6,7 +6,7 @@
* Author: Li Zhuoyi
* History: 0.1 2011-08-04 initial version
*
- * Derived from include/nuttx/drivers/can.h
+ * Derived from include/nuttx/can/can.h
*
* Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
diff --git a/include/nuttx/drivers/can.h b/include/nuttx/can/can.h
similarity index 99%
rename from include/nuttx/drivers/can.h
rename to include/nuttx/can/can.h
index 68df58dd791..e85a9fa54dc 100644
--- a/include/nuttx/drivers/can.h
+++ b/include/nuttx/can/can.h
@@ -1,5 +1,5 @@
/************************************************************************************
- * include/nuttx/drivers/can.h
+ * include/nuttx/can/can.h
*
* Copyright (C) 2008, 2009, 2011-2012, 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
@@ -33,8 +33,8 @@
*
************************************************************************************/
-#ifndef __INCLUDE_NUTTX_DRVERS_CAN_H
-#define __INCLUDE_NUTTX_DRVERS_CAN_H
+#ifndef __INCLUDE_NUTTX_CAN_CAN_H
+#define __INCLUDE_NUTTX_CAN_CAN_H
/************************************************************************************
* Included Files
@@ -819,4 +819,4 @@ int can_txready(FAR struct can_dev_s *dev);
#endif
#endif /* CONFIG_CAN */
-#endif /* __INCLUDE_NUTTX_DRVERS_CAN_H */
+#endif /* __INCLUDE_NUTTX_CAN_CAN_H */
diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h
index cfcc4507d60..ccd829f9187 100644
--- a/include/nuttx/fs/ioctl.h
+++ b/include/nuttx/fs/ioctl.h
@@ -357,7 +357,7 @@
#define _RELAYIOC(nr) _IOC(_RELAYBASE,nr)
/* CAN driver ioctl definitions *********************************************/
-/* (see nuttx/drivers/can.h */
+/* (see nuttx/can/can.h */
#define _CANIOCVALID(c) (_IOC_TYPE(c)==_CANBASE)
#define _CANIOC(nr) _IOC(_CANBASE,nr)