ChibiOS/RT
2.6.0
mac_lld.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
00003 
00004     Licensed under the Apache License, Version 2.0 (the "License");
00005     you may not use this file except in compliance with the License.
00006     You may obtain a copy of the License at
00007 
00008         http://www.apache.org/licenses/LICENSE-2.0
00009 
00010     Unless required by applicable law or agreed to in writing, software
00011     distributed under the License is distributed on an "AS IS" BASIS,
00012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013     See the License for the specific language governing permissions and
00014     limitations under the License.
00015 */
00016 
00017 /**
00018  * @file    templates/mac_lld.h
00019  * @brief   MAC Driver subsystem low level driver header template.
00020  *
00021  * @addtogroup MAC
00022  * @{
00023  */
00024 
00025 #ifndef _MAC_LLD_H_
00026 #define _MAC_LLD_H_
00027 
00028 #if HAL_USE_MAC || defined(__DOXYGEN__)
00029 
00030 /*===========================================================================*/
00031 /* Driver constants.                                                         */
00032 /*===========================================================================*/
00033 
00034 /**
00035  * @brief   This implementation supports the zero-copy mode API.
00036  */
00037 #define MAC_SUPPORTS_ZERO_COPY              TRUE
00038 
00039 /*===========================================================================*/
00040 /* Driver pre-compile time settings.                                         */
00041 /*===========================================================================*/
00042 
00043 /**
00044  * @name    Configuration options
00045  * @{
00046  */
00047 /**
00048  * @brief   MAC driver enable switch.
00049  * @details If set to @p TRUE the support for MAC1 is included.
00050  */
00051 #if !defined(PLATFORM_MAC_USE_MAC1) || defined(__DOXYGEN__)
00052 #define PLATFORM_MAC_USE_MAC1               FALSE
00053 #endif
00054 /** @} */
00055 
00056 /*===========================================================================*/
00057 /* Derived constants and error checks.                                       */
00058 /*===========================================================================*/
00059 
00060 /*===========================================================================*/
00061 /* Driver data structures and types.                                         */
00062 /*===========================================================================*/
00063 
00064 /**
00065  * @brief   Driver configuration structure.
00066  */
00067 typedef struct {
00068   /**
00069    * @brief MAC address.
00070    */
00071   uint8_t               *mac_address;
00072   /* End of the mandatory fields.*/
00073 } MACConfig;
00074 
00075 /**
00076  * @brief   Structure representing a MAC driver.
00077  */
00078 struct MACDriver {
00079   /**
00080    * @brief Driver state.
00081    */
00082   macstate_t            state;
00083   /**
00084    * @brief Current configuration data.
00085    */
00086   const MACConfig       *config;
00087   /**
00088    * @brief Transmit semaphore.
00089    */
00090   Semaphore             tdsem;
00091   /**
00092    * @brief Receive semaphore.
00093    */
00094   Semaphore             rdsem;
00095 #if MAC_USE_EVENTS || defined(__DOXYGEN__)
00096   /**
00097    * @brief Receive event.
00098    */
00099   EventSource           rdevent;
00100 #endif
00101   /* End of the mandatory fields.*/
00102 };
00103 
00104 /**
00105  * @brief   Structure representing a transmit descriptor.
00106  */
00107 typedef struct {
00108   /**
00109    * @brief Current write offset.
00110    */
00111   size_t                    offset;
00112   /**
00113    * @brief Available space size.
00114    */
00115   size_t                    size;
00116   /* End of the mandatory fields.*/
00117 } MACTransmitDescriptor;
00118 
00119 /**
00120  * @brief   Structure representing a receive descriptor.
00121  */
00122 typedef struct {
00123   /**
00124    * @brief Current read offset.
00125    */
00126   size_t                offset;
00127   /**
00128    * @brief Available data size.
00129    */
00130   size_t                size;
00131   /* End of the mandatory fields.*/
00132 } MACReceiveDescriptor;
00133 
00134 /*===========================================================================*/
00135 /* Driver macros.                                                            */
00136 /*===========================================================================*/
00137 
00138 /*===========================================================================*/
00139 /* External declarations.                                                    */
00140 /*===========================================================================*/
00141 
00142 #if PLATFORM_MAC_USE_MAC1 && !defined(__DOXYGEN__)
00143 extern MACDriver ETHD1;
00144 #endif
00145 
00146 #ifdef __cplusplus
00147 extern "C" {
00148 #endif
00149   void mac_lld_init(void);
00150   void mac_lld_start(MACDriver *macp);
00151   void mac_lld_stop(MACDriver *macp);
00152   msg_t mac_lld_get_transmit_descriptor(MACDriver *macp,
00153                                         MACTransmitDescriptor *tdp);
00154   void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
00155   msg_t mac_lld_get_receive_descriptor(MACDriver *macp,
00156                                        MACReceiveDescriptor *rdp);
00157   void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp);
00158   bool_t mac_lld_poll_link_status(MACDriver *macp);
00159   size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp,
00160                                            uint8_t *buf,
00161                                            size_t size);
00162   size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp,
00163                                          uint8_t *buf,
00164                                          size_t size);
00165 #if MAC_USE_ZERO_COPY
00166   uint8_t *mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp,
00167                                             size_t size,
00168                                             size_t *sizep);
00169   const uint8_t *mac_lld_get_next_receive_buffer(MACReceiveDescriptor *rdp,
00170                                                  size_t *sizep);
00171 #endif /* MAC_USE_ZERO_COPY */
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175 
00176 #endif /* HAL_USE_MAC */
00177 
00178 #endif /* _MAC_LLD_H_ */
00179 
00180 /** @} */