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/] [twi/] [twi.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 Two Wire Interface (TWI) peripheral.
36
///
37
/// !Usage
38
///
39
/// -# Configures a TWI peripheral to operate in master mode, at the given
40
/// frequency (in Hz) using TWI_ConfigureMaster().
41
/// -# or if hardware possible, configures a TWI peripheral to operate in 
42
/// slave mode, at the given frequency (in Hz) using TWI_ConfigureSlave().
43
/// -# Sends a STOP condition on the TWI using TWI_Stop().
44
/// -# Starts a read operation on the TWI bus with the specified slave using
45
/// TWI_StartRead(). Data must then be read using TWI_ReadByte() whenever 
46
/// a byte is available (poll using TWI_ByteReceived()).
47
/// -# Starts a write operation on the TWI to access the selected slave using
48
/// TWI_StartWrite(). A byte of data must be provided to start the write;
49
/// other bytes are written next. 
50
/// -# Sends a byte of data to one of the TWI slaves on the bus using TWI_WriteByte().
51
/// This function must be called once before TWI_StartWrite() with the first byte of data
52
/// to send, then it shall be called repeatedly after that to send the remaining bytes.
53
/// -# Check if a byte has been received and can be read on the given TWI
54
/// peripheral using TWI_ByteReceived(). 
55
/// Check if a byte has been sent using TWI_ByteSent().
56
/// -# Check if the current transmission is complete (the STOP has been sent)
57
/// using TWI_TransferComplete().
58
/// -# Enables & disable the selected interrupts sources on a TWI peripheral
59
/// using TWI_EnableIt() and TWI_DisableIt().
60
/// -# Get current status register of the given TWI peripheral using
61
/// TWI_GetStatus(). Get current status register of the given TWI peripheral, but
62
/// masking interrupt sources which are not currently enabled using 
63
/// TWI_GetMaskedStatus().
64
//------------------------------------------------------------------------------
65
 
66
#ifndef TWI_H
67
#define TWI_H
68
 
69
//------------------------------------------------------------------------------
70
//         Headers
71
//------------------------------------------------------------------------------
72
 
73
#include <board.h>
74
 
75
//------------------------------------------------------------------------------
76
//         Global definitions
77
//------------------------------------------------------------------------------
78
 
79
// Missing AT91C_TWI_TXRDY definition.
80
#ifndef AT91C_TWI_TXRDY
81
    #define AT91C_TWI_TXRDY   AT91C_TWI_TXRDY_MASTER
82
#endif
83
 
84
// Missing AT91C_TWI_TXCOMP definition.
85
#ifndef AT91C_TWI_TXCOMP
86
    #define AT91C_TWI_TXCOMP  AT91C_TWI_TXCOMP_MASTER
87
#endif
88
 
89
//------------------------------------------------------------------------------
90
//         Global macros
91
//------------------------------------------------------------------------------
92
 
93
/// Returns 1 if the TXRDY bit (ready to transmit data) is set in the given
94
/// status register value.
95
#define TWI_STATUS_TXRDY(status) ((status & AT91C_TWI_TXRDY) == AT91C_TWI_TXRDY)
96
 
97
/// Returns 1 if the RXRDY bit (ready to receive data) is set in the given
98
/// status register value.
99
#define TWI_STATUS_RXRDY(status) ((status & AT91C_TWI_RXRDY) == AT91C_TWI_RXRDY)
100
 
101
/// Returns 1 if the TXCOMP bit (transfer complete) is set in the given
102
/// status register value.
103
#define TWI_STATUS_TXCOMP(status) ((status & AT91C_TWI_TXCOMP) == AT91C_TWI_TXCOMP)
104
 
105
//------------------------------------------------------------------------------
106
//         Global functions
107
//------------------------------------------------------------------------------
108
 
109
extern void TWI_ConfigureMaster(AT91S_TWI *pTwi, unsigned int twck, unsigned int mck);
110
 
111
#ifdef AT91C_TWI_SVEN  // TWI slave
112
extern void TWI_ConfigureSlave(AT91S_TWI *pTwi, unsigned char slaveAddress);
113
#endif
114
 
115
extern void TWI_Stop(AT91S_TWI *pTwi);
116
 
117
extern void TWI_StartRead(
118
    AT91S_TWI *pTwi,
119
    unsigned char address,
120
    unsigned int iaddress,
121
    unsigned char isize);
122
 
123
extern unsigned char TWI_ReadByte(AT91S_TWI *pTwi);
124
 
125
extern void TWI_WriteByte(AT91S_TWI *pTwi, unsigned char byte);
126
 
127
extern void TWI_StartWrite(
128
    AT91S_TWI *pTwi,
129
    unsigned char address,
130
    unsigned int iaddress,
131
    unsigned char isize,
132
    unsigned char byte);
133
 
134
extern unsigned char TWI_ByteReceived(AT91S_TWI *pTwi);
135
 
136
extern unsigned char TWI_ByteSent(AT91S_TWI *pTwi);
137
 
138
extern unsigned char TWI_TransferComplete(AT91S_TWI *pTwi);
139
 
140
extern void TWI_EnableIt(AT91S_TWI *pTwi, unsigned int sources);
141
 
142
extern void TWI_DisableIt(AT91S_TWI *pTwi, unsigned int sources);
143
 
144
extern unsigned int TWI_GetStatus(AT91S_TWI *pTwi);
145
 
146
extern unsigned int TWI_GetMaskedStatus(AT91S_TWI *pTwi);
147
 
148
extern void TWI_SendSTOPCondition(AT91S_TWI *pTwi);
149
 
150
#endif //#ifndef TWI_H

powered by: WebSVN 2.1.0

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