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:
Tue Sep 10 21:34:24 2013 +0000
Revision:
1:bc9ca1d1d7a6
Parent:
0:5ef90cd25c10
Child:
2:25049dc7da13
Added ability to switch associations

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
ollie8 1:bc9ca1d1d7a6 6 #include <map>
ollie8 1:bc9ca1d1d7a6 7 //using std::map;
ollie8 1:bc9ca1d1d7a6 8 #include <string>
ollie8 1:bc9ca1d1d7a6 9 //using std::string;
ollie8 1:bc9ca1d1d7a6 10
ollie8 0:5ef90cd25c10 11 /*
ollie8 0:5ef90cd25c10 12 X ADDRESS
ollie8 0:5ef90cd25c10 13 AX3 AX2 AX1 AX0 X SWITCH
ollie8 0:5ef90cd25c10 14 0 0 0 0 X0
ollie8 0:5ef90cd25c10 15 0 0 0 1 X1
ollie8 0:5ef90cd25c10 16 0 0 1 0 X2
ollie8 0:5ef90cd25c10 17 0 0 1 1 X3
ollie8 0:5ef90cd25c10 18 0 1 0 0 X4
ollie8 0:5ef90cd25c10 19 0 1 0 1 X5
ollie8 0:5ef90cd25c10 20 0 1 1 0 X12
ollie8 0:5ef90cd25c10 21 0 1 1 1 X13
ollie8 0:5ef90cd25c10 22 1 0 0 0 X6
ollie8 0:5ef90cd25c10 23 1 0 0 1 X7
ollie8 0:5ef90cd25c10 24 1 0 1 0 X8
ollie8 0:5ef90cd25c10 25 1 0 1 1 X9
ollie8 0:5ef90cd25c10 26 1 1 0 0 X10
ollie8 0:5ef90cd25c10 27 1 1 0 1 X11
ollie8 0:5ef90cd25c10 28 1 1 1 0 X14
ollie8 0:5ef90cd25c10 29 1 1 1 1 X15
ollie8 0:5ef90cd25c10 30 */
ollie8 0:5ef90cd25c10 31
ollie8 0:5ef90cd25c10 32 #define X0 0x00
ollie8 0:5ef90cd25c10 33 #define X1 0x01
ollie8 0:5ef90cd25c10 34 #define X2 0x02
ollie8 0:5ef90cd25c10 35 #define X3 0x03
ollie8 0:5ef90cd25c10 36 #define X4 0x04
ollie8 0:5ef90cd25c10 37 #define X5 0x05
ollie8 0:5ef90cd25c10 38 #define X12 0x06
ollie8 0:5ef90cd25c10 39 #define X13 0x07
ollie8 0:5ef90cd25c10 40 #define X6 0x08
ollie8 0:5ef90cd25c10 41 #define X7 0x09
ollie8 0:5ef90cd25c10 42 #define X8 0x0A
ollie8 0:5ef90cd25c10 43 #define X9 0x0B
ollie8 0:5ef90cd25c10 44 #define X10 0x0C
ollie8 0:5ef90cd25c10 45 #define X11 0x0D
ollie8 0:5ef90cd25c10 46 #define X14 0x0E
ollie8 0:5ef90cd25c10 47 #define X15 0x0F
ollie8 0:5ef90cd25c10 48
ollie8 0:5ef90cd25c10 49 /*
ollie8 0:5ef90cd25c10 50 Y ADDRESS
ollie8 0:5ef90cd25c10 51 AY2 AY1 AY0 Y SWITCH
ollie8 0:5ef90cd25c10 52 0 0 0 Y0
ollie8 0:5ef90cd25c10 53 0 0 1 Y1
ollie8 0:5ef90cd25c10 54 0 1 0 Y2
ollie8 0:5ef90cd25c10 55 0 1 1 Y3
ollie8 0:5ef90cd25c10 56 1 0 0 Y4
ollie8 0:5ef90cd25c10 57 1 0 1 Y5
ollie8 0:5ef90cd25c10 58 1 1 0 Y6
ollie8 0:5ef90cd25c10 59 1 1 1 Y7
ollie8 0:5ef90cd25c10 60 */
ollie8 0:5ef90cd25c10 61
ollie8 0:5ef90cd25c10 62 #define Y0 0x0
ollie8 0:5ef90cd25c10 63 #define Y1 0x1
ollie8 0:5ef90cd25c10 64 #define Y2 0x2
ollie8 0:5ef90cd25c10 65 #define Y3 0x3
ollie8 0:5ef90cd25c10 66 #define Y4 0x4
ollie8 0:5ef90cd25c10 67 #define Y5 0x5
ollie8 0:5ef90cd25c10 68 #define Y6 0x6
ollie8 0:5ef90cd25c10 69 #define Y7 0x7
ollie8 0:5ef90cd25c10 70
ollie8 0:5ef90cd25c10 71 #define MAX_X 0x0F
ollie8 0:5ef90cd25c10 72 #define MAX_Y 0x7
ollie8 0:5ef90cd25c10 73
ollie8 0:5ef90cd25c10 74 class CD22M3494 {
ollie8 0:5ef90cd25c10 75
ollie8 0:5ef90cd25c10 76 public:
ollie8 0:5ef90cd25c10 77
ollie8 0:5ef90cd25c10 78 CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) {
ollie8 0:5ef90cd25c10 79 xbus = new BusOut(x0, x1, x2, x3);
ollie8 0:5ef90cd25c10 80 ybus = new BusOut(y0, y1, y2);
ollie8 0:5ef90cd25c10 81 data = new DigitalOut(d);
ollie8 0:5ef90cd25c10 82 strobe = new DigitalOut(str);
ollie8 0:5ef90cd25c10 83 reset = new DigitalOut(rs);
ollie8 0:5ef90cd25c10 84 data->write(0);
ollie8 0:5ef90cd25c10 85 strobe->write(0);
ollie8 0:5ef90cd25c10 86 reset->write(0);
ollie8 0:5ef90cd25c10 87 }
ollie8 0:5ef90cd25c10 88
ollie8 0:5ef90cd25c10 89 ~CD22M3494() {
ollie8 0:5ef90cd25c10 90 delete xbus;
ollie8 0:5ef90cd25c10 91 delete ybus;
ollie8 0:5ef90cd25c10 92 delete data;
ollie8 0:5ef90cd25c10 93 delete strobe;
ollie8 0:5ef90cd25c10 94 delete reset;
ollie8 0:5ef90cd25c10 95 }
ollie8 0:5ef90cd25c10 96
ollie8 0:5ef90cd25c10 97 bool crossPointConnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 98 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 99 data->write(1);
ollie8 0:5ef90cd25c10 100 xbus->write(x);
ollie8 0:5ef90cd25c10 101 ybus->write(y);
ollie8 0:5ef90cd25c10 102 // let the data busses settle before setting strobe high
ollie8 0:5ef90cd25c10 103 wait_us(2);
ollie8 0:5ef90cd25c10 104 strobe->write(1);
ollie8 0:5ef90cd25c10 105 // strobe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 106 wait_us(1);
ollie8 0:5ef90cd25c10 107 strobe->write(0);
ollie8 0:5ef90cd25c10 108 return true;
ollie8 0:5ef90cd25c10 109 }
ollie8 0:5ef90cd25c10 110 return false;
ollie8 0:5ef90cd25c10 111 }
ollie8 0:5ef90cd25c10 112
ollie8 0:5ef90cd25c10 113 bool crossPointDisconnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 114 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 115 data->write(0);
ollie8 0:5ef90cd25c10 116 xbus->write(x);
ollie8 0:5ef90cd25c10 117 ybus->write(y);
ollie8 0:5ef90cd25c10 118 // let the data busses settle before setting strobe high
ollie8 0:5ef90cd25c10 119 wait_us(2);
ollie8 0:5ef90cd25c10 120 strobe->write(1);
ollie8 0:5ef90cd25c10 121 // strobe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 122 wait_us(1);
ollie8 0:5ef90cd25c10 123 strobe->write(0);
ollie8 0:5ef90cd25c10 124 return true;
ollie8 0:5ef90cd25c10 125 }
ollie8 0:5ef90cd25c10 126 return false;
ollie8 0:5ef90cd25c10 127 }
ollie8 1:bc9ca1d1d7a6 128
ollie8 1:bc9ca1d1d7a6 129 void associate(string name, unsigned short xp1, unsigned short xp2) {
ollie8 1:bc9ca1d1d7a6 130 unsigned short xps[2];
ollie8 1:bc9ca1d1d7a6 131 xps[0] = xp1;
ollie8 1:bc9ca1d1d7a6 132 xps[1] = xp2;
ollie8 1:bc9ca1d1d7a6 133 associationTable[name] = xps;
ollie8 1:bc9ca1d1d7a6 134 }
ollie8 1:bc9ca1d1d7a6 135
ollie8 1:bc9ca1d1d7a6 136 bool routeAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 137 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 1:bc9ca1d1d7a6 138 crossPointConnect(associationTable[src][0], associationTable[dst][1]);
ollie8 1:bc9ca1d1d7a6 139 crossPointConnect(associationTable[src][0], associationTable[dst][1]);
ollie8 1:bc9ca1d1d7a6 140 return true;
ollie8 1:bc9ca1d1d7a6 141 }
ollie8 1:bc9ca1d1d7a6 142 return false;
ollie8 1:bc9ca1d1d7a6 143 }
ollie8 1:bc9ca1d1d7a6 144
ollie8 1:bc9ca1d1d7a6 145 bool unRouteAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 146 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 1:bc9ca1d1d7a6 147 crossPointDisconnect(associationTable[src][0], associationTable[dst][1]);
ollie8 1:bc9ca1d1d7a6 148 crossPointDisconnect(associationTable[src][0], associationTable[dst][1]);
ollie8 1:bc9ca1d1d7a6 149 return true;
ollie8 1:bc9ca1d1d7a6 150 }
ollie8 1:bc9ca1d1d7a6 151 return false;
ollie8 1:bc9ca1d1d7a6 152 }
ollie8 1:bc9ca1d1d7a6 153
ollie8 0:5ef90cd25c10 154 private:
ollie8 0:5ef90cd25c10 155 BusOut* xbus;
ollie8 0:5ef90cd25c10 156 BusOut* ybus;
ollie8 0:5ef90cd25c10 157 DigitalOut* data;
ollie8 0:5ef90cd25c10 158 DigitalOut* strobe;
ollie8 1:bc9ca1d1d7a6 159 DigitalOut* reset;
ollie8 1:bc9ca1d1d7a6 160 map<string, unsigned short*> associationTable;
ollie8 0:5ef90cd25c10 161 };
ollie8 0:5ef90cd25c10 162
ollie8 0:5ef90cd25c10 163
ollie8 0:5ef90cd25c10 164 #endif