Remove BOARDIOC_CAN_INITIALIZE. CAN initialization is now done in the board initialization logic just like every other device driver.

This commit is contained in:
Gregory Nutt 2016-12-06 08:51:37 -06:00
parent e5e5467097
commit 35dfe25430
75 changed files with 1024 additions and 835 deletions

View File

@ -2029,15 +2029,6 @@ config BOARDCTL_TSCTEST
specific logic must provide board_tsc_setup() and
board_tsc_teardown() interfaces.
config BOARDCTL_CANINIT
bool "Enable CAN initialize interface"
default n
depends on CAN
---help---
Enables support for the BOARDIOC_CAN_INITIALIZE boardctl() command.
Architecture specific logic must provide board_can_initialize()
interface.
config BOARDCTL_GRAPHICS
bool "Enable custom graphics initialization interfaces"
default n

View File

@ -426,21 +426,6 @@ int boardctl(unsigned int cmd, uintptr_t arg)
break;
#endif
#ifdef CONFIG_BOARDCTL_CANINIT
/* CMD: BOARDIOC_CAN_INITIALIZE
* DESCRIPTION: CAN device initialization
* ARG: None
* CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_CANINIT
* DEPENDENCIES: Board logic must provide board_can_initialize()
*/
case BOARDIOC_CAN_INITIALIZE:
{
ret = board_can_initialize();
}
break;
#endif
#ifdef CONFIG_BOARDCTL_GRAPHICS
/* CMD: BOARDIOC_GRAPHICS_SETUP
* DESCRIPTION: Configure graphics that require special initialization

View File

@ -545,7 +545,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
CONFIG_BOARDCTL_CANINIT=y
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -544,7 +544,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
# CONFIG_BOARDCTL_CANINIT is not set
CONFIG_BOARDCTL_GRAPHICS=y
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -191,4 +191,16 @@ int stm32_pwm_setup(void);
int stm32_adc_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __CONFIGS_NUCLEO_F303RE_SRC_NUCLEO_F303RE_H */

View File

@ -141,6 +141,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -45,60 +45,52 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/drivers/can.h>
#include "stm32.h"
#if defined(CONFIG_CAN) && defined(CONFIG_STM32_CAN1)
#ifdef CONFIG_CAN
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work
* with examples/can.
* Initialize CAN and register the CAN device
*
****************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#ifdef CONFIG_STM32_CAN1
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(1);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(1);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && CONFIG_STM32_CAN1 */
#endif /* CONFIG_CAN */

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/olimex-lpc1766stk/src/lpc1766stk.h
*
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2010-2011, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -260,6 +260,18 @@
void weak_function lpc1766stk_sspdev_initialize(void);
/************************************************************************************
* Name: lpc1766stk_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
************************************************************************************/
#ifdef CONFIG_CAN
int lpc1766stk_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* _CONFIGS_OLIMEX_LPC1766STK_SRC_LPC1766STK_H */

View File

