SAMV71 Xplained Ultra Software Package 1.3

twi.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  * \file
00032  *
00033  * Interface for configuration the Two Wire Interface (TWI) peripheral.
00034  *
00035  */
00036 
00037 #ifndef _TWI_
00038 #define _TWI_
00039 
00040 /*------------------------------------------------------------------------------
00041  *         Headers
00042  *----------------------------------------------------------------------------*/
00043 
00044 #include "chip.h"
00045 
00046 #include <stdint.h>
00047 
00048 /*----------------------------------------------------------------------------
00049  *        Macros
00050  *----------------------------------------------------------------------------*/
00051 /* Returns 1 if the TXRDY bit (ready to transmit data) is set in the given 
00052     status register value.*/
00053 #define TWI_STATUS_TXRDY(status) ((status & TWIHS_SR_TXRDY) == TWIHS_SR_TXRDY)
00054 
00055 /* Returns 1 if the RXRDY bit (ready to receive data) is set in the given 
00056     status register value.*/
00057 #define TWI_STATUS_RXRDY(status) ((status & TWIHS_SR_RXRDY) == TWIHS_SR_RXRDY)
00058 
00059 /* Returns 1 if the TXCOMP bit (transfer complete) is set in the given 
00060     status register value.*/
00061 #define TWI_STATUS_TXCOMP(status) ((status & TWIHS_SR_TXCOMP) == TWIHS_SR_TXCOMP)
00062 
00063 #ifdef __cplusplus
00064  extern "C" {
00065 #endif
00066 
00067 /*----------------------------------------------------------------------------
00068  *        External function
00069  *----------------------------------------------------------------------------*/
00070 
00071 extern void TWI_ConfigureMaster(Twihs *pTwi, uint32_t twck, uint32_t mck);
00072 
00073 extern void TWI_ConfigureSlave(Twihs *pTwi, uint8_t slaveAddress);
00074 
00075 extern void TWI_Stop(Twihs *pTwi);
00076 
00077 extern void TWI_StartRead(
00078     Twihs *pTwi,
00079     uint8_t address,
00080     uint32_t iaddress,
00081     uint8_t isize);
00082 
00083 extern uint8_t TWI_ReadByte(Twihs *pTwi);
00084 
00085 extern void TWI_WriteByte(Twihs *pTwi, uint8_t byte);
00086 
00087 extern void TWI_StartWrite(
00088     Twihs *pTwi,
00089     uint8_t address,
00090     uint32_t iaddress,
00091     uint8_t isize,
00092     uint8_t byte);
00093 
00094 extern uint8_t TWI_ByteReceived(Twihs *pTwi);
00095 
00096 extern uint8_t TWI_ByteSent(Twihs *pTwi);
00097 
00098 extern uint8_t TWI_TransferComplete(Twihs *pTwi);
00099 
00100 extern void TWI_EnableIt(Twihs *pTwi, uint32_t sources);
00101 
00102 extern void TWI_DisableIt(Twihs *pTwi, uint32_t sources);
00103 
00104 extern uint32_t TWI_GetStatus(Twihs *pTwi);
00105 
00106 extern uint32_t TWI_GetMaskedStatus(Twihs *pTwi);
00107 
00108 extern void TWI_SendSTOPCondition(Twihs *pTwi);
00109 
00110 #ifdef __cplusplus
00111 }
00112 #endif
00113 
00114 #endif /* #ifndef _TWI_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines