console.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. static 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. static int console(int argc, char **argv)
  29. {
  30. rt_err_t result = RT_EOK;
  31. if (argc > 1)
  32. {
  33. if (!rt_strcmp(argv[1], "set"))
  34. {
  35. rt_kprintf("console change to %s\n", argv[2]);
  36. rt_console_set_device(argv[2]);
  37. }
  38. else
  39. {
  40. rt_kprintf("Unknown command. Please enter 'console' for help\n");
  41. result = -RT_ERROR;
  42. }
  43. }
  44. else
  45. {
  46. rt_kprintf("Usage: \n");
  47. rt_kprintf("console set <name> - change console by name\n");
  48. result = -RT_ERROR;
  49. }
  50. return result;
  51. }
  52. MSH_CMD_EXPORT(console, set console name);