]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/peripherals/twi.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / peripherals / twi.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2015, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Interface for configuration the Two Wire Interface (TWI) peripheral.\r
34  *\r
35  */\r
36 \r
37 #ifndef _TWI_H_\r
38 #define _TWI_H_\r
39 \r
40 /*------------------------------------------------------------------------------\r
41  *         Headers\r
42  *------------------------------------------------------------------------------*/\r
43 \r
44 #include "chip.h"\r
45 \r
46 #include <stdint.h>\r
47 \r
48 /*----------------------------------------------------------------------------\r
49  *        Macros\r
50  *----------------------------------------------------------------------------*/\r
51 /* Returns 1 if the TXRDY bit (ready to transmit data) is set in the given status register value.*/\r
52 #define TWI_STATUS_TXRDY(status) ((status & TWI_SR_TXRDY) == TWI_SR_TXRDY)\r
53 \r
54 /* Returns 1 if the RXRDY bit (ready to receive data) is set in the given status register value.*/\r
55 #define TWI_STATUS_RXRDY(status) ((status & TWI_SR_RXRDY) == TWI_SR_RXRDY)\r
56 \r
57 /* Returns 1 if the TXCOMP bit (transfer complete) is set in the given status register value.*/\r
58 #define TWI_STATUS_TXCOMP(status) ((status & TWI_SR_TXCOMP) == TWI_SR_TXCOMP)\r
59 \r
60 #ifdef __cplusplus\r
61 extern "C" {\r
62 #endif\r
63 \r
64 /*----------------------------------------------------------------------------\r
65  *        External function\r
66  *----------------------------------------------------------------------------*/\r
67 \r
68 extern void twi_configure_master(Twi * pTwi, uint32_t twck);\r
69 extern void twi_configure_slave(Twi * pTwi, uint8_t slaveAddress);\r
70 extern void twi_stop(Twi * pTwi);\r
71 extern void twi_start_read(Twi * pTwi, uint8_t address,\r
72                                                    uint32_t iaddress, uint8_t isize);\r
73 extern uint8_t twi_read_byte(Twi * pTwi);\r
74 extern void twi_write_byte(Twi * pTwi, uint8_t byte);\r
75 extern void twi_start_write(Twi * pTwi, uint8_t address, uint32_t iaddress,\r
76                                                         uint8_t isize, uint8_t byte);\r
77 extern uint8_t twi_is_byte_received(Twi * pTwi);\r
78 extern uint8_t twi_byte_sent(Twi * pTwi);\r
79 extern uint8_t twi_is_transfer_complete(Twi * pTwi);\r
80 extern void twi_enable_it(Twi * pTwi, uint32_t sources);\r
81 extern void twi_disable_it(Twi * pTwi, uint32_t sources);\r
82 extern uint32_t twi_get_status(Twi * pTwi);\r
83 extern uint32_t twi_get_masked_status(Twi * pTwi);\r
84 extern void twi_send_stop_condition(Twi * pTwi);\r
85 \r
86 #ifdef CONFIG_HAVE_TWI_ALTERNATE_CMD\r
87 extern void twi_init_write_transfert(Twi * twi, uint8_t addr, uint32_t iaddress,\r
88                                      uint8_t isize, uint8_t len);\r
89 extern void twi_init_read_transfert(Twi * twi, uint8_t addr, uint32_t iaddress,\r
90                                     uint8_t isize, uint8_t len);\r
91 #endif\r
92 \r
93 #ifdef CONFIG_HAVE_TWI_FIFO\r
94 extern void twi_fifo_configure(Twi* twi, uint8_t tx_thres,\r
95                         uint8_t rx_thres,\r
96                         uint32_t ready_modes);\r
97 extern void twi_fifo_disable(Twi* twi);\r
98 \r
99 extern uint32_t twi_fifo_rx_size(Twi *twi);\r
100 extern uint32_t twi_fifo_tx_size(Twi *twi);\r
101 \r
102 extern uint32_t twi_read_stream(Twi *twi, uint32_t addr, uint32_t iaddr,\r
103                                  uint32_t isize, const void *stream, uint8_t len);\r
104 extern uint32_t twi_write_stream(Twi *twi, uint32_t addr, uint32_t iaddr,\r
105                                  uint32_t isize, const void *stream, uint8_t len);\r
106 #endif\r
107 \r
108 #ifdef __cplusplus\r
109 }\r
110 #endif\r
111 #endif /* #ifndef _TWI_H_ */\r