1 #include <ymodem.h> 2 3 static rt_device_t _odev; 4 5 static enum rym_code _rym_echo_data( 6 struct rym_ctx *ctx, 7 rt_uint8_t *buf, 8 rt_size_t len) 9 { 10 rt_device_write(_odev, 0, buf, len); 11 return RYM_CODE_ACK; 12 } 13 14 rt_err_t rym_cat_to_dev(rt_device_t idev, rt_device_t odev) 15 { 16 struct rym_ctx rctx; 17 rt_err_t res; 18 _odev = odev; 19 20 rt_kprintf("entering RYM mode\n"); 21 odev->flag &= ~RT_DEVICE_FLAG_STREAM; 22 res = rt_device_open(odev, 0); 23 if (res != RT_EOK) 24 { 25 rt_kprintf("open output device error: 0x%x", -res); 26 return res; 27 } 28 res = rym_recv_on_device(&rctx, idev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX, 29 RT_NULL, _rym_echo_data, RT_NULL, 1000); 30 rt_device_close(_odev); 31 rt_kprintf("leaving RYM mode with code %X\n", res); 32 return res; 33 } 34 35 #ifdef RT_USING_FINSH 36 #include <finsh.h> 37 void rym_cat_vcom(void) 38 { 39 extern rt_err_t rym_cat_to_dev(rt_device_t idev, rt_device_t odev); 40 rt_device_t idev, odev; 41 42 rt_thread_delay(RT_TICK_PER_SECOND*10); 43 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 55 rym_cat_to_dev(idev, odev); 56 } 57 FINSH_FUNCTION_EXPORT(rym_cat_vcom, test the YModem); 58 #endif 59 60