home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / NextLibrary / Documentation / NextDev / Examples / DriverKit / TestDriver / myTestDriver / myTestDriver_reloc.tproj / myTestDriver.m < prev    next >
Encoding:
Text File  |  1995-02-01  |  3.0 KB  |  104 lines

  1. /*     Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved. 
  2.  *
  3.  * Example of a loadable i386 driver. This driver doesn't do anything
  4.  * other than show that it has been loaded, probed, and has a valid
  5.  * IOEISADeviceDescription.
  6.  *
  7.  * HISTORY
  8.  * 04-Feb-93    Doug Mitchell at NeXT
  9.  *      Created. 
  10.  * 29-Mar-93    Kathy Walrath at NeXT
  11.  *      Modified for use as an example of building, loading, & debugging. 
  12.  */
  13. #import <driverkit/i386/directDevice.h>
  14. #import <driverkit/i386/IOEISADeviceDescription.h>
  15. #import <driverkit/generalFuncs.h>
  16. #import <kernserv/kern_server_types.h>
  17. #import <kernserv/prototypes.h>
  18. #import "myTestDriver.h"
  19. #import "myTestDriverUser.h"
  20.  
  21. #define my_PARAMETER_STRING "ack"
  22.  
  23. static int _myTestDriverUnit = 0;
  24.  
  25. @implementation myTestDriver
  26.  
  27. /*
  28.  * Probe, configure board and init new instance.  This method is 
  29.  * documented in the IODevice spec sheet.
  30.  */
  31. + (BOOL)probe:deviceDescription
  32. {
  33.     id driver;
  34.     
  35.     driver = [[self alloc] initFromDeviceDescription:deviceDescription];
  36.     if (driver == nil)
  37.     return NO;
  38.     else return YES;
  39. }
  40.  
  41. /*
  42.  * Init the new instance.  This method is documented in the i386-specific
  43.  * part of the IODirectDevice spec sheet.
  44.  */
  45. - initFromDeviceDescription:deviceDescription
  46. {
  47.     char name[80];
  48.  
  49. #ifdef USE_HW
  50.     /* 
  51.      * A real driver would call [super initFromDeviceDescription:], which
  52.      * reserves hardware resources (DMA channels, I/O ports, etc.).  
  53.      * Since this driver doesn't really do anything, it isn't necessary 
  54.      * to reserve resources.  However, it shouldn't hurt anything to 
  55.      * reserve them.  If the resources specified in this driver's bundle 
  56.      * (in /usr/Devices/myTestDriver.config/*.table) are already reserved,
  57.      * [super initFromDeviceDescription:] will return nil.
  58.      */
  59.     if ([super initFromDeviceDescription:deviceDescription] == nil)
  60.         return nil;
  61. #endif USE_HW
  62.  
  63.     IOLog("myTestDriver: interrupt %d channel %d\n",
  64.     [deviceDescription interrupt], 
  65.     [deviceDescription channel]);
  66.     sprintf(name, "%s%d", my_DEVICE_NAME, _myTestDriverUnit);
  67.     [self setName:name];
  68.     [self setUnit:_myTestDriverUnit++];
  69.     [self setLocation:NULL];
  70.     [self registerDevice];
  71.     _myParameter = my_PARAMETER_STRING;
  72.     
  73.     return self; 
  74. }
  75.  
  76. /* 
  77.  * This method is documented in the IODevice spec sheet.
  78.  */
  79. - (IOReturn)getCharValues   : (unsigned char *)parameterArray
  80.                forParameter : (IOParameterName)parameterName
  81.                       count : (unsigned int *)count
  82. {
  83.     const char  *param;
  84.     unsigned int length;
  85.     unsigned int maxCount = *count;
  86.  
  87.     if(strcmp(parameterName, my_PARAMETER_NAME) == 0){
  88.         param = _myParameter;
  89.         length = strlen(param);
  90.         if(length >= maxCount) {
  91.             length = maxCount - 1;
  92.         }
  93.         *count = length + 1;
  94.         strncpy(parameterArray, param, length);
  95.         parameterArray[length] = '\0';
  96.         return IO_R_SUCCESS;
  97.     }
  98.     else { 
  99.     /* Pass parameters we don't recognize to our superclass. */
  100.         return [super getCharValues:parameterArray 
  101.             forParameter:parameterName count:count];
  102.     }
  103. }
  104.