BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fhss_api.h Source File

fhss_api.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2016-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 fhss_api.h
00020  * \brief
00021  */
00022 
00023 #ifndef FHSS_API_H
00024 #define FHSS_API_H
00025 
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 typedef struct fhss_api fhss_api_t;
00032 typedef struct fhss_callback fhss_callback_t;
00033 
00034 /**
00035  * @brief FHSS frame types.
00036  */
00037 #define FHSS_SYNCH_FRAME            0   /**< FHSS synchronization frame */
00038 #define FHSS_SYNCH_REQUEST_FRAME    1   /**< FHSS synchronization request frame */
00039 #define FHSS_DATA_FRAME             2   /**< FHSS data frame */
00040 
00041 /**
00042  * @brief FHSS synchronization info length.
00043  */
00044 #define FHSS_SYNCH_INFO_LENGTH      21
00045 
00046 /**
00047  * @brief FHSS states.
00048  */
00049 typedef enum
00050 {
00051     FHSS_UNSYNCHRONIZED,
00052     FHSS_SYNCHRONIZED,
00053 } fhss_states;
00054 
00055 /**
00056  * @brief FHSS is broadcast channel. Checks if current channel is broadcast channel.
00057  * @param api FHSS instance.
00058  * @return false if unicast channel, true if broadcast channel.
00059  */
00060 typedef bool fhss_is_broadcast_channel(const fhss_api_t *api);
00061 
00062 /**
00063  * @brief FHSS queue check. Checks if broadcast queue must be used instead of unicast queue.
00064  * @param api FHSS instance.
00065  * @param is_broadcast_addr Destination address type of packet (true if broadcast address).
00066  * @param frame_type Frame type of packet (Frames types are defined by FHSS api).
00067  * @return false if unicast queue, true if broadcast queue.
00068  */
00069 typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
00070 
00071 /**
00072  * @brief FHSS TX handle. Set destination channel and write synchronization info.
00073  * @param api FHSS instance.
00074  * @param is_broadcast_addr Destination address type of packet (true if broadcast address).
00075  * @param destination_address Destination MAC address.
00076  * @param frame_type Frame type of packet (Frames types are defined by FHSS api).
00077  * @param synch_info Pointer to where FHSS synchronization info is written (if synch frame).
00078  * @param frame_length MSDU length of the frame.
00079  * @param phy_header_length PHY header length.
00080  * @param phy_tail_length PHY tail length.
00081  * @return  0 Success.
00082  * @return -1 Transmission of the packet is currently not allowed, try again.
00083  * @return -2 Invalid api.
00084  * @return -3 Broadcast packet on Unicast channel (not allowed), push packet back to queue.
00085  * @return -4 Synchronization info missing.
00086  */
00087 typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint8_t *synch_info, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
00088 
00089 /**
00090  * @brief Check TX permission.
00091  * @param api FHSS instance.
00092  * @param is_broadcast_addr Destination address type of packet (true if broadcast address).
00093  * @param handle Handle of the data request.
00094  * @param frame_type Frame type of packet (Frames types are defined by FHSS api).
00095  * @param frame_length MSDU length of the frame.
00096  * @param phy_header_length PHY header length.
00097  * @param phy_tail_length PHY tail length.
00098  * @return false if transmission is denied, true if transmission is allowed.
00099  */
00100 typedef bool fhss_check_tx_conditions(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
00101 
00102 /**
00103  * @brief Notification of received FHSS synch or synch request frame.
00104  * @param api FHSS instance.
00105  * @param pan_id Source PAN id of the received frame (FHSS_SYNCH_FRAME only).
00106  * @param source_address Source address of the received frame (FHSS_SYNCH_FRAME only).
00107  * @param timestamp Timestamp of reception (FHSS_SYNCH_FRAME only).
00108  * @param synch_info Pointer to synchronization info (FHSS_SYNCH_FRAME only).
00109  * @param frame_type Frame type of packet (Frames types are defined by FHSS api).
00110  */
00111 typedef void fhss_receive_frame(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
00112 
00113 /**
00114  * @brief Data TX done callback.
00115  * @param api FHSS instance.
00116  * @param waiting_ack MAC is waiting Acknowledgement for this frame.
00117  * @param tx_completed TX completed (Ack received or no more retries left (if unicast frame)).
00118  * @param handle Handle of the data request.
00119  */
00120 typedef void fhss_data_tx_done(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
00121 
00122 /**
00123  * @brief Data TX or CCA failed callback.
00124  * @param api FHSS instance.
00125  * @param handle Handle of the data request.
00126  * @param frame_type Frame type of packet (Frames types are defined by FHSS api).
00127  * @return true if frame has to be queued for retransmission, false otherwise.
00128  */
00129 typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_type);
00130 
00131 /**
00132  * @brief Change synchronization state.
00133  * @param api FHSS instance.
00134  * @param fhss_state FHSS state (FHSS states are defined by FHSS api).
00135  * @param pan_id PAN id of the network FHSS synchronizes with.
00136  */
00137 typedef void fhss_synch_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
00138 
00139 /**
00140  * @brief Read timestamp.
00141  * @param api FHSS instance.
00142  * @return Timestamp to be written in received frame.
00143  */
00144 typedef uint32_t fhss_read_timestamp(const fhss_api_t *api);
00145 
00146 /**
00147  * @brief Get retransmission period. FHSS uses different retry periods for different destinations.
00148  * @param api FHSS instance.
00149  * @param destination_address Destination MAC address.
00150  * @param phy_mtu PHY MTU size.
00151  * @return Retransmission period.
00152  */
00153 typedef uint16_t fhss_get_retry_period(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
00154 
00155 /**
00156  * @brief Initialize MAC functions.
00157  * @param api FHSS instance.
00158  * @param callbacks MAC functions to be called from FHSS.
00159  * @return  0 Success.
00160  * @return -1 Invalid parameters.
00161  */
00162 typedef int fhss_init_callbacks(const fhss_api_t *api, fhss_callback_t *callbacks);
00163 
00164 /**
00165  * \brief Struct fhss_api defines interface between software MAC and FHSS.
00166  * Application creates fhss_api_s object by calling FHSS creator function.
00167  * Then object is passed to software MAC which then initialises it's own callback functions.
00168  */
00169 struct fhss_api {
00170     fhss_is_broadcast_channel *is_broadcast_channel;    /**< FHSS is broadcast channel. */
00171     fhss_use_broadcast_queue *use_broadcast_queue;      /**< FHSS queue check. */
00172     fhss_tx_handle *tx_handle;                          /**< FHSS TX handle. */
00173     fhss_check_tx_conditions *check_tx_conditions;      /**< Check TX permission. */
00174     fhss_receive_frame *receive_frame;                  /**< Notification of received FHSS synch or synch request frame. */
00175     fhss_data_tx_done *data_tx_done;                    /**< Data TX done callback. */
00176     fhss_data_tx_fail *data_tx_fail;                    /**< Data TX or CCA failed callback. */
00177     fhss_synch_state_set *synch_state_set;              /**< Change synchronization state. */
00178     fhss_read_timestamp *read_timestamp;                /**< Read timestamp. */
00179     fhss_get_retry_period *get_retry_period;            /**< Get retransmission period. */
00180     fhss_init_callbacks *init_callbacks;                /**< Initialize MAC functions. */
00181 };
00182 
00183 /**
00184  * @brief Read MAC TX queue size.
00185  * @param fhss_api FHSS instance.
00186  * @param broadcast_queue Queue type to be read (true if broadcast queue).
00187  * @return Queue size (number of frames queued).
00188  */
00189 typedef uint16_t mac_read_tx_queue_size(const fhss_api_t *fhss_api, bool broadcast_queue);
00190 
00191 /**
00192  * @brief Read MAC address.
00193  * @param fhss_api FHSS instance.
00194  * @param mac_address MAC address pointer.
00195  * @return  0 Success.
00196  * @return -1 Invalid parameters.
00197  */
00198 typedef int mac_read_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address);
00199 
00200 /**
00201  * @brief Read PHY datarate.
00202  * @param fhss_api FHSS instance.
00203  * @return PHY datarate.
00204  */
00205 typedef uint32_t mac_read_datarate(const fhss_api_t *fhss_api);
00206 
00207 /**
00208  * @brief Change channel.
00209  * @param fhss_api FHSS instance.
00210  * @param channel_number Channel number.
00211  * @return  0 Success.
00212  * @return -1 Invalid parameters.
00213  */
00214 typedef int mac_change_channel(const fhss_api_t *fhss_api, uint8_t channel_number);
00215 
00216 /**
00217  * @brief Send FHSS frame.
00218  * @param fhss_api FHSS instance.
00219  * @param frame_type Frame type of packet (Frames types are defined by FHSS api).
00220  * @return  0 Success.
00221  * @return -1 Invalid parameters.
00222  */
00223 typedef int mac_send_fhss_frame(const fhss_api_t *fhss_api, int frame_type);
00224 
00225 /**
00226  * @brief Send notification when FHSS synchronization is lost.
00227  * @param fhss_api FHSS instance.
00228  * @return  0 Success.
00229  * @return -1 Invalid parameters.
00230  */
00231 typedef int mac_synch_lost_notification(const fhss_api_t *fhss_api);
00232 
00233 /**
00234  * @brief Poll TX queue.
00235  * @param fhss_api FHSS instance.
00236  * @return  0 Success.
00237  * @return -1 Invalid parameters.
00238  */
00239 typedef int mac_tx_poll(const fhss_api_t *fhss_api);
00240 
00241 /**
00242  * @brief Broadcast channel notification from FHSS.
00243  * @param fhss_api FHSS instance.
00244  * @param broadcast_time Remaining broadcast time.
00245  * @return  0 Success.
00246  * @return -1 Invalid parameters.
00247  */
00248 typedef int mac_broadcast_notify(const fhss_api_t *fhss_api, uint32_t broadcast_time);
00249 
00250 /**
00251  * @brief Read coordinator MAC address.
00252  * @param fhss_api FHSS instance.
00253  * @param mac_address MAC address pointer.
00254  * @return  0 Success.
00255  * @return -1 Invalid parameters.
00256  */
00257 typedef int mac_read_coordinator_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address);
00258 
00259 /**
00260  * \brief Struct fhss_callback defines functions that software MAC needs to implement.
00261  * Function pointers are passed to FHSS using fhss_init_callbacks function.
00262  */
00263 struct fhss_callback {
00264     mac_read_tx_queue_size *read_tx_queue_size;                 /**< Read MAC TX queue size. */
00265     mac_read_mac_address *read_mac_address;                     /**< Read MAC address. */
00266     mac_read_datarate *read_datarate;                           /**< Read PHY datarate. */
00267     mac_change_channel *change_channel;                         /**< Change channel. */
00268     mac_send_fhss_frame *send_fhss_frame;                       /**< Send FHSS frame. */
00269     mac_synch_lost_notification *synch_lost_notification;       /**< Send notification when FHSS synchronization is lost. */
00270     mac_tx_poll *tx_poll;                                       /**< Poll TX queue. */
00271     mac_broadcast_notify *broadcast_notify;                     /**< Broadcast channel notification from FHSS. */
00272     mac_read_coordinator_mac_address *read_coord_mac_address;   /**< Read coordinator MAC address. */
00273 };
00274 
00275 #ifdef __cplusplus
00276 }
00277 #endif
00278 
00279 #endif // FHSS_API_H