serial_bypass.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-11-20 zhujiale the first version
  9. */
  10. #ifndef __RTT_BYPASS_H__
  11. #define __RTT_BYPASS_H__
  12. #include <rtthread.h>
  13. #include <rttypes.h>
  14. #include <rtdevice.h>
  15. typedef rt_err_t(*bypass_function_t)(struct rt_serial_device* serial, char buf, void* data);
  16. #define RT_BYPASS_LEVEL_MAX 4
  17. #define RT_BYPASS_LEVEL_1 0
  18. #define RT_BYPASS_LEVEL_2 1
  19. #define RT_BYPASS_LEVEL_3 2
  20. #define RT_BYPASS_LEVEL_4 3
  21. #define RT_BYPASS_MAX_LEVEL 4
  22. /*The protect level can be register but can not be unregister we should use it carefully*/
  23. #define RT_BYPASS_PROTECT_LEVEL_1 10
  24. #define RT_BYPASS_PROTECT_LEVEL_2 11
  25. #define RT_BYPASS_PROTECT_LEVEL_3 12
  26. #define RT_BYPASS_PROTECT_LEVEL_4 13
  27. struct rt_serial_bypass_func {
  28. /*The function pointer of the bypassed data processing*/
  29. bypass_function_t bypass;
  30. /*The smaller the array of levels, the higher the priority of execution*/
  31. rt_uint8_t level;
  32. rt_list_t node;
  33. char name[RT_NAME_MAX];
  34. void* data;
  35. };
  36. struct rt_serial_bypass_head
  37. {
  38. rt_list_t head;
  39. struct rt_spinlock spinlock;
  40. };
  41. struct rt_serial_bypass {
  42. struct rt_work work;
  43. struct rt_spinlock spinlock;
  44. struct rt_workqueue* lower_workq;
  45. struct rt_serial_bypass_head* upper_h;
  46. struct rt_serial_bypass_head* lower_h;
  47. rt_mutex_t mutex;
  48. struct rt_ringbuffer* pipe;
  49. };
  50. int serial_bypass_list(int argc, char** argv);
  51. void rt_bypass_work_straight(struct rt_serial_device* serial);
  52. void rt_bypass_putchar(struct rt_serial_device* serial, rt_uint8_t ch);
  53. rt_size_t rt_bypass_getchar(struct rt_serial_device* serial, rt_uint8_t* ch);
  54. rt_err_t rt_bypass_upper_unregister(struct rt_serial_device* serial, rt_uint8_t level);
  55. rt_err_t rt_bypass_lower_unregister(struct rt_serial_device* serial, rt_uint8_t level);
  56. rt_err_t rt_bypass_upper_register(struct rt_serial_device* serial, const char* name, rt_uint8_t level, bypass_function_t func, void* data);
  57. rt_err_t rt_bypass_lower_register(struct rt_serial_device* serial, const char* name, rt_uint8_t level, bypass_function_t func, void* data);
  58. #endif