@ -362,6 +362,16 @@ int board_app_initialize(uintptr_t arg)
syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", ret);
}
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = lpc1766stk_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: lpc1766stk_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/solimex-lpc1766stk/src/lpc17_can.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -51,7 +51,7 @@
#include "lpc17_can.h"
#include "lpc1766stk.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_LPC17_CAN1) || defined(CONFIG_LPC17_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -78,48 +78,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: lpc1766stk_can_setup
*
* Description:
* All LPC17 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int lpc1766stk_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_LPC17_CAN1) || defined(CONFIG_LPC17_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call lpc17_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = lpc17_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call lpc17_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = lpc17_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_LPC17_CAN1 || CONFIG_LPC17_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -246,15 +246,15 @@ int stm32_sdio_initialize(void);
#endif
/****************************************************************************
* Name: stm32_can_initialize
* Name: stm32_can_setup
*
* Description:
* Called at application startup time to initialize the CAN functionality.
* Initialize CAN and register the CAN device
*
****************************************************************************/
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
int stm32_can_initialize(void);
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */

View File

@ -180,21 +180,19 @@ static void stm32_i2ctool(void)
int board_app_initialize(uintptr_t arg)
{
#if defined(CONFIG_CAN) || defined(CONFIG_ADC)
int ret;
#endif
/* Register I2C drivers on behalf of the I2C tool */
stm32_i2ctool();
#ifdef CONFIG_CAN
/* Configure on-board CAN if CAN support has been selected. */
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_initialize();
if (ret != OK)
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize CAN: %d\n", ret);
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
@ -231,5 +229,6 @@ int board_app_initialize(uintptr_t arg)
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -41,13 +41,15 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/drivers/can.h>
#include <arch/board/board.h>
#include "stm32.h"
#include "stm32_can.h"
#include "olimex-stm32-e407.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -69,62 +71,42 @@
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
****************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
return stm32_can_initialize();
}
/************************************************************************************
* Name: stm32_can_initialize
*
* Description:
* Called at application startup time to initialize the CAN functionality.
*
************************************************************************************/
int stm32_can_initialize(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
candbg("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
candbg("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
candbg("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
candbg("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -100,16 +100,16 @@ void weak_function stm32_usbinitialize(void);
int stm32_adc_setup(void);
#endif
/************************************************************************************
* Name: stm32_can_initialize
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Called at application startup time to initialize the CAN functionality.
* Initialize CAN and register the CAN device
*
************************************************************************************/
****************************************************************************/
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
int stm32_can_initialize(void);
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */

View File

@ -116,12 +116,12 @@ int board_app_initialize(uintptr_t arg)
#endif
#ifdef CONFIG_CAN
/* Configure on-board CAN if CAN support has been selected. */
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_initialize();
if (ret != OK)
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize CAN: %d\n", ret);
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif

View File

@ -47,14 +47,6 @@
#include "olimex-stm32-h405.h"
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/

View File

@ -41,13 +41,16 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/drivers/can.h>
#include <arch/board/board.h>
#include "stm32.h"
#include "stm32_can.h"
#include "olimex-stm32-h405.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -70,61 +73,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
return stm32_can_initialize();
}
/****************************************************************************************************
* Name: stm32_can_initialize
*
* Description:
* Called at application startup time to initialize the CAN functionality.
*
****************************************************************************************************/
int stm32_can_initialize(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -600,7 +600,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_UNIQUEID is not set
CONFIG_BOARDCTL_USBDEVCTRL=y
# CONFIG_BOARDCTL_TSCTEST is not set
CONFIG_BOARDCTL_CANINIT=y
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -267,15 +267,15 @@ int stm32_adc_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_initialize
* Name: stm32_can_setup
*
* Description:
* Called at application startup time to initialize the CAN functionality.
* Initialize CAN and register the CAN device
*
****************************************************************************/
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
int stm32_can_initialize(void);
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */

View File

@ -59,10 +59,6 @@
#ifdef CONFIG_LIB_BOARDCTL
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -97,14 +97,12 @@ int stm32_bringup(void)
int ret;
#ifdef CONFIG_CAN
/* Configure on-board CAN if CAN support has been selected. */
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_initialize();
if (ret != OK)
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize CAN: %d\n",
ret);
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif

View File

@ -41,13 +41,15 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/drivers/can.h>
#include <arch/board/board.h>
#include "stm32.h"
#include "stm32_can.h"
#include "olimex-stm32-h407.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -70,61 +72,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
return stm32_can_initialize();
}
/************************************************************************************
* Name: stm32_can_initialize
*
* Description:
* Called at application startup time to initialize the CAN functionality.
*
************************************************************************************/
int stm32_can_initialize(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -38,6 +38,10 @@
ASRCS =
CSRCS = stm32_boot.c stm32_spi.c
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
ifeq ($(CONFIG_CAN),y)
CSRCS += stm32_can.c
endif

View File

@ -32,6 +32,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __CONFIGS_OLIMEX_STM32_P107_SRC_H
#define __CONFIGS_OLIMEX_STM32_P107_SRC_H
@ -84,5 +85,17 @@
void weak_function stm32_spidev_initialize(void);
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_OLIMEX_STM32_P107_SRC_H */

View File

@ -0,0 +1,105 @@
/****************************************************************************
* configs/olimex-stm32-p107/src/stm32_appinit.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <syslog.h>
#include <errno.h>
#include <nuttx/board.h>
#include "stm32.h"
#include "olimex-stm32-p107.h"
#ifdef CONFIG_LIB_BOARDCTL
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* CONFIG_LIB_BOARDCTL=y:
* If CONFIG_NSH_ARCHINITIALIZE=y:
* Called from the NSH library (or other application)
* Otherse, assumed to be called from some other application.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initalization logic and the the
* matching application logic. The value cold be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
int ret;
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}
#endif /* CONFIG_LIB_BOARDCTL */

View File

@ -44,14 +44,6 @@
#include "up_arch.h"
#include "olimex-stm32-p107.h"
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/
@ -78,5 +70,4 @@ void stm32_boardinitialize(void)
stm32_spidev_initialize();
}
#endif
}

View File

@ -51,7 +51,7 @@
#include "stm32.h"
#include "stm32_can.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -59,55 +59,57 @@
/* Configuration ********************************************************************/
/* The STM32F107VC supports CAN1 and CAN2 */
#define CAN_PORT 1
#if defined(CONFIG_STM32_CAN1) && defined(CONFIG_STM32_CAN2)
# warning "Both CAN1 and CAN2 are enabled. Only CAN1 is used."
# undef CONFIG_STM32_CAN2
#endif
#ifdef CONFIG_STM32_CAN1
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
****************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && CONFIG_STM32_CAN1 */
#endif /* CONFIG_CAN */

View File

@ -626,7 +626,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
# CONFIG_BOARDCTL_CANINIT is not set
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -136,16 +136,16 @@ int stm32_usbhost_initialize(void);
int stm32_adc_setup(void);
#endif
/************************************************************************************
* Name: stm32_can_initialize
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Called at application startup time to initialize the CAN functionality.
* Initialize CAN and register the CAN device
*
************************************************************************************/
****************************************************************************/
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
int stm32_can_initialize(void);
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */

View File

@ -134,13 +134,13 @@ int board_app_initialize(uintptr_t arg)
{
int ret;
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
/* Configure on-board CAN if CAN support has been selected. */
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_initialize();
if (ret != OK)
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize CAN: %d\n", ret);
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/olimex-stm32-p207/src/stm32_can.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -41,13 +41,15 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/drivers/can.h>
#include <arch/board/board.h>
#include "stm32.h"
#include "stm32_can.h"
#include "olimex-stm32-p207.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -70,61 +72,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
return stm32_can_initialize();
}
/****************************************************************************************************
* Name: stm32_can_initialize
*
* Description:
* Called at application startup time to initialize the CAN functionality.
*
****************************************************************************************************/
int stm32_can_initialize(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -588,7 +588,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
CONFIG_BOARDCTL_CANINIT=y
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -569,7 +569,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
CONFIG_BOARDCTL_CANINIT=y
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -200,18 +200,6 @@ void stm32_usb_set_pwr_callback(xcpt_t pwr_changed_handler);
void stm32_led_initialize(void);
#endif
/************************************************************************************
* Name: stm32_can_initialize
*
* Description:
* Called at application startup time to initialize the CAN functionality.
*
************************************************************************************/
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
int stm32_can_initialize(void);
#endif
/****************************************************************************
* Name: board_usbmsc_initialize
*
@ -228,5 +216,17 @@ int stm32_can_initialize(void);
int board_usbmsc_initialize(int port);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_OLIMEXINO_STM32_SRC_OLIMEXINO_STM32_H */

View File

@ -105,5 +105,16 @@ int board_app_initialize(uintptr_t arg)
#endif
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return ret;
}

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/olimexino-stm32/src/stm32_can.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
@ -48,13 +48,12 @@
#include "chip.h"
#include "up_arch.h"
#include "olimexino-stm32.h"
#include "stm32.h"
#include "stm32_can.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#include "olimexino-stm32.h"
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -62,55 +61,57 @@
/* Configuration ********************************************************************/
/* The STM32F107VC supports CAN1 and CAN2 */
#define CAN_PORT 1
#if defined(CONFIG_STM32_CAN1) && defined(CONFIG_STM32_CAN2)
# warning "Both CAN1 and CAN2 are enabled. Only CAN1 is connected."
# undef CONFIG_STM32_CAN2
#endif
#ifdef CONFIG_STM32_CAN1
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && CONFIG_STM32_CAN1 */
#endif /* CONFIG_CAN */

View File

@ -569,7 +569,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
CONFIG_BOARDCTL_CANINIT=y
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -192,6 +192,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = sam_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sam_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/sama5d3-xplained/src/sam_can.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -51,7 +51,7 @@
#include "sam_can.h"
#include "sama5d3-xplained.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_SAMA5_CAN0) || defined(CONFIG_SAMA5_CAN1))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -74,48 +74,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: sam_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int sam_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_SAMA5_CAN0) || defined(CONFIG_SAMA5_CAN1)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = sam_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
can = sam_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_SAMA5_CAN0 || CONFIG_SAMA5_CAN1) */
#endif /* CONFIG_CAN */

View File

@ -763,6 +763,18 @@ int sam_pwm_setup(void);
int sam_adc_setup(void);
#endif
/************************************************************************************
* Name: sam_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
************************************************************************************/
#ifdef CONFIG_CAN
int sam_can_setup(void);
#endif
/************************************************************************************
* Name: sam_netinitialize
*

View File

@ -204,6 +204,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = sam_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sam_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/sama5d3x-ek/src/sam_can.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -51,7 +51,7 @@
#include "sam_can.h"
#include "sama5d3x-ek.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_SAMA5_CAN0) || defined(CONFIG_SAMA5_CAN1))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -74,48 +74,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: sam_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int sam_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_SAMA5_CAN0) || defined(CONFIG_SAMA5_CAN1)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = sam_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = sam_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_SAMA5_CAN0 || CONFIG_SAMA5_CAN1) */
#endif /* CONFIG_CAN */

View File

@ -807,14 +807,15 @@ bool sam_writeprotected(int slotno);
void weak_function sam_usbinitialize(void);
#endif
/****************************************************************************************************
/************************************************************************************
* Name: stm32_usbhost_initialize
*
* Description:
* Called at application startup time to initialize the USB host functionality. This function will
* start a thread that will monitor for device connection/disconnection events.
* Called at application startup time to initialize the USB host functionality.
* This function will start a thread that will monitor for device connection/
* disconnection events.
*
****************************************************************************************************/
************************************************************************************/
#ifdef HAVE_USBHOST
int sam_usbhost_initialize(void);
@ -856,7 +857,19 @@ int sam_pwm_setup(void);
int sam_adc_setup(void);
#endif
/****************************************************************************
/************************************************************************************
* Name: sam_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
************************************************************************************/
#ifdef CONFIG_CAN
int sam_can_setup(void);
#endif
/************************************************************************************
* Name: sam_wm8904_initialize
*
* Description:
@ -871,7 +884,7 @@ int sam_adc_setup(void);
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
************************************************************************************/
#ifdef HAVE_WM8904
int sam_wm8904_initialize(int minor);

View File

@ -732,10 +732,6 @@ MCAN1 Loopback Test
CONFIG_SAMV7_MCAN1_TXFIFOQ_SIZE=8 # There are 8 queue elements
CONFIG_SAMV7_MCAN1_TXEVENTFIFO_SIZE=0 # The event FIFO is not used
Board Selection
CONFIG_LIB_BOARDCTL=y # Needed for CAN initialization
CONFIG_BOARDCTL_CANINIT=y # Enabled CAN initialization
Enabling the CAN Loopback Test
------------------------------
Application Configuration -> Examples -> CAN Example

View File

@ -43,6 +43,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <debug.h>
@ -97,14 +98,14 @@ static void sam_i2c_register(int bus)
i2c = sam_i2cbus_initialize(bus);
if (i2c == NULL)
{
_err("ERROR: Failed to get I2C%d interface\n", bus);
syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
}
else
{
ret = i2c_register(i2c, bus);
if (ret < 0)
{
_err("ERROR: Failed to register I2C%d driver: %d\n", bus, ret);
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n", bus, ret);
sam_i2cbus_uninitialize(i2c);
}
}
@ -169,7 +170,7 @@ int sam_bringup(void)
ret = sam_emac0_setmac();
if (ret < 0)
{
_err("ERROR: sam_emac0_setmac() failed: %d\n", ret);
syslog(LOG_ERR, "ERROR: sam_emac0_setmac() failed: %d\n", ret);
}
#endif
@ -179,8 +180,8 @@ int sam_bringup(void)
ret = mount(NULL, SAME70_PROCFS_MOUNTPOINT, "procfs", 0, NULL);
if (ret < 0)
{
_err("ERROR: Failed to mount procfs at %s: %d\n",
SAME70_PROCFS_MOUNTPOINT, ret);
syslog(LOG_ERR, "ERROR: Failed to mount procfs at %s: %d\n",
SAME70_PROCFS_MOUNTPOINT, ret);
}
#endif
@ -192,7 +193,7 @@ int sam_bringup(void)
ret = sam_at24config();
if (ret < 0)
{
_err("ERROR: sam_at24config() failed: %d\n", ret);
syslog(LOG_ERR, "ERROR: sam_at24config() failed: %d\n", ret);
}
#endif
@ -202,8 +203,8 @@ int sam_bringup(void)
ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR);
if (ret < 0)
{
_err("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
HSMCI0_SLOTNO, HSMCI0_MINOR, ret);
syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
HSMCI0_SLOTNO, HSMCI0_MINOR, ret);
}
#ifdef CONFIG_SAME70XPLAINED_HSMCI0_MOUNT
@ -219,8 +220,8 @@ int sam_bringup(void)
if (ret < 0)
{
_err("ERROR: Failed to mount %s: %d\n",
CONFIG_SAME70XPLAINED_HSMCI0_MOUNT_MOUNTPOINT, errno);
syslog(LOG_ERR, "ERROR: Failed to mount %s: %d\n",
CONFIG_SAME70XPLAINED_HSMCI0_MOUNT_MOUNTPOINT, errno);
}
}
@ -241,7 +242,7 @@ int sam_bringup(void)
CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_SECTSIZE);
if (ret < 0)
{
_err("ERROR: romdisk_register failed: %d\n", -ret);
syslog(LOG_ERR, "ERROR: romdisk_register failed: %d\n", -ret);
}
else
{
@ -252,9 +253,9 @@ int sam_bringup(void)
"romfs", MS_RDONLY, NULL);
if (ret < 0)
{
_err("ERROR: mount(%s,%s,romfs) failed: %d\n",
CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_DEVNAME,
CONFIG_SAME70XPLAINED_ROMFS_MOUNT_MOUNTPOINT, errno);
syslog(LOG_ERR, "ERROR: mount(%s,%s,romfs) failed: %d\n",
CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_DEVNAME,
CONFIG_SAME70XPLAINED_ROMFS_MOUNT_MOUNTPOINT, errno);
}
}
#endif
@ -269,7 +270,7 @@ int sam_bringup(void)
mtd = progmem_initialize();
if (!mtd)
{
_err("ERROR: progmem_initialize failed\n");
syslog(LOG_ERR, "ERROR: progmem_initialize failed\n");
}
/* Use the FTL layer to wrap the MTD driver as a block driver */
@ -277,7 +278,7 @@ int sam_bringup(void)
ret = ftl_initialize(PROGMEM_MTD_MINOR, mtd);
if (ret < 0)
{
_err("ERROR: Failed to initialize the FTL layer: %d\n", ret);
syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n", ret);
return ret;
}
@ -291,7 +292,7 @@ int sam_bringup(void)
ret = bchdev_register(blockdev, chardev, false);
if (ret < 0)
{
_err("ERROR: bchdev_register %s failed: %d\n", chardev, ret);
syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n", chardev, ret);
return ret;
}
#endif
@ -304,7 +305,7 @@ int sam_bringup(void)
ret = sam_usbhost_initialize();
if (ret != OK)
{
_err("ERROR: Failed to initialize USB host: %d\n", ret);
syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", ret);
}
#endif
@ -314,18 +315,28 @@ int sam_bringup(void)
ret = usbmonitor_start();
if (ret != OK)
{
_err("ERROR: Failed to start the USB monitor: %d\n", ret);
syslog(LOG_ERR, "ERROR: Failed to start the USB monitor: %d\n", ret);
}
#endif
#ifdef CONFIG_SAMV7_MCAN
/* Initialize CAN and register the CAN driver. */
ret = sam_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sam_can_setup failed: %d\n", ret);
}
#endif
#ifdef HAVE_ELF
/* Initialize the ELF binary loader */
_err("Initializing the ELF binary loader\n");
syslog(LOG_ERR, "Initializing the ELF binary loader\n");
ret = elf_initialize();
if (ret < 0)
{
_err("ERROR: Initialization of the ELF loader failed: %d\n", ret);
syslog(LOG_ERR, "ERROR: Initialization of the ELF loader failed: %d\n", ret);
}
#endif
@ -333,7 +344,7 @@ int sam_bringup(void)
ret = sam_dacdev_initialize();
if (ret < 0)
{
_err("ERROR: Initialization of the DAC module failed: %d\n", ret);
syslog(LOG_ERR, "ERROR: Initialization of the DAC module failed: %d\n", ret);
}
#endif

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/same70-xplainedk/src/sam_mcan.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -49,7 +49,7 @@
#include "sam_mcan.h"
#include "same70-xplained.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_SAMV7_MCAN0) || defined(CONFIG_SAMV7_MCAN1))
#ifdef CONFIG_SAMV7_MCAN
/************************************************************************************
* Pre-processor Definitions
@ -72,48 +72,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: sam_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int sam_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_SAMV7_MCAN0) || defined(CONFIG_SAMV7_MCAN1)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = sam_mcan_initialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = sam_mcan_initialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_SAMV7_MCAN0 || CONFIG_SAMV7_MCAN1) */
#endif /* CONFIG_SAMV7_MCAN */

