OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [adc/] [current/] [include/] [adc.h] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_ADC_H
2
#define CYGONCE_ADC_H
3
/*==========================================================================
4
//
5
//      adc.h
6
//
7
//      Generic ADC driver layer header
8
//
9
//==========================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 2008 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later
18
// version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28
//
29
// As a special exception, if other files instantiate templates or use
30
// macros or inline functions from this file, or you compile this file
31
// and link it with other works to produce a work based on this file,
32
// this file does not by itself cause the resulting work to be covered by
33
// the GNU General Public License. However the source code for this file
34
// must still be made available in accordance with section (3) of the GNU
35
// General Public License v2.
36
//
37
// This exception does not invalidate any other reasons why a work based
38
// on this file might be covered by the GNU General Public License.
39
// -------------------------------------------
40
// ####ECOSGPLCOPYRIGHTEND####
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    nickg
45
// Date:         2008-03-31
46
// Description:  Implements generic layer of ADC drivers.
47
//
48
//####DESCRIPTIONEND####
49
//
50
//========================================================================*/
51
 
52
#include <pkgconf/system.h>
53
#include <pkgconf/io_adc.h>
54
 
55
#include <cyg/infra/cyg_type.h>
56
#include <cyg/io/io.h>
57
#include <cyg/io/devtab.h>
58
#include <cyg/io/config_keys.h>
59
#include <cyg/hal/drv_api.h>
60
 
61
 
62
#ifdef CYGPKG_IO_ADC_SELECT_SUPPORT
63
#include <cyg/fileio/fileio.h>
64
#endif
65
 
66
//==========================================================================
67
// Configuration information structure
68
 
69
typedef struct
70
{
71
    cyg_uint32          rate;           // Sample rate
72
} cyg_adc_info_t;
73
 
74
//==========================================================================
75
// Sample size type.
76
//
77
// Define sample size type depending on hardware capability.
78
 
79
#if CYGNUM_IO_ADC_SAMPLE_SIZE > 16
80
typedef cyg_int32 cyg_adc_sample_t;
81
#elif CYGNUM_IO_ADC_SAMPLE_SIZE > 8
82
typedef cyg_int16 cyg_adc_sample_t;
83
#else
84
typedef cyg_int8 cyg_adc_sample_t;
85
#endif
86
 
87
//==========================================================================
88
// Forward type definitions.
89
 
90
typedef struct cyg_adc_device cyg_adc_device;
91
typedef struct cyg_adc_channel cyg_adc_channel;
92
typedef struct cyg_adc_functions cyg_adc_functions;
93
 
94
//==========================================================================
95
// Callbacks from hardware drivers to generic driver.
96
 
97
__externC void cyg_adc_device_init( cyg_adc_device *device );
98
 
99
__externC void cyg_adc_channel_init(cyg_adc_channel *chan);
100
 
101
__externC cyg_uint32 cyg_adc_receive_sample(cyg_adc_channel *chan, cyg_adc_sample_t sample);
102
 
103
__externC void cyg_adc_wakeup(cyg_adc_channel *chan );
104
 
105
//==========================================================================
106
// Device table functions
107
 
108
__externC cyg_devio_table_t cyg_io_adc_devio;
109
 
110
//==========================================================================
111
// ADC device
112
//
113
// A single device may support several channels which share interrupt
114
// vectors and sample rate settings.
115
 
116
struct cyg_adc_device
117
{
118
    cyg_adc_functions   *funs;          // Hardware device functions
119
    void                *dev_priv;      // Hardware device private data
120
    cyg_adc_info_t      config;         // Current configuration
121
 
122
    cyg_bool            init;           // Initialized ?
123
    cyg_drv_mutex_t     lock;           // Device lock
124
};
125
 
126
#define CYG_ADC_DEVICE(__name, __funs, __dev_priv, __rate )     \
127
cyg_adc_device __name =                                         \
128
{                                                               \
129
    .funs               = __funs,                               \
130
    .dev_priv           = __dev_priv,                           \
131
    .config.rate        = __rate,                               \
132
    .init               = false                                 \
133
};
134
 
135
 
136
//==========================================================================
137
// ADC channel
138
//
139
// Each device may support several channels, each providing a separate
140
// stream of samples.
141
 
142
struct  cyg_adc_channel
143
{
144
    int                 channel;        // Channel number
145
 
146
    cyg_adc_sample_t    *buf;           // Sample data buffer
147
    int                 len;            // Buffer length in samples
148
    volatile int        put;            // Sample insert index
149
    volatile int        get;            // Sample extract index
150
 
151
    cyg_adc_device      *device;        // Controlling device
152
 
153
    cyg_bool            init;           // Initialized ?
154
    cyg_drv_cond_t      wait;           // Readers wait here for data
155
    cyg_bool            waiting;        // True if any threads waiting
156
    cyg_bool            wakeup;         // True if wakeup needed
157
 
158
    cyg_bool            enabled;        // Channel enabled?
159
    cyg_bool            blocking;       // Blocking IO
160
    int                 overflow;       // Overflow counter
161
 
162
#ifdef CYGPKG_IO_ADC_SELECT_SUPPORT    
163
    struct CYG_SELINFO_TAG   selinfo;   // Select info
164
#endif
165
 
166
};
167
 
168
#define CYG_ADC_CHANNEL( __name, __channel, __bufsize, __device )       \
169
static cyg_adc_sample_t __name##_buf[__bufsize];                        \
170
cyg_adc_channel __name =                                                \
171
{                                                                       \
172
    .channel            = __channel,                                    \
173
    .buf                = __name##_buf,                                 \
174
    .len                = __bufsize,                                    \
175
    .put                = 0,                                            \
176
    .get                = 0,                                            \
177
    .device             = __device,                                     \
178
    .init               = false                                         \
179
};
180
 
181
//==========================================================================
182
// Device functions
183
//
184
// These are the functions exported by the hardware device to the
185
// generic layer.
186
 
187
struct cyg_adc_functions
188
{
189
    void (*enable)( cyg_adc_channel *chan );
190
    void (*disable)( cyg_adc_channel *chan );
191
 
192
    void (*set_rate)( cyg_adc_channel *chan, cyg_uint32 rate );
193
};
194
 
195
#define CYG_ADC_FUNCTIONS( __name, __enable, __disable, __set_rate )    \
196
cyg_adc_functions __name =                                              \
197
{                                                                       \
198
    .enable             = __enable,                                     \
199
    .disable            = __disable,                                    \
200
    .set_rate           = __set_rate                                    \
201
};
202
 
203
//==========================================================================
204
#endif // CYGONCE_ADC_H
205
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.