2020-12-02 23:54:34 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* boards/arm/imxrt/teensy-4.x/src/imxrt_flexcan.c
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/can/can.h>
|
|
|
|
|
|
|
|
#include "imxrt_flexcan.h"
|
|
|
|
#include "teensy-4.h"
|
|
|
|
|
|
|
|
#if defined(CONFIG_IMXRT_FLEXCAN) && defined(CONFIG_NETDEV_LATEINIT)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: imxrt_can_setup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize CAN and register the CAN device
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int imxrt_can_setup(void)
|
|
|
|
{
|
|
|
|
int ret;
|
2021-08-29 22:59:14 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_IMXRT_FLEXCAN3_AS_CAN0
|
|
|
|
# ifdef CONFIG_IMXRT_FLEXCAN3
|
|
|
|
ret = imxrt_caninitialize(3);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
canerr("ERROR: Failed to get CAN interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2021-02-25 23:27:34 +01:00
|
|
|
#ifdef CONFIG_IMXRT_FLEXCAN1
|
2020-12-02 23:54:34 +01:00
|
|
|
/* Call arm_caninitialize() to get an instance of the CAN interface */
|
|
|
|
|
2021-02-25 23:27:34 +01:00
|
|
|
ret = imxrt_caninitialize(1);
|
2020-12-02 23:54:34 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
canerr("ERROR: Failed to get CAN interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2021-02-25 23:27:34 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_IMXRT_FLEXCAN2
|
2020-12-02 23:54:34 +01:00
|
|
|
ret = imxrt_caninitialize(2);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
canerr("ERROR: Failed to get CAN interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2021-02-25 23:27:34 +01:00
|
|
|
|
|
|
|
#endif
|
2021-08-29 22:59:14 +02:00
|
|
|
#ifndef CONFIG_IMXRT_FLEXCAN3_AS_CAN0
|
|
|
|
# ifdef CONFIG_IMXRT_FLEXCAN3
|
2021-02-25 23:27:34 +01:00
|
|
|
ret = imxrt_caninitialize(3);
|
2020-12-02 23:54:34 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
canerr("ERROR: Failed to get CAN interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2021-02-25 23:27:34 +01:00
|
|
|
|
2021-08-29 22:59:14 +02:00
|
|
|
# endif
|
2020-12-02 23:54:34 +01:00
|
|
|
#endif
|
|
|
|
UNUSED(ret);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_IMXRT_FLEXCAN */
|