1 | /* ---------------------------------------------------------------------------- */ |
---|
2 | /* Atmel Microcontroller Software Support */ |
---|
3 | /* SAM Software Package License */ |
---|
4 | /* ---------------------------------------------------------------------------- */ |
---|
5 | /* Copyright (c) 2015, Atmel Corporation */ |
---|
6 | /* */ |
---|
7 | /* All rights reserved. */ |
---|
8 | /* */ |
---|
9 | /* Redistribution and use in source and binary forms, with or without */ |
---|
10 | /* modification, are permitted provided that the following condition is met: */ |
---|
11 | /* */ |
---|
12 | /* - Redistributions of source code must retain the above copyright notice, */ |
---|
13 | /* this list of conditions and the disclaimer below. */ |
---|
14 | /* */ |
---|
15 | /* Atmel's name may not be used to endorse or promote products derived from */ |
---|
16 | /* this software without specific prior written permission. */ |
---|
17 | /* */ |
---|
18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ |
---|
19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ |
---|
20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ |
---|
21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ |
---|
22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ |
---|
23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ |
---|
24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ |
---|
25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ |
---|
26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ |
---|
27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
---|
28 | /* ---------------------------------------------------------------------------- */ |
---|
29 | |
---|
30 | #ifndef _TWID_ |
---|
31 | #define _TWID_ |
---|
32 | |
---|
33 | /*---------------------------------------------------------------------------- |
---|
34 | * Headers |
---|
35 | *----------------------------------------------------------------------------*/ |
---|
36 | |
---|
37 | #include "chip.h" |
---|
38 | |
---|
39 | #include <stdint.h> |
---|
40 | |
---|
41 | /*---------------------------------------------------------------------------- |
---|
42 | * Definition |
---|
43 | *----------------------------------------------------------------------------*/ |
---|
44 | |
---|
45 | /** TWI driver is currently busy. */ |
---|
46 | #define TWID_ERROR_BUSY 1 |
---|
47 | |
---|
48 | /** Transfer is still pending.*/ |
---|
49 | #define ASYNC_STATUS_PENDING 0xFF |
---|
50 | #ifdef __cplusplus |
---|
51 | extern "C" { |
---|
52 | #endif |
---|
53 | |
---|
54 | /*---------------------------------------------------------------------------- |
---|
55 | * Types |
---|
56 | *----------------------------------------------------------------------------*/ |
---|
57 | |
---|
58 | /*---------------------------------------------------------------------------- |
---|
59 | * Type |
---|
60 | *----------------------------------------------------------------------------*/ |
---|
61 | /** \brief Asynchronous transfer descriptor. */ |
---|
62 | typedef struct _Async { |
---|
63 | /** Asynchronous transfer status.*/ |
---|
64 | volatile uint32_t status; |
---|
65 | /** Callback function to invoke when transfer completes or fails.*/ |
---|
66 | void *callback; |
---|
67 | /** Driver storage area; do not use.*/ |
---|
68 | uint8_t pStorage[9]; |
---|
69 | } Async; |
---|
70 | |
---|
71 | /** \brief TWI driver structure. Holds the internal state of the driver.*/ |
---|
72 | typedef struct _Twid { |
---|
73 | /** Pointer to the underlying TWI peripheral.*/ |
---|
74 | Twihs *pTwi; |
---|
75 | /** Current asynchronous transfer being processed.*/ |
---|
76 | Async *pTransfer; |
---|
77 | } Twid; |
---|
78 | |
---|
79 | /** \brief TWI driver structure. Holds the internal state of the driver.*/ |
---|
80 | typedef struct { |
---|
81 | uint8_t Twi_id; |
---|
82 | /** Pointer to the underlying TWI driver.*/ |
---|
83 | Twid *pTwid; |
---|
84 | /** Pointer to the underlying DMA driver for TWI.*/ |
---|
85 | sXdmad *pTwiDma; |
---|
86 | } TwihsDma; |
---|
87 | |
---|
88 | /*---------------------------------------------------------------------------- |
---|
89 | * Export functions |
---|
90 | *----------------------------------------------------------------------------*/ |
---|
91 | extern void TWID_Initialize(Twid *pTwid, Twihs *pTwi); |
---|
92 | extern void TWID_DmaInitialize(TwihsDma *pTwidma, Twihs *pTwi, |
---|
93 | uint8_t bPolling); |
---|
94 | |
---|
95 | extern void TWID_Handler(Twid *pTwid); |
---|
96 | |
---|
97 | extern uint32_t ASYNC_IsFinished(Async *pAsync); |
---|
98 | |
---|
99 | extern uint8_t TWID_Read( |
---|
100 | Twid *pTwid, |
---|
101 | uint8_t address, |
---|
102 | uint32_t iaddress, |
---|
103 | uint8_t isize, |
---|
104 | uint8_t *pData, |
---|
105 | uint32_t num, |
---|
106 | Async *pAsync); |
---|
107 | |
---|
108 | extern uint8_t TWID_Write( |
---|
109 | Twid *pTwid, |
---|
110 | uint8_t address, |
---|
111 | uint32_t iaddress, |
---|
112 | uint8_t isize, |
---|
113 | uint8_t *pData, |
---|
114 | uint32_t num, |
---|
115 | Async *pAsync); |
---|
116 | |
---|
117 | extern uint8_t TWID_DmaRead( |
---|
118 | TwihsDma *pTwiXdma, |
---|
119 | uint8_t address, |
---|
120 | uint32_t iaddress, |
---|
121 | uint8_t isize, |
---|
122 | uint8_t *pData, |
---|
123 | uint32_t num, |
---|
124 | Async *pAsync); |
---|
125 | |
---|
126 | extern uint8_t TWID_DmaWrite( |
---|
127 | TwihsDma *pTwiXdma, |
---|
128 | uint8_t address, |
---|
129 | uint32_t iaddress, |
---|
130 | uint8_t isize, |
---|
131 | uint8_t *pData, |
---|
132 | uint32_t num, |
---|
133 | Async *pAsync); |
---|
134 | |
---|
135 | #ifdef __cplusplus |
---|
136 | } |
---|
137 | #endif |
---|
138 | |
---|
139 | #endif //#ifndef TWID_H |
---|
140 | |
---|