|
|
1.1 root 1: ADB driver thread pcode
2:
3: adbThread(id adbObject)
4: {
5: set up registers and interrupt ports and so forth;
6: cmdPort initially disabled;
7: doReset;
8: enable cmdPort;
9: while(1) {
10: wait for msg on portSet;
11: if msg on interrupt port
12: adbInterruptHandler;
13: else if msg on cmdPort
14: adbCommandHandler;
15: else
16: log error;
17: }
18: }
19:
20: /*
21: * Called on async interrupt only; should be "data avaiable" or
22: * service request.
23: */
24: - adbInterruptHandler
25: {
26: grab interrupt cause and clear the pending bits;
27: if (interrupt cause == AS_INPUT_DATA_PENDING) {
28:
29: /*
30: * Normal async data in case.
31: */
32: handleDataIn(currentAddress);
33: enableAutopoll(currentAddress);
34: enable cmdPort;
35: }
36: else if(interrupt cause == service request) {
37: scanServiceRequestor;
38: }
39: else {
40: handle error - probably just do a reset;
41: }
42: }
43:
44: /*
45: * Execute client command.
46: */
47: - adbCommandHandler
48: {
49: switch cmd {
50: case reset:
51: disable cmdPort;
52: doReset;
53: status = good;
54: enable cmdPort;
55: break;
56:
57: case send_cmd:
58: disable cmdPort;
59: disableAutopoll;
60: status = sendCmd(cmd);
61: enableAutopoll;
62: return rtn;
63:
64: case attach:
65: if desired address already attached
66: status = IO_CR_BUSY;
67: else {
68: record client/address pair;
69: status = good;
70: }
71: }
72: I/O complete(status);
73: }
74:
75: /*
76: * Handle service request.
77: */
78: - scanServiceRequestor
79: {
80: disableAutopoll;
81: for(currentAddress = 0 to max) {
82: send a talk register 0 command;
83: if OK {
84: get other registers;
85: dispatch to client;
86: }
87: else try next address;
88: }
89: enableAutopoll(last responding adress);
90: return;
91: }
92:
93: - doReset
94: {
95: disable cmdPort;
96: assert reset;
97: while(1) {
98: wait for interrupt message;
99: if resetPulseCompleted // nothing else matters
100: break;
101: }
102: scanBus;
103: enableAutopoll(address = 0);
104: }
105:
106: /*
107: * Autopoll must be off.
108: */
109: - (IOReturn)sendCmd : (adbDriverCommand *)cmd
110: {
111: disable cmdPort;
112: load cmd and byte count;
113: hit AC_TRANSMIT_COMMAND;
114: wait for interrupt;
115: if interrupt status = userAccessCompleted {
116: cool;
117: save bit count in *cmd;
118: return IO_R_SUCCESS;
119: }
120: if service request {
121: scanServiceRequestor;
122: }
123: deal with other errors;
124: if autopoll not enabled {
125: enableAutopoll(user access address);
126: }
127: }
128:
129: - (void)enableAutopoll(adbAddress address)
130: {
131: cmd = talk register 0 (address);
132: load cmd and bit count registers;
133: hit AC_ENABLE_AUTO_POLL;
134: }
135:
136: /*
137: * Shut down autopoll mode in preparation for doing a user poll operation.
138: */
139: - (void)disableAutopoll
140: {
141: if !autoPollEnabled
142: return;
143: hit AC_DISABLE_AUTO_POLL;
144: while(1) {
145: wait for interrupt;
146: if interrupt cause == AS_INPUT_DATA_PENDING {
147:
148: /*
149: * Lost a race, must handle this incoming event from
150: * last autopoll address.
151: */
152: handleDataIn(currentAddress);
153: }
154: else if interrupt cause = auto polling stopped
155: return;
156: }
157: }
158:
159: /*
160: * scan bus, resolve address conflicts.
161: */
162: - (void)scanBus
163: {
164:
165: }
166:
167: /*
168: * Handle async data available condition (AS_INPUT_DATA_PENDING true).
169: */
170: - -(void)handleDataIn(deviceAddress)
171: {
172: adbEvent localEvent;
173:
174: disable cmdPort;
175: do {
176: save reg 0 (current data0/1) in localEvent;
177: get the other three registers, stash in localEvent;
178: localEvent.deviceAddress = deviceAddress;
179: dispatchEvent(localEvent);
180: error = sendCmd(talk register 0 (deviceAddress));
181: while(!error);
182: }
183:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.