2014-11-01 17:01:38 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2014-11-01 17:01:38 +00:00
|
|
|
|
|
|
|
Licensed 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-11-02 16:38:13 +00:00
|
|
|
* @file can_lld.c
|
|
|
|
* @brief PLATFORM CAN subsystem low level driver source.
|
2014-11-01 17:01:38 +00:00
|
|
|
*
|
|
|
|
* @addtogroup CAN
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#if HAL_USE_CAN || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CAN1 driver identifier.
|
|
|
|
*/
|
|
|
|
#if PLATFORM_CAN_USE_CAN1 || defined(__DOXYGEN__)
|
|
|
|
CANDriver CAND1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver interrupt handlers. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Low level CAN driver initialization.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_init(void) {
|
|
|
|
|
|
|
|
#if PLATFORM_CAN_USE_CAN1
|
|
|
|
/* Driver initialization.*/
|
|
|
|
canObjectInit(&CAND1);
|
|
|
|
#endif /* PLATFORM_CAN_USE_CAN1 */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configures and activates the CAN peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_start(CANDriver *canp) {
|
|
|
|
|
|
|
|
if (canp->state == CAN_STOP) {
|
|
|
|
/* Enables the peripheral.*/
|
|
|
|
#if PLATFORM_CAN_USE_CAN1
|
|
|
|
if (&CAND1 == canp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PLATFORM_CAN_USE_CAN1 */
|
|
|
|
}
|
|
|
|
/* Configures the peripheral.*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deactivates the CAN peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_stop(CANDriver *canp) {
|
|
|
|
|
|
|
|
if (canp->state == CAN_READY) {
|
|
|
|
/* Resets the peripheral.*/
|
|
|
|
|
|
|
|
/* Disables the peripheral.*/
|
|
|
|
#if PLATFORM_CAN_USE_CAN1
|
|
|
|
if (&CAND1 == canp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PLATFORM_CAN_USE_CAN1 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Determines whether a frame can be transmitted.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
|
|
|
|
*
|
|
|
|
* @return The queue space availability.
|
|
|
|
* @retval FALSE no space in the transmit queue.
|
|
|
|
* @retval TRUE transmit slot available.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
bool can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) {
|
2014-11-01 17:01:38 +00:00
|
|
|
|
|
|
|
(void)canp;
|
|
|
|
|
|
|
|
switch (mailbox) {
|
|
|
|
case CAN_ANY_MAILBOX:
|
|
|
|
return FALSE;
|
|
|
|
case 1:
|
|
|
|
return FALSE;
|
|
|
|
case 2:
|
|
|
|
return FALSE;
|
|
|
|
case 3:
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Inserts a frame into the transmit queue.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
* @param[in] ctfp pointer to the CAN frame to be transmitted
|
|
|
|
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_transmit(CANDriver *canp,
|
|
|
|
canmbx_t mailbox,
|
|
|
|
const CANTxFrame *ctfp) {
|
|
|
|
|
|
|
|
(void)canp;
|
|
|
|
(void)mailbox;
|
|
|
|
(void)ctfp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Determines whether a frame has been received.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
|
|
|
|
*
|
|
|
|
* @return The queue space availability.
|
|
|
|
* @retval FALSE no space in the transmit queue.
|
|
|
|
* @retval TRUE transmit slot available.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
bool can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
|
2014-11-01 17:01:38 +00:00
|
|
|
|
|
|
|
(void)canp;
|
|
|
|
(void)mailbox;
|
|
|
|
|
|
|
|
switch (mailbox) {
|
|
|
|
case CAN_ANY_MAILBOX:
|
|
|
|
return FALSE;
|
|
|
|
case 1:
|
|
|
|
return FALSE;
|
|
|
|
case 2:
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Receives a frame from the input queue.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
* @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
|
|
|
|
* @param[out] crfp pointer to the buffer where the CAN frame is copied
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_receive(CANDriver *canp,
|
|
|
|
canmbx_t mailbox,
|
|
|
|
CANRxFrame *crfp) {
|
|
|
|
|
|
|
|
(void)canp;
|
|
|
|
(void)mailbox;
|
|
|
|
(void)crfp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__)
|
|
|
|
/**
|
|
|
|
* @brief Enters the sleep mode.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_sleep(CANDriver *canp) {
|
|
|
|
|
|
|
|
(void)canp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enforces leaving the sleep mode.
|
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void can_lld_wakeup(CANDriver *canp) {
|
|
|
|
|
|
|
|
(void)canp;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* CAN_USE_SLEEP_MODE */
|
|
|
|
|
|
|
|
#endif /* HAL_USE_CAN */
|
|
|
|
|
|
|
|
/** @} */
|