SAMV71 Xplained Ultra Software Package 1.4

twid.h

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 #ifndef _TWID_
00031 #define _TWID_
00032 
00033 /*----------------------------------------------------------------------------
00034  *        Headers
00035  *----------------------------------------------------------------------------*/
00036 
00037 #include "chip.h"
00038 
00039 #include <stdint.h>
00040 
00041 /*----------------------------------------------------------------------------
00042  *        Definition
00043  *----------------------------------------------------------------------------*/
00044 
00045 /** TWI driver is currently busy. */
00046 #define TWID_ERROR_BUSY              1
00047 
00048    /** Transfer is still pending.*/
00049 #define ASYNC_STATUS_PENDING        0xFF
00050 #ifdef __cplusplus
00051  extern "C" {
00052 #endif
00053 
00054 /*----------------------------------------------------------------------------
00055  *        Types
00056  *----------------------------------------------------------------------------*/
00057 
00058    /*----------------------------------------------------------------------------
00059  *        Type
00060  *----------------------------------------------------------------------------*/
00061 /** \brief Asynchronous transfer descriptor. */
00062 typedef struct _Async
00063 {
00064     /** Asynchronous transfer status.*/
00065     volatile uint32_t status ;
00066     /** Callback function to invoke when transfer completes or fails.*/
00067     void *callback ;
00068     /** Driver storage area; do not use.*/
00069     uint8_t pStorage[9] ;
00070 } Async ;
00071 
00072 /** \brief TWI driver structure. Holds the internal state of the driver.*/
00073 typedef struct _Twid
00074 {
00075     /** Pointer to the underlying TWI peripheral.*/
00076     Twihs *pTwi ;
00077     /** Current asynchronous transfer being processed.*/
00078     Async *pTransfer ;
00079 } Twid;
00080 
00081 /** \brief TWI driver structure. Holds the internal state of the driver.*/
00082 typedef struct
00083 {
00084     uint8_t Twi_id;
00085     /** Pointer to the underlying TWI driver.*/
00086     Twid *pTwid ;
00087     /** Pointer to the underlying DMA driver for TWI.*/
00088     sXdmad *pTwiDma;
00089 } TwihsDma;
00090 
00091 /*----------------------------------------------------------------------------
00092  *        Export functions
00093  *----------------------------------------------------------------------------*/
00094 extern void TWID_Initialize( Twid *pTwid, Twihs *pTwi ) ;
00095 extern void TWID_DmaInitialize(TwihsDma *pTwidma, Twihs *pTwi, uint8_t bPolling);
00096 
00097 extern void TWID_Handler( Twid *pTwid ) ;
00098 
00099 extern uint32_t ASYNC_IsFinished( Async* pAsync ) ;
00100 
00101 extern uint8_t TWID_Read(
00102     Twid *pTwid,
00103     uint8_t address,
00104     uint32_t iaddress,
00105     uint8_t isize,
00106     uint8_t *pData,
00107     uint32_t num,
00108     Async *pAsync);
00109 
00110 extern uint8_t TWID_Write(
00111     Twid *pTwid,
00112     uint8_t address,
00113     uint32_t iaddress,
00114     uint8_t isize,
00115     uint8_t *pData,
00116     uint32_t num,
00117     Async *pAsync);
00118 
00119 extern uint8_t TWID_DmaRead(
00120     TwihsDma *pTwiXdma,
00121     uint8_t address,
00122     uint32_t iaddress,
00123     uint8_t isize,
00124     uint8_t *pData,
00125     uint32_t num,
00126     Async *pAsync);
00127 
00128 extern uint8_t TWID_DmaWrite(
00129     TwihsDma *pTwiXdma,
00130     uint8_t address,
00131     uint32_t iaddress,
00132     uint8_t isize,
00133     uint8_t *pData,
00134     uint32_t num,
00135     Async *pAsync);
00136 
00137 #ifdef __cplusplus
00138 }
00139 #endif
00140 
00141 #endif //#ifndef TWID_H
00142 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines