echo.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <ymodem.h>
  10. static rt_device_t _odev;
  11. static enum rym_code _rym_echo_data(
  12. struct rym_ctx *ctx,
  13. rt_uint8_t *buf,
  14. rt_size_t len)
  15. {
  16. rt_device_write(_odev, 0, buf, len);
  17. return RYM_CODE_ACK;
  18. }
  19. rt_err_t rym_cat_to_dev(rt_device_t idev, rt_device_t odev)
  20. {
  21. struct rym_ctx rctx;
  22. rt_err_t res;
  23. _odev = odev;
  24. rt_kprintf("entering RYM mode\n");
  25. odev->flag &= ~RT_DEVICE_FLAG_STREAM;
  26. res = rt_device_open(odev, 0);
  27. if (res != RT_EOK)
  28. {
  29. rt_kprintf("open output device error: 0x%x", -res);
  30. return res;
  31. }
  32. res = rym_recv_on_device(&rctx, idev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
  33. RT_NULL, _rym_echo_data, RT_NULL, 1000);
  34. rt_device_close(_odev);
  35. rt_kprintf("leaving RYM mode with code %X\n", res);
  36. return res;
  37. }
  38. #ifdef RT_USING_FINSH
  39. void rym_cat_vcom(void)
  40. {
  41. extern rt_err_t rym_cat_to_dev(rt_device_t idev, rt_device_t odev);
  42. rt_device_t idev, odev;
  43. rt_thread_delay(RT_TICK_PER_SECOND*10);
  44. idev = rt_device_find("uart1");
  45. if (!idev)
  46. {
  47. rt_kprintf("could not find idev\n");
  48. }
  49. odev = rt_device_find("vcom");
  50. if (!odev)
  51. {
  52. rt_kprintf("could not find odev\n");
  53. }
  54. rym_cat_to_dev(idev, odev);
  55. }
  56. #endif