gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/include/sys/sensors.hbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*      $OpenBSD: sensors.h,v 1.31 2011/09/16 15:44:31 yuo Exp $     */
    2: 
    3: /*
    4:  * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
    5:  * Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru>
    6:  * All rights reserved.
    7:  *
    8:  * Redistribution and use in source and binary forms, with or without
    9:  * modification, are permitted provided that the following conditions
   10:  * are met:
   11:  * 1. Redistributions of source code must retain the above copyright
   12:  *    notice, this list of conditions and the following disclaimer.
   13:  * 2. Redistributions in binary form must reproduce the above copyright
   14:  *    notice, this list of conditions and the following disclaimer in the
   15:  *    documentation and/or other materials provided with the distribution.
   16:  *
   17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   18:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   19:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   20:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   21:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   22:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   23:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   24:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   25:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   26:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27:  */
   28: 
   29: #ifndef _SYS_SENSORS_H_
   30: #define _SYS_SENSORS_H_
   31: 
   32: /* Sensor types */
   33: enum sensor_type {
   34:         SENSOR_TEMP,                   /* temperature (muK) */
   35:         SENSOR_FANRPM,                 /* fan revolution speed */
   36:         SENSOR_VOLTS_DC,               /* voltage (muV DC) */
   37:         SENSOR_VOLTS_AC,               /* voltage (muV AC) */
   38:         SENSOR_OHMS,                   /* resistance */
   39:         SENSOR_WATTS,                  /* power (muW) */
   40:         SENSOR_AMPS,                   /* current (muA) */
   41:         SENSOR_WATTHOUR,               /* power capacity */
   42:         SENSOR_AMPHOUR,                        /* power capacity */
   43:         SENSOR_INDICATOR,              /* boolean indicator */
   44:         SENSOR_INTEGER,                        /* generic integer value */
   45:         SENSOR_PERCENT,                        /* percent */
   46:         SENSOR_LUX,                    /* illuminance (mulx) */
   47:         SENSOR_DRIVE,                  /* disk */
   48:         SENSOR_TIMEDELTA,              /* system time error (nSec) */
   49:         SENSOR_HUMIDITY,               /* humidity (m%RH) */
   50:         SENSOR_FREQ,                   /* frequency (muHz) */
   51:         SENSOR_ANGLE,                  /* angle (mudegrees) */
   52:         SENSOR_MAX_TYPES
   53: };
   54: 
   55: #ifndef _KERNEL
   56: static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = {
   57:         "temp",
   58:         "fan",
   59:         "volt",
   60:         "acvolt",
   61:         "resistance",
   62:         "power",
   63:         "current",
   64:         "watthour",
   65:         "amphour",
   66:         "indicator",
   67:         "raw",
   68:         "percent",
   69:         "illuminance",
   70:         "drive",
   71:         "timedelta",
   72:         "humidity",
   73:         "frequency",
   74:         "angle",
   75:         "undefined"
   76: };
   77: #endif  /* !_KERNEL */
   78: 
   79: #define SENSOR_DRIVE_EMPTY      1
   80: #define SENSOR_DRIVE_READY      2
   81: #define SENSOR_DRIVE_POWERUP    3
   82: #define SENSOR_DRIVE_ONLINE     4
   83: #define SENSOR_DRIVE_IDLE       5
   84: #define SENSOR_DRIVE_ACTIVE     6
   85: #define SENSOR_DRIVE_REBUILD    7
   86: #define SENSOR_DRIVE_POWERDOWN  8
   87: #define SENSOR_DRIVE_FAIL       9
   88: #define SENSOR_DRIVE_PFAIL      10
   89: 
   90: /* Sensor states */
   91: enum sensor_status {
   92:         SENSOR_S_UNSPEC,               /* status is unspecified */
   93:         SENSOR_S_OK,                   /* status is ok */
   94:         SENSOR_S_WARN,                 /* status is warning */
   95:         SENSOR_S_CRIT,                 /* status is critical */
   96:         SENSOR_S_UNKNOWN               /* status is unknown */
   97: };
   98: 
   99: /* Sensor data:
  100:  * New fields should be added at the end to encourage backwards compat
  101:  */
  102: struct sensor {
  103:         char desc[32];                 /* sensor description, may be empty */
  104:         struct timeval tv;             /* sensor value last change time */
  105:         int64_t value;                 /* current value */
  106:         enum sensor_type type;         /* sensor type */
  107:         enum sensor_status status;     /* sensor status */
  108:         int numt;                      /* sensor number of .type type */
  109:         int flags;                     /* sensor flags */
  110: #define SENSOR_FINVALID         0x0001 /* sensor is invalid */
  111: #define SENSOR_FUNKNOWN         0x0002 /* sensor value is unknown */
  112: };
  113: 
  114: /* Sensor device data:
  115:  * New fields should be added at the end to encourage backwards compat
  116:  */
  117: struct sensordev {
  118:         int num;                       /* sensordev number */
  119:         char xname[16];                        /* unix device name */
  120:         int maxnumt[SENSOR_MAX_TYPES];
  121:         int sensors_count;
  122: };
  123: 
  124: #ifdef _KERNEL
  125: 
  126: /* Sensor data */
  127: struct ksensor {
  128:         SLIST_ENTRY(ksensor) list;     /* device-scope list */
  129:         char desc[32];                 /* sensor description, may be empty */
  130:         struct timeval tv;             /* sensor value last change time */
  131:         int64_t value;                 /* current value */
  132:         enum sensor_type type;         /* sensor type */
  133:         enum sensor_status status;     /* sensor status */
  134:         int numt;                      /* sensor number of .type type */
  135:         int flags;                     /* sensor flags, ie. SENSOR_FINVALID */
  136: };
  137: SLIST_HEAD(ksensors_head, ksensor);
  138: 
  139: /* Sensor device data */
  140: struct ksensordev {
  141:         SLIST_ENTRY(ksensordev)        list;
  142:         int num;                       /* sensordev number */
  143:         char xname[16];                        /* unix device name */
  144:         int maxnumt[SENSOR_MAX_TYPES];
  145:         int sensors_count;
  146:         struct ksensors_head sensors_list;
  147: };
  148: 
  149: /* struct ksensordev */
  150: void                     sensordev_install(struct ksensordev *);
  151: void                     sensordev_deinstall(struct ksensordev *);
  152: int                      sensordev_get(int, struct ksensordev **);
  153: 
  154: /* struct ksensor */
  155: void                     sensor_attach(struct ksensordev *, struct ksensor *);
  156: void                     sensor_detach(struct ksensordev *, struct ksensor *);
  157: int                      sensor_find(int, enum sensor_type, int, struct ksensor **);
  158: 
  159: /* task scheduling */
  160: struct sensor_task;
  161: struct sensor_task      *sensor_task_register(void *, void (*)(void *), int);
  162: void                     sensor_task_unregister(struct sensor_task *);
  163: 
  164: #endif  /* _KERNEL */
  165: 
  166: #endif  /* !_SYS_SENSORS_H_ */