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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3S811_IAR/] [LuminaryCode/] [comp.c] - Blame information for rev 785

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

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//
3
// comp.c - Driver for the analog comparator.
4
//
5
// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
6
//
7
// Software License Agreement
8
//
9
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10
// exclusively on LMI's Stellaris Family of microcontroller products.
11
//
12
// The software is owned by LMI and/or its suppliers, and is protected under
13
// applicable copyright laws.  All rights are reserved.  Any use in violation
14
// of the foregoing restrictions may subject the user to criminal sanctions
15
// under applicable laws, as well as to civil liability for the breach of the
16
// terms and conditions of this license.
17
//
18
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
//
24
// This is part of revision 991 of the Stellaris Driver Library.
25
//
26
//*****************************************************************************
27
 
28
//*****************************************************************************
29
//
30
//! \addtogroup comp_api
31
//! @{
32
//
33
//*****************************************************************************
34
 
35
#include "../hw_comp.h"
36
#include "../hw_ints.h"
37
#include "../hw_memmap.h"
38
#include "../hw_types.h"
39
#include "comp.h"
40
#include "debug.h"
41
#include "interrupt.h"
42
 
43
//*****************************************************************************
44
//
45
//! Configures a comparator.
46
//!
47
//! \param ulBase is the base address of the comparator module.
48
//! \param ulComp is the index of the comparator to configure.
49
//! \param ulConfig is the configuration of the comparator.
50
//!
51
//! This function will configure a comparator.  The \e ulConfig parameter is
52
//! the result of a logical OR operation between the \b COMP_TRIG_xxx,
53
//! \b COMP_INT_xxx, \b COMP_ASRCP_xxx, and \b COMP_OUTPUT_xxx values.
54
//!
55
//! The \b COMP_TRIG_xxx term can take on the following values:
56
//!
57
//! - \b COMP_TRIG_NONE to have no trigger to the ADC.
58
//! - \b COMP_TRIG_HIGH to trigger the ADC when the comparator output is high.
59
//! - \b COMP_TRIG_LOW to trigger the ADC when the comparator output is low.
60
//! - \b COMP_TRIG_FALL to trigger the ADC when the comparator output goes low.
61
//! - \b COMP_TRIG_RISE to trigger the ADC when the comparator output goes
62
//! high.
63
//! - \b COMP_TRIG_BOTH to trigger the ADC when the comparator output goes low
64
//! or high.
65
//!
66
//! The \b COMP_INT_xxx term can take on the following values:
67
//!
68
//! - \b COMP_INT_HIGH to generate an interrupt when the comparator output is
69
//! high.
70
//! - \b COMP_INT_LOW to generate an interrupt when the comparator output is
71
//! low.
72
//! - \b COMP_INT_FALL to generate an interrupt when the comparator output goes
73
//! low.
74
//! - \b COMP_INT_RISE to generate an interrupt when the comparator output goes
75
//! high.
76
//! - \b COMP_INT_BOTH to generate an interrupt when the comparator output goes
77
//! low or high.
78
//!
79
//! The \b COMP_ASRCP_xxx term can take on the following values:
80
//!
81
//! - \b COMP_ASRCP_PIN to use the dedicated Comp+ pin as the reference
82
//! voltage.
83
//! - \b COMP_ASRCP_PIN0 to use the Comp0+ pin as the reference voltage (this
84
//! the same as \b COMP_ASRCP_PIN for the comparator 0).
85
//! - \b COMP_ASRCP_REF to use the internally generated voltage as the
86
//! reference voltage.
87
//!
88
//! The \b COMP_OUTPUT_xxx term can take on the following values:
89
//!
90
//! - \b COMP_OUTPUT_NONE to disable the output from the comparator to a device
91
//! pin.
92
//! - \b COMP_OUTPUT_NORMAL to enable a non-inverted output from the comparator
93
//! to a device pin.
94
//! - \b COMP_OUTPUT_INVERT to enable an inverted output from the comparator to
95
//! a device pin.
96
//!
97
//! \return None.
98
//
99
//*****************************************************************************
100
#if defined(GROUP_configure) || defined(BUILD_ALL) || defined(DOXYGEN)
101
void
102
ComparatorConfigure(unsigned long ulBase, unsigned long ulComp,
103
                    unsigned long ulConfig)
