User | Revision | Line number | New contents of line |
jinu |
0:6ba9b94b8997
|
1
|
/* Copyright (c) Nordic Semiconductor ASA
|
jinu |
0:6ba9b94b8997
|
2
|
* All rights reserved.
|
jinu |
0:6ba9b94b8997
|
3
|
*
|
jinu |
0:6ba9b94b8997
|
4
|
* Redistribution and use in source and binary forms, with or without modification,
|
jinu |
0:6ba9b94b8997
|
5
|
* are permitted provided that the following conditions are met:
|
jinu |
0:6ba9b94b8997
|
6
|
*
|
jinu |
0:6ba9b94b8997
|
7
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
jinu |
0:6ba9b94b8997
|
8
|
* list of conditions and the following disclaimer.
|
jinu |
0:6ba9b94b8997
|
9
|
*
|
jinu |
0:6ba9b94b8997
|
10
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this
|
jinu |
0:6ba9b94b8997
|
11
|
* list of conditions and the following disclaimer in the documentation and/or
|
jinu |
0:6ba9b94b8997
|
12
|
* other materials provided with the distribution.
|
jinu |
0:6ba9b94b8997
|
13
|
*
|
jinu |
0:6ba9b94b8997
|
14
|
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
|
jinu |
0:6ba9b94b8997
|
15
|
* contributors to this software may be used to endorse or promote products
|
jinu |
0:6ba9b94b8997
|
16
|
* derived from this software without specific prior written permission.
|
jinu |
0:6ba9b94b8997
|
17
|
*
|
jinu |
0:6ba9b94b8997
|
18
|
* 4. This software must only be used in a processor manufactured by Nordic
|
jinu |
0:6ba9b94b8997
|
19
|
* Semiconductor ASA, or in a processor manufactured by a third party that
|
jinu |
0:6ba9b94b8997
|
20
|
* is used in combination with a processor manufactured by Nordic Semiconductor.
|
jinu |
0:6ba9b94b8997
|
21
|
*
|
jinu |
0:6ba9b94b8997
|
22
|
*
|
jinu |
0:6ba9b94b8997
|
23
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
jinu |
0:6ba9b94b8997
|
24
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
jinu |
0:6ba9b94b8997
|
25
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
jinu |
0:6ba9b94b8997
|
26
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
jinu |
0:6ba9b94b8997
|
27
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
jinu |
0:6ba9b94b8997
|
28
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
jinu |
0:6ba9b94b8997
|
29
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
jinu |
0:6ba9b94b8997
|
30
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
jinu |
0:6ba9b94b8997
|
31
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
jinu |
0:6ba9b94b8997
|
32
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
jinu |
0:6ba9b94b8997
|
33
|
*/
|
jinu |
0:6ba9b94b8997
|
34
|
|
jinu |
0:6ba9b94b8997
|
35
|
/**@file
|
jinu |
0:6ba9b94b8997
|
36
|
*
|
jinu |
0:6ba9b94b8997
|
37
|
* @defgroup XXX
|
jinu |
0:6ba9b94b8997
|
38
|
* @{
|
jinu |
0:6ba9b94b8997
|
39
|
* @ingroup XXX
|
jinu |
0:6ba9b94b8997
|
40
|
*
|
jinu |
0:6ba9b94b8997
|
41
|
* @brief XXX
|
jinu |
0:6ba9b94b8997
|
42
|
*/
|
jinu |
0:6ba9b94b8997
|
43
|
|
jinu |
0:6ba9b94b8997
|
44
|
#include <stdint.h>
|
jinu |
0:6ba9b94b8997
|
45
|
|
jinu |
0:6ba9b94b8997
|
46
|
#ifndef BLE_ENCODE_TRANSPORT_H__
|
jinu |
0:6ba9b94b8997
|
47
|
#define BLE_ENCODE_TRANSPORT_H__
|
jinu |
0:6ba9b94b8997
|
48
|
|
jinu |
0:6ba9b94b8997
|
49
|
/**@brief @ref ble_encode_transport_cmd_write API command mode definitions. */
|
jinu |
0:6ba9b94b8997
|
50
|
typedef enum
|
jinu |
0:6ba9b94b8997
|
51
|
{
|
jinu |
0:6ba9b94b8997
|
52
|
BLE_ENCODE_WRITE_MODE_RESP, /**< Command written includes a corresponding command response. */
|
jinu |
0:6ba9b94b8997
|
53
|
BLE_ENCODE_WRITE_MODE_NO_RESP, /**< Command written does not include a corresponding command response. */
|
jinu |
0:6ba9b94b8997
|
54
|
BLE_ENCODE_WRITE_MODE_MAX /**< Enumeration upper bound. */
|
jinu |
0:6ba9b94b8997
|
55
|
} ble_encode_cmd_write_mode_t;
|
jinu |
0:6ba9b94b8997
|
56
|
|
jinu |
0:6ba9b94b8997
|
57
|
/**@brief Command response callback function type.
|
jinu |
0:6ba9b94b8997
|
58
|
*
|
jinu |
0:6ba9b94b8997
|
59
|
* Callback function for decoding the possible command response output parameteres and copying them
|
jinu |
0:6ba9b94b8997
|
60
|
* to application and decoding the command response return code.
|
jinu |
0:6ba9b94b8997
|
61
|
*
|
jinu |
0:6ba9b94b8997
|
62
|
* @param[in] p_buffer Pointer to begin of command response buffer.
|
jinu |
0:6ba9b94b8997
|
63
|
* @param[in] length Length of data in bytes.
|
jinu |
0:6ba9b94b8997
|
64
|
*
|
jinu |
0:6ba9b94b8997
|
65
|
* @return Decoded command response return code.
|
jinu |
0:6ba9b94b8997
|
66
|
*/
|
jinu |
0:6ba9b94b8997
|
67
|
typedef uint32_t (*ble_command_resp_decode_callback_t)(const uint8_t * p_buffer, uint32_t length);
|
jinu |
0:6ba9b94b8997
|
68
|
|
jinu |
0:6ba9b94b8997
|
69
|
/**@brief Function for allocating TX command memory.
|
jinu |
0:6ba9b94b8997
|
70
|
*
|
jinu |
0:6ba9b94b8997
|
71
|
* @note If memory can't be acquired error check is executed as implies an error as not allowed by
|
jinu |
0:6ba9b94b8997
|
72
|
* the system design and must be fixed at compile time.
|
jinu |
0:6ba9b94b8997
|
73
|
*
|
jinu |
0:6ba9b94b8997
|
74
|
* @return Pointer to the begin of the buffer allocated.
|
jinu |
0:6ba9b94b8997
|
75
|
*/
|
jinu |
0:6ba9b94b8997
|
76
|
uint8_t * ble_encode_transport_tx_alloc(void);
|
jinu |
0:6ba9b94b8997
|
77
|
|
jinu |
0:6ba9b94b8997
|
78
|
/**@brief Function for freeing TX command memory.
|
jinu |
0:6ba9b94b8997
|
79
|
*
|
jinu |
0:6ba9b94b8997
|
80
|
* @note Memory management works in FIFO principle meaning that free order must match the alloc
|
jinu |
0:6ba9b94b8997
|
81
|
* order.
|
jinu |
0:6ba9b94b8997
|
82
|
* @note Does nothing if no TX command memory to be freed exists.
|
jinu |
0:6ba9b94b8997
|
83
|
*/
|
jinu |
0:6ba9b94b8997
|
84
|
void ble_encode_transport_tx_free(void);
|
jinu |
0:6ba9b94b8997
|
85
|
|
jinu |
0:6ba9b94b8997
|
86
|
/**@brief Function for writing a command.
|
jinu |
0:6ba9b94b8997
|
87
|
*
|
jinu |
0:6ba9b94b8997
|
88
|
* @note Attempt to have multiple commands to be in progress at same time will lead to error check
|
jinu |
0:6ba9b94b8997
|
89
|
* as not allowed by the system design.
|
jinu |
0:6ba9b94b8997
|
90
|
* @note Error check is executed for validating @ref p_buffer against NULL.
|
jinu |
0:6ba9b94b8997
|
91
|
* @note Error check is executed for validating @ref length against 0.
|
jinu |
0:6ba9b94b8997
|
92
|
* @note Error check is executed for validating @ref cmd_write_mode.
|
jinu |
0:6ba9b94b8997
|
93
|
* @note Error check is executed for validating @ref cmd_resp_decode_callback against NULL.
|
jinu |
0:6ba9b94b8997
|
94
|
*
|
jinu |
0:6ba9b94b8997
|
95
|
* @param[in] p_buffer Pointer to begin of command buffer.
|
jinu |
0:6ba9b94b8997
|
96
|
* @param[in] length Length of data in bytes.
|
jinu |
0:6ba9b94b8997
|
97
|
* @param[in] cmd_write_mode Command write mode see @ref
|
jinu |
0:6ba9b94b8997
|
98
|
* ble_command_resp_decode_callback_t for details.
|
jinu |
0:6ba9b94b8997
|
99
|
* @param[in] cmd_resp_decode_callback Command response callback.
|
jinu |
0:6ba9b94b8997
|
100
|
*/
|
jinu |
0:6ba9b94b8997
|
101
|
void ble_encode_transport_cmd_write(const uint8_t * p_buffer,
|
jinu |
0:6ba9b94b8997
|
102
|
uint32_t length,
|
jinu |
0:6ba9b94b8997
|
103
|
ble_encode_cmd_write_mode_t cmd_write_mode,
|
jinu |
0:6ba9b94b8997
|
104
|
ble_command_resp_decode_callback_t cmd_resp_decode_callback);
|
jinu |
0:6ba9b94b8997
|
105
|
|
jinu |
0:6ba9b94b8997
|
106
|
#endif // BLE_ENCODE_TRANSPORT_H__
|
jinu |
0:6ba9b94b8997
|
107
|
|
jinu |
0:6ba9b94b8997
|
108
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
109
|
|