ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file can.h 00029 * @brief CAN Driver macros and structures. 00030 * 00031 * @addtogroup CAN 00032 * @{ 00033 */ 00034 00035 #ifndef _CAN_H_ 00036 #define _CAN_H_ 00037 00038 #if CH_HAL_USE_CAN || defined(__DOXYGEN__) 00039 00040 /*===========================================================================*/ 00041 /* Driver constants. */ 00042 /*===========================================================================*/ 00043 00044 /** 00045 * @brief Errors rate warning. 00046 */ 00047 #define CAN_LIMIT_WARNING 1 00048 /** 00049 * @brief Errors rate error. 00050 */ 00051 #define CAN_LIMIT_ERROR 2 00052 /** 00053 * @brief Bus off condition reached. 00054 */ 00055 #define CAN_BUS_OFF_ERROR 4 00056 /** 00057 * @brief Framing error of some kind on the CAN bus. 00058 */ 00059 #define CAN_FRAMING_ERROR 8 00060 /** 00061 * @brief Overflow in receive queue. 00062 */ 00063 #define CAN_OVERFLOW_ERROR 16 00064 00065 /*===========================================================================*/ 00066 /* Driver pre-compile time settings. */ 00067 /*===========================================================================*/ 00068 00069 /** 00070 * @brief Sleep mode related APIs inclusion switch. 00071 */ 00072 #if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) 00073 #define CAN_USE_SLEEP_MODE TRUE 00074 #endif 00075 00076 /*===========================================================================*/ 00077 /* Derived constants and error checks. */ 00078 /*===========================================================================*/ 00079 00080 #if !CH_USE_SEMAPHORES || !CH_USE_EVENTS 00081 #error "CAN driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS" 00082 #endif 00083 00084 /*===========================================================================*/ 00085 /* Driver data structures and types. */ 00086 /*===========================================================================*/ 00087 00088 /** 00089 * @brief Driver state machine possible states. 00090 */ 00091 typedef enum { 00092 CAN_UNINIT = 0, /**< @brief Not initialized. */ 00093 CAN_STOP = 1, /**< @brief Stopped. */ 00094 CAN_STARTING = 2, /**< @brief Starting. */ 00095 CAN_READY = 3, /**< @brief Ready. */ 00096 CAN_SLEEP = 4 /**< @brief Sleep state. */ 00097 } canstate_t; 00098 00099 #include "can_lld.h" 00100 00101 /*===========================================================================*/ 00102 /* Driver macros. */ 00103 /*===========================================================================*/ 00104 00105 /** 00106 * @brief Adds some flags to the CAN status mask. 00107 * 00108 * @param[in] canp pointer to the @p CANDriver object 00109 * @param[in] mask flags to be added to the status mask 00110 */ 00111 #define canAddFlagsI(canp, mask) ((canp)->cd_status |= (mask)) 00112 00113 /*===========================================================================*/ 00114 /* External declarations. */ 00115 /*===========================================================================*/ 00116 00117 #ifdef __cplusplus 00118 extern "C" { 00119 #endif 00120 void canInit(void); 00121 void canObjectInit(CANDriver *canp); 00122 void canStart(CANDriver *canp, const CANConfig *config); 00123 void canStop(CANDriver *canp); 00124 msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout); 00125 msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout); 00126 canstatus_t canGetAndClearFlags(CANDriver *canp); 00127 #if CAN_USE_SLEEP_MODE 00128 void canSleep(CANDriver *canp); 00129 void canWakeup(CANDriver *canp); 00130 #endif /* CAN_USE_SLEEP_MODE */ 00131 #ifdef __cplusplus 00132 } 00133 #endif 00134 00135 #endif /* CH_HAL_USE_CAN */ 00136 00137 #endif /* _CAN_H_ */ 00138 00139 /** @} */