104
{
105
    //
106
    // Check the arguments.
107
    //
108
    ASSERT(ulBase == COMP_BASE);
109
    ASSERT(ulComp < 3);
110
 
111
    //
112
    // Configure this comparator.
113
    //
114
    HWREG(ulBase + (ulComp * 0x20) + COMP_O_ACCTL0) = ulConfig;
115
}
116
#endif
117
 
118
//*****************************************************************************
119
//
120
//! Sets the internal reference voltage.
121
//!
122
//! \param ulBase is the base address of the comparator module.
123
//! \param ulRef is the desired reference voltage.
124
//!
125
//! This function will set the internal reference voltage value.  The voltage
126
//! is specified as one of the following values:
127
//!
128
//! - \b COMP_REF_OFF to turn off the reference voltage
129
//! - \b COMP_REF_0V to set the reference voltage to 0 V
130
//! - \b COMP_REF_0_1375V to set the reference voltage to 0.1375 V
131
//! - \b COMP_REF_0_275V to set the reference voltage to 0.275 V
132
//! - \b COMP_REF_0_4125V to set the reference voltage to 0.4125 V
133
//! - \b COMP_REF_0_55V to set the reference voltage to 0.55 V
134
//! - \b COMP_REF_0_6875V to set the reference voltage to 0.6875 V
135
//! - \b COMP_REF_0_825V to set the reference voltage to 0.825 V
136
//! - \b COMP_REF_0_928125V to set the reference voltage to 0.928125 V
137
//! - \b COMP_REF_0_9625V to set the reference voltage to 0.9625 V
138
//! - \b COMP_REF_1_03125V to set the reference voltage to 1.03125 V
139
//! - \b COMP_REF_1_134375V to set the reference voltage to 1.134375 V
140
//! - \b COMP_REF_1_1V to set the reference voltage to 1.1 V
141
//! - \b COMP_REF_1_2375V to set the reference voltage to 1.2375 V
142
//! - \b COMP_REF_1_340625V to set the reference voltage to 1.340625 V
143
//! - \b COMP_REF_1_375V to set the reference voltage to 1.375 V
144
//! - \b COMP_REF_1_44375V to set the reference voltage to 1.44375 V
145
//! - \b COMP_REF_1_5125V to set the reference voltage to 1.5125 V
146
//! - \b COMP_REF_1_546875V to set the reference voltage to 1.546875 V
147
//! - \b COMP_REF_1_65V to set the reference voltage to 1.65 V
148
//! - \b COMP_REF_1_753125V to set the reference voltage to 1.753125 V
149
//! - \b COMP_REF_1_7875V to set the reference voltage to 1.7875 V
150
//! - \b COMP_REF_1_85625V to set the reference voltage to 1.85625 V
151
//! - \b COMP_REF_1_925V to set the reference voltage to 1.925 V
152
//! - \b COMP_REF_1_959375V to set the reference voltage to 1.959375 V
153
//! - \b COMP_REF_2_0625V to set the reference voltage to 2.0625 V
154
//! - \b COMP_REF_2_165625V to set the reference voltage to 2.165625 V
155
//! - \b COMP_REF_2_26875V to set the reference voltage to 2.26875 V
156
//! - \b COMP_REF_2_371875V to set the reference voltage to 2.371875 V
157
//!
158
//! \return None.
159
//
160
//*****************************************************************************
161
#if defined(GROUP_refset) || defined(BUILD_ALL) || defined(DOXYGEN)
162
void
163
ComparatorRefSet(unsigned long ulBase, unsigned long ulRef)
164
{
165
    //
166
    // Check the arguments.
167
    //
168
    ASSERT(ulBase == COMP_BASE);
169
 
170
    //
171
    // Set the voltage reference voltage as requested.
172
    //
173
    HWREG(ulBase + COMP_O_REFCTL) = ulRef;
174
}
175
#endif
176
 
