takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

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-2018, 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_CCA_PREPARE,       /**< RX Tx timeout prepare operation like channel switch to Tx channel from Receive one If operation fail must return not zero*/
00049 } phy_link_tx_status_e;
00050 
00051 /** Extension types */
00052 typedef enum {
00053     PHY_EXTENSION_CTRL_PENDING_BIT, /**< Control MAC pending bit for indirect data. */
00054     PHY_EXTENSION_READ_LAST_ACK_PENDING_STATUS, /**< Read status if the last ACK is still pending. */
00055     PHY_EXTENSION_SET_CHANNEL,  /**< Net library channel set. */
00056     PHY_EXTENSION_READ_CHANNEL_ENERGY, /**< RF interface ED scan energy read. */
00057     PHY_EXTENSION_READ_LINK_STATUS, /**< Net library could read link status. */
00058     PHY_EXTENSION_CONVERT_SIGNAL_INFO, /**< Convert signal info. */
00059     PHY_EXTENSION_ACCEPT_ANY_BEACON, /**< Set boolean true or false for accept beacon from other Pan-ID than configured. Default value should be false */
00060     PHY_EXTENSION_SET_TX_TIME,  /**< Net library sets transmission time based on global time stamp. Max. 65ms from setting to TX. If TX time is set to zero, it should be ignored.*/
00061     PHY_EXTENSION_READ_RX_TIME, /**< Read the time of last reception based on global micro seconds time stamp. */
00062     PHY_EXTENSION_READ_TX_FINNISH_TIME, /**< Read the time of last finished TX micro seconds based on global time stamp. */
00063     PHY_EXTENSION_DYNAMIC_RF_SUPPORTED, /**< Read status for support Radio driver support for set TX time, CCA and Timestamp read. Also PHY_LINK_CCA_PREPARE tx status must be supported also*/
00064     PHY_EXTENSION_GET_TIMESTAMP, /**<  Read 32-bit constant monotonic time stamp in us */
00065     PHY_EXTENSION_SET_CSMA_PARAMETERS, /**< CSMA parameter's are given by phy_csma_params_t structure remember type cast uint8_t pointer to structure type*/
00066     PHY_EXTENSION_GET_SYMBOLS_PER_SECOND, /**<  Read Symbols per seconds which will help to convert symbol time to real time  */
00067 } phy_extension_type_e;
00068 
00069 /** Address types */
00070 typedef enum {
00071     PHY_MAC_48BIT, /**< IPv4/IPv6/BLE link layer address for Ethernet. This is optional. */
00072     PHY_MAC_64BIT, /**< RF/PLC link layer address. */
00073     PHY_MAC_16BIT, /**< RF interface short address. */
00074     PHY_MAC_PANID, /**< RF interface 16-Bit PAN-ID. */
00075 } phy_address_type_e;
00076 
00077 /** PHY types */
00078 typedef enum phy_link_type_e {
00079     PHY_LINK_ETHERNET_TYPE,         /**< Standard IEEE 802 Ethernet. */
00080     PHY_LINK_15_4_2_4GHZ_TYPE,      /**< Standard 802.15.4 2.4GHz radio. */
00081     PHY_LINK_15_4_SUBGHZ_TYPE,      /**< Standard 802.15.4 subGHz radio 868 /915MHz. */
00082     PHY_LINK_TUN,                   /**< Tunnel interface for Linux TUN, RF network driver over serial bus or just basic application to application data flow. */
00083     PHY_LINK_SLIP,                  /**< Generic SLIP driver which just forward SLIP payload */
00084 } phy_link_type_e;
00085 
00086 /** Data layers */
00087 typedef enum data_protocol_e {
00088     LOCAL_SOCKET_DATA = 0,          /**< 6LoWPAN library local socket data. */
00089     INTERFACE_DATA = 1,             /**< 6LoWPAN library interface internal used protocol. */
00090     PHY_LAYER_PAYLOAD = 2,          /**< PHY layer data selection or handler. */
00091     IPV6_DATAGRAM = 3,              /**< IP layer data or TUN driver request data. */
00092     UNKNOWN_PROTOCOL = 4            /**< Non-supported protocol ID. */
00093 } data_protocol_e;
00094 
00095 /** Requested data layer */
00096 typedef enum driver_data_request_e {
00097     PHY_LAYER_PAYLOAD_DATA_FLOW,    /**< PHY layer data. */
00098     IPV6_DATAGRAMS_DATA_FLOW,       /**< IP layer data or TUN driver request data. */
00099 } driver_data_request_e;
00100 
00101 /** \brief Signal info types.
00102  *
00103  * Types of signal quality indication desired by various link protocols. Some are
00104  * really statistical, but a driver should ideally be able to create an estimate
00105  * based on its LQI/DBM numbers, for example to bootstrap a statistic calculation.
00106  */
00107 typedef enum phy_signal_info_type_e {
00108     PHY_SIGNAL_INFO_ETX,            /**< Expected transmissions, unsigned 16-bit fixed-point ETX*128 [1..512], for example Zigbee IP + RFC 6719. */
00109     PHY_SIGNAL_INFO_IDR,            /**< Inverse Delivery Ratio, unsigned 16-bit fixed-point IDR*32*256 [1..8], for example MLE draft 06. */
00110     PHY_SIGNAL_INFO_LINK_MARGIN,    /**< Link margin, unsigned 16-bit fixed-point dB*256, [0..255], for example Thread routing draft. */
00111 } phy_signal_info_type_e;
00112 
00113 /** Signal level info */
00114 typedef struct phy_signal_info_s {
00115     phy_signal_info_type_e type;    /**< Signal info type desired. */
00116     uint8_t lqi;                    /**< Quality passed to arm_net_phy_rx. */
00117     int8_t dbm;                     /**< Strength passed to arm_net_phy_rx. */
00118     uint16_t result;                /**< Resulting signal information. */
00119 } phy_signal_info_s;
00120 
00121 /** CSMA-CA parameters */
00122 typedef struct phy_csma_params {
00123     uint32_t backoff_time;           /**< CSMA Backoff us time before start CCA & TX. 0 should disable current backoff*/
00124     bool cca_enabled;                /**< True will affect CCA check false start TX direct after backoff */
00125 } phy_csma_params_t;
00126 
00127 /** PHY modulation scheme */
00128 typedef enum phy_modulation_e
00129 {
00130     M_OFDM,     ///< QFDM
00131     M_OQPSK,    ///< OQPSK
00132     M_BPSK,     ///< BPSK
00133     M_GFSK,     ///< GFSK
00134     M_UNDEFINED ///< UNDEFINED
00135 } phy_modulation_e;
00136 
00137 /** Channel page numbers */
00138 typedef enum
00139 {
00140     CHANNEL_PAGE_0 = 0,     ///< Page 0
00141     CHANNEL_PAGE_1 = 1,     ///< Page 1
00142     CHANNEL_PAGE_2 = 2,     ///< Page 2
00143     CHANNEL_PAGE_3 = 3,     ///< Page 3
00144     CHANNEL_PAGE_4 = 4,     ///< Page 4
00145     CHANNEL_PAGE_5 = 5,     ///< Page 5
00146     CHANNEL_PAGE_6 = 6,     ///< Page 6
00147     CHANNEL_PAGE_9 = 9,     ///< Page 9
00148     CHANNEL_PAGE_10 = 10    ///< Page 10
00149 } channel_page_e;
00150 
00151 /** Channel configuration */
00152 typedef struct phy_rf_channel_configuration_s
00153 {
00154     uint32_t channel_0_center_frequency;    ///< Center frequency
00155     uint32_t channel_spacing;               ///< Channel spacing
00156     uint32_t datarate;                      ///< Data rate
00157     uint16_t number_of_channels;            ///< Number of channels
00158     phy_modulation_e modulation;            ///< Modulation scheme
00159 } phy_rf_channel_configuration_s;
00160 
00161 /** Channel page configuration */
00162 typedef struct phy_device_channel_page_s
00163 {
00164     channel_page_e channel_page;            ///< Channel page
00165     const phy_rf_channel_configuration_s *rf_channel_configuration; ///< Pointer to channel configuration
00166 } phy_device_channel_page_s;
00167 
00168 /** Virtual data request */
00169 typedef struct virtual_data_req_s {
00170     uint16_t parameter_length;      /**< Length of user specified header. Can be zero. */
00171     uint8_t *parameters;            /**< Pointer to user specified header. Optional */
00172     uint16_t msduLength;            /**< MSDU Length */
00173     const uint8_t *msdu;            /**< MSDU */
00174 } virtual_data_req_t;
00175 
00176 /**
00177  * @brief arm_net_phy_rx RX callback set by upper layer. Called when data is received
00178  * @param data_ptr Data received
00179  * @param data_len Length of the data received
00180  * @param link_quality Link quality
00181  * @param dbm Power ratio in decibels
00182  * @param driver_id ID of driver which received data
00183  * @return 0 if success, error otherwise
00184  */
00185 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);
00186 
00187 /**
00188  * @brief arm_net_phy_tx_done TX done callback set by upper layer. Called when tx sent by upper layer has been handled
00189  * @param driver_id Id of the driver which handled TX request
00190  * @param tx_handle Handle of the TX
00191  * @param status Status code of the TX handling result
00192  * @param cca_retry Number of CCA retries done during handling
00193  * @param tx_retry Number of TX retries done during handling
00194  * @return 0 if success, error otherwise
00195  */
00196 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);
00197 
00198 /**
00199  * @brief arm_net_virtual_rx RX callback set by user of serial MAC. Called when virtual RF has received data.
00200  * @param data_ptr Data received
00201  * @param data_len Length of the data received
00202  * @param driver_id ID of driver which received data
00203  * @return 0 if success, error otherwise
00204  */
00205 typedef int8_t arm_net_virtual_rx_fn(const uint8_t *data_ptr, uint16_t data_len,int8_t driver_id);
00206 
00207 /**
00208  * @brief arm_net_virtual_tx TX callback set by serial MAC. Used to send data.
00209  * @param data_req Data to be sent
00210  * @param driver_id Id of the driver to be used.
00211  * @return 0 if success, error otherwise
00212  */
00213 typedef int8_t arm_net_virtual_tx_fn(const virtual_data_req_t *data_req,int8_t driver_id);
00214 
00215 /**
00216  * @brief arm_net_virtual_config Configuration receive callback set by upper layer. Used to receive internal configuration parameters.
00217  * @param driver_id Id of the driver to be used.
00218  * @param data Pointer to received configuration data.
00219  * @param length Length of the configuration data.
00220  * @return 0 if success, error otherwise
00221  */
00222 typedef int8_t arm_net_virtual_config_rx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
00223 
00224 /**
00225  * @brief arm_net_virtual_config Configuration send callback set by upper layer. Used to send internal configuration parameters.
00226  * @param driver_id Id of the driver to be used.
00227  * @param data Pointer to sent configuration data.
00228  * @param length Length of the configuration data.
00229  * @return 0 if success, error otherwise
00230  */
00231 typedef int8_t arm_net_virtual_config_tx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
00232 
00233 /**
00234  * @brief arm_net_virtual_confirmation Confirmation receive callback set by upper layer. Used to receive MLME confirmation data.
00235  * @param driver_id Id of the driver to be used.
00236  * @param data Pointer to received confirmation data.
00237  * @param length Length of the confirmation data.
00238  * @return 0 if success, error otherwise
00239  */
00240 typedef int8_t arm_net_virtual_confirmation_rx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
00241 
00242 /** Device driver structure */
00243 typedef struct phy_device_driver_s
00244 {
00245     phy_link_type_e link_type;                                      /**< Define driver types. */
00246     driver_data_request_e data_request_layer;                       /**< Define interface data OUT protocol. */
00247     uint8_t *PHY_MAC;                                               /**< Pointer to 64-bit or 48-bit MAC address. */
00248     uint16_t phy_MTU;                                               /**< Define MAX PHY layer MTU size. */
00249     char *driver_description;                                       /**< Short driver platform description. Needs to end with zero. */
00250     uint8_t phy_tail_length;                                        /**< Define PHY driver needed TAIL Length. */
00251     uint8_t phy_header_length;                                      /**< Define PHY driver needed header length before PDU. */
00252     int8_t (*state_control)(phy_interface_state_e, uint8_t);        /**< Function pointer for control PHY driver state. */
00253     int8_t (*tx)(uint8_t *, uint16_t, uint8_t, data_protocol_e);    /**< Function pointer for PHY driver write operation. */
00254     int8_t (*address_write)(phy_address_type_e , uint8_t *);        /**< Function pointer for PHY driver address write. */
00255     int8_t (*extension)(phy_extension_type_e, uint8_t *);           /**< Function pointer for PHY driver extension control. */
00256     const phy_device_channel_page_s *phy_channel_pages;             /**< Pointer to channel page list */
00257 
00258     //Upper layer callbacks, set with arm_net_phy_register();
00259     arm_net_phy_rx_fn *phy_rx_cb;                                   /**< PHY RX callback. Initialized by \ref arm_net_phy_register(). */
00260     arm_net_phy_tx_done_fn *phy_tx_done_cb;                         /**< Transmission done callback. Initialized by \ref arm_net_phy_register(). */
00261     //Virtual upper data rx
00262     arm_net_virtual_rx_fn *arm_net_virtual_rx_cb;                   /**< Virtual RX callback. Initialized by \ref arm_net_phy_register(). */
00263     arm_net_virtual_tx_fn *arm_net_virtual_tx_cb;                   /**< Virtual TX callback. Initialized by \ref arm_net_phy_register(). */
00264     arm_net_virtual_config_rx_fn *virtual_config_rx_cb;             /**< Virtual config receive callback. Initialized by \ref arm_net_phy_register(). */
00265     arm_net_virtual_config_tx_fn *virtual_config_tx_cb;             /**< Virtual config send callback. Initialized by \ref arm_net_phy_register(). */
00266     arm_net_virtual_confirmation_rx_fn *virtual_confirmation_rx_cb; /**< Virtual confirmation receive callback. Initialized by \ref arm_net_phy_register(). */
00267     uint16_t tunnel_type; /**< Tun driver type. */
00268 } phy_device_driver_s;
00269 
00270 
00271 /**
00272  * \brief This function registers the device driver to stack.
00273  *
00274  * \param phy_driver A pointer to device driver structure.
00275  *
00276  * \return >= 0 Device driver ID.
00277  * \return < 0 Means register fail.
00278  *
00279  */
00280 extern int8_t arm_net_phy_register(phy_device_driver_s *phy_driver);
00281 
00282 
00283 /**
00284  * \brief Set driver mac64 address.
00285  *
00286  * \param MAC A pointer to new mac64 address which is copied to old one.
00287  * \param  id driver id
00288  *
00289  * \return >= 0 SET OK.
00290  * \return < 0 Means register fail.
00291  *
00292  */
00293 extern int8_t arm_net_phy_mac64_set(uint8_t *MAC, int8_t id);
00294 
00295 /**
00296  * \brief Get driver mac64 address.
00297  *
00298  * \param  id driver id
00299  *
00300  * \return > 0 Return pointer to MAC.
00301  * \return NULL.
00302  *
00303  */
00304 extern uint8_t *arm_net_phy_mac64_get(int8_t id);
00305 
00306 /**
00307  * \brief Get driver link type.
00308  *
00309  * \param  id driver id
00310  *
00311  * \return driver link type.
00312  *
00313  */
00314 extern int arm_net_phy_rf_type(int8_t id);
00315 
00316 /**
00317  * \brief Get driver link type MTU size.
00318  *
00319  * \param  id driver id
00320  *
00321  * \return size of MTU.
00322  *
00323  */
00324 extern uint16_t arm_net_phy_mtu_size(int8_t id);
00325 
00326 /**
00327  * \brief Unregister the driver from storage.
00328  *
00329  * \param driver_id driver id
00330  *
00331  */
00332 extern void arm_net_phy_unregister(int8_t driver_id);
00333 
00334 #ifdef __cplusplus
00335 }
00336 #endif
00337 #endif /* ARM_HAL_PHY_H_ */