echo.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <finsh.h>
  40. void rym_cat_vcom(void)
  41. {
  42. extern rt_err_t rym_cat_to_dev(rt_device_t idev, rt_device_t odev);
  43. rt_device_t idev, odev;
  44. rt_thread_delay(RT_TICK_PER_SECOND*10);
  45. idev = rt_device_find("uart1");
  46. if (!idev)
  47. {
  48. rt_kprintf("could not find idev\n");
  49. }
  50. odev = rt_device_find("vcom");
  51. if (!odev)
  52. {
  53. rt_kprintf("could not find odev\n");
  54. }
  55. rym_cat_to_dev(idev, odev);
  56. }
  57. FINSH_FUNCTION_EXPORT(rym_cat_vcom, test the YModem);
  58. #endif