177
//*****************************************************************************
178
//
179
//! Gets the current comparator output value.
180
//!
181
//! \param ulBase is the base address of the comparator module.
182
//! \param ulComp is the index of the comparator.
183
//!
184
//! This function retrieves the current value of the comparator output.
185
//!
186
//! \return Returns \b true if the comparator output is high and \b false if
187
//! the comparator output is low.
188
//
189
//*****************************************************************************
190
#if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)
191
tBoolean
192
ComparatorValueGet(unsigned long ulBase, unsigned long ulComp)
193
{
194
    //
195
    // Check the arguments.
196
    //
197
    ASSERT(ulBase == COMP_BASE);
198
    ASSERT(ulComp < 3);
199
 
200
    //
201
    // Return the appropriate value based on the comparator's present output
202
    // value.
203
    //
204
    if(HWREG(ulBase + (ulComp * 0x20) + COMP_O_ACSTAT0) & COMP_ACSTAT_OVAL)
205
    {
206
        return(true);
207
    }
208
    else
209
    {
210
        return(false);
211
    }
212
}
213
#endif
214
 
215
//*****************************************************************************
216
//
217
//! Registers an interrupt handler for the comparator interrupt.
218
//!
219
//! \param ulBase is the base address of the comparator module.
220
//! \param ulComp is the index of the comparator.
221
//! \param pfnHandler is a pointer to the function to be called when the
222
//! comparator interrupt occurs.
223
//!
224
//! This sets the handler to be called when the comparator interrupt occurs.
225
//! This will enable the interrupt in the interrupt controller; it is the
226
//! interrupt-handler's responsibility to clear the interrupt source via
227
//! ComparatorIntClear().
228
//!
229
//! \sa IntRegister() for important information about registering interrupt
230
//! handlers.
231
//!
232
//! \return None.
233
//
234
//*****************************************************************************
235
#if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
236
void
237
ComparatorIntRegister(unsigned long ulBase, unsigned long ulComp,
238
                      void (*pfnHandler)(void))
239
{
240
    //
241
    // Check the arguments.
242
    //
243
    ASSERT(ulBase == COMP_BASE);
244
    ASSERT(ulComp < 3);
245
 
246
    //
247
    // Register the interrupt handler, returning an error if an error occurs.
248
    //
249
    IntRegister(INT_COMP0 + ulComp, pfnHandler);
250
 
251
    //
252
    // Enable the interrupt in the interrupt controller.
253
    //
254
    IntEnable(INT_COMP0 + ulComp);
255
 
256
    //
257
    // Enable the comparator interrupt.
258
    //
259
    HWREG(ulBase + COMP_O_INTEN) |= 1 << ulComp;
260
}
261
#endif
262
 
263
//*****************************************************************************
264
//
265
//! Unregisters an interrupt handler for a comparator interrupt.
266
//!
267
//! \param ulBase is the base address of the comparator module.
268
//! \param ulComp is the index of the comparator.
269
//!
270
//! This function will clear the handler to be called when a comparator
271
//! interrupt occurs.  This will also mask off the interrupt in the interrupt
272
//! controller so that the interrupt handler no longer is called.
273
//!
274
//! \sa IntRegister() for important information about registering interrupt
275
//! handlers.
276
//!
277
//! \return None.
278
//
279
//*****************************************************************************
280
#if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
281
void
282
ComparatorIntUnregister(unsigned long ulBase, unsigned long ulComp)
283
{
284
    //
285
    // Check the arguments.
286
    //
287
    ASSERT(ulBase == COMP_BASE);
288
    ASSERT(ulComp < 3);
289
 
290
    //
291
    // Disable the comparator interrupt.
292
    //
293
    HWREG(ulBase + COMP_O_INTEN) &= ~(1 << ulComp);
294
 
295
    //
296
    // Disable the interrupt in the interrupt controller.
297
    //
298
    IntDisable(INT_COMP0 + ulComp);
299
 
300
    //
301
    // Unregister the interrupt handler.
302
    //
303
    IntUnregister(INT_COMP0 + ulComp);
304
}
305
#endif
306
 
