2019-08-15 18:19:17 +02:00
|
|
|
/****************************************************************************
|
2020-03-07 12:36:39 +01:00
|
|
|
* boards/arm/sama5/sama5d3-xplained/src/sam_can.c
|
2014-03-28 22:20:26 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-03-28 22:20:26 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-03-28 22:20:26 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-03-28 22:20:26 +01:00
|
|
|
*
|
2019-08-15 18:19:17 +02:00
|
|
|
****************************************************************************/
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2019-08-15 18:19:17 +02:00
|
|
|
/****************************************************************************
|
2014-03-28 22:20:26 +01:00
|
|
|
* Included Files
|
2019-08-15 18:19:17 +02:00
|
|
|
****************************************************************************/
|
2014-03-28 22:20:26 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2017-05-12 16:23:16 +02:00
|
|
|
#include <nuttx/can/can.h>
|
2014-03-28 22:20:26 +01:00
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
#include "chip.h"
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_arch.h"
|
2014-03-28 22:20:26 +01:00
|
|
|
|
|
|
|
#include "sam_can.h"
|
|
|
|
#include "sama5d3-xplained.h"
|
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
#ifdef CONFIG_CAN
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2019-08-15 18:19:17 +02:00
|
|
|
/****************************************************************************
|
2014-03-28 22:20:26 +01:00
|
|
|
* Pre-processor Definitions
|
2019-08-15 18:19:17 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration ************************************************************/
|
2014-03-28 22:20:26 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_SAMA5_CAN0) && defined(CONFIG_SAMA5_CAN1)
|
|
|
|
# warning "Both CAN0 and CAN1 are enabled. Assuming only CAN0."
|
|
|
|
# undef CONFIG_SAMA5_CAN1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_CAN0
|
|
|
|
# define CAN_PORT 0
|
|
|
|
#else
|
|
|
|
# define CAN_PORT 1
|
|
|
|
#endif
|
|
|
|
|
2019-08-15 18:19:17 +02:00
|
|
|
/****************************************************************************
|
2014-03-28 22:20:26 +01:00
|
|
|
* Public Functions
|
2019-08-15 18:19:17 +02:00
|
|
|
****************************************************************************/
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2019-08-15 18:19:17 +02:00
|
|
|
/****************************************************************************
|
2016-12-06 15:51:37 +01:00
|
|
|
* Name: sam_can_setup
|
2014-03-28 22:20:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-12-06 15:51:37 +01:00
|
|
|
* Initialize CAN and register the CAN device
|
2014-03-28 22:20:26 +01:00
|
|
|
*
|
2019-08-15 18:19:17 +02:00
|
|
|
****************************************************************************/
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
int sam_can_setup(void)
|
2014-03-28 22:20:26 +01:00
|
|
|
{
|
2016-12-06 15:51:37 +01:00
|
|
|
#if defined(CONFIG_SAMA5_CAN0) || defined(CONFIG_SAMA5_CAN1)
|
2014-03-28 22:20:26 +01:00
|
|
|
struct can_dev_s *can;
|
|
|
|
int ret;
|
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
/* Call stm32_caninitialize() to get an instance of the CAN interface */
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
can = sam_caninitialize(CAN_PORT);
|
|
|
|
if (can == NULL)
|
2014-03-28 22:20:26 +01:00
|
|
|
{
|
2016-12-06 15:51:37 +01:00
|
|
|
canerr("ERROR: Failed to get CAN interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
/* Register the CAN driver at "/dev/can0" */
|
2014-03-28 22:20:26 +01:00
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
ret = can_register("/dev/can0", can);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
canerr("ERROR: can_register failed: %d\n", ret);
|
|
|
|
return ret;
|
2019-08-15 18:19:17 +02:00
|
|
|
}
|
2014-03-28 22:20:26 +01:00
|
|
|
|
|
|
|
return OK;
|
2016-12-06 15:51:37 +01:00
|
|
|
#else
|
|
|
|
return -ENODEV;
|
|
|
|
#endif
|
2014-03-28 22:20:26 +01:00
|
|
|
}
|
|
|
|
|
2016-12-06 15:51:37 +01:00
|
|
|
#endif /* CONFIG_CAN */
|