[453] | 1 | /* Copyright (c) 2014, Nordic Semiconductor ASA
|
---|
| 2 | *
|
---|
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
| 4 | * of this software and associated documentation files (the "Software"), to deal
|
---|
| 5 | * in the Software without restriction, including without limitation the rights
|
---|
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
| 7 | * copies of the Software, and to permit persons to whom the Software is
|
---|
| 8 | * furnished to do so, subject to the following conditions:
|
---|
| 9 | *
|
---|
| 10 | * The above copyright notice and this permission notice shall be included in all
|
---|
| 11 | * copies or substantial portions of the Software.
|
---|
| 12 | *
|
---|
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
---|
| 19 | * SOFTWARE.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #ifndef LIB_ACI_H__
|
---|
| 23 | #define LIB_ACI_H__
|
---|
| 24 |
|
---|
| 25 | /** @file
|
---|
| 26 | * @brief ACI library
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup lib_aci
|
---|
| 30 | @{
|
---|
| 31 | @brief Library for the logical part of the Application Controller Interface (ACI)
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | #include "hal_platform.h"
|
---|
| 35 | #include "hal_aci_tl.h"
|
---|
| 36 | #include "aci_queue.h"
|
---|
| 37 | #include "aci.h"
|
---|
| 38 | #include "aci_cmds.h"
|
---|
| 39 | #include "aci_evts.h"
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | #define EVT_CMD_RESPONSE_MIN_LENGTH 3
|
---|
| 43 |
|
---|
| 44 | #define PIPES_ARRAY_SIZE ((ACI_DEVICE_MAX_PIPES + 7)/8)
|
---|
| 45 |
|
---|
| 46 | /* Same size as a hal_aci_data_t */
|
---|
| 47 | typedef struct {
|
---|
| 48 | uint8_t debug_byte;
|
---|
| 49 | aci_evt_t evt;
|
---|
| 50 | } _aci_packed_ hal_aci_evt_t;
|
---|
| 51 |
|
---|
| 52 | ACI_ASSERT_SIZE(hal_aci_evt_t, 34);
|
---|
| 53 |
|
---|
| 54 | typedef struct
|
---|
| 55 | {
|
---|
| 56 | uint8_t location; /**< enum aci_pipe_store_t */
|
---|
| 57 | aci_pipe_type_t pipe_type;
|
---|
| 58 | } services_pipe_type_mapping_t;
|
---|
| 59 |
|
---|
| 60 | typedef struct aci_setup_info_t
|
---|
| 61 | {
|
---|
| 62 | services_pipe_type_mapping_t *services_pipe_type_mapping;
|
---|
| 63 | uint8_t number_of_pipes;
|
---|
| 64 | hal_aci_data_t *setup_msgs;
|
---|
| 65 | uint8_t num_setup_msgs;
|
---|
| 66 | } aci_setup_info_t;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | // aci_struct that will contain
|
---|
| 71 | // total initial credits
|
---|
| 72 | // current credit
|
---|
| 73 | // current state of the aci (setup/standby/active/sleep)
|
---|
| 74 | // open remote pipe pending
|
---|
| 75 | // close remote pipe pending
|
---|
| 76 | // Current pipe available bitmap
|
---|
| 77 | // Current pipe closed bitmap
|
---|
| 78 | // Current connection interval, slave latency and link supervision timeout
|
---|
| 79 | // Current State of the the GATT client (Service Discovery status)
|
---|
| 80 | // Relationship of bond to peer address
|
---|
| 81 | typedef struct aci_state_t
|
---|
| 82 | {
|
---|
| 83 | aci_pins_t aci_pins; /* Pins on the MCU used to connect to the nRF8001 */
|
---|
| 84 | aci_setup_info_t aci_setup_info; /* Data structures that are created from nRFgo Studio */
|
---|
| 85 | uint8_t bonded; /* ( aci_bond_status_code_t ) Is the nRF8001 bonded to a peer device */
|
---|
| 86 | uint8_t data_credit_total; /* Total data credit available for the specific version of the nRF8001, total equals available when a link is established */
|
---|
| 87 | aci_device_operation_mode_t device_state; /* Operating mode of the nRF8001 */
|
---|
| 88 |
|
---|
| 89 | /* */
|
---|
| 90 |
|
---|
| 91 | /* Start : Variables that are valid only when in a connection */
|
---|
| 92 | uint8_t data_credit_available; /* Available data credits at a specific point of time, ACI_EVT_DATA_CREDIT updates the available credits */
|
---|
| 93 |
|
---|
| 94 | uint16_t connection_interval; /* Multiply by 1.25 to get the connection interval in milliseconds*/
|
---|
| 95 | uint16_t slave_latency; /* Number of consecutive connection intervals that the nRF8001 is not required to transmit. Use this to save power */
|
---|
| 96 | uint16_t supervision_timeout; /* Multiply by 10 to get the supervision timeout in milliseconds */
|
---|
| 97 |
|
---|
| 98 | uint8_t pipes_open_bitmap[PIPES_ARRAY_SIZE]; /* Bitmap -> pipes are open and can be used for sending data over the air */
|
---|
| 99 | uint8_t pipes_closed_bitmap[PIPES_ARRAY_SIZE]; /* Bitmap -> pipes are closed and cannot be used for sending data over the air */
|
---|
| 100 | bool confirmation_pending; /* Attribute protocol Handle Value confirmation is pending for a Handle Value Indication
|
---|
| 101 | (ACK is pending for a TX_ACK pipe) on local GATT Server*/
|
---|
| 102 | /* End : Variables that are valid only when in a connection */
|
---|
| 103 |
|
---|
| 104 | } aci_state_t;
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | #define DISCONNECT_REASON_CX_TIMEOUT 0x08
|
---|
| 109 | #define DISCONNECT_REASON_CX_CLOSED_BY_PEER_DEVICE 0x13
|
---|
| 110 | #define DISCONNECT_REASON_POWER_LOSS 0x14
|
---|
| 111 | #define DISCONNECT_REASON_CX_CLOSED_BY_LOCAL_DEVICE 0x16
|
---|
| 112 | #define DISCONNECT_REASON_ADVERTISER_TIMEOUT 0x50
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | /** @name Functions for library management */
|
---|
| 116 | //@{
|
---|
| 117 |
|
---|
| 118 | /** @brief Function to enable printing of all ACI commands sent and ACI events received
|
---|
| 119 | * @details This function shall be used to enable or disable the debug printing.
|
---|
| 120 | Debug printing is disabled by default.
|
---|
| 121 | */
|
---|
| 122 | void lib_aci_debug_print(bool enable);
|
---|
| 123 |
|
---|
| 124 | /** @brief Function to pin reset the nRF8001
|
---|
| 125 | * @details Pin resets the nRF8001 also handles differences between development boards
|
---|
| 126 | */
|
---|
| 127 | void lib_aci_pin_reset(void);
|
---|
| 128 |
|
---|
| 129 | /** @brief Initialization function.
|
---|
| 130 | * @details This function shall be used to initialize/reset ACI Library and also Resets the
|
---|
| 131 | * nRF8001 by togging the reset pin of the nRF8001. This function will reset
|
---|
| 132 | * all the variables locally used by ACI library to their respective default values.
|
---|
| 133 | * @param bool True if the data was successfully queued for sending,
|
---|
| 134 | * false if there is no more space to store messages to send.
|
---|
| 135 | */
|
---|
| 136 | void lib_aci_init(aci_state_t *aci_stat, bool debug);
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | /** @brief Gets the number of currently available ACI credits.
|
---|
| 140 | * @return Number of ACI credits.
|
---|
| 141 | */
|
---|
| 142 | uint8_t lib_aci_get_nb_available_credits(aci_state_t *aci_stat);
|
---|
| 143 |
|
---|
| 144 | /** @brief Gets the connection interval in milliseconds.
|
---|
| 145 | * @return Connection interval in milliseconds.
|
---|
| 146 | */
|
---|
| 147 | uint16_t lib_aci_get_cx_interval_ms(aci_state_t *aci_stat);
|
---|
| 148 |
|
---|
| 149 | /** @brief Gets the connection interval in multiple of 1.25 ms.
|
---|
| 150 | * @return Connection interval in multiple of 1.25 ms.
|
---|
| 151 | */
|
---|
| 152 | uint16_t lib_aci_get_cx_interval(aci_state_t *aci_stat);
|
---|
| 153 |
|
---|
| 154 | /** @brief Gets the current slave latency.
|
---|
| 155 | * @return Current slave latency.
|
---|
| 156 | */
|
---|
| 157 | uint16_t lib_aci_get_slave_latency(aci_state_t *aci_stat);
|
---|
| 158 |
|
---|
| 159 | /** @brief Checks if a given pipe is available.
|
---|
| 160 | * @param pipe Pipe to check.
|
---|
| 161 | * @return True if the pipe is available, otherwise false.
|
---|
| 162 | */
|
---|
| 163 | bool lib_aci_is_pipe_available(aci_state_t *aci_stat, uint8_t pipe);
|
---|
| 164 |
|
---|
| 165 | /** @brief Checks if a given pipe is closed.
|
---|
| 166 | * @param pipe Pipe to check.
|
---|
| 167 | * @return True if the pipe is closed, otherwise false.
|
---|
| 168 | */
|
---|
| 169 | bool lib_aci_is_pipe_closed(aci_state_t *aci_stat, uint8_t pipe);
|
---|
| 170 |
|
---|
| 171 | /** @brief Checks if the discovery operation is finished.
|
---|
| 172 | * @return True if the discovery is finished.
|
---|
| 173 | */
|
---|
| 174 | bool lib_aci_is_discovery_finished(aci_state_t *aci_stat);
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | //@}
|
---|
| 179 |
|
---|
| 180 | /** @name ACI Commands available in all modes */
|
---|
| 181 | //@{
|
---|
| 182 |
|
---|
| 183 | /** @brief Sets the radio in sleep mode.
|
---|
| 184 | * @details The function sends a @c sleep command to the radio.
|
---|
| 185 | * If the radio is advertising or connected, it sends back an error, then use lib_aci_radio_reset
|
---|
| 186 | * if advertising or disconnect if in a connection.
|
---|
| 187 | * @return True if the transaction is successfully initiated.
|
---|
| 188 | */
|
---|
| 189 | bool lib_aci_sleep(void);
|
---|
| 190 |
|
---|
| 191 | /** @brief Resets the radio.
|
---|
| 192 | * @details The function sends a @c BasebandReset command to the radio.
|
---|
| 193 | * @return True if the transaction is successfully initiated.
|
---|
| 194 | */
|
---|
| 195 | bool lib_aci_radio_reset(void);
|
---|
| 196 |
|
---|
| 197 | /** @brief Radio starts directed advertising to bonded device.
|
---|
| 198 | * @details The function sends a @c DirectedConnect command to the radio.
|
---|
| 199 | * @return True if the transaction is successfully initiated.
|
---|
| 200 | */
|
---|
| 201 | bool lib_aci_direct_connect(void);
|
---|
| 202 |
|
---|
| 203 | /** @brief Gets the radio's version.
|
---|
| 204 | * @details This function sends a @c GetDeviceVersion command.
|
---|
| 205 | * @return True if the transaction is successfully initiated.
|
---|
| 206 | */
|
---|
| 207 | bool lib_aci_device_version(void);
|
---|
| 208 |
|
---|
| 209 | /** @brief Gets the device address.
|
---|
| 210 | * @details This function sends a @c GetDeviceAddress command.
|
---|
| 211 | * @return True if the transaction is successfully initiated.
|
---|
| 212 | */
|
---|
| 213 | bool lib_aci_get_address(void);
|
---|
| 214 |
|
---|
| 215 | /** @brief Gets the temperature.
|
---|
| 216 | * @details This function sends a @c GetTemperature command. lib_aci
|
---|
| 217 | * calls the @ref lib_aci_transaction_finished_hook() function when the temperature is received.
|
---|
| 218 | * @return True if the transaction is successfully initiated.
|
---|
| 219 | */
|
---|
| 220 | bool lib_aci_get_temperature(void);
|
---|
| 221 |
|
---|
| 222 | /** @brief Gets the battery level.
|
---|
| 223 | * @details This function sends a @c GetBatteryLevel command.
|
---|
| 224 | * @return True if the transaction is successfully initiated.
|
---|
| 225 | */
|
---|
| 226 | bool lib_aci_get_battery_level(void);
|
---|
| 227 |
|
---|
| 228 | //@}
|
---|
| 229 |
|
---|
| 230 | /** @name ACI commands available in Sleep mode */
|
---|
| 231 | //@{
|
---|
| 232 |
|
---|
| 233 | /** @brief Wakes up the radio.
|
---|
| 234 | * @details This function sends a @c Wakeup command to wake up the radio from
|
---|
| 235 | * sleep mode. When woken up the radio sends a @c DeviceStartedEvent and
|
---|
| 236 | * a @c CommandResponseEvent.
|
---|
| 237 | * @return True if the transaction is successfully initiated.
|
---|
| 238 | */
|
---|
| 239 | bool lib_aci_wakeup(void);
|
---|
| 240 |
|
---|
| 241 | //@}
|
---|
| 242 |
|
---|
| 243 | /** @name ACI commands available in Active mode */
|
---|
| 244 | //@{
|
---|
| 245 |
|
---|
| 246 | /** @brief Sets the radio in test mode.
|
---|
| 247 | * @details This function sends a @c Test command to the radio. There are two
|
---|
| 248 | * Test modes available:
|
---|
| 249 | * - UART: DTM commands are received over UART.
|
---|
| 250 | * - ACI: DTM commands are received over ACI.
|
---|
| 251 | * The same command is used to exit the test mode When receiving
|
---|
| 252 | * a @c DeviceStartedEvent the radio has entered the new mode.
|
---|
| 253 | * @param enter_exit_test_mode Enter a Test mode, or exit Test mode.
|
---|
| 254 | * @return True if the transaction is successfully initiated.
|
---|
| 255 | */
|
---|
| 256 | bool lib_aci_test(aci_test_mode_change_t enter_exit_test_mode);
|
---|
| 257 |
|
---|
| 258 | /** @brief Sets the radio's TX power.
|
---|
| 259 | * @details This function sends a @c SetTxPower command.
|
---|
| 260 | * @param tx_power TX power to be used by the radio.
|
---|
| 261 | * @return True if the transaction is successfully initiated.
|
---|
| 262 | */
|
---|
| 263 | bool lib_aci_set_tx_power(aci_device_output_power_t tx_power);
|
---|
| 264 |
|
---|
| 265 | /** @brief Tries to connect to a peer device.
|
---|
| 266 | * @details This function sends a @c Connect command to the radio.
|
---|
| 267 | * @param run_timeout Maximum advertising time in seconds (0 means infinite).
|
---|
| 268 | * @param adv_interval Advertising interval (in multiple of 0.625 ms).
|
---|
| 269 | * @return True if the transaction is successfully initiated.
|
---|
| 270 | */
|
---|
| 271 | bool lib_aci_connect(uint16_t run_timeout, uint16_t adv_interval);
|
---|
| 272 |
|
---|
| 273 | /** @brief Tries to bond with a peer device.
|
---|
| 274 | * @details This function sends a @c Bond command to the radio.
|
---|
| 275 | * @param run_timeout Maximum advertising time in seconds (0 means infinite).
|
---|
| 276 | * @param adv_interval Advertising interval (in multiple of 0.625 ms).
|
---|
| 277 | * @return True if the transaction is successfully initiated.
|
---|
| 278 | */
|
---|
| 279 | bool lib_aci_bond(uint16_t run_timeout, uint16_t adv_interval);
|
---|
| 280 |
|
---|
| 281 | /** @brief Disconnects from peer device.
|
---|
| 282 | * @details This function sends a @c Disconnect command to the radio.
|
---|
| 283 | * @param reason Reason for disconnecting.
|
---|
| 284 | * @return True if the transaction is successfully initiated.
|
---|
| 285 | */
|
---|
| 286 | bool lib_aci_disconnect(aci_state_t *aci_stat, aci_disconnect_reason_t reason);
|
---|
| 287 |
|
---|
| 288 | /**@brief Sets Local Data.
|
---|
| 289 | * @details
|
---|
| 290 | * This command updates the value of the characteristic value or the characteristic descriptor stored locally on the device.
|
---|
| 291 | * Can be called for all types of pipes as long as the data is stored locally.
|
---|
| 292 | * @param ACI state structure
|
---|
| 293 | * @param pipe Pipe number on which the data should be set.
|
---|
| 294 | * @param value Pointer to the data to set.
|
---|
| 295 | * @param size Size of the data to set.
|
---|
| 296 | * @return True if the transaction is successfully initiated.
|
---|
| 297 | */
|
---|
| 298 | bool lib_aci_set_local_data(aci_state_t *aci_stat, uint8_t pipe, uint8_t *value, uint8_t size);
|
---|
| 299 |
|
---|
| 300 | /** @brief Sends Broadcast message to the radio.
|
---|
| 301 | * @details The Broadcast message starts advertisement procedure
|
---|
| 302 | * using the given interval with the intention of broadcasting data to a peer device.
|
---|
| 303 | * @param timeout Time, in seconds, to advertise before exiting to standby mode (0 means infinite).
|
---|
| 304 | * Valid values: 0 to 16383.
|
---|
| 305 | * @param adv_interval Advertising interval (in multiple of 0.625 ms).
|
---|
| 306 | * Valid values: 160 to 16384 (which corresponds to an interval from 100 ms to 10.24 s).
|
---|
| 307 | * @return True if the broadcast message is sent successfully to the radio.
|
---|
| 308 | */
|
---|
| 309 | bool lib_aci_broadcast(const uint16_t timeout, const uint16_t adv_interval);
|
---|
| 310 |
|
---|
| 311 | /** @name Open Advertising Pipes. */
|
---|
| 312 |
|
---|
| 313 | /** @brief Sends a command to the radio to set the input pipe to be placed in Advertisement Service Data.
|
---|
| 314 | * @details This function sends a command to the radio that places the pipe in
|
---|
| 315 | * advertisement service data. To start advertising service data, call this function before
|
---|
| 316 | * Connecting, Broadcasting or Bonding to peer. The data that should be sent in the advertisement packets
|
---|
| 317 | * must be set using the @c lib_aci_set_local_data function. This function can be called during
|
---|
| 318 | * advertising to enable/disable broadcast pipes.
|
---|
| 319 | * @param pipe The pipe that has to be placed in advertising service data.
|
---|
| 320 | * @return True if the Open Adv Pipe message is sent successfully to the radio.
|
---|
| 321 | */
|
---|
| 322 | bool lib_aci_open_adv_pipe(const uint8_t pipe);
|
---|
| 323 |
|
---|
| 324 |
|
---|
| 325 | /** @name Open Advertising Pipes */
|
---|
| 326 |
|
---|
| 327 | /** @brief Sends a command to the radio to set the pipes to be placed in Advertisement Service Data.
|
---|
| 328 | * @details This function will send a command to the radio that will set the pipes to be placed in
|
---|
| 329 | * advertisement Service Data. To start advertising service data, this function should be called before
|
---|
| 330 | * Connecting, Broadcasting or Bonding to peer. This function can be called during
|
---|
| 331 | * advertising to enable/disable broadcast pipes. Use this as an alternative to @ref lib_aci_open_adv_pipe
|
---|
| 332 | * to avoid multiple function calls for placing multiple pipes in the adv data.
|
---|
| 333 | * @param adv_service_data_pipes Pipe bitmap, where '1' indicates that the corresponding
|
---|
| 334 | * Valid Values: 0000000000000000 to FEFFFFFFFFFFFF7F (See the ACI Pipe Status Evt bitmap in the nRF8001 datasheet
|
---|
| 335 | * TX_BROADCAST pipe data is to be placed in Advertising Service Data fields
|
---|
| 336 | * @return true if the Open Adv Pipe message was sent successfully to the radio.
|
---|
| 337 | */
|
---|
| 338 | bool lib_aci_open_adv_pipes(const uint8_t * const adv_service_data_pipes);
|
---|
| 339 |
|
---|
| 340 |
|
---|
| 341 | //@}
|
---|
| 342 |
|
---|
| 343 | /** @name ACI commands available in Connected mode */
|
---|
| 344 | //@{
|
---|
| 345 |
|
---|
| 346 |
|
---|
| 347 | /** @brief Sets a given application latency.
|
---|
| 348 | * @details This function sends a @c setApplicationLatency command.
|
---|
| 349 | * @return True if the transaction is successfully initiated.
|
---|
| 350 | */
|
---|
| 351 | bool lib_aci_set_app_latency(uint16_t latency, aci_app_latency_mode_t latency_mode);
|
---|
| 352 |
|
---|
| 353 | /** @brief Opens a remote pipe.
|
---|
| 354 | * @details This function sends an @c OpenRemotePipe command.
|
---|
| 355 | * @param pipe Number of the pipe to open.
|
---|
| 356 | * @return True if the transaction is successfully initiated.
|
---|
| 357 | */
|
---|
| 358 | bool lib_aci_open_remote_pipe(aci_state_t *aci_stat, uint8_t pipe);
|
---|
| 359 |
|
---|
| 360 | /** @brief Closes a remote pipe.
|
---|
| 361 | * @details This function sends an @c CloseRemotePipe command.
|
---|
| 362 | * @param pipe Pipe number to close.
|
---|
| 363 | * @return True if the transaction is successfully initiated.
|
---|
| 364 | */
|
---|
| 365 | bool lib_aci_close_remote_pipe(aci_state_t *aci_stat, uint8_t pipe);
|
---|
| 366 |
|
---|
| 367 | /** @brief Sends data on a given pipe.
|
---|
| 368 | * @details This function sends a @c SendData command with application data to
|
---|
| 369 | * the radio. This function memorizes credit use, and checks that
|
---|
| 370 | * enough credits are available.
|
---|
| 371 | * @param pipe Pipe number on which the data should be sent.
|
---|
| 372 | * @param value Pointer to the data to send.
|
---|
| 373 | * @param size Size of the data to send.
|
---|
| 374 | * @return True if the transaction is successfully initiated.
|
---|
| 375 | */
|
---|
| 376 | bool lib_aci_send_data(uint8_t pipe, uint8_t *value, uint8_t size);
|
---|
| 377 |
|
---|
| 378 | /** @brief Requests data from a given pipe.
|
---|
| 379 | * @details This function sends a @c RequestData command to the radio. This
|
---|
| 380 | * function memorizes credit uses, and check that enough credits are available.
|
---|
| 381 | * After this command, the radio sends back either a @c DataReceivedEvent
|
---|
| 382 | * or a @c PipeErrorEvent.
|
---|
| 383 | * @param pipe Pipe number on which the data is requested.
|
---|
| 384 | * @return True if the transaction is successfully initiated.
|
---|
| 385 | */
|
---|
| 386 | bool lib_aci_request_data(aci_state_t *aci_stat, uint8_t pipe);
|
---|
| 387 |
|
---|
| 388 | /** @brief Sends a L2CAP change connection parameters request.
|
---|
| 389 | * @details This function sends a @c ChangeTiming command to the radio. This command triggers a "L2CAP change connection parameters" request
|
---|
| 390 | * to the master. If the master rejects or accepts but doesn't change the connection parameters within
|
---|
| 391 | * 30 seconds, a timing event with the unchanged connection parameters is sent by the radio.
|
---|
| 392 | * If the request is accepted and the master changes connection parameters, a timing event with
|
---|
| 393 | * the new connection parameters is sent by the radio.
|
---|
| 394 | * If the master doesn't reply to the request within 60 seconds, the radio disconnects.
|
---|
| 395 | * @param minimun_cx_interval Minimum connection interval requested, in multiple of 1.25 ms.
|
---|
| 396 | * @param maximum_cx_interval Maximum connection interval requested, in multiple of 1.25 ms.
|
---|
| 397 | * @param slave_latency requested slave latency.
|
---|
| 398 | * @param timeout requested slave timeout, in multiple of 10 ms.
|
---|
| 399 | * @return True if the transaction is successfully initiated.
|
---|
| 400 | */
|
---|
| 401 | bool lib_aci_change_timing(uint16_t minimun_cx_interval, uint16_t maximum_cx_interval, uint16_t slave_latency, uint16_t timeout);
|
---|
| 402 |
|
---|
| 403 | /** @brief Sends a L2CAP change connection parameters request with the connection predefined preffered connection parameters.
|
---|
| 404 | * @details This function sends a @c ChangeTiming command to the radio. This command triggers a "L2CAP change connection parameters" request
|
---|
| 405 | * to the master. If the master rejects or accepts but doesn't change the connection parameters within
|
---|
| 406 | * 30 seconds, a timing event with the unchanged connection parameters is sent by the radio.
|
---|
| 407 | * If the request is accepted and the master changes connection parameters, a timing event with
|
---|
| 408 | * the new connection parameters is sent by the radio.
|
---|
| 409 | * If the master doesn't reply to the request within 60 seconds, the radio disconnects.
|
---|
| 410 | * The timing parameters used are the Timing parameters in the GAP settings in the nRFgo Studio.
|
---|
| 411 | * The Timing parameters as stored as the GAP Preferred Peripheral Connection Parameters.
|
---|
| 412 | * @return True if the transaction is successfully initiated.
|
---|
| 413 | */
|
---|
| 414 | bool lib_aci_change_timing_GAP_PPCP(void);
|
---|
| 415 |
|
---|
| 416 | /** @brief Sends acknowledgement message to peer.
|
---|
| 417 | * @details This function sends @c SendDataAck command to radio. The radio is expected
|
---|
| 418 | * to send either Handle Value Confirmation or Write response depending
|
---|
| 419 | * on whether the data is stored remotely or locally.
|
---|
| 420 | * @param pipe Pipe number for which the acknowledgement is to be sent.
|
---|
| 421 | * @return True if the ack was sent successfully. False otherwise.
|
---|
| 422 | */
|
---|
| 423 | bool lib_aci_send_ack(aci_state_t *aci_stat, const uint8_t pipe);
|
---|
| 424 |
|
---|
| 425 | /** @brief Sends negative acknowledgement message to peer.
|
---|
| 426 | * @details This function sends @c SendDataNack command to radio. The radio is expected
|
---|
| 427 | * to send Error Response to the peer.
|
---|
| 428 | * @param pipe Pipe number for which the nack is to be sent.
|
---|
| 429 | * @param error_code Error code to be sent in the NACk.
|
---|
| 430 | * @return True if the nack was sent successfully. False otherwise.
|
---|
| 431 | */
|
---|
| 432 | bool lib_aci_send_nack(aci_state_t *aci_stat, const uint8_t pipe, const uint8_t error_code);
|
---|
| 433 |
|
---|
| 434 | /** @brief Sends ReadDynamicData command to the host.
|
---|
| 435 | * @details This function sends @c ReadDynamicData command to host. The host is expected
|
---|
| 436 | * to send @c CommandResponse back with the dynamic data. The application is expected to
|
---|
| 437 | * call this function in a loop until all the dynamic data is read out from the host.
|
---|
| 438 | * As long as there is dynamic data to be read from the host, the command response
|
---|
| 439 | * for this message has its status field set to ACI_STATUS_TRANSACTION_CONTINUE (0x01).
|
---|
| 440 | * The application may chose to store this read out data in a non-volatile memory location
|
---|
| 441 | * and later chose to write it back using the function lib_aci_write_dynamic_data.
|
---|
| 442 | * @return True if the command was sent successfully through the ACI. False otherwise.
|
---|
| 443 | */
|
---|
| 444 | bool lib_aci_read_dynamic_data(void);
|
---|
| 445 |
|
---|
| 446 | /** @brief Sends WriteDynamicData command to the host.
|
---|
| 447 | * @details This function sends @c WriteDynamicData command to host. The host is expected
|
---|
| 448 | * to send @c CommandResponse with the status of this operation. As long as the status field
|
---|
| 449 | * in the @c CommandResponse is ACI_STATUS_TRANSACTION_CONTINUE (0x01), the hosts expects
|
---|
| 450 | * more dynamic data to be written. This function should ideally be called in a cycle,
|
---|
| 451 | * until all the stored dynamic data is sent to the host. This function should be
|
---|
| 452 | * called with the dynamic data obtained from the response to a @c ReadDynamicData
|
---|
| 453 | * (see @c lib_aci_read_dynamic_data) command.
|
---|
| 454 | * @param sequence_number Sequence number of the dynamic data to be sent.
|
---|
| 455 | * @param dynamic_data Pointer to the dynamic data.
|
---|
| 456 | * @param length Length of the dynamic data.
|
---|
| 457 | * @return True if the command was sent successfully through the ACI. False otherwise.
|
---|
| 458 | */
|
---|
| 459 | bool lib_aci_write_dynamic_data(uint8_t sequence_number, uint8_t* dynamic_data, uint8_t length);
|
---|
| 460 | //@}
|
---|
| 461 |
|
---|
| 462 | /** @name ACI commands available while connected in Bond mode */
|
---|
| 463 | //@{
|
---|
| 464 |
|
---|
| 465 | /** @brief Sends a SMP Security Request.
|
---|
| 466 | * @details This function send a @c BondRequest command to the radio.
|
---|
| 467 | * This command triggers a SMP Security Request to the master. If the
|
---|
| 468 | * master rejects with a pairing failed or if the bond timer expires the connection is closed.
|
---|
| 469 | * @return True if the transaction is successfully initiated.
|
---|
| 470 | */
|
---|
| 471 | bool lib_aci_bond_request(void);
|
---|
| 472 |
|
---|
| 473 | /** @brief Set the key requested by the 8001.
|
---|
| 474 | * @details This function sends an @c SetKey command to the radio.
|
---|
| 475 | * @param key_rsp_type Type of key.
|
---|
| 476 | * @param key Pointer to the key to set.
|
---|
| 477 | * @param len Length of the key.
|
---|
| 478 | * @return True if the transaction is successfully initiated.
|
---|
| 479 | */
|
---|
| 480 | bool lib_aci_set_key(aci_key_type_t key_rsp_type, uint8_t *key, uint8_t len);
|
---|
| 481 |
|
---|
| 482 | //@}
|
---|
| 483 |
|
---|
| 484 |
|
---|
| 485 |
|
---|
| 486 | /** @name ACI commands available in Test mode */
|
---|
| 487 | //@{
|
---|
| 488 |
|
---|
| 489 | /** @brief Sends an echo message
|
---|
| 490 | * @details This function sends an @c Echo command to the radio. lib_aci
|
---|
| 491 | * places the Echp ACI command in the ACI command queue
|
---|
| 492 | * @param message_size Length of the data to send.
|
---|
| 493 | * @param message_data Pointer to the data to send.
|
---|
| 494 | * @return True if the transaction is successfully initiated.
|
---|
| 495 | */
|
---|
| 496 | bool lib_aci_echo_msg(uint8_t message_size, uint8_t *message_data);
|
---|
| 497 |
|
---|
| 498 | /** @brief Sends an DTM command
|
---|
| 499 | * @details This function sends an @c DTM command to the radio.
|
---|
| 500 | * @param dtm_command_msbyte Most significant byte of the DTM command.
|
---|
| 501 | * @param dtm_command_lsbyte Least significant byte of the DTM command.
|
---|
| 502 | * @return True if the transaction is successfully initiated.
|
---|
| 503 | */
|
---|
| 504 | bool lib_aci_dtm_command(uint8_t dtm_command_msbyte, uint8_t dtm_command_lsbyte);
|
---|
| 505 |
|
---|
| 506 | /** @brief Gets an ACI event from the ACI Event Queue
|
---|
| 507 | * @details This function gets an ACI event from the ACI event queue.
|
---|
| 508 | * The queue is updated by the SPI driver for the ACI running in the interrupt context
|
---|
| 509 | * @param aci_stat pointer to the state of the ACI.
|
---|
| 510 | * @param p_aci_data pointer to the ACI Event. The ACI Event received will be copied into this pointer.
|
---|
| 511 | * @return True if an ACI Event was copied to the pointer.
|
---|
| 512 | */
|
---|
| 513 | bool lib_aci_event_get(aci_state_t *aci_stat, hal_aci_evt_t * aci_evt);
|
---|
| 514 |
|
---|
| 515 | /** @brief Peeks an ACI event from the ACI Event Queue
|
---|
| 516 | * @details This function peeks at the top event in the ACI event queue.
|
---|
| 517 | * In polling mode, this function will query the nRF8001 for pending events, but unlike
|
---|
| 518 | * lib_aci_event_get() it will not dequeue the event from the local queue, but will instead
|
---|
| 519 | * only peek at it.
|
---|
| 520 | * @return True if an ACI Event was copied to the pointer.
|
---|
| 521 | */
|
---|
| 522 | bool lib_aci_event_peek(hal_aci_evt_t *p_aci_evt_data);
|
---|
| 523 |
|
---|
| 524 | /** @brief Flushes the events in the ACI command queues and ACI Event queue
|
---|
| 525 | *
|
---|
| 526 | */
|
---|
| 527 | void lib_aci_flush(void);
|
---|
| 528 |
|
---|
| 529 | /** @brief Return full status of the Event queue
|
---|
| 530 | * @details
|
---|
| 531 | *
|
---|
| 532 | */
|
---|
| 533 | bool lib_aci_event_queue_full(void);
|
---|
| 534 |
|
---|
| 535 | /** @brief Return empty status of the Event queue
|
---|
| 536 | * @details
|
---|
| 537 | *
|
---|
| 538 | */
|
---|
| 539 | bool lib_aci_event_queue_empty(void);
|
---|
| 540 |
|
---|
| 541 | /** @brief Return full status of Command queue
|
---|
| 542 | * @details
|
---|
| 543 | *
|
---|
| 544 | */
|
---|
| 545 | bool lib_aci_command_queue_full(void);
|
---|
| 546 |
|
---|
| 547 | /** @brief Return empty status of Command queue
|
---|
| 548 | * @details
|
---|
| 549 | *
|
---|
| 550 | */
|
---|
| 551 | bool lib_aci_command_queue_empty(void);
|
---|
| 552 |
|
---|
| 553 | //@}
|
---|
| 554 |
|
---|
| 555 | /** @} */
|
---|
| 556 |
|
---|
| 557 | #endif /* LIB_ACI_H__ */
|
---|