View File

@ -400,6 +400,18 @@ int sam_hsmci_initialize(int slot, int minor);
void sam_usbinitialize(void);
#endif
/****************************************************************************
* Name: sam_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_SAMV7_MCAN
int sam_can_setup(void);
#endif
/************************************************************************************
* Name: sam_netinitialize
*

View File

@ -1322,10 +1322,6 @@ MCAN1 Loopback Test
CONFIG_SAMV7_MCAN1_TXFIFOQ_SIZE=8 # There are 8 queue elements
CONFIG_SAMV7_MCAN1_TXEVENTFIFO_SIZE=0 # The event FIFO is not used
Board Selection
CONFIG_LIB_BOARDCTL=y # Needed for CAN initialization
CONFIG_BOARDCTL_CANINIT=y # Enabled CAN initialization
Enabling the CAN Loopback Test
------------------------------
Application Configuration -> Examples -> CAN Example

View File

@ -253,6 +253,16 @@ int sam_bringup(void)
}
#endif
#ifdef CONFIG_SAMV7_MCAN
/* Initialize CAN and register the CAN driver. */
ret = sam_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sam_can_setup failed: %d\n", ret);
}
#endif
#ifdef HAVE_MACADDR
/* Read the Ethernet MAC address from the AT24 FLASH and configure the
* Ethernet driver with that address.

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/samv71-xultk/src/sam_mcan.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -49,7 +49,7 @@
#include "sam_mcan.h"
#include "samv71-xult.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_SAMV7_MCAN0) || defined(CONFIG_SAMV7_MCAN1))
#ifdef CONFIG_SAMV7_MCAN
/************************************************************************************
* Pre-processor Definitions
@ -72,48 +72,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: sam_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int sam_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_SAMV7_MCAN0) || defined(CONFIG_SAMV7_MCAN1)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = sam_mcan_initialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = sam_mcan_initialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_SAMV7_MCAN0 || CONFIG_SAMV7_MCAN1) */
#endif /* CONFIG_SAMV7_MCAN */

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/samv71-xult/src/samv71-xult.h
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -597,6 +597,18 @@ int sam_bringup(void);
void sam_spidev_initialize(void);
#endif
/************************************************************************************
* Name: sam_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
************************************************************************************/
#ifdef CONFIG_SAMV7_MCAN
int sam_can_setup(void);
#endif
/************************************************************************************
* Name: sam_hsmci_initialize
*

View File

@ -1,7 +1,7 @@
/****************************************************************************************************
* configs/shenzhou/src/shenzhou.h
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -460,6 +460,18 @@ int stm32_usbhost_initialize(void);
int stm32_adc_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
/****************************************************************************
* Name: stm32_sdinitialize
*

View File

@ -214,6 +214,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/shenzhou/src/stm32_can.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -52,7 +52,7 @@
#include "stm32_can.h"
#include "shenzhou.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -60,55 +60,57 @@
/* Configuration ********************************************************************/
/* The STM32F107VC supports CAN1 and CAN2 */
#define CAN_PORT 1
#if defined(CONFIG_STM32_CAN1) && defined(CONFIG_STM32_CAN2)
# warning "Both CAN1 and CAN2 are enabled. Only CAN1 is connected."
# undef CONFIG_STM32_CAN2
#endif
#ifdef CONFIG_STM32_CAN1
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && CONFIG_STM32_CAN1 */
#endif /* CONFIG_CAN */

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/stm3210e_eval/src/stm3210e-eval.h
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -204,6 +204,18 @@ void weak_function stm32_usbinitialize(void);
int stm32_adc_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
/************************************************************************************
* Name: stm32_extcontextsave
*

View File

@ -294,6 +294,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_DJOYSTICK
/* Initialize and register the joystick driver */

View File

@ -52,7 +52,7 @@
#include "stm32_can.h"
#include "stm3210e-eval.h"
#if defined(CONFIG_CAN) && defined(CONFIG_STM32_CAN1)
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -67,48 +67,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#ifdef CONFIG_STM32_CAN1
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && CONFIG_STM32_CAN1 */
#endif /* CONFIG_CAN */

View File

@ -249,30 +249,42 @@ void weak_function stm32_usbinitialize(void);
int stm32_usbhost_initialize(void);
#endif
/************************************************************************************
/****************************************************************************************************
* Name: stm32_pwm_setup
*
* Description:
* Initialize PWM and register the PWM device.
*
************************************************************************************/
****************************************************************************************************/
#ifdef CONFIG_PWM
int stm32_pwm_setup(void);
#endif
/************************************************************************************
/****************************************************************************************************
* Name: stm32_adc_setup
*
* Description:
* Initialize ADC and register the ADC driver.
*
************************************************************************************/
****************************************************************************************************/
#ifdef CONFIG_ADC
int stm32_adc_setup(void);
#endif
/****************************************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
/****************************************************************************************************
* Name: stm32_extmemgpios
*

View File

@ -312,6 +312,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/stm3220g-eval/src/stm32_can.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -52,7 +52,7 @@
#include "stm32_can.h"
#include "stm3220g-eval.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -75,48 +75,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -262,30 +262,42 @@ int stm32_usbhost_initialize(void);
void stm32_led_initialize(void);
#endif
/************************************************************************************
/****************************************************************************************************
* Name: stm32_pwm_setup
*
* Description:
* Initialize PWM and register the PWM device.
*
************************************************************************************/
****************************************************************************************************/
#ifdef CONFIG_PWM
int stm32_pwm_setup(void);
#endif
/************************************************************************************
/****************************************************************************************************
* Name: stm32_adc_setup
*
* Description:
* Initialize ADC and register the ADC driver.
*
************************************************************************************/
****************************************************************************************************/
#ifdef CONFIG_ADC
int stm32_adc_setup(void);
#endif
/****************************************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
/****************************************************************************************************
* Name: stm32_extmemgpios
*

View File

@ -363,6 +363,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/stm3240g-eval/src/stm32_can.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -52,7 +52,7 @@
#include "stm32_can.h"
#include "stm3240g-eval.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -75,48 +75,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -589,7 +589,6 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_RESET is not set
# CONFIG_BOARDCTL_UNIQUEID is not set
# CONFIG_BOARDCTL_TSCTEST is not set
CONFIG_BOARDCTL_CANINIT=y
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set

View File

@ -169,6 +169,16 @@ int stm32_bringup(void)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_QENCODER
/* Initialize and register the qencoder driver */

View File

@ -52,7 +52,7 @@
#include "stm32_can.h"
#include "stm32f4discovery.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -76,48 +76,41 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_STM32_CAN1 || CONFIG_STM32_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -438,18 +438,30 @@ void weak_function stm32_usbinitialize(void);
int stm32_usbhost_initialize(void);
#endif
/************************************************************************************
/****************************************************************************
* Name: stm32_pwm_setup
*
* Description:
* Initialize PWM and register the PWM device.
*
************************************************************************************/
****************************************************************************/
#ifdef CONFIG_PWM
int stm32_pwm_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
/****************************************************************************
* Name: stm32_extmemgpios
*
@ -536,22 +548,6 @@ void stm32_led_pminitialize(void);
void stm32_pm_buttons(void);
#endif
/****************************************************************************
* Name: stm32_bringup
*
* Description:
* Perform architecture-specific initialization
*
* CONFIG_BOARD_INITIALIZE=y :
* Called from board_initialize().
*
* CONFIG_BOARD_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y :
* Called from the NSH library
*
****************************************************************************/
int stm32_bringup(void);
/****************************************************************************
* Name: stm32_sdio_initialize
*

View File

@ -146,17 +146,42 @@ static int rtc_driver_initialize(void)
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
(void)rtc_driver_initialize();
#endif
int ret;
#ifdef CONFIG_MPL115A
stm32_mpl115ainitialize("/dev/press");
#ifdef HAVE_RTC_DRIVER
ret = rtc_driver_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: rtc_driver_initialize failed: %d\n", ret);
}
#endif
#ifdef HAVE_MMCSD
return stm32_sdinitialize(CONFIG_NSH_MMCSDSLOTNO);
#else
return OK;
ret = stm32_sdinitialize(CONFIG_NSH_MMCSDSLOTNO);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_sdinitialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_MPL115A
ret = stm32_mpl115ainitialize("/dev/press");
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_mpl115ainitialize failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/viewtool-stm32f107/src/stm32_can.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -51,7 +51,7 @@
#include "stm32.h"
#include "stm32_can.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -59,55 +59,57 @@
/* Configuration ********************************************************************/
/* The STM32F107VC supports CAN1 and CAN2 */
#define CAN_PORT 1
#if defined(CONFIG_STM32_CAN1) && defined(CONFIG_STM32_CAN2)
# warning "Both CAN1 and CAN2 are enabled. Assuming only CAN1."
# undef CONFIG_STM32_CAN2
#endif
#ifdef CONFIG_STM32_CAN1
# define CAN_PORT 1
#else
# define CAN_PORT 2
#endif
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: stm32_can_setup
*
* Description:
* All STM32 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int stm32_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_STM32_CAN1) || defined(CONFIG_STM32_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
/* Call stm32_caninitialize() to get an instance of the CAN interface */
if (!initialized)
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
/* Call stm32_caninitialize() to get an instance of the CAN interface */
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
can = stm32_caninitialize(CAN_PORT);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN interface\n");
return -ENODEV;
}
/* Register the CAN driver at "/dev/can0" */
/* Register the CAN driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: can_register failed: %d\n", ret);
return ret;
}
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && CONFIG_STM32_CAN1 */
#endif /* CONFIG_CAN */

View File

@ -342,6 +342,18 @@ void weak_function stm32_usbdev_initialize(void);
int stm32_sdinitialize(int minor);
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_CAN
int stm32_can_setup(void);
#endif
/****************************************************************************
* Name: stm32_mpl115ainitialize
*

View File

@ -53,6 +53,7 @@
#include <nuttx/mmcsd.h>
#include "lpc17_spi.h"
#include "zkit-arm-1769.h"
/****************************************************************************
* Pre-processor Definitions
@ -202,6 +203,16 @@ int board_app_initialize(uintptr_t arg)
}
#endif
#ifdef CONFIG_CAN
/* Initialize CAN and register the CAN driver. */
ret = zkit_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: zkit_can_setup failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -6,7 +6,7 @@
*
* Based on configs/olimex-lpc1766stk/src/lpc17_can.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -56,7 +56,7 @@
#include "lpc17_can.h"
#include "zkit-arm-1769.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_LPC17_CAN1) || defined(CONFIG_LPC17_CAN2))
#ifdef CONFIG_CAN
/************************************************************************************
* Pre-processor Definitions
@ -71,70 +71,63 @@
************************************************************************************/
/************************************************************************************
* Name: board_can_initialize
* Name: zkit_can_setup
*
* Description:
* All LPC17 architectures must provide the following interface to work with
* examples/can.
* Initialize CAN and register the CAN device
*
************************************************************************************/
int board_can_initialize(void)
int zkit_can_setup(void)
{
static bool initialized = false;
#if defined(CONFIG_LPC17_CAN1) || defined(CONFIG_LPC17_CAN2)
struct can_dev_s *can;
int ret;
/* Check if we have already initialized */
if (!initialized)
{
#ifdef CONFIG_LPC17_CAN1
/* Call lpc17_caninitialize() to get an instance of the CAN1 interface */
/* Call lpc17_caninitialize() to get an instance of the CAN1 interface */
can = lpc17_caninitialize(CAN_PORT1);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN1 interface\n");
return -ENODEV;
}
can = lpc17_caninitialize(CAN_PORT1);
if (can == NULL)
{
canerr("ERROR: Failed to get CAN1 interface\n");
return -ENODEV;
}
/* Register the CAN1 driver at "/dev/can0" */
/* Register the CAN1 driver at "/dev/can0" */
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("ERROR: CAN1 register failed: %d\n", ret);
return ret;
}
ret = can_register("/dev/can0", can);
if (ret < 0)
{
canerr("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 */
/* Call lpc17_caninitialize() to get an instance of the CAN2 interface */
can = lpc17_caninitialize(CAN_PORT2);
if (can == NULL)
{
canerr("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)
{
canerr("ERROR: CAN2 register failed: %d\n", ret);
return ret;
}
#endif
/* Now we are initialized */
initialized = true;
can = lpc17_caninitialize(CAN_PORT2);
if (can == NULL)
{
canerr("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)
{
canerr("ERROR: CAN2 register failed: %d\n", ret);
return ret;
}
#endif
return OK;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_CAN && (CONFIG_LPC17_CAN1 || CONFIG_LPC17_CAN2) */
#endif /* CONFIG_CAN */

View File

@ -261,5 +261,17 @@ void weak_function zkit_spidev_initialize(void);
int zkit_adc_setup(void);
#endif
/************************************************************************************
* Name: zkit_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
************************************************************************************/
#ifdef CONFIG_CAN
int zkit_can_setup(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* _CONFIGS_ZKITARM_LPC1768_SRC_ZKITARM_H */

View File

@ -338,25 +338,6 @@ struct fb_vtable_s;
FAR struct fb_vtable_s *board_graphics_setup(unsigned int devno);
#endif
/****************************************************************************
* Name: board_can_initialize
*
* Description:
* Perform one-time CAN initialization. This is currently only needed for
* apps/examples/can.
*
* This is an internal OS interface but may be invoked indirectly from
* application-level graphics logic. If CONFIG_LIB_BOARDCTL=y and
* CONFIG_BOARDCTL_CANINIT=y, then this functions will be invoked via the
* (non-standard) boardctl() interface using the BOARDIOC_CAN_INITIALIZE
* command.
*
****************************************************************************/
#ifdef CONFIG_BOARDCTL_CANINIT
int board_can_initialize(void);
#endif
/****************************************************************************
* Name: board_ioctl
*

View File

@ -127,12 +127,6 @@
* CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_TSCTEST
* DEPENDENCIES: Board logic must provide board_tsc_teardown()
*
* CMD: BOARDIOC_CAN_INITIALIZE
* DESCRIPTION: CAN device initialization
* ARG: None
* CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_CANINIT
* DEPENDENCIES: Board logic must provide board_can_initialize()
*
* CMD: BOARDIOC_GRAPHICS_SETUP
* DESCRIPTION: Configure graphics that require special initialization
* procedures
@ -151,8 +145,7 @@
#define BOARDIOC_NX_START _BOARDIOC(0x0008)
#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0009)
#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x000a)
#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x000c)
#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000c)
#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000b)
/* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support.
* In this case, all commands not recognized by boardctl() will be forwarded