rtc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef _DEV_RTC_H_
  2. #define _DEV_RTC_H_
  3. /*
  4. * Copyright (C) 2005-2006 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log$
  36. * Revision 1.2 2008/08/11 06:59:59 haraldkipp
  37. * BSD types replaced by stdint types (feature request #1282721).
  38. *
  39. * Revision 1.1 2006/10/05 17:18:49 haraldkipp
  40. * Hardware independant RTC layer added.
  41. *
  42. */
  43. #include <sys/types.h>
  44. #include <stdint.h>
  45. #include <time.h>
  46. #define RTC_STATUS_PF 0x00000001
  47. #define RTC_STATUS_AL0 0x00000020
  48. #define RTC_STATUS_AL1 0x00000040
  49. #define RTC_ALARM_SECOND 0x00000001
  50. #define RTC_ALARM_MINUTE 0x00000002
  51. #define RTC_ALARM_HOUR 0x00000004
  52. #define RTC_ALARM_MDAY 0x00000008
  53. #define RTC_ALARM_MONTH 0x00000010
  54. #define RTC_ALARM_WDAY 0x00000080
  55. #define RTC_ALARM_YEAR 0x00000100
  56. #define RTC_ALARM_YDAY 0x00000200
  57. /*!
  58. * \brief Convert binary coded decimal to binary value.
  59. */
  60. #define BCD2BIN(x) ((((uint8_t)(x)) >> 4) * 10 + ((x) & 0x0F))
  61. /*!
  62. * \brief Convert binary to binary coded decimal value.
  63. */
  64. #define BIN2BCD(x) (((((uint8_t)(x)) / 10) << 4) + (x) % 10)
  65. /*!
  66. * \brief RTC device type.
  67. */
  68. typedef struct _NUTRTC NUTRTC;
  69. /*!
  70. * \brief RTC device structure.
  71. */
  72. struct _NUTRTC {
  73. void *dcb;
  74. int (*rtc_init) (NUTRTC *rtc);
  75. int (*rtc_gettime) (NUTRTC *rtc, struct _tm *);
  76. int (*rtc_settime) (NUTRTC *rtc, const struct _tm *);
  77. int (*rtc_getalarm) (NUTRTC *rtc, int idx, struct _tm *, int *);
  78. int (*rtc_setalarm) (NUTRTC *rtc, int idx, const struct _tm *, int);
  79. int (*rtc_getstatus) (NUTRTC *rtc, uint32_t *);
  80. int (*rtc_clrstatus) (NUTRTC *rtc, uint32_t);
  81. HANDLE alarm;
  82. };
  83. extern int NutRegisterRtc(NUTRTC *rtc);
  84. extern int NutRtcGetTime(struct _tm *tm);
  85. extern int NutRtcSetTime(const struct _tm *tm);
  86. extern int NutRtcGetAlarm(int idx, struct _tm *tm, int *aflags);
  87. extern int NutRtcSetAlarm(int idx, const struct _tm *tm, int aflags);
  88. extern int NutRtcGetStatus(uint32_t *sflags);
  89. extern int NutRtcClearStatus(uint32_t sflags);
  90. #endif