rtc_timer_wdt_test.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <sys/mman.h>
  7. #include <sys/time.h>
  8. #include <unistd.h>
  9. #include <sys/ioctl.h>
  10. #include <string.h>
  11. #include <signal.h>
  12. #include <linux/rtc.h>
  13. #include "ftcfg.h"
  14. #include "ftypes.h"
  15. #include "utils.h"
  16. #include "ark1668ft.h"
  17. int g_exit = 0;
  18. int fd_rtc = -1;
  19. int g_result = 0;
  20. unsigned int *wdtbase = NULL;
  21. unsigned int wdtval1, wdtval2;
  22. struct rtc_time rt1, rt2;
  23. void timer_handler(int sig)
  24. {
  25. int rtdiff, wdtdiff;
  26. if (ioctl(fd_rtc, RTC_RD_TIME, &rt2) < 0) {
  27. printf("read rtc time err.\n");
  28. g_exit = 1;
  29. return;
  30. }
  31. if (rt2.tm_sec >= rt1.tm_sec)
  32. rtdiff = rt2.tm_sec - rt1.tm_sec;
  33. else
  34. rtdiff = rt2.tm_sec + 60 - rt1.tm_sec;
  35. wdtval2 = *(wdtbase + 3);
  36. if (wdtval1 >= wdtval2)
  37. wdtdiff = wdtval1 - wdtval2;
  38. else
  39. wdtdiff = wdtval1 + *(wdtbase + 2) - wdtval2;
  40. printf("rtdiff = %d, wdtdiff=%d,\n", rtdiff, wdtdiff);
  41. if (rtdiff > 0 && rtdiff < 4 && wdtdiff > 8500 && wdtdiff < 9000)
  42. g_result = 1;
  43. g_exit = 1;
  44. }
  45. void *rtc_timer_wdt_test_thread(void *arg)
  46. {
  47. struct ft_runtime *rt = (struct ft_runtime *)arg;
  48. struct rtc_time dt;
  49. signal(SIGALRM, timer_handler);
  50. alarm(2);
  51. fd_rtc = open("/dev/rtc0", O_RDWR | O_SYNC);
  52. if (fd_rtc < 0) {
  53. printf("open rtc device fail.\n");
  54. goto err;
  55. }
  56. if (ioctl(fd_rtc, RTC_RD_TIME, &rt1) < 0) {
  57. printf("read rtc tim err.\n");
  58. goto err;
  59. }
  60. wdtbase = map_phy_memory(0xe4b00000, 0x100, 1);
  61. if (wdtbase == NULL) {
  62. printf("wdt reg map fail.\n");
  63. goto err;
  64. }
  65. wdtval1 = *(wdtbase + 3);
  66. while(!g_exit) {
  67. usleep(100000);
  68. }
  69. if (!g_result)
  70. goto err;
  71. unmap_phy_memory(wdtbase, 0x100);
  72. close(fd_rtc);
  73. rt->finish = 1;
  74. rt->pass = 1;
  75. return (void*)-1;
  76. err:
  77. if (wdtbase)
  78. unmap_phy_memory(wdtbase, 0x100);
  79. if (fd_rtc > 0)
  80. close(fd_rtc);
  81. rt->finish = 1;
  82. return (void*)-1;
  83. }