Debian Codegraph @

extras/ds1307/ds1307.h

raw
1 /*
2 Copyright (C) 2006 T. Scott Dattalo
3 Copyright (C) 2010 Roy R Rankin
4
5 This file is part of gpsim.
6
7 gpsim is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 gpsim is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with gpsim; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 #ifndef EXTRAS_DS1307_DS1307_H_
24 #define EXTRAS_DS1307_DS1307_H_
25
26 /* IN_MODULE should be defined for modules */
27 #define IN_MODULE
28 #define LOCAL_TIME
29
30 #include "src/modules.h"
31 #include "src/ioports.h"
32 #include "src/stimuli.h"
33 #include "src/trigger.h"
34 #include "src/i2c-ee.h"
35
36
37 class PromAddress;
38 class I2C_RTC;
39 class SQW_PIN;
40
41 namespace DS1307_Modules {
42
43 class ds1307 : public Module, public TriggerObject {
44 public:
45 explicit ds1307(const char *_name);
46 ~ds1307();
47
48 static Module *construct_ds1307(const char *new_name);
49 virtual void create_iopin_map();
50 virtual void setEnable(bool /* bNewState */ , unsigned int /* m_bit */ ) {}
51 virtual void callback();
52 void secWritten(unsigned int sec);
53 void controlWritten(unsigned int cntl);
54
55 enum control {
56 RS0 = 1 << 0,
57 RS1 = 1 << 1,
58 SQWE = 1 << 4,
59 OUT = 1 << 7
60 };
61
62 enum second {
63 CH = 1 << 7
64 };
65
66 protected:
67 void incrementRTC();
68
69 I2C_RTC *m_eeprom;
70 SQW_PIN *m_sqw;
71 unsigned int chip_select; // Write Protect and A0 - A2 state
72 PromAddress *att_eeprom;
73 guint64 next_clock_tick; // increment RTC here
74 guint64 next_sqw_edge; // change sqw edge here
75 guint64 sqw_interval; // cycles between edges
76 bool out; // Output state
77 };
78
79
80 } // end of namespace DS1307_Modules
81
82 class I2C_RTC : public I2C_EE {
83 public:
84 I2C_RTC(Processor *pCpu,
85 unsigned int _rom_size, unsigned int _write_page_size = 1,
86 unsigned int _addr_bytes = 1, unsigned int _CSmask = 0,
87 unsigned int _BSmask = 0, unsigned int _BSshift = 0
88 );
89 virtual ~I2C_RTC() {}
90
91 protected:
92 virtual bool match_address();
93 DS1307_Modules::ds1307 *pEE;
94 };
95
96
97 #endif // EXTRAS_DS1307_DS1307_H_