aboutsummaryrefslogtreecommitdiff
path: root/software/inc/int/dcf77.h
blob: 2d79cdd650ea0842d0fbdb1dea12a7648ce0a475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef CLOCK_H
#define CLOCK_H
  /* this dcf77-module relies on a accuarate clock (crystal) for receiving
   * the dcf-signal. therefor the clock is going to work as expected,
   * even with no dcf77-signal available.
   * receivement is automatically turned on, if the avr is connected to the
   * signal via INT0. if there is no signal the clock will not be set (K.I.S.S.)
   *
   */
  #include <avr/io.h>
  #include <avr/interrupt.h>
  #include <stdint.h>

  #define INT0_CONTROL       MCUCR
  // #define INT0_FALLING_EDGE  0x02
  // #define INT0_RISING_EDGE   0x03
  #define INT0_FALLING_EDGE  (1<<ISC01)
  #define INT0_RISING_EDGE   (1<<ISC01 | 1<<ISC00)
  #define INT0_EDGE_ANY      (1<<ISC00)

  typedef struct
  {
    volatile unsigned char bit : 1;
  } Bit;

  typedef struct
  {
    uint16_t  h;  // hour
    uint16_t  m;  // minute
    uint16_t  s;  // second
    uint16_t ms;  // milli second
    uint8_t  yy;  // year
    uint8_t  mm;  // month
    uint8_t  dd;  // day
    uint8_t  wd;  // weekday
  } Time;

  typedef enum
  {
    DCF_FIRST   = 0,  // start of a new minute (note: always 0)
    DCF_WEATHER = 14, // proprietary :-(
    DCF_ANTENNA = 15, // 0: normal, 1: replacement
    DCF_DST     = 16, // daylight saving time: this hour new time...
    DCF_MEZ     = 17, // 'summer-time'
    DCF_MESZ    = 18, // 'winter-time'
    DCF_DBLSEC  = 19, // one extra second gonna be inserted
    DCF_START   = 20, // begin of time-info (note: always 1)
    DCF_MIN     = 21, // 7 bit
    DCF_MINP    = 28, // parity bit for minutes
    DCF_HOUR    = 29, // 6 bit
    DCF_HOURP   = 35, // parity bit for hours
    DCF_DAY     = 36, // 6 bit
    DCF_WEEKDAY = 42, // 3 bit
    DCF_MONTH   = 45, // 5 bit
    DCF_YEAR    = 50, // 8 bit
    DCF_DATEP   = 58  // parity bit for date
  } DCF;

  volatile Bit dcf77[60];
  volatile uint8_t dcf77_bit;
  volatile Time t_current;
  volatile uint16_t interval;

  /// void getBits(volatile unsigned char* target, const DCF start, const char len, const DCF parity);
  /// void set_dcf_value();
  /// void interrupts_init();

#endif
..