2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2013-02-02 10:58:09 +00:00
|
|
|
2011,2012,2013 Giovanni Di Sirio.
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @file can.h
|
|
|
|
* @brief CAN Driver macros and structures.
|
|
|
|
*
|
2009-11-29 08:50:13 +00:00
|
|
|
* @addtogroup CAN
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CAN_H_
|
|
|
|
#define _CAN_H_
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_CAN || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2011-08-23 13:36:25 +00:00
|
|
|
/**
|
|
|
|
* @name CAN status flags
|
|
|
|
* @{
|
|
|
|
*/
|
2009-12-01 16:32:16 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Errors rate warning.
|
2009-12-01 16:32:16 +00:00
|
|
|
*/
|
2010-01-02 13:35:55 +00:00
|
|
|
#define CAN_LIMIT_WARNING 1
|
2009-12-01 16:32:16 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Errors rate error.
|
2009-12-01 16:32:16 +00:00
|
|
|
*/
|
2010-01-02 13:35:55 +00:00
|
|
|
#define CAN_LIMIT_ERROR 2
|
2009-12-01 16:32:16 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Bus off condition reached.
|
2009-12-01 16:32:16 +00:00
|
|
|
*/
|
2010-01-02 13:35:55 +00:00
|
|
|
#define CAN_BUS_OFF_ERROR 4
|
2009-12-01 16:32:16 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Framing error of some kind on the CAN bus.
|
2009-12-01 16:32:16 +00:00
|
|
|
*/
|
2010-01-02 13:35:55 +00:00
|
|
|
#define CAN_FRAMING_ERROR 8
|
2009-12-01 16:32:16 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Overflow in receive queue.
|
2009-12-01 16:32:16 +00:00
|
|
|
*/
|
2010-01-02 13:35:55 +00:00
|
|
|
#define CAN_OVERFLOW_ERROR 16
|
2011-08-23 13:36:25 +00:00
|
|
|
/** @} */
|
2009-12-01 16:32:16 +00:00
|
|
|
|
2013-02-22 13:42:10 +00:00
|
|
|
/**
|
|
|
|
* @brief Special TX mailbox identifier.
|
|
|
|
*/
|
|
|
|
#define CAN_ANY_TX_MAILBOX 0
|
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-08-23 13:36:25 +00:00
|
|
|
/**
|
|
|
|
* @name CAN configuration options
|
|
|
|
* @{
|
|
|
|
*/
|
2010-01-02 10:59:48 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Sleep mode related APIs inclusion switch.
|
2011-08-23 13:36:25 +00:00
|
|
|
* @details This option can only be enabled if the CAN implementation supports
|
|
|
|
* the sleep mode, see the macro @p CAN_SUPPORTS_SLEEP exported by
|
|
|
|
* the underlying implementation.
|
2010-01-02 10:59:48 +00:00
|
|
|
*/
|
2010-09-11 10:57:11 +00:00
|
|
|
#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
|
2010-01-02 10:59:48 +00:00
|
|
|
#define CAN_USE_SLEEP_MODE TRUE
|
2010-09-11 10:57:11 +00:00
|
|
|
#endif
|
2011-08-23 13:36:25 +00:00
|
|
|
/** @} */
|
2010-01-02 10:59:48 +00:00
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-12-29 13:15:29 +00:00
|
|
|
#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
|
2010-01-02 13:35:55 +00:00
|
|
|
#error "CAN driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS"
|
2009-12-29 11:12:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Driver state machine possible states.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2010-10-31 13:06:42 +00:00
|
|
|
CAN_UNINIT = 0, /**< Not initialized. */
|
|
|
|
CAN_STOP = 1, /**< Stopped. */
|
|
|
|
CAN_STARTING = 2, /**< Starting. */
|
|
|
|
CAN_READY = 3, /**< Ready. */
|
|
|
|
CAN_SLEEP = 4 /**< Sleep state. */
|
2009-11-29 08:50:13 +00:00
|
|
|
} canstate_t;
|
|
|
|
|
|
|
|
#include "can_lld.h"
|
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-08-23 13:36:25 +00:00
|
|
|
/**
|
|
|
|
* @name Macro Functions
|
|
|
|
* @{
|
|
|
|
*/
|
2013-02-22 15:10:56 +00:00
|
|
|
/**
|
|
|
|
* @bried Converts a mailbox index to a bit mask.
|
|
|
|
*/
|
|
|
|
#define CAN_MAILBOX_TO_MASK(mbx) (1 << ((mbx) - 1))
|
|
|
|
|
2009-11-30 21:34:05 +00:00
|
|
|
/**
|
2010-02-06 16:17:30 +00:00
|
|
|
* @brief Adds some flags to the CAN status mask.
|
2009-11-30 21:34:05 +00:00
|
|
|
*
|
|
|
|
* @param[in] canp pointer to the @p CANDriver object
|
|
|
|
* @param[in] mask flags to be added to the status mask
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
2009-11-30 21:34:05 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
#define canAddFlagsI(canp, mask) ((canp)->status |= (mask))
|
2011-08-23 13:36:25 +00:00
|
|
|
/** @} */
|
2009-11-30 21:34:05 +00:00
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void canInit(void);
|
|
|
|
void canObjectInit(CANDriver *canp);
|
|
|
|
void canStart(CANDriver *canp, const CANConfig *config);
|
|
|
|
void canStop(CANDriver *canp);
|
2013-02-22 13:42:10 +00:00
|
|
|
msg_t canTransmit(CANDriver *canp,
|
|
|
|
canmbx_t mailbox,
|
|
|
|
const CANTxFrame *ctfp,
|
|
|
|
systime_t timeout);
|
|
|
|
msg_t canReceive(CANDriver *canp,
|
|
|
|
canmbx_t mailbox,
|
|
|
|
CANRxFrame *crfp,
|
|
|
|
systime_t timeout);
|
2009-11-29 08:50:13 +00:00
|
|
|
#if CAN_USE_SLEEP_MODE
|
|
|
|
void canSleep(CANDriver *canp);
|
|
|
|
void canWakeup(CANDriver *canp);
|
|
|
|
#endif /* CAN_USE_SLEEP_MODE */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_CAN */
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#endif /* _CAN_H_ */
|
|
|
|
|
|
|
|
/** @} */
|