307
//*****************************************************************************
308
//
309
//! Enables the comparator interrupt.
310
//!
311
//! \param ulBase is the base address of the comparator module.
312
//! \param ulComp is the index of the comparator.
313
//!
314
//! This function enables generation of an interrupt from the specified
315
//! comparator.  Only comparators whose interrupts are enabled can be reflected
316
//! to the processor.
317
//!
318
//! \return None.
319
//
320
//*****************************************************************************
321
#if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
322
void
323
ComparatorIntEnable(unsigned long ulBase, unsigned long ulComp)
324
{
325
    //
326
    // Check the arguments.
327
    //
328
    ASSERT(ulBase == COMP_BASE);
329
    ASSERT(ulComp < 3);
330
 
331
    //
332
    // Enable the comparator interrupt.
333
    //
334
    HWREG(ulBase + COMP_O_INTEN) |= 1 << ulComp;
335
}
336
#endif
337
 
338
//*****************************************************************************
339
//
340
//! Disables the comparator interrupt.
341
//!
342
//! \param ulBase is the base address of the comparator module.
343
//! \param ulComp is the index of the comparator.
344
//!
345
//! This function disables generation of an interrupt from the specified
346
//! comparator.  Only comparators whose interrupts are enabled can be reflected
347
//! to the processor.
348
//!
349
//! \return None.
350
//
351
//*****************************************************************************
352
#if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
353
void
354
ComparatorIntDisable(unsigned long ulBase, unsigned long ulComp)
355
{
356
    //
357
    // Check the arguments.
358
    //
359
    ASSERT(ulBase == COMP_BASE);
360
    ASSERT(ulComp < 3);
361
 
362
    //
363
    // Disable the comparator interrupt.
364
    //
365
    HWREG(ulBase + COMP_O_INTEN) &= ~(1 << ulComp);
366
}
367
#endif
368
 
369
//*****************************************************************************
370
//
371
//! Gets the current interrupt status.
372
//!
373
//! \param ulBase is the base address of the comparator module.
374
//! \param ulComp is the index of the comparator.
375
//! \param bMasked is \b false if the raw interrupt status is required and
376
//! \b true if the masked interrupt status is required.
377
//!
378
//! This returns the interrupt status for the comparator.  Either the raw or
379
//! the masked interrupt status can be returned.
380
//!
381
//! \return \b true if the interrupt is asserted and \b false if it is not
382
//! asserted.
383
//
384
//*****************************************************************************
385
#if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
386
tBoolean
387
ComparatorIntStatus(unsigned long ulBase, unsigned long ulComp,
388
                    tBoolean bMasked)
389
{
390
    //
391
    // Check the arguments.
392
    //
393
    ASSERT(ulBase == COMP_BASE);
394
    ASSERT(ulComp < 3);
395
 
396
    //
397
    // Return either the interrupt status or the raw interrupt status as
398
    // requested.
399
    //
400
    if(bMasked)
401
    {
402
        return(((HWREG(ulBase + COMP_O_MIS) >> ulComp) & 1) ? true : false);
403
    }
404
    else
405
    {
406
        return(((HWREG(ulBase + COMP_O_RIS) >> ulComp) & 1) ? true : false);
407
    }
408
}
409
#endif
410
 
411
//*****************************************************************************
412
//
413
//! Clears a comparator interrupt.
414
//!
415
//! \param ulBase is the base address of the comparator module.
416
//! \param ulComp is the index of the comparator.
417
//!
418
//! The comparator interrupt is cleared, so that it no longer asserts.  This
419
//! must be done in the interrupt handler to keep it from being called again
420
//! immediately upon exit.  Note that for a level triggered interrupt, the
421
//! interrupt cannot be cleared until it stops asserting.
422
//!
423
//! \return None.
424
//
425
//*****************************************************************************
426
#if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)
427
void
428
ComparatorIntClear(unsigned long ulBase, unsigned long ulComp)
429
{
430
    //
431
    // Check the arguments.
432
    //
433
    ASSERT(ulBase == COMP_BASE);
434
    ASSERT(ulComp < 3);
435
 
436
    //
437
    // Clear the interrupt.
438
    //
439
    HWREG(ulBase + COMP_O_MIS) = 1 << ulComp;
440
}
441
#endif
442
 
443
//*****************************************************************************
444
//
445
// Close the Doxygen group.
446
//! @}
447
//
448
//*****************************************************************************

powered by: WebSVN 2.1.0

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