|
ChibiOS/RT
2.5.1 |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 00003 2011,2012 Giovanni Di Sirio. 00004 00005 This file is part of ChibiOS/RT. 00006 00007 ChibiOS/RT is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ChibiOS/RT is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 /** 00022 * @file mac.h 00023 * @brief MAC Driver macros and structures. 00024 * @addtogroup MAC 00025 * @{ 00026 */ 00027 00028 #ifndef _MAC_H_ 00029 #define _MAC_H_ 00030 00031 #if HAL_USE_MAC || defined(__DOXYGEN__) 00032 00033 /*===========================================================================*/ 00034 /* Driver constants. */ 00035 /*===========================================================================*/ 00036 00037 /*===========================================================================*/ 00038 /* Driver pre-compile time settings. */ 00039 /*===========================================================================*/ 00040 00041 /** 00042 * @name MAC configuration options 00043 * @{ 00044 */ 00045 /** 00046 * @brief Enables an event sources for incoming packets. 00047 */ 00048 #if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__) 00049 #define MAC_USE_EVENTS TRUE 00050 #endif 00051 /** @} */ 00052 00053 /*===========================================================================*/ 00054 /* Derived constants and error checks. */ 00055 /*===========================================================================*/ 00056 00057 #if !CH_USE_SEMAPHORES || !CH_USE_EVENTS 00058 #error "the MAC driver requires CH_USE_SEMAPHORES" 00059 #endif 00060 00061 #if MAC_USE_EVENTS && !CH_USE_EVENTS 00062 #error "the MAC driver requires CH_USE_EVENTS" 00063 #endif 00064 00065 /*===========================================================================*/ 00066 /* Driver data structures and types. */ 00067 /*===========================================================================*/ 00068 00069 /** 00070 * @brief Driver state machine possible states. 00071 */ 00072 typedef enum { 00073 MAC_UNINIT = 0, /**< Not initialized. */ 00074 MAC_STOP = 1, /**< Stopped. */ 00075 MAC_ACTIVE = 2 /**< Active. */ 00076 } macstate_t; 00077 00078 /** 00079 * @brief Type of a structure representing a MAC driver. 00080 */ 00081 typedef struct MACDriver MACDriver; 00082 00083 #include "mac_lld.h" 00084 00085 /*===========================================================================*/ 00086 /* Driver macros. */ 00087 /*===========================================================================*/ 00088 00089 /** 00090 * @name Macro Functions 00091 * @{ 00092 */ 00093 /** 00094 * @brief Returns the received frames event source. 00095 * 00096 * @param[in] macp pointer to the @p MACDriver object 00097 * @return The pointer to the @p EventSource structure. 00098 * 00099 * @api 00100 */ 00101 #if MAC_USE_EVENTS || defined(__DOXYGEN__) 00102 #define macGetReceiveEventSource(macp) (&(macp)->rdevent) 00103 #endif 00104 00105 /** 00106 * @brief Writes to a transmit descriptor's stream. 00107 * 00108 * @param[in] tdp pointer to a @p MACTransmitDescriptor structure 00109 * @param[in] buf pointer to the buffer containing the data to be written 00110 * @param[in] size number of bytes to be written 00111 * @return The number of bytes written into the descriptor's 00112 * stream, this value can be less than the amount 00113 * specified in the parameter @p size if the maximum frame 00114 * size is reached. 00115 * 00116 * @api 00117 */ 00118 #define macWriteTransmitDescriptor(tdp, buf, size) \ 00119 mac_lld_write_transmit_descriptor(tdp, buf, size) 00120 00121 /** 00122 * @brief Reads from a receive descriptor's stream. 00123 * 00124 * @param[in] rdp pointer to a @p MACReceiveDescriptor structure 00125 * @param[in] buf pointer to the buffer that will receive the read data 00126 * @param[in] size number of bytes to be read 00127 * @return The number of bytes read from the descriptor's stream, this 00128 * value can be less than the amount specified in the 00129 * parameter @p size if there are no more bytes to read. 00130 * 00131 * @api 00132 */ 00133 #define macReadReceiveDescriptor(rdp, buf, size) \ 00134 mac_lld_read_receive_descriptor(rdp, buf, size) 00135 /** @} */ 00136 00137 /*===========================================================================*/ 00138 /* External declarations. */ 00139 /*===========================================================================*/ 00140 00141 #ifdef __cplusplus 00142 extern "C" { 00143 #endif 00144 void macInit(void); 00145 void macObjectInit(MACDriver *macp); 00146 void macStart(MACDriver *macp, const MACConfig *config); 00147 void macStop(MACDriver *macp); 00148 void macSetAddress(MACDriver *macp, const uint8_t *p); 00149 msg_t macWaitTransmitDescriptor(MACDriver *macp, 00150 MACTransmitDescriptor *tdp, 00151 systime_t time); 00152 void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp); 00153 msg_t macWaitReceiveDescriptor(MACDriver *macp, 00154 MACReceiveDescriptor *rdp, 00155 systime_t time); 00156 void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp); 00157 bool_t macPollLinkStatus(MACDriver *macp); 00158 #ifdef __cplusplus 00159 } 00160 #endif 00161 00162 #endif /* HAL_USE_MAC */ 00163 00164 #endif /* _MAC_H_ */ 00165 00166 /** @} */