Contiki-NG
rf-ble-cmd.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Graz University of Technology
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /**
32  * \file
33  * BLE commands for the TI CC26xx BLE radio.
34  * These functions are specific to the TI CC26xx and cannot be
35  * reused by other BLE radios.
36  *
37  * \author
38  * Michael Spoerk <michael.spoerk@tugraz.at>
39  */
40 /*---------------------------------------------------------------------------*/
41 
42 #ifndef RF_BLE_CMD_H_
43 #define RF_BLE_CMD_H_
44 
45 #include "os/dev/ble-hal.h"
46 #include "../../ble-addr.h"
47 #include "rf_common_cmd.h"
48 
49 #define RF_BLE_CMD_OK 1
50 #define RF_BLE_CMD_ERROR 0
51 
52 /*---------------------------------------------------------------------------*/
53 /**
54  * \brief Sends a BLE radio command to the radio
55  * \param cmd A pointer to the command to be send
56  * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR
57  */
58 unsigned short rf_ble_cmd_send(uint8_t *cmd);
59 
60 /*---------------------------------------------------------------------------*/
61 /**
62  * \brief Waits for a running BLE radio command to be finished
63  * \param cmd A pointer to the running command
64  * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR
65  */
66 unsigned short rf_ble_cmd_wait(uint8_t *cmd);
67 
68 /*---------------------------------------------------------------------------*/
69 /**
70  * \brief Initializes the radio core to be used as a BLE radio
71  * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR
72  */
73 unsigned short rf_ble_cmd_setup_ble_mode(void);
74 
75 /*---------------------------------------------------------------------------*/
76 /**
77  * \brief Creates a BLE radio command structure that enables
78  * BLE advertisement when sent to the radio core
79  * \param command A pointer to command that is created
80  * \param channel The BLE advertisement channel used for advertisement
81  * \param param A pointer to the radio command parameters
82  * \param output A pointer to the radio command output
83  */
84 void rf_ble_cmd_create_adv_cmd(uint8_t *command, uint8_t channel,
85  uint8_t *param, uint8_t *output);
86 
87 /*---------------------------------------------------------------------------*/
88 /**
89  * \brief Creates BLE radio command parameters that are used to enable
90  * BLE advertisement on the radio core
91  * \param param A pointer to parameter structure that is created
92  * \param rx_queue A pointer to the RX queue that is used
93  * \param adv_data_len
94  * The length of the advertisement data
95  * \param adv_data A pointer to the advertisement data that is advertised
96  * \param scan_resp_data_len
97  * The length of the scan response data
98  * \param scan_resp_data
99  * A pointer to the scan response data
100  * \param own_addr_type
101  * Either BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM
102  * \param own_addr A pointer to the device address that is used as own address
103  */
104 void rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue,
105  uint8_t adv_data_len, uint8_t *adv_data,
106  uint8_t scan_resp_data_len, uint8_t *scan_resp_data,
107  ble_addr_type_t own_addr_type, uint8_t *own_addr);
108 
109 /*---------------------------------------------------------------------------*/
110 /**
111  * \brief Creates a BLE radio command structure that sets up a single
112  * BLE connection event when sent to the radio core
113  * \param cmd A pointer to command that is created
114  * \param channel The BLE data channel used for the connection event
115  * \param param A pointer to the radio command parameters
116  * \param output A pointer to the radio command output
117  * \param start_time
118  * The time in rf_core_ticks when the connection event will start
119  */
120 void rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *param,
121  uint8_t *output, uint32_t start_time);
122 
123 /*---------------------------------------------------------------------------*/
124 /**
125  * \brief Creates BLE radio command parameters that are used to setup a single
126  * BLE connection event on the radio core
127  * \param param A pointer to parameter structure that is created
128  * \param rx_queue A pointer to the RX queue that is used
129  * \param tx_queue A pointer to the TX queue that is used
130  * \param access_address
131  * The access address of the used BLE connection
132  * \param crc_init_0
133  * Part of the initialization of the CRC checksum
134  * \param crc_init_1
135  * Part of the initialization of the CRC checksum
136  * \param crc_init_2
137  * Part of the initialization of the CRC checksum
138  * \param win_size The window size parameter of the BLE connection event
139  * \param window_widening
140  * The window widening parameter used for this connection event
141  * \param first_packet
142  * 1 for the first packet of the BLE connection so that the
143  * connection is properly initialized
144  */
145 void rf_ble_cmd_create_slave_params(uint8_t *param, dataQueue_t *rx_queue,
146  dataQueue_t *tx_queue, uint32_t access_address,
147  uint8_t crc_init_0, uint8_t crc_init_1,
148  uint8_t crc_init_2, uint32_t win_size,
149  uint32_t window_widening, uint8_t first_packet);
150 
151 /*---------------------------------------------------------------------------*/
152 /**
153  * \brief Adds a data buffer to a BLE transmission queue
154  * \param q A pointer to BLE transmission queue where the buffer
155  * should be added
156  * \param e A pointer to the data buffer that is added
157  */
158 unsigned short rf_ble_cmd_add_data_queue_entry(dataQueue_t *q, uint8_t *e);
159 
160 #endif /* RF_BLE_CMD_H_ */
unsigned short rf_ble_cmd_wait(uint8_t *cmd)
Waits for a running BLE radio command to be finished.
Definition: rf-ble-cmd.c:86
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
Definition: sicslowpan.c:1549
void rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *param, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up a single BLE connection event when sent to the rad...
Definition: rf-ble-cmd.c:168
hardware abstraction for a BLE controller
unsigned short rf_ble_cmd_setup_ble_mode(void)
Initializes the radio core to be used as a BLE radio.
Definition: rf-ble-cmd.c:98
void rf_ble_cmd_create_adv_cmd(uint8_t *command, uint8_t channel, uint8_t *param, uint8_t *output)
Creates a BLE radio command structure that enables BLE advertisement when sent to the radio core...
Definition: rf-ble-cmd.c:120
unsigned short rf_ble_cmd_send(uint8_t *cmd)
Sends a BLE radio command to the radio.
Definition: rf-ble-cmd.c:72
void rf_ble_cmd_create_slave_params(uint8_t *param, dataQueue_t *rx_queue, dataQueue_t *tx_queue, uint32_t access_address, uint8_t crc_init_0, uint8_t crc_init_1, uint8_t crc_init_2, uint32_t win_size, uint32_t window_widening, uint8_t first_packet)
Creates BLE radio command parameters that are used to setup a single BLE connection event on the radi...
Definition: rf-ble-cmd.c:187
void rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue, uint8_t adv_data_len, uint8_t *adv_data, uint8_t scan_resp_data_len, uint8_t *scan_resp_data, ble_addr_type_t own_addr_type, uint8_t *own_addr)
Creates BLE radio command parameters that are used to enable BLE advertisement on the radio core...
Definition: rf-ble-cmd.c:136
unsigned short rf_ble_cmd_add_data_queue_entry(dataQueue_t *q, uint8_t *e)
Adds a data buffer to a BLE transmission queue.
Definition: rf-ble-cmd.c:236