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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [AT91Lib/] [peripherals/] [adc/] [adc12.h] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
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 are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
//------------------------------------------------------------------------------
31
/// \unit
32
///
33
/// !Purpose
34
///
35
/// Interface for configuration the Analog-to-Digital Converter (ADC) peripheral.
36
///
37
/// !Usage
38
///
39
/// -# Configurate the pins for ADC
40
/// -# Initialize the ADC with ADC_Initialize().
41
/// -# Select the active channel using ADC_EnableChannel()
42
/// -# Start the conversion with ADC_StartConversion()
43
//  -# Wait the end of the conversion by polling status with ADC_GetStatus()
44
//  -# Finally, get the converted data using ADC_GetConvertedData()
45
///
46
//------------------------------------------------------------------------------
47
#ifndef ADC12_H
48
#define ADC12_H
49
 
50
//------------------------------------------------------------------------------
51
//         Headers
52
//------------------------------------------------------------------------------
53
#include <utility/assert.h>
54
 
55
//------------------------------------------------------------------------------
56
//         Definitions
57
//------------------------------------------------------------------------------
58
#define ADC_CHANNEL_0 0
59
#define ADC_CHANNEL_1 1
60
#define ADC_CHANNEL_2 2
61
#define ADC_CHANNEL_3 3
62
#define ADC_CHANNEL_4 4
63
#define ADC_CHANNEL_5 5
64
#define ADC_CHANNEL_6 6
65
#define ADC_CHANNEL_7 7
66
 
67
//------------------------------------------------------------------------------
68
//         Macros function of register access
69
//------------------------------------------------------------------------------
70
#define ADC12_CfgModeReg(pAdc, mode)  { \
71
            ASSERT(((mode)&0xF00000C0)== 0, "ADC Bad configuration ADC MR");\
72
            (pAdc)->ADC_MR = (mode);\
73
        }
74
 
75
#define ADC12_GetModeReg(pAdc)                ((pAdc)->ADC_MR)
76
 
77
#define ADC12_StartConversion(pAdc)           ((pAdc)->ADC_CR = AT91C_ADC_START)
78
 
79
#define ADC12_SoftReset(pAdc)                 ((pAdc)->ADC_CR = AT91C_ADC_SWRST)
80
 
81
#define ADC12_EnableChannel(pAdc, channel)    {\
82
            ASSERT(channel < 8, "ADC Channel not exist");\
83
            (pAdc)->ADC_CHER = (1 << (channel));\
84
        }
85
 
86
#define ADC12_DisableChannel (pAdc, channel)  {\
87
            ASSERT((channel) < 8, "ADC Channel not exist");\
88
            (pAdc)->ADC_CHDR = (1 << (channel));\
89
        }
90
 
91
#define ADC12_EnableIt(pAdc, mode)            {\
92
            ASSERT(((mode)&0xFFF00000)== 0, "ADC bad interrupt IER");\
93
            (pAdc)->ADC_IER = (mode);\
94
        }
95
 
96
#define ADC12_DisableIt(pAdc, mode)           {\
97
            ASSERT(((mode)&0xFFF00000)== 0, "ADC bad interrupt IDR");\
98
            (pAdc)->ADC_IDR = (mode);\
99
        }
100
 
101
#define ADC12_EnableDataReadyIt(pAdc)         ((pAdc)->ADC_IER = AT91C_ADC_DRDY)
102
 
103
#define ADC12_GetStatus(pAdc)                 ((pAdc)->ADC_SR)
104
 
105
#define ADC12_GetChannelStatus(pAdc)          ((pAdc)->ADC_CHSR)
106
 
107
#define ADC12_GetInterruptMaskStatus(pAdc)    ((pAdc)->ADC_IMR)
108
 
109
#define ADC12_GetLastConvertedData(pAdc)      ((pAdc)->ADC_LCDR)
110
 
111
#define ADC12_CfgAnalogCtrlReg(pAdc,mode)     {\
112
            ASSERT(((mode) & 0xFFFCFF3C)==0, "ADC bad analog control config");\
113
            (pAdc)->ADC_ACR = (mode);\
114
        }
115
 
116
#define ADC12_CfgExtModeReg(pAdc, extmode)    {\
117
            ASSERT(((extmode) & 0xFF00FFFE)==0, "ADC bad extended mode config");\
118
            (pAdc)->ADC_EMR = (extmode);\
119
        }
120
 
121
#define ADC12_GetAnalogCtrlReg(pAdc)          ((pAdc)->ADC_ACR)
122
 
123
//------------------------------------------------------------------------------
124
//         Exported functions
125
//------------------------------------------------------------------------------
126
extern void ADC12_Initialize (AT91S_ADC *pAdc,
127
                     unsigned char idAdc,
128
                     unsigned char trgEn,
129
                     unsigned char trgSel,
130
                     unsigned char sleepMode,
131
                     unsigned char resolution,
132
                     unsigned int mckClock,
133
                     unsigned int adcClock,
134
                     unsigned int startupTime,
135
                     unsigned int sampleAndHoldTime);
136
extern unsigned int ADC12_GetConvertedData(AT91S_ADC *pAdc, unsigned int channel);
137
extern unsigned int ADC12_IsInterruptMasked(AT91S_ADC *pAdc, unsigned int flag);
138
extern unsigned int ADC12_IsStatusSet(AT91S_ADC *pAdc, unsigned int flag);
139
extern unsigned char ADC12_IsChannelInterruptStatusSet(unsigned int adc_sr,
140
                                              unsigned int channel);
141
 
142
#endif //#ifndef ADC12_H

powered by: WebSVN 2.1.0

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