console.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * 2021-11-11 GuEe-GUI the first version
  9. */
  10. #include <rtthread.h>
  11. #include <virtio_console.h>
  12. int console_init()
  13. {
  14. rt_err_t status = RT_EOK;
  15. rt_device_t device = rt_device_find("virtio-console0");
  16. if (device != RT_NULL && rt_device_open(device, 0) == RT_EOK)
  17. {
  18. /* Create vport0p1 */
  19. status = rt_device_control(device, VIRTIO_DEVICE_CTRL_CONSOLE_PORT_CREATE, RT_NULL);
  20. }
  21. if (device != RT_NULL)
  22. {
  23. rt_device_close(device);
  24. }
  25. return status;
  26. }
  27. INIT_ENV_EXPORT(console_init);
  28. #ifdef FINSH_USING_MSH
  29. static int console(int argc, char **argv)
  30. {
  31. rt_err_t result = RT_EOK;
  32. if (argc > 1)
  33. {
  34. if (!rt_strcmp(argv[1], "set"))
  35. {
  36. rt_kprintf("console change to %s\n", argv[2]);
  37. rt_console_set_device(argv[2]);
  38. finsh_set_device(argv[2]);
  39. }
  40. else
  41. {
  42. rt_kprintf("Unknown command. Please enter 'console' for help\n");
  43. result = -RT_ERROR;
  44. }
  45. }
  46. else
  47. {
  48. rt_kprintf("Usage: \n");
  49. rt_kprintf("console set <name> - change console by name\n");
  50. result = -RT_ERROR;
  51. }
  52. return result;
  53. }
  54. MSH_CMD_EXPORT(console, set console name);
  55. #endif /* FINSH_USING_MSH */