00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 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 /** Asynchronous transfer status.*/ 00064 volatile uint32_t status; 00065 /** Callback function to invoke when transfer completes or fails.*/ 00066 void *callback; 00067 /** Driver storage area; do not use.*/ 00068 uint8_t pStorage[9]; 00069 } Async; 00070 00071 /** \brief TWI driver structure. Holds the internal state of the driver.*/ 00072 typedef struct _Twid { 00073 /** Pointer to the underlying TWI peripheral.*/ 00074 Twihs *pTwi; 00075 /** Current asynchronous transfer being processed.*/ 00076 Async *pTransfer; 00077 } Twid; 00078 00079 /** \brief TWI driver structure. Holds the internal state of the driver.*/ 00080 typedef struct { 00081 uint8_t Twi_id; 00082 /** Pointer to the underlying TWI driver.*/ 00083 Twid *pTwid; 00084 /** Pointer to the underlying DMA driver for TWI.*/ 00085 sXdmad *pTwiDma; 00086 } TwihsDma; 00087 00088 /*---------------------------------------------------------------------------- 00089 * Export functions 00090 *----------------------------------------------------------------------------*/ 00091 extern void TWID_Initialize(Twid *pTwid, Twihs *pTwi); 00092 extern void TWID_DmaInitialize(TwihsDma *pTwidma, Twihs *pTwi, 00093 uint8_t bPolling); 00094 00095 extern void TWID_Handler(Twid *pTwid); 00096 00097 extern uint32_t ASYNC_IsFinished(Async *pAsync); 00098 00099 extern uint8_t TWID_Read( 00100 Twid *pTwid, 00101 uint8_t address, 00102 uint32_t iaddress, 00103 uint8_t isize, 00104 uint8_t *pData, 00105 uint32_t num, 00106 Async *pAsync); 00107 00108 extern uint8_t TWID_Write( 00109 Twid *pTwid, 00110 uint8_t address, 00111 uint32_t iaddress, 00112 uint8_t isize, 00113 uint8_t *pData, 00114 uint32_t num, 00115 Async *pAsync); 00116 00117 extern uint8_t TWID_DmaRead( 00118 TwihsDma *pTwiXdma, 00119 uint8_t address, 00120 uint32_t iaddress, 00121 uint8_t isize, 00122 uint8_t *pData, 00123 uint32_t num, 00124 Async *pAsync); 00125 00126 extern uint8_t TWID_DmaWrite( 00127 TwihsDma *pTwiXdma, 00128 uint8_t address, 00129 uint32_t iaddress, 00130 uint8_t isize, 00131 uint8_t *pData, 00132 uint32_t num, 00133 Async *pAsync); 00134 00135 #ifdef __cplusplus 00136 } 00137 #endif 00138 00139 #endif //#ifndef TWID_H 00140