libc.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <rtthread.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <sys/time.h>
  6. struct timeval _timevalue;
  7. static void libc_system_time_init()
  8. {
  9. rt_device_t device;
  10. time_t time;
  11. rt_tick_t tick;
  12. time = 0; tick = 0;
  13. device = rt_device_find("rtc");
  14. if (device != RT_NULL)
  15. {
  16. rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
  17. }
  18. tick = rt_tick_get();
  19. _timevalue.tv_sec = time;
  20. _timevalue.tv_usec = (1000000UL * tick)/RT_TICK_PER_SECOND;
  21. }
  22. void libc_system_init(const char* tty_name)
  23. {
  24. int fd;
  25. /* init console device */
  26. rt_console_init(tty_name);
  27. /* open console as stdin/stdout/stderr */
  28. fd = open("/dev/console", O_RDONLY, 0); /* for stdin */
  29. fd = open("/dev/console", O_WRONLY, 0); /* for stdout */
  30. fd = open("/dev/console", O_WRONLY, 0); /* for stderr */
  31. /* set PATH and HOME */
  32. putenv("PATH=/");
  33. putenv("HOME=/");
  34. }
  35. int libc_time_to_tick(const struct timespec *time)
  36. {
  37. int tick;
  38. tick = RT_WAITING_FOREVER;
  39. return tick;
  40. }