rtc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 EGNITE SOFTWARE GMBH 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 EGNITE
  23. * SOFTWARE GMBH 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: rtc.h,v $
  36. * Revision 1.1 2006/10/05 17:18:49 haraldkipp
  37. * Hardware independant RTC layer added.
  38. *
  39. */
  40. #include <sys/types.h>
  41. #include <time.h>
  42. #define RTC_STATUS_PF 0x00000001
  43. #define RTC_STATUS_AL0 0x00000020
  44. #define RTC_STATUS_AL1 0x00000040
  45. #define RTC_ALARM_SECOND 0x00000001
  46. #define RTC_ALARM_MINUTE 0x00000002
  47. #define RTC_ALARM_HOUR 0x00000004
  48. #define RTC_ALARM_MDAY 0x00000008
  49. #define RTC_ALARM_MONTH 0x00000010
  50. #define RTC_ALARM_WDAY 0x00000080
  51. /*!
  52. * \brief Convert binary coded decimal to binary value.
  53. */
  54. #define BCD2BIN(x) ((((u_char)(x)) >> 4) * 10 + ((x) & 0x0F))
  55. /*!
  56. * \brief Convert binary to binary coded decimal value.
  57. */
  58. #define BIN2BCD(x) (((((u_char)(x)) / 10) << 4) + (x) % 10)
  59. /*!
  60. * \brief RTC device type.
  61. */
  62. typedef struct _NUTRTC NUTRTC;
  63. /*!
  64. * \brief RTC device structure.
  65. */
  66. struct _NUTRTC {
  67. int (*rtc_init) (void);
  68. int (*rtc_gettime) (struct _tm *);
  69. int (*rtc_settime) (CONST struct _tm *);
  70. int (*rtc_getalarm) (int idx, struct _tm *, int *);
  71. int (*rtc_setalarm) (int idx, CONST struct _tm *, int);
  72. int (*rtc_getstatus) (u_long *);
  73. int (*rtc_clrstatus) (u_long);
  74. };
  75. __BEGIN_DECLS
  76. /* Prototypes */
  77. extern int NutRegisterRtc(NUTRTC *rtc);
  78. extern int NutRtcGetTime(struct _tm *tm);
  79. extern int NutRtcSetTime(CONST struct _tm *tm);
  80. extern int NutRtcGetAlarm(int idx, struct _tm *tm, int *aflags);
  81. extern int NutRtcSetAlarm(int idx, CONST struct _tm *tm, int aflags);
  82. extern int NutRtcGetStatus(u_long *sflags);
  83. extern int NutRtcClearStatus(u_long sflags);
  84. __END_DECLS
  85. /* End of prototypes */
  86. #endif