BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_hal_phy.h Source File

arm_hal_phy.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /**
00019  * \file arm_hal_phy.h
00020  * \brief PHY device driver API.
00021  */
00022 
00023 #ifndef ARM_HAL_PHY_H_
00024 #define ARM_HAL_PHY_H_
00025 
00026 #include "ns_types.h"
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 /** Interface states */
00033 typedef enum {
00034     PHY_INTERFACE_RESET,            /**< Reset PHY driver and set to idle. */
00035     PHY_INTERFACE_DOWN,             /**< Disable PHY interface driver (RF radio disable). */
00036     PHY_INTERFACE_UP,               /**< Enable PHY interface driver (RF radio receiver ON). */
00037     PHY_INTERFACE_RX_ENERGY_STATE,  /**< Enable wireless interface ED scan mode. */
00038     PHY_INTERFACE_SNIFFER_STATE     /**< Enable sniffer mode. */
00039 } phy_interface_state_e;
00040 
00041 /** TX process return codes */
00042 typedef enum {
00043     PHY_LINK_TX_DONE,           /**< TX process ready and ACK RX. */
00044     PHY_LINK_TX_DONE_PENDING,   /**< TX process OK with ACK pending flag. */
00045     PHY_LINK_TX_SUCCESS,        /**< MAC TX complete. MAC will a make decision to enter wait ACK or TX done state. */
00046     PHY_LINK_TX_FAIL,           /**< Link TX process fail. */
00047     PHY_LINK_CCA_FAIL,          /**< RF link CCA process fail. */
00048 } phy_link_tx_status_e;
00049 
00050 /** Extension types */
00051 typedef enum {
00052     PHY_EXTENSION_CTRL_PENDING_BIT, /**< Control MAC pending bit for indirect data. */
00053     PHY_EXTENSION_READ_LAST_ACK_PENDING_STATUS, /**< Read status if the last ACK is still pending. */
00054     PHY_EXTENSION_SET_CHANNEL,  /**< Net library channel set. */
00055     PHY_EXTENSION_READ_CHANNEL_ENERGY, /**< RF interface ED scan energy read. */
00056     PHY_EXTENSION_READ_LINK_STATUS, /**< Net library could read link status. */
00057     PHY_EXTENSION_CONVERT_SIGNAL_INFO, /**< Convert signal info. */
00058     PHY_EXTENSION_ACCEPT_ANY_BEACON, /**< Set boolean true or false for accept beacon from other Pan-ID than configured. Default value should be false */
00059 } phy_extension_type_e;
00060 
00061 /** Address types */
00062 typedef enum {
00063     PHY_MAC_48BIT, /**< IPv4/IPv6/BLE link layer address for Ethernet. This is optional. */
00064     PHY_MAC_64BIT, /**< RF/PLC link layer address. */
00065     PHY_MAC_16BIT, /**< RF interface short address. */
00066     PHY_MAC_PANID, /**< RF interface 16-Bit PAN-ID. */
00067 } phy_address_type_e;
00068 
00069 /** PHY types */
00070 typedef enum phy_link_type_e {
00071     PHY_LINK_ETHERNET_TYPE,         /**< Standard IEEE 802 Ethernet. */
00072     PHY_LINK_15_4_2_4GHZ_TYPE,      /**< Standard 802.15.4 2.4GHz radio. */
00073     PHY_LINK_15_4_SUBGHZ_TYPE,      /**< Standard 802.15.4 subGHz radio 868 /915MHz. */
00074     PHY_LINK_TUN,                   /**< Tunnel interface for Linux TUN, RF network driver over serial bus or just basic application to application data flow. */
00075     PHY_LINK_SLIP,                  /**< Generic SLIP driver which just forward SLIP payload */
00076 } phy_link_type_e;
00077 
00078 /** Data layers */
00079 typedef enum data_protocol_e {
00080     LOCAL_SOCKET_DATA = 0,          /**< 6LoWPAN library local socket data. */
00081     INTERFACE_DATA = 1,             /**< 6LoWPAN library interface internal used protocol. */
00082     PHY_LAYER_PAYLOAD = 2,          /**< PHY layer data selection or handler. */
00083     IPV6_DATAGRAM = 3,              /**< IP layer data or TUN driver request data. */
00084     UNKNOWN_PROTOCOL = 4            /**< Non-supported protocol ID. */
00085 } data_protocol_e;
00086 
00087 /** Requested data layer */
00088 typedef enum driver_data_request_e {
00089     PHY_LAYER_PAYLOAD_DATA_FLOW,    /**< PHY layer data. */
00090     IPV6_DATAGRAMS_DATA_FLOW,       /**< IP layer data or TUN driver request data. */
00091 } driver_data_request_e;
00092 
00093 /** \brief Signal info types.
00094  *
00095  * Types of signal quality indication desired by various link protocols. Some are
00096  * really statistical, but a driver should ideally be able to create an estimate
00097  * based on its LQI/DBM numbers, for example to bootstrap a statistic calculation.
00098  */
00099 typedef enum phy_signal_info_type_e {
00100     PHY_SIGNAL_INFO_ETX,            /**< Expected transmissions, unsigned 16-bit fixed-point ETX*128 [1..512], for example Zigbee IP + RFC 6719. */
00101     PHY_SIGNAL_INFO_IDR,            /**< Inverse Delivery Ratio, unsigned 16-bit fixed-point IDR*32*256 [1..8], for example MLE draft 06. */
00102     PHY_SIGNAL_INFO_LINK_MARGIN,    /**< Link margin, unsigned 16-bit fixed-point dB*256, [0..255], for example Thread routing draft. */
00103 } phy_signal_info_type_e;
00104 
00105 /** Signal level info */
00106 typedef struct phy_signal_info_s {
00107     phy_signal_info_type_e type;    /**< Signal info type desired. */
00108     uint8_t lqi;                    /**< Quality passed to arm_net_phy_rx. */
00109     int8_t dbm;                     /**< Strength passed to arm_net_phy_rx. */
00110     uint16_t result;                /**< Resulting signal information. */
00111 } phy_signal_info_s;
00112 
00113 /** PHY modulation scheme */
00114 typedef enum phy_modulation_e
00115 {
00116     M_OFDM,     ///< QFDM
00117     M_OQPSK,    ///< OQPSK
00118     M_BPSK,     ///< BPSK
00119     M_GFSK,     ///< GFSK
00120     M_UNDEFINED ///< UNDEFINED
00121 } phy_modulation_e;
00122 
00123 /** Channel page numbers */
00124 typedef enum
00125 {
00126     CHANNEL_PAGE_0 = 0,     ///< Page 0
00127     CHANNEL_PAGE_1 = 1,     ///< Page 1
00128     CHANNEL_PAGE_2 = 2,     ///< Page 2
00129     CHANNEL_PAGE_3 = 3,     ///< Page 3
00130     CHANNEL_PAGE_4 = 4,     ///< Page 4
00131     CHANNEL_PAGE_5 = 5,     ///< Page 5
00132     CHANNEL_PAGE_6 = 6,     ///< Page 6
00133     CHANNEL_PAGE_9 = 9,     ///< Page 9
00134     CHANNEL_PAGE_10 = 10    ///< Page 10
00135 } channel_page_e;
00136 
00137 /** Channel configuration */
00138 typedef struct phy_rf_channel_configuration_s
00139 {
00140     uint32_t channel_0_center_frequency;    ///< Center frequency
00141     uint32_t channel_spacing;               ///< Channel spacing
00142     uint32_t datarate;                      ///< Data rate
00143     uint16_t number_of_channels;            ///< Number of channels
00144     phy_modulation_e modulation;            ///< Modulation scheme
00145 } phy_rf_channel_configuration_s;
00146 
00147 /** Channel page configuration */
00148 typedef struct phy_device_channel_page_s
00149 {
00150     channel_page_e channel_page;            ///< Channel page
00151     const phy_rf_channel_configuration_s *rf_channel_configuration; ///< Pointer to channel configuration
00152 } phy_device_channel_page_s;
00153 
00154 /** Virtual data request */
00155 typedef struct virtual_data_req_s {
00156     uint16_t parameter_length;      /**< Length of user specified header. Can be zero. */
00157     uint8_t *parameters;            /**< Pointer to user specified header. Optional */
00158     uint16_t msduLength;            /**< MSDU Length */
00159     const uint8_t *msdu;            /**< MSDU */
00160 } virtual_data_req_t;
00161 
00162 /**
00163  * @brief arm_net_phy_rx RX callback set by upper layer. Called when data is received
00164  * @param data_ptr Data received
00165  * @param data_len Length of the data received
00166  * @param link_quality Link quality
00167  * @param dbm Power ratio in decibels
00168  * @param driver_id ID of driver which received data
00169  * @return 0 if success, error otherwise
00170  */
00171 typedef int8_t arm_net_phy_rx_fn(const uint8_t *data_ptr, uint16_t data_len, uint8_t link_quality, int8_t dbm, int8_t driver_id);
00172 
00173 /**
00174  * @brief arm_net_phy_tx_done TX done callback set by upper layer. Called when tx sent by upper layer has been handled
00175  * @param driver_id Id of the driver which handled TX request
00176  * @param tx_handle Handle of the TX
00177  * @param status Status code of the TX handling result
00178  * @param cca_retry Number of CCA retries done during handling
00179  * @param tx_retry Number of TX retries done during handling
00180  * @return 0 if success, error otherwise
00181  */
00182 typedef int8_t arm_net_phy_tx_done_fn(int8_t driver_id, uint8_t tx_handle, phy_link_tx_status_e status, uint8_t cca_retry, uint8_t tx_retry);
00183 
00184 /**
00185  * @brief arm_net_virtual_rx RX callback set by user of serial MAC. Called when virtual RF has received data.
00186  * @param data_ptr Data received
00187  * @param data_len Length of the data received
00188  * @param driver_id ID of driver which received data
00189  * @return 0 if success, error otherwise
00190  */
00191 typedef int8_t arm_net_virtual_rx_fn(const uint8_t *data_ptr, uint16_t data_len,int8_t driver_id);
00192 
00193 /**
00194  * @brief arm_net_virtual_tx TX callback set by serial MAC. Used to send data.
00195  * @param data_req Data to be sent
00196  * @param driver_id Id of the driver to be used.
00197  * @return 0 if success, error otherwise
00198  */
00199 typedef int8_t arm_net_virtual_tx_fn(const virtual_data_req_t *data_req,int8_t driver_id);
00200 
00201 /**
00202  * @brief arm_net_virtual_config Configuration receive callback set by upper layer. Used to receive internal configuration parameters.
00203  * @param driver_id Id of the driver to be used.
00204  * @param data Pointer to received configuration data.
00205  * @param length Length of the configuration data.
00206  * @return 0 if success, error otherwise
00207  */
00208 typedef int8_t arm_net_virtual_config_rx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
00209 
00210 /**
00211  * @brief arm_net_virtual_config Configuration send callback set by upper layer. Used to send internal configuration parameters.
00212  * @param driver_id Id of the driver to be used.
00213  * @param data Pointer to sent configuration data.
00214  * @param length Length of the configuration data.
00215  * @return 0 if success, error otherwise
00216  */
00217 typedef int8_t arm_net_virtual_config_tx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
00218 
00219 /**
00220  * @brief arm_net_virtual_confirmation Confirmation receive callback set by upper layer. Used to receive MLME confirmation data.
00221  * @param driver_id Id of the driver to be used.
00222  * @param data Pointer to received confirmation data.
00223  * @param length Length of the confirmation data.
00224  * @return 0 if success, error otherwise
00225  */
00226 typedef int8_t arm_net_virtual_confirmation_rx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
00227 
00228 /** Device driver structure */
00229 typedef struct phy_device_driver_s
00230 {
00231     phy_link_type_e link_type;                                      /**< Define driver types. */
00232     driver_data_request_e data_request_layer;                       /**< Define interface data OUT protocol. */
00233     uint8_t *PHY_MAC;                                               /**< Pointer to 64-bit or 48-bit MAC address. */
00234     uint16_t phy_MTU;                                               /**< Define MAX PHY layer MTU size. */
00235     char *driver_description;                                       /**< Short driver platform description. Needs to end with zero. */
00236     uint8_t phy_tail_length;                                        /**< Define PHY driver needed TAIL Length. */
00237     uint8_t phy_header_length;                                      /**< Define PHY driver needed header length before PDU. */
00238     int8_t (*state_control)(phy_interface_state_e, uint8_t);        /**< Function pointer for control PHY driver state. */
00239     int8_t (*tx)(uint8_t *, uint16_t, uint8_t, data_protocol_e);    /**< Function pointer for PHY driver write operation. */
00240     int8_t (*address_write)(phy_address_type_e , uint8_t *);        /**< Function pointer for PHY driver address write. */
00241     int8_t (*extension)(phy_extension_type_e, uint8_t *);           /**< Function pointer for PHY driver extension control. */
00242     const phy_device_channel_page_s *phy_channel_pages;             /**< Pointer to channel page list */
00243 
00244     //Upper layer callbacks, set with arm_net_phy_register();
00245     arm_net_phy_rx_fn *phy_rx_cb;                                   /**< PHY RX callback. Initialized by \ref arm_net_phy_register(). */
00246     arm_net_phy_tx_done_fn *phy_tx_done_cb;                         /**< Transmission done callback. Initialized by \ref arm_net_phy_register(). */
00247     //Virtual upper data rx
00248     arm_net_virtual_rx_fn *arm_net_virtual_rx_cb;                   /**< Virtual RX callback. Initialized by \ref arm_net_phy_register(). */
00249     arm_net_virtual_tx_fn *arm_net_virtual_tx_cb;                   /**< Virtual TX callback. Initialized by \ref arm_net_phy_register(). */
00250     arm_net_virtual_config_rx_fn *virtual_config_rx_cb;             /**< Virtual config receive callback. Initialized by \ref arm_net_phy_register(). */
00251     arm_net_virtual_config_tx_fn *virtual_config_tx_cb;             /**< Virtual config send callback. Initialized by \ref arm_net_phy_register(). */
00252     arm_net_virtual_confirmation_rx_fn *virtual_confirmation_rx_cb; /**< Virtual confirmation receive callback. Initialized by \ref arm_net_phy_register(). */
00253     uint16_t tunnel_type; /**< Tun driver type. */
00254 } phy_device_driver_s;
00255 
00256 
00257 /**
00258  * \brief This function registers the device driver to stack.
00259  *
00260  * \param phy_driver A pointer to device driver structure.
00261  *
00262  * \return >= 0 Device driver ID.
00263  * \return < 0 Means register fail.
00264  *
00265  */
00266 extern int8_t arm_net_phy_register(phy_device_driver_s *phy_driver);
00267 
00268 
00269 /**
00270  * \brief Set driver mac64 address.
00271  *
00272  * \param MAC A pointer to new mac64 address which is copied to old one.
00273  * \param  id driver id
00274  *
00275  * \return >= 0 SET OK.
00276  * \return < 0 Means register fail.
00277  *
00278  */
00279 extern int8_t arm_net_phy_mac64_set(uint8_t *MAC, int8_t id);
00280 
00281 /**
00282  * \brief Get driver mac64 address.
00283  *
00284  * \param  id driver id
00285  *
00286  * \return > 0 Return pointer to MAC.
00287  * \return NULL.
00288  *
00289  */
00290 extern uint8_t *arm_net_phy_mac64_get(int8_t id);
00291 
00292 /**
00293  * \brief Get driver link type.
00294  *
00295  * \param  id driver id
00296  *
00297  * \return driver link type.
00298  *
00299  */
00300 extern int arm_net_phy_rf_type(int8_t id);
00301 
00302 /**
00303  * \brief Get driver link type MTU size.
00304  *
00305  * \param  id driver id
00306  *
00307  * \return size of MTU.
00308  *
00309  */
00310 extern uint16_t arm_net_phy_mtu_size(int8_t id);
00311 
00312 /**
00313  * \brief Unregister the driver from storage.
00314  *
00315  * \param driver_id driver id
00316  *
00317  */
00318 extern void arm_net_phy_unregister(int8_t driver_id);
00319 
00320 #ifdef __cplusplus
00321 }
00322 #endif
00323 #endif /* ARM_HAL_PHY_H_ */