timer.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <sys/timer.h>
  4. #include "Wonx.h"
  5. #include "etc.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 = 0;
  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. default : Error("rtc_get_datetime", "Unknown parameter.");
  58. }
  59. printf("call : rtc_get_datetime() : return value = %d\n", (int)ret);
  60. fflush(stdout);
  61. return (ret);
  62. }
  63. void rtc_set_datetime_struct(void * buffer)
  64. {
  65. printf("call : rtc_set_datetime_struct() : buffer = %p\n", buffer);
  66. fflush(stdout);
  67. /* 未サポート */
  68. printf("call : rtc_set_datetime_struct() : not supported\n");
  69. printf("call : rtc_set_datetime_struct() : return value = none\n");
  70. fflush(stdout);
  71. return;
  72. }
  73. void rtc_get_datetime_struct(void * buffer)
  74. {
  75. time_t timer;
  76. struct tm * tblock;
  77. datetime_t * p;
  78. printf("call : rtc_get_datetime_struct() : buffer = %p\n", buffer);
  79. fflush(stdout);
  80. time(&timer);
  81. tblock = localtime(&timer);
  82. p = (datetime_t *)buffer;
  83. p->year = get_year(tblock);
  84. p->month = get_month(tblock);
  85. p->date = get_day(tblock);
  86. p->day_of_week = get_week(tblock);
  87. p->hour = get_hour(tblock);
  88. p->minute = get_minute(tblock);
  89. p->second = get_second(tblock);
  90. printf("call : rtc_get_datetime_struct() : return value = none\n");
  91. fflush(stdout);
  92. return;
  93. }
  94. void rtc_enable_alarm(int hour, int minute)
  95. {
  96. printf("call : rtc_enable_alarm() : hour = %d, minute = %d\n", hour, minute);
  97. fflush(stdout);
  98. /* 未サポート */
  99. printf("call : rtc_enable_alarm() : not supported\n");
  100. printf("call : rtc_enable_alarm() : return value = none\n");
  101. fflush(stdout);
  102. return;
  103. }
  104. void rtc_disable_alarm(void)
  105. {
  106. printf("call : rtc_disable_alarm() : \n");
  107. fflush(stdout);
  108. /* 未サポート */
  109. printf("call : rtc_disable_alarm() : not supported\n");
  110. printf("call : rtc_disable_alarm() : return value = none\n");
  111. fflush(stdout);
  112. return;
  113. }
  114. void timer_enable(int type, unsigned int auto_preset, unsigned int preset)
  115. {
  116. printf("call : timer_enable() : type = %d, auto_preset = %u, preset = %u\n",
  117. type, (int)auto_preset, (int)preset);
  118. fflush(stdout);
  119. /* 未サポート */
  120. printf("call : timer_enable() : not supported\n");
  121. printf("call : timer_enable() : return value = none\n");
  122. fflush(stdout);
  123. return;
  124. }
  125. void timer_disable(int type)
  126. {
  127. printf("call : timer_disable() : type = %d\n", type);
  128. fflush(stdout);
  129. /* 未サポート */
  130. printf("call : timer_disable() : not supported\n");
  131. printf("call : timer_disable() : return value = none\n");
  132. fflush(stdout);
  133. return;
  134. }
  135. unsigned int timer_get_count(int type)
  136. {
  137. unsigned int ret = 0;
  138. printf("call : timer_get_count() : type = %d\n", type);
  139. fflush(stdout);
  140. /* 未サポート */
  141. printf("call : timer_get_count() : not supported\n");
  142. printf("call : timer_get_count() : return value = %u\n", ret);
  143. fflush(stdout);
  144. return (ret);
  145. }