udebug-priv.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "blobmsg.h"
  21. #include "udebug.h"
  22. #include "udebug-proto.h"
  23. #define UDEBUG_TIMEOUT 1000
  24. __hidden int udebug_buf_open(struct udebug_buf *buf, int fd, uint32_t ring_size, uint32_t data_size);
  25. __hidden struct udebug_client_msg *
  26. udebug_send_and_wait(struct udebug *ctx, struct udebug_client_msg *msg, int *rfd);
  27. static inline int32_t u32_sub(uint32_t a, uint32_t b)
  28. {
  29. return a - b;
  30. }
  31. static inline int32_t u32_max(uint32_t a, uint32_t b)
  32. {
  33. return u32_sub(a, b) > 0 ? a : b;
  34. }
  35. static inline void u32_set(void *ptr, uint32_t val)
  36. {
  37. volatile uint32_t *v = ptr;
  38. *v = val;
  39. }
  40. static inline uint32_t u32_get(void *ptr)
  41. {
  42. volatile uint32_t *v = ptr;
  43. return *v;
  44. }
  45. #endif