File: i2c-eeprom.cc

package info (click to toggle)
gpsim 0.22.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,552 kB
  • ctags: 12,443
  • sloc: cpp: 69,959; sh: 8,747; asm: 7,706; ansic: 4,101; lex: 1,125; makefile: 1,102; yacc: 760
file content (157 lines) | stat: -rw-r--r-- 3,996 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
   Copyright (C) 2006 T. Scott Dattalo
   Copyright (C) 2006 Roy R Rankin

This file is part of gpsim.

gpsim is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

gpsim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with gpsim; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */


#include <stdio.h>

#include "../config.h"    // get the definition for HAVE_GUI
#ifdef HAVE_GUI
#include <gtk/gtk.h>
#endif

#include "../src/i2c-ee.h"
#include "i2c-eeprom.h"
#include "../src/stimuli.h"
#include "../src/ioports.h"
#include "../src/symbol.h"
#include "../src/value.h"
#include "../src/packages.h"

namespace I2C_EEPROM_Modules {

class I2C_ENABLE : public IOPIN
{
public:
  I2C_ENABLE(const char *name, unsigned int bit, I2C_EE_Module *pParent);

  virtual void setDrivenState(bool);

private:
  I2C_EE_Module *m_pParent;
  unsigned int m_bit;
};

I2C_ENABLE::I2C_ENABLE(const char *name, unsigned int bit, 
	I2C_EE_Module *pParent) : IOPIN(name), m_pParent(pParent),
	m_bit(bit)
{
}
void I2C_ENABLE::setDrivenState(bool bNewState)
{
  IOPIN::setDrivenState(bNewState);
  if (m_pParent)
    m_pParent->setEnable(bNewState, m_bit);
}

  I2C_EE_Module::I2C_EE_Module(const char *_name)
  {
    // Set module name
    if (_name)
	new_name(_name);
    initializeAttributes();
    chip_select = 0;
  }


  I2C_EE_Module::~I2C_EE_Module()
  {
    delete m_eeprom;
  }

  Module *I2C_EE_Module::construct_2k(const char *_new_name)
  {

    I2C_EE_Module *pEE = new I2C_EE_Module(_new_name);
    // I2C_EE size in bytes prom size in bits
    (pEE->m_eeprom) = new I2C_EE(256, 16, 1, 0xe, 0, 0);
    pEE->create_iopin_map();

    //if(get_interface().bUsingGUI()) 
    //  pEE->create_widget(pEe);
   return(pEE);

  }
  Module *I2C_EE_Module::construct_16k(const char *_new_name)
  {

    I2C_EE_Module *pEE = new I2C_EE_Module(_new_name);
    // I2C_EE size in bytes prom size in bits
    (pEE->m_eeprom) = new I2C_EE(2048, 16, 1, 0, 0xe, 1);
    pEE->create_iopin_map();

    //if(get_interface().bUsingGUI()) 
    //  pEE->create_widget(pEe);
   return(pEE);

  }
  Module *I2C_EE_Module::construct_256k(const char *_new_name)
  {

    I2C_EE_Module *pEE = new I2C_EE_Module(_new_name);
    // I2C_EE size in bytes prom size in bits
    (pEE->m_eeprom) = new I2C_EE(32768, 64, 2, 0xe, 0, 0);
    pEE->create_iopin_map();

    //if(get_interface().bUsingGUI()) 
    //  pEE->create_widget(pEe);
   return(pEE);

  }


  void I2C_EE_Module::create_iopin_map()
  {
        string pinName;

	pinName = name() + ".WP";
	m_wp  =  new I2C_ENABLE(pinName.c_str(), 0, this);
	pinName = name() + ".A0";
	m_A[0] = new I2C_ENABLE(pinName.c_str(), 1, this);
	pinName = name() + ".A1";
	m_A[1] = new I2C_ENABLE(pinName.c_str(), 2, this);
	pinName = name() + ".A2";
	m_A[2] = new I2C_ENABLE(pinName.c_str(), 3, this);

	pinName = name() + ".SDA";
	((IOPIN *)(m_eeprom->sda))->new_name(pinName.c_str());
	pinName = name() + ".SCL";
	((IOPIN *)(m_eeprom->scl))->new_name(pinName.c_str());

	package = new Package(8);
	package->assign_pin( 1, m_A[0]);
	package->assign_pin( 2, m_A[1]);
	package->assign_pin( 3, m_A[2]);
	package->assign_pin( 5, (IOPIN *)(m_eeprom->sda));
	package->assign_pin( 6, (IOPIN *)(m_eeprom->scl));
	package->assign_pin( 7, m_wp);

  }
  // WP or A0-A2 has changed
  void I2C_EE_Module::setEnable(bool NewState, unsigned int bit)
  {
	if (NewState)
	    chip_select |= 1 << bit;
	else
	    chip_select &= ~(1 << bit);
	m_eeprom->set_chipselect(chip_select);
  }

} // end of namespace I2C_EEEPROM_Modules