versadac  1
versadac - Scalable Recorder Firmware
ee_ssm.h
1 /*******************************************************************************
2 FILE : ee_ssm.h
3 VERSION : $Id$
4 AUTHOR : David Cozens
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains a heirachy of classes to fully control access
7  to an X25020 EEPROM device. There are seperate derived classes
8  for each type of access to the device
9  The majority of messages are sent in SPI mode as this is how the
10  EE devices are physically configured on the 2500 IO modules. The
11  read and write operations can be specified to be sent in either
12  SPI or SCI mode, the classes here sort out the bit ordering for
13  the command and start address bytes, the data bytes are then either
14  sent in SPI or SCI mode as requested.
15 WARNING : When writing to the EE you must first issue a write enable
16  instruction. Following this you send a write which must fit inside
17  a single page. Once the write has been sent to the device the only
18  transaction that appears to be safe is to read the status register
19  to check if the write is complete.
20 *******************************************************************************/
21 #ifndef __EER_SSM_H
22 #define __EER_SSM_H
23 #include "spismsg.h"
24 
25 // The status register has 2 bits that allow access to regions of the device to
26 // be protected. This enumerates the different values that can be configured.
27 enum enumProtectRange_t
28 {
29  X25020_SR_PROTECT_NONE = 0,
30  X25020_SR_PROTECT_C0_TO_FF = 0x4,
31  X25020_SR_PROTECT_80_TO_FF = 0x8,
32  X25020_SR_PROTECT_ALL = 0xC,
33 };
34 // Mask for the status register write in progress bit
35 #define X25020_SR_WIP 0x1
36 // Mask for the status register write enabled bit
37 #define X25020_SR_WEL 0x2
38 // Mask for the region protect bits
39 #define X25020_SR_PROTECT_MASK 0xC
40 
41 // This class provides a base for all of the EE classes. It provides services
42 // to bit swap data to allow for SPI and SCI modes it also provides a mapping
43 // between the module number and the BSP's device numbering.
44 class EESpiScheduledMessage:public SpiScheduledMessage
45 {
46  public:
47  EESpiScheduledMessage(unsigned char module, unsigned char length, SpiSciEnum spiSciMode );
48  virtual ~EESpiScheduledMessage();
49 
50  protected:
51  static unsigned char m_bitSwap[256];
52 
53  private:
54  static unsigned short moduleToDevice(unsigned char module);
55 
56 };
57 
58 // This class encapsulates reading of data from the EE.
60 {
61  public:
62  EEReadSpiScheduledMessage(unsigned char module, unsigned char start, unsigned char length, SpiSciEnum spiSciMode );
63  virtual ~EEReadSpiScheduledMessage();
64  /*------------------------------------------------------------------------------
65  FUNCTION : getDataPtr
66  DESCRIPTION : returns a pointer to where data has been read into.
67  ARGUMENTS :
68  RETURN : returns a pointer to where data has been read into.
69  NOTES :
70  ------------------------------------------------------------------------------*/
71  unsigned char *getDataPtr(){return getRxPtr()+2;};
72 
73  void setStart(unsigned char start);
74 
75  private:
76 };
77 
78 // This class encapsulates reading of the status register
80 {
81  public:
82  EEReadStatusSpiScheduledMessage(unsigned char module);
84  /*------------------------------------------------------------------------------
85  FUNCTION : getProtectRange
86  DESCRIPTION : gets the area of the device that is currently write protected
87  ARGUMENTS :
88  RETURN : enumProtectRange_t
89  NOTES :
90  ------------------------------------------------------------------------------*/
91  enumProtectRange_t getProtectRange(){return (enumProtectRange_t)(getRxPtr()[1]&X25020_SR_PROTECT_MASK);};
92  /*------------------------------------------------------------------------------
93  FUNCTION : getWriteEnable
94  DESCRIPTION : is the device write enabled?
95  ARGUMENTS :
96  RETURN : 0 write disabled, non-zero write enabled
97  NOTES :
98  ------------------------------------------------------------------------------*/
99  unsigned char getWriteEnable(){return getRxPtr()[1]&X25020_SR_WEL;};
100  /*------------------------------------------------------------------------------
101  FUNCTION : getWriteInProgress
102  DESCRIPTION : is a write currently in progress?
103  ARGUMENTS :
104  RETURN : 0 => no, non-zero a write is in progress.
105  NOTES :
106  ------------------------------------------------------------------------------*/
107  unsigned char getWriteInProgress(){return getRxPtr()[1]&X25020_SR_WIP;};
108 
109  private:
110 };
111 
112 // This class encapsulates the message required to write enable/disable the device
114 {
115  public:
116  EEWriteEnableSpiScheduledMessage(unsigned char module );
118  void setWriteEnable(unsigned char enable);
119 
120  virtual void sent();
121  private:
122 };
123 
124 // This class encapsulates writing of data to the device. It can do single byte or page
125 // writes it auto disables itself after one write attempt.
127 {
128  public:
129  EEWriteSpiScheduledMessage(unsigned char module, unsigned char start, unsigned char length, void * datap, SpiSciEnum spiSciMode );
130  virtual ~EEWriteSpiScheduledMessage();
131  void update(unsigned char start, unsigned char length, void * datap);
132  virtual void sent();
133  private:
134 
135 };
136 
137 // This class encapsulates the ability to write protect regions of the device.
139 {
140  public:
141  EEWriteProtectBlockSpiScheduledMessage(unsigned char module);
143  void setProtectRange(enumProtectRange_t range);
144 
145  virtual void sent();
146  private:
147 };
148 #endif /*__EER_SSM_H */
Definition: ee_ssm.h:79
Definition: ee_ssm.h:113
Definition: ee_ssm.h:44
Definition: ee_ssm.h:126
Definition: ee_ssm.h:59