timer.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <sys/timer.h>
  4. #include "wonx.h"
  5. #include "WonxDisplay.h"
  6. typedef struct {
  7. unsigned char year;
  8. unsigned char month;
  9. unsigned char date;
  10. unsigned char day_of_week;
  11. unsigned char hour;
  12. unsigned char minute;
  13. unsigned char second;
  14. } datetime_t;
  15. /* int tm_year; year - 1900 */
  16. static int get_year(struct tm * tblock) { return (tblock->tm_year - 100); }
  17. /* int tm_mon; month of year (0-11) */
  18. static int get_month(struct tm * tblock) { return (tblock->tm_mon + 1); }
  19. /* int tm_mday; day of month (1-31) */
  20. static int get_day(struct tm * tblock) { return (tblock->tm_mday); }
  21. /* int tm_wday; day of week (Sunday = 0) */
  22. static int get_week(struct tm * tblock) { return (tblock->tm_wday); }
  23. /* int tm_hour; hours (0 - 23) */
  24. static int get_hour(struct tm * tblock) { return (tblock->tm_hour); }
  25. /* int tm_min; minutes (0 - 59) */
  26. static int get_minute(struct tm * tblock) { return (tblock->tm_min); }
  27. /* int tm_sec; seconds (0 - 60) */
  28. static int get_second(struct tm * tblock) { return (tblock->tm_sec); }
  29. void rtc_set_datetime(int field, unsigned int value)
  30. {
  31. printf("call : rtc_set_datetime() : field = %d, value = %d\n",
  32. field, (int)value);
  33. fflush(stdout);
  34. /* 未サポート */
  35. printf("call : rtc_set_datetime() : not supported\n");
  36. printf("call : rtc_set_datetime() : return value = none\n");
  37. fflush(stdout);
  38. return;
  39. }
  40. unsigned int rtc_get_datetime(int field)
  41. {
  42. unsigned int ret;
  43. time_t timer;
  44. struct tm * tblock;
  45. printf("call : rtc_get_datetime() : field = %d\n", field);
  46. fflush(stdout);
  47. time(&timer);
  48. tblock = localtime(&timer);
  49. switch (field) {
  50. case RTC_YEAR : ret = get_year( tblock); break;
  51. case RTC_MONTH : ret = get_month( tblock); break;
  52. case RTC_DATE : ret = get_day( tblock); break;
  53. case RTC_DAY_OF_WEEK : ret = get_week( tblock); break;
  54. case RTC_HOUR : ret = get_hour( tblock); break;
  55. case RTC_MIN : ret = get_minute(tblock); break;
  56. case RTC_SEC : ret = get_second(tblock); break;
  57. }
  58. printf("call : rtc_get_datetime() : return value = %d\n", (int)ret);
  59. fflush(stdout);
  60. return (ret);
  61. }
  62. void rtc_set_datetime_struct(void * buffer)
  63. {
  64. printf("call : rtc_set_datetime_struct() : buffer = %p\n", buffer);
  65. fflush(stdout);
  66. /* 未サポート */
  67. printf("call : rtc_set_datetime_struct() : not supported\n");
  68. printf("call : rtc_set_datetime_struct() : return value = none\n");
  69. fflush(stdout);
  70. return;
  71. }
  72. void rtc_get_datetime_struct(void * buffer)
  73. {
  74. time_t timer;
  75. struct tm * tblock;
  76. datetime_t * p;
  77. printf("call : rtc_get_datetime_struct() : buffer = %p\n", buffer);
  78. fflush(stdout);
  79. time(&timer);
  80. tblock = localtime(&timer);
  81. p = (datetime_t *)buffer;
  82. p->year = get_year(tblock);
  83. p->month = get_month(tblock);
  84. p->date = get_day(tblock);
  85. p->day_of_week = get_week(tblock);
  86. p->hour = get_hour(tblock);
  87. p->minute = get_minute(tblock);
  88. p->second = get_second(tblock);
  89. printf("call : rtc_get_datetime_struct() : return value = none\n");
  90. fflush(stdout);
  91. return;
  92. }
  93. void rtc_enable_alarm(int hour, int minute)
  94. {
  95. printf("call : rtc_enable_alarm() : hour = %d, minute = %d\n", hour, minute);
  96. fflush(stdout);
  97. /* 未サポート */
  98. printf("call : rtc_enable_alarm() : not supported\n");
  99. printf("call : rtc_enable_alarm() : return value = none\n");
  100. fflush(stdout);
  101. return;
  102. }
  103. void rtc_disable_alarm(void)
  104. {
  105. printf("call : rtc_disable_alarm() : \n");
  106. fflush(stdout);
  107. /* 未サポート */
  108. printf("call : rtc_disable_alarm() : not supported\n");
  109. printf("call : rtc_disable_alarm() : return value = none\n");
  110. fflush(stdout);
  111. return;
  112. }
  113. void timer_enable(int type, unsigned int auto_preset, unsigned int preset)
  114. {
  115. printf("call : timer_enable() : type = %d, auto_preset = %u, preset = %u\n",
  116. type, (int)auto_preset, (int)preset);
  117. fflush(stdout);
  118. /* 未サポート */
  119. printf("call : timer_enable() : not supported\n");
  120. printf("call : timer_enable() : return value = none\n");
  121. fflush(stdout);
  122. return;
  123. }
  124. void timer_disable(int type)
  125. {
  126. printf("call : timer_disable() : type = %d\n", type);
  127. fflush(stdout);
  128. /* 未サポート */
  129. printf("call : timer_disable() : not supported\n");
  130. printf("call : timer_disable() : return value = none\n");
  131. fflush(stdout);
  132. return;
  133. }
  134. unsigned int timer_get_count(int type)
  135. {
  136. unsigned int ret = 0;
  137. printf("call : timer_get_count() : type = %d\n", type);
  138. fflush(stdout);
  139. /* 未サポート */
  140. printf("call : timer_get_count() : not supported\n");
  141. printf("call : timer_get_count() : return value = %u\n", ret);
  142. fflush(stdout);
  143. return;
  144. }