libubox
C utility functions for OpenWrt.
udebug-priv.h
Go to the documentation of this file.
1 /*
2  * udebug - debug ring buffer library
3  *
4  * Copyright (C) 2023 Felix Fietkau <nbd@nbd.name>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 #ifndef __UDEBUG_UTIL_H
19 #define __UDEBUG_UTIL_H
20 
21 #include "blobmsg.h"
22 #include "udebug.h"
23 #include "udebug-proto.h"
24 
25 #define UDEBUG_TIMEOUT 1000
26 
27 __hidden int udebug_buf_open(struct udebug_buf *buf, int fd, uint32_t ring_size, uint32_t data_size);
29 udebug_send_and_wait(struct udebug *ctx, struct udebug_client_msg *msg, int *rfd);
30 
31 static inline int32_t u32_sub(uint32_t a, uint32_t b)
32 {
33  return a - b;
34 }
35 
36 static inline int32_t u32_max(uint32_t a, uint32_t b)
37 {
38  return u32_sub(a, b) > 0 ? a : b;
39 }
40 
41 static inline void u32_set(void *ptr, uint32_t val)
42 {
43  volatile uint32_t *v = ptr;
44  *v = val;
45 }
46 
47 static inline uint32_t u32_get(void *ptr)
48 {
49  volatile uint32_t *v = ptr;
50  return *v;
51 }
52 
53 #endif
static struct blob_buf b
Definition: jshn.c:40
Definition: udebug.h:102
int uint32_t ring_size
Definition: udebug-priv.h:27
int uint32_t uint32_t data_size
Definition: udebug-priv.h:27
struct udebug_client_msg int * rfd
Definition: udebug-priv.h:29
static uint32_t u32_get(void *ptr)
Definition: udebug-priv.h:47
int fd
Definition: udebug-priv.h:27
static int32_t u32_sub(uint32_t a, uint32_t b)
Definition: udebug-priv.h:31
struct udebug_client_msg * msg
Definition: udebug-priv.h:29
static int32_t u32_max(uint32_t a, uint32_t b)
Definition: udebug-priv.h:36
static void u32_set(void *ptr, uint32_t val)
Definition: udebug-priv.h:41
struct udebug_client_msg * udebug_send_and_wait(struct udebug *ctx, struct udebug_client_msg *msg, int *rfd)
Definition: udebug.c:810
int udebug_buf_open(struct udebug_buf *buf, int fd, uint32_t ring_size, uint32_t data_size)
Definition: udebug.c:424
#define __hidden
Definition: utils.h:227