added debugging
Fork of BLE_nRF8001 by
BLE_nRF8001/utility/lib_aci.cpp@2:7805a5595aab, 2014-11-10 (annotated)
- Committer:
- jn80842
- Date:
- Mon Nov 10 01:24:23 2014 +0000
- Revision:
- 2:7805a5595aab
- Parent:
- 0:075ea2812998
just added debugging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RedBearLab | 0:075ea2812998 | 1 | /* Copyright (c) 2014, Nordic Semiconductor ASA |
RedBearLab | 0:075ea2812998 | 2 | * |
RedBearLab | 0:075ea2812998 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
RedBearLab | 0:075ea2812998 | 4 | * of this software and associated documentation files (the "Software"), to deal |
RedBearLab | 0:075ea2812998 | 5 | * in the Software without restriction, including without limitation the rights |
RedBearLab | 0:075ea2812998 | 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
RedBearLab | 0:075ea2812998 | 7 | * copies of the Software, and to permit persons to whom the Software is |
RedBearLab | 0:075ea2812998 | 8 | * furnished to do so, subject to the following conditions: |
RedBearLab | 0:075ea2812998 | 9 | * |
RedBearLab | 0:075ea2812998 | 10 | * The above copyright notice and this permission notice shall be included in all |
RedBearLab | 0:075ea2812998 | 11 | * copies or substantial portions of the Software. |
RedBearLab | 0:075ea2812998 | 12 | * |
RedBearLab | 0:075ea2812998 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
RedBearLab | 0:075ea2812998 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
RedBearLab | 0:075ea2812998 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
RedBearLab | 0:075ea2812998 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
RedBearLab | 0:075ea2812998 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
RedBearLab | 0:075ea2812998 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
RedBearLab | 0:075ea2812998 | 19 | * SOFTWARE. |
RedBearLab | 0:075ea2812998 | 20 | */ |
RedBearLab | 0:075ea2812998 | 21 | |
RedBearLab | 0:075ea2812998 | 22 | /** @file |
RedBearLab | 0:075ea2812998 | 23 | @brief Implementation of the ACI library. |
RedBearLab | 0:075ea2812998 | 24 | */ |
RedBearLab | 0:075ea2812998 | 25 | |
RedBearLab | 0:075ea2812998 | 26 | #include "hal_platform.h" |
RedBearLab | 0:075ea2812998 | 27 | #include "aci.h" |
RedBearLab | 0:075ea2812998 | 28 | #include "aci_cmds.h" |
RedBearLab | 0:075ea2812998 | 29 | #include "aci_evts.h" |
RedBearLab | 0:075ea2812998 | 30 | #include "aci_protocol_defines.h" |
RedBearLab | 0:075ea2812998 | 31 | #include "acilib_defs.h" |
RedBearLab | 0:075ea2812998 | 32 | #include "acilib_if.h" |
RedBearLab | 0:075ea2812998 | 33 | #include "hal_aci_tl.h" |
RedBearLab | 0:075ea2812998 | 34 | #include "aci_queue.h" |
RedBearLab | 0:075ea2812998 | 35 | #include "lib_aci.h" |
RedBearLab | 0:075ea2812998 | 36 | |
RedBearLab | 0:075ea2812998 | 37 | |
RedBearLab | 0:075ea2812998 | 38 | #define LIB_ACI_DEFAULT_CREDIT_NUMBER 1 |
RedBearLab | 0:075ea2812998 | 39 | |
RedBearLab | 0:075ea2812998 | 40 | /* |
RedBearLab | 0:075ea2812998 | 41 | Global additionally used used in aci_setup |
RedBearLab | 0:075ea2812998 | 42 | */ |
RedBearLab | 0:075ea2812998 | 43 | hal_aci_data_t msg_to_send; |
RedBearLab | 0:075ea2812998 | 44 | |
RedBearLab | 0:075ea2812998 | 45 | |
RedBearLab | 0:075ea2812998 | 46 | static services_pipe_type_mapping_t * p_services_pipe_type_map; |
RedBearLab | 0:075ea2812998 | 47 | static hal_aci_data_t * p_setup_msgs; |
RedBearLab | 0:075ea2812998 | 48 | |
RedBearLab | 0:075ea2812998 | 49 | |
RedBearLab | 0:075ea2812998 | 50 | |
RedBearLab | 0:075ea2812998 | 51 | |
RedBearLab | 0:075ea2812998 | 52 | static bool is_request_operation_pending; |
RedBearLab | 0:075ea2812998 | 53 | static bool is_indicate_operation_pending; |
RedBearLab | 0:075ea2812998 | 54 | static bool is_open_remote_pipe_pending; |
RedBearLab | 0:075ea2812998 | 55 | static bool is_close_remote_pipe_pending; |
RedBearLab | 0:075ea2812998 | 56 | |
RedBearLab | 0:075ea2812998 | 57 | static uint8_t request_operation_pipe = 0; |
RedBearLab | 0:075ea2812998 | 58 | static uint8_t indicate_operation_pipe = 0; |
RedBearLab | 0:075ea2812998 | 59 | |
RedBearLab | 0:075ea2812998 | 60 | |
RedBearLab | 0:075ea2812998 | 61 | // The following structure (aci_cmd_params_open_adv_pipe) will be used to store the complete command |
RedBearLab | 0:075ea2812998 | 62 | // including the pipes to be opened. |
RedBearLab | 0:075ea2812998 | 63 | static aci_cmd_params_open_adv_pipe_t aci_cmd_params_open_adv_pipe; |
RedBearLab | 0:075ea2812998 | 64 | |
RedBearLab | 0:075ea2812998 | 65 | |
RedBearLab | 0:075ea2812998 | 66 | |
RedBearLab | 0:075ea2812998 | 67 | extern aci_queue_t aci_rx_q; |
RedBearLab | 0:075ea2812998 | 68 | extern aci_queue_t aci_tx_q; |
RedBearLab | 0:075ea2812998 | 69 | |
RedBearLab | 0:075ea2812998 | 70 | bool lib_aci_is_pipe_available(aci_state_t *aci_stat, uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 71 | { |
RedBearLab | 0:075ea2812998 | 72 | uint8_t byte_idx; |
RedBearLab | 0:075ea2812998 | 73 | |
RedBearLab | 0:075ea2812998 | 74 | byte_idx = pipe / 8; |
RedBearLab | 0:075ea2812998 | 75 | if (aci_stat->pipes_open_bitmap[byte_idx] & (0x01 << (pipe % 8))) |
RedBearLab | 0:075ea2812998 | 76 | { |
RedBearLab | 0:075ea2812998 | 77 | return(true); |
RedBearLab | 0:075ea2812998 | 78 | } |
RedBearLab | 0:075ea2812998 | 79 | return(false); |
RedBearLab | 0:075ea2812998 | 80 | } |
RedBearLab | 0:075ea2812998 | 81 | |
RedBearLab | 0:075ea2812998 | 82 | |
RedBearLab | 0:075ea2812998 | 83 | bool lib_aci_is_pipe_closed(aci_state_t *aci_stat, uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 84 | { |
RedBearLab | 0:075ea2812998 | 85 | uint8_t byte_idx; |
RedBearLab | 0:075ea2812998 | 86 | |
RedBearLab | 0:075ea2812998 | 87 | byte_idx = pipe / 8; |
RedBearLab | 0:075ea2812998 | 88 | if (aci_stat->pipes_closed_bitmap[byte_idx] & (0x01 << (pipe % 8))) |
RedBearLab | 0:075ea2812998 | 89 | { |
RedBearLab | 0:075ea2812998 | 90 | return(true); |
RedBearLab | 0:075ea2812998 | 91 | } |
RedBearLab | 0:075ea2812998 | 92 | return(false); |
RedBearLab | 0:075ea2812998 | 93 | } |
RedBearLab | 0:075ea2812998 | 94 | |
RedBearLab | 0:075ea2812998 | 95 | |
RedBearLab | 0:075ea2812998 | 96 | bool lib_aci_is_discovery_finished(aci_state_t *aci_stat) |
RedBearLab | 0:075ea2812998 | 97 | { |
RedBearLab | 0:075ea2812998 | 98 | return(aci_stat->pipes_open_bitmap[0]&0x01); |
RedBearLab | 0:075ea2812998 | 99 | } |
RedBearLab | 0:075ea2812998 | 100 | |
RedBearLab | 0:075ea2812998 | 101 | void lib_aci_board_init(aci_state_t *aci_stat) |
RedBearLab | 0:075ea2812998 | 102 | { |
RedBearLab | 0:075ea2812998 | 103 | hal_aci_evt_t *aci_data = NULL; |
RedBearLab | 0:075ea2812998 | 104 | aci_data = (hal_aci_evt_t *)&msg_to_send; |
RedBearLab | 0:075ea2812998 | 105 | |
RedBearLab | 0:075ea2812998 | 106 | if (REDBEARLAB_SHIELD_V1_1 == aci_stat->aci_pins.board_name) |
RedBearLab | 0:075ea2812998 | 107 | { |
RedBearLab | 0:075ea2812998 | 108 | /* |
RedBearLab | 0:075ea2812998 | 109 | The Bluetooth low energy Arduino shield v1.1 requires about 100ms to reset. |
RedBearLab | 0:075ea2812998 | 110 | This is not required for the nRF2740, nRF2741 modules |
RedBearLab | 0:075ea2812998 | 111 | */ |
RedBearLab | 0:075ea2812998 | 112 | delay(100); |
RedBearLab | 0:075ea2812998 | 113 | |
RedBearLab | 0:075ea2812998 | 114 | /* |
RedBearLab | 0:075ea2812998 | 115 | Send the soft reset command to the nRF8001 to get the nRF8001 to a known state. |
RedBearLab | 0:075ea2812998 | 116 | */ |
RedBearLab | 0:075ea2812998 | 117 | lib_aci_radio_reset(); |
RedBearLab | 0:075ea2812998 | 118 | |
RedBearLab | 0:075ea2812998 | 119 | while (1) |
RedBearLab | 0:075ea2812998 | 120 | { |
RedBearLab | 0:075ea2812998 | 121 | /*Wait for the command response of the radio reset command. |
RedBearLab | 0:075ea2812998 | 122 | as the nRF8001 will be in either SETUP or STANDBY after the ACI Reset Radio is processed |
RedBearLab | 0:075ea2812998 | 123 | */ |
RedBearLab | 0:075ea2812998 | 124 | |
RedBearLab | 0:075ea2812998 | 125 | |
RedBearLab | 0:075ea2812998 | 126 | if (true == lib_aci_event_get(aci_stat, aci_data)) |
RedBearLab | 0:075ea2812998 | 127 | { |
RedBearLab | 0:075ea2812998 | 128 | aci_evt_t * aci_evt; |
RedBearLab | 0:075ea2812998 | 129 | aci_evt = &(aci_data->evt); |
RedBearLab | 0:075ea2812998 | 130 | |
RedBearLab | 0:075ea2812998 | 131 | if (ACI_EVT_CMD_RSP == aci_evt->evt_opcode) |
RedBearLab | 0:075ea2812998 | 132 | { |
RedBearLab | 0:075ea2812998 | 133 | if (ACI_STATUS_ERROR_DEVICE_STATE_INVALID == aci_evt->params.cmd_rsp.cmd_status) //in SETUP |
RedBearLab | 0:075ea2812998 | 134 | { |
RedBearLab | 0:075ea2812998 | 135 | //Inject a Device Started Event Setup to the ACI Event Queue |
RedBearLab | 0:075ea2812998 | 136 | msg_to_send.buffer[0] = 4; //Length |
RedBearLab | 0:075ea2812998 | 137 | msg_to_send.buffer[1] = 0x81; //Device Started Event |
RedBearLab | 0:075ea2812998 | 138 | msg_to_send.buffer[2] = 0x02; //Setup |
RedBearLab | 0:075ea2812998 | 139 | msg_to_send.buffer[3] = 0; //Hardware Error -> None |
RedBearLab | 0:075ea2812998 | 140 | msg_to_send.buffer[4] = 2; //Data Credit Available |
RedBearLab | 0:075ea2812998 | 141 | aci_queue_enqueue(&aci_rx_q, &msg_to_send); |
RedBearLab | 0:075ea2812998 | 142 | } |
RedBearLab | 0:075ea2812998 | 143 | else if (ACI_STATUS_SUCCESS == aci_evt->params.cmd_rsp.cmd_status) //We are now in STANDBY |
RedBearLab | 0:075ea2812998 | 144 | { |
RedBearLab | 0:075ea2812998 | 145 | //Inject a Device Started Event Standby to the ACI Event Queue |
RedBearLab | 0:075ea2812998 | 146 | msg_to_send.buffer[0] = 4; //Length |
RedBearLab | 0:075ea2812998 | 147 | msg_to_send.buffer[1] = 0x81; //Device Started Event |
RedBearLab | 0:075ea2812998 | 148 | msg_to_send.buffer[2] = 0x03; //Standby |
RedBearLab | 0:075ea2812998 | 149 | msg_to_send.buffer[3] = 0; //Hardware Error -> None |
RedBearLab | 0:075ea2812998 | 150 | msg_to_send.buffer[4] = 2; //Data Credit Available |
RedBearLab | 0:075ea2812998 | 151 | aci_queue_enqueue(&aci_rx_q, &msg_to_send); |
RedBearLab | 0:075ea2812998 | 152 | } |
RedBearLab | 0:075ea2812998 | 153 | else if (ACI_STATUS_ERROR_CMD_UNKNOWN == aci_evt->params.cmd_rsp.cmd_status) //We are now in TEST |
RedBearLab | 0:075ea2812998 | 154 | { |
RedBearLab | 0:075ea2812998 | 155 | //Inject a Device Started Event Test to the ACI Event Queue |
RedBearLab | 0:075ea2812998 | 156 | msg_to_send.buffer[0] = 4; //Length |
RedBearLab | 0:075ea2812998 | 157 | msg_to_send.buffer[1] = 0x81; //Device Started Event |
RedBearLab | 0:075ea2812998 | 158 | msg_to_send.buffer[2] = 0x01; //Test |
RedBearLab | 0:075ea2812998 | 159 | msg_to_send.buffer[3] = 0; //Hardware Error -> None |
RedBearLab | 0:075ea2812998 | 160 | msg_to_send.buffer[4] = 0; //Data Credit Available |
RedBearLab | 0:075ea2812998 | 161 | aci_queue_enqueue(&aci_rx_q, &msg_to_send); |
RedBearLab | 0:075ea2812998 | 162 | } |
RedBearLab | 0:075ea2812998 | 163 | |
RedBearLab | 0:075ea2812998 | 164 | //Break out of the while loop |
RedBearLab | 0:075ea2812998 | 165 | break; |
RedBearLab | 0:075ea2812998 | 166 | } |
RedBearLab | 0:075ea2812998 | 167 | else |
RedBearLab | 0:075ea2812998 | 168 | { |
RedBearLab | 0:075ea2812998 | 169 | //Serial.println(F("Discard any other ACI Events")); |
RedBearLab | 0:075ea2812998 | 170 | } |
RedBearLab | 0:075ea2812998 | 171 | |
RedBearLab | 0:075ea2812998 | 172 | } |
RedBearLab | 0:075ea2812998 | 173 | } |
RedBearLab | 0:075ea2812998 | 174 | } |
RedBearLab | 0:075ea2812998 | 175 | } |
RedBearLab | 0:075ea2812998 | 176 | |
RedBearLab | 0:075ea2812998 | 177 | |
RedBearLab | 0:075ea2812998 | 178 | void lib_aci_init(aci_state_t *aci_stat, bool debug) |
RedBearLab | 0:075ea2812998 | 179 | { |
RedBearLab | 0:075ea2812998 | 180 | uint8_t i; |
RedBearLab | 0:075ea2812998 | 181 | |
RedBearLab | 0:075ea2812998 | 182 | for (i = 0; i < PIPES_ARRAY_SIZE; i++) |
RedBearLab | 0:075ea2812998 | 183 | { |
RedBearLab | 0:075ea2812998 | 184 | aci_stat->pipes_open_bitmap[i] = 0; |
RedBearLab | 0:075ea2812998 | 185 | aci_stat->pipes_closed_bitmap[i] = 0; |
RedBearLab | 0:075ea2812998 | 186 | aci_cmd_params_open_adv_pipe.pipes[i] = 0; |
RedBearLab | 0:075ea2812998 | 187 | } |
RedBearLab | 0:075ea2812998 | 188 | |
RedBearLab | 0:075ea2812998 | 189 | |
RedBearLab | 0:075ea2812998 | 190 | |
RedBearLab | 0:075ea2812998 | 191 | |
RedBearLab | 0:075ea2812998 | 192 | is_request_operation_pending = false; |
RedBearLab | 0:075ea2812998 | 193 | is_indicate_operation_pending = false; |
RedBearLab | 0:075ea2812998 | 194 | is_open_remote_pipe_pending = false; |
RedBearLab | 0:075ea2812998 | 195 | is_close_remote_pipe_pending = false; |
RedBearLab | 0:075ea2812998 | 196 | |
RedBearLab | 0:075ea2812998 | 197 | |
RedBearLab | 0:075ea2812998 | 198 | |
RedBearLab | 0:075ea2812998 | 199 | |
RedBearLab | 0:075ea2812998 | 200 | |
RedBearLab | 0:075ea2812998 | 201 | request_operation_pipe = 0; |
RedBearLab | 0:075ea2812998 | 202 | indicate_operation_pipe = 0; |
RedBearLab | 0:075ea2812998 | 203 | |
RedBearLab | 0:075ea2812998 | 204 | |
RedBearLab | 0:075ea2812998 | 205 | |
RedBearLab | 0:075ea2812998 | 206 | p_services_pipe_type_map = aci_stat->aci_setup_info.services_pipe_type_mapping; |
RedBearLab | 0:075ea2812998 | 207 | |
RedBearLab | 0:075ea2812998 | 208 | p_setup_msgs = aci_stat->aci_setup_info.setup_msgs; |
RedBearLab | 0:075ea2812998 | 209 | |
RedBearLab | 0:075ea2812998 | 210 | |
RedBearLab | 0:075ea2812998 | 211 | hal_aci_tl_init(&aci_stat->aci_pins, debug); |
RedBearLab | 0:075ea2812998 | 212 | |
RedBearLab | 0:075ea2812998 | 213 | lib_aci_board_init(aci_stat); |
RedBearLab | 0:075ea2812998 | 214 | } |
RedBearLab | 0:075ea2812998 | 215 | |
RedBearLab | 0:075ea2812998 | 216 | |
RedBearLab | 0:075ea2812998 | 217 | uint8_t lib_aci_get_nb_available_credits(aci_state_t *aci_stat) |
RedBearLab | 0:075ea2812998 | 218 | { |
RedBearLab | 0:075ea2812998 | 219 | return aci_stat->data_credit_available; |
RedBearLab | 0:075ea2812998 | 220 | } |
RedBearLab | 0:075ea2812998 | 221 | |
RedBearLab | 0:075ea2812998 | 222 | uint16_t lib_aci_get_cx_interval_ms(aci_state_t *aci_stat) |
RedBearLab | 0:075ea2812998 | 223 | { |
RedBearLab | 0:075ea2812998 | 224 | uint32_t cx_rf_interval_ms_32bits; |
RedBearLab | 0:075ea2812998 | 225 | uint16_t cx_rf_interval_ms; |
RedBearLab | 0:075ea2812998 | 226 | |
RedBearLab | 0:075ea2812998 | 227 | cx_rf_interval_ms_32bits = aci_stat->connection_interval; |
RedBearLab | 0:075ea2812998 | 228 | cx_rf_interval_ms_32bits *= 125; // the connection interval is given in multiples of 0.125 milliseconds |
RedBearLab | 0:075ea2812998 | 229 | cx_rf_interval_ms = cx_rf_interval_ms_32bits / 100; |
RedBearLab | 0:075ea2812998 | 230 | |
RedBearLab | 0:075ea2812998 | 231 | return cx_rf_interval_ms; |
RedBearLab | 0:075ea2812998 | 232 | } |
RedBearLab | 0:075ea2812998 | 233 | |
RedBearLab | 0:075ea2812998 | 234 | |
RedBearLab | 0:075ea2812998 | 235 | uint16_t lib_aci_get_cx_interval(aci_state_t *aci_stat) |
RedBearLab | 0:075ea2812998 | 236 | { |
RedBearLab | 0:075ea2812998 | 237 | return aci_stat->connection_interval; |
RedBearLab | 0:075ea2812998 | 238 | } |
RedBearLab | 0:075ea2812998 | 239 | |
RedBearLab | 0:075ea2812998 | 240 | |
RedBearLab | 0:075ea2812998 | 241 | uint16_t lib_aci_get_slave_latency(aci_state_t *aci_stat) |
RedBearLab | 0:075ea2812998 | 242 | { |
RedBearLab | 0:075ea2812998 | 243 | return aci_stat->slave_latency; |
RedBearLab | 0:075ea2812998 | 244 | } |
RedBearLab | 0:075ea2812998 | 245 | |
RedBearLab | 0:075ea2812998 | 246 | |
RedBearLab | 0:075ea2812998 | 247 | bool lib_aci_set_app_latency(uint16_t latency, aci_app_latency_mode_t latency_mode) |
RedBearLab | 0:075ea2812998 | 248 | { |
RedBearLab | 0:075ea2812998 | 249 | aci_cmd_params_set_app_latency_t aci_set_app_latency; |
RedBearLab | 0:075ea2812998 | 250 | |
RedBearLab | 0:075ea2812998 | 251 | aci_set_app_latency.mode = latency_mode; |
RedBearLab | 0:075ea2812998 | 252 | aci_set_app_latency.latency = latency; |
RedBearLab | 0:075ea2812998 | 253 | acil_encode_cmd_set_app_latency(&(msg_to_send.buffer[0]), &aci_set_app_latency); |
RedBearLab | 0:075ea2812998 | 254 | |
RedBearLab | 0:075ea2812998 | 255 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 256 | } |
RedBearLab | 0:075ea2812998 | 257 | |
RedBearLab | 0:075ea2812998 | 258 | |
RedBearLab | 0:075ea2812998 | 259 | bool lib_aci_test(aci_test_mode_change_t enter_exit_test_mode) |
RedBearLab | 0:075ea2812998 | 260 | { |
RedBearLab | 0:075ea2812998 | 261 | aci_cmd_params_test_t aci_cmd_params_test; |
RedBearLab | 0:075ea2812998 | 262 | aci_cmd_params_test.test_mode_change = enter_exit_test_mode; |
RedBearLab | 0:075ea2812998 | 263 | acil_encode_cmd_set_test_mode(&(msg_to_send.buffer[0]), &aci_cmd_params_test); |
RedBearLab | 0:075ea2812998 | 264 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 265 | } |
RedBearLab | 0:075ea2812998 | 266 | |
RedBearLab | 0:075ea2812998 | 267 | |
RedBearLab | 0:075ea2812998 | 268 | bool lib_aci_sleep() |
RedBearLab | 0:075ea2812998 | 269 | { |
RedBearLab | 0:075ea2812998 | 270 | acil_encode_cmd_sleep(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 271 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 272 | } |
RedBearLab | 0:075ea2812998 | 273 | |
RedBearLab | 0:075ea2812998 | 274 | |
RedBearLab | 0:075ea2812998 | 275 | bool lib_aci_radio_reset() |
RedBearLab | 0:075ea2812998 | 276 | { |
RedBearLab | 0:075ea2812998 | 277 | acil_encode_baseband_reset(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 278 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 279 | } |
RedBearLab | 0:075ea2812998 | 280 | |
RedBearLab | 0:075ea2812998 | 281 | |
RedBearLab | 0:075ea2812998 | 282 | bool lib_aci_direct_connect() |
RedBearLab | 0:075ea2812998 | 283 | { |
RedBearLab | 0:075ea2812998 | 284 | acil_encode_direct_connect(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 285 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 286 | } |
RedBearLab | 0:075ea2812998 | 287 | |
RedBearLab | 0:075ea2812998 | 288 | |
RedBearLab | 0:075ea2812998 | 289 | bool lib_aci_device_version() |
RedBearLab | 0:075ea2812998 | 290 | { |
RedBearLab | 0:075ea2812998 | 291 | acil_encode_cmd_get_device_version(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 292 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 293 | } |
RedBearLab | 0:075ea2812998 | 294 | |
RedBearLab | 0:075ea2812998 | 295 | |
RedBearLab | 0:075ea2812998 | 296 | bool lib_aci_set_local_data(aci_state_t *aci_stat, uint8_t pipe, uint8_t *p_value, uint8_t size) |
RedBearLab | 0:075ea2812998 | 297 | { |
RedBearLab | 0:075ea2812998 | 298 | aci_cmd_params_set_local_data_t aci_cmd_params_set_local_data; |
RedBearLab | 0:075ea2812998 | 299 | |
RedBearLab | 0:075ea2812998 | 300 | // if ((p_services_pipe_type_map[pipe-1].location != ACI_STORE_LOCAL) |
RedBearLab | 0:075ea2812998 | 301 | // || |
RedBearLab | 0:075ea2812998 | 302 | // (size > ACI_PIPE_TX_DATA_MAX_LEN)) |
RedBearLab | 0:075ea2812998 | 303 | // { |
RedBearLab | 0:075ea2812998 | 304 | // return false; |
RedBearLab | 0:075ea2812998 | 305 | // } |
RedBearLab | 0:075ea2812998 | 306 | |
RedBearLab | 0:075ea2812998 | 307 | aci_cmd_params_set_local_data.tx_data.pipe_number = pipe; |
RedBearLab | 0:075ea2812998 | 308 | memcpy(&(aci_cmd_params_set_local_data.tx_data.aci_data[0]), p_value, size); |
RedBearLab | 0:075ea2812998 | 309 | acil_encode_cmd_set_local_data(&(msg_to_send.buffer[0]), &aci_cmd_params_set_local_data, size); |
RedBearLab | 0:075ea2812998 | 310 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 311 | } |
RedBearLab | 0:075ea2812998 | 312 | |
RedBearLab | 0:075ea2812998 | 313 | bool lib_aci_connect(uint16_t run_timeout, uint16_t adv_interval) |
RedBearLab | 0:075ea2812998 | 314 | { |
RedBearLab | 0:075ea2812998 | 315 | aci_cmd_params_connect_t aci_cmd_params_connect; |
RedBearLab | 0:075ea2812998 | 316 | aci_cmd_params_connect.timeout = run_timeout; |
RedBearLab | 0:075ea2812998 | 317 | aci_cmd_params_connect.adv_interval = adv_interval; |
RedBearLab | 0:075ea2812998 | 318 | acil_encode_cmd_connect(&(msg_to_send.buffer[0]), &aci_cmd_params_connect); |
RedBearLab | 0:075ea2812998 | 319 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 320 | } |
RedBearLab | 0:075ea2812998 | 321 | |
RedBearLab | 0:075ea2812998 | 322 | |
RedBearLab | 0:075ea2812998 | 323 | bool lib_aci_disconnect(aci_state_t *aci_stat, aci_disconnect_reason_t reason) |
RedBearLab | 0:075ea2812998 | 324 | { |
RedBearLab | 0:075ea2812998 | 325 | bool ret_val; |
RedBearLab | 0:075ea2812998 | 326 | uint8_t i; |
RedBearLab | 0:075ea2812998 | 327 | aci_cmd_params_disconnect_t aci_cmd_params_disconnect; |
RedBearLab | 0:075ea2812998 | 328 | aci_cmd_params_disconnect.reason = reason; |
RedBearLab | 0:075ea2812998 | 329 | acil_encode_cmd_disconnect(&(msg_to_send.buffer[0]), &aci_cmd_params_disconnect); |
RedBearLab | 0:075ea2812998 | 330 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 331 | // If we have actually sent the disconnect |
RedBearLab | 0:075ea2812998 | 332 | if (ret_val) |
RedBearLab | 0:075ea2812998 | 333 | { |
RedBearLab | 0:075ea2812998 | 334 | // Update pipes immediately so that while the disconnect is happening, |
RedBearLab | 0:075ea2812998 | 335 | // the application can't attempt sending another message |
RedBearLab | 0:075ea2812998 | 336 | // If the application sends another message before we updated this |
RedBearLab | 0:075ea2812998 | 337 | // a ACI Pipe Error Event will be received from nRF8001 |
RedBearLab | 0:075ea2812998 | 338 | for (i=0; i < PIPES_ARRAY_SIZE; i++) |
RedBearLab | 0:075ea2812998 | 339 | { |
RedBearLab | 0:075ea2812998 | 340 | aci_stat->pipes_open_bitmap[i] = 0; |
RedBearLab | 0:075ea2812998 | 341 | aci_stat->pipes_closed_bitmap[i] = 0; |
RedBearLab | 0:075ea2812998 | 342 | } |
RedBearLab | 0:075ea2812998 | 343 | } |
RedBearLab | 0:075ea2812998 | 344 | return ret_val; |
RedBearLab | 0:075ea2812998 | 345 | } |
RedBearLab | 0:075ea2812998 | 346 | |
RedBearLab | 0:075ea2812998 | 347 | |
RedBearLab | 0:075ea2812998 | 348 | bool lib_aci_bond(uint16_t run_timeout, uint16_t adv_interval) |
RedBearLab | 0:075ea2812998 | 349 | { |
RedBearLab | 0:075ea2812998 | 350 | aci_cmd_params_bond_t aci_cmd_params_bond; |
RedBearLab | 0:075ea2812998 | 351 | aci_cmd_params_bond.timeout = run_timeout; |
RedBearLab | 0:075ea2812998 | 352 | aci_cmd_params_bond.adv_interval = adv_interval; |
RedBearLab | 0:075ea2812998 | 353 | acil_encode_cmd_bond(&(msg_to_send.buffer[0]), &aci_cmd_params_bond); |
RedBearLab | 0:075ea2812998 | 354 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 355 | } |
RedBearLab | 0:075ea2812998 | 356 | |
RedBearLab | 0:075ea2812998 | 357 | |
RedBearLab | 0:075ea2812998 | 358 | bool lib_aci_wakeup() |
RedBearLab | 0:075ea2812998 | 359 | { |
RedBearLab | 0:075ea2812998 | 360 | acil_encode_cmd_wakeup(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 361 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 362 | } |
RedBearLab | 0:075ea2812998 | 363 | |
RedBearLab | 0:075ea2812998 | 364 | |
RedBearLab | 0:075ea2812998 | 365 | bool lib_aci_set_tx_power(aci_device_output_power_t tx_power) |
RedBearLab | 0:075ea2812998 | 366 | { |
RedBearLab | 0:075ea2812998 | 367 | aci_cmd_params_set_tx_power_t aci_cmd_params_set_tx_power; |
RedBearLab | 0:075ea2812998 | 368 | aci_cmd_params_set_tx_power.device_power = tx_power; |
RedBearLab | 0:075ea2812998 | 369 | acil_encode_cmd_set_radio_tx_power(&(msg_to_send.buffer[0]), &aci_cmd_params_set_tx_power); |
RedBearLab | 0:075ea2812998 | 370 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 371 | } |
RedBearLab | 0:075ea2812998 | 372 | |
RedBearLab | 0:075ea2812998 | 373 | |
RedBearLab | 0:075ea2812998 | 374 | bool lib_aci_get_address() |
RedBearLab | 0:075ea2812998 | 375 | { |
RedBearLab | 0:075ea2812998 | 376 | acil_encode_cmd_get_address(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 377 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 378 | } |
RedBearLab | 0:075ea2812998 | 379 | |
RedBearLab | 0:075ea2812998 | 380 | |
RedBearLab | 0:075ea2812998 | 381 | bool lib_aci_get_temperature() |
RedBearLab | 0:075ea2812998 | 382 | { |
RedBearLab | 0:075ea2812998 | 383 | acil_encode_cmd_temparature(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 384 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 385 | } |
RedBearLab | 0:075ea2812998 | 386 | |
RedBearLab | 0:075ea2812998 | 387 | |
RedBearLab | 0:075ea2812998 | 388 | bool lib_aci_get_battery_level() |
RedBearLab | 0:075ea2812998 | 389 | { |
RedBearLab | 0:075ea2812998 | 390 | acil_encode_cmd_battery_level(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 391 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 392 | } |
RedBearLab | 0:075ea2812998 | 393 | |
RedBearLab | 0:075ea2812998 | 394 | |
RedBearLab | 0:075ea2812998 | 395 | bool lib_aci_send_data(uint8_t pipe, uint8_t *p_value, uint8_t size) |
RedBearLab | 0:075ea2812998 | 396 | { |
RedBearLab | 0:075ea2812998 | 397 | bool ret_val = false; |
RedBearLab | 0:075ea2812998 | 398 | aci_cmd_params_send_data_t aci_cmd_params_send_data; |
RedBearLab | 0:075ea2812998 | 399 | |
RedBearLab | 0:075ea2812998 | 400 | |
RedBearLab | 0:075ea2812998 | 401 | // if(!((p_services_pipe_type_map[pipe-1].pipe_type == ACI_TX) || |
RedBearLab | 0:075ea2812998 | 402 | // (p_services_pipe_type_map[pipe-1].pipe_type == ACI_TX_ACK))) |
RedBearLab | 0:075ea2812998 | 403 | // { |
RedBearLab | 0:075ea2812998 | 404 | // return false; |
RedBearLab | 0:075ea2812998 | 405 | // } |
RedBearLab | 0:075ea2812998 | 406 | |
RedBearLab | 0:075ea2812998 | 407 | if (size > ACI_PIPE_TX_DATA_MAX_LEN) |
RedBearLab | 0:075ea2812998 | 408 | { |
RedBearLab | 0:075ea2812998 | 409 | return false; |
RedBearLab | 0:075ea2812998 | 410 | } |
RedBearLab | 0:075ea2812998 | 411 | { |
RedBearLab | 0:075ea2812998 | 412 | aci_cmd_params_send_data.tx_data.pipe_number = pipe; |
RedBearLab | 0:075ea2812998 | 413 | memcpy(&(aci_cmd_params_send_data.tx_data.aci_data[0]), p_value, size); |
RedBearLab | 0:075ea2812998 | 414 | acil_encode_cmd_send_data(&(msg_to_send.buffer[0]), &aci_cmd_params_send_data, size); |
RedBearLab | 0:075ea2812998 | 415 | |
RedBearLab | 0:075ea2812998 | 416 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 417 | } |
RedBearLab | 0:075ea2812998 | 418 | return ret_val; |
RedBearLab | 0:075ea2812998 | 419 | } |
RedBearLab | 0:075ea2812998 | 420 | |
RedBearLab | 0:075ea2812998 | 421 | |
RedBearLab | 0:075ea2812998 | 422 | bool lib_aci_request_data(aci_state_t *aci_stat, uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 423 | { |
RedBearLab | 0:075ea2812998 | 424 | bool ret_val = false; |
RedBearLab | 0:075ea2812998 | 425 | aci_cmd_params_request_data_t aci_cmd_params_request_data; |
RedBearLab | 0:075ea2812998 | 426 | |
RedBearLab | 0:075ea2812998 | 427 | if(!((p_services_pipe_type_map[pipe-1].location == ACI_STORE_REMOTE)&&(p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_REQ))) |
RedBearLab | 0:075ea2812998 | 428 | { |
RedBearLab | 0:075ea2812998 | 429 | return false; |
RedBearLab | 0:075ea2812998 | 430 | } |
RedBearLab | 0:075ea2812998 | 431 | |
RedBearLab | 0:075ea2812998 | 432 | |
RedBearLab | 0:075ea2812998 | 433 | { |
RedBearLab | 0:075ea2812998 | 434 | |
RedBearLab | 0:075ea2812998 | 435 | { |
RedBearLab | 0:075ea2812998 | 436 | |
RedBearLab | 0:075ea2812998 | 437 | |
RedBearLab | 0:075ea2812998 | 438 | |
RedBearLab | 0:075ea2812998 | 439 | aci_cmd_params_request_data.pipe_number = pipe; |
RedBearLab | 0:075ea2812998 | 440 | acil_encode_cmd_request_data(&(msg_to_send.buffer[0]), &aci_cmd_params_request_data); |
RedBearLab | 0:075ea2812998 | 441 | |
RedBearLab | 0:075ea2812998 | 442 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 443 | } |
RedBearLab | 0:075ea2812998 | 444 | } |
RedBearLab | 0:075ea2812998 | 445 | return ret_val; |
RedBearLab | 0:075ea2812998 | 446 | } |
RedBearLab | 0:075ea2812998 | 447 | |
RedBearLab | 0:075ea2812998 | 448 | |
RedBearLab | 0:075ea2812998 | 449 | bool lib_aci_change_timing(uint16_t minimun_cx_interval, uint16_t maximum_cx_interval, uint16_t slave_latency, uint16_t timeout) |
RedBearLab | 0:075ea2812998 | 450 | { |
RedBearLab | 0:075ea2812998 | 451 | aci_cmd_params_change_timing_t aci_cmd_params_change_timing; |
RedBearLab | 0:075ea2812998 | 452 | aci_cmd_params_change_timing.conn_params.min_conn_interval = minimun_cx_interval; |
RedBearLab | 0:075ea2812998 | 453 | aci_cmd_params_change_timing.conn_params.max_conn_interval = maximum_cx_interval; |
RedBearLab | 0:075ea2812998 | 454 | aci_cmd_params_change_timing.conn_params.slave_latency = slave_latency; |
RedBearLab | 0:075ea2812998 | 455 | aci_cmd_params_change_timing.conn_params.timeout_mult = timeout; |
RedBearLab | 0:075ea2812998 | 456 | acil_encode_cmd_change_timing_req(&(msg_to_send.buffer[0]), &aci_cmd_params_change_timing); |
RedBearLab | 0:075ea2812998 | 457 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 458 | } |
RedBearLab | 0:075ea2812998 | 459 | |
RedBearLab | 0:075ea2812998 | 460 | |
RedBearLab | 0:075ea2812998 | 461 | bool lib_aci_change_timing_GAP_PPCP() |
RedBearLab | 0:075ea2812998 | 462 | { |
RedBearLab | 0:075ea2812998 | 463 | acil_encode_cmd_change_timing_req_GAP_PPCP(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 464 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 465 | } |
RedBearLab | 0:075ea2812998 | 466 | |
RedBearLab | 0:075ea2812998 | 467 | |
RedBearLab | 0:075ea2812998 | 468 | bool lib_aci_open_remote_pipe(aci_state_t *aci_stat, uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 469 | { |
RedBearLab | 0:075ea2812998 | 470 | bool ret_val = false; |
RedBearLab | 0:075ea2812998 | 471 | aci_cmd_params_open_remote_pipe_t aci_cmd_params_open_remote_pipe; |
RedBearLab | 0:075ea2812998 | 472 | |
RedBearLab | 0:075ea2812998 | 473 | if(!((p_services_pipe_type_map[pipe-1].location == ACI_STORE_REMOTE)&& |
RedBearLab | 0:075ea2812998 | 474 | ((p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX)|| |
RedBearLab | 0:075ea2812998 | 475 | (p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK_AUTO)|| |
RedBearLab | 0:075ea2812998 | 476 | (p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK)))) |
RedBearLab | 0:075ea2812998 | 477 | { |
RedBearLab | 0:075ea2812998 | 478 | return false; |
RedBearLab | 0:075ea2812998 | 479 | } |
RedBearLab | 0:075ea2812998 | 480 | |
RedBearLab | 0:075ea2812998 | 481 | |
RedBearLab | 0:075ea2812998 | 482 | { |
RedBearLab | 0:075ea2812998 | 483 | |
RedBearLab | 0:075ea2812998 | 484 | is_request_operation_pending = true; |
RedBearLab | 0:075ea2812998 | 485 | is_open_remote_pipe_pending = true; |
RedBearLab | 0:075ea2812998 | 486 | request_operation_pipe = pipe; |
RedBearLab | 0:075ea2812998 | 487 | aci_cmd_params_open_remote_pipe.pipe_number = pipe; |
RedBearLab | 0:075ea2812998 | 488 | acil_encode_cmd_open_remote_pipe(&(msg_to_send.buffer[0]), &aci_cmd_params_open_remote_pipe); |
RedBearLab | 0:075ea2812998 | 489 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 490 | } |
RedBearLab | 0:075ea2812998 | 491 | return ret_val; |
RedBearLab | 0:075ea2812998 | 492 | } |
RedBearLab | 0:075ea2812998 | 493 | |
RedBearLab | 0:075ea2812998 | 494 | |
RedBearLab | 0:075ea2812998 | 495 | bool lib_aci_close_remote_pipe(aci_state_t *aci_stat, uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 496 | { |
RedBearLab | 0:075ea2812998 | 497 | bool ret_val = false; |
RedBearLab | 0:075ea2812998 | 498 | aci_cmd_params_close_remote_pipe_t aci_cmd_params_close_remote_pipe; |
RedBearLab | 0:075ea2812998 | 499 | |
RedBearLab | 0:075ea2812998 | 500 | if(!((p_services_pipe_type_map[pipe-1].location == ACI_STORE_REMOTE)&& |
RedBearLab | 0:075ea2812998 | 501 | ((p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX)|| |
RedBearLab | 0:075ea2812998 | 502 | (p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK_AUTO)|| |
RedBearLab | 0:075ea2812998 | 503 | (p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK)))) |
RedBearLab | 0:075ea2812998 | 504 | { |
RedBearLab | 0:075ea2812998 | 505 | return false; |
RedBearLab | 0:075ea2812998 | 506 | } |
RedBearLab | 0:075ea2812998 | 507 | |
RedBearLab | 0:075ea2812998 | 508 | |
RedBearLab | 0:075ea2812998 | 509 | { |
RedBearLab | 0:075ea2812998 | 510 | |
RedBearLab | 0:075ea2812998 | 511 | is_request_operation_pending = true; |
RedBearLab | 0:075ea2812998 | 512 | is_close_remote_pipe_pending = true; |
RedBearLab | 0:075ea2812998 | 513 | request_operation_pipe = pipe; |
RedBearLab | 0:075ea2812998 | 514 | aci_cmd_params_close_remote_pipe.pipe_number = pipe; |
RedBearLab | 0:075ea2812998 | 515 | acil_encode_cmd_close_remote_pipe(&(msg_to_send.buffer[0]), &aci_cmd_params_close_remote_pipe); |
RedBearLab | 0:075ea2812998 | 516 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 517 | } |
RedBearLab | 0:075ea2812998 | 518 | return ret_val; |
RedBearLab | 0:075ea2812998 | 519 | } |
RedBearLab | 0:075ea2812998 | 520 | |
RedBearLab | 0:075ea2812998 | 521 | |
RedBearLab | 0:075ea2812998 | 522 | bool lib_aci_set_key(aci_key_type_t key_rsp_type, uint8_t *key, uint8_t len) |
RedBearLab | 0:075ea2812998 | 523 | { |
RedBearLab | 0:075ea2812998 | 524 | aci_cmd_params_set_key_t aci_cmd_params_set_key; |
RedBearLab | 0:075ea2812998 | 525 | aci_cmd_params_set_key.key_type = key_rsp_type; |
RedBearLab | 0:075ea2812998 | 526 | memcpy((uint8_t*)&(aci_cmd_params_set_key.key), key, len); |
RedBearLab | 0:075ea2812998 | 527 | acil_encode_cmd_set_key(&(msg_to_send.buffer[0]), &aci_cmd_params_set_key); |
RedBearLab | 0:075ea2812998 | 528 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 529 | } |
RedBearLab | 0:075ea2812998 | 530 | |
RedBearLab | 0:075ea2812998 | 531 | |
RedBearLab | 0:075ea2812998 | 532 | bool lib_aci_echo_msg(uint8_t msg_size, uint8_t *p_msg_data) |
RedBearLab | 0:075ea2812998 | 533 | { |
RedBearLab | 0:075ea2812998 | 534 | aci_cmd_params_echo_t aci_cmd_params_echo; |
RedBearLab | 0:075ea2812998 | 535 | if(msg_size > (ACI_ECHO_DATA_MAX_LEN)) |
RedBearLab | 0:075ea2812998 | 536 | { |
RedBearLab | 0:075ea2812998 | 537 | return false; |
RedBearLab | 0:075ea2812998 | 538 | } |
RedBearLab | 0:075ea2812998 | 539 | |
RedBearLab | 0:075ea2812998 | 540 | if (msg_size > (ACI_ECHO_DATA_MAX_LEN)) |
RedBearLab | 0:075ea2812998 | 541 | { |
RedBearLab | 0:075ea2812998 | 542 | msg_size = ACI_ECHO_DATA_MAX_LEN; |
RedBearLab | 0:075ea2812998 | 543 | } |
RedBearLab | 0:075ea2812998 | 544 | |
RedBearLab | 0:075ea2812998 | 545 | memcpy(&(aci_cmd_params_echo.echo_data[0]), p_msg_data, msg_size); |
RedBearLab | 0:075ea2812998 | 546 | acil_encode_cmd_echo_msg(&(msg_to_send.buffer[0]), &aci_cmd_params_echo, msg_size); |
RedBearLab | 0:075ea2812998 | 547 | |
RedBearLab | 0:075ea2812998 | 548 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 549 | } |
RedBearLab | 0:075ea2812998 | 550 | |
RedBearLab | 0:075ea2812998 | 551 | |
RedBearLab | 0:075ea2812998 | 552 | bool lib_aci_bond_request() |
RedBearLab | 0:075ea2812998 | 553 | { |
RedBearLab | 0:075ea2812998 | 554 | acil_encode_cmd_bond_security_request(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 555 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 556 | } |
RedBearLab | 0:075ea2812998 | 557 | |
RedBearLab | 0:075ea2812998 | 558 | bool lib_aci_event_peek(hal_aci_evt_t *p_aci_evt_data) |
RedBearLab | 0:075ea2812998 | 559 | { |
RedBearLab | 0:075ea2812998 | 560 | return hal_aci_tl_event_peek((hal_aci_data_t *)p_aci_evt_data); |
RedBearLab | 0:075ea2812998 | 561 | } |
RedBearLab | 0:075ea2812998 | 562 | |
RedBearLab | 0:075ea2812998 | 563 | bool lib_aci_event_get(aci_state_t *aci_stat, hal_aci_evt_t *p_aci_evt_data) |
RedBearLab | 0:075ea2812998 | 564 | { |
RedBearLab | 0:075ea2812998 | 565 | bool status = false; |
RedBearLab | 0:075ea2812998 | 566 | |
RedBearLab | 0:075ea2812998 | 567 | status = hal_aci_tl_event_get((hal_aci_data_t *)p_aci_evt_data); |
RedBearLab | 0:075ea2812998 | 568 | |
RedBearLab | 0:075ea2812998 | 569 | /** |
RedBearLab | 0:075ea2812998 | 570 | Update the state of the ACI with the |
RedBearLab | 0:075ea2812998 | 571 | ACI Events -> Pipe Status, Disconnected, Connected, Bond Status, Pipe Error |
RedBearLab | 0:075ea2812998 | 572 | */ |
RedBearLab | 0:075ea2812998 | 573 | if (true == status) |
RedBearLab | 0:075ea2812998 | 574 | { |
RedBearLab | 0:075ea2812998 | 575 | aci_evt_t * aci_evt; |
RedBearLab | 0:075ea2812998 | 576 | |
RedBearLab | 0:075ea2812998 | 577 | aci_evt = &p_aci_evt_data->evt; |
RedBearLab | 0:075ea2812998 | 578 | |
RedBearLab | 0:075ea2812998 | 579 | switch(aci_evt->evt_opcode) |
RedBearLab | 0:075ea2812998 | 580 | { |
RedBearLab | 0:075ea2812998 | 581 | case ACI_EVT_PIPE_STATUS: |
RedBearLab | 0:075ea2812998 | 582 | { |
RedBearLab | 0:075ea2812998 | 583 | uint8_t i=0; |
RedBearLab | 0:075ea2812998 | 584 | |
RedBearLab | 0:075ea2812998 | 585 | for (i=0; i < PIPES_ARRAY_SIZE; i++) |
RedBearLab | 0:075ea2812998 | 586 | { |
RedBearLab | 0:075ea2812998 | 587 | aci_stat->pipes_open_bitmap[i] = aci_evt->params.pipe_status.pipes_open_bitmap[i]; |
RedBearLab | 0:075ea2812998 | 588 | aci_stat->pipes_closed_bitmap[i] = aci_evt->params.pipe_status.pipes_closed_bitmap[i]; |
RedBearLab | 0:075ea2812998 | 589 | } |
RedBearLab | 0:075ea2812998 | 590 | } |
RedBearLab | 0:075ea2812998 | 591 | break; |
RedBearLab | 0:075ea2812998 | 592 | |
RedBearLab | 0:075ea2812998 | 593 | case ACI_EVT_DISCONNECTED: |
RedBearLab | 0:075ea2812998 | 594 | { |
RedBearLab | 0:075ea2812998 | 595 | uint8_t i=0; |
RedBearLab | 0:075ea2812998 | 596 | |
RedBearLab | 0:075ea2812998 | 597 | for (i=0; i < PIPES_ARRAY_SIZE; i++) |
RedBearLab | 0:075ea2812998 | 598 | { |
RedBearLab | 0:075ea2812998 | 599 | aci_stat->pipes_open_bitmap[i] = 0; |
RedBearLab | 0:075ea2812998 | 600 | aci_stat->pipes_closed_bitmap[i] = 0; |
RedBearLab | 0:075ea2812998 | 601 | } |
RedBearLab | 0:075ea2812998 | 602 | aci_stat->confirmation_pending = false; |
RedBearLab | 0:075ea2812998 | 603 | aci_stat->data_credit_available = aci_stat->data_credit_total; |
RedBearLab | 0:075ea2812998 | 604 | |
RedBearLab | 0:075ea2812998 | 605 | } |
RedBearLab | 0:075ea2812998 | 606 | break; |
RedBearLab | 0:075ea2812998 | 607 | |
RedBearLab | 0:075ea2812998 | 608 | case ACI_EVT_TIMING: |
RedBearLab | 0:075ea2812998 | 609 | aci_stat->connection_interval = aci_evt->params.timing.conn_rf_interval; |
RedBearLab | 0:075ea2812998 | 610 | aci_stat->slave_latency = aci_evt->params.timing.conn_slave_rf_latency; |
RedBearLab | 0:075ea2812998 | 611 | aci_stat->supervision_timeout = aci_evt->params.timing.conn_rf_timeout; |
RedBearLab | 0:075ea2812998 | 612 | break; |
RedBearLab | 0:075ea2812998 | 613 | |
RedBearLab | 0:075ea2812998 | 614 | default: |
RedBearLab | 0:075ea2812998 | 615 | /* Need default case to avoid compiler warnings about missing enum |
RedBearLab | 0:075ea2812998 | 616 | * values on some platforms. |
RedBearLab | 0:075ea2812998 | 617 | */ |
RedBearLab | 0:075ea2812998 | 618 | break; |
RedBearLab | 0:075ea2812998 | 619 | |
RedBearLab | 0:075ea2812998 | 620 | |
RedBearLab | 0:075ea2812998 | 621 | |
RedBearLab | 0:075ea2812998 | 622 | } |
RedBearLab | 0:075ea2812998 | 623 | } |
RedBearLab | 0:075ea2812998 | 624 | return status; |
RedBearLab | 0:075ea2812998 | 625 | } |
RedBearLab | 0:075ea2812998 | 626 | |
RedBearLab | 0:075ea2812998 | 627 | |
RedBearLab | 0:075ea2812998 | 628 | bool lib_aci_send_ack(aci_state_t *aci_stat, const uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 629 | { |
RedBearLab | 0:075ea2812998 | 630 | bool ret_val = false; |
RedBearLab | 0:075ea2812998 | 631 | { |
RedBearLab | 0:075ea2812998 | 632 | acil_encode_cmd_send_data_ack(&(msg_to_send.buffer[0]), pipe); |
RedBearLab | 0:075ea2812998 | 633 | |
RedBearLab | 0:075ea2812998 | 634 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 635 | } |
RedBearLab | 0:075ea2812998 | 636 | return ret_val; |
RedBearLab | 0:075ea2812998 | 637 | } |
RedBearLab | 0:075ea2812998 | 638 | |
RedBearLab | 0:075ea2812998 | 639 | |
RedBearLab | 0:075ea2812998 | 640 | bool lib_aci_send_nack(aci_state_t *aci_stat, const uint8_t pipe, const uint8_t error_code) |
RedBearLab | 0:075ea2812998 | 641 | { |
RedBearLab | 0:075ea2812998 | 642 | bool ret_val = false; |
RedBearLab | 0:075ea2812998 | 643 | |
RedBearLab | 0:075ea2812998 | 644 | { |
RedBearLab | 0:075ea2812998 | 645 | |
RedBearLab | 0:075ea2812998 | 646 | acil_encode_cmd_send_data_nack(&(msg_to_send.buffer[0]), pipe, error_code); |
RedBearLab | 0:075ea2812998 | 647 | ret_val = hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 648 | } |
RedBearLab | 0:075ea2812998 | 649 | return ret_val; |
RedBearLab | 0:075ea2812998 | 650 | } |
RedBearLab | 0:075ea2812998 | 651 | |
RedBearLab | 0:075ea2812998 | 652 | |
RedBearLab | 0:075ea2812998 | 653 | bool lib_aci_broadcast(const uint16_t timeout, const uint16_t adv_interval) |
RedBearLab | 0:075ea2812998 | 654 | { |
RedBearLab | 0:075ea2812998 | 655 | aci_cmd_params_broadcast_t aci_cmd_params_broadcast; |
RedBearLab | 0:075ea2812998 | 656 | if (timeout > 16383) |
RedBearLab | 0:075ea2812998 | 657 | { |
RedBearLab | 0:075ea2812998 | 658 | return false; |
RedBearLab | 0:075ea2812998 | 659 | } |
RedBearLab | 0:075ea2812998 | 660 | |
RedBearLab | 0:075ea2812998 | 661 | // The adv_interval should be between 160 and 16384 (which translates to the advertisement |
RedBearLab | 0:075ea2812998 | 662 | // interval values 100 ms and 10.24 s. |
RedBearLab | 0:075ea2812998 | 663 | if ((160 > adv_interval) || (adv_interval > 16384)) |
RedBearLab | 0:075ea2812998 | 664 | { |
RedBearLab | 0:075ea2812998 | 665 | return false; |
RedBearLab | 0:075ea2812998 | 666 | } |
RedBearLab | 0:075ea2812998 | 667 | |
RedBearLab | 0:075ea2812998 | 668 | aci_cmd_params_broadcast.timeout = timeout; |
RedBearLab | 0:075ea2812998 | 669 | aci_cmd_params_broadcast.adv_interval = adv_interval; |
RedBearLab | 0:075ea2812998 | 670 | acil_encode_cmd_broadcast(&(msg_to_send.buffer[0]), &aci_cmd_params_broadcast); |
RedBearLab | 0:075ea2812998 | 671 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 672 | } |
RedBearLab | 0:075ea2812998 | 673 | |
RedBearLab | 0:075ea2812998 | 674 | |
RedBearLab | 0:075ea2812998 | 675 | bool lib_aci_open_adv_pipes(const uint8_t * const adv_service_data_pipes) |
RedBearLab | 0:075ea2812998 | 676 | { |
RedBearLab | 0:075ea2812998 | 677 | uint8_t i; |
RedBearLab | 0:075ea2812998 | 678 | |
RedBearLab | 0:075ea2812998 | 679 | for (i = 0; i < PIPES_ARRAY_SIZE; i++) |
RedBearLab | 0:075ea2812998 | 680 | { |
RedBearLab | 0:075ea2812998 | 681 | aci_cmd_params_open_adv_pipe.pipes[i] = adv_service_data_pipes[i]; |
RedBearLab | 0:075ea2812998 | 682 | } |
RedBearLab | 0:075ea2812998 | 683 | |
RedBearLab | 0:075ea2812998 | 684 | acil_encode_cmd_open_adv_pipes(&(msg_to_send.buffer[0]), &aci_cmd_params_open_adv_pipe); |
RedBearLab | 0:075ea2812998 | 685 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 686 | } |
RedBearLab | 0:075ea2812998 | 687 | |
RedBearLab | 0:075ea2812998 | 688 | bool lib_aci_open_adv_pipe(const uint8_t pipe) |
RedBearLab | 0:075ea2812998 | 689 | { |
RedBearLab | 0:075ea2812998 | 690 | uint8_t byte_idx = pipe / 8; |
RedBearLab | 0:075ea2812998 | 691 | |
RedBearLab | 0:075ea2812998 | 692 | aci_cmd_params_open_adv_pipe.pipes[byte_idx] |= (0x01 << (pipe % 8)); |
RedBearLab | 0:075ea2812998 | 693 | acil_encode_cmd_open_adv_pipes(&(msg_to_send.buffer[0]), &aci_cmd_params_open_adv_pipe); |
RedBearLab | 0:075ea2812998 | 694 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 695 | } |
RedBearLab | 0:075ea2812998 | 696 | |
RedBearLab | 0:075ea2812998 | 697 | |
RedBearLab | 0:075ea2812998 | 698 | bool lib_aci_read_dynamic_data() |
RedBearLab | 0:075ea2812998 | 699 | { |
RedBearLab | 0:075ea2812998 | 700 | acil_encode_cmd_read_dynamic_data(&(msg_to_send.buffer[0])); |
RedBearLab | 0:075ea2812998 | 701 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 702 | } |
RedBearLab | 0:075ea2812998 | 703 | |
RedBearLab | 0:075ea2812998 | 704 | |
RedBearLab | 0:075ea2812998 | 705 | bool lib_aci_write_dynamic_data(uint8_t sequence_number, uint8_t* dynamic_data, uint8_t length) |
RedBearLab | 0:075ea2812998 | 706 | { |
RedBearLab | 0:075ea2812998 | 707 | acil_encode_cmd_write_dynamic_data(&(msg_to_send.buffer[0]), sequence_number, dynamic_data, length); |
RedBearLab | 0:075ea2812998 | 708 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 709 | } |
RedBearLab | 0:075ea2812998 | 710 | |
RedBearLab | 0:075ea2812998 | 711 | bool lib_aci_dtm_command(uint8_t dtm_command_msbyte, uint8_t dtm_command_lsbyte) |
RedBearLab | 0:075ea2812998 | 712 | { |
RedBearLab | 0:075ea2812998 | 713 | aci_cmd_params_dtm_cmd_t aci_cmd_params_dtm_cmd; |
RedBearLab | 0:075ea2812998 | 714 | aci_cmd_params_dtm_cmd.cmd_msb = dtm_command_msbyte; |
RedBearLab | 0:075ea2812998 | 715 | aci_cmd_params_dtm_cmd.cmd_lsb = dtm_command_lsbyte; |
RedBearLab | 0:075ea2812998 | 716 | acil_encode_cmd_dtm_cmd(&(msg_to_send.buffer[0]), &aci_cmd_params_dtm_cmd); |
RedBearLab | 0:075ea2812998 | 717 | return hal_aci_tl_send(&msg_to_send); |
RedBearLab | 0:075ea2812998 | 718 | } |
RedBearLab | 0:075ea2812998 | 719 | |
RedBearLab | 0:075ea2812998 | 720 | void lib_aci_flush(void) |
RedBearLab | 0:075ea2812998 | 721 | { |
RedBearLab | 0:075ea2812998 | 722 | hal_aci_tl_q_flush(); |
RedBearLab | 0:075ea2812998 | 723 | } |
RedBearLab | 0:075ea2812998 | 724 | |
RedBearLab | 0:075ea2812998 | 725 | void lib_aci_debug_print(bool enable) |
RedBearLab | 0:075ea2812998 | 726 | { |
RedBearLab | 0:075ea2812998 | 727 | hal_aci_tl_debug_print(enable); |
RedBearLab | 0:075ea2812998 | 728 | |
RedBearLab | 0:075ea2812998 | 729 | } |
RedBearLab | 0:075ea2812998 | 730 | |
RedBearLab | 0:075ea2812998 | 731 | void lib_aci_pin_reset(void) |
RedBearLab | 0:075ea2812998 | 732 | { |
RedBearLab | 0:075ea2812998 | 733 | hal_aci_tl_pin_reset(); |
RedBearLab | 0:075ea2812998 | 734 | } |
RedBearLab | 0:075ea2812998 | 735 | |
RedBearLab | 0:075ea2812998 | 736 | bool lib_aci_event_queue_empty(void) |
RedBearLab | 0:075ea2812998 | 737 | { |
RedBearLab | 0:075ea2812998 | 738 | return hal_aci_tl_rx_q_empty(); |
RedBearLab | 0:075ea2812998 | 739 | } |
RedBearLab | 0:075ea2812998 | 740 | |
RedBearLab | 0:075ea2812998 | 741 | bool lib_aci_event_queue_full(void) |
RedBearLab | 0:075ea2812998 | 742 | { |
RedBearLab | 0:075ea2812998 | 743 | return hal_aci_tl_rx_q_full(); |
RedBearLab | 0:075ea2812998 | 744 | } |
RedBearLab | 0:075ea2812998 | 745 | |
RedBearLab | 0:075ea2812998 | 746 | bool lib_aci_command_queue_empty(void) |
RedBearLab | 0:075ea2812998 | 747 | { |
RedBearLab | 0:075ea2812998 | 748 | return hal_aci_tl_tx_q_empty(); |
RedBearLab | 0:075ea2812998 | 749 | } |
RedBearLab | 0:075ea2812998 | 750 | |
RedBearLab | 0:075ea2812998 | 751 | bool lib_aci_command_queue_full(void) |
RedBearLab | 0:075ea2812998 | 752 | { |
RedBearLab | 0:075ea2812998 | 753 | return hal_aci_tl_tx_q_full(); |
RedBearLab | 0:075ea2812998 | 754 | } |