Driver for a CD22M3494 cross point switcher

Library description

The CD22M3494 is a 16x8 crosspoint switch matrix, it can be used in any configuration i.e. 16 ins' 8 outs' or 16 outs' and 8 ins'. Control of the chip is pretty simple there are two parallel address buses a 4 byte address controls the X axis (16 IO pins) and a 3 byte address controls the Y axis (8 IO pins). A data bus says whether to open or close the switch and a 'strobe' bus actually performs the switch. This library provides a simple interface to control the CD22M3494 and provides a mechanism to associate source and destinations in pairs and switch the pairs via their names.

Committer:
ollie8
Date:
Wed Oct 09 12:48:33 2013 +0000
Revision:
6:3f51c9139496
Parent:
5:ca315c82dc1b
Child:
7:6dc462dd6a0a
Added crosspoint lookup table

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ollie8 0:5ef90cd25c10 1 #ifndef CD22M3494_H
ollie8 0:5ef90cd25c10 2 #define CD22M3494_H
ollie8 0:5ef90cd25c10 3
ollie8 0:5ef90cd25c10 4 #include <mbed.h>
ollie8 1:bc9ca1d1d7a6 5 #include <map>
ollie8 1:bc9ca1d1d7a6 6 #include <string>
ollie8 1:bc9ca1d1d7a6 7
ollie8 0:5ef90cd25c10 8 /*
ollie8 0:5ef90cd25c10 9 X ADDRESS
ollie8 0:5ef90cd25c10 10 AX3 AX2 AX1 AX0 X SWITCH
ollie8 0:5ef90cd25c10 11 0 0 0 0 X0
ollie8 0:5ef90cd25c10 12 0 0 0 1 X1
ollie8 0:5ef90cd25c10 13 0 0 1 0 X2
ollie8 0:5ef90cd25c10 14 0 0 1 1 X3
ollie8 0:5ef90cd25c10 15 0 1 0 0 X4
ollie8 0:5ef90cd25c10 16 0 1 0 1 X5
ollie8 0:5ef90cd25c10 17 0 1 1 0 X12
ollie8 0:5ef90cd25c10 18 0 1 1 1 X13
ollie8 0:5ef90cd25c10 19 1 0 0 0 X6
ollie8 0:5ef90cd25c10 20 1 0 0 1 X7
ollie8 0:5ef90cd25c10 21 1 0 1 0 X8
ollie8 0:5ef90cd25c10 22 1 0 1 1 X9
ollie8 0:5ef90cd25c10 23 1 1 0 0 X10
ollie8 0:5ef90cd25c10 24 1 1 0 1 X11
ollie8 0:5ef90cd25c10 25 1 1 1 0 X14
ollie8 0:5ef90cd25c10 26 1 1 1 1 X15
ollie8 0:5ef90cd25c10 27 */
ollie8 4:6ffeb0008f11 28 #define X0 "X0"
ollie8 4:6ffeb0008f11 29 #define X1 "X1"
ollie8 4:6ffeb0008f11 30 #define X2 "X2"
ollie8 4:6ffeb0008f11 31 #define X3 "X3"
ollie8 4:6ffeb0008f11 32 #define X4 "X4"
ollie8 4:6ffeb0008f11 33 #define X5 "X5"
ollie8 4:6ffeb0008f11 34 #define X6 "X6"
ollie8 4:6ffeb0008f11 35 #define X7 "X7"
ollie8 4:6ffeb0008f11 36 #define X8 "X8"
ollie8 4:6ffeb0008f11 37 #define X9 "X9"
ollie8 4:6ffeb0008f11 38 #define X10 "X10"
ollie8 4:6ffeb0008f11 39 #define X11 "X11"
ollie8 4:6ffeb0008f11 40 #define X12 "X12"
ollie8 4:6ffeb0008f11 41 #define X13 "X13"
ollie8 4:6ffeb0008f11 42 #define X14 "X14"
ollie8 4:6ffeb0008f11 43 #define X15 "X15"
ollie8 0:5ef90cd25c10 44
ollie8 4:6ffeb0008f11 45
ollie8 4:6ffeb0008f11 46 #define X0I 0x00
ollie8 4:6ffeb0008f11 47 #define X1I 0x01
ollie8 4:6ffeb0008f11 48 #define X2I 0x02
ollie8 4:6ffeb0008f11 49 #define X3I 0x03
ollie8 4:6ffeb0008f11 50 #define X4I 0x04
ollie8 4:6ffeb0008f11 51 #define X5I 0x05
ollie8 4:6ffeb0008f11 52 #define X12I 0x06
ollie8 4:6ffeb0008f11 53 #define X13I 0x07
ollie8 4:6ffeb0008f11 54 #define X6I 0x08
ollie8 4:6ffeb0008f11 55 #define X7I 0x09
ollie8 4:6ffeb0008f11 56 #define X8I 0x0A
ollie8 4:6ffeb0008f11 57 #define X9I 0x0B
ollie8 4:6ffeb0008f11 58 #define X10I 0x0C
ollie8 4:6ffeb0008f11 59 #define X11I 0x0D
ollie8 4:6ffeb0008f11 60 #define X14I 0x0E
ollie8 4:6ffeb0008f11 61 #define X15I 0x0F
ollie8 0:5ef90cd25c10 62
ollie8 0:5ef90cd25c10 63 /*
ollie8 0:5ef90cd25c10 64 Y ADDRESS
ollie8 0:5ef90cd25c10 65 AY2 AY1 AY0 Y SWITCH
ollie8 0:5ef90cd25c10 66 0 0 0 Y0
ollie8 0:5ef90cd25c10 67 0 0 1 Y1
ollie8 0:5ef90cd25c10 68 0 1 0 Y2
ollie8 0:5ef90cd25c10 69 0 1 1 Y3
ollie8 0:5ef90cd25c10 70 1 0 0 Y4
ollie8 0:5ef90cd25c10 71 1 0 1 Y5
ollie8 0:5ef90cd25c10 72 1 1 0 Y6
ollie8 0:5ef90cd25c10 73 1 1 1 Y7
ollie8 0:5ef90cd25c10 74 */
ollie8 0:5ef90cd25c10 75
ollie8 4:6ffeb0008f11 76 #define Y0I 0x0
ollie8 4:6ffeb0008f11 77 #define Y1I 0x1
ollie8 4:6ffeb0008f11 78 #define Y2I 0x2
ollie8 4:6ffeb0008f11 79 #define Y3I 0x3
ollie8 4:6ffeb0008f11 80 #define Y4I 0x4
ollie8 4:6ffeb0008f11 81 #define Y5I 0x5
ollie8 4:6ffeb0008f11 82 #define Y6I 0x6
ollie8 4:6ffeb0008f11 83 #define Y7I 0x7
ollie8 4:6ffeb0008f11 84
ollie8 4:6ffeb0008f11 85 #define Y0 "Y0"
ollie8 4:6ffeb0008f11 86 #define Y1 "Y1"
ollie8 4:6ffeb0008f11 87 #define Y2 "Y2"
ollie8 4:6ffeb0008f11 88 #define Y3 "Y3"
ollie8 4:6ffeb0008f11 89 #define Y4 "Y4"
ollie8 4:6ffeb0008f11 90 #define Y5 "Y5"
ollie8 4:6ffeb0008f11 91 #define Y6 "Y6"
ollie8 4:6ffeb0008f11 92 #define Y7 "Y7"
ollie8 0:5ef90cd25c10 93
ollie8 0:5ef90cd25c10 94 #define MAX_X 0x0F
ollie8 0:5ef90cd25c10 95 #define MAX_Y 0x7
ollie8 0:5ef90cd25c10 96
ollie8 6:3f51c9139496 97 struct Association {
ollie8 6:3f51c9139496 98 string name;
ollie8 6:3f51c9139496 99 string xp1;
ollie8 6:3f51c9139496 100 string xp2;
ollie8 6:3f51c9139496 101 };
ollie8 6:3f51c9139496 102
ollie8 5:ca315c82dc1b 103 /**A driver for the CD22M3494 crosspoint switch matrix.
ollie8 5:ca315c82dc1b 104 */
ollie8 0:5ef90cd25c10 105 class CD22M3494 {
ollie8 0:5ef90cd25c10 106
ollie8 0:5ef90cd25c10 107 public:
ollie8 0:5ef90cd25c10 108
ollie8 4:6ffeb0008f11 109 /**Conucts a new CD22M3494 object
ollie8 4:6ffeb0008f11 110 *
ollie8 4:6ffeb0008f11 111 * @param x0 the pin name for the first byte of the x axis address
ollie8 4:6ffeb0008f11 112 * @param x1 the pin name for the second byte of the x axis address
ollie8 4:6ffeb0008f11 113 * @param x2 the pin name for the thrid byte of the x axis address
ollie8 4:6ffeb0008f11 114 * @param x3 the pin name for the forth byte of the x axis address
ollie8 4:6ffeb0008f11 115 * @param y0 the pin name for the first byte of the y axis address
ollie8 4:6ffeb0008f11 116 * @param y1 the pin name for the second byte of the y axis address
ollie8 4:6ffeb0008f11 117 * @param y2 the pin name for the thrid byte of the y axis address
ollie8 4:6ffeb0008f11 118 * @param d the pin name for the data bus
ollie8 4:6ffeb0008f11 119 * @param str the pin name for the strobe bus
ollie8 4:6ffeb0008f11 120 * @param rs the pin name for reset.
ollie8 4:6ffeb0008f11 121 */
ollie8 0:5ef90cd25c10 122 CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) {
ollie8 0:5ef90cd25c10 123 xbus = new BusOut(x0, x1, x2, x3);
ollie8 0:5ef90cd25c10 124 ybus = new BusOut(y0, y1, y2);
ollie8 0:5ef90cd25c10 125 data = new DigitalOut(d);
ollie8 4:6ffeb0008f11 126 obe = new DigitalOut(str);
ollie8 0:5ef90cd25c10 127 reset = new DigitalOut(rs);
ollie8 0:5ef90cd25c10 128 data->write(0);
ollie8 4:6ffeb0008f11 129 obe->write(0);
ollie8 0:5ef90cd25c10 130 reset->write(0);
ollie8 4:6ffeb0008f11 131 crosspointLookup[X0] = X0I;
ollie8 4:6ffeb0008f11 132 crosspointLookup[X1] = X1I;
ollie8 4:6ffeb0008f11 133 crosspointLookup[X2] = X2I;
ollie8 4:6ffeb0008f11 134 crosspointLookup[X3] = X3I;
ollie8 4:6ffeb0008f11 135 crosspointLookup[X4] = X4I;
ollie8 4:6ffeb0008f11 136 crosspointLookup[X5] = X5I;
ollie8 4:6ffeb0008f11 137 crosspointLookup[X6] = X6I;
ollie8 4:6ffeb0008f11 138 crosspointLookup[X7] = X7I;
ollie8 4:6ffeb0008f11 139 crosspointLookup[X8] = X8I;
ollie8 4:6ffeb0008f11 140 crosspointLookup[X9] = X9I;
ollie8 4:6ffeb0008f11 141 crosspointLookup[X10] = X10I;
ollie8 4:6ffeb0008f11 142 crosspointLookup[X11] = X11I;
ollie8 4:6ffeb0008f11 143 crosspointLookup[X12] = X12I;
ollie8 4:6ffeb0008f11 144 crosspointLookup[X13] = X13I;
ollie8 4:6ffeb0008f11 145 crosspointLookup[X14] = X14I;
ollie8 4:6ffeb0008f11 146 crosspointLookup[X15] = X15I;
ollie8 4:6ffeb0008f11 147 crosspointLookup[Y0] = Y0I;
ollie8 4:6ffeb0008f11 148 crosspointLookup[Y1] = Y1I;
ollie8 4:6ffeb0008f11 149 crosspointLookup[Y2] = Y2I;
ollie8 4:6ffeb0008f11 150 crosspointLookup[Y3] = Y3I;
ollie8 4:6ffeb0008f11 151 crosspointLookup[Y4] = Y4I;
ollie8 4:6ffeb0008f11 152 crosspointLookup[Y5] = Y5I;
ollie8 4:6ffeb0008f11 153 crosspointLookup[Y6] = Y6I;
ollie8 4:6ffeb0008f11 154 crosspointLookup[Y7] = Y7I;
ollie8 0:5ef90cd25c10 155 }
ollie8 0:5ef90cd25c10 156
ollie8 0:5ef90cd25c10 157 ~CD22M3494() {
ollie8 0:5ef90cd25c10 158 delete xbus;
ollie8 0:5ef90cd25c10 159 delete ybus;
ollie8 0:5ef90cd25c10 160 delete data;
ollie8 4:6ffeb0008f11 161 delete obe;
ollie8 0:5ef90cd25c10 162 delete reset;
ollie8 2:25049dc7da13 163 associationTable.clear();
ollie8 2:25049dc7da13 164 delete &associationTable;
ollie8 0:5ef90cd25c10 165 }
ollie8 6:3f51c9139496 166
ollie8 4:6ffeb0008f11 167 /**Closes the switch at the given cross point.
ollie8 4:6ffeb0008f11 168 *
ollie8 4:6ffeb0008f11 169 * @param x the x axis
ollie8 4:6ffeb0008f11 170 * @param y the y axis
ollie8 4:6ffeb0008f11 171 */
ollie8 0:5ef90cd25c10 172 bool crossPointConnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 173 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 174 data->write(1);
ollie8 0:5ef90cd25c10 175 xbus->write(x);
ollie8 0:5ef90cd25c10 176 ybus->write(y);
ollie8 4:6ffeb0008f11 177 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 178 wait_us(2);
ollie8 4:6ffeb0008f11 179 obe->write(1);
ollie8 4:6ffeb0008f11 180 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 181 wait_us(1);
ollie8 4:6ffeb0008f11 182 obe->write(0);
ollie8 0:5ef90cd25c10 183 return true;
ollie8 0:5ef90cd25c10 184 }
ollie8 0:5ef90cd25c10 185 return false;
ollie8 0:5ef90cd25c10 186 }
ollie8 0:5ef90cd25c10 187
ollie8 4:6ffeb0008f11 188 /**Opens the switch at the given cross point.
ollie8 4:6ffeb0008f11 189 *
ollie8 4:6ffeb0008f11 190 * @param x the x axis
ollie8 4:6ffeb0008f11 191 * @param y the y axis
ollie8 4:6ffeb0008f11 192 */
ollie8 0:5ef90cd25c10 193 bool crossPointDisconnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 194 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 195 data->write(0);
ollie8 0:5ef90cd25c10 196 xbus->write(x);
ollie8 0:5ef90cd25c10 197 ybus->write(y);
ollie8 4:6ffeb0008f11 198 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 199 wait_us(2);
ollie8 4:6ffeb0008f11 200 obe->write(1);
ollie8 4:6ffeb0008f11 201 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 202 wait_us(1);
ollie8 4:6ffeb0008f11 203 obe->write(0);
ollie8 0:5ef90cd25c10 204 return true;
ollie8 0:5ef90cd25c10 205 }
ollie8 0:5ef90cd25c10 206 return false;
ollie8 0:5ef90cd25c10 207 }
ollie8 1:bc9ca1d1d7a6 208
ollie8 4:6ffeb0008f11 209 /**Associated the two given crosspoint with the given name, note, both crosspoint MUST be on the same axis.
ollie8 4:6ffeb0008f11 210 *
ollie8 4:6ffeb0008f11 211 * @param name the name of the association
ollie8 4:6ffeb0008f11 212 * @param xp1 the first crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 213 * @param xp2 the second crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 214 */
ollie8 4:6ffeb0008f11 215 bool associate(string name, string xp1, string xp2) {
ollie8 4:6ffeb0008f11 216 if (crosspointLookup.count(xp1) && crosspointLookup.count(xp2)) {
ollie8 4:6ffeb0008f11 217 Association *assoc = new Association();
ollie8 4:6ffeb0008f11 218 assoc->xp1 = xp1;
ollie8 4:6ffeb0008f11 219 assoc->xp2 = xp2;
ollie8 4:6ffeb0008f11 220 associationTable[name] = assoc;
ollie8 6:3f51c9139496 221 return true;
ollie8 4:6ffeb0008f11 222 }
ollie8 6:3f51c9139496 223 return false;
ollie8 1:bc9ca1d1d7a6 224 }
ollie8 1:bc9ca1d1d7a6 225
ollie8 4:6ffeb0008f11 226 /**Connects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 227 *
ollie8 4:6ffeb0008f11 228 * @param src the source association
ollie8 4:6ffeb0008f11 229 * @param dst the destination to connect the source to.
ollie8 4:6ffeb0008f11 230 */
ollie8 1:bc9ca1d1d7a6 231 bool routeAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 232 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 233 crossPointConnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 234 crossPointConnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 235 return true;
ollie8 1:bc9ca1d1d7a6 236 }
ollie8 1:bc9ca1d1d7a6 237 return false;
ollie8 1:bc9ca1d1d7a6 238 }
ollie8 1:bc9ca1d1d7a6 239
ollie8 4:6ffeb0008f11 240 /**Disconnects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 241 *
ollie8 4:6ffeb0008f11 242 * @param src the source association
ollie8 4:6ffeb0008f11 243 * @param dst the destination to disconnect from the source.
ollie8 4:6ffeb0008f11 244 */
ollie8 1:bc9ca1d1d7a6 245 bool unRouteAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 246 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 247 crossPointDisconnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 248 crossPointDisconnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 249 return true;
ollie8 1:bc9ca1d1d7a6 250 }
ollie8 1:bc9ca1d1d7a6 251 return false;
ollie8 1:bc9ca1d1d7a6 252 }
ollie8 6:3f51c9139496 253
ollie8 6:3f51c9139496 254 Association* getAssociation(string name) {
ollie8 6:3f51c9139496 255 return associationTable[name];
ollie8 6:3f51c9139496 256 }
ollie8 6:3f51c9139496 257
ollie8 0:5ef90cd25c10 258 private:
ollie8 2:25049dc7da13 259 BusOut *xbus;
ollie8 2:25049dc7da13 260 BusOut *ybus;
ollie8 2:25049dc7da13 261 DigitalOut *data;
ollie8 4:6ffeb0008f11 262 DigitalOut *obe;
ollie8 6:3f51c9139496 263 DigitalOut *reset;
ollie8 4:6ffeb0008f11 264 map<string, Association*> associationTable;
ollie8 4:6ffeb0008f11 265 map<string, unsigned short> crosspointLookup;
ollie8 0:5ef90cd25c10 266 };
ollie8 0:5ef90cd25c10 267
ollie8 0:5ef90cd25c10 268
ollie8 0:5ef90cd25c10 269 #endif