diff options
author | Felix Fietkau <nbd@nbd.name> | 2023-11-27 17:44:33 +0300 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2023-11-27 20:30:01 +0300 |
commit | d4c3066e7c5efa5f395c21db77609516d386cbf8 (patch) | |
tree | 405d0aaa23f7207eb9d2f0c891ac2fb54bca8659 /udebug-priv.h | |
parent | b3fa3d92e3ebae9b224a0111427d6bdd8b869399 (diff) |
udebug: add udebug library code
Copied and adapted from udebug.git
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'udebug-priv.h')
-rw-r--r-- | udebug-priv.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/udebug-priv.h b/udebug-priv.h new file mode 100644 index 0000000..9e43ddf --- /dev/null +++ b/udebug-priv.h @@ -0,0 +1,54 @@ +/* + * udebug - debug ring buffer library + * + * Copyright (C) 2023 Felix Fietkau <nbd@nbd.name> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef __UDEBUG_UTIL_H +#define __UDEBUG_UTIL_H + +#include "blobmsg.h" +#include "udebug.h" +#include "udebug-proto.h" + +#define UDEBUG_TIMEOUT 1000 + +__hidden int udebug_buf_open(struct udebug_buf *buf, int fd, uint32_t ring_size, uint32_t data_size); +__hidden struct udebug_client_msg *__udebug_poll(struct udebug *ctx, int *fd, bool wait); +__hidden void udebug_send_msg(struct udebug *ctx, struct udebug_client_msg *msg, + struct blob_attr *meta, int fd); + +static inline int32_t u32_sub(uint32_t a, uint32_t b) +{ + return a - b; +} + +static inline int32_t u32_max(uint32_t a, uint32_t b) +{ + return u32_sub(a, b) > 0 ? a : b; +} + +static inline void u32_set(void *ptr, uint32_t val) +{ + volatile uint32_t *v = ptr; + *v = val; +} + +static inline uint32_t u32_get(void *ptr) +{ + volatile uint32_t *v = ptr; + return *v; +} + +#endif |