Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
ca821x-posix.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Cascoda Ltd.
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 are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
43 #ifndef CA821X_POSIX_H
44 #define CA821X_POSIX_H 1
45 
47 #include "ca821x_api.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
81 ca_error ca821x_util_init(struct ca821x_dev *pDeviceRef,
82  ca821x_errorhandler errorHandler,
83  union ca821x_util_init_extra_arg arg);
84 
110 ca_error ca821x_util_init_path(struct ca821x_dev *pDeviceRef,
111  ca821x_errorhandler errorHandler,
112  enum ca821x_exchange_type exchangeType,
113  const char *path);
114 
124 void ca821x_util_deinit(struct ca821x_dev *pDeviceRef);
125 
138 ca_error ca821x_util_enumerate(util_device_found aCallback, bool enumerate_uart, void *aContext);
139 
151 ca_error ca821x_util_reset(struct ca821x_dev *pDeviceRef);
152 
171 
188 
199 
213 
221 ca_error exchange_wait_send_complete(time_t timeout_s, struct ca821x_dev *pDeviceRef);
222 
238 ca_error exchange_user_command(uint8_t cmdid, uint8_t cmdlen, uint8_t *payload, struct ca821x_dev *pDeviceRef);
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif //CA821X_POSIX_H
245 
Various types used by the cascoda posix api.
void(* util_device_found)(struct ca_device_info *aDeviceInfo, void *aContext)
Function type for handling enumerated devices when finding them.
Definition: ca821x-types.h:241
ca821x_exchange_type
Enumeration for identifying the underlying exchange interface type.
Definition: ca821x-types.h:166
ca_error(* exchange_user_callback)(const uint8_t *buf, size_t len, struct ca821x_dev *pDeviceRef)
Optional Exchange User Callback.
Definition: ca821x-types.h:75
ca_error(* ca821x_errorhandler)(ca_error error, struct ca821x_dev *pDeviceRef)
Error callback.
Definition: ca821x-types.h:61
The main ca821x-api include file.
ca_error
Cascoda error type.
Definition: ca821x_error.h:51
ca_error exchange_user_command(uint8_t cmdid, uint8_t cmdlen, uint8_t *payload, struct ca821x_dev *pDeviceRef)
Sends a user-defined command over the connected interface.
Definition: ca821x-generic-exchange.c:293
void ca821x_util_deinit(struct ca821x_dev *pDeviceRef)
Generic function to deinitialise an initialised ca821x device.
Definition: ca821x-posix-util.c:148
ca_error ca821x_util_init(struct ca821x_dev *pDeviceRef, ca821x_errorhandler errorHandler, union ca821x_util_init_extra_arg arg)
Generic function to initialise an available ca821x device.
Definition: ca821x-posix-util.c:72
ca_error ca821x_util_reset(struct ca821x_dev *pDeviceRef)
Generic function to attempt a hard reset of the ca821x chip.
Definition: ca821x-posix-util.c:286
ca_error exchange_register_user_callback(exchange_user_callback callback, struct ca821x_dev *pDeviceRef)
Registers the callback to call for any non-ca821x commands that are sent over the interface.
Definition: ca821x-generic-exchange.c:261
ca_error ca821x_util_start_upstream_dispatch_worker()
Start the upstream_dispatch worker, which asynchronously calls the message callbacks (such as MCPS_DA...
Definition: ca821x-generic-exchange.c:136
ca_error ca821x_util_enumerate(util_device_found aCallback, bool enumerate_uart, void *aContext)
Function to enumerate all of the connected devices, calling aCallback with a struct describing each o...
Definition: ca821x-posix-util.c:274
ca_error ca821x_util_dispatch_poll()
Generic function to poll the receive queue and call callbacks for received commands.
Definition: ca821x-generic-exchange.c:99
ca_error exchange_wait_send_complete(time_t timeout_s, struct ca821x_dev *pDeviceRef)
Query whether the given exchange has any messages pending being sent in its send queue.
Definition: ca821x-generic-exchange.c:273
ca_error ca821x_util_init_path(struct ca821x_dev *pDeviceRef, ca821x_errorhandler errorHandler, enum ca821x_exchange_type exchangeType, const char *path)
Generic function to initialise a specific device as found via ca821x_util_enumerate or other mechanis...
Definition: ca821x-posix-util.c:105
ca_error ca821x_util_stop_upstream_dispatch_worker()
Stop the upstream_dispatch worker, so callbacks will no longer be triggered from a separate thread.
Definition: ca821x-generic-exchange.c:157
CA-821x Device reference struct.
Definition: ca821x_api.h:123
Extra argument to the function ca821x_util_init().
Definition: ca821x-types.h:157