rt_null.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2011-2023, Shanghai Real-Thread Electronic Technology Co.,Ltd
  3. *
  4. * Change Logs:
  5. * Date Author Notes
  6. * 2020-12-03 quanzhao the first version
  7. */
  8. #include <time.h>
  9. #include <string.h>
  10. #include <rtthread.h>
  11. static struct rt_device null_dev;
  12. static rt_ssize_t null_read (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
  13. {
  14. return 0;
  15. }
  16. static rt_ssize_t null_write (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
  17. {
  18. return size;
  19. }
  20. static rt_err_t null_control (rt_device_t dev, int cmd, void *args)
  21. {
  22. return RT_EOK;
  23. }
  24. #ifdef RT_USING_DEVICE_OPS
  25. const static struct rt_device_ops null_ops =
  26. {
  27. RT_NULL,
  28. RT_NULL,
  29. RT_NULL,
  30. null_read,
  31. null_write,
  32. null_control
  33. };
  34. #endif
  35. int null_device_init(void)
  36. {
  37. static rt_bool_t init_ok = RT_FALSE;
  38. if (init_ok)
  39. {
  40. return 0;
  41. }
  42. RT_ASSERT(!rt_device_find("null"));
  43. null_dev.type = RT_Device_Class_Miscellaneous;
  44. #ifdef RT_USING_DEVICE_OPS
  45. null_dev.ops = &null_ops;
  46. #else
  47. null_dev.init = RT_NULL;
  48. null_dev.open = RT_NULL;
  49. null_dev.close = RT_NULL;
  50. null_dev.read = null_read;
  51. null_dev.write = null_write;
  52. null_dev.control = null_control;
  53. #endif
  54. /* no private */
  55. null_dev.user_data = RT_NULL;
  56. rt_device_register(&null_dev, "null", RT_DEVICE_FLAG_RDWR);
  57. init_ok = RT_TRUE;
  58. return 0;
  59. }
  60. INIT_DEVICE_EXPORT(null_device_init);