nidas  v1.2-1520
types.h
Go to the documentation of this file.
1 /* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8; -*- */
2 /* vim: set shiftwidth=8 softtabstop=8 expandtab: */
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2007, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 /*
27 
28  C structures defining samples which are sent from Linux modules to user space.
29 
30 */
31 
32 #ifndef NIDAS_LINUX_TYPES_H
33 #define NIDAS_LINUX_TYPES_H
34 
35 /* get other types while we're at it. */
36 #ifdef __KERNEL__
37 #include <linux/types.h>
38 #else
39 #include <sys/types.h>
40 #include <stdint.h>
41 #endif
42 
48 typedef int dsm_sample_time_t;
49 
51 typedef unsigned int dsm_sample_length_t;
52 
53 /*
54  * A data sample as it is passed from kernel-level drivers
55  * to user space.
56  *
57  * The time tag is a 4-byte time, relative to 00:00 UTC, which
58  * is converted to an 8-byte absolute time after the sample
59  * is read in real-time.
60  *
61  * The data member array length is 0, allowing one to create
62  * varying length samples.
63  * In actual use one will create and use a dsm_sample
64  * as follows:
65  struct dsm_sample* samp =
66  kmalloc(SIZEOF_DSM_SAMPLE_HEADER + SPACE_ENOUGH_FOR_DATA,GFP_KERNEL);
67  ...
68  samp->timetag = xxx;
69  if (len > SPACE_ENOUGH_FOR_DATA) we_ve_got_trouble();
70  samp->length = len;
71  memcpy(samp->data,buffer,len);
72  ...
73  *
74  * When sample is read on the user side:
75  struct dsm_sample header;
76  read(fd,&header,SIZEOF_DSM_SAMPLE_HEADER);
77  char* data = (char*) malloc(header.length);
78  * read data portion
79  read(fd,data,header.length);
80  */
81 
82 typedef struct dsm_sample {
83 
86 
89 
91  char data[0];
92 } dsm_sample_t;
93 
94 #define SIZEOF_DSM_SAMPLE_HEADER \
95  (sizeof(dsm_sample_time_t) + sizeof(dsm_sample_length_t))
96 
97 #ifndef NSECS_PER_SEC
98 #define NSECS_PER_SEC 1000000000
99 #endif
100 
101 #ifndef NSECS_PER_MSEC
102 #define NSECS_PER_MSEC 1000000
103 #endif
104 
105 /* TMSEC is a tenth of a millisecond */
106 #ifndef NSECS_PER_TMSEC
107 #define NSECS_PER_TMSEC 100000
108 #endif
109 
110 #ifndef NSECS_PER_USEC
111 #define NSECS_PER_USEC 1000
112 #endif
113 
114 #ifndef USECS_PER_MSEC
115 #define USECS_PER_MSEC 1000
116 #endif
117 
118 #ifndef USECS_PER_TMSEC
119 #define USECS_PER_TMSEC 100
120 #endif
121 
122 #ifndef TMSECS_PER_MSEC
123 #define TMSECS_PER_MSEC 10
124 #endif
125 
126 #ifndef USECS_PER_SEC
127 #define USECS_PER_SEC 1000000
128 #endif
129 
130 #ifndef MSECS_PER_SEC
131 #define MSECS_PER_SEC 1000
132 #endif
133 
134 #ifndef TMSECS_PER_SEC
135 #define TMSECS_PER_SEC 10000
136 #endif
137 
138 #ifndef MSECS_PER_DAY
139 #define MSECS_PER_DAY 86400000
140 #endif
141 
142 #ifndef TMSECS_PER_DAY
143 #define TMSECS_PER_DAY 864000000
144 #endif
145 
146 #ifndef SECS_PER_DAY
147 #define SECS_PER_DAY 86400
148 #endif
149 
150 #endif
int dsm_sample_time_t
Depending on the module, either tenths of milliseconds, or milliseconds since 00:00 UTC today...
Definition: types.h:48
dsm_sample_length_t length
number of bytes in data
Definition: types.h:88
struct dsm_sample dsm_sample_t
dsm_sample_time_t timetag
4-byte relative timetag of sample
Definition: types.h:85
Definition: types.h:82
unsigned int dsm_sample_length_t
length of data portion of sample.
Definition: types.h:51
char data[0]
space holder for the data
Definition: types.h:91