Annotation of driverkit/tests/adbevent.m, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: /*
                     25:  * adbevent - FAKE_HARDWARE event dispatch test
                     26:  */
                     27:  
                     28: #define FAKE_HARDWARE  1
                     29: 
                     30: #import <adb/adbDriver.h>
                     31: #import <driverkit/generalFuncs.h>
                     32: #import <driverkit/debugging.h>
                     33: #import <driverkit/KernDevUxpr.h>
                     34: #import <libc.h>
                     35: #import <driverkit/IOtsval.h>
                     36: 
                     37: static struct tsval tsvalLast = {0,0};
                     38: 
                     39: /*
                     40:  * prototypes for private functions.
                     41:  */
                     42: static void usage(char **argv);
                     43: static void resetThread(id driverid);
                     44: static void commandThread(id driverid);
                     45: 
                     46: /*
                     47:  * Dumb little object which will be a client of AdbDriver.
                     48:  */
                     49: @interface adbClient : Object <adbDriverClient>
                     50: {
                     51:        id      _driver;
                     52: }
                     53: 
                     54: - setDriver : driver;
                     55: @end
                     56: 
                     57: @implementation adbClient
                     58: 
                     59: /*
                     60:  * These standard methods run from the driver's I/O thread.
                     61:  */
                     62:  
                     63: /*
                     64:  * Called when driver detects one new ADB event.
                     65:  */
                     66: - (void)dispatchAdbEvent : (adbEvent *)event
                     67: {
                     68:        unsigned reg;
                     69:        int regnum;
                     70:        unsigned long long regval_l;
                     71:        unsigned regval;
                     72:        
                     73:        printf("%u:%u  delta = %u\n",
                     74:                event->timeStamp.high_val, event->timeStamp.low_val,
                     75:                ts_diff(&event->timeStamp, &tsvalLast));
                     76:        tsvalLast = event->timeStamp;
                     77:        printf("   address %d\n", 
                     78:                event->deviceAddress);
                     79:        for(regnum=0; regnum<=3; regnum++) {
                     80:                reg = *((unsigned *)(&event->regs[regnum].data.stand.byte[0]));
                     81:                regval_l = adbDeviceRegisterData(&event->regs[regnum]);
                     82:                if(regval_l > ULONG_MAX) {
                     83:                        printf("***length exceeded; using ULONG_MAX\n");
                     84:                        regval = ULONG_MAX;
                     85:                }
                     86:                else
                     87:                        regval = regval_l;
                     88:                printf("   register %d: length %d data 0x%x\n",
                     89:                        regnum, event->regs[regnum].length, regval);
                     90:        }
                     91:        [_driver freeAdbEvent:event];
                     92: }
                     93: 
                     94: /*
                     95:  * Called on ADB bus reset.
                     96:  */
                     97: - (void)adbBusWasReset
                     98: {
                     99:        printf("adbClient: reset detected\n");
                    100:        
                    101:        /*
                    102:         * Re-register; the driver thinks the world has changed.
                    103:         */
                    104:        [_driver attachAddress: FAKE_HARDWARE_START_ADDRESS client:self];
                    105: }
                    106: 
                    107: - setDriver : driver
                    108: {
                    109:        _driver = driver;
                    110:        return self;
                    111: }
                    112: 
                    113: @end
                    114: 
                    115: extern int verbose;
                    116: int reset_interval = 0;
                    117: int command_interval = 0;
                    118: 
                    119: int main(int argc, char **argv)
                    120: {
                    121:        int arg;
                    122:        id driverId;
                    123:        id clientId;
                    124:                
                    125:        if(argc < 2)
                    126:                usage(argv);
                    127:        for(arg=1; arg<argc; arg++) {
                    128:                switch(argv[arg][0]) {
                    129:                    case 'v':
                    130:                        verbose++;
                    131:                        break;
                    132:                    case 'r':
                    133:                        reset_interval = atoi(&argv[arg][2]);
                    134:                        break;
                    135:                    case 'c':
                    136:                        command_interval = atoi(&argv[arg][2]);
                    137:                        break;
                    138:                    default:
                    139:                        usage(argv);
                    140:                }
                    141:        }
                    142: 
                    143:         IOInitGeneralFuncs();
                    144:        IOInitDDM(1000, "adbXpr");
                    145:        IOSetDDMMask(XPR_IODEVICE_INDEX, XPR_LIBIO | XPR_ADB);
                    146: 
                    147:        /*
                    148:         * Instantiate and init a client and the driver.
                    149:         */
                    150:        clientId = [adbClient new];
                    151:        driverId = [adbDriver probe:0 deviceMaster:PORT_NULL];
                    152:        [clientId setDriver:driverId];
                    153:        [driverId attachAddress: FAKE_HARDWARE_START_ADDRESS client:clientId];
                    154:        if(reset_interval)
                    155:                IOForkThread((IOThreadFunc)resetThread, driverId);
                    156:        if(command_interval)
                    157:                IOForkThread((IOThreadFunc)commandThread, driverId);
                    158:        while(1) {
                    159:                IOSleep(10);
                    160:        }
                    161: }
                    162: 
                    163: static void resetThread(id driverId)
                    164: {
                    165:        while(1) {
                    166:                IOSleep(reset_interval * 1000);
                    167:                [driverId resetAdb];
                    168:        }
                    169: }
                    170: 
                    171: static void commandThread(id driverId)
                    172: {
                    173:        adbUserCommand cmd;
                    174:        IOReturn rtn;
                    175:        
                    176:        while(1) {
                    177:                IOSleep(command_interval * 1000);
                    178:                cmd.command = TALK_REGISTER(3, FAKE_HARDWARE_START_ADDRESS);
                    179:                cmd.reg.length = 0;
                    180:                rtn = [driverId sendUserCommand:&cmd];
                    181:                if(rtn) {
                    182:                        printf("sendUserCommand returned %s\n",
                    183:                                [driverId stringFromReturn:rtn]);
                    184:                }
                    185:                else {
                    186:                        printf("Talk Register 3: data = 0x%x\n",
                    187:                                cmd.reg.data.reg3.sh.data);
                    188:                }
                    189:        }
                    190: }
                    191: 
                    192: static void usage(char **argv)
                    193: {
                    194:        printf("usage: %s [options]\n", argv[0]);
                    195:        printf("Options (must specify at least one):\n");
                    196:        printf("\tv  verbose mode\n");
                    197:        printf("\tr=reset_interval (in seconds; default is no reset)\n");
                    198:        printf("\tc=command_interval (in seconds; default is no command\n");
                    199:        exit(1);
                    200: }
                    201: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.